Page Speed Optimization Libraries
1.7.30.3
|
Classes | |
struct | CompressionOptions |
struct | ConversionBySourceVariable |
struct | ConversionVariables |
Public Types | |
enum | PreferredWebp { WEBP_NONE = 0, WEBP_LOSSY, WEBP_LOSSLESS } |
Public Member Functions | |
virtual void | Dimensions (ImageDim *natural_dim)=0 |
size_t | input_size () const |
Returns the size of original input in bytes. | |
size_t | output_size () |
Returns the size of output image in bytes. | |
ImageType | image_type () |
virtual bool | ResizeTo (const ImageDim &new_dim)=0 |
virtual void | SetTransformToLowRes ()=0 |
const ContentType * | content_type () |
StringPiece | Contents () |
virtual bool | DrawImage (Image *image, int x, int y)=0 |
virtual bool | EnsureLoaded (bool output_useful)=0 |
virtual const GoogleString & | url ()=0 |
Returns the image URL. | |
Static Public Member Functions | |
static const ContentType * | TypeToContentType (ImageType t) |
static method to convert image type to content type. | |
Protected Member Functions | |
Image (const StringPiece &original_contents) | |
Image (ImageType type) | |
virtual void | ComputeImageType ()=0 |
Internal helpers. | |
virtual bool | ComputeOutputContents ()=0 |
virtual void | SetResizedDimensions (const ImageDim &dim)=0 |
Inject desired resized dimensions directly for testing. | |
virtual bool | ShouldConvertToProgressive (int64 quality) const =0 |
Protected Attributes | |
ImageType | image_type_ |
Lazily initialized, initially IMAGE_UNKNOWN. | |
const StringPiece | original_contents_ |
GoogleString | output_contents_ |
Lazily filled. | |
bool | output_valid_ |
Indicates output_contents_ now correct. | |
bool | rewrite_attempted_ |
Indicates if we tried rewriting for this. | |
Friends | |
class | ImageTestingPeer |
class | ImageTest |
Images that are in the process of being transformed are represented by an Image. This class encapsulates various operations that are sensitive to the format of the compressed image file and of the image libraries we are using. In particular, the timing of compression and decompression operations may be a bit unexpected, because we may do these operations early in order to retrieve image metadata, or we may choose to skip them entirely if we don't need them or don't understand how to do them.
In future we may need to plumb this to other data sources or change how metadata is retrieved; the object is to do so locally in this class without disrupting any of its clients.
const ContentType* net_instaweb::Image::content_type | ( | ) | [inline] |
Returns image-appropriate content type, or NULL if no content type is known. Result is a top-level const pointer and should not be deleted etc.
StringPiece net_instaweb::Image::Contents | ( | ) |
Returns the best known image contents. If image type is not understood, then Contents() will have NULL data().
virtual void net_instaweb::Image::Dimensions | ( | ImageDim * | natural_dim | ) | [pure virtual] |
Stores the image dimensions in natural_dim (on success, sets natural_dim->{width, height} and ImageUrlEncoder::HasValidDimensions(natural_dim) == true). This method can fail (ImageUrlEncoder::HasValidDimensions(natural_dim) == false) for various reasons: we don't understand the image format, we can't find the headers, the library doesn't support a particular encoding, etc. In that case the other fields are left alone.
virtual bool net_instaweb::Image::DrawImage | ( | Image * | image, |
int | x, | ||
int | y | ||
) | [pure virtual] |
Draws the given image on top of this one at the given offset. Returns true if successful.
virtual bool net_instaweb::Image::EnsureLoaded | ( | bool | output_useful | ) | [pure virtual] |
Attempts to decode this image and load its raster into memory. If this returns false, future calls to DrawImage and ResizeTo will fail.
If output_useful is true, the decoded version might be written out directly to user, so it may be worthwhile to make it efficient.
virtual bool net_instaweb::Image::ResizeTo | ( | const ImageDim & | new_dim | ) | [pure virtual] |
Changes the size of the image to the given width and height. This will run image processing on the image, and return false if the image processing fails. Otherwise the image contents and type can change.
virtual void net_instaweb::Image::SetTransformToLowRes | ( | ) | [pure virtual] |
Enable the transformation to low res image. If low res image is enabled, all jpeg images are transformed to low quality jpeg images and all webp images to low quality webp images, if possible.
virtual bool net_instaweb::Image::ShouldConvertToProgressive | ( | int64 | quality | ) | const [protected, pure virtual] |
Determines whether it's a good idea to convert this image to progressive jpeg.