OLD | NEW |
1 /* | 1 /* |
2 * Copyright 2010 The Android Open Source Project | 2 * Copyright 2010 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 "SkPDFImage.h" | 8 #include "SkPDFImage.h" |
9 | 9 |
10 #include "SkBitmap.h" | 10 #include "SkBitmap.h" |
(...skipping 204 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
215 kRGB_565_SkColorType == colorType)) { | 215 kRGB_565_SkColorType == colorType)) { |
216 if (isTransparent != NULL) { | 216 if (isTransparent != NULL) { |
217 *isTransparent = false; | 217 *isTransparent = false; |
218 } | 218 } |
219 return NULL; | 219 return NULL; |
220 } | 220 } |
221 bool isOpaque = true; | 221 bool isOpaque = true; |
222 bool transparent = extractAlpha; | 222 bool transparent = extractAlpha; |
223 SkStream* stream = NULL; | 223 SkStream* stream = NULL; |
224 | 224 |
225 bitmap.lockPixels(); | 225 SkAutoLockPixels lock(bitmap); |
| 226 if (NULL == bitmap.getPixels()) { |
| 227 return NULL; |
| 228 } |
| 229 |
226 switch (colorType) { | 230 switch (colorType) { |
227 case kIndex_8_SkColorType: | 231 case kIndex_8_SkColorType: |
228 if (!extractAlpha) { | 232 if (!extractAlpha) { |
229 stream = extract_index8_image(bitmap, srcRect); | 233 stream = extract_index8_image(bitmap, srcRect); |
230 } | 234 } |
231 break; | 235 break; |
232 case kARGB_4444_SkColorType: | 236 case kARGB_4444_SkColorType: |
233 stream = extract_argb4444_data(bitmap, srcRect, extractAlpha, | 237 stream = extract_argb4444_data(bitmap, srcRect, extractAlpha, |
234 &isOpaque, &transparent); | 238 &isOpaque, &transparent); |
235 break; | 239 break; |
(...skipping 10 matching lines...) Expand all Loading... |
246 if (!extractAlpha) { | 250 if (!extractAlpha) { |
247 stream = create_black_image(); | 251 stream = create_black_image(); |
248 } else { | 252 } else { |
249 stream = extract_a8_alpha(bitmap, srcRect, | 253 stream = extract_a8_alpha(bitmap, srcRect, |
250 &isOpaque, &transparent); | 254 &isOpaque, &transparent); |
251 } | 255 } |
252 break; | 256 break; |
253 default: | 257 default: |
254 SkASSERT(false); | 258 SkASSERT(false); |
255 } | 259 } |
256 bitmap.unlockPixels(); | |
257 | 260 |
258 if (isTransparent != NULL) { | 261 if (isTransparent != NULL) { |
259 *isTransparent = transparent; | 262 *isTransparent = transparent; |
260 } | 263 } |
261 if (extractAlpha && (transparent || isOpaque)) { | 264 if (extractAlpha && (transparent || isOpaque)) { |
262 SkSafeUnref(stream); | 265 SkSafeUnref(stream); |
263 return NULL; | 266 return NULL; |
264 } | 267 } |
265 return stream; | 268 return stream; |
266 } | 269 } |
(...skipping 446 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
713 if (SkIRect::MakeWH(bitmap.width(), bitmap.height()) == subset) { | 716 if (SkIRect::MakeWH(bitmap.width(), bitmap.height()) == subset) { |
714 SkAutoTUnref<SkData> encodedData(ref_encoded_data(bitmap)); | 717 SkAutoTUnref<SkData> encodedData(ref_encoded_data(bitmap)); |
715 if (is_jfif_jpeg(encodedData)) { | 718 if (is_jfif_jpeg(encodedData)) { |
716 return SkNEW_ARGS(PDFJPEGImage, | 719 return SkNEW_ARGS(PDFJPEGImage, |
717 (encodedData, bitmap.width(), bitmap.height())); | 720 (encodedData, bitmap.width(), bitmap.height())); |
718 } | 721 } |
719 } | 722 } |
720 #endif | 723 #endif |
721 return SkPDFImage::CreateImage(bitmap, subset, encoder); | 724 return SkPDFImage::CreateImage(bitmap, subset, encoder); |
722 } | 725 } |
OLD | NEW |