[4] | 1 | /******************************************************************************
|
---|
| 2 | * SAGE - Scalable Adaptive Graphics Environment
|
---|
| 3 | *
|
---|
| 4 | * Copyright (C) 2004 Electronic Visualization Laboratory,
|
---|
| 5 | * University of Illinois at Chicago
|
---|
| 6 | *
|
---|
| 7 | * All rights reserved.
|
---|
| 8 | *
|
---|
| 9 | * Redistribution and use in source and binary forms, with or without
|
---|
| 10 | * modification, are permitted provided that the following conditions are met:
|
---|
| 11 | *
|
---|
| 12 | * * Redistributions of source code must retain the above copyright
|
---|
| 13 | * notice, this list of conditions and the following disclaimer.
|
---|
| 14 | * * Redistributions in binary form must reproduce the above
|
---|
| 15 | * copyright notice, this list of conditions and the following disclaimer
|
---|
| 16 | * in the documentation and/or other materials provided with the distribution.
|
---|
| 17 | * * Neither the name of the University of Illinois at Chicago nor
|
---|
| 18 | * the names of its contributors may be used to endorse or promote
|
---|
| 19 | * products derived from this software without specific prior written permission.
|
---|
| 20 | *
|
---|
| 21 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
---|
| 22 | * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
---|
| 23 | * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
|
---|
| 24 | * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
|
---|
| 25 | * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
|
---|
| 26 | * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
|
---|
| 27 | * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
|
---|
| 28 | * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
|
---|
| 29 | * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
|
---|
| 30 | * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
|
---|
| 31 | * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
---|
| 32 | *
|
---|
| 33 | * Direct questions, comments etc about SAGE to http://www.evl.uic.edu/cavern/forum/
|
---|
| 34 | *
|
---|
| 35 | *****************************************************************************/
|
---|
| 36 |
|
---|
| 37 | #include <windows.h>
|
---|
| 38 | #include "stdafx.h"
|
---|
| 39 | #include "YuvToRGB.h"
|
---|
| 40 |
|
---|
| 41 | #define MYUCHAR(_flt_) ((_flt_>0 && _flt_<256)?_flt_:((_flt_<0)?0:255))
|
---|
| 42 |
|
---|
| 43 | // U0 Y0 Vo Y1 | U2 Y2 V2 Y3 | U4 Y4 V4 Y5 | ...
|
---|
| 44 | void YUV422UYVY_ToRGB24(unsigned char* pbYUV, unsigned char* pbRGB, DWORD yuv_len)
|
---|
| 45 | {
|
---|
| 46 |
|
---|
| 47 | // /*
|
---|
| 48 | int B_Cb128,R_Cr128,G_CrCb128;
|
---|
| 49 | int Y0,U,Y1,V;
|
---|
| 50 | int R,G,B;
|
---|
| 51 |
|
---|
| 52 | BYTE *yuv_index;
|
---|
| 53 | BYTE *rgb_index;
|
---|
| 54 |
|
---|
| 55 | // long lStride_out = (((dwWidth * 3) + 3) / 4) * 4;
|
---|
| 56 |
|
---|
| 57 | yuv_index = pbYUV;
|
---|
| 58 | rgb_index = pbRGB;
|
---|
| 59 |
|
---|
| 60 | for (DWORD i = 0, j = 0; i < yuv_len; )
|
---|
| 61 | {
|
---|
| 62 | // Each WORD is a 'UY' or 'VY' block.
|
---|
| 63 | // Set the low byte (chroma) to 0x80 and leave the high byte (luma)
|
---|
| 64 | // WORD pixel = pwSource[x] & 0xFF00;
|
---|
| 65 | // pixel |= 0x0080;
|
---|
| 66 | // pwTarget[x] = pixel;
|
---|
| 67 |
|
---|
| 68 | // R = 1.164(Y - 16) + 1.596(V - 128)
|
---|
| 69 | // G = 1.164(Y - 16) - 0.813(V - 128) - 0.391(U - 128)
|
---|
| 70 | // B = 1.164(Y - 16) + 2.018(U - 128)
|
---|
| 71 |
|
---|
| 72 | U = (int)((float)yuv_index[i++]-128.0f);
|
---|
| 73 | Y0 = (int)(1.164f * ((float)pbYUV[i++]-16.0f));
|
---|
| 74 | V = (int)((float)yuv_index[i++]-128.0f);
|
---|
| 75 | Y1 = (int)(1.164f * ((float)yuv_index[i++]-16.0f));
|
---|
| 76 |
|
---|
| 77 | R_Cr128 = (int)(1.596f*V);
|
---|
| 78 | G_CrCb128 = (int)(-0.813f*V - 0.391f*U);
|
---|
| 79 | B_Cb128 = (int)(2.018f*U);
|
---|
| 80 |
|
---|
| 81 | R= Y0 + R_Cr128;
|
---|
| 82 | G = Y0 + G_CrCb128;
|
---|
| 83 | B = Y0 + B_Cb128;
|
---|
| 84 |
|
---|
| 85 | rgb_index[j++] = max(0, min(B, 255));
|
---|
| 86 | rgb_index[j++] = max(0, min(G, 255));
|
---|
| 87 | rgb_index[j++] = max(0, min(R, 255));
|
---|
| 88 |
|
---|
| 89 | R= Y1 + R_Cr128;
|
---|
| 90 | G = Y1 + G_CrCb128;
|
---|
| 91 | B = Y1 + B_Cb128;
|
---|
| 92 |
|
---|
| 93 | rgb_index[j++] = max(0, min(B, 255));
|
---|
| 94 | rgb_index[j++] = max(0, min(G, 255));
|
---|
| 95 | rgb_index[j++] = max(0, min(R, 255));
|
---|
| 96 | }
|
---|
| 97 | // */
|
---|
| 98 | }
|
---|