Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(46)

Side by Side Diff: src/images/SkImageDecoder_libico.cpp

Issue 14363003: Updates to skimage tool to use it for testing. (Closed) Base URL: https://skia.googlecode.com/svn/trunk
Patch Set: Implement onGetFormat for other decoders. Created 7 years, 8 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
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"
11 #include "SkStream.h" 11 #include "SkStream.h"
12 #include "SkColorPriv.h" 12 #include "SkColorPriv.h"
13 #include "SkTypes.h" 13 #include "SkTypes.h"
14 14
15 class SkICOImageDecoder : public SkImageDecoder { 15 class SkICOImageDecoder : public SkImageDecoder {
16 public: 16 public:
17 SkICOImageDecoder(); 17 SkICOImageDecoder();
18 18
19 virtual Format getFormat() const SK_OVERRIDE { 19 virtual Format getFormat() const SK_OVERRIDE {
20 return kICO_Format; 20 return kICO_Format;
21 } 21 }
22 22
23 virtual Format onGetFormat(SkStream*) const SK_OVERRIDE;
24
23 protected: 25 protected:
24 virtual bool onDecode(SkStream* stream, SkBitmap* bm, Mode) SK_OVERRIDE; 26 virtual bool onDecode(SkStream* stream, SkBitmap* bm, Mode) SK_OVERRIDE;
25 27
26 private: 28 private:
27 typedef SkImageDecoder INHERITED; 29 typedef SkImageDecoder INHERITED;
28 }; 30 };
29 31
30 //////////////////////////////////////////////////////////////////////////////// ///////// 32 //////////////////////////////////////////////////////////////////////////////// /////////
31 33
32 //read bytes starting from the begin-th index in the buffer 34 //read bytes starting from the begin-th index in the buffer
(...skipping 329 matching lines...) Expand 10 before | Expand all | Expand 10 after
362 int green = readByte(buf, xorOffset + 4*pixelNo + 1); 364 int green = readByte(buf, xorOffset + 4*pixelNo + 1);
363 int red = readByte(buf, xorOffset + 4*pixelNo + 2); 365 int red = readByte(buf, xorOffset + 4*pixelNo + 2);
364 int alphaBit = (alphaByte & m) >> shift; 366 int alphaBit = (alphaByte & m) >> shift;
365 #if 1 // don't trust the alphaBit for 32bit images <mrr> 367 #if 1 // don't trust the alphaBit for 32bit images <mrr>
366 alphaBit = 0; 368 alphaBit = 0;
367 #endif 369 #endif
368 int alpha = readByte(buf, xorOffset + 4*pixelNo + 3) & ((alphaBit-1)&0xFF); 370 int alpha = readByte(buf, xorOffset + 4*pixelNo + 3) & ((alphaBit-1)&0xFF);
369 *address = SkPreMultiplyARGB(alpha, red, green, blue); 371 *address = SkPreMultiplyARGB(alpha, red, green, blue);
370 } 372 }
371 373
372 /////////////////////////////////////////////////////////////////////////////// 374 static bool is_ico(SkStream* stream) {
373 DEFINE_DECODER_CREATOR(ICOImageDecoder);
374 //////////////////////////////////////////////////////////////////////////////// /////////
375
376 #include "SkTRegistry.h"
377
378 static SkImageDecoder* sk_libico_dfactory(SkStream* stream) {
379 // Check to see if the first four bytes are 0,0,1,0 375 // Check to see if the first four bytes are 0,0,1,0
380 // FIXME: Is that required and sufficient? 376 // FIXME: Is that required and sufficient?
381 SkAutoMalloc autoMal(4); 377 SkAutoMalloc autoMal(4);
382 unsigned char* buf = (unsigned char*)autoMal.get(); 378 unsigned char* buf = (unsigned char*)autoMal.get();
383 stream->read((void*)buf, 4); 379 stream->read((void*)buf, 4);
384 int reserved = read2Bytes(buf, 0); 380 int reserved = read2Bytes(buf, 0);
385 int type = read2Bytes(buf, 2); 381 int type = read2Bytes(buf, 2);
386 if (reserved != 0 || type != 1) { 382 if (reserved != 0 || type != 1) {
387 // This stream does not represent an ICO image. 383 // This stream does not represent an ICO image.
388 return NULL; 384 return false;
389 } 385 }
390 return SkNEW(SkICOImageDecoder); 386 return true;
387 }
388
389 SkImageDecoder::Format SkICOImageDecoder::onGetFormat(SkStream* stream) const {
390 if (is_ico(stream)) {
391 return kICO_Format;
392 }
393 return kUnknown_Format;
394 }
395
396 ///////////////////////////////////////////////////////////////////////////////
397 DEFINE_DECODER_CREATOR(ICOImageDecoder);
398 //////////////////////////////////////////////////////////////////////////////// /////////
399
400 #include "SkTRegistry.h"
401
402 static SkImageDecoder* sk_libico_dfactory(SkStream* stream) {
403 if (is_ico(stream)) {
404 return SkNEW(SkICOImageDecoder);
405 }
406 return NULL;
391 } 407 }
392 408
393 static SkTRegistry<SkImageDecoder*, SkStream*> gReg(sk_libico_dfactory); 409 static SkTRegistry<SkImageDecoder*, SkStream*> gReg(sk_libico_dfactory);
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698