license header for review
[cinelerra_cv/ct.git] / cinelerra / filejpeglist.C
blob8266a1ddb1b30bd5d094aecfba25bad1845e1fa5
1 #include "assets.h"
2 #include "file.h"
3 #include "filejpeglist.h"
4 #include "guicast.h"
5 #include "libmjpeg.h"
6 #include "mwindow.inc"
7 #include "jpegwrapper.h"
8 #include "quicktime.h"
9 #include "vframe.h"
11 #include <ctype.h>
12 #include <stdlib.h>
13 #include <string.h>
16 FileJPEGList::FileJPEGList(Asset_GC asset, File *file)
17  : FileList(asset, file)
19         asset->format = FILE_JPEG_LIST;
22 FileJPEGList::~FileJPEGList()
24         close_file();
27 char* FileJPEGList::list_title()
29         return _("JPEGLIST");
32 char* FileJPEGList::extension()
34         return ".jpg";
37 void FileJPEGList::get_parameters(BC_WindowBase *parent_window, 
38         Asset_GC asset, 
39         BC_WindowBase* &format_window,
40         int audio_options,
41         int video_options)
43         if(video_options)
44         {
45                 JPEGConfigVideo *window = new JPEGConfigVideo(parent_window, asset);
46                 format_window = window;
47                 window->create_objects();
48                 window->run_window();
49                 delete window;
50         }
53 int FileJPEGList::can_copy_from(Asset_GC asset)
55         if(asset->format == FILE_JPEG_LIST)
56                 return 1;
57         else
58         if(asset->format == FILE_MOV && match4(asset->vcodec, QUICKTIME_JPEG))
59                 return 1;
60         
61         return 0;
64 int FileJPEGList::get_best_colormodel(int driver, int colormodel)
66         if(colormodel > -1)
67         {
68                 switch(colormodel)
69                 {
70                         case BC_YUV420P:
71                         case BC_YUV422P:
72                         case BC_YUV422:
73                                 return colormodel;
74                                 break;
75                         default:
76                                 return BC_YUV422P;
77                                 break;
78                 }
79         }
80         return BC_YUV422P;
84 int FileJPEGList::read_frame(VFrame *frame, VFrame *data)
86         mjpeg_t *mjpeg = mjpeg_new(asset->width, 
87                 asset->height, 
88                 1);
89         mjpeg_decompress(mjpeg, 
90                 data->get_data(), 
91                 data->get_compressed_size(),
92                 0,  
93                 frame->get_rows(), 
94                 frame->get_y(), 
95                 frame->get_u(), 
96                 frame->get_v(),
97                 frame->get_color_model(),
98                 file->cpus);
99         mjpeg_delete(mjpeg);
100         return 0;
103 int FileJPEGList::write_frame(VFrame *frame, VFrame *data)
105         mjpeg_t *mjpeg = mjpeg_new(asset->width, 
106                 asset->height, 
107                 1);
108         mjpeg_compress(mjpeg, 
109                 frame->get_rows(), 
110                 frame->get_y(), 
111                 frame->get_u(), 
112                 frame->get_v(),
113                 frame->get_color_model(),
114                 file->cpus);
115         data->allocate_compressed_data(mjpeg_output_size(mjpeg));
116         bcopy(mjpeg_output_buffer(mjpeg), frame->get_data(), mjpeg_output_size(mjpeg));
117         mjpeg_delete(mjpeg);
118         return 0;
131 JPEGConfigVideo::JPEGConfigVideo(BC_WindowBase *parent_window, Asset_GC asset)
132  : BC_Window(PROGRAM_NAME ": Video Compression",
133         parent_window->get_abs_cursor_x(),
134         parent_window->get_abs_cursor_y(),
135         400,
136         100)
138         this->parent_window = parent_window;
139         this->asset = asset;
142 JPEGConfigVideo::~JPEGConfigVideo()
146 int JPEGConfigVideo::create_objects()
148         int x = 10, y = 10;
150         add_subwindow(new BC_Title(x, y, _("Quality:")));
151         add_subwindow(new BC_ISlider(x + 80, 
152                 y,
153                 0,
154                 200,
155                 200,
156                 0,
157                 100,
158                 asset->quality,
159                 0,
160                 0,
161                 &asset->quality));
163         add_subwindow(new BC_OKButton(this));
164         return 0;
167 int JPEGConfigVideo::close_event()
169         set_done(0);
170         return 1;
180 //      Local Variables:
181 //      mode: C++
182 //      c-file-style: "linux"
183 //      End: