annotate gui/util/bitmap.c @ 33126:a5dc70e2cda3

Cosmetic: Adjust indent.
author ib
date Mon, 04 Apr 2011 18:25:11 +0000
parents 9c178cf14a61
children 6328f0baeaa9
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 {
33122
1d81476c0d1e Cosmetic: Rephrase some conditions and rename some variables.
ib
parents: 33121
diff changeset
33 FILE *file;
33046
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
33122
1d81476c0d1e Cosmetic: Rephrase some conditions and rename some variables.
ib
parents: 33121
diff changeset
41 file = fopen(fname, "rb");
33046
9684ad0e1291 Move files with auxiliary functions to own directory.
ib
parents:
diff changeset
42
33122
1d81476c0d1e Cosmetic: Rephrase some conditions and rename some variables.
ib
parents: 33121
diff changeset
43 if (!file) {
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
33122
1d81476c0d1e Cosmetic: Rephrase some conditions and rename some variables.
ib
parents: 33121
diff changeset
48 fseek(file, 0, SEEK_END);
1d81476c0d1e Cosmetic: Rephrase some conditions and rename some variables.
ib
parents: 33121
diff changeset
49 len = ftell(file);
33046
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) {
33122
1d81476c0d1e Cosmetic: Rephrase some conditions and rename some variables.
ib
parents: 33121
diff changeset
52 fclose(file);
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
33122
1d81476c0d1e Cosmetic: Rephrase some conditions and rename some variables.
ib
parents: 33121
diff changeset
59 fseek(file, 0, SEEK_SET);
1d81476c0d1e Cosmetic: Rephrase some conditions and rename some variables.
ib
parents: 33121
diff changeset
60 fread(data, len, 1, file);
1d81476c0d1e Cosmetic: Rephrase some conditions and rename some variables.
ib
parents: 33121
diff changeset
61 fclose(file);
33046
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
33121
7623be6c1f0e Rename conv24to32() Convert24to32().
ib
parents: 33120
diff changeset
121 static int Convert24to32(txSample *bf)
33046
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);
33121
7623be6c1f0e Rename conv24to32() Convert24to32().
ib
parents: 33120
diff changeset
135 return 0;
33046
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
33121
7623be6c1f0e Rename conv24to32() Convert24to32().
ib
parents: 33120
diff changeset
146 return 1;
33046
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];
33122
1d81476c0d1e Cosmetic: Rephrase some conditions and rename some variables.
ib
parents: 33121
diff changeset
164 FILE *file;
33046
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
33122
1d81476c0d1e Cosmetic: Rephrase some conditions and rename some variables.
ib
parents: 33121
diff changeset
168 file = fopen(fname, "rb");
33046
9684ad0e1291 Move files with auxiliary functions to own directory.
ib
parents:
diff changeset
169
33122
1d81476c0d1e Cosmetic: Rephrase some conditions and rename some variables.
ib
parents: 33121
diff changeset
170 if (file) {
1d81476c0d1e Cosmetic: Rephrase some conditions and rename some variables.
ib
parents: 33121
diff changeset
171 fclose(file);
33046
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]);
33122
1d81476c0d1e Cosmetic: Rephrase some conditions and rename some variables.
ib
parents: 33121
diff changeset
177 file = fopen(tmp, "rb");
33046
9684ad0e1291 Move files with auxiliary functions to own directory.
ib
parents:
diff changeset
178
33122
1d81476c0d1e Cosmetic: Rephrase some conditions and rename some variables.
ib
parents: 33121
diff changeset
179 if (file) {
1d81476c0d1e Cosmetic: Rephrase some conditions and rename some variables.
ib
parents: 33121
diff changeset
180 fclose(file);
33046
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
33122
1d81476c0d1e Cosmetic: Rephrase some conditions and rename some variables.
ib
parents: 33121
diff changeset
192 if (!fname)
33046
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
33122
1d81476c0d1e Cosmetic: Rephrase some conditions and rename some variables.
ib
parents: 33121
diff changeset
195 if (pngRead(fname, bf) != 0) {
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
33121
7623be6c1f0e Rename conv24to32() Convert24to32().
ib
parents: 33120
diff changeset
205 if (!Convert24to32(bf))
33046
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
33122
1d81476c0d1e Cosmetic: Rephrase some conditions and rename some variables.
ib
parents: 33121
diff changeset
233 if (!out->Image) {
33114
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;
33125
9c178cf14a61 Get rid of else-block to improve readability.
ib
parents: 33122
diff changeset
236 }
9c178cf14a61 Get rid of else-block to improve readability.
ib
parents: 33122
diff changeset
237
33126
a5dc70e2cda3 Cosmetic: Adjust indent.
ib
parents: 33125
diff changeset
238 buf = (uint32_t *)in->Image;
33046
9684ad0e1291 Move files with auxiliary functions to own directory.
ib
parents:
diff changeset
239
33126
a5dc70e2cda3 Cosmetic: Adjust indent.
ib
parents: 33125
diff changeset
240 for (i = 0; i < out->Width * out->Height; i++) {
a5dc70e2cda3 Cosmetic: Adjust indent.
ib
parents: 33125
diff changeset
241 tmp >>= 1;
33119
8835e684a41d Move common pixel shifting statement
ib
parents: 33118
diff changeset
242
33126
a5dc70e2cda3 Cosmetic: Adjust indent.
ib
parents: 33125
diff changeset
243 if (buf[i] != transparent)
a5dc70e2cda3 Cosmetic: Adjust indent.
ib
parents: 33125
diff changeset
244 tmp |= 0x80;
a5dc70e2cda3 Cosmetic: Adjust indent.
ib
parents: 33125
diff changeset
245 else {
a5dc70e2cda3 Cosmetic: Adjust indent.
ib
parents: 33125
diff changeset
246 buf[i] = 0;
a5dc70e2cda3 Cosmetic: Adjust indent.
ib
parents: 33125
diff changeset
247 shaped = 1;
33046
9684ad0e1291 Move files with auxiliary functions to own directory.
ib
parents:
diff changeset
248 }
9684ad0e1291 Move files with auxiliary functions to own directory.
ib
parents:
diff changeset
249
33126
a5dc70e2cda3 Cosmetic: Adjust indent.
ib
parents: 33125
diff changeset
250 if (++b == 8) {
a5dc70e2cda3 Cosmetic: Adjust indent.
ib
parents: 33125
diff changeset
251 out->Image[c++] = tmp;
a5dc70e2cda3 Cosmetic: Adjust indent.
ib
parents: 33125
diff changeset
252 tmp = b = 0;
a5dc70e2cda3 Cosmetic: Adjust indent.
ib
parents: 33125
diff changeset
253 }
a5dc70e2cda3 Cosmetic: Adjust indent.
ib
parents: 33125
diff changeset
254 }
33112
654dfdf176ac Revise debug messages.
ib
parents: 33053
diff changeset
255
33126
a5dc70e2cda3 Cosmetic: Adjust indent.
ib
parents: 33125
diff changeset
256 mp_dbg(MSGT_GPLAYER, MSGL_DBG2, "[bitmap] 1 bpp conversion size: %lu\n", out->ImageSize);
33046
9684ad0e1291 Move files with auxiliary functions to own directory.
ib
parents:
diff changeset
257
33126
a5dc70e2cda3 Cosmetic: Adjust indent.
ib
parents: 33125
diff changeset
258 if (b)
a5dc70e2cda3 Cosmetic: Adjust indent.
ib
parents: 33125
diff changeset
259 out->Image[c] = tmp;
a5dc70e2cda3 Cosmetic: Adjust indent.
ib
parents: 33125
diff changeset
260
a5dc70e2cda3 Cosmetic: Adjust indent.
ib
parents: 33125
diff changeset
261 if (!shaped)
a5dc70e2cda3 Cosmetic: Adjust indent.
ib
parents: 33125
diff changeset
262 bpFree(out);
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 }