annotate gui/util/bitmap.c @ 33983:2218c589f9ab

Cosmetic: Rename parameters bf img in bitmap.c.
author ib
date Tue, 06 Sep 2011 14:59:04 +0000
parents fd498969e72d
children 60449f4234f7
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>
33130
4f60cd16ac04 Clean up and simplify fExist().
ib
parents: 33129
diff changeset
22 #include <unistd.h>
33046
9684ad0e1291 Move files with auxiliary functions to own directory.
ib
parents:
diff changeset
23
9684ad0e1291 Move files with auxiliary functions to own directory.
ib
parents:
diff changeset
24 #include "bitmap.h"
9684ad0e1291 Move files with auxiliary functions to own directory.
ib
parents:
diff changeset
25
9684ad0e1291 Move files with auxiliary functions to own directory.
ib
parents:
diff changeset
26 #include "help_mp.h"
9684ad0e1291 Move files with auxiliary functions to own directory.
ib
parents:
diff changeset
27 #include "libavcodec/avcodec.h"
33690
76342ee379eb Add missing #include "libavutil/common.h".
ib
parents: 33555
diff changeset
28 #include "libavutil/common.h"
33046
9684ad0e1291 Move files with auxiliary functions to own directory.
ib
parents:
diff changeset
29 #include "libavutil/intreadwrite.h"
9684ad0e1291 Move files with auxiliary functions to own directory.
ib
parents:
diff changeset
30 #include "libvo/fastmemcpy.h"
9684ad0e1291 Move files with auxiliary functions to own directory.
ib
parents:
diff changeset
31 #include "mp_msg.h"
9684ad0e1291 Move files with auxiliary functions to own directory.
ib
parents:
diff changeset
32
33983
2218c589f9ab Cosmetic: Rename parameters bf img in bitmap.c.
ib
parents: 33710
diff changeset
33 static int pngRead(const char *fname, guiImage *img)
33046
9684ad0e1291 Move files with auxiliary functions to own directory.
ib
parents:
diff changeset
34 {
33122
1d81476c0d1e Cosmetic: Rephrase some conditions and rename some variables.
ib
parents: 33121
diff changeset
35 FILE *file;
33134
ffe524b8b8f3 Make len match ftell() return value type.
ib
parents: 33133
diff changeset
36 long len;
33046
9684ad0e1291 Move files with auxiliary functions to own directory.
ib
parents:
diff changeset
37 void *data;
33135
36fdc061b4a8 Prevent segmentation faults.
ib
parents: 33134
diff changeset
38 int decode_ok, bpl;
33046
9684ad0e1291 Move files with auxiliary functions to own directory.
ib
parents:
diff changeset
39 AVCodecContext *avctx;
9684ad0e1291 Move files with auxiliary functions to own directory.
ib
parents:
diff changeset
40 AVFrame *frame;
9684ad0e1291 Move files with auxiliary functions to own directory.
ib
parents:
diff changeset
41 AVPacket pkt;
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 file = fopen(fname, "rb");
33046
9684ad0e1291 Move files with auxiliary functions to own directory.
ib
parents:
diff changeset
44
33137
f884fb919ac5 Remove various pngRead() debug messages.
ib
parents: 33136
diff changeset
45 if (!file)
f884fb919ac5 Remove various pngRead() debug messages.
ib
parents: 33136
diff changeset
46 return 2;
33046
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);
33137
f884fb919ac5 Remove various pngRead() debug messages.
ib
parents: 33136
diff changeset
53 return 3;
33046
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
33135
36fdc061b4a8 Prevent segmentation faults.
ib
parents: 33134
diff changeset
58 if (!data) {
36fdc061b4a8 Prevent segmentation faults.
ib
parents: 33134
diff changeset
59 fclose(file);
33137
f884fb919ac5 Remove various pngRead() debug messages.
ib
parents: 33136
diff changeset
60 return 4;
33135
36fdc061b4a8 Prevent segmentation faults.
ib
parents: 33134
diff changeset
61 }
36fdc061b4a8 Prevent segmentation faults.
ib
parents: 33134
diff changeset
62
33122
1d81476c0d1e Cosmetic: Rephrase some conditions and rename some variables.
ib
parents: 33121
diff changeset
63 fseek(file, 0, SEEK_SET);
1d81476c0d1e Cosmetic: Rephrase some conditions and rename some variables.
ib
parents: 33121
diff changeset
64 fread(data, len, 1, file);
1d81476c0d1e Cosmetic: Rephrase some conditions and rename some variables.
ib
parents: 33121
diff changeset
65 fclose(file);
33046
9684ad0e1291 Move files with auxiliary functions to own directory.
ib
parents:
diff changeset
66
9684ad0e1291 Move files with auxiliary functions to own directory.
ib
parents:
diff changeset
67 avctx = avcodec_alloc_context();
9684ad0e1291 Move files with auxiliary functions to own directory.
ib
parents:
diff changeset
68 frame = avcodec_alloc_frame();
33139
64f29d5dfea2 Prevent segmentation faults.
ib
parents: 33138
diff changeset
69
64f29d5dfea2 Prevent segmentation faults.
ib
parents: 33138
diff changeset
70 if (!(avctx && frame)) {
64f29d5dfea2 Prevent segmentation faults.
ib
parents: 33138
diff changeset
71 av_free(frame);
64f29d5dfea2 Prevent segmentation faults.
ib
parents: 33138
diff changeset
72 av_free(avctx);
64f29d5dfea2 Prevent segmentation faults.
ib
parents: 33138
diff changeset
73 av_free(data);
64f29d5dfea2 Prevent segmentation faults.
ib
parents: 33138
diff changeset
74 return 5;
64f29d5dfea2 Prevent segmentation faults.
ib
parents: 33138
diff changeset
75 }
64f29d5dfea2 Prevent segmentation faults.
ib
parents: 33138
diff changeset
76
33046
9684ad0e1291 Move files with auxiliary functions to own directory.
ib
parents:
diff changeset
77 avcodec_register_all();
9684ad0e1291 Move files with auxiliary functions to own directory.
ib
parents:
diff changeset
78 avcodec_open(avctx, avcodec_find_decoder(CODEC_ID_PNG));
33139
64f29d5dfea2 Prevent segmentation faults.
ib
parents: 33138
diff changeset
79
33046
9684ad0e1291 Move files with auxiliary functions to own directory.
ib
parents:
diff changeset
80 av_init_packet(&pkt);
9684ad0e1291 Move files with auxiliary functions to own directory.
ib
parents:
diff changeset
81 pkt.data = data;
9684ad0e1291 Move files with auxiliary functions to own directory.
ib
parents:
diff changeset
82 pkt.size = len;
9684ad0e1291 Move files with auxiliary functions to own directory.
ib
parents:
diff changeset
83 // HACK: make PNGs decode normally instead of as CorePNG delta frames
9684ad0e1291 Move files with auxiliary functions to own directory.
ib
parents:
diff changeset
84 pkt.flags = AV_PKT_FLAG_KEY;
33139
64f29d5dfea2 Prevent segmentation faults.
ib
parents: 33138
diff changeset
85
33046
9684ad0e1291 Move files with auxiliary functions to own directory.
ib
parents:
diff changeset
86 avcodec_decode_video2(avctx, frame, &decode_ok, &pkt);
33134
ffe524b8b8f3 Make len match ftell() return value type.
ib
parents: 33133
diff changeset
87
33983
2218c589f9ab Cosmetic: Rename parameters bf img in bitmap.c.
ib
parents: 33710
diff changeset
88 memset(img, 0, sizeof(*img));
33046
9684ad0e1291 Move files with auxiliary functions to own directory.
ib
parents:
diff changeset
89
9684ad0e1291 Move files with auxiliary functions to own directory.
ib
parents:
diff changeset
90 switch (avctx->pix_fmt) {
9684ad0e1291 Move files with auxiliary functions to own directory.
ib
parents:
diff changeset
91 case PIX_FMT_GRAY8:
33983
2218c589f9ab Cosmetic: Rename parameters bf img in bitmap.c.
ib
parents: 33710
diff changeset
92 img->Bpp = 8;
33046
9684ad0e1291 Move files with auxiliary functions to own directory.
ib
parents:
diff changeset
93 break;
9684ad0e1291 Move files with auxiliary functions to own directory.
ib
parents:
diff changeset
94
9684ad0e1291 Move files with auxiliary functions to own directory.
ib
parents:
diff changeset
95 case PIX_FMT_GRAY16BE:
33983
2218c589f9ab Cosmetic: Rename parameters bf img in bitmap.c.
ib
parents: 33710
diff changeset
96 img->Bpp = 16;
33046
9684ad0e1291 Move files with auxiliary functions to own directory.
ib
parents:
diff changeset
97 break;
9684ad0e1291 Move files with auxiliary functions to own directory.
ib
parents:
diff changeset
98
9684ad0e1291 Move files with auxiliary functions to own directory.
ib
parents:
diff changeset
99 case PIX_FMT_RGB24:
33983
2218c589f9ab Cosmetic: Rename parameters bf img in bitmap.c.
ib
parents: 33710
diff changeset
100 img->Bpp = 24;
33046
9684ad0e1291 Move files with auxiliary functions to own directory.
ib
parents:
diff changeset
101 break;
9684ad0e1291 Move files with auxiliary functions to own directory.
ib
parents:
diff changeset
102
9684ad0e1291 Move files with auxiliary functions to own directory.
ib
parents:
diff changeset
103 case PIX_FMT_BGRA:
9684ad0e1291 Move files with auxiliary functions to own directory.
ib
parents:
diff changeset
104 case PIX_FMT_ARGB:
33983
2218c589f9ab Cosmetic: Rename parameters bf img in bitmap.c.
ib
parents: 33710
diff changeset
105 img->Bpp = 32;
33046
9684ad0e1291 Move files with auxiliary functions to own directory.
ib
parents:
diff changeset
106 break;
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 default:
33983
2218c589f9ab Cosmetic: Rename parameters bf img in bitmap.c.
ib
parents: 33710
diff changeset
109 img->Bpp = 0;
33046
9684ad0e1291 Move files with auxiliary functions to own directory.
ib
parents:
diff changeset
110 break;
9684ad0e1291 Move files with auxiliary functions to own directory.
ib
parents:
diff changeset
111 }
9684ad0e1291 Move files with auxiliary functions to own directory.
ib
parents:
diff changeset
112
33983
2218c589f9ab Cosmetic: Rename parameters bf img in bitmap.c.
ib
parents: 33710
diff changeset
113 if (decode_ok && img->Bpp) {
2218c589f9ab Cosmetic: Rename parameters bf img in bitmap.c.
ib
parents: 33710
diff changeset
114 img->Width = avctx->width;
2218c589f9ab Cosmetic: Rename parameters bf img in bitmap.c.
ib
parents: 33710
diff changeset
115 img->Height = avctx->height;
2218c589f9ab Cosmetic: Rename parameters bf img in bitmap.c.
ib
parents: 33710
diff changeset
116 bpl = img->Width * (img->Bpp / 8);
2218c589f9ab Cosmetic: Rename parameters bf img in bitmap.c.
ib
parents: 33710
diff changeset
117 img->ImageSize = bpl * img->Height;
33136
07be88814256 Move debug messages.
ib
parents: 33135
diff changeset
118
07be88814256 Move debug messages.
ib
parents: 33135
diff changeset
119 mp_dbg(MSGT_GPLAYER, MSGL_DBG2, "[bitmap] file: %s\n", fname);
33983
2218c589f9ab Cosmetic: Rename parameters bf img in bitmap.c.
ib
parents: 33710
diff changeset
120 mp_dbg(MSGT_GPLAYER, MSGL_DBG2, "[bitmap] size: %lux%lu, color depth: %u\n", img->Width, img->Height, img->Bpp);
2218c589f9ab Cosmetic: Rename parameters bf img in bitmap.c.
ib
parents: 33710
diff changeset
121 mp_dbg(MSGT_GPLAYER, MSGL_DBG2, "[bitmap] image size: %lu\n", img->ImageSize);
33136
07be88814256 Move debug messages.
ib
parents: 33135
diff changeset
122
33983
2218c589f9ab Cosmetic: Rename parameters bf img in bitmap.c.
ib
parents: 33710
diff changeset
123 img->Image = malloc(img->ImageSize);
33135
36fdc061b4a8 Prevent segmentation faults.
ib
parents: 33134
diff changeset
124
33983
2218c589f9ab Cosmetic: Rename parameters bf img in bitmap.c.
ib
parents: 33710
diff changeset
125 if (img->Image)
2218c589f9ab Cosmetic: Rename parameters bf img in bitmap.c.
ib
parents: 33710
diff changeset
126 memcpy_pic(img->Image, frame->data[0], bpl, img->Height, bpl, frame->linesize[0]);
33137
f884fb919ac5 Remove various pngRead() debug messages.
ib
parents: 33136
diff changeset
127 else
f884fb919ac5 Remove various pngRead() debug messages.
ib
parents: 33136
diff changeset
128 decode_ok = 0;
33046
9684ad0e1291 Move files with auxiliary functions to own directory.
ib
parents:
diff changeset
129 }
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 avcodec_close(avctx);
33138
3335d117f6e6 Replace av_freep by av_free
ib
parents: 33137
diff changeset
132 av_free(frame);
3335d117f6e6 Replace av_freep by av_free
ib
parents: 33137
diff changeset
133 av_free(avctx);
3335d117f6e6 Replace av_freep by av_free
ib
parents: 33137
diff changeset
134 av_free(data);
33046
9684ad0e1291 Move files with auxiliary functions to own directory.
ib
parents:
diff changeset
135
33983
2218c589f9ab Cosmetic: Rename parameters bf img in bitmap.c.
ib
parents: 33710
diff changeset
136 return !(decode_ok && img->Bpp);
33046
9684ad0e1291 Move files with auxiliary functions to own directory.
ib
parents:
diff changeset
137 }
9684ad0e1291 Move files with auxiliary functions to own directory.
ib
parents:
diff changeset
138
33983
2218c589f9ab Cosmetic: Rename parameters bf img in bitmap.c.
ib
parents: 33710
diff changeset
139 static int Convert24to32(guiImage *img)
33046
9684ad0e1291 Move files with auxiliary functions to own directory.
ib
parents:
diff changeset
140 {
33132
6ac1b560e209 Revise Convert24to32().
ib
parents: 33131
diff changeset
141 char *orgImage;
6ac1b560e209 Revise Convert24to32().
ib
parents: 33131
diff changeset
142 unsigned long i, c;
33046
9684ad0e1291 Move files with auxiliary functions to own directory.
ib
parents:
diff changeset
143
33983
2218c589f9ab Cosmetic: Rename parameters bf img in bitmap.c.
ib
parents: 33710
diff changeset
144 if (img->Bpp == 24) {
2218c589f9ab Cosmetic: Rename parameters bf img in bitmap.c.
ib
parents: 33710
diff changeset
145 orgImage = img->Image;
33132
6ac1b560e209 Revise Convert24to32().
ib
parents: 33131
diff changeset
146
33983
2218c589f9ab Cosmetic: Rename parameters bf img in bitmap.c.
ib
parents: 33710
diff changeset
147 img->Bpp = 32;
2218c589f9ab Cosmetic: Rename parameters bf img in bitmap.c.
ib
parents: 33710
diff changeset
148 img->ImageSize = img->Width * img->Height * 4;
2218c589f9ab Cosmetic: Rename parameters bf img in bitmap.c.
ib
parents: 33710
diff changeset
149 img->Image = calloc(1, img->ImageSize);
33046
9684ad0e1291 Move files with auxiliary functions to own directory.
ib
parents:
diff changeset
150
33983
2218c589f9ab Cosmetic: Rename parameters bf img in bitmap.c.
ib
parents: 33710
diff changeset
151 if (!img->Image) {
33132
6ac1b560e209 Revise Convert24to32().
ib
parents: 33131
diff changeset
152 free(orgImage);
33983
2218c589f9ab Cosmetic: Rename parameters bf img in bitmap.c.
ib
parents: 33710
diff changeset
153 mp_dbg(MSGT_GPLAYER, MSGL_DBG2, "[bitmap] not enough memory: %lu\n", img->ImageSize);
33121
7623be6c1f0e Rename conv24to32() Convert24to32().
ib
parents: 33120
diff changeset
154 return 0;
33046
9684ad0e1291 Move files with auxiliary functions to own directory.
ib
parents:
diff changeset
155 }
9684ad0e1291 Move files with auxiliary functions to own directory.
ib
parents:
diff changeset
156
33983
2218c589f9ab Cosmetic: Rename parameters bf img in bitmap.c.
ib
parents: 33710
diff changeset
157 mp_dbg(MSGT_GPLAYER, MSGL_DBG2, "[bitmap] 32 bpp conversion size: %lu\n", img->ImageSize);
33112
654dfdf176ac Revise debug messages.
ib
parents: 33053
diff changeset
158
33983
2218c589f9ab Cosmetic: Rename parameters bf img in bitmap.c.
ib
parents: 33710
diff changeset
159 for (c = 0, i = 0; c < img->ImageSize; c += 4, i += 3)
2218c589f9ab Cosmetic: Rename parameters bf img in bitmap.c.
ib
parents: 33710
diff changeset
160 *(uint32_t *)&img->Image[c] = ALPHA_OPAQUE | AV_RB24(&orgImage[i]);
33046
9684ad0e1291 Move files with auxiliary functions to own directory.
ib
parents:
diff changeset
161
33132
6ac1b560e209 Revise Convert24to32().
ib
parents: 33131
diff changeset
162 free(orgImage);
33046
9684ad0e1291 Move files with auxiliary functions to own directory.
ib
parents:
diff changeset
163 }
9684ad0e1291 Move files with auxiliary functions to own directory.
ib
parents:
diff changeset
164
33121
7623be6c1f0e Rename conv24to32() Convert24to32().
ib
parents: 33120
diff changeset
165 return 1;
33046
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
33710
fd498969e72d Clean up some function prototypes.
reimar
parents: 33690
diff changeset
168 static const char *fExist(const char *fname)
33046
9684ad0e1291 Move files with auxiliary functions to own directory.
ib
parents:
diff changeset
169 {
33141
fd90a10d81a1 Define ext array more skillfully.
ib
parents: 33139
diff changeset
170 static const char ext[][4] = { "png", "PNG" };
33710
fd498969e72d Clean up some function prototypes.
reimar
parents: 33690
diff changeset
171 static char buf[512];
33130
4f60cd16ac04 Clean up and simplify fExist().
ib
parents: 33129
diff changeset
172 unsigned int i;
33046
9684ad0e1291 Move files with auxiliary functions to own directory.
ib
parents:
diff changeset
173
33130
4f60cd16ac04 Clean up and simplify fExist().
ib
parents: 33129
diff changeset
174 if (access(fname, R_OK) == 0)
33046
9684ad0e1291 Move files with auxiliary functions to own directory.
ib
parents:
diff changeset
175 return fname;
9684ad0e1291 Move files with auxiliary functions to own directory.
ib
parents:
diff changeset
176
33130
4f60cd16ac04 Clean up and simplify fExist().
ib
parents: 33129
diff changeset
177 for (i = 0; i < FF_ARRAY_ELEMS(ext); i++) {
4f60cd16ac04 Clean up and simplify fExist().
ib
parents: 33129
diff changeset
178 snprintf(buf, sizeof(buf), "%s.%s", fname, ext[i]);
33046
9684ad0e1291 Move files with auxiliary functions to own directory.
ib
parents:
diff changeset
179
33130
4f60cd16ac04 Clean up and simplify fExist().
ib
parents: 33129
diff changeset
180 if (access(buf, R_OK) == 0)
4f60cd16ac04 Clean up and simplify fExist().
ib
parents: 33129
diff changeset
181 return buf;
33046
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 return NULL;
9684ad0e1291 Move files with auxiliary functions to own directory.
ib
parents:
diff changeset
185 }
9684ad0e1291 Move files with auxiliary functions to own directory.
ib
parents:
diff changeset
186
33983
2218c589f9ab Cosmetic: Rename parameters bf img in bitmap.c.
ib
parents: 33710
diff changeset
187 int bpRead(const char *fname, guiImage *img)
33046
9684ad0e1291 Move files with auxiliary functions to own directory.
ib
parents:
diff changeset
188 {
33137
f884fb919ac5 Remove various pngRead() debug messages.
ib
parents: 33136
diff changeset
189 int r;
f884fb919ac5 Remove various pngRead() debug messages.
ib
parents: 33136
diff changeset
190
33046
9684ad0e1291 Move files with auxiliary functions to own directory.
ib
parents:
diff changeset
191 fname = fExist(fname);
9684ad0e1291 Move files with auxiliary functions to own directory.
ib
parents:
diff changeset
192
33122
1d81476c0d1e Cosmetic: Rephrase some conditions and rename some variables.
ib
parents: 33121
diff changeset
193 if (!fname)
33046
9684ad0e1291 Move files with auxiliary functions to own directory.
ib
parents:
diff changeset
194 return -2;
9684ad0e1291 Move files with auxiliary functions to own directory.
ib
parents:
diff changeset
195
33983
2218c589f9ab Cosmetic: Rename parameters bf img in bitmap.c.
ib
parents: 33710
diff changeset
196 r = pngRead(fname, img);
33137
f884fb919ac5 Remove various pngRead() debug messages.
ib
parents: 33136
diff changeset
197
f884fb919ac5 Remove various pngRead() debug messages.
ib
parents: 33136
diff changeset
198 if (r != 0) {
f884fb919ac5 Remove various pngRead() debug messages.
ib
parents: 33136
diff changeset
199 mp_dbg(MSGT_GPLAYER, MSGL_DBG2, "[bitmap] read error #%d: %s\n", r, fname);
33046
9684ad0e1291 Move files with auxiliary functions to own directory.
ib
parents:
diff changeset
200 return -5;
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
33983
2218c589f9ab Cosmetic: Rename parameters bf img in bitmap.c.
ib
parents: 33710
diff changeset
203 if (img->Bpp < 24) {
2218c589f9ab Cosmetic: Rename parameters bf img in bitmap.c.
ib
parents: 33710
diff changeset
204 mp_dbg(MSGT_GPLAYER, MSGL_DBG2, "[bitmap] bpp too low: %u\n", img->Bpp);
33046
9684ad0e1291 Move files with auxiliary functions to own directory.
ib
parents:
diff changeset
205 return -1;
9684ad0e1291 Move files with auxiliary functions to own directory.
ib
parents:
diff changeset
206 }
9684ad0e1291 Move files with auxiliary functions to own directory.
ib
parents:
diff changeset
207
33983
2218c589f9ab Cosmetic: Rename parameters bf img in bitmap.c.
ib
parents: 33710
diff changeset
208 if (!Convert24to32(img))
33046
9684ad0e1291 Move files with auxiliary functions to own directory.
ib
parents:
diff changeset
209 return -8;
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 return 0;
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
33983
2218c589f9ab Cosmetic: Rename parameters bf img in bitmap.c.
ib
parents: 33710
diff changeset
214 void bpFree(guiImage *img)
33046
9684ad0e1291 Move files with auxiliary functions to own directory.
ib
parents:
diff changeset
215 {
33983
2218c589f9ab Cosmetic: Rename parameters bf img in bitmap.c.
ib
parents: 33710
diff changeset
216 free(img->Image);
2218c589f9ab Cosmetic: Rename parameters bf img in bitmap.c.
ib
parents: 33710
diff changeset
217 memset(img, 0, sizeof(*img));
33046
9684ad0e1291 Move files with auxiliary functions to own directory.
ib
parents:
diff changeset
218 }
9684ad0e1291 Move files with auxiliary functions to own directory.
ib
parents:
diff changeset
219
33710
fd498969e72d Clean up some function prototypes.
reimar
parents: 33690
diff changeset
220 int bpRenderMask(const guiImage *in, guiImage *out)
33046
9684ad0e1291 Move files with auxiliary functions to own directory.
ib
parents:
diff changeset
221 {
33118
ae464a957cd0 Move variable definitions at top of function.
ib
parents: 33117
diff changeset
222 uint32_t *buf;
ae464a957cd0 Move variable definitions at top of function.
ib
parents: 33117
diff changeset
223 unsigned long i;
ae464a957cd0 Move variable definitions at top of function.
ib
parents: 33117
diff changeset
224 int b = 0, c = 0;
ae464a957cd0 Move variable definitions at top of function.
ib
parents: 33117
diff changeset
225 unsigned char tmp = 0;
ae464a957cd0 Move variable definitions at top of function.
ib
parents: 33117
diff changeset
226 int shaped = 0;
ae464a957cd0 Move variable definitions at top of function.
ib
parents: 33117
diff changeset
227
33046
9684ad0e1291 Move files with auxiliary functions to own directory.
ib
parents:
diff changeset
228 out->Width = in->Width;
9684ad0e1291 Move files with auxiliary functions to own directory.
ib
parents:
diff changeset
229 out->Height = in->Height;
33555
c5a19bbeac2b Cosmetic: Rename some GUI variables and functions.
ib
parents: 33534
diff changeset
230 out->Bpp = 1;
33046
9684ad0e1291 Move files with auxiliary functions to own directory.
ib
parents:
diff changeset
231 out->ImageSize = (out->Width * out->Height + 7) / 8;
33118
ae464a957cd0 Move variable definitions at top of function.
ib
parents: 33117
diff changeset
232 out->Image = calloc(1, out->ImageSize);
33046
9684ad0e1291 Move files with auxiliary functions to own directory.
ib
parents:
diff changeset
233
33122
1d81476c0d1e Cosmetic: Rephrase some conditions and rename some variables.
ib
parents: 33121
diff changeset
234 if (!out->Image) {
33114
5ad451a5ebec Remove useless warning message.
ib
parents: 33113
diff changeset
235 mp_dbg(MSGT_GPLAYER, MSGL_DBG2, "[bitmap] not enough memory: %lu\n", out->ImageSize);
5ad451a5ebec Remove useless warning message.
ib
parents: 33113
diff changeset
236 return 0;
33125
9c178cf14a61 Get rid of else-block to improve readability.
ib
parents: 33122
diff changeset
237 }
9c178cf14a61 Get rid of else-block to improve readability.
ib
parents: 33122
diff changeset
238
33126
a5dc70e2cda3 Cosmetic: Adjust indent.
ib
parents: 33125
diff changeset
239 buf = (uint32_t *)in->Image;
33046
9684ad0e1291 Move files with auxiliary functions to own directory.
ib
parents:
diff changeset
240
33126
a5dc70e2cda3 Cosmetic: Adjust indent.
ib
parents: 33125
diff changeset
241 for (i = 0; i < out->Width * out->Height; i++) {
a5dc70e2cda3 Cosmetic: Adjust indent.
ib
parents: 33125
diff changeset
242 tmp >>= 1;
33119
8835e684a41d Move common pixel shifting statement
ib
parents: 33118
diff changeset
243
33534
22c3241467b3 Remove function Normalize().
ib
parents: 33141
diff changeset
244 if (!IS_TRANSPARENT(buf[i]))
33126
a5dc70e2cda3 Cosmetic: Adjust indent.
ib
parents: 33125
diff changeset
245 tmp |= 0x80;
33128
64d19aaf624a Revert r33214.
ib
parents: 33127
diff changeset
246 else {
64d19aaf624a Revert r33214.
ib
parents: 33127
diff changeset
247 buf[i] = 0;
33126
a5dc70e2cda3 Cosmetic: Adjust indent.
ib
parents: 33125
diff changeset
248 shaped = 1;
33128
64d19aaf624a Revert r33214.
ib
parents: 33127
diff changeset
249 }
33046
9684ad0e1291 Move files with auxiliary functions to own directory.
ib
parents:
diff changeset
250
33126
a5dc70e2cda3 Cosmetic: Adjust indent.
ib
parents: 33125
diff changeset
251 if (++b == 8) {
a5dc70e2cda3 Cosmetic: Adjust indent.
ib
parents: 33125
diff changeset
252 out->Image[c++] = tmp;
a5dc70e2cda3 Cosmetic: Adjust indent.
ib
parents: 33125
diff changeset
253 tmp = b = 0;
a5dc70e2cda3 Cosmetic: Adjust indent.
ib
parents: 33125
diff changeset
254 }
a5dc70e2cda3 Cosmetic: Adjust indent.
ib
parents: 33125
diff changeset
255 }
33112
654dfdf176ac Revise debug messages.
ib
parents: 33053
diff changeset
256
33126
a5dc70e2cda3 Cosmetic: Adjust indent.
ib
parents: 33125
diff changeset
257 if (b)
a5dc70e2cda3 Cosmetic: Adjust indent.
ib
parents: 33125
diff changeset
258 out->Image[c] = tmp;
a5dc70e2cda3 Cosmetic: Adjust indent.
ib
parents: 33125
diff changeset
259
a5dc70e2cda3 Cosmetic: Adjust indent.
ib
parents: 33125
diff changeset
260 if (!shaped)
a5dc70e2cda3 Cosmetic: Adjust indent.
ib
parents: 33125
diff changeset
261 bpFree(out);
33114
5ad451a5ebec Remove useless warning message.
ib
parents: 33113
diff changeset
262
33133
41485430b18a Move debug message.
ib
parents: 33132
diff changeset
263 mp_dbg(MSGT_GPLAYER, MSGL_DBG2, "[bitmap] 1 bpp conversion size: %lu\n", out->ImageSize);
41485430b18a Move debug message.
ib
parents: 33132
diff changeset
264
33114
5ad451a5ebec Remove useless warning message.
ib
parents: 33113
diff changeset
265 return 1;
33046
9684ad0e1291 Move files with auxiliary functions to own directory.
ib
parents:
diff changeset
266 }