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

Side by Side Diff: pdf/pdfium/pdfium_engine.cc

Issue 2947533002: Potentially do less work in PDFiumEngine::CreateSinglePageRasterPdf(). (Closed)
Patch Set: Created 3 years, 6 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 | 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 // Copyright (c) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "pdf/pdfium/pdfium_engine.h" 5 #include "pdf/pdfium/pdfium_engine.h"
6 6
7 #include <math.h> 7 #include <math.h>
8 #include <stddef.h> 8 #include <stddef.h>
9 #include <stdint.h> 9 #include <stdint.h>
10 10
(...skipping 1398 matching lines...) Expand 10 before | Expand all | Expand 10 after
1409 static_cast<unsigned char*>(FPDFBitmap_GetBuffer(bitmap)); 1409 static_cast<unsigned char*>(FPDFBitmap_GetBuffer(bitmap));
1410 double ratio_x = ConvertUnitDouble(bitmap_size.width(), print_settings.dpi, 1410 double ratio_x = ConvertUnitDouble(bitmap_size.width(), print_settings.dpi,
1411 kPointsPerInch); 1411 kPointsPerInch);
1412 double ratio_y = ConvertUnitDouble(bitmap_size.height(), print_settings.dpi, 1412 double ratio_y = ConvertUnitDouble(bitmap_size.height(), print_settings.dpi,
1413 kPointsPerInch); 1413 kPointsPerInch);
1414 1414
1415 // Add the bitmap to an image object and add the image object to the output 1415 // Add the bitmap to an image object and add the image object to the output
1416 // page. 1416 // page.
1417 FPDF_PAGEOBJECT temp_img = FPDFPageObj_NewImageObj(temp_doc); 1417 FPDF_PAGEOBJECT temp_img = FPDFPageObj_NewImageObj(temp_doc);
1418 1418
1419 bool encoded = false;
1419 std::vector<uint8_t> compressed_bitmap_data; 1420 std::vector<uint8_t> compressed_bitmap_data;
1420 // Use quality = 40 as this does not significantly degrade the printed 1421 if (!(print_settings.format & PP_PRINTOUTPUTFORMAT_PDF)) {
1421 // document relative to a normal bitmap and provides better compression than 1422 // Use quality = 40 as this does not significantly degrade the printed
1422 // a higher quality setting. 1423 // document relative to a normal bitmap and provides better compression than
1423 const int quality = 40; 1424 // a higher quality setting.
1424 SkImageInfo info = SkImageInfo::Make( 1425 const int kQuality = 40;
1425 FPDFBitmap_GetWidth(bitmap), FPDFBitmap_GetHeight(bitmap), 1426 SkImageInfo info = SkImageInfo::Make(
1426 kBGRA_8888_SkColorType, kOpaque_SkAlphaType); 1427 FPDFBitmap_GetWidth(bitmap), FPDFBitmap_GetHeight(bitmap),
1427 SkPixmap src(info, bitmap_data, FPDFBitmap_GetStride(bitmap)); 1428 kBGRA_8888_SkColorType, kOpaque_SkAlphaType);
1428 if (!(print_settings.format & PP_PRINTOUTPUTFORMAT_PDF) && 1429 SkPixmap src(info, bitmap_data, FPDFBitmap_GetStride(bitmap));
1429 (gfx::JPEGCodec::Encode(src, quality, &compressed_bitmap_data))) { 1430 encoded = gfx::JPEGCodec::Encode(src, kQuality, &compressed_bitmap_data);
1431 }
1432 if (encoded) {
1430 FPDF_FILEACCESS file_access = {}; 1433 FPDF_FILEACCESS file_access = {};
1431 file_access.m_FileLen = 1434 file_access.m_FileLen =
1432 static_cast<unsigned long>(compressed_bitmap_data.size()); 1435 static_cast<unsigned long>(compressed_bitmap_data.size());
1433 file_access.m_GetBlock = &GetBlockForJpeg; 1436 file_access.m_GetBlock = &GetBlockForJpeg;
1434 file_access.m_Param = &compressed_bitmap_data; 1437 file_access.m_Param = &compressed_bitmap_data;
1435 1438
1436 FPDFImageObj_LoadJpegFileInline(&temp_page, 1, temp_img, &file_access); 1439 FPDFImageObj_LoadJpegFileInline(&temp_page, 1, temp_img, &file_access);
1437 } else { 1440 } else {
1438 FPDFImageObj_SetBitmap(&temp_page, 1, temp_img, bitmap); 1441 FPDFImageObj_SetBitmap(&temp_page, 1, temp_img, bitmap);
1439 } 1442 }
(...skipping 2695 matching lines...) Expand 10 before | Expand all | Expand 10 after
4135 FPDF_DOCUMENT doc = 4138 FPDF_DOCUMENT doc =
4136 FPDF_LoadMemDocument(pdf_buffer, pdf_buffer_size, nullptr); 4139 FPDF_LoadMemDocument(pdf_buffer, pdf_buffer_size, nullptr);
4137 if (!doc) 4140 if (!doc)
4138 return false; 4141 return false;
4139 bool success = FPDF_GetPageSizeByIndex(doc, page_number, width, height) != 0; 4142 bool success = FPDF_GetPageSizeByIndex(doc, page_number, width, height) != 0;
4140 FPDF_CloseDocument(doc); 4143 FPDF_CloseDocument(doc);
4141 return success; 4144 return success;
4142 } 4145 }
4143 4146
4144 } // namespace chrome_pdf 4147 } // namespace chrome_pdf
OLDNEW
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698