[Gdal-dev] compression CCITTFAX4 ?

Ivan Mjartan ivan.mjartan at geovap.cz
Tue Jan 31 07:55:57 EST 2006


Hi, list

At first thank you Frank for your help.

I used

c:\Projects\GDAL\library\tiff-3.8.0\tools>tiffcp -s -r 200 -c g3:2d:fill 
c:\temp\problemraster.tif c:\temp\rastr.tif

and than I am able use gdal_translate.exe

I am programming viewer for our geodata with raster support, I am using gdal 
library.

Whole algorithm is working in 5 steps.

1) Get intersection of raster and window of application
2) Compute coordinate of intersection
3) Call createSubImage function
4) Load result image (bitmap) from disk and display it in window.
5) Delete tempimage

createSubImage function looks like follow, this function is fragment of 
gedal_translate.exe and returns small subwindow of input raster.

But problem is when I get on input this large raster.

It is possible use something else then createcopy? I am not sure but 
mapserver is working properly on this raster.

Is my function createSubImage correct ?


thanks a lot Ivan Mjartan


void createSubImage(char *pszSrcFilename,char *pszDesFilename,int x, int 
y,int xsize,int ysize,int outXsize,int outYsize){
    GDALDatasetH hDataset,hOutDS;
    GDALDriverH hDriver;
    VRTDataset *poVDS;
    int nBandCount = 0;
    int i;

    GDALAllRegister();
    hDriver = GetGDALDriverManager()->GetDriverByName("BMP");
    hDataset = GDALOpenShared( pszSrcFilename, GA_ReadOnly );
    poVDS = new VRTDataset(outXsize, outYsize);

    nBandCount = GDALGetRasterCount( hDataset );

    for( i = 0; i < nBandCount; i++ ){
       VRTSourcedRasterBand   *poVRTBand;
       GDALRasterBand  *poSrcBand;
       GDALDataType    eBandType;

      poSrcBand = ((GDALDataset *)hDataset)->GetRasterBand(i+1);
      eBandType = poSrcBand->GetRasterDataType();
      poVDS->AddBand( eBandType, NULL );
      poVRTBand = (VRTSourcedRasterBand *) poVDS->GetRasterBand( i+1 );

      poVRTBand->AddSimpleSource( poSrcBand,x, y, xsize, ysize,0, 0, 
outXsize, outYsize );
      poVRTBand->CopyCommonInfoFrom( poSrcBand );
   }


     hOutDS = GDALCreateCopy( hDriver,pszDesFilename, (GDALDatasetH) poVDS,
                             FALSE, NULL,
                             NULL, NULL );

     if( hOutDS != NULL )
    {
        GDALClose( hOutDS );
    }

    GDALClose( (GDALDatasetH) poVDS );

    GDALClose( hDataset );
    GDALDestroyDriverManager();

}


----- Original Message ----- 
From: "Frank Warmerdam" <warmerdam at pobox.com>
To: "Ivan Mjartan" <ivan.mjartan at geovap.cz>
Cc: <gdal-dev at lists.maptools.org>
Sent: Monday, January 30, 2006 5:54 PM
Subject: Re: [Gdal-dev] compression CCITTFAX4 ?


On 1/30/06, Ivan Mjartan <ivan.mjartan at geovap.cz> wrote:
>
> Hi list,
>
> I have little problem with one raster
>
> This raster is info by gdalinfo.exe
>
> Driver: GTiff/GeoTIFF
> Size is 29320, 23915
> Coordinate System is `'
> Origin = (-526217.400234,-1169079.558552)
> Pixel Size = (0.20988818,-0.20988818)
> Metadata:
>   TIFFTAG_XRESOLUTION=1000
>   TIFFTAG_YRESOLUTION=1000
>   TIFFTAG_RESOLUTIONUNIT=2 (pixels/inch)
> Image Structure Metadata:
>   COMPRESSION=CCITTFAX4
> Corner Coordinates:
> Upper Left  ( -526217.400,-1169079.559)
> Lower Left  ( -526217.400,-1174099.034)
> Upper Right ( -520063.479,-1169079.559)
> Lower Right ( -520063.479,-1174099.034)
> Center      ( -523140.439,-1171589.296)
> Band 1 Block=29320x23915 Type=Byte, ColorInterp=Palette
>   Color Table (RGB with 2 entries)
>     0: 255,255,255,255
>     1: 0,0,0,255
>
> But problem is when I tried
>
> gdal_translate.exe -of BMP bohuslavice_pk.tif bohuslavice_pk.bmp
>
> I got following error
>
> ERROR 1: Internalize failed
> ERROR 1: GetBlockRef failed at X block offset 0, Y block offset 0

Ivan,

I believe the problem is that to GDAL the TIFF files seems to be
one big tile.  So when it reads it, it allocates a 29320x23915
memory array which fails, resulting in the error message you see.

I would suggest using tiffcp to convert the file into a stripped
file with a reasonable strip size.

eg.

tiffcp -s -r 200 your.tif stripped.tif

Then it should be possible to operate on it with gdal_translate.

But the other thing I must warn you is that GDAL treats 1bit TIFF
files as 8bit so the resulting image may be much larger than you
would expect (circa 500MB).

Best regards,
--
---------------------------------------+--------------------------------------
I set the clouds in motion - turn up   | Frank Warmerdam, 
warmerdam at pobox.com
light and sound - activate the windows | http://pobox.com/~warmerdam
and watch the world go round - Rush    | Geospatial Programmer for Rent







More information about the Gdal-dev mailing list