annotate libmpdemux/demux_bmp.c @ 5909:adc04b7ed226

OpenBSD patch - by Bj«Órn Sandell <biorn@dce.chalmers.se>
author arpi
date Mon, 29 Apr 2002 21:42:36 +0000
parents 8a357300d0ec
children 1a26db279e50
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
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 stream_reset(demuxer->stream);
dd79075bbd98 added a BMP file demuxer...yeah, that's right, a static image BMP file
melanson
parents:
diff changeset
27 stream_seek(demuxer->stream, 0);
dd79075bbd98 added a BMP file demuxer...yeah, that's right, a static image BMP file
melanson
parents:
diff changeset
28
dd79075bbd98 added a BMP file demuxer...yeah, that's right, a static image BMP file
melanson
parents:
diff changeset
29 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
30 return 1;
dd79075bbd98 added a BMP file demuxer...yeah, that's right, a static image BMP file
melanson
parents:
diff changeset
31 else
dd79075bbd98 added a BMP file demuxer...yeah, that's right, a static image BMP file
melanson
parents:
diff changeset
32 return 0;
dd79075bbd98 added a BMP file demuxer...yeah, that's right, a static image BMP file
melanson
parents:
diff changeset
33 }
dd79075bbd98 added a BMP file demuxer...yeah, that's right, a static image BMP file
melanson
parents:
diff changeset
34
dd79075bbd98 added a BMP file demuxer...yeah, that's right, a static image BMP file
melanson
parents:
diff changeset
35 // return value:
dd79075bbd98 added a BMP file demuxer...yeah, that's right, a static image BMP file
melanson
parents:
diff changeset
36 // 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
37 // 1 = successfully read a packet
dd79075bbd98 added a BMP file demuxer...yeah, that's right, a static image BMP file
melanson
parents:
diff changeset
38 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
39 {
dd79075bbd98 added a BMP file demuxer...yeah, that's right, a static image BMP file
melanson
parents:
diff changeset
40 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
41
dd79075bbd98 added a BMP file demuxer...yeah, that's right, a static image BMP file
melanson
parents:
diff changeset
42 stream_reset(demuxer->stream);
dd79075bbd98 added a BMP file demuxer...yeah, that's right, a static image BMP file
melanson
parents:
diff changeset
43 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
44 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
45 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
46
dd79075bbd98 added a BMP file demuxer...yeah, that's right, a static image BMP file
melanson
parents:
diff changeset
47 return 1;
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
dd79075bbd98 added a BMP file demuxer...yeah, that's right, a static image BMP file
melanson
parents:
diff changeset
50 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
51 {
dd79075bbd98 added a BMP file demuxer...yeah, that's right, a static image BMP file
melanson
parents:
diff changeset
52 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
53 unsigned int filesize;
dd79075bbd98 added a BMP file demuxer...yeah, that's right, a static image BMP file
melanson
parents:
diff changeset
54 unsigned int data_offset;
dd79075bbd98 added a BMP file demuxer...yeah, that's right, a static image BMP file
melanson
parents:
diff changeset
55 bmp_image_t *bmp_image;
dd79075bbd98 added a BMP file demuxer...yeah, that's right, a static image BMP file
melanson
parents:
diff changeset
56
dd79075bbd98 added a BMP file demuxer...yeah, that's right, a static image BMP file
melanson
parents:
diff changeset
57 // go back to the beginning
dd79075bbd98 added a BMP file demuxer...yeah, that's right, a static image BMP file
melanson
parents:
diff changeset
58 stream_reset(demuxer->stream);
dd79075bbd98 added a BMP file demuxer...yeah, that's right, a static image BMP file
melanson
parents:
diff changeset
59 stream_seek(demuxer->stream, 2);
dd79075bbd98 added a BMP file demuxer...yeah, that's right, a static image BMP file
melanson
parents:
diff changeset
60 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
61 stream_skip(demuxer->stream, 4);
dd79075bbd98 added a BMP file demuxer...yeah, that's right, a static image BMP file
melanson
parents:
diff changeset
62 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
63 stream_skip(demuxer->stream, 2);
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 // 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
66 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
67
dd79075bbd98 added a BMP file demuxer...yeah, that's right, a static image BMP file
melanson
parents:
diff changeset
68 // 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
69 demuxer->video->sh = sh_video;
dd79075bbd98 added a BMP file demuxer...yeah, that's right, a static image BMP file
melanson
parents:
diff changeset
70
dd79075bbd98 added a BMP file demuxer...yeah, that's right, a static image BMP file
melanson
parents:
diff changeset
71 // 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
72 // parent video demuxer stream
dd79075bbd98 added a BMP file demuxer...yeah, that's right, a static image BMP file
melanson
parents:
diff changeset
73 sh_video->ds = demuxer->video;
dd79075bbd98 added a BMP file demuxer...yeah, that's right, a static image BMP file
melanson
parents:
diff changeset
74
dd79075bbd98 added a BMP file demuxer...yeah, that's right, a static image BMP file
melanson
parents:
diff changeset
75 // load the BITMAPINFOHEADER
dd79075bbd98 added a BMP file demuxer...yeah, that's right, a static image BMP file
melanson
parents:
diff changeset
76 // 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
77 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
78 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
79 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
80 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
81 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
82 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
83 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
84 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
85 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
86 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
87 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
88 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
89 // fetch the palette
dd79075bbd98 added a BMP file demuxer...yeah, that's right, a static image BMP file
melanson
parents:
diff changeset
90 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
91 sh_video->bih->biClrUsed * 4);
dd79075bbd98 added a BMP file demuxer...yeah, that's right, a static image BMP file
melanson
parents:
diff changeset
92
dd79075bbd98 added a BMP file demuxer...yeah, that's right, a static image BMP file
melanson
parents:
diff changeset
93 // load the data
dd79075bbd98 added a BMP file demuxer...yeah, that's right, a static image BMP file
melanson
parents:
diff changeset
94 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
95 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
96 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
97
dd79075bbd98 added a BMP file demuxer...yeah, that's right, a static image BMP file
melanson
parents:
diff changeset
98 // 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
99 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
100
dd79075bbd98 added a BMP file demuxer...yeah, that's right, a static image BMP file
melanson
parents:
diff changeset
101 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
102 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
103
dd79075bbd98 added a BMP file demuxer...yeah, that's right, a static image BMP file
melanson
parents:
diff changeset
104 // get the speed
dd79075bbd98 added a BMP file demuxer...yeah, that's right, a static image BMP file
melanson
parents:
diff changeset
105 sh_video->fps = 2;
dd79075bbd98 added a BMP file demuxer...yeah, that's right, a static image BMP file
melanson
parents:
diff changeset
106 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
107
dd79075bbd98 added a BMP file demuxer...yeah, that's right, a static image BMP file
melanson
parents:
diff changeset
108 demuxer->priv = bmp_image;
dd79075bbd98 added a BMP file demuxer...yeah, that's right, a static image BMP file
melanson
parents:
diff changeset
109
dd79075bbd98 added a BMP file demuxer...yeah, that's right, a static image BMP file
melanson
parents:
diff changeset
110 return demuxer;
dd79075bbd98 added a BMP file demuxer...yeah, that's right, a static image BMP file
melanson
parents:
diff changeset
111 }
5810
8a357300d0ec Added demuxer uninit
albeu
parents: 5214
diff changeset
112
8a357300d0ec Added demuxer uninit
albeu
parents: 5214
diff changeset
113 void demux_close_bmp(demuxer_t* demuxer) {
8a357300d0ec Added demuxer uninit
albeu
parents: 5214
diff changeset
114 bmp_image_t *bmp_image = demuxer->priv;
8a357300d0ec Added demuxer uninit
albeu
parents: 5214
diff changeset
115
8a357300d0ec Added demuxer uninit
albeu
parents: 5214
diff changeset
116 if(!bmp_image)
8a357300d0ec Added demuxer uninit
albeu
parents: 5214
diff changeset
117 return;
8a357300d0ec Added demuxer uninit
albeu
parents: 5214
diff changeset
118 free(bmp_image);
8a357300d0ec Added demuxer uninit
albeu
parents: 5214
diff changeset
119 }