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