src/video/SDL_yuv_sw.c
author Sam Lantinga <slouken@lokigames.com>
Thu, 26 Apr 2001 16:45:43 +0000
changeset 0 74212992fb08
child 9 a1c15fa4abb9
permissions -rw-r--r--
Initial revision
slouken@0
     1
/*
slouken@0
     2
    SDL - Simple DirectMedia Layer
slouken@0
     3
    Copyright (C) 1997, 1998, 1999, 2000, 2001  Sam Lantinga
slouken@0
     4
slouken@0
     5
    This library is free software; you can redistribute it and/or
slouken@0
     6
    modify it under the terms of the GNU Library General Public
slouken@0
     7
    License as published by the Free Software Foundation; either
slouken@0
     8
    version 2 of the License, or (at your option) any later version.
slouken@0
     9
slouken@0
    10
    This library is distributed in the hope that it will be useful,
slouken@0
    11
    but WITHOUT ANY WARRANTY; without even the implied warranty of
slouken@0
    12
    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
slouken@0
    13
    Library General Public License for more details.
slouken@0
    14
slouken@0
    15
    You should have received a copy of the GNU Library General Public
slouken@0
    16
    License along with this library; if not, write to the Free
slouken@0
    17
    Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
slouken@0
    18
slouken@0
    19
    Sam Lantinga
slouken@0
    20
    slouken@devolution.com
slouken@0
    21
*/
slouken@0
    22
slouken@0
    23
#ifdef SAVE_RCSID
slouken@0
    24
static char rcsid =
slouken@0
    25
 "@(#) $Id$";
slouken@0
    26
#endif
slouken@0
    27
slouken@0
    28
/* This is the software implementation of the YUV video overlay support */
slouken@0
    29
slouken@0
    30
/* This code was derived from code carrying the following copyright notices:
slouken@0
    31
slouken@0
    32
 * Copyright (c) 1995 The Regents of the University of California.
slouken@0
    33
 * All rights reserved.
slouken@0
    34
 * 
slouken@0
    35
 * Permission to use, copy, modify, and distribute this software and its
slouken@0
    36
 * documentation for any purpose, without fee, and without written agreement is
slouken@0
    37
 * hereby granted, provided that the above copyright notice and the following
slouken@0
    38
 * two paragraphs appear in all copies of this software.
slouken@0
    39
 * 
slouken@0
    40
 * IN NO EVENT SHALL THE UNIVERSITY OF CALIFORNIA BE LIABLE TO ANY PARTY FOR
slouken@0
    41
 * DIRECT, INDIRECT, SPECIAL, INCIDENTAL, OR CONSEQUENTIAL DAMAGES ARISING OUT
slouken@0
    42
 * OF THE USE OF THIS SOFTWARE AND ITS DOCUMENTATION, EVEN IF THE UNIVERSITY OF
slouken@0
    43
 * CALIFORNIA HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
slouken@0
    44
 * 
slouken@0
    45
 * THE UNIVERSITY OF CALIFORNIA SPECIFICALLY DISCLAIMS ANY WARRANTIES,
slouken@0
    46
 * INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY
slouken@0
    47
 * AND FITNESS FOR A PARTICULAR PURPOSE.  THE SOFTWARE PROVIDED HEREUNDER IS
slouken@0
    48
 * ON AN "AS IS" BASIS, AND THE UNIVERSITY OF CALIFORNIA HAS NO OBLIGATION TO
slouken@0
    49
 * PROVIDE MAINTENANCE, SUPPORT, UPDATES, ENHANCEMENTS, OR MODIFICATIONS.
slouken@0
    50
slouken@0
    51
 * Copyright (c) 1995 Erik Corry
slouken@0
    52
 * All rights reserved.
slouken@0
    53
 * 
slouken@0
    54
 * Permission to use, copy, modify, and distribute this software and its
slouken@0
    55
 * documentation for any purpose, without fee, and without written agreement is
slouken@0
    56
 * hereby granted, provided that the above copyright notice and the following
slouken@0
    57
 * two paragraphs appear in all copies of this software.
slouken@0
    58
 * 
slouken@0
    59
 * IN NO EVENT SHALL ERIK CORRY BE LIABLE TO ANY PARTY FOR DIRECT, INDIRECT,
slouken@0
    60
 * SPECIAL, INCIDENTAL, OR CONSEQUENTIAL DAMAGES ARISING OUT OF THE USE OF
slouken@0
    61
 * THIS SOFTWARE AND ITS DOCUMENTATION, EVEN IF ERIK CORRY HAS BEEN ADVISED
slouken@0
    62
 * OF THE POSSIBILITY OF SUCH DAMAGE.
slouken@0
    63
 * 
slouken@0
    64
 * ERIK CORRY SPECIFICALLY DISCLAIMS ANY WARRANTIES, INCLUDING, BUT NOT
slouken@0
    65
 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A
slouken@0
    66
 * PARTICULAR PURPOSE.  THE SOFTWARE PROVIDED HEREUNDER IS ON AN "AS IS"
slouken@0
    67
 * BASIS, AND ERIK CORRY HAS NO OBLIGATION TO PROVIDE MAINTENANCE, SUPPORT,
slouken@0
    68
 * UPDATES, ENHANCEMENTS, OR MODIFICATIONS.
slouken@0
    69
slouken@0
    70
 * Portions of this software Copyright (c) 1995 Brown University.
slouken@0
    71
 * All rights reserved.
slouken@0
    72
 * 
slouken@0
    73
 * Permission to use, copy, modify, and distribute this software and its
slouken@0
    74
 * documentation for any purpose, without fee, and without written agreement
slouken@0
    75
 * is hereby granted, provided that the above copyright notice and the
slouken@0
    76
 * following two paragraphs appear in all copies of this software.
slouken@0
    77
 * 
slouken@0
    78
 * IN NO EVENT SHALL BROWN UNIVERSITY BE LIABLE TO ANY PARTY FOR
slouken@0
    79
 * DIRECT, INDIRECT, SPECIAL, INCIDENTAL, OR CONSEQUENTIAL DAMAGES ARISING OUT
slouken@0
    80
 * OF THE USE OF THIS SOFTWARE AND ITS DOCUMENTATION, EVEN IF BROWN
slouken@0
    81
 * UNIVERSITY HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
slouken@0
    82
 * 
slouken@0
    83
 * BROWN UNIVERSITY SPECIFICALLY DISCLAIMS ANY WARRANTIES, INCLUDING, BUT NOT
slouken@0
    84
 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A
slouken@0
    85
 * PARTICULAR PURPOSE.  THE SOFTWARE PROVIDED HEREUNDER IS ON AN "AS IS"
slouken@0
    86
 * BASIS, AND BROWN UNIVERSITY HAS NO OBLIGATION TO PROVIDE MAINTENANCE,
slouken@0
    87
 * SUPPORT, UPDATES, ENHANCEMENTS, OR MODIFICATIONS.
slouken@0
    88
 */
slouken@0
    89
slouken@0
    90
#include <stdlib.h>
slouken@0
    91
#include <string.h>
slouken@0
    92
slouken@0
    93
#include "SDL_error.h"
slouken@0
    94
#include "SDL_video.h"
slouken@0
    95
#include "SDL_stretch_c.h"
slouken@0
    96
#include "SDL_yuvfuncs.h"
slouken@0
    97
#include "SDL_yuv_sw_c.h"
slouken@0
    98
slouken@0
    99
/* Function to check the CPU flags */
slouken@0
   100
#define MMX_CPU		0x800000
slouken@0
   101
#ifdef USE_ASMBLIT
slouken@0
   102
#define CPU_Flags()	Hermes_X86_CPU()
slouken@0
   103
#else
slouken@0
   104
#define CPU_Flags()	0L
slouken@0
   105
#endif
slouken@0
   106
slouken@0
   107
#ifdef USE_ASMBLIT
slouken@0
   108
#define X86_ASSEMBLER
slouken@0
   109
#define HermesConverterInterface	void
slouken@0
   110
#define HermesClearInterface		void
slouken@0
   111
#define STACKCALL
slouken@0
   112
typedef Uint32 int32;
slouken@0
   113
slouken@0
   114
#include "HeadX86.h"
slouken@0
   115
#endif
slouken@0
   116
slouken@0
   117
/* The functions used to manipulate software video overlays */
slouken@0
   118
static struct private_yuvhwfuncs sw_yuvfuncs = {
slouken@0
   119
	SDL_LockYUV_SW,
slouken@0
   120
	SDL_UnlockYUV_SW,
slouken@0
   121
	SDL_DisplayYUV_SW,
slouken@0
   122
	SDL_FreeYUV_SW
slouken@0
   123
};
slouken@0
   124
slouken@0
   125
/* RGB conversion lookup tables */
slouken@0
   126
struct private_yuvhwdata {
slouken@0
   127
	SDL_Surface *stretch;
slouken@0
   128
	SDL_Surface *display;
slouken@0
   129
	Uint8 *pixels;
slouken@0
   130
	int *colortab;
slouken@0
   131
	Uint32 *rgb_2_pix;
slouken@0
   132
	void (*Display1X)(int *colortab, Uint32 *rgb_2_pix,
slouken@0
   133
                          unsigned char *lum, unsigned char *cr,
slouken@0
   134
                          unsigned char *cb, unsigned char *out,
slouken@0
   135
                          int rows, int cols, int mod );
slouken@0
   136
	void (*Display2X)(int *colortab, Uint32 *rgb_2_pix,
slouken@0
   137
	                  unsigned char *lum, unsigned char *cr,
slouken@0
   138
                          unsigned char *cb, unsigned char *out,
slouken@0
   139
                          int rows, int cols, int mod );
slouken@0
   140
slouken@0
   141
	/* These are just so we don't have to allocate them separately */
slouken@0
   142
	Uint16 pitches[3];
slouken@0
   143
	Uint8 *planes[3];
slouken@0
   144
};
slouken@0
   145
