michael@0: /* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- michael@0: * This Source Code Form is subject to the terms of the Mozilla Public michael@0: * License, v. 2.0. If a copy of the MPL was not distributed with this michael@0: * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ michael@0: michael@0: #include "nsISupports.idl" michael@0: #include "nsIAsyncInputStream.idl" michael@0: #include "nsIEventTarget.idl" michael@0: michael@0: /** michael@0: * imgIEncoder interface michael@0: */ michael@0: [scriptable, uuid(4baa2d6e-fee7-42df-ae3f-5fbebc0c267c)] michael@0: interface imgIEncoder : nsIAsyncInputStream michael@0: { michael@0: // Possible values for outputOptions. Multiple values are semicolon-separated. michael@0: // michael@0: // PNG: michael@0: // ---- michael@0: // transparency=[yes|no|none] -- default: "yes" michael@0: // Overrides default from input format. "no" and "none" are equivalent. michael@0: // michael@0: // michael@0: // APNG: michael@0: // ----- michael@0: // The following options can be used with startImageEncode(): michael@0: // michael@0: // transparency=[yes|no|none] -- default: "yes" michael@0: // Overrides default from input format. "no" and "none" are equivalent. michael@0: // skipfirstframe=[yes|no] -- default: "no" michael@0: // Controls display of the first frame in animations. PNG-only clients always michael@0: // display the first frame (and only that frame). michael@0: // frames=# -- default: "1" michael@0: // Total number of frames in the image. The first frame, even if skipped, is michael@0: // always included in the count. michael@0: // plays=# -- default: "0" michael@0: // Number of times to play the animation sequence. "0" will repeat forever. michael@0: // michael@0: // michael@0: // The following options can be used for each frame, with addImageFrame(): michael@0: // michael@0: // transparency=[yes|no|none] -- default: "yes" michael@0: // Overrides default from input format. "no" and "none" are equivalent. michael@0: // delay=# -- default: "500" michael@0: // Number of milliseconds to display the frame, before moving to the next frame. michael@0: // dispose=[none|background|previous] -- default: "none" michael@0: // What to do with the image's canvas before rendering the next frame. See APNG spec. michael@0: // blend=[source|over] -- default: "source" michael@0: // How to render the new frame on the canvas. See APNG spec. michael@0: // xoffset=# -- default: "0" michael@0: // yoffset=# -- default: "0" michael@0: // Where to draw the frame, relative to the canvas. michael@0: // michael@0: // michael@0: // JPEG: michael@0: // ----- michael@0: // michael@0: // quality=# -- default: "92" michael@0: // Quality of compression, 0-100 (worst-best). michael@0: // Quality >= 90 prevents down-sampling of the color channels. michael@0: michael@0: michael@0: // Possible values for input format (note that not all image formats michael@0: // support saving alpha channels): michael@0: michael@0: // Input is RGB each pixel is represented by three bytes: michael@0: // R, G, and B (in that order, regardless of host endianness) michael@0: const uint32_t INPUT_FORMAT_RGB = 0; michael@0: michael@0: // Input is RGB each pixel is represented by four bytes: michael@0: // R, G, and B (in that order, regardless of host endianness). michael@0: // POST-MULTIPLIED alpha us used (50% transparent red is 0xff000080) michael@0: const uint32_t INPUT_FORMAT_RGBA = 1; michael@0: michael@0: // Input is host-endian ARGB: On big-endian machines each pixel is therefore michael@0: // ARGB, and for little-endian machiens (Intel) each pixel is BGRA michael@0: // (This is used by canvas to match it's internal representation) michael@0: // michael@0: // PRE-MULTIPLIED alpha is used (That is, 50% transparent red is 0x80800000, michael@0: // not 0x80ff0000 michael@0: const uint32_t INPUT_FORMAT_HOSTARGB = 2; michael@0: michael@0: /* data - list of bytes in the format specified by inputFormat michael@0: * width - width in pixels michael@0: * height - height in pixels michael@0: * stride - number of bytes per row in the image michael@0: * Normally (width*3) or (width*4), depending on your input format, michael@0: * but some data uses padding at the end of each row, which would michael@0: * be extra. michael@0: * inputFormat - one of INPUT_FORMAT_* specifying the format of data michael@0: * outputOptions - semicolon-delimited list of name=value pairs that can michael@0: * give options to the output encoder. Options are encoder- michael@0: * specific. Just give empty string for default behavior. michael@0: */ michael@0: void initFromData([array, size_is(length), const] in uint8_t data, michael@0: in unsigned long length, michael@0: in uint32_t width, michael@0: in uint32_t height, michael@0: in uint32_t stride, michael@0: in uint32_t inputFormat, michael@0: in AString outputOptions); michael@0: michael@0: /* michael@0: * For encoding images which may contain multiple frames, the 1-shot michael@0: * initFromData() interface is too simplistic. The alternative is to michael@0: * use startImageEncode(), call addImageFrame() one or more times, and michael@0: * then finish initialization with endImageEncode(). michael@0: * michael@0: * The arguments are basically the same as in initFromData(). michael@0: */ michael@0: void startImageEncode(in uint32_t width, michael@0: in uint32_t height, michael@0: in uint32_t inputFormat, michael@0: in AString outputOptions); michael@0: michael@0: void addImageFrame( [array, size_is(length), const] in uint8_t data, michael@0: in unsigned long length, michael@0: in uint32_t width, michael@0: in uint32_t height, michael@0: in uint32_t stride, michael@0: in uint32_t frameFormat, michael@0: in AString frameOptions); michael@0: michael@0: void endImageEncode(); michael@0: michael@0: /* michael@0: * Sometimes an encoder can contain another encoder and direct access michael@0: * to its buffer is necessary. It is only safe to assume that the buffer michael@0: * returned from getImageBuffer() is of size equal to getImageBufferUsed(). michael@0: */ michael@0: [noscript] unsigned long getImageBufferUsed(); michael@0: [noscript] charPtr getImageBuffer(); michael@0: };