OLD | NEW |
1 /* | 1 /* |
2 * Copyright 2013 Google Inc. | 2 * Copyright 2013 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 "SkPdfRenderer.h" | 8 #include "SkPdfRenderer.h" |
9 | 9 |
10 #include "SkBitmapDevice.h" | 10 #include "SkBitmapDevice.h" |
(...skipping 214 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
225 | 225 |
226 virtual SkPdfResult consumeToken(PdfToken& token) SK_OVERRIDE; | 226 virtual SkPdfResult consumeToken(PdfToken& token) SK_OVERRIDE; |
227 virtual void loop() SK_OVERRIDE; | 227 virtual void loop() SK_OVERRIDE; |
228 | 228 |
229 private: | 229 private: |
230 typedef SkPdfTokenLooper INHERITED; | 230 typedef SkPdfTokenLooper INHERITED; |
231 }; | 231 }; |
232 | 232 |
233 // Utilities | 233 // Utilities |
234 static void setup_bitmap(SkBitmap* bitmap, int width, int height, SkColor color
= SK_ColorWHITE) { | 234 static void setup_bitmap(SkBitmap* bitmap, int width, int height, SkColor color
= SK_ColorWHITE) { |
235 bitmap->setConfig(SkBitmap::kARGB_8888_Config, width, height); | 235 bitmap->allocN32Pixels(width, height); |
236 | |
237 bitmap->allocPixels(); | |
238 bitmap->eraseColor(color); | 236 bitmap->eraseColor(color); |
239 } | 237 } |
240 | 238 |
241 // TODO(edisonn): synonyms? /DeviceRGB and /RGB mean the same thing. Context dep
endent. | 239 // TODO(edisonn): synonyms? /DeviceRGB and /RGB mean the same thing. Context dep
endent. |
242 static int GetColorSpaceComponents(NotOwnedString& colorSpace) { | 240 static int GetColorSpaceComponents(NotOwnedString& colorSpace) { |
243 if (colorSpace.equals("DeviceCMYK")) { | 241 if (colorSpace.equals("DeviceCMYK")) { |
244 return 4; | 242 return 4; |
245 } else if (colorSpace.equals("DeviceGray") || | 243 } else if (colorSpace.equals("DeviceGray") || |
246 colorSpace.equals("CalGray") || | 244 colorSpace.equals("CalGray") || |
247 colorSpace.equals("Indexed")) { | 245 colorSpace.equals("Indexed")) { |
(...skipping 143 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
391 long i = width * (h); | 389 long i = width * (h); |
392 for (int w = 0 ; w < width; w++) { | 390 for (int w = 0 ; w < width; w++) { |
393 uncompressedStreamArgb[i] = SkColorSetRGB(uncompressedStream[3 *
w], | 391 uncompressedStreamArgb[i] = SkColorSetRGB(uncompressedStream[3 *
w], |
394 uncompressedStream[3 *
w + 1], | 392 uncompressedStream[3 *
w + 1], |
395 uncompressedStream[3 *
w + 2]); | 393 uncompressedStream[3 *
w + 2]); |
396 i++; | 394 i++; |
397 } | 395 } |
398 uncompressedStream += bytesPerLine; | 396 uncompressedStream += bytesPerLine; |
399 } | 397 } |
400 | 398 |
401 bitmap->setConfig(SkBitmap::kARGB_8888_Config, width, height); | 399 const SkImageInfo info = SkImageInfo::MakeN32Premul(width, height); |
402 bitmap->setPixels(uncompressedStreamArgb); | 400 bitmap->installPixels(info, uncompressedStreamArgb, info.minRowBytes()); |
403 } | 401 } |
404 else if ((colorSpace.equals("DeviceGray") || colorSpace.equals("Gray")) && b
pc == 8) { | 402 else if ((colorSpace.equals("DeviceGray") || colorSpace.equals("Gray")) && b
pc == 8) { |
405 unsigned char* uncompressedStreamA8 = (unsigned char*)malloc(width * hei
ght); | 403 unsigned char* uncompressedStreamA8 = (unsigned char*)malloc(width * hei
ght); |
406 | 404 |
407 for (int h = 0 ; h < height; h++) { | 405 for (int h = 0 ; h < height; h++) { |
408 long i = width * (h); | 406 long i = width * (h); |
409 for (int w = 0 ; w < width; w++) { | 407 for (int w = 0 ; w < width; w++) { |
410 uncompressedStreamA8[i] = transparencyMask ? 255 - uncompressedS
tream[w] : | 408 uncompressedStreamA8[i] = transparencyMask ? 255 - uncompressedS
tream[w] : |
411 uncompressedStream[
w]; | 409 uncompressedStream[
w]; |
412 i++; | 410 i++; |
413 } | 411 } |
414 uncompressedStream += bytesPerLine; | 412 uncompressedStream += bytesPerLine; |
415 } | 413 } |
416 | 414 |
417 bitmap->setConfig(transparencyMask ? SkBitmap::kA8_Config : SkBitmap::kI
ndex8_Config, | 415 const SkColorType ct = transparencyMask ? kAlpha_8_SkColorType : kIndex_
8_SkColorType; |
418 width, height); | 416 const SkImageInfo info = SkImageInfo::Make(width, height, ct, kPremul_Sk
AlphaType); |
419 bitmap->setPixels(uncompressedStreamA8, transparencyMask ? NULL : getGra
yColortable()); | 417 bitmap->installPixels(info, uncompressedStreamA8, info.minRowBytes(), |
| 418 transparencyMask ? NULL : getGrayColortable(), NUL
L, NULL); |
420 } | 419 } |
421 | 420 |
422 // TODO(edisonn): pass color space and context here? | 421 // TODO(edisonn): pass color space and context here? |
423 SkPdfReport(kCodeWarning_SkPdfIssueSeverity, kNYI_SkPdfIssue, "Color space N
YI", NULL, NULL); | 422 SkPdfReport(kCodeWarning_SkPdfIssueSeverity, kNYI_SkPdfIssue, "Color space N
YI", NULL, NULL); |
424 return bitmap; | 423 return bitmap; |
425 } | 424 } |
426 // TODO(edisonn): preserve A1 format that skia knows, + fast convert from 111, 2
22, 444 to closest | 425 // TODO(edisonn): preserve A1 format that skia knows, + fast convert from 111, 2
22, 444 to closest |
427 // skia format. | 426 // skia format. |
428 | 427 |
429 // This functions returns the image, it does not look at the smask. | 428 // This functions returns the image, it does not look at the smask. |
(...skipping 82 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
512 streamDict->getFilterAsArray(NULL)->objAtAIndex(0)->nameValue2
() | 511 streamDict->getFilterAsArray(NULL)->objAtAIndex(0)->nameValue2
() |
513 .equals("DCT
Decode")))) { | 512 .equals("DCT
Decode")))) { |
514 SkBitmap* bitmap = new SkBitmap(); | 513 SkBitmap* bitmap = new SkBitmap(); |
515 SkImageDecoder::DecodeMemory(uncompressedStream, uncompressedStreamLengt
h, bitmap); | 514 SkImageDecoder::DecodeMemory(uncompressedStream, uncompressedStreamLengt
h, bitmap); |
516 return bitmap; | 515 return bitmap; |
517 } | 516 } |
518 | 517 |
519 // TODO(edisonn): assumes RGB for now, since it is the only one implemented | 518 // TODO(edisonn): assumes RGB for now, since it is the only one implemented |
520 if (indexed) { | 519 if (indexed) { |
521 SkBitmap* bitmap = new SkBitmap(); | 520 SkBitmap* bitmap = new SkBitmap(); |
522 bitmap->setConfig(SkBitmap::kIndex8_Config, width, height); | 521 const SkImageInfo info = SkImageInfo::Make(width, height, kIndex_8_SkCol
orType, |
523 SkColorTable* colorTable = new SkColorTable(colors, cnt); | 522 kPremul_SkAlphaType); |
524 bitmap->setPixels((void*)uncompressedStream, colorTable); | 523 SkAutoTUnref<SkColorTable> colorTable(new SkColorTable(colors, cnt)); |
| 524 bitmap->installPixels(info, (void*)uncompressedStream, info.minRowBytes(
), colorTable, |
| 525 NULL, NULL); |
525 return bitmap; | 526 return bitmap; |
526 } | 527 } |
527 | 528 |
528 int bytesPerLine = (int)(uncompressedStreamLength / height); | 529 int bytesPerLine = (int)(uncompressedStreamLength / height); |
529 #ifdef PDF_TRACE | 530 #ifdef PDF_TRACE |
530 if (uncompressedStreamLength % height != 0) { | 531 if (uncompressedStreamLength % height != 0) { |
531 printf("Warning uncompressedStreamLength modulo height != 0 !!!\n"); | 532 printf("Warning uncompressedStreamLength modulo height != 0 !!!\n"); |
532 } | 533 } |
533 #endif | 534 #endif |
534 | 535 |
(...skipping 2370 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2905 | 2906 |
2906 rect = SkRect::MakeWH(width, height); | 2907 rect = SkRect::MakeWH(width, height); |
2907 | 2908 |
2908 setup_bitmap(output, SkScalarCeilToInt(width), SkScalarCeilToInt(height)); | 2909 setup_bitmap(output, SkScalarCeilToInt(width), SkScalarCeilToInt(height)); |
2909 | 2910 |
2910 SkAutoTUnref<SkBaseDevice> device(SkNEW_ARGS(SkBitmapDevice, (*output))); | 2911 SkAutoTUnref<SkBaseDevice> device(SkNEW_ARGS(SkBitmapDevice, (*output))); |
2911 SkCanvas canvas(device); | 2912 SkCanvas canvas(device); |
2912 | 2913 |
2913 return renderer->renderPage(page, &canvas, rect); | 2914 return renderer->renderPage(page, &canvas, rect); |
2914 } | 2915 } |
OLD | NEW |