6 #include "interlacemodes.h"
7 #include "jpegwrapper.h"
10 #include "mwindow.inc"
11 #include "quicktime.h"
13 #include "videodevice.inc"
14 #include "mainerror.h"
17 FileJPEG::FileJPEG(Asset *asset, File *file)
18 : FileList(asset, file, "JPEGLIST", ".jpg", FILE_JPEG, FILE_JPEG_LIST)
25 if(decompressor) mjpeg_delete((mjpeg_t*)decompressor);
29 int FileJPEG::check_sig(Asset *asset)
31 FILE *stream = fopen(asset->path, "rb");
36 fread(test, 10, 1, stream);
39 if(test[6] == 'J' && test[7] == 'F' && test[8] == 'I' && test[9] == 'F')
44 if(test[0] == 'J' && test[1] == 'P' && test[2] == 'E' && test[3] == 'G' &&
45 test[4] == 'L' && test[5] == 'I' && test[6] == 'S' && test[7] == 'T')
51 if(strlen(asset->path) > 4)
53 int len = strlen(asset->path);
54 if(!strncasecmp(asset->path + len - 4, ".jpg", 4)) return 1;
61 void FileJPEG::get_parameters(BC_WindowBase *parent_window,
63 BC_WindowBase* &format_window,
69 JPEGConfigVideo *window = new JPEGConfigVideo(parent_window, asset);
70 format_window = window;
71 window->create_objects();
78 int FileJPEG::can_copy_from(Edit *edit, int64_t position)
80 //printf("FileJPEG::can_copy_from %d %s\n", asset->format, asset->vcodec);
81 if(edit->asset->format == FILE_MOV)
83 if(match4(edit->asset->vcodec, QUICKTIME_JPEG)) return 1;
86 if(edit->asset->format == FILE_JPEG ||
87 edit->asset->format == FILE_JPEG_LIST)
93 int FileJPEG::colormodel_supported(int colormodel)
99 int FileJPEG::get_best_colormodel(Asset *asset, int driver)
106 case PLAYBACK_X11_XV:
107 case PLAYBACK_DV1394:
108 case PLAYBACK_FIREWIRE:
109 case PLAYBACK_ASYNCHRONOUS:
112 case PLAYBACK_X11_GL:
125 case VIDEO4LINUX2JPEG:
128 case CAPTURE_FIREWIRE:
129 case CAPTURE_IEC61883:
137 int FileJPEG::write_frame(VFrame *frame, VFrame *data, FrameWriterUnit *unit)
140 JPEGUnit *jpeg_unit = (JPEGUnit*)unit;
142 if(!jpeg_unit->compressor)
143 jpeg_unit->compressor = mjpeg_new(asset->width,
146 mjpeg_set_quality((mjpeg_t*)jpeg_unit->compressor, asset->jpeg_quality);
149 mjpeg_compress((mjpeg_t*)jpeg_unit->compressor,
154 frame->get_color_model(),
157 data->allocate_compressed_data(mjpeg_output_size((mjpeg_t*)jpeg_unit->compressor));
158 data->set_compressed_size(mjpeg_output_size((mjpeg_t*)jpeg_unit->compressor));
159 memcpy(data->get_data(),
160 mjpeg_output_buffer((mjpeg_t*)jpeg_unit->compressor),
161 mjpeg_output_size((mjpeg_t*)jpeg_unit->compressor));
175 int FileJPEG::read_frame_header(char *path)
182 if(!(stream = fopen(path, "rb")))
184 eprintf("Error while opening \"%s\" for reading. \n%m\n", asset->path);
190 struct jpeg_decompress_struct jpeg_decompress;
191 struct jpeg_error_mgr jpeg_error;
193 jpeg_decompress.err = jpeg_std_error(&jpeg_error);
194 jpeg_create_decompress(&jpeg_decompress);
196 jpeg_stdio_src(&jpeg_decompress, stream);
197 jpeg_read_header(&jpeg_decompress, TRUE);
199 asset->width = jpeg_decompress.image_width;
200 asset->height = jpeg_decompress.image_height;
202 asset->interlace_mode = BC_ILACE_MODE_NOTINTERLACED;
204 jpeg_destroy((j_common_ptr)&jpeg_decompress);
214 int FileJPEG::read_frame(VFrame *output, VFrame *input)
216 if(!decompressor) decompressor = mjpeg_new(asset->width,
219 mjpeg_decompress((mjpeg_t*)decompressor,
221 input->get_compressed_size(),
227 output->get_color_model(),
234 FrameWriterUnit* FileJPEG::new_writer_unit(FrameWriter *writer)
236 return new JPEGUnit(this, writer);
244 JPEGUnit::JPEGUnit(FileJPEG *file, FrameWriter *writer)
245 : FrameWriterUnit(writer)
250 JPEGUnit::~JPEGUnit()
252 if(compressor) mjpeg_delete((mjpeg_t*)compressor);
261 JPEGConfigVideo::JPEGConfigVideo(BC_WindowBase *parent_window, Asset *asset)
262 : BC_Window(PROGRAM_NAME ": Video Compression",
263 parent_window->get_abs_cursor_x(1),
264 parent_window->get_abs_cursor_y(1),
268 this->parent_window = parent_window;
272 JPEGConfigVideo::~JPEGConfigVideo()
276 int JPEGConfigVideo::create_objects()
280 add_subwindow(new BC_Title(x, y, _("Quality:")));
281 add_subwindow(new BC_ISlider(x + 80,
291 &asset->jpeg_quality));
293 add_subwindow(new BC_OKButton(this));
297 int JPEGConfigVideo::close_event()