"Fossies" - the Fresh Open Source Software Archive

Member "mapgenerator-1.1.2/src/read_gif.cpp" (26 Oct 2003, 2564 Bytes) of package /linux/www/old/mapgenerator-1.1.2.tar.gz:


As a special service "Fossies" has tried to format the requested source page into HTML format using (guessed) C and C++ source code syntax highlighting (style: standard) with prefixed line numbers and code folding option. Alternatively you can here view or download the uninterpreted source code file. For more information about "read_gif.cpp" see the Fossies "Dox" file reference documentation.

    1 /***************************************************************************
    2                           read_gif.cpp  -  description
    3                              -------------------
    4     begin                : Thu Aug 23 2001
    5     copyright            : (C) 2001 by Gabriel Huber
    6     email                : Gabriel-Huber@gmx.de
    7  ***************************************************************************/
    8 
    9 /***************************************************************************
   10  *                                                                         *
   11  *   This program is free software; you can redistribute it and/or modify  *
   12  *   it under the terms of the GNU General Public License as published by  *
   13  *   the Free Software Foundation; either version 2 of the License, or     *
   14  *   (at your option) any later version.                                   *
   15  *                                                                         *
   16  ***************************************************************************/
   17 
   18 #include "read_gif.h"
   19 #include <FL/fl_message.H>
   20 
   21 extern "C" {
   22 #include <gif_lib.h>
   23 }
   24 
   25 Frame_Buffer* read_gif(const char name[]){
   26     static int InterlacedOffset[] = { 0, 4, 2, 1 };
   27     static int InterlacedJumps[] = { 8, 8, 4, 2 };
   28     static ColorMapObject *ColorMap;
   29     static GifColorType *ColorMapEntry;
   30     struct GifFileType* giftype;
   31     GifRecordType record;   
   32     giftype=DGifOpenFileName(name); 
   33     int row,col;
   34     Frame_Buffer *fb=new Frame_Buffer(giftype->SWidth, giftype->SHeight,3);
   35     unsigned char *bt  = (unsigned char*)fb->buffer();
   36     unsigned char *btemp=new unsigned char[giftype->SWidth*giftype->SHeight];
   37     while(true){
   38         DGifGetRecordType(giftype, &record);
   39         if(TERMINATE_RECORD_TYPE==record) break;
   40         if(IMAGE_DESC_RECORD_TYPE!=record) continue;
   41         DGifGetImageDesc(giftype);
   42         row=giftype->Image.Top;
   43         col=giftype->Image.Left;
   44         if(giftype->Image.Interlace){
   45             for(int i=0;i<4;i++){
   46                 for (int j=row+InterlacedOffset[i];j<row+giftype->SHeight;j+=InterlacedJumps[i])
   47                     DGifGetLine(giftype,btemp+(col+j*giftype->SWidth),giftype->SWidth);
   48             }
   49         }
   50         else{
   51             for(int i=0;i<giftype->SHeight;i++){
   52                 DGifGetLine(giftype,btemp+(col+row*giftype->SWidth),giftype->SWidth);
   53                 row++;
   54             }
   55         }
   56     }
   57     ColorMap = (giftype->Image.ColorMap ? giftype->Image.ColorMap : giftype->SColorMap);
   58     for(int i=0;i<giftype->SWidth*giftype->SHeight;i++,bt+=3){
   59         *(bt)=giftype->SColorMap->Colors[btemp[i]].Red;
   60         *(bt+1)=giftype->SColorMap->Colors[btemp[i]].Green;
   61         *(bt+2)=giftype->SColorMap->Colors[btemp[i]].Blue;
   62     }
   63     DGifCloseFile(giftype);
   64     return fb;
   65 }