3 #include "bcwidgetgrid.h"
7 #include "interlacemodes.h"
8 #include "jpegwrapper.h"
11 #include "mwindow.inc"
12 #include "quicktime.h"
14 #include "videodevice.inc"
15 #include "mainerror.h"
18 FileJPEG::FileJPEG(Asset_GC asset, File *file)
19 : FileList(asset, file, "JPEGLIST", ".jpg", FILE_JPEG, FILE_JPEG_LIST)
26 if(decompressor) mjpeg_delete((mjpeg_t*)decompressor);
30 int FileJPEG::check_sig(Asset_GC asset)
32 FILE *stream = fopen(asset->path, "rb");
37 fread(test, 10, 1, stream);
40 if(test[6] == 'J' && test[7] == 'F' && test[8] == 'I' && test[9] == 'F')
45 if(test[0] == 'J' && test[1] == 'P' && test[2] == 'E' && test[3] == 'G' &&
46 test[4] == 'L' && test[5] == 'I' && test[6] == 'S' && test[7] == 'T')
52 if(strlen(asset->path) > 4)
54 int len = strlen(asset->path);
55 if(!strncasecmp(asset->path + len - 4, ".jpg", 4)) return 1;
62 void FileJPEG::get_parameters(BC_WindowBase *parent_window,
64 BC_WindowBase* &format_window,
70 JPEGConfigVideo *window = new JPEGConfigVideo(parent_window, asset);
71 format_window = window;
72 window->create_objects();
79 int FileJPEG::can_copy_from(Edit *edit, int64_t position)
81 //printf("FileJPEG::can_copy_from %d %s\n", asset->format, asset->vcodec);
82 if(edit->asset->format == FILE_MOV)
84 if(match4(edit->asset->vcodec, QUICKTIME_JPEG)) return 1;
87 if(edit->asset->format == FILE_JPEG ||
88 edit->asset->format == FILE_JPEG_LIST)
94 int FileJPEG::colormodel_supported(int colormodel)
100 int FileJPEG::get_best_colormodel(Asset_GC asset, int driver)
107 case PLAYBACK_X11_XV:
108 case PLAYBACK_DV1394:
109 case PLAYBACK_FIREWIRE:
110 case PLAYBACK_ASYNCHRONOUS:
113 case PLAYBACK_X11_GL:
126 case VIDEO4LINUX2JPEG:
129 case CAPTURE_FIREWIRE:
130 case CAPTURE_IEC61883:
138 int FileJPEG::write_frame(VFrame *frame, VFrame *data, FrameWriterUnit *unit)
141 JPEGUnit *jpeg_unit = (JPEGUnit*)unit;
143 if(!jpeg_unit->compressor)
144 jpeg_unit->compressor = mjpeg_new(asset->width,
147 mjpeg_set_quality((mjpeg_t*)jpeg_unit->compressor, asset->jpeg_quality);
150 mjpeg_compress((mjpeg_t*)jpeg_unit->compressor,
155 frame->get_color_model(),
158 data->allocate_compressed_data(mjpeg_output_size((mjpeg_t*)jpeg_unit->compressor));
159 data->set_compressed_size(mjpeg_output_size((mjpeg_t*)jpeg_unit->compressor));
160 memcpy(data->get_data(),
161 mjpeg_output_buffer((mjpeg_t*)jpeg_unit->compressor),
162 mjpeg_output_size((mjpeg_t*)jpeg_unit->compressor));
176 int FileJPEG::read_frame_header(char *path)
183 if(!(stream = fopen(path, "rb")))
185 eprintf("Error while opening \"%s\" for reading. \n%m\n", asset->path);
191 struct jpeg_decompress_struct jpeg_decompress;
192 struct jpeg_error_mgr jpeg_error;
194 jpeg_decompress.err = jpeg_std_error(&jpeg_error);
195 jpeg_create_decompress(&jpeg_decompress);
197 jpeg_stdio_src(&jpeg_decompress, stream);
198 jpeg_read_header(&jpeg_decompress, TRUE);
200 asset->width = jpeg_decompress.image_width;
201 asset->height = jpeg_decompress.image_height;
203 asset->interlace_mode = BC_ILACE_MODE_NOTINTERLACED;
205 jpeg_destroy((j_common_ptr)&jpeg_decompress);
215 int FileJPEG::read_frame(VFrame *output, VFrame *input)
217 if(!decompressor) decompressor = mjpeg_new(asset->width,
220 mjpeg_decompress((mjpeg_t*)decompressor,
222 input->get_compressed_size(),
228 output->get_color_model(),
235 FrameWriterUnit* FileJPEG::new_writer_unit(FrameWriter *writer)
237 return new JPEGUnit(this, writer);
245 JPEGUnit::JPEGUnit(FileJPEG *file, FrameWriter *writer)
246 : FrameWriterUnit(writer)
251 JPEGUnit::~JPEGUnit()
253 if(compressor) mjpeg_delete((mjpeg_t*)compressor);
262 JPEGConfigVideo::JPEGConfigVideo(BC_WindowBase *parent_window, Asset_GC asset)
263 : BC_Window(PROGRAM_NAME ": Video Compression",
264 parent_window->get_abs_cursor_x(1),
265 parent_window->get_abs_cursor_y(1),
273 this->parent_window = parent_window;
277 JPEGConfigVideo::~JPEGConfigVideo()
281 int JPEGConfigVideo::create_objects()
286 BC_RelocatableWidget *rw;
288 wg = add_widgetgrid(new BC_WidgetGrid(10, 10, 10, 10, 3, 3));
291 add_subwindow(new BC_Title(x, y, _("Quality:")));
294 add_subwindow(new BC_ISlider(x + 80,
304 &asset->jpeg_quality));
308 add_subwindow(new BC_OKButton(this));
311 resize_window(wg->get_w_wm(), wg->get_h_wm() + rw->get_h());
315 int JPEGConfigVideo::close_event()
326 // c-file-style: "linux"