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