• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 // Copyright (c) 2016 Marshall A. Greenblatt. All rights reserved.
2 //
3 // Redistribution and use in source and binary forms, with or without
4 // modification, are permitted provided that the following conditions are
5 // met:
6 //
7 //    * Redistributions of source code must retain the above copyright
8 // notice, this list of conditions and the following disclaimer.
9 //    * Redistributions in binary form must reproduce the above
10 // copyright notice, this list of conditions and the following disclaimer
11 // in the documentation and/or other materials provided with the
12 // distribution.
13 //    * Neither the name of Google Inc. nor the name Chromium Embedded
14 // Framework nor the names of its contributors may be used to endorse
15 // or promote products derived from this software without specific prior
16 // written permission.
17 //
18 // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
19 // "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
20 // LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
21 // A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
22 // OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
23 // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
24 // LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
25 // DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
26 // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
27 // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
28 // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
29 //
30 // ---------------------------------------------------------------------------
31 //
32 // The contents of this file must follow a specific format in order to
33 // support the CEF translator tool. See the translator.README.txt file in the
34 // tools directory for more information.
35 //
36 
37 #ifndef CEF_INCLUDE_CEF_IMAGE_H_
38 #define CEF_INCLUDE_CEF_IMAGE_H_
39 #pragma once
40 
41 #include "include/cef_base.h"
42 #include "include/cef_values.h"
43 
44 ///
45 // Container for a single image represented at different scale factors. All
46 // image representations should be the same size in density independent pixel
47 // (DIP) units. For example, if the image at scale factor 1.0 is 100x100 pixels
48 // then the image at scale factor 2.0 should be 200x200 pixels -- both images
49 // will display with a DIP size of 100x100 units. The methods of this class can
50 // be called on any browser process thread.
51 ///
52 /*--cef(source=library)--*/
53 class CefImage : public virtual CefBaseRefCounted {
54  public:
55   ///
56   // Create a new CefImage. It will initially be empty. Use the Add*() methods
57   // to add representations at different scale factors.
58   ///
59   /*--cef()--*/
60   static CefRefPtr<CefImage> CreateImage();
61 
62   ///
63   // Returns true if this Image is empty.
64   ///
65   /*--cef()--*/
66   virtual bool IsEmpty() = 0;
67 
68   ///
69   // Returns true if this Image and |that| Image share the same underlying
70   // storage. Will also return true if both images are empty.
71   ///
72   /*--cef()--*/
73   virtual bool IsSame(CefRefPtr<CefImage> that) = 0;
74 
75   ///
76   // Add a bitmap image representation for |scale_factor|. Only 32-bit RGBA/BGRA
77   // formats are supported. |pixel_width| and |pixel_height| are the bitmap
78   // representation size in pixel coordinates. |pixel_data| is the array of
79   // pixel data and should be |pixel_width| x |pixel_height| x 4 bytes in size.
80   // |color_type| and |alpha_type| values specify the pixel format.
81   ///
82   /*--cef()--*/
83   virtual bool AddBitmap(float scale_factor,
84                          int pixel_width,
85                          int pixel_height,
86                          cef_color_type_t color_type,
87                          cef_alpha_type_t alpha_type,
88                          const void* pixel_data,
89                          size_t pixel_data_size) = 0;
90 
91   ///
92   // Add a PNG image representation for |scale_factor|. |png_data| is the image
93   // data of size |png_data_size|. Any alpha transparency in the PNG data will
94   // be maintained.
95   ///
96   /*--cef()--*/
97   virtual bool AddPNG(float scale_factor,
98                       const void* png_data,
99                       size_t png_data_size) = 0;
100 
101   ///
102   // Create a JPEG image representation for |scale_factor|. |jpeg_data| is the
103   // image data of size |jpeg_data_size|. The JPEG format does not support
104   // transparency so the alpha byte will be set to 0xFF for all pixels.
105   ///
106   /*--cef()--*/
107   virtual bool AddJPEG(float scale_factor,
108                        const void* jpeg_data,
109                        size_t jpeg_data_size) = 0;
110 
111   ///
112   // Returns the image width in density independent pixel (DIP) units.
113   ///
114   /*--cef()--*/
115   virtual size_t GetWidth() = 0;
116 
117   ///
118   // Returns the image height in density independent pixel (DIP) units.
119   ///
120   /*--cef()--*/
121   virtual size_t GetHeight() = 0;
122 
123   ///
124   // Returns true if this image contains a representation for |scale_factor|.
125   ///
126   /*--cef()--*/
127   virtual bool HasRepresentation(float scale_factor) = 0;
128 
129   ///
130   // Removes the representation for |scale_factor|. Returns true on success.
131   ///
132   /*--cef()--*/
133   virtual bool RemoveRepresentation(float scale_factor) = 0;
134 
135   ///
136   // Returns information for the representation that most closely matches
137   // |scale_factor|. |actual_scale_factor| is the actual scale factor for the
138   // representation. |pixel_width| and |pixel_height| are the representation
139   // size in pixel coordinates. Returns true on success.
140   ///
141   /*--cef()--*/
142   virtual bool GetRepresentationInfo(float scale_factor,
143                                      float& actual_scale_factor,
144                                      int& pixel_width,
145                                      int& pixel_height) = 0;
146 
147   ///
148   // Returns the bitmap representation that most closely matches |scale_factor|.
149   // Only 32-bit RGBA/BGRA formats are supported. |color_type| and |alpha_type|
150   // values specify the desired output pixel format. |pixel_width| and
151   // |pixel_height| are the output representation size in pixel coordinates.
152   // Returns a CefBinaryValue containing the pixel data on success or NULL on
153   // failure.
154   ///
155   /*--cef()--*/
156   virtual CefRefPtr<CefBinaryValue> GetAsBitmap(float scale_factor,
157                                                 cef_color_type_t color_type,
158                                                 cef_alpha_type_t alpha_type,
159                                                 int& pixel_width,
160                                                 int& pixel_height) = 0;
161 
162   ///
163   // Returns the PNG representation that most closely matches |scale_factor|. If
164   // |with_transparency| is true any alpha transparency in the image will be
165   // represented in the resulting PNG data. |pixel_width| and |pixel_height| are
166   // the output representation size in pixel coordinates. Returns a
167   // CefBinaryValue containing the PNG image data on success or NULL on failure.
168   ///
169   /*--cef()--*/
170   virtual CefRefPtr<CefBinaryValue> GetAsPNG(float scale_factor,
171                                              bool with_transparency,
172                                              int& pixel_width,
173                                              int& pixel_height) = 0;
174 
175   ///
176   // Returns the JPEG representation that most closely matches |scale_factor|.
177   // |quality| determines the compression level with 0 == lowest and 100 ==
178   // highest. The JPEG format does not support alpha transparency and the alpha
179   // channel, if any, will be discarded. |pixel_width| and |pixel_height| are
180   // the output representation size in pixel coordinates. Returns a
181   // CefBinaryValue containing the JPEG image data on success or NULL on
182   // failure.
183   ///
184   /*--cef()--*/
185   virtual CefRefPtr<CefBinaryValue> GetAsJPEG(float scale_factor,
186                                               int quality,
187                                               int& pixel_width,
188                                               int& pixel_height) = 0;
189 };
190 
191 #endif  // CEF_INCLUDE_CEF_IMAGE_H_
192