2 Copyright © 1995-2003, The AROS Development Team. All rights reserved.
6 /****************************************************************************************/
8 #include "icon_intern.h"
11 # include <aros/debug.h>
13 /****************************************************************************************/
15 static void RemoveToolType(STRPTR
*tt
)
31 /****************************************************************************************/
33 /* Decode3NI() based on ModifyIcon by Dirk Stöcker */
35 /****************************************************************************************/
37 static char *DecodeNI(STRPTR
*tt
, UBYTE
*outbuffer
, LONG bits
, LONG entries
, WORD which
, BOOL is_palette
)
39 LONG numbits
= 0, curentry
= 0, bitbuf
= 0, loop
= 0, mask
, val
;
50 src
= ""; /* a dummy start */
52 mask
= (1 << bits
) - 1;
54 while(curentry
< entries
)
66 if(!src
|| src
[0] != 'I' || src
[1] != 'M' || src
[2] != '1' + which
|| src
[3] != '=')
68 return "NewIcon data truncated";
72 src
+= 4; numbits
= 0;
81 return "NewIcon data invalid";
98 bitbuf
= (bitbuf
<< 7) + byte
;
101 while(numbits
>= bits
&& curentry
< entries
)
103 val
= (bitbuf
>> (numbits
- bits
)) & mask
;
115 /****************************************************************************************/
117 static BOOL
ReadImageNI(struct NativeIcon
*icon
, WORD which
, STRPTR
*tooltypes
,
118 struct IconBase
*IconBase
)
122 LONG width
, height
, numcols
;
126 img
= which
? &icon
->icon35
.img2
: &icon
->icon35
.img1
;
128 while((tt
= *tooltypes
))
130 if (tt
[0] == 'I' && tt
[1] == 'M' && tt
[2] == '1' + which
&& tt
[3] == '=')
137 if (!tt
) return FALSE
;
141 if (strlen(tt
) < 5) return FALSE
;
143 width
= tt
[1] - 0x21;
144 height
= tt
[2] - 0x21;
146 /* Selected image must have same size as normal image otherwise ignore it. */
147 if (which
&& ((width
!= icon
->icon35
.width
) || (height
!= icon
->icon35
.height
)))
152 numcols
= (((tt
[3] - 0x21) << 6) + (tt
[4] - 0x21));
153 transp
= (tt
[0] =='B') ? TRUE
: FALSE
;
155 size
= width
* height
;
156 size
+= numcols
* sizeof(struct ColorRegister
);
157 if (transp
) size
+= RASSIZE(width
, height
);
159 img
->imagedata
= AllocVec(size
, MEMF_ANY
);
160 if (!img
->imagedata
) return FALSE
;
164 icon
->icon35
.width
= width
;
165 icon
->icon35
.height
= height
;
166 icon
->icon35
.flags
= ICON35F_FRAMELESS
;
167 icon
->icon35
.aspect
= 0x1111; /* ?? */
170 img
->palette
= img
->imagedata
+ width
* height
;
171 img
->mask
= transp
? (img
->palette
+ numcols
* sizeof(struct ColorRegister
)) :
173 img
->flags
= transp
? (IMAGE35F_HASPALETTE
| IMAGE35F_HASTRANSPARENTCOLOR
) :
175 img
->transparentcolor
= 0;
176 img
->numcolors
= numcols
;
179 while((1L << img
->depth
) < img
->numcolors
)
184 DecodeNI(tooltypes
, img
->palette
, 8, img
->numcolors
* sizeof(struct ColorRegister
), which
, TRUE
);
185 DecodeNI(tooltypes
, img
->imagedata
, img
->depth
, width
* height
, which
, FALSE
);
187 if (transp
) MakeMask35(img
->imagedata
, img
->mask
, 0, width
, height
);
193 /****************************************************************************************/
195 BOOL
ReadIconNI(struct NativeIcon
*icon
, struct Hook
*streamhook
,
196 void *stream
, struct IconBase
*IconBase
)
198 STRPTR
*tooltypes
, tt
;
200 D(bug("ReadIconNI\n"));
202 if (icon
->icon35
.img1
.imagedata
)
204 /* It's an 3.5 style icon. Ignore possible NewIcon */
208 tooltypes
= icon
->dobj
.do_ToolTypes
;
209 if ( ! tooltypes
) return TRUE
;
210 while ((tt
= *tooltypes
))
212 if (strcmp(tt
, "*** DON'T EDIT THE FOLLOWING LINES!! ***") == 0)
220 if (!tt
) return TRUE
;
222 RemoveToolType(tooltypes
);
224 ReadImageNI(icon
, 0, tooltypes
, IconBase
);
225 ReadImageNI(icon
, 1, tooltypes
, IconBase
);
230 /****************************************************************************************/
232 BOOL
WriteIconNI(struct NativeIcon
*icon
, struct Hook
*streamhook
,
233 void *stream
, struct IconBase
*IconBase
)
235 D(bug("WriteIconNI\n"));
240 /****************************************************************************************/
242 VOID
FreeIconNI(struct NativeIcon
*icon
, struct IconBase
*IconBase
)
244 D(bug("FreeIconNI\n"));
246 /* Don't do anything */
249 /****************************************************************************************/