Page Speed Optimization Libraries  1.13.35.1
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
image_data_lookup.h
Go to the documentation of this file.
1 /*
2  * Copyright 2011 Google Inc.
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  * http:///www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */
16 
18 
19 #ifndef NET_INSTAWEB_REWRITER_PUBLIC_IMAGE_DATA_LOOKUP_H_
20 #define NET_INSTAWEB_REWRITER_PUBLIC_IMAGE_DATA_LOOKUP_H_
21 
22 #include <cstddef>
25 
26 namespace net_instaweb {
27 
31 
33 inline int CharToInt(char c) {
34  uint8 uc = static_cast<uint8>(c);
35  return static_cast<int>(uc);
36 }
37 
38 inline int JpegIntAtPosition(const StringPiece& buf, size_t pos) {
39  return (CharToInt(buf[pos]) << 8) |
40  (CharToInt(buf[pos + 1]));
41 }
42 
43 inline int GifIntAtPosition(const StringPiece& buf, size_t pos) {
44  return (CharToInt(buf[pos + 1]) << 8) |
45  (CharToInt(buf[pos]));
46 }
47 
48 inline int PngIntAtPosition(const StringPiece& buf, size_t pos) {
49  return (CharToInt(buf[pos ]) << 24) |
50  (CharToInt(buf[pos + 1]) << 16) |
51  (CharToInt(buf[pos + 2]) << 8) |
52  (CharToInt(buf[pos + 3]));
53 }
54 
55 inline bool PngSectionIdIs(const char* hdr,
56  const StringPiece& buf, size_t pos) {
57  return ((buf[pos + 4] == hdr[0]) &&
58  (buf[pos + 5] == hdr[1]) &&
59  (buf[pos + 6] == hdr[2]) &&
60  (buf[pos + 7] == hdr[3]));
61 }
62 
63 namespace ImageHeaders {
65  extern const char kPngHeader[];
66  extern const size_t kPngHeaderLength;
67  extern const char kPngIHDR[];
68  extern const size_t kPngIHDRLength;
69  extern const size_t kIHDRDataStart;
70  extern const size_t kPngIntSize;
71 
72  extern const char kGifHeader[];
73  extern const size_t kGifHeaderLength;
74  extern const size_t kGifDimStart;
75  extern const size_t kGifIntSize;
76 
77  extern const size_t kJpegIntSize;
78 }
79 
80 }
81 
82 #endif
int CharToInt(char c)
char to int without sign extension.
Definition: image_data_lookup.h:33