initial commit
[goodguy/history.git] / cinelerra-5.0 / cinelerra / filejpeglist.C
1
2 /*
3  * CINELERRA
4  * Copyright (C) 2008 Adam Williams <broadcast at earthling dot net>
5  * 
6  * This program is free software; you can redistribute it and/or modify
7  * it under the terms of the GNU General Public License as published by
8  * the Free Software Foundation; either version 2 of the License, or
9  * (at your option) any later version.
10  * 
11  * This program is distributed in the hope that it will be useful,
12  * but WITHOUT ANY WARRANTY; without even the implied warranty of
13  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14  * GNU General Public License for more details.
15  * 
16  * You should have received a copy of the GNU General Public License
17  * along with this program; if not, write to the Free Software
18  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
19  * 
20  */
21
22 #include "assets.h"
23 #include "file.h"
24 #include "filejpeglist.h"
25 #include "guicast.h"
26 #include "libmjpeg.h"
27 #include "mwindow.inc"
28 #include "jpegwrapper.h"
29 #include "quicktime.h"
30 #include "vframe.h"
31
32 #include <ctype.h>
33 #include <stdlib.h>
34 #include <string.h>
35
36
37 FileJPEGList::FileJPEGList(Asset *asset, File *file)
38  : FileList(asset, file)
39 {
40         asset->format = FILE_JPEG_LIST;
41 }
42
43 FileJPEGList::~FileJPEGList()
44 {
45         close_file();
46 }
47
48 char* FileJPEGList::list_title()
49 {
50         return _("JPEGLIST");
51 }
52
53 char* FileJPEGList::extension()
54 {
55         return ".jpg";
56 }
57
58 void FileJPEGList::get_parameters(BC_WindowBase *parent_window, 
59         Asset *asset, 
60         BC_WindowBase* &format_window,
61         int audio_options,
62         int video_options)
63 {
64         if(video_options)
65         {
66                 JPEGConfigVideo *window = new JPEGConfigVideo(parent_window, asset);
67                 format_window = window;
68                 window->create_objects();
69                 window->run_window();
70                 delete window;
71         }
72 }
73
74 int FileJPEGList::can_copy_from(Asset *asset)
75 {
76         if(asset->format == FILE_JPEG_LIST)
77                 return 1;
78         else
79         if(asset->format == FILE_MOV && match4(asset->vcodec, QUICKTIME_JPEG))
80                 return 1;
81         
82         return 0;
83 }
84
85 int FileJPEGList::get_best_colormodel(int driver, int colormodel)
86 {
87         if(colormodel > -1)
88         {
89                 switch(colormodel)
90                 {
91                         case BC_YUV420P:
92                         case BC_YUV422P:
93                         case BC_YUV422:
94                                 return colormodel;
95                                 break;
96                         default:
97                                 return BC_YUV422P;
98                                 break;
99                 }
100         }
101         return BC_YUV422P;
102 }
103
104
105 int FileJPEGList::read_frame(VFrame *frame, VFrame *data)
106 {
107         PRINT_TRACE
108
109         mjpeg_t *mjpeg = mjpeg_new(asset->width, 
110                 asset->height, 
111                 1);
112         mjpeg_decompress(mjpeg, 
113                 data->get_data(), 
114                 data->get_compressed_size(),
115                 0,  
116                 frame->get_rows(), 
117                 frame->get_y(), 
118                 frame->get_u(), 
119                 frame->get_v(),
120                 frame->get_color_model(),
121                 file->cpus);
122         mjpeg_delete(mjpeg);
123         PRINT_TRACE
124         return 0;
125 }
126
127 int FileJPEGList::write_frame(VFrame *frame, VFrame *data)
128 {
129         mjpeg_t *mjpeg = mjpeg_new(asset->width, 
130                 asset->height, 
131                 1);
132         mjpeg_compress(mjpeg, 
133                 frame->get_rows(), 
134                 frame->get_y(), 
135                 frame->get_u(), 
136                 frame->get_v(),
137                 frame->get_color_model(),
138                 file->cpus);
139         data->allocate_compressed_data(mjpeg_output_size(mjpeg));
140         bcopy(mjpeg_output_buffer(mjpeg), frame->get_data(), mjpeg_output_size(mjpeg));
141         mjpeg_delete(mjpeg);
142         return 0;
143 }
144
145
146
147
148
149
150
151
152
153
154
155 JPEGConfigVideo::JPEGConfigVideo(BC_WindowBase *parent_window, Asset *asset)
156  : BC_Window(PROGRAM_NAME ": Video Compression",
157         parent_window->get_abs_cursor_x(),
158         parent_window->get_abs_cursor_y(),
159         400,
160         100)
161 {
162         this->parent_window = parent_window;
163         this->asset = asset;
164 }
165
166 JPEGConfigVideo::~JPEGConfigVideo()
167 {
168 }
169
170 int JPEGConfigVideo::create_objects()
171 {
172         int x = 10, y = 10;
173         lock_window("JPEGConfigVideo::create_objects");
174         add_subwindow(new BC_Title(x, y, _("Quality:")));
175         add_subwindow(new BC_ISlider(x + 80, 
176                 y,
177                 0,
178                 200,
179                 200,
180                 0,
181                 100,
182                 asset->quality,
183                 0,
184                 0,
185                 &asset->quality));
186
187         add_subwindow(new BC_OKButton(this));
188         unlock_window();
189         return 0;
190 }
191
192 int JPEGConfigVideo::close_event()
193 {
194         set_done(0);
195         return 1;
196 }
197
198
199
200
201
202
203