slouken@0
   146
slouken@0
   147
/* The colorspace conversion functions */
slouken@0
   148
slouken@0
   149
extern void Color565DitherYV12MMX1X( int *colortab, Uint32 *rgb_2_pix,
slouken@0
   150
                                     unsigned char *lum, unsigned char *cr,
slouken@0
   151
                                     unsigned char *cb, unsigned char *out,
slouken@0
   152
                                     int rows, int cols, int mod );
slouken@0
   153
extern void ColorRGBDitherYV12MMX1X( int *colortab, Uint32 *rgb_2_pix,
slouken@0
   154
                                     unsigned char *lum, unsigned char *cr,
slouken@0
   155
                                     unsigned char *cb, unsigned char *out,
slouken@0
   156
                                     int rows, int cols, int mod );
slouken@0
   157
slouken@0
   158
static void Color16DitherYV12Mod1X( int *colortab, Uint32 *rgb_2_pix,
slouken@0
   159
                                    unsigned char *lum, unsigned char *cr,
slouken@0
   160
                                    unsigned char *cb, unsigned char *out,
slouken@0
   161
                                    int rows, int cols, int mod )
slouken@0
   162
{
slouken@0
   163
    unsigned short* row1;
slouken@0
   164
    unsigned short* row2;
slouken@0
   165
    unsigned char* lum2;
slouken@0
   166
    int x, y;
slouken@0
   167
    int cr_r;
slouken@0
   168
    int crb_g;
slouken@0
   169
    int cb_b;
slouken@0
   170
    int cols_2 = cols / 2;
slouken@0
   171
slouken@0
   172
    row1 = (unsigned short*) out;
slouken@0
   173
    row2 = row1 + cols + mod;
slouken@0
   174
    lum2 = lum + cols;
slouken@0
   175
slouken@0
   176
    mod += cols + mod;
slouken@0
   177
slouken@0
   178
    y = rows / 2;
slouken@0
   179
    while( y-- )
slouken@0
   180
    {
slouken@0
   181
        x = cols_2;
slouken@0
   182
        while( x-- )
slouken@0
   183
        {
slouken@0
   184
            register int L;
slouken@0
   185
slouken@0
   186
            cr_r   = 0*768+256 + colortab[ *cr + 0*256 ];
slouken@0
   187
            crb_g  = 1*768+256 + colortab[ *cr + 1*256 ]
slouken@0
   188
                               + colortab[ *cb + 2*256 ];
slouken@0
   189
            cb_b   = 2*768+256 + colortab[ *cb + 3*256 ];
slouken@0
   190
            ++cr; ++cb;
slouken@0
   191
slouken@0
   192
            L = *lum++;
slouken@0
   193
            *row1++ = (rgb_2_pix[ L + cr_r ] |
slouken@0
   194
                       rgb_2_pix[ L + crb_g ] |
slouken@0
   195
                       rgb_2_pix[ L + cb_b ]);
slouken@0
   196
slouken@0
   197
            L = *lum++;
slouken@0
   198
            *row1++ = (rgb_2_pix[ L + cr_r ] |
slouken@0
   199
                       rgb_2_pix[ L + crb_g ] |
slouken@0
   200
                       rgb_2_pix[ L + cb_b ]);
slouken@0
   201
slouken@0
   202
slouken@0
   203
            /* Now, do second row.  */
slouken@0
   204
slouken@0
   205
            L = *lum2++;
slouken@0
   206
            *row2++ = (rgb_2_pix[ L + cr_r ] |
slouken@0
   207
                       rgb_2_pix[ L + crb_g ] |
slouken@0
   208
                       rgb_2_pix[ L + cb_b ]);
slouken@0
   209
slouken@0
   210
            L = *lum2++;
slouken@0
   211
            *row2++ = (rgb_2_pix[ L + cr_r ] |
slouken@0
   212
                       rgb_2_pix[ L + crb_g ] |
slouken@0
   213
                       rgb_2_pix[ L + cb_b ]);
slouken@0
   214
        }
slouken@0
   215
slouken@0
   216
        /*
slouken@0
   217
         * These values are at the start of the next line, (due
slouken@0
   218
         * to the ++'s above),but they need to be at the start
slouken@0
   219
         * of the line after that.
slouken@0
   220
         */
slouken@0
   221
        lum  += cols;
slouken@0
   222
        lum2 += cols;
slouken@0
   223
        row1 += mod;
slouken@0
   224
        row2 += mod;
slouken@0
   225
    }
slouken@0
   226
}
slouken@0
   227
slouken@0
   228
static void Color24DitherYV12Mod1X( int *colortab, Uint32 *rgb_2_pix,
slouken@0
   229
                                    unsigned char *lum, unsigned char *cr,
slouken@0
   230
                                    unsigned char *cb, unsigned char *out,
slouken@0
   231
                                    int rows, int cols, int mod )
slouken@0
   232
{
slouken@0
   233
    unsigned int value;
slouken@0
   234
    unsigned char* row1;
slouken@0
   235
    unsigned char* row2;
slouken@0
   236
    unsigned char* lum2;
slouken@0
   237
    int x, y;
slouken@0
   238
    int cr_r;
slouken@0
   239
    int crb_g;
slouken@0
   240
    int cb_b;
slouken@0
   241
    int cols_2 = cols / 2;
slouken@0
   242
slouken@0
   243
    row1 = out;
slouken@0
   244
    row2 = row1 + cols*3 + mod*3;
slouken@0
   245
    lum2 = lum + cols;
slouken@0
   246
slouken@0
   247
    mod += cols + mod;
slouken@0
   248
    mod *= 3;
slouken@0
   249
slouken@0
   250
    y = rows / 2;
slouken@0
   251
    while( y-- )
slouken@0
   252
    {
slouken@0
   253
        x = cols_2;
slouken@0
   254
        while( x-- )
slouken@0
   255
        {
slouken@0
   256
            register int L;
slouken@0
   257
slouken@0
   258
            cr_r   = 0*768+256 + colortab[ *cr + 0*256 ];
slouken@0
   259
            crb_g  = 1*768+256 + colortab[ *cr + 1*256 ]
slouken@0
   260
                               + colortab[ *cb + 2*256 ];
slouken@0
   261
            cb_b   = 2*768+256 + colortab[ *cb + 3*256 ];
slouken@0
   262
            ++cr; ++cb;
slouken@0
   263
slouken@0
   264
            L = *lum++;
slouken@0
   265
            value = (rgb_2_pix[ L + cr_r ] |
slouken@0
   266
                     rgb_2_pix[ L + crb_g ] |
slouken@0
   267
                     rgb_2_pix[ L + cb_b ]);
slouken@0
   268
            *row1++ = (value      ) & 0xFF;
slouken@0
   269
            *row1++ = (value >>  8) & 0xFF;
slouken@0
   270
            *row1++ = (value >> 16) & 0xFF;
slouken@0
   271
slouken@0
   272
            L = *lum++;
slouken@0
   273
            value = (rgb_2_pix[ L + cr_r ] |
slouken@0
   274
                     rgb_2_pix[ L + crb_g ] |
slouken@0
   275
                     rgb_2_pix[ L + cb_b ]);
slouken@0
   276
            *row1++ = (value      ) & 0xFF;
slouken@0
   277
            *row1++ = (value >>  8) & 0xFF;
slouken@0
   278
            *row1++ = (value >> 16) & 0xFF;
slouken@0
   279
slouken@0
   280
slouken@0
   281
            /* Now, do second row.  */
slouken@0
   282
slouken@0
   283
            L = *lum2++;
slouken@0
   284
            value = (rgb_2_pix[ L + cr_r ] |
slouken@0
   285
                     rgb_2_pix[ L + crb_g ] |
slouken@0
   286
                     rgb_2_pix[ L + cb_b ]);
slouken@0
   287
            *row2++ = (value      ) & 0xFF;
slouken@0
   288
            *row2++ = (value >>  8) & 0xFF;
slouken@0
   289
            *row2++ = (value >> 16) & 0xFF;
slouken@0
   290
slouken@0
   291
            L = *lum2++;
slouken@0
   292
            value = (rgb_2_pix[ L + cr_r ] |
slouken@0
   293
                     rgb_2_pix[ L + crb_g ] |
slouken@0
   294
                     rgb_2_pix[ L + cb_b ]);
slouken@0
   295
            *row2++ = (value      ) & 0xFF;
slouken@0
   296
            *row2++ = (value >>  8) & 0xFF;
slouken@0
   297
            *row2++ = (value >> 16) & 0xFF;
slouken@0
   298
        }
slouken@0
   299
slouken@0
   300
        /*
slouken@0
   301
         * These values are at the start of the next line, (due
slouken@0
   302
         * to the ++'s above),but they need to be at the start
slouken@0
   303
         * of the line after that.
slouken@0
   304
         */
slouken@0
   305
        lum  += cols;
slouken@0
   306
        lum2 += cols;
slouken@0
   307
        row1 += mod;
slouken@0
   308
        row2 += mod;
slouken@0
   309
    }
slouken@0
   310
}
slouken@0
   311
slouken@0
   312
static void Color32DitherYV12Mod1X( int *colortab, Uint32 *rgb_2_pix,
slouken@0
   313
                                    unsigned char *lum, unsigned char *cr,
slouken@0
   314
                                    unsigned char *cb, unsigned char *out,
slouken@0
   315
                                    int rows, int cols, int mod )
