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 "ios/chrome/browser/webp_transcode/webp_decoder.h" | 5 #include "ios/web/public/image_fetcher/webp_decoder.h" |
6 | 6 |
7 #import <Foundation/Foundation.h> | 7 #import <Foundation/Foundation.h> |
8 #include <stdint.h> | 8 #include <stdint.h> |
9 #import <UIKit/UIKit.h> | 9 #import <UIKit/UIKit.h> |
10 | 10 |
11 #include "base/logging.h" | 11 #include "base/logging.h" |
12 #include "base/metrics/histogram.h" | 12 #include "base/metrics/histogram.h" |
13 | 13 |
14 #if !defined(__has_feature) || !__has_feature(objc_arc) | 14 #if !defined(__has_feature) || !__has_feature(objc_arc) |
15 #error "This file requires ARC support." | 15 #error "This file requires ARC support." |
(...skipping 22 matching lines...) Expand all Loading... |
38 | 38 |
39 void WriteTiffHeader(uint8_t* dst, | 39 void WriteTiffHeader(uint8_t* dst, |
40 int width, | 40 int width, |
41 int height, | 41 int height, |
42 int bytes_per_px, | 42 int bytes_per_px, |
43 bool has_alpha) { | 43 bool has_alpha) { |
44 // For non-alpha case, we omit tag 0x152 (ExtraSamples). | 44 // For non-alpha case, we omit tag 0x152 (ExtraSamples). |
45 const uint8_t num_ifd_entries = | 45 const uint8_t num_ifd_entries = |
46 has_alpha ? kNumIfdEntries : kNumIfdEntries - 1; | 46 has_alpha ? kNumIfdEntries : kNumIfdEntries - 1; |
47 uint8_t tiff_header[kHeaderSize] = { | 47 uint8_t tiff_header[kHeaderSize] = { |
48 0x49, 0x49, 0x2a, 0x00, // little endian signature | 48 0x49, 0x49, 0x2a, 0x00, // little endian signature |
49 8, 0, 0, 0, // offset to the unique IFD that follows | 49 8, 0, 0, 0, // offset to the unique IFD that follows |
50 // IFD (offset = 8). Entries must be written in increasing tag order. | 50 // IFD (offset = 8). Entries must be written in increasing tag order. |
51 num_ifd_entries, 0, // Number of entries in the IFD (12 bytes each). | 51 num_ifd_entries, 0, // Number of entries in the IFD (12 bytes each). |
52 0x00, 0x01, 3, 0, 1, 0, 0, 0, 0, 0, 0, 0, // 10: Width (TBD) | 52 0x00, 0x01, 3, 0, 1, 0, 0, 0, 0, 0, 0, 0, // 10: Width (TBD) |
53 0x01, 0x01, 3, 0, 1, 0, 0, 0, 0, 0, 0, 0, // 22: Height (TBD) | 53 0x01, 0x01, 3, 0, 1, 0, 0, 0, 0, 0, 0, 0, // 22: Height (TBD) |
54 0x02, 0x01, 3, 0, bytes_per_px, 0, 0, 0, // 34: BitsPerSample: 8888 | 54 0x02, 0x01, 3, 0, bytes_per_px, 0, 0, 0, // 34: BitsPerSample: 8888 |
55 kExtraDataOffset + 0, 0, 0, 0, | 55 kExtraDataOffset + 0, 0, 0, 0, 0x03, 0x01, 3, 0, 1, 0, 0, 0, 1, 0, 0, |
56 0x03, 0x01, 3, 0, 1, 0, 0, 0, 1, 0, 0, 0, // 46: Compression: none | 56 0, // 46: Compression: none |
57 0x06, 0x01, 3, 0, 1, 0, 0, 0, 2, 0, 0, 0, // 58: Photometric: RGB | 57 0x06, 0x01, 3, 0, 1, 0, 0, 0, 2, 0, 0, 0, // 58: Photometric: RGB |
58 0x11, 0x01, 4, 0, 1, 0, 0, 0, // 70: Strips offset: | 58 0x11, 0x01, 4, 0, 1, 0, 0, 0, // 70: Strips offset: |
59 kHeaderSize, 0, 0, 0, // data follows header | 59 kHeaderSize, 0, 0, 0, // data follows header |
60 0x12, 0x01, 3, 0, 1, 0, 0, 0, 1, 0, 0, 0, // 82: Orientation: topleft | 60 0x12, 0x01, 3, 0, 1, 0, 0, 0, 1, 0, 0, 0, // 82: Orientation: topleft |
61 0x15, 0x01, 3, 0, 1, 0, 0, 0, // 94: SamplesPerPixels | 61 0x15, 0x01, 3, 0, 1, 0, 0, 0, // 94: SamplesPerPixels |
62 bytes_per_px, 0, 0, 0, | 62 bytes_per_px, 0, 0, 0, 0x16, 0x01, 3, 0, 1, 0, 0, 0, 0, 0, 0, |
63 0x16, 0x01, 3, 0, 1, 0, 0, 0, 0, 0, 0, 0, // 106: Rows per strip (TBD) | 63 0, // 106: Rows per strip (TBD) |
64 0x17, 0x01, 4, 0, 1, 0, 0, 0, 0, 0, 0, 0, // 118: StripByteCount (TBD) | 64 0x17, 0x01, 4, 0, 1, 0, 0, 0, 0, 0, 0, 0, // 118: StripByteCount (TBD) |
65 0x1a, 0x01, 5, 0, 1, 0, 0, 0, // 130: X-resolution | 65 0x1a, 0x01, 5, 0, 1, 0, 0, 0, // 130: X-resolution |
66 kExtraDataOffset + 8, 0, 0, 0, | 66 kExtraDataOffset + 8, 0, 0, 0, 0x1b, 0x01, 5, 0, 1, 0, 0, |
67 0x1b, 0x01, 5, 0, 1, 0, 0, 0, // 142: Y-resolution | 67 0, // 142: Y-resolution |
68 kExtraDataOffset + 8, 0, 0, 0, | 68 kExtraDataOffset + 8, 0, 0, 0, 0x1c, 0x01, 3, 0, 1, 0, 0, 0, 1, 0, 0, |
69 0x1c, 0x01, 3, 0, 1, 0, 0, 0, 1, 0, 0, 0, // 154: PlanarConfiguration | 69 0, // 154: PlanarConfiguration |
70 0x28, 0x01, 3, 0, 1, 0, 0, 0, 2, 0, 0, 0, // 166: ResolutionUnit (inch) | 70 0x28, 0x01, 3, 0, 1, 0, 0, 0, 2, 0, 0, 0, // 166: ResolutionUnit (inch) |
71 0x52, 0x01, 3, 0, 1, 0, 0, 0, 1, 0, 0, 0, // 178: ExtraSamples: rgbA | 71 0x52, 0x01, 3, 0, 1, 0, 0, 0, 1, 0, 0, 0, // 178: ExtraSamples: rgbA |
72 0, 0, 0, 0, // 190: IFD terminator | 72 0, 0, 0, 0, // 190: IFD terminator |
73 // kExtraDataOffset: | 73 // kExtraDataOffset: |
74 8, 0, 8, 0, 8, 0, 8, 0, // BitsPerSample | 74 8, 0, 8, 0, 8, 0, 8, 0, // BitsPerSample |
75 72, 0, 0, 0, 1, 0, 0, 0 // 72 pixels/inch, for X/Y-resolution | 75 72, 0, 0, 0, 1, 0, 0, 0 // 72 pixels/inch, for X/Y-resolution |
76 }; | 76 }; |
77 | 77 |
78 // Fill placeholders in IFD: | 78 // Fill placeholders in IFD: |
79 PutLE32(tiff_header + 10 + 8, width); | 79 PutLE32(tiff_header + 10 + 8, width); |
80 PutLE32(tiff_header + 22 + 8, height); | 80 PutLE32(tiff_header + 22 + 8, height); |
81 PutLE32(tiff_header + 106 + 8, height); | 81 PutLE32(tiff_header + 106 + 8, height); |
82 PutLE32(tiff_header + 118 + 8, width * bytes_per_px * height); | 82 PutLE32(tiff_header + 118 + 8, width * bytes_per_px * height); |
83 if (!has_alpha) | 83 if (!has_alpha) |
84 PutLE32(tiff_header + 178, 0); | 84 PutLE32(tiff_header + 178, 0); |
85 | 85 |
(...skipping 160 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
246 } | 246 } |
247 UMA_HISTOGRAM_ENUMERATION("WebP.DecodedImageFormat", format, | 247 UMA_HISTOGRAM_ENUMERATION("WebP.DecodedImageFormat", format, |
248 DECODED_FORMAT_COUNT); | 248 DECODED_FORMAT_COUNT); |
249 delegate_->SetImageFeatures([result_data length], format); | 249 delegate_->SetImageFeatures([result_data length], format); |
250 delegate_->OnDataDecoded(result_data); | 250 delegate_->OnDataDecoded(result_data); |
251 output_buffer_.reset(); | 251 output_buffer_.reset(); |
252 return true; | 252 return true; |
253 } | 253 } |
254 | 254 |
255 } // namespace webp_transcode | 255 } // namespace webp_transcode |
OLD | NEW |