19 #ifndef PAGESPEED_KERNEL_IMAGE_PNG_OPTIMIZER_H_
20 #define PAGESPEED_KERNEL_IMAGE_PNG_OPTIMIZER_H_
26 #ifdef USE_SYSTEM_LIBPNG
29 #include "third_party/libpng/src/png.h"
36 #include "third_party/optipng/src/opngreduc/opngreduc.h"
44 namespace net_instaweb {
50 namespace image_compression {
54 class ScanlineStreamInput;
96 bool valid()
const {
return png_ptr_ != NULL && info_ptr_ != NULL; }
102 png_structp png_ptr()
const {
return png_ptr_; }
103 png_infop info_ptr()
const {
return info_ptr_; }
106 png_structp png_ptr_;
128 bool require_opaque)
const = 0;
136 int transforms)
const {
137 return ReadPng(body, png_ptr, info_ptr, transforms,
false);
148 int* out_color_type)
const = 0;
154 png_structp png_ptr, png_infop info_ptr,
155 unsigned char *red,
unsigned char* green,
unsigned char* blue,
189 jmp_buf* GetJmpBuf();
193 virtual bool Reset();
208 void set_transform(
int transform);
209 void set_require_opaque(
bool require_opaque);
211 bool GetBackgroundColor(
212 unsigned char* red,
unsigned char* green,
unsigned char* blue);
216 size_t buffer_length);
220 size_t current_scanline_;
222 bool require_opaque_;
256 void EnableBestCompression() { best_compression_ =
true; }
259 bool CopyReadToWrite();
261 size_t param_list_size,
268 bool best_compression_;
283 bool require_opaque)
const;
289 int* out_color_type)
const;
318 virtual bool Reset();
323 size_t buffer_length);
342 PixelFormat pixel_format_;
343 bool is_progressive_;
346 size_t bytes_per_row_;
348 bool was_initialized_;
371 PixelFormat pixel_format);
381 const void *scanline_bytes);
396 bool DoBestCompression();
401 size_t bytes_per_row_;
403 PixelFormat pixel_format_;
405 bool was_initialized_;
406 bool try_best_compression_;
Definition: png_optimizer.h:228
Definition: scanline_status.h:93
bool is_progressive
Indicates whether to encode the image in progressive / interlacing format.
Definition: png_optimizer.h:82
virtual bool ReadPng(const GoogleString &body, png_structp png_ptr, png_infop info_ptr, int transforms, bool require_opaque) const
virtual bool IsProgressive()
Definition: png_optimizer.h:339
Definition: png_optimizer.h:184
virtual bool HasMoreScanLines()
Returns true if there are more scanlines to read.
Definition: png_optimizer.h:335
bool InitializeRead(const PngReaderInterface &reader, const GoogleString &in)
Initializes the read structures with the given input.
virtual size_t GetImageWidth()
Returns the width of the image.
Definition: png_optimizer.h:338
Definition: scanline_interface.h:83
virtual bool ReadPng(const GoogleString &body, png_structp png_ptr, png_infop info_ptr, int transforms, bool require_opaque) const =0
virtual ScanlineStatus FinalizeWriteWithStatus()
virtual ScanlineStatus InitializeWithStatus(const void *image_buffer, size_t buffer_length)
This is a no-op and should not be called.
Helper that manages the lifetime of the png_ptr and info_ptr.
Definition: png_optimizer.h:86
Definition: scoped_ptr.h:30
bool try_best_compression
Definition: png_optimizer.h:80
Definition: png_optimizer.h:363
std::string GoogleString
PAGESPEED_KERNEL_BASE_STRING_H_.
Definition: string.h:24
virtual bool GetAttributes(const GoogleString &body, int *out_width, int *out_height, int *out_bit_depth, int *out_color_type) const
virtual size_t GetImageHeight()
Returns the height of the image.
virtual ScanlineStatus InitializeWriteWithStatus(const void *params, GoogleString *png_image)
Definition: png_optimizer.h:56
virtual size_t GetBytesPerScanline()
Return the number of bytes in a row (without padding).
Definition: png_optimizer.h:333
virtual ScanlineStatus InitWithStatus(const size_t width, const size_t height, PixelFormat pixel_format)
Definition: scanline_interface.h:32
virtual bool GetAttributes(const GoogleString &body, int *out_width, int *out_height, int *out_bit_depth, int *out_color_type) const =0
virtual size_t GetBytesPerScanline()
Returns number of bytes that required to store a scanline.
bool ReadPng(const GoogleString &body, png_structp png_ptr, png_infop info_ptr, int transforms) const
Definition: png_optimizer.h:133
virtual ScanlineStatus WriteNextScanlineWithStatus(const void *scanline_bytes)
Write a scanline with the data provided. Return false in case of error.
Reader for PNG-encoded data.
Definition: png_optimizer.h:275
int compression_strategy
Definition: png_optimizer.h:77
virtual PixelFormat GetPixelFormat()
Returns the pixel format that need to be used by writer.
Definition: png_optimizer.h:336
virtual ScanlineStatus InitializeWithStatus(const void *image_buffer, size_t buffer_length)
virtual size_t GetImageWidth()
Returns the width of the image.
Definition: image_util.h:198
Definition: message_handler.h:39
virtual bool HasMoreScanLines()
Returns true if there are more scanlines to read.
virtual size_t GetImageHeight()
Returns the height of the image.
Definition: png_optimizer.h:337
static bool GetBackgroundColor(png_structp png_ptr, png_infop info_ptr, unsigned char *red, unsigned char *green, unsigned char *blue, MessageHandler *handler)
virtual ScanlineStatus ReadNextScanlineWithStatus(void **out_scanline_bytes)
virtual bool IsProgressive()
virtual PixelFormat GetPixelFormat()
Returns the pixel format that need to be used by writer.
Definition: png_optimizer.h:114
Definition: png_optimizer.h:311
virtual ScanlineStatus ReadNextScanlineWithStatus(void **out_scanline_bytes)
int filter_level
Definition: png_optimizer.h:69
static bool IsAlphaChannelOpaque(png_structp png_ptr, png_infop info_ptr, MessageHandler *handler)