Commit c6f0b231 authored by Robert Sprowson's avatar Robert Sprowson

Add support for Windows icon and cursor import

Windows 3 style ICO and CUR files are internally very similar to BMP files, so much of the hard work already existed.
As with other multi-frame formats (GIF and Sprite for example) ChangeFSI simply picks the first one it finds in a file, even if there are several offered.
In modifying the BMP importer, ChangeFSI no longer reads off the end of the palette for bitmaps which don't use all 2^bpp entries.
Tested with a variety of icons and bitmaps up to the maximum size allowed 256x256 pixels.
Documents updated.

Version 1.51. Tagged as 'ChangeFSI-1_51'
parent a609304f
......@@ -40,7 +40,8 @@ Pineapple 16 bit per pixel images
FITS astronomical format images
Irlam Instruments YUV 411 files
Irlam Instruments 24-bit files
Windows 3 and OS/2 BMP files
Windows 3 and OS/2 BMP files -
and BMP embedded in ICO (icon) and CUR (cursor) files
Compuserve's GIF files up to 8 bit per pixel
.PIC 8 bit per pixel files
Sun 'pixrect' raster files
......@@ -393,6 +394,11 @@ 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.
Device independent bitmaps are also used for icons (.ICO) and cursors (.CUR)
- Icons recognised by &00010000 at the start of file and file type 132
- Cursors recognised by &00020000 at the start of file and file type 6A5
in each case only the first bitmap in the container will be displayed.
Generally uncompressed, but can use RLE4 or RLE8 when fewer than 8bpp.
2bpp variant occurs on the Windows CE platform.
......@@ -740,6 +746,11 @@ 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 and OS/2 BMP files [BM in file]
and RIFF files [RIFF AND RDIBdata AND BM in file]
and ICO files [0,0,1,0 in file AND (file type 132
OR named /ICO)]
and CUR files [0,0,2,0 in file AND (file type 6A5
OR named /CUR)]
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.50)
/* (1.51)
*
* This file is automatically maintained by srccommit, do not edit manually.
* Last processed by srccommit version: 1.1.
*
*/
#define Module_MajorVersion_CMHG 1.50
#define Module_MajorVersion_CMHG 1.51
#define Module_MinorVersion_CMHG
#define Module_Date_CMHG 08 Aug 2014
#define Module_Date_CMHG 02 Sep 2014
#define Module_MajorVersion "1.50"
#define Module_Version 150
#define Module_MajorVersion "1.51"
#define Module_Version 151
#define Module_MinorVersion ""
#define Module_Date "08 Aug 2014"
#define Module_Date "02 Sep 2014"
#define Module_ApplicationDate "08-Aug-14"
#define Module_ApplicationDate "02-Sep-14"
#define Module_ComponentName "ChangeFSI"
#define Module_ComponentPath "mixed/RiscOS/Sources/Apps/ChangeFSI"
#define Module_FullVersion "1.50"
#define Module_HelpVersion "1.50 (08 Aug 2014)"
#define Module_LibraryVersionInfo "1:50"
#define Module_FullVersion "1.51"
#define Module_HelpVersion "1.51 (02 Sep 2014)"
#define Module_LibraryVersionInfo "1:51"
......@@ -1699,7 +1699,7 @@ DEF FNChangeFSI(A$,spritearea%,workspace%,worklimit%,oksave%,okinfo%,RETURN ram%
REM TRACE TO ":4.foo"
REM TRACE ON
colourindex=255
SYS &66f4d TO ;pcd%
SYS &66f4d TO ;pcd% : REM PhotoCD_MiscOp
CASE ftype OF
WHEN &FF9
flag=0
......@@ -1768,8 +1768,10 @@ DEF FNChangeFSI(A$,spritearea%,workspace%,worklimit%,oksave%,okinfo%,RETURN ram%
IF flag=-1 IF FNuc(LEFT$(S$,8))="MERCSOF1" flag=903
IF flag=-1 IF FNuc(LEFT$(S$,13))="IRLAM YUV 411" flag=2250
IF flag=-1 IF LEFT$(S$,5)="Irlam" flag=2200
IF flag=-1 IF LEFT$(S$,2)="BM" flag=2400:riffoff%=0
IF flag=-1 IF LEFT$(S$,4)="RIFF" AND MID$(S$,9,8)="RDIBdata" AND MID$(S$,21,2)="BM" flag=2400:riffoff%=20
IF flag=-1 IF LEFT$(S$,2)="BM" flag=2400
IF flag=-1 IF LEFT$(S$,4)="RIFF" AND MID$(S$,9,8)="RDIBdata" AND MID$(S$,21,2)="BM" flag=2401
IF flag=-1 IF LEFT$(S$,4)=CHR$0+CHR$0+CHR$1+CHR$0 AND ftype=&132 flag=2402
IF flag=-1 IF LEFT$(S$,4)=CHR$0+CHR$0+CHR$2+CHR$0 AND ftype=&6A5 flag=2403
IF flag=-1 IF LEFT$(S$,4)="GIF8" flag=500
IF flag=-1 IF LEFT$(S$,5)="AV_VO" flag=600
IF flag=-1 IF LEFT$(S$,4)=CHR$&59+CHR$&A6+CHR$&6A+CHR$&95 flag=1100
......@@ -1789,7 +1791,7 @@ DEF FNChangeFSI(A$,spritearea%,workspace%,worklimit%,oksave%,okinfo%,RETURN ram%
IF flag=-1 IF LEFT$(S$,8)="ALPIAR12" flag=3900:colourindex=4095
IF flag=-1 IF LEFT$(S$,8)="ALPIAR16" flag=3905:colourindex=65535
IF flag=-1 IF LEFT$(S$,8)=CHR$&89+"PNG"+CHR$13+CHR$10+CHR$26+CHR$10 flag=4000
IF flag=-1 IF LEFT$(S$,2)=CHR$0+CHR$0 AND (ftype=&F8F OR FNuc(RIGHT$(s$,5))="/WBMP") THEN flag=4100
IF flag=-1 IF LEFT$(S$,2)=CHR$0+CHR$0 AND (ftype=&F8F OR FNuc(RIGHT$(s$,5))="/WBMP") flag=4100
IF flag=-1 THEN
IF MID$(S$,7,4)="JFIF" OR LEFT$(S$,3)=CHR$&FF+CHR$&D8+CHR$&FF OR ftype=&C85 THEN
REM Read the cache size variable
......@@ -3310,13 +3312,25 @@ DEF FNChangeFSI(A$,spritearea%,workspace%,worklimit%,oksave%,okinfo%,RETURN ram%
gb%=buff%+1*sx%
bb%=buff%+2*sx%
PROCrewind
info$="Utah rle image, "+ STR$sx%+" by "+ STR$sy%+" pixels, "+FNbits(ncolors%*quant%)
WHEN 2400
REM Windows 3 .BMP (guessed currently)
PTR#c%=riffoff%+&0a
st%=FNW
pal%=FNW
CASE pal% OF
info$="Utah RLE image, "+ STR$sx%+" by "+ STR$sy%+" pixels, "+FNbits(ncolors%*quant%)
WHEN 2400,2401,2402,2403
REM OS/2 and Windows 3 bitmaps, possibly containerised
CASE flag OF
WHEN 2400
riffoff%=0
s$="BMP"
WHEN 2401
riffoff%=20
s$="BMP inside RIFF"
WHEN 2402,2403
REM Pick the first one in the icon directory
PTR#c%=6+12 : REM Skip ICONDIR and up to the image offset of 1st ICONDIRENTRY
riffoff%=FNW-14 : REM Back calculate where 'BM' would have been
IF flag=2403 THEN s$="cursor" ELSE s$="icon"
ENDCASE
PTR#c%=riffoff%+&E
sz%=FNW
CASE sz% OF
WHEN 12
REM OS/2 1.x form 'BITMAPCOREHEADER'
sx%=FNHW
......@@ -3324,6 +3338,7 @@ DEF FNChangeFSI(A$,spritearea%,workspace%,worklimit%,oksave%,okinfo%,RETURN ram%
PTR#c%=riffoff%+&18
input=FNHW
compression=0
cmaplen%=0
info$="OS/2 "
WHEN 40
REM Windows 3 form 'BITMAPINFOHEADER'
......@@ -3337,7 +3352,7 @@ DEF FNChangeFSI(A$,spritearea%,workspace%,worklimit%,oksave%,okinfo%,RETURN ram%
PTR#c%=riffoff%+&26
xppm=FNW
yppm=FNW
REM pixels per meter
REM pixels per metre
IF (xppm<>0 AND yppm<>0 AND scale%<>0) THEN
xdiv%=xdiv%*xppm
xmul%=xmul%*3543
......@@ -3345,13 +3360,17 @@ DEF FNChangeFSI(A$,spritearea%,workspace%,worklimit%,oksave%,okinfo%,RETURN ram%
ydiv%=ydiv%*yppm
ymul%=ymul%*3543
ENDIF
cmaplen%=FNW : REM Colours used in colour table
info$="Windows 3.0 "
OTHERWISE
ERROR 42,"Unknown BMP variant (size "+ STR$pal%+")"
ERROR 42,"Unknown BMP variant (size "+ STR$sz%+")"
ENDCASE
quant%=input
bigendianbits= TRUE
vflip%=NOT vflip%
IF flag=2402 OR flag=2403 THEN sy%=sy%/2 : REM Icon and cursor heights are image+mask, only want image
flag=2400 : REM All common from here on
PTR#c%=riffoff%+&E+sz%
CASE input OF
WHEN 1
rowbytes%=sx%+7>>3
......@@ -3369,7 +3388,6 @@ DEF FNChangeFSI(A$,spritearea%,workspace%,worklimit%,oksave%,okinfo%,RETURN ram%
rmask%=&7c00
IF compression=3 THEN
REM Inspect 'BITFIELDS' masks
PTR#c%=riffoff%+14+pal%
rmask%=FNW:gmask%=FNW:bmask%=FNW
compression=0
ENDIF
......@@ -3409,7 +3427,6 @@ DEF FNChangeFSI(A$,spritearea%,workspace%,worklimit%,oksave%,okinfo%,RETURN ram%
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
......@@ -3422,14 +3439,17 @@ DEF FNChangeFSI(A$,spritearea%,workspace%,worklimit%,oksave%,okinfo%,RETURN ram%
ERROR 42,"BMP file of unusual depth ("+ STR$input+")"
ENDCASE
IF input<=8 THEN
PTR#c%=riffoff%+14+pal%
r$="FN8"
FOR C%=0 TO 2^input-1
IF cmaplen%=0 cmaplen%=1<<input : REM Default number
FOR C%=0 TO cmaplen%-1
b%(C%)=BGET#c%/255*F
g%(C%)=BGET#c%/255*F
r%(C%)=BGET#c%/255*F
IF pal%<>12 THEN junk%=BGET#c% : REM OS/2 uses RGB, Win 3.0 uses RGBA
IF sz%<>12 THEN junk%=BGET#c% : REM OS/2 uses RGB, Win 3.0 uses ARGB
NEXT
ELSE
REM 16/24/32 can have an optimal colour table too, skip over those words
IF cmaplen%<>0 THEN PTR#c%=PTR#c% + (cmaplen%*4)
ENDIF
CASE compression OF
WHEN 0
......@@ -3442,11 +3462,12 @@ DEF FNChangeFSI(A$,spritearea%,workspace%,worklimit%,oksave%,okinfo%,RETURN ram%
OTHERWISE
ERROR 42,"BMP compression type not supported ("+ STR$compression+")"
ENDCASE
REM Now at the image start for general case 'BM'<header>[bitfields][palette]<image>
st%=PTR#c%
rowbytes%=rowbytes%+3 AND NOT 3
IF compression<>0 cachebytes%= TRUE :plbuff%=FNdim(rowbytes%)
cache%= TRUE
PTR#c%=riffoff%+st%
info$+="BMP image, "+ STR$sx%+" by "+ STR$sy%+" pixels, "+FNbits(quant%)
info$+=s$+", "+ STR$sx%+" by "+ STR$sy%+" pixels, "+FNbits(quant%)
WHEN 2500
REM !Translator Clear format
PTR#c%=0
......
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