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 | #include "stdafx.h"
|
---|
37 | #include "YUV_RGB.h"
|
---|
38 |
|
---|
39 | /*
|
---|
40 | typedef struct tagRGBQUAD {
|
---|
41 | BYTE rgbBlue;
|
---|
42 | BYTE rgbGreen;
|
---|
43 | BYTE rgbRed;
|
---|
44 | BYTE rgbReserved;
|
---|
45 | } RGBQUAD;
|
---|
46 |
|
---|
47 | typedef struct tagBITMAPINFOHEADER {
|
---|
48 | DWORD biSize;
|
---|
49 | LONG biWidth;
|
---|
50 | LONG biHeight;
|
---|
51 | WORD biPlanes;
|
---|
52 | WORD biBitCount;
|
---|
53 | DWORD biCompression;
|
---|
54 | DWORD biSizeImage;
|
---|
55 | LONG biXPelsPerMeter;
|
---|
56 | LONG biYPelsPerMeter;
|
---|
57 | DWORD biClrUsed;
|
---|
58 | DWORD biClrImportant;
|
---|
59 | } BITMAPINFOHEADER;
|
---|
60 |
|
---|
61 | typedef struct tagBITMAPFILEHEADER {
|
---|
62 | WORD bfType;
|
---|
63 | DWORD bfSize;
|
---|
64 | WORD bfReserved1;
|
---|
65 | WORD bfReserved2;
|
---|
66 | DWORD bfOffBits;
|
---|
67 | } BITMAPFILEHEADER;
|
---|
68 |
|
---|
69 | typedef struct tagBITMAPINFO {
|
---|
70 | BITMAPINFOHEADER bmiHeader; //
|
---|
71 | RGBQUAD bmiColors[1]; // »ý»ó Å×À̺í
|
---|
72 | } BITMAPINFO;
|
---|
73 | //*/
|
---|
74 |
|
---|
75 |
|
---|
76 | //-----------------------------------------------------------------------------
|
---|
77 | // SaveBMP Function
|
---|
78 | //
|
---|
79 | // ÁÖŸîÁø °æ·Î·Î ÀúÀå.
|
---|
80 | void SaveToBmp(char *Path, unsigned char *img_buff, int width, int height, int bitcount) {
|
---|
81 | ///*
|
---|
82 | BITMAPFILEHEADER fh; // bmp file header
|
---|
83 | BITMAPINFOHEADER bh; // bmp info header
|
---|
84 |
|
---|
85 | int palSize;
|
---|
86 | DWORD dwWritten;
|
---|
87 | HANDLE hFile;
|
---|
88 |
|
---|
89 | palSize = (bitcount==24 ? 0:1 << bitcount)*sizeof(RGBQUAD);
|
---|
90 |
|
---|
91 | // bmp info header
|
---|
92 | bh.biSize = sizeof(BITMAPINFOHEADER); // Bmp Header Size
|
---|
93 | bh.biWidth = width; // Width
|
---|
94 | bh.biHeight = height; // Height
|
---|
95 | bh.biPlanes = 1; // Planes
|
---|
96 | bh.biBitCount = 24; // BitCount
|
---|
97 | // YUV - mmioFOURCC('I','4','2','0'), width*height*3/2),
|
---|
98 | // RGB24 (non compression)
|
---|
99 | bh.biCompression = BI_RGB; // Compression
|
---|
100 | // bh.biSizeImage = (((width * 3) + 3) / 4) * 4 * height;
|
---|
101 | bh.biSizeImage = width * height * (bitcount/8);
|
---|
102 | bh.biXPelsPerMeter = 0; // X,Y Pixels per Meter
|
---|
103 | bh.biYPelsPerMeter = 0;
|
---|
104 | bh.biClrUsed = 0; // Colors that used(if 0, Maximum colors)
|
---|
105 | bh.biClrImportant = 0; // Important colors that used(if 0, all colors are important)
|
---|
106 |
|
---|
107 | // BITMAPFILEHEADER.
|
---|
108 | fh.bfType = 0x4d42;
|
---|
109 | fh.bfReserved1 = 0;
|
---|
110 | fh.bfReserved2 = 0;
|
---|
111 | fh.bfSize = bh.biSize + palSize + bh.biSizeImage + sizeof(BITMAPFILEHEADER);
|
---|
112 | fh.bfOffBits = sizeof(BITMAPFILEHEADER)+sizeof(BITMAPINFOHEADER)+palSize;
|
---|
113 |
|
---|
114 | // Write to File.
|
---|
115 | hFile=CreateFile(Path,GENERIC_WRITE,0,NULL, CREATE_ALWAYS,FILE_ATTRIBUTE_NORMAL,NULL);
|
---|
116 | WriteFile(hFile, &fh, sizeof(fh), &dwWritten, NULL);
|
---|
117 | WriteFile(hFile, &bh, sizeof(bh), &dwWritten, NULL);
|
---|
118 | WriteFile(hFile, img_buff, bh.biSizeImage, &dwWritten, NULL);
|
---|
119 |
|
---|
120 | CloseHandle(hFile);
|
---|
121 | // */
|
---|
122 | }
|
---|