1 |
/* |
2 |
* HT Editor |
3 |
* sysvaccel.cc |
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 |
extern "C" void __attribute__((regparm (3))) x86_mmx_convert_2be555_to_2le555(uint32 pixel, byte *input, byte *output); |
26 |
extern "C" void __attribute__((regparm (3))) x86_mmx_convert_2be555_to_2le565(uint32 pixel, byte *input, byte *output); |
27 |
extern "C" void __attribute__((regparm (3))) x86_mmx_convert_2be555_to_4le888(uint32 pixel, byte *input, byte *output); |
28 |
extern "C" void __attribute__((regparm (3))) x86_sse2_convert_2be555_to_2le555(uint32 pixel, byte *input, byte *output); |
29 |
extern "C" void __attribute__((regparm (3))) x86_sse2_convert_2be555_to_2le565(uint32 pixel, byte *input, byte *output); |
30 |
extern "C" void __attribute__((regparm (3))) x86_sse2_convert_2be555_to_4le888(uint32 pixel, byte *input, byte *output); |
31 |
extern "C" void __attribute__((regparm (3))) x86_convert_4be888_to_4le888(uint32 pixel, byte *input, byte *output); |
32 |
|
33 |
static inline void convertBaseColor(uint &b, uint fromBits, uint toBits) |
34 |
{ |
35 |
if (toBits > fromBits) { |
36 |
b <<= toBits - fromBits; |
37 |
} else { |
38 |
b >>= fromBits - toBits; |
39 |
} |
40 |
} |
41 |
|
42 |
static inline void genericConvertDisplay( |
43 |
const DisplayCharacteristics &aSrcChar, |
44 |
const DisplayCharacteristics &aDestChar, |
45 |
const void *aSrcBuf, |
46 |
void *aDestBuf, |
47 |
int firstLine, |
48 |
int lastLine) |
49 |
{ |
50 |
byte *src = (byte*)aSrcBuf + aSrcChar.bytesPerPixel * aSrcChar.width * firstLine; |
51 |
byte *dest = (byte*)aDestBuf + aDestChar.bytesPerPixel * aDestChar.width * firstLine; |
52 |
for (int y=firstLine; y <= lastLine; y++) { |
53 |
for (int x=0; x < aSrcChar.width; x++) { |
54 |
uint r, g, b; |
55 |
uint p; |
56 |
switch (aSrcChar.bytesPerPixel) { |
57 |
case 2: |
58 |
p = (src[0] << 8) | src[1]; |
59 |
break; |
60 |
case 4: |
61 |
p = (src[0] << 24) | (src[1] << 16) | (src[2] << 8) | src[3]; |
62 |
break; |
63 |
default: |
64 |
ht_printf("internal error in %s:%d\n", __FILE__, __LINE__); |
65 |
exit(1); |
66 |
break; |
67 |
} |
68 |
r = (p >> aSrcChar.redShift) & ((1<<aSrcChar.redSize)-1); |
69 |
g = (p >> aSrcChar.greenShift) & ((1<<aSrcChar.greenSize)-1); |
70 |
b = (p >> aSrcChar.blueShift) & ((1<<aSrcChar.blueSize)-1); |
71 |
convertBaseColor(r, aSrcChar.redSize, aDestChar.redSize); |
72 |
convertBaseColor(g, aSrcChar.greenSize, aDestChar.greenSize); |
73 |
convertBaseColor(b, aSrcChar.blueSize, aDestChar.blueSize); |
74 |
p = (r << aDestChar.redShift) | (g << aDestChar.greenShift) |
75 |
| (b << aDestChar.blueShift); |
76 |
switch (aDestChar.bytesPerPixel) { |
77 |
case 2: |
78 |
dest[0] = p; dest[1] = p>>8; |
79 |
break; |
80 |
case 3: |
81 |
dest[0] = p; dest[1] = p>>8; dest[2] = p>>16; |
82 |
break; |
83 |
case 4: |
84 |
*(uint32*)dest = p; |
85 |
break; |
86 |
default: |
87 |
ht_printf("internal error in %s:%d\n", __FILE__, __LINE__); |
88 |
exit(1); |
89 |
} |
90 |
dest += aDestChar.bytesPerPixel; |
91 |
src += aSrcChar.bytesPerPixel; |
92 |
} |
93 |
dest += aDestChar.scanLineLength - aDestChar.width*aDestChar.bytesPerPixel; |
94 |
src += aSrcChar.scanLineLength - aSrcChar.width*aSrcChar.bytesPerPixel; |
95 |
} |
96 |
} |
97 |
|
98 |
void sys_convert_display( |
99 |
const DisplayCharacteristics &aSrcChar, |
100 |
const DisplayCharacteristics &aDestChar, |
101 |
const void *aSrcBuf, |
102 |
void *aDestBuf, |
103 |
int firstLine, |
104 |
int lastLine) |
105 |
{ |
106 |
byte *src = (byte*)aSrcBuf + aSrcChar.bytesPerPixel * aSrcChar.width * firstLine; |
107 |
byte *dest = (byte*)aDestBuf + aDestChar.bytesPerPixel * aDestChar.width * firstLine; |
108 |
uint32 pixel = (lastLine-firstLine+1) * aSrcChar.width; |
109 |
if (aSrcChar.bytesPerPixel == 2 && aDestChar.bytesPerPixel == 2) { |
110 |
if (aDestChar.redSize == 5 && aDestChar.greenSize == 6 && aDestChar.blueSize == 5) { |
111 |
x86_mmx_convert_2be555_to_2le565(pixel, src, dest); |
112 |
} else if (aDestChar.redSize == 5 && aDestChar.greenSize == 5 && aDestChar.blueSize == 5) { |
113 |
x86_mmx_convert_2be555_to_2le555(pixel, src, dest); |
114 |
} else { |
115 |
genericConvertDisplay(aSrcChar, aDestChar, aSrcBuf, aDestBuf, firstLine, lastLine); |
116 |
} |
117 |
} else if (aSrcChar.bytesPerPixel == 2 && aDestChar.bytesPerPixel == 4) { |
118 |
x86_mmx_convert_2be555_to_4le888(pixel, src, dest); |
119 |
} else if (aSrcChar.bytesPerPixel == 4 && aDestChar.bytesPerPixel == 4) { |
120 |
x86_convert_4be888_to_4le888(pixel, src, dest); |
121 |
} else { |
122 |
genericConvertDisplay(aSrcChar, aDestChar, aSrcBuf, aDestBuf, firstLine, lastLine); |
123 |
} |
124 |
} |