blob: c8e432df8626f9250878ffceaca571ef7cd1623d [file] [log] [blame]
Pierre Ossmanc02c05d2014-01-30 10:47:07 +01001/* Copyright 2014 Pierre Ossman for Cendio AB
2 *
3 * This is free software; you can redistribute it and/or modify
4 * it under the terms of the GNU General Public License as published by
5 * the Free Software Foundation; either version 2 of the License, or
6 * (at your option) any later version.
7 *
8 * This software is distributed in the hope that it will be useful,
9 * but WITHOUT ANY WARRANTY; without even the implied warranty of
10 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11 * GNU General Public License for more details.
12 *
13 * You should have received a copy of the GNU General Public License
14 * along with this software; if not, write to the Free Software
15 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307,
16 * USA.
17 */
18
19#define CONCAT2(a,b) a##b
20#define CONCAT2E(a,b) CONCAT2(a,b)
21
22#define UIN CONCAT2E(U,INBPP)
23#define UOUT CONCAT2E(U,OUTBPP)
24
25#define SWAP16(n) ((((n) & 0xff) << 8) | (((n) >> 8) & 0xff))
26#define SWAP32(n) (((n) >> 24) | (((n) & 0x00ff0000) >> 8) | \
27 (((n) & 0x0000ff00) << 8) | ((n) << 24))
28
29#define SWAPIN CONCAT2E(SWAP,INBPP)
30#define SWAPOUT CONCAT2E(SWAP,OUTBPP)
31
32#if INBPP == 32
33
34void PixelFormat::directBufferFromBufferFrom888(rdr::UOUT* dst,
35 const PixelFormat &srcPF,
36 const rdr::U8* src,
37 int w, int h,
38 int dstStride,
39 int srcStride) const
40{
41 const rdr::U8 *r, *g, *b;
42 int dstPad, srcPad;
43
Pierre Ossman816baa32018-03-01 14:11:39 +010044 const rdr::U8 *redDownTable, *greenDownTable, *blueDownTable;
Pierre Ossmanc02c05d2014-01-30 10:47:07 +010045
Pierre Ossman816baa32018-03-01 14:11:39 +010046 redDownTable = &downconvTable[(redBits-1)*256];
47 greenDownTable = &downconvTable[(greenBits-1)*256];
48 blueDownTable = &downconvTable[(blueBits-1)*256];
Pierre Ossmanc02c05d2014-01-30 10:47:07 +010049
50 if (srcPF.bigEndian) {
51 r = src + (24 - srcPF.redShift)/8;
52 g = src + (24 - srcPF.greenShift)/8;
53 b = src + (24 - srcPF.blueShift)/8;
54 } else {
55 r = src + srcPF.redShift/8;
56 g = src + srcPF.greenShift/8;
57 b = src + srcPF.blueShift/8;
58 }
59
60 dstPad = (dstStride - w);
61 srcPad = (srcStride - w) * 4;
62 while (h--) {
63 int w_ = w;
64 while (w_--) {
65 rdr::UOUT d;
66
Pierre Ossman816baa32018-03-01 14:11:39 +010067 d = redDownTable[*r] << redShift;
68 d |= greenDownTable[*g] << greenShift;
69 d |= blueDownTable[*b] << blueShift;
Pierre Ossmanc02c05d2014-01-30 10:47:07 +010070
71#if OUTBPP != 8
72 if (endianMismatch)
73 d = SWAPOUT(d);
74#endif
75
76 *dst = d;
77
78 dst++;
79 r += 4;
80 g += 4;
81 b += 4;
82 }
83 dst += dstPad;
84 r += srcPad;
85 g += srcPad;
86 b += srcPad;
87 }
88}
89
90#endif /* INBPP == 32 */
91
92#if OUTBPP == 32
93
94void PixelFormat::directBufferFromBufferTo888(rdr::U8* dst,
95 const PixelFormat &srcPF,
96 const rdr::UIN* src,
97 int w, int h,
98 int dstStride,
99 int srcStride) const
100{
101 rdr::U8 *r, *g, *b, *x;
102 int dstPad, srcPad;
103
104 const rdr::U8 *redUpTable, *greenUpTable, *blueUpTable;
105
106 redUpTable = &upconvTable[(srcPF.redBits-1)*256];
107 greenUpTable = &upconvTable[(srcPF.greenBits-1)*256];
108 blueUpTable = &upconvTable[(srcPF.blueBits-1)*256];
109
110 if (bigEndian) {
111 r = dst + (24 - redShift)/8;
112 g = dst + (24 - greenShift)/8;
113 b = dst + (24 - blueShift)/8;
114 x = dst + (24 - (48 - redShift - greenShift - blueShift))/8;
115 } else {
116 r = dst + redShift/8;
117 g = dst + greenShift/8;
118 b = dst + blueShift/8;
119 x = dst + (48 - redShift - greenShift - blueShift)/8;
120 }
121
122 dstPad = (dstStride - w) * 4;
123 srcPad = (srcStride - w);
124 while (h--) {
125 int w_ = w;
126 while (w_--) {
127 rdr::UIN s;
128
129 s = *src;
130
131#if INBPP != 8
132 if (srcPF.endianMismatch)
133 s = SWAPIN(s);
134#endif
135
136 *r = redUpTable[(s >> srcPF.redShift) & 0xff];
137 *g = greenUpTable[(s >> srcPF.greenShift) & 0xff];
138 *b = blueUpTable[(s >> srcPF.blueShift) & 0xff];
139 *x = 0;
140
141 r += 4;
142 g += 4;
143 b += 4;
144 x += 4;
145 src++;
146 }
147 r += dstPad;
148 g += dstPad;
149 b += dstPad;
150 x += dstPad;
151 src += srcPad;
152 }
153}
154
155#endif /* OUTBPP == 32 */