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

Unified Diff: chrome/utility/cloud_print/pwg_encoder.cc

Issue 214243006: Minimal patch to add rotation to PWG raster generation (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 6 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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « chrome/utility/cloud_print/pwg_encoder.h ('k') | chrome/utility/cloud_print/pwg_encoder_unittest.cc » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: chrome/utility/cloud_print/pwg_encoder.cc
diff --git a/chrome/utility/cloud_print/pwg_encoder.cc b/chrome/utility/cloud_print/pwg_encoder.cc
index 1e331162adf137a6f3a8e250d13aee97fedfb564..c4aeded2e34f72d833e949217099478af4e28dfe 100644
--- a/chrome/utility/cloud_print/pwg_encoder.cc
+++ b/chrome/utility/cloud_print/pwg_encoder.cc
@@ -40,6 +40,10 @@ const int kPwgMaxPackedRows = 256;
const int kPwgMaxPackedPixels = 128;
+inline int FlipIfNeeded(bool flip, int current, int total) {
+ return flip ? total - current : current;
+}
+
} // namespace
PwgEncoder::PwgEncoder() {}
@@ -158,7 +162,8 @@ inline const uint8* PwgEncoder::GetRow(const BitmapImage& image,
bool PwgEncoder::EncodePage(const BitmapImage& image,
const uint32 dpi,
const uint32 total_pages,
- std::string* output) const {
+ std::string* output,
+ bool rotate) const {
// For now only some 4-channel colorspaces are supported.
if (image.channels() != 4) {
LOG(ERROR) << "Unsupported colorspace.";
@@ -168,20 +173,32 @@ bool PwgEncoder::EncodePage(const BitmapImage& image,
EncodePageHeader(image, dpi, total_pages, output);
int row_size = image.size().width() * image.channels();
+ scoped_ptr<uint8[]> current_row_cpy(new uint8[row_size]);
int row_number = 0;
- while (row_number < image.size().height()) {
- const uint8* current_row = GetRow(image, row_number++);
+ int total_rows = image.size().height();
+ while (row_number < total_rows) {
+ const uint8* current_row =
+ GetRow(image, FlipIfNeeded(rotate, row_number++, total_rows));
int num_identical_rows = 1;
// We count how many times the current row is repeated.
- while (num_identical_rows < kPwgMaxPackedRows
- && row_number < image.size().height()
- && !memcmp(current_row, GetRow(image, row_number), row_size)) {
+ while (num_identical_rows < kPwgMaxPackedRows &&
+ row_number < image.size().height() &&
+ !memcmp(current_row,
+ GetRow(image, FlipIfNeeded(rotate, row_number, total_rows)),
+ row_size)) {
num_identical_rows++;
row_number++;
}
output->push_back(static_cast<char>(num_identical_rows - 1));
+ if (rotate) {
+ memcpy(current_row_cpy.get(), current_row, row_size);
+ std::reverse(reinterpret_cast<uint32*>(current_row_cpy.get()),
+ reinterpret_cast<uint32*>(current_row_cpy.get() + row_size));
+ current_row = current_row_cpy.get();
+ }
+
// Both supported colorspaces have a 32-bit pixels information.
if (!EncodeRowFrom32Bit(
current_row, image.size().width(), image.colorspace(), output)) {
« no previous file with comments | « chrome/utility/cloud_print/pwg_encoder.h ('k') | chrome/utility/cloud_print/pwg_encoder_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698