slouken@0
   316
{
slouken@0
   317
    unsigned int* row1;
slouken@0
   318
    unsigned int* row2;
slouken@0
   319
    unsigned char* lum2;
slouken@0
   320
    int x, y;
slouken@0
   321
    int cr_r;
slouken@0
   322
    int crb_g;
slouken@0
   323
    int cb_b;
slouken@0
   324
    int cols_2 = cols / 2;
slouken@0
   325
slouken@0
   326
    row1 = (unsigned int*) out;
slouken@0
   327
    row2 = row1 + cols + mod;
slouken@0
   328
    lum2 = lum + cols;
slouken@0
   329
slouken@0
   330
    mod += cols + mod;
slouken@0
   331
slouken@0
   332
    y = rows / 2;
slouken@0
   333
    while( y-- )
slouken@0
   334
    {
slouken@0
   335
        x = cols_2;
slouken@0
   336
        while( x-- )
slouken@0
   337
        {
slouken@0
   338
            register int L;
slouken@0
   339
slouken@0
   340
            cr_r   = 0*768+256 + colortab[ *cr + 0*256 ];
slouken@0
   341
            crb_g  = 1*768+256 + colortab[ *cr + 1*256 ]
slouken@0
   342
                               + colortab[ *cb + 2*256 ];
slouken@0
   343
            cb_b   = 2*768+256 + colortab[ *cb + 3*256 ];
slouken@0
   344
            ++cr; ++cb;
slouken@0
   345
slouken@0
   346
            L = *lum++;
slouken@0
   347
            *row1++ = (rgb_2_pix[ L + cr_r ] |
slouken@0
   348
                       rgb_2_pix[ L + crb_g ] |
slouken@0
   349
                       rgb_2_pix[ L + cb_b ]);
slouken@0
   350
slouken@0
   351
            L = *lum++;
slouken@0
   352
            *row1++ = (rgb_2_pix[ L + cr_r ] |
slouken@0
   353
                       rgb_2_pix[ L + crb_g ] |
slouken@0
   354
                       rgb_2_pix[ L + cb_b ]);
slouken@0
   355
slouken@0
   356
slouken@0
   357
            /* Now, do second row.  */
slouken@0
   358
slouken@0
   359
            L = *lum2++;
slouken@0
   360
            *row2++ = (rgb_2_pix[ L + cr_r ] |
slouken@0
   361
                       rgb_2_pix[ L + crb_g ] |
slouken@0
   362
                       rgb_2_pix[ L + cb_b ]);
slouken@0
   363
slouken@0
   364
            L = *lum2++;
slouken@0
   365
            *row2++ = (rgb_2_pix[ L + cr_r ] |
slouken@0
   366
                       rgb_2_pix[ L + crb_g ] |
slouken@0
   367
                       rgb_2_pix[ L + cb_b ]);
slouken@0
   368
        }
slouken@0
   369
slouken@0
   370
        /*
slouken@0
   371
         * These values are at the start of the next line, (due
slouken@0
   372
         * to the ++'s above),but they need to be at the start
slouken@0
   373
         * of the line after that.
slouken@0
   374
         */
slouken@0
   375
        lum  += cols;
slouken@0
   376
        lum2 += cols;
slouken@0
   377
        row1 += mod;
slouken@0
   378
        row2 += mod;
slouken@0
   379
    }
slouken@0
   380
}
slouken@0
   381
slouken@0
   382
/*
slouken@0
   383
 * In this function I make use of a nasty trick. The tables have the lower
slouken@0
   384
 * 16 bits replicated in the upper 16. This means I can write ints and get
slouken@0
   385
 * the horisontal doubling for free (almost).
slouken@0
   386
 */
slouken@0
   387
static void Color16DitherYV12Mod2X( int *colortab, Uint32 *rgb_2_pix,
slouken@0
   388
                                    unsigned char *lum, unsigned char *cr,
slouken@0
   389
                                    unsigned char *cb, unsigned char *out,
slouken@0
   390
                                    int rows, int cols, int mod )
slouken@0
   391
{
slouken@0
   392
    unsigned int* row1 = (unsigned int*) out;
slouken@0
   393
    const int next_row = cols+(mod/2);
slouken@0
   394
    unsigned int* row2 = row1 + 2*next_row;
slouken@0
   395
    unsigned char* lum2;
slouken@0
   396
    int x, y;
slouken@0
   397
    int cr_r;
slouken@0
   398
    int crb_g;
slouken@0
   399
    int cb_b;
slouken@0
   400
    int cols_2 = cols / 2;
slouken@0
   401
slouken@0
   402
    lum2 = lum + cols;
slouken@0
   403
slouken@0
   404
    mod = (next_row * 3) + (mod/2);
slouken@0
   405
slouken@0
   406
    y = rows / 2;
slouken@0
   407
    while( y-- )
slouken@0
   408
    {
slouken@0
   409
        x = cols_2;
slouken@0
   410
        while( x-- )
slouken@0
   411
        {
slouken@0
   412
            register int L;
slouken@0
   413
slouken@0
   414
            cr_r   = 0*768+256 + colortab[ *cr + 0*256 ];
slouken@0
   415
            crb_g  = 1*768+256 + colortab[ *cr + 1*256 ]
slouken@0
   416
                               + colortab[ *cb + 2*256 ];
slouken@0
   417
            cb_b   = 2*768+256 + colortab[ *cb + 3*256 ];
slouken@0
   418
            ++cr; ++cb;
slouken@0
   419
slouken@0
   420
            L = *lum++;
slouken@0
   421
            row1[0] = row1[next_row] = (rgb_2_pix[ L + cr_r ] |
slouken@0
   422
                                        rgb_2_pix[ L + crb_g ] |
slouken@0
   423
                                        rgb_2_pix[ L + cb_b ]);
slouken@0
   424
            row1++;
slouken@0
   425
slouken@0
   426
            L = *lum++;
slouken@0
   427
            row1[0] = row1[next_row] = (rgb_2_pix[ L + cr_r ] |
slouken@0
   428
                                        rgb_2_pix[ L + crb_g ] |
slouken@0
   429
                                        rgb_2_pix[ L + cb_b ]);
slouken@0
   430
            row1++;
slouken@0
   431
slouken@0
   432
slouken@0
   433
            /* Now, do second row. */
slouken@0
   434
slouken@0
   435
            L = *lum2++;
slouken@0
   436
            row2[0] = row2[next_row] = (rgb_2_pix[ L + cr_r ] |
slouken@0
   437
                                        rgb_2_pix[ L + crb_g ] |
slouken@0
   438
                                        rgb_2_pix[ L + cb_b ]);
slouken@0
   439
            row2++;
slouken@0
   440
slouken@0
   441
            L = *lum2++;
slouken@0
   442
            row2[0] = row2[next_row] = (rgb_2_pix[ L + cr_r ] |
slouken@0
   443
                                        rgb_2_pix[ L + crb_g ] |
slouken@0
   444
                                        rgb_2_pix[ L + cb_b ]);
slouken@0
   445
            row2++;
slouken@0
   446
        }
slouken@0
   447
slouken@0
   448
        /*
slouken@0
   449
         * These values are at the start of the next line, (due
slouken@0
   450
         * to the ++'s above),but they need to be at the start
slouken@0
   451
         * of the line after that.
slouken@0
   452
         */
slouken@0
   453
        lum  += cols;
slouken@0
   454
        lum2 += cols;
slouken@0
   455
        row1 += mod;
slouken@0
   456
        row2 += mod;
slouken@0
   457
    }
slouken@0
   458
}
slouken@0
   459
slouken@0
   460
static void Color24DitherYV12Mod2X( int *colortab, Uint32 *rgb_2_pix,
slouken@0
   461
                                    unsigned char *lum, unsigned char *cr,
slouken@0
   462
                                    unsigned char *cb, unsigned char *out,
slouken@0
   463
                                    int rows, int cols, int mod )
