19 #ifndef NET_INSTAWEB_REWRITER_PUBLIC_IMAGE_H_
20 #define NET_INSTAWEB_REWRITER_PUBLIC_IMAGE_H_
24 #include "net/instaweb/rewriter/image_types.pb.h"
25 #include "net/instaweb/rewriter/cached_result.pb.h"
31 namespace net_instaweb {
71 FROM_UNKNOWN_FORMAT = 0,
80 if ((var_type < FROM_UNKNOWN_FORMAT) ||
81 (var_type >= NUM_VARIABLE_TYPE)) {
84 return &(vars[var_type]);
93 allow_webp_alpha(
false),
94 webp_quality(RewriteOptions::kDefaultImageRecompressQuality),
95 jpeg_quality(RewriteOptions::kDefaultImageRecompressQuality),
96 progressive_jpeg_min_bytes(
97 RewriteOptions::kDefaultProgressiveJpegMinBytes),
98 progressive_jpeg(
false),
99 convert_gif_to_png(
false),
100 convert_png_to_jpeg(
false),
101 convert_jpeg_to_webp(
false),
102 recompress_jpeg(
false),
103 recompress_png(
false),
104 recompress_webp(
false),
105 retain_color_profile(
false),
106 retain_color_sampling(
false),
107 retain_exif_data(
false),
108 use_transparent_for_blank_image(
false),
109 jpeg_num_progressive_scans(
110 RewriteOptions::kDefaultImageJpegNumProgressiveScans),
111 webp_conversion_timeout_ms(-1),
113 preserve_lossless(
false),
114 webp_conversion_variables(NULL) {}
119 bool allow_webp_alpha;
122 int64 progressive_jpeg_min_bytes;
123 bool progressive_jpeg;
124 bool convert_gif_to_png;
125 bool convert_png_to_jpeg;
126 bool convert_jpeg_to_webp;
127 bool recompress_jpeg;
129 bool recompress_webp;
130 bool retain_color_profile;
131 bool retain_color_sampling;
132 bool retain_exif_data;
133 bool use_transparent_for_blank_image;
134 int64 jpeg_num_progressive_scans;
135 int64 webp_conversion_timeout_ms;
140 bool preserve_lossless;
158 virtual void Dimensions(ImageDim* natural_dim) = 0;
162 return original_contents_.size();
176 ImageType image_type() {
187 ComputeOutputContents();
189 return minimal_webp_support_;
195 virtual bool ResizeTo(
const ImageDim& new_dim) = 0;
224 virtual const GoogleString&
url() = 0;
233 explicit Image(
const StringPiece& original_contents);
234 explicit Image(ImageType type);
238 virtual bool ComputeOutputContents() = 0;
249 const StringPiece original_contents_;
253 ResourceContext::LibWebpLevel minimal_webp_support_;
257 friend class ImageTest;
259 DISALLOW_COPY_AND_ASSIGN(
Image);
273 const GoogleString& url,
274 const StringPiece& file_prefix,
277 MessageHandler* handler);
282 const StringPiece& tmp_dir,
284 MessageHandler* handler,
virtual void ComputeImageType()=0
Internal helpers.
Image * NewImage(const StringPiece &original_contents, const GoogleString &url, const StringPiece &file_prefix, Image::CompressionOptions *options, Timer *timer, MessageHandler *handler)
Histogram * failure_ms
Failed (and non-timed-out) conversion duration.
Definition: image.h:66
GoogleString output_contents_
Lazily filled.
Definition: image.h:250
size_t output_size()
Returns the size of output image in bytes.
Definition: image.h:166
bool rewrite_attempted_
Indicates if we tried rewriting for this.
Definition: image.h:252
size_t input_size() const
Returns the size of original input in bytes.
Definition: image.h:161
virtual const GoogleString & debug_message()=0
Returns the debug message.
Variable * timeout_count
of timed-out conversions.
Definition: image.h:64
ImageType image_type_
Lazily initialized, initially IMAGE_UNKNOWN.
Definition: image.h:248
Histogram * success_ms
Successful conversion duration.
Definition: image.h:65
virtual void Dimensions(ImageDim *natural_dim)=0
const ContentType * content_type()
Definition: image.h:204
virtual const GoogleString & url()=0
Returns the image URL.
virtual void SetResizedDimensions(const ImageDim &dim)=0
Inject desired resized dimensions directly for testing.
virtual bool EnsureLoaded(bool output_useful)=0
virtual bool ResizeTo(const ImageDim &new_dim)=0
Image * BlankImageWithOptions(int width, int height, ImageType type, const StringPiece &tmp_dir, Timer *timer, MessageHandler *handler, Image::CompressionOptions *options)
static const ContentType * TypeToContentType(ImageType t)
static method to convert image type to content type.
int conversions_attempted
Definition: image.h:139
virtual bool ShouldConvertToProgressive(int64 quality) const =0
PreferredWebp
Definition: image.h:52
Definition: image_testing_peer.h:29
ResourceContext::LibWebpLevel MinimalWebpSupport()
Definition: image.h:185
bool output_valid_
Indicates output_contents_ now correct.
Definition: image.h:251
PreferredWebp preferred_webp
Definition: image.h:118
virtual const GoogleString & resize_debug_message()=0
Returns the resized image debug message.
virtual bool DrawImage(Image *image, int x, int y)=0
virtual void SetTransformToLowRes()=0