Mercurial > mplayer.hg
comparison 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 |
comparison
equal
deleted
inserted
replaced
33982:d7527ee45784 | 33983:2218c589f9ab |
---|---|
28 #include "libavutil/common.h" | 28 #include "libavutil/common.h" |
29 #include "libavutil/intreadwrite.h" | 29 #include "libavutil/intreadwrite.h" |
30 #include "libvo/fastmemcpy.h" | 30 #include "libvo/fastmemcpy.h" |
31 #include "mp_msg.h" | 31 #include "mp_msg.h" |
32 | 32 |
33 static int pngRead(const char *fname, guiImage *bf) | 33 static int pngRead(const char *fname, guiImage *img) |
34 { | 34 { |
35 FILE *file; | 35 FILE *file; |
36 long len; | 36 long len; |
37 void *data; | 37 void *data; |
38 int decode_ok, bpl; | 38 int decode_ok, bpl; |
83 // HACK: make PNGs decode normally instead of as CorePNG delta frames | 83 // HACK: make PNGs decode normally instead of as CorePNG delta frames |
84 pkt.flags = AV_PKT_FLAG_KEY; | 84 pkt.flags = AV_PKT_FLAG_KEY; |
85 | 85 |
86 avcodec_decode_video2(avctx, frame, &decode_ok, &pkt); | 86 avcodec_decode_video2(avctx, frame, &decode_ok, &pkt); |
87 | 87 |
88 memset(bf, 0, sizeof(*bf)); | 88 memset(img, 0, sizeof(*img)); |
89 | 89 |
90 switch (avctx->pix_fmt) { | 90 switch (avctx->pix_fmt) { |
91 case PIX_FMT_GRAY8: | 91 case PIX_FMT_GRAY8: |
92 bf->Bpp = 8; | 92 img->Bpp = 8; |
93 break; | 93 break; |
94 | 94 |
95 case PIX_FMT_GRAY16BE: | 95 case PIX_FMT_GRAY16BE: |
96 bf->Bpp = 16; | 96 img->Bpp = 16; |
97 break; | 97 break; |
98 | 98 |
99 case PIX_FMT_RGB24: | 99 case PIX_FMT_RGB24: |
100 bf->Bpp = 24; | 100 img->Bpp = 24; |
101 break; | 101 break; |
102 | 102 |
103 case PIX_FMT_BGRA: | 103 case PIX_FMT_BGRA: |
104 case PIX_FMT_ARGB: | 104 case PIX_FMT_ARGB: |
105 bf->Bpp = 32; | 105 img->Bpp = 32; |
106 break; | 106 break; |
107 | 107 |
108 default: | 108 default: |
109 bf->Bpp = 0; | 109 img->Bpp = 0; |
110 break; | 110 break; |
111 } | 111 } |
112 | 112 |
113 if (decode_ok && bf->Bpp) { | 113 if (decode_ok && img->Bpp) { |
114 bf->Width = avctx->width; | 114 img->Width = avctx->width; |
115 bf->Height = avctx->height; | 115 img->Height = avctx->height; |
116 bpl = bf->Width * (bf->Bpp / 8); | 116 bpl = img->Width * (img->Bpp / 8); |
117 bf->ImageSize = bpl * bf->Height; | 117 img->ImageSize = bpl * img->Height; |
118 | 118 |
119 mp_dbg(MSGT_GPLAYER, MSGL_DBG2, "[bitmap] file: %s\n", fname); | 119 mp_dbg(MSGT_GPLAYER, MSGL_DBG2, "[bitmap] file: %s\n", fname); |
120 mp_dbg(MSGT_GPLAYER, MSGL_DBG2, "[bitmap] size: %lux%lu, color depth: %u\n", bf->Width, bf->Height, bf->Bpp); | 120 mp_dbg(MSGT_GPLAYER, MSGL_DBG2, "[bitmap] size: %lux%lu, color depth: %u\n", img->Width, img->Height, img->Bpp); |
121 mp_dbg(MSGT_GPLAYER, MSGL_DBG2, "[bitmap] image size: %lu\n", bf->ImageSize); | 121 mp_dbg(MSGT_GPLAYER, MSGL_DBG2, "[bitmap] image size: %lu\n", img->ImageSize); |
122 | 122 |
123 bf->Image = malloc(bf->ImageSize); | 123 img->Image = malloc(img->ImageSize); |
124 | 124 |
125 if (bf->Image) | 125 if (img->Image) |
126 memcpy_pic(bf->Image, frame->data[0], bpl, bf->Height, bpl, frame->linesize[0]); | 126 memcpy_pic(img->Image, frame->data[0], bpl, img->Height, bpl, frame->linesize[0]); |
127 else | 127 else |
128 decode_ok = 0; | 128 decode_ok = 0; |
129 } | 129 } |
130 | 130 |
131 avcodec_close(avctx); | 131 avcodec_close(avctx); |
132 av_free(frame); | 132 av_free(frame); |
133 av_free(avctx); | 133 av_free(avctx); |
134 av_free(data); | 134 av_free(data); |
135 | 135 |
136 return !(decode_ok && bf->Bpp); | 136 return !(decode_ok && img->Bpp); |
137 } | 137 } |
138 | 138 |
139 static int Convert24to32(guiImage *bf) | 139 static int Convert24to32(guiImage *img) |
140 { | 140 { |
141 char *orgImage; | 141 char *orgImage; |
142 unsigned long i, c; | 142 unsigned long i, c; |
143 | 143 |
144 if (bf->Bpp == 24) { | 144 if (img->Bpp == 24) { |
145 orgImage = bf->Image; | 145 orgImage = img->Image; |
146 | 146 |
147 bf->Bpp = 32; | 147 img->Bpp = 32; |
148 bf->ImageSize = bf->Width * bf->Height * 4; | 148 img->ImageSize = img->Width * img->Height * 4; |
149 bf->Image = calloc(1, bf->ImageSize); | 149 img->Image = calloc(1, img->ImageSize); |
150 | 150 |
151 if (!bf->Image) { | 151 if (!img->Image) { |
152 free(orgImage); | 152 free(orgImage); |
153 mp_dbg(MSGT_GPLAYER, MSGL_DBG2, "[bitmap] not enough memory: %lu\n", bf->ImageSize); | 153 mp_dbg(MSGT_GPLAYER, MSGL_DBG2, "[bitmap] not enough memory: %lu\n", img->ImageSize); |
154 return 0; | 154 return 0; |
155 } | 155 } |
156 | 156 |
157 mp_dbg(MSGT_GPLAYER, MSGL_DBG2, "[bitmap] 32 bpp conversion size: %lu\n", bf->ImageSize); | 157 mp_dbg(MSGT_GPLAYER, MSGL_DBG2, "[bitmap] 32 bpp conversion size: %lu\n", img->ImageSize); |
158 | 158 |
159 for (c = 0, i = 0; c < bf->ImageSize; c += 4, i += 3) | 159 for (c = 0, i = 0; c < img->ImageSize; c += 4, i += 3) |
160 *(uint32_t *)&bf->Image[c] = ALPHA_OPAQUE | AV_RB24(&orgImage[i]); | 160 *(uint32_t *)&img->Image[c] = ALPHA_OPAQUE | AV_RB24(&orgImage[i]); |
161 | 161 |
162 free(orgImage); | 162 free(orgImage); |
163 } | 163 } |
164 | 164 |
165 return 1; | 165 return 1; |
182 } | 182 } |
183 | 183 |
184 return NULL; | 184 return NULL; |
185 } | 185 } |
186 | 186 |
187 int bpRead(const char *fname, guiImage *bf) | 187 int bpRead(const char *fname, guiImage *img) |
188 { | 188 { |
189 int r; | 189 int r; |
190 | 190 |
191 fname = fExist(fname); | 191 fname = fExist(fname); |
192 | 192 |
193 if (!fname) | 193 if (!fname) |
194 return -2; | 194 return -2; |
195 | 195 |
196 r = pngRead(fname, bf); | 196 r = pngRead(fname, img); |
197 | 197 |
198 if (r != 0) { | 198 if (r != 0) { |
199 mp_dbg(MSGT_GPLAYER, MSGL_DBG2, "[bitmap] read error #%d: %s\n", r, fname); | 199 mp_dbg(MSGT_GPLAYER, MSGL_DBG2, "[bitmap] read error #%d: %s\n", r, fname); |
200 return -5; | 200 return -5; |
201 } | 201 } |
202 | 202 |
203 if (bf->Bpp < 24) { | 203 if (img->Bpp < 24) { |
204 mp_dbg(MSGT_GPLAYER, MSGL_DBG2, "[bitmap] bpp too low: %u\n", bf->Bpp); | 204 mp_dbg(MSGT_GPLAYER, MSGL_DBG2, "[bitmap] bpp too low: %u\n", img->Bpp); |
205 return -1; | 205 return -1; |
206 } | 206 } |
207 | 207 |
208 if (!Convert24to32(bf)) | 208 if (!Convert24to32(img)) |
209 return -8; | 209 return -8; |
210 | 210 |
211 return 0; | 211 return 0; |
212 } | 212 } |
213 | 213 |
214 void bpFree(guiImage *bf) | 214 void bpFree(guiImage *img) |
215 { | 215 { |
216 free(bf->Image); | 216 free(img->Image); |
217 memset(bf, 0, sizeof(*bf)); | 217 memset(img, 0, sizeof(*img)); |
218 } | 218 } |
219 | 219 |
220 int bpRenderMask(const guiImage *in, guiImage *out) | 220 int bpRenderMask(const guiImage *in, guiImage *out) |
221 { | 221 { |
222 uint32_t *buf; | 222 uint32_t *buf; |