slouken@0
   464
{
slouken@0
   465
    unsigned int value;
slouken@0
   466
    unsigned char* row1 = out;
slouken@0
   467
    const int next_row = (cols*2 + mod) * 3;
slouken@0
   468
    unsigned char* row2 = row1 + 2*next_row;
slouken@0
   469
    unsigned char* lum2;
slouken@0
   470
    int x, y;
slouken@0
   471
    int cr_r;
slouken@0
   472
    int crb_g;
slouken@0
   473
    int cb_b;
slouken@0
   474
    int cols_2 = cols / 2;
slouken@0
   475
slouken@0
   476
    lum2 = lum + cols;
slouken@0
   477
slouken@0
   478
    mod = next_row*3 + mod*3;
slouken@0
   479
slouken@0
   480
    y = rows / 2;
slouken@0
   481
    while( y-- )
slouken@0
   482
    {
slouken@0
   483
        x = cols_2;
slouken@0
   484
        while( x-- )
slouken@0
   485
        {
slouken@0
   486
            register int L;
slouken@0
   487
slouken@0
   488
            cr_r   = 0*768+256 + colortab[ *cr + 0*256 ];
slouken@0
   489
            crb_g  = 1*768+256 + colortab[ *cr + 1*256 ]
slouken@0
   490
                               + colortab[ *cb + 2*256 ];
slouken@0
   491
            cb_b   = 2*768+256 + colortab[ *cb + 3*256 ];
slouken@0
   492
            ++cr; ++cb;
slouken@0
   493
slouken@0
   494
            L = *lum++;
slouken@0
   495
            value = (rgb_2_pix[ L + cr_r ] |
slouken@0
   496
                     rgb_2_pix[ L + crb_g ] |
slouken@0
   497
                     rgb_2_pix[ L + cb_b ]);
slouken@0
   498
            row1[0+0] = row1[3+0] = row1[next_row+0] = row1[next_row+3+0] =
slouken@0
   499
                     (value      ) & 0xFF;
slouken@0
   500
            row1[0+1] = row1[3+1] = row1[next_row+1] = row1[next_row+3+1] =
slouken@0
   501
                     (value >>  8) & 0xFF;
slouken@0
   502
            row1[0+2] = row1[3+2] = row1[next_row+2] = row1[next_row+3+2] =
slouken@0
   503
                     (value >> 16) & 0xFF;
slouken@0
   504
            row1 += 2*3;
slouken@0
   505
slouken@0
   506
            L = *lum++;
slouken@0
   507
            value = (rgb_2_pix[ L + cr_r ] |
slouken@0
   508
                     rgb_2_pix[ L + crb_g ] |
slouken@0
   509
                     rgb_2_pix[ L + cb_b ]);
slouken@0
   510
            row1[0+0] = row1[3+0] = row1[next_row+0] = row1[next_row+3+0] =
slouken@0
   511
                     (value      ) & 0xFF;
slouken@0
   512
            row1[0+1] = row1[3+1] = row1[next_row+1] = row1[next_row+3+1] =
slouken@0
   513
                     (value >>  8) & 0xFF;
slouken@0
   514
            row1[0+2] = row1[3+2] = row1[next_row+2] = row1[next_row+3+2] =
slouken@0
   515
                     (value >> 16) & 0xFF;
slouken@0
   516
            row1 += 2*3;
slouken@0
   517
slouken@0
   518
slouken@0
   519
            /* Now, do second row. */
slouken@0
   520
slouken@0
   521
            L = *lum2++;
slouken@0
   522
            value = (rgb_2_pix[ L + cr_r ] |
slouken@0
   523
                     rgb_2_pix[ L + crb_g ] |
slouken@0
   524
                     rgb_2_pix[ L + cb_b ]);
slouken@0
   525
            row2[0+0] = row2[3+0] = row2[next_row+0] = row2[next_row+3+0] =
slouken@0
   526
                     (value      ) & 0xFF;
slouken@0
   527
            row2[0+1] = row2[3+1] = row2[next_row+1] = row2[next_row+3+1] =
slouken@0
   528
                     (value >>  8) & 0xFF;
slouken@0
   529
            row2[0+2] = row2[3+2] = row2[next_row+2] = row2[next_row+3+2] =
slouken@0
   530
                     (value >> 16) & 0xFF;
slouken@0
   531
            row2 += 2*3;
slouken@0
   532
slouken@0
   533
            L = *lum2++;
slouken@0
   534
            value = (rgb_2_pix[ L + cr_r ] |
slouken@0
   535
                     rgb_2_pix[ L + crb_g ] |
slouken@0
   536
                     rgb_2_pix[ L + cb_b ]);
slouken@0
   537
            row2[0+0] = row2[3+0] = row2[next_row+0] = row2[next_row+3+0] =
slouken@0
   538
                     (value      ) & 0xFF;
slouken@0
   539
            row2[0+1] = row2[3+1] = row2[next_row+1] = row2[next_row+3+1] =
slouken@0
   540
                     (value >>  8) & 0xFF;
slouken@0
   541
            row2[0+2] = row2[3+2] = row2[next_row+2] = row2[next_row+3+2] =
slouken@0
   542
                     (value >> 16) & 0xFF;
slouken@0
   543
            row2 += 2*3;
slouken@0
   544
        }
slouken@0
   545
slouken@0
   546
        /*
slouken@0
   547
         * These values are at the start of the next line, (due
slouken@0
   548
         * to the ++'s above),but they need to be at the start
slouken@0
   549
         * of the line after that.
slouken@0
   550
         */
slouken@0
   551
        lum  += cols;
slouken@0
   552
        lum2 += cols;
slouken@0
   553
        row1 += mod;
slouken@0
   554
        row2 += mod;
slouken@0
   555
    }
slouken@0
   556
}
slouken@0
   557
slouken@0
   558
static void Color32DitherYV12Mod2X( int *colortab, Uint32 *rgb_2_pix,
slouken@0
   559
                                    unsigned char *lum, unsigned char *cr,
slouken@0
   560
                                    unsigned char *cb, unsigned char *out,
slouken@0
   561
                                    int rows, int cols, int mod )
slouken@0
   562
{
slouken@0
   563
    unsigned int* row1 = (unsigned int*) out;
slouken@0
   564
    const int next_row = cols*2+mod;
slouken@0
   565
    unsigned int* row2 = row1 + 2*next_row;
slouken@0
   566
    unsigned char* lum2;
slouken@0
   567
    int x, y;
slouken@0
   568
    int cr_r;
slouken@0
   569
    int crb_g;
slouken@0
   570
    int cb_b;
slouken@0
   571
    int cols_2 = cols / 2;
slouken@0
   572
slouken@0
   573
    lum2 = lum + cols;
slouken@0
   574
slouken@0
   575
    mod = (next_row * 3) + mod;
slouken@0
   576
slouken@0
   577
    y = rows / 2;
slouken@0
   578
    while( y-- )
slouken@0
   579
    {
slouken@0
   580
        x = cols_2;
slouken@0
   581
        while( x-- )
slouken@0
   582
        {
slouken@0
   583
            register int L;
slouken@0
   584
slouken@0
   585
            cr_r   = 0*768+256 + colortab[ *cr + 0*256 ];
slouken@0
   586
            crb_g  = 1*768+256 + colortab[ *cr + 1*256 ]
slouken@0
   587
                               + colortab[ *cb + 2*256 ];
slouken@0
   588
            cb_b   = 2*768+256 + colortab[ *cb + 3*256 ];
slouken@0
   589
            ++cr; ++cb;
slouken@0
   590
slouken@0
   591
            L = *lum++;
slouken@0
   592
            row1[0] = row1[1] = row1[next_row] = row1[next_row+1] =
slouken@0
   593
                                       (rgb_2_pix[ L + cr_r ] |
slouken@0
   594
                                        rgb_2_pix[ L + crb_g ] |
slouken@0
   595
                                        rgb_2_pix[ L + cb_b ]);
slouken@0
   596
            row1 += 2;
slouken@0
   597
slouken@0
   598
            L = *lum++;
slouken@0
   599
            row1[0] = row1[1] = row1[next_row] = row1[next_row+1] =
slouken@0
   600
                                       (rgb_2_pix[ L + cr_r ] |
slouken@0
   601
                                        rgb_2_pix[ L + crb_g ] |
slouken@0
   602
                                        rgb_2_pix[ L + cb_b ]);
slouken@0
   603
            row1 += 2;
slouken@0
   604
slouken@0
   605
slouken@0
   606
            /* Now, do second row. */
slouken@0
   607
slouken@0
   608
            L = *lum2++;
slouken@0
   609
            row2[0] = row2[1] = row2[next_row] = row2[next_row+1] =
slouken@0
   610
                                       (rgb_2_pix[ L + cr_r ] |
slouken@0
   611
                                        rgb_2_pix[ L + crb_g ] |
slouken@0
   612
                                        rgb_2_pix[ L + cb_b ]);
slouken@0
   613
            row2 += 2;
slouken@0
   614
slouken@0
   615
            L = *lum2++;
slouken@0
   616
            row2[0] = row2[1] = row2[next_row] = row2[next_row+1] =
slouken@0
   617
                                       (rgb_2_pix[ L + cr_r ] |
slouken@0
   618
                                        rgb_2_pix[ L + crb_g ] |
slouken@0
   619
                                        rgb_2_pix[ L + cb_b ]);
slouken@0
   620
            row2 += 2;
slouken@0
   621
        }
slouken@0
   622
slouken@0
   623
        /*
slouken@0
   624
         * These values are at the start of the next line, (due
slouken@0
   625
         * to the ++'s above),but they need to be at the start
slouken@0
   626
         * of the line after that.
slouken@0
   627
         */
slouken@0
   628
        lum  += cols;
slouken@0
   629
        lum2 += cols;
slouken@0
   630
        row1 += mod;
slouken@0
   631
        row2 += mod;
slouken@0
   632
    }
slouken@0
   633
}
slouken@0
   634
slouken@0
   635
static void Color16DitherYUY2Mod1X( int *colortab, Uint32 *rgb_2_pix,
slouken@0
   636
                                    unsigned char *lum, unsigned char *cr,
slouken@0
   637
                                    unsigned char *cb, unsigned char *out,
slouken@0
   638
                                    int rows, int cols, int mod )
slouken@0
   639
{
slouken@0
   640
    unsigned short* row;
slouken@0
   641
    int x, y;
slouken@0
   642
    int cr_r;
slouken@0
   643
    int crb_g;
slouken@0
   644
    int cb_b;
slouken@0
   645
    int cols_2 = cols / 2;
slouken@0
   646
slouken@0
   647
    row = (unsigned short*) out;
slouken@0
   648
slouken@0
   649
    y = rows;
slouken@0
   650
    while( y-- )
slouken@0
   651
    {
slouken@0
   652
        x = cols_2;
slouken@0
   653
        while( x-- )
slouken@0
   654
        {
slouken@0
   655
            register int L;
slouken@0
   656
slouken@0
   657
            cr_r   = 0*768+256 + colortab[ *cr + 0*256 ];
slouken@0
   658
            crb_g  = 1*768+256 + colortab[ *cr + 1*256 ]
slouken@0
   659
                               + colortab[ *cb + 2*256 ];
slouken@0
   660
            cb_b   = 2*768+256 + colortab[ *cb + 3*256 ];
slouken@0
   661
            cr += 4; cb += 4;
slouken@0
   662
slouken@0
   663
            L = *lum; lum += 2;
slouken@0
   664
            *row++ = (rgb_2_pix[ L + cr_r ] |
slouken@0
   665
                       rgb_2_pix[ L + crb_g ] |
slouken@0
   666
                       rgb_2_pix[ L + cb_b ]);
slouken@0
   667
slouken@0
   668
            L = *lum; lum += 2;
slouken@0
   669
            *row++ = (rgb_2_pix[ L + cr_r ] |
slouken@0
   670
                       rgb_2_pix[ L + crb_g ] |
slouken@0
   671
                       rgb_2_pix[ L + cb_b ]);
slouken@0
   672
slouken@0
   673
        }
slouken@0
   674
slouken@0
   675
        row += mod;
slouken@0
   676
    }
slouken@0
   677
}
slouken@0
   678
