1 |
/* |
2 |
* HT Editor |
3 |
* sysvaccel.cc - generic implementation |
4 |
* |
5 |
* Copyright (C) 2004 Stefan Weyergraf |
6 |
* |
7 |
* This program is free software; you can redistribute it and/or modify |
8 |
* it under the terms of the GNU General Public License version 2 as |
9 |
* published by the Free Software Foundation. |
10 |
* |
11 |
* This program is distributed in the hope that it will be useful, |
12 |
* but WITHOUT ANY WARRANTY; without even the implied warranty of |
13 |
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
14 |
* GNU General Public License for more details. |
15 |
* |
16 |
* You should have received a copy of the GNU General Public License |
17 |
* along with this program; if not, write to the Free Software |
18 |
* Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. |
19 |
*/ |
20 |
|
21 |
#include "system/sysvaccel.h" |
22 |
|
23 |
#include "tools/snprintf.h" |
24 |
|
25 |
static inline void convertBaseColor(uint &b, uint fromBits, uint toBits) |
26 |
{ |
27 |
if (toBits > fromBits) { |
28 |
b <<= toBits - fromBits; |
29 |
} else { |
30 |
b >>= fromBits - toBits; |
31 |
} |
32 |
} |
33 |
|
34 |
void sys_convert_display( |
35 |
const DisplayCharacteristics &aSrcChar, |
36 |
const DisplayCharacteristics &aDestChar, |
37 |
const void *aSrcBuf, |
38 |
void *aDestBuf, |
39 |
int firstLine, |
40 |
int lastLine) |
41 |
{ |
42 |
byte *src = (byte*)aSrcBuf + aSrcChar.bytesPerPixel * aSrcChar.width * firstLine; |
43 |
byte *dest = (byte*)aDestBuf + aDestChar.bytesPerPixel * aDestChar.width * firstLine; |
44 |
for (int y=firstLine; y <= lastLine; y++) { |
45 |
for (int x=0; x < aSrcChar.width; x++) { |
46 |
uint r, g, b; |
47 |
uint p; |
48 |
switch (aSrcChar.bytesPerPixel) { |
49 |
case 2: |
50 |
p = (src[0] << 8) | src[1]; |
51 |
break; |
52 |
case 4: |
53 |
p = (src[0] << 24) | (src[1] << 16) | (src[2] << 8) | src[3]; |
54 |
break; |
55 |
default: |
56 |
ht_printf("internal error in %s:%d\n", __FILE__, __LINE__); |
57 |
exit(1); |
58 |
break; |
59 |
} |
60 |
r = (p >> aSrcChar.redShift) & ((1<<aSrcChar.redSize)-1); |
61 |
g = (p >> aSrcChar.greenShift) & ((1<<aSrcChar.greenSize)-1); |
62 |
b = (p >> aSrcChar.blueShift) & ((1<<aSrcChar.blueSize)-1); |
63 |
convertBaseColor(r, aSrcChar.redSize, aDestChar.redSize); |
64 |
convertBaseColor(g, aSrcChar.greenSize, aDestChar.greenSize); |
65 |
convertBaseColor(b, aSrcChar.blueSize, aDestChar.blueSize); |
66 |
p = (r << aDestChar.redShift) | (g << aDestChar.greenShift) |
67 |
| (b << aDestChar.blueShift); |
68 |
switch (aDestChar.bytesPerPixel) { |
69 |
case 2: |
70 |
*(uint16*)dest = p; |
71 |
break; |
72 |
case 3: |
73 |
dest[0] = p; dest[1] = p>>8; dest[2] = p>>16; |
74 |
break; |
75 |
case 4: |
76 |
*(uint32*)dest = p; |
77 |
break; |
78 |
default: |
79 |
ht_printf("internal error in %s:%d\n", __FILE__, __LINE__); |
80 |
exit(1); |
81 |
} |
82 |
dest += aDestChar.bytesPerPixel; |
83 |
src += aSrcChar.bytesPerPixel; |
84 |
} |
85 |
dest += aDestChar.scanLineLength - aDestChar.width*aDestChar.bytesPerPixel; |
86 |
src += aSrcChar.scanLineLength - aSrcChar.width*aSrcChar.bytesPerPixel; |
87 |
} |
88 |
} |