remove incorrectly named
[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         }
341
342 // Read image
343         VFrame *output_frame;
344         if(frame->get_color_model() == source_cmodel)
345         {
346                 output_frame = frame;
347         }
348         else
349         {
350                 if(temp && temp->get_color_model() != source_cmodel)
351                 {
352                         delete temp;
353                         temp = 0;
354                 }
355
356                 if(!temp)
357                 {
358                         temp = new VFrame(width, height, source_cmodel, 0);
359                 }
360                 output_frame = temp;
361         }
362
363         if(flipvert)
364         {
365                 for(int i = height - 1; i >= 0; i--)
366                 {
367                         read_line(output_frame->get_rows()[i],
368                                 data->get_data(),
369                                 file_offset,
370                                 image_type,
371                                 bpp,
372                                 image_compression,
373                                 bytes,
374                                 width,
375                                 fliphoriz,
376                                 alphabits,
377                                 data_size);
378                 }
379         }
380         else
381         {
382                 for(int i = 0; i < height; i++)
383                 {
384                         read_line(output_frame->get_rows()[i],
385                                 data->get_data(),
386                                 file_offset,
387                                 image_type,
388                                 bpp,
389                                 image_compression,
390                                 bytes,
391                                 width,
392                                 fliphoriz,
393                                 alphabits,
394                                 data_size);
395                 }
396         }
397
398         if(output_frame != frame)
399         {
400                 BC_CModels::transfer(frame->get_rows(), output_frame->get_rows(),
401                         frame->get_y(), frame->get_u(), frame->get_v(),
402                         output_frame->get_y(), output_frame->get_u(), output_frame->get_v(),
403                         0, 0, width, height,
404                         0, 0, frame->get_w(), frame->get_h(),
405                         output_frame->get_color_model(), frame->get_color_model(),
406                         0, width, frame->get_w());
407         }
408 }
409
410 void FileTGA::write_tga(Asset *asset, VFrame *frame, VFrame *data, VFrame* &temp)
411 {
412         unsigned char header[18];
413         //unsigned char footer[26];
414         int64_t file_offset = 0;
415         int out_bpp = 0;
416         int rle = 0;
417         int dest_cmodel = BC_RGB888;
418
419 //printf("FileTGA::write_tga 1\n");
420
421         header[0] = 0;
422         header[1] = 0;
423         if(!strcasecmp(asset->vcodec, TGA_RGBA_RLE))
424         {
425                 header[2] = 10;
426                 out_bpp = 4;
427                 rle = 1;
428                 header[16] = 32; /* bpp */
429                 header[17] = 0x28; /* alpha + orientation */
430                 dest_cmodel = BC_RGBA8888;
431         }
432         else
433         if(!strcasecmp(asset->vcodec, TGA_RGBA))
434         {
435                 header[2] = 2;
436                 out_bpp = 4;
437                 rle = 0;
438                 header[16] = 32; /* bpp */
439                 header[17] = 0x28; /* alpha + orientation */
440                 dest_cmodel = BC_RGBA8888;
441         }
442         else
443         if(!strcasecmp(asset->vcodec, TGA_RGB_RLE))
444         {
445                 header[2] = 10;
446                 out_bpp = 3;
447                 rle = 1;
448                 header[16] = 24; /* bpp */
449                 header[17] = 0x20; /* alpha + orientation */
450                 dest_cmodel = BC_RGB888;
451         }
452         else
453         {
454                 header[2] = 2;
455                 out_bpp = 3;
456                 rle = 0;
457                 header[16] = 24; /* bpp */
458                 header[17] = 0x20; /* alpha + orientation */
459                 dest_cmodel = BC_RGB888;
460         }
461         header[3] = header[4] = header[5] = header[6] = header[7] = 0;
462 //printf("FileTGA::write_tga 1\n");
463
464         VFrame *input_frame;
465         if(frame->get_color_model() == dest_cmodel)
466         {
467                 input_frame = frame;
468         }
469         else
470         {
471                 if(temp && temp->get_color_model() != dest_cmodel)
472                 {
473                         delete temp;
474                         temp = 0;
475                 }
476
477                 if(!temp)
478                 {
479                         temp = new VFrame(0, -1, frame->get_w(), frame->get_h(), dest_cmodel, -1);
480                 }
481                 input_frame = temp;
482
483                 BC_CModels::transfer(input_frame->get_rows(), frame->get_rows(),
484                         input_frame->get_y(), input_frame->get_u(), input_frame->get_v(),
485                         frame->get_y(), frame->get_u(), frame->get_v(),
486                         0, 0, frame->get_w(), frame->get_h(),
487                         0, 0, frame->get_w(), frame->get_h(),
488                         frame->get_color_model(), input_frame->get_color_model(),
489                         0, frame->get_w(), frame->get_w());
490         }
491 //printf("FileTGA::write_tga 1\n");
492
493 // xorigin
494 // yorigin
495         header[8]  = header[9]  = 0;
496         header[10] = header[11] = 0;
497
498         header[12] = input_frame->get_w() % 256;
499         header[13] = input_frame->get_w() / 256;
500
501         header[14] = input_frame->get_h() % 256;
502         header[15] = input_frame->get_h() / 256;
503 //printf("FileTGA::write_tga 1\n");
504
505         write_data(header, data, file_offset, sizeof(header));
506 //printf("FileTGA::write_tga 1\n");
507
508         unsigned char *output = new unsigned char[out_bpp * input_frame->get_w()];
509 //printf("FileTGA::write_tga 1\n");
510         for(int i = 0; i < input_frame->get_h(); i++)
511         {
512 //printf("FileTGA::write_tga 2\n");
513                 bgr2rgb(output, input_frame->get_rows()[i], input_frame->get_w(), out_bpp, (out_bpp == 4));
514 //printf("FileTGA::write_tga 3\n");
515
516                 if(rle)
517                 {
518 //printf("FileTGA::write_tga 4\n");
519                         rle_write(output,
520                                 input_frame->get_w(),
521                                 out_bpp,
522                                 data,
523                                 file_offset);
524 //printf("FileTGA::write_tga 5\n");
525                 }
526                 else
527                 {
528 //printf("FileTGA::write_tga 6\n");
529                         write_data(output,
530                                 data,
531                                 file_offset,
532                                 input_frame->get_w() * out_bpp);
533 //printf("FileTGA::write_tga 7\n");
534                 }
535         }
536 //printf("FileTGA::write_tga 8\n");
537         delete [] output;
538 //printf("FileTGA::write_tga 9\n");
539 }
540
541 void FileTGA::write_data(unsigned char *buffer,
542         VFrame *data,
543         int64_t &file_offset,
544         int64_t len)
545 {
546 //printf("FileTGA::write_data 1 %d\n", len);
547         if(data->get_compressed_allocated() <= data->get_compressed_size() + len)
548         {
549                 data->allocate_compressed_data((data->get_compressed_size() + len) * 2);
550         }
551 //printf("FileTGA::write_data 1 %d\n", len);
552
553         bcopy(buffer, data->get_data() + file_offset, len);
554 //printf("FileTGA::write_data 1 %d\n", len);
555         file_offset += len;
556 //printf("FileTGA::write_data 1 %d\n", len);
557         data->set_compressed_size(file_offset);
558 //printf("FileTGA::write_data 2 %d\n", len);
559 }
560
561 void FileTGA::read_line(unsigned char *row, unsigned char *data,
562         int64_t &file_offset, int image_type, int bpp, int image_compression,
563         int bytes, int width, int fliphoriz, int alphabits, int data_size)
564 {
565         if(file_offset >= data_size) return;
566         if(image_compression == TGA_COMP_RLE)
567         {
568                 rle_read(row, data, file_offset, bytes, width);
569         }
570         else
571         {
572                 if(file_offset + bytes * width <= data_size)
573                         bcopy(data + file_offset, row, bytes * width);
574                 file_offset += bytes * width;
575         }
576
577         if(fliphoriz)
578         {
579                 flip_line(row, bytes, width);
580         }
581
582         if(image_type == TGA_TYPE_COLOR)
583         {
584                 if(bpp == 16)
585                 {
586                         upsample(row, row, width, bytes);
587                 }
588                 else
589                 {
590                         bgr2rgb(row, row, width, bytes, alphabits);
591                 }
592         }
593         else
594         {
595                 ;
596         }
597 }
598
599 void FileTGA::flip_line(unsigned char *row, int bytes, int width)
600 {
601         unsigned char temp;
602         unsigned char *alt;
603         int x, s;
604         alt = row + (bytes * (width - 1));
605
606         for (x = 0; x * 2 <= width; x++) {
607                 for(s = 0; s < bytes; ++s) {
608                         temp = row[s];
609                         row[s] = alt[s];
610                         alt[s] = temp;
611                 }
612
613                 row += bytes;
614                 alt -= bytes;
615         }
616 }
617
618 void FileTGA::rle_read(unsigned char *row,
619         unsigned char *data,
620         int64_t &file_offset,
621         int bytes,
622         int width)
623 {
624         int repeat = 0;
625         int direct = 0;
626         unsigned char sample[4];
627         int head;
628
629         for(int x = 0; x < width; x++)
630         {
631                 if(repeat == 0 && direct == 0)
632                 {
633                         head = data[file_offset++];
634                         if(head == EOF)
635                         {
636                                 return;
637                         }
638                         else
639                         if(head >= 128)
640                         {
641                                 repeat = head - 127;
642                                 bcopy(data + file_offset, sample, bytes);
643                                 file_offset += bytes;
644                         }
645                         else
646                         {
647                                 direct = head + 1;
648                         }
649                 }
650
651                 if(repeat > 0)
652                 {
653                         for(int k = 0; k < bytes; k++)
654                         {
655                                 row[k] = sample[k];
656                         }
657
658                         repeat--;
659                 }
660                 else
661                 {
662                         bcopy(data + file_offset, row, bytes);
663                         file_offset += bytes;
664
665                         direct--;
666                 }
667
668                 row += bytes;
669         }
670 }
671
672 void FileTGA::rle_write(unsigned char *buffer,
673         int width,
674         int bytes,
675         VFrame *frame,
676         int64_t &file_offset)
677 {
678         int repeat = 0;
679         int direct = 0;
680         unsigned char *from = buffer;
681         unsigned char output;
682         int x;
683
684         for(x = 1; x < width; ++x)
685         {
686 /* next pixel is different */
687                 if(memcmp(buffer, buffer + bytes, bytes))
688                 {
689                         if(repeat)
690                         {
691                                 output = 128 + repeat;
692                                 write_data(&output, frame, file_offset, 1);
693                                 write_data(from, frame, file_offset, bytes);
694                                 from = buffer + bytes;
695                                 repeat = 0;
696                                 direct = 0;
697                         }
698                         else
699                         {
700                                 direct++;
701                         }
702                 }
703                 else
704 /* next pixel is the same */
705                 {
706                         if(direct)
707                         {
708                                 output = direct - 1;
709                                 write_data(&output, frame, file_offset, 1);
710                                 write_data(from, frame, file_offset, bytes * direct);
711                                 from = buffer;
712                                 direct = 0;
713                                 repeat = 1;
714                         }
715                         else
716                         {
717                                 repeat++;
718                         }
719                 }
720
721                 if(repeat == 128)
722                 {
723                         output = 255;
724                         write_data(&output, frame, file_offset, 1);
725                         write_data(from, frame, file_offset, bytes);
726                         from = buffer + bytes;
727                         direct = 0;
728                         repeat = 0;
729                 }
730                 else
731                 if(direct == 128)
732                 {
733                         output = 127;
734                         write_data(&output, frame, file_offset, 1);
735                         write_data(from, frame, file_offset, direct * bytes);
736                         from = buffer + bytes;
737                         direct = 0;
738                         repeat = 0;
739                 }
740
741                 buffer += bytes;
742         }
743
744         if(repeat > 0)
745         {
746                 output = 128 + repeat;
747                 write_data(&output, frame, file_offset, 1);
748                 write_data(from, frame, file_offset, bytes);
749         }
750         else
751         {
752                 output = direct;
753                 write_data(&output, frame, file_offset, 1);
754                 write_data(from, frame, file_offset, bytes * (direct + 1));
755         }
756 }
757
758
759 void FileTGA::bgr2rgb(unsigned char *dest, unsigned char *src,
760                  int width, int bytes, int alpha)
761 {
762         int x;
763         unsigned char r, g, b;
764
765         if(alpha) {
766                 for(x = 0; x < width; x++) {
767                         r = src[2]; g = src[1]; b = src[0];
768                         *(dest++) = r; *(dest++) = g; *(dest++) = b;
769                         *(dest++) = src[3]; src += bytes;
770                 }
771         }
772         else {
773                 for(x = 0; x < width; x++) {
774                         r = src[2]; g = src[1]; b = src[0];
775                         *(dest++) = r; *(dest++) = g; *(dest++) = b;
776                         src += bytes;
777                 }
778         }
779 }
780
781 void FileTGA::upsample(unsigned char *dest,
782           unsigned char *src,
783           int width,
784           int bytes)
785 {
786         int x;
787
788         dest += (width - 1) * 3;
789         src += (width - 1) * bytes;
790         for(x = width - 1; x >= 0; x--) {
791                 dest[0] =  ((src[1] << 1) & 0xf8);
792                 dest[0] += (dest[0] >> 5);
793
794                 dest[1] =  ((src[0] & 0xe0) >> 2) + ((src[1] & 0x03) << 6);
795                 dest[1] += (dest[1] >> 5);
796
797                 dest[2] =  ((src[0] << 3) & 0xf8);
798                 dest[2] += (dest[2] >> 5);
799
800                 dest -= 3;
801                 src -= bytes;
802         }
803 }
804
805
806 TGAUnit::TGAUnit(FileTGA *file, FrameWriter *writer)
807  : FrameWriterUnit(writer)
808 {
809         temp = 0;
810         this->file = file;
811 }
812
813 TGAUnit::~TGAUnit()
814 {
815         if(temp) delete temp;
816 }
817
818
819 TGAConfigVideo::TGAConfigVideo(BC_WindowBase *gui, Asset *asset)
820  : BC_Window(_(PROGRAM_NAME ": Video Compression"),
821         gui->get_abs_cursor_x(1), gui->get_abs_cursor_y(1),
822         xS(400), yS(100))
823 {
824         this->gui = gui;
825         this->asset = asset;
826
827         compression_items.append(new BC_ListBoxItem(FileTGA::compression_to_str(TGA_RGB_RLE)));
828         compression_items.append(new BC_ListBoxItem(FileTGA::compression_to_str(TGA_RGBA_RLE)));
829         compression_items.append(new BC_ListBoxItem(FileTGA::compression_to_str(TGA_RGB)));
830         compression_items.append(new BC_ListBoxItem(FileTGA::compression_to_str(TGA_RGBA)));
831 // *** CONTEXT_HELP ***
832         context_help_set_keyword("Single File Rendering");
833 }
834
835 TGAConfigVideo::~TGAConfigVideo()
836 {
837         compression_items.remove_all_objects();
838 }
839
840 void TGAConfigVideo::create_objects()
841 {
842         lock_window("TGAConfigVideo::create_objects");
843         int x = xS(10), y = yS(10);
844
845         add_subwindow(new BC_Title(x, y, _("Compression:")));
846         TGACompression *textbox = new TGACompression(this,
847                         x + xS(110), y, asset, &compression_items);
848         textbox->create_objects();
849         add_subwindow(new BC_OKButton(this));
850         show_window(1);
851         unlock_window();
852 }
853
854 int TGAConfigVideo::close_event()
855 {
856         set_done(0);
857         return 1;
858 }
859
860
861 TGACompression::TGACompression(TGAConfigVideo *gui, int x, int y,
862         Asset *asset, ArrayList<BC_ListBoxItem*> *compression_items)
863  : BC_PopupTextBox(gui, compression_items,
864         FileTGA::compression_to_str(gui->asset->vcodec),
865         x, y, xS(200), yS(200))
866 {
867         this->asset = asset;
868 }
869 int TGACompression::handle_event()
870 {
871         strcpy(asset->vcodec, FileTGA::str_to_compression(get_text()));
872         return 1;
873 }