GDAL club,

I am using a test image, called world.jp2, you could download from 
http://www.microimages.com/gallery/jp2/, specifically, 
http://www.microimages.com/gallery/jp2/1.jp2.  I have made my own application 
to provide block segments viewing capabilities in both .jp2 and .tif format.

I converted this file, world.jp2 to world.tif, to test my code.  Objective is 
get a block of image data given xoff,yoff,xsize,ysize.  If the parameters go 
outside bounds, I manually readjust the xsize and ysize to what was given to 
what GDAL can actually retrieve using the xoff,yoff as my origin for new image.

This code works for .tif images.  I have tested it thoroughly and have not had 
any problems.  For .jp2 files, Whenever I acquire the bottom region of the 
file, the remaining 10 lines or so of the image, GDALRasterIO() returns bad 
values but it still does not give me an error.  Can someone duplicate this test 
case.  I believe it should be a new ticket, but I need confirmation first.

Detailed example test case that provides bad output: 
JPEG2000 Driver Using: KAKADU
File name: World.jp2
Size: Width = 800 Heigth = 400
pixelOffset = 0
lineOffset  = 100
usrImageWidth = 512
UsrImageHeight = 300

This will grab the bottom left corner of the image.  It correctly gives me the 
image data all the way up to approx. line 285 or 295...

Here is my code to parse through world.jp2 which is a RGB color format:

BYTE* __fastcall GeoJp2k::getImageBlockLocation(int pixelOffset, int lineOffset,
                                                                int 
&usrImageWidth, int &UsrImageHeight)
      int imgLoc = 0;
      int requestedBlockHeight = 0;
        if(GDALGetOverviewCount(mainImageBand) > 0)
        {

                curError = CE_None; //Reset b4 reading in data...
                
curGeoData->setImageColorFormat(GDALGetRasterColorInterpretation(mainImageBand));
            GDALColorInterp curColorFormat = curGeoData->getColorFormat();
                if(curColorFormat == GCI_GrayIndex)
                {
                        //GrayScale format image...
                        //removed for this purpose...   
                }
                else if(curColorFormat == GCI_RedBand)
                {
                                //GCI_RedBand refers to RGB Format image...

                         //Image data in Bands
                         // GDALGetRasterBand() retrieves...
                         //Band 1:  RED
                         //Band 2:  GREEN
                         //Band 3:  BLUE
                        GDALRasterBandH RedBand, GreenBand, BlueBand;
                        CPLErr RedError   = CE_None;
                        CPLErr GreenError = CE_None;
                        CPLErr BlueError  = CE_None;

                        BYTE *RedStrip   = NULL; //
                        BYTE *GreenStrip = NULL; //
                        BYTE *BlueStrip  = NULL;

                RedStrip   = (BYTE *) malloc(usrImageWidth); //
                GreenStrip = (BYTE *) malloc(usrImageWidth); //
                BlueStrip  = (BYTE *) malloc(usrImageWidth); //
    

                        //Retrieve the RGB colors....
                        RedBand   = GDALGetRasterBand(fileDataset, 1);
                        GreenBand = GDALGetRasterBand(fileDataset, 2);
                        BlueBand  = GDALGetRasterBand(fileDataset, 3);

                        for(int curRow =0; curRow < UsrImageHeight && curError 
== CE_None; curRow++)
                        {

 
                     RedError   =                               GDALRasterIO( 
RedBand, GF_Read,
                                                          pixelOffset,
                                                          lineOffset + curRow,
                                                          usrImageWidth,
                                                          1,
                                                          RedStrip,
                                                          usrImageWidth,
                                                          1,
                                                          GDT_Byte,
                                                          0,
                                                          0 );

                     GreenError =                               GDALRasterIO( 
GreenBand, GF_Read,
                                                          pixelOffset ,
                                                          lineOffset + curRow,
                                                          usrImageWidth,
                                                          1,
                                                          GreenStrip,
                                                          usrImageWidth,
                                                          1,
                                                          GDT_Byte,
                                                          0,
                                                          0 );

                     BlueError  =                               GDALRasterIO( 
BlueBand, GF_Read,
                                                          pixelOffset,
                                                          lineOffset + curRow,
                                                          usrImageWidth,
                                                          1,
                                                          BlueStrip,
                                                          usrImageWidth,
                                                          1,
                                                          GDT_Byte,
                                                          0,
                                                          0 );

                     if(RedError != CE_None || GreenError != CE_None || 
BlueError != CE_None)
                     {
                         //Error occured, return nothing to show error reading 
in bits...
                         return NULL;
                     }

                     //save out to output image buffer...
                    //Grab pixel per pixel
                    for(int col =0; col < usrImageWidth; col++)
                    {
                        imageBits[imgLoc++] = BlueStrip[col];
                        imageBits[imgLoc++] = GreenStrip[col];
                        imageBits[imgLoc++] = RedStrip[col];
                    }


                        }//End of outer For

                        //Free memory...
                        free(RedStrip);
                        free(BlueStrip);
                        free(GreenStrip);
            RedStrip = NULL;
            BlueStrip = NULL;
            GreenStrip = NULL;            
                        GDALClose(RedBand);
                        GDALClose(BlueBand);
                        GDALClose(GreenBand);
                } 


Attachment: smime.p7s
Description: S/MIME cryptographic signature

_______________________________________________
gdal-dev mailing list
gdal-dev@lists.osgeo.org
http://lists.osgeo.org/mailman/listinfo/gdal-dev

Reply via email to