| OLD | NEW |
| 1 | 1 |
| 2 /* | 2 /* |
| 3 * Copyright 2006 The Android Open Source Project | 3 * Copyright 2006 The Android Open Source Project |
| 4 * | 4 * |
| 5 * Use of this source code is governed by a BSD-style license that can be | 5 * Use of this source code is governed by a BSD-style license that can be |
| 6 * found in the LICENSE file. | 6 * found in the LICENSE file. |
| 7 */ | 7 */ |
| 8 | 8 |
| 9 | 9 |
| 10 #include "SkImageDecoder.h" | 10 #include "SkImageDecoder.h" |
| (...skipping 355 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 366 alphaBit = 0; | 366 alphaBit = 0; |
| 367 #endif | 367 #endif |
| 368 int alpha = readByte(buf, xorOffset + 4*pixelNo + 3) & ((alphaBit-1)&0xFF); | 368 int alpha = readByte(buf, xorOffset + 4*pixelNo + 3) & ((alphaBit-1)&0xFF); |
| 369 *address = SkPreMultiplyARGB(alpha, red, green, blue); | 369 *address = SkPreMultiplyARGB(alpha, red, green, blue); |
| 370 } | 370 } |
| 371 | 371 |
| 372 /////////////////////////////////////////////////////////////////////////////// | 372 /////////////////////////////////////////////////////////////////////////////// |
| 373 DEFINE_DECODER_CREATOR(ICOImageDecoder); | 373 DEFINE_DECODER_CREATOR(ICOImageDecoder); |
| 374 ////////////////////////////////////////////////////////////////////////////////
///////// | 374 ////////////////////////////////////////////////////////////////////////////////
///////// |
| 375 | 375 |
| 376 #include "SkTRegistry.h" | 376 static bool is_ico(SkStream* stream) { |
| 377 | |
| 378 static SkImageDecoder* sk_libico_dfactory(SkStream* stream) { | |
| 379 // Check to see if the first four bytes are 0,0,1,0 | 377 // Check to see if the first four bytes are 0,0,1,0 |
| 380 // FIXME: Is that required and sufficient? | 378 // FIXME: Is that required and sufficient? |
| 381 SkAutoMalloc autoMal(4); | 379 SkAutoMalloc autoMal(4); |
| 382 unsigned char* buf = (unsigned char*)autoMal.get(); | 380 unsigned char* buf = (unsigned char*)autoMal.get(); |
| 383 stream->read((void*)buf, 4); | 381 stream->read((void*)buf, 4); |
| 384 int reserved = read2Bytes(buf, 0); | 382 int reserved = read2Bytes(buf, 0); |
| 385 int type = read2Bytes(buf, 2); | 383 int type = read2Bytes(buf, 2); |
| 386 if (reserved != 0 || type != 1) { | 384 if (reserved != 0 || type != 1) { |
| 387 // This stream does not represent an ICO image. | 385 // This stream does not represent an ICO image. |
| 388 return NULL; | 386 return false; |
| 389 } | 387 } |
| 390 return SkNEW(SkICOImageDecoder); | 388 return true; |
| 389 } |
| 390 |
| 391 #include "SkTRegistry.h" |
| 392 |
| 393 static SkImageDecoder* sk_libico_dfactory(SkStream* stream) { |
| 394 if (is_ico(stream)) { |
| 395 return SkNEW(SkICOImageDecoder); |
| 396 } |
| 397 return NULL; |
| 391 } | 398 } |
| 392 | 399 |
| 393 static SkTRegistry<SkImageDecoder*, SkStream*> gReg(sk_libico_dfactory); | 400 static SkTRegistry<SkImageDecoder*, SkStream*> gReg(sk_libico_dfactory); |
| 401 |
| 402 static SkImageDecoder::Format get_format_ico(SkStream* stream) { |
| 403 if (is_ico(stream)) { |
| 404 return SkImageDecoder::kICO_Format; |
| 405 } |
| 406 return SkImageDecoder::kUnknown_Format; |
| 407 } |
| 408 |
| 409 static SkTRegistry<SkImageDecoder::Format, SkStream*> gFormatReg(get_format_ico)
; |
| OLD | NEW |