00001 #include "asset.h"
00002 #include "bcsignals.h"
00003 #include "edit.h"
00004 #include "filetga.h"
00005 #include "language.h"
00006 #include "mwindow.inc"
00007 #include "vframe.h"
00008 #include "mainerror.h"
00009
00010 #include <string.h>
00011 #include <unistd.h>
00012
00013
00014 #define TGA_TYPE_MAPPED 1
00015 #define TGA_TYPE_COLOR 2
00016 #define TGA_TYPE_GRAY 3
00017
00018
00019 #define TGA_COMP_NONE 0
00020 #define TGA_COMP_RLE 1
00021
00022
00023 FileTGA::FileTGA(Asset *asset, File *file)
00024 : FileList(asset, file, "TGALIST", ".tga", FILE_TGA, FILE_TGA_LIST)
00025 {
00026 temp = 0;
00027 }
00028
00029 FileTGA::~FileTGA()
00030 {
00031 if(temp) delete temp;
00032 }
00033
00034 int FileTGA::check_sig(Asset *asset)
00035 {
00036
00037
00038
00039 int result = 0;
00040 char *ext = strrchr(asset->path, '.');
00041
00042 if(ext)
00043 {
00044
00045 if(!strncasecmp(ext, ".tga", 4)) result = 1;
00046
00047 }
00048
00049
00050
00051
00052 if(!result)
00053 {
00054 FILE *stream;
00055 if(!(stream = fopen(asset->path, "rb")))
00056 {
00057
00058 result = 0;
00059 }
00060 else
00061 {
00062 char test[16];
00063 fread(test, 16, 1, stream);
00064 fclose(stream);
00065 if(test[0] == 'T' && test[1] == 'G' && test[2] == 'A' &&
00066 test[3] == 'L' && test[4] == 'I' && test[5] == 'S' &&
00067 test[6] == 'T')
00068 {
00069 result = 1;
00070 }
00071
00072 }
00073 }
00074
00075
00076 return result;
00077 }
00078
00079 void FileTGA::get_parameters(BC_WindowBase *parent_window,
00080 Asset *asset,
00081 BC_WindowBase* &format_window,
00082 int audio_options,
00083 int video_options)
00084 {
00085 if(video_options)
00086 {
00087 TGAConfigVideo *window = new TGAConfigVideo(parent_window, asset);
00088 format_window = window;
00089 window->create_objects();
00090 window->run_window();
00091 delete window;
00092 }
00093 }
00094
00095 #if 0
00096 N_("RGB compressed")
00097 N_("RGBA compressed")
00098 N_("RGB uncompressed")
00099 N_("RGBA uncompressed")
00100 #endif
00101
00102 #define TGA_RGB_RLE "rle "
00103 #define TGA_RGBA_RLE "rlea"
00104 #define TGA_RGB "raw "
00105 #define TGA_RGBA "rawa"
00106
00107 #define TGA_RGB_RLE_NAME "RGB compressed"
00108 #define TGA_RGBA_RLE_NAME "RGBA compressed"
00109 #define TGA_RGB_NAME "RGB uncompressed"
00110 #define TGA_RGBA_NAME "RGBA uncompressed"
00111
00112 char* FileTGA::compression_to_str(char *compression)
00113 {
00114 if(!strcasecmp(compression, TGA_RGB_RLE)) return _(TGA_RGB_RLE_NAME);
00115 if(!strcasecmp(compression, TGA_RGBA_RLE)) return _(TGA_RGBA_RLE_NAME);
00116 if(!strcasecmp(compression, TGA_RGB)) return _(TGA_RGB_NAME);
00117 if(!strcasecmp(compression, TGA_RGBA)) return _(TGA_RGBA_NAME);
00118 return TGA_RGB_NAME;
00119 }
00120
00121 char* FileTGA::str_to_compression(char *string)
00122 {
00123 if(!strcasecmp(compression_to_str(TGA_RGB_RLE), string)) return TGA_RGB_RLE;
00124 if(!strcasecmp(compression_to_str(TGA_RGBA_RLE), string)) return TGA_RGBA_RLE;
00125 if(!strcasecmp(compression_to_str(TGA_RGB), string)) return TGA_RGB;
00126 if(!strcasecmp(compression_to_str(TGA_RGBA), string)) return TGA_RGBA;
00127 return TGA_RGB;
00128 }
00129
00130 int FileTGA::can_copy_from(Edit *edit, int64_t position)
00131 {
00132 if(edit->asset->format == FILE_TGA_LIST ||
00133 edit->asset->format == FILE_TGA)
00134 return 1;
00135
00136 return 0;
00137 }
00138
00139
00140 int FileTGA::colormodel_supported(int colormodel)
00141 {
00142 return colormodel;
00143 }
00144
00145 int FileTGA::get_best_colormodel(Asset *asset, int driver)
00146 {
00147 if(!strcasecmp(asset->vcodec, TGA_RGB_RLE) ||
00148 !strcasecmp(asset->vcodec, TGA_RGB)) return BC_RGB888;
00149 if(!strcasecmp(asset->vcodec, TGA_RGBA_RLE) ||
00150 !strcasecmp(asset->vcodec, TGA_RGBA)) return BC_RGBA8888;
00151 return BC_RGB888;
00152 }
00153
00154 int FileTGA::read_frame(VFrame *frame, VFrame *data)
00155 {
00156 read_tga(asset, frame, data, temp);
00157 return 0;
00158 }
00159
00160 int FileTGA::write_frame(VFrame *frame, VFrame *data, FrameWriterUnit *unit)
00161 {
00162 TGAUnit *tga_unit = (TGAUnit*)unit;
00163
00164 write_tga(asset, frame, data, tga_unit->temp);
00165 return 0;
00166 }
00167
00168 FrameWriterUnit* FileTGA::new_writer_unit(FrameWriter *writer)
00169 {
00170 return new TGAUnit(this, writer);
00171 }
00172
00173 int64_t FileTGA::get_memory_usage()
00174 {
00175 int64_t result = FileList::get_memory_usage();
00176 if(temp) result += temp->get_data_size();
00177 return result;
00178 }
00179
00180
00181
00182
00183
00184
00185
00186
00187 #define FOOTERSIZE 26
00188 #define HEADERSIZE 18
00189 int FileTGA::read_frame_header(char *path)
00190 {
00191 int result = 0;
00192
00193
00194 FILE *stream;
00195
00196 if(!(stream = fopen(path, "rb")))
00197 {
00198 eprintf("Error while opening \"%s\" for reading. \n%m\n", asset->path);
00199 return 1;
00200 }
00201
00202 unsigned char header[HEADERSIZE];
00203 fread(header, HEADERSIZE, 1, stream);
00204 fclose(stream);
00205
00206 asset->width = header[12] | (header[13] << 8);
00207 asset->height = header[14] | (header[15] << 8);
00208 int bpp = header[16];
00209 int rle = header[2] & 0x8;
00210 switch(bpp)
00211 {
00212 case 32:
00213 if(rle)
00214 strcpy(asset->vcodec, TGA_RGBA_RLE);
00215 else
00216 strcpy(asset->vcodec, TGA_RGBA);
00217 break;
00218 case 24:
00219 if(rle)
00220 strcpy(asset->vcodec, TGA_RGB_RLE);
00221 else
00222 strcpy(asset->vcodec, TGA_RGB);
00223 break;
00224 }
00225
00226
00227 return result;
00228 }
00229
00230 void FileTGA::read_tga(Asset *asset, VFrame *frame, VFrame *data, VFrame* &temp)
00231 {
00232
00233 unsigned char *footer, *header;
00234 int input_cmodel;
00235 int64_t file_offset = 0;
00236
00237 footer = data->get_data() +
00238 data->get_compressed_size() -
00239 FOOTERSIZE;
00240 header = data->get_data();
00241 file_offset += HEADERSIZE;
00242
00243 int image_type;
00244 int image_compression;
00245 switch(header[2])
00246 {
00247 case 1:
00248 image_type = TGA_TYPE_MAPPED;
00249 image_compression = TGA_COMP_NONE;
00250 break;
00251 case 2:
00252 image_type = TGA_TYPE_COLOR;
00253 image_compression = TGA_COMP_NONE;
00254 break;
00255 case 3:
00256 image_type = TGA_TYPE_GRAY;
00257 image_compression = TGA_COMP_NONE;
00258 break;
00259 case 9:
00260 image_type = TGA_TYPE_MAPPED;
00261 image_compression = TGA_COMP_RLE;
00262 break;
00263 case 10:
00264 image_type = TGA_TYPE_COLOR;
00265 image_compression = TGA_COMP_RLE;
00266 break;
00267 case 11:
00268 image_type = TGA_TYPE_GRAY;
00269 image_compression = TGA_COMP_RLE;
00270 break;
00271 default:
00272 image_type = 0;
00273 }
00274
00275 int idlength = header[0];
00276 int colormaptype = header[1];
00277 int colormapindex = header[3] + header[4] * 256;
00278 int colormaplength = header[5] + header[6] * 256;
00279 int colormapsize = header[7];
00280 int xorigin = header[8] + header[9] * 256;
00281 int yorigin = header[10] + header[11] * 256;
00282 int width = header[12] + header[13] * 256;
00283 int height = header[14] + header[15] * 256;
00284 int bpp = header[16];
00285 int bytes = (bpp + 7) / 8;
00286 int alphabits = header[17] & 0x0f;
00287 int fliphoriz = (header[17] & 0x10) ? 1 : 0;
00288 int flipvert = (header[17] & 0x20) ? 0 : 1;
00289 int data_size = data->get_compressed_size();
00290
00291 if(idlength) file_offset += idlength;
00292
00293
00294 unsigned char *tga_cmap;
00295 unsigned char colormap[4 * 256];
00296
00297 if(colormaptype == 1)
00298 {
00299 int cmap_bytes = (colormapsize + 7) / 8;
00300 tga_cmap = data->get_data() + file_offset;
00301 file_offset += colormaplength * cmap_bytes;
00302
00303 switch(colormapsize)
00304 {
00305 case 32:
00306 bgr2rgb(colormap, tga_cmap, colormaplength, cmap_bytes, 1);
00307 break;
00308 case 24:
00309 bgr2rgb(colormap, tga_cmap, colormaplength, cmap_bytes, 0);
00310 break;
00311 case 16:
00312 upsample(colormap, tga_cmap, colormaplength, cmap_bytes);
00313 break;
00314 }
00315 }
00316
00317 int source_cmodel = BC_RGB888;
00318 switch(bpp)
00319 {
00320 case 32:
00321 source_cmodel = BC_RGBA8888;
00322 break;
00323 case 24:
00324 source_cmodel = BC_RGB888;
00325 break;
00326 }
00327
00328
00329 VFrame *output_frame;
00330 if(frame->get_color_model() == source_cmodel)
00331 {
00332 output_frame = frame;
00333 }
00334 else
00335 {
00336 if(temp && temp->get_color_model() != source_cmodel)
00337 {
00338 delete temp;
00339 temp = 0;
00340 }
00341
00342 if(!temp)
00343 {
00344 temp = new VFrame(0, width, height, source_cmodel);
00345 }
00346 output_frame = temp;
00347 }
00348
00349 if(flipvert)
00350 {
00351 for(int i = height - 1; i >= 0; i--)
00352 {
00353 read_line(output_frame->get_rows()[i],
00354 data->get_data(),
00355 file_offset,
00356 image_type,
00357 bpp,
00358 image_compression,
00359 bytes,
00360 width,
00361 fliphoriz,
00362 alphabits,
00363 data_size);
00364 }
00365 }
00366 else
00367 {
00368 for(int i = 0; i < height; i++)
00369 {
00370 read_line(output_frame->get_rows()[i],
00371 data->get_data(),
00372 file_offset,
00373 image_type,
00374 bpp,
00375 image_compression,
00376 bytes,
00377 width,
00378 fliphoriz,
00379 alphabits,
00380 data_size);
00381 }
00382 }
00383
00384 if(output_frame != frame)
00385 {
00386 cmodel_transfer(frame->get_rows(),
00387 output_frame->get_rows(),
00388 frame->get_y(),
00389 frame->get_u(),
00390 frame->get_v(),
00391 output_frame->get_y(),
00392 output_frame->get_u(),
00393 output_frame->get_v(),
00394 0,
00395 0,
00396 width,
00397 height,
00398 0,
00399 0,
00400 frame->get_w(),
00401 frame->get_h(),
00402 output_frame->get_color_model(),
00403 frame->get_color_model(),
00404 0,
00405 width,
00406 frame->get_w());
00407 }
00408 }
00409
00410 void FileTGA::write_tga(Asset *asset, VFrame *frame, VFrame *data, VFrame* &temp)
00411 {
00412 unsigned char header[18];
00413 unsigned char footer[26];
00414 int64_t file_offset = 0;
00415 int out_bpp = 0;
00416 int rle = 0;
00417 int dest_cmodel = BC_RGB888;
00418
00419
00420
00421 header[0] = 0;
00422 header[1] = 0;
00423 if(!strcasecmp(asset->vcodec, TGA_RGBA_RLE))
00424 {
00425 header[2] = 10;
00426 out_bpp = 4;
00427 rle = 1;
00428 header[16] = 32;
00429 header[17] = 0x28;
00430 dest_cmodel = BC_RGBA8888;
00431 }
00432 else
00433 if(!strcasecmp(asset->vcodec, TGA_RGBA))
00434 {
00435 header[2] = 2;
00436 out_bpp = 4;
00437 rle = 0;
00438 header[16] = 32;
00439 header[17] = 0x28;
00440 dest_cmodel = BC_RGBA8888;
00441 }
00442 else
00443 if(!strcasecmp(asset->vcodec, TGA_RGB_RLE))
00444 {
00445 header[2] = 10;
00446 out_bpp = 3;
00447 rle = 1;
00448 header[16] = 24;
00449 header[17] = 0x20;
00450 dest_cmodel = BC_RGB888;
00451 }
00452 else
00453 {
00454 header[2] = 2;
00455 out_bpp = 3;
00456 rle = 0;
00457 header[16] = 24;
00458 header[17] = 0x20;
00459 dest_cmodel = BC_RGB888;
00460 }
00461 header[3] = header[4] = header[5] = header[6] = header[7] = 0;
00462
00463
00464 VFrame *input_frame;
00465 if(frame->get_color_model() == dest_cmodel)
00466 {
00467 input_frame = frame;
00468 }
00469 else
00470 {
00471 if(temp && temp->get_color_model() != dest_cmodel)
00472 {
00473 delete temp;
00474 temp = 0;
00475 }
00476
00477 if(!temp)
00478 {
00479 temp = new VFrame(0, frame->get_w(), frame->get_h(), dest_cmodel);
00480 }
00481 input_frame = temp;
00482
00483 cmodel_transfer(input_frame->get_rows(),
00484 frame->get_rows(),
00485 input_frame->get_y(),
00486 input_frame->get_u(),
00487 input_frame->get_v(),
00488 frame->get_y(),
00489 frame->get_u(),
00490 frame->get_v(),
00491 0,
00492 0,
00493 frame->get_w(),
00494 frame->get_h(),
00495 0,
00496 0,
00497 frame->get_w(),
00498 frame->get_h(),
00499 frame->get_color_model(),
00500 input_frame->get_color_model(),
00501 0,
00502 frame->get_w(),
00503 frame->get_w());
00504 }
00505
00506
00507
00508
00509 header[8] = header[9] = 0;
00510 header[10] = header[11] = 0;
00511
00512 header[12] = input_frame->get_w() % 256;
00513 header[13] = input_frame->get_w() / 256;
00514
00515 header[14] = input_frame->get_h() % 256;
00516 header[15] = input_frame->get_h() / 256;
00517
00518
00519 write_data(header, data, file_offset, sizeof(header));
00520
00521
00522 unsigned char *output = new unsigned char[out_bpp * input_frame->get_w()];
00523
00524 for(int i = 0; i < input_frame->get_h(); i++)
00525 {
00526
00527 bgr2rgb(output, input_frame->get_rows()[i], input_frame->get_w(), out_bpp, (out_bpp == 4));
00528
00529
00530 if(rle)
00531 {
00532
00533 rle_write(output,
00534 input_frame->get_w(),
00535 out_bpp,
00536 data,
00537 file_offset);
00538
00539 }
00540 else
00541 {
00542
00543 write_data(output,
00544 data,
00545 file_offset,
00546 input_frame->get_w() * out_bpp);
00547
00548 }
00549 }
00550
00551 delete [] output;
00552
00553 }
00554
00555 void FileTGA::write_data(unsigned char *buffer,
00556 VFrame *data,
00557 int64_t &file_offset,
00558 int64_t len)
00559 {
00560
00561 if(data->get_compressed_allocated() <= data->get_compressed_size() + len)
00562 {
00563 data->allocate_compressed_data((data->get_compressed_size() + len) * 2);
00564 }
00565
00566
00567 bcopy(buffer, data->get_data() + file_offset, len);
00568
00569 file_offset += len;
00570
00571 data->set_compressed_size(file_offset);
00572
00573 }
00574
00575 void FileTGA::read_line(unsigned char *row,
00576 unsigned char *data,
00577 int64_t &file_offset,
00578 int image_type,
00579 int bpp,
00580 int image_compression,
00581 int bytes,
00582 int width,
00583 int fliphoriz,
00584 int alphabits,
00585 int data_size)
00586 {
00587 if(file_offset >= data_size) return;
00588 if(image_compression == TGA_COMP_RLE)
00589 {
00590 rle_read(row,
00591 data,
00592 file_offset,
00593 bytes,
00594 width);
00595 }
00596 else
00597 {
00598 if(file_offset + bytes * width <= data_size)
00599 bcopy(data + file_offset, row, bytes * width);
00600 file_offset += bytes * width;
00601 }
00602
00603 if(fliphoriz)
00604 {
00605 flip_line(row, bytes, width);
00606 }
00607
00608 if(image_type == TGA_TYPE_COLOR)
00609 {
00610 if(bpp == 16)
00611 {
00612 upsample(row, row, width, bytes);
00613 }
00614 else
00615 {
00616 bgr2rgb(row, row, width, bytes, alphabits);
00617 }
00618 }
00619 else
00620 {
00621 ;
00622 }
00623 }
00624
00625 void FileTGA::flip_line(unsigned char *row, int bytes, int width)
00626 {
00627 unsigned char temp;
00628 unsigned char *alt;
00629 int x, s;
00630
00631 alt = row + (bytes * (width - 1));
00632
00633 for (x = 0; x * 2 <= width; x++)
00634 {
00635 for(s = 0; s < bytes; ++s)
00636 {
00637 temp = row[s];
00638 row[s] = alt[s];
00639 alt[s] = temp;
00640 }
00641
00642 row += bytes;
00643 alt -= bytes;
00644 }
00645 }
00646
00647 void FileTGA::rle_read(unsigned char *row,
00648 unsigned char *data,
00649 int64_t &file_offset,
00650 int bytes,
00651 int width)
00652 {
00653 int repeat = 0;
00654 int direct = 0;
00655 unsigned char sample[4];
00656 int head;
00657
00658 for(int x = 0; x < width; x++)
00659 {
00660 if(repeat == 0 && direct == 0)
00661 {
00662 head = data[file_offset++];
00663 if(head == EOF)
00664 {
00665 return;
00666 }
00667 else
00668 if(head >= 128)
00669 {
00670 repeat = head - 127;
00671 bcopy(data + file_offset, sample, bytes);
00672 file_offset += bytes;
00673 }
00674 else
00675 {
00676 direct = head + 1;
00677 }
00678 }
00679
00680 if(repeat > 0)
00681 {
00682 for(int k = 0; k < bytes; k++)
00683 {
00684 row[k] = sample[k];
00685 }
00686
00687 repeat--;
00688 }
00689 else
00690 {
00691 bcopy(data + file_offset, row, bytes);
00692 file_offset += bytes;
00693
00694 direct--;
00695 }
00696
00697 row += bytes;
00698 }
00699 }
00700
00701 void FileTGA::rle_write(unsigned char *buffer,
00702 int width,
00703 int bytes,
00704 VFrame *frame,
00705 int64_t &file_offset)
00706 {
00707 int repeat = 0;
00708 int direct = 0;
00709 unsigned char *from = buffer;
00710 unsigned char output;
00711 int x;
00712
00713 for(x = 1; x < width; ++x)
00714 {
00715
00716 if(memcmp(buffer, buffer + bytes, bytes))
00717 {
00718 if(repeat)
00719 {
00720 output = 128 + repeat;
00721 write_data(&output, frame, file_offset, 1);
00722 write_data(from, frame, file_offset, bytes);
00723 from = buffer + bytes;
00724 repeat = 0;
00725 direct = 0;
00726 }
00727 else
00728 {
00729 direct++;
00730 }
00731 }
00732 else
00733
00734 {
00735 if(direct)
00736 {
00737 output = direct - 1;
00738 write_data(&output, frame, file_offset, 1);
00739 write_data(from, frame, file_offset, bytes * direct);
00740 from = buffer;
00741 direct = 0;
00742 repeat = 1;
00743 }
00744 else
00745 {
00746 repeat++;
00747 }
00748 }
00749
00750 if(repeat == 128)
00751 {
00752 output = 255;
00753 write_data(&output, frame, file_offset, 1);
00754 write_data(from, frame, file_offset, bytes);
00755 from = buffer + bytes;
00756 direct = 0;
00757 repeat = 0;
00758 }
00759 else
00760 if(direct == 128)
00761 {
00762 output = 127;
00763 write_data(&output, frame, file_offset, 1);
00764 write_data(from, frame, file_offset, direct * bytes);
00765 from = buffer + bytes;
00766 direct = 0;
00767 repeat = 0;
00768 }
00769
00770 buffer += bytes;
00771 }
00772
00773 if(repeat > 0)
00774 {
00775 output = 128 + repeat;
00776 write_data(&output, frame, file_offset, 1);
00777 write_data(from, frame, file_offset, bytes);
00778 }
00779 else
00780 {
00781 output = direct;
00782 write_data(&output, frame, file_offset, 1);
00783 write_data(from, frame, file_offset, bytes * (direct + 1));
00784 }
00785 }
00786
00787
00788 void FileTGA::bgr2rgb(unsigned char *dest,
00789 unsigned char *src,
00790 int width,
00791 int bytes,
00792 int alpha)
00793 {
00794 int x;
00795 unsigned char r, g, b;
00796
00797 if(alpha)
00798 {
00799 for(x = 0; x < width; x++)
00800 {
00801 r = src[2];
00802 g = src[1];
00803 b = src[0];
00804 *(dest++) = r;
00805 *(dest++) = g;
00806 *(dest++) = b;
00807 *(dest++) = src[3];
00808
00809 src += bytes;
00810 }
00811 }
00812 else
00813 {
00814 for(x = 0; x < width; x++)
00815 {
00816 r = src[2];
00817 g = src[1];
00818 b = src[0];
00819 *(dest++) = r;
00820 *(dest++) = g;
00821 *(dest++) = b;
00822
00823 src += bytes;
00824 }
00825 }
00826 }
00827
00828 void FileTGA::upsample(unsigned char *dest,
00829 unsigned char *src,
00830 int width,
00831 int bytes)
00832 {
00833 int x;
00834
00835 dest += (width - 1) * 3;
00836 src += (width - 1) * bytes;
00837 for(x = width - 1; x >= 0; x--)
00838 {
00839 dest[0] = ((src[1] << 1) & 0xf8);
00840 dest[0] += (dest[0] >> 5);
00841
00842 dest[1] = ((src[0] & 0xe0) >> 2) + ((src[1] & 0x03) << 6);
00843 dest[1] += (dest[1] >> 5);
00844
00845 dest[2] = ((src[0] << 3) & 0xf8);
00846 dest[2] += (dest[2] >> 5);
00847
00848 dest -= 3;
00849 src -= bytes;
00850 }
00851 }
00852
00853
00854
00855
00856
00857
00858
00859
00860
00861 TGAUnit::TGAUnit(FileTGA *file, FrameWriter *writer)
00862 : FrameWriterUnit(writer)
00863 {
00864 temp = 0;
00865 this->file = file;
00866 }
00867
00868 TGAUnit::~TGAUnit()
00869 {
00870 if(temp) delete temp;
00871 }
00872
00873
00874
00875
00876
00877
00878
00879
00880
00881
00882
00883
00884
00885 TGAConfigVideo::TGAConfigVideo(BC_WindowBase *gui, Asset *asset)
00886 : BC_Window(PROGRAM_NAME ": Video Compression",
00887 gui->get_abs_cursor_x(1),
00888 gui->get_abs_cursor_y(1),
00889 400,
00890 100)
00891 {
00892 this->gui = gui;
00893 this->asset = asset;
00894
00895 compression_items.append(new BC_ListBoxItem(FileTGA::compression_to_str(TGA_RGB_RLE)));
00896 compression_items.append(new BC_ListBoxItem(FileTGA::compression_to_str(TGA_RGBA_RLE)));
00897 compression_items.append(new BC_ListBoxItem(FileTGA::compression_to_str(TGA_RGB)));
00898 compression_items.append(new BC_ListBoxItem(FileTGA::compression_to_str(TGA_RGBA)));
00899 }
00900
00901 TGAConfigVideo::~TGAConfigVideo()
00902 {
00903 compression_items.remove_all_objects();
00904 }
00905
00906 int TGAConfigVideo::create_objects()
00907 {
00908 int x = 10, y = 10;
00909
00910 add_subwindow(new BC_Title(x, y, _("Compression:")));
00911 TGACompression *textbox = new TGACompression(this,
00912 x + 110,
00913 y,
00914 asset,
00915 &compression_items);
00916 textbox->create_objects();
00917 add_subwindow(new BC_OKButton(this));
00918 return 0;
00919 }
00920
00921 int TGAConfigVideo::close_event()
00922 {
00923 set_done(0);
00924 return 1;
00925 }
00926
00927
00928 TGACompression::TGACompression(TGAConfigVideo *gui,
00929 int x,
00930 int y,
00931 Asset *asset,
00932 ArrayList<BC_ListBoxItem*> *compression_items)
00933 : BC_PopupTextBox(gui,
00934 compression_items,
00935 FileTGA::compression_to_str(gui->asset->vcodec),
00936 x,
00937 y,
00938 200,
00939 200)
00940 {
00941 this->asset = asset;
00942 }
00943 int TGACompression::handle_event()
00944 {
00945 strcpy(asset->vcodec, FileTGA::str_to_compression(get_text()));
00946 return 1;
00947 }