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 <libraries/Picasso96.h>
30 #include <proto/Picasso96API.h>
32 BOOL
IsSupportedRGBFormat_P96 (ULONG rgbformat
) {
53 IPTR
WriteRGBAPixels_P96 (REG(a0
, struct Hook
*hook
), REG(a2
, struct RastPort
*rp
),
54 REG(a1
, struct BackFillMessage
*msg
))
56 struct HookData
*data
= hook
->h_Data
;
62 ULONG src_mod
, dst_mod
;
64 w
= msg
->Bounds
.MaxX
- msg
->Bounds
.MinX
+ 1;
65 h
= msg
->Bounds
.MaxY
- msg
->Bounds
.MinY
+ 1;
67 src
= data
->image
+ (msg
->OffsetY
- data
->y
) * (data
->w
* 4UL) + (msg
->OffsetX
- data
->x
) * 4UL;
68 src_mod
= (data
->w
- w
) * 4UL;
70 lock
= p96LockBitMap(rp
->BitMap
, (UBYTE
*)&ri
, sizeof(ri
));
72 bpp
= p96GetBitMapAttr(rp
->BitMap
, P96BMA_BYTESPERPIXEL
);
73 dst
= (UBYTE
*)ri
.Memory
+ msg
->Bounds
.MinY
* ri
.BytesPerRow
+ msg
->Bounds
.MinX
* bpp
;
74 dst_mod
= ri
.BytesPerRow
- w
* bpp
;
76 switch (ri
.RGBFormat
) {
82 for (y
= 0; y
< h
; y
++) {
83 for (x
= 0; x
< w
; x
++) {
88 r
= (src
[0] >> 3) + ((a5
* ((rgb
>> 11) & 31)) >> 5);
89 g
= (src
[1] >> 2) + ((a6
* ((rgb
>> 5) & 63)) >> 6);
90 b
= (src
[2] >> 3) + ((a5
* ((rgb
) & 31)) >> 5);
91 wbe16(dst
, (r
<< 11)|(g
<< 5)|(b
));
107 for (y
= 0; y
< h
; y
++) {
108 for (x
= 0; x
< w
; x
++) {
113 r
= (src
[0] >> 3) + ((a5
* ((rgb
>> 11) & 31)) >> 5);
114 g
= (src
[1] >> 2) + ((a6
* ((rgb
>> 5) & 63)) >> 6);
115 b
= (src
[2] >> 3) + ((a5
* ((rgb
) & 31)) >> 5);
116 wle16(dst
, (r
<< 11)|(g
<< 5)|(b
));
132 for (y
= 0; y
< h
; y
++) {
133 for (x
= 0; x
< w
; x
++) {
138 b
= (src
[2] >> 3) + ((a5
* ((rgb
>> 11) & 31)) >> 5);
139 g
= (src
[1] >> 2) + ((a6
* ((rgb
>> 5) & 63)) >> 6);
140 r
= (src
[0] >> 3) + ((a5
* ((rgb
) & 31)) >> 5);
141 wle16(dst
, (b
<< 11)|(g
<< 5)|(r
));
157 for (y
= 0; y
< h
; y
++) {
158 for (x
= 0; x
< w
; x
++) {
162 r
= (src
[0] >> 3) + ((a5
* ((rgb
>> 10) & 31)) >> 5);
163 g
= (src
[1] >> 3) + ((a5
* ((rgb
>> 5) & 31)) >> 5);
164 b
= (src
[2] >> 3) + ((a5
* ((rgb
) & 31)) >> 5);
165 wbe16(dst
, (r
<< 10)|(g
<< 5)|(b
));
181 for (y
= 0; y
< h
; y
++) {
182 for (x
= 0; x
< w
; x
++) {
186 r
= (src
[0] >> 3) + ((a5
* ((rgb
>> 10) & 31)) >> 5);
187 g
= (src
[1] >> 3) + ((a5
* ((rgb
>> 5) & 31)) >> 5);
188 b
= (src
[2] >> 3) + ((a5
* ((rgb
) & 31)) >> 5);
189 wle16(dst
, (r
<< 10)|(g
<< 5)|(b
));
205 for (y
= 0; y
< h
; y
++) {
206 for (x
= 0; x
< w
; x
++) {
210 b
= (src
[2] >> 3) + ((a5
* ((rgb
>> 10) & 31)) >> 5);
211 g
= (src
[1] >> 3) + ((a5
* ((rgb
>> 5) & 31)) >> 5);
212 r
= (src
[0] >> 3) + ((a5
* ((rgb
) & 31)) >> 5);
213 wle16(dst
, (b
<< 10)|(g
<< 5)|(r
));
230 pre
= (ri
.RGBFormat
== RGBFB_A8R8G8B8
);
231 post
= (ri
.RGBFormat
== RGBFB_R8G8B8A8
);
232 for (y
= 0; y
< h
; y
++) {
233 for (x
= 0; x
< w
; x
++) {
237 dst
[0] = src
[0] + ((a
* dst
[0]) >> 8);
238 dst
[1] = src
[1] + ((a
* dst
[1]) >> 8);
239 dst
[2] = src
[2] + ((a
* dst
[2]) >> 8);
257 pre
= (ri
.RGBFormat
== RGBFB_A8B8G8R8
);
258 post
= (ri
.RGBFormat
== RGBFB_B8G8R8A8
);
259 for (y
= 0; y
< h
; y
++) {
260 for (x
= 0; x
< w
; x
++) {
264 dst
[0] = src
[2] + ((a
* dst
[0]) >> 8);
265 dst
[1] = src
[1] + ((a
* dst
[1]) >> 8);
266 dst
[2] = src
[0] + ((a
* dst
[2]) >> 8);
279 p96UnlockBitMap(rp
->BitMap
, lock
);