2 * Copyright (c) 2007 Ivan Leben
4 * This library is free software; you can redistribute it and/or
5 * modify it under the terms of the GNU Lesser General Public
6 * License as published by the Free Software Foundation; either
7 * version 2.1 of the License, or (at your option) any later version.
9 * This library is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 * Lesser General Public License for more details.
14 * You should have received a copy of the GNU Lesser General Public
15 * License along with this library in the file COPYING;
16 * if not, write to the Free Software Foundation, Inc.,
17 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
26 /*-----------------------------------------------------------
27 * ColorFormat holds the data necessary to pack/unpack color
28 * components from a pixel of each supported image format
29 *-----------------------------------------------------------*/
33 VGImageFormat vgformat;
64 void SHColor_ctor(SHColor *c);
65 void SHColor_dtor(SHColor *c);
67 #define _ITEM_T SHColor
68 #define _ARRAY_T SHColorArray
69 #define _FUNC_T shColorArray
70 #define _ARRAY_DECLARE
71 #include "shArrayBase.h"
88 void SHImage_ctor(SHImage *i);
89 void SHImage_dtor(SHImage *i);
91 #define _ITEM_T SHImage*
92 #define _ARRAY_T SHImageArray
93 #define _FUNC_T shImageArray
94 #define _ARRAY_DECLARE
95 #include "shArrayBase.h"
97 /*-------------------------------------------------------
99 *-------------------------------------------------------*/
101 #define CSET(c, rr,gg,bb,aa) { c.r=rr; c.g=gg; c.b=bb; c.a=aa; }
102 #define CSETC(c1, c2) { c1.r=c2.r; c1.g=c2.g; c1.b=c2.b; c1.a=c2.a; }
104 #define CSUB(c1, rr,gg,bb,aa) { c.r-=rr; c.g-=gg; c.b-=bb; c.a-=aa; }
105 #define CSUBC(c1, c2) { c1.r-=c2.r; c1.g-=c2.g; c1.b-=c2.b; c1.a-=c2.a; }
106 #define CSUBCTO(c1, c2, c3) { c3.r=c1.r-c2.r; c3.g=c1.g-c2.g; c3.b=c1.b-c2.b; c3.a=c1.a-c2.a; }
108 #define CADD(c1, rr,gg,bb,aa) { c.r+=rr; c.g+=gg; c.b+=bb; c.a+=aa; }
109 #define CADDC(c1, c2) { c1.r+=c2.r; c1.g+=c2.g; c1.b+=c2.b; c1.a+=c2.a; }
110 #define CADDTO(c1, c2, c3) { c3.r=c1.r+c2.r; c3.g=c1.g+c2.g; c3.b=c1.b+c2.b; c3.a=c1.a+c2.a; }
111 #define CADDCK(c1, c2, k) { c1.r+=k*c2.r; c1.g+=k*c2.g; c1.b+=k*c2.b; c1.a+=k*c2.a; }
113 #define CMUL(c, s) { c.r*=s; c.g*=s; c.b*=s; c.a*=s; }
114 #define CDIV(c, s) { c.r/=s; c.g/=s; c.b/=s; c.a/=s; }
116 #define CPREMUL(c) { c.r*=c.a; c.g*=c.a; c.b*=c.a; }
117 #define CUNPREMUL(c) { c.r/=c.a; c.g/=c.a; c.b/=c.a; }
119 /*-------------------------------------------------------
120 * Color-to-memory functions
121 *-------------------------------------------------------*/
123 #define CSTORE_RGBA1D_8(c, rgba, x) { \
124 rgba[x*4+0] = (SHuint8)SH_FLOOR(c.r * 255); \
125 rgba[x*4+1] = (SHuint8)SH_FLOOR(c.g * 255); \
126 rgba[x*4+2] = (SHuint8)SH_FLOOR(c.b * 255); \
127 rgba[x*4+3] = (SHuint8)SH_FLOOR(c.a * 255); }
129 #define CSTORE_RGBA1D_F(c, rgba, x) { \
135 #define CSTORE_RGBA2D_8(c, rgba, x, y, width) { \
136 rgba[y*width*4+x*4+0] = (SHuint8)SH_FLOOR(c.r * 255); \
137 rgba[y*width*4+x*4+1] = (SHuint8)SH_FLOOR(c.g * 255); \
138 rgba[y*width*4+x*4+2] = (SHuint8)SH_FLOOR(c.b * 255); \
139 rgba[y*width*4+x*4+3] = (SHuint8)SH_FLOOR(c.a * 255); }
141 #define CSTORE_RGBA2D_F(c, rgba, x, y, width) { \
142 rgba[y*width*4+x*4+0] = c.r; \
143 rgba[y*width*4+x*4+1] = c.g; \
144 rgba[y*width*4+x*4+2] = c.b; \
145 rgba[y*width*4+x*4+3] = c.a; }
147 #define INT2COLCOORD(i, max) ( (SHfloat)i / (SHfloat)max )
148 #define COL2INTCOORD(c, max) ( (SHuint)SH_FLOOR(c * (SHfloat)max + 0.5f) )
150 void shStoreColor(SHColor *c, void *data, SHImageFormatDesc *f);
151 void shLoadColor(SHColor *c, const void *data, SHImageFormatDesc *f);
154 #endif /* __SHIMAGE_H */