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 356 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
367 return SkPackARGB4444(SK_AlphaOPAQUE & 0x0F, 0, 0, 0); | 367 return SkPackARGB4444(SK_AlphaOPAQUE & 0x0F, 0, 0, 0); |
368 } else { | 368 } else { |
369 return SkPackARGB4444(SK_AlphaOPAQUE & 0x0F, | 369 return SkPackARGB4444(SK_AlphaOPAQUE & 0x0F, |
370 r / count, g / count, b / count); | 370 r / count, g / count, b / count); |
371 } | 371 } |
372 } | 372 } |
373 | 373 |
374 static SkBitmap unpremultiply_bitmap(const SkBitmap& bitmap, | 374 static SkBitmap unpremultiply_bitmap(const SkBitmap& bitmap, |
375 const SkIRect& srcRect) { | 375 const SkIRect& srcRect) { |
376 SkBitmap outBitmap; | 376 SkBitmap outBitmap; |
377 outBitmap.allocPixels(bitmap.info().makeWH(srcRect.width(), srcRect.height()
)); | 377 SkAssertResult(outBitmap.allocPixels( |
| 378 bitmap.info().makeWH(srcRect.width(), srcRect.height()))); |
378 int dstRow = 0; | 379 int dstRow = 0; |
379 | 380 |
380 outBitmap.lockPixels(); | 381 SkAutoLockPixels outBitmapPixelLock(outBitmap); |
381 bitmap.lockPixels(); | 382 SkAutoLockPixels bitmapPixelLock(bitmap); |
382 switch (bitmap.colorType()) { | 383 switch (bitmap.colorType()) { |
383 case kARGB_4444_SkColorType: { | 384 case kARGB_4444_SkColorType: { |
384 for (int y = srcRect.fTop; y < srcRect.fBottom; y++) { | 385 for (int y = srcRect.fTop; y < srcRect.fBottom; y++) { |
385 uint16_t* dst = outBitmap.getAddr16(0, dstRow); | 386 uint16_t* dst = outBitmap.getAddr16(0, dstRow); |
386 uint16_t* src = bitmap.getAddr16(0, y); | 387 uint16_t* src = bitmap.getAddr16(0, y); |
387 for (int x = srcRect.fLeft; x < srcRect.fRight; x++) { | 388 for (int x = srcRect.fLeft; x < srcRect.fRight; x++) { |
388 uint8_t a = SkGetPackedA4444(src[x]); | 389 uint8_t a = SkGetPackedA4444(src[x]); |
389 // It is necessary to average the color component of | 390 // It is necessary to average the color component of |
390 // transparent pixels with their surrounding neighbors | 391 // transparent pixels with their surrounding neighbors |
391 // since the PDF renderer may separately re-sample the | 392 // since the PDF renderer may separately re-sample the |
(...skipping 29 matching lines...) Expand all Loading... |
421 } | 422 } |
422 dst++; | 423 dst++; |
423 } | 424 } |
424 dstRow++; | 425 dstRow++; |
425 } | 426 } |
426 break; | 427 break; |
427 } | 428 } |
428 default: | 429 default: |
429 SkASSERT(false); | 430 SkASSERT(false); |
430 } | 431 } |
431 bitmap.unlockPixels(); | |
432 outBitmap.unlockPixels(); | |
433 | 432 |
434 outBitmap.setImmutable(); | 433 outBitmap.setImmutable(); |
435 | 434 |
436 return outBitmap; | 435 return outBitmap; |
437 } | 436 } |
438 | 437 |
439 // static | 438 // static |
440 SkPDFImage* SkPDFImage::CreateImage(const SkBitmap& bitmap, | 439 SkPDFImage* SkPDFImage::CreateImage(const SkBitmap& bitmap, |
441 const SkIRect& srcRect, | 440 const SkIRect& srcRect, |
442 SkPicture::EncodeBitmap encoder) { | 441 SkPicture::EncodeBitmap encoder) { |
(...skipping 179 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
622 // but the new catalog wants it compressed. | 621 // but the new catalog wants it compressed. |
623 if (!getSubstitute()) { | 622 if (!getSubstitute()) { |
624 SkPDFStream* substitute = SkNEW_ARGS(SkPDFImage, (*this)); | 623 SkPDFStream* substitute = SkNEW_ARGS(SkPDFImage, (*this)); |
625 setSubstitute(substitute); | 624 setSubstitute(substitute); |
626 catalog->setSubstitute(this, substitute); | 625 catalog->setSubstitute(this, substitute); |
627 } | 626 } |
628 return false; | 627 return false; |
629 } | 628 } |
630 return true; | 629 return true; |
631 } | 630 } |
OLD | NEW |