#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#pragma pack(1)
int adjust_brightness = 100; //-255 .. +255
typedef struct
{
char signature[2];
unsigned int fileSize;
unsigned int reserved;
unsigned int offset;
unsigned int headerSize;
unsigned int width;
unsigned int height;
unsigned short planeCount;
unsigned short bitDepth;
unsigned int compression;
unsigned int compressedImageSize;
unsigned int horizontalResolution;
unsigned int verticalResolution;
unsigned int numColors;
unsigned int importantColors;
} BmpHeader;
int main(int argc, char **argv) {
FILE *inFile,*outFile;
long bytesPerLine;
BmpHeader header;
unsigned char *line;
inFile = fopen( "aa.bmp", "rb" );
if( !inFile ) {
printf( "Error opening file %s.\n", argv[1] );
return -1;
}
if( fread(&header, 1, sizeof(BmpHeader), inFile) != sizeof(BmpHeader) ) {
printf( "Error reading bmp header.\n" );
return -1;
}
bytesPerLine = (3 * (header.width + 1) / 4) * 4;
outFile = fopen( "bb.bmp", "wb" );
if( !outFile ) {
printf( "Error opening outputfile.\n" );
return -1;
}
fwrite(&header,1,sizeof(BmpHeader),outFile);
line = new unsigned char[bytesPerLine];
for (int i = 0; i < header.height; i++)
{
fread(line, 1, bytesPerLine, inFile);
for (int j=0; j<bytesPerLine; j++)
{
if (line[j]+adjust_brightness > 255) line[j]=255;
else if (line[j]+adjust_brightness < 0) line[j]=0;
else line[j]=line[j]+adjust_brightness;
}
fwrite(line, bytesPerLine, 1, outFile);
}
printf( "Done.\n" );
fclose(inFile);
fclose(outFile);
printf( "\nBMP-Info:\n" );
printf( "Width x Height: %i x %i\n", header.width, header.height );
printf( "Depth: %i\n", (int)header.bitDepth );
free(line);
return 0;
}
Если Вы уже зарегистрированы на Портале - войдите в систему, если Вы еще не регистрировались - пройдите простую процедуру регистрации.