Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(96)

Side by Side Diff: src/pdf/SkPDFImage.cpp

Issue 1010343002: add kGray_8_SkColorType (Closed) Base URL: https://skia.googlesource.com/skia.git@master
Patch Set: Created 5 years, 9 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « src/gpu/SkGr.cpp ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 13 matching lines...) Expand all
24 const SkIRect& srcRect) { 24 const SkIRect& srcRect) {
25 switch (bitmap.colorType()) { 25 switch (bitmap.colorType()) {
26 case kIndex_8_SkColorType: 26 case kIndex_8_SkColorType:
27 return srcRect.width() * srcRect.height(); 27 return srcRect.width() * srcRect.height();
28 case kARGB_4444_SkColorType: 28 case kARGB_4444_SkColorType:
29 return ((srcRect.width() * 3 + 1) / 2) * srcRect.height(); 29 return ((srcRect.width() * 3 + 1) / 2) * srcRect.height();
30 case kRGB_565_SkColorType: 30 case kRGB_565_SkColorType:
31 return srcRect.width() * 3 * srcRect.height(); 31 return srcRect.width() * 3 * srcRect.height();
32 case kRGBA_8888_SkColorType: 32 case kRGBA_8888_SkColorType:
33 case kBGRA_8888_SkColorType: 33 case kBGRA_8888_SkColorType:
34 case kGray_8_SkColorType:
34 return srcRect.width() * 3 * srcRect.height(); 35 return srcRect.width() * 3 * srcRect.height();
35 case kAlpha_8_SkColorType: 36 case kAlpha_8_SkColorType:
36 return 1; 37 return 1;
37 default: 38 default:
38 SkASSERT(false); 39 SkASSERT(false);
39 return 0; 40 return 0;
40 } 41 }
41 } 42 }
42 43
43 static SkStream* extract_index8_image(const SkBitmap& bitmap, 44 static SkStream* extract_index8_image(const SkBitmap& bitmap,
(...skipping 62 matching lines...) Expand 10 before | Expand all | Expand 10 after
106 } 107 }
107 } 108 }
108 } 109 }
109 return stream; 110 return stream;
110 } 111 }
111 112
112 static SkStream* extract_rgb565_image(const SkBitmap& bitmap, 113 static SkStream* extract_rgb565_image(const SkBitmap& bitmap,
113 const SkIRect& srcRect) { 114 const SkIRect& srcRect) {
114 SkStream* stream = SkNEW_ARGS(SkMemoryStream, 115 SkStream* stream = SkNEW_ARGS(SkMemoryStream,
115 (get_uncompressed_size(bitmap, 116 (get_uncompressed_size(bitmap,
116 srcRect))); 117 srcRect)));
117 uint8_t* dst = (uint8_t*)stream->getMemoryBase(); 118 uint8_t* dst = (uint8_t*)stream->getMemoryBase();
118 for (int y = srcRect.fTop; y < srcRect.fBottom; y++) { 119 for (int y = srcRect.fTop; y < srcRect.fBottom; y++) {
119 uint16_t* src = bitmap.getAddr16(0, y); 120 uint16_t* src = bitmap.getAddr16(0, y);
120 for (int x = srcRect.fLeft; x < srcRect.fRight; x++) { 121 for (int x = srcRect.fLeft; x < srcRect.fRight; x++) {
121 dst[0] = SkGetPackedR16(src[x]); 122 dst[0] = SkGetPackedR16(src[x]);
122 dst[1] = SkGetPackedG16(src[x]); 123 dst[1] = SkGetPackedG16(src[x]);
123 dst[2] = SkGetPackedB16(src[x]); 124 dst[2] = SkGetPackedB16(src[x]);
124 dst += 3; 125 dst += 3;
125 } 126 }
126 } 127 }
127 return stream; 128 return stream;
128 } 129 }
129 130
131 static SkStream* extract_gray8_image(const SkBitmap& bitmap, const SkIRect& srcR ect) {
132 SkStream* stream = SkNEW_ARGS(SkMemoryStream,
133 (get_uncompressed_size(bitmap, srcRect)));
134 uint8_t* dst = (uint8_t*)stream->getMemoryBase();
135 for (int y = srcRect.fTop; y < srcRect.fBottom; y++) {
136 uint8_t* src = bitmap.getAddr8(0, y);
137 for (int x = srcRect.fLeft; x < srcRect.fRight; x++) {
138 dst[0] = dst[1] = dst[2] = src[x];
139 dst += 3;
140 }
141 }
142 return stream;
143 }
144
130 static uint32_t get_argb8888_neighbor_avg_color(const SkBitmap& bitmap, 145 static uint32_t get_argb8888_neighbor_avg_color(const SkBitmap& bitmap,
131 int xOrig, 146 int xOrig,
132 int yOrig); 147 int yOrig);
133 148
134 static SkStream* extract_argb8888_data(const SkBitmap& bitmap, 149 static SkStream* extract_argb8888_data(const SkBitmap& bitmap,
135 const SkIRect& srcRect, 150 const SkIRect& srcRect,
136 bool extractAlpha, 151 bool extractAlpha,
137 bool* isOpaque, 152 bool* isOpaque,
138 bool* isTransparent) { 153 bool* isTransparent) {
139 size_t streamSize = extractAlpha ? srcRect.width() * srcRect.height() 154 size_t streamSize = extractAlpha ? srcRect.width() * srcRect.height()
(...skipping 80 matching lines...) Expand 10 before | Expand all | Expand 10 after
220 * extractAlpha == true. 235 * extractAlpha == true.
221 * @return Unencoded image data, or NULL if either data was not 236 * @return Unencoded image data, or NULL if either data was not
222 * available or alpha data was requested but the image was 237 * available or alpha data was requested but the image was
223 * entirely transparent or opaque. 238 * entirely transparent or opaque.
224 */ 239 */
225 static SkStream* extract_image_data(const SkBitmap& bitmap, 240 static SkStream* extract_image_data(const SkBitmap& bitmap,
226 const SkIRect& srcRect, 241 const SkIRect& srcRect,
227 bool extractAlpha, bool* isTransparent) { 242 bool extractAlpha, bool* isTransparent) {
228 SkColorType colorType = bitmap.colorType(); 243 SkColorType colorType = bitmap.colorType();
229 if (extractAlpha && (kIndex_8_SkColorType == colorType || 244 if (extractAlpha && (kIndex_8_SkColorType == colorType ||
230 kRGB_565_SkColorType == colorType)) { 245 kRGB_565_SkColorType == colorType ||
246 kGray_8_SkColorType == colorType)) {
231 if (isTransparent != NULL) { 247 if (isTransparent != NULL) {
232 *isTransparent = false; 248 *isTransparent = false;
233 } 249 }
234 return NULL; 250 return NULL;
235 } 251 }
236 252
237 SkAutoLockPixels lock(bitmap); 253 SkAutoLockPixels lock(bitmap);
238 if (NULL == bitmap.getPixels()) { 254 if (NULL == bitmap.getPixels()) {
239 return NULL; 255 return NULL;
240 } 256 }
(...skipping 10 matching lines...) Expand all
251 break; 267 break;
252 case kARGB_4444_SkColorType: 268 case kARGB_4444_SkColorType:
253 stream.reset(extract_argb4444_data(bitmap, srcRect, extractAlpha, 269 stream.reset(extract_argb4444_data(bitmap, srcRect, extractAlpha,
254 &isOpaque, &transparent)); 270 &isOpaque, &transparent));
255 break; 271 break;
256 case kRGB_565_SkColorType: 272 case kRGB_565_SkColorType:
257 if (!extractAlpha) { 273 if (!extractAlpha) {
258 stream.reset(extract_rgb565_image(bitmap, srcRect)); 274 stream.reset(extract_rgb565_image(bitmap, srcRect));
259 } 275 }
260 break; 276 break;
277 case kGray_8_SkColorType:
278 if (!extractAlpha) {
279 stream.reset(extract_gray8_image(bitmap, srcRect));
280 }
281 break;
261 case kN32_SkColorType: 282 case kN32_SkColorType:
262 stream.reset(extract_argb8888_data(bitmap, srcRect, extractAlpha, 283 stream.reset(extract_argb8888_data(bitmap, srcRect, extractAlpha,
263 &isOpaque, &transparent)); 284 &isOpaque, &transparent));
264 break; 285 break;
265 case kAlpha_8_SkColorType: 286 case kAlpha_8_SkColorType:
266 if (!extractAlpha) { 287 if (!extractAlpha) {
267 stream.reset(create_black_image()); 288 stream.reset(create_black_image());
268 } else { 289 } else {
269 stream.reset(extract_a8_alpha(bitmap, srcRect, 290 stream.reset(extract_a8_alpha(bitmap, srcRect,
270 &isOpaque, &transparent)); 291 &isOpaque, &transparent));
(...skipping 426 matching lines...) Expand 10 before | Expand all | Expand 10 after
697 if (SkIRect::MakeWH(bitmap.width(), bitmap.height()) == subset) { 718 if (SkIRect::MakeWH(bitmap.width(), bitmap.height()) == subset) {
698 SkAutoTUnref<SkData> encodedData(ref_encoded_data(bitmap)); 719 SkAutoTUnref<SkData> encodedData(ref_encoded_data(bitmap));
699 if (is_jfif_jpeg(encodedData)) { 720 if (is_jfif_jpeg(encodedData)) {
700 return SkNEW_ARGS(PDFJPEGImage, 721 return SkNEW_ARGS(PDFJPEGImage,
701 (encodedData, bitmap.width(), bitmap.height())); 722 (encodedData, bitmap.width(), bitmap.height()));
702 } 723 }
703 } 724 }
704 #endif 725 #endif
705 return SkPDFImage::CreateImage(bitmap, subset); 726 return SkPDFImage::CreateImage(bitmap, subset);
706 } 727 }
OLDNEW
« no previous file with comments | « src/gpu/SkGr.cpp ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698