Search
lxdream.org :: lxdream/src/pvr2/yuv.c
lxdream 0.9.1
released Jun 29
Download Now
filename src/pvr2/yuv.c
changeset 281:2019e605cb27
next282:01e53698ff38
author nkeynes
date Sun Jan 14 02:55:25 2007 +0000 (13 years ago)
permissions -rw-r--r--
last change Add work-in-progress YUV support
file annotate diff log raw
nkeynes@281
     1
/**
nkeynes@281
     2
 * $Id: yuv.c,v 1.1 2007-01-14 02:55:25 nkeynes Exp $
nkeynes@281
     3
 *
nkeynes@281
     4
 * YUV420 and YUV422 decoding
nkeynes@281
     5
 *
nkeynes@281
     6
 * Copyright (c) 2005 Nathan Keynes.
nkeynes@281
     7
 *
nkeynes@281
     8
 * This program is free software; you can redistribute it and/or modify
nkeynes@281
     9
 * it under the terms of the GNU General Public License as published by
nkeynes@281
    10
 * the Free Software Foundation; either version 2 of the License, or
nkeynes@281
    11
 * (at your option) any later version.
nkeynes@281
    12
 *
nkeynes@281
    13
 * This program is distributed in the hope that it will be useful,
nkeynes@281
    14
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
nkeynes@281
    15
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
nkeynes@281
    16
 * GNU General Public License for more details.
nkeynes@281
    17
 */
nkeynes@281
    18
#include "dream.h"
nkeynes@281
    19
nkeynes@281
    20
#define YUV420_BLOCK_SIZE 384
nkeynes@281
    21
nkeynes@281
    22
static inline uint16_t decode_yuv420_to_rgb565_pixel( uint8_t y, uint8_t u, uint8_t v )
nkeynes@281
    23
{
nkeynes@281
    24
    
nkeynes@281
    25
nkeynes@281
    26
}
nkeynes@281
    27
nkeynes@281
    28
/**
nkeynes@281
    29
 * Convert a single 16x16 yuv420 block to rgb565.
nkeynes@281
    30
 * @param dest output memory location for this block
nkeynes@281
    31
 * @param src start of source block
nkeynes@281
    32
 * @param stride length of overall line in pixels (ie 16-bit words)
nkeynes@281
    33
 */
nkeynes@281
    34
static void decode_yuv420_to_rgb565_block( uint16_t *dest, uint8_t *src, uint32_t stride ) 
nkeynes@281
    35
{
nkeynes@281
    36
    uint8_t *up = *src;
nkeynes@281
    37
    uint8_t *vp = u + 64;
nkeynes@281
    38
    uint8_t *yp = v + 64;
nkeynes@281
    39
    
nkeynes@281
    40
    for( int yb=0; yb<16; yb++ ) {
nkeynes@281
    41
	for( int xb=0; xb<16; xb++ ) {
nkeynes@281
    42
	    uint8_t y = *yp++;
nkeynes@281
    43
	    uint8_t u = up[xb>>1 + (yb>>1)<<3];
nkeynes@281
    44
	    uint8_t v = vp[xb>>1 + (yb>>1)<<3];
nkeynes@281
    45
	    *dest++ = decode_yuv420_to_rgb565_block(y,u,v);
nkeynes@281
    46
	}
nkeynes@281
    47
	dest = dest + stride - 16;
nkeynes@281
    48
    }
nkeynes@281
    49
}
nkeynes@281
    50
nkeynes@281
    51
void decode_yuv420_to_rgb565( uint16_t *dest, uint8_t *src, int width, int height ) 
nkeynes@281
    52
{
nkeynes@281
    53
    uint16_t *p;
nkeynes@281
    54
    for( int j=0; j<height; j++ ) {
nkeynes@281
    55
	for( int i=0; i<width; i++ ) {
nkeynes@281
    56
	    p = dest + (j<<5)*width + i<<5;
nkeynes@281
    57
	    decode_yuv420_to_rgb565_block( p, src, width );
nkeynes@281
    58
	    src += YUV420_BLOCK_SIZE;
nkeynes@281
    59
	}
nkeynes@281
    60
    }
nkeynes@281
    61
}
.