comparison dvbsub.c @ 5067:6166fbf375cc libavcodec

Remove duplicate bytestream functions
author ramiro
date Wed, 23 May 2007 14:55:13 +0000
parents c8c591fe26f8
children dfa6e7fa2bac
comparison
equal deleted inserted replaced
5066:27afc3835257 5067:6166fbf375cc
17 * You should have received a copy of the GNU Lesser General Public 17 * You should have received a copy of the GNU Lesser General Public
18 * License along with FFmpeg; if not, write to the Free Software 18 * License along with FFmpeg; if not, write to the Free Software
19 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA 19 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
20 */ 20 */
21 #include "avcodec.h" 21 #include "avcodec.h"
22 #include "bytestream.h"
22 23
23 typedef struct DVBSubtitleContext { 24 typedef struct DVBSubtitleContext {
24 int hide_state; 25 int hide_state;
25 int object_version; 26 int object_version;
26 } DVBSubtitleContext; 27 } DVBSubtitleContext;
206 207
207 #define RGB_TO_V_CCIR(r1, g1, b1, shift)\ 208 #define RGB_TO_V_CCIR(r1, g1, b1, shift)\
208 (((FIX(0.50000*224.0/255.0) * r1 - FIX(0.41869*224.0/255.0) * g1 - \ 209 (((FIX(0.50000*224.0/255.0) * r1 - FIX(0.41869*224.0/255.0) * g1 - \
209 FIX(0.08131*224.0/255.0) * b1 + (ONE_HALF << shift) - 1) >> (SCALEBITS + shift)) + 128) 210 FIX(0.08131*224.0/255.0) * b1 + (ONE_HALF << shift) - 1) >> (SCALEBITS + shift)) + 128)
210 211
211 static inline void putbe16(uint8_t **pq, uint16_t v)
212 {
213 uint8_t *q;
214 q = *pq;
215 *q++ = v >> 8;
216 *q++ = v;
217 *pq = q;
218 }
219
220 static int encode_dvb_subtitles(DVBSubtitleContext *s, 212 static int encode_dvb_subtitles(DVBSubtitleContext *s,
221 uint8_t *outbuf, AVSubtitle *h) 213 uint8_t *outbuf, AVSubtitle *h)
222 { 214 {
223 uint8_t *q, *pseg_len; 215 uint8_t *q, *pseg_len;
224 int page_id, region_id, clut_id, object_id, i, bpp_index, page_state; 216 int page_id, region_id, clut_id, object_id, i, bpp_index, page_state;
235 227
236 /* page composition segment */ 228 /* page composition segment */
237 229
238 *q++ = 0x0f; /* sync_byte */ 230 *q++ = 0x0f; /* sync_byte */
239 *q++ = 0x10; /* segment_type */ 231 *q++ = 0x10; /* segment_type */
240 putbe16(&q, page_id); 232 bytestream_put_be16(&q, page_id);
241 pseg_len = q; 233 pseg_len = q;
242 q += 2; /* segment length */ 234 q += 2; /* segment length */
243 *q++ = 30; /* page_timeout (seconds) */ 235 *q++ = 30; /* page_timeout (seconds) */
244 if (s->hide_state) 236 if (s->hide_state)
245 page_state = 0; /* normal case */ 237 page_state = 0; /* normal case */
249 *q++ = s->object_version | (page_state << 2) | 3; 241 *q++ = s->object_version | (page_state << 2) | 3;
250 242
251 for (region_id = 0; region_id < h->num_rects; region_id++) { 243 for (region_id = 0; region_id < h->num_rects; region_id++) {
252 *q++ = region_id; 244 *q++ = region_id;
253 *q++ = 0xff; /* reserved */ 245 *q++ = 0xff; /* reserved */
254 putbe16(&q, h->rects[region_id].x); /* left pos */ 246 bytestream_put_be16(&q, h->rects[region_id].x); /* left pos */
255 putbe16(&q, h->rects[region_id].y); /* top pos */ 247 bytestream_put_be16(&q, h->rects[region_id].y); /* top pos */
256 } 248 }
257 249
258 putbe16(&pseg_len, q - pseg_len - 2); 250 bytestream_put_be16(&pseg_len, q - pseg_len - 2);
259 251
260 if (!s->hide_state) { 252 if (!s->hide_state) {
261 for (clut_id = 0; clut_id < h->num_rects; clut_id++) { 253 for (clut_id = 0; clut_id < h->num_rects; clut_id++) {
262 254
263 /* CLUT segment */ 255 /* CLUT segment */
272 return -1; 264 return -1;
273 } 265 }
274 266
275 *q++ = 0x0f; /* sync byte */ 267 *q++ = 0x0f; /* sync byte */
276 *q++ = 0x12; /* CLUT definition segment */ 268 *q++ = 0x12; /* CLUT definition segment */
277 putbe16(&q, page_id); 269 bytestream_put_be16(&q, page_id);
278 pseg_len = q; 270 pseg_len = q;
279 q += 2; /* segment length */ 271 q += 2; /* segment length */
280 *q++ = clut_id; 272 *q++ = clut_id;
281 *q++ = (0 << 4) | 0xf; /* version = 0 */ 273 *q++ = (0 << 4) | 0xf; /* version = 0 */
282 274
295 *q++ = RGB_TO_U_CCIR(r, g, b, 0); 287 *q++ = RGB_TO_U_CCIR(r, g, b, 0);
296 *q++ = 255 - a; 288 *q++ = 255 - a;
297 } 289 }
298 } 290 }
299 291
300 putbe16(&pseg_len, q - pseg_len - 2); 292 bytestream_put_be16(&pseg_len, q - pseg_len - 2);
301 } 293 }
302 } 294 }
303 295
304 for (region_id = 0; region_id < h->num_rects; region_id++) { 296 for (region_id = 0; region_id < h->num_rects; region_id++) {
305 297
315 return -1; 307 return -1;
316 } 308 }
317 309
318 *q++ = 0x0f; /* sync_byte */ 310 *q++ = 0x0f; /* sync_byte */
319 *q++ = 0x11; /* segment_type */ 311 *q++ = 0x11; /* segment_type */
320 putbe16(&q, page_id); 312 bytestream_put_be16(&q, page_id);
321 pseg_len = q; 313 pseg_len = q;
322 q += 2; /* segment length */ 314 q += 2; /* segment length */
323 *q++ = region_id; 315 *q++ = region_id;
324 *q++ = (s->object_version << 4) | (0 << 3) | 0x07; /* version , no fill */ 316 *q++ = (s->object_version << 4) | (0 << 3) | 0x07; /* version , no fill */
325 putbe16(&q, h->rects[region_id].w); /* region width */ 317 bytestream_put_be16(&q, h->rects[region_id].w); /* region width */
326 putbe16(&q, h->rects[region_id].h); /* region height */ 318 bytestream_put_be16(&q, h->rects[region_id].h); /* region height */
327 *q++ = ((1 + bpp_index) << 5) | ((1 + bpp_index) << 2) | 0x03; 319 *q++ = ((1 + bpp_index) << 5) | ((1 + bpp_index) << 2) | 0x03;
328 *q++ = region_id; /* clut_id == region_id */ 320 *q++ = region_id; /* clut_id == region_id */
329 *q++ = 0; /* 8 bit fill colors */ 321 *q++ = 0; /* 8 bit fill colors */
330 *q++ = 0x03; /* 4 bit and 2 bit fill colors */ 322 *q++ = 0x03; /* 4 bit and 2 bit fill colors */
331 323
332 if (!s->hide_state) { 324 if (!s->hide_state) {
333 putbe16(&q, region_id); /* object_id == region_id */ 325 bytestream_put_be16(&q, region_id); /* object_id == region_id */
334 *q++ = (0 << 6) | (0 << 4); 326 *q++ = (0 << 6) | (0 << 4);
335 *q++ = 0; 327 *q++ = 0;
336 *q++ = 0xf0; 328 *q++ = 0xf0;
337 *q++ = 0; 329 *q++ = 0;
338 } 330 }
339 331
340 putbe16(&pseg_len, q - pseg_len - 2); 332 bytestream_put_be16(&pseg_len, q - pseg_len - 2);
341 } 333 }
342 334
343 if (!s->hide_state) { 335 if (!s->hide_state) {
344 336
345 for (object_id = 0; object_id < h->num_rects; object_id++) { 337 for (object_id = 0; object_id < h->num_rects; object_id++) {
355 return -1; 347 return -1;
356 } 348 }
357 349
358 *q++ = 0x0f; /* sync byte */ 350 *q++ = 0x0f; /* sync byte */
359 *q++ = 0x13; 351 *q++ = 0x13;
360 putbe16(&q, page_id); 352 bytestream_put_be16(&q, page_id);
361 pseg_len = q; 353 pseg_len = q;
362 q += 2; /* segment length */ 354 q += 2; /* segment length */
363 355
364 putbe16(&q, object_id); 356 bytestream_put_be16(&q, object_id);
365 *q++ = (s->object_version << 4) | (0 << 2) | (0 << 1) | 1; /* version = 0, 357 *q++ = (s->object_version << 4) | (0 << 2) | (0 << 1) | 1; /* version = 0,
366 onject_coding_method, 358 onject_coding_method,
367 non_modifying_color_flag */ 359 non_modifying_color_flag */
368 { 360 {
369 uint8_t *ptop_field_len, *pbottom_field_len, *top_ptr, *bottom_ptr; 361 uint8_t *ptop_field_len, *pbottom_field_len, *top_ptr, *bottom_ptr;
386 bottom_ptr = q; 378 bottom_ptr = q;
387 dvb_encode_rle(&q, h->rects[object_id].bitmap + h->rects[object_id].w, 379 dvb_encode_rle(&q, h->rects[object_id].bitmap + h->rects[object_id].w,
388 h->rects[object_id].w * 2, h->rects[object_id].w, 380 h->rects[object_id].w * 2, h->rects[object_id].w,
389 h->rects[object_id].h >> 1); 381 h->rects[object_id].h >> 1);
390 382
391 putbe16(&ptop_field_len, bottom_ptr - top_ptr); 383 bytestream_put_be16(&ptop_field_len, bottom_ptr - top_ptr);
392 putbe16(&pbottom_field_len, q - bottom_ptr); 384 bytestream_put_be16(&pbottom_field_len, q - bottom_ptr);
393 } 385 }
394 386
395 putbe16(&pseg_len, q - pseg_len - 2); 387 bytestream_put_be16(&pseg_len, q - pseg_len - 2);
396 } 388 }
397 } 389 }
398 390
399 /* end of display set segment */ 391 /* end of display set segment */
400 392
401 *q++ = 0x0f; /* sync_byte */ 393 *q++ = 0x0f; /* sync_byte */
402 *q++ = 0x80; /* segment_type */ 394 *q++ = 0x80; /* segment_type */
403 putbe16(&q, page_id); 395 bytestream_put_be16(&q, page_id);
404 pseg_len = q; 396 pseg_len = q;
405 q += 2; /* segment length */ 397 q += 2; /* segment length */
406 398
407 putbe16(&pseg_len, q - pseg_len - 2); 399 bytestream_put_be16(&pseg_len, q - pseg_len - 2);
408 400
409 *q++ = 0xff; /* end of PES data */ 401 *q++ = 0xff; /* end of PES data */
410 402
411 s->object_version = (s->object_version + 1) & 0xf; 403 s->object_version = (s->object_version + 1) & 0xf;
412 s->hide_state = !s->hide_state; 404 s->hide_state = !s->hide_state;