19 #ifndef NET_INSTAWEB_REWRITER_PUBLIC_IMAGE_H_
20 #define NET_INSTAWEB_REWRITER_PUBLIC_IMAGE_H_
24 #include "net/instaweb/rewriter/cached_result.pb.h"
29 #include "pagespeed/kernel/http/image_types.pb.h"
32 namespace net_instaweb {
66 FROM_UNKNOWN_FORMAT = 0,
76 if ((var_type < FROM_UNKNOWN_FORMAT) ||
77 (var_type >= NUM_VARIABLE_TYPE)) {
80 return &(vars[var_type]);
89 allow_webp_alpha(
false),
90 allow_webp_animated(
false),
91 webp_quality(RewriteOptions::kDefaultImageRecompressQuality),
92 webp_animated_quality(RewriteOptions::kDefaultImageRecompressQuality),
93 jpeg_quality(RewriteOptions::kDefaultImageRecompressQuality),
94 progressive_jpeg_min_bytes(
95 RewriteOptions::kDefaultProgressiveJpegMinBytes),
96 progressive_jpeg(
false),
97 convert_gif_to_png(
false),
98 convert_png_to_jpeg(
false),
99 convert_jpeg_to_webp(
false),
100 recompress_jpeg(
false),
101 recompress_png(
false),
102 recompress_webp(
false),
103 retain_color_profile(
false),
104 retain_color_sampling(
false),
105 retain_exif_data(
false),
106 use_transparent_for_blank_image(
false),
107 jpeg_num_progressive_scans(
108 RewriteOptions::kDefaultImageJpegNumProgressiveScans),
109 webp_conversion_timeout_ms(-1),
111 preserve_lossless(
false),
112 webp_conversion_variables(NULL) {}
117 bool allow_webp_alpha;
118 bool allow_webp_animated;
120 int64 webp_animated_quality;
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() {
186 virtual bool ResizeTo(
const ImageDim& new_dim) = 0;
227 explicit Image(
const StringPiece& original_contents);
228 explicit Image(ImageType type);
232 virtual bool ComputeOutputContents() = 0;
243 const StringPiece original_contents_;
250 friend class ImageTest;
267 const StringPiece& file_prefix,
275 const StringPiece& tmp_dir,
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)
pagespeed::image_compression::PreferredLibwebpLevel preferred_webp
Definition: image.h:116
virtual void SetDebugMessageUrl(const GoogleString &url)=0
Sets the URL to be printed in debug messages.
Histogram * failure_ms
Failed (and non-timed-out) conversion duration.
Definition: image.h:61
GoogleString output_contents_
Lazily filled.
Definition: image.h:244
Definition: statistics.h:43
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:246
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:59
ImageType image_type_
Lazily initialized, initially IMAGE_UNKNOWN.
Definition: image.h:242
Histogram * success_ms
Successful conversion duration.
Definition: image.h:60
virtual void Dimensions(ImageDim *natural_dim)=0
const ContentType * content_type()
Definition: image.h:195
virtual const GoogleString & url()=0
Returns the image URL.
std::string GoogleString
PAGESPEED_KERNEL_BASE_STRING_H_.
Definition: string.h:24
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.
Definition: content_type.h:31
int conversions_attempted
Definition: image.h:139
Definition: statistics.h:138
virtual bool ShouldConvertToProgressive(int64 quality) const =0
Definition: image_testing_peer.h:29
Definition: message_handler.h:39
bool output_valid_
Indicates output_contents_ now correct.
Definition: image.h:245
virtual const GoogleString & resize_debug_message()=0
Returns the resized image debug message.
Timer interface, made virtual so it can be mocked for tests.
Definition: timer.h:27
virtual bool DrawImage(Image *image, int x, int y)=0
virtual void SetTransformToLowRes()=0