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