Main Page | Class Hierarchy | Alphabetical List | Class List | Directories | File List | Class Members | File Members

filegif.C

Go to the documentation of this file.
00001 #include "assets.h"
00002 #include "file.h"
00003 #include "filetiff.h"
00004 #include "interlacemodes.h"
00005 #include "vframe.h"
00006 
00007 
00008 FileGIF::FileGIF(Asset *asset)
00009  : FileBase(asset)
00010 {
00011         reset_parameters();
00012         asset->video_data = 1;
00013         asset->format = FILE_GIF;
00014 }
00015 
00016 FileGIF::~FileGIF()
00017 {
00018         close_file();
00019 }
00020 
00021 int FileGIF::reset_parameters_derived()
00022 {
00023         data = 0;
00024 }
00025 
00026 int FileGIF::open_file(int rd, int wr)
00027 {
00028         this->rd = rd;
00029         this->wr = wr;
00030 
00031 // skip header for write
00032         if(wr)
00033         {
00034         }
00035         else
00036         if(rd)
00037         {
00038                 return read_header();
00039         }
00040         return 0;
00041 }
00042 
00043 int64_t FileGIF::get_video_length()
00044 {
00045         return -1;    // infinity
00046 // should be determined by whether the GIF is animated
00047 }
00048 
00049 int64_t FileGIF::get_memory_usage()
00050 {
00051 // give buffer length plus padding
00052         if(data)
00053                 return asset->width * asset->height * sizeof(VPixel);
00054         else
00055                 return 256;
00056 }
00057 
00058 int FileGIF::close_file_derived()
00059 {
00060         if(data) delete data;
00061         reset_parameters();
00062 }
00063 
00064 int FileGIF::read_header()
00065 {
00066         GIF *stream;
00067 
00068         if(!(stream = GIFOpen(asset->path, "r")))
00069         {
00070                 perror("FileGIF::read_header");
00071                 return 1;
00072         }
00073         
00074         GIFGetField(stream, GIFTAG_IMAGEWIDTH, &(asset->width));
00075         GIFGetField(stream, GIFTAG_IMAGELENGTH, &(asset->height));
00076         asset->interlacemode = BC_ILACE_MODE_NOTINTERLACED;
00077         asset->layers = 1;
00078 
00079         GIFClose(stream);
00080         return 0;
00081 }
00082 
00083 
00084 VFrame* FileGIF::read_frame(int use_alpha, int use_float)
00085 {
00086         read_raw();
00087         return data;
00088 }
00089 
00090 int FileGIF::read_raw()
00091 {
00092         if(!data)
00093         {
00094 // read the raw data
00095                 GIF *stream;
00096                 unsigned char *raw_data;
00097                 int i;
00098 
00099                 if(!(stream = GIFOpen(asset->path, "r")))
00100                 {
00101                         perror("FileGIF::read_raw");
00102                         return 1;
00103                 }
00104 
00105                 raw_data = new unsigned char[asset->width * asset->height * 4];
00106                 GIFReadRGBAImage(stream, asset->width, asset->height, (uint32*)raw_data, 0);
00107 
00108                 GIFClose(stream);
00109 
00110 // convert to a Bcast 2000 Frame
00111                 data = new VFrame(asset->width, asset->height);
00112 
00113                 for(i = 0; i < asset->height; i++)
00114                 {
00115                         import_row(data->rows[asset->height - i - 1], &raw_data[i * asset->width * 4]);
00116                 }
00117 
00118 // delete temporary buffers
00119                 delete raw_data;
00120         }
00121         return 0;
00122 }
00123 
00124 int FileGIF::import_row(VPixel *output, unsigned char *row_pointer)
00125 {
00126         for(int i = 0, j = 0; j < asset->width; j++)
00127         {
00128 #if (VMAX == 65535)
00129                 output[j].red =  ((VWORD)row_pointer[i++]) << 8;
00130                 output[j].green =  ((VWORD)row_pointer[i++]) << 8;
00131                 output[j].blue = ((VWORD)row_pointer[i++]) << 8;
00132                 output[j].alpha = ((VWORD)row_pointer[i++]) << 8;
00133 #else
00134                 output[j].red =  (VWORD)row_pointer[i++];
00135                 output[j].green =  (VWORD)row_pointer[i++];
00136                 output[j].blue = (VWORD)row_pointer[i++];
00137                 output[j].alpha = (VWORD)row_pointer[i++];
00138 #endif
00139         }
00140 }

Generated on Sun Jan 8 13:38:54 2006 for Cinelerra-svn by  doxygen 1.4.4