Page Speed Optimization Libraries
1.7.30.1
|
00001 /* 00002 * Copyright 2011 Google Inc. 00003 * 00004 * Licensed under the Apache License, Version 2.0 (the "License"); 00005 * you may not use this file except in compliance with the License. 00006 * You may obtain a copy of the License at 00007 * 00008 * http:///www.apache.org/licenses/LICENSE-2.0 00009 * 00010 * Unless required by applicable law or agreed to in writing, software 00011 * distributed under the License is distributed on an "AS IS" BASIS, 00012 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 00013 * See the License for the specific language governing permissions and 00014 * limitations under the License. 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_