00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00018
00019 #ifndef NET_INSTAWEB_REWRITER_PUBLIC_IMAGE_DATA_LOOKUP_H_
00020 #define NET_INSTAWEB_REWRITER_PUBLIC_IMAGE_DATA_LOOKUP_H_
00021
00022 #include <cstddef>
00023 #include "net/instaweb/util/public/basictypes.h"
00024 #include "net/instaweb/util/public/string_util.h"
00025
00026 namespace net_instaweb {
00027
00031
00033 inline int CharToInt(char c) {
00034 uint8 uc = static_cast<uint8>(c);
00035 return static_cast<int>(uc);
00036 }
00037
00038 inline int JpegIntAtPosition(const StringPiece& buf, size_t pos) {
00039 return (CharToInt(buf[pos]) << 8) |
00040 (CharToInt(buf[pos + 1]));
00041 }
00042
00043 inline int GifIntAtPosition(const StringPiece& buf, size_t pos) {
00044 return (CharToInt(buf[pos + 1]) << 8) |
00045 (CharToInt(buf[pos]));
00046 }
00047
00048 inline int PngIntAtPosition(const StringPiece& buf, size_t pos) {
00049 return (CharToInt(buf[pos ]) << 24) |
00050 (CharToInt(buf[pos + 1]) << 16) |
00051 (CharToInt(buf[pos + 2]) << 8) |
00052 (CharToInt(buf[pos + 3]));
00053 }
00054
00055 inline bool PngSectionIdIs(const char* hdr,
00056 const StringPiece& buf, size_t pos) {
00057 return ((buf[pos + 4] == hdr[0]) &&
00058 (buf[pos + 5] == hdr[1]) &&
00059 (buf[pos + 6] == hdr[2]) &&
00060 (buf[pos + 7] == hdr[3]));
00061 }
00062
00063 namespace ImageHeaders {
00065 extern const char kPngHeader[];
00066 extern const size_t kPngHeaderLength;
00067 extern const char kPngIHDR[];
00068 extern const size_t kPngIHDRLength;
00069 extern const size_t kIHDRDataStart;
00070 extern const size_t kPngIntSize;
00071
00072 extern const char kGifHeader[];
00073 extern const size_t kGifHeaderLength;
00074 extern const size_t kGifDimStart;
00075 extern const size_t kGifIntSize;
00076
00077 extern const size_t kJpegIntSize;
00078 }
00079
00080 }
00081
00082 #endif ///< NET_INSTAWEB_REWRITER_PUBLIC_IMAGE_DATA_LOOKUP_H_