| 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 387 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 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) { |
| 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 char buf[4]; |
| 409 unsigned char* buf = (unsigned char*)autoMal.get(); | 409 if (stream->read((void*)buf, 4) != 4) { |
| 410 stream->read((void*)buf, 4); | 410 return false; |
| 411 } |
| 411 int reserved = read2Bytes(buf, 0); | 412 int reserved = read2Bytes(buf, 0); |
| 412 int type = read2Bytes(buf, 2); | 413 int type = read2Bytes(buf, 2); |
| 413 if (reserved != 0 || type != 1) { | 414 return 0 == reserved && 1 == type; |
| 414 // This stream does not represent an ICO image. | |
| 415 return false; | |
| 416 } | |
| 417 return true; | |
| 418 } | 415 } |
| 419 | 416 |
| 420 static SkImageDecoder* sk_libico_dfactory(SkStreamRewindable* stream) { | 417 static SkImageDecoder* sk_libico_dfactory(SkStreamRewindable* stream) { |
| 421 if (is_ico(stream)) { | 418 if (is_ico(stream)) { |
| 422 return SkNEW(SkICOImageDecoder); | 419 return SkNEW(SkICOImageDecoder); |
| 423 } | 420 } |
| 424 return NULL; | 421 return NULL; |
| 425 } | 422 } |
| 426 | 423 |
| 427 static SkImageDecoder_DecodeReg gReg(sk_libico_dfactory); | 424 static SkImageDecoder_DecodeReg gReg(sk_libico_dfactory); |
| 428 | 425 |
| 429 static SkImageDecoder::Format get_format_ico(SkStreamRewindable* stream) { | 426 static SkImageDecoder::Format get_format_ico(SkStreamRewindable* stream) { |
| 430 if (is_ico(stream)) { | 427 if (is_ico(stream)) { |
| 431 return SkImageDecoder::kICO_Format; | 428 return SkImageDecoder::kICO_Format; |
| 432 } | 429 } |
| 433 return SkImageDecoder::kUnknown_Format; | 430 return SkImageDecoder::kUnknown_Format; |
| 434 } | 431 } |
| 435 | 432 |
| 436 static SkImageDecoder_FormatReg gFormatReg(get_format_ico); | 433 static SkImageDecoder_FormatReg gFormatReg(get_format_ico); |
| OLD | NEW |