1 /* Copyright 2007-2012 Fredrik Wikstrom. All rights reserved.
3 ** Redistribution and use in source and binary forms, with or without
4 ** modification, are permitted provided that the following conditions
7 ** 1. Redistributions of source code must retain the above copyright
8 ** notice, this list of conditions and the following disclaimer.
10 ** 2. Redistributions in binary form must reproduce the above copyright
11 ** notice, this list of conditions and the following disclaimer in the
12 ** documentation and/or other materials provided with the distribution.
14 ** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS `AS IS'
15 ** AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
16 ** IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
17 ** ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
18 ** LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
19 ** CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
20 ** SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
21 ** INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
22 ** CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
23 ** ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
24 ** POSSIBILITY OF SUCH DAMAGE.
29 #include <cybergraphx/cybergraphics.h>
30 #include <proto/cybergraphics.h>
32 BOOL
IsSupportedRGBFormat_CGX (ULONG rgbformat
) {
54 IPTR
WriteRGBAPixels_CGX (REG(a0
, struct Hook
*hook
), REG(a2
, struct RastPort
*rp
),
55 REG(a1
, struct BackFillMessage
*msg
))
57 struct HookData
*data
= hook
->h_Data
;
63 ULONG src_mod
, dst_mod
;
65 w
= msg
->Bounds
.MaxX
- msg
->Bounds
.MinX
+ 1;
66 h
= msg
->Bounds
.MaxY
- msg
->Bounds
.MinY
+ 1;
68 src
= data
->image
+ (msg
->OffsetY
- data
->y
) * (data
->w
* 4UL) + (msg
->OffsetX
- data
->x
) * 4UL;
69 src_mod
= (data
->w
- w
) * 4UL;
71 lock
= LockBitMapTags(rp
->BitMap
,
72 LBMI_BASEADDRESS
, &dst
,
73 LBMI_BYTESPERPIX
, &bpp
,
74 LBMI_BYTESPERROW
, &bpr
,
75 LBMI_PIXFMT
, &rgbformat
,
81 dst
= dst
+ msg
->Bounds
.MinY
* bpr
+ msg
->Bounds
.MinX
* bpp
;
82 dst_mod
= bpr
- w
* bpp
;
90 for (y
= 0; y
< h
; y
++) {
91 for (x
= 0; x
< w
; x
++) {
96 r
= (src
[0] >> 3) + ((a5
* ((rgb
>> 11) & 31)) >> 5);
97 g
= (src
[1] >> 2) + ((a6
* ((rgb
>> 5) & 63)) >> 6);
98 b
= (src
[2] >> 3) + ((a5
* ((rgb
) & 31)) >> 5);
99 wbe16(dst
, (r
<< 11)|(g
<< 5)|(b
));
115 for (y
= 0; y
< h
; y
++) {
116 for (x
= 0; x
< w
; x
++) {
121 r
= (src
[0] >> 3) + ((a5
* ((rgb
>> 11) & 31)) >> 5);
122 g
= (src
[1] >> 2) + ((a6
* ((rgb
>> 5) & 63)) >> 6);
123 b
= (src
[2] >> 3) + ((a5
* ((rgb
) & 31)) >> 5);
124 wle16(dst
, (r
<< 11)|(g
<< 5)|(b
));
140 for (y
= 0; y
< h
; y
++) {
141 for (x
= 0; x
< w
; x
++) {
146 b
= (src
[2] >> 3) + ((a5
* ((rgb
>> 11) & 31)) >> 5);
147 g
= (src
[1] >> 2) + ((a6
* ((rgb
>> 5) & 63)) >> 6);
148 r
= (src
[0] >> 3) + ((a5
* ((rgb
) & 31)) >> 5);
149 wbe16(dst
, (b
<< 11)|(g
<< 5)|(r
));
165 for (y
= 0; y
< h
; y
++) {
166 for (x
= 0; x
< w
; x
++) {
171 b
= (src
[2] >> 3) + ((a5
* ((rgb
>> 11) & 31)) >> 5);
172 g
= (src
[1] >> 2) + ((a6
* ((rgb
>> 5) & 63)) >> 6);
173 r
= (src
[0] >> 3) + ((a5
* ((rgb
) & 31)) >> 5);
174 wle16(dst
, (b
<< 11)|(g
<< 5)|(r
));
190 for (y
= 0; y
< h
; y
++) {
191 for (x
= 0; x
< w
; x
++) {
195 r
= (src
[0] >> 3) + ((a5
* ((rgb
>> 10) & 31)) >> 5);
196 g
= (src
[1] >> 3) + ((a5
* ((rgb
>> 5) & 31)) >> 5);
197 b
= (src
[2] >> 3) + ((a5
* ((rgb
) & 31)) >> 5);
198 wbe16(dst
, (r
<< 10)|(g
<< 5)|(b
));
214 for (y
= 0; y
< h
; y
++) {
215 for (x
= 0; x
< w
; x
++) {
219 r
= (src
[0] >> 3) + ((a5
* ((rgb
>> 10) & 31)) >> 5);
220 g
= (src
[1] >> 3) + ((a5
* ((rgb
>> 5) & 31)) >> 5);
221 b
= (src
[2] >> 3) + ((a5
* ((rgb
) & 31)) >> 5);
222 wle16(dst
, (r
<< 10)|(g
<< 5)|(b
));
238 for (y
= 0; y
< h
; y
++) {
239 for (x
= 0; x
< w
; x
++) {
243 b
= (src
[2] >> 3) + ((a5
* ((rgb
>> 10) & 31)) >> 5);
244 g
= (src
[1] >> 3) + ((a5
* ((rgb
>> 5) & 31)) >> 5);
245 r
= (src
[0] >> 3) + ((a5
* ((rgb
) & 31)) >> 5);
246 wbe16(dst
, (b
<< 10)|(g
<< 5)|(r
));
262 for (y
= 0; y
< h
; y
++) {
263 for (x
= 0; x
< w
; x
++) {
267 b
= (src
[2] >> 3) + ((a5
* ((rgb
>> 10) & 31)) >> 5);
268 g
= (src
[1] >> 3) + ((a5
* ((rgb
>> 5) & 31)) >> 5);
269 r
= (src
[0] >> 3) + ((a5
* ((rgb
) & 31)) >> 5);
270 wle16(dst
, (b
<< 10)|(g
<< 5)|(r
));
287 pre
= (rgbformat
== PIXFMT_ARGB32
);
288 post
= (rgbformat
== PIXFMT_RGBA32
);
289 for (y
= 0; y
< h
; y
++) {
290 for (x
= 0; x
< w
; x
++) {
294 dst
[0] = src
[0] + ((a
* dst
[0]) >> 8);
295 dst
[1] = src
[1] + ((a
* dst
[1]) >> 8);
296 dst
[2] = src
[2] + ((a
* dst
[2]) >> 8);
313 post
= (rgbformat
== PIXFMT_BGRA32
);
314 for (y
= 0; y
< h
; y
++) {
315 for (x
= 0; x
< w
; x
++) {
318 dst
[0] = src
[2] + ((a
* dst
[0]) >> 8);
319 dst
[1] = src
[1] + ((a
* dst
[1]) >> 8);
320 dst
[2] = src
[0] + ((a
* dst
[2]) >> 8);