slouken@0
   679
static void Color24DitherYUY2Mod1X( int *colortab, Uint32 *rgb_2_pix,
slouken@0
   680
                                    unsigned char *lum, unsigned char *cr,
slouken@0
   681
                                    unsigned char *cb, unsigned char *out,
slouken@0
   682
                                    int rows, int cols, int mod )
slouken@0
   683
{
slouken@0
   684
    unsigned int value;
slouken@0
   685
    unsigned char* row;
slouken@0
   686
    int x, y;
slouken@0
   687
    int cr_r;
slouken@0
   688
    int crb_g;
slouken@0
   689
    int cb_b;
slouken@0
   690
    int cols_2 = cols / 2;
slouken@0
   691
slouken@0
   692
    row = (unsigned char*) out;
slouken@0
   693
    mod *= 3;
slouken@0
   694
    y = rows;
slouken@0
   695
    while( y-- )
slouken@0
   696
    {
slouken@0
   697
        x = cols_2;
slouken@0
   698
        while( x-- )
slouken@0
   699
        {
slouken@0
   700
            register int L;
slouken@0
   701
slouken@0
   702
            cr_r   = 0*768+256 + colortab[ *cr + 0*256 ];
slouken@0
   703
            crb_g  = 1*768+256 + colortab[ *cr + 1*256 ]
slouken@0
   704
                               + colortab[ *cb + 2*256 ];
slouken@0
   705
            cb_b   = 2*768+256 + colortab[ *cb + 3*256 ];
slouken@0
   706
            cr += 4; cb += 4;
slouken@0
   707
slouken@0
   708
            L = *lum; lum += 2;
slouken@0
   709
            value = (rgb_2_pix[ L + cr_r ] |
slouken@0
   710
                     rgb_2_pix[ L + crb_g ] |
slouken@0
   711
                     rgb_2_pix[ L + cb_b ]);
slouken@0
   712
            *row++ = (value      ) & 0xFF;
slouken@0
   713
            *row++ = (value >>  8) & 0xFF;
slouken@0
   714
            *row++ = (value >> 16) & 0xFF;
slouken@0
   715
slouken@0
   716
            L = *lum; lum += 2;
slouken@0
   717
            value = (rgb_2_pix[ L + cr_r ] |
slouken@0
   718
                     rgb_2_pix[ L + crb_g ] |
slouken@0
   719
                     rgb_2_pix[ L + cb_b ]);
slouken@0
   720
            *row++ = (value      ) & 0xFF;
slouken@0
   721
            *row++ = (value >>  8) & 0xFF;
slouken@0
   722
            *row++ = (value >> 16) & 0xFF;
slouken@0
   723
slouken@0
   724
        }
slouken@0
   725
        row += mod;
slouken@0
   726
    }
slouken@0
   727
}
slouken@0
   728
slouken@0
   729
static void Color32DitherYUY2Mod1X( int *colortab, Uint32 *rgb_2_pix,
slouken@0
   730
                                    unsigned char *lum, unsigned char *cr,
slouken@0
   731
                                    unsigned char *cb, unsigned char *out,
slouken@0
   732
                                    int rows, int cols, int mod )
slouken@0
   733
{
slouken@0
   734
    unsigned int* row;
slouken@0
   735
    int x, y;
slouken@0
   736
    int cr_r;
slouken@0
   737
    int crb_g;
slouken@0
   738
    int cb_b;
slouken@0
   739
    int cols_2 = cols / 2;
slouken@0
   740
slouken@0
   741
    row = (unsigned int*) out;
slouken@0
   742
    y = rows;
slouken@0
   743
    while( y-- )
slouken@0
   744
    {
slouken@0
   745
        x = cols_2;
slouken@0
   746
        while( x-- )
slouken@0
   747
        {
slouken@0
   748
            register int L;
slouken@0
   749
slouken@0
   750
            cr_r   = 0*768+256 + colortab[ *cr + 0*256 ];
slouken@0
   751
            crb_g  = 1*768+256 + colortab[ *cr + 1*256 ]
slouken@0
   752
                               + colortab[ *cb + 2*256 ];
slouken@0
   753
            cb_b   = 2*768+256 + colortab[ *cb + 3*256 ];
slouken@0
   754
            cr += 4; cb += 4;
slouken@0
   755
slouken@0
   756
            L = *lum; lum += 2;
slouken@0
   757
            *row++ = (rgb_2_pix[ L + cr_r ] |
slouken@0
   758
                       rgb_2_pix[ L + crb_g ] |
slouken@0
   759
                       rgb_2_pix[ L + cb_b ]);
slouken@0
   760
slouken@0
   761
            L = *lum; lum += 2;
slouken@0
   762
            *row++ = (rgb_2_pix[ L + cr_r ] |
slouken@0
   763
                       rgb_2_pix[ L + crb_g ] |
slouken@0
   764
                       rgb_2_pix[ L + cb_b ]);
slouken@0
   765
slouken@0
   766
slouken@0
   767
        }
slouken@0
   768
        row += mod;
slouken@0
   769
    }
slouken@0
   770
}
slouken@0
   771
slouken@0
   772
/*
slouken@0
   773
 * In this function I make use of a nasty trick. The tables have the lower
slouken@0
   774
 * 16 bits replicated in the upper 16. This means I can write ints and get
slouken@0
   775
 * the horisontal doubling for free (almost).
slouken@0
   776
 */
slouken@0
   777
static void Color16DitherYUY2Mod2X( int *colortab, Uint32 *rgb_2_pix,
slouken@0
   778
                                    unsigned char *lum, unsigned char *cr,
slouken@0
   779
                                    unsigned char *cb, unsigned char *out,
slouken@0
   780
                                    int rows, int cols, int mod )
slouken@0
   781
{
slouken@0
   782
    unsigned int* row = (unsigned int*) out;
slouken@0
   783
    const int next_row = cols+(mod/2);
slouken@0
   784
    int x, y;
slouken@0
   785
    int cr_r;
slouken@0
   786
    int crb_g;
slouken@0
   787
    int cb_b;
slouken@0
   788
    int cols_2 = cols / 2;
slouken@0
   789
slouken@0
   790
    y = rows;
slouken@0
   791
    while( y-- )
slouken@0
   792
    {
slouken@0
   793
        x = cols_2;
slouken@0
   794
        while( x-- )
slouken@0
   795
        {
slouken@0
   796
            register int L;
slouken@0
   797
slouken@0
   798
            cr_r   = 0*768+256 + colortab[ *cr + 0*256 ];
slouken@0
   799
            crb_g  = 1*768+256 + colortab[ *cr + 1*256 ]
slouken@0
   800
                               + colortab[ *cb + 2*256 ];
slouken@0
   801
            cb_b   = 2*768+256 + colortab[ *cb + 3*256 ];
slouken@0
   802
            cr += 4; cb += 4;
slouken@0
   803
slouken@0
   804
            L = *lum; lum += 2;
slouken@0
   805
            row[0] = row[next_row] = (rgb_2_pix[ L + cr_r ] |
slouken@0
   806
                                        rgb_2_pix[ L + crb_g ] |
slouken@0
   807
                                        rgb_2_pix[ L + cb_b ]);
slouken@0
   808
            row++;
slouken@0
   809
slouken@0
   810
            L = *lum; lum += 2;
slouken@0
   811
            row[0] = row[next_row] = (rgb_2_pix[ L + cr_r ] |
slouken@0
   812
                                        rgb_2_pix[ L + crb_g ] |
slouken@0
   813
                                        rgb_2_pix[ L + cb_b ]);
slouken@0
   814
            row++;
slouken@0
   815
slouken@0
   816
        }
slouken@0
   817
        row += next_row;
slouken@0
   818
    }
slouken@0
   819
}
slouken@0
   820
slouken@0
   821
static void Color24DitherYUY2Mod2X( int *colortab, Uint32 *rgb_2_pix,
slouken@0
   822
                                    unsigned char *lum, unsigned char *cr,
slouken@0
   823
                                    unsigned char *cb, unsigned char *out,
slouken@0
   824
                                    int rows, int cols, int mod )
