⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 dat2bmp.cpp

📁 在dsp6416上执行BMP到数据格式的转换.已经经过调试.
💻 CPP
字号:
/************************************************
* DAT2BMP.CPP *
*************************************************/
#include <stdlib.h>
#include <stdio.h>
typedef struct byte5 /* DSP OUTPUT DATA FILE FORMAT */
{
char byte0; /* example : 0023 */
char byte1; /* byte0='0', byte1='0' */
char byte2; /* byte2='2', byte3='3' */
char byte3; /* enter occupy one byte */
char enter;
} byte5;
int main()
{
FILE *ifp, *ofp;
char rfile[35],gfile[35],bfile[35],outfile[35];
int i=0;
byte5 b[76800], g[76800], r[76800]; /* Image Size = 160*120 */
char otemp[230400]; /* Image Size*3 = 160*120*3 bytes */
char bmpheader[54]= /* BMP FILE HEADER 54 BYTES */
{0x42, 0x4d, /* bfType = 'BM' */
0x36, 0x84, 0x03, 0x00, /*bfSize = 57654 */
0x00, 0x00, /* bfReserved1 = 0 */
0x00, 0x00, /* bfReserved2 = 0 */
0x36, 0x00, 0x00, 0x00, /* bf0ffBits =54 */
0x28, 0x00, 0x00, 0x00, /* biSize = 40 */
0x40, 0x01, 0x00, 0x00, /* biWidth = 160 */
0xf0, 0x00, 0x00, 0x00, /* biHeight = 120 */
0x01, 0x00, /* biPlanes = 1 */
0x18, 0x00, /* biBitCount = 24 */
0x00, 0x00, 0x00, 0x00, /* biCompression = 0 */
0x00, 0x84, 0x03, 0x00, /* biSizeImageSize = 57600*/
0xc4, 0x0e, 0x00, 0x00, /* biXpelsPerMeter = 3780*/
0xc4, 0x0e, 0x00, 0x00, /* biYpelsPerMeter = 3780*/
0x00, 0x00, 0x00, 0x00, /* biClrUsed = 0 */
0x00, 0x00, 0x00, 0x00 /* biClrImportant = 0 */
};
//--------------------------------------------
// GET DATA FROM 3 DSP OUTPUT DAT FILES
//--------------------------------------------
printf("\nEnter R data filename: ");
scanf("%s", &rfile);
printf("\nEnter G data filename: ");
scanf("%s", &gfile);
printf("\nEnter B data filename: ");
scanf("%s", &bfile);
printf("\nEnter BMP filename(*.bmp): ");
scanf("%s", &outfile);
if ((ifp=fopen(bfile,"r"))==NULL)
{ printf("Cannot open file test.in\n");
exit(1);
};
fread(b, 5, 76800, ifp);
fclose(ifp);
if ((ifp=fopen(gfile,"r"))==NULL)
{ printf("Cannot open file test.in\n");
exit(1);
};
fread(g, 5, 76800, ifp);
fclose(ifp);
if ((ifp=fopen(rfile,"r"))==NULL)
{ printf("Cannot open file test.in\n");
exit(1);
};
fread(r, 5, 76800, ifp);
fclose(ifp);
//--------------------------------------------
// DATA TRANSFORMATION : From string to hex
// example: '0023' -> 23h
//--------------------------------------------
for (i=0;i<76800;i++) /* The order of ouput data is B G R */
{
//---------------------------------------------------------
if ((b[i].byte2 >= 48) && (b[i].byte2 <= 57))
otemp[3*i] = 16*(b[i].byte2-48);
if ((b[i].byte2 >= 65) && (b[i].byte2 <= 70))
otemp[3*i] = 16*(b[i].byte2-65+10);
if ((b[i].byte2 >= 97) && (b[i].byte2 <= 102))
otemp[3*i] = 16*(b[i].byte2-97+10);
if ((b[i].byte3 >= 48) && (b[i].byte3 <= 57))
otemp[3*i] = otemp[3*i] + (b[i].byte3-48);
if ((b[i].byte3 >= 65) && (b[i].byte3 <= 70))
otemp[3*i] = otemp[3*i] + (b[i].byte3-65+10);
if ((b[i].byte3 >= 97) && (b[i].byte3 <= 102))
otemp[3*i] = otemp[3*i] + (b[i].byte3-97+10);
//---------------------------------------------------------
if ((g[i].byte2 >= 48) && (g[i].byte2 <= 57))
otemp[3*i+1] = 16*(g[i].byte2-48);
if ((g[i].byte2 >= 65) && (g[i].byte2 <= 70))
otemp[3*i+1] = 16*(g[i].byte2-65+10);
if ((g[i].byte2 >= 97) && (g[i].byte2 <= 102))
otemp[3*i+1] = 16*(g[i].byte2-97+10);
if ((g[i].byte3 >= 48) && (g[i].byte3 <= 57))
otemp[3*i+1] = otemp[3*i+1] + (g[i].byte3-48);
if ((g[i].byte3 >= 65) && (g[i].byte3 <= 70))
otemp[3*i+1] = otemp[3*i+1] + (g[i].byte3-65+10);
if ((g[i].byte3 >= 97) && (g[i].byte3 <= 102))
otemp[3*i+1] = otemp[3*i+1] + (g[i].byte3-97+10);
//---------------------------------------------------------
if ((r[i].byte2 >= 48) && (r[i].byte2 <= 57))
otemp[3*i+2] = 16*(r[i].byte2-48);
if ((r[i].byte2 >= 65) && (r[i].byte2 <= 70))
otemp[3*i+2] = 16*(r[i].byte2-65+10);
if ((r[i].byte2 >= 97) && (r[i].byte2 <= 102))
otemp[3*i+2] = 16*(r[i].byte2-97+10);
if ((r[i].byte3 >= 48) && (r[i].byte3 <= 57))
otemp[3*i+2] = otemp[3*i+2] + (r[i].byte3-48);
if ((r[i].byte3 >= 65) && (r[i].byte3 <= 70))
otemp[3*i+2] = otemp[3*i+2] + (r[i].byte3-65+10);
if ((r[i].byte3 >= 97) && (r[i].byte3 <= 102))
otemp[3*i+2] = otemp[3*i+2] + (r[i].byte3-97+10);
}
//--------------------------------------------
// RESTORE TRANSFERED DATA TO AN BMP FILE
//--------------------------------------------
if ((ofp=fopen(outfile,"w"))==NULL)
{ printf("Cannot open output file \n");
exit(1);
}
fwrite(bmpheader, 1, 54, ofp); /* bit map file header */
fwrite(otemp, 1, 230400, ofp); /* bit map file BGR data */
fclose(ofp);
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -