OLD | NEW |
1 /* | 1 /* |
2 * Copyright 2006 The Android Open Source Project | 2 * Copyright 2006 The Android Open Source Project |
3 * | 3 * |
4 * Use of this source code is governed by a BSD-style license that can be | 4 * Use of this source code is governed by a BSD-style license that can be |
5 * found in the LICENSE file. | 5 * found in the LICENSE file. |
6 */ | 6 */ |
7 | 7 |
8 #include "SkColorPriv.h" | 8 #include "SkColorPriv.h" |
9 #include "SkImageDecoder.h" | 9 #include "SkImageDecoder.h" |
10 #include "SkStream.h" | 10 #include "SkStream.h" |
(...skipping 79 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
90 return kFailure; | 90 return kFailure; |
91 } | 91 } |
92 | 92 |
93 int count = read2Bytes(buf, 4); | 93 int count = read2Bytes(buf, 4); |
94 | 94 |
95 //need to at least have enough space to hold the initial table of info | 95 //need to at least have enough space to hold the initial table of info |
96 if (length < (size_t)(6 + count*16)) { | 96 if (length < (size_t)(6 + count*16)) { |
97 return kFailure; | 97 return kFailure; |
98 } | 98 } |
99 | 99 |
100 #ifdef SK_SUPPORT_LEGACY_IMAGEDECODER_CHOOSER | |
101 int choice; | |
102 Chooser* chooser = this->getChooser(); | |
103 //FIXME:if no chooser, consider providing the largest color image | |
104 //what are the odds that the largest image would be monochrome? | |
105 if (NULL == chooser) { | |
106 choice = 0; | |
107 } else { | |
108 chooser->begin(count); | |
109 for (int i = 0; i < count; i++) | |
110 { | |
111 //need to find out the config, width, and height from the stream | |
112 int width = readByte(buf, 6 + i*16); | |
113 int height = readByte(buf, 7 + i*16); | |
114 int offset = read4Bytes(buf, 18 + i*16); | |
115 int bitCount = read2Bytes(buf, offset+14); | |
116 SkBitmap::Config c; | |
117 //currently only provide ARGB_8888_, but maybe we want kIndex8_Confi
g for 1 and 4, and possibly 8? | |
118 //or maybe we'll determine this based on the provided config | |
119 switch (bitCount) | |
120 { | |
121 case 1: | |
122 case 4: | |
123 // In reality, at least for the moment, these will be decode
d into kARGB_8888 bitmaps. | |
124 // However, this will be used to distinguish between the low
er quality 1bpp and 4 bpp | |
125 // images and the higher quality images. | |
126 c = SkBitmap::kIndex8_Config; | |
127 break; | |
128 case 8: | |
129 case 24: | |
130 case 32: | |
131 c = SkBitmap::kARGB_8888_Config; | |
132 break; | |
133 default: | |
134 SkDEBUGF(("Image with %ibpp not supported\n", bitCount)); | |
135 continue; | |
136 } | |
137 chooser->inspect(i, c, width, height); | |
138 } | |
139 choice = chooser->choose(); | |
140 } | |
141 | |
142 //you never know what the chooser is going to supply | |
143 if (choice >= count || choice < 0) { | |
144 return kFailure; | |
145 } | |
146 #else | |
147 const int choice = 0; // TODO: fold this value into the expressions below | |
148 #endif | |
149 | |
150 //skip ahead to the correct header | 100 //skip ahead to the correct header |
151 //commented out lines are not used, but if i switch to other read method, ne
ed to know how many to skip | 101 //commented out lines are not used, but if i switch to other read method, ne
ed to know how many to skip |
152 //otherwise, they could be used for error checking | 102 //otherwise, they could be used for error checking |
153 int w = readByte(buf, 6 + choice*16); | 103 int w = readByte(buf, 6); |
154 int h = readByte(buf, 7 + choice*16); | 104 int h = readByte(buf, 7); |
155 int colorCount = readByte(buf, 8 + choice*16); | 105 int colorCount = readByte(buf, 8); |
156 //int reservedToo = readByte(buf, 9 + choice*16); //0 | 106 //int reservedToo = readByte(buf, 9 + choice*16); //0 |
157 //int planes = read2Bytes(buf, 10 + choice*16); //1 - but often 0 | 107 //int planes = read2Bytes(buf, 10 + choice*16); //1 - but often 0 |
158 //int fakeBitCount = read2Bytes(buf, 12 + choice*16); //should be real - usu
ally 0 | 108 //int fakeBitCount = read2Bytes(buf, 12 + choice*16); //should be real - usu
ally 0 |
159 const size_t size = read4Bytes(buf, 14 + choice*16); //matters? | 109 const size_t size = read4Bytes(buf, 14); //matters? |
160 const size_t offset = read4Bytes(buf, 18 + choice*16); | 110 const size_t offset = read4Bytes(buf, 18); |
161 // promote the sum to 64-bits to avoid overflow | 111 // promote the sum to 64-bits to avoid overflow |
162 if (offset > length || size > length || ((uint64_t)offset + size) > length)
{ | 112 if (offset > length || size > length || ((uint64_t)offset + size) > length)
{ |
163 return kFailure; | 113 return kFailure; |
164 } | 114 } |
165 | 115 |
166 // Check to see if this is a PNG image inside the ICO | 116 // Check to see if this is a PNG image inside the ICO |
167 { | 117 { |
168 SkMemoryStream subStream(buf + offset, size, false); | 118 SkMemoryStream subStream(buf + offset, size, false); |
169 SkAutoTDelete<SkImageDecoder> otherDecoder(SkImageDecoder::Factory(&subS
tream)); | 119 SkAutoTDelete<SkImageDecoder> otherDecoder(SkImageDecoder::Factory(&subS
tream)); |
170 if (otherDecoder.get() != NULL) { | 120 if (otherDecoder.get() != NULL) { |
(...skipping 253 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
424 static SkImageDecoder_DecodeReg gReg(sk_libico_dfactory); | 374 static SkImageDecoder_DecodeReg gReg(sk_libico_dfactory); |
425 | 375 |
426 static SkImageDecoder::Format get_format_ico(SkStreamRewindable* stream) { | 376 static SkImageDecoder::Format get_format_ico(SkStreamRewindable* stream) { |
427 if (is_ico(stream)) { | 377 if (is_ico(stream)) { |
428 return SkImageDecoder::kICO_Format; | 378 return SkImageDecoder::kICO_Format; |
429 } | 379 } |
430 return SkImageDecoder::kUnknown_Format; | 380 return SkImageDecoder::kUnknown_Format; |
431 } | 381 } |
432 | 382 |
433 static SkImageDecoder_FormatReg gFormatReg(get_format_ico); | 383 static SkImageDecoder_FormatReg gFormatReg(get_format_ico); |
OLD | NEW |