You are on page 1of 22

LOGO

FILE BITMAP & LOAD FILE BITMAP


TRN T-ENGINE

Nhm thc hin :


1.Nguyn Th Hu Hng
50701036
2.Nguyn An Huy
50700932

Contents

Cu trc file bitmap

Load file bitmap trn T-Engine

Q&A

File bitmap & load file bitmap

Cu trc file bitmap


File Bitmap : mt chun file nh ca
Windown 3.0
Cc tp tin bitmap c lu di 2
dng file :
.bmp
.dib (Device Indepentdent Bitmap)

File bitmap & load file bitmap

Cu trc file bitmap


1

S bit
trn mi
im nh

Chiu cao
ca nh

Chiu rng
ca nh

(bit per pixel)

(height)

(width)

Cc thuc tnh tiu biu ca mt file .bmp


4

File bitmap & load file bitmap

Cu trc file bitmap


S bit trn mi im nh (bit per pixel)
Mt nh bmp c n-bit c 2^n mu
Gi tr n cng ln th nh cng c nhiu mu v
cng r nt
Gi tr tiu biu ca n :
n = 1 : nh 2 mu en trng (1 bit per 1 pixel)
n = 8 : nh 256 mu (8 bit per pixel)

Mt nh bmp c gi tr n trong khong (1 24)


5

File bitmap & load file bitmap

Cu trc file bitmap

14 bytes

Bitmap Header

40 bytes

Bitmap Information

4*x bytes
(x l s mu)

D liu nh

Color Palette

Bitmap Data

Cu trc file bmp gm 4 phn


6

File bitmap & load file bitmap

Cu trc file bitmap


Cu trc header file
{

bfType[2] : File type .Set to BM


bfSize[4] : Size in BYTES of the
file
bfReserved1[2] : Reserved .Set
to zero
bfReserved2[2] : Reserved .Set
to zero
bfOffBits[4] : Offset to the data

typedef struct
{
char
unsigned char
unsigned char
unsigned char
unsigned char

bfType[2];
bfSize[4];
bfReserved1[2];
bfReserved2[2];
bfOffBits[4];

} bmfh;

} bmfh;

Bitmap Header
7

File bitmap & load file bitmap

Cu trc file bitmap


Cu trc header nh
{

biSize[4] : Size of rest of header.


Set to 40
biWidth[4] : Width of bitmap in pixels
biHeight[4] : Height of bitmap in pixels
biPlanes[2] : Number of Planes
Set to 1
biBitCount[2] : Number of bits per
pixel
stuff1[16] :
biClrUsed[4] : Number of color used
biClrImportant[4] : Number of
Important color
} bmih;

typedef struct
{
unsigned char biSize[4];
unsigned char biWidth[4];
unsigned char biHeight[4];
unsigned char biPlanes[2];
unsigned char biBitCount[2];
unsigned char stuff1[16];
unsigned char biClrUsed[4];
unsigned char
biClrImportant[4];
} bmih;

Bitmap Information
8

File bitmap & load file bitmap

Cu trc file bitmap


Bitmap Information :
biBitCount :
o Xc inh phn gii mu sc ca bitmap
o Gi tr c th l 1 (trng/en) , 4 (16 mu) , 8 (256
mu) , 24 (16,7 triu mu)
o Cc phn t d liu biBitCount cng quyt nh ,nu
c mt bng mu trong file v trng n nh th no

biClrUsed : s lng mu sc s dng


stuff1 : loi nn (4 bytes) , kch thc nh 4 ,
phn gii theo chiu ngang 4 , dc 4
9

File bitmap & load file bitmap

Cu trc file bitmap


Color Palette : nh ngha cc mu s dng
trong nh
Gm nhiu b c kch thc 4 bytes xp lin nhau
theo cu trc :
Blue Green Red Reserved
Kch thc ca bng mu (4*x bytes) , x l s
mu s dng trong nh
Note :
o Bng mu ca mn hnh c th t : Red Green Blue
o Bng mu ca bitmap c th t : Blue Green Red
o Nn khi c bng mu ca nh bitmap cn phi chuyn i
cho ng th t
10

