| OLD | NEW |
| 1 // Copyright 2013 The Chromium Authors. All rights reserved. | 1 // Copyright 2013 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 "chrome/utility/cloud_print/pwg_encoder.h" | 5 #include "chrome/utility/cloud_print/pwg_encoder.h" |
| 6 | 6 |
| 7 #include <algorithm> | 7 #include <algorithm> |
| 8 | 8 |
| 9 #include "base/big_endian.h" |
| 9 #include "base/logging.h" | 10 #include "base/logging.h" |
| 10 #include "base/memory/scoped_ptr.h" | 11 #include "base/memory/scoped_ptr.h" |
| 11 #include "chrome/utility/cloud_print/bitmap_image.h" | 12 #include "chrome/utility/cloud_print/bitmap_image.h" |
| 12 #include "net/base/big_endian.h" | |
| 13 | 13 |
| 14 namespace cloud_print { | 14 namespace cloud_print { |
| 15 | 15 |
| 16 namespace { | 16 namespace { |
| 17 | 17 |
| 18 const uint32 kBitsPerColor = 8; | 18 const uint32 kBitsPerColor = 8; |
| 19 const uint32 kColorSpace = 19; // sRGB. | 19 const uint32 kColorSpace = 19; // sRGB. |
| 20 const uint32 kColorOrder = 0; // chunky. | 20 const uint32 kColorOrder = 0; // chunky. |
| 21 const uint32 kNumColors = 3; | 21 const uint32 kNumColors = 3; |
| 22 const uint32 kBitsPerPixel = kNumColors * kBitsPerColor; | 22 const uint32 kBitsPerPixel = kNumColors * kBitsPerColor; |
| (...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 59 void PwgEncoder::EncodeDocumentHeader(std::string* output) const { | 59 void PwgEncoder::EncodeDocumentHeader(std::string* output) const { |
| 60 output->clear(); | 60 output->clear(); |
| 61 output->append(kPwgKeyword, 4); | 61 output->append(kPwgKeyword, 4); |
| 62 } | 62 } |
| 63 | 63 |
| 64 void PwgEncoder::EncodePageHeader(const BitmapImage& image, const uint32 dpi, | 64 void PwgEncoder::EncodePageHeader(const BitmapImage& image, const uint32 dpi, |
| 65 const uint32 total_pages, | 65 const uint32 total_pages, |
| 66 std::string* output) const { | 66 std::string* output) const { |
| 67 char header[kHeaderSize]; | 67 char header[kHeaderSize]; |
| 68 memset(header, 0, kHeaderSize); | 68 memset(header, 0, kHeaderSize); |
| 69 net::WriteBigEndian<uint32>(header + kHeaderHwResolutionHorizontal, dpi); | 69 base::WriteBigEndian<uint32>(header + kHeaderHwResolutionHorizontal, dpi); |
| 70 net::WriteBigEndian<uint32>(header + kHeaderHwResolutionVertical, dpi); | 70 base::WriteBigEndian<uint32>(header + kHeaderHwResolutionVertical, dpi); |
| 71 net::WriteBigEndian<uint32>(header + kHeaderCupsWidth, image.size().width()); | 71 base::WriteBigEndian<uint32>(header + kHeaderCupsWidth, image.size().width()); |
| 72 net::WriteBigEndian<uint32>(header + kHeaderCupsHeight, | 72 base::WriteBigEndian<uint32>(header + kHeaderCupsHeight, |
| 73 image.size().height()); | 73 image.size().height()); |
| 74 net::WriteBigEndian<uint32>(header + kHeaderCupsBitsPerColor, kBitsPerColor); | 74 base::WriteBigEndian<uint32>(header + kHeaderCupsBitsPerColor, kBitsPerColor); |
| 75 net::WriteBigEndian<uint32>(header + kHeaderCupsBitsPerPixel, kBitsPerPixel); | 75 base::WriteBigEndian<uint32>(header + kHeaderCupsBitsPerPixel, kBitsPerPixel); |
| 76 net::WriteBigEndian<uint32>(header + kHeaderCupsBytesPerLine, | 76 base::WriteBigEndian<uint32>(header + kHeaderCupsBytesPerLine, |
| 77 (kBitsPerPixel * image.size().width() + 7) / 8); | 77 (kBitsPerPixel * image.size().width() + 7) / 8); |
| 78 net::WriteBigEndian<uint32>(header + kHeaderCupsColorOrder, kColorOrder); | 78 base::WriteBigEndian<uint32>(header + kHeaderCupsColorOrder, kColorOrder); |
| 79 net::WriteBigEndian<uint32>(header + kHeaderCupsColorSpace, kColorSpace); | 79 base::WriteBigEndian<uint32>(header + kHeaderCupsColorSpace, kColorSpace); |
| 80 net::WriteBigEndian<uint32>(header + kHeaderCupsNumColors, kNumColors); | 80 base::WriteBigEndian<uint32>(header + kHeaderCupsNumColors, kNumColors); |
| 81 net::WriteBigEndian<uint32>(header + kHeaderPwgTotalPageCount, total_pages); | 81 base::WriteBigEndian<uint32>(header + kHeaderPwgTotalPageCount, total_pages); |
| 82 output->append(header, kHeaderSize); | 82 output->append(header, kHeaderSize); |
| 83 } | 83 } |
| 84 | 84 |
| 85 bool PwgEncoder::EncodeRowFrom32Bit(const uint8* row, const int width, | 85 bool PwgEncoder::EncodeRowFrom32Bit(const uint8* row, const int width, |
| 86 const int color_space, | 86 const int color_space, |
| 87 std::string* output) const { | 87 std::string* output) const { |
| 88 void (*pixel_encoder)(const uint8*, std::string*); | 88 void (*pixel_encoder)(const uint8*, std::string*); |
| 89 switch (color_space) { | 89 switch (color_space) { |
| 90 case BitmapImage::RGBA: | 90 case BitmapImage::RGBA: |
| 91 pixel_encoder = &encodePixelFromRGBA; | 91 pixel_encoder = &encodePixelFromRGBA; |
| (...skipping 93 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 185 // Both supported colorspaces have a 32-bit pixels information. | 185 // Both supported colorspaces have a 32-bit pixels information. |
| 186 if (!EncodeRowFrom32Bit( | 186 if (!EncodeRowFrom32Bit( |
| 187 current_row, image.size().width(), image.colorspace(), output)) { | 187 current_row, image.size().width(), image.colorspace(), output)) { |
| 188 return false; | 188 return false; |
| 189 } | 189 } |
| 190 } | 190 } |
| 191 return true; | 191 return true; |
| 192 } | 192 } |
| 193 | 193 |
| 194 } // namespace cloud_print | 194 } // namespace cloud_print |
| OLD | NEW |