annotate gui/bitmap.c @ 32955:e12d6cd72b75

Go without gtk functions. Normal string function are sufficient to handle item->text, there is no need to use gtk functions.
author ib
date Mon, 07 Mar 2011 20:27:29 +0000
parents 9949f3a123cf
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
26458
b0a7b35b78d2 Add standard GPL header to individual files.
diego
parents: 26069
diff changeset
1 /*
b0a7b35b78d2 Add standard GPL header to individual files.
diego
parents: 26069
diff changeset
2 * This file is part of MPlayer.
b0a7b35b78d2 Add standard GPL header to individual files.
diego
parents: 26069
diff changeset
3 *
b0a7b35b78d2 Add standard GPL header to individual files.
diego
parents: 26069
diff changeset
4 * MPlayer is free software; you can redistribute it and/or modify
b0a7b35b78d2 Add standard GPL header to individual files.
diego
parents: 26069
diff changeset
5 * it under the terms of the GNU General Public License as published by
b0a7b35b78d2 Add standard GPL header to individual files.
diego
parents: 26069
diff changeset
6 * the Free Software Foundation; either version 2 of the License, or
b0a7b35b78d2 Add standard GPL header to individual files.
diego
parents: 26069
diff changeset
7 * (at your option) any later version.
b0a7b35b78d2 Add standard GPL header to individual files.
diego
parents: 26069
diff changeset
8 *
b0a7b35b78d2 Add standard GPL header to individual files.
diego
parents: 26069
diff changeset
9 * MPlayer is distributed in the hope that it will be useful,
b0a7b35b78d2 Add standard GPL header to individual files.
diego
parents: 26069
diff changeset
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
b0a7b35b78d2 Add standard GPL header to individual files.
diego
parents: 26069
diff changeset
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
b0a7b35b78d2 Add standard GPL header to individual files.
diego
parents: 26069
diff changeset
12 * GNU General Public License for more details.
b0a7b35b78d2 Add standard GPL header to individual files.
diego
parents: 26069
diff changeset
13 *
b0a7b35b78d2 Add standard GPL header to individual files.
diego
parents: 26069
diff changeset
14 * You should have received a copy of the GNU General Public License along
b0a7b35b78d2 Add standard GPL header to individual files.
diego
parents: 26069
diff changeset
15 * with MPlayer; if not, write to the Free Software Foundation, Inc.,
b0a7b35b78d2 Add standard GPL header to individual files.
diego
parents: 26069
diff changeset
16 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
b0a7b35b78d2 Add standard GPL header to individual files.
diego
parents: 26069
diff changeset
17 */
b0a7b35b78d2 Add standard GPL header to individual files.
diego
parents: 26069
diff changeset
18
23077
17bf4f4b0715 Gui --> gui
diego
parents:
diff changeset
19 #include <stdio.h>
17bf4f4b0715 Gui --> gui
diego
parents:
diff changeset
20 #include <stdlib.h>
17bf4f4b0715 Gui --> gui
diego
parents:
diff changeset
21 #include <string.h>
17bf4f4b0715 Gui --> gui
diego
parents:
diff changeset
22
32913
d971fcdbb787 Cosmetic: Format to MPlayer coding style.
ib
parents: 32768
diff changeset
23 #include "bitmap.h"
d971fcdbb787 Cosmetic: Format to MPlayer coding style.
ib
parents: 32768
diff changeset
24
23077
17bf4f4b0715 Gui --> gui
diego
parents:
diff changeset
25 #include "help_mp.h"
23193
7857af1ca50b Remove libpng dependency for Gui, use libavcodec instead
reimar
parents: 23077
diff changeset
26 #include "libavcodec/avcodec.h"
23225
794aba782ebd Fix Gui colors for 32 bit png images after switch to libavcodec decoding
reimar
parents: 23200
diff changeset
27 #include "libavutil/intreadwrite.h"
23193
7857af1ca50b Remove libpng dependency for Gui, use libavcodec instead
reimar
parents: 23077
diff changeset
28 #include "libvo/fastmemcpy.h"
32913
d971fcdbb787 Cosmetic: Format to MPlayer coding style.
ib
parents: 32768
diff changeset
29 #include "mp_msg.h"
23077
17bf4f4b0715 Gui --> gui
diego
parents:
diff changeset
30
32913
d971fcdbb787 Cosmetic: Format to MPlayer coding style.
ib
parents: 32768
diff changeset
31 static int pngRead(unsigned char *fname, txSample *bf)
23077
17bf4f4b0715 Gui --> gui
diego
parents:
diff changeset
32 {
32913
d971fcdbb787 Cosmetic: Format to MPlayer coding style.
ib
parents: 32768
diff changeset
33 FILE *fp;
d971fcdbb787 Cosmetic: Format to MPlayer coding style.
ib
parents: 32768
diff changeset
34 int decode_ok;
d971fcdbb787 Cosmetic: Format to MPlayer coding style.
ib
parents: 32768
diff changeset
35 void *data;
d971fcdbb787 Cosmetic: Format to MPlayer coding style.
ib
parents: 32768
diff changeset
36 int len;
d971fcdbb787 Cosmetic: Format to MPlayer coding style.
ib
parents: 32768
diff changeset
37 AVCodecContext *avctx;
d971fcdbb787 Cosmetic: Format to MPlayer coding style.
ib
parents: 32768
diff changeset
38 AVFrame *frame;
d971fcdbb787 Cosmetic: Format to MPlayer coding style.
ib
parents: 32768
diff changeset
39 AVPacket pkt;
d971fcdbb787 Cosmetic: Format to MPlayer coding style.
ib
parents: 32768
diff changeset
40
d971fcdbb787 Cosmetic: Format to MPlayer coding style.
ib
parents: 32768
diff changeset
41 fp = fopen(fname, "rb");
d971fcdbb787 Cosmetic: Format to MPlayer coding style.
ib
parents: 32768
diff changeset
42
d971fcdbb787 Cosmetic: Format to MPlayer coding style.
ib
parents: 32768
diff changeset
43 if (!fp) {
d971fcdbb787 Cosmetic: Format to MPlayer coding style.
ib
parents: 32768
diff changeset
44 mp_dbg(MSGT_GPLAYER, MSGL_DBG2, "[png] file read error ( %s )\n", fname);
d971fcdbb787 Cosmetic: Format to MPlayer coding style.
ib
parents: 32768
diff changeset
45 return 1;
d971fcdbb787 Cosmetic: Format to MPlayer coding style.
ib
parents: 32768
diff changeset
46 }
d971fcdbb787 Cosmetic: Format to MPlayer coding style.
ib
parents: 32768
diff changeset
47
d971fcdbb787 Cosmetic: Format to MPlayer coding style.
ib
parents: 32768
diff changeset
48 fseek(fp, 0, SEEK_END);
d971fcdbb787 Cosmetic: Format to MPlayer coding style.
ib
parents: 32768
diff changeset
49 len = ftell(fp);
29263
0f1b5b68af32 whitespace cosmetics: Remove all trailing whitespace.
diego
parents: 26458
diff changeset
50
32913
d971fcdbb787 Cosmetic: Format to MPlayer coding style.
ib
parents: 32768
diff changeset
51 if (len > 50 * 1024 * 1024) {
d971fcdbb787 Cosmetic: Format to MPlayer coding style.
ib
parents: 32768
diff changeset
52 fclose(fp);
d971fcdbb787 Cosmetic: Format to MPlayer coding style.
ib
parents: 32768
diff changeset
53 return 2;
d971fcdbb787 Cosmetic: Format to MPlayer coding style.
ib
parents: 32768
diff changeset
54 }
d971fcdbb787 Cosmetic: Format to MPlayer coding style.
ib
parents: 32768
diff changeset
55
d971fcdbb787 Cosmetic: Format to MPlayer coding style.
ib
parents: 32768
diff changeset
56 data = av_malloc(len + FF_INPUT_BUFFER_PADDING_SIZE);
d971fcdbb787 Cosmetic: Format to MPlayer coding style.
ib
parents: 32768
diff changeset
57
d971fcdbb787 Cosmetic: Format to MPlayer coding style.
ib
parents: 32768
diff changeset
58 fseek(fp, 0, SEEK_SET);
d971fcdbb787 Cosmetic: Format to MPlayer coding style.
ib
parents: 32768
diff changeset
59 fread(data, len, 1, fp);
d971fcdbb787 Cosmetic: Format to MPlayer coding style.
ib
parents: 32768
diff changeset
60 fclose(fp);
d971fcdbb787 Cosmetic: Format to MPlayer coding style.
ib
parents: 32768
diff changeset
61
d971fcdbb787 Cosmetic: Format to MPlayer coding style.
ib
parents: 32768
diff changeset
62 avctx = avcodec_alloc_context();
d971fcdbb787 Cosmetic: Format to MPlayer coding style.
ib
parents: 32768
diff changeset
63 frame = avcodec_alloc_frame();
d971fcdbb787 Cosmetic: Format to MPlayer coding style.
ib
parents: 32768
diff changeset
64 avcodec_register_all();
d971fcdbb787 Cosmetic: Format to MPlayer coding style.
ib
parents: 32768
diff changeset
65 avcodec_open(avctx, avcodec_find_decoder(CODEC_ID_PNG));
d971fcdbb787 Cosmetic: Format to MPlayer coding style.
ib
parents: 32768
diff changeset
66 av_init_packet(&pkt);
d971fcdbb787 Cosmetic: Format to MPlayer coding style.
ib
parents: 32768
diff changeset
67 pkt.data = data;
d971fcdbb787 Cosmetic: Format to MPlayer coding style.
ib
parents: 32768
diff changeset
68 pkt.size = len;
d971fcdbb787 Cosmetic: Format to MPlayer coding style.
ib
parents: 32768
diff changeset
69 // HACK: make PNGs decode normally instead of as CorePNG delta frames
d971fcdbb787 Cosmetic: Format to MPlayer coding style.
ib
parents: 32768
diff changeset
70 pkt.flags = AV_PKT_FLAG_KEY;
d971fcdbb787 Cosmetic: Format to MPlayer coding style.
ib
parents: 32768
diff changeset
71 avcodec_decode_video2(avctx, frame, &decode_ok, &pkt);
d971fcdbb787 Cosmetic: Format to MPlayer coding style.
ib
parents: 32768
diff changeset
72 memset(bf, 0, sizeof(*bf));
23077
17bf4f4b0715 Gui --> gui
diego
parents:
diff changeset
73
32913
d971fcdbb787 Cosmetic: Format to MPlayer coding style.
ib
parents: 32768
diff changeset
74 switch (avctx->pix_fmt) {
d971fcdbb787 Cosmetic: Format to MPlayer coding style.
ib
parents: 32768
diff changeset
75 case PIX_FMT_GRAY8:
d971fcdbb787 Cosmetic: Format to MPlayer coding style.
ib
parents: 32768
diff changeset
76 bf->BPP = 8;
d971fcdbb787 Cosmetic: Format to MPlayer coding style.
ib
parents: 32768
diff changeset
77 break;
d971fcdbb787 Cosmetic: Format to MPlayer coding style.
ib
parents: 32768
diff changeset
78
d971fcdbb787 Cosmetic: Format to MPlayer coding style.
ib
parents: 32768
diff changeset
79 case PIX_FMT_GRAY16BE:
d971fcdbb787 Cosmetic: Format to MPlayer coding style.
ib
parents: 32768
diff changeset
80 bf->BPP = 16;
d971fcdbb787 Cosmetic: Format to MPlayer coding style.
ib
parents: 32768
diff changeset
81 break;
d971fcdbb787 Cosmetic: Format to MPlayer coding style.
ib
parents: 32768
diff changeset
82
d971fcdbb787 Cosmetic: Format to MPlayer coding style.
ib
parents: 32768
diff changeset
83 case PIX_FMT_RGB24:
d971fcdbb787 Cosmetic: Format to MPlayer coding style.
ib
parents: 32768
diff changeset
84 bf->BPP = 24;
d971fcdbb787 Cosmetic: Format to MPlayer coding style.
ib
parents: 32768
diff changeset
85 break;
d971fcdbb787 Cosmetic: Format to MPlayer coding style.
ib
parents: 32768
diff changeset
86
d971fcdbb787 Cosmetic: Format to MPlayer coding style.
ib
parents: 32768
diff changeset
87 case PIX_FMT_BGRA:
d971fcdbb787 Cosmetic: Format to MPlayer coding style.
ib
parents: 32768
diff changeset
88 case PIX_FMT_ARGB:
d971fcdbb787 Cosmetic: Format to MPlayer coding style.
ib
parents: 32768
diff changeset
89 bf->BPP = 32;
d971fcdbb787 Cosmetic: Format to MPlayer coding style.
ib
parents: 32768
diff changeset
90 break;
23077
17bf4f4b0715 Gui --> gui
diego
parents:
diff changeset
91
32913
d971fcdbb787 Cosmetic: Format to MPlayer coding style.
ib
parents: 32768
diff changeset
92 default:
d971fcdbb787 Cosmetic: Format to MPlayer coding style.
ib
parents: 32768
diff changeset
93 bf->BPP = 0;
d971fcdbb787 Cosmetic: Format to MPlayer coding style.
ib
parents: 32768
diff changeset
94 break;
d971fcdbb787 Cosmetic: Format to MPlayer coding style.
ib
parents: 32768
diff changeset
95 }
d971fcdbb787 Cosmetic: Format to MPlayer coding style.
ib
parents: 32768
diff changeset
96
d971fcdbb787 Cosmetic: Format to MPlayer coding style.
ib
parents: 32768
diff changeset
97 if (decode_ok && bf->BPP) {
d971fcdbb787 Cosmetic: Format to MPlayer coding style.
ib
parents: 32768
diff changeset
98 int bpl;
d971fcdbb787 Cosmetic: Format to MPlayer coding style.
ib
parents: 32768
diff changeset
99
d971fcdbb787 Cosmetic: Format to MPlayer coding style.
ib
parents: 32768
diff changeset
100 bf->Width = avctx->width;
d971fcdbb787 Cosmetic: Format to MPlayer coding style.
ib
parents: 32768
diff changeset
101 bf->Height = avctx->height;
d971fcdbb787 Cosmetic: Format to MPlayer coding style.
ib
parents: 32768
diff changeset
102 bpl = bf->Width * (bf->BPP / 8);
d971fcdbb787 Cosmetic: Format to MPlayer coding style.
ib
parents: 32768
diff changeset
103 bf->ImageSize = bpl * bf->Height;
d971fcdbb787 Cosmetic: Format to MPlayer coding style.
ib
parents: 32768
diff changeset
104 bf->Image = malloc(bf->ImageSize);
d971fcdbb787 Cosmetic: Format to MPlayer coding style.
ib
parents: 32768
diff changeset
105 memcpy_pic(bf->Image, frame->data[0], bpl, bf->Height, bpl, frame->linesize[0]);
d971fcdbb787 Cosmetic: Format to MPlayer coding style.
ib
parents: 32768
diff changeset
106 }
d971fcdbb787 Cosmetic: Format to MPlayer coding style.
ib
parents: 32768
diff changeset
107
d971fcdbb787 Cosmetic: Format to MPlayer coding style.
ib
parents: 32768
diff changeset
108 avcodec_close(avctx);
d971fcdbb787 Cosmetic: Format to MPlayer coding style.
ib
parents: 32768
diff changeset
109 av_freep(&frame);
d971fcdbb787 Cosmetic: Format to MPlayer coding style.
ib
parents: 32768
diff changeset
110 av_freep(&avctx);
d971fcdbb787 Cosmetic: Format to MPlayer coding style.
ib
parents: 32768
diff changeset
111 av_freep(&data);
d971fcdbb787 Cosmetic: Format to MPlayer coding style.
ib
parents: 32768
diff changeset
112
d971fcdbb787 Cosmetic: Format to MPlayer coding style.
ib
parents: 32768
diff changeset
113 mp_dbg(MSGT_GPLAYER, MSGL_DBG2, "[png] filename: %s.\n", fname);
32915
0cd5c0498962 Provide proper conversion specification for long and unsigned variables.
ib
parents: 32914
diff changeset
114 mp_dbg(MSGT_GPLAYER, MSGL_DBG2, "[png] size: %lux%lu bits: %u\n", bf->Width, bf->Height, bf->BPP);
32913
d971fcdbb787 Cosmetic: Format to MPlayer coding style.
ib
parents: 32768
diff changeset
115 mp_dbg(MSGT_GPLAYER, MSGL_DBG2, "[png] imagesize: %lu\n", bf->ImageSize);
d971fcdbb787 Cosmetic: Format to MPlayer coding style.
ib
parents: 32768
diff changeset
116
d971fcdbb787 Cosmetic: Format to MPlayer coding style.
ib
parents: 32768
diff changeset
117 return !(decode_ok && bf->BPP);
23077
17bf4f4b0715 Gui --> gui
diego
parents:
diff changeset
118 }
17bf4f4b0715 Gui --> gui
diego
parents:
diff changeset
119
32913
d971fcdbb787 Cosmetic: Format to MPlayer coding style.
ib
parents: 32768
diff changeset
120 static int conv24to32(txSample *bf)
23077
17bf4f4b0715 Gui --> gui
diego
parents:
diff changeset
121 {
32913
d971fcdbb787 Cosmetic: Format to MPlayer coding style.
ib
parents: 32768
diff changeset
122 unsigned char *tmpImage;
32916
5fdd52feb5ea Use appropriate declaration for array indices.
ib
parents: 32915
diff changeset
123 unsigned int i, c;
32913
d971fcdbb787 Cosmetic: Format to MPlayer coding style.
ib
parents: 32768
diff changeset
124
d971fcdbb787 Cosmetic: Format to MPlayer coding style.
ib
parents: 32768
diff changeset
125 if (bf->BPP == 24) {
d971fcdbb787 Cosmetic: Format to MPlayer coding style.
ib
parents: 32768
diff changeset
126 tmpImage = bf->Image;
d971fcdbb787 Cosmetic: Format to MPlayer coding style.
ib
parents: 32768
diff changeset
127 bf->BPP = 32;
d971fcdbb787 Cosmetic: Format to MPlayer coding style.
ib
parents: 32768
diff changeset
128 bf->ImageSize = bf->Width * bf->Height * 4;
d971fcdbb787 Cosmetic: Format to MPlayer coding style.
ib
parents: 32768
diff changeset
129 bf->Image = calloc(1, bf->ImageSize);
23077
17bf4f4b0715 Gui --> gui
diego
parents:
diff changeset
130
32913
d971fcdbb787 Cosmetic: Format to MPlayer coding style.
ib
parents: 32768
diff changeset
131 if (!bf->Image) {
d971fcdbb787 Cosmetic: Format to MPlayer coding style.
ib
parents: 32768
diff changeset
132 free(tmpImage);
d971fcdbb787 Cosmetic: Format to MPlayer coding style.
ib
parents: 32768
diff changeset
133 mp_dbg(MSGT_GPLAYER, MSGL_DBG2, "[bitmap] not enough memory for image\n");
d971fcdbb787 Cosmetic: Format to MPlayer coding style.
ib
parents: 32768
diff changeset
134 return 1;
d971fcdbb787 Cosmetic: Format to MPlayer coding style.
ib
parents: 32768
diff changeset
135 }
d971fcdbb787 Cosmetic: Format to MPlayer coding style.
ib
parents: 32768
diff changeset
136
d971fcdbb787 Cosmetic: Format to MPlayer coding style.
ib
parents: 32768
diff changeset
137 for (c = 0, i = 0; c < bf->ImageSize; c += 4, i += 3)
d971fcdbb787 Cosmetic: Format to MPlayer coding style.
ib
parents: 32768
diff changeset
138 *(uint32_t *)&bf->Image[c] = AV_RB24(&tmpImage[i]);
d971fcdbb787 Cosmetic: Format to MPlayer coding style.
ib
parents: 32768
diff changeset
139
d971fcdbb787 Cosmetic: Format to MPlayer coding style.
ib
parents: 32768
diff changeset
140 free(tmpImage);
23077
17bf4f4b0715 Gui --> gui
diego
parents:
diff changeset
141 }
32913
d971fcdbb787 Cosmetic: Format to MPlayer coding style.
ib
parents: 32768
diff changeset
142
d971fcdbb787 Cosmetic: Format to MPlayer coding style.
ib
parents: 32768
diff changeset
143 return 0;
23077
17bf4f4b0715 Gui --> gui
diego
parents:
diff changeset
144 }
17bf4f4b0715 Gui --> gui
diego
parents:
diff changeset
145
32913
d971fcdbb787 Cosmetic: Format to MPlayer coding style.
ib
parents: 32768
diff changeset
146 static void Normalize(txSample *bf)
23077
17bf4f4b0715 Gui --> gui
diego
parents:
diff changeset
147 {
32913
d971fcdbb787 Cosmetic: Format to MPlayer coding style.
ib
parents: 32768
diff changeset
148 int i;
d971fcdbb787 Cosmetic: Format to MPlayer coding style.
ib
parents: 32768
diff changeset
149
d971fcdbb787 Cosmetic: Format to MPlayer coding style.
ib
parents: 32768
diff changeset
150 for (i = 0; i < (int)bf->ImageSize; i += 4)
29401
f01023c524c3 Replace WORDS_BIGENDIAN by HAVE_BIGENDIAN in all internal code.
diego
parents: 29263
diff changeset
151 #if !HAVE_BIGENDIAN
32913
d971fcdbb787 Cosmetic: Format to MPlayer coding style.
ib
parents: 32768
diff changeset
152 bf->Image[i + 3] = 0;
23077
17bf4f4b0715 Gui --> gui
diego
parents:
diff changeset
153 #else
32913
d971fcdbb787 Cosmetic: Format to MPlayer coding style.
ib
parents: 32768
diff changeset
154 bf->Image[i] = 0;
23077
17bf4f4b0715 Gui --> gui
diego
parents:
diff changeset
155 #endif
17bf4f4b0715 Gui --> gui
diego
parents:
diff changeset
156 }
17bf4f4b0715 Gui --> gui
diego
parents:
diff changeset
157
32913
d971fcdbb787 Cosmetic: Format to MPlayer coding style.
ib
parents: 32768
diff changeset
158 static unsigned char *fExist(unsigned char *fname)
23077
17bf4f4b0715 Gui --> gui
diego
parents:
diff changeset
159 {
32914
692c174b6dc9 Move declaration of char array into scope of fExist() where it's used.
ib
parents: 32913
diff changeset
160 static unsigned char tmp[512];
32913
d971fcdbb787 Cosmetic: Format to MPlayer coding style.
ib
parents: 32768
diff changeset
161 FILE *fl;
d971fcdbb787 Cosmetic: Format to MPlayer coding style.
ib
parents: 32768
diff changeset
162 unsigned char ext[][6] = { ".png\0", ".PNG\0" };
d971fcdbb787 Cosmetic: Format to MPlayer coding style.
ib
parents: 32768
diff changeset
163 int i;
d971fcdbb787 Cosmetic: Format to MPlayer coding style.
ib
parents: 32768
diff changeset
164
d971fcdbb787 Cosmetic: Format to MPlayer coding style.
ib
parents: 32768
diff changeset
165 fl = fopen(fname, "rb");
23077
17bf4f4b0715 Gui --> gui
diego
parents:
diff changeset
166
32913
d971fcdbb787 Cosmetic: Format to MPlayer coding style.
ib
parents: 32768
diff changeset
167 if (fl != NULL) {
d971fcdbb787 Cosmetic: Format to MPlayer coding style.
ib
parents: 32768
diff changeset
168 fclose(fl);
d971fcdbb787 Cosmetic: Format to MPlayer coding style.
ib
parents: 32768
diff changeset
169 return fname;
23077
17bf4f4b0715 Gui --> gui
diego
parents:
diff changeset
170 }
32913
d971fcdbb787 Cosmetic: Format to MPlayer coding style.
ib
parents: 32768
diff changeset
171
d971fcdbb787 Cosmetic: Format to MPlayer coding style.
ib
parents: 32768
diff changeset
172 for (i = 0; i < 2; i++) {
32914
692c174b6dc9 Move declaration of char array into scope of fExist() where it's used.
ib
parents: 32913
diff changeset
173 snprintf(tmp, sizeof(tmp), "%s%s", fname, ext[i]);
32913
d971fcdbb787 Cosmetic: Format to MPlayer coding style.
ib
parents: 32768
diff changeset
174 fl = fopen(tmp, "rb");
d971fcdbb787 Cosmetic: Format to MPlayer coding style.
ib
parents: 32768
diff changeset
175
d971fcdbb787 Cosmetic: Format to MPlayer coding style.
ib
parents: 32768
diff changeset
176 if (fl != NULL) {
d971fcdbb787 Cosmetic: Format to MPlayer coding style.
ib
parents: 32768
diff changeset
177 fclose(fl);
d971fcdbb787 Cosmetic: Format to MPlayer coding style.
ib
parents: 32768
diff changeset
178 return tmp;
d971fcdbb787 Cosmetic: Format to MPlayer coding style.
ib
parents: 32768
diff changeset
179 }
d971fcdbb787 Cosmetic: Format to MPlayer coding style.
ib
parents: 32768
diff changeset
180 }
d971fcdbb787 Cosmetic: Format to MPlayer coding style.
ib
parents: 32768
diff changeset
181
d971fcdbb787 Cosmetic: Format to MPlayer coding style.
ib
parents: 32768
diff changeset
182 return NULL;
23077
17bf4f4b0715 Gui --> gui
diego
parents:
diff changeset
183 }
17bf4f4b0715 Gui --> gui
diego
parents:
diff changeset
184
32913
d971fcdbb787 Cosmetic: Format to MPlayer coding style.
ib
parents: 32768
diff changeset
185 int bpRead(char *fname, txSample *bf)
23077
17bf4f4b0715 Gui --> gui
diego
parents:
diff changeset
186 {
32913
d971fcdbb787 Cosmetic: Format to MPlayer coding style.
ib
parents: 32768
diff changeset
187 fname = fExist(fname);
d971fcdbb787 Cosmetic: Format to MPlayer coding style.
ib
parents: 32768
diff changeset
188
d971fcdbb787 Cosmetic: Format to MPlayer coding style.
ib
parents: 32768
diff changeset
189 if (fname == NULL)
d971fcdbb787 Cosmetic: Format to MPlayer coding style.
ib
parents: 32768
diff changeset
190 return -2;
d971fcdbb787 Cosmetic: Format to MPlayer coding style.
ib
parents: 32768
diff changeset
191
d971fcdbb787 Cosmetic: Format to MPlayer coding style.
ib
parents: 32768
diff changeset
192 if (pngRead(fname, bf)) {
d971fcdbb787 Cosmetic: Format to MPlayer coding style.
ib
parents: 32768
diff changeset
193 mp_dbg(MSGT_GPLAYER, MSGL_FATAL, "[bitmap] unknown file type ( %s )\n", fname);
d971fcdbb787 Cosmetic: Format to MPlayer coding style.
ib
parents: 32768
diff changeset
194 return -5;
d971fcdbb787 Cosmetic: Format to MPlayer coding style.
ib
parents: 32768
diff changeset
195 }
d971fcdbb787 Cosmetic: Format to MPlayer coding style.
ib
parents: 32768
diff changeset
196
d971fcdbb787 Cosmetic: Format to MPlayer coding style.
ib
parents: 32768
diff changeset
197 if (bf->BPP < 24) {
d971fcdbb787 Cosmetic: Format to MPlayer coding style.
ib
parents: 32768
diff changeset
198 mp_dbg(MSGT_GPLAYER, MSGL_DBG2, "[bitmap] Sorry, only 24 and 32 bpp bitmaps are supported.\n");
d971fcdbb787 Cosmetic: Format to MPlayer coding style.
ib
parents: 32768
diff changeset
199 return -1;
d971fcdbb787 Cosmetic: Format to MPlayer coding style.
ib
parents: 32768
diff changeset
200 }
d971fcdbb787 Cosmetic: Format to MPlayer coding style.
ib
parents: 32768
diff changeset
201
d971fcdbb787 Cosmetic: Format to MPlayer coding style.
ib
parents: 32768
diff changeset
202 if (conv24to32(bf))
d971fcdbb787 Cosmetic: Format to MPlayer coding style.
ib
parents: 32768
diff changeset
203 return -8;
d971fcdbb787 Cosmetic: Format to MPlayer coding style.
ib
parents: 32768
diff changeset
204
d971fcdbb787 Cosmetic: Format to MPlayer coding style.
ib
parents: 32768
diff changeset
205 Normalize(bf);
d971fcdbb787 Cosmetic: Format to MPlayer coding style.
ib
parents: 32768
diff changeset
206 return 0;
23077
17bf4f4b0715 Gui --> gui
diego
parents:
diff changeset
207 }
17bf4f4b0715 Gui --> gui
diego
parents:
diff changeset
208
32917
9949f3a123cf Add new function bpFree() to free txSamples (bitmaps).
ib
parents: 32916
diff changeset
209 void bpFree(txSample *bf)
9949f3a123cf Add new function bpFree() to free txSamples (bitmaps).
ib
parents: 32916
diff changeset
210 {
9949f3a123cf Add new function bpFree() to free txSamples (bitmaps).
ib
parents: 32916
diff changeset
211 free(bf->Image);
9949f3a123cf Add new function bpFree() to free txSamples (bitmaps).
ib
parents: 32916
diff changeset
212 memset(bf, 0, sizeof(*bf));
9949f3a123cf Add new function bpFree() to free txSamples (bitmaps).
ib
parents: 32916
diff changeset
213 }
9949f3a123cf Add new function bpFree() to free txSamples (bitmaps).
ib
parents: 32916
diff changeset
214
32913
d971fcdbb787 Cosmetic: Format to MPlayer coding style.
ib
parents: 32768
diff changeset
215 void Convert32to1(txSample *in, txSample *out, int adaptivlimit)
23077
17bf4f4b0715 Gui --> gui
diego
parents:
diff changeset
216 {
32913
d971fcdbb787 Cosmetic: Format to MPlayer coding style.
ib
parents: 32768
diff changeset
217 out->Width = in->Width;
d971fcdbb787 Cosmetic: Format to MPlayer coding style.
ib
parents: 32768
diff changeset
218 out->Height = in->Height;
d971fcdbb787 Cosmetic: Format to MPlayer coding style.
ib
parents: 32768
diff changeset
219 out->BPP = 1;
d971fcdbb787 Cosmetic: Format to MPlayer coding style.
ib
parents: 32768
diff changeset
220 out->ImageSize = (out->Width * out->Height + 7) / 8;
d971fcdbb787 Cosmetic: Format to MPlayer coding style.
ib
parents: 32768
diff changeset
221
32915
0cd5c0498962 Provide proper conversion specification for long and unsigned variables.
ib
parents: 32914
diff changeset
222 mp_dbg(MSGT_GPLAYER, MSGL_DBG2, "[c32to1] imagesize: %lu\n", out->ImageSize);
32913
d971fcdbb787 Cosmetic: Format to MPlayer coding style.
ib
parents: 32768
diff changeset
223
d971fcdbb787 Cosmetic: Format to MPlayer coding style.
ib
parents: 32768
diff changeset
224 out->Image = calloc(1, out->ImageSize);
d971fcdbb787 Cosmetic: Format to MPlayer coding style.
ib
parents: 32768
diff changeset
225
d971fcdbb787 Cosmetic: Format to MPlayer coding style.
ib
parents: 32768
diff changeset
226 if (out->Image == NULL)
d971fcdbb787 Cosmetic: Format to MPlayer coding style.
ib
parents: 32768
diff changeset
227 mp_msg(MSGT_GPLAYER, MSGL_WARN, MSGTR_NotEnoughMemoryC32To1);
d971fcdbb787 Cosmetic: Format to MPlayer coding style.
ib
parents: 32768
diff changeset
228 {
d971fcdbb787 Cosmetic: Format to MPlayer coding style.
ib
parents: 32768
diff changeset
229 int i, b, c = 0;
d971fcdbb787 Cosmetic: Format to MPlayer coding style.
ib
parents: 32768
diff changeset
230 unsigned int *buf = NULL;
d971fcdbb787 Cosmetic: Format to MPlayer coding style.
ib
parents: 32768
diff changeset
231 unsigned char tmp = 0;
d971fcdbb787 Cosmetic: Format to MPlayer coding style.
ib
parents: 32768
diff changeset
232 int nothaveshape = 1;
d971fcdbb787 Cosmetic: Format to MPlayer coding style.
ib
parents: 32768
diff changeset
233
d971fcdbb787 Cosmetic: Format to MPlayer coding style.
ib
parents: 32768
diff changeset
234 buf = (unsigned int *)in->Image;
d971fcdbb787 Cosmetic: Format to MPlayer coding style.
ib
parents: 32768
diff changeset
235
d971fcdbb787 Cosmetic: Format to MPlayer coding style.
ib
parents: 32768
diff changeset
236 for (b = 0, i = 0; i < (int)(out->Width * out->Height); i++) {
d971fcdbb787 Cosmetic: Format to MPlayer coding style.
ib
parents: 32768
diff changeset
237 if ((int)buf[i] != adaptivlimit)
d971fcdbb787 Cosmetic: Format to MPlayer coding style.
ib
parents: 32768
diff changeset
238 tmp = (tmp >> 1) | 128;
d971fcdbb787 Cosmetic: Format to MPlayer coding style.
ib
parents: 32768
diff changeset
239 else {
d971fcdbb787 Cosmetic: Format to MPlayer coding style.
ib
parents: 32768
diff changeset
240 tmp = tmp >> 1;
d971fcdbb787 Cosmetic: Format to MPlayer coding style.
ib
parents: 32768
diff changeset
241 buf[i] = nothaveshape = 0;
d971fcdbb787 Cosmetic: Format to MPlayer coding style.
ib
parents: 32768
diff changeset
242 }
d971fcdbb787 Cosmetic: Format to MPlayer coding style.
ib
parents: 32768
diff changeset
243
d971fcdbb787 Cosmetic: Format to MPlayer coding style.
ib
parents: 32768
diff changeset
244 if (b++ == 7) {
d971fcdbb787 Cosmetic: Format to MPlayer coding style.
ib
parents: 32768
diff changeset
245 out->Image[c++] = tmp;
d971fcdbb787 Cosmetic: Format to MPlayer coding style.
ib
parents: 32768
diff changeset
246 tmp = b = 0;
d971fcdbb787 Cosmetic: Format to MPlayer coding style.
ib
parents: 32768
diff changeset
247 }
d971fcdbb787 Cosmetic: Format to MPlayer coding style.
ib
parents: 32768
diff changeset
248 }
d971fcdbb787 Cosmetic: Format to MPlayer coding style.
ib
parents: 32768
diff changeset
249
d971fcdbb787 Cosmetic: Format to MPlayer coding style.
ib
parents: 32768
diff changeset
250 if (b)
d971fcdbb787 Cosmetic: Format to MPlayer coding style.
ib
parents: 32768
diff changeset
251 out->Image[c] = tmp;
d971fcdbb787 Cosmetic: Format to MPlayer coding style.
ib
parents: 32768
diff changeset
252
d971fcdbb787 Cosmetic: Format to MPlayer coding style.
ib
parents: 32768
diff changeset
253 if (nothaveshape) {
d971fcdbb787 Cosmetic: Format to MPlayer coding style.
ib
parents: 32768
diff changeset
254 free(out->Image);
d971fcdbb787 Cosmetic: Format to MPlayer coding style.
ib
parents: 32768
diff changeset
255 out->Image = NULL;
d971fcdbb787 Cosmetic: Format to MPlayer coding style.
ib
parents: 32768
diff changeset
256 }
d971fcdbb787 Cosmetic: Format to MPlayer coding style.
ib
parents: 32768
diff changeset
257 }
23077
17bf4f4b0715 Gui --> gui
diego
parents:
diff changeset
258 }