metaeducation / rebol-issues

6 stars 1 forks source link

image converted from too short binary has unexpected size #1048

Open rebolbot opened 15 years ago

rebolbot commented 15 years ago

Submitted by: meijeru

When applying TO-IMAGE on a binary of length L, the size is computed as TO-PAIR [L / 4 1], in other words, it is a single row of pixels. But when L < 4, the result is not 0x1 as per this formula, but 1x0 instead, in other words a single column.

>> i: to-image #{0000} ; too few bytes for the first pixel
== make image! [1x0 #{}]
>> append i [0.0.0.0 0.0.0.0]
== make image! [1x2 #{000000000000}]

CC - Data [ Version: alpha 66 Type: Bug Platform: All Category: n/a Reproduce: Always Fixed-in:alpha 67 ]

rebolbot commented 15 years ago

Submitted by: meijeru

Mind you, I think the 1x0 is inevitable, since append works by adding rows at the bottom of a column, and with 0x1 there would not be a column to which to add. Thus the formula could become TO-PAIR [1 L / 4] instead.

rebolbot commented 15 years ago

Submitted by: Carl

In A67, when less than 4 bytes, an error will be thrown.

For longer binaries, note that any extra pixels (non mod 4) will be discarded.