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