OLD | NEW |
1 /* | 1 /* |
2 * Copyright 2015 Google Inc. | 2 * Copyright 2015 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 "SkColorPriv.h" | 8 #include "SkColorPriv.h" |
9 #include "SkData.h" | 9 #include "SkData.h" |
10 #include "SkDeflate.h" | 10 #include "SkDeflate.h" |
11 #include "SkImage_Base.h" | 11 #include "SkImage_Base.h" |
12 #include "SkJpegInfo.h" | 12 #include "SkJpegInfo.h" |
13 #include "SkPDFBitmap.h" | 13 #include "SkPDFBitmap.h" |
14 #include "SkPDFCanon.h" | 14 #include "SkPDFCanon.h" |
15 #include "SkStream.h" | 15 #include "SkStream.h" |
16 #include "SkUnPreMultiply.h" | 16 #include "SkUnPreMultiply.h" |
17 | 17 |
18 void image_get_ro_pixels(const SkImage* image, SkBitmap* dst) { | 18 void image_get_ro_pixels(const SkImage* image, SkBitmap* dst) { |
19 if(as_IB(image)->getROPixels(dst) | 19 if(as_IB(image)->getROPixels(dst) |
20 && dst->dimensions() == image->dimensions()) { | 20 && dst->dimensions() == image->dimensions()) { |
21 return; | 21 if (dst->colorType() != kIndex_8_SkColorType) { |
| 22 return; |
| 23 } |
| 24 // We must check to see if the bitmap has a color table. |
| 25 SkAutoLockPixels autoLockPixels(*dst); |
| 26 if (!dst->getColorTable()) { |
| 27 // We can't use an indexed bitmap with no colortable. |
| 28 dst->reset(); |
| 29 } else { |
| 30 return; |
| 31 } |
22 } | 32 } |
23 // no pixels or wrong size: fill with zeros. | 33 // no pixels or wrong size: fill with zeros. |
24 SkAlphaType at = image->isOpaque() ? kOpaque_SkAlphaType : kPremul_SkAlphaTy
pe; | 34 SkAlphaType at = image->isOpaque() ? kOpaque_SkAlphaType : kPremul_SkAlphaTy
pe; |
25 dst->setInfo(SkImageInfo::MakeN32(image->width(), image->height(), at)); | 35 dst->setInfo(SkImageInfo::MakeN32(image->width(), image->height(), at)); |
26 } | 36 } |
27 | 37 |
28 bool image_compute_is_opaque(const SkImage* image) { | 38 bool image_compute_is_opaque(const SkImage* image) { |
29 if (image->isOpaque()) { | 39 if (image->isOpaque()) { |
30 return true; | 40 return true; |
31 } | 41 } |
(...skipping 287 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
319 | 329 |
320 static void emit_image_xobject(SkWStream* stream, | 330 static void emit_image_xobject(SkWStream* stream, |
321 const SkImage* image, | 331 const SkImage* image, |
322 bool alpha, | 332 bool alpha, |
323 SkPDFObject* smask, | 333 SkPDFObject* smask, |
324 const SkPDFObjNumMap& objNumMap, | 334 const SkPDFObjNumMap& objNumMap, |
325 const SkPDFSubstituteMap& substitutes) { | 335 const SkPDFSubstituteMap& substitutes) { |
326 SkBitmap bitmap; | 336 SkBitmap bitmap; |
327 image_get_ro_pixels(image, &bitmap); // TODO(halcanary): test | 337 image_get_ro_pixels(image, &bitmap); // TODO(halcanary): test |
328 SkAutoLockPixels autoLockPixels(bitmap); // with malformed images. | 338 SkAutoLockPixels autoLockPixels(bitmap); // with malformed images. |
329 SkASSERT(bitmap.colorType() != kIndex_8_SkColorType || | |
330 bitmap.getColorTable()); | |
331 | 339 |
332 // Write to a temporary buffer to get the compressed length. | 340 // Write to a temporary buffer to get the compressed length. |
333 SkDynamicMemoryWStream buffer; | 341 SkDynamicMemoryWStream buffer; |
334 SkDeflateWStream deflateWStream(&buffer); | 342 SkDeflateWStream deflateWStream(&buffer); |
335 if (alpha) { | 343 if (alpha) { |
336 bitmap_alpha_to_a8(bitmap, &deflateWStream); | 344 bitmap_alpha_to_a8(bitmap, &deflateWStream); |
337 } else { | 345 } else { |
338 bitmap_to_pdf_pixels(bitmap, &deflateWStream); | 346 bitmap_to_pdf_pixels(bitmap, &deflateWStream); |
339 } | 347 } |
340 deflateWStream.finalize(); // call before detachAsStream(). | 348 deflateWStream.finalize(); // call before detachAsStream(). |
(...skipping 132 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
473 return new PDFJpegBitmap(info.fSize, data, yuv); | 481 return new PDFJpegBitmap(info.fSize, data, yuv); |
474 } | 482 } |
475 } | 483 } |
476 SkPDFObject* smask = | 484 SkPDFObject* smask = |
477 image_compute_is_opaque(image) ? nullptr : new PDFAlphaBitmap(image)
; | 485 image_compute_is_opaque(image) ? nullptr : new PDFAlphaBitmap(image)
; |
478 #ifdef SK_PDF_IMAGE_STATS | 486 #ifdef SK_PDF_IMAGE_STATS |
479 gRegularImageObjects.fetch_add(1); | 487 gRegularImageObjects.fetch_add(1); |
480 #endif | 488 #endif |
481 return new PDFDefaultBitmap(image, smask); | 489 return new PDFDefaultBitmap(image, smask); |
482 } | 490 } |
OLD | NEW |