5 #include "jpegwrapper.h"
10 #include "videodevice.inc"
13 #define _(String) gettext(String)
14 #define gettext_noop(String) String
15 #define N_(String) gettext_noop (String)
18 FileJPEG::FileJPEG(Asset *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 *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 *asset, int driver)
107 case PLAYBACK_X11_XV:
108 case PLAYBACK_FIREWIRE:
123 case CAPTURE_FIREWIRE:
131 int FileJPEG::write_frame(VFrame *frame, VFrame *data, FrameWriterUnit *unit)
134 JPEGUnit *jpeg_unit = (JPEGUnit*)unit;
136 if(!jpeg_unit->compressor)
137 jpeg_unit->compressor = mjpeg_new(asset->width,
140 mjpeg_set_quality((mjpeg_t*)jpeg_unit->compressor, asset->jpeg_quality);
143 mjpeg_compress((mjpeg_t*)jpeg_unit->compressor,
148 frame->get_color_model(),
151 data->allocate_compressed_data(mjpeg_output_size((mjpeg_t*)jpeg_unit->compressor));
152 data->set_compressed_size(mjpeg_output_size((mjpeg_t*)jpeg_unit->compressor));
153 memcpy(data->get_data(),
154 mjpeg_output_buffer((mjpeg_t*)jpeg_unit->compressor),
155 mjpeg_output_size((mjpeg_t*)jpeg_unit->compressor));
169 int FileJPEG::read_frame_header(char *path)
176 if(!(stream = fopen(path, "rb")))
178 perror("FileJPEG::read_frame_header");
184 struct jpeg_decompress_struct jpeg_decompress;
185 struct jpeg_error_mgr jpeg_error;
187 jpeg_decompress.err = jpeg_std_error(&jpeg_error);
188 jpeg_create_decompress(&jpeg_decompress);
190 jpeg_stdio_src(&jpeg_decompress, stream);
191 jpeg_read_header(&jpeg_decompress, TRUE);
193 asset->width = jpeg_decompress.image_width;
194 asset->height = jpeg_decompress.image_height;
196 jpeg_destroy((j_common_ptr)&jpeg_decompress);
206 int FileJPEG::read_frame(VFrame *output, VFrame *input)
208 //printf("FileJPEG::read_frame 1\n");
209 if(!decompressor) decompressor = mjpeg_new(asset->width,
212 //printf("FileJPEG::read_frame 1\n");
213 mjpeg_decompress((mjpeg_t*)decompressor,
215 input->get_compressed_size(),
221 output->get_color_model(),
223 //printf("FileJPEG::read_frame 1\n");
224 //printf("FileJPEG::read_frame 2\n");
230 FrameWriterUnit* FileJPEG::new_writer_unit(FrameWriter *writer)
232 return new JPEGUnit(this, writer);
240 JPEGUnit::JPEGUnit(FileJPEG *file, FrameWriter *writer)
241 : FrameWriterUnit(writer)
246 JPEGUnit::~JPEGUnit()
248 if(compressor) mjpeg_delete((mjpeg_t*)compressor);
257 JPEGConfigVideo::JPEGConfigVideo(BC_WindowBase *parent_window, Asset *asset)
258 : BC_Window(PROGRAM_NAME ": Video Compression",
259 parent_window->get_abs_cursor_x(),
260 parent_window->get_abs_cursor_y(),
264 this->parent_window = parent_window;
268 JPEGConfigVideo::~JPEGConfigVideo()
272 int JPEGConfigVideo::create_objects()
276 add_subwindow(new BC_Title(x, y, _("Quality:")));
277 add_subwindow(new BC_ISlider(x + 80,
287 &asset->jpeg_quality));
289 add_subwindow(new BC_OKButton(this));
293 int JPEGConfigVideo::close_event()