1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229
|
/*
* YV12.c
*
* Copyright (C) Charles 'Buck' Krasic - April 2000
* Copyright (C) Erik Walthinsen - April 2000
*
* This file is part of libdv, a free DV (IEC 61834/SMPTE 314M)
* codec.
*
* libdv is free software; you can redistribute it and/or modify it
* under the terms of the GNU Lesser Public License as published by
* the Free Software Foundation; either version 2.1, or (at your
* option) any later version.
*
* libdv is distributed in the hope that it will be useful, but
* WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser Public License for more details.
*
* You should have received a copy of the GNU Lesser Public License
* along with libdv; see the file COPYING. If not, write to
* the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA.
*
* The libdv homepage is http://libdv.sourceforge.net/.
*/
#if HAVE_CONFIG_H
# include <config.h>
#endif
#include <stdlib.h>
#include "YV12.h"
#if ARCH_X86 || ARCH_X86_64
#include "mmx.h"
#endif // ARCH_X86 || ARCH_X86_64
/* Lookup tables for mapping signed to unsigned, and clamping */
static unsigned char real_uvlut[256], *uvlut;
static unsigned char real_ylut[768], *ylut;
#if ARCH_X86 || ARCH_X86_64
/* Define some constants used in MMX range mapping and clamping logic */
static mmx_t mmx_0x10s = (mmx_t) 0x1010101010101010LL,
mmx_0x0080s = (mmx_t) 0x0080008000800080LL,
mmx_0x7f24s = (mmx_t) 0x7f247f247f247f24LL,
mmx_0x7f94s = (mmx_t) 0x7f947f947f947f94LL,
mmx_0x7f7fs = (mmx_t) 0x7f7f7f7f7f7f7f7fLL,
mmx_0x7f00s = (mmx_t) 0x7f007f007f007f00LL;
#endif // ARCH_X86 || ARCH_X86_64
void
dv_YV12_init(int clamp_luma, int clamp_chroma) {
int i;
int value;
uvlut = real_uvlut + 128; // index from -128 .. 127
for(i=-128;
i<128;
++i) {
value = i + 128;
if (clamp_chroma == TRUE) value = CLAMP(value, 16, 240);
uvlut[i] = value;
} /* for */
ylut = real_ylut + 256; // index from -256 .. 511
for(i=-256;
i<512;
++i) {
value = i + 128;
if (clamp_luma == TRUE) value = CLAMP(value, 16, 235);
ylut[i] = value;
} /* for */
} /* dv_YV12_init */
void
dv_mb420_YV12(dv_macroblock_t *mb, uint8_t **pixels, uint16_t *pitches) {
dv_coeff_t *Y[4], *UV[2], *Ytmp, *UVtmp;
unsigned char *py, *pwy, *puv, *pwuv;
int i, j, row, col;
Y [0] = mb->b[0].coeffs;
Y [1] = mb->b[1].coeffs;
Y [2] = mb->b[2].coeffs;
Y [3] = mb->b[3].coeffs;
UV[0] = mb->b[4].coeffs;
UV[1] = mb->b[5].coeffs;
py = pixels[0] + mb->x + (mb->y * pitches[0]);
for(i=0; i<4; i+=2) { // two rows of Y blocks
for(row=0;
row < 8;
row++) {
pwy = py;
for(j=0; j<2; j++) { // two columns of Y blocks
Ytmp = Y[i+j];
for(col = 0; col < 8; col++) {
*pwy++ = ylut[CLAMP(*Ytmp, -256, 511)];
Ytmp++;
}
Y[i+j] = Ytmp;
} /* for j */
py += pitches[0];
} /* for row */
} /* for i */
for(i=1;
i<3;
i++) { // two Chroma blocks
puv = pixels[i] + (mb->x/2) + ((mb->y/2) * pitches[i]);
UVtmp = UV[i-1];
for(row=0;
row < 8;
row++, puv += pitches[i]) {
pwuv = puv;
for(col=0;
col<8;
col++) {
*pwuv++ = uvlut[CLAMP(*UVtmp, -128, 127)];
UVtmp++;
} /* for col */
} /* for row */
} // for i
} /* dv_mb420_YV12 */
#if ARCH_X86 || ARCH_X86_64
/* TODO: clamping */
void
dv_mb420_YV12_mmx(dv_macroblock_t *mb, uint8_t **pixels, uint16_t *pitches,
int clamp_luma, int clamp_chroma) {
dv_coeff_t *Y[4], *UV[2], *Ytmp, *UVtmp;
unsigned char *py, *pwy, *puv;
int i, j, row;
Y [0] = mb->b[0].coeffs;
Y [1] = mb->b[1].coeffs;
Y [2] = mb->b[2].coeffs;
Y [3] = mb->b[3].coeffs;
UV[0] = mb->b[4].coeffs;
UV[1] = mb->b[5].coeffs;
py = pixels[0] + mb->x + (mb->y * pitches[0]);
movq_m2r(mmx_0x0080s,mm0);
movq_m2r(mmx_0x10s,mm1);
if (clamp_luma == TRUE) {
movq_m2r(mmx_0x7f94s,mm2); /* hi clamp */
movq_m2r(mmx_0x7f24s,mm3); /* lo clamp */
} else {
movq_m2r(mmx_0x7f7fs,mm2); /* no clamp */
movq_m2r(mmx_0x7f00s,mm3); /* no clamp */
}
for(i=0; i<4; i+=2) { // two rows of Y blocks
for(row=0;
row < 8;
row++) {
pwy = py;
for(j=0; j<2; j++) { // two columns of Y blocks
Ytmp = Y[i+j];
movq_m2r(*(Ytmp ),mm4);
movq_m2r(*(Ytmp+4),mm5);
paddw_r2r(mm0,mm4); // +128
paddw_r2r(mm0,mm5); // +128
packuswb_r2r(mm5,mm4); // 16 -> 8 bit
movq_r2m(mm4, *pwy);
Y[i+j] = Ytmp + 8;
pwy += 8;
} /* for j */
py += pitches[0];
} /* for row */
} /* for i */
for(i=1;
i<3;
i++) { // two Chroma blocks
puv = pixels[i] + (mb->x/2) + ((mb->y/2) * pitches[i]);
UVtmp = UV[i-1];
for(row=0;
row < 8;
row++) {
movq_m2r(*(UVtmp ),mm4);
movq_m2r(*(UVtmp+4),mm5);
paddw_r2r(mm0,mm4); // +128
paddw_r2r(mm0,mm5); // +128
packuswb_r2r(mm5,mm4); // 16 -> 8 bit
movq_r2m(mm4, *puv);
UVtmp += 8;
puv += pitches[i];
} /* for row */
} // for i
emms();
} /* dv_mb420_YV12_mmx */
#endif // ARCH_X86 || ARCH_X86_64
|