Glide Plugin GLES2 port from mupen64plus-ae, but with special FrameSkip code
[mupen64plus-pandora.git] / source / gles2glide64 / src / Glide64 / TexConv.h
1 /*
2 * Glide64 - Glide video plugin for Nintendo 64 emulators.
3 * Copyright (c) 2002  Dave2001
4 * Copyright (c) 2003-2009  Sergey 'Gonetz' Lipski
5 *
6 * This program is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation; either version 2 of the License, or
9 * any later version.
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., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
19 */
20
21 //****************************************************************
22 //
23 // Glide64 - Glide Plugin for Nintendo 64 emulators
24 // Project started on December 29th, 2001
25 //
26 // Authors:
27 // Dave2001, original author, founded the project in 2001, left it in 2002
28 // Gugaman, joined the project in 2002, left it in 2002
29 // Sergey 'Gonetz' Lipski, joined the project in 2002, main author since fall of 2002
30 // Hiroshi 'KoolSmoky' Morii, joined the project in 2007
31 //
32 //****************************************************************
33 //
34 // To modify Glide64:
35 // * Write your name and (optional)email, commented by your work, so I know who did it, and so that you can find which parts you modified when it comes time to send it to me.
36 // * Do NOT send me the whole project or file that you modified.  Take out your modified code sections, and tell me where to put them.  If people sent the whole thing, I would have many different versions, but no idea how to combine them all.
37 //
38 //****************************************************************
39
40 static inline void texConv_ARGB1555_ARGB4444(uint8_t *src, uint8_t *dst, int size)
41 {
42   uint32_t *v3;
43   uint32_t *v4;
44   int v5;
45   uint32_t v6;
46   uint32_t v7;
47
48   v3 = (uint32_t *)src;
49   v4 = (uint32_t *)dst;
50   v5 = size;
51   do
52   {
53     v6 = *v3;
54     ++v3;
55     v7 = v6;
56     *v4 = ((v7 & 0x1E001E) >> 1) | ((v6 & 0x3C003C0) >> 2) | ((v6 & 0x78007800) >> 3) | ((v6 & 0x80008000) >> 3) | ((v6 & 0x80008000) >> 2) | ((v6 & 0x80008000) >> 1) | (v6 & 0x80008000);
57     ++v4;
58     --v5;
59   }
60   while ( v5 );
61 }
62
63 static inline void texConv_AI88_ARGB4444(uint8_t *src, uint8_t *dst, int size)
64 {
65   uint32_t *v3;
66   uint32_t *v4;
67   int v5;
68   uint32_t v6;
69   uint32_t v7;
70
71   v3 = (uint32_t *)src;
72   v4 = (uint32_t *)dst;
73   v5 = size;
74   do
75   {
76     v6 = *v3;
77     ++v3;
78     v7 = v6;
79     *v4 = (16 * (v7 & 0xF000F0) >> 8) | (v7 & 0xF000F0) | (16 * (v7 & 0xF000F0)) | (v6 & 0xF000F000);
80     ++v4;
81     --v5;
82   }
83   while ( v5 );
84 }
85
86 static inline void texConv_AI44_ARGB4444(uint8_t *src, uint8_t *dst, int size)
87 {
88   uint32_t *v3;
89   uint32_t *v4;
90   int v5;
91   uint32_t v6;
92   uint32_t *v7;
93
94   v3 = (uint32_t *)src;
95   v4 = (uint32_t *)dst;
96   v5 = size;
97   do
98   {
99     v6 = *v3;
100     ++v3;
101     *v4 = ((((uint16_t)v6 << 8) & 0xFF00 & 0xF00u) >> 8) | ((((uint16_t)v6 << 8) & 0xFF00 & 0xF00u) >> 4) | (uint16_t)(((uint16_t)v6 << 8) & 0xFF00) | (((v6 << 16) & 0xF000000) >> 8) | (((v6 << 16) & 0xF000000) >> 4) | ((v6 << 16) & 0xFF000000);
102     v7 = v4 + 1;
103     *v7 = (((v6 >> 8) & 0xF00) >> 8) | (((v6 >> 8) & 0xF00) >> 4) | ((v6 >> 8) & 0xFF00) | ((v6 & 0xF000000) >> 8) | ((v6 & 0xF000000) >> 4) | (v6 & 0xFF000000);
104     v4 = v7 + 1;
105     --v5;
106   }
107   while ( v5 );
108 }
109
110 static inline void texConv_A8_ARGB4444(uint8_t *src, uint8_t *dst, int size)
111 {
112   uint32_t *v3;
113   uint32_t *v4;
114   int v5;
115   uint32_t v6;
116   uint32_t v7;
117   uint32_t *v8;
118
119   v3 = (uint32_t *)src;
120   v4 = (uint32_t *)dst;
121   v5 = size;
122   do
123   {
124     v6 = *v3;
125     ++v3;
126     v7 = v6;
127     *v4 = ((v6 & 0xF0) << 8 >> 12) | (uint8_t)(v6 & 0xF0) | (16 * (uint8_t)(v6 & 0xF0) & 0xFFFFFFF) | ((uint8_t)(v6 & 0xF0) << 8) | (16 * (uint16_t)(v6 & 0xF000) & 0xFFFFF) | (((uint16_t)(v6 & 0xF000) << 8) & 0xFFFFFF) | (((uint16_t)(v6 & 0xF000) << 12) & 0xFFFFFFF) | ((uint16_t)(v6 & 0xF000) << 16);
128     v8 = v4 + 1;
129     *v8 = ((v7 & 0xF00000) >> 20) | ((v7 & 0xF00000) >> 16) | ((v7 & 0xF00000) >> 12) | ((v7 & 0xF00000) >> 8) | ((v6 & 0xF0000000) >> 12) | ((v6 & 0xF0000000) >> 8) | ((v6 & 0xF0000000) >> 4) | (v6 & 0xF0000000);
130     v4 = v8 + 1;
131     --v5;
132   }
133   while ( v5 );
134 }
135
136 void TexConv_ARGB1555_ARGB4444 (unsigned char * src, unsigned char * dst, int width, int height)
137 {
138   int size = (width * height) >> 1;     // Hiroshi Morii <koolsmoky@users.sourceforge.net>
139   // 2 pixels are converted in one loop
140   // NOTE: width * height must be a multiple of 2
141   texConv_ARGB1555_ARGB4444(src, dst, size);
142 }
143
144 void TexConv_AI88_ARGB4444 (unsigned char * src, unsigned char * dst, int width, int height)
145 {
146   int size = (width * height) >> 1;     // Hiroshi Morii <koolsmoky@users.sourceforge.net>
147   // 2 pixels are converted in one loop
148   // NOTE: width * height must be a multiple of 2
149   texConv_AI88_ARGB4444(src, dst, size);
150 }
151
152 void TexConv_AI44_ARGB4444 (unsigned char * src, unsigned char * dst, int width, int height)
153 {
154   int size = (width * height) >> 2;     // Hiroshi Morii <koolsmoky@users.sourceforge.net>
155   // 4 pixels are converted in one loop
156   // NOTE: width * height must be a multiple of 4
157   texConv_AI44_ARGB4444(src, dst, size);
158 }
159
160 void TexConv_A8_ARGB4444 (unsigned char * src, unsigned char * dst, int width, int height)
161 {
162   int size = (width * height) >> 2;     // Hiroshi Morii <koolsmoky@users.sourceforge.net>
163   // 4 pixels are converted in one loop
164   // NOTE: width * height must be a multiple of 4
165   texConv_A8_ARGB4444(src, dst, size);
166 }
167