--- gdal-1.9.2/configure.in.orig 2013-01-06 15:03:02.347950440 +0100 +++ gdal-1.9.2/configure.in 2013-01-06 15:06:03.784613325 +0100 @@ -1644,20 +1644,20 @@ elif test "$with_openjpeg" = "yes" -o "$with_openjpeg" = "" ; then - AC_CHECK_LIB(openjpeg,opj_decode_tile_data,HAVE_OPENJPEG=yes,HAVE_OPENJPEG=no,) - AC_CHECK_HEADERS(openjpeg.h) + AC_CHECK_LIB(openjp2,opj_decode_tile_data,HAVE_OPENJPEG=yes,HAVE_OPENJPEG=no,) + AC_CHECK_HEADERS(openjpeg-2.0/openjpeg.h) - if test "$ac_cv_header_openjpeg_h" = "no"; then + if test "$ac_cv_header_openjpeg_2_0_openjpeg_h" = "no"; then HAVE_OPENJPEG=no fi if test "$HAVE_OPENJPEG" = "yes" ; then - LIBS="-lopenjpeg $LIBS" + LIBS="-lopenjp2 $LIBS" fi else HAVE_OPENJPEG=yes - LIBS="-L$with_openjpeg -L$with_openjpeg/lib -lopenjpeg $LIBS" + LIBS="-L$with_openjpeg -L$with_openjpeg/lib -lopenjp2 $LIBS" if test -r $with_openjpeg/include/openjpeg-2.0/openjpeg.h ; then EXTRA_INCLUDES="-I$with_openjpeg/include/openjpeg-2.0 $EXTRA_INCLUDES" elif test -r $with_openjpeg/include/openjpeg.h ; then @@ -1668,7 +1668,7 @@ AC_MSG_ERROR([openjpeg.h not found in $with_openjpeg/include or $with_openjpeg/include/openjpeg-2.0]) fi - AC_CHECK_LIB(openjpeg,opj_decode_tile_data,HAVE_OPENJPEG=yes,HAVE_OPENJPEG=no,) + AC_CHECK_LIB(openjp2,opj_decode_tile_data,HAVE_OPENJPEG=yes,HAVE_OPENJPEG=no,) if test "$HAVE_OPENJPEG" = "yes" ; then AC_MSG_NOTICE([using OpenJPEG library from $with_openjpeg.]) --- gdal-1.9.2/frmts/openjpeg/openjpegdataset.cpp.orig 2012-10-09 02:58:27.000000000 +0200 +++ gdal-1.9.2/frmts/openjpeg/openjpegdataset.cpp 2013-01-07 20:31:31.410092737 +0100 @@ -37,7 +37,7 @@ /* and when calling openjpeg API from the driver, we have to replace bool by int also */ #define bool int #define GDAL_OPENJPEG_BOOL int -#include +#include #undef bool /* undef now, so that later includes are happy */ #include "gdal_pam.h" @@ -77,7 +77,7 @@ /* JP2OpenJPEGDataset_Read() */ /************************************************************************/ -static OPJ_UINT32 JP2OpenJPEGDataset_Read(void* pBuffer, OPJ_UINT32 nBytes, +static OPJ_SIZE_T JP2OpenJPEGDataset_Read(void* pBuffer, OPJ_SIZE_T nBytes, void *pUserData) { int nRet = VSIFReadL(pBuffer, 1, nBytes, (VSILFILE*)pUserData); @@ -93,7 +93,7 @@ /* JP2OpenJPEGDataset_Write() */ /************************************************************************/ -static OPJ_UINT32 JP2OpenJPEGDataset_Write(void* pBuffer, OPJ_UINT32 nBytes, +static OPJ_SIZE_T JP2OpenJPEGDataset_Write(void* pBuffer, OPJ_SIZE_T nBytes, void *pUserData) { int nRet = VSIFWriteL(pBuffer, 1, nBytes, (VSILFILE*)pUserData); @@ -107,7 +107,7 @@ /* JP2OpenJPEGDataset_Seek() */ /************************************************************************/ -static GDAL_OPENJPEG_BOOL JP2OpenJPEGDataset_Seek(OPJ_SIZE_T nBytes, void * pUserData) +static GDAL_OPENJPEG_BOOL JP2OpenJPEGDataset_Seek(OPJ_OFF_T nBytes, void * pUserData) { #ifdef DEBUG CPLDebug("OPENJPEG", "JP2OpenJPEGDataset_Seek(%d)", nBytes); @@ -119,7 +119,7 @@ /* JP2OpenJPEGDataset_Skip() */ /************************************************************************/ -static OPJ_SIZE_T JP2OpenJPEGDataset_Skip(OPJ_SIZE_T nBytes, void * pUserData) +static OPJ_OFF_T JP2OpenJPEGDataset_Skip(OPJ_OFF_T nBytes, void * pUserData) { vsi_l_offset nOffset = VSIFTellL((VSILFILE*)pUserData); nOffset += nBytes; @@ -332,10 +332,7 @@ opj_stream_set_user_data(pStream, poGDS->fp); opj_image_t * psImage = NULL; - OPJ_INT32 nX0,nY0; - OPJ_UINT32 nTileW,nTileH,nTilesX,nTilesY; - if(!opj_read_header(pCodec, &psImage, &nX0, &nY0, &nTileW, &nTileH, - &nTilesX, &nTilesY, pStream)) + if(!opj_read_header(pStream, pCodec, &psImage)) { CPLError(CE_Failure, CPLE_AppDefined, "opj_read_header() failed"); opj_destroy_codec(pCodec); @@ -343,7 +340,7 @@ return CE_Failure; } - if (!opj_set_decode_area(pCodec, + if (!opj_set_decode_area(pCodec, psImage, nBlockXOff * nBlockXSize, nBlockYOff * nBlockYSize, nBlockXOff * nBlockXSize + nWidthToRead, @@ -378,9 +375,9 @@ do { - if (!opj_read_tile_header(pCodec, &nTileIndex, &nRequiredSize, + if (!opj_read_tile_header(pCodec, pStream, &nTileIndex, &nRequiredSize, &nTileX0, &nTileY0, &nTileX1, &nTileY1, - &nCompCount, &bDataToUncompress, pStream)) + &nCompCount, &bDataToUncompress)) { CPLError(CE_Failure, CPLE_AppDefined, "opj_read_tile_header() failed"); CPLFree(pTempBuffer); @@ -494,7 +491,7 @@ { JP2OpenJPEGDataset *poGDS = (JP2OpenJPEGDataset *) poDS; - if (poGDS->eColorSpace == CLRSPC_GRAY) + if (poGDS->eColorSpace == OPJ_CLRSPC_GRAY) return GCI_GrayIndex; else if (poGDS->nBands == 3 || poGDS->nBands == 4) { @@ -541,8 +538,8 @@ adfGeoTransform[4] = 0.0; adfGeoTransform[5] = 1.0; bLoadingOtherBands = FALSE; - eCodecFormat = CODEC_UNKNOWN; - eColorSpace = CLRSPC_UNKNOWN; + eCodecFormat = OPJ_CODEC_UNKNOWN; + eColorSpace = OPJ_CLRSPC_UNKNOWN; bIs420 = FALSE; pFullBuffer = NULL; } @@ -676,9 +673,9 @@ static const unsigned char jpc_header[] = {0xff,0x4f}; if (memcmp( poOpenInfo->pabyHeader, jpc_header, sizeof(jpc_header) ) == 0) - eCodecFormat = CODEC_J2K; + eCodecFormat = OPJ_CODEC_J2K; else - eCodecFormat = CODEC_JP2; + eCodecFormat = OPJ_CODEC_JP2; opj_codec_t* pCodec = opj_create_decompress(eCodecFormat); @@ -703,10 +700,8 @@ opj_stream_set_user_data(pStream, fp); opj_image_t * psImage = NULL; - OPJ_INT32 nX0,nY0; - OPJ_UINT32 nTileW,nTileH,nTilesX,nTilesY; - if(!opj_read_header(pCodec, &psImage, &nX0, &nY0, &nTileW, &nTileH, - &nTilesX, &nTilesY, pStream)) + OPJ_UINT32 nTileW,nTileH; + if(!opj_read_header(pStream, pCodec, &psImage)) { CPLError(CE_Failure, CPLE_AppDefined, "opj_read_header() failed"); opj_destroy_codec(pCodec); @@ -725,10 +720,21 @@ return NULL; } + opj_codestream_info_v2_t *csinfo = opj_get_cstr_info(pCodec); + if (csinfo == NULL) + { + opj_destroy_codec(pCodec); + opj_stream_destroy(pStream); + opj_image_destroy(psImage); + VSIFCloseL(fp); + return NULL; + } + nTileW = csinfo->tdx; + nTileH = csinfo->tdy; + opj_destroy_cstr_info(&csinfo); + #ifdef DEBUG int i; - CPLDebug("OPENJPEG", "nX0 = %d", nX0); - CPLDebug("OPENJPEG", "nY0 = %d", nY0); CPLDebug("OPENJPEG", "nTileW = %d", nTileW); CPLDebug("OPENJPEG", "nTileH = %d", nTileH); CPLDebug("OPENJPEG", "psImage->x0 = %d", psImage->x0); @@ -780,7 +786,7 @@ eDataType = GDT_UInt16; } - int bIs420 = (psImage->color_space != CLRSPC_SRGB && + int bIs420 = (psImage->color_space != OPJ_CLRSPC_SRGB && eDataType == GDT_Byte && psImage->numcomps == 3 && psImage->comps[1].w == psImage->comps[0].w / 2 && @@ -932,14 +938,14 @@ /* -------------------------------------------------------------------- */ /* Analyze creation options. */ /* -------------------------------------------------------------------- */ - OPJ_CODEC_FORMAT eCodecFormat = CODEC_J2K; + OPJ_CODEC_FORMAT eCodecFormat = OPJ_CODEC_J2K; const char* pszCodec = CSLFetchNameValueDef(papszOptions, "CODEC", NULL); if (pszCodec) { if (EQUAL(pszCodec, "JP2")) - eCodecFormat = CODEC_JP2; + eCodecFormat = OPJ_CODEC_JP2; else if (EQUAL(pszCodec, "J2K")) - eCodecFormat = CODEC_J2K; + eCodecFormat = OPJ_CODEC_J2K; else { CPLError(CE_Warning, CPLE_NotSupported, @@ -952,7 +958,7 @@ if (strlen(pszFilename) > 4 && EQUAL(pszFilename + strlen(pszFilename) - 4, ".JP2")) { - eCodecFormat = CODEC_JP2; + eCodecFormat = OPJ_CODEC_JP2; } } @@ -971,19 +977,19 @@ if (nYSize < nBlockYSize) nBlockYSize = nYSize; - OPJ_PROG_ORDER eProgOrder = LRCP; + OPJ_PROG_ORDER eProgOrder = OPJ_LRCP; const char* pszPROGORDER = CSLFetchNameValueDef(papszOptions, "PROGRESSION", "LRCP"); if (EQUAL(pszPROGORDER, "LRCP")) - eProgOrder = LRCP; + eProgOrder = OPJ_LRCP; else if (EQUAL(pszPROGORDER, "RLCP")) - eProgOrder = RLCP; + eProgOrder = OPJ_RLCP; else if (EQUAL(pszPROGORDER, "RPCL")) - eProgOrder = RPCL; + eProgOrder = OPJ_RPCL; else if (EQUAL(pszPROGORDER, "PCRL")) - eProgOrder = PCRL; + eProgOrder = OPJ_PCRL; else if (EQUAL(pszPROGORDER, "CPRL")) - eProgOrder = CPRL; + eProgOrder = OPJ_CPRL; else { CPLError(CE_Warning, CPLE_NotSupported, @@ -1097,7 +1103,7 @@ opj_set_warning_handler(pCodec, JP2OpenJPEGDataset_WarningCallback,NULL); opj_set_error_handler(pCodec, JP2OpenJPEGDataset_ErrorCallback,NULL); - OPJ_COLOR_SPACE eColorSpace = (bResample) ? CLRSPC_SYCC : (nBands == 3) ? CLRSPC_SRGB : CLRSPC_GRAY; + OPJ_COLOR_SPACE eColorSpace = (bResample) ? OPJ_CLRSPC_SYCC : (nBands == 3) ? OPJ_CLRSPC_SRGB : OPJ_CLRSPC_GRAY; opj_image_t* psImage = opj_image_tile_create(nBands,pasBandParams, eColorSpace); CPLFree(pasBandParams);