Updated PCI IDs to latest snapshot.
[tangerine.git] / workbench / libs / icon / diskobjNIio.c
blobc5d864f171ddc0e316a770db4aa93a8b7670f958
1 /*
2 Copyright © 1995-2003, The AROS Development Team. All rights reserved.
3 $Id$
4 */
6 /****************************************************************************************/
8 #include "icon_intern.h"
10 # define DEBUG 0
11 # include <aros/debug.h>
13 /****************************************************************************************/
15 static void RemoveToolType(STRPTR *tt)
17 if (tt[0])
19 FreeVec(tt[0]);
21 for(;;)
23 tt[0] = tt[1];
24 if (!tt[0]) break;
26 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;
40 UBYTE byte;
41 STRPTR src;
43 if(is_palette)
45 src = *tt + 9;
46 RemoveToolType(tt);
48 else
50 src = ""; /* a dummy start */
52 mask = (1 << bits) - 1;
54 while(curentry < entries)
56 if(loop)
58 byte = 0;
59 --loop;
61 else
63 if(!*src)
65 src = *tt;
66 if(!src || src[0] != 'I' || src[1] != 'M' || src[2] != '1' + which || src[3] != '=')
68 return "NewIcon data truncated";
70 else
72 src += 4; numbits = 0;
74 RemoveToolType(tt);
77 byte = *(src++);
79 if(!byte)
81 return "NewIcon data invalid";
83 else if(byte < 0xA0)
85 byte -= 0x20;
87 else if(byte < 0xD1)
89 byte -= 0x51;
91 else
93 loop = byte - 0xD1;
94 byte = 0;
98 bitbuf = (bitbuf << 7) + byte;
99 numbits += 7;
101 while(numbits >= bits && curentry < entries)
103 val = (bitbuf >> (numbits - bits)) & mask;
105 *outbuffer++ = val;
107 numbits -= bits;
108 curentry++;
112 return 0;
115 /****************************************************************************************/
117 static BOOL ReadImageNI(struct NativeIcon *icon, WORD which, STRPTR *tooltypes,
118 struct IconBase *IconBase)
120 struct Image35 *img;
121 STRPTR tt;
122 LONG width, height, numcols;
123 ULONG size;
124 BOOL transp;
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] == '=')
132 break;
134 tooltypes++;
137 if (!tt) return FALSE;
139 tt += 4;
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)))
149 return FALSE;
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;
162 if (!which)
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)) :
172 NULL;
173 img->flags = transp ? (IMAGE35F_HASPALETTE | IMAGE35F_HASTRANSPARENTCOLOR) :
174 IMAGE35F_HASPALETTE;
175 img->transparentcolor = 0;
176 img->numcolors = numcols;
178 img->depth = 1;
179 while((1L << img->depth) < img->numcolors)
181 img->depth++;
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);
189 return TRUE;
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 */
205 return TRUE;
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)
214 break;
217 tooltypes++;
220 if (!tt) return TRUE;
222 RemoveToolType(tooltypes);
224 ReadImageNI(icon, 0, tooltypes, IconBase);
225 ReadImageNI(icon, 1, tooltypes, IconBase);
227 return TRUE;
230 /****************************************************************************************/
232 BOOL WriteIconNI(struct NativeIcon *icon, struct Hook *streamhook,
233 void *stream, struct IconBase *IconBase)
235 D(bug("WriteIconNI\n"));
237 return TRUE;
240 /****************************************************************************************/
242 VOID FreeIconNI(struct NativeIcon *icon, struct IconBase *IconBase)
244 D(bug("FreeIconNI\n"));
246 /* Don't do anything */
249 /****************************************************************************************/