blob: 790be4e80e5da293ff622b2eaa5412f083bec672 [file] [log] [blame]
[email protected]2272ed32011-03-30 17:37:541/* Copyright (c) 2011 The Chromium Authors. All rights reserved.
2 * Use of this source code is governed by a BSD-style license that can be
3 * found in the LICENSE file.
4 */
5
[email protected]745b0d42011-07-16 23:53:226/**
7 * This file defines the <code>PPB_ImageData</code> struct for determining how
8 * a browser handles image data.
9 */
[email protected]2272ed32011-03-30 17:37:5410
[email protected]745b0d42011-07-16 23:53:2211 label Chrome {
[email protected]745b0d42011-07-16 23:53:2212 M14 = 1.0
13 };
14
15/**
16 * <code>PP_ImageDataFormat</code> is an enumeration of the different types of
17 * image data formats.
18 *
19 * The third part of each enumeration value describes the memory layout from
20 * the lowest address to the highest. For example, BGRA means the B component
21 * is stored in the lowest address, no matter what endianness the platform is
22 * using.
23 *
24 * The PREMUL suffix implies pre-multiplied alpha is used. In this mode, the
25 * red, green and blue color components of the pixel data supplied to an image
26 * data should be pre-multiplied by their alpha value. For example: starting
27 * with floating point color components, here is how to convert them to 8-bit
28 * premultiplied components for image data:
29 *
30 * ...components of a pixel, floats ranging from 0 to 1...
31 * <code>float red = 1.0f;</code>
[email protected]e6ce5e422011-08-15 17:23:1432 * <code>float green = 0.50f;</code>
[email protected]745b0d42011-07-16 23:53:2233 * <code>float blue = 0.0f;</code>
34 * <code>float alpha = 0.75f;</code>
35 * ...components for image data are 8-bit values ranging from 0 to 255...
36 * <code>uint8_t image_data_red_premul = (uint8_t)(red * alpha * 255.0f);
37 * </code>
38 * <code>uint8_t image_data_green_premul = (uint8_t)(green * alpha * 255.0f);
39 * </code>
40 * <code>uint8_t image_data_blue_premul = (uint8_t)(blue * alpha * 255.0f);
41 * </code>
42 * <code>uint8_t image_data_alpha_premul = (uint8_t)(alpha * 255.0f);</code>
43 *
44 * <strong>Note:</strong> The resulting pre-multiplied red, green and blue
45 * components should not be greater than the alpha value.
46 */
47[assert_size(4)]
[email protected]2272ed32011-03-30 17:37:5448enum PP_ImageDataFormat {
[email protected]745b0d42011-07-16 23:53:2249 PP_IMAGEDATAFORMAT_BGRA_PREMUL,
50 PP_IMAGEDATAFORMAT_RGBA_PREMUL
[email protected]2272ed32011-03-30 17:37:5451};
52
[email protected]745b0d42011-07-16 23:53:2253/**
54 * The <code>PP_ImageDataDesc</code> structure represents a description of
55 * image data.
56 */
57[assert_size(16)]
[email protected]2272ed32011-03-30 17:37:5458struct PP_ImageDataDesc {
[email protected]745b0d42011-07-16 23:53:2259 /**
60 * This value represents one of the image data types in the
61 * <code>PP_ImageDataFormat</code> enum.
62 */
[email protected]2272ed32011-03-30 17:37:5463 PP_ImageDataFormat format;
64
[email protected]745b0d42011-07-16 23:53:2265 /** This value represents the size of the bitmap in pixels. */
[email protected]2272ed32011-03-30 17:37:5466 PP_Size size;
67
[email protected]745b0d42011-07-16 23:53:2268 /**
69 * This value represents the row width in bytes. This may be different than
70 * width * 4 since there may be padding at the end of the lines.
[email protected]2272ed32011-03-30 17:37:5471 */
72 int32_t stride;
73};
74
[email protected]745b0d42011-07-16 23:53:2275/**
76 * The <code>PPB_ImageData</code> interface contains pointers to several
77 * functions for determining the browser's treatment of image data.
78 */
[email protected]745b0d42011-07-16 23:53:2279interface PPB_ImageData {
80 /**
81 * GetNativeImageDataFormat() returns the browser's preferred format for
82 * image data. The browser uses this format internally for painting. Other
83 * formats may require internal conversions to paint or may have additional
84 * restrictions depending on the function.
85 *
86 * @return A <code>PP_ImageDataFormat</code> containing the preferred format.
[email protected]2272ed32011-03-30 17:37:5487 */
88 PP_ImageDataFormat GetNativeImageDataFormat();
89
[email protected]745b0d42011-07-16 23:53:2290 /**
91 * IsImageDataFormatSupported() determines if the given image data format is
92 * supported by the browser.
93 *
94 * @param[in] format The image data format.
95 *
96 * @return A <code>PP_Bool</code> with <code>PP_TRUE</code> if the given
97 * image data format is supported by the browser.
[email protected]2272ed32011-03-30 17:37:5498 */
99 PP_Bool IsImageDataFormatSupported(
100 [in] PP_ImageDataFormat format);
101
[email protected]745b0d42011-07-16 23:53:22102 /**
103 * Create() allocates an image data resource with the given format and size.
[email protected]2272ed32011-03-30 17:37:54104 *
105 * For security reasons, if uninitialized, the bitmap will not contain random
106 * memory, but may contain data from a previous image produced by the same
[email protected]745b0d42011-07-16 23:53:22107 * module if the bitmap was cached and re-used.
108 *
[email protected]e12a6a12011-08-31 16:07:59109 * @param[in] instance A <code>PP_Instance</code> identifying one instance
[email protected]745b0d42011-07-16 23:53:22110 * of a module.
111 * @param[in] format The desired image data format.
112 * @param[in] size A pointer to a <code>PP_Size</code> containing the image
113 * size.
114 * @param[in] init_to_zero A <code>PP_Bool</code> to determine transparency
115 * at creation.
116 * Set the <code>init_to_zero</code> flag if you want the bitmap initialized
117 * to transparent during the creation process. If this flag is not set, the
118 * current contents of the bitmap will be undefined, and the module should
119 * be sure to set all the pixels.
120 *
[email protected]e12a6a12011-08-31 16:07:59121 * @return A <code>PP_Resource</code> with a nonzero ID on success or zero on
[email protected]745b0d42011-07-16 23:53:22122 * failure. Failure means the instance, image size, or format was invalid.
[email protected]2272ed32011-03-30 17:37:54123 */
124 PP_Resource Create(
125 [in] PP_Instance instance,
126 [in] PP_ImageDataFormat format,
127 [in] PP_Size size,
128 [in] PP_Bool init_to_zero);
129
[email protected]745b0d42011-07-16 23:53:22130 /**
[email protected]c896ec112011-12-21 22:00:48131 * IsImageData() determines if a given resource is image data.
[email protected]745b0d42011-07-16 23:53:22132 *
133 * @param[in] image_data A <code>PP_Resource</code> corresponding to image
134 * data.
135 *
136 * @return A <code>PP_Bool</code> with <code>PP_TRUE</code> if the given
[email protected]c896ec112011-12-21 22:00:48137 * resource is an image data or <code>PP_FALSE</code> if the resource is
[email protected]745b0d42011-07-16 23:53:22138 * invalid or some type other than image data.
[email protected]2272ed32011-03-30 17:37:54139 */
140 PP_Bool IsImageData(
141 [in] PP_Resource image_data);
142
[email protected]745b0d42011-07-16 23:53:22143 /**
144 * Describe() computes the description of the
145 * image data.
146 *
147 * @param[in] image_data A <code>PP_Resource</code> corresponding to image
148 * data.
149 * @param[in,out] desc A pointer to a <code>PP_ImageDataDesc</code>
150 * containing the description.
151 *
152 * @return A <code>PP_Bool</code> with <code>PP_TRUE</code> on success or
153 * <code>PP_FALSE</code> if the resource is not an image data. On
154 * <code>PP_FALSE</code>, the <code>desc</code> structure will be filled
155 * with 0.
[email protected]2272ed32011-03-30 17:37:54156 */
157 PP_Bool Describe(
158 [in] PP_Resource image_data,
159 [out] PP_ImageDataDesc desc);
160
[email protected]745b0d42011-07-16 23:53:22161 /**
162 * Map() maps an image data into the module address space.
163 *
164 * @param[in] image_data A <code>PP_Resource</code> corresponding to image
165 * data.
166 *
167 * @return A pointer to the beginning of the data.
[email protected]2272ed32011-03-30 17:37:54168 */
169 mem_t Map(
170 [in] PP_Resource image_data);
171
[email protected]745b0d42011-07-16 23:53:22172 /**
173 * Unmap is a pointer to a function that unmaps an image data from the module
174 * address space.
175 *
176 * @param[in] image_data A <code>PP_Resource</code> corresponding to image
177 * data.
178 */
[email protected]2272ed32011-03-30 17:37:54179 void Unmap(
180 [in] PP_Resource image_data);
181};
[email protected]745b0d42011-07-16 23:53:22182