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 | #ifndef _YUV_RGB_
|
---|
37 | #define _YUV_RGB_
|
---|
38 |
|
---|
39 | #include <windows.h>
|
---|
40 | #include "stdafx.h"
|
---|
41 |
|
---|
42 | // nominal luma range
|
---|
43 | #define MIN_LUMA 16
|
---|
44 | #define MAX_LUMA 235
|
---|
45 | #define LUMA_RANGE (MAX_LUMA - MIN_LUMA + 1) // Total number of valid luma values
|
---|
46 |
|
---|
47 | #define clipRGB(x) clip((x), 0, 255)
|
---|
48 | #define clipYUV(x) clip((x), MIN_LUMA, MAX_LUMA)
|
---|
49 |
|
---|
50 | typedef struct _UYVY {
|
---|
51 | unsigned char u;
|
---|
52 | unsigned char y0;
|
---|
53 | unsigned char v;
|
---|
54 | unsigned char y1;
|
---|
55 | }UYVY_ARRAY;
|
---|
56 |
|
---|
57 | void SaveToBmp(char *Path, unsigned char *img_buff, int width, int height, int bitcount);
|
---|
58 |
|
---|
59 | inline long clip(long i, long min, long max)
|
---|
60 | {
|
---|
61 | if (i < min) return min;
|
---|
62 | if (i > max) return max;
|
---|
63 | return i;
|
---|
64 | }
|
---|
65 |
|
---|
66 | // RGB2YUV: Convert an RGB pixel to YUV
|
---|
67 |
|
---|
68 | inline BYTE RGB2Y(DWORD r, DWORD g, DWORD b)
|
---|
69 | {
|
---|
70 | BYTE luma = static_cast<BYTE>(( ( 66 * r + 129 * g + 25 * b + 128) >> 8) + 16);
|
---|
71 | _ASSERTE(luma >= MIN_LUMA);
|
---|
72 | _ASSERTE(luma <= MAX_LUMA);
|
---|
73 | return luma;
|
---|
74 | }
|
---|
75 |
|
---|
76 | inline BYTE RGB2U(DWORD r, DWORD g, DWORD b)
|
---|
77 | {
|
---|
78 | return static_cast<BYTE>(( ( -38 * r - 74 * g + 112 * b + 128) >> 8) + 128);
|
---|
79 | }
|
---|
80 |
|
---|
81 | inline BYTE RGB2V(DWORD r, DWORD g, DWORD b)
|
---|
82 | {
|
---|
83 | return static_cast<BYTE>(( ( 112 * r - 94 * g - 18 * b + 128) >> 8) + 128);
|
---|
84 | }
|
---|
85 |
|
---|
86 | // Convert YUV to RGB
|
---|
87 |
|
---|
88 | inline BYTE YUV2Red(long y, long u, long v)
|
---|
89 | {
|
---|
90 | return static_cast<BYTE>(clipRGB(( 298 * (y - 16) + 409 * (v - 128) + 128) >> 8));
|
---|
91 | }
|
---|
92 |
|
---|
93 |
|
---|
94 | inline BYTE YUV2Green(long y, long u, long v)
|
---|
95 | {
|
---|
96 | return static_cast<BYTE>((clipRGB(( 298 * (y - 16) - 100 * (u - 128) - 208 * (v - 128) + 128) >> 8)));
|
---|
97 | }
|
---|
98 |
|
---|
99 | inline BYTE YUV2Blue(long y, long u, long v)
|
---|
100 | {
|
---|
101 | return static_cast<BYTE>((clipRGB(( 298 * (y - 16) + 516 * (u - 128) + 128) >> 8)));
|
---|
102 | }
|
---|
103 |
|
---|
104 |
|
---|
105 | #endif
|
---|