Credit Andrew - fix vorbis audio which was scratchy and ensure aging plugin does...
[goodguy/cinelerra.git] / cinelerra-5.1 / cinelerra / filetga.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 "asset.h"
23 #include "bcsignals.h"
24 #include "edit.h"
25 #include "filetga.h"
26 #include "language.h"
27 #include "mwindow.inc"
28 #include "vframe.h"
29 #include "mainerror.h"
30
31 #include <string.h>
32 #include <unistd.h>
33
34 /* Known image types. */
35 #define TGA_TYPE_MAPPED      1
36 #define TGA_TYPE_COLOR       2
37 #define TGA_TYPE_GRAY        3
38
39 /* Only known compression is RLE */
40 #define TGA_COMP_NONE        0
41 #define TGA_COMP_RLE         1
42
43
44 FileTGA::FileTGA(Asset *asset, File *file)
45  : FileList(asset, file, "TGALIST", ".tga", FILE_TGA, FILE_TGA_LIST)
46 {
47         temp = 0;
48 }
49
50 FileTGA::~FileTGA()
51 {
52         if(temp) delete temp;
53 }
54
55 int FileTGA::check_sig(Asset *asset)
56 {
57
58
59 // Test file extension
60         int result = 0;
61         char *ext = strrchr(asset->path, '.');
62
63         if(ext)
64         {
65
66                 if(!strncasecmp(ext, ".tga", 4)) result = 1;
67
68         }
69
70
71
72 // Test for list
73         if(!result)
74         {
75                 FILE *stream;
76                 if(!(stream = fopen(asset->path, "rb")))
77                 {
78 // file not found
79                         result = 0;
80                 }
81                 else
82                 {
83                         char test[16];
84                         (void)fread(test, 16, 1, stream);
85                         fclose(stream);
86                         if(test[0] == 'T' && test[1] == 'G' && test[2] == 'A' &&
87                                 test[3] == 'L' && test[4] == 'I' && test[5] == 'S' &&
88                                 test[6] == 'T')
89                         {
90                                 result = 1;
91                         }
92
93                 }
94         }
95
96
97         return result;
98 }
99
100 void FileTGA::get_parameters(BC_WindowBase *parent_window,
101         Asset *asset, BC_WindowBase* &format_window,
102         int audio_options, int video_options, EDL *edl)
103 {
104         if(video_options)
105         {
106                 TGAConfigVideo *window = new TGAConfigVideo(parent_window, asset);
107                 format_window = window;
108                 window->create_objects();
109                 window->run_window();
110                 delete window;
111         }
112 }
113
114 #if 0
115 N_("RGB compressed")
116 N_("RGBA compressed")
117 N_("RGB uncompressed")
118 N_("RGBA uncompressed")
119 #endif
120
121 #define TGA_RGB_RLE "rle "
122 #define TGA_RGBA_RLE "rlea"
123 #define TGA_RGB "raw "
124 #define TGA_RGBA "rawa"
125
126 #define TGA_RGB_RLE_NAME "RGB compressed"
127 #define TGA_RGBA_RLE_NAME "RGBA compressed"
128 #define TGA_RGB_NAME "RGB uncompressed"
129 #define TGA_RGBA_NAME "RGBA uncompressed"
130
131 const char* FileTGA::compression_to_str(const char *compression)
132 {
133         if(!strcasecmp(compression, TGA_RGB_RLE)) return _(TGA_RGB_RLE_NAME);
134         if(!strcasecmp(compression, TGA_RGBA_RLE)) return _(TGA_RGBA_RLE_NAME);
135         if(!strcasecmp(compression, TGA_RGB)) return _(TGA_RGB_NAME);
136         if(!strcasecmp(compression, TGA_RGBA)) return _(TGA_RGBA_NAME);
137         return TGA_RGB_NAME;
138 }
139
140 const char* FileTGA::str_to_compression(const char *string)
141 {
142         if(!strcasecmp(compression_to_str(TGA_RGB_RLE), string)) return TGA_RGB_RLE;
143         if(!strcasecmp(compression_to_str(TGA_RGBA_RLE), string)) return TGA_RGBA_RLE;
144         if(!strcasecmp(compression_to_str(TGA_RGB), string)) return TGA_RGB;
145         if(!strcasecmp(compression_to_str(TGA_RGBA), string)) return TGA_RGBA;
146         return TGA_RGB;
147 }
148
149 int FileTGA::can_copy_from(Asset *asset, int64_t position)
150 {
151         if(asset->format == FILE_TGA_LIST ||
152                 asset->format == FILE_TGA)
153                 return 1;
154
155         return 0;
156 }
157
158
159 int  FileTGA::colormodel_supported(int colormodel)
160 {
161         return colormodel;
162 }
163
164 int FileTGA::get_best_colormodel(Asset *asset, int driver)
165 {
166         if(!strcasecmp(asset->vcodec, TGA_RGB_RLE) ||
167                 !strcasecmp(asset->vcodec, TGA_RGB)) return BC_RGB888;
168         if(!strcasecmp(asset->vcodec, TGA_RGBA_RLE) ||
169                 !strcasecmp(asset->vcodec, TGA_RGBA)) return BC_RGBA8888;
170         return BC_RGB888;
171 }
172
173 int FileTGA::read_frame(VFrame *frame, VFrame *data)
174 {
175         read_tga(asset, frame, data, temp);
176         return 0;
177 }
178
179 int FileTGA::write_frame(VFrame *frame, VFrame *data, FrameWriterUnit *unit)
180 {
181         TGAUnit *tga_unit = (TGAUnit*)unit;
182
183         write_tga(asset, frame, data, tga_unit->temp);
184         return 0;
185 }
186
187 FrameWriterUnit* FileTGA::new_writer_unit(FrameWriter *writer)
188 {
189         return new TGAUnit(this, writer);
190 }
191
192 int64_t FileTGA::get_memory_usage()
193 {
194         int64_t result = FileList::get_memory_usage();
195         if(temp) result += temp->get_data_size();
196         return result;
197 }
198
199
200
201
202
203
204
205
206 #define FOOTERSIZE 26
207 #define HEADERSIZE 18
208 int FileTGA::read_frame_header(char *path)
209 {
210         int result = 0;
211
212 //printf("FileTGA::read_frame_header 1\n");
213         FILE *stream;
214
215         if(!(stream = fopen(path, "rb")))
216         {
217                 eprintf(_("Error while opening \"%s\" for reading. \n%m\n"), asset->path);
218                 return 1;
219         }
220
221         unsigned char header[HEADERSIZE];
222         (void)fread(header, HEADERSIZE, 1, stream);
223         fclose(stream);
224
225         asset->width = header[12] | (header[13] << 8);
226         asset->height = header[14] | (header[15] << 8);
227         int bpp = header[16];
228         int rle = header[2] & 0x8;
229         switch(bpp)
230         {
231                 case 32:
232                         if(rle)
233                                 strcpy(asset->vcodec, TGA_RGBA_RLE);
234                         else
235                                 strcpy(asset->vcodec, TGA_RGBA);
236                         break;
237                 case 24:
238                         if(rle)
239                                 strcpy(asset->vcodec, TGA_RGB_RLE);
240                         else
241                                 strcpy(asset->vcodec, TGA_RGB);
242                         break;
243         }
244 //printf("FileTGA::read_frame_header 2 %d %d\n", asset->width, asset->height);
245
246         return result;
247 }
248
249 void FileTGA::read_tga(Asset *asset, VFrame *frame, VFrame *data, VFrame* &temp)
250 {
251 // Read header
252         int64_t file_offset = 0;
253
254 //      unsigned char *footer = data->get_data() +
255 //              data->get_compressed_size() - FOOTERSIZE;
256         unsigned char *header = data->get_data();
257         file_offset += HEADERSIZE;
258
259         int image_type = 0;
260         int image_compression = 0;
261         switch(header[2])
262         {
263                 case 1:
264                         image_type = TGA_TYPE_MAPPED;
265                         image_compression = TGA_COMP_NONE;
266                         break;
267                 case 2:
268                         image_type = TGA_TYPE_COLOR;
269                         image_compression = TGA_COMP_NONE;
270                         break;
271                 case 3:
272                         image_type = TGA_TYPE_GRAY;
273                         image_compression = TGA_COMP_NONE;
274                         break;
275                 case 9:
276                         image_type = TGA_TYPE_MAPPED;
277                         image_compression = TGA_COMP_RLE;
278                         break;
279                 case 10:
280                         image_type = TGA_TYPE_COLOR;
281                         image_compression = TGA_COMP_RLE;
282                         break;
283                 case 11:
284                         image_type = TGA_TYPE_GRAY;
285                         image_compression = TGA_COMP_RLE;
286                         break;
287         }
288
289         int idlength = header[0];
290         int colormaptype = header[1];
291         //int colormapindex = header[3] + header[4] * 256;
292         int colormaplength = header[5] + header[6] * 256;
293         int colormapsize = header[7];
294         //int xorigin = header[8] + header[9] * 256;
295         //int yorigin = header[10] + header[11] * 256;
296         int width = header[12] + header[13] * 256;
297         int height = header[14] + header[15] * 256;
298         int bpp = header[16];
299         int bytes = (bpp + 7) / 8;
300         int alphabits = header[17] & 0x0f;
301         int fliphoriz = (header[17] & 0x10) ? 1 : 0;
302         int flipvert = (header[17] & 0x20) ? 0 : 1;
303         int data_size = data->get_compressed_size();
304
305         if(idlength) file_offset += idlength;
306
307 // Get colormap
308         unsigned char *tga_cmap;
309         unsigned char colormap[4 * 256];
310
311         if(colormaptype == 1)
312         {
313                 int cmap_bytes = (colormapsize + 7) / 8;
314                 tga_cmap = data->get_data() + file_offset;
315                 file_offset += colormaplength * cmap_bytes;
316
317                 switch(colormapsize)
318                 {
319                         case 32:
320                                 bgr2rgb(colormap, tga_cmap, colormaplength, cmap_bytes, 1);
321                                 break;
322                         case 24:
323                                 bgr2rgb(colormap, tga_cmap, colormaplength, cmap_bytes, 0);
324                                 break;
325                         case 16:
326                                 upsample(colormap, tga_cmap, colormaplength, cmap_bytes);
327                                 break;
328                 }
329         }
330
331         int source_cmodel = BC_RGB888;
332         switch(bpp)
333         {
334                 case 32:
335                         source_cmodel = BC_RGBA8888;
336                         break;
337                 case 24:
338                         source_cmodel = BC_RGB888;
339                         break;
340                 default:
341                         return;
342         }
343
344 // Read image
345         VFrame *output_frame;
346         if(frame->get_color_model() == source_cmodel)
347         {
348                 output_frame = frame;
349         }
350         else
351         {
352                 if(temp && temp->get_color_model() != source_cmodel)
353                 {
354                         delete temp;
355                         temp = 0;
356                 }
357
358                 if(!temp)
359                 {
360                         temp = new VFrame(width, height, source_cmodel, 0);
361                 }
362                 output_frame = temp;
363         }
364
365         if(flipvert)
366         {
367                 for(int i = height - 1; i >= 0; i--)
368                 {
369                         read_line(output_frame->get_rows()[i],
370                                 data->get_data(),
371                                 file_offset,
372                                 image_type,
373                                 bpp,
374                                 image_compression,
375                                 bytes,
376                                 width,
377                                 fliphoriz,
378                                 alphabits,
379                                 data_size);
380                 }
381         }
382         else
383         {
384                 for(int i = 0; i < height; i++)
385                 {
386                         read_line(output_frame->get_rows()[i],
387                                 data->get_data(),
388                                 file_offset,
389                                 image_type,
390                                 bpp,
391                                 image_compression,
392                                 bytes,
393                                 width,
394                                 fliphoriz,
395                                 alphabits,
396                                 data_size);
397                 }
398         }
399
400         if(output_frame != frame)
401         {
402                 BC_CModels::transfer(frame->get_rows(), output_frame->get_rows(),
403                         frame->get_y(), frame->get_u(), frame->get_v(),
404                         output_frame->get_y(), output_frame->get_u(), output_frame->get_v(),
405                         0, 0, width, height,
406                         0, 0, frame->get_w(), frame->get_h(),
407                         output_frame->get_color_model(), frame->get_color_model(),
408                         0, width, frame->get_w());
409         }
410 }
411
412 void FileTGA::write_tga(Asset *asset, VFrame *frame, VFrame *data, VFrame* &temp)
413 {
414         unsigned char header[18];
415         //unsigned char footer[26];
416         int64_t file_offset = 0;
417         int out_bpp = 0;
418         int rle = 0;
419         int dest_cmodel = BC_RGB888;
420
421 //printf("FileTGA::write_tga 1\n");
422
423         header[0] = 0;
424         header[1] = 0;
425         if(!strcasecmp(asset->vcodec, TGA_RGBA_RLE))
426         {
427                 header[2] = 10;
428                 out_bpp = 4;
429                 rle = 1;
430                 header[16] = 32; /* bpp */
431                 header[17] = 0x28; /* alpha + orientation */
432                 dest_cmodel = BC_RGBA8888;
433         }
434         else
435         if(!strcasecmp(asset->vcodec, TGA_RGBA))
436         {
437                 header[2] = 2;
438                 out_bpp = 4;
439                 rle = 0;
440                 header[16] = 32; /* bpp */
441                 header[17] = 0x28; /* alpha + orientation */
442                 dest_cmodel = BC_RGBA8888;
443         }
444         else
445         if(!strcasecmp(asset->vcodec, TGA_RGB_RLE))
446         {
447                 header[2] = 10;
448                 out_bpp = 3;
449                 rle = 1;
450                 header[16] = 24; /* bpp */
451                 header[17] = 0x20; /* alpha + orientation */
452                 dest_cmodel = BC_RGB888;
453         }
454         else
455         {
456                 header[2] = 2;
457                 out_bpp = 3;
458                 rle = 0;
459                 header[16] = 24; /* bpp */
460                 header[17] = 0x20; /* alpha + orientation */
461                 dest_cmodel = BC_RGB888;
462         }
463         header[3] = header[4] = header[5] = header[6] = header[7] = 0;
464 //printf("FileTGA::write_tga 1\n");
465
466         VFrame *input_frame;
467         if(frame->get_color_model() == dest_cmodel)
468         {
469                 input_frame = frame;
470         }
471         else
472         {
473                 if(temp && temp->get_color_model() != dest_cmodel)
474                 {
475                         delete temp;
476                         temp = 0;
477                 }
478
479                 if(!temp)
480                 {
481                         temp = new VFrame(0, -1, frame->get_w(), frame->get_h(), dest_cmodel, -1);
482                 }
483                 input_frame = temp;
484
485                 BC_CModels::transfer(input_frame->get_rows(), frame->get_rows(),
486                         input_frame->get_y(), input_frame->get_u(), input_frame->get_v(),
487                         frame->get_y(), frame->get_u(), frame->get_v(),
488                         0, 0, frame->get_w(), frame->get_h(),
489                         0, 0, frame->get_w(), frame->get_h(),
490                         frame->get_color_model(), input_frame->get_color_model(),
491                         0, frame->get_w(), frame->get_w());
492         }
493 //printf("FileTGA::write_tga 1\n");
494
495 // xorigin
496 // yorigin
497         header[8]  = header[9]  = 0;
498         header[10] = header[11] = 0;
499
500         header[12] = input_frame->get_w() % 256;
501         header[13] = input_frame->get_w() / 256;
502
503         header[14] = input_frame->get_h() % 256;
504         header[15] = input_frame->get_h() / 256;
505 //printf("FileTGA::write_tga 1\n");
506
507         write_data(header, data, file_offset, sizeof(header));
508 //printf("FileTGA::write_tga 1\n");
509
510         unsigned char *output = new unsigned char[out_bpp * input_frame->get_w()];
511 //printf("FileTGA::write_tga 1\n");
512         for(int i = 0; i < input_frame->get_h(); i++)
513         {
514 //printf("FileTGA::write_tga 2\n");
515                 bgr2rgb(output, input_frame->get_rows()[i], input_frame->get_w(), out_bpp, (out_bpp == 4));
516 //printf("FileTGA::write_tga 3\n");
517
518                 if(rle)
519                 {
520 //printf("FileTGA::write_tga 4\n");
521                         rle_write(output,
522                                 input_frame->get_w(),
523                                 out_bpp,
524                                 data,
525                                 file_offset);
526 //printf("FileTGA::write_tga 5\n");
527                 }
528                 else
529                 {
530 //printf("FileTGA::write_tga 6\n");
531                         write_data(output,
532                                 data,
533                                 file_offset,
534                                 input_frame->get_w() * out_bpp);
535 //printf("FileTGA::write_tga 7\n");
536                 }
537         }
538 //printf("FileTGA::write_tga 8\n");
539         delete [] output;
540 //printf("FileTGA::write_tga 9\n");
541 }
542
543 void FileTGA::write_data(unsigned char *buffer,
544         VFrame *data,
545         int64_t &file_offset,
546         int64_t len)
547 {
548 //printf("FileTGA::write_data 1 %d\n", len);
549         if(data->get_compressed_allocated() <= data->get_compressed_size() + len)
550         {
551                 data->allocate_compressed_data((data->get_compressed_size() + len) * 2);
552         }
553 //printf("FileTGA::write_data 1 %d\n", len);
554
555         bcopy(buffer, data->get_data() + file_offset, len);
556 //printf("FileTGA::write_data 1 %d\n", len);
557         file_offset += len;
558 //printf("FileTGA::write_data 1 %d\n", len);
559         data->set_compressed_size(file_offset);
560 //printf("FileTGA::write_data 2 %d\n", len);
561 }
562
563 void FileTGA::read_line(unsigned char *row, unsigned char *data,
564         int64_t &file_offset, int image_type, int bpp, int image_compression,
565         int bytes, int width, int fliphoriz, int alphabits, int data_size)
566 {
567         if(file_offset >= data_size) return;
568         if(image_compression == TGA_COMP_RLE)
569         {
570                 rle_read(row, data, file_offset, bytes, width);
571         }
572         else
573         {
574                 if(file_offset + bytes * width <= data_size)
575                         bcopy(data + file_offset, row, bytes * width);
576                 file_offset += bytes * width;
577         }
578
579         if(fliphoriz)
580         {
581                 flip_line(row, bytes, width);
582         }
583
584         if(image_type == TGA_TYPE_COLOR)
585         {
586                 if(bpp == 16)
587                 {
588                         upsample(row, row, width, bytes);
589                 }
590                 else
591                 {
592                         bgr2rgb(row, row, width, bytes, alphabits);
593                 }
594         }
595         else
596         {
597                 ;
598         }
599 }
600
601 void FileTGA::flip_line(unsigned char *row, int bytes, int width)
602 {
603         unsigned char temp;
604         unsigned char *alt;
605         int x, s;
606         alt = row + (bytes * (width - 1));
607
608         for (x = 0; x * 2 <= width; x++) {
609                 for(s = 0; s < bytes; ++s) {
610                         temp = row[s];
611                         row[s] = alt[s];
612                         alt[s] = temp;
613                 }
614
615                 row += bytes;
616                 alt -= bytes;
617         }
618 }
619
620 void FileTGA::rle_read(unsigned char *row,
621         unsigned char *data,
622         int64_t &file_offset,
623         int bytes,
624         int width)
625 {
626         int repeat = 0;
627         int direct = 0;
628         unsigned char sample[4];
629         int head;
630
631         for(int x = 0; x < width; x++)
632         {
633                 if(repeat == 0 && direct == 0)
634                 {
635                         head = data[file_offset++];
636                         if(head == EOF)
637                         {
638                                 return;
639                         }
640                         else
641                         if(head >= 128)
642                         {
643                                 repeat = head - 127;
644                                 bcopy(data + file_offset, sample, bytes);
645                                 file_offset += bytes;
646                         }
647                         else
648                         {
649                                 direct = head + 1;
650                         }
651                 }
652
653                 if(repeat > 0)
654                 {
655                         for(int k = 0; k < bytes; k++)
656                         {
657                                 row[k] = sample[k];
658                         }
659
660                         repeat--;
661                 }
662                 else
663                 {
664                         bcopy(data + file_offset, row, bytes);
665                         file_offset += bytes;
666
667                         direct--;
668                 }
669
670                 row += bytes;
671         }
672 }
673
674 void FileTGA::rle_write(unsigned char *buffer,
675         int width,
676         int bytes,
677         VFrame *frame,
678         int64_t &file_offset)
679 {
680         int repeat = 0;
681         int direct = 0;
682         unsigned char *from = buffer;
683         unsigned char output;
684         int x;
685
686         for(x = 1; x < width; ++x)
687         {
688 /* next pixel is different */
689                 if(memcmp(buffer, buffer + bytes, bytes))
690                 {
691                         if(repeat)
692                         {
693                                 output = 128 + repeat;
694                                 write_data(&output, frame, file_offset, 1);
695                                 write_data(from, frame, file_offset, bytes);
696                                 from = buffer + bytes;
697                                 repeat = 0;
698                                 direct = 0;
699                         }
700                         else
701                         {
702                                 direct++;
703                         }
704                 }
705                 else
706 /* next pixel is the same */
707                 {
708                         if(direct)
709                         {
710                                 output = direct - 1;
711                                 write_data(&output, frame, file_offset, 1);
712                                 write_data(from, frame, file_offset, bytes * direct);
713                                 from = buffer;
714                                 direct = 0;
715                                 repeat = 1;
716                         }
717                         else
718                         {
719                                 repeat++;
720                         }
721                 }
722
723                 if(repeat == 128)
724                 {
725                         output = 255;
726                         write_data(&output, frame, file_offset, 1);
727                         write_data(from, frame, file_offset, bytes);
728                         from = buffer + bytes;
729                         direct = 0;
730                         repeat = 0;
731                 }
732                 else
733                 if(direct == 128)
734                 {
735                         output = 127;
736                         write_data(&output, frame, file_offset, 1);
737                         write_data(from, frame, file_offset, direct * bytes);
738                         from = buffer + bytes;
739                         direct = 0;
740                         repeat = 0;
741                 }
742
743                 buffer += bytes;
744         }
745
746         if(repeat > 0)
747         {
748                 output = 128 + repeat;
749                 write_data(&output, frame, file_offset, 1);
750                 write_data(from, frame, file_offset, bytes);
751         }
752         else
753         {
754                 output = direct;
755                 write_data(&output, frame, file_offset, 1);
756                 write_data(from, frame, file_offset, bytes * (direct + 1));
757         }
758 }
759
760
761 void FileTGA::bgr2rgb(unsigned char *dest, unsigned char *src,
762                  int width, int bytes, int alpha)
763 {
764         int x;
765         unsigned char r, g, b;
766
767         if(alpha) {
768                 for(x = 0; x < width; x++) {
769                         r = src[2]; g = src[1]; b = src[0];
770                         *(dest++) = r; *(dest++) = g; *(dest++) = b;
771                         *(dest++) = src[3]; src += bytes;
772                 }
773         }
774         else {
775                 for(x = 0; x < width; x++) {
776                         r = src[2]; g = src[1]; b = src[0];
777                         *(dest++) = r; *(dest++) = g; *(dest++) = b;
778                         src += bytes;
779                 }
780         }
781 }
782
783 void FileTGA::upsample(unsigned char *dest,
784           unsigned char *src,
785           int width,
786           int bytes)
787 {
788         int x;
789
790         dest += (width - 1) * 3;
791         src += (width - 1) * bytes;
792         for(x = width - 1; x >= 0; x--) {
793                 dest[0] =  ((src[1] << 1) & 0xf8);
794                 dest[0] += (dest[0] >> 5);
795
796                 dest[1] =  ((src[0] & 0xe0) >> 2) + ((src[1] & 0x03) << 6);
797                 dest[1] += (dest[1] >> 5);
798
799                 dest[2] =  ((src[0] << 3) & 0xf8);
800                 dest[2] += (dest[2] >> 5);
801
802                 dest -= 3;
803                 src -= bytes;
804         }
805 }
806
807
808 TGAUnit::TGAUnit(FileTGA *file, FrameWriter *writer)
809  : FrameWriterUnit(writer)
810 {
811         temp = 0;
812         this->file = file;
813 }
814
815 TGAUnit::~TGAUnit()
816 {
817         if(temp) delete temp;
818 }
819
820
821 TGAConfigVideo::TGAConfigVideo(BC_WindowBase *gui, Asset *asset)
822  : BC_Window(_(PROGRAM_NAME ": Video Compression"),
823         gui->get_abs_cursor_x(1), gui->get_abs_cursor_y(1),
824         xS(400), yS(100))
825 {
826         this->gui = gui;
827         this->asset = asset;
828
829         compression_items.append(new BC_ListBoxItem(FileTGA::compression_to_str(TGA_RGB_RLE)));
830         compression_items.append(new BC_ListBoxItem(FileTGA::compression_to_str(TGA_RGBA_RLE)));
831         compression_items.append(new BC_ListBoxItem(FileTGA::compression_to_str(TGA_RGB)));
832         compression_items.append(new BC_ListBoxItem(FileTGA::compression_to_str(TGA_RGBA)));
833 // *** CONTEXT_HELP ***
834         context_help_set_keyword("Single File Rendering");
835 }
836
837 TGAConfigVideo::~TGAConfigVideo()
838 {
839         compression_items.remove_all_objects();
840 }
841
842 void TGAConfigVideo::create_objects()
843 {
844         lock_window("TGAConfigVideo::create_objects");
845         int x = xS(10), y = yS(10);
846
847         add_subwindow(new BC_Title(x, y, _("Compression:")));
848         TGACompression *textbox = new TGACompression(this,
849                         x + xS(110), y, asset, &compression_items);
850         textbox->create_objects();
851         add_subwindow(new BC_OKButton(this));
852         show_window(1);
853         unlock_window();
854 }
855
856 int TGAConfigVideo::close_event()
857 {
858         set_done(0);
859         return 1;
860 }
861
862
863 TGACompression::TGACompression(TGAConfigVideo *gui, int x, int y,
864         Asset *asset, ArrayList<BC_ListBoxItem*> *compression_items)
865  : BC_PopupTextBox(gui, compression_items,
866         FileTGA::compression_to_str(gui->asset->vcodec),
867         x, y, xS(200), yS(200))
868 {
869         this->asset = asset;
870 }
871 int TGACompression::handle_event()
872 {
873         strcpy(asset->vcodec, FileTGA::str_to_compression(get_text()));
874         return 1;
875 }