19682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall/* 29682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall SDL - Simple DirectMedia Layer 39682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall Copyright (C) 1997-2012 Sam Lantinga 49682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall 59682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall This library is free software; you can redistribute it and/or 69682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall modify it under the terms of the GNU Lesser General Public 79682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall License as published by the Free Software Foundation; either 89682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall version 2.1 of the License, or (at your option) any later version. 99682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall 109682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall This library is distributed in the hope that it will be useful, 119682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall but WITHOUT ANY WARRANTY; without even the implied warranty of 129682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 139682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall Lesser General Public License for more details. 149682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall 159682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall You should have received a copy of the GNU Lesser General Public 169682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall License along with this library; if not, write to the Free Software 179682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA 189682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall 199682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall Sam Lantinga 209682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall slouken@libsdl.org 219682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall*/ 229682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall#include "SDL_config.h" 239682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall 249682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall/* This is the software implementation of the YUV video overlay support */ 259682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall 269682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall/* This code was derived from code carrying the following copyright notices: 279682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall 289682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall * Copyright (c) 1995 The Regents of the University of California. 299682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall * All rights reserved. 309682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall * 319682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall * Permission to use, copy, modify, and distribute this software and its 329682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall * documentation for any purpose, without fee, and without written agreement is 339682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall * hereby granted, provided that the above copyright notice and the following 349682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall * two paragraphs appear in all copies of this software. 359682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall * 369682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall * IN NO EVENT SHALL THE UNIVERSITY OF CALIFORNIA BE LIABLE TO ANY PARTY FOR 379682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall * DIRECT, INDIRECT, SPECIAL, INCIDENTAL, OR CONSEQUENTIAL DAMAGES ARISING OUT 389682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall * OF THE USE OF THIS SOFTWARE AND ITS DOCUMENTATION, EVEN IF THE UNIVERSITY OF 399682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall * CALIFORNIA HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 409682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall * 419682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall * THE UNIVERSITY OF CALIFORNIA SPECIFICALLY DISCLAIMS ANY WARRANTIES, 429682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall * INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY 439682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall * AND FITNESS FOR A PARTICULAR PURPOSE. THE SOFTWARE PROVIDED HEREUNDER IS 449682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall * ON AN "AS IS" BASIS, AND THE UNIVERSITY OF CALIFORNIA HAS NO OBLIGATION TO 459682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall * PROVIDE MAINTENANCE, SUPPORT, UPDATES, ENHANCEMENTS, OR MODIFICATIONS. 469682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall 479682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall * Copyright (c) 1995 Erik Corry 489682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall * All rights reserved. 499682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall * 509682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall * Permission to use, copy, modify, and distribute this software and its 519682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall * documentation for any purpose, without fee, and without written agreement is 529682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall * hereby granted, provided that the above copyright notice and the following 539682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall * two paragraphs appear in all copies of this software. 549682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall * 559682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall * IN NO EVENT SHALL ERIK CORRY BE LIABLE TO ANY PARTY FOR DIRECT, INDIRECT, 569682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall * SPECIAL, INCIDENTAL, OR CONSEQUENTIAL DAMAGES ARISING OUT OF THE USE OF 579682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall * THIS SOFTWARE AND ITS DOCUMENTATION, EVEN IF ERIK CORRY HAS BEEN ADVISED 589682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall * OF THE POSSIBILITY OF SUCH DAMAGE. 599682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall * 609682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall * ERIK CORRY SPECIFICALLY DISCLAIMS ANY WARRANTIES, INCLUDING, BUT NOT 619682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A 629682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall * PARTICULAR PURPOSE. THE SOFTWARE PROVIDED HEREUNDER IS ON AN "AS IS" 639682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall * BASIS, AND ERIK CORRY HAS NO OBLIGATION TO PROVIDE MAINTENANCE, SUPPORT, 649682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall * UPDATES, ENHANCEMENTS, OR MODIFICATIONS. 659682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall 669682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall * Portions of this software Copyright (c) 1995 Brown University. 679682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall * All rights reserved. 689682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall * 699682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall * Permission to use, copy, modify, and distribute this software and its 709682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall * documentation for any purpose, without fee, and without written agreement 719682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall * is hereby granted, provided that the above copyright notice and the 729682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall * following two paragraphs appear in all copies of this software. 739682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall * 749682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall * IN NO EVENT SHALL BROWN UNIVERSITY BE LIABLE TO ANY PARTY FOR 759682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall * DIRECT, INDIRECT, SPECIAL, INCIDENTAL, OR CONSEQUENTIAL DAMAGES ARISING OUT 769682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall * OF THE USE OF THIS SOFTWARE AND ITS DOCUMENTATION, EVEN IF BROWN 779682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall * UNIVERSITY HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 789682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall * 799682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall * BROWN UNIVERSITY SPECIFICALLY DISCLAIMS ANY WARRANTIES, INCLUDING, BUT NOT 809682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A 819682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall * PARTICULAR PURPOSE. THE SOFTWARE PROVIDED HEREUNDER IS ON AN "AS IS" 829682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall * BASIS, AND BROWN UNIVERSITY HAS NO OBLIGATION TO PROVIDE MAINTENANCE, 839682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall * SUPPORT, UPDATES, ENHANCEMENTS, OR MODIFICATIONS. 849682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall */ 859682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall 869682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall#include "SDL_video.h" 879682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall#include "SDL_cpuinfo.h" 889682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall#include "SDL_stretch_c.h" 899682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall#include "SDL_yuvfuncs.h" 909682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall#include "SDL_yuv_sw_c.h" 919682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall 929682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall/* The functions used to manipulate software video overlays */ 939682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hallstatic struct private_yuvhwfuncs sw_yuvfuncs = { 949682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall SDL_LockYUV_SW, 959682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall SDL_UnlockYUV_SW, 969682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall SDL_DisplayYUV_SW, 979682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall SDL_FreeYUV_SW 989682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall}; 999682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall 1009682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall/* RGB conversion lookup tables */ 1019682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hallstruct private_yuvhwdata { 1029682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall SDL_Surface *stretch; 1039682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall SDL_Surface *display; 1049682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall Uint8 *pixels; 1059682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall int *colortab; 1069682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall Uint32 *rgb_2_pix; 1079682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall void (*Display1X)(int *colortab, Uint32 *rgb_2_pix, 1089682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall unsigned char *lum, unsigned char *cr, 1099682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall unsigned char *cb, unsigned char *out, 1109682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall int rows, int cols, int mod ); 1119682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall void (*Display2X)(int *colortab, Uint32 *rgb_2_pix, 1129682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall unsigned char *lum, unsigned char *cr, 1139682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall unsigned char *cb, unsigned char *out, 1149682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall int rows, int cols, int mod ); 1159682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall 1169682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall /* These are just so we don't have to allocate them separately */ 1179682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall Uint16 pitches[3]; 1189682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall Uint8 *planes[3]; 1199682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall}; 1209682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall 1219682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall 1229682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall/* The colorspace conversion functions */ 1239682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall 1249682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall#if (__GNUC__ > 2) && defined(__i386__) && __OPTIMIZE__ && SDL_ASSEMBLY_ROUTINES 1259682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hallextern void Color565DitherYV12MMX1X( int *colortab, Uint32 *rgb_2_pix, 1269682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall unsigned char *lum, unsigned char *cr, 1279682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall unsigned char *cb, unsigned char *out, 1289682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall int rows, int cols, int mod ); 1299682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hallextern void ColorRGBDitherYV12MMX1X( int *colortab, Uint32 *rgb_2_pix, 1309682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall unsigned char *lum, unsigned char *cr, 1319682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall unsigned char *cb, unsigned char *out, 1329682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall int rows, int cols, int mod ); 1339682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall#endif 1349682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall 1359682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hallstatic void Color16DitherYV12Mod1X( int *colortab, Uint32 *rgb_2_pix, 1369682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall unsigned char *lum, unsigned char *cr, 1379682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall unsigned char *cb, unsigned char *out, 1389682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall int rows, int cols, int mod ) 1399682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall{ 1409682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall unsigned short* row1; 1419682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall unsigned short* row2; 1429682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall unsigned char* lum2; 1439682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall int x, y; 1449682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall int cr_r; 1459682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall int crb_g; 1469682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall int cb_b; 1479682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall int cols_2 = cols / 2; 1489682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall 1499682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall row1 = (unsigned short*) out; 1509682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall row2 = row1 + cols + mod; 1519682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall lum2 = lum + cols; 1529682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall 1539682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall mod += cols + mod; 1549682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall 1559682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall y = rows / 2; 1569682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall while( y-- ) 1579682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall { 1589682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall x = cols_2; 1599682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall while( x-- ) 1609682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall { 1619682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall register int L; 1629682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall 1639682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall cr_r = 0*768+256 + colortab[ *cr + 0*256 ]; 1649682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall crb_g = 1*768+256 + colortab[ *cr + 1*256 ] 1659682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall + colortab[ *cb + 2*256 ]; 1669682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall cb_b = 2*768+256 + colortab[ *cb + 3*256 ]; 1679682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall ++cr; ++cb; 1689682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall 1699682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall L = *lum++; 1709682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall *row1++ = (unsigned short)(rgb_2_pix[ L + cr_r ] | 1719682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall rgb_2_pix[ L + crb_g ] | 1729682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall rgb_2_pix[ L + cb_b ]); 1739682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall 1749682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall L = *lum++; 1759682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall *row1++ = (unsigned short)(rgb_2_pix[ L + cr_r ] | 1769682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall rgb_2_pix[ L + crb_g ] | 1779682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall rgb_2_pix[ L + cb_b ]); 1789682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall 1799682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall 1809682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall /* Now, do second row. */ 1819682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall 1829682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall L = *lum2++; 1839682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall *row2++ = (unsigned short)(rgb_2_pix[ L + cr_r ] | 1849682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall rgb_2_pix[ L + crb_g ] | 1859682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall rgb_2_pix[ L + cb_b ]); 1869682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall 1879682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall L = *lum2++; 1889682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall *row2++ = (unsigned short)(rgb_2_pix[ L + cr_r ] | 1899682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall rgb_2_pix[ L + crb_g ] | 1909682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall rgb_2_pix[ L + cb_b ]); 1919682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall } 1929682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall 1939682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall /* 1949682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall * These values are at the start of the next line, (due 1959682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall * to the ++'s above),but they need to be at the start 1969682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall * of the line after that. 1979682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall */ 1989682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall lum += cols; 1999682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall lum2 += cols; 2009682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall row1 += mod; 2019682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall row2 += mod; 2029682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall } 2039682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall} 2049682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall 2059682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hallstatic void Color24DitherYV12Mod1X( int *colortab, Uint32 *rgb_2_pix, 2069682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall unsigned char *lum, unsigned char *cr, 2079682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall unsigned char *cb, unsigned char *out, 2089682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall int rows, int cols, int mod ) 2099682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall{ 2109682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall unsigned int value; 2119682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall unsigned char* row1; 2129682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall unsigned char* row2; 2139682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall unsigned char* lum2; 2149682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall int x, y; 2159682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall int cr_r; 2169682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall int crb_g; 2179682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall int cb_b; 2189682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall int cols_2 = cols / 2; 2199682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall 2209682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall row1 = out; 2219682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall row2 = row1 + cols*3 + mod*3; 2229682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall lum2 = lum + cols; 2239682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall 2249682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall mod += cols + mod; 2259682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall mod *= 3; 2269682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall 2279682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall y = rows / 2; 2289682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall while( y-- ) 2299682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall { 2309682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall x = cols_2; 2319682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall while( x-- ) 2329682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall { 2339682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall register int L; 2349682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall 2359682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall cr_r = 0*768+256 + colortab[ *cr + 0*256 ]; 2369682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall crb_g = 1*768+256 + colortab[ *cr + 1*256 ] 2379682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall + colortab[ *cb + 2*256 ]; 2389682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall cb_b = 2*768+256 + colortab[ *cb + 3*256 ]; 2399682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall ++cr; ++cb; 2409682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall 2419682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall L = *lum++; 2429682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall value = (rgb_2_pix[ L + cr_r ] | 2439682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall rgb_2_pix[ L + crb_g ] | 2449682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall rgb_2_pix[ L + cb_b ]); 2459682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall *row1++ = (value ) & 0xFF; 2469682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall *row1++ = (value >> 8) & 0xFF; 2479682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall *row1++ = (value >> 16) & 0xFF; 2489682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall 2499682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall L = *lum++; 2509682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall value = (rgb_2_pix[ L + cr_r ] | 2519682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall rgb_2_pix[ L + crb_g ] | 2529682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall rgb_2_pix[ L + cb_b ]); 2539682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall *row1++ = (value ) & 0xFF; 2549682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall *row1++ = (value >> 8) & 0xFF; 2559682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall *row1++ = (value >> 16) & 0xFF; 2569682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall 2579682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall 2589682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall /* Now, do second row. */ 2599682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall 2609682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall L = *lum2++; 2619682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall value = (rgb_2_pix[ L + cr_r ] | 2629682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall rgb_2_pix[ L + crb_g ] | 2639682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall rgb_2_pix[ L + cb_b ]); 2649682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall *row2++ = (value ) & 0xFF; 2659682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall *row2++ = (value >> 8) & 0xFF; 2669682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall *row2++ = (value >> 16) & 0xFF; 2679682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall 2689682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall L = *lum2++; 2699682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall value = (rgb_2_pix[ L + cr_r ] | 2709682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall rgb_2_pix[ L + crb_g ] | 2719682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall rgb_2_pix[ L + cb_b ]); 2729682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall *row2++ = (value ) & 0xFF; 2739682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall *row2++ = (value >> 8) & 0xFF; 2749682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall *row2++ = (value >> 16) & 0xFF; 2759682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall } 2769682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall 2779682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall /* 2789682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall * These values are at the start of the next line, (due 2799682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall * to the ++'s above),but they need to be at the start 2809682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall * of the line after that. 2819682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall */ 2829682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall lum += cols; 2839682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall lum2 += cols; 2849682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall row1 += mod; 2859682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall row2 += mod; 2869682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall } 2879682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall} 2889682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall 2899682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hallstatic void Color32DitherYV12Mod1X( int *colortab, Uint32 *rgb_2_pix, 2909682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall unsigned char *lum, unsigned char *cr, 2919682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall unsigned char *cb, unsigned char *out, 2929682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall int rows, int cols, int mod ) 2939682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall{ 2949682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall unsigned int* row1; 2959682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall unsigned int* row2; 2969682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall unsigned char* lum2; 2979682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall int x, y; 2989682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall int cr_r; 2999682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall int crb_g; 3009682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall int cb_b; 3019682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall int cols_2 = cols / 2; 3029682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall 3039682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall row1 = (unsigned int*) out; 3049682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall row2 = row1 + cols + mod; 3059682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall lum2 = lum + cols; 3069682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall 3079682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall mod += cols + mod; 3089682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall 3099682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall y = rows / 2; 3109682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall while( y-- ) 3119682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall { 3129682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall x = cols_2; 3139682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall while( x-- ) 3149682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall { 3159682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall register int L; 3169682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall 3179682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall cr_r = 0*768+256 + colortab[ *cr + 0*256 ]; 3189682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall crb_g = 1*768+256 + colortab[ *cr + 1*256 ] 3199682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall + colortab[ *cb + 2*256 ]; 3209682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall cb_b = 2*768+256 + colortab[ *cb + 3*256 ]; 3219682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall ++cr; ++cb; 3229682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall 3239682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall L = *lum++; 3249682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall *row1++ = (rgb_2_pix[ L + cr_r ] | 3259682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall rgb_2_pix[ L + crb_g ] | 3269682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall rgb_2_pix[ L + cb_b ]); 3279682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall 3289682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall L = *lum++; 3299682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall *row1++ = (rgb_2_pix[ L + cr_r ] | 3309682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall rgb_2_pix[ L + crb_g ] | 3319682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall rgb_2_pix[ L + cb_b ]); 3329682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall 3339682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall 3349682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall /* Now, do second row. */ 3359682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall 3369682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall L = *lum2++; 3379682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall *row2++ = (rgb_2_pix[ L + cr_r ] | 3389682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall rgb_2_pix[ L + crb_g ] | 3399682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall rgb_2_pix[ L + cb_b ]); 3409682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall 3419682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall L = *lum2++; 3429682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall *row2++ = (rgb_2_pix[ L + cr_r ] | 3439682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall rgb_2_pix[ L + crb_g ] | 3449682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall rgb_2_pix[ L + cb_b ]); 3459682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall } 3469682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall 3479682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall /* 3489682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall * These values are at the start of the next line, (due 3499682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall * to the ++'s above),but they need to be at the start 3509682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall * of the line after that. 3519682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall */ 3529682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall lum += cols; 3539682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall lum2 += cols; 3549682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall row1 += mod; 3559682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall row2 += mod; 3569682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall } 3579682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall} 3589682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall 3599682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall/* 3609682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall * In this function I make use of a nasty trick. The tables have the lower 3619682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall * 16 bits replicated in the upper 16. This means I can write ints and get 3629682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall * the horisontal doubling for free (almost). 3639682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall */ 3649682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hallstatic void Color16DitherYV12Mod2X( int *colortab, Uint32 *rgb_2_pix, 3659682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall unsigned char *lum, unsigned char *cr, 3669682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall unsigned char *cb, unsigned char *out, 3679682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall int rows, int cols, int mod ) 3689682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall{ 3699682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall unsigned int* row1 = (unsigned int*) out; 3709682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall const int next_row = cols+(mod/2); 3719682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall unsigned int* row2 = row1 + 2*next_row; 3729682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall unsigned char* lum2; 3739682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall int x, y; 3749682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall int cr_r; 3759682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall int crb_g; 3769682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall int cb_b; 3779682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall int cols_2 = cols / 2; 3789682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall 3799682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall lum2 = lum + cols; 3809682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall 3819682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall mod = (next_row * 3) + (mod/2); 3829682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall 3839682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall y = rows / 2; 3849682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall while( y-- ) 3859682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall { 3869682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall x = cols_2; 3879682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall while( x-- ) 3889682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall { 3899682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall register int L; 3909682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall 3919682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall cr_r = 0*768+256 + colortab[ *cr + 0*256 ]; 3929682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall crb_g = 1*768+256 + colortab[ *cr + 1*256 ] 3939682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall + colortab[ *cb + 2*256 ]; 3949682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall cb_b = 2*768+256 + colortab[ *cb + 3*256 ]; 3959682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall ++cr; ++cb; 3969682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall 3979682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall L = *lum++; 3989682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall row1[0] = row1[next_row] = (rgb_2_pix[ L + cr_r ] | 3999682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall rgb_2_pix[ L + crb_g ] | 4009682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall rgb_2_pix[ L + cb_b ]); 4019682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall row1++; 4029682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall 4039682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall L = *lum++; 4049682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall row1[0] = row1[next_row] = (rgb_2_pix[ L + cr_r ] | 4059682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall rgb_2_pix[ L + crb_g ] | 4069682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall rgb_2_pix[ L + cb_b ]); 4079682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall row1++; 4089682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall 4099682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall 4109682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall /* Now, do second row. */ 4119682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall 4129682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall L = *lum2++; 4139682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall row2[0] = row2[next_row] = (rgb_2_pix[ L + cr_r ] | 4149682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall rgb_2_pix[ L + crb_g ] | 4159682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall rgb_2_pix[ L + cb_b ]); 4169682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall row2++; 4179682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall 4189682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall L = *lum2++; 4199682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall row2[0] = row2[next_row] = (rgb_2_pix[ L + cr_r ] | 4209682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall rgb_2_pix[ L + crb_g ] | 4219682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall rgb_2_pix[ L + cb_b ]); 4229682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall row2++; 4239682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall } 4249682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall 4259682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall /* 4269682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall * These values are at the start of the next line, (due 4279682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall * to the ++'s above),but they need to be at the start 4289682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall * of the line after that. 4299682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall */ 4309682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall lum += cols; 4319682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall lum2 += cols; 4329682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall row1 += mod; 4339682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall row2 += mod; 4349682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall } 4359682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall} 4369682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall 4379682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hallstatic void Color24DitherYV12Mod2X( int *colortab, Uint32 *rgb_2_pix, 4389682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall unsigned char *lum, unsigned char *cr, 4399682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall unsigned char *cb, unsigned char *out, 4409682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall int rows, int cols, int mod ) 4419682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall{ 4429682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall unsigned int value; 4439682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall unsigned char* row1 = out; 4449682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall const int next_row = (cols*2 + mod) * 3; 4459682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall unsigned char* row2 = row1 + 2*next_row; 4469682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall unsigned char* lum2; 4479682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall int x, y; 4489682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall int cr_r; 4499682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall int crb_g; 4509682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall int cb_b; 4519682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall int cols_2 = cols / 2; 4529682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall 4539682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall lum2 = lum + cols; 4549682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall 4559682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall mod = next_row*3 + mod*3; 4569682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall 4579682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall y = rows / 2; 4589682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall while( y-- ) 4599682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall { 4609682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall x = cols_2; 4619682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall while( x-- ) 4629682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall { 4639682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall register int L; 4649682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall 4659682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall cr_r = 0*768+256 + colortab[ *cr + 0*256 ]; 4669682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall crb_g = 1*768+256 + colortab[ *cr + 1*256 ] 4679682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall + colortab[ *cb + 2*256 ]; 4689682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall cb_b = 2*768+256 + colortab[ *cb + 3*256 ]; 4699682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall ++cr; ++cb; 4709682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall 4719682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall L = *lum++; 4729682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall value = (rgb_2_pix[ L + cr_r ] | 4739682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall rgb_2_pix[ L + crb_g ] | 4749682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall rgb_2_pix[ L + cb_b ]); 4759682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall row1[0+0] = row1[3+0] = row1[next_row+0] = row1[next_row+3+0] = 4769682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall (value ) & 0xFF; 4779682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall row1[0+1] = row1[3+1] = row1[next_row+1] = row1[next_row+3+1] = 4789682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall (value >> 8) & 0xFF; 4799682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall row1[0+2] = row1[3+2] = row1[next_row+2] = row1[next_row+3+2] = 4809682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall (value >> 16) & 0xFF; 4819682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall row1 += 2*3; 4829682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall 4839682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall L = *lum++; 4849682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall value = (rgb_2_pix[ L + cr_r ] | 4859682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall rgb_2_pix[ L + crb_g ] | 4869682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall rgb_2_pix[ L + cb_b ]); 4879682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall row1[0+0] = row1[3+0] = row1[next_row+0] = row1[next_row+3+0] = 4889682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall (value ) & 0xFF; 4899682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall row1[0+1] = row1[3+1] = row1[next_row+1] = row1[next_row+3+1] = 4909682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall (value >> 8) & 0xFF; 4919682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall row1[0+2] = row1[3+2] = row1[next_row+2] = row1[next_row+3+2] = 4929682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall (value >> 16) & 0xFF; 4939682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall row1 += 2*3; 4949682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall 4959682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall 4969682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall /* Now, do second row. */ 4979682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall 4989682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall L = *lum2++; 4999682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall value = (rgb_2_pix[ L + cr_r ] | 5009682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall rgb_2_pix[ L + crb_g ] | 5019682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall rgb_2_pix[ L + cb_b ]); 5029682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall row2[0+0] = row2[3+0] = row2[next_row+0] = row2[next_row+3+0] = 5039682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall (value ) & 0xFF; 5049682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall row2[0+1] = row2[3+1] = row2[next_row+1] = row2[next_row+3+1] = 5059682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall (value >> 8) & 0xFF; 5069682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall row2[0+2] = row2[3+2] = row2[next_row+2] = row2[next_row+3+2] = 5079682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall (value >> 16) & 0xFF; 5089682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall row2 += 2*3; 5099682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall 5109682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall L = *lum2++; 5119682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall value = (rgb_2_pix[ L + cr_r ] | 5129682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall rgb_2_pix[ L + crb_g ] | 5139682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall rgb_2_pix[ L + cb_b ]); 5149682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall row2[0+0] = row2[3+0] = row2[next_row+0] = row2[next_row+3+0] = 5159682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall (value ) & 0xFF; 5169682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall row2[0+1] = row2[3+1] = row2[next_row+1] = row2[next_row+3+1] = 5179682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall (value >> 8) & 0xFF; 5189682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall row2[0+2] = row2[3+2] = row2[next_row+2] = row2[next_row+3+2] = 5199682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall (value >> 16) & 0xFF; 5209682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall row2 += 2*3; 5219682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall } 5229682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall 5239682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall /* 5249682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall * These values are at the start of the next line, (due 5259682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall * to the ++'s above),but they need to be at the start 5269682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall * of the line after that. 5279682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall */ 5289682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall lum += cols; 5299682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall lum2 += cols; 5309682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall row1 += mod; 5319682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall row2 += mod; 5329682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall } 5339682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall} 5349682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall 5359682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hallstatic void Color32DitherYV12Mod2X( int *colortab, Uint32 *rgb_2_pix, 5369682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall unsigned char *lum, unsigned char *cr, 5379682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall unsigned char *cb, unsigned char *out, 5389682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall int rows, int cols, int mod ) 5399682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall{ 5409682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall unsigned int* row1 = (unsigned int*) out; 5419682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall const int next_row = cols*2+mod; 5429682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall unsigned int* row2 = row1 + 2*next_row; 5439682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall unsigned char* lum2; 5449682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall int x, y; 5459682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall int cr_r; 5469682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall int crb_g; 5479682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall int cb_b; 5489682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall int cols_2 = cols / 2; 5499682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall 5509682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall lum2 = lum + cols; 5519682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall 5529682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall mod = (next_row * 3) + mod; 5539682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall 5549682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall y = rows / 2; 5559682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall while( y-- ) 5569682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall { 5579682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall x = cols_2; 5589682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall while( x-- ) 5599682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall { 5609682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall register int L; 5619682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall 5629682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall cr_r = 0*768+256 + colortab[ *cr + 0*256 ]; 5639682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall crb_g = 1*768+256 + colortab[ *cr + 1*256 ] 5649682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall + colortab[ *cb + 2*256 ]; 5659682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall cb_b = 2*768+256 + colortab[ *cb + 3*256 ]; 5669682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall ++cr; ++cb; 5679682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall 5689682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall L = *lum++; 5699682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall row1[0] = row1[1] = row1[next_row] = row1[next_row+1] = 5709682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall (rgb_2_pix[ L + cr_r ] | 5719682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall rgb_2_pix[ L + crb_g ] | 5729682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall rgb_2_pix[ L + cb_b ]); 5739682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall row1 += 2; 5749682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall 5759682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall L = *lum++; 5769682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall row1[0] = row1[1] = row1[next_row] = row1[next_row+1] = 5779682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall (rgb_2_pix[ L + cr_r ] | 5789682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall rgb_2_pix[ L + crb_g ] | 5799682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall rgb_2_pix[ L + cb_b ]); 5809682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall row1 += 2; 5819682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall 5829682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall 5839682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall /* Now, do second row. */ 5849682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall 5859682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall L = *lum2++; 5869682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall row2[0] = row2[1] = row2[next_row] = row2[next_row+1] = 5879682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall (rgb_2_pix[ L + cr_r ] | 5889682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall rgb_2_pix[ L + crb_g ] | 5899682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall rgb_2_pix[ L + cb_b ]); 5909682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall row2 += 2; 5919682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall 5929682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall L = *lum2++; 5939682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall row2[0] = row2[1] = row2[next_row] = row2[next_row+1] = 5949682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall (rgb_2_pix[ L + cr_r ] | 5959682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall rgb_2_pix[ L + crb_g ] | 5969682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall rgb_2_pix[ L + cb_b ]); 5979682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall row2 += 2; 5989682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall } 5999682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall 6009682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall /* 6019682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall * These values are at the start of the next line, (due 6029682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall * to the ++'s above),but they need to be at the start 6039682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall * of the line after that. 6049682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall */ 6059682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall lum += cols; 6069682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall lum2 += cols; 6079682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall row1 += mod; 6089682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall row2 += mod; 6099682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall } 6109682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall} 6119682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall 6129682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hallstatic void Color16DitherYUY2Mod1X( int *colortab, Uint32 *rgb_2_pix, 6139682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall unsigned char *lum, unsigned char *cr, 6149682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall unsigned char *cb, unsigned char *out, 6159682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall int rows, int cols, int mod ) 6169682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall{ 6179682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall unsigned short* row; 6189682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall int x, y; 6199682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall int cr_r; 6209682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall int crb_g; 6219682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall int cb_b; 6229682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall int cols_2 = cols / 2; 6239682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall 6249682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall row = (unsigned short*) out; 6259682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall 6269682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall y = rows; 6279682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall while( y-- ) 6289682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall { 6299682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall x = cols_2; 6309682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall while( x-- ) 6319682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall { 6329682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall register int L; 6339682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall 6349682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall cr_r = 0*768+256 + colortab[ *cr + 0*256 ]; 6359682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall crb_g = 1*768+256 + colortab[ *cr + 1*256 ] 6369682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall + colortab[ *cb + 2*256 ]; 6379682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall cb_b = 2*768+256 + colortab[ *cb + 3*256 ]; 6389682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall cr += 4; cb += 4; 6399682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall 6409682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall L = *lum; lum += 2; 6419682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall *row++ = (unsigned short)(rgb_2_pix[ L + cr_r ] | 6429682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall rgb_2_pix[ L + crb_g ] | 6439682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall rgb_2_pix[ L + cb_b ]); 6449682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall 6459682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall L = *lum; lum += 2; 6469682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall *row++ = (unsigned short)(rgb_2_pix[ L + cr_r ] | 6479682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall rgb_2_pix[ L + crb_g ] | 6489682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall rgb_2_pix[ L + cb_b ]); 6499682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall 6509682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall } 6519682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall 6529682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall row += mod; 6539682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall } 6549682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall} 6559682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall 6569682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hallstatic void Color24DitherYUY2Mod1X( int *colortab, Uint32 *rgb_2_pix, 6579682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall unsigned char *lum, unsigned char *cr, 6589682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall unsigned char *cb, unsigned char *out, 6599682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall int rows, int cols, int mod ) 6609682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall{ 6619682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall unsigned int value; 6629682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall unsigned char* row; 6639682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall int x, y; 6649682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall int cr_r; 6659682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall int crb_g; 6669682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall int cb_b; 6679682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall int cols_2 = cols / 2; 6689682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall 6699682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall row = (unsigned char*) out; 6709682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall mod *= 3; 6719682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall y = rows; 6729682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall while( y-- ) 6739682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall { 6749682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall x = cols_2; 6759682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall while( x-- ) 6769682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall { 6779682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall register int L; 6789682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall 6799682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall cr_r = 0*768+256 + colortab[ *cr + 0*256 ]; 6809682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall crb_g = 1*768+256 + colortab[ *cr + 1*256 ] 6819682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall + colortab[ *cb + 2*256 ]; 6829682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall cb_b = 2*768+256 + colortab[ *cb + 3*256 ]; 6839682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall cr += 4; cb += 4; 6849682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall 6859682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall L = *lum; lum += 2; 6869682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall value = (rgb_2_pix[ L + cr_r ] | 6879682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall rgb_2_pix[ L + crb_g ] | 6889682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall rgb_2_pix[ L + cb_b ]); 6899682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall *row++ = (value ) & 0xFF; 6909682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall *row++ = (value >> 8) & 0xFF; 6919682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall *row++ = (value >> 16) & 0xFF; 6929682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall 6939682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall L = *lum; lum += 2; 6949682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall value = (rgb_2_pix[ L + cr_r ] | 6959682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall rgb_2_pix[ L + crb_g ] | 6969682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall rgb_2_pix[ L + cb_b ]); 6979682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall *row++ = (value ) & 0xFF; 6989682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall *row++ = (value >> 8) & 0xFF; 6999682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall *row++ = (value >> 16) & 0xFF; 7009682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall 7019682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall } 7029682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall row += mod; 7039682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall } 7049682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall} 7059682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall 7069682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hallstatic void Color32DitherYUY2Mod1X( int *colortab, Uint32 *rgb_2_pix, 7079682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall unsigned char *lum, unsigned char *cr, 7089682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall unsigned char *cb, unsigned char *out, 7099682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall int rows, int cols, int mod ) 7109682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall{ 7119682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall unsigned int* row; 7129682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall int x, y; 7139682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall int cr_r; 7149682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall int crb_g; 7159682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall int cb_b; 7169682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall int cols_2 = cols / 2; 7179682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall 7189682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall row = (unsigned int*) out; 7199682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall y = rows; 7209682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall while( y-- ) 7219682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall { 7229682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall x = cols_2; 7239682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall while( x-- ) 7249682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall { 7259682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall register int L; 7269682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall 7279682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall cr_r = 0*768+256 + colortab[ *cr + 0*256 ]; 7289682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall crb_g = 1*768+256 + colortab[ *cr + 1*256 ] 7299682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall + colortab[ *cb + 2*256 ]; 7309682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall cb_b = 2*768+256 + colortab[ *cb + 3*256 ]; 7319682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall cr += 4; cb += 4; 7329682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall 7339682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall L = *lum; lum += 2; 7349682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall *row++ = (rgb_2_pix[ L + cr_r ] | 7359682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall rgb_2_pix[ L + crb_g ] | 7369682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall rgb_2_pix[ L + cb_b ]); 7379682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall 7389682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall L = *lum; lum += 2; 7399682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall *row++ = (rgb_2_pix[ L + cr_r ] | 7409682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall rgb_2_pix[ L + crb_g ] | 7419682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall rgb_2_pix[ L + cb_b ]); 7429682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall 7439682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall 7449682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall } 7459682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall row += mod; 7469682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall } 7479682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall} 7489682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall 7499682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall/* 7509682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall * In this function I make use of a nasty trick. The tables have the lower 7519682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall * 16 bits replicated in the upper 16. This means I can write ints and get 7529682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall * the horisontal doubling for free (almost). 7539682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall */ 7549682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hallstatic void Color16DitherYUY2Mod2X( int *colortab, Uint32 *rgb_2_pix, 7559682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall unsigned char *lum, unsigned char *cr, 7569682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall unsigned char *cb, unsigned char *out, 7579682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall int rows, int cols, int mod ) 7589682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall{ 7599682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall unsigned int* row = (unsigned int*) out; 7609682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall const int next_row = cols+(mod/2); 7619682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall int x, y; 7629682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall int cr_r; 7639682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall int crb_g; 7649682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall int cb_b; 7659682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall int cols_2 = cols / 2; 7669682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall 7679682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall y = rows; 7689682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall while( y-- ) 7699682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall { 7709682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall x = cols_2; 7719682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall while( x-- ) 7729682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall { 7739682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall register int L; 7749682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall 7759682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall cr_r = 0*768+256 + colortab[ *cr + 0*256 ]; 7769682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall crb_g = 1*768+256 + colortab[ *cr + 1*256 ] 7779682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall + colortab[ *cb + 2*256 ]; 7789682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall cb_b = 2*768+256 + colortab[ *cb + 3*256 ]; 7799682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall cr += 4; cb += 4; 7809682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall 7819682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall L = *lum; lum += 2; 7829682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall row[0] = row[next_row] = (rgb_2_pix[ L + cr_r ] | 7839682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall rgb_2_pix[ L + crb_g ] | 7849682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall rgb_2_pix[ L + cb_b ]); 7859682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall row++; 7869682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall 7879682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall L = *lum; lum += 2; 7889682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall row[0] = row[next_row] = (rgb_2_pix[ L + cr_r ] | 7899682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall rgb_2_pix[ L + crb_g ] | 7909682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall rgb_2_pix[ L + cb_b ]); 7919682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall row++; 7929682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall 7939682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall } 7949682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall row += next_row; 7959682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall } 7969682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall} 7979682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall 7989682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hallstatic void Color24DitherYUY2Mod2X( int *colortab, Uint32 *rgb_2_pix, 7999682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall unsigned char *lum, unsigned char *cr, 8009682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall unsigned char *cb, unsigned char *out, 8019682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall int rows, int cols, int mod ) 8029682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall{ 8039682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall unsigned int value; 8049682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall unsigned char* row = out; 8059682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall const int next_row = (cols*2 + mod) * 3; 8069682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall int x, y; 8079682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall int cr_r; 8089682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall int crb_g; 8099682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall int cb_b; 8109682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall int cols_2 = cols / 2; 8119682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall y = rows; 8129682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall while( y-- ) 8139682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall { 8149682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall x = cols_2; 8159682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall while( x-- ) 8169682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall { 8179682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall register int L; 8189682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall 8199682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall cr_r = 0*768+256 + colortab[ *cr + 0*256 ]; 8209682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall crb_g = 1*768+256 + colortab[ *cr + 1*256 ] 8219682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall + colortab[ *cb + 2*256 ]; 8229682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall cb_b = 2*768+256 + colortab[ *cb + 3*256 ]; 8239682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall cr += 4; cb += 4; 8249682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall 8259682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall L = *lum; lum += 2; 8269682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall value = (rgb_2_pix[ L + cr_r ] | 8279682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall rgb_2_pix[ L + crb_g ] | 8289682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall rgb_2_pix[ L + cb_b ]); 8299682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall row[0+0] = row[3+0] = row[next_row+0] = row[next_row+3+0] = 8309682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall (value ) & 0xFF; 8319682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall row[0+1] = row[3+1] = row[next_row+1] = row[next_row+3+1] = 8329682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall (value >> 8) & 0xFF; 8339682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall row[0+2] = row[3+2] = row[next_row+2] = row[next_row+3+2] = 8349682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall (value >> 16) & 0xFF; 8359682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall row += 2*3; 8369682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall 8379682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall L = *lum; lum += 2; 8389682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall value = (rgb_2_pix[ L + cr_r ] | 8399682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall rgb_2_pix[ L + crb_g ] | 8409682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall rgb_2_pix[ L + cb_b ]); 8419682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall row[0+0] = row[3+0] = row[next_row+0] = row[next_row+3+0] = 8429682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall (value ) & 0xFF; 8439682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall row[0+1] = row[3+1] = row[next_row+1] = row[next_row+3+1] = 8449682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall (value >> 8) & 0xFF; 8459682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall row[0+2] = row[3+2] = row[next_row+2] = row[next_row+3+2] = 8469682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall (value >> 16) & 0xFF; 8479682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall row += 2*3; 8489682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall 8499682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall } 8509682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall row += next_row; 8519682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall } 8529682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall} 8539682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall 8549682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hallstatic void Color32DitherYUY2Mod2X( int *colortab, Uint32 *rgb_2_pix, 8559682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall unsigned char *lum, unsigned char *cr, 8569682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall unsigned char *cb, unsigned char *out, 8579682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall int rows, int cols, int mod ) 8589682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall{ 8599682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall unsigned int* row = (unsigned int*) out; 8609682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall const int next_row = cols*2+mod; 8619682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall int x, y; 8629682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall int cr_r; 8639682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall int crb_g; 8649682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall int cb_b; 8659682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall int cols_2 = cols / 2; 8669682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall mod+=mod; 8679682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall y = rows; 8689682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall while( y-- ) 8699682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall { 8709682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall x = cols_2; 8719682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall while( x-- ) 8729682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall { 8739682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall register int L; 8749682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall 8759682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall cr_r = 0*768+256 + colortab[ *cr + 0*256 ]; 8769682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall crb_g = 1*768+256 + colortab[ *cr + 1*256 ] 8779682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall + colortab[ *cb + 2*256 ]; 8789682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall cb_b = 2*768+256 + colortab[ *cb + 3*256 ]; 8799682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall cr += 4; cb += 4; 8809682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall 8819682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall L = *lum; lum += 2; 8829682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall row[0] = row[1] = row[next_row] = row[next_row+1] = 8839682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall (rgb_2_pix[ L + cr_r ] | 8849682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall rgb_2_pix[ L + crb_g ] | 8859682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall rgb_2_pix[ L + cb_b ]); 8869682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall row += 2; 8879682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall 8889682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall L = *lum; lum += 2; 8899682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall row[0] = row[1] = row[next_row] = row[next_row+1] = 8909682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall (rgb_2_pix[ L + cr_r ] | 8919682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall rgb_2_pix[ L + crb_g ] | 8929682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall rgb_2_pix[ L + cb_b ]); 8939682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall row += 2; 8949682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall 8959682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall 8969682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall } 8979682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall 8989682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall row += next_row; 8999682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall } 9009682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall} 9019682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall 9029682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall/* 9039682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall * How many 1 bits are there in the Uint32. 9049682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall * Low performance, do not call often. 9059682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall */ 9069682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hallstatic int number_of_bits_set( Uint32 a ) 9079682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall{ 9089682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall if(!a) return 0; 9099682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall if(a & 1) return 1 + number_of_bits_set(a >> 1); 9109682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall return(number_of_bits_set(a >> 1)); 9119682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall} 9129682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall 9139682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall/* 9149682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall * How many 0 bits are there at least significant end of Uint32. 9159682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall * Low performance, do not call often. 9169682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall */ 9179682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hallstatic int free_bits_at_bottom( Uint32 a ) 9189682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall{ 9199682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall /* assume char is 8 bits */ 9209682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall if(!a) return sizeof(Uint32) * 8; 9219682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall if(((Sint32)a) & 1l) return 0; 9229682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall return 1 + free_bits_at_bottom ( a >> 1); 9239682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall} 9249682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall 9259682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall 9269682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse HallSDL_Overlay *SDL_CreateYUV_SW(_THIS, int width, int height, Uint32 format, SDL_Surface *display) 9279682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall{ 9289682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall SDL_Overlay *overlay; 9299682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall struct private_yuvhwdata *swdata; 9309682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall int *Cr_r_tab; 9319682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall int *Cr_g_tab; 9329682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall int *Cb_g_tab; 9339682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall int *Cb_b_tab; 9349682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall Uint32 *r_2_pix_alloc; 9359682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall Uint32 *g_2_pix_alloc; 9369682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall Uint32 *b_2_pix_alloc; 9379682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall int i; 9389682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall int CR, CB; 9399682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall Uint32 Rmask, Gmask, Bmask; 9409682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall 9419682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall /* Only RGB packed pixel conversion supported */ 9429682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall if ( (display->format->BytesPerPixel != 2) && 9439682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall (display->format->BytesPerPixel != 3) && 9449682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall (display->format->BytesPerPixel != 4) ) { 9459682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall SDL_SetError("Can't use YUV data on non 16/24/32 bit surfaces"); 9469682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall return(NULL); 9479682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall } 9489682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall 9499682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall /* Verify that we support the format */ 9509682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall switch (format) { 9519682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall case SDL_YV12_OVERLAY: 9529682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall case SDL_IYUV_OVERLAY: 9539682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall case SDL_YUY2_OVERLAY: 9549682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall case SDL_UYVY_OVERLAY: 9559682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall case SDL_YVYU_OVERLAY: 9569682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall break; 9579682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall default: 9589682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall SDL_SetError("Unsupported YUV format"); 9599682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall return(NULL); 9609682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall } 9619682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall 9629682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall /* Create the overlay structure */ 9639682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall overlay = (SDL_Overlay *)SDL_malloc(sizeof *overlay); 9649682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall if ( overlay == NULL ) { 9659682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall SDL_OutOfMemory(); 9669682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall return(NULL); 9679682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall } 9689682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall SDL_memset(overlay, 0, (sizeof *overlay)); 9699682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall 9709682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall /* Fill in the basic members */ 9719682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall overlay->format = format; 9729682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall overlay->w = width; 9739682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall overlay->h = height; 9749682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall 9759682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall /* Set up the YUV surface function structure */ 9769682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall overlay->hwfuncs = &sw_yuvfuncs; 9779682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall 9789682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall /* Create the pixel data and lookup tables */ 9799682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall swdata = (struct private_yuvhwdata *)SDL_malloc(sizeof *swdata); 9809682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall overlay->hwdata = swdata; 9819682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall if ( swdata == NULL ) { 9829682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall SDL_OutOfMemory(); 9839682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall SDL_FreeYUVOverlay(overlay); 9849682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall return(NULL); 9859682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall } 9869682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall swdata->stretch = NULL; 9879682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall swdata->display = display; 9889682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall swdata->pixels = (Uint8 *) SDL_malloc(width*height*2); 9899682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall swdata->colortab = (int *)SDL_malloc(4*256*sizeof(int)); 9909682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall Cr_r_tab = &swdata->colortab[0*256]; 9919682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall Cr_g_tab = &swdata->colortab[1*256]; 9929682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall Cb_g_tab = &swdata->colortab[2*256]; 9939682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall Cb_b_tab = &swdata->colortab[3*256]; 9949682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall swdata->rgb_2_pix = (Uint32 *)SDL_malloc(3*768*sizeof(Uint32)); 9959682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall r_2_pix_alloc = &swdata->rgb_2_pix[0*768]; 9969682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall g_2_pix_alloc = &swdata->rgb_2_pix[1*768]; 9979682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall b_2_pix_alloc = &swdata->rgb_2_pix[2*768]; 9989682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall if ( ! swdata->pixels || ! swdata->colortab || ! swdata->rgb_2_pix ) { 9999682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall SDL_OutOfMemory(); 10009682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall SDL_FreeYUVOverlay(overlay); 10019682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall return(NULL); 10029682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall } 10039682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall 10049682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall /* Generate the tables for the display surface */ 10059682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall for (i=0; i<256; i++) { 10069682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall /* Gamma correction (luminescence table) and chroma correction 10079682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall would be done here. See the Berkeley mpeg_play sources. 10089682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall */ 10099682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall CB = CR = (i-128); 10109682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall Cr_r_tab[i] = (int) ( (0.419/0.299) * CR); 10119682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall Cr_g_tab[i] = (int) (-(0.299/0.419) * CR); 10129682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall Cb_g_tab[i] = (int) (-(0.114/0.331) * CB); 10139682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall Cb_b_tab[i] = (int) ( (0.587/0.331) * CB); 10149682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall } 10159682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall 10169682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall /* 10179682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall * Set up entries 0-255 in rgb-to-pixel value tables. 10189682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall */ 10199682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall Rmask = display->format->Rmask; 10209682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall Gmask = display->format->Gmask; 10219682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall Bmask = display->format->Bmask; 10229682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall for ( i=0; i<256; ++i ) { 10239682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall r_2_pix_alloc[i+256] = i >> (8 - number_of_bits_set(Rmask)); 10249682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall r_2_pix_alloc[i+256] <<= free_bits_at_bottom(Rmask); 10259682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall g_2_pix_alloc[i+256] = i >> (8 - number_of_bits_set(Gmask)); 10269682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall g_2_pix_alloc[i+256] <<= free_bits_at_bottom(Gmask); 10279682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall b_2_pix_alloc[i+256] = i >> (8 - number_of_bits_set(Bmask)); 10289682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall b_2_pix_alloc[i+256] <<= free_bits_at_bottom(Bmask); 10299682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall } 10309682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall 10319682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall /* 10329682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall * If we have 16-bit output depth, then we double the value 10339682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall * in the top word. This means that we can write out both 10349682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall * pixels in the pixel doubling mode with one op. It is 10359682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall * harmless in the normal case as storing a 32-bit value 10369682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall * through a short pointer will lose the top bits anyway. 10379682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall */ 10389682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall if( display->format->BytesPerPixel == 2 ) { 10399682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall for ( i=0; i<256; ++i ) { 10409682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall r_2_pix_alloc[i+256] |= (r_2_pix_alloc[i+256]) << 16; 10419682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall g_2_pix_alloc[i+256] |= (g_2_pix_alloc[i+256]) << 16; 10429682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall b_2_pix_alloc[i+256] |= (b_2_pix_alloc[i+256]) << 16; 10439682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall } 10449682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall } 10459682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall 10469682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall /* 10479682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall * Spread out the values we have to the rest of the array so that 10489682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall * we do not need to check for overflow. 10499682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall */ 10509682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall for ( i=0; i<256; ++i ) { 10519682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall r_2_pix_alloc[i] = r_2_pix_alloc[256]; 10529682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall r_2_pix_alloc[i+512] = r_2_pix_alloc[511]; 10539682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall g_2_pix_alloc[i] = g_2_pix_alloc[256]; 10549682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall g_2_pix_alloc[i+512] = g_2_pix_alloc[511]; 10559682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall b_2_pix_alloc[i] = b_2_pix_alloc[256]; 10569682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall b_2_pix_alloc[i+512] = b_2_pix_alloc[511]; 10579682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall } 10589682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall 10599682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall /* You have chosen wisely... */ 10609682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall switch (format) { 10619682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall case SDL_YV12_OVERLAY: 10629682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall case SDL_IYUV_OVERLAY: 10639682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall if ( display->format->BytesPerPixel == 2 ) { 10649682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall#if (__GNUC__ > 2) && defined(__i386__) && __OPTIMIZE__ && SDL_ASSEMBLY_ROUTINES 10659682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall /* inline assembly functions */ 10669682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall if ( SDL_HasMMX() && (Rmask == 0xF800) && 10679682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall (Gmask == 0x07E0) && 10689682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall (Bmask == 0x001F) && 10699682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall (width & 15) == 0) { 10709682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall/*printf("Using MMX 16-bit 565 dither\n");*/ 10719682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall swdata->Display1X = Color565DitherYV12MMX1X; 10729682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall } else { 10739682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall/*printf("Using C 16-bit dither\n");*/ 10749682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall swdata->Display1X = Color16DitherYV12Mod1X; 10759682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall } 10769682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall#else 10779682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall swdata->Display1X = Color16DitherYV12Mod1X; 10789682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall#endif 10799682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall swdata->Display2X = Color16DitherYV12Mod2X; 10809682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall } 10819682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall if ( display->format->BytesPerPixel == 3 ) { 10829682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall swdata->Display1X = Color24DitherYV12Mod1X; 10839682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall swdata->Display2X = Color24DitherYV12Mod2X; 10849682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall } 10859682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall if ( display->format->BytesPerPixel == 4 ) { 10869682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall#if (__GNUC__ > 2) && defined(__i386__) && __OPTIMIZE__ && SDL_ASSEMBLY_ROUTINES 10879682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall /* inline assembly functions */ 10889682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall if ( SDL_HasMMX() && (Rmask == 0x00FF0000) && 10899682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall (Gmask == 0x0000FF00) && 10909682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall (Bmask == 0x000000FF) && 10919682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall (width & 15) == 0) { 10929682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall/*printf("Using MMX 32-bit dither\n");*/ 10939682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall swdata->Display1X = ColorRGBDitherYV12MMX1X; 10949682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall } else { 10959682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall/*printf("Using C 32-bit dither\n");*/ 10969682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall swdata->Display1X = Color32DitherYV12Mod1X; 10979682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall } 10989682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall#else 10999682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall swdata->Display1X = Color32DitherYV12Mod1X; 11009682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall#endif 11019682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall swdata->Display2X = Color32DitherYV12Mod2X; 11029682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall } 11039682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall break; 11049682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall case SDL_YUY2_OVERLAY: 11059682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall case SDL_UYVY_OVERLAY: 11069682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall case SDL_YVYU_OVERLAY: 11079682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall if ( display->format->BytesPerPixel == 2 ) { 11089682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall swdata->Display1X = Color16DitherYUY2Mod1X; 11099682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall swdata->Display2X = Color16DitherYUY2Mod2X; 11109682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall } 11119682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall if ( display->format->BytesPerPixel == 3 ) { 11129682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall swdata->Display1X = Color24DitherYUY2Mod1X; 11139682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall swdata->Display2X = Color24DitherYUY2Mod2X; 11149682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall } 11159682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall if ( display->format->BytesPerPixel == 4 ) { 11169682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall swdata->Display1X = Color32DitherYUY2Mod1X; 11179682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall swdata->Display2X = Color32DitherYUY2Mod2X; 11189682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall } 11199682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall break; 11209682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall default: 11219682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall /* We should never get here (caught above) */ 11229682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall break; 11239682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall } 11249682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall 11259682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall /* Find the pitch and offset values for the overlay */ 11269682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall overlay->pitches = swdata->pitches; 11279682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall overlay->pixels = swdata->planes; 11289682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall switch (format) { 11299682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall case SDL_YV12_OVERLAY: 11309682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall case SDL_IYUV_OVERLAY: 11319682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall overlay->pitches[0] = overlay->w; 11329682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall overlay->pitches[1] = overlay->pitches[0] / 2; 11339682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall overlay->pitches[2] = overlay->pitches[0] / 2; 11349682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall overlay->pixels[0] = swdata->pixels; 11359682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall overlay->pixels[1] = overlay->pixels[0] + 11369682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall overlay->pitches[0] * overlay->h; 11379682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall overlay->pixels[2] = overlay->pixels[1] + 11389682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall overlay->pitches[1] * overlay->h / 2; 11399682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall overlay->planes = 3; 11409682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall break; 11419682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall case SDL_YUY2_OVERLAY: 11429682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall case SDL_UYVY_OVERLAY: 11439682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall case SDL_YVYU_OVERLAY: 11449682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall overlay->pitches[0] = overlay->w*2; 11459682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall overlay->pixels[0] = swdata->pixels; 11469682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall overlay->planes = 1; 11479682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall break; 11489682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall default: 11499682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall /* We should never get here (caught above) */ 11509682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall break; 11519682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall } 11529682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall 11539682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall /* We're all done.. */ 11549682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall return(overlay); 11559682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall} 11569682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall 11579682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hallint SDL_LockYUV_SW(_THIS, SDL_Overlay *overlay) 11589682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall{ 11599682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall return(0); 11609682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall} 11619682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall 11629682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hallvoid SDL_UnlockYUV_SW(_THIS, SDL_Overlay *overlay) 11639682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall{ 11649682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall return; 11659682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall} 11669682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall 11679682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hallint SDL_DisplayYUV_SW(_THIS, SDL_Overlay *overlay, SDL_Rect *src, SDL_Rect *dst) 11689682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall{ 11699682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall struct private_yuvhwdata *swdata; 11709682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall int stretch; 11719682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall int scale_2x; 11729682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall SDL_Surface *display; 11739682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall Uint8 *lum, *Cr, *Cb; 11749682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall Uint8 *dstp; 11759682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall int mod; 11769682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall 11779682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall swdata = overlay->hwdata; 11789682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall stretch = 0; 11799682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall scale_2x = 0; 11809682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall if ( src->x || src->y || src->w < overlay->w || src->h < overlay->h ) { 11819682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall /* The source rectangle has been clipped. 11829682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall Using a scratch surface is easier than adding clipped 11839682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall source support to all the blitters, plus that would 11849682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall slow them down in the general unclipped case. 11859682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall */ 11869682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall stretch = 1; 11879682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall } else if ( (src->w != dst->w) || (src->h != dst->h) ) { 11889682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall if ( (dst->w == 2*src->w) && 11899682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall (dst->h == 2*src->h) ) { 11909682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall scale_2x = 1; 11919682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall } else { 11929682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall stretch = 1; 11939682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall } 11949682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall } 11959682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall if ( stretch ) { 11969682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall if ( ! swdata->stretch ) { 11979682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall display = swdata->display; 11989682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall swdata->stretch = SDL_CreateRGBSurface( 11999682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall SDL_SWSURFACE, 12009682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall overlay->w, overlay->h, 12019682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall display->format->BitsPerPixel, 12029682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall display->format->Rmask, 12039682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall display->format->Gmask, 12049682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall display->format->Bmask, 0); 12059682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall if ( ! swdata->stretch ) { 12069682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall return(-1); 12079682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall } 12089682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall } 12099682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall display = swdata->stretch; 12109682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall } else { 12119682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall display = swdata->display; 12129682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall } 12139682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall switch (overlay->format) { 12149682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall case SDL_YV12_OVERLAY: 12159682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall lum = overlay->pixels[0]; 12169682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall Cr = overlay->pixels[1]; 12179682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall Cb = overlay->pixels[2]; 12189682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall break; 12199682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall case SDL_IYUV_OVERLAY: 12209682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall lum = overlay->pixels[0]; 12219682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall Cr = overlay->pixels[2]; 12229682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall Cb = overlay->pixels[1]; 12239682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall break; 12249682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall case SDL_YUY2_OVERLAY: 12259682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall lum = overlay->pixels[0]; 12269682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall Cr = lum + 3; 12279682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall Cb = lum + 1; 12289682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall break; 12299682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall case SDL_UYVY_OVERLAY: 12309682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall lum = overlay->pixels[0]+1; 12319682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall Cr = lum + 1; 12329682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall Cb = lum - 1; 12339682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall break; 12349682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall case SDL_YVYU_OVERLAY: 12359682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall lum = overlay->pixels[0]; 12369682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall Cr = lum + 1; 12379682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall Cb = lum + 3; 12389682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall break; 12399682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall default: 12409682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall SDL_SetError("Unsupported YUV format in blit"); 12419682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall return(-1); 12429682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall } 12439682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall if ( SDL_MUSTLOCK(display) ) { 12449682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall if ( SDL_LockSurface(display) < 0 ) { 12459682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall return(-1); 12469682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall } 12479682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall } 12489682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall if ( stretch ) { 12499682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall dstp = (Uint8 *)swdata->stretch->pixels; 12509682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall } else { 12519682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall dstp = (Uint8 *)display->pixels 12529682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall + dst->x * display->format->BytesPerPixel 12539682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall + dst->y * display->pitch; 12549682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall } 12559682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall mod = (display->pitch / display->format->BytesPerPixel); 12569682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall 12579682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall if ( scale_2x ) { 12589682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall mod -= (overlay->w * 2); 12599682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall swdata->Display2X(swdata->colortab, swdata->rgb_2_pix, 12609682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall lum, Cr, Cb, dstp, overlay->h, overlay->w, mod); 12619682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall } else { 12629682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall mod -= overlay->w; 12639682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall swdata->Display1X(swdata->colortab, swdata->rgb_2_pix, 12649682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall lum, Cr, Cb, dstp, overlay->h, overlay->w, mod); 12659682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall } 12669682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall if ( SDL_MUSTLOCK(display) ) { 12679682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall SDL_UnlockSurface(display); 12689682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall } 12699682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall if ( stretch ) { 12709682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall display = swdata->display; 12719682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall SDL_SoftStretch(swdata->stretch, src, display, dst); 12729682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall } 12739682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall SDL_UpdateRects(display, 1, dst); 12749682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall 12759682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall return(0); 12769682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall} 12779682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall 12789682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hallvoid SDL_FreeYUV_SW(_THIS, SDL_Overlay *overlay) 12799682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall{ 12809682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall struct private_yuvhwdata *swdata; 12819682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall 12829682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall swdata = overlay->hwdata; 12839682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall if ( swdata ) { 12849682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall if ( swdata->stretch ) { 12859682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall SDL_FreeSurface(swdata->stretch); 12869682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall } 12879682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall if ( swdata->pixels ) { 12889682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall SDL_free(swdata->pixels); 12899682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall } 12909682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall if ( swdata->colortab ) { 12919682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall SDL_free(swdata->colortab); 12929682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall } 12939682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall if ( swdata->rgb_2_pix ) { 12949682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall SDL_free(swdata->rgb_2_pix); 12959682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall } 12969682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall SDL_free(swdata); 12979682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall overlay->hwdata = NULL; 12989682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall } 12999682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall} 1300