반응형

#include <string.h>
#include <stdio.h>
#include <stdlib.h>
#include <stdint.h>


#pragma warning(disable:4996)
#define _CRT_SECURE_NO_WARNINGS

typedef uint8_t  BYTE;
typedef uint32_t DWORD;
typedef int32_t  LONG;
typedef uint16_t WORD;


/*********************************************************STRUCTS***********************************************************/
#pragma pack(push, 1)
typedef struct tagBITMAPFILEHEADER
{
WORD bfType;  //specifies the file type
DWORD bfSize;  //specifies the size in bytes of the bitmap file
WORD bfReserved1;  //reserved; must be 0
WORD bfReserved2;  //reserved; must be 0
DWORD bfOffBits;  //species the offset in bytes from the bitmapfileheader to the bitmap bits
}BITMAPFILEHEADER;


typedef struct tagBITMAPINFOHEADER
{
DWORD biSize;  //specifies the number of bytes required by the struct
LONG biWidth;  //specifies width in pixels
LONG biHeight;  //species height in pixels
WORD biPlanes; //specifies the number of color planes, must be 1
WORD biBitCount; //specifies the number of bit per pixel
DWORD biCompression;//specifies the type of compression
DWORD biSizeImage;  //size of image in bytes
LONG biXPelsPerMeter;  //number of pixels per meter in x axis
LONG biYPelsPerMeter;  //number of pixels per meter in y axis
DWORD biClrUsed;  //number of colors used by the bitmap
DWORD biClrImportant;  //number of colors that are important
}BITMAPINFOHEADER;

typedef struct
{
BYTE  rgbtBlue;
BYTE  rgbtGreen;
BYTE  rgbtRed;
}RGBTRIPLE;

typedef struct
{
BYTE hslHue;
BYTE hslSaturation;
BYTE hslLightness;
}HSL;
#pragma pack(pop)
/*********************************************************STRUCTS***********************************************************/

#define filterWidth 3
#define filterHeight 3

void Filters(int biHeight, int biWidth, RGBTRIPLE** triple);
int CopyBitmapFile(char* filename, BITMAPINFOHEADER* bitmapInfoHeader, char* copy_filename);

int main()
{
char image[80], image_copy[80];
printf("원본 이미지 파일 : ");
scanf("%s", image);

printf("편집 이미지 파일 : ");
scanf("%s", image_copy);


BITMAPINFOHEADER bitmapInfoHeader;
memset(&bitmapInfoHeader, 0, sizeof(BITMAPINFOHEADER));
CopyBitmapFile(image, &bitmapInfoHeader, image_copy);

}


int CopyBitmapFile(char* filename, BITMAPINFOHEADER* bitmapInfoHeader, char* copy_filename)
{
int i, j, k;
FILE* filePtr; 
BITMAPFILEHEADER bitmapFileHeader; 
memset(&bitmapFileHeader, 0, sizeof(BITMAPFILEHEADER));

filePtr = fopen(filename, "rb");
if (filePtr == NULL)
return 1;

FILE* outptr = fopen(copy_filename, "wb");
if (outptr == NULL)
{
fclose(filePtr);
fprintf(stderr, "Could not create %s.\n", copy_filename);
return 2;
}


fread(&bitmapFileHeader, sizeof(BITMAPFILEHEADER), 1, filePtr);

if (bitmapFileHeader.bfType != 0x4D42)
{
printf("이미지 파일 찾을 수 없엉");
fclose(filePtr);
fclose(outptr);
return 3;
}


fread(bitmapInfoHeader, sizeof(BITMAPINFOHEADER), 1, filePtr);


fwrite(&bitmapFileHeader, sizeof(BITMAPFILEHEADER), 1, outptr);

fwrite(bitmapInfoHeader, sizeof(BITMAPINFOHEADER), 1, outptr);

int padding = (4 - (bitmapInfoHeader->biWidth * sizeof(RGBTRIPLE)) % 4) % 4;

int biHeight = abs(bitmapInfoHeader->biHeight);
int biWidth = bitmapInfoHeader->biWidth;

RGBTRIPLE** triple;
triple = (RGBTRIPLE**)malloc(sizeof(RGBTRIPLE*) * biHeight);
int ii;
for (ii = 0; ii < biHeight; ii++)
{
triple[ii] = (RGBTRIPLE*)malloc(sizeof(RGBTRIPLE) * biWidth);
}


for (i = 0; i < biHeight; i++)
{
for (j = 0; j < biWidth; j++)
{
fread(&triple[i][j], sizeof(RGBTRIPLE), 1, filePtr);
}
}



for (i = 0; i < biHeight; i++)
{
for (j = 0; j < biWidth; j++)
{
// brighter image
int x, y, z;
x = triple[i][j].rgbtBlue  + 75;
y = triple[i][j].rgbtGreen + 75;
z = triple[i][j].rgbtRed + 75;
triple[i][j].rgbtBlue = ((x > 255) ? 255 : x);
triple[i][j].rgbtGreen = ((y > 255) ? 255 : y);
triple[i][j].rgbtRed = ((z > 255) ? 255 : z);
}
}

for (i = 0; i < biHeight; i++)
{
for (j = 0; j < biWidth; j++)
{

fwrite(&triple[i][j], sizeof(RGBTRIPLE), 1, outptr);
}

fseek(filePtr, padding, SEEK_CUR);

for (k = 0; k < padding; k++)
{
fputc(0x00, outptr);
}
}

fclose(filePtr);
fclose(outptr);

for(int p = 0; p < biHeight; p++ )
{
free(triple[p]);
}
free(triple);

return 0;
}

728x90
반응형

+ Recent posts