blob: a3297062ce051f52768435e4c401ba5297ecca4e [file] [log] [blame]
epoger@google.comec3ed6a2011-07-28 14:26:00 +00001/*
2 * Copyright 2006 The Android Open Source Project
3 *
4 * Use of this source code is governed by a BSD-style license that can be
5 * found in the LICENSE file.
6 */
7
scroggo@google.comdbf9f882013-08-21 15:01:48 +00008#include "SkColorPriv.h"
reed@android.com8a1c16f2008-12-17 15:59:43 +00009#include "SkImageDecoder.h"
10#include "SkStream.h"
halcanary67ec1f82014-06-27 11:36:20 -070011#include "SkStreamPriv.h"
reed@android.com8a1c16f2008-12-17 15:59:43 +000012#include "SkTypes.h"
13
14class SkICOImageDecoder : public SkImageDecoder {
15public:
16 SkICOImageDecoder();
rmistry@google.comd6176b02012-08-23 18:14:13 +000017
commit-bot@chromium.orga936e372013-03-14 14:42:18 +000018 virtual Format getFormat() const SK_OVERRIDE {
reed@android.com8a1c16f2008-12-17 15:59:43 +000019 return kICO_Format;
20 }
21
22protected:
scroggo2a120802014-10-22 12:07:00 -070023 virtual Result onDecode(SkStream* stream, SkBitmap* bm, Mode) SK_OVERRIDE;
reed@android.com8a1c16f2008-12-17 15:59:43 +000024
commit-bot@chromium.orga936e372013-03-14 14:42:18 +000025private:
26 typedef SkImageDecoder INHERITED;
27};
reed@google.com3bbee322011-08-05 16:13:09 +000028
reed@android.com8a1c16f2008-12-17 15:59:43 +000029/////////////////////////////////////////////////////////////////////////////////////////
30
31//read bytes starting from the begin-th index in the buffer
32//read in Intel order, and return an integer
33
34#define readByte(buffer,begin) buffer[begin]
35#define read2Bytes(buffer,begin) buffer[begin]+(buffer[begin+1]<<8)
36#define read4Bytes(buffer,begin) buffer[begin]+(buffer[begin+1]<<8)+(buffer[begin+2]<<16)+(buffer[begin+3]<<24)
37
38/////////////////////////////////////////////////////////////////////////////////////////
39
reed@android.com8a1c16f2008-12-17 15:59:43 +000040SkICOImageDecoder::SkICOImageDecoder()
41{
42}
43
44//helpers - my function pointer will call one of these, depending on the bitCount, each time through the inner loop
rmistry@google.comd6176b02012-08-23 18:14:13 +000045static void editPixelBit1(const int pixelNo, const unsigned char* buf,
46 const int xorOffset, int& x, int y, const int w,
reed@android.com8a1c16f2008-12-17 15:59:43 +000047 SkBitmap* bm, int alphaByte, int m, int shift, SkPMColor* colors);
rmistry@google.comd6176b02012-08-23 18:14:13 +000048static void editPixelBit4(const int pixelNo, const unsigned char* buf,
49 const int xorOffset, int& x, int y, const int w,
reed@android.com8a1c16f2008-12-17 15:59:43 +000050 SkBitmap* bm, int alphaByte, int m, int shift, SkPMColor* colors);
rmistry@google.comd6176b02012-08-23 18:14:13 +000051static void editPixelBit8(const int pixelNo, const unsigned char* buf,
52 const int xorOffset, int& x, int y, const int w,
reed@android.com8a1c16f2008-12-17 15:59:43 +000053 SkBitmap* bm, int alphaByte, int m, int shift, SkPMColor* colors);
rmistry@google.comd6176b02012-08-23 18:14:13 +000054static void editPixelBit24(const int pixelNo, const unsigned char* buf,
55 const int xorOffset, int& x, int y, const int w,
reed@android.com8a1c16f2008-12-17 15:59:43 +000056 SkBitmap* bm, int alphaByte, int m, int shift, SkPMColor* colors);
rmistry@google.comd6176b02012-08-23 18:14:13 +000057static void editPixelBit32(const int pixelNo, const unsigned char* buf,
58 const int xorOffset, int& x, int y, const int w,
reed@android.com8a1c16f2008-12-17 15:59:43 +000059 SkBitmap* bm, int alphaByte, int m, int shift, SkPMColor* colors);
rmistry@google.comd6176b02012-08-23 18:14:13 +000060
61
reed@android.com8a1c16f2008-12-17 15:59:43 +000062static int calculateRowBytesFor8888(int w, int bitCount)
63{
64 // Default rowBytes is w << 2 for kARGB_8888
65 // In the case of a 4 bit image with an odd width, we need to add some
66 // so we can go off the end of the drawn bitmap.
67 // Add 4 to ensure that it is still a multiple of 4.
68 if (4 == bitCount && (w & 0x1)) {
69 return (w + 1) << 2;
70 }
71 // Otherwise return 0, which will allow it to be calculated automatically.
72 return 0;
73}
74
scroggo2a120802014-10-22 12:07:00 -070075SkImageDecoder::Result SkICOImageDecoder::onDecode(SkStream* stream, SkBitmap* bm, Mode mode)
reed@android.com8a1c16f2008-12-17 15:59:43 +000076{
scroggo@google.comdbf9f882013-08-21 15:01:48 +000077 SkAutoMalloc autoMal;
halcanary67ec1f82014-06-27 11:36:20 -070078 const size_t length = SkCopyStreamToStorage(&autoMal, stream);
scroggo@google.comdbf9f882013-08-21 15:01:48 +000079 if (0 == length) {
scroggo2a120802014-10-22 12:07:00 -070080 return kFailure;
reed@android.com8a1c16f2008-12-17 15:59:43 +000081 }
rmistry@google.comd6176b02012-08-23 18:14:13 +000082
scroggo@google.comdbf9f882013-08-21 15:01:48 +000083 unsigned char* buf = (unsigned char*)autoMal.get();
84
reed@android.com8a1c16f2008-12-17 15:59:43 +000085 //these should always be the same - should i use for error checking? - what about files that have some
86 //incorrect values, but still decode properly?
87 int reserved = read2Bytes(buf, 0); // 0
88 int type = read2Bytes(buf, 2); // 1
scroggo2a120802014-10-22 12:07:00 -070089 if (reserved != 0 || type != 1) {
90 return kFailure;
91 }
92
reed@android.com8a1c16f2008-12-17 15:59:43 +000093 int count = read2Bytes(buf, 4);
rmistry@google.comd6176b02012-08-23 18:14:13 +000094
reed@android.com8a1c16f2008-12-17 15:59:43 +000095 //need to at least have enough space to hold the initial table of info
scroggo2a120802014-10-22 12:07:00 -070096 if (length < (size_t)(6 + count*16)) {
97 return kFailure;
98 }
rmistry@google.comd6176b02012-08-23 18:14:13 +000099
reed@android.com8a1c16f2008-12-17 15:59:43 +0000100 //skip ahead to the correct header
101 //commented out lines are not used, but if i switch to other read method, need to know how many to skip
102 //otherwise, they could be used for error checking
reed2d73d802014-12-22 07:37:29 -0800103 int w = readByte(buf, 6);
104 int h = readByte(buf, 7);
105 int colorCount = readByte(buf, 8);
reed@android.com8a1c16f2008-12-17 15:59:43 +0000106 //int reservedToo = readByte(buf, 9 + choice*16); //0
107 //int planes = read2Bytes(buf, 10 + choice*16); //1 - but often 0
108 //int fakeBitCount = read2Bytes(buf, 12 + choice*16); //should be real - usually 0
reed2d73d802014-12-22 07:37:29 -0800109 const size_t size = read4Bytes(buf, 14); //matters?
110 const size_t offset = read4Bytes(buf, 18);
djsollen97b49472014-08-26 08:31:24 -0700111 // promote the sum to 64-bits to avoid overflow
scroggob61e2062014-11-10 13:12:25 -0800112 if (offset > length || size > length || ((uint64_t)offset + size) > length) {
scroggo2a120802014-10-22 12:07:00 -0700113 return kFailure;
scroggo57ad4932014-07-09 15:04:20 -0700114 }
scroggo@google.com468142b2013-07-09 15:48:24 +0000115
116 // Check to see if this is a PNG image inside the ICO
117 {
118 SkMemoryStream subStream(buf + offset, size, false);
119 SkAutoTDelete<SkImageDecoder> otherDecoder(SkImageDecoder::Factory(&subStream));
120 if (otherDecoder.get() != NULL) {
djsollen6a9c7b12014-08-26 11:35:14 -0700121 // Disallow nesting ICO files within one another
scroggo2a120802014-10-22 12:07:00 -0700122 // FIXME: Can ICO files contain other formats besides PNG?
djsollen6a9c7b12014-08-26 11:35:14 -0700123 if (otherDecoder->getFormat() == SkImageDecoder::kICO_Format) {
scroggo2a120802014-10-22 12:07:00 -0700124 return kFailure;
djsollen6a9c7b12014-08-26 11:35:14 -0700125 }
scroggo@google.com468142b2013-07-09 15:48:24 +0000126 // Set fields on the other decoder to be the same as this one.
127 this->copyFieldsToOther(otherDecoder.get());
scroggo2a120802014-10-22 12:07:00 -0700128 const Result result = otherDecoder->decode(&subStream, bm, this->getDefaultPref(),
129 mode);
130 // FIXME: Should we just return result here? Is it possible that data that looked like
131 // a subimage was not, but was actually a valid ICO?
132 if (result != kFailure) {
133 return result;
scroggo@google.com468142b2013-07-09 15:48:24 +0000134 }
135 }
136 }
137
reed@android.com8a1c16f2008-12-17 15:59:43 +0000138 //int infoSize = read4Bytes(buf, offset); //40
139 //int width = read4Bytes(buf, offset+4); //should == w
140 //int height = read4Bytes(buf, offset+8); //should == 2*h
141 //int planesToo = read2Bytes(buf, offset+12); //should == 1 (does it?)
142 int bitCount = read2Bytes(buf, offset+14);
rmistry@google.comd6176b02012-08-23 18:14:13 +0000143
144 void (*placePixel)(const int pixelNo, const unsigned char* buf,
145 const int xorOffset, int& x, int y, const int w,
reed@android.com8a1c16f2008-12-17 15:59:43 +0000146 SkBitmap* bm, int alphaByte, int m, int shift, SkPMColor* colors) = NULL;
147 switch (bitCount)
148 {
149 case 1:
150 placePixel = &editPixelBit1;
151 colorCount = 2;
152 break;
153 case 4:
154 placePixel = &editPixelBit4;
155 colorCount = 16;
156 break;
157 case 8:
158 placePixel = &editPixelBit8;
159 colorCount = 256;
160 break;
161 case 24:
162 placePixel = &editPixelBit24;
163 colorCount = 0;
164 break;
165 case 32:
166 placePixel = &editPixelBit32;
167 colorCount = 0;
168 break;
169 default:
170 SkDEBUGF(("Decoding %ibpp is unimplemented\n", bitCount));
scroggo2a120802014-10-22 12:07:00 -0700171 return kFailure;
reed@android.com8a1c16f2008-12-17 15:59:43 +0000172 }
rmistry@google.comd6176b02012-08-23 18:14:13 +0000173
reed@android.com8a1c16f2008-12-17 15:59:43 +0000174 //these should all be zero, but perhaps are not - need to check
175 //int compression = read4Bytes(buf, offset+16); //0
176 //int imageSize = read4Bytes(buf, offset+20); //0 - sometimes has a value
177 //int xPixels = read4Bytes(buf, offset+24); //0
178 //int yPixels = read4Bytes(buf, offset+28); //0
179 //int colorsUsed = read4Bytes(buf, offset+32) //0 - might have an actual value though
180 //int colorsImportant = read4Bytes(buf, offset+36); //0
rmistry@google.comd6176b02012-08-23 18:14:13 +0000181
bsalomon98806072014-12-12 15:11:17 -0800182 int begin = SkToInt(offset + 40);
reed@android.com8a1c16f2008-12-17 15:59:43 +0000183 //this array represents the colortable
184 //if i allow other types of bitmaps, it may actually be used as a part of the bitmap
185 SkPMColor* colors = NULL;
186 int blue, green, red;
rmistry@google.comd6176b02012-08-23 18:14:13 +0000187 if (colorCount)
reed@android.com8a1c16f2008-12-17 15:59:43 +0000188 {
189 colors = new SkPMColor[colorCount];
190 for (int j = 0; j < colorCount; j++)
191 {
192 //should this be a function - maybe a #define?
193 blue = readByte(buf, begin + 4*j);
194 green = readByte(buf, begin + 4*j + 1);
195 red = readByte(buf, begin + 4*j + 2);
196 colors[j] = SkPackARGB32(0xFF, red & 0xFF, green & 0xFF, blue & 0xFF);
197 }
198 }
199 int bitWidth = w*bitCount;
200 int test = bitWidth & 0x1F;
201 int mask = -(((test >> 4) | (test >> 3) | (test >> 2) | (test >> 1) | test) & 0x1); //either 0xFFFFFFFF or 0
202 int lineBitWidth = (bitWidth & 0xFFFFFFE0) + (0x20 & mask);
203 int lineWidth = lineBitWidth/bitCount;
rmistry@google.comd6176b02012-08-23 18:14:13 +0000204
reed@android.com8a1c16f2008-12-17 15:59:43 +0000205 int xorOffset = begin + colorCount*4; //beginning of the color bitmap
206 //other read method means we will just be here already
207 int andOffset = xorOffset + ((lineWidth*h*bitCount) >> 3);
rmistry@google.comd6176b02012-08-23 18:14:13 +0000208
reed@android.com8a1c16f2008-12-17 15:59:43 +0000209 /*int */test = w & 0x1F; //the low 5 bits - we are rounding up to the next 32 (2^5)
210 /*int */mask = -(((test >> 4) | (test >> 3) | (test >> 2) | (test >> 1) | test) & 0x1); //either 0xFFFFFFFF or 0
211 int andLineWidth = (w & 0xFFFFFFE0) + (0x20 & mask);
212 //if we allow different Configs, everything is the same til here
213 //change the config, and use different address getter, and place index vs color, and add the color table
214 //FIXME: what is the tradeoff in size?
215 //if the andbitmap (mask) is all zeroes, then we can easily do an index bitmap
216 //however, with small images with large colortables, maybe it's better to still do argb_8888
217
reed6c225732014-06-09 19:52:07 -0700218 bm->setInfo(SkImageInfo::MakeN32Premul(w, h), calculateRowBytesFor8888(w, bitCount));
scroggo@google.combc69ce92013-07-09 15:45:14 +0000219
reed@android.com8a1c16f2008-12-17 15:59:43 +0000220 if (SkImageDecoder::kDecodeBounds_Mode == mode) {
221 delete[] colors;
scroggo2a120802014-10-22 12:07:00 -0700222 return kSuccess;
reed@android.com8a1c16f2008-12-17 15:59:43 +0000223 }
224
225 if (!this->allocPixelRef(bm, NULL))
226 {
227 delete[] colors;
scroggo2a120802014-10-22 12:07:00 -0700228 return kFailure;
reed@android.com8a1c16f2008-12-17 15:59:43 +0000229 }
rmistry@google.comd6176b02012-08-23 18:14:13 +0000230
reed@android.com8a1c16f2008-12-17 15:59:43 +0000231 SkAutoLockPixels alp(*bm);
232
233 for (int y = 0; y < h; y++)
234 {
235 for (int x = 0; x < w; x++)
236 {
237 //U32* address = bm->getAddr32(x, y);
rmistry@google.comd6176b02012-08-23 18:14:13 +0000238
reed@android.com8a1c16f2008-12-17 15:59:43 +0000239 //check the alpha bit first, but pass it along to the function to figure out how to deal with it
240 int andPixelNo = andLineWidth*(h-y-1)+x;
241 //only need to get a new alphaByte when x %8 == 0
242 //but that introduces an if and a mod - probably much slower
243 //that's ok, it's just a read of an array, not a stream
244 int alphaByte = readByte(buf, andOffset + (andPixelNo >> 3));
245 int shift = 7 - (andPixelNo & 0x7);
246 int m = 1 << shift;
rmistry@google.comd6176b02012-08-23 18:14:13 +0000247
reed@android.com8a1c16f2008-12-17 15:59:43 +0000248 int pixelNo = lineWidth*(h-y-1)+x;
249 placePixel(pixelNo, buf, xorOffset, x, y, w, bm, alphaByte, m, shift, colors);
250
251 }
252 }
253
254 delete [] colors;
255 //ensure we haven't read off the end?
256 //of course this doesn't help us if the andOffset was a lie...
257 //return andOffset + (andLineWidth >> 3) <= length;
scroggo2a120802014-10-22 12:07:00 -0700258 return kSuccess;
reed@android.com8a1c16f2008-12-17 15:59:43 +0000259} //onDecode
260
261//function to place the pixel, determined by the bitCount
rmistry@google.comd6176b02012-08-23 18:14:13 +0000262static void editPixelBit1(const int pixelNo, const unsigned char* buf,
263 const int xorOffset, int& x, int y, const int w,
reed@android.com8a1c16f2008-12-17 15:59:43 +0000264 SkBitmap* bm, int alphaByte, int m, int shift, SkPMColor* colors)
265{
266 // note that this should be the same as/similar to the AND bitmap
267 SkPMColor* address = bm->getAddr32(x,y);
268 int byte = readByte(buf, xorOffset + (pixelNo >> 3));
269 int colorBit;
270 int alphaBit;
rmistry@google.comd6176b02012-08-23 18:14:13 +0000271 // Read all of the bits in this byte.
reed@android.com8a1c16f2008-12-17 15:59:43 +0000272 int i = x + 8;
rmistry@google.comd6176b02012-08-23 18:14:13 +0000273 // Pin to the width so we do not write outside the bounds of
reed@android.com8a1c16f2008-12-17 15:59:43 +0000274 // our color table.
275 i = i > w ? w : i;
276 // While loop to check all 8 bits individually.
277 while (x < i)
278 {
rmistry@google.comd6176b02012-08-23 18:14:13 +0000279
reed@android.com8a1c16f2008-12-17 15:59:43 +0000280 colorBit = (byte & m) >> shift;
281 alphaBit = (alphaByte & m) >> shift;
282 *address = (alphaBit-1)&(colors[colorBit]);
283 x++;
284 // setup for the next pixel
285 address = address + 1;
286 m = m >> 1;
287 shift -= 1;
288 }
289 x--;
290}
rmistry@google.comd6176b02012-08-23 18:14:13 +0000291static void editPixelBit4(const int pixelNo, const unsigned char* buf,
292 const int xorOffset, int& x, int y, const int w,
reed@android.com8a1c16f2008-12-17 15:59:43 +0000293 SkBitmap* bm, int alphaByte, int m, int shift, SkPMColor* colors)
294{
295 SkPMColor* address = bm->getAddr32(x, y);
296 int byte = readByte(buf, xorOffset + (pixelNo >> 1));
297 int pixel = (byte >> 4) & 0xF;
298 int alphaBit = (alphaByte & m) >> shift;
299 *address = (alphaBit-1)&(colors[pixel]);
300 x++;
301 //if w is odd, x may be the same as w, which means we are writing to an unused portion of the bitmap
302 //but that's okay, since i've added an extra rowByte for just this purpose
303 address = address + 1;
304 pixel = byte & 0xF;
305 m = m >> 1;
306 alphaBit = (alphaByte & m) >> (shift-1);
307 //speed up trick here
308 *address = (alphaBit-1)&(colors[pixel]);
309}
310
rmistry@google.comd6176b02012-08-23 18:14:13 +0000311static void editPixelBit8(const int pixelNo, const unsigned char* buf,
312 const int xorOffset, int& x, int y, const int w,
reed@android.com8a1c16f2008-12-17 15:59:43 +0000313 SkBitmap* bm, int alphaByte, int m, int shift, SkPMColor* colors)
314{
315 SkPMColor* address = bm->getAddr32(x, y);
316 int pixel = readByte(buf, xorOffset + pixelNo);
317 int alphaBit = (alphaByte & m) >> shift;
318 *address = (alphaBit-1)&(colors[pixel]);
rmistry@google.comd6176b02012-08-23 18:14:13 +0000319}
reed@android.com8a1c16f2008-12-17 15:59:43 +0000320
rmistry@google.comd6176b02012-08-23 18:14:13 +0000321static void editPixelBit24(const int pixelNo, const unsigned char* buf,
322 const int xorOffset, int& x, int y, const int w,
reed@android.com8a1c16f2008-12-17 15:59:43 +0000323 SkBitmap* bm, int alphaByte, int m, int shift, SkPMColor* colors)
324{
325 SkPMColor* address = bm->getAddr32(x, y);
326 int blue = readByte(buf, xorOffset + 3*pixelNo);
327 int green = readByte(buf, xorOffset + 3*pixelNo + 1);
328 int red = readByte(buf, xorOffset + 3*pixelNo + 2);
329 int alphaBit = (alphaByte & m) >> shift;
330 //alphaBit == 1 => alpha = 0
331 int alpha = (alphaBit-1) & 0xFF;
rmistry@google.comd6176b02012-08-23 18:14:13 +0000332 *address = SkPreMultiplyARGB(alpha, red, green, blue);
reed@android.com8a1c16f2008-12-17 15:59:43 +0000333}
334
rmistry@google.comd6176b02012-08-23 18:14:13 +0000335static void editPixelBit32(const int pixelNo, const unsigned char* buf,
336 const int xorOffset, int& x, int y, const int w,
reed@android.com8a1c16f2008-12-17 15:59:43 +0000337 SkBitmap* bm, int alphaByte, int m, int shift, SkPMColor* colors)
338{
339 SkPMColor* address = bm->getAddr32(x, y);
340 int blue = readByte(buf, xorOffset + 4*pixelNo);
341 int green = readByte(buf, xorOffset + 4*pixelNo + 1);
342 int red = readByte(buf, xorOffset + 4*pixelNo + 2);
343 int alphaBit = (alphaByte & m) >> shift;
reed@google.com3bbee322011-08-05 16:13:09 +0000344#if 1 // don't trust the alphaBit for 32bit images <mrr>
345 alphaBit = 0;
346#endif
reed@android.com8a1c16f2008-12-17 15:59:43 +0000347 int alpha = readByte(buf, xorOffset + 4*pixelNo + 3) & ((alphaBit-1)&0xFF);
reed@android.comca776972010-04-13 14:03:27 +0000348 *address = SkPreMultiplyARGB(alpha, red, green, blue);
reed@android.com8a1c16f2008-12-17 15:59:43 +0000349}
350
robertphillips@google.comec51cb82012-03-23 18:13:47 +0000351///////////////////////////////////////////////////////////////////////////////
352DEFINE_DECODER_CREATOR(ICOImageDecoder);
reed@android.com00bf85a2009-01-22 13:04:56 +0000353/////////////////////////////////////////////////////////////////////////////////////////
354
scroggo@google.comb5571b32013-09-25 21:34:24 +0000355static bool is_ico(SkStreamRewindable* stream) {
reed@android.com00bf85a2009-01-22 13:04:56 +0000356 // Check to see if the first four bytes are 0,0,1,0
357 // FIXME: Is that required and sufficient?
scroggob752f9f2014-10-24 06:49:57 -0700358 char buf[4];
359 if (stream->read((void*)buf, 4) != 4) {
scroggo@google.com39edf4c2013-04-25 17:33:51 +0000360 return false;
reed@android.com00bf85a2009-01-22 13:04:56 +0000361 }
scroggob752f9f2014-10-24 06:49:57 -0700362 int reserved = read2Bytes(buf, 0);
363 int type = read2Bytes(buf, 2);
364 return 0 == reserved && 1 == type;
scroggo@google.com39edf4c2013-04-25 17:33:51 +0000365}
366
scroggo@google.comb5571b32013-09-25 21:34:24 +0000367static SkImageDecoder* sk_libico_dfactory(SkStreamRewindable* stream) {
scroggo@google.com39edf4c2013-04-25 17:33:51 +0000368 if (is_ico(stream)) {
369 return SkNEW(SkICOImageDecoder);
370 }
371 return NULL;
reed@android.com00bf85a2009-01-22 13:04:56 +0000372}
373
mtklein@google.combd6343b2013-09-04 17:20:18 +0000374static SkImageDecoder_DecodeReg gReg(sk_libico_dfactory);
scroggo@google.com39edf4c2013-04-25 17:33:51 +0000375
scroggo@google.comb5571b32013-09-25 21:34:24 +0000376static SkImageDecoder::Format get_format_ico(SkStreamRewindable* stream) {
scroggo@google.com39edf4c2013-04-25 17:33:51 +0000377 if (is_ico(stream)) {
378 return SkImageDecoder::kICO_Format;
379 }
380 return SkImageDecoder::kUnknown_Format;
381}
382
mtklein@google.combd6343b2013-09-04 17:20:18 +0000383static SkImageDecoder_FormatReg gFormatReg(get_format_ico);