00001 #include "asset.h"
00002 #include "bcsignals.h"
00003 #include "edit.h"
00004 #include "file.h"
00005 #include "filejpeg.h"
00006 #include "interlacemodes.h"
00007 #include "jpegwrapper.h"
00008 #include "language.h"
00009 #include "libmjpeg.h"
00010 #include "mwindow.inc"
00011 #include "quicktime.h"
00012 #include "vframe.h"
00013 #include "videodevice.inc"
00014
00015
00016
00017 FileJPEG::FileJPEG(Asset *asset, File *file)
00018 : FileList(asset, file, "JPEGLIST", ".jpg", FILE_JPEG, FILE_JPEG_LIST)
00019 {
00020 decompressor = 0;
00021 }
00022
00023 FileJPEG::~FileJPEG()
00024 {
00025 if(decompressor) mjpeg_delete((mjpeg_t*)decompressor);
00026 }
00027
00028
00029 int FileJPEG::check_sig(Asset *asset)
00030 {
00031 FILE *stream = fopen(asset->path, "rb");
00032
00033 if(stream)
00034 {
00035 char test[10];
00036 fread(test, 10, 1, stream);
00037 fclose(stream);
00038
00039 if(test[6] == 'J' && test[7] == 'F' && test[8] == 'I' && test[9] == 'F')
00040 {
00041 return 1;
00042 }
00043 else
00044 if(test[0] == 'J' && test[1] == 'P' && test[2] == 'E' && test[3] == 'G' &&
00045 test[4] == 'L' && test[5] == 'I' && test[6] == 'S' && test[7] == 'T')
00046 {
00047 return 1;
00048 }
00049 }
00050
00051 if(strlen(asset->path) > 4)
00052 {
00053 int len = strlen(asset->path);
00054 if(!strncasecmp(asset->path + len - 4, ".jpg", 4)) return 1;
00055 }
00056 return 0;
00057 }
00058
00059
00060
00061 void FileJPEG::get_parameters(BC_WindowBase *parent_window,
00062 Asset *asset,
00063 BC_WindowBase* &format_window,
00064 int audio_options,
00065 int video_options)
00066 {
00067 if(video_options)
00068 {
00069 JPEGConfigVideo *window = new JPEGConfigVideo(parent_window, asset);
00070 format_window = window;
00071 window->create_objects();
00072 window->run_window();
00073 delete window;
00074 }
00075 }
00076
00077
00078 int FileJPEG::can_copy_from(Edit *edit, int64_t position)
00079 {
00080
00081 if(edit->asset->format == FILE_MOV)
00082 {
00083 if(match4(edit->asset->vcodec, QUICKTIME_JPEG)) return 1;
00084 }
00085 else
00086 if(edit->asset->format == FILE_JPEG ||
00087 edit->asset->format == FILE_JPEG_LIST)
00088 return 1;
00089
00090 return 0;
00091 }
00092
00093 int FileJPEG::colormodel_supported(int colormodel)
00094 {
00095 return colormodel;
00096 }
00097
00098
00099 int FileJPEG::get_best_colormodel(Asset *asset, int driver)
00100 {
00101 switch(driver)
00102 {
00103 case PLAYBACK_X11:
00104 return BC_RGB888;
00105 break;
00106 case PLAYBACK_X11_XV:
00107 case PLAYBACK_DV1394:
00108 case PLAYBACK_FIREWIRE:
00109 return BC_YUV420P;
00110 break;
00111 case PLAYBACK_LML:
00112 case PLAYBACK_BUZ:
00113 return BC_YUV422P;
00114 break;
00115 case VIDEO4LINUX:
00116 case VIDEO4LINUX2:
00117 return BC_YUV420P;
00118 break;
00119 case CAPTURE_BUZ:
00120 case CAPTURE_LML:
00121 case VIDEO4LINUX2JPEG:
00122 return BC_YUV422;
00123 break;
00124 case CAPTURE_FIREWIRE:
00125 case CAPTURE_IEC61883:
00126 return BC_YUV420P;
00127 break;
00128 }
00129 return BC_YUV420P;
00130 }
00131
00132
00133 int FileJPEG::write_frame(VFrame *frame, VFrame *data, FrameWriterUnit *unit)
00134 {
00135 int result = 0;
00136 JPEGUnit *jpeg_unit = (JPEGUnit*)unit;
00137
00138 if(!jpeg_unit->compressor)
00139 jpeg_unit->compressor = mjpeg_new(asset->width,
00140 asset->height,
00141 1);
00142 mjpeg_set_quality((mjpeg_t*)jpeg_unit->compressor, asset->jpeg_quality);
00143
00144
00145 mjpeg_compress((mjpeg_t*)jpeg_unit->compressor,
00146 frame->get_rows(),
00147 frame->get_y(),
00148 frame->get_u(),
00149 frame->get_v(),
00150 frame->get_color_model(),
00151 1);
00152
00153 data->allocate_compressed_data(mjpeg_output_size((mjpeg_t*)jpeg_unit->compressor));
00154 data->set_compressed_size(mjpeg_output_size((mjpeg_t*)jpeg_unit->compressor));
00155 memcpy(data->get_data(),
00156 mjpeg_output_buffer((mjpeg_t*)jpeg_unit->compressor),
00157 mjpeg_output_size((mjpeg_t*)jpeg_unit->compressor));
00158
00159 return result;
00160 }
00161
00162
00163
00164
00165
00166
00167
00168
00169
00170
00171 int FileJPEG::read_frame_header(char *path)
00172 {
00173 int result = 0;
00174
00175
00176 FILE *stream;
00177
00178 if(!(stream = fopen(path, "rb")))
00179 {
00180 perror("FileJPEG::read_frame_header");
00181 return 1;
00182 }
00183
00184
00185
00186 struct jpeg_decompress_struct jpeg_decompress;
00187 struct jpeg_error_mgr jpeg_error;
00188
00189 jpeg_decompress.err = jpeg_std_error(&jpeg_error);
00190 jpeg_create_decompress(&jpeg_decompress);
00191
00192 jpeg_stdio_src(&jpeg_decompress, stream);
00193 jpeg_read_header(&jpeg_decompress, TRUE);
00194
00195 asset->width = jpeg_decompress.image_width;
00196 asset->height = jpeg_decompress.image_height;
00197
00198 asset->interlace_mode = BC_ILACE_MODE_NOTINTERLACED;
00199
00200 jpeg_destroy((j_common_ptr)&jpeg_decompress);
00201 fclose(stream);
00202
00203
00204
00205 return result;
00206 }
00207
00208
00209
00210 int FileJPEG::read_frame(VFrame *output, VFrame *input)
00211 {
00212 SET_TRACE
00213 if(!decompressor) decompressor = mjpeg_new(asset->width,
00214 asset->height,
00215 1);
00216 SET_TRACE
00217 mjpeg_decompress((mjpeg_t*)decompressor,
00218 input->get_data(),
00219 input->get_compressed_size(),
00220 0,
00221 output->get_rows(),
00222 output->get_y(),
00223 output->get_u(),
00224 output->get_v(),
00225 output->get_color_model(),
00226 1);
00227 SET_TRACE
00228
00229
00230 return 0;
00231 }
00232
00233 FrameWriterUnit* FileJPEG::new_writer_unit(FrameWriter *writer)
00234 {
00235 return new JPEGUnit(this, writer);
00236 }
00237
00238
00239
00240
00241
00242
00243 JPEGUnit::JPEGUnit(FileJPEG *file, FrameWriter *writer)
00244 : FrameWriterUnit(writer)
00245 {
00246 this->file = file;
00247 compressor = 0;
00248 }
00249 JPEGUnit::~JPEGUnit()
00250 {
00251 if(compressor) mjpeg_delete((mjpeg_t*)compressor);
00252 }
00253
00254
00255
00256
00257
00258
00259
00260 JPEGConfigVideo::JPEGConfigVideo(BC_WindowBase *parent_window, Asset *asset)
00261 : BC_Window(PROGRAM_NAME ": Video Compression",
00262 parent_window->get_abs_cursor_x(1),
00263 parent_window->get_abs_cursor_y(1),
00264 400,
00265 100)
00266 {
00267 this->parent_window = parent_window;
00268 this->asset = asset;
00269 }
00270
00271 JPEGConfigVideo::~JPEGConfigVideo()
00272 {
00273 }
00274
00275 int JPEGConfigVideo::create_objects()
00276 {
00277 int x = 10, y = 10;
00278
00279 add_subwindow(new BC_Title(x, y, _("Quality:")));
00280 add_subwindow(new BC_ISlider(x + 80,
00281 y,
00282 0,
00283 200,
00284 200,
00285 0,
00286 100,
00287 asset->jpeg_quality,
00288 0,
00289 0,
00290 &asset->jpeg_quality));
00291
00292 add_subwindow(new BC_OKButton(this));
00293 return 0;
00294 }
00295
00296 int JPEGConfigVideo::close_event()
00297 {
00298 set_done(0);
00299 return 1;
00300 }
00301
00302
00303