| OLD | NEW |
| (Empty) |
| 1 // Copyright (c) 2006-2008 The Chromium Authors. All rights reserved. | |
| 2 // Use of this source code is governed by a BSD-style license that can be | |
| 3 // found in the LICENSE file. | |
| 4 | |
| 5 #ifndef BASE_GFX_PNG_DECODER_H_ | |
| 6 #define BASE_GFX_PNG_DECODER_H_ | |
| 7 | |
| 8 #include <vector> | |
| 9 | |
| 10 #include "base/basictypes.h" | |
| 11 | |
| 12 class SkBitmap; | |
| 13 | |
| 14 // Interface for decoding PNG data. This is a wrapper around libpng, | |
| 15 // which has an inconvenient interface for callers. This is currently designed | |
| 16 // for use in tests only (where we control the files), so the handling isn't as | |
| 17 // robust as would be required for a browser (see Decode() for more). WebKit | |
| 18 // has its own more complicated PNG decoder which handles, among other things, | |
| 19 // partially downloaded data. | |
| 20 class PNGDecoder { | |
| 21 public: | |
| 22 enum ColorFormat { | |
| 23 // 3 bytes per pixel (packed), in RGB order regardless of endianness. | |
| 24 // This is the native JPEG format. | |
| 25 FORMAT_RGB, | |
| 26 | |
| 27 // 4 bytes per pixel, in RGBA order in memory regardless of endianness. | |
| 28 FORMAT_RGBA, | |
| 29 | |
| 30 // 4 bytes per pixel, in BGRA order in memory regardless of endianness. | |
| 31 // This is the default Windows DIB order. | |
| 32 FORMAT_BGRA | |
| 33 }; | |
| 34 | |
| 35 // Decodes the PNG data contained in input of length input_size. The | |
| 36 // decoded data will be placed in *output with the dimensions in *w and *h | |
| 37 // on success (returns true). This data will be written in the 'format' | |
| 38 // format. On failure, the values of these output variables are undefined. | |
| 39 // | |
| 40 // This function may not support all PNG types, and it hasn't been tested | |
| 41 // with a large number of images, so assume a new format may not work. It's | |
| 42 // really designed to be able to read in something written by Encode() above. | |
| 43 static bool Decode(const unsigned char* input, size_t input_size, | |
| 44 ColorFormat format, std::vector<unsigned char>* output, | |
| 45 int* w, int* h); | |
| 46 | |
| 47 // A convenience function for decoding PNGs as previously encoded by the PNG | |
| 48 // encoder. Chrome encodes png in the format PNGDecoder::FORMAT_BGRA. | |
| 49 // | |
| 50 // Returns true if data is non-null and can be decoded as a png, false | |
| 51 // otherwise. | |
| 52 static bool Decode(const std::vector<unsigned char>* data, SkBitmap* icon); | |
| 53 | |
| 54 // Create a SkBitmap from a decoded BGRA DIB. The caller owns the returned | |
| 55 // SkBitmap. | |
| 56 static SkBitmap* CreateSkBitmapFromBGRAFormat( | |
| 57 std::vector<unsigned char>& bgra, int width, int height); | |
| 58 | |
| 59 private: | |
| 60 DISALLOW_COPY_AND_ASSIGN(PNGDecoder); | |
| 61 }; | |
| 62 | |
| 63 #endif // BASE_GFX_PNG_DECODER_H_ | |
| OLD | NEW |