|
1 /* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- |
|
2 * This Source Code Form is subject to the terms of the Mozilla Public |
|
3 * License, v. 2.0. If a copy of the MPL was not distributed with this |
|
4 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ |
|
5 |
|
6 #include "nsISupports.idl" |
|
7 #include "nsIAsyncInputStream.idl" |
|
8 #include "nsIEventTarget.idl" |
|
9 |
|
10 /** |
|
11 * imgIEncoder interface |
|
12 */ |
|
13 [scriptable, uuid(4baa2d6e-fee7-42df-ae3f-5fbebc0c267c)] |
|
14 interface imgIEncoder : nsIAsyncInputStream |
|
15 { |
|
16 // Possible values for outputOptions. Multiple values are semicolon-separated. |
|
17 // |
|
18 // PNG: |
|
19 // ---- |
|
20 // transparency=[yes|no|none] -- default: "yes" |
|
21 // Overrides default from input format. "no" and "none" are equivalent. |
|
22 // |
|
23 // |
|
24 // APNG: |
|
25 // ----- |
|
26 // The following options can be used with startImageEncode(): |
|
27 // |
|
28 // transparency=[yes|no|none] -- default: "yes" |
|
29 // Overrides default from input format. "no" and "none" are equivalent. |
|
30 // skipfirstframe=[yes|no] -- default: "no" |
|
31 // Controls display of the first frame in animations. PNG-only clients always |
|
32 // display the first frame (and only that frame). |
|
33 // frames=# -- default: "1" |
|
34 // Total number of frames in the image. The first frame, even if skipped, is |
|
35 // always included in the count. |
|
36 // plays=# -- default: "0" |
|
37 // Number of times to play the animation sequence. "0" will repeat forever. |
|
38 // |
|
39 // |
|
40 // The following options can be used for each frame, with addImageFrame(): |
|
41 // |
|
42 // transparency=[yes|no|none] -- default: "yes" |
|
43 // Overrides default from input format. "no" and "none" are equivalent. |
|
44 // delay=# -- default: "500" |
|
45 // Number of milliseconds to display the frame, before moving to the next frame. |
|
46 // dispose=[none|background|previous] -- default: "none" |
|
47 // What to do with the image's canvas before rendering the next frame. See APNG spec. |
|
48 // blend=[source|over] -- default: "source" |
|
49 // How to render the new frame on the canvas. See APNG spec. |
|
50 // xoffset=# -- default: "0" |
|
51 // yoffset=# -- default: "0" |
|
52 // Where to draw the frame, relative to the canvas. |
|
53 // |
|
54 // |
|
55 // JPEG: |
|
56 // ----- |
|
57 // |
|
58 // quality=# -- default: "92" |
|
59 // Quality of compression, 0-100 (worst-best). |
|
60 // Quality >= 90 prevents down-sampling of the color channels. |
|
61 |
|
62 |
|
63 // Possible values for input format (note that not all image formats |
|
64 // support saving alpha channels): |
|
65 |
|
66 // Input is RGB each pixel is represented by three bytes: |
|
67 // R, G, and B (in that order, regardless of host endianness) |
|
68 const uint32_t INPUT_FORMAT_RGB = 0; |
|
69 |
|
70 // Input is RGB each pixel is represented by four bytes: |
|
71 // R, G, and B (in that order, regardless of host endianness). |
|
72 // POST-MULTIPLIED alpha us used (50% transparent red is 0xff000080) |
|
73 const uint32_t INPUT_FORMAT_RGBA = 1; |
|
74 |
|
75 // Input is host-endian ARGB: On big-endian machines each pixel is therefore |
|
76 // ARGB, and for little-endian machiens (Intel) each pixel is BGRA |
|
77 // (This is used by canvas to match it's internal representation) |
|
78 // |
|
79 // PRE-MULTIPLIED alpha is used (That is, 50% transparent red is 0x80800000, |
|
80 // not 0x80ff0000 |
|
81 const uint32_t INPUT_FORMAT_HOSTARGB = 2; |
|
82 |
|
83 /* data - list of bytes in the format specified by inputFormat |
|
84 * width - width in pixels |
|
85 * height - height in pixels |
|
86 * stride - number of bytes per row in the image |
|
87 * Normally (width*3) or (width*4), depending on your input format, |
|
88 * but some data uses padding at the end of each row, which would |
|
89 * be extra. |
|
90 * inputFormat - one of INPUT_FORMAT_* specifying the format of data |
|
91 * outputOptions - semicolon-delimited list of name=value pairs that can |
|
92 * give options to the output encoder. Options are encoder- |
|
93 * specific. Just give empty string for default behavior. |
|
94 */ |
|
95 void initFromData([array, size_is(length), const] in uint8_t data, |
|
96 in unsigned long length, |
|
97 in uint32_t width, |
|
98 in uint32_t height, |
|
99 in uint32_t stride, |
|
100 in uint32_t inputFormat, |
|
101 in AString outputOptions); |
|
102 |
|
103 /* |
|
104 * For encoding images which may contain multiple frames, the 1-shot |
|
105 * initFromData() interface is too simplistic. The alternative is to |
|
106 * use startImageEncode(), call addImageFrame() one or more times, and |
|
107 * then finish initialization with endImageEncode(). |
|
108 * |
|
109 * The arguments are basically the same as in initFromData(). |
|
110 */ |
|
111 void startImageEncode(in uint32_t width, |
|
112 in uint32_t height, |
|
113 in uint32_t inputFormat, |
|
114 in AString outputOptions); |
|
115 |
|
116 void addImageFrame( [array, size_is(length), const] in uint8_t data, |
|
117 in unsigned long length, |
|
118 in uint32_t width, |
|
119 in uint32_t height, |
|
120 in uint32_t stride, |
|
121 in uint32_t frameFormat, |
|
122 in AString frameOptions); |
|
123 |
|
124 void endImageEncode(); |
|
125 |
|
126 /* |
|
127 * Sometimes an encoder can contain another encoder and direct access |
|
128 * to its buffer is necessary. It is only safe to assume that the buffer |
|
129 * returned from getImageBuffer() is of size equal to getImageBufferUsed(). |
|
130 */ |
|
131 [noscript] unsigned long getImageBufferUsed(); |
|
132 [noscript] charPtr getImageBuffer(); |
|
133 }; |