Page Speed Optimization Libraries  1.13.35.1
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
jpeg_optimizer.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_JPEG_OPTIMIZER_H_
20 #define PAGESPEED_KERNEL_IMAGE_JPEG_OPTIMIZER_H_
21 
22 #include <setjmp.h>
23 #include <cstddef>
29 
32 
33 namespace net_instaweb {
34 class MessageHandler;
35 }
36 
37 namespace pagespeed {
38 
39 namespace image_compression {
40 
42 
43 enum ColorSampling {
44  RETAIN,
45  YUV420,
46  YUV422,
47  YUV444
48 };
49 
51  JpegLossyOptions() : quality(85), num_scans(-1), color_sampling(YUV420) {}
56  int quality;
57 
60  int num_scans;
61 
63  ColorSampling color_sampling;
64 };
65 
68  : progressive(false), retain_color_profile(false),
69  retain_exif_data(false), lossy(false) {}
70 
71  ~JpegCompressionOptions() override;
72 
77 
80 
83 
85  bool lossy;
86 
89 };
90 
93 bool OptimizeJpeg(const GoogleString &original,
94  GoogleString *compressed,
95  MessageHandler* handler);
96 
98 bool OptimizeJpegWithOptions(const GoogleString &original,
99  GoogleString *compressed,
100  const JpegCompressionOptions &options,
101  MessageHandler* handler);
102 
122  public:
123  explicit JpegScanlineWriter(MessageHandler* handler);
124  virtual ~JpegScanlineWriter();
125 
127  void SetJmpBufEnv(jmp_buf* env);
128 
131  void AbortWrite();
132 
133  virtual ScanlineStatus InitWithStatus(const size_t width, const size_t height,
134  PixelFormat pixel_format);
139  virtual ScanlineStatus InitializeWriteWithStatus(const void* params,
140  GoogleString *compressed);
142  const void *scanline_bytes);
144 
145  private:
148  void SetJpegCompressParams(const JpegCompressionOptions& options);
149 
152  struct Data;
153  Data* const data_;
154  MessageHandler* message_handler_;
155 
156 
157 };
158 
159 }
160 
161 }
162 
163 #endif
Definition: jpeg_optimizer.h:50
Definition: scanline_status.h:93
ColorSampling color_sampling
Color sampling that needs to be used while recompressing the image.
Definition: jpeg_optimizer.h:63
Definition: jpeg_optimizer.h:121
virtual ScanlineStatus InitializeWriteWithStatus(const void *params, GoogleString *compressed)
bool progressive
Definition: jpeg_optimizer.h:76
std::string GoogleString
PAGESPEED_KERNEL_BASE_STRING_H_.
Definition: string.h:24
void SetJmpBufEnv(jmp_buf *env)
Set the environment for longjmp calls.
virtual ScanlineStatus InitWithStatus(const size_t width, const size_t height, PixelFormat pixel_format)
Initialize the basic parameter for writing the image.
bool retain_color_profile
If set to 'true' any color profile information is retained.
Definition: jpeg_optimizer.h:79
bool retain_exif_data
If set to 'true' any exif information is retained.
Definition: jpeg_optimizer.h:82
bool lossy
Whether or not to use lossy compression.
Definition: jpeg_optimizer.h:85
int num_scans
Definition: jpeg_optimizer.h:60
Definition: message_handler.h:39
JpegLossyOptions lossy_options
Lossy compression options. Only applicable if lossy (above) is set to true.
Definition: jpeg_optimizer.h:88
virtual ScanlineStatus WriteNextScanlineWithStatus(const void *scanline_bytes)
virtual ScanlineStatus FinalizeWriteWithStatus()
Finalizes write structure once all scanlines are written.
int quality
Definition: jpeg_optimizer.h:56