blob: e5008fa186e6f1fb5d709b60fb612a7f4a433d05 [file] [log] [blame]
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html><head><meta http-equiv="Content-Type" content="text/html;charset=iso-8859-1">
<title>SGL: SkBitmap.h Source File</title>
<link href="doxygen.css" rel="stylesheet" type="text/css">
</head><body>
<!-- Generated by Doxygen 1.4.0 -->
<div class="qindex"><a class="qindex" href="index.html">Main&nbsp;Page</a> | <a class="qindex" href="hierarchy.html">Class&nbsp;Hierarchy</a> | <a class="qindex" href="annotated.html">Class&nbsp;List</a> | <a class="qindex" href="dirs.html">Directories</a> | <a class="qindex" href="files.html">File&nbsp;List</a> | <a class="qindex" href="functions.html">Class&nbsp;Members</a> | <a class="qindex" href="globals.html">File&nbsp;Members</a></div>
<div class="nav">
<a class="el" href="dir_000000.html">include</a>&nbsp;/&nbsp;<a class="el" href="dir_000001.html">skia</a></div>
<h1>SkBitmap.h</h1><div class="fragment"><pre class="fragment">00001 <span class="preprocessor">#ifndef SkBitmap_DEFINED</span>
00002 <span class="preprocessor"></span><span class="preprocessor">#define SkBitmap_DEFINED</span>
00003 <span class="preprocessor"></span>
00004 <span class="preprocessor">#include "<a class="code" href="SkColor_8h.html">SkColor.h</a>"</span>
00005 <span class="preprocessor">#include "SkRefCnt.h"</span>
00006
00007 <span class="comment">// Android - we need to run as an embedded product, not X11</span>
00008 <span class="comment">//#ifdef SK_BUILD_FOR_UNIX</span>
00009 <span class="comment">//#include &lt;X11/Xlib.h&gt;</span>
00010 <span class="comment">//#endif</span>
00011
00012
00013 <span class="keyword">class </span><a class="code" href="classSkColorTable.html">SkColorTable</a>;
00014
<a name="l00022"></a><a class="code" href="classSkBitmap.html">00022</a> <span class="keyword">class </span><a class="code" href="classSkBitmap.html">SkBitmap</a> {
00023 <span class="keyword">public</span>:
<a name="l00024"></a><a class="code" href="classSkBitmap.html#w7">00024</a> <span class="keyword">enum</span> <a class="code" href="classSkBitmap.html#w7">Config</a> {
00025 kNo_Config,
00026 <a class="code" href="classSkBitmap.html#w7w1">kA1_Config</a>,
00027 <a class="code" href="classSkBitmap.html#w7w2">kA8_Config</a>,
00028 <a class="code" href="classSkBitmap.html#w7w3">kIndex8_Config</a>,
00029 <a class="code" href="classSkBitmap.html#w7w4">kRGB_565_Config</a>,
00030 <a class="code" href="classSkBitmap.html#w7w5">kARGB_8888_Config</a>,
00031
00032 kConfigCount
00033 };
00034
00038 <a class="code" href="classSkBitmap.html#a0">SkBitmap</a>();
00042 <a class="code" href="classSkBitmap.html#a0">SkBitmap</a>(<span class="keyword">const</span> <a class="code" href="classSkBitmap.html">SkBitmap</a>&amp; src);
00045 <a class="code" href="classSkBitmap.html#a2">~SkBitmap</a>();
00046
00050 <a class="code" href="classSkBitmap.html">SkBitmap</a>&amp; <a class="code" href="classSkBitmap.html#a3">operator=</a>(<span class="keyword">const</span> <a class="code" href="classSkBitmap.html">SkBitmap</a>&amp; src);
00053 <span class="keywordtype">void</span> <a class="code" href="classSkBitmap.html#a4">swap</a>(<a class="code" href="classSkBitmap.html">SkBitmap</a>&amp; other);
00054
<a name="l00057"></a><a class="code" href="classSkBitmap.html#a5">00057</a> <a class="code" href="classSkBitmap.html#w7">Config</a> <a class="code" href="classSkBitmap.html#a5">getConfig</a>()<span class="keyword"> const </span>{ <span class="keywordflow">return</span> (<a class="code" href="classSkBitmap.html#w7">Config</a>)fConfig; }
<a name="l00060"></a><a class="code" href="classSkBitmap.html#a6">00060</a> <span class="keywordtype">unsigned</span> <a class="code" href="classSkBitmap.html#a6">width</a>()<span class="keyword"> const </span>{ <span class="keywordflow">return</span> fWidth; }
<a name="l00063"></a><a class="code" href="classSkBitmap.html#a7">00063</a> <span class="keywordtype">unsigned</span> <a class="code" href="classSkBitmap.html#a7">height</a>()<span class="keyword"> const </span>{ <span class="keywordflow">return</span> fHeight; }
<a name="l00066"></a><a class="code" href="classSkBitmap.html#a8">00066</a> <span class="keywordtype">unsigned</span> <a class="code" href="classSkBitmap.html#a8">rowBytes</a>()<span class="keyword"> const </span>{ <span class="keywordflow">return</span> fRowBytes; }
<a name="l00072"></a><a class="code" href="classSkBitmap.html#a9">00072</a> <span class="keywordtype">void</span>* <a class="code" href="classSkBitmap.html#a9">getPixels</a>()<span class="keyword"> const </span>{ <span class="keywordflow">return</span> fPixels; }
<a name="l00075"></a><a class="code" href="classSkBitmap.html#a10">00075</a> size_t <a class="code" href="classSkBitmap.html#a10">getSize</a>()<span class="keyword"> const </span>{ <span class="keywordflow">return</span> fHeight * fRowBytes; }
00076
00079 <span class="keywordtype">bool</span> <a class="code" href="classSkBitmap.html#a11">isOpaque</a>() <span class="keyword">const</span>;
00083 <span class="keywordtype">void</span> <a class="code" href="classSkBitmap.html#a12">setIsOpaque</a>(<span class="keywordtype">bool</span>);
00084
00088 <span class="keywordtype">void</span> <a class="code" href="classSkBitmap.html#a13">reset</a>();
00093 <span class="keywordtype">void</span> <a class="code" href="classSkBitmap.html#a14">setConfig</a>(Config, U16CPU width, U16CPU height, U16CPU rowBytes = 0);
00098 <span class="keywordtype">void</span> <a class="code" href="classSkBitmap.html#a15">setPixels</a>(<span class="keywordtype">void</span>* p);
00103 <span class="keywordtype">void</span> <a class="code" href="classSkBitmap.html#a16">allocPixels</a>();
00108 <span class="comment">// not implemented</span>
00109 <span class="comment">// void resizeAlloc(U16CPU width, U16CPU height);</span>
00110
00114 <span class="keywordtype">bool</span> <a class="code" href="classSkBitmap.html#a17">getOwnsPixels</a>() <span class="keyword">const</span>;
00119 <span class="keywordtype">void</span> <a class="code" href="classSkBitmap.html#a18">setOwnsPixels</a>(<span class="keywordtype">bool</span> ownsPixels);
00120
<a name="l00124"></a><a class="code" href="classSkBitmap.html#a19">00124</a> <a class="code" href="classSkColorTable.html">SkColorTable</a>* <a class="code" href="classSkBitmap.html#a19">getColorTable</a>()<span class="keyword"> const </span>{ <span class="keywordflow">return</span> fColorTable; }
00132 <a class="code" href="classSkColorTable.html">SkColorTable</a>* <a class="code" href="classSkBitmap.html#a20">setColorTable</a>(<a class="code" href="classSkColorTable.html">SkColorTable</a>* ctable);
00133
00138 <span class="keywordtype">void</span> <a class="code" href="classSkBitmap.html#a21">eraseARGB</a>(U8CPU a, U8CPU r, U8CPU g, U8CPU b);
<a name="l00144"></a><a class="code" href="classSkBitmap.html#a22">00144</a> <span class="keywordtype">void</span> <a class="code" href="classSkBitmap.html#a22">eraseRGB</a>(U8CPU r, U8CPU g, U8CPU b)
00145 {
00146 this-&gt;<a class="code" href="classSkBitmap.html#a21">eraseARGB</a>(0xFF, r, g, b);
00147 }
<a name="l00152"></a><a class="code" href="classSkBitmap.html#a23">00152</a> <span class="keywordtype">void</span> <a class="code" href="classSkBitmap.html#a23">eraseColor</a>(SkColor c)
00153 {
00154 this-&gt;<a class="code" href="classSkBitmap.html#a21">eraseARGB</a>(<a class="code" href="SkColor_8h.html#a1">SkColorGetA</a>(c), <a class="code" href="SkColor_8h.html#a2">SkColorGetR</a>(c), <a class="code" href="SkColor_8h.html#a3">SkColorGetG</a>(c), <a class="code" href="SkColor_8h.html#a4">SkColorGetB</a>(c));
00155 }
00156
00160 <span class="keyword">inline</span> uint32_t* <a class="code" href="classSkBitmap.html#a24">getAddr32</a>(<span class="keywordtype">int</span> x, <span class="keywordtype">int</span> y) <span class="keyword">const</span>;
00164 <span class="keyword">inline</span> uint16_t* <a class="code" href="classSkBitmap.html#a25">getAddr16</a>(<span class="keywordtype">int</span> x, <span class="keywordtype">int</span> y) <span class="keyword">const</span>;
00168 <span class="keyword">inline</span> uint8_t* <a class="code" href="classSkBitmap.html#a26">getAddr8</a>(<span class="keywordtype">int</span> x, <span class="keywordtype">int</span> y) <span class="keyword">const</span>;
00172 <span class="keyword">inline</span> <a class="code" href="SkColor_8h.html#a18">SkPMColor</a> <a class="code" href="classSkBitmap.html#a27">getIndex8Color</a>(<span class="keywordtype">int</span> x, <span class="keywordtype">int</span> y) <span class="keyword">const</span>;
00176 <span class="keyword">inline</span> uint8_t* <a class="code" href="classSkBitmap.html#a28">getAddr1</a>(<span class="keywordtype">int</span> x, <span class="keywordtype">int</span> y) <span class="keyword">const</span>;
00177
00178 <span class="preprocessor">#ifdef SK_SUPPORT_16_8_BITMAP</span>
00179 <span class="preprocessor"></span> uint8_t* getA8Plane()<span class="keyword"> const </span>{ <span class="keywordflow">return</span> fA8Plane; }
00180 <span class="keywordtype">void</span> setA8Plane(U8* plane) { fA8Plane = plane; }
00181 <span class="keywordtype">unsigned</span> getA8PlaneRowBytes()<span class="keyword"> const </span>{ <span class="keywordflow">return</span> fA8PlaneRowBytes; }
00182 <span class="keywordtype">void</span> setA8PlaneRowBytes(U16CPU rb) { fA8PlaneRowBytes = SkToU16(rb); }
00183 <span class="preprocessor">#endif</span>
00184 <span class="preprocessor"></span>
00190 <span class="keywordtype">void</span> <a class="code" href="classSkBitmap.html#a29">applyGamma</a>(<span class="keyword">const</span> U8 red[256], <span class="keyword">const</span> U8 green[256], <span class="keyword">const</span> U8 blue[256]);
00191 <span class="keywordtype">void</span> <a class="code" href="classSkBitmap.html#a29">applyGamma</a>(<span class="keyword">const</span> U8 table[256])
00192 {
00193 this-&gt;<a class="code" href="classSkBitmap.html#a29">applyGamma</a>(table, table, table);
00194 }
00195
00196 <span class="comment">// OS-specific helpers</span>
00197 <span class="preprocessor">#ifndef SK_USE_WXWIDGETS</span>
00198 <span class="preprocessor"></span><span class="preprocessor">#ifdef SK_BUILD_FOR_WIN</span>
00199 <span class="preprocessor"></span>
00202 <span class="keywordtype">void</span> drawToHDC(HDC, <span class="keywordtype">int</span> left, <span class="keywordtype">int</span> top) <span class="keyword">const</span>;
00203 <span class="preprocessor">#elif defined(SK_BUILD_FOR_MAC)</span>
00204 <span class="preprocessor"></span>
00207 <span class="keywordtype">void</span> drawToPort(WindowRef) <span class="keyword">const</span>;
00208 <span class="preprocessor">#elif defined(SK_BUILD_FOR_UNIX)</span>
00209 <span class="preprocessor"></span>
00212 <span class="comment">//void drawToWin(Display*, Window) const;</span>
00213 <span class="comment">// not implemented</span>
00214 <span class="comment">// void drawToWin(void*, void*) const;</span>
00215 <span class="preprocessor">#endif</span>
00216 <span class="preprocessor"></span><span class="preprocessor">#endif</span>
00217 <span class="preprocessor"></span>
00218 <span class="preprocessor">#ifdef SK_SUPPORT_MIPMAP</span>
00219 <span class="preprocessor"></span> <span class="keyword">struct </span>MipLevel {
00220 <span class="keywordtype">void</span>* fPixels;
00221 uint16_t fWidth, fHeight, fRowBytes;
00222 uint8_t fConfig, fShift;
00223 };
00224 <span class="keywordtype">void</span> buildMipMap();
00225 <span class="keywordtype">unsigned</span> countMipLevels() <span class="keyword">const</span>;
00226 <span class="keyword">const</span> MipLevel* getMipLevel(<span class="keywordtype">unsigned</span> level) <span class="keyword">const</span>;
00227 <span class="preprocessor">#endif</span>
00228 <span class="preprocessor"></span>
00229 <span class="keyword">private</span>:
00230 <a class="code" href="classSkColorTable.html">SkColorTable</a>* fColorTable; <span class="comment">// only meaningful for kIndex8</span>
00231 <span class="preprocessor">#ifdef SK_SUPPORT_16_8_BITMAP</span>
00232 <span class="preprocessor"></span> U8* fA8Plane;
00233 uint16_t fA8PlaneRowBytes;
00234 <span class="preprocessor">#endif</span>
00235 <span class="preprocessor"></span>
00236 <span class="preprocessor">#ifdef SK_SUPPORT_MIPMAP</span>
00237 <span class="preprocessor"></span> <span class="keyword">enum</span> {
00238 kMaxMipLevels = 5
00239 };
00240 <span class="keyword">struct </span>MipMap {
00241 MipLevel fLevel[kMaxMipLevels];
00242 };
00243 MipMap* fMipMap;
00244 <span class="preprocessor">#endif</span>
00245 <span class="preprocessor"></span>
00246 <span class="keyword">enum</span> Flags {
00247 kWeOwnThePixels_Flag = 0x01,
00248 kWeOwnTheMipMap_Flag = 0x02,
00249 kImageIsOpaque_Flag = 0x04
00250 };
00251
00252 <span class="keywordtype">void</span>* fPixels;
00253 uint16_t fWidth, fHeight, fRowBytes;
00254 uint8_t fConfig;
00255 uint8_t fFlags;
00256
00257 <span class="keywordtype">void</span> freePixels();
00258 };
00259
<a name="l00265"></a><a class="code" href="classSkColorTable.html">00265</a> <span class="keyword">class </span><a class="code" href="classSkColorTable.html">SkColorTable</a> : <span class="keyword">public</span> <a class="code" href="classSkRefCnt.html">SkRefCnt</a> {
00266 <span class="keyword">public</span>:
00269 <a class="code" href="classSkColorTable.html#a0">SkColorTable</a>();
00270 <span class="keyword">virtual</span> ~<a class="code" href="classSkColorTable.html">SkColorTable</a>();
00271
<a name="l00272"></a><a class="code" href="classSkColorTable.html#w1">00272</a> <span class="keyword">enum</span> <a class="code" href="classSkColorTable.html#w1">Flags</a> {
00273 <a class="code" href="classSkColorTable.html#w1w0">kColorsAreOpaque_Flag</a> = 0x01
00274 };
<a name="l00277"></a><a class="code" href="classSkColorTable.html#a2">00277</a> <span class="keywordtype">unsigned</span> <a class="code" href="classSkColorTable.html#a2">getFlags</a>()<span class="keyword"> const </span>{ <span class="keywordflow">return</span> fFlags; }
00280 <span class="keywordtype">void</span> <a class="code" href="classSkColorTable.html#a3">setFlags</a>(<span class="keywordtype">unsigned</span> flags);
00281
<a name="l00284"></a><a class="code" href="classSkColorTable.html#a4">00284</a> <span class="keywordtype">int</span> <a class="code" href="classSkColorTable.html#a4">count</a>()<span class="keyword"> const </span>{ <span class="keywordflow">return</span> fCount; }
00285
<a name="l00289"></a><a class="code" href="classSkColorTable.html#a5">00289</a> <a class="code" href="SkColor_8h.html#a18">SkPMColor</a> <a class="code" href="classSkColorTable.html#a5">operator[]</a>(<span class="keywordtype">int</span> index)<span class="keyword"> const</span>
00290 <span class="keyword"> </span>{
00291 SkASSERT(fColors != nil &amp;&amp; (<span class="keywordtype">unsigned</span>)index &lt; fCount);
00292 <span class="keywordflow">return</span> fColors[index];
00293 }
00294
<a name="l00300"></a><a class="code" href="classSkColorTable.html#a6">00300</a> <span class="keywordtype">void</span> <a class="code" href="classSkColorTable.html#a6">setColors</a>(<span class="keywordtype">int</span> count) { this-&gt;<a class="code" href="classSkColorTable.html#a6">setColors</a>(nil, count); }
00301 <span class="keywordtype">void</span> <a class="code" href="classSkColorTable.html#a6">setColors</a>(<span class="keyword">const</span> SkPMColor[], <span class="keywordtype">int</span> count);
00302
<a name="l00307"></a><a class="code" href="classSkColorTable.html#a8">00307</a> <a class="code" href="SkColor_8h.html#a18">SkPMColor</a>* <a class="code" href="classSkColorTable.html#a8">lockColors</a>()
00308 {
00309 SkDEBUGCODE(fColorLockCount += 1;)
00310 <span class="keywordflow">return</span> fColors;
00311 }
<a name="l00314"></a><a class="code" href="classSkColorTable.html#a9">00314</a> <span class="keywordtype">void</span> <a class="code" href="classSkColorTable.html#a9">unlockColors</a>(<span class="keywordtype">bool</span> changed)
00315 {
00316 SkASSERT(fColorLockCount != 0);
00317 SkDEBUGCODE(fColorLockCount -= 1;)
00318 }
00319
00325 <span class="keyword">const</span> uint16_t* <a class="code" href="classSkColorTable.html#a10">lock16BitCache</a>();
<a name="l00328"></a><a class="code" href="classSkColorTable.html#a11">00328</a> <span class="keywordtype">void</span> <a class="code" href="classSkColorTable.html#a11">unlock16BitCache</a>()
00329 {
00330 SkASSERT(f16BitCacheLockCount &gt; 0);
00331 SkDEBUGCODE(f16BitCacheLockCount -= 1);
00332 }
00333
00334 <span class="keyword">private</span>:
00335 <a class="code" href="SkColor_8h.html#a18">SkPMColor</a>* fColors;
00336 uint16_t* f16BitCache;
00337 uint16_t fCount;
00338 uint8_t fFlags;
00339 SkDEBUGCODE(<span class="keywordtype">int</span> fColorLockCount;)
00340 SkDEBUGCODE(<span class="keywordtype">int</span> f16BitCacheLockCount;)
00341
00342 <span class="keywordtype">void</span> inval16BitCache();
00343 };
00344
00346
<a name="l00347"></a><a class="code" href="classSkBitmap.html#a24">00347</a> <span class="keyword">inline</span> uint32_t* <a class="code" href="classSkBitmap.html#a24">SkBitmap::getAddr32</a>(<span class="keywordtype">int</span> x, <span class="keywordtype">int</span> y)<span class="keyword"> const</span>
00348 <span class="keyword"></span>{
00349 SkASSERT(fPixels);
00350 SkASSERT(fConfig == <a class="code" href="classSkBitmap.html#w7w5">kARGB_8888_Config</a>);
00351 SkASSERT((<span class="keywordtype">unsigned</span>)x &lt; fWidth &amp;&amp; (<span class="keywordtype">unsigned</span>)y &lt; fHeight);
00352
00353 <span class="keywordflow">return</span> (uint32_t*)((<span class="keywordtype">char</span>*)fPixels + y * fRowBytes + (x &lt;&lt; 2));
00354 }
00355
<a name="l00356"></a><a class="code" href="classSkBitmap.html#a25">00356</a> <span class="keyword">inline</span> uint16_t* <a class="code" href="classSkBitmap.html#a25">SkBitmap::getAddr16</a>(<span class="keywordtype">int</span> x, <span class="keywordtype">int</span> y)<span class="keyword"> const</span>
00357 <span class="keyword"></span>{
00358 SkASSERT(fPixels);
00359 SkASSERT(fConfig == <a class="code" href="classSkBitmap.html#w7w4">kRGB_565_Config</a>);
00360 SkASSERT((<span class="keywordtype">unsigned</span>)x &lt; fWidth &amp;&amp; (<span class="keywordtype">unsigned</span>)y &lt; fHeight);
00361
00362 <span class="keywordflow">return</span> (uint16_t*)((<span class="keywordtype">char</span>*)fPixels + y * fRowBytes + (x &lt;&lt; 1));
00363 }
00364
<a name="l00365"></a><a class="code" href="classSkBitmap.html#a26">00365</a> <span class="keyword">inline</span> uint8_t* <a class="code" href="classSkBitmap.html#a26">SkBitmap::getAddr8</a>(<span class="keywordtype">int</span> x, <span class="keywordtype">int</span> y)<span class="keyword"> const</span>
00366 <span class="keyword"></span>{
00367 SkASSERT(fPixels);
00368 SkASSERT(fConfig == <a class="code" href="classSkBitmap.html#w7w2">kA8_Config</a> || fConfig == <a class="code" href="classSkBitmap.html#w7w3">kIndex8_Config</a>);
00369 SkASSERT((<span class="keywordtype">unsigned</span>)x &lt; fWidth &amp;&amp; (<span class="keywordtype">unsigned</span>)y &lt; fHeight);
00370 <span class="keywordflow">return</span> (uint8_t*)fPixels + y * fRowBytes + x;
00371 }
00372
<a name="l00373"></a><a class="code" href="classSkBitmap.html#a27">00373</a> <span class="keyword">inline</span> <a class="code" href="SkColor_8h.html#a18">SkPMColor</a> <a class="code" href="classSkBitmap.html#a27">SkBitmap::getIndex8Color</a>(<span class="keywordtype">int</span> x, <span class="keywordtype">int</span> y)<span class="keyword"> const</span>
00374 <span class="keyword"></span>{
00375 SkASSERT(fPixels);
00376 SkASSERT(fConfig == <a class="code" href="classSkBitmap.html#w7w3">kIndex8_Config</a>);
00377 SkASSERT((<span class="keywordtype">unsigned</span>)x &lt; fWidth &amp;&amp; (<span class="keywordtype">unsigned</span>)y &lt; fHeight);
00378 SkASSERT(fColorTable);
00379 <span class="keywordflow">return</span> (*fColorTable)[*((<span class="keyword">const</span> uint8_t*)fPixels + y * fRowBytes + x)];
00380 }
00381
00382 <span class="comment">// returns the address of the byte that contains the x coordinate</span>
<a name="l00383"></a><a class="code" href="classSkBitmap.html#a28">00383</a> <span class="keyword">inline</span> uint8_t* <a class="code" href="classSkBitmap.html#a28">SkBitmap::getAddr1</a>(<span class="keywordtype">int</span> x, <span class="keywordtype">int</span> y)<span class="keyword"> const</span>
00384 <span class="keyword"></span>{
00385 SkASSERT(fPixels);
00386 SkASSERT(fConfig == <a class="code" href="classSkBitmap.html#w7w1">kA1_Config</a>);
00387 SkASSERT((<span class="keywordtype">unsigned</span>)x &lt; fWidth &amp;&amp; (<span class="keywordtype">unsigned</span>)y &lt; fHeight);
00388 <span class="keywordflow">return</span> (uint8_t*)fPixels + y * fRowBytes + (x &gt;&gt; 3);
00389 }
00390
00391
00392 <span class="preprocessor">#endif</span>
00393 <span class="preprocessor"></span>
</pre></div><hr size="1"><address style="align: right;"><small>Generated on Tue May 9 14:35:23 2006 for SGL by&nbsp;
<a href="http://www.doxygen.org/index.html">
<img src="doxygen.png" alt="doxygen" align="middle" border="0"></a> 1.4.0 </small></address>
</body>
</html>