Lecture bmp of C language

13
Bitmap Image. Embedded System Engineering

description

BMP lecture of C language

Transcript of Lecture bmp of C language

Page 1: Lecture bmp of C language

Bitmap Image.

Embedded System Engineer-ing

Page 2: Lecture bmp of C language

Bitmap Image : Bitmap Structure

File Header

Info Header

Opt. Palette

Image Data

BITMAPFILEHEADER

BITMAPINFOHEADER

RGBQUAD[n]

RGBTRIPLE[m]

Page 3: Lecture bmp of C language

Bitmap Image : File Header

File Header

Info Header

Opt. Palette

Image Data

14

40

4n

3m

BMRESERVED

Page 4: Lecture bmp of C language

Bitmap Image : Info Header

File Header

Info Header

Opt. Palette

Image Data

40

Width

Height

Page 5: Lecture bmp of C language

Bitmap Image : Image Data

Page 6: Lecture bmp of C language

Bitmap : Bitmap - Reading

File Header

Info Header

Image Data

#include <windows.h>

FILE *fp;BITMAPFILEHEADER bh;BITMAPINFOHEADER ih;RGBTRIPLE pixel;int i = 0;

if(!(fp = fopen("lena.bmp", "rb"))) return 0;

fread(&bh, sizeof(BITMAPFILEHEADER), 1, fp);fread(&ih, sizeof(BITMAPINFOHEADER), 1, fp);while(fread(&pixel, sizeof(RGBTRIPLE), 1, fp)){

printf("pixel #%5d: %02x %02x %02x\n", i++, pixel.rgbtBlue, pixel.rgbtGreen, pix-el.rgbtRed);}

printf("%d pixels read.\n", i);

Starting point!

Page 7: Lecture bmp of C language

Bitmap : Bitmap – Writing

File Header

Info Header

Image Data

FILE *fp;BITMAPFILEHEADER bh;BITMAPINFOHEADER ih;char pixel[60*30*3];int i;

for( i = 0 ; i < 60 * 30 * 3 ; i+=3 ){

// bluepixel[i] = 0xff;// greenpixel[i+1] = 0x00;// redpixel[i+2] = 0x00;

}

ih.biSize = sizeof(BITMAPINFOHEADER);ih.biWidth = 60;ih.biHeight = 30;ih.biPlanes = 1;ih.biBitCount = 24;ih.biCompression = 0;ih.biSizeImage = sizeof(pixel);ih.biXPelsPerMeter = ih.biYPelsPerMeter = 0;ih.biClrImportant = ih.biClrUsed = 0;

bh.bfType = 0x4d42;bh.bfSize = sizeof(BITMAPFILEHEADER) + sizeof(BITMAPINFOHEADER) + sizeof(pixel);bh.bfOffBits = sizeof(BITMAPFILEHEADER) + sizeof(BITMAPINFOHEADER);

if(!(fp = fopen("blue.bmp", "wb"))) return 0;

fwrite(&bh, sizeof(BITMAPFILEHEADER), 1, fp);fwrite(&ih, sizeof(BITMAPINFOHEADER), 1, fp);fwrite(&pixel, sizeof(pixel), 1, fp);

30

60

Page 8: Lecture bmp of C language

Bitmap : Practice #1

Inverting

Hint :: Each pixel data(R,G,B) ^ 0xff

Page 9: Lecture bmp of C language

Bitmap : Practice #2

Hint :: Red * 0.299, Green * 0.587, Blue * 0.114

Sepia effect

Page 10: Lecture bmp of C language

Bitmap : Practice #3

Draw the flag of NETHERLANDSize : 600 x 300

Page 11: Lecture bmp of C language

Bitmap : Practice #4

Draw the flag of FRANCESize : 600 x 300

Page 12: Lecture bmp of C language

Bitmap : Practice #5

In this square, there are some black pixels, how many pixels are there?And, where is location of pixels?

Page 13: Lecture bmp of C language

Bitmap : Practice #6

Rotation