1 #define __NR_PIXBLOCK_PIXEL_C__
3 /*
4 * Pixel buffer rendering library
5 *
6 * Authors:
7 * Lauris Kaplinski <lauris@kaplinski.com>
8 *
9 * This code is in public domain
10 */
12 #include "nr-pixops.h"
13 #include "nr-pixblock-pixel.h"
15 void
16 nr_compose_pixblock_pixblock_pixel (NRPixBlock *dpb, unsigned char *d, const NRPixBlock *spb, const unsigned char *s)
17 {
18 if (spb->empty) return;
20 if (dpb->empty) {
21 /* Empty destination */
22 switch (dpb->mode) {
23 case NR_PIXBLOCK_MODE_A8:
24 switch (spb->mode) {
25 case NR_PIXBLOCK_MODE_A8:
26 break;
27 case NR_PIXBLOCK_MODE_R8G8B8:
28 d[0] = 255;
29 break;
30 case NR_PIXBLOCK_MODE_R8G8B8A8N:
31 d[0] = s[3];
32 break;
33 case NR_PIXBLOCK_MODE_R8G8B8A8P:
34 d[0] = s[3];
35 break;
36 default:
37 break;
38 }
39 break;
40 case NR_PIXBLOCK_MODE_R8G8B8:
41 switch (spb->mode) {
42 case NR_PIXBLOCK_MODE_A8:
43 break;
44 case NR_PIXBLOCK_MODE_R8G8B8:
45 d[0] = s[0];
46 d[1] = s[1];
47 d[2] = s[2];
48 break;
49 case NR_PIXBLOCK_MODE_R8G8B8A8N:
50 d[0] = NR_COMPOSEN11_1111 (s[0], s[3], 255);
51 d[1] = NR_COMPOSEN11_1111 (s[1], s[3], 255);
52 d[2] = NR_COMPOSEN11_1111 (s[2], s[3], 255);
53 break;
54 case NR_PIXBLOCK_MODE_R8G8B8A8P:
55 d[0] = NR_COMPOSEP11_1111 (s[0], s[3], 255);
56 d[1] = NR_COMPOSEP11_1111 (s[1], s[3], 255);
57 d[2] = NR_COMPOSEP11_1111 (s[2], s[3], 255);
58 break;
59 default:
60 break;
61 }
62 break;
63 case NR_PIXBLOCK_MODE_R8G8B8A8N:
64 switch (spb->mode) {
65 case NR_PIXBLOCK_MODE_A8:
66 break;
67 case NR_PIXBLOCK_MODE_R8G8B8:
68 d[0] = s[0];
69 d[1] = s[1];
70 d[2] = s[2];
71 d[3] = 255;
72 break;
73 case NR_PIXBLOCK_MODE_R8G8B8A8N:
74 d[0] = s[0];
75 d[1] = s[1];
76 d[2] = s[2];
77 d[3] = s[3];
78 break;
79 case NR_PIXBLOCK_MODE_R8G8B8A8P:
80 if (s[3] == 0) {
81 d[0] = 255;
82 d[1] = 255;
83 d[2] = 255;
84 } else {
85 d[0] = NR_DEMUL_111(s[0], s[3]);
86 d[1] = NR_DEMUL_111(s[0], s[3]);
87 d[2] = NR_DEMUL_111(s[0], s[3]);
88 }
89 d[3] = s[3];
90 break;
91 default:
92 break;
93 }
94 break;
95 case NR_PIXBLOCK_MODE_R8G8B8A8P:
96 switch (spb->mode) {
97 case NR_PIXBLOCK_MODE_A8:
98 break;
99 case NR_PIXBLOCK_MODE_R8G8B8:
100 d[0] = s[0];
101 d[1] = s[1];
102 d[2] = s[2];
103 d[3] = 255;
104 break;
105 case NR_PIXBLOCK_MODE_R8G8B8A8N:
106 d[0] = NR_PREMUL_111 (s[0], s[3]);
107 d[1] = NR_PREMUL_111 (s[1], s[3]);
108 d[2] = NR_PREMUL_111 (s[2], s[3]);
109 d[3] = s[3];
110 break;
111 case NR_PIXBLOCK_MODE_R8G8B8A8P:
112 d[0] = s[0];
113 d[1] = s[1];
114 d[2] = s[2];
115 d[3] = s[3];
116 break;
117 default:
118 break;
119 }
120 break;
121 default:
122 break;
123 }
124 } else {
125 /* Image destination */
126 switch (dpb->mode) {
127 case NR_PIXBLOCK_MODE_A8:
128 switch (spb->mode) {
129 case NR_PIXBLOCK_MODE_A8:
130 break;
131 case NR_PIXBLOCK_MODE_R8G8B8:
132 d[0] = 255;
133 break;
134 case NR_PIXBLOCK_MODE_R8G8B8A8N:
135 d[0] = NR_COMPOSEA_111(s[3], d[0]);
136 break;
137 case NR_PIXBLOCK_MODE_R8G8B8A8P:
138 d[0] = NR_COMPOSEA_111(s[3], d[0]);
139 break;
140 default:
141 break;
142 }
143 break;
144 case NR_PIXBLOCK_MODE_R8G8B8:
145 switch (spb->mode) {
146 case NR_PIXBLOCK_MODE_A8:
147 break;
148 case NR_PIXBLOCK_MODE_R8G8B8:
149 d[0] = s[0];
150 d[1] = s[1];
151 d[2] = s[2];
152 break;
153 case NR_PIXBLOCK_MODE_R8G8B8A8N:
154 d[0] = NR_COMPOSEN11_1111 (s[0], s[3], d[0]);
155 d[1] = NR_COMPOSEN11_1111 (s[1], s[3], d[1]);
156 d[2] = NR_COMPOSEN11_1111 (s[2], s[3], d[2]);
157 break;
158 case NR_PIXBLOCK_MODE_R8G8B8A8P:
159 d[0] = NR_COMPOSEP11_1111 (s[0], s[3], d[0]);
160 d[1] = NR_COMPOSEP11_1111 (s[1], s[3], d[1]);
161 d[2] = NR_COMPOSEP11_1111 (s[2], s[3], d[2]);
162 break;
163 default:
164 break;
165 }
166 break;
167 case NR_PIXBLOCK_MODE_R8G8B8A8N:
168 switch (spb->mode) {
169 case NR_PIXBLOCK_MODE_A8:
170 break;
171 case NR_PIXBLOCK_MODE_R8G8B8:
172 d[0] = s[0];
173 d[1] = s[1];
174 d[2] = s[2];
175 break;
176 case NR_PIXBLOCK_MODE_R8G8B8A8N:
177 if (s[3] != 0) {
178 unsigned int ca;
179 ca = NR_COMPOSEA_112(s[3], d[3]);
180 d[0] = NR_COMPOSENNN_111121 (s[0], s[3], d[0], d[3], ca);
181 d[1] = NR_COMPOSENNN_111121 (s[1], s[3], d[1], d[3], ca);
182 d[2] = NR_COMPOSENNN_111121 (s[2], s[3], d[2], d[3], ca);
183 d[3] = NR_NORMALIZE_21(ca);
184 }
185 break;
186 case NR_PIXBLOCK_MODE_R8G8B8A8P:
187 if (s[3] != 0) {
188 unsigned int ca;
189 ca = NR_COMPOSEA_112(s[3], d[3]);
190 d[0] = NR_COMPOSEPNN_111121 (s[0], s[3], d[0], d[3], ca);
191 d[1] = NR_COMPOSEPNN_111121 (s[1], s[3], d[0], d[3], ca);
192 d[2] = NR_COMPOSEPNN_111121 (s[2], s[3], d[0], d[3], ca);
193 d[3] = NR_NORMALIZE_21(ca);
194 }
195 break;
196 default:
197 break;
198 }
199 break;
200 case NR_PIXBLOCK_MODE_R8G8B8A8P:
201 switch (spb->mode) {
202 case NR_PIXBLOCK_MODE_A8:
203 break;
204 case NR_PIXBLOCK_MODE_R8G8B8:
205 d[0] = s[0];
206 d[1] = s[1];
207 d[2] = s[2];
208 break;
209 case NR_PIXBLOCK_MODE_R8G8B8A8N:
210 d[0] = NR_COMPOSENPP_1111 (s[0], s[3], d[0]);
211 d[1] = NR_COMPOSENPP_1111 (s[1], s[3], d[1]);
212 d[2] = NR_COMPOSENPP_1111 (s[2], s[3], d[2]);
213 d[3] = NR_COMPOSEA_111(s[3], d[3]);
214 break;
215 case NR_PIXBLOCK_MODE_R8G8B8A8P:
216 d[0] = NR_COMPOSEPPP_1111 (s[0], s[3], d[0]);
217 d[1] = NR_COMPOSEPPP_1111 (s[1], s[3], d[1]);
218 d[2] = NR_COMPOSEPPP_1111 (s[2], s[3], d[2]);
219 d[3] = NR_COMPOSEA_111(s[3], d[3]);
220 break;
221 default:
222 break;
223 }
224 break;
225 default:
226 break;
227 }
228 }
229 }