2 Copyright © 1995-2013, The AROS Development Team. All rights reserved.
6 /****************************************************************************************/
8 #include <aros/debug.h>
10 #include "icon_intern.h"
12 /****************************************************************************************/
14 static STRPTR
RemoveToolType(STRPTR
*tt
)
32 /****************************************************************************************/
34 /* DecodeNI() based on ModifyIcon by Dirk Stöcker */
36 /****************************************************************************************/
38 static char *DecodeNI(struct DiskObject
*icon
, STRPTR
*tt
, UBYTE
*outbuffer
, LONG bits
, LONG entries
, WORD which
, BOOL is_palette
, APTR IconBase
)
40 LONG numbits
= 0, curentry
= 0, bitbuf
= 0, loop
= 0, mask
, val
;
42 STRPTR src
, dead
= NULL
;
47 dead
= RemoveToolType(tt
);
51 src
= ""; /* a dummy start */
53 mask
= (1 << bits
) - 1;
55 while(curentry
< entries
)
71 if(!src
|| src
[0] != 'I' || src
[1] != 'M' || src
[2] != '1' + which
|| src
[3] != '=')
73 return "NewIcon data truncated";
77 src
+= 4; numbits
= 0;
79 dead
= RemoveToolType(tt
);
86 return "NewIcon data invalid";
103 bitbuf
= (bitbuf
<< 7) + byte
;
106 while(numbits
>= bits
&& curentry
< entries
)
108 val
= (bitbuf
>> (numbits
- bits
)) & mask
;
120 /****************************************************************************************/
122 static BOOL
ReadImageNI(struct NativeIcon
*icon
, WORD which
, STRPTR
*tooltypes
,
123 struct IconBase
*IconBase
)
125 struct NativeIconImage
*img
;
127 LONG width
, height
, numcols
;
132 img
= which
? &icon
->ni_Image
[1] : &icon
->ni_Image
[0];
134 while((tt
= *tooltypes
))
136 if (tt
[0] == 'I' && tt
[1] == 'M' && tt
[2] == '1' + which
&& tt
[3] == '=')
143 if (!tt
) return FALSE
;
147 if (strlen(tt
) < 5) return FALSE
;
149 width
= tt
[1] - 0x21;
150 height
= tt
[2] - 0x21;
152 /* Selected image must have same size as normal image otherwise ignore it. */
153 if (which
&& ((width
!= icon
->ni_Face
.Width
) || (height
!= icon
->ni_Face
.Height
)))
158 numcols
= (((tt
[3] - 0x21) << 6) + (tt
[4] - 0x21));
159 transp
= (tt
[0] =='B') ? TRUE
: FALSE
;
161 size
= width
* height
;
164 AllocMemIcon(&icon
->ni_DiskObject
, size
, MEMF_PUBLIC
, IconBase
);
165 if (!img
->ImageData
) return FALSE
;
169 icon
->ni_Frameless
= TRUE
;
170 icon
->ni_Face
.Width
= width
;
171 icon
->ni_Face
.Height
= height
;
172 icon
->ni_Face
.Aspect
= PACK_ICON_ASPECT_RATIO(1,1);
175 size
= numcols
* sizeof(struct ColorRegister
);
177 AllocMemIcon(&icon
->ni_DiskObject
, size
, MEMF_PUBLIC
, IconBase
);
178 if (!img
->Palette
) return FALSE
;
180 img
->TransparentColor
= transp
? 0 : -1;
183 DecodeNI(&icon
->ni_DiskObject
, tooltypes
, (UBYTE
*)img
->Palette
, 8, img
->Pens
* sizeof(struct ColorRegister
), which
, TRUE
, IconBase
);
184 for (bits
= 1; (1 << bits
) < numcols
; bits
++);
185 DecodeNI(&icon
->ni_DiskObject
, tooltypes
, (UBYTE
*)img
->ImageData
, bits
, width
* height
, which
, FALSE
, IconBase
);
187 D(bug("%s: Read NewIcon image %d data from tooltypes\n", __func__
, which
+ 1));
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
->ni_Image
[0].ImageData
)
204 /* It's an 3.5 style icon. Ignore possible NewIcon */
208 tooltypes
= icon
->ni_DiskObject
.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
;
224 if (!ReadImageNI(icon
, 0, tooltypes
, IconBase
))
227 if (!ReadImageNI(icon
, 1, tooltypes
, IconBase
))
233 /****************************************************************************************/
235 BOOL
WriteIconNI(struct NativeIcon
*icon
, struct Hook
*streamhook
,
236 void *stream
, struct IconBase
*IconBase
)
238 D(bug("WriteIconNI\n"));
243 /****************************************************************************************/
245 VOID
FreeIconNI(struct NativeIcon
*icon
, struct IconBase
*IconBase
)
247 D(bug("FreeIconNI\n"));
249 /* Don't do anything */
252 /****************************************************************************************/