add bluray dv, misc fixes
[goodguy/history.git] / cinelerra-5.1 / 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 "vframe.h"
30
31 #include <ctype.h>
32 #include <stdlib.h>
33 #include <string.h>
34
35
36 FileJPEGList::FileJPEGList(Asset *asset, File *file)
37  : FileList(asset, file)
38 {
39         asset->format = FILE_JPEG_LIST;
40 }
41
42 FileJPEGList::~FileJPEGList()
43 {
44         close_file();
45 }
46
47 char* FileJPEGList::list_title()
48 {
49         return _("JPEGLIST");
50 }
51
52 char* FileJPEGList::extension()
53 {
54         return ".jpg";
55 }
56
57 void FileJPEGList::get_parameters(BC_WindowBase *parent_window,
58         Asset *asset,
59         BC_WindowBase* &format_window,
60         int audio_options,
61         int video_options)
62 {
63         if(video_options)
64         {
65                 JPEGConfigVideo *window = new JPEGConfigVideo(parent_window, asset);
66                 format_window = window;
67                 window->create_objects();
68                 window->run_window();
69                 delete window;
70         }
71 }
72
73 int FileJPEGList::can_copy_from(Asset *asset)
74 {
75         if(asset->format == FILE_JPEG_LIST)
76                 return 1;
77
78         return 0;
79 }
80
81 int FileJPEGList::get_best_colormodel(int driver, int colormodel)
82 {
83         if(colormodel > -1)
84         {
85                 switch(colormodel)
86                 {
87                         case BC_YUV420P:
88                         case BC_YUV422P:
89                         case BC_YUV422:
90                                 return colormodel;
91                                 break;
92                         default:
93                                 return BC_YUV422P;
94                                 break;
95                 }
96         }
97         return BC_YUV422P;
98 }
99
100
101 int FileJPEGList::read_frame(VFrame *frame, VFrame *data)
102 {
103         PRINT_TRACE
104
105         mjpeg_t *mjpeg = mjpeg_new(asset->width,
106                 asset->height,
107                 1);
108         mjpeg_decompress(mjpeg,
109                 data->get_data(),
110                 data->get_compressed_size(),
111                 0,
112                 frame->get_rows(),
113                 frame->get_y(),
114                 frame->get_u(),
115                 frame->get_v(),
116                 frame->get_color_model(),
117                 file->cpus);
118         mjpeg_delete(mjpeg);
119         PRINT_TRACE
120         return 0;
121 }
122
123 int FileJPEGList::write_frame(VFrame *frame, VFrame *data)
124 {
125         mjpeg_t *mjpeg = mjpeg_new(asset->width,
126                 asset->height,
127                 1);
128         mjpeg_compress(mjpeg,
129                 frame->get_rows(),
130                 frame->get_y(),
131                 frame->get_u(),
132                 frame->get_v(),
133                 frame->get_color_model(),
134                 file->cpus);
135         data->allocate_compressed_data(mjpeg_output_size(mjpeg));
136         bcopy(mjpeg_output_buffer(mjpeg), frame->get_data(), mjpeg_output_size(mjpeg));
137         mjpeg_delete(mjpeg);
138         return 0;
139 }
140
141
142
143
144
145
146
147
148
149
150
151 JPEGConfigVideo::JPEGConfigVideo(BC_WindowBase *parent_window, Asset *asset)
152  : BC_Window(_(PROGRAM_NAME ": Video Compression"),
153         parent_window->get_abs_cursor_x(),
154         parent_window->get_abs_cursor_y(),
155         400,
156         100)
157 {
158         this->parent_window = parent_window;
159         this->asset = asset;
160 }
161
162 JPEGConfigVideo::~JPEGConfigVideo()
163 {
164 }
165
166 void JPEGConfigVideo::create_objects()
167 {
168         int x = 10, y = 10;
169         lock_window("JPEGConfigVideo::create_objects");
170         add_subwindow(new BC_Title(x, y, _("Quality:")));
171         add_subwindow(new BC_ISlider(x + 80,
172                 y,
173                 0,
174                 200,
175                 200,
176                 0,
177                 100,
178                 asset->quality,
179                 0,
180                 0,
181                 &asset->quality));
182
183         add_subwindow(new BC_OKButton(this));
184         unlock_window();
185 }
186
187 int JPEGConfigVideo::close_event()
188 {
189         set_done(0);
190         return 1;
191 }
192
193
194
195
196
197
198