annotate src/video/ps3/spulibs/yuv2rgb_converter.c @ 4337:4eb6b4be1dbc SDL-1.2

Fixed bug #728 I am using a headset on my monitor as primary sound output device. From time to time it happens that I switch off my monitor when I leave my computer and switch it on when I come back. When doing so while wesnoth is running I get no sound back when I switch on my monitor. There is probably good reason for that. Therefore I wanted to exit and restart wesnoth. Unfortunately, wesnoth always hangs in this situation. It looks like wesnoth can not be exited when the primary sound device vanished. I created a backtrace of this situation (please see attachment).
author Sam Lantinga <slouken@libsdl.org>
date Thu, 15 Oct 2009 02:52:11 +0000
parents 3b8ac3d311a2
children
rev   line source
4165
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
1 /*
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
2 * SDL - Simple DirectMedia Layer
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
3 * CELL BE Support for PS3 Framebuffer
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
4 * Copyright (C) 2008, 2009 International Business Machines Corporation
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
5 *
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
6 * This library is free software; you can redistribute it and/or modify it
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
7 * under the terms of the GNU Lesser General Public License as published
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
8 * by the Free Software Foundation; either version 2.1 of the License, or
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
9 * (at your option) any later version.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
10 *
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
11 * This library is distributed in the hope that it will be useful, but
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
12 * WITHOUT ANY WARRANTY; without even the implied warranty of
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
14 * Lesser General Public License for more details.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
15 *
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
16 * You should have received a copy of the GNU Lesser General Public
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
17 * License along with this library; if not, write to the Free Software
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
18 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
19 * USA
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
20 *
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
21 * Martin Lowinski <lowinski [at] de [dot] ibm [ibm] com>
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
22 * Dirk Herrendoerfer <d.herrendoerfer [at] de [dot] ibm [dot] com>
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
23 * SPE code based on research by:
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
24 * Rene Becker
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
25 * Thimo Emmerich
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
26 */
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
27
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
28 #include "spu_common.h"
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
29
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
30 #include <spu_intrinsics.h>
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
31 #include <spu_mfcio.h>
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
32
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
33 // Debugging
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
34 //#define DEBUG
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
35
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
36 #ifdef DEBUG
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
37 #define deprintf(fmt, args... ) \
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
38 fprintf( stdout, fmt, ##args ); \
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
39 fflush( stdout );
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
40 #else
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
41 #define deprintf( fmt, args... )
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
42 #endif
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
43
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
44 struct yuv2rgb_parms_t parms_converter __attribute__((aligned(128)));
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
45
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
46 /* A maximum of 8 lines Y, therefore 4 lines V, 4 lines U are stored
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
47 * there might be the need to retrieve misaligned data, adjust
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
48 * incoming v and u plane to be able to handle this (add 128)
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
49 */
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
50 unsigned char y_plane[2][(MAX_HDTV_WIDTH + 128) * 4] __attribute__((aligned(128)));
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
51 unsigned char v_plane[2][(MAX_HDTV_WIDTH + 128) * 2] __attribute__((aligned(128)));
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
52 unsigned char u_plane[2][(MAX_HDTV_WIDTH + 128) * 2] __attribute__((aligned(128)));
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
53
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
54 /* A maximum of 4 lines BGRA are stored, 4 byte per pixel */
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
55 unsigned char bgra[4 * MAX_HDTV_WIDTH * 4] __attribute__((aligned(128)));
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
56
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
57 /* some vectors needed by the float to int conversion */
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
58 static const vector float vec_255 = { 255.0f, 255.0f, 255.0f, 255.0f };
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
59 static const vector float vec_0_1 = { 0.1f, 0.1f, 0.1f, 0.1f };
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
60
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
61 void yuv_to_rgb_w16();
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
62 void yuv_to_rgb_w32();
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
63
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
64 void yuv_to_rgb_w16_line(unsigned char* y_addr, unsigned char* v_addr, unsigned char* u_addr, unsigned char* bgra_addr, unsigned int width);
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
65 void yuv_to_rgb_w32_line(unsigned char* y_addr, unsigned char* v_addr, unsigned char* u_addr, unsigned char* bgra_addr_, unsigned int width);
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
66
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
67
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
68 int main(unsigned long long spe_id __attribute__((unused)), unsigned long long argp __attribute__ ((unused)))
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
69 {
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
70 deprintf("[SPU] yuv2rgb_spu is up... (on SPE #%llu)\n", spe_id);
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
71 uint32_t ea_mfc, mbox;
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
72 // send ready message
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
73 spu_write_out_mbox(SPU_READY);
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
74
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
75 while (1) {
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
76 /* Check mailbox */
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
77 mbox = spu_read_in_mbox();
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
78 deprintf("[SPU] Message is %u\n", mbox);
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
79 switch (mbox) {
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
80 case SPU_EXIT:
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
81 deprintf("[SPU] fb_writer goes down...\n");
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
82 return 0;
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
83 case SPU_START:
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
84 break;
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
85 default:
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
86 deprintf("[SPU] Cannot handle message\n");
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
87 continue;
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
88 }
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
89
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
90 /* Tag Manager setup */
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
91 unsigned int tag_id;
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
92 tag_id = mfc_multi_tag_reserve(1);
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
93 if (tag_id == MFC_TAG_INVALID) {
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
94 deprintf("[SPU] Failed to reserve mfc tags on yuv2rgb_converter\n");
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
95 return 0;
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
96 }
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
97
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
98 /* DMA transfer for the input parameters */
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
99 ea_mfc = spu_read_in_mbox();
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
100 deprintf("[SPU] Message on yuv2rgb_converter is %u\n", ea_mfc);
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
101 spu_mfcdma32(&parms_converter, (unsigned int)ea_mfc, sizeof(struct yuv2rgb_parms_t), tag_id, MFC_GET_CMD);
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
102 DMA_WAIT_TAG(tag_id);
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
103
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
104 /* There are alignment issues that involve handling of special cases
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
105 * a width of 32 results in a width of 16 in the chrominance
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
106 * --> choose the proper handling to optimize the performance
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
107 */
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
108 deprintf("[SPU] Convert %ix%i from YUV to RGB\n", parms_converter.src_pixel_width, parms_converter.src_pixel_height);
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
109 if (parms_converter.src_pixel_width & 0x1f) {
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
110 deprintf("[SPU] Using yuv_to_rgb_w16\n");
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
111 yuv_to_rgb_w16();
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
112 } else {
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
113 deprintf("[SPU] Using yuv_to_rgb_w32\n");
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
114 yuv_to_rgb_w32();
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
115 }
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
116
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
117 mfc_multi_tag_release(tag_id, 1);
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
118 deprintf("[SPU] yuv2rgb_spu... done!\n");
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
119 /* Send FIN message */
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
120 spu_write_out_mbox(SPU_FIN);
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
121 }
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
122
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
123 return 0;
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
124 }
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
125
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
126
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
127 /*
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
128 * float_to_char()
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
129 *
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
130 * converts a float to a character using saturated
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
131 * arithmetic
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
132 *
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
133 * @param s float for conversion
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
134 * @returns converted character
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
135 */
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
136 inline static unsigned char float_to_char(float s) {
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
137 vector float vec_s = spu_splats(s);
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
138 vector unsigned int select_1 = spu_cmpgt(vec_0_1, vec_s);
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
139 vec_s = spu_sel(vec_s, vec_0_1, select_1);
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
140
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
141 vector unsigned int select_2 = spu_cmpgt(vec_s, vec_255);
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
142 vec_s = spu_sel(vec_s, vec_255, select_2);
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
143 return (unsigned char) spu_extract(vec_s,0);
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
144 }
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
145
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
146
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
147 /*
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
148 * vfloat_to_vuint()
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
149 *
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
150 * converts a float vector to an unsinged int vector using saturated
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
151 * arithmetic
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
152 *
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
153 * @param vec_s float vector for conversion
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
154 * @returns converted unsigned int vector
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
155 */
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
156 inline static vector unsigned int vfloat_to_vuint(vector float vec_s) {
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
157 vector unsigned int select_1 = spu_cmpgt(vec_0_1, vec_s);
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
158 vec_s = spu_sel(vec_s, vec_0_1, select_1);
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
159
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
160 vector unsigned int select_2 = spu_cmpgt(vec_s, vec_255);
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
161 vec_s = spu_sel(vec_s, vec_255, select_2);
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
162 return spu_convtu(vec_s,0);
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
163 }
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
164
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
165
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
166 void yuv_to_rgb_w16() {
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
167 // Pixel dimensions of the picture
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
168 uint32_t width, height;
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
169
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
170 // Extract parameters
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
171 width = parms_converter.src_pixel_width;
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
172 height = parms_converter.src_pixel_height;
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
173
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
174 // Plane data management
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
175 // Y
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
176 unsigned char* ram_addr_y = parms_converter.y_plane;
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
177 // V
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
178 unsigned char* ram_addr_v = parms_converter.v_plane;
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
179 // U
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
180 unsigned char* ram_addr_u = parms_converter.u_plane;
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
181
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
182 // BGRA
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
183 unsigned char* ram_addr_bgra = parms_converter.dstBuffer;
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
184
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
185 // Strides
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
186 unsigned int stride_y = width;
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
187 unsigned int stride_vu = width>>1;
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
188
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
189 // Buffer management
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
190 unsigned int buf_idx = 0;
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
191 unsigned int size_4lines_y = stride_y<<2;
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
192 unsigned int size_2lines_y = stride_y<<1;
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
193 unsigned int size_2lines_vu = stride_vu<<1;
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
194
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
195 // 2*width*4byte_per_pixel
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
196 unsigned int size_2lines_bgra = width<<3;
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
197
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
198
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
199 // start double-buffered processing
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
200 // 4 lines y
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
201 spu_mfcdma32(y_plane[buf_idx], (unsigned int) ram_addr_y, size_4lines_y, RETR_BUF+buf_idx, MFC_GET_CMD);
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
202
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
203 // 2 lines v
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
204 spu_mfcdma32(v_plane[buf_idx], (unsigned int) ram_addr_v, size_2lines_vu, RETR_BUF+buf_idx, MFC_GET_CMD);
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
205
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
206 // 2 lines u
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
207 spu_mfcdma32(u_plane[buf_idx], (unsigned int) ram_addr_u, size_2lines_vu, RETR_BUF+buf_idx, MFC_GET_CMD);
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
208
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
209 // Wait for these transfers to be completed
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
210 DMA_WAIT_TAG((RETR_BUF + buf_idx));
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
211
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
212 unsigned int i;
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
213 for(i=0; i<(height>>2)-1; i++) {
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
214
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
215 buf_idx^=1;
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
216
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
217 // 4 lines y
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
218 spu_mfcdma32(y_plane[buf_idx], (unsigned int) ram_addr_y+size_4lines_y, size_4lines_y, RETR_BUF+buf_idx, MFC_GET_CMD);
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
219
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
220 // 2 lines v
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
221 spu_mfcdma32(v_plane[buf_idx], (unsigned int) ram_addr_v+size_2lines_vu, size_2lines_vu, RETR_BUF+buf_idx, MFC_GET_CMD);
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
222
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
223 // 2 lines u
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
224 spu_mfcdma32(u_plane[buf_idx], (unsigned int) ram_addr_u+size_2lines_vu, size_2lines_vu, RETR_BUF+buf_idx, MFC_GET_CMD);
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
225
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
226 DMA_WAIT_TAG((RETR_BUF + buf_idx));
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
227
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
228 buf_idx^=1;
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
229
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
230
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
231 // Convert YUV to BGRA, store it back (first two lines)
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
232 yuv_to_rgb_w16_line(y_plane[buf_idx], v_plane[buf_idx], u_plane[buf_idx], bgra, width);
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
233
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
234 // Next two lines
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
235 yuv_to_rgb_w16_line(y_plane[buf_idx] + size_2lines_y,
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
236 v_plane[buf_idx] + stride_vu,
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
237 u_plane[buf_idx] + stride_vu,
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
238 bgra + size_2lines_bgra,
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
239 width);
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
240
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
241 // Wait for previous storing transfer to be completed
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
242 DMA_WAIT_TAG(STR_BUF);
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
243
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
244 // Store converted lines in two steps->max transfer size 16384
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
245 spu_mfcdma32(bgra, (unsigned int) ram_addr_bgra, size_2lines_bgra, STR_BUF, MFC_PUT_CMD);
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
246 ram_addr_bgra += size_2lines_bgra;
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
247 spu_mfcdma32(bgra+size_2lines_bgra, (unsigned int) ram_addr_bgra, size_2lines_bgra, STR_BUF, MFC_PUT_CMD);
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
248 ram_addr_bgra += size_2lines_bgra;
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
249
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
250 // Move 4 lines
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
251 ram_addr_y += size_4lines_y;
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
252 ram_addr_v += size_2lines_vu;
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
253 ram_addr_u += size_2lines_vu;
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
254
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
255 buf_idx^=1;
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
256 }
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
257
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
258 // Convert YUV to BGRA, store it back (first two lines)
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
259 yuv_to_rgb_w16_line(y_plane[buf_idx], v_plane[buf_idx], u_plane[buf_idx], bgra, width);
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
260
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
261 // Next two lines
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
262 yuv_to_rgb_w16_line(y_plane[buf_idx] + size_2lines_y,
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
263 v_plane[buf_idx] + stride_vu,
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
264 u_plane[buf_idx] + stride_vu,
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
265 bgra + size_2lines_bgra,
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
266 width);
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
267
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
268 // Wait for previous storing transfer to be completed
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
269 DMA_WAIT_TAG(STR_BUF);
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
270 spu_mfcdma32(bgra, (unsigned int) ram_addr_bgra, size_2lines_bgra, STR_BUF, MFC_PUT_CMD);
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
271 ram_addr_bgra += size_2lines_bgra;
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
272 spu_mfcdma32(bgra+size_2lines_bgra, (unsigned int) ram_addr_bgra, size_2lines_bgra, STR_BUF, MFC_PUT_CMD);
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
273
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
274 // wait for previous storing transfer to be completed
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
275 DMA_WAIT_TAG(STR_BUF);
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
276
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
277 }
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
278
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
279
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
280 void yuv_to_rgb_w32() {
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
281 // Pixel dimensions of the picture
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
282 uint32_t width, height;
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
283
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
284 // Extract parameters
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
285 width = parms_converter.src_pixel_width;
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
286 height = parms_converter.src_pixel_height;
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
287
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
288 // Plane data management
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
289 // Y
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
290 unsigned char* ram_addr_y = parms_converter.y_plane;
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
291 // V
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
292 unsigned char* ram_addr_v = parms_converter.v_plane;
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
293 // U
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
294 unsigned char* ram_addr_u = parms_converter.u_plane;
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
295
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
296 // BGRA
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
297 unsigned char* ram_addr_bgra = parms_converter.dstBuffer;
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
298
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
299 // Strides
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
300 unsigned int stride_y = width;
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
301 unsigned int stride_vu = width>>1;
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
302
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
303 // Buffer management
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
304 unsigned int buf_idx = 0;
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
305 unsigned int size_4lines_y = stride_y<<2;
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
306 unsigned int size_2lines_y = stride_y<<1;
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
307 unsigned int size_2lines_vu = stride_vu<<1;
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
308
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
309 // 2*width*4byte_per_pixel
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
310 unsigned int size_2lines_bgra = width<<3;
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
311
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
312 // start double-buffered processing
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
313 // 4 lines y
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
314 spu_mfcdma32(y_plane[buf_idx], (unsigned int) ram_addr_y, size_4lines_y, RETR_BUF + buf_idx, MFC_GET_CMD);
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
315 // 2 lines v
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
316 spu_mfcdma32(v_plane[buf_idx], (unsigned int) ram_addr_v, size_2lines_vu, RETR_BUF + buf_idx, MFC_GET_CMD);
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
317 // 2 lines u
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
318 spu_mfcdma32(u_plane[buf_idx], (unsigned int) ram_addr_u, size_2lines_vu, RETR_BUF + buf_idx, MFC_GET_CMD);
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
319
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
320 // Wait for these transfers to be completed
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
321 DMA_WAIT_TAG((RETR_BUF + buf_idx));
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
322
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
323 unsigned int i;
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
324 for(i=0; i < (height>>2)-1; i++) {
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
325 buf_idx^=1;
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
326 // 4 lines y
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
327 spu_mfcdma32(y_plane[buf_idx], (unsigned int) ram_addr_y+size_4lines_y, size_4lines_y, RETR_BUF + buf_idx, MFC_GET_CMD);
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
328 deprintf("4lines = %d\n", size_4lines_y);
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
329 // 2 lines v
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
330 spu_mfcdma32(v_plane[buf_idx], (unsigned int) ram_addr_v+size_2lines_vu, size_2lines_vu, RETR_BUF + buf_idx, MFC_GET_CMD);
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
331 deprintf("2lines = %d\n", size_2lines_vu);
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
332 // 2 lines u
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
333 spu_mfcdma32(u_plane[buf_idx], (unsigned int) ram_addr_u+size_2lines_vu, size_2lines_vu, RETR_BUF + buf_idx, MFC_GET_CMD);
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
334 deprintf("2lines = %d\n", size_2lines_vu);
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
335
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
336 DMA_WAIT_TAG((RETR_BUF + buf_idx));
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
337
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
338 buf_idx^=1;
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
339
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
340 // Convert YUV to BGRA, store it back (first two lines)
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
341 yuv_to_rgb_w32_line(y_plane[buf_idx], v_plane[buf_idx], u_plane[buf_idx], bgra, width);
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
342
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
343 // Next two lines
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
344 yuv_to_rgb_w32_line(y_plane[buf_idx] + size_2lines_y,
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
345 v_plane[buf_idx] + stride_vu,
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
346 u_plane[buf_idx] + stride_vu,
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
347 bgra + size_2lines_bgra,
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
348 width);
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
349
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
350 // Wait for previous storing transfer to be completed
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
351 DMA_WAIT_TAG(STR_BUF);
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
352
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
353 // Store converted lines in two steps->max transfer size 16384
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
354 spu_mfcdma32(bgra, (unsigned int)ram_addr_bgra, size_2lines_bgra, STR_BUF, MFC_PUT_CMD);
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
355 ram_addr_bgra += size_2lines_bgra;
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
356 spu_mfcdma32(bgra + size_2lines_bgra, (unsigned int)ram_addr_bgra, size_2lines_bgra, STR_BUF, MFC_PUT_CMD);
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
357 ram_addr_bgra += size_2lines_bgra;
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
358
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
359 // Move 4 lines
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
360 ram_addr_y += size_4lines_y;
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
361 ram_addr_v += size_2lines_vu;
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
362 ram_addr_u += size_2lines_vu;
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
363
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
364 buf_idx^=1;
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
365 }
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
366
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
367 // Convert YUV to BGRA, store it back (first two lines)
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
368 yuv_to_rgb_w32_line(y_plane[buf_idx], v_plane[buf_idx], u_plane[buf_idx], bgra, width);
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
369
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
370 // Next two lines
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
371 yuv_to_rgb_w32_line(y_plane[buf_idx] + size_2lines_y,
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
372 v_plane[buf_idx] + stride_vu,
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
373 u_plane[buf_idx] + stride_vu,
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
374 bgra + size_2lines_bgra,
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
375 width);
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
376
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
377 // Wait for previous storing transfer to be completed
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
378 DMA_WAIT_TAG(STR_BUF);
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
379 spu_mfcdma32(bgra, (unsigned int) ram_addr_bgra, size_2lines_bgra, STR_BUF, MFC_PUT_CMD);
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
380 ram_addr_bgra += size_2lines_bgra;
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
381 spu_mfcdma32(bgra + size_2lines_bgra, (unsigned int) ram_addr_bgra, size_2lines_bgra, STR_BUF, MFC_PUT_CMD);
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
382
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
383 // Wait for previous storing transfer to be completed
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
384 DMA_WAIT_TAG(STR_BUF);
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
385 }
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
386
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
387
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
388 /* Some vectors needed by the yuv 2 rgb conversion algorithm */
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
389 const vector float vec_minus_128 = { -128.0f, -128.0f, -128.0f, -128.0f };
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
390 const vector unsigned char vec_null = { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 };
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
391 const vector unsigned char vec_char2int_first = { 0x00, 0x00, 0x00, 0x10, 0x00, 0x00, 0x00, 0x11, 0x00, 0x00, 0x00, 0x12, 0x00, 0x00, 0x00, 0x13 };
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
392 const vector unsigned char vec_char2int_second = { 0x00, 0x00, 0x00, 0x14, 0x00, 0x00, 0x00, 0x15, 0x00, 0x00, 0x00, 0x16, 0x00, 0x00, 0x00, 0x17 };
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
393 const vector unsigned char vec_char2int_third = { 0x00, 0x00, 0x00, 0x18, 0x00, 0x00, 0x00, 0x19, 0x00, 0x00, 0x00, 0x1A, 0x00, 0x00, 0x00, 0x1B };
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
394 const vector unsigned char vec_char2int_fourth = { 0x00, 0x00, 0x00, 0x1C, 0x00, 0x00, 0x00, 0x1D, 0x00, 0x00, 0x00, 0x1E, 0x00, 0x00, 0x00, 0x1F };
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
395
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
396 const vector float vec_R_precalc_coeff = {1.403f, 1.403f, 1.403f, 1.403f};
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
397 const vector float vec_Gu_precalc_coeff = {-0.344f, -0.344f, -0.344f, -0.344f};
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
398 const vector float vec_Gv_precalc_coeff = {-0.714f, -0.714f, -0.714f, -0.714f};
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
399 const vector float vec_B_precalc_coeff = {1.773f, 1.773f, 1.773f, 1.773f};
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
400
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
401 const vector unsigned int vec_alpha = { 255 << 24, 255 << 24, 255 << 24, 255 << 24 };
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
402
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
403 const vector unsigned char vec_select_floats_upper = { 0x00, 0x01, 0x02, 0x03, 0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x04, 0x05, 0x06, 0x07 };
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
404 const vector unsigned char vec_select_floats_lower = { 0x08, 0x09, 0x0A, 0x0B, 0x08, 0x09, 0x0A, 0x0B, 0x0C, 0x0D, 0x0E, 0x0F, 0x0C, 0x0D, 0x0E, 0x0F };
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
405
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
406
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
407 /*
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
408 * yuv_to_rgb_w16()
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
409 *
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
410 * processes to line of yuv-input, width has to be a multiple of 16
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
411 * two lines of yuv are taken as input
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
412 *
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
413 * @param y_addr address of the y plane in local store
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
414 * @param v_addr address of the v plane in local store
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
415 * @param u_addr address of the u plane in local store
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
416 * @param bgra_addr_ address of the bgra output buffer
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
417 * @param width the width in pixel
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
418 */
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
419 void yuv_to_rgb_w16_line(unsigned char* y_addr, unsigned char* v_addr, unsigned char* u_addr, unsigned char* bgra_addr_, unsigned int width) {
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
420 // each pixel is stored as an integer
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
421 unsigned int* bgra_addr = (unsigned int*) bgra_addr_;
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
422
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
423 unsigned int x;
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
424 for(x = 0; x < width; x+=2) {
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
425 // Gehe zweischrittig durch die zeile, da jeder u und v wert fuer 4 pixel(zwei hoch, zwei breit) gilt
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
426 const unsigned char Y_1 = *(y_addr + x);
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
427 const unsigned char Y_2 = *(y_addr + x + 1);
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
428 const unsigned char Y_3 = *(y_addr + x + width);
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
429 const unsigned char Y_4 = *(y_addr + x + width + 1);
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
430 const unsigned char U = *(u_addr + (x >> 1));
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
431 const unsigned char V = *(v_addr + (x >> 1));
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
432
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
433 float V_minus_128 = (float)((float)V - 128.0f);
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
434 float U_minus_128 = (float)((float)U - 128.0f);
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
435
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
436 float R_precalculate = 1.403f * V_minus_128;
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
437 float G_precalculate = -(0.344f * U_minus_128 + 0.714f * V_minus_128);
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
438 float B_precalculate = 1.773f * U_minus_128;
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
439
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
440 const unsigned char R_1 = float_to_char((Y_1 + R_precalculate));
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
441 const unsigned char R_2 = float_to_char((Y_2 + R_precalculate));
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
442 const unsigned char R_3 = float_to_char((Y_3 + R_precalculate));
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
443 const unsigned char R_4 = float_to_char((Y_4 + R_precalculate));
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
444 const unsigned char G_1 = float_to_char((Y_1 + G_precalculate));
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
445 const unsigned char G_2 = float_to_char((Y_2 + G_precalculate));
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
446 const unsigned char G_3 = float_to_char((Y_3 + G_precalculate));
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
447 const unsigned char G_4 = float_to_char((Y_4 + G_precalculate));
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
448 const unsigned char B_1 = float_to_char((Y_1 + B_precalculate));
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
449 const unsigned char B_2 = float_to_char((Y_2 + B_precalculate));
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
450 const unsigned char B_3 = float_to_char((Y_3 + B_precalculate));
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
451 const unsigned char B_4 = float_to_char((Y_4 + B_precalculate));
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
452
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
453 *(bgra_addr + x) = (B_1 << 0)| (G_1 << 8) | (R_1 << 16) | (255 << 24);
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
454 *(bgra_addr + x + 1) = (B_2 << 0)| (G_2 << 8) | (R_2 << 16) | (255 << 24);
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
455 *(bgra_addr + x + width) = (B_3 << 0)| (G_3 << 8) | (R_3 << 16) | (255 << 24);
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
456 *(bgra_addr + x + width + 1) = (B_4 << 0)| (G_4 << 8) | (R_4 << 16) | (255 << 24);
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
457 }
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
458 }
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
459
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
460
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
461 /*
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
462 * yuv_to_rgb_w32()
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
463 *
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
464 * processes to line of yuv-input, width has to be a multiple of 32
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
465 * two lines of yuv are taken as input
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
466 *
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
467 * @param y_addr address of the y plane in local store
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
468 * @param v_addr address of the v plane in local store
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
469 * @param u_addr address of the u plane in local store
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
470 * @param bgra_addr_ address of the bgra output buffer
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
471 * @param width the width in pixel
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
472 */
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
473 void yuv_to_rgb_w32_line(unsigned char* y_addr, unsigned char* v_addr, unsigned char* u_addr, unsigned char* bgra_addr_, unsigned int width) {
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
474 // each pixel is stored as an integer
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
475 unsigned int* bgra_addr = (unsigned int*) bgra_addr_;
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
476
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
477 unsigned int x;
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
478 for(x = 0; x < width; x+=32) {
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
479 // Gehe zweischrittig durch die zeile, da jeder u und v wert fuer 4 pixel(zwei hoch, zwei breit) gilt
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
480
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
481 const vector unsigned char vchar_Y_1 = *((vector unsigned char*)(y_addr + x));
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
482 const vector unsigned char vchar_Y_2 = *((vector unsigned char*)(y_addr + x + 16));
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
483 const vector unsigned char vchar_Y_3 = *((vector unsigned char*)(y_addr + x + width));
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
484 const vector unsigned char vchar_Y_4 = *((vector unsigned char*)(y_addr + x + width + 16));
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
485 const vector unsigned char vchar_U = *((vector unsigned char*)(u_addr + (x >> 1)));
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
486 const vector unsigned char vchar_V = *((vector unsigned char*)(v_addr + (x >> 1)));
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
487
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
488 const vector float vfloat_U_1 = spu_add(spu_convtf((vector unsigned int)spu_shuffle(vec_null, vchar_U, vec_char2int_first), 0),vec_minus_128);
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
489 const vector float vfloat_U_2 = spu_add(spu_convtf((vector unsigned int)spu_shuffle(vec_null, vchar_U, vec_char2int_second), 0),vec_minus_128);
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
490 const vector float vfloat_U_3 = spu_add(spu_convtf((vector unsigned int)spu_shuffle(vec_null, vchar_U, vec_char2int_third), 0),vec_minus_128);
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
491 const vector float vfloat_U_4 = spu_add(spu_convtf((vector unsigned int)spu_shuffle(vec_null, vchar_U, vec_char2int_fourth), 0),vec_minus_128);
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
492
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
493 const vector float vfloat_V_1 = spu_add(spu_convtf((vector unsigned int)spu_shuffle(vec_null, vchar_V, vec_char2int_first), 0),vec_minus_128);
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
494 const vector float vfloat_V_2 = spu_add(spu_convtf((vector unsigned int)spu_shuffle(vec_null, vchar_V, vec_char2int_second), 0),vec_minus_128);
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
495 const vector float vfloat_V_3 = spu_add(spu_convtf((vector unsigned int)spu_shuffle(vec_null, vchar_V, vec_char2int_third), 0),vec_minus_128);
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
496 const vector float vfloat_V_4 = spu_add(spu_convtf((vector unsigned int)spu_shuffle(vec_null, vchar_V, vec_char2int_fourth), 0),vec_minus_128);
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
497
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
498 vector float Y_1 = spu_convtf((vector unsigned int)spu_shuffle(vec_null, vchar_Y_1, vec_char2int_first), 0);
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
499 vector float Y_2 = spu_convtf((vector unsigned int)spu_shuffle(vec_null, vchar_Y_1, vec_char2int_second), 0);
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
500 vector float Y_3 = spu_convtf((vector unsigned int)spu_shuffle(vec_null, vchar_Y_1, vec_char2int_third), 0);
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
501 vector float Y_4 = spu_convtf((vector unsigned int)spu_shuffle(vec_null, vchar_Y_1, vec_char2int_fourth), 0);
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
502 vector float Y_5 = spu_convtf((vector unsigned int)spu_shuffle(vec_null, vchar_Y_2, vec_char2int_first), 0);
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
503 vector float Y_6 = spu_convtf((vector unsigned int)spu_shuffle(vec_null, vchar_Y_2, vec_char2int_second), 0);
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
504 vector float Y_7 = spu_convtf((vector unsigned int)spu_shuffle(vec_null, vchar_Y_2, vec_char2int_third), 0);
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
505 vector float Y_8 = spu_convtf((vector unsigned int)spu_shuffle(vec_null, vchar_Y_2, vec_char2int_fourth), 0);
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
506 vector float Y_9 = spu_convtf((vector unsigned int)spu_shuffle(vec_null, vchar_Y_3, vec_char2int_first), 0);
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
507 vector float Y_10 = spu_convtf((vector unsigned int)spu_shuffle(vec_null, vchar_Y_3, vec_char2int_second), 0);
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
508 vector float Y_11 = spu_convtf((vector unsigned int)spu_shuffle(vec_null, vchar_Y_3, vec_char2int_third), 0);
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
509 vector float Y_12 = spu_convtf((vector unsigned int)spu_shuffle(vec_null, vchar_Y_3, vec_char2int_fourth), 0);
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
510 vector float Y_13 = spu_convtf((vector unsigned int)spu_shuffle(vec_null, vchar_Y_4, vec_char2int_first), 0);
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
511 vector float Y_14 = spu_convtf((vector unsigned int)spu_shuffle(vec_null, vchar_Y_4, vec_char2int_second), 0);
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
512 vector float Y_15 = spu_convtf((vector unsigned int)spu_shuffle(vec_null, vchar_Y_4, vec_char2int_third), 0);
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
513 vector float Y_16 = spu_convtf((vector unsigned int)spu_shuffle(vec_null, vchar_Y_4, vec_char2int_fourth), 0);
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
514
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
515 const vector float R1a_precalculate = spu_mul(vec_R_precalc_coeff, vfloat_V_1);
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
516 const vector float R2a_precalculate = spu_mul(vec_R_precalc_coeff, vfloat_V_2);
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
517 const vector float R3a_precalculate = spu_mul(vec_R_precalc_coeff, vfloat_V_3);
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
518 const vector float R4a_precalculate = spu_mul(vec_R_precalc_coeff, vfloat_V_4);
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
519
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
520 const vector float R1_precalculate = spu_shuffle(R1a_precalculate, R1a_precalculate, vec_select_floats_upper);
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
521 const vector float R2_precalculate = spu_shuffle(R1a_precalculate, R1a_precalculate, vec_select_floats_lower);
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
522 const vector float R3_precalculate = spu_shuffle(R2a_precalculate, R2a_precalculate, vec_select_floats_upper);
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
523 const vector float R4_precalculate = spu_shuffle(R2a_precalculate, R2a_precalculate, vec_select_floats_lower);
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
524 const vector float R5_precalculate = spu_shuffle(R3a_precalculate, R3a_precalculate, vec_select_floats_upper);
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
525 const vector float R6_precalculate = spu_shuffle(R3a_precalculate, R3a_precalculate, vec_select_floats_lower);
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
526 const vector float R7_precalculate = spu_shuffle(R4a_precalculate, R4a_precalculate, vec_select_floats_upper);
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
527 const vector float R8_precalculate = spu_shuffle(R4a_precalculate, R4a_precalculate, vec_select_floats_lower);
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
528
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
529
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
530 const vector float G1a_precalculate = spu_madd(vec_Gu_precalc_coeff, vfloat_U_1, spu_mul(vfloat_V_1, vec_Gv_precalc_coeff));
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
531 const vector float G2a_precalculate = spu_madd(vec_Gu_precalc_coeff, vfloat_U_2, spu_mul(vfloat_V_2, vec_Gv_precalc_coeff));
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
532 const vector float G3a_precalculate = spu_madd(vec_Gu_precalc_coeff, vfloat_U_3, spu_mul(vfloat_V_3, vec_Gv_precalc_coeff));
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
533 const vector float G4a_precalculate = spu_madd(vec_Gu_precalc_coeff, vfloat_U_4, spu_mul(vfloat_V_4, vec_Gv_precalc_coeff));
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
534
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
535 const vector float G1_precalculate = spu_shuffle(G1a_precalculate, G1a_precalculate, vec_select_floats_upper);
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
536 const vector float G2_precalculate = spu_shuffle(G1a_precalculate, G1a_precalculate, vec_select_floats_lower);
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
537 const vector float G3_precalculate = spu_shuffle(G2a_precalculate, G2a_precalculate, vec_select_floats_upper);
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
538 const vector float G4_precalculate = spu_shuffle(G2a_precalculate, G2a_precalculate, vec_select_floats_lower);
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
539 const vector float G5_precalculate = spu_shuffle(G3a_precalculate, G3a_precalculate, vec_select_floats_upper);
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
540 const vector float G6_precalculate = spu_shuffle(G3a_precalculate, G3a_precalculate, vec_select_floats_lower);
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
541 const vector float G7_precalculate = spu_shuffle(G4a_precalculate, G4a_precalculate, vec_select_floats_upper);
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
542 const vector float G8_precalculate = spu_shuffle(G4a_precalculate, G4a_precalculate, vec_select_floats_lower);
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
543
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
544
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
545 const vector float B1a_precalculate = spu_mul(vec_B_precalc_coeff, vfloat_U_1);
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
546 const vector float B2a_precalculate = spu_mul(vec_B_precalc_coeff, vfloat_U_2);
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
547 const vector float B3a_precalculate = spu_mul(vec_B_precalc_coeff, vfloat_U_3);
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
548 const vector float B4a_precalculate = spu_mul(vec_B_precalc_coeff, vfloat_U_4);
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
549
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
550 const vector float B1_precalculate = spu_shuffle(B1a_precalculate, B1a_precalculate, vec_select_floats_upper);
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
551 const vector float B2_precalculate = spu_shuffle(B1a_precalculate, B1a_precalculate, vec_select_floats_lower);
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
552 const vector float B3_precalculate = spu_shuffle(B2a_precalculate, B2a_precalculate, vec_select_floats_upper);
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
553 const vector float B4_precalculate = spu_shuffle(B2a_precalculate, B2a_precalculate, vec_select_floats_lower);
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
554 const vector float B5_precalculate = spu_shuffle(B3a_precalculate, B3a_precalculate, vec_select_floats_upper);
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
555 const vector float B6_precalculate = spu_shuffle(B3a_precalculate, B3a_precalculate, vec_select_floats_lower);
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
556 const vector float B7_precalculate = spu_shuffle(B4a_precalculate, B4a_precalculate, vec_select_floats_upper);
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
557 const vector float B8_precalculate = spu_shuffle(B4a_precalculate, B4a_precalculate, vec_select_floats_lower);
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
558
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
559
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
560 const vector unsigned int R_1 = vfloat_to_vuint(spu_add( Y_1, R1_precalculate));
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
561 const vector unsigned int R_2 = vfloat_to_vuint(spu_add( Y_2, R2_precalculate));
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
562 const vector unsigned int R_3 = vfloat_to_vuint(spu_add( Y_3, R3_precalculate));
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
563 const vector unsigned int R_4 = vfloat_to_vuint(spu_add( Y_4, R4_precalculate));
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
564 const vector unsigned int R_5 = vfloat_to_vuint(spu_add( Y_5, R5_precalculate));
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
565 const vector unsigned int R_6 = vfloat_to_vuint(spu_add( Y_6, R6_precalculate));
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
566 const vector unsigned int R_7 = vfloat_to_vuint(spu_add( Y_7, R7_precalculate));
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
567 const vector unsigned int R_8 = vfloat_to_vuint(spu_add( Y_8, R8_precalculate));
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
568 const vector unsigned int R_9 = vfloat_to_vuint(spu_add( Y_9, R1_precalculate));
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
569 const vector unsigned int R_10 = vfloat_to_vuint(spu_add(Y_10, R2_precalculate));
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
570 const vector unsigned int R_11 = vfloat_to_vuint(spu_add(Y_11, R3_precalculate));
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
571 const vector unsigned int R_12 = vfloat_to_vuint(spu_add(Y_12, R4_precalculate));
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
572 const vector unsigned int R_13 = vfloat_to_vuint(spu_add(Y_13, R5_precalculate));
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
573 const vector unsigned int R_14 = vfloat_to_vuint(spu_add(Y_14, R6_precalculate));
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
574 const vector unsigned int R_15 = vfloat_to_vuint(spu_add(Y_15, R7_precalculate));
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
575 const vector unsigned int R_16 = vfloat_to_vuint(spu_add(Y_16, R8_precalculate));
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
576
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
577 const vector unsigned int G_1 = vfloat_to_vuint(spu_add( Y_1, G1_precalculate));
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
578 const vector unsigned int G_2 = vfloat_to_vuint(spu_add( Y_2, G2_precalculate));
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
579 const vector unsigned int G_3 = vfloat_to_vuint(spu_add( Y_3, G3_precalculate));
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
580 const vector unsigned int G_4 = vfloat_to_vuint(spu_add( Y_4, G4_precalculate));
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
581 const vector unsigned int G_5 = vfloat_to_vuint(spu_add( Y_5, G5_precalculate));
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
582 const vector unsigned int G_6 = vfloat_to_vuint(spu_add( Y_6, G6_precalculate));
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
583 const vector unsigned int G_7 = vfloat_to_vuint(spu_add( Y_7, G7_precalculate));
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
584 const vector unsigned int G_8 = vfloat_to_vuint(spu_add( Y_8, G8_precalculate));
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
585 const vector unsigned int G_9 = vfloat_to_vuint(spu_add( Y_9, G1_precalculate));
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
586 const vector unsigned int G_10 = vfloat_to_vuint(spu_add(Y_10, G2_precalculate));
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
587 const vector unsigned int G_11 = vfloat_to_vuint(spu_add(Y_11, G3_precalculate));
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
588 const vector unsigned int G_12 = vfloat_to_vuint(spu_add(Y_12, G4_precalculate));
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
589 const vector unsigned int G_13 = vfloat_to_vuint(spu_add(Y_13, G5_precalculate));
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
590 const vector unsigned int G_14 = vfloat_to_vuint(spu_add(Y_14, G6_precalculate));
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
591 const vector unsigned int G_15 = vfloat_to_vuint(spu_add(Y_15, G7_precalculate));
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
592 const vector unsigned int G_16 = vfloat_to_vuint(spu_add(Y_16, G8_precalculate));
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
593
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
594 const vector unsigned int B_1 = vfloat_to_vuint(spu_add( Y_1, B1_precalculate));
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
595 const vector unsigned int B_2 = vfloat_to_vuint(spu_add( Y_2, B2_precalculate));
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
596 const vector unsigned int B_3 = vfloat_to_vuint(spu_add( Y_3, B3_precalculate));
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
597 const vector unsigned int B_4 = vfloat_to_vuint(spu_add( Y_4, B4_precalculate));
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
598 const vector unsigned int B_5 = vfloat_to_vuint(spu_add( Y_5, B5_precalculate));
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
599 const vector unsigned int B_6 = vfloat_to_vuint(spu_add( Y_6, B6_precalculate));
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
600 const vector unsigned int B_7 = vfloat_to_vuint(spu_add( Y_7, B7_precalculate));
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
601 const vector unsigned int B_8 = vfloat_to_vuint(spu_add( Y_8, B8_precalculate));
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
602 const vector unsigned int B_9 = vfloat_to_vuint(spu_add( Y_9, B1_precalculate));
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
603 const vector unsigned int B_10 = vfloat_to_vuint(spu_add(Y_10, B2_precalculate));
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
604 const vector unsigned int B_11 = vfloat_to_vuint(spu_add(Y_11, B3_precalculate));
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
605 const vector unsigned int B_12 = vfloat_to_vuint(spu_add(Y_12, B4_precalculate));
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
606 const vector unsigned int B_13 = vfloat_to_vuint(spu_add(Y_13, B5_precalculate));
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
607 const vector unsigned int B_14 = vfloat_to_vuint(spu_add(Y_14, B6_precalculate));
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
608 const vector unsigned int B_15 = vfloat_to_vuint(spu_add(Y_15, B7_precalculate));
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
609 const vector unsigned int B_16 = vfloat_to_vuint(spu_add(Y_16, B8_precalculate));
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
610
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
611 *((vector unsigned int*)(bgra_addr + x)) = spu_or(spu_or(vec_alpha, B_1), spu_or(spu_slqwbyte( R_1, 2),spu_slqwbyte(G_1, 1)));
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
612 *((vector unsigned int*)(bgra_addr + x + 4)) = spu_or(spu_or(vec_alpha, B_2), spu_or(spu_slqwbyte( R_2, 2),spu_slqwbyte(G_2, 1)));
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
613 *((vector unsigned int*)(bgra_addr + x + 8)) = spu_or(spu_or(vec_alpha, B_3), spu_or(spu_slqwbyte( R_3, 2),spu_slqwbyte(G_3, 1)));
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
614 *((vector unsigned int*)(bgra_addr + x + 12)) = spu_or(spu_or(vec_alpha, B_4), spu_or(spu_slqwbyte( R_4, 2),spu_slqwbyte(G_4, 1)));
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
615 *((vector unsigned int*)(bgra_addr + x + 16)) = spu_or(spu_or(vec_alpha, B_5), spu_or(spu_slqwbyte( R_5, 2),spu_slqwbyte(G_5, 1)));
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
616 *((vector unsigned int*)(bgra_addr + x + 20)) = spu_or(spu_or(vec_alpha, B_6), spu_or(spu_slqwbyte( R_6, 2),spu_slqwbyte(G_6, 1)));
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
617 *((vector unsigned int*)(bgra_addr + x + 24)) = spu_or(spu_or(vec_alpha, B_7), spu_or(spu_slqwbyte( R_7, 2),spu_slqwbyte(G_7, 1)));
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
618 *((vector unsigned int*)(bgra_addr + x + 28)) = spu_or(spu_or(vec_alpha, B_8), spu_or(spu_slqwbyte( R_8, 2),spu_slqwbyte(G_8, 1)));
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
619 *((vector unsigned int*)(bgra_addr + x + width)) = spu_or(spu_or(vec_alpha, B_9), spu_or(spu_slqwbyte( R_9, 2),spu_slqwbyte(G_9, 1)));
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
620 *((vector unsigned int*)(bgra_addr + x + width + 4)) = spu_or(spu_or(vec_alpha, B_10), spu_or(spu_slqwbyte(R_10, 2),spu_slqwbyte(G_10, 1)));
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
621 *((vector unsigned int*)(bgra_addr + x + width + 8)) = spu_or(spu_or(vec_alpha, B_11), spu_or(spu_slqwbyte(R_11, 2),spu_slqwbyte(G_11, 1)));
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
622 *((vector unsigned int*)(bgra_addr + x + width + 12)) = spu_or(spu_or(vec_alpha, B_12), spu_or(spu_slqwbyte(R_12, 2),spu_slqwbyte(G_12, 1)));
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
623 *((vector unsigned int*)(bgra_addr + x + width + 16)) = spu_or(spu_or(vec_alpha, B_13), spu_or(spu_slqwbyte(R_13, 2),spu_slqwbyte(G_13, 1)));
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
624 *((vector unsigned int*)(bgra_addr + x + width + 20)) = spu_or(spu_or(vec_alpha, B_14), spu_or(spu_slqwbyte(R_14, 2),spu_slqwbyte(G_14, 1)));
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
625 *((vector unsigned int*)(bgra_addr + x + width + 24)) = spu_or(spu_or(vec_alpha, B_15), spu_or(spu_slqwbyte(R_15, 2),spu_slqwbyte(G_15, 1)));
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
626 *((vector unsigned int*)(bgra_addr + x + width + 28)) = spu_or(spu_or(vec_alpha, B_16), spu_or(spu_slqwbyte(R_16, 2),spu_slqwbyte(G_16, 1)));
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
627 }
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
628 }
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
629