Openholo
v5.0
Open Source Digital Holographic Library
Bitmap.h
Go to the documentation of this file.
1
#ifndef __Bitmap_h
2
#define __Bitmap_h
3
4
#include "
include.h
"
5
6
//#define WIDTHBYTES(bits) (((bits)+31)/32*4)
7
//
9
//#define _planes 1
10
//#define _compression 0
11
//#define _xpixelpermeter 0x130B //2835 , 72 DPI
12
//#define _ypixelpermeter 0x130B //2835 , 72 DPI
14
//
15
//#pragma pack(push,1)
16
//typedef struct{
17
// uint8_t signature[2];
18
// uint32_t filesize;
19
// uint32_t reserved;
20
// uint32_t fileoffset_to_pixelarray;
21
//} fileheader;
22
//typedef struct{
23
// uint32_t dibheadersize;
24
// uint32_t width;
25
// uint32_t height;
26
// uint16_t planes;
27
// uint16_t bitsperpixel;
28
// uint32_t compression;
29
// uint32_t imagesize;
30
// uint32_t ypixelpermeter;
31
// uint32_t xpixelpermeter;
32
// uint32_t numcolorspallette;
33
// uint32_t mostimpcolor;
34
//} bitmapinfoheader;
36
//typedef struct{
37
// uint8_t rgbBlue;
38
// uint8_t rgbGreen;
39
// uint8_t rgbRed;
40
// uint8_t rgbReserved;
41
//} rgbquad;
42
//typedef struct {
43
// fileheader fileheader;
44
// bitmapinfoheader bitmapinfoheader;
45
// rgbquad rgbquad[256]; // 8ºñÆ® 256Ä®¶ó(Èæ¹é)
46
//} bitmap;
47
//#pragma pack(pop)
48
49
namespace
oph
50
{
51
//int createBitmapFile(unsigned char* pixelbuffer, int pic_width, int pic_height, uint16_t bitsperpixel, const char* file_name) {
52
53
// int _height = pic_height;
54
// int _width = pic_width;
55
// int _pixelbytesize = _height * _width*bitsperpixel / 8;
56
// int _filesize = _pixelbytesize + sizeof(bitmap);
57
58
// char bmpFile[256];
59
// std::string fname(file_name);
60
// int pos = fname.find(".bmp");
61
// if (pos == std::string::npos)
62
// sprintf_s(bmpFile, "%s.bmp", fname.c_str());
63
// else
64
// {
65
// if (strcmp(fname.substr(pos).c_str(), ".bmp") == 0)
66
// sprintf_s(bmpFile, "%s", fname.c_str());
67
// else
68
// sprintf_s(bmpFile, "%s.bmp", fname.c_str());
69
// }
70
71
72
// FILE *fp;
73
// fopen_s(&fp, bmpFile, "wb");
74
// bitmap *pbitmap = (bitmap*)calloc(1, sizeof(bitmap));
75
// memset(pbitmap, 0x00, sizeof(bitmap));
76
77
// // ÆÄÀÏÇì´õ // pbitmap->fileheader.signature[0] = 'B'; // pbitmap->fileheader.signature[1] = 'M'; // pbitmap->fileheader.filesize = _filesize; // pbitmap->fileheader.fileoffset_to_pixelarray = sizeof(bitmap); // // ÆÈ·¹Æ® ÃʱâÈ: Èæ¹éÀ¸·Î ¸¸µé¾î ÁÝ´Ï´Ù. // for (int i = 0; i < 256; i++) { // pbitmap->rgbquad[i].rgbBlue = i; // pbitmap->rgbquad[i].rgbGreen = i; // pbitmap->rgbquad[i].rgbRed = i; // } // // À̹ÌÁö Çì´õ // pbitmap->bitmapinfoheader.dibheadersize = sizeof(bitmapinfoheader); // pbitmap->bitmapinfoheader.width = _width; // pbitmap->bitmapinfoheader.height = _height; // pbitmap->bitmapinfoheader.planes = _planes; // pbitmap->bitmapinfoheader.bitsperpixel = bitsperpixel; // pbitmap->bitmapinfoheader.compression = _compression; // pbitmap->bitmapinfoheader.imagesize = _pixelbytesize; // pbitmap->bitmapinfoheader.ypixelpermeter = _ypixelpermeter; // pbitmap->bitmapinfoheader.xpixelpermeter = _xpixelpermeter; // pbitmap->bitmapinfoheader.numcolorspallette = 256; // fwrite(pbitmap, 1, sizeof(bitmap), fp); // // data upside down // //unsigned char* img_tmp = (unsigned char*)malloc(sizeof(unsigned char)*_pixelbytesize); // //int rowsz = _width * (bitsperpixel / 8); // //for (int k = 0; k < _pixelbytesize; k++) // //{ // // int r = k / rowsz; // // int c = k % rowsz; // // img_tmp[(_height - r - 1)*rowsz + c] = pixelbuffer[r*rowsz + c]; // //} // fwrite(pixelbuffer, 1, _pixelbytesize, fp); // fclose(fp); // free(pbitmap); // return 1; //} //int getBitmapSize(int& w, int& h, int& bytesperpixel, const char* file_name) //{ // char bmpFile[256]; // sprintf_s(bmpFile, "%s", file_name); // FILE *infile; // fopen_s(&infile, bmpFile, "rb"); // if (infile == NULL) { printf("No Image File"); return 0; } // // BMP Header Information // fileheader hf; // bitmapinfoheader hInfo; // fread(&hf, sizeof(fileheader), 1, infile); // if (hf.signature[0] != 'B' || hf.signature[1] != 'M') return 0; // fread(&hInfo, sizeof(bitmapinfoheader), 1, infile); // //if (hInfo.bitsperpixel != 8) { printf("Bad File Format!!"); return 0; } // w = hInfo.width; // h = hInfo.height; // bytesperpixel = hInfo.bitsperpixel / 8; // fclose(infile); // return 1; //} //int loadBitmapFile(unsigned char* pixelbuffer, const char* file_name) //{ // char bmpFile[256]; // std::string fname(file_name); // int pos = fname.find(".bmp"); // if (pos == std::string::npos) // sprintf_s(bmpFile, "%s.bmp", fname.c_str()); // else // { // if (strcmp(fname.substr(pos).c_str(), ".bmp") == 0) // sprintf_s(bmpFile, "%s", fname.c_str()); // else // sprintf_s(bmpFile, "%s.bmp", fname.c_str()); // } // FILE *infile; // fopen_s(&infile, bmpFile, "rb"); // if (infile == NULL) { printf("No Image File"); return 0; } // // BMP Header Information // fileheader hf; // bitmapinfoheader hInfo; // fread(&hf, sizeof(fileheader), 1, infile); // if (hf.signature[0] != 'B' || hf.signature[1] != 'M') return 0; // fread(&hInfo, sizeof(bitmapinfoheader), 1, infile); // //if (hInfo.bitsperpixel != 8) { printf("Bad File Format!!"); return 0; } // // BMP Pallete // //rgbquad hRGB[256]; // //fread(hRGB, sizeof(rgbquad), 256, infile); // // Memory // fseek(infile, hf.fileoffset_to_pixelarray, SEEK_SET); // unsigned char* img_tmp; // if (hInfo.imagesize == 0) // { // img_tmp = (unsigned char*)malloc(sizeof(unsigned char)*hInfo.width*hInfo.height*(hInfo.bitsperpixel / 8)); // fread(img_tmp, sizeof(char), hInfo.width*hInfo.height*(hInfo.bitsperpixel / 8), infile); // } // else { // img_tmp = (unsigned char*)malloc(hInfo.imagesize); // fread(img_tmp, sizeof(char), hInfo.imagesize, infile); // } // fclose(infile); // // data upside down // int bytesperpixel = hInfo.bitsperpixel / 8; // int rowsz = bytesperpixel * hInfo.width; // for (int k = 0; k < hInfo.height*rowsz; k++) // { // int r = k / rowsz; // int c = k % rowsz; // pixelbuffer[(hInfo.height - r - 1)*rowsz + c] = img_tmp[r*rowsz + c]; // } // free(img_tmp); // return 1; //} //void convertToFormatGray8(unsigned char* img, unsigned char* imgload, int w, int h, int bytesperpixel) //{ // int idx = 0; // unsigned int r, g, b; // for (int i = 0; i < w*h*bytesperpixel; i++) // { // unsigned int r = imgload[i + 0]; // unsigned int g = imgload[i + 1]; // unsigned int b = imgload[i + 2]; // img[idx++] = (r + g + b) / 3; // i += bytesperpixel - 1; // } //} //void imgScaleBilnear(unsigned char* src, unsigned char* dst, int w, int h, int neww, int newh) //{ // for (int y = 0; y < newh; y++) // { // for (int x = 0; x < neww; x++) // { // float gx = (x / (float)neww) * (w - 1); // float gy = (y / (float)newh) * (h - 1); // int gxi = (int)gx; // int gyi = (int)gy; // uint32_t a00 = src[gxi + 0 + gyi * w]; // uint32_t a01 = src[gxi + 1 + gyi * w]; // uint32_t a10 = src[gxi + 0 + (gyi + 1)*w]; // uint32_t a11 = src[gxi + 1 + (gyi + 1)*w]; // float dx = gx - gxi; // float dy = gy - gyi; // dst[x + y * neww] = a00 * (1 - dx)*(1 - dy) + a01 * dx*(1 - dy) + a10 * (1 - dx)*dy + a11 * dx*dy; // } // } //} } #endif // !__Bitmap_h
78
// pbitmap->fileheader.signature[0] = 'B';
79
// pbitmap->fileheader.signature[1] = 'M';
80
// pbitmap->fileheader.filesize = _filesize;
81
// pbitmap->fileheader.fileoffset_to_pixelarray = sizeof(bitmap);
82
83
// // ÆÈ·¹Æ® ÃʱâÈ: Èæ¹éÀ¸·Î ¸¸µé¾î ÁÝ´Ï´Ù.
84
// for (int i = 0; i < 256; i++) {
85
// pbitmap->rgbquad[i].rgbBlue = i;
86
// pbitmap->rgbquad[i].rgbGreen = i;
87
// pbitmap->rgbquad[i].rgbRed = i;
88
// }
89
// // À̹ÌÁö Çì´õ // pbitmap->bitmapinfoheader.dibheadersize = sizeof(bitmapinfoheader); // pbitmap->bitmapinfoheader.width = _width; // pbitmap->bitmapinfoheader.height = _height; // pbitmap->bitmapinfoheader.planes = _planes; // pbitmap->bitmapinfoheader.bitsperpixel = bitsperpixel; // pbitmap->bitmapinfoheader.compression = _compression; // pbitmap->bitmapinfoheader.imagesize = _pixelbytesize; // pbitmap->bitmapinfoheader.ypixelpermeter = _ypixelpermeter; // pbitmap->bitmapinfoheader.xpixelpermeter = _xpixelpermeter; // pbitmap->bitmapinfoheader.numcolorspallette = 256; // fwrite(pbitmap, 1, sizeof(bitmap), fp); // // data upside down // //unsigned char* img_tmp = (unsigned char*)malloc(sizeof(unsigned char)*_pixelbytesize); // //int rowsz = _width * (bitsperpixel / 8); // //for (int k = 0; k < _pixelbytesize; k++) // //{ // // int r = k / rowsz; // // int c = k % rowsz; // // img_tmp[(_height - r - 1)*rowsz + c] = pixelbuffer[r*rowsz + c]; // //} // fwrite(pixelbuffer, 1, _pixelbytesize, fp); // fclose(fp); // free(pbitmap); // return 1; //} //int getBitmapSize(int& w, int& h, int& bytesperpixel, const char* file_name) //{ // char bmpFile[256]; // sprintf_s(bmpFile, "%s", file_name); // FILE *infile; // fopen_s(&infile, bmpFile, "rb"); // if (infile == NULL) { printf("No Image File"); return 0; } // // BMP Header Information // fileheader hf; // bitmapinfoheader hInfo; // fread(&hf, sizeof(fileheader), 1, infile); // if (hf.signature[0] != 'B' || hf.signature[1] != 'M') return 0; // fread(&hInfo, sizeof(bitmapinfoheader), 1, infile); // //if (hInfo.bitsperpixel != 8) { printf("Bad File Format!!"); return 0; } // w = hInfo.width; // h = hInfo.height; // bytesperpixel = hInfo.bitsperpixel / 8; // fclose(infile); // return 1; //} //int loadBitmapFile(unsigned char* pixelbuffer, const char* file_name) //{ // char bmpFile[256]; // std::string fname(file_name); // int pos = fname.find(".bmp"); // if (pos == std::string::npos) // sprintf_s(bmpFile, "%s.bmp", fname.c_str()); // else // { // if (strcmp(fname.substr(pos).c_str(), ".bmp") == 0) // sprintf_s(bmpFile, "%s", fname.c_str()); // else // sprintf_s(bmpFile, "%s.bmp", fname.c_str()); // } // FILE *infile; // fopen_s(&infile, bmpFile, "rb"); // if (infile == NULL) { printf("No Image File"); return 0; } // // BMP Header Information // fileheader hf; // bitmapinfoheader hInfo; // fread(&hf, sizeof(fileheader), 1, infile); // if (hf.signature[0] != 'B' || hf.signature[1] != 'M') return 0; // fread(&hInfo, sizeof(bitmapinfoheader), 1, infile); // //if (hInfo.bitsperpixel != 8) { printf("Bad File Format!!"); return 0; } // // BMP Pallete // //rgbquad hRGB[256]; // //fread(hRGB, sizeof(rgbquad), 256, infile); // // Memory // fseek(infile, hf.fileoffset_to_pixelarray, SEEK_SET); // unsigned char* img_tmp; // if (hInfo.imagesize == 0) // { // img_tmp = (unsigned char*)malloc(sizeof(unsigned char)*hInfo.width*hInfo.height*(hInfo.bitsperpixel / 8)); // fread(img_tmp, sizeof(char), hInfo.width*hInfo.height*(hInfo.bitsperpixel / 8), infile); // } // else { // img_tmp = (unsigned char*)malloc(hInfo.imagesize); // fread(img_tmp, sizeof(char), hInfo.imagesize, infile); // } // fclose(infile); // // data upside down // int bytesperpixel = hInfo.bitsperpixel / 8; // int rowsz = bytesperpixel * hInfo.width; // for (int k = 0; k < hInfo.height*rowsz; k++) // { // int r = k / rowsz; // int c = k % rowsz; // pixelbuffer[(hInfo.height - r - 1)*rowsz + c] = img_tmp[r*rowsz + c]; // } // free(img_tmp); // return 1; //} //void convertToFormatGray8(unsigned char* img, unsigned char* imgload, int w, int h, int bytesperpixel) //{ // int idx = 0; // unsigned int r, g, b; // for (int i = 0; i < w*h*bytesperpixel; i++) // { // unsigned int r = imgload[i + 0]; // unsigned int g = imgload[i + 1]; // unsigned int b = imgload[i + 2]; // img[idx++] = (r + g + b) / 3; // i += bytesperpixel - 1; // } //} //void imgScaleBilnear(unsigned char* src, unsigned char* dst, int w, int h, int neww, int newh) //{ // for (int y = 0; y < newh; y++) // { // for (int x = 0; x < neww; x++) // { // float gx = (x / (float)neww) * (w - 1); // float gy = (y / (float)newh) * (h - 1); // int gxi = (int)gx; // int gyi = (int)gy; // uint32_t a00 = src[gxi + 0 + gyi * w]; // uint32_t a01 = src[gxi + 1 + gyi * w]; // uint32_t a10 = src[gxi + 0 + (gyi + 1)*w]; // uint32_t a11 = src[gxi + 1 + (gyi + 1)*w]; // float dx = gx - gxi; // float dy = gy - gyi; // dst[x + y * neww] = a00 * (1 - dx)*(1 - dy) + a01 * dx*(1 - dy) + a10 * (1 - dx)*dy + a11 * dx*dy; // } // } //} } #endif // !__Bitmap_h
90
// pbitmap->bitmapinfoheader.dibheadersize = sizeof(bitmapinfoheader);
91
// pbitmap->bitmapinfoheader.width = _width;
92
// pbitmap->bitmapinfoheader.height = _height;
93
// pbitmap->bitmapinfoheader.planes = _planes;
94
// pbitmap->bitmapinfoheader.bitsperpixel = bitsperpixel;
95
// pbitmap->bitmapinfoheader.compression = _compression;
96
// pbitmap->bitmapinfoheader.imagesize = _pixelbytesize;
97
// pbitmap->bitmapinfoheader.ypixelpermeter = _ypixelpermeter;
98
// pbitmap->bitmapinfoheader.xpixelpermeter = _xpixelpermeter;
99
// pbitmap->bitmapinfoheader.numcolorspallette = 256;
100
// fwrite(pbitmap, 1, sizeof(bitmap), fp);
101
102
// // data upside down
103
// //unsigned char* img_tmp = (unsigned char*)malloc(sizeof(unsigned char)*_pixelbytesize);
104
// //int rowsz = _width * (bitsperpixel / 8);
105
// //for (int k = 0; k < _pixelbytesize; k++)
106
// //{
107
// // int r = k / rowsz;
108
// // int c = k % rowsz;
109
// // img_tmp[(_height - r - 1)*rowsz + c] = pixelbuffer[r*rowsz + c];
110
// //}
111
112
113
// fwrite(pixelbuffer, 1, _pixelbytesize, fp);
114
// fclose(fp);
115
// free(pbitmap);
116
// return 1;
117
//}
118
119
//int getBitmapSize(int& w, int& h, int& bytesperpixel, const char* file_name)
120
//{
121
// char bmpFile[256];
122
// sprintf_s(bmpFile, "%s", file_name);
123
// FILE *infile;
124
// fopen_s(&infile, bmpFile, "rb");
125
// if (infile == NULL) { printf("No Image File"); return 0; }
126
127
// // BMP Header Information
128
// fileheader hf;
129
// bitmapinfoheader hInfo;
130
// fread(&hf, sizeof(fileheader), 1, infile);
131
// if (hf.signature[0] != 'B' || hf.signature[1] != 'M') return 0;
132
// fread(&hInfo, sizeof(bitmapinfoheader), 1, infile);
133
// //if (hInfo.bitsperpixel != 8) { printf("Bad File Format!!"); return 0; }
134
135
// w = hInfo.width;
136
// h = hInfo.height;
137
// bytesperpixel = hInfo.bitsperpixel / 8;
138
139
// fclose(infile);
140
141
// return 1;
142
143
//}
144
145
//int loadBitmapFile(unsigned char* pixelbuffer, const char* file_name)
146
//{
147
// char bmpFile[256];
148
149
// std::string fname(file_name);
150
// int pos = fname.find(".bmp");
151
// if (pos == std::string::npos)
152
// sprintf_s(bmpFile, "%s.bmp", fname.c_str());
153
// else
154
// {
155
// if (strcmp(fname.substr(pos).c_str(), ".bmp") == 0)
156
// sprintf_s(bmpFile, "%s", fname.c_str());
157
// else
158
// sprintf_s(bmpFile, "%s.bmp", fname.c_str());
159
// }
160
161
// FILE *infile;
162
// fopen_s(&infile, bmpFile, "rb");
163
// if (infile == NULL) { printf("No Image File"); return 0; }
164
165
// // BMP Header Information
166
// fileheader hf;
167
// bitmapinfoheader hInfo;
168
// fread(&hf, sizeof(fileheader), 1, infile);
169
// if (hf.signature[0] != 'B' || hf.signature[1] != 'M') return 0;
170
// fread(&hInfo, sizeof(bitmapinfoheader), 1, infile);
171
// //if (hInfo.bitsperpixel != 8) { printf("Bad File Format!!"); return 0; }
172
173
// // BMP Pallete
174
// //rgbquad hRGB[256];
175
// //fread(hRGB, sizeof(rgbquad), 256, infile);
176
177
// // Memory
178
// fseek(infile, hf.fileoffset_to_pixelarray, SEEK_SET);
179
180
// unsigned char* img_tmp;
181
// if (hInfo.imagesize == 0)
182
// {
183
// img_tmp = (unsigned char*)malloc(sizeof(unsigned char)*hInfo.width*hInfo.height*(hInfo.bitsperpixel / 8));
184
// fread(img_tmp, sizeof(char), hInfo.width*hInfo.height*(hInfo.bitsperpixel / 8), infile);
185
// }
186
// else {
187
// img_tmp = (unsigned char*)malloc(hInfo.imagesize);
188
// fread(img_tmp, sizeof(char), hInfo.imagesize, infile);
189
// }
190
// fclose(infile);
191
192
// // data upside down
193
// int bytesperpixel = hInfo.bitsperpixel / 8;
194
// int rowsz = bytesperpixel * hInfo.width;
195
196
// for (int k = 0; k < hInfo.height*rowsz; k++)
197
// {
198
// int r = k / rowsz;
199
// int c = k % rowsz;
200
// pixelbuffer[(hInfo.height - r - 1)*rowsz + c] = img_tmp[r*rowsz + c];
201
// }
202
203
// free(img_tmp);
204
// return 1;
205
206
//}
207
208
//void convertToFormatGray8(unsigned char* img, unsigned char* imgload, int w, int h, int bytesperpixel)
209
//{
210
// int idx = 0;
211
// unsigned int r, g, b;
212
// for (int i = 0; i < w*h*bytesperpixel; i++)
213
// {
214
// unsigned int r = imgload[i + 0];
215
// unsigned int g = imgload[i + 1];
216
// unsigned int b = imgload[i + 2];
217
// img[idx++] = (r + g + b) / 3;
218
// i += bytesperpixel - 1;
219
// }
220
//}
221
222
//void imgScaleBilnear(unsigned char* src, unsigned char* dst, int w, int h, int neww, int newh)
223
//{
224
// for (int y = 0; y < newh; y++)
225
// {
226
// for (int x = 0; x < neww; x++)
227
// {
228
// float gx = (x / (float)neww) * (w - 1);
229
// float gy = (y / (float)newh) * (h - 1);
230
231
// int gxi = (int)gx;
232
// int gyi = (int)gy;
233
234
// uint32_t a00 = src[gxi + 0 + gyi * w];
235
// uint32_t a01 = src[gxi + 1 + gyi * w];
236
// uint32_t a10 = src[gxi + 0 + (gyi + 1)*w];
237
// uint32_t a11 = src[gxi + 1 + (gyi + 1)*w];
238
239
// float dx = gx - gxi;
240
// float dy = gy - gyi;
241
242
// dst[x + y * neww] = a00 * (1 - dx)*(1 - dy) + a01 * dx*(1 - dy) + a10 * (1 - dx)*dy + a11 * dx*dy;
243
244
// }
245
// }
246
//}
247
}
248
#endif // !__Bitmap_h
include.h
oph
Definition:
Bitmap.h:49
Openholo
Openholo
src
Bitmap.h
Generated by
1.8.14