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

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

Issue 1304493002: SkPDF: Simplify PDFStream / emitObject() const (Closed) Base URL: https://skia.googlesource.com/skia.git@master
Patch Set: formatting Created 5 years, 4 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 | « no previous file | src/pdf/SkPDFFont.cpp » ('j') | 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 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"
(...skipping 231 matching lines...) Expand 10 before | Expand all | Expand 10 after
242 //////////////////////////////////////////////////////////////////////////////// 242 ////////////////////////////////////////////////////////////////////////////////
243 243
244 namespace { 244 namespace {
245 // This SkPDFObject only outputs the alpha layer of the given bitmap. 245 // This SkPDFObject only outputs the alpha layer of the given bitmap.
246 class PDFAlphaBitmap : public SkPDFObject { 246 class PDFAlphaBitmap : public SkPDFObject {
247 public: 247 public:
248 PDFAlphaBitmap(const SkBitmap& bm) : fBitmap(bm) {} 248 PDFAlphaBitmap(const SkBitmap& bm) : fBitmap(bm) {}
249 ~PDFAlphaBitmap() {} 249 ~PDFAlphaBitmap() {}
250 void emitObject(SkWStream*, 250 void emitObject(SkWStream*,
251 const SkPDFObjNumMap&, 251 const SkPDFObjNumMap&,
252 const SkPDFSubstituteMap&) override; 252 const SkPDFSubstituteMap&) const override;
253 253
254 private: 254 private:
255 const SkBitmap fBitmap; 255 const SkBitmap fBitmap;
256 }; 256 };
257 257
258 void PDFAlphaBitmap::emitObject(SkWStream* stream, 258 void PDFAlphaBitmap::emitObject(SkWStream* stream,
259 const SkPDFObjNumMap& objNumMap, 259 const SkPDFObjNumMap& objNumMap,
260 const SkPDFSubstituteMap& substitutes) { 260 const SkPDFSubstituteMap& substitutes) const {
261 SkAutoLockPixels autoLockPixels(fBitmap); 261 SkAutoLockPixels autoLockPixels(fBitmap);
262 SkASSERT(fBitmap.colorType() != kIndex_8_SkColorType || 262 SkASSERT(fBitmap.colorType() != kIndex_8_SkColorType ||
263 fBitmap.getColorTable()); 263 fBitmap.getColorTable());
264 264
265 // Write to a temporary buffer to get the compressed length. 265 // Write to a temporary buffer to get the compressed length.
266 SkDynamicMemoryWStream buffer; 266 SkDynamicMemoryWStream buffer;
267 SkDeflateWStream deflateWStream(&buffer); 267 SkDeflateWStream deflateWStream(&buffer);
268 bitmap_alpha_to_a8(fBitmap, &deflateWStream); 268 bitmap_alpha_to_a8(fBitmap, &deflateWStream);
269 deflateWStream.finalize(); // call before detachAsStream(). 269 deflateWStream.finalize(); // call before detachAsStream().
270 SkAutoTDelete<SkStreamAsset> asset(buffer.detachAsStream()); 270 SkAutoTDelete<SkStreamAsset> asset(buffer.detachAsStream());
(...skipping 15 matching lines...) Expand all
286 } // namespace 286 } // namespace
287 287
288 //////////////////////////////////////////////////////////////////////////////// 288 ////////////////////////////////////////////////////////////////////////////////
289 289
290 namespace { 290 namespace {
291 class PDFDefaultBitmap : public SkPDFBitmap { 291 class PDFDefaultBitmap : public SkPDFBitmap {
292 public: 292 public:
293 const SkAutoTUnref<SkPDFObject> fSMask; 293 const SkAutoTUnref<SkPDFObject> fSMask;
294 void emitObject(SkWStream*, 294 void emitObject(SkWStream*,
295 const SkPDFObjNumMap&, 295 const SkPDFObjNumMap&,
296 const SkPDFSubstituteMap&) override; 296 const SkPDFSubstituteMap&) const override;
297 void addResources(SkPDFObjNumMap*, 297 void addResources(SkPDFObjNumMap*,
298 const SkPDFSubstituteMap&) const override; 298 const SkPDFSubstituteMap&) const override;
299 PDFDefaultBitmap(const SkBitmap& bm, SkPDFObject* smask) 299 PDFDefaultBitmap(const SkBitmap& bm, SkPDFObject* smask)
300 : SkPDFBitmap(bm), fSMask(smask) {} 300 : SkPDFBitmap(bm), fSMask(smask) {}
301 }; 301 };
302 } // namespace 302 } // namespace
303 303
304 void PDFDefaultBitmap::addResources( 304 void PDFDefaultBitmap::addResources(
305 SkPDFObjNumMap* catalog, 305 SkPDFObjNumMap* catalog,
306 const SkPDFSubstituteMap& substitutes) const { 306 const SkPDFSubstituteMap& substitutes) const {
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after
338 pmcolor_to_rgb24(colors[i], tablePtr); 338 pmcolor_to_rgb24(colors[i], tablePtr);
339 tablePtr += 3; 339 tablePtr += 3;
340 } 340 }
341 SkString tableString(tableArray, 3 * table->count()); 341 SkString tableString(tableArray, 3 * table->count());
342 result->appendString(tableString); 342 result->appendString(tableString);
343 return result; 343 return result;
344 } 344 }
345 345
346 void PDFDefaultBitmap::emitObject(SkWStream* stream, 346 void PDFDefaultBitmap::emitObject(SkWStream* stream,
347 const SkPDFObjNumMap& objNumMap, 347 const SkPDFObjNumMap& objNumMap,
348 const SkPDFSubstituteMap& substitutes) { 348 const SkPDFSubstituteMap& substitutes) const {
349 SkAutoLockPixels autoLockPixels(fBitmap); 349 SkAutoLockPixels autoLockPixels(fBitmap);
350 SkASSERT(fBitmap.colorType() != kIndex_8_SkColorType || 350 SkASSERT(fBitmap.colorType() != kIndex_8_SkColorType ||
351 fBitmap.getColorTable()); 351 fBitmap.getColorTable());
352 352
353 // Write to a temporary buffer to get the compressed length. 353 // Write to a temporary buffer to get the compressed length.
354 SkDynamicMemoryWStream buffer; 354 SkDynamicMemoryWStream buffer;
355 SkDeflateWStream deflateWStream(&buffer); 355 SkDeflateWStream deflateWStream(&buffer);
356 bitmap_to_pdf_pixels(fBitmap, &deflateWStream); 356 bitmap_to_pdf_pixels(fBitmap, &deflateWStream);
357 deflateWStream.finalize(); // call before detachAsStream(). 357 deflateWStream.finalize(); // call before detachAsStream().
358 SkAutoTDelete<SkStreamAsset> asset(buffer.detachAsStream()); 358 SkAutoTDelete<SkStreamAsset> asset(buffer.detachAsStream());
(...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after
400 * Jpeg-encoded data that can be directly embedded into a PDF. 400 * Jpeg-encoded data that can be directly embedded into a PDF.
401 */ 401 */
402 class PDFJpegBitmap : public SkPDFBitmap { 402 class PDFJpegBitmap : public SkPDFBitmap {
403 public: 403 public:
404 SkAutoTUnref<SkData> fData; 404 SkAutoTUnref<SkData> fData;
405 bool fIsYUV; 405 bool fIsYUV;
406 PDFJpegBitmap(const SkBitmap& bm, SkData* data, bool isYUV) 406 PDFJpegBitmap(const SkBitmap& bm, SkData* data, bool isYUV)
407 : SkPDFBitmap(bm), fData(SkRef(data)), fIsYUV(isYUV) {} 407 : SkPDFBitmap(bm), fData(SkRef(data)), fIsYUV(isYUV) {}
408 void emitObject(SkWStream*, 408 void emitObject(SkWStream*,
409 const SkPDFObjNumMap&, 409 const SkPDFObjNumMap&,
410 const SkPDFSubstituteMap&) override; 410 const SkPDFSubstituteMap&) const override;
411 }; 411 };
412 412
413 void PDFJpegBitmap::emitObject(SkWStream* stream, 413 void PDFJpegBitmap::emitObject(SkWStream* stream,
414 const SkPDFObjNumMap& objNumMap, 414 const SkPDFObjNumMap& objNumMap,
415 const SkPDFSubstituteMap& substituteMap) { 415 const SkPDFSubstituteMap& substituteMap) const {
416 SkPDFDict pdfDict("XObject"); 416 SkPDFDict pdfDict("XObject");
417 pdfDict.insertName("Subtype", "Image"); 417 pdfDict.insertName("Subtype", "Image");
418 pdfDict.insertInt("Width", fBitmap.width()); 418 pdfDict.insertInt("Width", fBitmap.width());
419 pdfDict.insertInt("Height", fBitmap.height()); 419 pdfDict.insertInt("Height", fBitmap.height());
420 if (fIsYUV) { 420 if (fIsYUV) {
421 pdfDict.insertName("ColorSpace", "DeviceRGB"); 421 pdfDict.insertName("ColorSpace", "DeviceRGB");
422 } else { 422 } else {
423 pdfDict.insertName("ColorSpace", "DeviceGray"); 423 pdfDict.insertName("ColorSpace", "DeviceGray");
424 } 424 }
425 pdfDict.insertInt("BitsPerComponent", 8); 425 pdfDict.insertInt("BitsPerComponent", 8);
(...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after
464 } 464 }
465 465
466 SkPDFObject* smask = NULL; 466 SkPDFObject* smask = NULL;
467 if (!bm.isOpaque() && !SkBitmap::ComputeIsOpaque(bm)) { 467 if (!bm.isOpaque() && !SkBitmap::ComputeIsOpaque(bm)) {
468 smask = SkNEW_ARGS(PDFAlphaBitmap, (bm)); 468 smask = SkNEW_ARGS(PDFAlphaBitmap, (bm));
469 } 469 }
470 SkPDFBitmap* pdfBitmap = SkNEW_ARGS(PDFDefaultBitmap, (bm, smask)); 470 SkPDFBitmap* pdfBitmap = SkNEW_ARGS(PDFDefaultBitmap, (bm, smask));
471 canon->addBitmap(pdfBitmap); 471 canon->addBitmap(pdfBitmap);
472 return pdfBitmap; 472 return pdfBitmap;
473 } 473 }
OLDNEW
« no previous file with comments | « no previous file | src/pdf/SkPDFFont.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698