File bitmap & load file bitmap

Cu trc file bitmap

pixels displayed on the screen

11

pixels stored in .bmp-file

File bitmap & load file bitmap

Cu trc file bitmap


Bitmap Data : lu d liu nh
Cha gi tr mu ca cc im nh trong .bmp
Cc im nh c lu theo th t t tri qua
phi trn 1 dng v cc dng c lu theo th
t di ln trn
Mi byte trong vng Bitmap Data biu din 1
hoc nhiu im nh ty theo s bits trn 1 pixel

12

File bitmap & load file bitmap

Cu trc file bitmap


Note :
Bitmap l mt nh dng file nh khng nn
bng bt k thut ton no
Khi lu nh ,cc im nh c ghi trc tip
vo tp tin => kch c ln
Khng dng trao i qua Internet

13

File bitmap & load file bitmap

Load file bitmap trn T-Engine


C ch hin th mt hnh nh ln trn
screen:
Ta cn mt mng d liu thit lp mu cho
tng pixel tng ng.
V d: trong th vin graphic.h h tr v mt k t
8x16, chng hn k t A c d liu tng ng t
bng nh sau:
{ 0x00, 0x10, 0x10, 0x28, 0x28, 0x28, 0x44, 0x44,
0x44, 0x7c, 0x82, 0x82, 0x82, 0x82, 0x82, 0x00 }
/* A*/
14

File bitmap & load file bitmap

Ct
hng

10

11

12

13

14

15

15

File bitmap & load file bitmap

Chng ta c nhng g?
Screen.h: vi nhng thuc
tnh d liu thng dng
nh: DN_SCRCOLOR,
DN_SCRBMP,
DN_SCRUPDRECT
Graphic.h: in_rect,
draw_pixel, draw_line,
fill_rect, draw_text,
draw_btn
16

File bitmap & load file bitmap

Gii thut c file

c bitmap Header

Nhn dng file


c ng l bmp
tht khng.
(2byte u l
BM)
Xc nh byte
bt u vng
Bitmap Data
(d liu ca
nh)

c bitmap Info

Ly cc thng
tin c bn nh:
chiu rng,
chiu cao, s
bit cho mt
pixel.
T suy ra
s mu v kch
thc palette
mu
17

File bitmap & load file bitmap

Gii thut c file

c Palette mu

c bitmap data

Chuyn i
Palette mu t
dng Blue
Green Red
Reserved sang
Ren Green
Blue.

Tnh ton tng


im nh ra
mn hnh sau
v theo th
t t tri qua
phi v t di
ln trn.

18

File bitmap & load file bitmap

Cch lu v c file bitmap


S lng byte trong file bit map lun l bi s
ca 4.
V d:
- 6 byte mt hng trong bitmap: A0 37 F2 00 | 31 C4
- Phi c lu nh sau: A0 37 F2 00 | 31 C4 00 00
Khi tin hnh c file ta chuyn t Blue
Green Red Reserved sang Red Green
Blue.
V d: khi c file F2 37 A0 | 00 C4 31

19

File bitmap & load file bitmap

Cc hm cn hin thc
unsigned long ** read_BMP(char*
file_name,int *h,int *w): c file BMP
t tp file_name, suy ra chiu cao h, v
rng w ca nh, tnh ton pixel cn v.
void show_BMP(unsigned long **
pixels,int x,int y,int height,int width):
v tng pixel theo th t t tri sang phi
v t di ln trn.

20

File bitmap & load file bitmap

Q&A

Q
&
A
21

File bitmap & load file bitmap

LOGO

Thank You (^_^) :-* !

File bitmap & load file bitmap

You might also like