| OLD | NEW |
| 1 /* | 1 /* |
| 2 * Copyright 2012 Google Inc. | 2 * Copyright 2012 Google Inc. |
| 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 "SkImageDecoder.h" | 8 #include "SkImageDecoder.h" |
| 9 #include "SkImage_Base.h" | 9 #include "SkImage_Base.h" |
| 10 #include "SkBitmap.h" | 10 #include "SkBitmap.h" |
| (...skipping 23 matching lines...) Expand all Loading... |
| 34 fEncodedData = data; | 34 fEncodedData = data; |
| 35 fEncodedData->ref(); | 35 fEncodedData->ref(); |
| 36 } | 36 } |
| 37 | 37 |
| 38 SkImage_Codec::~SkImage_Codec() { | 38 SkImage_Codec::~SkImage_Codec() { |
| 39 fEncodedData->unref(); | 39 fEncodedData->unref(); |
| 40 } | 40 } |
| 41 | 41 |
| 42 void SkImage_Codec::onDraw(SkCanvas* canvas, SkScalar x, SkScalar y, const SkPai
nt* paint) { | 42 void SkImage_Codec::onDraw(SkCanvas* canvas, SkScalar x, SkScalar y, const SkPai
nt* paint) { |
| 43 if (!fBitmap.pixelRef()) { | 43 if (!fBitmap.pixelRef()) { |
| 44 if (!SkImageDecoder::DecodeMemory(fEncodedData->bytes(), fEncodedData->s
ize(), | 44 if (!SkImageDecoder::DecodeMemory(fEncodedData->bytes(), fEncodedData->s
ize(), &fBitmap)) { |
| 45 &fBitmap)) { | |
| 46 return; | 45 return; |
| 47 } | 46 } |
| 48 } | 47 } |
| 49 canvas->drawBitmap(fBitmap, x, y, paint); | 48 canvas->drawBitmap(fBitmap, x, y, paint); |
| 50 } | 49 } |
| 51 | 50 |
| 52 void SkImage_Codec::onDrawRectToRect(SkCanvas* canvas, const SkRect* src, | 51 void SkImage_Codec::onDrawRectToRect(SkCanvas* canvas, const SkRect* src, |
| 53 const SkRect& dst, const SkPaint* paint) { | 52 const SkRect& dst, const SkPaint* paint) { |
| 54 if (!fBitmap.pixelRef()) { | 53 if (!fBitmap.pixelRef()) { |
| 55 if (!SkImageDecoder::DecodeMemory(fEncodedData->bytes(), fEncodedData->s
ize(), | 54 if (!SkImageDecoder::DecodeMemory(fEncodedData->bytes(), fEncodedData->s
ize(), &fBitmap)) { |
| 56 &fBitmap)) { | |
| 57 return; | 55 return; |
| 58 } | 56 } |
| 59 } | 57 } |
| 60 canvas->drawBitmapRectToRect(fBitmap, src, dst, paint); | 58 canvas->drawBitmapRectToRect(fBitmap, src, dst, paint); |
| 61 } | 59 } |
| 62 | 60 |
| 63 /////////////////////////////////////////////////////////////////////////////// | 61 /////////////////////////////////////////////////////////////////////////////// |
| 64 | 62 |
| 65 SkImage* SkImage::NewEncodedData(SkData* data) { | 63 SkImage* SkImage::NewEncodedData(SkData* data) { |
| 66 if (NULL == data) { | 64 if (NULL == data) { |
| 67 return NULL; | 65 return NULL; |
| 68 } | 66 } |
| 69 | 67 |
| 70 SkBitmap bitmap; | 68 SkBitmap bitmap; |
| 71 if (!SkImageDecoder::DecodeMemory(data->bytes(), data->size(), &bitmap, | 69 if (!SkImageDecoder::DecodeMemory(data->bytes(), data->size(), &bitmap, kUnk
nown_SkColorType, |
| 72 SkBitmap::kNo_Config, | |
| 73 SkImageDecoder::kDecodeBounds_Mode)) { | 70 SkImageDecoder::kDecodeBounds_Mode)) { |
| 74 return NULL; | 71 return NULL; |
| 75 } | 72 } |
| 76 | 73 |
| 77 return SkNEW_ARGS(SkImage_Codec, (data, bitmap.width(), bitmap.height())); | 74 return SkNEW_ARGS(SkImage_Codec, (data, bitmap.width(), bitmap.height())); |
| 78 } | 75 } |
| OLD | NEW |