jpeg.c
上传用户:luping1608
上传日期:2007-01-06
资源大小:38k
文件大小:3k
源码类别:

多媒体

开发平台:

Unix_Linux

  1. #include "quicktime.h"
  2. #include "jpeglib.h"
  3. int quicktime_init_codec_jpeg(quicktime_video_map_t *vtrack)
  4. {
  5. vtrack->codecs.jpeg_codec.quality = 100;
  6. vtrack->codecs.jpeg_codec.use_float = 0;
  7. }
  8. int quicktime_delete_codec_jpeg(quicktime_video_map_t *vtrack)
  9. {
  10. }
  11. int quicktime_set_jpeg(quicktime_t *file, int quality, int use_float)
  12. {
  13. int i;
  14. char *compressor;
  15. for(i = 0; i < file->total_vtracks; i++)
  16. {
  17. if(quicktime_match_32(quicktime_video_compressor(file, i), QUICKTIME_JPEG))
  18. {
  19. quicktime_jpeg_codec_t *codec = &(file->vtracks[i].codecs.jpeg_codec);
  20. codec->quality = quality;
  21. codec->use_float = use_float;
  22. }
  23. }
  24. }
  25. int quicktime_decode_jpeg(quicktime_t *file, unsigned char **row_pointers, int track)
  26. {
  27. int result = 0;
  28. struct jpeg_decompress_struct jpeg_decompress;
  29. struct jpeg_error_mgr jpeg_error;
  30. long i, color_channels, bytes;
  31. quicktime_trak_t *trak = file->vtracks[track].track;
  32. jpeg_decompress.err = jpeg_std_error(&jpeg_error);
  33. jpeg_create_decompress(&jpeg_decompress);
  34. if(!file->vtracks[track].frames_cached)
  35. {
  36. quicktime_set_video_position(file, file->vtracks[track].current_position, track);
  37. jpeg_stdio_src(&jpeg_decompress, quicktime_get_fd(file));
  38. }
  39. else
  40. {
  41. jpeg_buffer_src(&jpeg_decompress, 
  42. file->vtracks[track].frame_cache[file->vtracks[track].current_position],
  43. quicktime_frame_size(file, file->vtracks[track].current_position, track));
  44. }
  45. jpeg_read_header(&jpeg_decompress, TRUE);
  46. jpeg_start_decompress(&jpeg_decompress);
  47. color_channels = jpeg_decompress.jpeg_color_space;
  48. row_pointers = (JSAMPROW*)row_pointers;
  49. // read the image
  50. while(jpeg_decompress.output_scanline < jpeg_decompress.output_height)
  51. {
  52. jpeg_read_scanlines(&jpeg_decompress, 
  53. (JSAMPROW*)&row_pointers[jpeg_decompress.output_scanline], 
  54. jpeg_decompress.output_height - jpeg_decompress.output_scanline);
  55. }
  56. jpeg_finish_decompress(&jpeg_decompress);
  57. jpeg_destroy((j_common_ptr)&jpeg_decompress);
  58. return result;
  59. }
  60. int quicktime_encode_jpeg(quicktime_t *file, unsigned char **row_pointers, int track)
  61. {
  62. long offset = quicktime_position(file);
  63. int result = 0;
  64. int i;
  65. quicktime_trak_t *trak = file->vtracks[track].track;
  66. int height = trak->tkhd.track_height;
  67. int width = trak->tkhd.track_width;
  68. struct jpeg_compress_struct jpeg_compress;
  69. struct jpeg_error_mgr jpeg_error;
  70. JSAMPROW row_pointer[1];
  71. long bytes;
  72. jpeg_compress.err = jpeg_std_error(&jpeg_error);
  73. jpeg_create_compress(&jpeg_compress);
  74. jpeg_stdio_dest(&jpeg_compress, quicktime_get_fd(file));
  75. jpeg_compress.image_width = width;
  76. jpeg_compress.image_height = height;
  77. jpeg_compress.input_components = 3;
  78. jpeg_compress.in_color_space = JCS_RGB;
  79. jpeg_set_defaults(&jpeg_compress);
  80. jpeg_set_quality(&jpeg_compress, file->vtracks[track].codecs.jpeg_codec.quality, 0);
  81. if(file->vtracks[track].codecs.jpeg_codec.use_float)
  82. jpeg_compress.dct_method = JDCT_FLOAT;
  83. jpeg_start_compress(&jpeg_compress, TRUE);
  84. while(jpeg_compress.next_scanline < jpeg_compress.image_height)
  85. {
  86. row_pointer[0] = row_pointers[jpeg_compress.next_scanline];
  87. jpeg_write_scanlines(&jpeg_compress, row_pointer, 1);
  88. }
  89. jpeg_finish_compress(&jpeg_compress);
  90. jpeg_destroy((j_common_ptr)&jpeg_compress);
  91. bytes = quicktime_position(file) - offset;
  92. quicktime_update_tables(file->vtracks[track].track,
  93. offset,
  94. file->vtracks[track].current_chunk,
  95. file->vtracks[track].current_position,
  96. 1,
  97. bytes);
  98. file->vtracks[track].current_chunk++;
  99. return result;
  100. }