src/video/SDL_yuv_sw.c
author Sam Lantinga <slouken@libsdl.org>
Sun, 28 May 2006 13:04:16 +0000
branchSDL-1.3
changeset 1662 782fd950bd46
parent 1644 8a858076f39d
child 1668 4da1ee79c9af
permissions -rw-r--r--
Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.

WARNING: None of the video drivers have been updated for the new API yet! The API is still under design and very fluid.

The code is now run through a consistent indent format:
indent -i4 -nut -nsc -br -ce

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