1 : /* -*- Mode: C++; tab-width: 20; indent-tabs-mode: nil; c-basic-offset: 4 -*-
2 : * ***** BEGIN LICENSE BLOCK *****
3 : * Version: MPL 1.1/GPL 2.0/LGPL 2.1
4 : *
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/
9 : *
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.
14 : *
15 : * The Original Code is Oracle Corporation code.
16 : *
17 : * The Initial Developer of the Original Code is Oracle Corporation.
18 : * Portions created by the Initial Developer are Copyright (C) 2005
19 : * the Initial Developer. All Rights Reserved.
20 : *
21 : * Contributor(s):
22 : * Stuart Parmenter <pavlov@pavlov.net>
23 : *
24 : * Alternatively, the contents of this file may be used under the terms of
25 : * either the GNU General Public License Version 2 or later (the "GPL"), or
26 : * 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.
35 : *
36 : * ***** END LICENSE BLOCK ***** */
37 :
38 : #ifndef GFX_IMAGESURFACE_H
39 : #define GFX_IMAGESURFACE_H
40 :
41 : #include "gfxASurface.h"
42 : #include "gfxPoint.h"
43 :
44 : // ARGB -- raw buffer.. wont be changed.. good for storing data.
45 :
46 : class gfxSubimageSurface;
47 :
48 : /**
49 : * A raw image buffer. The format can be set in the constructor. Its main
50 : * purpose is for storing read-only images and using it as a source surface,
51 : * but it can also be drawn to.
52 : */
53 : class THEBES_API gfxImageSurface : public gfxASurface {
54 : public:
55 : /**
56 : * Construct an image surface around an existing buffer of image data.
57 : * @param aData A buffer containing the image data
58 : * @param aSize The size of the buffer
59 : * @param aStride The stride of the buffer
60 : * @param format Format of the data
61 : *
62 : * @see gfxImageFormat
63 : */
64 : gfxImageSurface(unsigned char *aData, const gfxIntSize& aSize,
65 : long aStride, gfxImageFormat aFormat);
66 :
67 : /**
68 : * Construct an image surface.
69 : * @param aSize The size of the buffer
70 : * @param format Format of the data
71 : *
72 : * @see gfxImageFormat
73 : */
74 : gfxImageSurface(const gfxIntSize& size, gfxImageFormat format);
75 : gfxImageSurface(cairo_surface_t *csurf);
76 :
77 : virtual ~gfxImageSurface();
78 :
79 : // ImageSurface methods
80 0 : gfxImageFormat Format() const { return mFormat; }
81 :
82 14 : virtual const gfxIntSize GetSize() const { return mSize; }
83 0 : PRInt32 Width() const { return mSize.width; }
84 0 : PRInt32 Height() const { return mSize.height; }
85 :
86 : /**
87 : * Distance in bytes between the start of a line and the start of the
88 : * next line.
89 : */
90 0 : PRInt32 Stride() const { return mStride; }
91 : /**
92 : * Returns a pointer for the image data. Users of this function can
93 : * write to it, but must not attempt to free the buffer.
94 : */
95 0 : unsigned char* Data() const { return mData; } // delete this data under us and die.
96 : /**
97 : * Returns the total size of the image data.
98 : */
99 : PRInt32 GetDataSize() const { return mStride*mSize.height; }
100 :
101 : /* Fast copy from another image surface; returns TRUE if successful, FALSE otherwise */
102 : bool CopyFrom (gfxImageSurface *other);
103 :
104 : /* return new Subimage with pointing to original image starting from aRect.pos
105 : * and size of aRect.size. New subimage keeping current image reference
106 : */
107 : already_AddRefed<gfxSubimageSurface> GetSubimage(const gfxRect& aRect);
108 :
109 : virtual already_AddRefed<gfxImageSurface> GetAsImageSurface();
110 :
111 : /** See gfxASurface.h. */
112 : NS_OVERRIDE
113 : virtual void MovePixels(const nsIntRect& aSourceRect,
114 : const nsIntPoint& aDestTopLeft);
115 :
116 : protected:
117 : gfxImageSurface();
118 : void InitWithData(unsigned char *aData, const gfxIntSize& aSize,
119 : long aStride, gfxImageFormat aFormat);
120 : void InitFromSurface(cairo_surface_t *csurf);
121 130 : long ComputeStride() const { return ComputeStride(mSize, mFormat); }
122 :
123 : static long ComputeStride(const gfxIntSize&, gfxImageFormat);
124 :
125 : void MakeInvalid();
126 :
127 : gfxIntSize mSize;
128 : bool mOwnsData;
129 : unsigned char *mData;
130 : gfxImageFormat mFormat;
131 : long mStride;
132 : };
133 :
134 0 : class THEBES_API gfxSubimageSurface : public gfxImageSurface {
135 : protected:
136 : friend class gfxImageSurface;
137 : gfxSubimageSurface(gfxImageSurface* aParent,
138 : unsigned char* aData,
139 : const gfxIntSize& aSize);
140 : private:
141 : nsRefPtr<gfxImageSurface> mParent;
142 : };
143 :
144 : #endif /* GFX_IMAGESURFACE_H */
|