| 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 365 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 376 alphaBit = 0; | 376 alphaBit = 0; |
| 377 #endif | 377 #endif |
| 378 int alpha = readByte(buf, xorOffset + 4*pixelNo + 3) & ((alphaBit-1)&0xFF); | 378 int alpha = readByte(buf, xorOffset + 4*pixelNo + 3) & ((alphaBit-1)&0xFF); |
| 379 *address = SkPreMultiplyARGB(alpha, red, green, blue); | 379 *address = SkPreMultiplyARGB(alpha, red, green, blue); |
| 380 } | 380 } |
| 381 | 381 |
| 382 /////////////////////////////////////////////////////////////////////////////// | 382 /////////////////////////////////////////////////////////////////////////////// |
| 383 DEFINE_DECODER_CREATOR(ICOImageDecoder); | 383 DEFINE_DECODER_CREATOR(ICOImageDecoder); |
| 384 ////////////////////////////////////////////////////////////////////////////////
///////// | 384 ////////////////////////////////////////////////////////////////////////////////
///////// |
| 385 | 385 |
| 386 static bool is_ico(SkStream* stream) { | 386 static bool is_ico(SkStreamRewindable* stream) { |
| 387 // Check to see if the first four bytes are 0,0,1,0 | 387 // Check to see if the first four bytes are 0,0,1,0 |
| 388 // FIXME: Is that required and sufficient? | 388 // FIXME: Is that required and sufficient? |
| 389 SkAutoMalloc autoMal(4); | 389 SkAutoMalloc autoMal(4); |
| 390 unsigned char* buf = (unsigned char*)autoMal.get(); | 390 unsigned char* buf = (unsigned char*)autoMal.get(); |
| 391 stream->read((void*)buf, 4); | 391 stream->read((void*)buf, 4); |
| 392 int reserved = read2Bytes(buf, 0); | 392 int reserved = read2Bytes(buf, 0); |
| 393 int type = read2Bytes(buf, 2); | 393 int type = read2Bytes(buf, 2); |
| 394 if (reserved != 0 || type != 1) { | 394 if (reserved != 0 || type != 1) { |
| 395 // This stream does not represent an ICO image. | 395 // This stream does not represent an ICO image. |
| 396 return false; | 396 return false; |
| 397 } | 397 } |
| 398 return true; | 398 return true; |
| 399 } | 399 } |
| 400 | 400 |
| 401 static SkImageDecoder* sk_libico_dfactory(SkStream* stream) { | 401 static SkImageDecoder* sk_libico_dfactory(SkStreamRewindable* stream) { |
| 402 if (is_ico(stream)) { | 402 if (is_ico(stream)) { |
| 403 return SkNEW(SkICOImageDecoder); | 403 return SkNEW(SkICOImageDecoder); |
| 404 } | 404 } |
| 405 return NULL; | 405 return NULL; |
| 406 } | 406 } |
| 407 | 407 |
| 408 static SkImageDecoder_DecodeReg gReg(sk_libico_dfactory); | 408 static SkImageDecoder_DecodeReg gReg(sk_libico_dfactory); |
| 409 | 409 |
| 410 static SkImageDecoder::Format get_format_ico(SkStream* stream) { | 410 static SkImageDecoder::Format get_format_ico(SkStreamRewindable* stream) { |
| 411 if (is_ico(stream)) { | 411 if (is_ico(stream)) { |
| 412 return SkImageDecoder::kICO_Format; | 412 return SkImageDecoder::kICO_Format; |
| 413 } | 413 } |
| 414 return SkImageDecoder::kUnknown_Format; | 414 return SkImageDecoder::kUnknown_Format; |
| 415 } | 415 } |
| 416 | 416 |
| 417 static SkImageDecoder_FormatReg gFormatReg(get_format_ico); | 417 static SkImageDecoder_FormatReg gFormatReg(get_format_ico); |
| OLD | NEW |