slouken@0
   825
{
slouken@0
   826
    unsigned int value;
slouken@0
   827
    unsigned char* row = out;
slouken@0
   828
    const int next_row = (cols*2 + mod) * 3;
slouken@0
   829
    int x, y;
slouken@0
   830
    int cr_r;
slouken@0
   831
    int crb_g;
slouken@0
   832
    int cb_b;
slouken@0
   833
    int cols_2 = cols / 2;
slouken@0
   834
    y = rows;
slouken@0
   835
    while( y-- )
slouken@0
   836
    {
slouken@0
   837
        x = cols_2;
slouken@0
   838
        while( x-- )
slouken@0
   839
        {
slouken@0
   840
            register int L;
slouken@0
   841
slouken@0
   842
            cr_r   = 0*768+256 + colortab[ *cr + 0*256 ];
slouken@0
   843
            crb_g  = 1*768+256 + colortab[ *cr + 1*256 ]
slouken@0
   844
                               + colortab[ *cb + 2*256 ];
slouken@0
   845
            cb_b   = 2*768+256 + colortab[ *cb + 3*256 ];
slouken@0
   846
            cr += 4; cb += 4;
slouken@0
   847
slouken@0
   848
            L = *lum; lum += 2;
slouken@0
   849
            value = (rgb_2_pix[ L + cr_r ] |
slouken@0
   850
                     rgb_2_pix[ L + crb_g ] |
slouken@0
   851
                     rgb_2_pix[ L + cb_b ]);
slouken@0
   852
            row[0+0] = row[3+0] = row[next_row+0] = row[next_row+3+0] =
slouken@0
   853
                     (value      ) & 0xFF;
slouken@0
   854
            row[0+1] = row[3+1] = row[next_row+1] = row[next_row+3+1] =
slouken@0
   855
                     (value >>  8) & 0xFF;
slouken@0
   856
            row[0+2] = row[3+2] = row[next_row+2] = row[next_row+3+2] =
slouken@0
   857
                     (value >> 16) & 0xFF;
slouken@0
   858
            row += 2*3;
slouken@0
   859
slouken@0
   860
            L = *lum; lum += 2;
slouken@0
   861
            value = (rgb_2_pix[ L + cr_r ] |
slouken@0
   862
                     rgb_2_pix[ L + crb_g ] |
slouken@0
   863
                     rgb_2_pix[ L + cb_b ]);
slouken@0
   864
            row[0+0] = row[3+0] = row[next_row+0] = row[next_row+3+0] =
slouken@0
   865
                     (value      ) & 0xFF;
slouken@0
   866
            row[0+1] = row[3+1] = row[next_row+1] = row[next_row+3+1] =
slouken@0
   867
                     (value >>  8) & 0xFF;
slouken@0
   868
            row[0+2] = row[3+2] = row[next_row+2] = row[next_row+3+2] =
slouken@0
   869
                     (value >> 16) & 0xFF;
slouken@0
   870
            row += 2*3;
slouken@0
   871
slouken@0
   872
        }
slouken@0
   873
        row += next_row;
slouken@0
   874
    }
slouken@0
   875
}
slouken@0
   876
slouken@0
   877
static void Color32DitherYUY2Mod2X( int *colortab, Uint32 *rgb_2_pix,
slouken@0
   878
                                    unsigned char *lum, unsigned char *cr,
slouken@0
   879
                                    unsigned char *cb, unsigned char *out,
slouken@0
   880
                                    int rows, int cols, int mod )
slouken@0
   881
{
slouken@0
   882
    unsigned int* row = (unsigned int*) out;
slouken@0
   883
    const int next_row = cols*2+mod;
slouken@0
   884
    int x, y;
slouken@0
   885
    int cr_r;
slouken@0
   886
    int crb_g;
slouken@0
   887
    int cb_b;
slouken@0
   888
    int cols_2 = cols / 2;
slouken@0
   889
    mod+=mod;
slouken@0
   890
    y = rows;
slouken@0
   891
    while( y-- )
slouken@0
   892
    {
slouken@0
   893
        x = cols_2;
slouken@0
   894
        while( x-- )
slouken@0
   895
        {
slouken@0
   896
            register int L;
slouken@0
   897
slouken@0
   898
            cr_r   = 0*768+256 + colortab[ *cr + 0*256 ];
slouken@0
   899
            crb_g  = 1*768+256 + colortab[ *cr + 1*256 ]
slouken@0
   900
                               + colortab[ *cb + 2*256 ];
slouken@0
   901
            cb_b   = 2*768+256 + colortab[ *cb + 3*256 ];
slouken@0
   902
            cr += 4; cb += 4;
slouken@0
   903
slouken@0
   904
            L = *lum; lum += 2;
slouken@0
   905
            row[0] = row[1] = row[next_row] = row[next_row+1] =
slouken@0
   906
                                       (rgb_2_pix[ L + cr_r ] |
slouken@0
   907
                                        rgb_2_pix[ L + crb_g ] |
slouken@0
   908
                                        rgb_2_pix[ L + cb_b ]);
slouken@0
   909
            row += 2;
slouken@0
   910
slouken@0
   911
            L = *lum; lum += 2;
slouken@0
   912
            row[0] = row[1] = row[next_row] = row[next_row+1] =
slouken@0
   913
                                       (rgb_2_pix[ L + cr_r ] |
slouken@0
   914
                                        rgb_2_pix[ L + crb_g ] |
slouken@0
   915
                                        rgb_2_pix[ L + cb_b ]);
slouken@0
   916
            row += 2;
slouken@0
   917
slouken@0
   918
slouken@0
   919
        }
slouken@0
   920
slouken@0
   921
        row += next_row;
slouken@0
   922
    }
slouken@0
   923
}
slouken@0
   924
slouken@0
   925
/*
slouken@0
   926
 * How many 1 bits are there in the Uint32.
slouken@0
   927
 * Low performance, do not call often.
slouken@0
   928
 */
slouken@0
   929
static int number_of_bits_set( Uint32 a )
slouken@0
   930
{
slouken@0
   931
    if(!a) return 0;
slouken@0
   932
    if(a & 1) return 1 + number_of_bits_set(a >> 1);
slouken@0
   933
    return(number_of_bits_set(a >> 1));
slouken@0
   934
}
slouken@0
   935
slouken@0
   936
/*
slouken@0
   937
 * How many 0 bits are there at least significant end of Uint32.
slouken@0
   938
 * Low performance, do not call often.
slouken@0
   939
 */
slouken@0
   940
static int free_bits_at_bottom( Uint32 a )
slouken@0
   941
{
slouken@0
   942
      /* assume char is 8 bits */
slouken@0
   943
    if(!a) return sizeof(Uint32) * 8;
slouken@0
   944
    if(((Sint32)a) & 1l) return 0;
slouken@0
   945
    return 1 + free_bits_at_bottom ( a >> 1);
slouken@0
   946
}
slouken@0
   947
slouken@0
   948
slouken@0
   949
