Hello Even,

thank you for the reply. I attached a minimal test that compares as you
suggested to buffers.
When I use CPLSetConfigOption("ECW_CLEVER", "NO"); two buffers are equal.
When
CPLSetConfigOption("ECW_CLEVER", "YES"); two buffers are different. A 4
bands image can be donwloaded from this link :
http://www.astrium-geo.com/en/23-sample-imagery

I do not know if it is an issue in GDAL, however there is something strange
with the usage of sCachedMultiBandIO from ECWDataset.

Cheers,
Victor

PS : sorry for duplicate
// std
#include <iostream>
#include <string>

// GDAL
#include <gdal_priv.h>
#include "cpl_conv.h"

// ------------- GLOBAL VARIABLES ----------------------------------

std::string inputFilename="C:/Images/Pleiades/ORTHO/ORTHO_UTM_BUNDLE/IMG_PHR1A_MS_002/IMG_PHR1A_MS_201202250025599_ORT_IPU_20120504_1772-003_R1C1.JP2";


struct Data
{
    Data() : buffer(0), width(0), height(0), nbBands(0) {}
    double * buffer;
    int width;
    int height;
    int nbBands;
};

bool compareBuffers(const Data & data1, const Data & data2)
{
    int n = std::memcmp( data1.buffer, data2.buffer, data1.width * data1.height * data1.nbBands * 8 );
    if (n > 0 || n < 0)
    {
        return false;
    }
    return true;
}

bool getBufferFromImage(GDALDataset * dataset, Data & data, int * offset, int desiredNbOfSamples)
{
    int nbBands = dataset->GetRasterCount();
    int pixelSizeInBytes = nbBands * 8;
    int rowSizeInBytes = pixelSizeInBytes * data.width;
    // extract data:
    unsigned char * bufferPtr = reinterpret_cast<unsigned char*>(data.buffer);

    for (int band=1;band<=nbBands;band++)
    {
        GDALRasterBand* rasterBand = dataset->GetRasterBand(band)->GetRasterSampleOverview(desiredNbOfSamples);
        std::cout << "overview size : " << rasterBand->GetXSize() << ", " << rasterBand->GetYSize() << std::endl;
        // Extract from RasterIO
        CPLErr err = rasterBand->RasterIO( GF_Read, offset[0], offset[1], data.width, data.height,
           bufferPtr + 8*(band - 1), data.width, data.height, GDT_Float64, pixelSizeInBytes, rowSizeInBytes );
        if (err != CE_None)
        {
            std::cerr << "GDAL failed to read data" << std::endl;
            return false;
        }
    }
    return true;
}

void createBuffer(Data & data, int nbBands)
{
    data.width = 500;
    data.height = 400;
    data.nbBands = nbBands;
    data.buffer = new double[data.width * data.height * data.nbBands]();
}

// ------------- MAIN() ----------------------------------

int main(int argc, char** argv)
{

    CPLSetConfigOption( "GDAL_DATA", "C:/GDAL/data" );
    CPLSetConfigOption("ECW_CLEVER", "NO");

    // setup data buffer:
    Data data1, data2;

    GDALAllRegister();
    // exract data using GDAL:
    GDALDataset * dataset = static_cast<GDALDataset *>(GDALOpen(inputFilename.c_str(), GA_ReadOnly));
    if (!dataset)
    {
        std::cerr << "Failed to open the file" << std::endl;
        GDALDestroyDriverManager();
        return 1;
    }

    int width = dataset->GetRasterXSize();
    int height = dataset->GetRasterYSize();
    int nbBands = dataset->GetRasterCount();
    std::cout << "Nb, W, H : " << nbBands << ", " << width << ", " << height << std::endl;

    createBuffer(data1, nbBands);
    createBuffer(data2, nbBands);

    int offset[] = {0, 0};
    int desiredNbOfSamples = width * height / 16.0;

    if (!getBufferFromImage(dataset, data1, offset, desiredNbOfSamples))
    {
        return 1;
    }

    if (!getBufferFromImage(dataset, data2, offset, desiredNbOfSamples))
    {
        return 1;
    }

    if (compareBuffers(data1,data2))
    {
        std::cout << "RESULT : buffers are equal = OK" << std::endl;
    }
    else
    {
        std::cout << "RESULT : buffers are NOT equal = NOK" << std::endl;
    }

    GDALClose(dataset);
    GDALDestroyDriverManager();

    return 0;
}




_______________________________________________
gdal-dev mailing list
[email protected]
http://lists.osgeo.org/mailman/listinfo/gdal-dev

Reply via email to