Page Speed Optimization Libraries  1.13.35.1
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
gif_reader.h
Go to the documentation of this file.
1 /*
2  * Copyright 2009 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 PAGESPEED_KERNEL_IMAGE_GIF_READER_H_
20 #define PAGESPEED_KERNEL_IMAGE_GIF_READER_H_
21 
31 
32 extern "C" {
33 #include "third_party/giflib/lib/gif_lib.h"
34 
35 #ifdef USE_SYSTEM_LIBPNG
36 #include "png.h"
37 #else
38 #include "third_party/libpng/src/png.h"
39 #endif
40 }
41 
42 namespace pagespeed {
43 
44 namespace image_compression {
45 
47 
48 class ScopedGifStruct;
49 
52 FrameSpec::DisposalMethod GifDisposalToFrameSpecDisposal(int gif_disposal);
53 
55 class GifReader : public PngReaderInterface {
56  public:
57  explicit GifReader(MessageHandler* handler);
58  virtual ~GifReader();
59 
60  virtual bool ReadPng(const GoogleString& body,
61  png_structp png_ptr,
62  png_infop info_ptr,
63  int transforms,
64  bool require_opaque) const;
65 
66  virtual bool GetAttributes(const GoogleString& body,
67  int* out_width,
68  int* out_height,
69  int* out_bit_depth,
70  int* out_color_type) const;
71 
72  private:
73  MessageHandler* message_handler_;
74 
75 };
76 
97  public:
98  virtual ~GifFrameReader();
99 
100  virtual ScanlineStatus Reset();
101 
105  virtual ScanlineStatus Initialize();
106 
107  virtual bool HasMoreFrames() const {
108  return (image_initialized_ && (next_frame_ < image_spec_.num_frames));
109  }
110 
111  virtual bool HasMoreScanlines() const {
112  return (frame_initialized_ && (next_row_ < frame_spec_.height));
113  }
114 
116 
121  virtual ScanlineStatus ReadNextScanline(const void** out_scanline_bytes);
122 
123  virtual ScanlineStatus GetFrameSpec(FrameSpec* frame_spec) const {
124  if (frame_spec == NULL) {
126  SCANLINE_STATUS_INVOCATION_ERROR,
127  FRAME_GIFREADER,
128  "Unexpected NULL pointer.");
129  }
130  *frame_spec = frame_spec_;
131  return ScanlineStatus(SCANLINE_STATUS_SUCCESS);
132  }
133 
134  virtual ScanlineStatus GetImageSpec(ImageSpec* image_spec) const {
135  if (image_spec == NULL) {
137  SCANLINE_STATUS_INVOCATION_ERROR,
138  FRAME_GIFREADER,
139  "Unexpected NULL pointer.");
140  }
141  *image_spec = image_spec_;
142  return ScanlineStatus(SCANLINE_STATUS_SUCCESS);
143  }
144 
145  virtual ScanlineStatus set_quirks_mode(QuirksMode quirks_mode);
146 
150  static void ApplyQuirksModeToImage(QuirksMode quirks_mode,
151  bool has_loop_count,
152  const FrameSpec& frame_spec,
153  ImageSpec* image_spec);
154 
157  static void ApplyQuirksModeToFirstFrame(QuirksMode quirks_mode,
158  const ImageSpec& image_spec,
159  FrameSpec* frame_spec);
160 
161  private:
165  ImageFormat image_type,
166  MessageHandler* handler,
167  ScanlineStatus* status);
168 
170  friend class TestGifFrameReader;
171 
174  explicit GifFrameReader(MessageHandler* handler);
175 
180  static const int kNoTransparentIndex;
181 
182 
184  ScanlineStatus DecodeProgressiveGif();
185 
187  ScanlineStatus DecodeNonProgressiveGif();
188 
189  ScanlineStatus CreateColorMap();
190 
194  ScanlineStatus GetImageData();
195 
198  ScanlineStatus ProcessExtensionAffectingImage(bool past_first_frame);
199 
203  ScanlineStatus ProcessExtensionAffectingFrame();
204 
206  bool image_initialized_;
207 
209  bool frame_initialized_;
210 
212  ImageSpec image_spec_;
213 
215  FrameSpec frame_spec_;
216 
218  bool has_loop_count_;
219 
221  size_px next_frame_;
222 
224 
226  size_px next_row_;
227 
230  int frame_transparent_index_;
231 
234 
237 
241 
247 
255  int frame_palette_size_;
256 
264  bool frame_eagerly_read_;
265 
266 
267 };
268 
269 }
270 
271 }
272 
273 #endif
Reader for GIF-encoded data.
Definition: gif_reader.h:55
Definition: scanline_status.h:93
virtual bool HasMoreScanlines() const
Definition: gif_reader.h:111
static void ApplyQuirksModeToFirstFrame(QuirksMode quirks_mode, const ImageSpec &image_spec, FrameSpec *frame_spec)
Definition: image_frame_interface.h:146
MessageHandler * message_handler() const
Definition: image_frame_interface.h:203
Definition: scoped_ptr.h:47
friend class TestGifFrameReader
Used in gif_reader_test.cc and frame_interface_integration_test.cc.
Definition: gif_reader.h:170
virtual bool ReadPng(const GoogleString &body, png_structp png_ptr, png_infop info_ptr, int transforms, bool require_opaque) const
#define PS_LOGGED_STATUS(_LOGGER, _HANDLER, _TYPE, _SOURCE,...)
Definition: scanline_status.h:189
virtual ScanlineStatus Reset()
Resets the MultipleFrameReader to its initial state.
std::string GoogleString
PAGESPEED_KERNEL_BASE_STRING_H_.
Definition: string.h:24
virtual ScanlineStatus GetImageSpec(ImageSpec *image_spec) const
Definition: gif_reader.h:134
virtual bool GetAttributes(const GoogleString &body, int *out_width, int *out_height, int *out_bit_depth, int *out_color_type) const
static void ApplyQuirksModeToImage(QuirksMode quirks_mode, bool has_loop_count, const FrameSpec &frame_spec, ImageSpec *image_spec)
Definition: image_frame_interface.h:43
Definition: image_frame_interface.h:79
virtual bool HasMoreFrames() const
Definition: gif_reader.h:107
Definition: message_handler.h:39
virtual ScanlineStatus GetFrameSpec(FrameSpec *frame_spec) const
Definition: gif_reader.h:123
DisposalMethod
Definition: image_frame_interface.h:80
virtual ScanlineStatus ReadNextScanline(const void **out_scanline_bytes)
#define PS_LOG_DFATAL(handler,...)
NDEBUG.
Definition: message_handler.h:150
friend MultipleFrameReader * InstantiateImageFrameReader(ImageFormat image_type, MessageHandler *handler, ScanlineStatus *status)