Bug 458861. Validate TrueType headers before activating downloaded font. r=roc, sr...
[wine-gecko.git] / gfx / public / nsIImage.h
blobd9674c87bd997d80f7c318e311ea5cde1da217ee
1 /* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
2 /* ***** BEGIN LICENSE BLOCK *****
3 * Version: MPL 1.1/GPL 2.0/LGPL 2.1
5 * The contents of this file are subject to the Mozilla Public License Version
6 * 1.1 (the "License"); you may not use this file except in compliance with
7 * the License. You may obtain a copy of the License at
8 * http://www.mozilla.org/MPL/
10 * Software distributed under the License is distributed on an "AS IS" basis,
11 * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
12 * for the specific language governing rights and limitations under the
13 * License.
15 * The Original Code is mozilla.org code.
17 * The Initial Developer of the Original Code is
18 * Netscape Communications Corporation.
19 * Portions created by the Initial Developer are Copyright (C) 1998
20 * the Initial Developer. All Rights Reserved.
22 * Contributor(s):
24 * Alternatively, the contents of this file may be used under the terms of
25 * either of the GNU General Public License Version 2 or later (the "GPL"),
26 * or the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
27 * in which case the provisions of the GPL or the LGPL are applicable instead
28 * of those above. If you wish to allow use of your version of this file only
29 * under the terms of either the GPL or the LGPL, and not to allow others to
30 * use your version of this file under the terms of the MPL, indicate your
31 * decision by deleting the provisions above and replace them with the notice
32 * and other provisions required by the GPL or the LGPL. If you do not delete
33 * the provisions above, a recipient may use your version of this file under
34 * the terms of any one of the MPL, the GPL or the LGPL.
36 * ***** END LICENSE BLOCK ***** */
38 #ifndef nsIImage_h___
39 #define nsIImage_h___
41 #include "nsISupports.h"
42 #include "nsIRenderingContext.h"
43 #include "nsRect.h"
44 #include "gfxRect.h"
46 class gfxASurface;
47 class gfxPattern;
49 class nsIDeviceContext;
51 struct nsColorMap
53 //I lifted this from the image lib. The difference is that
54 //this uses nscolor instead of NI_RGB. Multiple color pollution
55 //is a bad thing. MMP
56 PRInt32 NumColors; // Number of colors in the colormap.
57 // A negative value can be used to denote a
58 // possibly non-unique set.
59 //nscolor *Map; // Colormap colors.
60 PRUint8 *Index; // NULL, if map is in index order, otherwise
61 // specifies the indices of the map entries. */
64 typedef enum {
65 nsMaskRequirements_kNoMask,
66 nsMaskRequirements_kNeeds1Bit,
67 nsMaskRequirements_kNeeds8Bit
68 } nsMaskRequirements;
71 #define nsImageUpdateFlags_kColorMapChanged 0x1
72 #define nsImageUpdateFlags_kBitsChanged 0x2
74 // IID for the nsIImage interface
75 // 96d9d7ce-e575-4265-8507-35555112a430
76 #define NS_IIMAGE_IID \
77 { 0x96d9d7ce, 0xe575, 0x4265, \
78 { 0x85, 0x07, 0x35, 0x55, 0x51, 0x12, 0xa4, 0x30 } }
80 // Interface to Images
81 class nsIImage : public nsISupports
84 public:
85 NS_DECLARE_STATIC_IID_ACCESSOR(NS_IIMAGE_IID)
87 /**
88 * Build and initialize the nsIImage
89 * @param aWidth The width in pixels of the desired pixelmap
90 * @param aHeight The height in pixels of the desired pixelmap
91 * @param aDepth The number of bits per pixel for the pixelmap
92 * @param aMaskRequirements A flag indicating if a alpha mask should be allocated
94 virtual nsresult Init(PRInt32 aWidth, PRInt32 aHeight, PRInt32 aDepth, nsMaskRequirements aMaskRequirements) = 0;
96 /**
97 * Get the number of bytes per pixel for this image
98 * @update - dwc 2/3/99
99 * @return - the number of bytes per pixel
101 virtual PRInt32 GetBytesPix() = 0;
104 * Get whether rows are organized top to bottom, or bottom to top
105 * @update - syd 3/29/99
106 * @return PR_TRUE if top to bottom, else PR_FALSE
108 virtual PRBool GetIsRowOrderTopToBottom() = 0;
111 * Get the width for the pixelmap
112 * @update - dwc 2/1/99
113 * @return The width in pixels for the pixelmap
115 virtual PRInt32 GetWidth() = 0;
118 * Get the height for the pixelmap
119 * @update - dwc 2/1/99
120 * @return The height in pixels for the pixelmap
122 virtual PRInt32 GetHeight() = 0;
125 * Get a pointer to the bits for the pixelmap, only if it is not optimized
126 * @update - dwc 2/1/99
127 * @return address of the DIB pixel array
129 virtual PRUint8 * GetBits() = 0;
132 * Get the number of bytes needed to get to the next scanline for the pixelmap
133 * @update - dwc 2/1/99
134 * @return The number of bytes in each scanline
136 virtual PRInt32 GetLineStride() = 0;
139 * Get whether this image has an alpha mask. Preferable to testing
140 * if GetAlphaBits() is non-null.
141 * @update - sfraser 10/19/99
142 * @return PR_TRUE if the image has an alpha mask, PR_FALSE otherwise
144 virtual PRBool GetHasAlphaMask() = 0;
147 * Get a pointer to the bits for the alpha mask
148 * @update - dwc 2/1/99
149 * @return address of the alpha mask pixel array
151 virtual PRUint8 * GetAlphaBits() = 0;
154 * Get the number of bytes per scanline for the alpha mask
155 * @update - dwc 2/1/99
156 * @return The number of bytes in each scanline
158 virtual PRInt32 GetAlphaLineStride() = 0;
161 * Update the nsIImage color table
162 * @update - dougt 9/9/08
163 * @param aFlags Used to pass in parameters for the update
164 * @param aUpdateRect The rectangle to update
165 * @return success code. failure means stop decoding
167 virtual nsresult ImageUpdated(nsIDeviceContext *aContext, PRUint8 aFlags, nsIntRect *aUpdateRect) = 0;
170 * Get whether this image's region is completely filled with data.
171 * @return PR_TRUE if image is complete, PR_FALSE if image is not yet
172 * complete or broken
174 virtual PRBool GetIsImageComplete() = 0;
177 * Converted this pixelmap to an optimized pixelmap for the device
178 * @update - dwc 2/1/99
179 * @param aContext The device to optimize for
180 * @return the result of the operation, if NS_OK, then the pixelmap is optimized
182 virtual nsresult Optimize(nsIDeviceContext* aContext) = 0;
185 * Get the colormap for the nsIImage
186 * @update - dwc 2/1/99
187 * @return if non null, the colormap for the pixelmap,otherwise the image is not color mapped
189 virtual nsColorMap * GetColorMap() = 0;
192 * BitBlit the nsIImage to a device, the source and dest can be scaled
193 * @param aSourceRect source rectangle, in image pixels
194 * @param aSubimageRect the subimage that we're extracting the contents from.
195 * It must contain aSourceRect. Pixels outside this rectangle must not
196 * be sampled.
197 * @param aDestRect destination rectangle, in device pixels
199 NS_IMETHOD Draw(nsIRenderingContext &aContext,
200 const gfxRect &aSourceRect,
201 const gfxRect &aSubimageRect,
202 const gfxRect &aDestRect) = 0;
205 * Get the alpha depth for the image mask
206 * @update - lordpixel 2001/05/16
207 * @return the alpha mask depth for the image, ie, 0, 1 or 8
209 virtual PRInt8 GetAlphaDepth() = 0;
212 * Return information about the bits for this structure
213 * @update - dwc 2/1/99
214 * @return a bitmap info structure for the Device Dependent Bits
216 virtual void* GetBitInfo() = 0;
220 * LockImagePixels
221 * Lock the image pixels so that we can access them directly,
222 * with safety. May be a noop on some platforms.
224 * If you want to be able to call GetSurface(), wrap the call in
225 * LockImagePixels()/UnlockImagePixels(). This also allows you to write to
226 * the surface returned by GetSurface().
228 * aMaskPixels = PR_TRUE for the mask, PR_FALSE for the image
230 * Must be balanced by a call to UnlockImagePixels().
232 * @update - sfraser 10/18/99
233 * @return error result
235 NS_IMETHOD LockImagePixels(PRBool aMaskPixels) = 0;
238 * UnlockImagePixels
239 * Unlock the image pixels. May be a noop on some platforms.
241 * Should balance an earlier call to LockImagePixels().
243 * aMaskPixels = PR_TRUE for the mask, PR_FALSE for the image
245 * @update - sfraser 10/18/99
246 * @return error result
248 NS_IMETHOD UnlockImagePixels(PRBool aMaskPixels) = 0;
251 * GetSurface
252 * Return the Thebes gfxASurface in aSurface, if there is one. Should be
253 * wrapped by LockImagePixels()/UnlockImagePixels().
255 * aSurface will be AddRef'd (as with most getters), so
256 * getter_AddRefs should be used.
258 NS_IMETHOD GetSurface(gfxASurface **aSurface) = 0;
261 * GetSurface
262 * Return the Thebes gfxPattern in aPattern. It is always possible to get a
263 * gfxPattern (unlike the gfxASurface from GetSurface()).
265 * aPattern will be AddRef'd (as with most getters), so
266 * getter_AddRefs should be used.
268 NS_IMETHOD GetPattern(gfxPattern **aPattern) = 0;
271 * SetHasNoAlpha
273 * Hint to the image that all the pixels are fully opaque, even if
274 * the original format requested a 1-bit or 8-bit alpha mask
276 virtual void SetHasNoAlpha() = 0;
279 NS_DEFINE_STATIC_IID_ACCESSOR(nsIImage, NS_IIMAGE_IID)
281 #endif