Skip to content

Commit 19257d8

Browse files
committed
FIX: MOLD/FLAT on image values does not remove line breaks
fixes: metaeducation/rebol-issues#2389
1 parent 060126a commit 19257d8

File tree

2 files changed

+18
-5
lines changed

2 files changed

+18
-5
lines changed

src/core/t-image.c

+9-5
Original file line numberDiff line numberDiff line change
@@ -433,6 +433,7 @@ INLINE REBCNT ARGB_To_BGR(REBCNT i)
433433
REBCNT size;
434434
REBCNT *data;
435435
REBYTE* pixel;
436+
REBOOL indented = !GET_MOPT(mold, MOPT_INDENT);
436437

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

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

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

455456
// Output Alpha channel, if it has one:
456457
if (Image_Has_Alpha(value, FALSE)) {
457-
458-
Append_Bytes(mold->series, "\n} #{");
458+
if (indented) Append_Byte(mold->series, '\n');
459+
Append_Bytes(mold->series, "} #{");
459460

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

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

470-
Append_Bytes(mold->series, "\n}");
471+
if (indented)
472+
Append_Bytes(mold->series, "\n}");
473+
else
474+
Append_Byte(mold->series, '}');
471475
}
472476

473477

src/tests/units/mold-test.r3

+9
Original file line numberDiff line numberDiff line change
@@ -269,6 +269,15 @@ Rebol [
269269
--assert "make image! [10x0 #{}]" = mold make image! 10x0
270270
--assert "make image! [0x10 #{}]" = mold make image! 0x10
271271

272+
--test-- "mold/flat image!"
273+
;@@ https://github.com/rebol/rebol-issues/issues/2389
274+
--assert (mold/flat make image! 8x1) = {make image! [8x1 #{FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF}]}
275+
--assert (mold/flat make image! 8x2) = {make image! [8x2 #{FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF}]}
276+
277+
--test-- "mold/flat/all image!"
278+
--assert (mold/all/flat make image! 8x1) = {#[image! 8x1 #{FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF}]}
279+
--assert (mold/all/flat next make image! 8x1) = {#[image! 8x1 #{FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF} 2]}
280+
272281
===end-group===
273282

274283
~~~end-file~~~

0 commit comments

Comments
 (0)