Exemplo n.º 1
0
/*--------------------------------------------------------------------------*/
static int DoExtension( gifdata* gd, int label )
{
	unsigned char buf[256];

	switch ( label )
	{
	  case 0x01:		/* Plain Text Extension */
		break;

	  case 0xff:		/* Application Extension */
		break;

	  case 0xfe:		/* Comment Extension */
		while ( GetDataBlock(gd,buf) != 0 )
			;
		return FALSE;

	  case 0xf9:		/* Graphic Control Extension */
		(void)GetDataBlock( gd, buf );
		gd->g89.disposal	= (buf[0] >> 2) & 0x7;
		gd->g89.inputFlag	= (buf[0] >> 1) & 0x1;
		gd->g89.delayTime	= LM_to_uint(buf[1],buf[2]);
		if ( (buf[0] & 0x1) != 0 )
			gd->g89.transparent = buf[3];

		while ( GetDataBlock(gd,buf) != 0 )
			;
		return FALSE;
	}

	while ( GetDataBlock(gd,buf) != 0 )
		;

	return FALSE;
}
Exemplo n.º 2
0
/*!
  \brief Get data block

  \param pszName data block name

  \return pointer to VFKDataBlock instance
  \return NULL on failure
*/
VFKDataBlock *VFKReader::GetDataBlock(const char *pszName) const
{
    for (int i = 0; i < m_nDataBlockCount; i++) {
        if (EQUAL(GetDataBlock(i)->GetName(), pszName))
            return GetDataBlock(i);
    }

    return NULL;
}
Exemplo n.º 3
0
int LWZState::Code::Get( RageFile &f, int code_size )
{
	if( (curbit + code_size) >= lastbit )
	{
		if (done)
		{
//			if( curbit >= lastbit )
//				RWSetMsg("ran off the end of my bits");
			return -1;
		}
		buf[0] = buf[last_byte - 2];
		buf[1] = buf[last_byte - 1];

		unsigned char count = (unsigned char) GetDataBlock( f, &buf[2] );
		if( count == 0 )
			done = true;

		last_byte = 2 + count;
		curbit = (curbit - lastbit) + 16;
		lastbit = (2 + count) * 8;
	}
	int ret = 0;
	int i, j;
	for (i = curbit, j = 0; j < code_size; ++i, ++j)
		ret |= ((buf[i / 8] & (1 << (i % 8))) != 0) << j;

	curbit += code_size;

	return ret;
}
Exemplo n.º 4
0
// Get a POINT value
POINT CIni::GetPoint(LPCTSTR lpSection, LPCTSTR lpKey, POINT ptDefault) const
{
	POINT pt;
	if (GetDataBlock(lpSection, lpKey, &pt, sizeof(POINT)) != sizeof(POINT))
		pt = ptDefault;
	return pt;
}
Exemplo n.º 5
0
// Get a RECT value
RECT CIni::GetRect(LPCTSTR lpSection, LPCTSTR lpKey, RECT rcDefault) const
{
	RECT rc;
	if (GetDataBlock(lpSection, lpKey, &rc, sizeof(RECT)) != sizeof(RECT))
		rc = rcDefault;
	return rc;
}
static int DoExtension( IDirectFBVideoProvider_GIF_data *data, int label )
{
     unsigned char buf[256] = { 0 };
     char *str;

     switch (label) {
          case 0x01:              /* Plain Text Extension */
               str = "Plain Text Extension";
               break;
          case 0xff:              /* Application Extension */
               str = "Application Extension";
               break;
          case 0xfe:              /* Comment Extension */
               str = "Comment Extension";
               while (GetDataBlock( data->buffer, (u8*) buf ) != 0)
                    GIFDEBUGMSG("gif comment: %s", buf);
               return false;
          case 0xf9:              /* Graphic Control Extension */
               str = "Graphic Control Extension";
               (void) GetDataBlock( data->buffer, (u8*) buf );
               data->disposal  = (buf[0] >> 2) & 0x7;
               data->inputFlag = (buf[0] >> 1) & 0x1;
               if (LM_to_uint( buf[1], buf[2] ))
                    data->delayTime = LM_to_uint( buf[1], buf[2] ) * 10000;
               if ((buf[0] & 0x1) != 0)
                    data->transparent = buf[3];
               else
                    data->transparent = -1;
               while (GetDataBlock( data->buffer, (u8*) buf ) != 0)
                    ;
               return false;
          default:
               str = (char*) buf;
               snprintf(str, 256, "UNKNOWN (0x%02x)", label);
          break;
     }

     GIFDEBUGMSG("got a '%s' extension", str );

     while (GetDataBlock( data->buffer, (u8*) buf ) != 0);

     return 0;
}
Exemplo n.º 7
0
static gint
GetCode (FILE     *fd,
         gint      code_size,
         gboolean  flag)
{
  static guchar buf[280];
  static gint   curbit, lastbit, done, last_byte;
  gint          i, j, ret, count;

  if (flag)
    {
      curbit = 0;
      lastbit = 0;
      done = FALSE;
      last_byte = 2;
      return 0;
    }

  while ((curbit + code_size) > lastbit)
    {
      if (done)
        {
          if (curbit >= lastbit)
            g_message ("Ran off the end of my bits");

          return -1;
        }

      buf[0] = buf[last_byte - 2];
      buf[1] = buf[last_byte - 1];

      count = GetDataBlock (fd, &buf[2]);
      if (count < 0)
        {
          return -1;
        }
      else if (count == 0)
        {
          done = TRUE;
        }

      last_byte = 2 + count;
      curbit = (curbit - lastbit) + 16;
      lastbit = (2 + count) * 8;
    }

  ret = 0;
  for (i = curbit, j = 0; j < code_size; ++i, ++j)
    ret |= ((buf[i / 8] & (1 << (i % 8))) != 0) << j;

  curbit += code_size;

  return ret;
}
Exemplo n.º 8
0
static int
DoExtension(SDL_RWops *src, int label)
{
    static unsigned char buf[256];
    char *str;

    switch (label) {
    case 0x01:          /* Plain Text Extension */
    str = "Plain Text Extension";
    break;
    case 0xff:          /* Application Extension */
    str = "Application Extension";
    break;
    case 0xfe:          /* Comment Extension */
    str = "Comment Extension";
    while (GetDataBlock(src, (unsigned char *) buf) != 0)
        ;
    return FALSE;
    case 0xf9:          /* Graphic Control Extension */
    str = "Graphic Control Extension";
    (void) GetDataBlock(src, (unsigned char *) buf);
    Gif89.disposal = (buf[0] >> 2) & 0x7;
    Gif89.inputFlag = (buf[0] >> 1) & 0x1;
    Gif89.delayTime = LM_to_uint(buf[1], buf[2]);
    if ((buf[0] & 0x1) != 0)
        Gif89.transparent = buf[3];

    while (GetDataBlock(src, (unsigned char *) buf) != 0)
        ;
    return FALSE;
    default:
    str = (char *)buf;
    SDL_snprintf(str, 256, "UNKNOWN (0x%02x)", label);
    break;
    }

    while (GetDataBlock(src, (unsigned char *) buf) != 0)
    ;

    return FALSE;
}
static int DoExtension (MG_RWops *area, int label, GIFSCREEN* GifScreen)
{
    static unsigned char buf[256];

    switch (label) {
    case 0x01:                        /* Plain Text Extension */
        while (GetDataBlock (area, (unsigned char *) buf) != 0);
        break;
    case 0xff:                        /* Application Extension */
        while (GetDataBlock (area, (unsigned char *) buf) != 0);
        break;
    case 0xfe:                        /* Comment Extension */
        while (GetDataBlock (area, (unsigned char *) buf) != 0);
        return 0;
    case 0xf9:                        /* Graphic Control Extension */
        GetDataBlock (area, (unsigned char *) buf);
        GifScreen->disposal = (buf[0] >> 2) & 0x7;//000 000 0 0 the middle 2 bit is disposal
        GifScreen->inputFlag = (buf[0] >> 1) & 0x1;//000 000 0 0 the secand last bit 
                            //is user input flag
        GifScreen->delayTime = LM_to_uint(buf[1], buf[2]);
        if ((buf[0] & 0x1) != 0)// 000 000 0 0 the last bit is transparent flag
            GifScreen->transparent = buf[3];
        else
            GifScreen->transparent = -1;

        while (GetDataBlock (area, (unsigned char *) buf) != 0);
        return 0;
    default:
        while (GetDataBlock (area, (unsigned char *) buf) != 0);
        break;
    }

    return 0;
}
Exemplo n.º 10
0
static int
DoExtension(GifFrame* frame, SDL_RWops *src, int label)
{
    static unsigned char buf[256];
    char *str;

    switch (label) {
	    case 0x01:			/* Plain Text Extension */
			dbgout("Plain Text Extension\n");
			break;
		case 0xff:			/* Application Extension */
			dbgout("Application Extension\n");
			break;
	    case 0xfe:			/* Comment Extension */
			dbgout("Comment Extension\n");
			while (GetDataBlock(src, (unsigned char *) buf) != 0)
			    ;
			return FALSE;
	    case 0xf9:			/* Graphic Control Extension */
			dbgout("Graphic Control Extension\n");
			(void) GetDataBlock(src, (unsigned char *) buf);
			frame->disposal = (buf[0] >> 2) & 0x7;
			frame->inputFlag = (buf[0] >> 1) & 0x1;
			frame->delayMs = LM_to_uint(buf[1], buf[2]);
			if ((buf[0] & 0x1) != 0)
			    frame->transparent = buf[3];

			while (GetDataBlock(src, (unsigned char *) buf) != 0)
			    ;
			return FALSE;
	    default:
			dbgout("Unknown Extension: %s (0x%02x)\n", (char*)buf, label);
			break;
    }

    while (GetDataBlock(src, (unsigned char *) buf) != 0)
	;

    return FALSE;
}
Exemplo n.º 11
0
static int
GetCode(byte **inbuf, int code_size, int flag, GifState *g)
{
    int            i, j, ret;
    unsigned char  count;
    unsigned char  *buf = g->buf;

    if (flag) {
        for (i = 0; i < 280; i++)
                buf[i] = 0;
        g->last_byte = 0;
        g->curbit = 0;
        g->lastbit = 0;
        g->done = FALSE;
        return 0;
    }

    if ( (g->curbit+code_size) >= g->lastbit) {
        if (g->done) {
            if (g->curbit >= g->lastbit)
                _gif_error("ran off the end of my bits", 0 );
            return -1;
        }
        if (g->last_byte) {
                buf[0] = buf[g->last_byte-2];
                buf[1] = buf[g->last_byte-1];
        }

        if ((count = GetDataBlock(inbuf, &buf[2], g)) == 0)
            g->done = TRUE;

        g->last_byte = 2 + count;
        g->curbit = (g->curbit - g->lastbit) + 16;
        g->lastbit = (2+count)*8 ;
    }

    ret = 0;
    for (i = g->curbit, j = 0; j < code_size; ++i, ++j)
        ret |= ((buf[ i / 8 ] & (1 << (i % 8))) != 0) << j;

    g->curbit += code_size;

    return ret;
}
Exemplo n.º 12
0
/*--------------------------------------------------------------------------*/
static int GetCode( gifdata* gd, int code_size, int flag )
{
	int i, j, ret;
	int count;

	if ( flag )
	{
		gd->curbit = 0;
		gd->lastbit = 0;
		gd->done = FALSE;
		return 0;
	}

	if ( (gd->curbit + code_size) >= gd->lastbit )
	{
		if ( gd->done )
		{
			if ( gd->curbit >= gd->lastbit )
			SDL_SetError( "ran off the end of my bits" );
			return -1;
		}

		gd->buf[0] = gd->buf[gd->lastbyte - 2];
		gd->buf[1] = gd->buf[gd->lastbyte - 1];

		if ( (count = GetDataBlock(gd, &gd->buf[2])) == 0 )
			gd->done = TRUE;

		gd->lastbyte = 2 + count;
		gd->curbit = (gd->curbit - gd->lastbit) + 16;
		gd->lastbit = (2 + count)*8;
	}

	ret = 0;
	for ( i = gd->curbit, j = 0; j < code_size; ++i, ++j )
		ret |= ((gd->buf[i / 8] & (1 << (i % 8))) != 0) << j;

	gd->curbit += code_size;

	return ret;
}
Exemplo n.º 13
0
static int GetCode(FILE *fd, int code_size, int flag){
	static unsigned char	buf[280];
	static int		curbit, lastbit, done, last_byte;
	int			i, j, ret;
	unsigned char		count;
	
	char *str;

	if (flag) {
		curbit = 0;
		lastbit = 0;
		done = FALSE;
		return 0;
	}

	if ( (curbit+code_size) >= lastbit) {
		if (done) {
			if (curbit >= lastbit)
			    strcpy(str,"ran off the end of my bits");
				pm_error(str);
			return -1;
		}
		buf[0] = buf[last_byte-2];
		buf[1] = buf[last_byte-1];

		if ((count = GetDataBlock(fd, &buf[2])) == 0)
			done = TRUE;

		last_byte = 2 + count;
		curbit = (curbit - lastbit) + 16;
		lastbit = (2+count)*8 ;
	}

	ret = 0;
	for (i = curbit, j = 0; j < code_size; ++i, ++j)
		ret |= ((buf[ i / 8 ] & (1 << (i % 8))) != 0) << j;

	curbit += code_size;

	return ret;
}
static int GetCode(IDirectFBVideoProvider_GIF_data *data, int code_size, int flag)
{
     int i, j, ret;
     unsigned char count;

     if (flag) {
          data->curbit = 0;
          data->lastbit = 0;
          data->done = false;
          return 0;
     }

     if ( (data->curbit+code_size) >= data->lastbit) {
          if (data->done) {
               if (data->curbit >= data->lastbit) {
                    GIFERRORMSG("ran off the end of my bits");
               }
               return -1;
          }
          data->buf[0] = data->buf[data->last_byte-2];
          data->buf[1] = data->buf[data->last_byte-1];

          if ((count = GetDataBlock( data->buffer, &data->buf[2] )) == 0) {
               data->done = true;
          }

          data->last_byte = 2 + count;
          data->curbit = (data->curbit - data->lastbit) + 16;
          data->lastbit = (2+count) * 8;
     }

     ret = 0;
     for (i = data->curbit, j = 0; j < code_size; ++i, ++j) {
          ret |= ((data->buf[ i / 8 ] & (1 << (i % 8))) != 0) << j;
     }
     data->curbit += code_size;

     return ret;
}
static int GetCode(MG_RWops *area, int code_size, int flag)
{
    static unsigned char buf[280];
    static int curbit, lastbit, done, last_byte;
    int i, j, ret;
    unsigned char count;

    if (flag) {
        curbit = 0;
        lastbit = 0;
        done = FALSE;
        return 0;
    }
    if ((curbit + code_size) >= lastbit) {
        if (done) {
            if (curbit >= lastbit)
                _MG_PRINTF ("EX_CTRL>GIF89a: bad decode\n");
            return -1;
        }
        buf[0] = buf[last_byte - 2];
        buf[1] = buf[last_byte - 1];

        if ((count = GetDataBlock(area, &buf[2])) == 0)
            done = TRUE;

        last_byte = 2 + count;
        curbit = (curbit - lastbit) + 16;
        lastbit = (2 + count) * 8;
    }
    ret = 0;
    for (i = curbit, j = 0; j < code_size; ++i, ++j)
        ret |= ((buf[i / 8] & (1 << (i % 8))) != 0) << j;

    curbit += code_size;

    return ret;
}
Exemplo n.º 16
0
/*!
  \brief Load data records (&D)

  Call VFKReader::OpenFile() before this function.

  \param poDataBlock limit to selected data block or NULL for all

  \return number of data records or -1 on error
*/
int VFKReaderSQLite::ReadDataRecords(IVFKDataBlock *poDataBlock)
{
    int         nDataRecords;
    int         iDataBlock;
    const char *pszName;
    CPLString   osSQL;

    IVFKDataBlock *poDataBlockCurrent;

    sqlite3_stmt *hStmt;

    pszName = NULL;

    if (poDataBlock) { /* read records only for selected data block */
        /* table name */
        pszName = poDataBlock->GetName();

        /* check for existing records (re-use already inserted data) */
        osSQL.Printf("SELECT num_records FROM %s WHERE "
                     "table_name = '%s'",
                     VFK_DB_TABLE, pszName);
        hStmt = PrepareStatement(osSQL.c_str());
        nDataRecords = -1;
        if (ExecuteSQL(hStmt) == OGRERR_NONE) {
            nDataRecords = sqlite3_column_int(hStmt, 0);
        }
        sqlite3_finalize(hStmt);
    }
    else {
                      /* read all data blocks */

        /* check for existing records (re-use already inserted data) */
        osSQL.Printf("SELECT COUNT(*) FROM %s WHERE num_records = -1", VFK_DB_TABLE);
        hStmt = PrepareStatement(osSQL.c_str());
        if (ExecuteSQL(hStmt) == OGRERR_NONE &&
            sqlite3_column_int(hStmt, 0) == 0)
            nDataRecords = 0;     /* -> read from DB */
        else
            nDataRecords = -1;    /* -> read from VFK file */

        sqlite3_finalize(hStmt);
    }

    if (nDataRecords > -1) {        /* read records from DB */
        /* read from  DB */
        long iFID;
        int  iRowId;
        VFKFeatureSQLite *poNewFeature = NULL;

        poDataBlockCurrent = NULL;
        for (iDataBlock = 0; iDataBlock < GetDataBlockCount(); iDataBlock++) {
            poDataBlockCurrent = GetDataBlock(iDataBlock);

            if (poDataBlock && poDataBlock != poDataBlockCurrent)
                continue;

            poDataBlockCurrent->SetFeatureCount(0); /* avoid recursive call */

            pszName = poDataBlockCurrent->GetName();
            CPLAssert(NULL != pszName);

            osSQL.Printf("SELECT %s,_rowid_ FROM %s ",
                         FID_COLUMN, pszName);
            if (EQUAL(pszName, "SBP"))
              osSQL += "WHERE PORADOVE_CISLO_BODU = 1 ";
            osSQL += "ORDER BY ";
            osSQL += FID_COLUMN;
            hStmt = PrepareStatement(osSQL.c_str());
            nDataRecords = 0;
            while (ExecuteSQL(hStmt) == OGRERR_NONE) {
                iFID = sqlite3_column_int(hStmt, 0);
                iRowId = sqlite3_column_int(hStmt, 1);
                poNewFeature = new VFKFeatureSQLite(poDataBlockCurrent, iRowId, iFID);
                poDataBlockCurrent->AddFeature(poNewFeature);
                nDataRecords++;
            }

            /* check DB consistency */
            osSQL.Printf("SELECT num_features FROM %s WHERE table_name = '%s'",
                         VFK_DB_TABLE, pszName);
            hStmt = PrepareStatement(osSQL.c_str());
            if (ExecuteSQL(hStmt) == OGRERR_NONE) {
                int nFeatDB;

                nFeatDB = sqlite3_column_int(hStmt, 0);
                if (nFeatDB > 0 && nFeatDB != poDataBlockCurrent->GetFeatureCount())
                    CPLError(CE_Failure, CPLE_AppDefined,
                             "%s: Invalid number of features " CPL_FRMT_GIB " (should be %d)",
                             pszName, poDataBlockCurrent->GetFeatureCount(), nFeatDB);
            }
            sqlite3_finalize(hStmt);
        }
    }
    else {                          /* read from VFK file and insert records into DB */
        /* begin transaction */
        ExecuteSQL("BEGIN");

        /* INSERT ... */
        nDataRecords = VFKReader::ReadDataRecords(poDataBlock);

        /* update VFK_DB_TABLE table */
        poDataBlockCurrent = NULL;
        for (iDataBlock = 0; iDataBlock < GetDataBlockCount(); iDataBlock++) {
            poDataBlockCurrent = GetDataBlock(iDataBlock);

            if (poDataBlock && poDataBlock != poDataBlockCurrent)
                continue;

            osSQL.Printf("UPDATE %s SET num_records = %d WHERE "
                         "table_name = '%s'",
                         VFK_DB_TABLE, poDataBlockCurrent->GetRecordCount(),
                         poDataBlockCurrent->GetName());

            ExecuteSQL(osSQL);
        }

        /* commit transaction */
        ExecuteSQL("COMMIT");
    }

    return nDataRecords;
}
static int LWZReadByte( IDirectFBVideoProvider_GIF_data *data, int flag, int input_code_size )
{
     int code, incode;
     int i;

     if (flag) {
          data->set_code_size = input_code_size;
          data->code_size = data->set_code_size+1;
          data->clear_code = 1 << data->set_code_size ;
          data->end_code = data->clear_code + 1;
          data->max_code_size = 2*data->clear_code;
          data->max_code = data->clear_code+2;

          GetCode(data, 0, true);

          data->fresh = true;

          for (i = 0; i < data->clear_code; ++i) {
               data->table[0][i] = 0;
               data->table[1][i] = i;
          }
          for (; i < (1<<MAX_LWZ_BITS); ++i) {
               data->table[0][i] = data->table[1][0] = 0;
          }
          data->sp = data->stack;

          return 0;
     }
     else if (data->fresh) {
          data->fresh = false;
          do {
               data->firstcode = data->oldcode = GetCode( data, data->code_size, false );
          } while (data->firstcode == data->clear_code);

          return data->firstcode;
     }

     if (data->sp > data->stack) {
          return *--data->sp;
     }

     while ((code = GetCode( data, data->code_size, false )) >= 0) {
          if (code == data->clear_code) {
               for (i = 0; i < data->clear_code; ++i) {
                    data->table[0][i] = 0;
                    data->table[1][i] = i;
               }
               for (; i < (1<<MAX_LWZ_BITS); ++i) {
                    data->table[0][i] = data->table[1][i] = 0;
               }
               data->code_size = data->set_code_size+1;
               data->max_code_size = 2*data->clear_code;
               data->max_code = data->clear_code+2;
               data->sp = data->stack;
               data->firstcode = data->oldcode = GetCode( data, data->code_size, false );

               return data->firstcode;
          }
          else if (code == data->end_code) {
               int count;
               u8 buf[260];

               if (ZeroDataBlock) {
                    return -2;
               }

               while ((count = GetDataBlock( data->buffer, buf )) > 0)
                    ;

               if (count != 0)
                    GIFERRORMSG("missing EOD in data stream (common occurence)");

               return -2;
          }

          incode = code;

          if (code >= data->max_code) {
               *data->sp++ = data->firstcode;
               code = data->oldcode;
          }

          while (code >= data->clear_code) {
               *data->sp++ = data->table[1][code];
               if (code == data->table[0][code]) {
                    GIFERRORMSG("circular table entry BIG ERROR");
               }
               code = data->table[0][code];
          }

          *data->sp++ = data->firstcode = data->table[1][code];

          if ((code = data->max_code) <(1<<MAX_LWZ_BITS)) {
               data->table[0][code] = data->oldcode;
               data->table[1][code] = data->firstcode;
               ++data->max_code;
               if ((data->max_code >= data->max_code_size)
                   && (data->max_code_size < (1<<MAX_LWZ_BITS)))
               {
                    data->max_code_size *= 2;
                    ++data->code_size;
               }
          }

          data->oldcode = incode;

          if (data->sp > data->stack) {
               return *--data->sp;
          }
     }
     return code;
}
Exemplo n.º 18
0
RageSurfaceUtils::OpenResult RageSurface_Load_GIF( const RString &sPath, RageSurface *&ret, bool bHeaderOnly, RString &error )
{
	unsigned char buf[256];
	int imageCount = 0;
	int imageNumber = 1;
	RageFile f;

	if( !f.Open( sPath ) )
	{
		error = f.GetError();
		return RageSurfaceUtils::OPEN_FATAL_ERROR;
	}
	
	if( !ReadOK(f, buf, 6) )
	{
		error = "error reading magic number";
		return RageSurfaceUtils::OPEN_FATAL_ERROR;
	}
	if( strncmp((char *) buf, "GIF", 3) != 0 )
	{
		error = "not a GIF file";
		return RageSurfaceUtils::OPEN_UNKNOWN_FILE_FORMAT;
	}

	{
		char version[4];
		strncpy(version, (char *) buf + 3, 3);
		version[3] = '\0';

		if( (strcmp(version, "87a") != 0) && (strcmp(version, "89a") != 0) )
		{
			error = "bad version number, not '87a' or '89a'";
			return RageSurfaceUtils::OPEN_FATAL_ERROR;
		}
	}

	if( !ReadOK(f, buf, 7) )
	{
		error = "failed to read screen descriptor";
		return RageSurfaceUtils::OPEN_FATAL_ERROR;
	}

	RageSurfaceColor GlobalColorMap[MAXCOLORMAPSIZE];
	unsigned int GlobalBitPixel = 0;

	GlobalBitPixel = 2 << (buf[4] & 0x07);

	if( BitSet(buf[4], LOCALCOLORMAP) )
	{
		/* Global Colormap */
		if( !ReadPalette(f, GlobalBitPixel, GlobalColorMap ) )
		{
			error = "error reading global colormap";
			return RageSurfaceUtils::OPEN_FATAL_ERROR;
		}
	}

	int transparency = -1;

	while(1)
	{
		unsigned char type;
		if( !ReadOK(f, &type, 1) )
		{
			error = "EOF / read error on image data";
			return RageSurfaceUtils::OPEN_FATAL_ERROR;
		}
		switch( type )
		{
		case ';':
		{
			/* GIF terminator */
			if( imageCount < imageNumber )
			{
				error = ssprintf( "only %d image%s found in file",
					imageCount, imageCount > 1 ? "s" : "");
				return RageSurfaceUtils::OPEN_FATAL_ERROR;
			}
		}

		case '!':
		{
			/* Extension */
			unsigned char label;
			if( !ReadOK(f, &label, 1) )
			{
				error = "EOF / read error on extention function code";
				return RageSurfaceUtils::OPEN_FATAL_ERROR;
			}

			switch( label )
			{
			case 0xf9:
				GetDataBlock( f, (unsigned char *) buf );
				if( (buf[0] & 0x1) != 0 )
					transparency  = buf[3];
			}

			while( GetDataBlock(f, (unsigned char *) buf) != 0 )
				;

			continue;
		}
		case ',':
		{
			++imageCount;

			if( !ReadOK(f, buf, 9) )
			{
				error = "couldn't read left/top/width/height";
				return RageSurfaceUtils::OPEN_FATAL_ERROR;
			}

			int bitPixel = 1 << ((buf[8] & 0x07) + 1);
			RageSurfaceColor LocalColorMap[MAXCOLORMAPSIZE];

			if( BitSet(buf[8], LOCALCOLORMAP) )
			{
				if( !ReadPalette(f, bitPixel, LocalColorMap) )
				{
					error = "error reading local colormap";
					return RageSurfaceUtils::OPEN_FATAL_ERROR;
				}
			} else {
				bitPixel = GlobalBitPixel;
				memcpy( LocalColorMap, GlobalColorMap, sizeof(LocalColorMap) );
			}

			ret = ReadImage( f, LM_to_uint(buf[4], buf[5]), LM_to_uint(buf[6], buf[7]),
					LocalColorMap, BitSet(buf[8], INTERLACE),
					imageCount != imageNumber );

			if( !ret )
				continue;

			if( transparency != -1 )
				ret->format->palette->colors[ transparency ].a = 0;

			return RageSurfaceUtils::OPEN_OK;
		}
		default: continue; /* Not a valid start character */
		}
	}

	return RageSurfaceUtils::OPEN_FATAL_ERROR;
}
Exemplo n.º 19
0
static int
LWZReadByte(byte **inbuf, int flag, int input_code_size, GifState *g)
{
    int        code, incode;
    register int    i;

    if (flag) {
        g->set_code_size = input_code_size;
        g->code_size = g->set_code_size+1;
        g->clear_code = 1 << g->set_code_size ;
        g->end_code = g->clear_code + 1;
        g->max_code_size = 2*g->clear_code;
        g->max_code = g->clear_code+2;

        GetCode(inbuf, 0, TRUE, g);
        
        g->fresh = TRUE;

        for (i = 0; i < g->clear_code; ++i) {
            g->table[0][i] = 0;
            g->table[1][i] = i;
        }
        for (; i < (1<<MAX_LWZ_BITS); ++i)
            g->table[0][i] = g->table[1][0] = 0;

        g->sp = g->stack;

        return 0;
    } else if (g->fresh) {
       g->fresh = FALSE;
        do {
            g->firstcode = g->oldcode =
                GetCode(inbuf, g->code_size, FALSE, g);
        } while (g->firstcode == g->clear_code);
        return g->firstcode;
    }

    if (g->sp > g->stack)
        return *--(g->sp);

    while ((code = GetCode(inbuf, g->code_size, FALSE, g)) >= 0) {
        if (code == g->clear_code) {
            for (i = 0; i < g->clear_code; ++i) {
                g->table[0][i] = 0;
                g->table[1][i] = i;
            }
            for (; i < (1<<MAX_LWZ_BITS); ++i)
                g->table[0][i] = g->table[1][i] = 0;
            g->code_size = g->set_code_size+1;
            g->max_code_size = 2*g->clear_code;
            g->max_code = g->clear_code+2;
            g->sp = g->stack;
            g->firstcode = g->oldcode =
                    GetCode(inbuf, g->code_size, FALSE, g);
            return g->firstcode;
        } else if (code == g->end_code) {
            int        count;
            unsigned char    buf[260];

            if (g->ZeroDataBlock)
                return -2;

            while ((count = GetDataBlock(inbuf, buf, g)) > 0)
                ;

#ifdef DEBUG
            if (count != 0)
                _gif_message("missing EOD in data stream (common occurence)");
#endif
            return -2;
        }

        incode = code;

        if (code >= g->max_code) {
            *(g->sp)++ = g->firstcode;
            code = g->oldcode;
        }

        while (code >= g->clear_code) {
            *(g->sp++) = g->table[1][code];
            if (code == g->table[0][code])
                _gif_error("circular table entry BIG ERROR", 0);
            code = g->table[0][code];
        }

        *(g->sp)++ = g->firstcode = g->table[1][code];

        if ((code = g->max_code) <(1<<MAX_LWZ_BITS)) {
            g->table[0][code] = g->oldcode;
            g->table[1][code] = g->firstcode;
            ++(g->max_code);
            if ((g->max_code >= g->max_code_size) &&
                (g->max_code_size < (1<<MAX_LWZ_BITS))) {
                g->max_code_size *= 2;
                ++(g->code_size);
            }
        }

        g->oldcode = incode;

        if (g->sp > g->stack)
            return *--(g->sp);
    }
    return code;
}
Exemplo n.º 20
0
/*--------------------------------------------------------------------------*/
static int LWZReadByte( gifdata* gd, int flag, int input_code_size )
{
	int i, code, incode;

	if ( flag )
	{
		gd->setcodesize	= input_code_size;
		gd->codesize	= gd->setcodesize + 1;
		gd->clearcode	= 1 << gd->setcodesize;
		gd->endcode		= gd->clearcode + 1;
		gd->maxcodesize	= gd->clearcode*2;
		gd->maxcode		= gd->clearcode + 2;

		GetCode( gd, 0, TRUE );

		gd->fresh = TRUE;

		for ( i = 0; i < gd->clearcode; ++i )
		{
			gd->table[0][i] = 0;
			gd->table[1][i] = i;
		}

		for ( ; i < (1 << MAX_LWZ_BITS); ++i )
			gd->table[0][i] = gd->table[1][0] = 0;

		gd->sp = gd->stack;
		return 0;
	}
	else if ( gd->fresh )
	{
		gd->fresh = FALSE;
		do
		{
			gd->firstcode = gd->oldcode = GetCode( gd, gd->codesize, FALSE );
		} while ( gd->firstcode == gd->clearcode );
		return gd->firstcode;
	}

	if ( gd->sp > gd->stack )
		return *--gd->sp;

	while ( (code = GetCode(gd,gd->codesize,FALSE)) >= 0 )
	{
		if ( code == gd->clearcode )
		{
			for ( i = 0; i < gd->clearcode; ++i )
			{
				gd->table[0][i] = 0;
				gd->table[1][i] = i;
			}

			for ( ; i < (1 << MAX_LWZ_BITS); ++i )
				gd->table[0][i] = gd->table[1][i] = 0;

			gd->codesize	= gd->setcodesize + 1;
			gd->maxcodesize	= gd->clearcode*2;
			gd->maxcode		= gd->clearcode + 2;
			gd->sp			= gd->stack;
			gd->firstcode	= gd->oldcode = GetCode( gd, gd->codesize, FALSE );
			return gd->firstcode;
		}
		else if ( code == gd->endcode )
		{
			int count;
			unsigned char buf[260];

			if ( gd->zerodatablock )
				return -2;

			while ( (count = GetDataBlock(gd,buf)) > 0 )
				;

			if ( count != 0 )
			{
				/* pm_message("missing EOD in data stream (common occurence)"); */
			}
			return -2;
		}

		incode = code;

		if ( code >= gd->maxcode )
		{
			*gd->sp++ = gd->firstcode;
			code = gd->oldcode;
		}

		while ( code >= gd->clearcode )
		{
			*gd->sp++ = gd->table[1][code];
			if ( code == gd->table[0][code] )
				SDL_SetError( "circular table entry BIG ERROR" );
			code = gd->table[0][code];
		}

		*gd->sp++ = gd->firstcode = gd->table[1][code];

		if ( (code = gd->maxcode) < (1 << MAX_LWZ_BITS) )
		{
			gd->table[0][code] = gd->oldcode;
			gd->table[1][code] = gd->firstcode;
			++gd->maxcode;
			if ( (gd->maxcode >= gd->maxcodesize) && (gd->maxcodesize < (1 << MAX_LWZ_BITS)) )
			{
				gd->maxcodesize *= 2;
				++gd->codesize;
			}
		}

		gd->oldcode = incode;

		if ( gd->sp > gd->stack )
			return *--gd->sp;
	}

	return code;
}
Exemplo n.º 21
0
static int
DoExtension(byte **inbuf, int label, GifState *g)
{
    char           *str;
    char           *buf = g->ext_buf;

    switch (label) {
    case 0x01:        /* Plain Text Extension */
        str = "Plain Text Extension";
#ifdef notdef
        if (GetDataBlock(inbuf, (unsigned char*) buf, g) == 0)
            ;

        lpos   = LM_to_uint(buf[0], buf[1]);
        tpos   = LM_to_uint(buf[2], buf[3]);
        width  = LM_to_uint(buf[4], buf[5]);
        height = LM_to_uint(buf[6], buf[7]);
        cellw  = buf[8];
        cellh  = buf[9];
        foreground = buf[10];
        background = buf[11];

        while (GetDataBlock(inbuf, (unsigned char*) buf, g) != 0) {
            PPM_ASSIGN(image[ypos][xpos],
                    cmap[CM_RED][v],
                    cmap[CM_GREEN][v],
                    cmap[CM_BLUE][v]);
            ++index;
        }

        return FALSE;
#else
        break;
#endif
    case 0xff:        /* Application Extension */
        str = "Application Extension";
        break;
    case 0xfe:        /* Comment Extension */
        str = "Comment Extension";
        while (GetDataBlock(inbuf, (unsigned char*) buf, g) != 0) {
#ifdef DEBUG
            _gif_message("gif comment: %s", buf );
#endif
        }
        return FALSE;
    case 0xf9:        /* Graphic Control Extension */
        str = "Graphic Control Extension";
        (void) GetDataBlock(inbuf, (unsigned char*) buf, g);
        g->Gif89.disposal    = (buf[0] >> 2) & 0x7;
        g->Gif89.inputFlag   = (buf[0] >> 1) & 0x1;
        g->Gif89.delayTime   = LM_to_uint(buf[1], buf[2]);
        if ((buf[0] & 0x1) != 0)
            g->Gif89.transparent = buf[3];

        while (GetDataBlock(inbuf, (unsigned char*) buf, g) != 0)
            ;
        return FALSE;
    default:
        str = buf;
        sprintf(buf, "UNKNOWN (0x%02x)", label);
        break;
    }

#ifdef DEBUG
    _gif_message("got a '%s' extension", str );
#endif

    while (GetDataBlock(inbuf, (unsigned char*) buf, g) != 0)
        ;

    return FALSE;
}
Exemplo n.º 22
0
static int
LWZReadByte(SDL_RWops *src, int flag, int input_code_size)
{
    static int fresh = FALSE;
    int code, incode;
    static int code_size, set_code_size;
    static int max_code, max_code_size;
    static int firstcode, oldcode;
    static int clear_code, end_code;
    static int table[2][(1 << MAX_LWZ_BITS)];
    static int stack[(1 << (MAX_LWZ_BITS)) * 2], *sp;
    register int i;

    /* Fixed buffer overflow found by Michael Skladnikiewicz */
    if (input_code_size > MAX_LWZ_BITS)
        return -1;

    if (flag) {
    set_code_size = input_code_size;
    code_size = set_code_size + 1;
    clear_code = 1 << set_code_size;
    end_code = clear_code + 1;
    max_code_size = 2 * clear_code;
    max_code = clear_code + 2;

    GetCode(src, 0, TRUE);

    fresh = TRUE;

    for (i = 0; i < clear_code; ++i) {
        table[0][i] = 0;
        table[1][i] = i;
    }
    table[1][0] = 0;
    for (; i < (1 << MAX_LWZ_BITS); ++i)
        table[0][i] = 0;

    sp = stack;

    return 0;
    } else if (fresh) {
    fresh = FALSE;
    do {
        firstcode = oldcode = GetCode(src, code_size, FALSE);
    } while (firstcode == clear_code);
    return firstcode;
    }
    if (sp > stack)
    return *--sp;

    while ((code = GetCode(src, code_size, FALSE)) >= 0) {
    if (code == clear_code) {
        for (i = 0; i < clear_code; ++i) {
        table[0][i] = 0;
        table[1][i] = i;
        }
        for (; i < (1 << MAX_LWZ_BITS); ++i)
        table[0][i] = table[1][i] = 0;
        code_size = set_code_size + 1;
        max_code_size = 2 * clear_code;
        max_code = clear_code + 2;
        sp = stack;
        firstcode = oldcode = GetCode(src, code_size, FALSE);
        return firstcode;
    } else if (code == end_code) {
        int count;
        unsigned char buf[260];

        if (ZeroDataBlock)
        return -2;

        while ((count = GetDataBlock(src, buf)) > 0)
        ;

        if (count != 0) {
        /*
         * pm_message("missing EOD in data stream (common occurence)");
         */
        }
        return -2;
    }
    incode = code;

    if (code >= max_code) {
        *sp++ = firstcode;
        code = oldcode;
    }
    while (code >= clear_code) {
        /* Guard against buffer overruns */
        if (code < 0 || code >= (1 << MAX_LWZ_BITS)) {
            RWSetMsg("invalid LWZ data");
            return -3;
        }
        *sp++ = table[1][code];
        if (code == table[0][code]) {
            RWSetMsg("circular table entry BIG ERROR");
            return -3;
        }
        code = table[0][code];
    }

    /* Guard against buffer overruns */
    if (code < 0 || code >= (1 << MAX_LWZ_BITS)) {
        RWSetMsg("invalid LWZ data");
        return -4;
    }
    *sp++ = firstcode = table[1][code];

    if ((code = max_code) < (1 << MAX_LWZ_BITS)) {
        table[0][code] = oldcode;
        table[1][code] = firstcode;
        ++max_code;
        if ((max_code >= max_code_size) &&
        (max_code_size < (1 << MAX_LWZ_BITS))) {
        max_code_size *= 2;
        ++code_size;
        }
    }
    oldcode = incode;

    if (sp > stack)
        return *--sp;
    }
    return code;
}
Exemplo n.º 23
0
static gint
DoExtension (FILE *fd,
             gint  label)
{
  static guchar  buf[256];
  gchar         *str;

  switch (label)
    {
    case 0x01:                  /* Plain Text Extension */
      str = "Plain Text Extension";
#ifdef notdef
      if (GetDataBlock (fd, (guchar *) buf) == 0)
        ;

      lpos       = LM_to_uint (buf[0], buf[1]);
      tpos       = LM_to_uint (buf[2], buf[3]);
      width      = LM_to_uint (buf[4], buf[5]);
      height     = LM_to_uint (buf[6], buf[7]);
      cellw      = buf[8];
      cellh      = buf[9];
      foreground = buf[10];
      background = buf[11];

      while (GetDataBlock (fd, (guchar *) buf) > 0)
        {
          PPM_ASSIGN (image[ypos][xpos],
                      cmap[CM_RED][v],
                      cmap[CM_GREEN][v],
                      cmap[CM_BLUE][v]);
          ++index;
        }

      return FALSE;
#else
      break;
#endif

    case 0xff:                  /* Application Extension */
      str = "Application Extension";
      break;
    case 0xfe:                  /* Comment Extension */
      str = "Comment Extension";
      while (GetDataBlock (fd, (guchar *) buf) > 0)
        {
          gchar *comment = (gchar *) buf;

          if (! g_utf8_validate (comment, -1, NULL))
            continue;

          if (comment_parasite)
            gimp_parasite_free (comment_parasite);

          comment_parasite = gimp_parasite_new ("gimp-comment",
                                                GIMP_PARASITE_PERSISTENT,
                                                strlen (comment) + 1, comment);
        }
      return TRUE;
      break;

    case 0xf9:                  /* Graphic Control Extension */
      str = "Graphic Control Extension";
      (void) GetDataBlock (fd, (guchar *) buf);
      Gif89.disposal  = (buf[0] >> 2) & 0x7;
      Gif89.inputFlag = (buf[0] >> 1) & 0x1;
      Gif89.delayTime = LM_to_uint (buf[1], buf[2]);
      if ((buf[0] & 0x1) != 0)
        Gif89.transparent = buf[3];
      else
        Gif89.transparent = -1;

      while (GetDataBlock (fd, (guchar *) buf) > 0);

      return FALSE;
      break;

    default:
      str = (gchar *)buf;
      sprintf ((gchar *)buf, "UNKNOWN (0x%02x)", label);
      break;
    }

#ifdef GIFDEBUG
  g_print ("GIF: got a '%s'\n", str);
#endif

  while (GetDataBlock (fd, (guchar *) buf) > 0);

  return FALSE;
}
Exemplo n.º 24
0
static gint
LZWReadByte (FILE *fd,
             gint  just_reset_LZW,
             gint  input_code_size)
{
  static gint fresh = FALSE;
  gint        code, incode;
  static gint code_size, set_code_size;
  static gint max_code, max_code_size;
  static gint firstcode, oldcode;
  static gint clear_code, end_code;
  static gint table[2][(1 << MAX_LZW_BITS)];
  static gint stack[(1 << (MAX_LZW_BITS)) * 2], *sp;
  gint        i;

  if (just_reset_LZW)
    {
      if (input_code_size > MAX_LZW_BITS)
        {
          g_message ("Value out of range for code size (corrupted file?)");
          return -1;
        }

      set_code_size = input_code_size;
      code_size     = set_code_size + 1;
      clear_code    = 1 << set_code_size;
      end_code      = clear_code + 1;
      max_code_size = 2 * clear_code;
      max_code      = clear_code + 2;

      GetCode (fd, 0, TRUE);

      fresh = TRUE;

      sp = stack;

      for (i = 0; i < clear_code; ++i)
        {
          table[0][i] = 0;
          table[1][i] = i;
        }
      for (; i < (1 << MAX_LZW_BITS); ++i)
        {
          table[0][i] = 0;
          table[1][i] = 0;
        }

      return 0;
    }
  else if (fresh)
    {
      fresh = FALSE;
      do
        {
          firstcode = oldcode = GetCode (fd, code_size, FALSE);
        }
      while (firstcode == clear_code);

      return firstcode;
    }

  if (sp > stack)
    return *--sp;

  while ((code = GetCode (fd, code_size, FALSE)) >= 0)
    {
      if (code == clear_code)
        {
          for (i = 0; i < clear_code; ++i)
            {
              table[0][i] = 0;
              table[1][i] = i;
            }
          for (; i < (1 << MAX_LZW_BITS); ++i)
            {
              table[0][i] = 0;
              table[1][i] = 0;
            }

          code_size     = set_code_size + 1;
          max_code_size = 2 * clear_code;
          max_code      = clear_code + 2;
          sp            = stack;
          firstcode     = oldcode = GetCode (fd, code_size, FALSE);

          return firstcode;
        }
      else if (code == end_code)
        {
          gint   count;
          guchar buf[260];

          if (ZeroDataBlock)
            return -2;

          while ((count = GetDataBlock (fd, buf)) > 0)
            ;

          if (count != 0)
            g_print ("GIF: missing EOD in data stream (common occurence)");

          return -2;
        }

      incode = code;

      if (code >= max_code)
        {
          *sp++ = firstcode;
          code = oldcode;
        }

      while (code >= clear_code)
        {
          *sp++ = table[1][code];
          if (code == table[0][code])
            {
              g_message ("Circular table entry.  Corrupt file.");
              gimp_quit ();
            }
          code = table[0][code];
        }

      *sp++ = firstcode = table[1][code];

      if ((code = max_code) < (1 << MAX_LZW_BITS))
        {
          table[0][code] = oldcode;
          table[1][code] = firstcode;
          ++max_code;
          if ((max_code >= max_code_size) &&
              (max_code_size < (1 << MAX_LZW_BITS)))
            {
              max_code_size *= 2;
              ++code_size;
            }
        }

      oldcode = incode;

      if (sp > stack)
        return *--sp;
    }

  return code;
}
static int LWZReadByte (MG_RWops *area, int flag, int input_code_size)
{
    int code, incode;
    register int i;
    static int fresh = FALSE;
    static int code_size, set_code_size;
    static int max_code, max_code_size;
    static int firstcode, oldcode;
    static int clear_code, end_code;
    static int table[2][(1 << MAX_LWZ_BITS)];
    static int stack[(1 << (MAX_LWZ_BITS)) * 2], *sp;

    if (flag) {
        set_code_size = input_code_size;
        code_size = set_code_size + 1;
        clear_code = 1 << set_code_size;
        end_code = clear_code + 1;
        max_code_size = 2 * clear_code;
        max_code = clear_code + 2;

        GetCode(area, 0, TRUE);

        fresh = TRUE;

        for (i = 0; i < clear_code; ++i) {
            table[0][i] = 0;
            table[1][i] = i;
        }
        for (; i < (1 << MAX_LWZ_BITS); ++i)
            table[0][i] = table[1][0] = 0;

        sp = stack;

        return 0;
    } else if (fresh) {
        fresh = FALSE;
        do {
            firstcode = oldcode = GetCode(area, code_size, FALSE);
        } while (firstcode == clear_code);
        return firstcode;
    }
    if (sp > stack)
        return *--sp;

    while ((code = GetCode(area, code_size, FALSE)) >= 0) {
        if (code == clear_code) {
            for (i = 0; i < clear_code; ++i) {
                table[0][i] = 0;
                table[1][i] = i;
            }
            for (; i < (1 << MAX_LWZ_BITS); ++i)
                table[0][i] = table[1][i] = 0;
            code_size = set_code_size + 1;
            max_code_size = 2 * clear_code;
            max_code = clear_code + 2;
            sp = stack;
            firstcode = oldcode = GetCode(area, code_size, FALSE);
            return firstcode;
        } else if (code == end_code) {
            int count;
            unsigned char buf[260];

            if (ZeroDataBlock)
                return -2;

            while ((count = GetDataBlock(area, buf)) > 0);

            if (count != 0) {
                /*
                 * fprintf (stderr,"missing EOD in data stream (common occurence)");
                 */
            }
            return -2;
        }
        incode = code;

        if (code >= max_code) {
            *sp++ = firstcode;
            code = oldcode;
        }
        while (code >= clear_code) {
            *sp++ = table[1][code];
            if (code == table[0][code]) {
                _MG_PRINTF ("EX_CTRL>GIF89a: circular table entry\n");
                return -1;
            }
            code = table[0][code];
        }

        *sp++ = firstcode = table[1][code];

        if ((code = max_code) < (1 << MAX_LWZ_BITS)) {
            table[0][code] = oldcode;
            table[1][code] = firstcode;
            ++max_code;
            if ((max_code >= max_code_size) &&
                (max_code_size < (1 << MAX_LWZ_BITS))) {
                max_code_size *= 2;
                ++code_size;
            }
        }
        oldcode = incode;

        if (sp > stack)
            return *--sp;
    }
    return code;
}
Exemplo n.º 26
0
/*!
  \brief Get data blocks (&B)

  Call LoadData() before this function.

  \return FALSE on error
  \return TRUE on success
*/
int VFKReader::LoadDataBlocks()
{ 
    char         *pszChar;
    char         *pszLine;
    char         *pszBlockName;
    int           nRow;
    
    VFKDataBlock *poNewDataBlock;

    if (m_pszWholeText == NULL)
        return FALSE;

    poNewDataBlock = NULL;
    pszBlockName = NULL;
    nRow = 0;

    /* read lines */
    pszChar = m_pszWholeText;
    pszLine = m_pszWholeText;
    while (*pszChar != '\0') {
	if (*pszChar == '\r' && *(pszChar+1) == '\n') {
	    nRow++;
	    if (*pszLine == '&' && *(pszLine+1) == 'B') {
		/* add data block */
		pszBlockName = GetDataBlockName(pszLine);
                if (pszBlockName == NULL)
                    break;

		poNewDataBlock = new VFKDataBlock(pszBlockName, this);
		CPLFree(pszBlockName);
		pszBlockName = NULL;
		poNewDataBlock->SetGeometryType();
		poNewDataBlock->SetProperties(pszLine);
		AddDataBlock(poNewDataBlock);
	    }
	    else if (*pszLine == '&' && *(pszLine+1) == 'D') {
		/* data row */
		pszBlockName = GetDataBlockName(pszLine);
                if (pszBlockName == NULL)
                    break;

		poNewDataBlock = GetDataBlock(pszBlockName);
		if (poNewDataBlock == NULL) {
		    if (!EQUAL(pszBlockName, "KATUZE")) {
			/* ignore KATUZE block */
			CPLError(CE_Warning, CPLE_AppDefined, 
				 "Data block '%s' not found.\n", pszBlockName);
		    }
		}
		else 
		    poNewDataBlock->AddFeature(pszLine);

		CPLFree(pszBlockName);
		pszBlockName = NULL;
	    }
	    else if (*pszLine == '&' && *(pszLine+1) == 'H') {
		/* header - metadata */
		AddInfo(pszLine);
	    }
	    else if (*pszLine == '&' && *(pszLine+1) == 'K') {
		/* end of file */
		break;
	    }
	    pszChar++;
	    pszLine = pszChar + 1;
	}
	pszChar++;
    }

    return TRUE;
}
Exemplo n.º 27
0
int LWZState::ReadByte( RageFile &f )
{
	if( fresh )
	{
		fresh = false;
		do {
			firstcode = oldcode = m_Code.Get( f, code_size );
		} while ( firstcode == clear_code );
		return firstcode;
	}

	if( sp > stack )
		return *--sp;

	int code;
	while( (code = m_Code.Get(f, code_size)) >= 0 )
	{
		if( code == clear_code )
		{
			memset( table, 0, sizeof(table) );
			for( int i = 0; i < clear_code; ++i )
				table[1][i] = i;
			code_size = set_code_size + 1;
			max_code_size = 2 * clear_code;
			max_code = clear_code + 2;
			sp = stack;
			firstcode = oldcode = m_Code.Get( f, code_size );
			return firstcode;
		}
		else if( code == end_code )
		{
			int count;
			unsigned char buf[260];

			if( m_Code.done )
				return -2;

			while( (count = GetDataBlock(f, buf)) > 0 )
				;

			if( count != 0 )
			{
				/*
				 * pm_message("missing EOD in data stream (common occurence)");
				 */
			}
			return -2;
		}
		int incode = code;

		if( code >= max_code )
		{
			*sp++ = firstcode;
			code = oldcode;
		}
		while( code >= clear_code )
		{
			*sp++ = table[1][code];
//			if (code == table[0][code])
//				RWSetMsg("circular table entry BIG ERROR");
			code = table[0][code];
		}

		*sp++ = firstcode = table[1][code];

		if( (code = max_code) < (1 << MAX_LWZ_BITS) )
		{
			table[0][code] = oldcode;
			table[1][code] = firstcode;
			++max_code;
			if (max_code >= max_code_size &&
				max_code_size < (1 << MAX_LWZ_BITS))
			{
				max_code_size *= 2;
				++code_size;
			}
		}
		oldcode = incode;

		if( sp > stack )
			return *--sp;
	}
	return code;
}
Exemplo n.º 28
0
static int
LWZReadByte(SDL_RWops *src, int flag, int input_code_size)
{
    static int fresh = FALSE;
    int code, incode;
    static int code_size, set_code_size;
    static int max_code, max_code_size;
    static int firstcode, oldcode;
    static int clear_code, end_code;
    static int table[2][(1 << MAX_LWZ_BITS)];
    static int stack[(1 << (MAX_LWZ_BITS)) * 2], *sp;
    register int i;

    if (flag) {
		set_code_size = input_code_size;
		code_size = set_code_size + 1;
		clear_code = 1 << set_code_size;
		end_code = clear_code + 1;
		max_code_size = 2 * clear_code;
		max_code = clear_code + 2;

		GetCode(src, 0, TRUE);

		fresh = TRUE;

		for (i = 0; i < clear_code; ++i) {
		    table[0][i] = 0;
		    table[1][i] = i;
		}
		for (; i < (1 << MAX_LWZ_BITS); ++i)
		    table[0][i] = table[1][0] = 0;

		sp = stack;

		return 0;
    } else if (fresh) {
		fresh = FALSE;
		do {
		    firstcode = oldcode = GetCode(src, code_size, FALSE);
		} while (firstcode == clear_code);
		
		return firstcode;
    }
    if (sp > stack)
		return *--sp;

    while ((code = GetCode(src, code_size, FALSE)) >= 0) {
		if (code == clear_code) {
		    for (i = 0; i < clear_code; ++i) {
			table[0][i] = 0;
			table[1][i] = i;
		    }
		    for (; i < (1 << MAX_LWZ_BITS); ++i)
			table[0][i] = table[1][i] = 0;
		    code_size = set_code_size + 1;
		    max_code_size = 2 * clear_code;
		    max_code = clear_code + 2;
		    sp = stack;
		    firstcode = oldcode = GetCode(src, code_size, FALSE);
		    return firstcode;
		} else if (code == end_code) {
		    int count;
		    unsigned char buf[260];

		    if (ZeroDataBlock)
				return -2;

		    while ((count = GetDataBlock(src, buf)) > 0)
			;

		    if (count != 0) {
			/*
			 * pm_message("missing EOD in data stream (common occurence)");
			 */
				dbgout("missing EOD in data stream (common occurence)\n");
		    }
		    return -2;
		}
		incode = code;

		if (code >= max_code) {
		    *sp++ = firstcode;
		    code = oldcode;
		}
		while (code >= clear_code) {
		    *sp++ = table[1][code];
		    if (code == table[0][code])
				IMG_SetError("circular table entry BIG ERROR");
		    code = table[0][code];
		}

		*sp++ = firstcode = table[1][code];

		if ((code = max_code) < (1 << MAX_LWZ_BITS)) {
		    table[0][code] = oldcode;
		    table[1][code] = firstcode;
		    ++max_code;
		    if ((max_code >= max_code_size) &&
				(max_code_size < (1 << MAX_LWZ_BITS))) {
				max_code_size *= 2;
				++code_size;
		    }
		}
		oldcode = incode;

		if (sp > stack)
		    return *--sp;
    }
    return code;
}
Exemplo n.º 29
0
static int DoExtension(FILE *fd, int label){
	static char	buf[256];
	char		*str;

	switch (label) {
	case 0x01:		/* Plain Text Extension */
		strcpy(str,"Plain Text Extension");
#ifdef notdef
		if (GetDataBlock(fd, (unsigned char*) buf) == 0)
			;

		lpos	= LM_to_uint(buf[0], buf[1]);
		tpos	= LM_to_uint(buf[2], buf[3]);
		width	= LM_to_uint(buf[4], buf[5]);
		height = LM_to_uint(buf[6], buf[7]);
		cellw	= buf[8];
		cellh	= buf[9];
		foreground = buf[10];
		background = buf[11];

		while (GetDataBlock(fd, (unsigned char*) buf) != 0) {
			PPM_ASSIGN(image[ypos][xpos],
					cmap[CM_RED][v],
					cmap[CM_GREEN][v],
					cmap[CM_BLUE][v]);
			++index;
		}

		return FALSE;
#else
		break;
#endif
	case 0xff:		/* Application Extension */
		strcpy(str,"Application Extension");
		GetDataBlock(fd, (unsigned char*) buf);
#if 0
		if (showComment){
			fprintf(stderr, "Application Extension: %c%c%c%c%c%c%c%c ",
				buf[0],buf[1],buf[2],buf[3],buf[4],buf[5],buf[6],buf[7]);
			fprintf(stderr, " Authentication Code=)%02x %02x %02x\n",
				buf[8], buf[9], buf[10]);
		}
#endif
		break;
	case 0xfe:		/* Comment Extension */
		strcpy(str,"Comment Extension");
		while (GetDataBlock(fd, (unsigned char*) buf) != 0) {
#if 0
	    	if (showComment)
				fprintf(stderr,"gif comment: %s\n", buf );
#endif
		}
		return FALSE;
	case 0xf9:		/* Graphic Control Extension */
		strcpy(str,"Graphic Control Extension");
		(void) GetDataBlock(fd, (unsigned char*) buf);
		Gif89.disposal    = (buf[0] >> 2) & 0x7;
		Gif89.inputFlag   = (buf[0] >> 1) & 0x1;
		Gif89.delayTime   = LM_to_uint(buf[1],buf[2]);
		if ((buf[0] & 0x1) != 0)
			Gif89.transparent = buf[3];

		while (GetDataBlock(fd, (unsigned char*) buf) != 0)
			;
		return FALSE;
	default:
		str = buf;
		sprintf(buf, "UNKNOWN (0x%02x)", label);
		break;
	}

	fprintf(stderr,"got a '%s' extension\n", str );

	while (GetDataBlock(fd, (unsigned char*) buf) != 0)
		;

	return FALSE;
}