SDL_Overlay *SDL_CreateYUV_SW(_THIS, int width, int height, Uint32 format, SDL_Surface *display)
slouken@0
   950
{
slouken@0
   951
	SDL_Overlay *overlay;
slouken@0
   952
	struct private_yuvhwdata *swdata;
slouken@0
   953
	int *Cr_r_tab;
slouken@0
   954
	int *Cr_g_tab;
slouken@0
   955
	int *Cb_g_tab;
slouken@0
   956
	int *Cb_b_tab;
slouken@0
   957
	Uint32 *r_2_pix_alloc;
slouken@0
   958
	Uint32 *g_2_pix_alloc;
slouken@0
   959
	Uint32 *b_2_pix_alloc;
slouken@0
   960
	int i, cpu_mmx;
slouken@0
   961
	int CR, CB;
slouken@0
   962
	Uint32 Rmask, Gmask, Bmask;
slouken@0
   963
slouken@0
   964
	/* Only RGB packed pixel conversion supported */
slouken@0
   965
	if ( (display->format->BytesPerPixel != 2) &&
slouken@0
   966
	     (display->format->BytesPerPixel != 3) &&
slouken@0
   967
	     (display->format->BytesPerPixel != 4) ) {
slouken@0
   968
		SDL_SetError("Can't use YUV data on non 16/24/32 bit surfaces");
slouken@0
   969
		return(NULL);
slouken@0
   970
	}
slouken@0
   971
slouken@0
   972
	/* Verify that we support the format */
slouken@0
   973
	switch (format) {
slouken@0
   974
	    case SDL_YV12_OVERLAY:
slouken@0
   975
	    case SDL_IYUV_OVERLAY:
slouken@0
   976
	    case SDL_YUY2_OVERLAY:
slouken@0
   977
	    case SDL_UYVY_OVERLAY:
slouken@0
   978
	    case SDL_YVYU_OVERLAY:
slouken@0
   979
		break;
slouken@0
   980
	    default:
slouken@0
   981
		SDL_SetError("Unsupported YUV format");
slouken@0
   982
		return(NULL);
slouken@0
   983
	}
slouken@0
   984
slouken@0
   985
	/* Create the overlay structure */
slouken@0
   986
	overlay = (SDL_Overlay *)malloc(sizeof *overlay);
slouken@0
   987
	if ( overlay == NULL ) {
slouken@0
   988
		SDL_OutOfMemory();
slouken@0
   989
		return(NULL);
slouken@0
   990
	}
slouken@0
   991
	memset(overlay, 0, (sizeof *overlay));
slouken@0
   992
slouken@0
   993
	/* Fill in the basic members */
slouken@0
   994
	overlay->format = format;
slouken@0
   995
	overlay->w = width;
slouken@0
   996
	overlay->h = height;
slouken@0
   997
slouken@0
   998
	/* Set up the YUV surface function structure */
slouken@0
   999
	overlay->hwfuncs = &sw_yuvfuncs;
slouken@0
  1000
slouken@0
  1001
	/* Create the pixel data and lookup tables */
slouken@0
  1002
	swdata = (struct private_yuvhwdata *)malloc(sizeof *swdata);
slouken@0
  1003
	overlay->hwdata = swdata;
slouken@0
  1004
	if ( swdata == NULL ) {
slouken@0
  1005
		SDL_OutOfMemory();
slouken@0
  1006
		SDL_FreeYUVOverlay(overlay);
slouken@0
  1007
		return(NULL);
slouken@0
  1008
	}
slouken@0
  1009
	swdata->stretch = NULL;
slouken@0
  1010
	swdata->display = display;
slouken@0
  1011
	swdata->pixels = (Uint8 *) malloc(width*height*2);
slouken@0
  1012
	swdata->colortab = (int *)malloc(4*256*sizeof(int));
slouken@0
  1013
	Cr_r_tab = &swdata->colortab[0*256];
slouken@0
  1014
	Cr_g_tab = &swdata->colortab[1*256];
slouken@0
  1015
	Cb_g_tab = &swdata->colortab[2*256];
slouken@0
  1016
	Cb_b_tab = &swdata->colortab[3*256];
slouken@0
  1017
	swdata->rgb_2_pix = (Uint32 *)malloc(3*768*sizeof(Uint32));
slouken@0
  1018
	r_2_pix_alloc = &swdata->rgb_2_pix[0*768];
slouken@0
  1019
	g_2_pix_alloc = &swdata->rgb_2_pix[1*768];
slouken@0
  1020
	b_2_pix_alloc = &swdata->rgb_2_pix[2*768];
slouken@0
  1021
	if ( ! swdata->pixels || ! swdata->colortab || ! swdata->rgb_2_pix ) {
slouken@0
  1022
		SDL_OutOfMemory();
slouken@0
  1023
		SDL_FreeYUVOverlay(overlay);
slouken@0
  1024
		return(NULL);
slouken@0
  1025
	}
slouken@0
  1026
slouken@0
  1027
	/* Generate the tables for the display surface */
slouken@0
  1028
	for (i=0; i<256; i++) {
slouken@0
  1029
		/* Gamma correction (luminescence table) and chroma correction
slouken@0
  1030
		   would be done here.  See the Berkeley mpeg_play sources.
slouken@0
  1031
		*/
slouken@0
  1032
		CB = CR = (i-128);
slouken@0
  1033
		Cr_r_tab[i] = (int) ( (0.419/0.299) * CR);
slouken@0
  1034
		Cr_g_tab[i] = (int) (-(0.299/0.419) * CR);
slouken@0
  1035
		Cb_g_tab[i] = (int) (-(0.114/0.331) * CB); 
slouken@0
  1036
		Cb_b_tab[i] = (int) ( (0.587/0.331) * CB);
slouken@0
  1037
	}
slouken@0
  1038
slouken@0
  1039
	/* 
slouken@0
  1040
	 * Set up entries 0-255 in rgb-to-pixel value tables.
slouken@0
  1041
	 */
slouken@0
  1042
	Rmask = display->format->Rmask;
slouken@0
  1043
	Gmask = display->format->Gmask;
slouken@0
  1044
	Bmask = display->format->Bmask;
slouken@0
  1045
	for ( i=0; i<256; ++i ) {
slouken@0
  1046
		r_2_pix_alloc[i+256] = i >> (8 - number_of_bits_set(Rmask));
slouken@0
  1047
		r_2_pix_alloc[i+256] <<= free_bits_at_bottom(Rmask);
slouken@0
  1048
		g_2_pix_alloc[i+256] = i >> (8 - number_of_bits_set(Gmask));
slouken@0
  1049
		g_2_pix_alloc[i+256] <<= free_bits_at_bottom(Gmask);
slouken@0
  1050
		b_2_pix_alloc[i+256] = i >> (8 - number_of_bits_set(Bmask));
slouken@0
  1051
		b_2_pix_alloc[i+256] <<= free_bits_at_bottom(Bmask);
slouken@0
  1052
	}
slouken@0
  1053
slouken@0
  1054
	/*
slouken@0
  1055
	 * If we have 16-bit output depth, then we double the value
slouken@0
  1056
	 * in the top word. This means that we can write out both
slouken@0
  1057
	 * pixels in the pixel doubling mode with one op. It is 
slouken@0
  1058
	 * harmless in the normal case as storing a 32-bit value
slouken@0
  1059
	 * through a short pointer will lose the top bits anyway.
slouken@0
  1060
	 */
slouken@0
  1061
	if( display->format->BytesPerPixel == 2 ) {
slouken@0
  1062
		for ( i=0; i<256; ++i ) {
slouken@0
  1063
			r_2_pix_alloc[i+256] |= (r_2_pix_alloc[i+256]) << 16;
slouken@0
  1064
			g_2_pix_alloc[i+256] |= (g_2_pix_alloc[i+256]) << 16;
slouken@0
  1065
			b_2_pix_alloc[i+256] |= (b_2_pix_alloc[i+256]) << 16;
slouken@0
  1066
		}
slouken@0
  1067
	}
slouken@0
  1068
slouken@0
  1069
	/*
slouken@0
  1070
	 * Spread out the values we have to the rest of the array so that
slouken@0
  1071
	 * we do not need to check for overflow.
slouken@0
  1072
	 */
slouken@0
  1073
	for ( i=0; i<256; ++i ) {
slouken@0
  1074
		r_2_pix_alloc[i] = r_2_pix_alloc[256];
slouken@0
  1075
		r_2_pix_alloc[i+512] = r_2_pix_alloc[511];
slouken@0
  1076
		g_2_pix_alloc[i] = g_2_pix_alloc[256];
slouken@0
  1077
		g_2_pix_alloc[i+512] = g_2_pix_alloc[511];
slouken@0
  1078
		b_2_pix_alloc[i] = b_2_pix_alloc[256];
slouken@0
  1079
		b_2_pix_alloc[i+512] = b_2_pix_alloc[511];
slouken@0
  1080
	}
slouken@0
  1081
slouken@0
  1082
	/* You have chosen wisely... */
slouken@0
  1083
	switch (format) {
slouken@0
  1084
	    case SDL_YV12_OVERLAY:
slouken@0
  1085
	    case SDL_IYUV_OVERLAY:
slouken@0
  1086
		cpu_mmx = CPU_Flags() & MMX_CPU;
slouken@0
  1087
		if ( display->format->BytesPerPixel == 2 ) {
slouken@0
  1088
#if defined(i386) && defined(__GNUC__) && defined(USE_ASMBLIT)
slouken@0
  1089
			/* inline assembly functions */
slouken@0
  1090
			if ( cpu_mmx && (Rmask == 0xF800) &&
slouken@0
  1091
			                (Gmask == 0x07E0) &&
slouken@0
  1092
				        (Bmask == 0x001F) &&
slouken@0
  1093
			                (width & 15) == 0) {
slouken@0
  1094
/*printf("Using MMX 16-bit 565 dither\n");*/
slouken@0
  1095
				swdata->Display1X = Color565DitherYV12MMX1X;
slouken@0
  1096
			} else {
slouken@0
  1097
/*printf("Using C 16-bit dither\n");*/
slouken@0
  1098
				swdata->Display1X = Color16DitherYV12Mod1X;
slouken@0
  1099
			}
slouken@0
  1100
#else
slouken@0
  1101
			swdata->Display1X = Color16DitherYV12Mod1X;
slouken@0
  1102
#endif
slouken@0
  1103
			swdata->Display2X = Color16DitherYV12Mod2X;
slouken@0
  1104
		}
slouken@0
  1105
		if ( display->format->BytesPerPixel == 3 ) {
slouken@0
  1106
			swdata->Display1X = Color24DitherYV12Mod1X;
slouken@0
  1107
			swdata->Display2X = Color24DitherYV12Mod2X;
slouken@0
  1108
		}
slouken@0
  1109
		if ( display->format->BytesPerPixel == 4 ) {
slouken@0
  1110
#if defined(i386) && defined(__GNUC__) && defined(USE_ASMBLIT)
slouken@0
  1111
			/* inline assembly functions */
slouken@0
  1112
			if ( cpu_mmx && (Rmask == 0x00FF0000) &&
slouken@0
  1113
			                (Gmask == 0x0000FF00) &&
slouken@0
  1114
				        (Bmask == 0x000000FF) && 
slouken@0
  1115
			                (width & 15) == 0) {
slouken@0
  1116
/*printf("Using MMX 32-bit dither\n");*/
slouken@0
  1117
				swdata->Display1X = ColorRGBDitherYV12MMX1X;
slouken@0
  1118
			} else {
slouken@0
  1119
/*printf("Using C 32-bit dither\n");*/
slouken@0
  1120
				swdata->Display1X = Color32DitherYV12Mod1X;
slouken@0
  1121
			}
slouken@0
  1122
#else
slouken@0
  1123
			swdata->Display1X = Color32DitherYV12Mod1X;
slouken@0
  1124
#endif
slouken@0
  1125
			swdata->Display2X = Color32DitherYV12Mod2X;
slouken@0
  1126
		}
slouken@0
  1127
		break;
slouken@0
  1128
	    case SDL_YUY2_OVERLAY:
slouken@0
  1129
	    case SDL_UYVY_OVERLAY:
slouken@0
  1130
	    case SDL_YVYU_OVERLAY:
slouken@0
  1131
		if ( display->format->BytesPerPixel == 2 ) {
slouken@0
  1132
			swdata->Display1X = Color16DitherYUY2Mod1X;
slouken@0
  1133
			swdata->Display2X = Color16DitherYUY2Mod2X;
slouken@0
  1134
		}
slouken@0
  1135
		if ( display->format->BytesPerPixel == 3 ) {
slouken@0
  1136
			swdata->Display1X = Color24DitherYUY2Mod1X;
slouken@0
  1137
			swdata->Display2X = Color24DitherYUY2Mod2X;
slouken@0
  1138
		}
slouken@0
  1139
		if ( display->format->BytesPerPixel == 4 ) {
slouken@0
  1140
			swdata->Display1X = Color32DitherYUY2Mod1X;
slouken@0
  1141
			swdata->Display2X = Color32DitherYUY2Mod2X;
slouken@0
  1142
		}
slouken@0
  1143
		break;
slouken@0
  1144
	    default:
slouken@0
  1145
		/* We should never get here (caught above) */
slouken@0
  1146
		break;
slouken@0
  1147
	}
slouken@0
  1148
slouken@0
  1149
	/* Find the pitch and offset values for the overlay */
slouken@0
  1150
	overlay->pitches = swdata->pitches;
slouken@0
  1151
	overlay->pixels = swdata->planes;
slouken@0
  1152
	switch (format) {
slouken@0
  1153
	    case SDL_YV12_OVERLAY:
slouken@0
  1154
	    case SDL_IYUV_OVERLAY:
slouken@0
  1155
		overlay->pitches[0] = overlay->w;
slouken@0
  1156
		overlay->pitches[1] = overlay->pitches[0] / 2;
slouken@0
  1157
		overlay->pitches[2] = overlay->pitches[0] / 2;
slouken@0
  1158
	        overlay->pixels[0] = swdata->pixels;
slouken@0
  1159
	        overlay->pixels[1] = overlay->pixels[0] +
slouken@0
  1160
		                     overlay->pitches[0] * overlay->h;
slouken@0
  1161
	        overlay->pixels[2] = overlay->pixels[1] +
slouken@0
  1162
		                     overlay->pitches[1] * overlay->h / 2;
slouken@0
  1163
		overlay->planes = 3;
slouken@0
  1164
		break;
slouken@0
  1165
	    case SDL_YUY2_OVERLAY:
slouken@0
  1166
	    case SDL_UYVY_OVERLAY:
slouken@0
  1167
	    case SDL_YVYU_OVERLAY:
slouken@0
  1168
		overlay->pitches[0] = overlay->w*2;
slouken@0
  1169
	        overlay->pixels[0] = swdata->pixels;
slouken@0
  1170
		overlay->planes = 1;
slouken@0
  1171
		break;
slouken@0
  1172
	    default:
slouken@0
  1173
		/* We should never get here (caught above) */
slouken@0
  1174
		break;
slouken@0
  1175
	}
slouken@0
  1176
slouken@0
  1177
	/* We're all done.. */
slouken@0
  1178
	return(overlay);
slouken@0
  1179
}
slouken@0
  1180
