2 Copyright © 1995-2013, The AROS Development Team. All rights reserved.
6 /****************************************************************************************/
8 #include <aros/debug.h>
10 #include <datatypes/pictureclass.h>
12 #include <proto/dos.h>
13 #include <proto/alib.h>
17 #include <aros/bigendianio.h>
18 #include <aros/asmcall.h>
20 #include "icon_intern.h"
22 /****************************************************************************************/
24 #define ID_ICON MAKE_ID('I','C','O','N')
25 #define ID_FACE MAKE_ID('F','A','C','E')
26 #define ID_IMAG MAKE_ID('I','M','A','G')
27 #define ID_png MAKE_ID('p','n','g',' ')
28 #define ID_ARGB MAKE_ID('A','R','G','B')
30 /****************************************************************************************/
38 UBYTE MaxPaletteBytes
[2];
43 UBYTE TransparentColor
;
49 UBYTE NumImageBytes
[2];
50 UBYTE NumPaletteBytes
[2];
53 /****************************************************************************************/
55 static LONG
MyDOSStreamHandler(struct Hook
*hook
, struct IFFHandle
* iff
, struct IFFStreamCmd
* cmd
)
59 struct IconBase
*IconBase
= hook
->h_Data
;
61 switch(cmd
->sc_Command
)
69 error
= (FRead((BPTR
)iff
->iff_Stream
, cmd
->sc_Buf
, 1, cmd
->sc_NBytes
)) != cmd
->sc_NBytes
;
73 error
= (FWrite((BPTR
)iff
->iff_Stream
, cmd
->sc_Buf
, 1, cmd
->sc_NBytes
)) != cmd
->sc_NBytes
;
77 Flush((BPTR
)iff
->iff_Stream
);
78 error
= (Seek((BPTR
)iff
->iff_Stream
, cmd
->sc_NBytes
, OFFSET_CURRENT
)) == -1;
85 static LONG
MyMemStreamHandler(struct Hook
*hook
, struct IFFHandle
* iff
, struct IFFStreamCmd
* cmd
)
88 APTR
*buffp
= (APTR
*)iff
->iff_Stream
;
91 switch(cmd
->sc_Command
)
100 CopyMem(buff
, cmd
->sc_Buf
, cmd
->sc_NBytes
);
101 (*buffp
) += cmd
->sc_NBytes
;
106 CopyMem(cmd
->sc_Buf
, buff
, cmd
->sc_NBytes
);
107 (*buffp
) += cmd
->sc_NBytes
;
111 (*buffp
) += cmd
->sc_NBytes
;
119 /****************************************************************************************/
121 /* Decode35() based on ModifyIcon by Dirk Stöcker */
123 /****************************************************************************************/
125 static char *Decode35(UBYTE
*buffer
, UBYTE
*outbuffer
, LONG numbytes
, LONG bits
, LONG entries
)
127 int cop
= 0, loop
= 0, numbits
= 0, mask
, curentry
= 0;
133 while((numbytes
|| (cop
&& numbits
>= bits
)) && (curentry
< entries
))
139 bitbuf
= (bitbuf
<<8)|*(buffer
++); --numbytes
;
143 byte
= (bitbuf
>>(numbits
-8))&0xFF;
146 if(byte
<= 127) cop
= byte
+1;
147 else if(byte
> 128) loop
= 256-byte
+1;
155 bitbuf
= (bitbuf
<<8)|*(buffer
++); --numbytes
;
159 byte
= (bitbuf
>>(numbits
-bits
))&mask
;
161 while(loop
&& (curentry
< entries
))
173 return curentry
!= entries
? "error decoding new icon data" : 0;
176 /****************************************************************************************/
178 VOID
MakeMask35(UBYTE
*imgdata
, UBYTE
*imgmask
, UBYTE transpcolor
, LONG imagew
, LONG imageh
)
181 WORD x
, y
, bpr
, mask
;
183 memset(imgmask
, 0xFF, RASSIZE(imagew
, imageh
));
185 bpr
= ((imagew
+ 15) & ~15) / 8;
189 for(y
= 0; y
< imageh
; y
++)
195 for(x
= 0; x
< imagew
; x
++)
197 if (*(src
++) == transpcolor
)
215 /****************************************************************************************/
216 void *malloc(size_t size
)
218 return AllocVec(size
, MEMF_PUBLIC
);
226 STATIC BOOL
ReadARGB35(struct DiskObject
*icon
, struct IFFHandle
*iff
, struct FileFaceChunk
*fc
,
227 LONG chunksize
, UBYTE
**argbptr
,
228 struct IconBase
*IconBase
)
230 UBYTE
*src
, *mem
, *argb
= NULL
;
236 imagew
= fc
->Width
+ 1;
237 imageh
= fc
->Height
+ 1;
238 size
= imagew
* imageh
* 4;
240 D(bug("[%s] ARGB size is %dx%d, %d => %d bytes\n", __func__
, imagew
, imageh
, chunksize
, size
));
242 src
= mem
= AllocMemIcon(icon
, chunksize
, MEMF_PUBLIC
, IconBase
);
243 if (!src
) return FALSE
;
245 if (ReadChunkBytes(iff
, src
, chunksize
) != chunksize
)
250 argb
= AllocMemIcon(icon
, size
, MEMF_PUBLIC
, IconBase
);
251 if (!argb
) goto fail
;
253 zsize
= AROS_BE2WORD(*((UWORD
*)(src
+ 6))) + 1;
254 err
= uncompress(argb
, &size
, src
+ 10, zsize
);
256 D(bug("%s: Can't uncompress %d ARGB bytes: %s\n", __func__
, zsize
, zError(err
)));
268 /****************************************************************************************/
270 STATIC BOOL
ReadImage35(struct DiskObject
*icon
, struct IFFHandle
*iff
, struct FileFaceChunk
*fc
,
271 struct FileImageChunk
*ic
, UBYTE
**imgdataptr
,
272 struct ColorRegister
**imgpalptr
, struct IconBase
*IconBase
)
274 UBYTE
*src
, *mem
, *imgdata
= NULL
;
275 struct ColorRegister
*imgpal
= NULL
;
276 LONG size
, imgsize
, palsize
, imagew
, imageh
, numcols
;
278 imagew
= fc
->Width
+ 1;
279 imageh
= fc
->Height
+ 1;
280 numcols
= ic
->NumColors
+ 1;
282 imgsize
= ic
->NumImageBytes
[0] * 256 + ic
->NumImageBytes
[1] + 1;
283 if (ic
->Flags
& IMAGE35F_HASPALETTE
)
285 palsize
= ic
->NumPaletteBytes
[0] * 256 + ic
->NumPaletteBytes
[1] + 1;
292 D(bug("[%s] Image size is %dx%d, %d bytes\n", __func__
, imagew
, imageh
, imgsize
));
293 D(bug("[%s] Palette size is %d colors, %d bytes\n", __func__
, numcols
, palsize
));
295 size
= imgsize
+ palsize
;
297 src
= mem
= AllocMemIcon(icon
, size
, MEMF_PUBLIC
, IconBase
);
298 if (!src
) return FALSE
;
300 if (ReadChunkBytes(iff
, src
, size
) != size
)
305 if (ic
->Flags
& IMAGE35F_HASPALETTE
)
307 if (numcols
< 1 || numcols
> 256)
310 size
= numcols
* sizeof(struct ColorRegister
);
311 imgpal
= AllocMemIcon(icon
, size
, MEMF_PUBLIC
, IconBase
);
312 if (!imgpal
) goto fail
;
315 size
= imagew
* imageh
;
316 imgdata
= AllocMemIcon(icon
, size
, MEMF_PUBLIC
, IconBase
);
317 if (!imgdata
) goto fail
;
319 if (ic
->ImageFormat
== 0)
321 memcpy(imgdata
, src
, imagew
* imageh
);
325 Decode35(src
, imgdata
, imgsize
, ic
->Depth
, imagew
* imageh
);
329 if (ic
->Flags
& IMAGE35F_HASPALETTE
)
331 struct ColorRegister
*dst
;
335 D(bug("[%s] PaletteFormat %d, src %p\n", __func__
, ic
->PaletteFormat
, src
));
336 if (ic
->PaletteFormat
== 0)
340 for(i
= 0; i
< numcols
; i
++)
356 err
= Decode35(src
, (UBYTE
*)imgpal
, palsize
, 8, 3 * numcols
);
358 D(bug("[%s] Palette decode error: %s\n", __func__
, err
));
363 if (imgpal
&& sizeof(struct ColorRegister
) != 3)
365 struct ColorRegister
*dst
;
368 D(bug("[%s] Realigning ColorRegister\n", __func__
));
370 src
= (APTR
)imgpal
+ 3 * numcols
;
371 dst
= (struct ColorRegister
*)(imgpal
+ sizeof(struct ColorRegister
) * numcols
);
373 for (i
= 0; i
< numcols
; i
++)
388 } /* if (ic->Flags & IMAGE35F_HASPALETTE) */
390 *imgdataptr
= imgdata
;
399 /****************************************************************************************/
401 BOOL
ReadIcon35(struct NativeIcon
*icon
, struct Hook
*streamhook
,
402 void *stream
, struct IconBase
*IconBase
)
404 static const LONG
const stopchunks
[] =
412 struct IFFHandle
*iff
;
414 struct FileFaceChunk fc
;
415 struct FileImageChunk ic1
, ic2
;
416 UBYTE
*argb1data
= NULL
, *argb2data
= NULL
;
417 UBYTE
*img1data
= NULL
, *img2data
= NULL
;
418 struct ColorRegister
*img1pal
= NULL
, *img2pal
= NULL
;
419 BOOL have_face
= FALSE
, have_imag1
= FALSE
, have_imag2
= FALSE
;
420 BOOL have_argb1
= FALSE
, have_argb2
= FALSE
;
422 LONG here
, extrasize
;
425 D(bug("ReadIcon35, stream %p\n", stream
));
427 here
= Seek((BPTR
)stream
, 0, OFFSET_CURRENT
);
428 D(bug("[%s] Extra data starts at %d\n", __func__
, here
));
429 Seek((BPTR
)stream
, 0, OFFSET_END
);
430 extrasize
= Seek((BPTR
)stream
, 0, OFFSET_CURRENT
);
431 D(bug("[%s] Extra data ends at %d\n", __func__
, extrasize
));
433 Seek((BPTR
)stream
, here
, OFFSET_BEGINNING
);
434 D(bug("[%s] .. %d bytes\n", __func__
, extrasize
));
436 /* No extra data? That's fine. */
437 if (extrasize
<= 0) {
438 D(bug("[%s] No extra data\n", __func__
));
442 if (IFFParseBase
== NULL
)
445 data
= AllocMemIcon(&icon
->ni_DiskObject
, extrasize
, MEMF_PUBLIC
,
450 if (Read((BPTR
)stream
, data
, extrasize
) != extrasize
) {
451 D(bug("[%s] Can't read extra data\n", __func__
));
455 icon
->ni_Extra
.Data
= data
;
456 icon
->ni_Extra
.Size
= extrasize
;
458 iffhook
.h_Entry
= (HOOKFUNC
)HookEntry
;
459 iffhook
.h_SubEntry
= (HOOKFUNC
)MyMemStreamHandler
;
460 iffhook
.h_Data
= (APTR
)IconBase
;
462 if ((iff
= AllocIFF()))
464 D(bug("ReadIcon35. AllocIFF okay\n"));
466 iff
->iff_Stream
= (IPTR
)&data
;
468 InitIFF(iff
, IFFF_RSEEK
, &iffhook
);
470 if (!OpenIFF(iff
, IFFF_READ
))
472 D(bug("ReadIcon35. OpenIFF okay\n"));
474 if (!StopChunks(iff
, stopchunks
, 4))
478 D(bug("ReadIcon35. StopChunks okay\n"));
480 while(!(error
= ParseIFF(iff
, IFFPARSE_SCAN
)))
482 struct ContextNode
*cn
;
484 cn
= CurrentChunk(iff
);
486 D(bug("inside ParseIFF loop\n"));
487 if ((cn
->cn_ID
== ID_FACE
) && (cn
->cn_Size
>= sizeof(struct FileFaceChunk
)))
489 D(bug("ReadIcon35. Found FACE chunk\n"));
490 if (ReadChunkBytes(iff
, &fc
, sizeof(fc
)) == sizeof(fc
))
495 else if (have_face
&& (cn
->cn_ID
== ID_IMAG
) && (cn
->cn_Size
>= sizeof(struct FileImageChunk
)))
497 D(bug("ReadIcon35. Found IMAG chunk\n"));
498 if (ReadChunkBytes(iff
, (have_imag1
? &ic2
: &ic1
), sizeof(ic1
)) == sizeof(ic1
))
502 if (ReadImage35(&icon
->ni_DiskObject
, iff
, &fc
, &ic2
, &img2data
, &img2pal
, IconBase
))
509 if (ReadImage35(&icon
->ni_DiskObject
, iff
, &fc
, &ic1
, &img1data
, &img1pal
, IconBase
))
516 } else if (cn
->cn_ID
== ID_ARGB
) {
517 D(bug("ReadIcon35. Found ARGB chunk\n"));
520 if (ReadARGB35(&icon
->ni_DiskObject
, iff
, &fc
, cn
->cn_Size
, &argb2data
, IconBase
))
527 if (ReadARGB35(&icon
->ni_DiskObject
, iff
, &fc
, cn
->cn_Size
, &argb1data
, IconBase
))
532 } else if (cn
->cn_ID
== ID_png
) {
534 LONG here
= data
- icon
->ni_Extra
.Data
;
535 D(bug("[%s] Found PNG image %d\n", __func__
, have_png
));
536 icon
->ni_Extra
.PNG
[have_png
].Offset
= here
;
537 icon
->ni_Extra
.PNG
[have_png
].Size
= cn
->cn_Size
;
539 D(bug("[%s] Ignoring PNG image %d\n", __func__
, have_png
));
543 D(bug("[%s] Unknown chunk ID 0x%08x\n", __func__
, cn
->cn_ID
));
546 } /* while(!ParseIFF(iff, IFFPARSE_SCAN)) */
548 } /* if (!StopChunks(iff, stopchunks, 4)) */
550 } /* if (!OpenIFF(iff, IFFF_READ)) */
554 } /* if ((iff = AllocIFF())) */
556 /* Only use the Width and Height fields of a FACE section
557 * if it also contains image data.
560 if (have_argb1
|| have_argb2
|| have_imag1
|| have_imag2
) {
561 icon
->ni_Face
.Width
= fc
.Width
+ 1;
562 icon
->ni_Face
.Height
= fc
.Height
+ 1;
564 //icon->icon35.flags = fc.Flags;
565 icon
->ni_Face
.Aspect
= fc
.Aspect
;
570 icon
->ni_Image
[0].ARGB
= (APTR
)argb1data
;
575 icon
->ni_Image
[1].ARGB
= (APTR
)argb2data
;
580 icon
->ni_Image
[0].ImageData
= img1data
;
581 icon
->ni_Image
[0].Palette
= img1pal
;
582 icon
->ni_Image
[0].Pens
= ic1
.NumColors
+ 1;
583 icon
->ni_Image
[0].TransparentColor
= ic1
.TransparentColor
;
585 if (icon
->ni_Image
[0].Pens
< 1 || icon
->ni_Image
[0].Pens
> 256)
590 icon
->ni_Image
[1].ImageData
= img2data
;
591 icon
->ni_Image
[1].TransparentColor
= ic2
.TransparentColor
;
595 icon
->ni_Image
[1].Palette
= img2pal
;
596 icon
->ni_Image
[1].Pens
= ic2
.NumColors
+ 1;
597 if (icon
->ni_Image
[1].Pens
< 1 || icon
->ni_Image
[0].Pens
> 256)
603 icon
->ni_Image
[1].Palette
= img1pal
;
604 icon
->ni_Image
[1].Pens
= ic1
.NumColors
+ 1;
612 /****************************************************************************************/
614 /* Encode35() based on ModifyIcon source by Dirk Stöcker */
616 /****************************************************************************************/
618 static UBYTE
*Encode35(struct DiskObject
*icon
, ULONG depth
, UBYTE
*dtype
, LONG
*dsize
, ULONG size
, CONST UBYTE
*src
, APTR IconBase
)
621 ULONG bitbuf
, numbits
;
623 LONG ressize
, numcopy
, numequal
;
625 buf
= AllocMemIcon(icon
, size
* 2, MEMF_PUBLIC
, IconBase
);
626 if (!buf
) return NULL
;
633 k
= 0; /* the really output pointer */
635 for(i
= 1; numequal
|| numcopy
;)
637 if(i
< size
&& numequal
&& (src
[i
-1] == src
[i
]))
641 else if(i
< size
&& numequal
*depth
<= 16)
643 numcopy
+= numequal
; numequal
= 1; ++i
;
647 /* care for end case, where it maybe better to join the two */
648 if(i
== size
&& numcopy
+ numequal
<= 128 && (numequal
-1)*depth
<= 8)
650 numcopy
+= numequal
; numequal
= 0;
655 if((j
= numcopy
) > 128) j
= 128;
657 bitbuf
= (bitbuf
<<8) | (j
-1);
662 if((j
= numequal
) > 128) j
= 128;
664 bitbuf
= (bitbuf
<<8) | (256-(j
-1));
670 buf
[ressize
++] = (bitbuf
>> numbits
);
675 bitbuf
= (bitbuf
<<depth
) | src
[k
++];
680 buf
[ressize
++] = (bitbuf
>> numbits
);
684 if(i
< size
&& !numcopy
&& !numequal
)
692 buf
[ressize
++] = bitbuf
<< (8-numbits
);
694 if(ressize
> size
) /* no RLE */
698 for(i
= 0; i
< size
; ++i
)
709 /****************************************************************************************/
711 static BOOL
WriteARGB35(struct IFFHandle
*iff
, struct NativeIcon
*icon
,
712 APTR ARGB
, struct IconBase
*IconBase
)
714 struct ARGB35_Header
{
715 ULONG ztype
; /* Always 1 */
716 ULONG zsize
; /* Compressed size, -1 */
717 UWORD resv
; /* Always 0 */
724 /* Assume uncompressible.. */
725 zsize
= size
= icon
->ni_Face
.Width
* icon
->ni_Face
.Height
* 4;
727 zdest
= AllocVec(zsize
, MEMF_ANY
);
731 err
= compress(zdest
, &zsize
, ARGB
, size
);
733 D(bug("%s: Can't compress %d ARGB bytes: %s\n", __func__
, size
, zError(err
)));
737 ahdr
.ztype
= AROS_LONG2BE(1);
738 ahdr
.zsize
= AROS_LONG2BE(zsize
- 1);
739 ahdr
.resv
= AROS_WORD2BE(0);
741 if (!PushChunk(iff
, ID_ICON
, ID_ARGB
, IFFSIZE_UNKNOWN
))
745 if ((WriteChunkBytes(iff
, &ahdr
, sizeof(ahdr
)) != sizeof(ahdr
)) ||
746 (WriteChunkBytes(iff
, zdest
, zsize
) != zsize
))
759 /****************************************************************************************/
761 static BOOL
WriteImage35(struct IFFHandle
*iff
, struct NativeIcon
*icon
,
762 struct NativeIconImage
*img
, struct IconBase
*IconBase
)
764 struct FileImageChunk ic
;
765 UBYTE
*imagedata
, *pal
= NULL
;
766 LONG imagesize
, palsize
= 0;
767 UBYTE imagepacked
, palpacked
= 0;
768 UBYTE imageflags
= 0;
773 pal
= Encode35(&icon
->ni_DiskObject
, 8, &palpacked
, &palsize
, img
->Pens
* 3, (APTR
)img
->Palette
, IconBase
);
774 if (!pal
) return FALSE
;
775 imageflags
|= IMAGE35F_HASPALETTE
;
778 if (img
->TransparentColor
>= 0)
779 imageflags
|= IMAGE35F_HASTRANSPARENTCOLOR
;
781 imagedata
= Encode35(&icon
->ni_DiskObject
, 8, &imagepacked
, &imagesize
,
782 icon
->ni_Face
.Width
* icon
->ni_Face
.Height
, img
->ImageData
, IconBase
);
789 ic
.TransparentColor
= (imageflags
& IMAGE35F_HASTRANSPARENTCOLOR
) ? 255 : img
->TransparentColor
;
790 ic
.NumColors
= img
->Pens
- 1;
791 ic
.Flags
= imageflags
;
792 ic
.ImageFormat
= imagepacked
;
793 ic
.PaletteFormat
= palpacked
;
795 ic
.NumImageBytes
[0] = (imagesize
- 1) / 256;
796 ic
.NumImageBytes
[1] = (imagesize
- 1) & 255;
797 ic
.NumPaletteBytes
[0] = (palsize
- 1) / 256;
798 ic
.NumPaletteBytes
[1] = (palsize
- 1) & 255;
800 if (!PushChunk(iff
, ID_ICON
, ID_IMAG
, IFFSIZE_UNKNOWN
))
804 if (WriteChunkBytes(iff
, &ic
, sizeof(ic
)) != sizeof(ic
))
811 if (WriteChunkBytes(iff
, imagedata
, imagesize
) != imagesize
)
819 if (WriteChunkBytes(iff
, pal
, palsize
) != palsize
)
828 } /* if (!PushChunk(iff, ID_ICON, ID_IMAG, IFFSIZE_UNKNOWN)) */
833 /****************************************************************************************/
835 BOOL
WriteIcon35(struct NativeIcon
*icon
, struct Hook
*streamhook
,
836 void *stream
, struct IconBase
*IconBase
)
838 struct IFFHandle
*iff
;
840 struct FileFaceChunk fc
;
843 D(bug("WriteIcon35\n"));
845 if (IFFParseBase
== NULL
)
847 D(bug("%s: IFFParseBase is NULL\n", __func__
));
851 if (!GetNativeIcon(&icon
->ni_DiskObject
, IconBase
))
853 D(bug("%s: No native icon data\n", __func__
));
857 /* If the extra imagery wasn't modified, just write it out. */
858 if (icon
->ni_Extra
.Size
!= 0) {
861 len
= FWrite((BPTR
)stream
, icon
->ni_Extra
.Data
, 1, icon
->ni_Extra
.Size
);
862 if (len
< 0 || (ULONG
)len
!= icon
->ni_Extra
.Size
)
868 D(bug("%s: Write Icon %p\n", __func__
, icon
));
869 D(bug("%s: n_Image[0].ImageData = %p\n", __func__
, icon
->ni_Image
[0].ImageData
));
870 D(bug("%s: n_Image[1].ImageData = %p\n", __func__
, icon
->ni_Image
[1].ImageData
));
871 D(bug("%s: n_Image[0].ARGB = %p\n", __func__
, icon
->ni_Image
[0].ARGB
));
872 D(bug("%s: n_Image[1].ARGB = %p\n", __func__
, icon
->ni_Image
[1].ARGB
));
874 if (icon
->ni_Image
[0].ImageData
== NULL
&& icon
->ni_Image
[0].ARGB
== NULL
)
876 D(bug("%s: No image data to write\n", __func__
));
880 iffhook
.h_Entry
= (HOOKFUNC
)HookEntry
;
881 iffhook
.h_SubEntry
= (HOOKFUNC
)MyDOSStreamHandler
;
882 iffhook
.h_Data
= (APTR
)IconBase
;
884 if ((iff
= AllocIFF()))
886 D(bug("WriteIcon35. AllocIFF okay\n"));
888 iff
->iff_Stream
= (IPTR
)stream
;
890 InitIFF(iff
, IFFF_RSEEK
, &iffhook
);
892 if (!OpenIFF(iff
, IFFF_WRITE
))
894 D(bug("WriteIcon35. OpenIFF okay\n"));
896 if (!PushChunk(iff
, ID_ICON
, ID_FORM
, IFFSIZE_UNKNOWN
))
898 D(bug("WriteIcon35. PushChunk(ID_ICON, ID_FORM) okay\n"));
900 if (!PushChunk(iff
, ID_ICON
, ID_FACE
, sizeof(struct FileFaceChunk
)))
904 D(bug("WriteIcon35. PushChunk(ID_ICON, ID_FACE) okay\n"));
906 fc
.Width
= icon
->ni_Face
.Width
- 1;
907 fc
.Height
= icon
->ni_Face
.Height
- 1;
908 fc
.Flags
= (icon
->ni_Frameless
) ? ICON35F_FRAMELESS
: 0;
909 fc
.Aspect
= icon
->ni_Face
.Aspect
;
911 cmapentries
= icon
->ni_Image
[0].Pens
;
913 if (icon
->ni_Image
[1].ImageData
&&
914 icon
->ni_Image
[1].Palette
)
916 if (icon
->ni_Image
[1].Pens
> cmapentries
)
918 cmapentries
= icon
->ni_Image
[1].Pens
;
922 cmapentries
= cmapentries
* 3 - 1;
924 fc
.MaxPaletteBytes
[0] = cmapentries
/ 256;
925 fc
.MaxPaletteBytes
[1] = cmapentries
& 255;
927 if (WriteChunkBytes(iff
, &fc
, sizeof(fc
)) == sizeof(fc
))
929 D(bug("WriteIcon35. WriteChunkBytes of FACE chunk ok.\n"));
933 if (icon
->ni_Image
[0].ImageData
)
935 if (WriteImage35(iff
, icon
, &icon
->ni_Image
[0], IconBase
))
937 D(bug("WriteIcon35. WriteImage35() of 1st image ok.\n"));
939 if (icon
->ni_Image
[1].ImageData
)
941 if (WriteImage35(iff
, icon
, &icon
->ni_Image
[1], IconBase
))
943 D(bug("WriteIcon35. WriteImage35() of 2nd image ok.\n"));
948 } /* if (icon->ni_Image[1].ImageData) */
954 } /* if (WriteImage35(iff, &icon, &icon->ni_Image[0], IconBase)) */
955 } /* if (icon->ni_Image[0].ImageData) */
957 if (icon
->ni_Image
[0].ARGB
)
959 if (WriteARGB35(iff
, icon
, &icon
->ni_Image
[0].ARGB
, IconBase
))
961 D(bug("WriteIcon35. WriteImage35() of 1st image ok.\n"));
962 if (icon
->ni_Image
[1].ARGB
)
964 if (WriteARGB35(iff
, icon
, &icon
->ni_Image
[1].ARGB
, IconBase
))
966 D(bug("WriteIcon35. WriteImage35() of 2nd image ok.\n"));
972 } /* if (WriteARGB35(iff, icon, &icon->ni_Image[0].ARGB, IconBase) */
973 } /* if (icon->ni_Image[0].ARGB) */
975 } /* if (WriteChunkBytes(iff, &fc, sizeof(fc)) == sizeof(fc)) */
981 } /* if (!PushChunk(iff, ID_ICON, ID_FACE, sizeof(struct FileFaceChunk))) */
983 if (icon
->ni_Extra
.PNG
[0].Size
&&
984 !PushChunk(iff
, ID_ICON
, ID_png
, IFFSIZE_UNKNOWN
)) {
985 WriteChunkBytes(iff
, icon
->ni_Extra
.Data
+ icon
->ni_Extra
.PNG
[0].Offset
, icon
->ni_Extra
.PNG
[0].Size
);
990 if (icon
->ni_Extra
.PNG
[1].Size
&&
991 !PushChunk(iff
, ID_ICON
, ID_png
, IFFSIZE_UNKNOWN
)) {
992 WriteChunkBytes(iff
, icon
->ni_Extra
.Data
+ icon
->ni_Extra
.PNG
[1].Offset
, icon
->ni_Extra
.PNG
[1].Size
);
999 } /* if (!PushChunk(iff, ID_ICON, ID_FORM, IFFSIZE_UNKNOWN)) */
1001 } /* if (!OpenIFF(iff, IFFF_READ)) */
1003 } /* if ((iff = AllocIFF())) */
1008 /****************************************************************************************/
1010 VOID
FreeIcon35(struct NativeIcon
*icon
, struct IconBase
*IconBase
)
1014 /****************************************************************************************/