Skip to content

Commit

Permalink
FIX: MOLD/FLAT on image values does not remove line breaks
Browse files Browse the repository at this point in the history
  • Loading branch information
Oldes committed Sep 24, 2019
1 parent 060126a commit 19257d8
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 5 deletions.
14 changes: 9 additions & 5 deletions src/core/t-image.c
Original file line number Diff line number Diff line change
Expand Up @@ -433,6 +433,7 @@ INLINE REBCNT ARGB_To_BGR(REBCNT i)
REBCNT size;
REBCNT *data;
REBYTE* pixel;
REBOOL indented = !GET_MOPT(mold, MOPT_INDENT);

Emit(mold, "IxI #{", VAL_IMAGE_WIDE(value), VAL_IMAGE_HIGH(value));

Expand All @@ -444,18 +445,18 @@ INLINE REBCNT ARGB_To_BGR(REBCNT i)
return;
}
data = (REBCNT *)VAL_IMAGE_DATA(value);
up = Prep_Uni_Series(mold, (size * 6) + ((size - 1) / 10) + 1);
up = Prep_Uni_Series(mold, indented ? ((size * 6) + ((size - 1) / 10) + 1) : (size * 6));

for (len = 0; len < size; len++) {
pixel = (REBYTE*)data++;
if ((len % 10) == 0) *up++ = LF;
if (indented && (len % 10) == 0) *up++ = LF;
up = Form_RGB_Uni(up, TO_RGBA_COLOR(pixel[C_R], pixel[C_G], pixel[C_B], pixel[C_A]));
}

// Output Alpha channel, if it has one:
if (Image_Has_Alpha(value, FALSE)) {

Append_Bytes(mold->series, "\n} #{");
if (indented) Append_Byte(mold->series, '\n');
Append_Bytes(mold->series, "} #{");

up = Prep_Uni_Series(mold, (size * 2) + (size / 10) + 1);

Expand All @@ -467,7 +468,10 @@ INLINE REBCNT ARGB_To_BGR(REBCNT i)
}
*up = 0; // tail already set from Prep.

Append_Bytes(mold->series, "\n}");
if (indented)
Append_Bytes(mold->series, "\n}");
else
Append_Byte(mold->series, '}');
}


Expand Down
9 changes: 9 additions & 0 deletions src/tests/units/mold-test.r3
Original file line number Diff line number Diff line change
Expand Up @@ -269,6 +269,15 @@ Rebol [
--assert "make image! [10x0 #{}]" = mold make image! 10x0
--assert "make image! [0x10 #{}]" = mold make image! 0x10

--test-- "mold/flat image!"
;@@ https://github.com/rebol/rebol-issues/issues/2389
--assert (mold/flat make image! 8x1) = {make image! [8x1 #{FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF}]}
--assert (mold/flat make image! 8x2) = {make image! [8x2 #{FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF}]}

--test-- "mold/flat/all image!"
--assert (mold/all/flat make image! 8x1) = {#[image! 8x1 #{FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF}]}
--assert (mold/all/flat next make image! 8x1) = {#[image! 8x1 #{FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF} 2]}

===end-group===

~~~end-file~~~

0 comments on commit 19257d8

Please sign in to comment.