slouken@0
  1181
int SDL_LockYUV_SW(_THIS, SDL_Overlay *overlay)
slouken@0
  1182
{
slouken@0
  1183
	return(0);
slouken@0
  1184
}
slouken@0
  1185
slouken@0
  1186
void SDL_UnlockYUV_SW(_THIS, SDL_Overlay *overlay)
slouken@0
  1187
{
slouken@0
  1188
	return;
slouken@0
  1189
}
slouken@0
  1190
slouken@0
  1191
int SDL_DisplayYUV_SW(_THIS, SDL_Overlay *overlay, SDL_Rect *dstrect)
slouken@0
  1192
{
slouken@0
  1193
	struct private_yuvhwdata *swdata;
slouken@0
  1194
	SDL_Surface *stretch;
slouken@0
  1195
	SDL_Surface *display;
slouken@0
  1196
	int scale_2x;
slouken@0
  1197
	Uint8 *lum, *Cr, *Cb;
slouken@0
  1198
	Uint8 *dst;
slouken@0
  1199
	int mod;
slouken@0
  1200
slouken@0
  1201
	swdata = overlay->hwdata;
slouken@0
  1202
	scale_2x = 0;
slouken@0
  1203
	stretch = 0;
slouken@0
  1204
	if ( (overlay->w != dstrect->w) || (overlay->h != dstrect->h) ) {
slouken@0
  1205
		if ( (dstrect->w == 2*overlay->w) &&
slouken@0
  1206
		     (dstrect->h == 2*overlay->h) ) {
slouken@0
  1207
			scale_2x = 1;
slouken@0
  1208
		} else {
slouken@0
  1209
			if ( ! swdata->stretch ) {
slouken@0
  1210
				display = swdata->display;
slouken@0
  1211
				swdata->stretch = SDL_CreateRGBSurface(
slouken@0
  1212
					SDL_SWSURFACE,
slouken@0
  1213
					overlay->w, overlay->h,
slouken@0
  1214
					display->format->BitsPerPixel,
slouken@0
  1215
					display->format->Rmask,
slouken@0
  1216
					display->format->Gmask,
slouken@0
  1217
					display->format->Bmask, 0);
slouken@0
  1218
				if ( ! swdata->stretch ) {
slouken@0
  1219
					return(-1);
slouken@0
  1220
				}
slouken@0
  1221
			}
slouken@0
  1222
			stretch = swdata->stretch;
slouken@0
  1223
		}
slouken@0
  1224
	}
slouken@0
  1225
slouken@0
  1226
	if ( stretch ) {
slouken@0
  1227
		display = stretch;
slouken@0
  1228
	} else {
slouken@0
  1229
		display = swdata->display;
slouken@0
  1230
	}
slouken@0
  1231
	switch (overlay->format) {
slouken@0
  1232
	    case SDL_YV12_OVERLAY:
slouken@0
  1233
		lum = overlay->pixels[0];
slouken@0
  1234
		Cr =  overlay->pixels[1];
slouken@0
  1235
		Cb =  overlay->pixels[2];
slouken@0
  1236
		break;
slouken@0
  1237
	    case SDL_IYUV_OVERLAY:
slouken@0
  1238
		lum = overlay->pixels[0];
slouken@0
  1239
		Cr =  overlay->pixels[2];
slouken@0
  1240
		Cb =  overlay->pixels[1];
slouken@0
  1241
		break;
slouken@0
  1242
	    case SDL_YUY2_OVERLAY:
slouken@0
  1243
		lum = overlay->pixels[0];
slouken@0
  1244
		Cr = lum + 3;
slouken@0
  1245
		Cb = lum + 1;
slouken@0
  1246
		break;
slouken@0
  1247
	    case SDL_UYVY_OVERLAY:
slouken@0
  1248
		lum = overlay->pixels[0]+1;
slouken@0
  1249
		Cr = lum + 1;
slouken@0
  1250
		Cb = lum - 1;
slouken@0
  1251
		break;
slouken@0
  1252
	    case SDL_YVYU_OVERLAY:
slouken@0
  1253
		lum = overlay->pixels[0];
slouken@0
  1254
		Cr = lum + 1;
slouken@0
  1255
		Cb = lum + 3;
slouken@0
  1256
		break;
slouken@0
  1257
	    default:
slouken@0
  1258
		SDL_SetError("Unsupported YUV format in blit (??)");
slouken@0
  1259
		return(-1);
slouken@0
  1260
	}
slouken@0
  1261
	if ( SDL_MUSTLOCK(display) ) {
slouken@0
  1262
        	if ( SDL_LockSurface(display) < 0 ) {
slouken@0
  1263
			return(-1);
slouken@0
  1264
		}
slouken@0
  1265
	}
slouken@0
  1266
	if ( stretch ) {
slouken@0
  1267
		dst = (Uint8 *)stretch->pixels;
slouken@0
  1268
	} else {
slouken@0
  1269
		dst = (Uint8 *)display->pixels
slouken@0
  1270
			+ dstrect->x * display->format->BytesPerPixel
slouken@0
  1271
			+ dstrect->y * display->pitch;
slouken@0
  1272
	}
slouken@0
  1273
	mod = (display->pitch / display->format->BytesPerPixel);
slouken@0
  1274
slouken@0
  1275
	if ( scale_2x ) {
slouken@0
  1276
		mod -= (overlay->w * 2);
slouken@0
  1277
		swdata->Display2X(swdata->colortab, swdata->rgb_2_pix,
slouken@0
  1278
		                  lum, Cr, Cb, dst, overlay->h, overlay->w,mod);
slouken@0
  1279
	} else {
slouken@0
  1280
		mod -= overlay->w;
slouken@0
  1281
		swdata->Display1X(swdata->colortab, swdata->rgb_2_pix,
slouken@0
  1282
		                  lum, Cr, Cb, dst, overlay->h, overlay->w,mod);
slouken@0
  1283
	}
slouken@0
  1284
	if ( SDL_MUSTLOCK(display) ) {
slouken@0
  1285
		SDL_UnlockSurface(display);
slouken@0
  1286
	}
slouken@0
  1287
	if ( stretch ) {
slouken@0
  1288
		display = swdata->display;
slouken@0
  1289
		SDL_SoftStretch(stretch, NULL, display, dstrect);
slouken@0
  1290
	}
slouken@0
  1291
	SDL_UpdateRects(display, 1, dstrect);
slouken@0
  1292
slouken@0
  1293
	return(0);
slouken@0
  1294
}
slouken@0
  1295
slouken@0
  1296
void SDL_FreeYUV_SW(_THIS, SDL_Overlay *overlay)
slouken@0
  1297
{
slouken@0
  1298
	struct private_yuvhwdata *swdata;
slouken@0
  1299
slouken@0
  1300
	swdata = overlay->hwdata;
slouken@0
  1301
	if ( swdata ) {
slouken@0
  1302
		if ( swdata->pixels ) {
slouken@0
  1303
			free(swdata->pixels);
slouken@0
  1304
		}
slouken@0
  1305
		if ( swdata->colortab ) {
slouken@0
  1306
			free(swdata->colortab);
slouken@0
  1307
		}
slouken@0
  1308
		if ( swdata->rgb_2_pix ) {
slouken@0
  1309
			free(swdata->rgb_2_pix);
slouken@0
  1310
		}
slouken@0
  1311
		free(swdata);
slouken@0
  1312
	}
slouken@0
  1313
}