annotate gui/util/bitmap.c @ 33120:e1403616342f

Increment the counter before the comparison. This expresses the 8 bit nature of the image data more intensely.
author ib
date Mon, 04 Apr 2011 14:14:10 +0000
parents 8835e684a41d
children 7623be6c1f0e
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
33046
9684ad0e1291 Move files with auxiliary functions to own directory.
ib
parents:
diff changeset
1 /*
9684ad0e1291 Move files with auxiliary functions to own directory.
ib
parents:
diff changeset
2 * This file is part of MPlayer.
9684ad0e1291 Move files with auxiliary functions to own directory.
ib
parents:
diff changeset
3 *
9684ad0e1291 Move files with auxiliary functions to own directory.
ib
parents:
diff changeset
4 * MPlayer is free software; you can redistribute it and/or modify
9684ad0e1291 Move files with auxiliary functions to own directory.
ib
parents:
diff changeset
5 * it under the terms of the GNU General Public License as published by
9684ad0e1291 Move files with auxiliary functions to own directory.
ib
parents:
diff changeset
6 * the Free Software Foundation; either version 2 of the License, or
9684ad0e1291 Move files with auxiliary functions to own directory.
ib
parents:
diff changeset
7 * (at your option) any later version.
9684ad0e1291 Move files with auxiliary functions to own directory.
ib
parents:
diff changeset
8 *
9684ad0e1291 Move files with auxiliary functions to own directory.
ib
parents:
diff changeset
9 * MPlayer is distributed in the hope that it will be useful,
9684ad0e1291 Move files with auxiliary functions to own directory.
ib
parents:
diff changeset
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
9684ad0e1291 Move files with auxiliary functions to own directory.
ib
parents:
diff changeset
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
9684ad0e1291 Move files with auxiliary functions to own directory.
ib
parents:
diff changeset
12 * GNU General Public License for more details.
9684ad0e1291 Move files with auxiliary functions to own directory.
ib
parents:
diff changeset
13 *
9684ad0e1291 Move files with auxiliary functions to own directory.
ib
parents:
diff changeset
14 * You should have received a copy of the GNU General Public License along
9684ad0e1291 Move files with auxiliary functions to own directory.
ib
parents:
diff changeset
15 * with MPlayer; if not, write to the Free Software Foundation, Inc.,
9684ad0e1291 Move files with auxiliary functions to own directory.
ib
parents:
diff changeset
16 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
9684ad0e1291 Move files with auxiliary functions to own directory.
ib
parents:
diff changeset
17 */
9684ad0e1291 Move files with auxiliary functions to own directory.
ib
parents:
diff changeset
18
9684ad0e1291 Move files with auxiliary functions to own directory.
ib
parents:
diff changeset
19 #include <stdio.h>
9684ad0e1291 Move files with auxiliary functions to own directory.
ib
parents:
diff changeset
20 #include <stdlib.h>
9684ad0e1291 Move files with auxiliary functions to own directory.
ib
parents:
diff changeset
21 #include <string.h>
9684ad0e1291 Move files with auxiliary functions to own directory.
ib
parents:
diff changeset
22
9684ad0e1291 Move files with auxiliary functions to own directory.
ib
parents:
diff changeset
23 #include "bitmap.h"
9684ad0e1291 Move files with auxiliary functions to own directory.
ib
parents:
diff changeset
24
9684ad0e1291 Move files with auxiliary functions to own directory.
ib
parents:
diff changeset
25 #include "help_mp.h"
9684ad0e1291 Move files with auxiliary functions to own directory.
ib
parents:
diff changeset
26 #include "libavcodec/avcodec.h"
9684ad0e1291 Move files with auxiliary functions to own directory.
ib
parents:
diff changeset
27 #include "libavutil/intreadwrite.h"
9684ad0e1291 Move files with auxiliary functions to own directory.
ib
parents:
diff changeset
28 #include "libvo/fastmemcpy.h"
9684ad0e1291 Move files with auxiliary functions to own directory.
ib
parents:
diff changeset
29 #include "mp_msg.h"
9684ad0e1291 Move files with auxiliary functions to own directory.
ib
parents:
diff changeset
30
9684ad0e1291 Move files with auxiliary functions to own directory.
ib
parents:
diff changeset
31 static int pngRead(unsigned char *fname, txSample *bf)
9684ad0e1291 Move files with auxiliary functions to own directory.
ib
parents:
diff changeset
32 {
9684ad0e1291 Move files with auxiliary functions to own directory.
ib
parents:
diff changeset
33 FILE *fp;
9684ad0e1291 Move files with auxiliary functions to own directory.
ib
parents:
diff changeset
34 int decode_ok;
9684ad0e1291 Move files with auxiliary functions to own directory.
ib
parents:
diff changeset
35 void *data;
9684ad0e1291 Move files with auxiliary functions to own directory.
ib
parents:
diff changeset
36 int len;
9684ad0e1291 Move files with auxiliary functions to own directory.
ib
parents:
diff changeset
37 AVCodecContext *avctx;
9684ad0e1291 Move files with auxiliary functions to own directory.
ib
parents:
diff changeset
38 AVFrame *frame;
9684ad0e1291 Move files with auxiliary functions to own directory.
ib
parents:
diff changeset
39 AVPacket pkt;
9684ad0e1291 Move files with auxiliary functions to own directory.
ib
parents:
diff changeset
40
9684ad0e1291 Move files with auxiliary functions to own directory.
ib
parents:
diff changeset
41 fp = fopen(fname, "rb");
9684ad0e1291 Move files with auxiliary functions to own directory.
ib
parents:
diff changeset
42
9684ad0e1291 Move files with auxiliary functions to own directory.
ib
parents:
diff changeset
43 if (!fp) {
33112
654dfdf176ac Revise debug messages.
ib
parents: 33053
diff changeset
44 mp_dbg(MSGT_GPLAYER, MSGL_DBG2, "[bitmap] open error: %s\n", fname);
33046
9684ad0e1291 Move files with auxiliary functions to own directory.
ib
parents:
diff changeset
45 return 1;
9684ad0e1291 Move files with auxiliary functions to own directory.
ib
parents:
diff changeset
46 }
9684ad0e1291 Move files with auxiliary functions to own directory.
ib
parents:
diff changeset
47
9684ad0e1291 Move files with auxiliary functions to own directory.
ib
parents:
diff changeset
48 fseek(fp, 0, SEEK_END);
9684ad0e1291 Move files with auxiliary functions to own directory.
ib
parents:
diff changeset
49 len = ftell(fp);
9684ad0e1291 Move files with auxiliary functions to own directory.
ib
parents:
diff changeset
50
9684ad0e1291 Move files with auxiliary functions to own directory.
ib
parents:
diff changeset
51 if (len > 50 * 1024 * 1024) {
9684ad0e1291 Move files with auxiliary functions to own directory.
ib
parents:
diff changeset
52 fclose(fp);
33112
654dfdf176ac Revise debug messages.
ib
parents: 33053
diff changeset
53 mp_dbg(MSGT_GPLAYER, MSGL_DBG2, "[bitmap] file too big: %s\n", fname);
33046
9684ad0e1291 Move files with auxiliary functions to own directory.
ib
parents:
diff changeset
54 return 2;
9684ad0e1291 Move files with auxiliary functions to own directory.
ib
parents:
diff changeset
55 }
9684ad0e1291 Move files with auxiliary functions to own directory.
ib
parents:
diff changeset
56
9684ad0e1291 Move files with auxiliary functions to own directory.
ib
parents:
diff changeset
57 data = av_malloc(len + FF_INPUT_BUFFER_PADDING_SIZE);
9684ad0e1291 Move files with auxiliary functions to own directory.
ib
parents:
diff changeset
58
9684ad0e1291 Move files with auxiliary functions to own directory.
ib
parents:
diff changeset
59 fseek(fp, 0, SEEK_SET);
9684ad0e1291 Move files with auxiliary functions to own directory.
ib
parents:
diff changeset
60 fread(data, len, 1, fp);
9684ad0e1291 Move files with auxiliary functions to own directory.
ib
parents:
diff changeset
61 fclose(fp);
9684ad0e1291 Move files with auxiliary functions to own directory.
ib
parents:
diff changeset
62
9684ad0e1291 Move files with auxiliary functions to own directory.
ib
parents:
diff changeset
63 avctx = avcodec_alloc_context();
9684ad0e1291 Move files with auxiliary functions to own directory.
ib
parents:
diff changeset
64 frame = avcodec_alloc_frame();
9684ad0e1291 Move files with auxiliary functions to own directory.
ib
parents:
diff changeset
65 avcodec_register_all();
9684ad0e1291 Move files with auxiliary functions to own directory.
ib
parents:
diff changeset
66 avcodec_open(avctx, avcodec_find_decoder(CODEC_ID_PNG));
9684ad0e1291 Move files with auxiliary functions to own directory.
ib
parents:
diff changeset
67 av_init_packet(&pkt);
9684ad0e1291 Move files with auxiliary functions to own directory.
ib
parents:
diff changeset
68 pkt.data = data;
9684ad0e1291 Move files with auxiliary functions to own directory.
ib
parents:
diff changeset
69 pkt.size = len;
9684ad0e1291 Move files with auxiliary functions to own directory.
ib
parents:
diff changeset
70 // HACK: make PNGs decode normally instead of as CorePNG delta frames
9684ad0e1291 Move files with auxiliary functions to own directory.
ib
parents:
diff changeset
71 pkt.flags = AV_PKT_FLAG_KEY;
9684ad0e1291 Move files with auxiliary functions to own directory.
ib
parents:
diff changeset
72 avcodec_decode_video2(avctx, frame, &decode_ok, &pkt);
9684ad0e1291 Move files with auxiliary functions to own directory.
ib
parents:
diff changeset
73 memset(bf, 0, sizeof(*bf));
9684ad0e1291 Move files with auxiliary functions to own directory.
ib
parents:
diff changeset
74
9684ad0e1291 Move files with auxiliary functions to own directory.
ib
parents:
diff changeset
75 switch (avctx->pix_fmt) {
9684ad0e1291 Move files with auxiliary functions to own directory.
ib
parents:
diff changeset
76 case PIX_FMT_GRAY8:
9684ad0e1291 Move files with auxiliary functions to own directory.
ib
parents:
diff changeset
77 bf->BPP = 8;
9684ad0e1291 Move files with auxiliary functions to own directory.
ib
parents:
diff changeset
78 break;
9684ad0e1291 Move files with auxiliary functions to own directory.
ib
parents:
diff changeset
79
9684ad0e1291 Move files with auxiliary functions to own directory.
ib
parents:
diff changeset
80 case PIX_FMT_GRAY16BE:
9684ad0e1291 Move files with auxiliary functions to own directory.
ib
parents:
diff changeset
81 bf->BPP = 16;
9684ad0e1291 Move files with auxiliary functions to own directory.
ib
parents:
diff changeset
82 break;
9684ad0e1291 Move files with auxiliary functions to own directory.
ib
parents:
diff changeset
83
9684ad0e1291 Move files with auxiliary functions to own directory.
ib
parents:
diff changeset
84 case PIX_FMT_RGB24:
9684ad0e1291 Move files with auxiliary functions to own directory.
ib
parents:
diff changeset
85 bf->BPP = 24;
9684ad0e1291 Move files with auxiliary functions to own directory.
ib
parents:
diff changeset
86 break;
9684ad0e1291 Move files with auxiliary functions to own directory.
ib
parents:
diff changeset
87
9684ad0e1291 Move files with auxiliary functions to own directory.
ib
parents:
diff changeset
88 case PIX_FMT_BGRA:
9684ad0e1291 Move files with auxiliary functions to own directory.
ib
parents:
diff changeset
89 case PIX_FMT_ARGB:
9684ad0e1291 Move files with auxiliary functions to own directory.
ib
parents:
diff changeset
90 bf->BPP = 32;
9684ad0e1291 Move files with auxiliary functions to own directory.
ib
parents:
diff changeset
91 break;
9684ad0e1291 Move files with auxiliary functions to own directory.
ib
parents:
diff changeset
92
9684ad0e1291 Move files with auxiliary functions to own directory.
ib
parents:
diff changeset
93 default:
9684ad0e1291 Move files with auxiliary functions to own directory.
ib
parents:
diff changeset
94 bf->BPP = 0;
9684ad0e1291 Move files with auxiliary functions to own directory.
ib
parents:
diff changeset
95 break;
9684ad0e1291 Move files with auxiliary functions to own directory.
ib
parents:
diff changeset
96 }
9684ad0e1291 Move files with auxiliary functions to own directory.
ib
parents:
diff changeset
97
9684ad0e1291 Move files with auxiliary functions to own directory.
ib
parents:
diff changeset
98 if (decode_ok && bf->BPP) {
9684ad0e1291 Move files with auxiliary functions to own directory.
ib
parents:
diff changeset
99 int bpl;
9684ad0e1291 Move files with auxiliary functions to own directory.
ib
parents:
diff changeset
100
9684ad0e1291 Move files with auxiliary functions to own directory.
ib
parents:
diff changeset
101 bf->Width = avctx->width;
9684ad0e1291 Move files with auxiliary functions to own directory.
ib
parents:
diff changeset
102 bf->Height = avctx->height;
9684ad0e1291 Move files with auxiliary functions to own directory.
ib
parents:
diff changeset
103 bpl = bf->Width * (bf->BPP / 8);
9684ad0e1291 Move files with auxiliary functions to own directory.
ib
parents:
diff changeset
104 bf->ImageSize = bpl * bf->Height;
9684ad0e1291 Move files with auxiliary functions to own directory.
ib
parents:
diff changeset
105 bf->Image = malloc(bf->ImageSize);
9684ad0e1291 Move files with auxiliary functions to own directory.
ib
parents:
diff changeset
106 memcpy_pic(bf->Image, frame->data[0], bpl, bf->Height, bpl, frame->linesize[0]);
9684ad0e1291 Move files with auxiliary functions to own directory.
ib
parents:
diff changeset
107 }
9684ad0e1291 Move files with auxiliary functions to own directory.
ib
parents:
diff changeset
108
9684ad0e1291 Move files with auxiliary functions to own directory.
ib
parents:
diff changeset
109 avcodec_close(avctx);
9684ad0e1291 Move files with auxiliary functions to own directory.
ib
parents:
diff changeset
110 av_freep(&frame);
9684ad0e1291 Move files with auxiliary functions to own directory.
ib
parents:
diff changeset
111 av_freep(&avctx);
9684ad0e1291 Move files with auxiliary functions to own directory.
ib
parents:
diff changeset
112 av_freep(&data);
9684ad0e1291 Move files with auxiliary functions to own directory.
ib
parents:
diff changeset
113
33112
654dfdf176ac Revise debug messages.
ib
parents: 33053
diff changeset
114 mp_dbg(MSGT_GPLAYER, MSGL_DBG2, "[bitmap] file: %s\n", fname);
654dfdf176ac Revise debug messages.
ib
parents: 33053
diff changeset
115 mp_dbg(MSGT_GPLAYER, MSGL_DBG2, "[bitmap] size: %lux%lu, color depth: %u\n", bf->Width, bf->Height, bf->BPP);
654dfdf176ac Revise debug messages.
ib
parents: 33053
diff changeset
116 mp_dbg(MSGT_GPLAYER, MSGL_DBG2, "[bitmap] image size: %lu\n", bf->ImageSize);
33046
9684ad0e1291 Move files with auxiliary functions to own directory.
ib
parents:
diff changeset
117
9684ad0e1291 Move files with auxiliary functions to own directory.
ib
parents:
diff changeset
118 return !(decode_ok && bf->BPP);
9684ad0e1291 Move files with auxiliary functions to own directory.
ib
parents:
diff changeset
119 }
9684ad0e1291 Move files with auxiliary functions to own directory.
ib
parents:
diff changeset
120
9684ad0e1291 Move files with auxiliary functions to own directory.
ib
parents:
diff changeset
121 static int conv24to32(txSample *bf)
9684ad0e1291 Move files with auxiliary functions to own directory.
ib
parents:
diff changeset
122 {
9684ad0e1291 Move files with auxiliary functions to own directory.
ib
parents:
diff changeset
123 unsigned char *tmpImage;
9684ad0e1291 Move files with auxiliary functions to own directory.
ib
parents:
diff changeset
124 unsigned int i, c;
9684ad0e1291 Move files with auxiliary functions to own directory.
ib
parents:
diff changeset
125
9684ad0e1291 Move files with auxiliary functions to own directory.
ib
parents:
diff changeset
126 if (bf->BPP == 24) {
9684ad0e1291 Move files with auxiliary functions to own directory.
ib
parents:
diff changeset
127 tmpImage = bf->Image;
9684ad0e1291 Move files with auxiliary functions to own directory.
ib
parents:
diff changeset
128 bf->BPP = 32;
9684ad0e1291 Move files with auxiliary functions to own directory.
ib
parents:
diff changeset
129 bf->ImageSize = bf->Width * bf->Height * 4;
9684ad0e1291 Move files with auxiliary functions to own directory.
ib
parents:
diff changeset
130 bf->Image = calloc(1, bf->ImageSize);
9684ad0e1291 Move files with auxiliary functions to own directory.
ib
parents:
diff changeset
131
9684ad0e1291 Move files with auxiliary functions to own directory.
ib
parents:
diff changeset
132 if (!bf->Image) {
9684ad0e1291 Move files with auxiliary functions to own directory.
ib
parents:
diff changeset
133 free(tmpImage);
33112
654dfdf176ac Revise debug messages.
ib
parents: 33053
diff changeset
134 mp_dbg(MSGT_GPLAYER, MSGL_DBG2, "[bitmap] not enough memory: %lu\n", bf->ImageSize);
33046
9684ad0e1291 Move files with auxiliary functions to own directory.
ib
parents:
diff changeset
135 return 1;
9684ad0e1291 Move files with auxiliary functions to own directory.
ib
parents:
diff changeset
136 }
9684ad0e1291 Move files with auxiliary functions to own directory.
ib
parents:
diff changeset
137
33112
654dfdf176ac Revise debug messages.
ib
parents: 33053
diff changeset
138 mp_dbg(MSGT_GPLAYER, MSGL_DBG2, "[bitmap] 32 bpp conversion size: %lu\n", bf->ImageSize);
654dfdf176ac Revise debug messages.
ib
parents: 33053
diff changeset
139
33046
9684ad0e1291 Move files with auxiliary functions to own directory.
ib
parents:
diff changeset
140 for (c = 0, i = 0; c < bf->ImageSize; c += 4, i += 3)
9684ad0e1291 Move files with auxiliary functions to own directory.
ib
parents:
diff changeset
141 *(uint32_t *)&bf->Image[c] = AV_RB24(&tmpImage[i]);
9684ad0e1291 Move files with auxiliary functions to own directory.
ib
parents:
diff changeset
142
9684ad0e1291 Move files with auxiliary functions to own directory.
ib
parents:
diff changeset
143 free(tmpImage);
9684ad0e1291 Move files with auxiliary functions to own directory.
ib
parents:
diff changeset
144 }
9684ad0e1291 Move files with auxiliary functions to own directory.
ib
parents:
diff changeset
145
9684ad0e1291 Move files with auxiliary functions to own directory.
ib
parents:
diff changeset
146 return 0;
9684ad0e1291 Move files with auxiliary functions to own directory.
ib
parents:
diff changeset
147 }
9684ad0e1291 Move files with auxiliary functions to own directory.
ib
parents:
diff changeset
148
9684ad0e1291 Move files with auxiliary functions to own directory.
ib
parents:
diff changeset
149 static void Normalize(txSample *bf)
9684ad0e1291 Move files with auxiliary functions to own directory.
ib
parents:
diff changeset
150 {
9684ad0e1291 Move files with auxiliary functions to own directory.
ib
parents:
diff changeset
151 int i;
9684ad0e1291 Move files with auxiliary functions to own directory.
ib
parents:
diff changeset
152
9684ad0e1291 Move files with auxiliary functions to own directory.
ib
parents:
diff changeset
153 for (i = 0; i < (int)bf->ImageSize; i += 4)
9684ad0e1291 Move files with auxiliary functions to own directory.
ib
parents:
diff changeset
154 #if !HAVE_BIGENDIAN
9684ad0e1291 Move files with auxiliary functions to own directory.
ib
parents:
diff changeset
155 bf->Image[i + 3] = 0;
9684ad0e1291 Move files with auxiliary functions to own directory.
ib
parents:
diff changeset
156 #else
9684ad0e1291 Move files with auxiliary functions to own directory.
ib
parents:
diff changeset
157 bf->Image[i] = 0;
9684ad0e1291 Move files with auxiliary functions to own directory.
ib
parents:
diff changeset
158 #endif
9684ad0e1291 Move files with auxiliary functions to own directory.
ib
parents:
diff changeset
159 }
9684ad0e1291 Move files with auxiliary functions to own directory.
ib
parents:
diff changeset
160
9684ad0e1291 Move files with auxiliary functions to own directory.
ib
parents:
diff changeset
161 static unsigned char *fExist(unsigned char *fname)
9684ad0e1291 Move files with auxiliary functions to own directory.
ib
parents:
diff changeset
162 {
9684ad0e1291 Move files with auxiliary functions to own directory.
ib
parents:
diff changeset
163 static unsigned char tmp[512];
9684ad0e1291 Move files with auxiliary functions to own directory.
ib
parents:
diff changeset
164 FILE *fl;
9684ad0e1291 Move files with auxiliary functions to own directory.
ib
parents:
diff changeset
165 unsigned char ext[][6] = { ".png\0", ".PNG\0" };
9684ad0e1291 Move files with auxiliary functions to own directory.
ib
parents:
diff changeset
166 int i;
9684ad0e1291 Move files with auxiliary functions to own directory.
ib
parents:
diff changeset
167
9684ad0e1291 Move files with auxiliary functions to own directory.
ib
parents:
diff changeset
168 fl = fopen(fname, "rb");
9684ad0e1291 Move files with auxiliary functions to own directory.
ib
parents:
diff changeset
169
9684ad0e1291 Move files with auxiliary functions to own directory.
ib
parents:
diff changeset
170 if (fl != NULL) {
9684ad0e1291 Move files with auxiliary functions to own directory.
ib
parents:
diff changeset
171 fclose(fl);
9684ad0e1291 Move files with auxiliary functions to own directory.
ib
parents:
diff changeset
172 return fname;
9684ad0e1291 Move files with auxiliary functions to own directory.
ib
parents:
diff changeset
173 }
9684ad0e1291 Move files with auxiliary functions to own directory.
ib
parents:
diff changeset
174
9684ad0e1291 Move files with auxiliary functions to own directory.
ib
parents:
diff changeset
175 for (i = 0; i < 2; i++) {
9684ad0e1291 Move files with auxiliary functions to own directory.
ib
parents:
diff changeset
176 snprintf(tmp, sizeof(tmp), "%s%s", fname, ext[i]);
9684ad0e1291 Move files with auxiliary functions to own directory.
ib
parents:
diff changeset
177 fl = fopen(tmp, "rb");
9684ad0e1291 Move files with auxiliary functions to own directory.
ib
parents:
diff changeset
178
9684ad0e1291 Move files with auxiliary functions to own directory.
ib
parents:
diff changeset
179 if (fl != NULL) {
9684ad0e1291 Move files with auxiliary functions to own directory.
ib
parents:
diff changeset
180 fclose(fl);
9684ad0e1291 Move files with auxiliary functions to own directory.
ib
parents:
diff changeset
181 return tmp;
9684ad0e1291 Move files with auxiliary functions to own directory.
ib
parents:
diff changeset
182 }
9684ad0e1291 Move files with auxiliary functions to own directory.
ib
parents:
diff changeset
183 }
9684ad0e1291 Move files with auxiliary functions to own directory.
ib
parents:
diff changeset
184
9684ad0e1291 Move files with auxiliary functions to own directory.
ib
parents:
diff changeset
185 return NULL;
9684ad0e1291 Move files with auxiliary functions to own directory.
ib
parents:
diff changeset
186 }
9684ad0e1291 Move files with auxiliary functions to own directory.
ib
parents:
diff changeset
187
9684ad0e1291 Move files with auxiliary functions to own directory.
ib
parents:
diff changeset
188 int bpRead(char *fname, txSample *bf)
9684ad0e1291 Move files with auxiliary functions to own directory.
ib
parents:
diff changeset
189 {
9684ad0e1291 Move files with auxiliary functions to own directory.
ib
parents:
diff changeset
190 fname = fExist(fname);
9684ad0e1291 Move files with auxiliary functions to own directory.
ib
parents:
diff changeset
191
9684ad0e1291 Move files with auxiliary functions to own directory.
ib
parents:
diff changeset
192 if (fname == NULL)
9684ad0e1291 Move files with auxiliary functions to own directory.
ib
parents:
diff changeset
193 return -2;
9684ad0e1291 Move files with auxiliary functions to own directory.
ib
parents:
diff changeset
194
9684ad0e1291 Move files with auxiliary functions to own directory.
ib
parents:
diff changeset
195 if (pngRead(fname, bf)) {
33112
654dfdf176ac Revise debug messages.
ib
parents: 33053
diff changeset
196 mp_dbg(MSGT_GPLAYER, MSGL_DBG2, "[bitmap] read error: %s\n", fname);
33046
9684ad0e1291 Move files with auxiliary functions to own directory.
ib
parents:
diff changeset
197 return -5;
9684ad0e1291 Move files with auxiliary functions to own directory.
ib
parents:
diff changeset
198 }
9684ad0e1291 Move files with auxiliary functions to own directory.
ib
parents:
diff changeset
199
9684ad0e1291 Move files with auxiliary functions to own directory.
ib
parents:
diff changeset
200 if (bf->BPP < 24) {
33112
654dfdf176ac Revise debug messages.
ib
parents: 33053
diff changeset
201 mp_dbg(MSGT_GPLAYER, MSGL_DBG2, "[bitmap] bpp too low: %u\n", bf->BPP);
33046
9684ad0e1291 Move files with auxiliary functions to own directory.
ib
parents:
diff changeset
202 return -1;
9684ad0e1291 Move files with auxiliary functions to own directory.
ib
parents:
diff changeset
203 }
9684ad0e1291 Move files with auxiliary functions to own directory.
ib
parents:
diff changeset
204
9684ad0e1291 Move files with auxiliary functions to own directory.
ib
parents:
diff changeset
205 if (conv24to32(bf))
9684ad0e1291 Move files with auxiliary functions to own directory.
ib
parents:
diff changeset
206 return -8;
9684ad0e1291 Move files with auxiliary functions to own directory.
ib
parents:
diff changeset
207
9684ad0e1291 Move files with auxiliary functions to own directory.
ib
parents:
diff changeset
208 Normalize(bf);
33053
f64d41dac10b Cosmetic: Separate return statement with newline.
ib
parents: 33046
diff changeset
209
33046
9684ad0e1291 Move files with auxiliary functions to own directory.
ib
parents:
diff changeset
210 return 0;
9684ad0e1291 Move files with auxiliary functions to own directory.
ib
parents:
diff changeset
211 }
9684ad0e1291 Move files with auxiliary functions to own directory.
ib
parents:
diff changeset
212
9684ad0e1291 Move files with auxiliary functions to own directory.
ib
parents:
diff changeset
213 void bpFree(txSample *bf)
9684ad0e1291 Move files with auxiliary functions to own directory.
ib
parents:
diff changeset
214 {
9684ad0e1291 Move files with auxiliary functions to own directory.
ib
parents:
diff changeset
215 free(bf->Image);
9684ad0e1291 Move files with auxiliary functions to own directory.
ib
parents:
diff changeset
216 memset(bf, 0, sizeof(*bf));
9684ad0e1291 Move files with auxiliary functions to own directory.
ib
parents:
diff changeset
217 }
9684ad0e1291 Move files with auxiliary functions to own directory.
ib
parents:
diff changeset
218
33115
c2da7b725fd8 Use appropriate data type uint32_t for 32 bpp bitmap data.
ib
parents: 33114
diff changeset
219 int Convert32to1(txSample *in, txSample *out, uint32_t transparent)
33046
9684ad0e1291 Move files with auxiliary functions to own directory.
ib
parents:
diff changeset
220 {
33118
ae464a957cd0 Move variable definitions at top of function.
ib
parents: 33117
diff changeset
221 uint32_t *buf;
ae464a957cd0 Move variable definitions at top of function.
ib
parents: 33117
diff changeset
222 unsigned long i;
ae464a957cd0 Move variable definitions at top of function.
ib
parents: 33117
diff changeset
223 int b = 0, c = 0;
ae464a957cd0 Move variable definitions at top of function.
ib
parents: 33117
diff changeset
224 unsigned char tmp = 0;
ae464a957cd0 Move variable definitions at top of function.
ib
parents: 33117
diff changeset
225 int shaped = 0;
ae464a957cd0 Move variable definitions at top of function.
ib
parents: 33117
diff changeset
226
33046
9684ad0e1291 Move files with auxiliary functions to own directory.
ib
parents:
diff changeset
227 out->Width = in->Width;
9684ad0e1291 Move files with auxiliary functions to own directory.
ib
parents:
diff changeset
228 out->Height = in->Height;
9684ad0e1291 Move files with auxiliary functions to own directory.
ib
parents:
diff changeset
229 out->BPP = 1;
9684ad0e1291 Move files with auxiliary functions to own directory.
ib
parents:
diff changeset
230 out->ImageSize = (out->Width * out->Height + 7) / 8;
33118
ae464a957cd0 Move variable definitions at top of function.
ib
parents: 33117
diff changeset
231 out->Image = calloc(1, out->ImageSize);
33046
9684ad0e1291 Move files with auxiliary functions to own directory.
ib
parents:
diff changeset
232
33114
5ad451a5ebec Remove useless warning message.
ib
parents: 33113
diff changeset
233 if (out->Image == NULL) {
5ad451a5ebec Remove useless warning message.
ib
parents: 33113
diff changeset
234 mp_dbg(MSGT_GPLAYER, MSGL_DBG2, "[bitmap] not enough memory: %lu\n", out->ImageSize);
5ad451a5ebec Remove useless warning message.
ib
parents: 33113
diff changeset
235 return 0;
5ad451a5ebec Remove useless warning message.
ib
parents: 33113
diff changeset
236 } else {
33115
c2da7b725fd8 Use appropriate data type uint32_t for 32 bpp bitmap data.
ib
parents: 33114
diff changeset
237 buf = (uint32_t *)in->Image;
33046
9684ad0e1291 Move files with auxiliary functions to own directory.
ib
parents:
diff changeset
238
33118
ae464a957cd0 Move variable definitions at top of function.
ib
parents: 33117
diff changeset
239 for (i = 0; i < out->Width * out->Height; i++) {
33119
8835e684a41d Move common pixel shifting statement
ib
parents: 33118
diff changeset
240 tmp >>= 1;
8835e684a41d Move common pixel shifting statement
ib
parents: 33118
diff changeset
241
33115
c2da7b725fd8 Use appropriate data type uint32_t for 32 bpp bitmap data.
ib
parents: 33114
diff changeset
242 if (buf[i] != transparent)
33119
8835e684a41d Move common pixel shifting statement
ib
parents: 33118
diff changeset
243 tmp |= 0x80;
33046
9684ad0e1291 Move files with auxiliary functions to own directory.
ib
parents:
diff changeset
244 else {
33116
00cea1a6740a Rename variable nothaveshape and invert logic.
ib
parents: 33115
diff changeset
245 buf[i] = 0;
00cea1a6740a Rename variable nothaveshape and invert logic.
ib
parents: 33115
diff changeset
246 shaped = 1;
33046
9684ad0e1291 Move files with auxiliary functions to own directory.
ib
parents:
diff changeset
247 }
9684ad0e1291 Move files with auxiliary functions to own directory.
ib
parents:
diff changeset
248
33120
e1403616342f Increment the counter before the comparison.
ib
parents: 33119
diff changeset
249 if (++b == 8) {
33046
9684ad0e1291 Move files with auxiliary functions to own directory.
ib
parents:
diff changeset
250 out->Image[c++] = tmp;
9684ad0e1291 Move files with auxiliary functions to own directory.
ib
parents:
diff changeset
251 tmp = b = 0;
9684ad0e1291 Move files with auxiliary functions to own directory.
ib
parents:
diff changeset
252 }
9684ad0e1291 Move files with auxiliary functions to own directory.
ib
parents:
diff changeset
253 }
9684ad0e1291 Move files with auxiliary functions to own directory.
ib
parents:
diff changeset
254
33112
654dfdf176ac Revise debug messages.
ib
parents: 33053
diff changeset
255 mp_dbg(MSGT_GPLAYER, MSGL_DBG2, "[bitmap] 1 bpp conversion size: %lu\n", out->ImageSize);
654dfdf176ac Revise debug messages.
ib
parents: 33053
diff changeset
256
33046
9684ad0e1291 Move files with auxiliary functions to own directory.
ib
parents:
diff changeset
257 if (b)
9684ad0e1291 Move files with auxiliary functions to own directory.
ib
parents:
diff changeset
258 out->Image[c] = tmp;
9684ad0e1291 Move files with auxiliary functions to own directory.
ib
parents:
diff changeset
259
33117
8db0a5bf65d9 Use bpFree() to free the bitmap structure.
ib
parents: 33116
diff changeset
260 if (!shaped)
8db0a5bf65d9 Use bpFree() to free the bitmap structure.
ib
parents: 33116
diff changeset
261 bpFree(out);
33046
9684ad0e1291 Move files with auxiliary functions to own directory.
ib
parents:
diff changeset
262 }
33114
5ad451a5ebec Remove useless warning message.
ib
parents: 33113
diff changeset
263
5ad451a5ebec Remove useless warning message.
ib
parents: 33113
diff changeset
264 return 1;
33046
9684ad0e1291 Move files with auxiliary functions to own directory.
ib
parents:
diff changeset
265 }