From 935849b418542ae001b1eb10f170d6029b39e812 Mon Sep 17 00:00:00 2001 From: Doug Coleman <doug.coleman@gmail.com> Date: Sat, 14 Mar 2009 15:31:59 -0500 Subject: [PATCH] fix bitmap rendering --- basis/images/bitmap/bitmap.factor | 28 +++++++++++++++++----------- 1 file changed, 17 insertions(+), 11 deletions(-) diff --git a/basis/images/bitmap/bitmap.factor b/basis/images/bitmap/bitmap.factor index dfa2d7f4bf..db3f1c93da 100755 --- a/basis/images/bitmap/bitmap.factor +++ b/basis/images/bitmap/bitmap.factor @@ -11,6 +11,8 @@ IN: images.bitmap : read2 ( -- n ) 2 read le> ; : read4 ( -- n ) 4 read le> ; +: write2 ( n -- ) 2 >le write ; +: write4 ( n -- ) 4 >le write ; TUPLE: bitmap-image < image ; @@ -34,22 +36,25 @@ M: bitmap-magic summary ERROR: bmp-not-supported n ; -: raw-bitmap>seq ( bitmap -- array ) +: reverse-lines ( byte-array width -- byte-array ) + 3 * <sliced-groups> <reversed> concat ; inline + +: raw-bitmap>seq ( loading-bitmap -- array ) dup bit-count>> { { 32 [ color-index>> ] } - { 24 [ color-index>> ] } - { 8 [ 8bit>buffer ] } + { 24 [ [ color-index>> ] [ width>> ] bi reverse-lines ] } + { 8 [ [ 8bit>buffer ] [ width>> ] bi reverse-lines ] } [ bmp-not-supported ] } case >byte-array ; -: parse-file-header ( bitmap -- bitmap ) +: parse-file-header ( loading-bitmap -- loading-bitmap ) 2 read "BM" assert-sequence= read4 >>size read4 >>reserved read4 >>offset ; -: parse-bitmap-header ( bitmap -- bitmap ) +: parse-bitmap-header ( loading-bitmap -- loading-bitmap ) read4 >>header-length read4 >>width read4 >>height @@ -84,7 +89,7 @@ ERROR: bmp-not-supported n ; ERROR: unknown-component-order bitmap ; -: bitmap>component-order ( bitmap -- object ) +: bitmap>component-order ( loading-bitmap -- object ) bit-count>> { { 32 [ BGRA ] } { 24 [ BGR ] } @@ -102,10 +107,8 @@ ERROR: unknown-component-order bitmap ; M: bitmap-image load-image* ( path loading-bitmap -- bitmap ) drop loading-bitmap new - load-bitmap-data loading-bitmap>bitmap-image ; - -: write2 ( n -- ) 2 >le write ; -: write4 ( n -- ) 4 >le write ; + load-bitmap-data + loading-bitmap>bitmap-image ; PRIVATE> @@ -150,7 +153,10 @@ PRIVATE> [ drop 0 write4 ] ! rgb-quads - [ bitmap>> bitmap>color-index write ] + [ + [ bitmap>> bitmap>color-index ] [ dim>> first ] bi + reverse-lines write + ] } cleave ] bi ] with-file-writer ;