Chromium Code Reviews| 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 384 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 395 alphaBit = 0; | 395 alphaBit = 0; |
| 396 #endif | 396 #endif |
| 397 int alpha = readByte(buf, xorOffset + 4*pixelNo + 3) & ((alphaBit-1)&0xFF); | 397 int alpha = readByte(buf, xorOffset + 4*pixelNo + 3) & ((alphaBit-1)&0xFF); |
| 398 *address = SkPreMultiplyARGB(alpha, red, green, blue); | 398 *address = SkPreMultiplyARGB(alpha, red, green, blue); |
| 399 } | 399 } |
| 400 | 400 |
| 401 /////////////////////////////////////////////////////////////////////////////// | 401 /////////////////////////////////////////////////////////////////////////////// |
| 402 DEFINE_DECODER_CREATOR(ICOImageDecoder); | 402 DEFINE_DECODER_CREATOR(ICOImageDecoder); |
| 403 //////////////////////////////////////////////////////////////////////////////// ///////// | 403 //////////////////////////////////////////////////////////////////////////////// ///////// |
| 404 | 404 |
| 405 static bool is_ico(SkStreamRewindable* stream) { | 405 static bool is_ico(SkStreamRewindable* stream) { |
|
mtklein
2014/10/24 01:59:06
Guh..
I know this is really secondary, but this c
| |
| 406 // Check to see if the first four bytes are 0,0,1,0 | 406 // Check to see if the first four bytes are 0,0,1,0 |
| 407 // FIXME: Is that required and sufficient? | 407 // FIXME: Is that required and sufficient? |
| 408 SkAutoMalloc autoMal(4); | 408 SkAutoMalloc autoMal(4); |
| 409 unsigned char* buf = (unsigned char*)autoMal.get(); | 409 unsigned char* buf = (unsigned char*)autoMal.get(); |
| 410 stream->read((void*)buf, 4); | 410 if (stream->read((void*)buf, 4) < 4) { |
| 411 return false; | |
| 412 } | |
| 411 int reserved = read2Bytes(buf, 0); | 413 int reserved = read2Bytes(buf, 0); |
| 412 int type = read2Bytes(buf, 2); | 414 int type = read2Bytes(buf, 2); |
| 413 if (reserved != 0 || type != 1) { | 415 if (reserved != 0 || type != 1) { |
| 414 // This stream does not represent an ICO image. | 416 // This stream does not represent an ICO image. |
| 415 return false; | 417 return false; |
| 416 } | 418 } |
| 417 return true; | 419 return true; |
| 418 } | 420 } |
| 419 | 421 |
| 420 static SkImageDecoder* sk_libico_dfactory(SkStreamRewindable* stream) { | 422 static SkImageDecoder* sk_libico_dfactory(SkStreamRewindable* stream) { |
| 421 if (is_ico(stream)) { | 423 if (is_ico(stream)) { |
| 422 return SkNEW(SkICOImageDecoder); | 424 return SkNEW(SkICOImageDecoder); |
| 423 } | 425 } |
| 424 return NULL; | 426 return NULL; |
| 425 } | 427 } |
| 426 | 428 |
| 427 static SkImageDecoder_DecodeReg gReg(sk_libico_dfactory); | 429 static SkImageDecoder_DecodeReg gReg(sk_libico_dfactory); |
| 428 | 430 |
| 429 static SkImageDecoder::Format get_format_ico(SkStreamRewindable* stream) { | 431 static SkImageDecoder::Format get_format_ico(SkStreamRewindable* stream) { |
| 430 if (is_ico(stream)) { | 432 if (is_ico(stream)) { |
| 431 return SkImageDecoder::kICO_Format; | 433 return SkImageDecoder::kICO_Format; |
| 432 } | 434 } |
| 433 return SkImageDecoder::kUnknown_Format; | 435 return SkImageDecoder::kUnknown_Format; |
| 434 } | 436 } |
| 435 | 437 |
| 436 static SkImageDecoder_FormatReg gFormatReg(get_format_ico); | 438 static SkImageDecoder_FormatReg gFormatReg(get_format_ico); |
| OLD | NEW |