What's new? | Help | Directory | Sign in
Google
gears
Improving Your Web Browser
  
  
  
    
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
// Copyright 2008, Google Inc.
//
// Redistribution and use in source and binary forms, with or without
// modification, are permitted provided that the following conditions are met:
//
// 1. Redistributions of source code must retain the above copyright notice,
// this list of conditions and the following disclaimer.
// 2. Redistributions in binary form must reproduce the above copyright notice,
// this list of conditions and the following disclaimer in the documentation
// and/or other materials provided with the distribution.
// 3. Neither the name of Google Inc. nor the names of its contributors may be
// used to endorse or promote products derived from this software without
// specific prior written permission.
//
// THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR IMPLIED
// WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
// MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO
// EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
// PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
// OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
// WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
// OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
// ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.

#ifndef GEARS_IMAGE_BACKING_IMAGE_H__
#define GEARS_IMAGE_BACKING_IMAGE_H__

#ifdef OFFICIAL_BUILD
// The Image API has not been finalized for official builds
#else

#include "third_party/libgd/gd.h"
#include "gears/blob/blob_interface.h"

// To create an image, construct it, then initialize it from a blob with
// Init(blob). If Init is not called, or returns false, the
// image is not initialized and should not be used until it is initialized.
class BackingImage {
public:
// IJG quality value in the range [0..95], or -1 for the libGD default:
static const int kJpegQuality = -1;

// This is the maximum width or height that can be generated by this module.
// Note that it is possible to load an image that is larger than this.
static const int kMaxImageDimension = 4096;

enum ImageFormat {
FORMAT_PNG = 0,
FORMAT_GIF = 1,
FORMAT_JPEG = 2
};

// Creates an uninitialised image.
BackingImage();

// Initializes this with the contents of blob and returns true, or returns
// false on failure.
bool Init(BlobInterface *blob, std::string16 *error);

// Resizes the image, or returns false if width or height are negative, or if
// width or height are larger than kMaxImageDimension.
bool Resize(int width, int height, std::string16 *error);

// Crops the image to the bounding box with a displacement of (x, y) from the
// left and top edges respectively, and the given width and height. Returns
// false if the bounding box is invalid or out of bounds.
bool Crop(int x, int y, int width, int height, std::string16 *error);

// Rotates by degrees anti-clockwise. Only supports orthogonal rotations for
// now. Non-orthogonal rotations return false.
bool Rotate(int degrees, std::string16 *error);

// Flips the image about the vertical axis.
bool FlipHorizontal(std::string16 *error);

// Flips the image about the horizontal axis.
bool FlipVertical(std::string16 *error);

// Composes the given image at the given displacement from the left and top.
bool DrawImage(const BackingImage* img, int x, int y, std::string16 *error);

int Width() const;

int Height() const;

// Returns a blob containing the image data in the format specified.
void ToBlob(scoped_refptr<BlobInterface> *out, ImageFormat format);

// Returns a blob of the format from which it was originally saved.
void ToBlob(scoped_refptr<BlobInterface> *out);

~BackingImage();

private:
gdImagePtr img_ptr_;

ImageFormat original_format_;
};

#endif // not OFFICIAL_BUILD

#endif // GEARS_IMAGE_BACKING_IMAGE_H__
Show details Hide details

Change log

r1361 by gears.daemon on Apr 11, 2008   Diff
[Author: cprince]

Gears Relocation: update files to reflect
new /third_party location.

PRESUBMIT=passed
TBR=aa
OCL=6927147
SCL=6927168
Go to: 
Project members, sign in to write a code review

Older revisions

r1331 by gears.daemon on Apr 09, 2008   Diff
[Author: nigeltao]

Blob and Image modules are now
Dispatcher-based.

...
All revisions of this file

File info

Size: 4063 bytes, 103 lines