Commit a609304f authored by Robert Sprowson's avatar Robert Sprowson

Add support for 2bpp BMP files and those with flipped scan order

Fix import of OS/2 BMP files

WinCE is documented on MSDN as creating and displaying 2bpp bitmaps, so we might as well support them.
Also, MSDN states that when the BITMAPINFOHEADER is in use the height is a signed number, with -ve values meaning the scan order is reversed (top down).

Relatedly, the width and height in an OS/2 bitmap are only 16 (unsigned) bits, whereas ChangeFSI was reading in 32 bit values leading to grossly wrong dimensions, plus it uses packed 24 bit palette values not 32 bit like Windows.
Docs updated and info fields made more verbose to report whether it's a Windows or OS/2 BMP.

Now successfully opens all the 'good' bitmaps in BMP Suite http://entropymine.com/jason/bmpsuite/

Version 1.50. Tagged as 'ChangeFSI-1_50'
parent 47af4441
......@@ -40,7 +40,7 @@ Pineapple 16 bit per pixel images
FITS astronomical format images
Irlam Instruments YUV 411 files
Irlam Instruments 24-bit files
Windows 3 .BMP files
Windows 3 and OS/2 BMP files
Compuserve's GIF files up to 8 bit per pixel
.PIC 8 bit per pixel files
Sun 'pixrect' raster files
......@@ -385,17 +385,20 @@ Irlam Instruments 24-bit files
Can be written.
Windows 3 .BMP files
--------------------
Windows 3 and OS/2 BMP files
----------------------------
Used by MicroSoft in Windows 3 and PaintBrush for Windows 3. Provides an
arbitrary sized image and 1, 4 or 8 bits per pixel. Uncompressed.
arbitrary sized image with 1, 2, 4, 8, 24 or 32 bits per pixel.
Recognised by 'BM' at the start of the file; or 'RIFF' at the start of the
file, and 'RDIBdata' at offset 8 and 'BM' at offset 20 in file.
No resolution specified; equal to mode 27 assumed.
Generally uncompressed, but can use RLE4 or RLE8 when fewer than 8bpp.
2bpp variant occurs on the Windows CE platform.
Documentation never seen - 7 files examined and intelligent guesses made!
Resolution derived from pixels-per-metre value in Windows 3 header.
No resolution specified in OS/2 header; equal to mode 27 assumed.
Compuserve's GIF files up to 8 bit per pixel
--------------------------------------------
......@@ -736,7 +739,7 @@ Pineapple 16 bit per pixel image [FSIfile in file]
FITS astronomical format [SIMPLE in file]
Irlam Instruments YUV 411 files [IRLAM YUV 411 in file]
Irlam Instruments 24 bit files [Irlam in file]
Windows 3 .BMP files [BM in file]
Windows 3 and OS/2 BMP files [BM in file]
Compuserve's GIF files up to 8 bit per pixel [GIF87a in file]
.PIC 8 bit per pixel files [AV_VO in file]
Sun 'pixrect' Raster Files [&956AA659 in file]
......
/* (1.49)
/* (1.50)
*
* This file is automatically maintained by srccommit, do not edit manually.
* Last processed by srccommit version: 1.1.
*
*/
#define Module_MajorVersion_CMHG 1.49
#define Module_MajorVersion_CMHG 1.50
#define Module_MinorVersion_CMHG
#define Module_Date_CMHG 04 Aug 2014
#define Module_Date_CMHG 08 Aug 2014
#define Module_MajorVersion "1.49"
#define Module_Version 149
#define Module_MajorVersion "1.50"
#define Module_Version 150
#define Module_MinorVersion ""
#define Module_Date "04 Aug 2014"
#define Module_Date "08 Aug 2014"
#define Module_ApplicationDate "04-Aug-14"
#define Module_ApplicationDate "08-Aug-14"
#define Module_ComponentName "ChangeFSI"
#define Module_ComponentPath "mixed/RiscOS/Sources/Apps/ChangeFSI"
#define Module_FullVersion "1.49"
#define Module_HelpVersion "1.49 (04 Aug 2014)"
#define Module_LibraryVersionInfo "1:49"
#define Module_FullVersion "1.50"
#define Module_HelpVersion "1.50 (08 Aug 2014)"
#define Module_LibraryVersionInfo "1:50"
......@@ -3316,16 +3316,21 @@ DEF FNChangeFSI(A$,spritearea%,workspace%,worklimit%,oksave%,okinfo%,RETURN ram%
PTR#c%=riffoff%+&0a
st%=FNW
pal%=FNW
sx%=FNW
sy%=FNW
CASE pal% OF
WHEN 12
REM OS/2 1.x variant
REM OS/2 1.x form 'BITMAPCOREHEADER'
sx%=FNHW
sy%=FNHW
PTR#c%=riffoff%+&18
input=FNHW
compression=0
info$="OS/2 "
WHEN 40
REM proper Windows form
REM Windows 3 form 'BITMAPINFOHEADER'
sx%=FNW
sy%=FNW
IF sx%<0 THEN ERROR 42, "Negative BMP width encountered"
IF sy%<0 THEN sy%=ABS(sy%) : vflip%=NOT vflip% : REM Top down scan order
PTR#c%=riffoff%+&1c
input=FNHW
compression=FNW
......@@ -3340,28 +3345,36 @@ DEF FNChangeFSI(A$,spritearea%,workspace%,worklimit%,oksave%,okinfo%,RETURN ram%
ydiv%=ydiv%*yppm
ymul%=ymul%*3543
ENDIF
info$="Windows 3.0 "
OTHERWISE
ERROR 42,"Unknown .BMP variant ("+ STR$pal%+")"
ERROR 42,"Unknown BMP variant (size "+ STR$pal%+")"
ENDCASE
quant%=input
bigendianbits= TRUE
vflip%=NOT vflip%
CASE input OF
WHEN 1
rowbytes%=sx%+7>>3
WHEN 2
rowbytes%=sx%+3>>2 : REM WinCE
WHEN 4
rowbytes%=sx%+1>>1
WHEN 8
rowbytes%=sx%
WHEN 16
rowbytes%=sx%*2
r$="FN16"
step24=2
rowbytes%=sx%*step24
r$="FN16"
DIM rpal%(255),gpal%(255)
rmask%=&7c00
gmask%=42
bmask%=-42
IF compression=3 PTR#c%=riffoff%+14+pal%:rmask%=FNW:gmask%=FNW:bmask%=FNW:compression=0
IF compression=3 THEN
REM Inspect 'BITFIELDS' masks
PTR#c%=riffoff%+14+pal%
rmask%=FNW:gmask%=FNW:bmask%=FNW
compression=0
ENDIF
IF rmask%=&7c00 THEN
REM 5:5:5 (default)
FOR C%=0 TO 255
gpal%(C%)=(C%>>5)<<8 OR (C% AND 31)<<16
rpal%(C%)=(C%>>2) AND 31 OR (C% AND 3)<<11
......@@ -3373,6 +3386,7 @@ DEF FNChangeFSI(A$,spritearea%,workspace%,worklimit%,oksave%,okinfo%,RETURN ram%
b%()=r%()
ENDIF
IF rmask%=&f800 THEN
REM 5:6:5
FOR C%=0 TO 255
gpal%(C%)=(C%>>5)<<8 OR (C% AND 31)<<16
rpal%(C%)=(C%>>3) AND 31 OR (C% AND 7)<<11
......@@ -3386,28 +3400,26 @@ DEF FNChangeFSI(A$,spritearea%,workspace%,worklimit%,oksave%,okinfo%,RETURN ram%
NEXT
ENDIF
WHEN 24,32
step24=input DIV8
rowbytes%=sx%*step24
r$="FN24"
rbo%=2
gbo%=1
bbo%=0
r$="FN24"
FOR C%=0 TO 255
r%(C%)=C%/255*F
NEXT
g%()=r%()
b%()=r%()
r$="FN24"
step24=input/8
rowbytes%=sx%*step24
rmask%=-1
gmask%=42
bmask%=-42
IF compression=3 PTR#c%=riffoff%+14+pal%:rmask%=FNW:gmask%=FNW:bmask%=FNW:compression=0
IF rmask%=&FF THEN rbo%=0:gbo%=1:bbo%=2
IF gmask%=&FF THEN gbo%=0:bbo%=1:rbo%=2
IF bmask%=&FF THEN bbo%=0:gbo%=1:rbo%=2
PROCnopal
IF compression=3 THEN
REM Inspect 'BITFIELDS' masks
PTR#c%=riffoff%+14+pal%
rmask%=FNW:gmask%=FNW:bmask%=FNW
rbo%=-1:gbo%=-1:bbo%=-1
compression=0
REPEAT:rbo%+=1:rmask%=rmask%>>>8:UNTIL rmask%=0
REPEAT:gbo%+=1:gmask%=gmask%>>>8:UNTIL gmask%=0
REPEAT:bbo%+=1:bmask%=bmask%>>>8:UNTIL bmask%=0
ENDIF
input=24
OTHERWISE
ERROR 42,".BMP file of unusual depth ("+ STR$input+")"
ERROR 42,"BMP file of unusual depth ("+ STR$input+")"
ENDCASE
IF input<=8 THEN
PTR#c%=riffoff%+14+pal%
......@@ -3416,26 +3428,25 @@ DEF FNChangeFSI(A$,spritearea%,workspace%,worklimit%,oksave%,okinfo%,RETURN ram%
b%(C%)=BGET#c%/255*F
g%(C%)=BGET#c%/255*F
r%(C%)=BGET#c%/255*F
IF BGET#c%
IF pal%<>12 THEN junk%=BGET#c% : REM OS/2 uses RGB, Win 3.0 uses RGBA
NEXT
ENDIF
CASE compression OF
WHEN 0
info$="Uncompressed "
WHEN 1
info$="RLE8 compressed "
info$+="RLE8 compressed "
r$="FN2401"
WHEN 2
info$="RLE4 compressed "
info$+="RLE4 compressed "
r$="FN2402"
OTHERWISE
ERROR 42,".BMP compression type not supported ("+ STR$compression+")"
ERROR 42,"BMP compression type not supported ("+ STR$compression+")"
ENDCASE
rowbytes%=rowbytes%+3 AND NOT 3
IF compression<>0 cachebytes%= TRUE :plbuff%=FNdim(rowbytes%)
cache%= TRUE
PTR#c%=riffoff%+st%
info$+="Windows 3.0 .BMP image, "+ STR$sx%+" by "+ STR$sy%+" pixels, "+FNbits(input)
info$+="BMP image, "+ STR$sx%+" by "+ STR$sy%+" pixels, "+FNbits(quant%)
WHEN 2500
REM !Translator Clear format
PTR#c%=0
......@@ -8272,10 +8283,10 @@ DEF FNChangeFSI(A$,spritearea%,workspace%,worklimit%,oksave%,okinfo%,RETURN ram%
REM TEQ r0,#0 REM is it end-of-row?
REM LDMEQFD SP !,{R14}
REM MOVEQS PC,R14
REM others not implemented...
CMP r3,#0
MOVGT r5,r2,LSR#24
STRGTB r5,[r8],#1
REM others not implemented...
LDMFD SP !,{R5,R14}
FNcpsr_from_r(5)
MOV PC,R14
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment