annotate gui/util/bitmap.c @ 33046:9684ad0e1291

Move files with auxiliary functions to own directory.
author ib
date Mon, 28 Mar 2011 12:37:48 +0000
parents
children f64d41dac10b
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) {
9684ad0e1291 Move files with auxiliary functions to own directory.
ib
parents:
diff changeset
44 mp_dbg(MSGT_GPLAYER, MSGL_DBG2, "[png] file read error ( %s )\n", fname);
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);
9684ad0e1291 Move files with auxiliary functions to own directory.
ib
parents:
diff changeset
53 return 2;
9684ad0e1291 Move files with auxiliary functions to own directory.
ib
parents:
diff changeset
54 }
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 data = av_malloc(len + FF_INPUT_BUFFER_PADDING_SIZE);
9684ad0e1291 Move files with auxiliary functions to own directory.
ib
parents:
diff changeset
57
9684ad0e1291 Move files with auxiliary functions to own directory.
ib
parents:
diff changeset
58 fseek(fp, 0, SEEK_SET);
9684ad0e1291 Move files with auxiliary functions to own directory.
ib
parents:
diff changeset
59 fread(data, len, 1, fp);
9684ad0e1291 Move files with auxiliary functions to own directory.
ib
parents:
diff changeset
60 fclose(fp);
9684ad0e1291 Move files with auxiliary functions to own directory.
ib
parents:
diff changeset
61
9684ad0e1291 Move files with auxiliary functions to own directory.
ib
parents:
diff changeset
62 avctx = avcodec_alloc_context();
9684ad0e1291 Move files with auxiliary functions to own directory.
ib
parents:
diff changeset
63 frame = avcodec_alloc_frame();
9684ad0e1291 Move files with auxiliary functions to own directory.
ib
parents:
diff changeset
64 avcodec_register_all();
9684ad0e1291 Move files with auxiliary functions to own directory.
ib
parents:
diff changeset
65 avcodec_open(avctx, avcodec_find_decoder(CODEC_ID_PNG));
9684ad0e1291 Move files with auxiliary functions to own directory.
ib
parents:
diff changeset
66 av_init_packet(&pkt);
9684ad0e1291 Move files with auxiliary functions to own directory.
ib
parents:
diff changeset
67 pkt.data = data;
9684ad0e1291 Move files with auxiliary functions to own directory.
ib
parents:
diff changeset
68 pkt.size = len;
9684ad0e1291 Move files with auxiliary functions to own directory.
ib
parents:
diff changeset
69 // HACK: make PNGs decode normally instead of as CorePNG delta frames
9684ad0e1291 Move files with auxiliary functions to own directory.
ib
parents:
diff changeset
70 pkt.flags = AV_PKT_FLAG_KEY;
9684ad0e1291 Move files with auxiliary functions to own directory.
ib
parents:
diff changeset
71 avcodec_decode_video2(avctx, frame, &decode_ok, &pkt);
9684ad0e1291 Move files with auxiliary functions to own directory.
ib
parents:
diff changeset
72 memset(bf, 0, sizeof(*bf));
9684ad0e1291 Move files with auxiliary functions to own directory.
ib
parents:
diff changeset
73
9684ad0e1291 Move files with auxiliary functions to own directory.
ib
parents:
diff changeset
74 switch (avctx->pix_fmt) {
9684ad0e1291 Move files with auxiliary functions to own directory.
ib
parents:
diff changeset
75 case PIX_FMT_GRAY8:
9684ad0e1291 Move files with auxiliary functions to own directory.
ib
parents:
diff changeset
76 bf->BPP = 8;
9684ad0e1291 Move files with auxiliary functions to own directory.
ib
parents:
diff changeset
77 break;
9684ad0e1291 Move files with auxiliary functions to own directory.
ib
parents:
diff changeset
78
9684ad0e1291 Move files with auxiliary functions to own directory.
ib
parents:
diff changeset
79 case PIX_FMT_GRAY16BE:
9684ad0e1291 Move files with auxiliary functions to own directory.
ib
parents:
diff changeset
80 bf->BPP = 16;
9684ad0e1291 Move files with auxiliary functions to own directory.
ib
parents:
diff changeset
81 break;
9684ad0e1291 Move files with auxiliary functions to own directory.
ib
parents:
diff changeset
82
9684ad0e1291 Move files with auxiliary functions to own directory.
ib
parents:
diff changeset
83 case PIX_FMT_RGB24:
9684ad0e1291 Move files with auxiliary functions to own directory.
ib
parents:
diff changeset
84 bf->BPP = 24;
9684ad0e1291 Move files with auxiliary functions to own directory.
ib
parents:
diff changeset
85 break;
9684ad0e1291 Move files with auxiliary functions to own directory.
ib
parents:
diff changeset
86
9684ad0e1291 Move files with auxiliary functions to own directory.
ib
parents:
diff changeset
87 case PIX_FMT_BGRA:
9684ad0e1291 Move files with auxiliary functions to own directory.
ib
parents:
diff changeset
88 case PIX_FMT_ARGB:
9684ad0e1291 Move files with auxiliary functions to own directory.
ib
parents:
diff changeset
89 bf->BPP = 32;
9684ad0e1291 Move files with auxiliary functions to own directory.
ib
parents:
diff changeset
90 break;
9684ad0e1291 Move files with auxiliary functions to own directory.
ib
parents:
diff changeset
91
9684ad0e1291 Move files with auxiliary functions to own directory.
ib
parents:
diff changeset
92 default:
9684ad0e1291 Move files with auxiliary functions to own directory.
ib
parents:
diff changeset
93 bf->BPP = 0;
9684ad0e1291 Move files with auxiliary functions to own directory.
ib
parents:
diff changeset
94 break;
9684ad0e1291 Move files with auxiliary functions to own directory.
ib
parents:
diff changeset
95 }
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 if (decode_ok && bf->BPP) {
9684ad0e1291 Move files with auxiliary functions to own directory.
ib
parents:
diff changeset
98 int bpl;
9684ad0e1291 Move files with auxiliary functions to own directory.
ib
parents:
diff changeset
99
9684ad0e1291 Move files with auxiliary functions to own directory.
ib
parents:
diff changeset
100 bf->Width = avctx->width;
9684ad0e1291 Move files with auxiliary functions to own directory.
ib
parents:
diff changeset
101 bf->Height = avctx->height;
9684ad0e1291 Move files with auxiliary functions to own directory.
ib
parents:
diff changeset
102 bpl = bf->Width * (bf->BPP / 8);
9684ad0e1291 Move files with auxiliary functions to own directory.
ib
parents:
diff changeset
103 bf->ImageSize = bpl * bf->Height;
9684ad0e1291 Move files with auxiliary functions to own directory.
ib
parents:
diff changeset
104 bf->Image = malloc(bf->ImageSize);
9684ad0e1291 Move files with auxiliary functions to own directory.
ib
parents:
diff changeset
105 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
106 }
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 avcodec_close(avctx);
9684ad0e1291 Move files with auxiliary functions to own directory.
ib
parents:
diff changeset
109 av_freep(&frame);
9684ad0e1291 Move files with auxiliary functions to own directory.
ib
parents:
diff changeset
110 av_freep(&avctx);
9684ad0e1291 Move files with auxiliary functions to own directory.
ib
parents:
diff changeset
111 av_freep(&data);
9684ad0e1291 Move files with auxiliary functions to own directory.
ib
parents:
diff changeset
112
9684ad0e1291 Move files with auxiliary functions to own directory.
ib
parents:
diff changeset
113 mp_dbg(MSGT_GPLAYER, MSGL_DBG2, "[png] filename: %s.\n", fname);
9684ad0e1291 Move files with auxiliary functions to own directory.
ib
parents:
diff changeset
114 mp_dbg(MSGT_GPLAYER, MSGL_DBG2, "[png] size: %lux%lu bits: %u\n", bf->Width, bf->Height, bf->BPP);
9684ad0e1291 Move files with auxiliary functions to own directory.
ib
parents:
diff changeset
115 mp_dbg(MSGT_GPLAYER, MSGL_DBG2, "[png] imagesize: %lu\n", bf->ImageSize);
9684ad0e1291 Move files with auxiliary functions to own directory.
ib
parents:
diff changeset
116
9684ad0e1291 Move files with auxiliary functions to own directory.
ib
parents:
diff changeset
117 return !(decode_ok && bf->BPP);
9684ad0e1291 Move files with auxiliary functions to own directory.
ib
parents:
diff changeset
118 }
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 static int conv24to32(txSample *bf)
9684ad0e1291 Move files with auxiliary functions to own directory.
ib
parents:
diff changeset
121 {
9684ad0e1291 Move files with auxiliary functions to own directory.
ib
parents:
diff changeset
122 unsigned char *tmpImage;
9684ad0e1291 Move files with auxiliary functions to own directory.
ib
parents:
diff changeset
123 unsigned int i, c;
9684ad0e1291 Move files with auxiliary functions to own directory.
ib
parents:
diff changeset
124
9684ad0e1291 Move files with auxiliary functions to own directory.
ib
parents:
diff changeset
125 if (bf->BPP == 24) {
9684ad0e1291 Move files with auxiliary functions to own directory.
ib
parents:
diff changeset
126 tmpImage = bf->Image;
9684ad0e1291 Move files with auxiliary functions to own directory.
ib
parents:
diff changeset
127 bf->BPP = 32;
9684ad0e1291 Move files with auxiliary functions to own directory.
ib
parents:
diff changeset
128 bf->ImageSize = bf->Width * bf->Height * 4;
9684ad0e1291 Move files with auxiliary functions to own directory.
ib
parents:
diff changeset
129 bf->Image = calloc(1, bf->ImageSize);
9684ad0e1291 Move files with auxiliary functions to own directory.
ib
parents:
diff changeset
130
9684ad0e1291 Move files with auxiliary functions to own directory.
ib
parents:
diff changeset
131 if (!bf->Image) {
9684ad0e1291 Move files with auxiliary functions to own directory.
ib
parents:
diff changeset
132 free(tmpImage);
9684ad0e1291 Move files with auxiliary functions to own directory.
ib
parents:
diff changeset
133 mp_dbg(MSGT_GPLAYER, MSGL_DBG2, "[bitmap] not enough memory for image\n");
9684ad0e1291 Move files with auxiliary functions to own directory.
ib
parents:
diff changeset
134 return 1;
9684ad0e1291 Move files with auxiliary functions to own directory.
ib
parents:
diff changeset
135 }
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 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
138 *(uint32_t *)&bf->Image[c] = AV_RB24(&tmpImage[i]);
9684ad0e1291 Move files with auxiliary functions to own directory.
ib
parents:
diff changeset
139
9684ad0e1291 Move files with auxiliary functions to own directory.
ib
parents:
diff changeset
140 free(tmpImage);
9684ad0e1291 Move files with auxiliary functions to own directory.
ib
parents:
diff changeset
141 }
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 return 0;
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 static void Normalize(txSample *bf)
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 int i;
9684ad0e1291 Move files with auxiliary functions to own directory.
ib
parents:
diff changeset
149
9684ad0e1291 Move files with auxiliary functions to own directory.
ib
parents:
diff changeset
150 for (i = 0; i < (int)bf->ImageSize; i += 4)
9684ad0e1291 Move files with auxiliary functions to own directory.
ib
parents:
diff changeset
151 #if !HAVE_BIGENDIAN
9684ad0e1291 Move files with auxiliary functions to own directory.
ib
parents:
diff changeset
152 bf->Image[i + 3] = 0;
9684ad0e1291 Move files with auxiliary functions to own directory.
ib
parents:
diff changeset
153 #else
9684ad0e1291 Move files with auxiliary functions to own directory.
ib
parents:
diff changeset
154 bf->Image[i] = 0;
9684ad0e1291 Move files with auxiliary functions to own directory.
ib
parents:
diff changeset
155 #endif
9684ad0e1291 Move files with auxiliary functions to own directory.
ib
parents:
diff changeset
156 }
9684ad0e1291 Move files with auxiliary functions to own directory.
ib
parents:
diff changeset
157
9684ad0e1291 Move files with auxiliary functions to own directory.
ib
parents:
diff changeset
158 static unsigned char *fExist(unsigned char *fname)
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 static unsigned char tmp[512];
9684ad0e1291 Move files with auxiliary functions to own directory.
ib
parents:
diff changeset
161 FILE *fl;
9684ad0e1291 Move files with auxiliary functions to own directory.
ib
parents:
diff changeset
162 unsigned char ext[][6] = { ".png\0", ".PNG\0" };
9684ad0e1291 Move files with auxiliary functions to own directory.
ib
parents:
diff changeset
163 int i;
9684ad0e1291 Move files with auxiliary functions to own directory.
ib
parents:
diff changeset
164
9684ad0e1291 Move files with auxiliary functions to own directory.
ib
parents:
diff changeset
165 fl = fopen(fname, "rb");
9684ad0e1291 Move files with auxiliary functions to own directory.
ib
parents:
diff changeset
166
9684ad0e1291 Move files with auxiliary functions to own directory.
ib
parents:
diff changeset
167 if (fl != NULL) {
9684ad0e1291 Move files with auxiliary functions to own directory.
ib
parents:
diff changeset
168 fclose(fl);
9684ad0e1291 Move files with auxiliary functions to own directory.
ib
parents:
diff changeset
169 return fname;
9684ad0e1291 Move files with auxiliary functions to own directory.
ib
parents:
diff changeset
170 }
9684ad0e1291 Move files with auxiliary functions to own directory.
ib
parents:
diff changeset
171
9684ad0e1291 Move files with auxiliary functions to own directory.
ib
parents:
diff changeset
172 for (i = 0; i < 2; i++) {
9684ad0e1291 Move files with auxiliary functions to own directory.
ib
parents:
diff changeset
173 snprintf(tmp, sizeof(tmp), "%s%s", fname, ext[i]);
9684ad0e1291 Move files with auxiliary functions to own directory.
ib
parents:
diff changeset
174 fl = fopen(tmp, "rb");
9684ad0e1291 Move files with auxiliary functions to own directory.
ib
parents:
diff changeset
175
9684ad0e1291 Move files with auxiliary functions to own directory.
ib
parents:
diff changeset
176 if (fl != NULL) {
9684ad0e1291 Move files with auxiliary functions to own directory.
ib
parents:
diff changeset
177 fclose(fl);
9684ad0e1291 Move files with auxiliary functions to own directory.
ib
parents:
diff changeset
178 return tmp;
9684ad0e1291 Move files with auxiliary functions to own directory.
ib
parents:
diff changeset
179 }
9684ad0e1291 Move files with auxiliary functions to own directory.
ib
parents:
diff changeset
180 }
9684ad0e1291 Move files with auxiliary functions to own directory.
ib
parents:
diff changeset
181
9684ad0e1291 Move files with auxiliary functions to own directory.
ib
parents:
diff changeset
182 return NULL;
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 int bpRead(char *fname, txSample *bf)
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 fname = fExist(fname);
9684ad0e1291 Move files with auxiliary functions to own directory.
ib
parents:
diff changeset
188
9684ad0e1291 Move files with auxiliary functions to own directory.
ib
parents:
diff changeset
189 if (fname == NULL)
9684ad0e1291 Move files with auxiliary functions to own directory.
ib
parents:
diff changeset
190 return -2;
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 (pngRead(fname, bf)) {
9684ad0e1291 Move files with auxiliary functions to own directory.
ib
parents:
diff changeset
193 mp_dbg(MSGT_GPLAYER, MSGL_FATAL, "[bitmap] unknown file type ( %s )\n", fname);
9684ad0e1291 Move files with auxiliary functions to own directory.
ib
parents:
diff changeset
194 return -5;
9684ad0e1291 Move files with auxiliary functions to own directory.
ib
parents:
diff changeset
195 }
9684ad0e1291 Move files with auxiliary functions to own directory.
ib
parents:
diff changeset
196
9684ad0e1291 Move files with auxiliary functions to own directory.
ib
parents:
diff changeset
197 if (bf->BPP < 24) {
9684ad0e1291 Move files with auxiliary functions to own directory.
ib
parents:
diff changeset
198 mp_dbg(MSGT_GPLAYER, MSGL_DBG2, "[bitmap] Sorry, only 24 and 32 bpp bitmaps are supported.\n");
9684ad0e1291 Move files with auxiliary functions to own directory.
ib
parents:
diff changeset
199 return -1;
9684ad0e1291 Move files with auxiliary functions to own directory.
ib
parents:
diff changeset
200 }
9684ad0e1291 Move files with auxiliary functions to own directory.
ib
parents:
diff changeset
201
9684ad0e1291 Move files with auxiliary functions to own directory.
ib
parents:
diff changeset
202 if (conv24to32(bf))
9684ad0e1291 Move files with auxiliary functions to own directory.
ib
parents:
diff changeset
203 return -8;
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 Normalize(bf);
9684ad0e1291 Move files with auxiliary functions to own directory.
ib
parents:
diff changeset
206 return 0;
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
9684ad0e1291 Move files with auxiliary functions to own directory.
ib
parents:
diff changeset
209 void bpFree(txSample *bf)
9684ad0e1291 Move files with auxiliary functions to own directory.
ib
parents:
diff changeset
210 {
9684ad0e1291 Move files with auxiliary functions to own directory.
ib
parents:
diff changeset
211 free(bf->Image);
9684ad0e1291 Move files with auxiliary functions to own directory.
ib
parents:
diff changeset
212 memset(bf, 0, sizeof(*bf));
9684ad0e1291 Move files with auxiliary functions to own directory.
ib
parents:
diff changeset
213 }
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 void Convert32to1(txSample *in, txSample *out, int adaptivlimit)
9684ad0e1291 Move files with auxiliary functions to own directory.
ib
parents:
diff changeset
216 {
9684ad0e1291 Move files with auxiliary functions to own directory.
ib
parents:
diff changeset
217 out->Width = in->Width;
9684ad0e1291 Move files with auxiliary functions to own directory.
ib
parents:
diff changeset
218 out->Height = in->Height;
9684ad0e1291 Move files with auxiliary functions to own directory.
ib
parents:
diff changeset
219 out->BPP = 1;
9684ad0e1291 Move files with auxiliary functions to own directory.
ib
parents:
diff changeset
220 out->ImageSize = (out->Width * out->Height + 7) / 8;
9684ad0e1291 Move files with auxiliary functions to own directory.
ib
parents:
diff changeset
221
9684ad0e1291 Move files with auxiliary functions to own directory.
ib
parents:
diff changeset
222 mp_dbg(MSGT_GPLAYER, MSGL_DBG2, "[c32to1] imagesize: %lu\n", out->ImageSize);
9684ad0e1291 Move files with auxiliary functions to own directory.
ib
parents:
diff changeset
223
9684ad0e1291 Move files with auxiliary functions to own directory.
ib
parents:
diff changeset
224 out->Image = calloc(1, out->ImageSize);
9684ad0e1291 Move files with auxiliary functions to own directory.
ib
parents:
diff changeset
225
9684ad0e1291 Move files with auxiliary functions to own directory.
ib
parents:
diff changeset
226 if (out->Image == NULL)
9684ad0e1291 Move files with auxiliary functions to own directory.
ib
parents:
diff changeset
227 mp_msg(MSGT_GPLAYER, MSGL_WARN, MSGTR_NotEnoughMemoryC32To1);
9684ad0e1291 Move files with auxiliary functions to own directory.
ib
parents:
diff changeset
228 {
9684ad0e1291 Move files with auxiliary functions to own directory.
ib
parents:
diff changeset
229 int i, b, c = 0;
9684ad0e1291 Move files with auxiliary functions to own directory.
ib
parents:
diff changeset
230 unsigned int *buf = NULL;
9684ad0e1291 Move files with auxiliary functions to own directory.
ib
parents:
diff changeset
231 unsigned char tmp = 0;
9684ad0e1291 Move files with auxiliary functions to own directory.
ib
parents:
diff changeset
232 int nothaveshape = 1;
9684ad0e1291 Move files with auxiliary functions to own directory.
ib
parents:
diff changeset
233
9684ad0e1291 Move files with auxiliary functions to own directory.
ib
parents:
diff changeset
234 buf = (unsigned int *)in->Image;
9684ad0e1291 Move files with auxiliary functions to own directory.
ib
parents:
diff changeset
235
9684ad0e1291 Move files with auxiliary functions to own directory.
ib
parents:
diff changeset
236 for (b = 0, i = 0; i < (int)(out->Width * out->Height); i++) {
9684ad0e1291 Move files with auxiliary functions to own directory.
ib
parents:
diff changeset
237 if ((int)buf[i] != adaptivlimit)
9684ad0e1291 Move files with auxiliary functions to own directory.
ib
parents:
diff changeset
238 tmp = (tmp >> 1) | 128;
9684ad0e1291 Move files with auxiliary functions to own directory.
ib
parents:
diff changeset
239 else {
9684ad0e1291 Move files with auxiliary functions to own directory.
ib
parents:
diff changeset
240 tmp = tmp >> 1;
9684ad0e1291 Move files with auxiliary functions to own directory.
ib
parents:
diff changeset
241 buf[i] = nothaveshape = 0;
9684ad0e1291 Move files with auxiliary functions to own directory.
ib
parents:
diff changeset
242 }
9684ad0e1291 Move files with auxiliary functions to own directory.
ib
parents:
diff changeset
243
9684ad0e1291 Move files with auxiliary functions to own directory.
ib
parents:
diff changeset
244 if (b++ == 7) {
9684ad0e1291 Move files with auxiliary functions to own directory.
ib
parents:
diff changeset
245 out->Image[c++] = tmp;
9684ad0e1291 Move files with auxiliary functions to own directory.
ib
parents:
diff changeset
246 tmp = b = 0;
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 }
9684ad0e1291 Move files with auxiliary functions to own directory.
ib
parents:
diff changeset
249
9684ad0e1291 Move files with auxiliary functions to own directory.
ib
parents:
diff changeset
250 if (b)
9684ad0e1291 Move files with auxiliary functions to own directory.
ib
parents:
diff changeset
251 out->Image[c] = tmp;
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 if (nothaveshape) {
9684ad0e1291 Move files with auxiliary functions to own directory.
ib
parents:
diff changeset
254 free(out->Image);
9684ad0e1291 Move files with auxiliary functions to own directory.
ib
parents:
diff changeset
255 out->Image = NULL;
9684ad0e1291 Move files with auxiliary functions to own directory.
ib
parents:
diff changeset
256 }
9684ad0e1291 Move files with auxiliary functions to own directory.
ib
parents:
diff changeset
257 }
9684ad0e1291 Move files with auxiliary functions to own directory.
ib
parents:
diff changeset
258 }