Changeset 289aade717ba57b0a47ea0aab00b3f5ca98a826b
- Timestamp:
- 03/01/04 13:54:56 (5 years ago)
- git-parent:
- Files:
-
- modules/codec/ogt/common.c (modified) (5 diffs)
- modules/codec/ogt/common.h (modified) (3 diffs)
- modules/codec/ogt/cvd.c (modified) (6 diffs)
- modules/codec/ogt/cvd_parse.c (modified) (4 diffs)
- modules/codec/ogt/ogt.c (modified) (2 diffs)
- modules/codec/ogt/ogt_parse.c (modified) (6 diffs)
- modules/codec/ogt/subtitle.h (modified) (3 diffs)
Legend:
- Unmodified
- Added
- Removed
- Modified
- Copied
- Moved
modules/codec/ogt/common.c
rc17dee7 r289aade 2 2 * Common SVCD and VCD subtitle routines. 3 3 ***************************************************************************** 4 * Copyright (C) 2003 VideoLAN5 * $Id: common.c,v 1. 2 2003/12/30 04:43:52rocky Exp $4 * Copyright (C) 2003, 2004 VideoLAN 5 * $Id: common.c,v 1.3 2004/01/03 12:54:56 rocky Exp $ 6 6 * 7 7 * Author: Rocky Bernstein … … 35 35 #include "subtitle.h" 36 36 #include "common.h" 37 #ifdef HAVE_LIBPNG 38 #include "write_png.h" 39 #endif 37 40 38 41 /***************************************************************************** … … 124 127 125 128 if ( chunk_length > 0 ) { 129 #if 0 130 int i; 131 int8_t *b=buffer; 132 for (i=0; i<chunk_length; i++) 133 printf ("%02x", b[i]); 134 printf("\n"); 135 #endif 136 126 137 memcpy(p_sys->subtitle_data + p_sys->subtitle_data_pos, 127 138 buffer, chunk_length); … … 176 187 177 188 for ( ; n >= 0 ; n-- ) { 178 p_to[n] = p_sys->p i_palette[p_from[n]];189 p_to[n] = p_sys->p_palette[p_from[n]]; 179 190 } 180 191 } … … 303 314 } 304 315 316 /* 317 Dump an a subtitle image to standard output - for debugging. 318 */ 319 void VCDSubDumpImage( uint8_t *p_image, uint32_t i_height, uint32_t i_width ) 320 { 321 uint8_t *p = p_image; 322 unsigned int i_row; /* scanline row number */ 323 unsigned int i_column; /* scanline column number */ 324 325 printf("-------------------------------------\n++"); 326 for ( i_row=0; i_row < i_height; i_row ++ ) { 327 for ( i_column=0; i_column<i_width; i_column++ ) { 328 printf("%1d", *p++ & 0x03); 329 } 330 printf("\n++"); 331 } 332 printf("\n-------------------------------------\n"); 333 } 334 335 /* 336 FIXME: 337 MOVE clip_8_bit and uuv2rgb TO A MORE GENERIC PLACE. 338 */ 339 340 /* Force v in the range 0.255 */ 341 static inline uint8_t 342 clip_8_bit(int v) 343 { 344 if (v<0) return 0; 345 if (v>255) return 255; 346 return (uint8_t) v; 347 } 348 349 /*************************************************** 350 Color conversion from 351 http://www.inforamp.net/~poynton/notes/colour_and_gamma/ColorFAQ.html#RTFToC30 352 http://people.ee.ethz.ch/~buc/brechbuehler/mirror/color/ColorFAQ.html 353 354 Thanks to Billy Biggs <vektor@dumbterm.net> for the pointer and 355 the following conversion. 356 357 R' = [ 1.1644 0 1.5960 ] ([ Y' ] [ 16 ]) 358 G' = [ 1.1644 -0.3918 -0.8130 ] * ([ Cb ] - [ 128 ]) 359 B' = [ 1.1644 2.0172 0 ] ([ Cr ] [ 128 ]) 360 361 See also vlc/modules/video_chroma/i420_rgb.h and 362 vlc/modules/video_chroma/i420_rgb_c.h for a way to do this in a way 363 more optimized for integer arithmetic. Would be nice to merge the 364 two routines. 365 366 ***************************************************/ 367 368 static inline void 369 yuv2rgb(ogt_yuvt_t *p_yuv, uint8_t *p_rgb_out ) 370 { 371 372 int i_Y = p_yuv->s.y - 16; 373 int i_Cb = p_yuv->s.v - 128; 374 int i_Cr = p_yuv->s.u - 128; 375 376 int i_red = (1.1644 * i_Y) + (1.5960 * i_Cr); 377 int i_green = (1.1644 * i_Y) - (0.3918 * i_Cb) - (0.8130 * i_Cr); 378 int i_blue = (1.1644 * i_Y) + (2.0172 * i_Cb); 379 380 i_red = clip_8_bit( i_red ); 381 i_green = clip_8_bit( i_green ); 382 i_blue = clip_8_bit( i_blue ); 383 384 *p_rgb_out++ = i_red; 385 *p_rgb_out++ = i_green; 386 *p_rgb_out++ = i_blue; 387 388 } 389 390 #ifdef HAVE_LIBPNG 391 392 #define BYTES_PER_RGB 3 393 #define PALETTE_SIZE 4 394 /* Note the below assumes the above is a power of 2 */ 395 #define PALETTE_SIZE_MASK (PALETTE_SIZE-1) 396 397 /* 398 Dump an a subtitle image to a Portable Network Graphics (PNG) file. 399 All we do here is convert YUV palette entries to RGB, expand 400 the image into a linear RGB pixel array, and call the routine 401 that does the PNG writing. 402 */ 403 404 void 405 VCDSubDumpPNG( uint8_t *p_image, decoder_t *p_dec, 406 uint32_t i_height, uint32_t i_width, const char *filename, 407 png_text *text_ptr, int i_text_count ) 408 { 409 decoder_sys_t *p_sys = p_dec->p_sys; 410 uint8_t *p = p_image; 411 uint8_t *image_data = malloc(BYTES_PER_RGB * i_height * i_width ); 412 uint8_t *q = image_data; 413 unsigned int i_row; /* scanline row number */ 414 unsigned int i_column; /* scanline column number */ 415 uint8_t rgb_palette[PALETTE_SIZE * BYTES_PER_RGB]; 416 int i; 417 418 dbg_print( (DECODE_DBG_CALL), "%s", filename); 419 420 if (NULL == image_data) return; 421 422 /* Convert palette YUV into RGB. */ 423 for (i=0; i<PALETTE_SIZE; i++) { 424 ogt_yuvt_t *p_yuv = &(p_sys->p_palette[i]); 425 uint8_t *p_rgb_out = &(rgb_palette[i*BYTES_PER_RGB]); 426 yuv2rgb( p_yuv, p_rgb_out ); 427 } 428 429 /* Convert palette entries into linear RGB array. */ 430 for ( i_row=0; i_row < i_height; i_row ++ ) { 431 for ( i_column=0; i_column<i_width; i_column++ ) { 432 uint8_t *p_rgb = &rgb_palette[ ((*p)&PALETTE_SIZE_MASK)*BYTES_PER_RGB ]; 433 *q++ = p_rgb[0]; 434 *q++ = p_rgb[1]; 435 *q++ = p_rgb[2]; 436 p++; 437 } 438 } 439 440 write_png( filename, i_height, i_width, image_data, text_ptr, i_text_count ); 441 free(image_data); 442 } 443 #endif /*HAVE_LIBPNG*/ modules/codec/ogt/common.h
rc17dee7 r289aade 2 2 * Header for Common SVCD and VCD subtitle routines. 3 3 ***************************************************************************** 4 * Copyright (C) 2003 VideoLAN5 * $Id: common.h,v 1. 2 2003/12/30 04:43:52rocky Exp $4 * Copyright (C) 2003, 2004 VideoLAN 5 * $Id: common.h,v 1.3 2004/01/03 12:54:56 rocky Exp $ 6 6 * 7 7 * Author: Rocky Bernstein … … 23 23 24 24 void VCDSubClose ( vlc_object_t * ); 25 25 26 void VCDSubInitSubtitleBlock( decoder_sys_t * p_sys ); 27 26 28 void VCDSubInitSubtitleData(decoder_sys_t *p_sys); 29 27 30 void VCDSubAppendData( decoder_t *p_dec, uint8_t *buffer, 28 31 uint32_t buf_len ); … … 31 34 void VCDSubScaleX( decoder_t *p_dec, subpicture_t *p_spu, 32 35 unsigned int i_scale_x, unsigned int i_scale_y ); 36 33 37 void VCDSubDestroySPU( subpicture_t *p_spu ); 38 34 39 int VCDSubCropCallback( vlc_object_t *p_object, char const *psz_var, 35 40 vlc_value_t oldval, vlc_value_t newval, 36 41 void *p_data ); 42 37 43 void VCDSubUpdateSPU( subpicture_t *p_spu, vlc_object_t *p_object ); 44 38 45 void VCDInlinePalette ( /*inout*/ uint8_t *p_dest, 39 46 decoder_sys_t *p_sys, unsigned int i_height, 40 47 unsigned int i_width ); 41 48 49 void VCDSubDumpImage( uint8_t *p_image, uint32_t i_height, 50 uint32_t i_width ); 42 51 43 52 #ifdef HAVE_LIBPNG 53 #include <png.h> 54 void VCDSubDumpPNG( uint8_t *p_image, decoder_t *p_dec, 55 uint32_t i_height, uint32_t i_width, 56 const char *filename, /*in*/ png_text *text_ptr, 57 int i_text_count ); 58 #endif /*HAVE_LIBPNG*/ modules/codec/ogt/cvd.c
rb72e3b1 r289aade 3 3 ***************************************************************************** 4 4 * Copyright (C) 2003 VideoLAN 5 * $Id: cvd.c,v 1. 5 2004/01/01 13:54:24rocky Exp $5 * $Id: cvd.c,v 1.6 2004/01/03 12:54:56 rocky Exp $ 6 6 * 7 7 * Authors: Rocky Bernstein … … 37 37 #include "common.h" 38 38 39 #define DEBUG_LONGTEXT N_( \40 "This integer when viewed in binary is a debugging mask\n" \41 "external call 1\n" \42 "all calls 2\n" \43 "packet assembly info 4\n" \44 "image bitmaps 8\n" \45 "image transformations 16\n" \46 "misc info 32\n" )47 48 39 /***************************************************************************** 49 40 * Module descriptor. … … 325 316 v, p[1], p[2], p[3]); 326 317 327 p_sys->p i_palette[v].s.y = p[1];328 p_sys->p i_palette[v].s.u = p[2];329 p_sys->p i_palette[v].s.v = p[3];318 p_sys->p_palette[v].s.y = p[1]; 319 p_sys->p_palette[v].s.u = p[2]; 320 p_sys->p_palette[v].s.v = p[3]; 330 321 break; 331 322 } … … 344 335 345 336 /* Highlight Palette */ 346 p_sys->p i_palette_highlight[v].s.y = p[1];347 p_sys->p i_palette_highlight[v].s.u = p[2];348 p_sys->p i_palette_highlight[v].s.v = p[3];337 p_sys->p_palette_highlight[v].s.y = p[1]; 338 p_sys->p_palette_highlight[v].s.u = p[2]; 339 p_sys->p_palette_highlight[v].s.v = p[3]; 349 340 break; 350 341 } … … 352 343 case 0x37: 353 344 /* transparency for primary palette */ 354 p_sys->p i_palette[0].s.t = p[3] & 0x0f;355 p_sys->p i_palette[1].s.t = p[3] >> 4;356 p_sys->p i_palette[2].s.t = p[2] & 0x0f;357 p_sys->p i_palette[3].s.t = p[2] >> 4;345 p_sys->p_palette[0].s.t = p[3] & 0x0f; 346 p_sys->p_palette[1].s.t = p[3] >> 4; 347 p_sys->p_palette[2].s.t = p[2] & 0x0f; 348 p_sys->p_palette[3].s.t = p[2] >> 4; 358 349 359 350 dbg_print( DECODE_DBG_PACKET, 360 351 "transparancy for primary palette 0..3: " 361 352 "0x%0x 0x%0x 0x%0x 0x%0x", 362 p_sys->p i_palette[0].s.t,363 p_sys->p i_palette[1].s.t,364 p_sys->p i_palette[2].s.t,365 p_sys->p i_palette[3].s.t );353 p_sys->p_palette[0].s.t, 354 p_sys->p_palette[1].s.t, 355 p_sys->p_palette[2].s.t, 356 p_sys->p_palette[3].s.t ); 366 357 367 358 break; … … 369 360 case 0x3f: 370 361 /* transparency for highlight palette */ 371 p_sys->p i_palette_highlight[0].s.t = p[2] & 0x0f;372 p_sys->p i_palette_highlight[1].s.t = p[2] >> 4;373 p_sys->p i_palette_highlight[2].s.t = p[1] & 0x0f;374 p_sys->p i_palette_highlight[3].s.t = p[1] >> 4;362 p_sys->p_palette_highlight[0].s.t = p[2] & 0x0f; 363 p_sys->p_palette_highlight[1].s.t = p[2] >> 4; 364 p_sys->p_palette_highlight[2].s.t = p[1] & 0x0f; 365 p_sys->p_palette_highlight[3].s.t = p[1] >> 4; 375 366 376 367 dbg_print( DECODE_DBG_PACKET, 377 368 "transparancy for primary palette 0..3: " 378 369 "0x%0x 0x%0x 0x%0x 0x%0x", 379 p_sys->p i_palette_highlight[0].s.t,380 p_sys->p i_palette_highlight[1].s.t,381 p_sys->p i_palette_highlight[2].s.t,382 p_sys->p i_palette_highlight[3].s.t );370 p_sys->p_palette_highlight[0].s.t, 371 p_sys->p_palette_highlight[1].s.t, 372 p_sys->p_palette_highlight[2].s.t, 373 p_sys->p_palette_highlight[3].s.t ); 383 374 384 375 break; modules/codec/ogt/cvd_parse.c
rc17dee7 r289aade 2 2 * parse.c: Philips OGT (SVCD subtitle) packet parser 3 3 ***************************************************************************** 4 * Copyright (C) 2003 VideoLAN5 * $Id: cvd_parse.c,v 1. 4 2003/12/30 04:43:52rocky Exp $4 * Copyright (C) 2003, 2004 VideoLAN 5 * $Id: cvd_parse.c,v 1.5 2004/01/03 12:54:56 rocky Exp $ 6 6 * 7 7 * Authors: Rocky Bernstein … … 37 37 #include "cvd.h" 38 38 #include "common.h" 39 40 #ifdef HAVE_LIBPNG 41 #include <png.h> 42 #endif 39 43 40 44 /* An image color is a two-bit palette entry: 0..3 */ … … 265 269 i_nibble_field = 2; /* 4-bit pieces available in *p */ 266 270 271 #if 0 272 unsigned int i; 273 int8_t *b=p; 274 for (i=0; i< i_width * i_height; i++) 275 printf ("%02x", b[i]); 276 printf("\n"); 277 #endif 278 267 279 for ( i_row=i_field; i_row < i_height; i_row += 2 ) { 268 280 b_filling = VLC_FALSE; … … 327 339 } 328 340 329 /* Dump out image not interlaced... */ 330 if (p_sys && p_sys->i_debug & DECODE_DBG_IMAGE) { 331 uint8_t *p = p_dest; 332 printf("-------------------------------------\n++"); 333 for ( i_row=0; i_row < i_height; i_row ++ ) { 334 for ( i_column=0; i_column<i_width; i_column++ ) { 335 printf("%1d", *p++ & 0x03); 336 } 337 printf("\n++"); 338 } 339 printf("\n-------------------------------------\n"); 340 } 341 if (p_sys && (p_sys->i_debug & DECODE_DBG_IMAGE)) { 342 /* Dump out image not interlaced... */ 343 VCDSubDumpImage( p_dest, i_height, i_width ); 344 } 345 346 #ifdef HAVE_LIBPNG 347 if (p_sys && (p_sys->i_debug & DECODE_DBG_PNG)) { 348 #define TEXT_COUNT 2 349 /* Dump image to a file in PNG format. */ 350 char filename[300]; 351 png_text text_ptr[TEXT_COUNT]; 352 353 text_ptr[0].key = "Preparer"; 354 text_ptr[0].text = "VLC"; 355 text_ptr[0].compression = PNG_TEXT_COMPRESSION_NONE; 356 text_ptr[1].key = "Description"; 357 text_ptr[1].text = "CVD Subtitle"; 358 text_ptr[1].compression = PNG_TEXT_COMPRESSION_NONE; 359 360 snprintf(filename, 300, "%s%d.png", "/tmp/vlc-cvd-sub", p_sys->i_image); 361 VCDSubDumpPNG( p_dest, p_dec, i_height, i_width, filename, 362 text_ptr, TEXT_COUNT ); 363 } 364 #endif /*HAVE_LIBPNG*/ 365 341 366 342 367 VCDInlinePalette( p_dest, p_sys, i_height, i_width ); modules/codec/ogt/ogt.c
rb72e3b1 r289aade 2 2 * ogt.c : Overlay Graphics Text (SVCD subtitles) decoder thread 3 3 ***************************************************************************** 4 * Copyright (C) 2003 VideoLAN5 * $Id: ogt.c,v 1. 7 2004/01/01 13:55:17rocky Exp $6 * 7 * Author s: Rocky Bernstein4 * Copyright (C) 2003, 2004 VideoLAN 5 * $Id: ogt.c,v 1.8 2004/01/03 12:54:56 rocky Exp $ 6 * 7 * Author: Rocky Bernstein 8 8 * based on code from: 9 9 * Julio Sanchez Fernandez (http://subhandler.sourceforge.net) … … 36 36 #include "ogt.h" 37 37 #include "common.h" 38 39 #define DEBUG_LONGTEXT N_( \40 "This integer when viewed in binary is a debugging mask\n" \41 "external call 1\n" \42 "all calls 2\n" \43 "packet assembly info 4\n" \44 "image bitmaps 8\n" \45 "image transformations 16\n" \46 "rendering information 32\n" \47 "misc info 64\n" )48 49 38 50 39 /***************************************************************************** modules/codec/ogt/ogt_parse.c
rc17dee7 r289aade 2 2 * Philips OGT (SVCD subtitle) packet parser 3 3 ***************************************************************************** 4 * Copyright (C) 2003 VideoLAN5 * $Id: ogt_parse.c,v 1. 4 2003/12/30 04:43:52rocky Exp $4 * Copyright (C) 2003, 2004 VideoLAN 5 * $Id: ogt_parse.c,v 1.5 2004/01/03 12:54:56 rocky Exp $ 6 6 * 7 7 * Author: Rocky Bernstein … … 37 37 #include "render.h" 38 38 #include "ogt.h" 39 40 #ifdef HAVE_LIBPNG 41 #include <png.h> 42 #endif 39 43 40 44 /* An image color is a two-bit palette entry: 0..3 */ … … 105 109 106 110 for (i=0; i<4; i++) { 107 p_sys->p i_palette[i].s.y = *p++;108 p_sys->p i_palette[i].s.u = *p++;109 p_sys->p i_palette[i].s.v = *p++;111 p_sys->p_palette[i].s.y = *p++; 112 p_sys->p_palette[i].s.u = *p++; 113 p_sys->p_palette[i].s.v = *p++; 110 114 /* OGT has 8-bit resolution for alpha, but DVD's and CVDS use 4-bits. 111 115 Since we want to use the same render routine, rather than scale up 112 116 CVD (and DVD) subtitles, we'll scale down ours. 113 117 */ 114 p_sys->p i_palette[i].s.t = (*p++) >> 4;118 p_sys->p_palette[i].s.t = (*p++) >> 4; 115 119 } 116 120 p_sys->i_cmd = *p++; … … 137 141 for (i=0; i<4; i++) { 138 142 msg_Dbg( p_dec, "palette[%d]= T: %2x, Y: %2x, u: %2x, v: %2x", i, 139 p_sys->p i_palette[i].s.t, p_sys->pi_palette[i].s.y,140 p_sys->p i_palette[i].s.u, p_sys->pi_palette[i].s.v );143 p_sys->p_palette[i].s.t, p_sys->p_palette[i].s.y, 144 p_sys->p_palette[i].s.u, p_sys->p_palette[i].s.v ); 141 145 } 142 146 } … … 326 330 } 327 331 328 if (p_sys && p_sys->i_debug & DECODE_DBG_IMAGE)332 if (p_sys && (p_sys->i_debug & DECODE_DBG_IMAGE)) 329 333 printf("\n"); 330 334 … … 338 342 } 339 343 340 /* Dump out image not interlaced... */ 341 if (p_sys && p_sys->i_debug & DECODE_DBG_IMAGE) { 342 uint8_t *p = p_dest; 343 printf("-------------------------------------\n++"); 344 for ( i_row=0; i_row < i_height; i_row ++ ) { 345 for ( i_column=0; i_column<i_width; i_column++ ) { 346 printf("%1d", *p++ & 0x03); 347 } 348 printf("\n++"); 349 } 350 printf("\n-------------------------------------\n"); 351 } 352 344 if (p_sys && (p_sys->i_debug & DECODE_DBG_IMAGE)) { 345 /* Dump out image not interlaced... */ 346 VCDSubDumpImage( p_dest, i_height, i_width ); 347 } 348 349 #ifdef HAVE_LIBPNG 350 if (p_sys && (p_sys->i_debug & DECODE_DBG_PNG)) { 351 #define TEXT_COUNT 2 352 /* Dump image to a file in PNG format. */ 353 char filename[300]; 354 png_text text_ptr[TEXT_COUNT]; 355 356 text_ptr[0].key = "Preparer"; 357 text_ptr[0].text = "VLC"; 358 text_ptr[0].compression = PNG_TEXT_COMPRESSION_NONE; 359 text_ptr[1].key = "Description"; 360 text_ptr[1].text = "SVCD Subtitle"; 361 text_ptr[1].compression = PNG_TEXT_COMPRESSION_NONE; 362 363 snprintf(filename, 300, "%s%d.png", "/tmp/vlc-svcd-sub", p_sys->i_image); 364 VCDSubDumpPNG( p_dest, p_dec, i_height, i_width, filename, 365 text_ptr, TEXT_COUNT ); 366 } 367 #endif /*HAVE_LIBPNG*/ 368 353 369 VCDInlinePalette( p_dest, p_sys, i_height, i_width ); 370 354 371 355 372 /* The video is automatically scaled. However subtitle bitmaps modules/codec/ogt/subtitle.h
rbea939b r289aade 2 2 * subtitle.h : Common SVCD and CVD subtitles header 3 3 ***************************************************************************** 4 * Copyright (C) 2003 VideoLAN5 * $Id: subtitle.h,v 1. 2 2003/12/28 11:26:52rocky Exp $4 * Copyright (C) 2003,2004 VideoLAN 5 * $Id: subtitle.h,v 1.3 2004/01/03 12:54:56 rocky Exp $ 6 6 * 7 7 * Author: Rocky Bernstein … … 31 31 #define DECODE_DBG_TRANSFORM 16 /* bitmap transformations */ 32 32 #define DECODE_DBG_RENDER 32 /* rendering information */ 33 #define DECODE_DBG_INFO 64 33 #define DECODE_DBG_PNG 64 /* Extract subtitles to PNG files. */ 34 #define DECODE_DBG_INFO 128 35 36 #define DEBUG_LONGTEXT N_( \ 37 "This integer when viewed in binary is a debugging mask\n" \ 38 "external call 1\n" \ 39 "all calls 2\n" \ 40 "packet assembly info 4\n" \ 41 "image bitmaps 8\n" \ 42 "image transformations 16\n" \ 43 "rendering information 32\n" \ 44 "extract subtitles 64\n" \ 45 "misc info 128\n" ) 34 46 35 47 #define DECODE_DEBUG 1 … … 125 137 uint16_t i_width, i_height; /* dimensions in pixels of image */ 126 138 127 ogt_yuvt_t p i_palette[NUM_SUBTITLE_COLORS]; /* Palette of colors used139 ogt_yuvt_t p_palette[NUM_SUBTITLE_COLORS]; /* Palette of colors used 128 140 in subtitle */ 129 141 130 142 131 ogt_yuvt_t p i_palette_highlight[NUM_SUBTITLE_COLORS]; /* Only used143 ogt_yuvt_t p_palette_highlight[NUM_SUBTITLE_COLORS]; /* Only used 132 144 for CVD */ 133 145
