#include "stdafx.h"
#include <stdio.h>
#include <fftw3.h>
#include <windows.h>
#define Kwidth 1024
#define Kheight 1024
#define Ksize 1024*1024
int _tmain(int argc, _TCHAR* argv[])
{
fftw_complex *V;
V = (fftw_complex*)fftw_malloc(sizeof(fftw_complex)*Ksize);
RGBQUAD rgb[256];
int a;
for(a=0; a<256; a++)
{
rgb[a].rgbBlue = a;
rgb[a].rgbGreen = a;
rgb[a].rgbRed = a;
rgb[a].rgbReserved = 0;
}
BITMAPFILEHEADER bmfh;
BITMAPINFOHEADER bmih;
FILE *fp = NULL;
fopen_s(&fp, "RGB256.bmp", "rb");
if(fp==NULL)
{
printf("画像の読み込みに失敗");
exit (-1); /*処理を継続できないので終了する*/
}
fread( &bmfh, sizeof(BITMAPFILEHEADER), 1, fp );
fread( &bmih, sizeof(BITMAPINFOHEADER), 1, fp );
fread( &rgb , sizeof(RGBQUAD)*256, 1 , fp );
int Inwidth,Inheight,Insize;
Inwidth = bmih.biWidth;
Inheight = bmih.biHeight;
Insize = Inwidth * Inheight;
unsigned char* in;
in = new unsigned char[Insize];
fread(in, Insize, 1, fp);
fclose(fp);
int e,x,y;
for (e=0; e<Ksize; e++)
{
V[e][0] = 0;
V[e][1] = 0;
}
int v;
a=0;
for (y=0; y<Kheight; y++)
{
for (x=0; x<Kwidth; x++)
{
if ( (640<=y) && (y<=768) )
{
if ( (384<=x) && (x<640) )
{
v = (int)( Kwidth*640 + 384 + Kwidth*y + x);
V[v][0] = in[a];
a++;
}
}
}
}
unsigned char *RV;
RV = new unsigned char[Ksize];
for (e=0; e<Ksize; e++)
{
RV[e] = V[e][0];
}
bmfh.bfType = 0x4D42;
bmfh.bfSize = 54+Ksize+(4*256);
bmfh.bfReserved1 = 0;
bmfh.bfReserved2 = 0;
bmfh.bfOffBits = 54+4*256;
bmih.biSize = 40;
bmih.biWidth = Kwidth;
bmih.biHeight = Kheight;
bmih.biPlanes = 1;
bmih.biBitCount = 8;
bmih.biCompression = 0;
bmih.biSizeImage = Ksize;
bmih.biXPelsPerMeter = 0;
bmih.biYPelsPerMeter = 0;
bmih.biClrUsed = 256;
bmih.biClrImportant = 0;
fopen_s(&fp, "RV.bmp" , "wb" );
fwrite( &bmfh , sizeof(BITMAPFILEHEADER) , 1 , fp );
fwrite( &bmih , sizeof(BITMAPINFOHEADER) , 1 , fp );
fwrite( &rgb , sizeof(RGBQUAD)*256 , 1 , fp );
fwrite( RV , 1 , Ksize , fp );
fclose( fp );
return 0;
}