bsd lang segv fix, enable bsd lv2, lv2 gui enable fix, proxy/ffmpeg toggle resize...
[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, BC_WindowBase* &format_window,
59         int audio_options, int video_options, EDL *edl)
60 {
61         if(video_options)
62         {
63                 JPEGConfigVideo *window = new JPEGConfigVideo(parent_window, asset);
64                 format_window = window;
65                 window->create_objects();
66                 window->run_window();
67                 delete window;
68         }
69 }
70
71 int FileJPEGList::can_copy_from(Asset *asset)
72 {
73         if(asset->format == FILE_JPEG_LIST)
74                 return 1;
75
76         return 0;
77 }
78
79 int FileJPEGList::get_best_colormodel(int driver, int colormodel)
80 {
81         if(colormodel > -1)
82         {
83                 switch(colormodel)
84                 {
85                         case BC_YUV420P:
86                         case BC_YUV422P:
87                         case BC_YUV422:
88                                 return colormodel;
89                                 break;
90                         default:
91                                 return BC_YUV422P;
92                                 break;
93                 }
94         }
95         return BC_YUV422P;
96 }
97
98
99 int FileJPEGList::read_frame(VFrame *frame, VFrame *data)
100 {
101         PRINT_TRACE
102
103         mjpeg_t *mjpeg = mjpeg_new(asset->width,
104                 asset->height,
105                 1);
106         mjpeg_decompress(mjpeg,
107                 data->get_data(),
108                 data->get_compressed_size(),
109                 0,
110                 frame->get_rows(),
111                 frame->get_y(),
112                 frame->get_u(),
113                 frame->get_v(),
114                 frame->get_color_model(),
115                 file->cpus);
116         mjpeg_delete(mjpeg);
117         PRINT_TRACE
118         return 0;
119 }
120
121 int FileJPEGList::write_frame(VFrame *frame, VFrame *data)
122 {
123         mjpeg_t *mjpeg = mjpeg_new(asset->width,
124                 asset->height,
125                 1);
126         mjpeg_compress(mjpeg,
127                 frame->get_rows(),
128                 frame->get_y(),
129                 frame->get_u(),
130                 frame->get_v(),
131                 frame->get_color_model(),
132                 file->cpus);
133         data->allocate_compressed_data(mjpeg_output_size(mjpeg));
134         bcopy(mjpeg_output_buffer(mjpeg), frame->get_data(), mjpeg_output_size(mjpeg));
135         mjpeg_delete(mjpeg);
136         return 0;
137 }
138
139
140
141
142
143
144
145
146
147
148
149 JPEGConfigVideo::JPEGConfigVideo(BC_WindowBase *parent_window, Asset *asset)
150  : BC_Window(_(PROGRAM_NAME ": Video Compression"),
151         parent_window->get_abs_cursor_x(),
152         parent_window->get_abs_cursor_y(),
153         400,
154         100)
155 {
156         this->parent_window = parent_window;
157         this->asset = asset;
158 }
159
160 JPEGConfigVideo::~JPEGConfigVideo()
161 {
162 }
163
164 void JPEGConfigVideo::create_objects()
165 {
166         int x = 10, y = 10;
167         lock_window("JPEGConfigVideo::create_objects");
168         add_subwindow(new BC_Title(x, y, _("Quality:")));
169         add_subwindow(new BC_ISlider(x + 80,
170                 y,
171                 0,
172                 200,
173                 200,
174                 0,
175                 100,
176                 asset->quality,
177                 0,
178                 0,
179                 &asset->quality));
180
181         add_subwindow(new BC_OKButton(this));
182         unlock_window();
183 }
184
185 int JPEGConfigVideo::close_event()
186 {
187         set_done(0);
188         return 1;
189 }
190
191
192
193
194
195
196