Mercurial > mplayer.hg
annotate libmpdemux/demux_bmp.c @ 10564:2345addedd01
sync
author | gabucino |
---|---|
date | Mon, 11 Aug 2003 07:28:25 +0000 |
parents | 1a26db279e50 |
children | c2e17a510b4b |
rev | line source |
---|---|
5214
dd79075bbd98
added a BMP file demuxer...yeah, that's right, a static image BMP file
melanson
parents:
diff
changeset
|
1 /* |
dd79075bbd98
added a BMP file demuxer...yeah, that's right, a static image BMP file
melanson
parents:
diff
changeset
|
2 BMP file parser for the MPlayer program |
dd79075bbd98
added a BMP file demuxer...yeah, that's right, a static image BMP file
melanson
parents:
diff
changeset
|
3 by Mike Melanson |
dd79075bbd98
added a BMP file demuxer...yeah, that's right, a static image BMP file
melanson
parents:
diff
changeset
|
4 */ |
dd79075bbd98
added a BMP file demuxer...yeah, that's right, a static image BMP file
melanson
parents:
diff
changeset
|
5 |
dd79075bbd98
added a BMP file demuxer...yeah, that's right, a static image BMP file
melanson
parents:
diff
changeset
|
6 #include <stdio.h> |
dd79075bbd98
added a BMP file demuxer...yeah, that's right, a static image BMP file
melanson
parents:
diff
changeset
|
7 #include <stdlib.h> |
dd79075bbd98
added a BMP file demuxer...yeah, that's right, a static image BMP file
melanson
parents:
diff
changeset
|
8 #include <unistd.h> |
dd79075bbd98
added a BMP file demuxer...yeah, that's right, a static image BMP file
melanson
parents:
diff
changeset
|
9 |
dd79075bbd98
added a BMP file demuxer...yeah, that's right, a static image BMP file
melanson
parents:
diff
changeset
|
10 #include "config.h" |
dd79075bbd98
added a BMP file demuxer...yeah, that's right, a static image BMP file
melanson
parents:
diff
changeset
|
11 #include "mp_msg.h" |
dd79075bbd98
added a BMP file demuxer...yeah, that's right, a static image BMP file
melanson
parents:
diff
changeset
|
12 #include "help_mp.h" |
dd79075bbd98
added a BMP file demuxer...yeah, that's right, a static image BMP file
melanson
parents:
diff
changeset
|
13 |
dd79075bbd98
added a BMP file demuxer...yeah, that's right, a static image BMP file
melanson
parents:
diff
changeset
|
14 #include "stream.h" |
dd79075bbd98
added a BMP file demuxer...yeah, that's right, a static image BMP file
melanson
parents:
diff
changeset
|
15 #include "demuxer.h" |
dd79075bbd98
added a BMP file demuxer...yeah, that's right, a static image BMP file
melanson
parents:
diff
changeset
|
16 #include "stheader.h" |
dd79075bbd98
added a BMP file demuxer...yeah, that's right, a static image BMP file
melanson
parents:
diff
changeset
|
17 |
dd79075bbd98
added a BMP file demuxer...yeah, that's right, a static image BMP file
melanson
parents:
diff
changeset
|
18 typedef struct { |
dd79075bbd98
added a BMP file demuxer...yeah, that's right, a static image BMP file
melanson
parents:
diff
changeset
|
19 int image_size; |
dd79075bbd98
added a BMP file demuxer...yeah, that's right, a static image BMP file
melanson
parents:
diff
changeset
|
20 int image_offset; |
dd79075bbd98
added a BMP file demuxer...yeah, that's right, a static image BMP file
melanson
parents:
diff
changeset
|
21 } bmp_image_t; |
dd79075bbd98
added a BMP file demuxer...yeah, that's right, a static image BMP file
melanson
parents:
diff
changeset
|
22 |
dd79075bbd98
added a BMP file demuxer...yeah, that's right, a static image BMP file
melanson
parents:
diff
changeset
|
23 // Check if a file is a BMP file depending on whether starts with 'BM' |
dd79075bbd98
added a BMP file demuxer...yeah, that's right, a static image BMP file
melanson
parents:
diff
changeset
|
24 int bmp_check_file(demuxer_t *demuxer) |
dd79075bbd98
added a BMP file demuxer...yeah, that's right, a static image BMP file
melanson
parents:
diff
changeset
|
25 { |
dd79075bbd98
added a BMP file demuxer...yeah, that's right, a static image BMP file
melanson
parents:
diff
changeset
|
26 if (stream_read_word(demuxer->stream) == (('B' << 8) | 'M')) |
dd79075bbd98
added a BMP file demuxer...yeah, that's right, a static image BMP file
melanson
parents:
diff
changeset
|
27 return 1; |
dd79075bbd98
added a BMP file demuxer...yeah, that's right, a static image BMP file
melanson
parents:
diff
changeset
|
28 else |
dd79075bbd98
added a BMP file demuxer...yeah, that's right, a static image BMP file
melanson
parents:
diff
changeset
|
29 return 0; |
dd79075bbd98
added a BMP file demuxer...yeah, that's right, a static image BMP file
melanson
parents:
diff
changeset
|
30 } |
dd79075bbd98
added a BMP file demuxer...yeah, that's right, a static image BMP file
melanson
parents:
diff
changeset
|
31 |
dd79075bbd98
added a BMP file demuxer...yeah, that's right, a static image BMP file
melanson
parents:
diff
changeset
|
32 // return value: |
dd79075bbd98
added a BMP file demuxer...yeah, that's right, a static image BMP file
melanson
parents:
diff
changeset
|
33 // 0 = EOF or no stream found |
dd79075bbd98
added a BMP file demuxer...yeah, that's right, a static image BMP file
melanson
parents:
diff
changeset
|
34 // 1 = successfully read a packet |
dd79075bbd98
added a BMP file demuxer...yeah, that's right, a static image BMP file
melanson
parents:
diff
changeset
|
35 int demux_bmp_fill_buffer(demuxer_t *demuxer) |
dd79075bbd98
added a BMP file demuxer...yeah, that's right, a static image BMP file
melanson
parents:
diff
changeset
|
36 { |
dd79075bbd98
added a BMP file demuxer...yeah, that's right, a static image BMP file
melanson
parents:
diff
changeset
|
37 bmp_image_t *bmp_image = (bmp_image_t *)demuxer->priv; |
dd79075bbd98
added a BMP file demuxer...yeah, that's right, a static image BMP file
melanson
parents:
diff
changeset
|
38 |
dd79075bbd98
added a BMP file demuxer...yeah, that's right, a static image BMP file
melanson
parents:
diff
changeset
|
39 stream_reset(demuxer->stream); |
dd79075bbd98
added a BMP file demuxer...yeah, that's right, a static image BMP file
melanson
parents:
diff
changeset
|
40 stream_seek(demuxer->stream, bmp_image->image_offset); |
dd79075bbd98
added a BMP file demuxer...yeah, that's right, a static image BMP file
melanson
parents:
diff
changeset
|
41 ds_read_packet(demuxer->video, demuxer->stream, bmp_image->image_size, |
dd79075bbd98
added a BMP file demuxer...yeah, that's right, a static image BMP file
melanson
parents:
diff
changeset
|
42 0, bmp_image->image_offset, 1); |
dd79075bbd98
added a BMP file demuxer...yeah, that's right, a static image BMP file
melanson
parents:
diff
changeset
|
43 |
dd79075bbd98
added a BMP file demuxer...yeah, that's right, a static image BMP file
melanson
parents:
diff
changeset
|
44 return 1; |
dd79075bbd98
added a BMP file demuxer...yeah, that's right, a static image BMP file
melanson
parents:
diff
changeset
|
45 } |
dd79075bbd98
added a BMP file demuxer...yeah, that's right, a static image BMP file
melanson
parents:
diff
changeset
|
46 |
dd79075bbd98
added a BMP file demuxer...yeah, that's right, a static image BMP file
melanson
parents:
diff
changeset
|
47 demuxer_t* demux_open_bmp(demuxer_t* demuxer) |
dd79075bbd98
added a BMP file demuxer...yeah, that's right, a static image BMP file
melanson
parents:
diff
changeset
|
48 { |
dd79075bbd98
added a BMP file demuxer...yeah, that's right, a static image BMP file
melanson
parents:
diff
changeset
|
49 sh_video_t *sh_video = NULL; |
dd79075bbd98
added a BMP file demuxer...yeah, that's right, a static image BMP file
melanson
parents:
diff
changeset
|
50 unsigned int filesize; |
dd79075bbd98
added a BMP file demuxer...yeah, that's right, a static image BMP file
melanson
parents:
diff
changeset
|
51 unsigned int data_offset; |
dd79075bbd98
added a BMP file demuxer...yeah, that's right, a static image BMP file
melanson
parents:
diff
changeset
|
52 bmp_image_t *bmp_image; |
dd79075bbd98
added a BMP file demuxer...yeah, that's right, a static image BMP file
melanson
parents:
diff
changeset
|
53 |
dd79075bbd98
added a BMP file demuxer...yeah, that's right, a static image BMP file
melanson
parents:
diff
changeset
|
54 // go back to the beginning |
dd79075bbd98
added a BMP file demuxer...yeah, that's right, a static image BMP file
melanson
parents:
diff
changeset
|
55 stream_reset(demuxer->stream); |
dd79075bbd98
added a BMP file demuxer...yeah, that's right, a static image BMP file
melanson
parents:
diff
changeset
|
56 stream_seek(demuxer->stream, 2); |
dd79075bbd98
added a BMP file demuxer...yeah, that's right, a static image BMP file
melanson
parents:
diff
changeset
|
57 filesize = stream_read_dword_le(demuxer->stream); |
dd79075bbd98
added a BMP file demuxer...yeah, that's right, a static image BMP file
melanson
parents:
diff
changeset
|
58 stream_skip(demuxer->stream, 4); |
dd79075bbd98
added a BMP file demuxer...yeah, that's right, a static image BMP file
melanson
parents:
diff
changeset
|
59 data_offset = stream_read_word_le(demuxer->stream); |
dd79075bbd98
added a BMP file demuxer...yeah, that's right, a static image BMP file
melanson
parents:
diff
changeset
|
60 stream_skip(demuxer->stream, 2); |
dd79075bbd98
added a BMP file demuxer...yeah, that's right, a static image BMP file
melanson
parents:
diff
changeset
|
61 |
dd79075bbd98
added a BMP file demuxer...yeah, that's right, a static image BMP file
melanson
parents:
diff
changeset
|
62 // create a new video stream header |
dd79075bbd98
added a BMP file demuxer...yeah, that's right, a static image BMP file
melanson
parents:
diff
changeset
|
63 sh_video = new_sh_video(demuxer, 0); |
dd79075bbd98
added a BMP file demuxer...yeah, that's right, a static image BMP file
melanson
parents:
diff
changeset
|
64 |
dd79075bbd98
added a BMP file demuxer...yeah, that's right, a static image BMP file
melanson
parents:
diff
changeset
|
65 // make sure the demuxer knows about the new video stream header |
dd79075bbd98
added a BMP file demuxer...yeah, that's right, a static image BMP file
melanson
parents:
diff
changeset
|
66 demuxer->video->sh = sh_video; |
dd79075bbd98
added a BMP file demuxer...yeah, that's right, a static image BMP file
melanson
parents:
diff
changeset
|
67 |
dd79075bbd98
added a BMP file demuxer...yeah, that's right, a static image BMP file
melanson
parents:
diff
changeset
|
68 // make sure that the video demuxer stream header knows about its |
dd79075bbd98
added a BMP file demuxer...yeah, that's right, a static image BMP file
melanson
parents:
diff
changeset
|
69 // parent video demuxer stream |
dd79075bbd98
added a BMP file demuxer...yeah, that's right, a static image BMP file
melanson
parents:
diff
changeset
|
70 sh_video->ds = demuxer->video; |
dd79075bbd98
added a BMP file demuxer...yeah, that's right, a static image BMP file
melanson
parents:
diff
changeset
|
71 |
dd79075bbd98
added a BMP file demuxer...yeah, that's right, a static image BMP file
melanson
parents:
diff
changeset
|
72 // load the BITMAPINFOHEADER |
dd79075bbd98
added a BMP file demuxer...yeah, that's right, a static image BMP file
melanson
parents:
diff
changeset
|
73 // allocate size and take the palette table into account |
dd79075bbd98
added a BMP file demuxer...yeah, that's right, a static image BMP file
melanson
parents:
diff
changeset
|
74 sh_video->bih = (BITMAPINFOHEADER *)malloc(data_offset - 12); |
dd79075bbd98
added a BMP file demuxer...yeah, that's right, a static image BMP file
melanson
parents:
diff
changeset
|
75 sh_video->bih->biSize = stream_read_dword_le(demuxer->stream); |
dd79075bbd98
added a BMP file demuxer...yeah, that's right, a static image BMP file
melanson
parents:
diff
changeset
|
76 sh_video->bih->biWidth = stream_read_dword_le(demuxer->stream); |
dd79075bbd98
added a BMP file demuxer...yeah, that's right, a static image BMP file
melanson
parents:
diff
changeset
|
77 sh_video->bih->biHeight = stream_read_dword_le(demuxer->stream); |
dd79075bbd98
added a BMP file demuxer...yeah, that's right, a static image BMP file
melanson
parents:
diff
changeset
|
78 sh_video->bih->biPlanes = stream_read_word_le(demuxer->stream); |
dd79075bbd98
added a BMP file demuxer...yeah, that's right, a static image BMP file
melanson
parents:
diff
changeset
|
79 sh_video->bih->biBitCount = stream_read_word_le(demuxer->stream); |
dd79075bbd98
added a BMP file demuxer...yeah, that's right, a static image BMP file
melanson
parents:
diff
changeset
|
80 sh_video->bih->biCompression = stream_read_dword_le(demuxer->stream); |
dd79075bbd98
added a BMP file demuxer...yeah, that's right, a static image BMP file
melanson
parents:
diff
changeset
|
81 sh_video->bih->biSizeImage = stream_read_dword_le(demuxer->stream); |
dd79075bbd98
added a BMP file demuxer...yeah, that's right, a static image BMP file
melanson
parents:
diff
changeset
|
82 sh_video->bih->biXPelsPerMeter = stream_read_dword_le(demuxer->stream); |
dd79075bbd98
added a BMP file demuxer...yeah, that's right, a static image BMP file
melanson
parents:
diff
changeset
|
83 sh_video->bih->biYPelsPerMeter = stream_read_dword_le(demuxer->stream); |
dd79075bbd98
added a BMP file demuxer...yeah, that's right, a static image BMP file
melanson
parents:
diff
changeset
|
84 sh_video->bih->biClrUsed = stream_read_dword_le(demuxer->stream); |
dd79075bbd98
added a BMP file demuxer...yeah, that's right, a static image BMP file
melanson
parents:
diff
changeset
|
85 sh_video->bih->biClrImportant = stream_read_dword_le(demuxer->stream); |
dd79075bbd98
added a BMP file demuxer...yeah, that's right, a static image BMP file
melanson
parents:
diff
changeset
|
86 // fetch the palette |
dd79075bbd98
added a BMP file demuxer...yeah, that's right, a static image BMP file
melanson
parents:
diff
changeset
|
87 stream_read(demuxer->stream, (unsigned char *)(sh_video->bih) + 40, |
dd79075bbd98
added a BMP file demuxer...yeah, that's right, a static image BMP file
melanson
parents:
diff
changeset
|
88 sh_video->bih->biClrUsed * 4); |
dd79075bbd98
added a BMP file demuxer...yeah, that's right, a static image BMP file
melanson
parents:
diff
changeset
|
89 |
dd79075bbd98
added a BMP file demuxer...yeah, that's right, a static image BMP file
melanson
parents:
diff
changeset
|
90 // load the data |
dd79075bbd98
added a BMP file demuxer...yeah, that's right, a static image BMP file
melanson
parents:
diff
changeset
|
91 bmp_image = (bmp_image_t *)malloc(sizeof(bmp_image_t)); |
dd79075bbd98
added a BMP file demuxer...yeah, that's right, a static image BMP file
melanson
parents:
diff
changeset
|
92 bmp_image->image_size = filesize - data_offset; |
dd79075bbd98
added a BMP file demuxer...yeah, that's right, a static image BMP file
melanson
parents:
diff
changeset
|
93 bmp_image->image_offset = data_offset; |
dd79075bbd98
added a BMP file demuxer...yeah, that's right, a static image BMP file
melanson
parents:
diff
changeset
|
94 |
dd79075bbd98
added a BMP file demuxer...yeah, that's right, a static image BMP file
melanson
parents:
diff
changeset
|
95 // custom fourcc for internal MPlayer use |
dd79075bbd98
added a BMP file demuxer...yeah, that's right, a static image BMP file
melanson
parents:
diff
changeset
|
96 sh_video->format = sh_video->bih->biCompression; |
dd79075bbd98
added a BMP file demuxer...yeah, that's right, a static image BMP file
melanson
parents:
diff
changeset
|
97 |
dd79075bbd98
added a BMP file demuxer...yeah, that's right, a static image BMP file
melanson
parents:
diff
changeset
|
98 sh_video->disp_w = sh_video->bih->biWidth; |
dd79075bbd98
added a BMP file demuxer...yeah, that's right, a static image BMP file
melanson
parents:
diff
changeset
|
99 sh_video->disp_h = sh_video->bih->biHeight; |
dd79075bbd98
added a BMP file demuxer...yeah, that's right, a static image BMP file
melanson
parents:
diff
changeset
|
100 |
dd79075bbd98
added a BMP file demuxer...yeah, that's right, a static image BMP file
melanson
parents:
diff
changeset
|
101 // get the speed |
dd79075bbd98
added a BMP file demuxer...yeah, that's right, a static image BMP file
melanson
parents:
diff
changeset
|
102 sh_video->fps = 2; |
dd79075bbd98
added a BMP file demuxer...yeah, that's right, a static image BMP file
melanson
parents:
diff
changeset
|
103 sh_video->frametime = 1 / sh_video->fps; |
dd79075bbd98
added a BMP file demuxer...yeah, that's right, a static image BMP file
melanson
parents:
diff
changeset
|
104 |
dd79075bbd98
added a BMP file demuxer...yeah, that's right, a static image BMP file
melanson
parents:
diff
changeset
|
105 demuxer->priv = bmp_image; |
dd79075bbd98
added a BMP file demuxer...yeah, that's right, a static image BMP file
melanson
parents:
diff
changeset
|
106 |
dd79075bbd98
added a BMP file demuxer...yeah, that's right, a static image BMP file
melanson
parents:
diff
changeset
|
107 return demuxer; |
dd79075bbd98
added a BMP file demuxer...yeah, that's right, a static image BMP file
melanson
parents:
diff
changeset
|
108 } |
5810 | 109 |
110 void demux_close_bmp(demuxer_t* demuxer) { | |
111 bmp_image_t *bmp_image = demuxer->priv; | |
112 | |
113 if(!bmp_image) | |
114 return; | |
115 free(bmp_image); | |
116 } |