Changeset 13920

Show
Ignore:
Timestamp:
03/03/08 17:45:40 (4 months ago)
Author:
warmerdam
Message:

add vsil support for reading and writing (#2255).
Fix bug in Identify() with jpc files (were ignored).

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • sandbox/warmerdam/1.4-esri/gdal/frmts/jp2kak/jp2kakdataset.cpp

    r11731 r13920  
    4646#endif 
    4747#include "subfile_source.h" 
     48#include "vsil_target.h" 
    4849 
    4950// Application level includes 
     
    10941095/*      Check header                                                    */ 
    10951096/* -------------------------------------------------------------------- */ 
    1096     if( poOpenInfo->fp == NULL
     1097    if( poOpenInfo->nHeaderBytes < (int) sizeof(jp2_header)
    10971098    { 
    10981099        const char  *pszExtension = NULL; 
     
    11231124 
    11241125        pszExtension = CPLGetExtension( poOpenInfo->pszFilename ); 
    1125         if( !EQUAL(pszExtension,"jpc") && !EQUAL(pszExtension,"j2k")  
    1126             && !EQUAL(pszExtension,"jp2") && !EQUAL(pszExtension,"jpx")  
    1127             && !EQUAL(pszExtension,"j2c") ) 
     1126        if( EQUAL(pszExtension,"jpc")  
     1127            || EQUAL(pszExtension,"j2k")  
     1128            || EQUAL(pszExtension,"jp2")  
     1129            || EQUAL(pszExtension,"jpx")  
     1130            || EQUAL(pszExtension,"j2c") ) 
    11281131            return TRUE; 
    11291132    } 
     
    11521155/* -------------------------------------------------------------------- */ 
    11531156    pszExtension = CPLGetExtension( poOpenInfo->pszFilename ); 
    1154     if( poOpenInfo->fp == NULL
     1157    if( poOpenInfo->nHeaderBytes < 16
    11551158    { 
    11561159        if( (EQUALN(poOpenInfo->pszFilename,"http://",7) 
     
    11681171            try 
    11691172            { 
    1170                 poRawInput = new subfile_source( poOpenInfo->pszFilename ); 
     1173                poRawInput = new subfile_source(); 
     1174                poRawInput->open( poOpenInfo->pszFilename ); 
    11711175                poRawInput->seek( 0 ); 
    11721176 
     
    11881192    else 
    11891193    { 
    1190         if( poOpenInfo->nHeaderBytes < 16 ) 
    1191             return NULL; 
    1192  
    11931194        pabyHeader = poOpenInfo->pabyHeader; 
    11941195    } 
     
    11961197    KakaduInitialize(); 
    11971198         
     1199/* -------------------------------------------------------------------- */ 
     1200/*      If we think this should be access via vsil, then open it        */ 
     1201/*      accordingly.                                                    */ 
     1202/* -------------------------------------------------------------------- */ 
     1203    if( poOpenInfo->fp == NULL 
     1204        && poRawInput == NULL 
     1205        && !bIsJPIP ) 
     1206    { 
     1207        try 
     1208        { 
     1209            poRawInput = new subfile_source; 
     1210            poRawInput->open( poOpenInfo->pszFilename ); 
     1211            poRawInput->seek( 0 ); 
     1212        } 
     1213        catch( ... ) 
     1214        { 
     1215            return NULL; 
     1216        } 
     1217    } 
     1218 
    11981219/* -------------------------------------------------------------------- */ 
    11991220/*      If the header is a JP2 header, mark this as a JP2 dataset.      */ 
     
    14071428/*      Look for supporting coordinate system information.              */ 
    14081429/* -------------------------------------------------------------------- */ 
    1409         if( poOpenInfo->fp != NULL
     1430        if( poOpenInfo->nHeaderBytes > 0
    14101431        { 
    14111432            GDALJP2Metadata oJP2Geo; 
     
    23582379    kdu_codestream         oCodeStream; 
    23592380 
     2381    vsil_target            oVSILTarget; 
     2382 
    23602383    if( !pfnProgress( 0.0, NULL, pProgressData ) ) 
    23612384        return NULL; 
     
    23632386    try 
    23642387    { 
     2388        oVSILTarget.open( pszFilename, "w" ); 
     2389 
    23652390        if( bIsJP2 ) 
    23662391        { 
    23672392#ifdef KAKADU4 
    2368             family.open( pszFilename ); 
     2393            family.open( &oVSILTarget ); 
    23692394 
    23702395            jp2_out.open( &family ); 
     
    23772402        else if( bIsJPX ) 
    23782403        { 
    2379             jpx_family.open( pszFilename ); 
     2404            jpx_family.open( &oVSILTarget ); 
    23802405 
    23812406            jpx_out.open( &jpx_family ); 
     
    23852410        else 
    23862411        { 
    2387             jpc_out.open( pszFilename ); 
    2388             poOutputFile = &jpc_out; 
     2412            poOutputFile = &oVSILTarget; 
    23892413        } 
    23902414 
     
    27132737        poOutputFile->close(); 
    27142738    } 
     2739 
     2740    oVSILTarget.close(); 
    27152741 
    27162742    if( !pfnProgress( 1.0, NULL, pProgressData ) ) 
  • sandbox/warmerdam/1.4-esri/gdal/frmts/jp2kak/subfile_source.h

    r10646 r13920  
    3939  public:  
    4040    subfile_source() { file = NULL; } 
    41     subfile_source(const char *fname, bool allow_seeks=true) 
    42       { file = NULL; open(fname,allow_seeks); } 
    43  
    44  
    4541    ~subfile_source() { close(); } 
    4642 
     
    5046    bool operator!() { return (file == NULL); } 
    5147 
    52     void open(const char *fname, bool allow_seeks=true
     48    void open(const char *fname
    5349      { 
    5450          const char *real_filename; 
    5551          close(); 
    5652 
    57           if( sscanf( fname, "J2K_SUBFILE:%d,%d",  
    58                       &subfile_offset, &subfile_size ) != 2 ) 
     53          if( EQUALN( fname, "J2K_SUBFILE:",12) ) 
    5954          { 
    60               kdu_error e; 
    61  
    62               e << "Corrupt subfile definition:" << fname; 
    63               return; 
     55              if( sscanf( fname, "J2K_SUBFILE:%d,%d",  
     56                          &subfile_offset, &subfile_size ) != 2 ) 
     57              { 
     58                  kdu_error e; 
     59                   
     60                  e << "Corrupt subfile definition:" << fname; 
     61                  return; 
     62              } 
     63              real_filename = strstr(fname,","); 
     64              if( real_filename != NULL ) 
     65                  real_filename = strstr(real_filename+1,","); 
     66              if( real_filename != NULL ) 
     67                  real_filename++; 
     68              else 
     69              { 
     70                  kdu_error e; 
     71               
     72                  e << "Could not find filename in subfile definition." << fname; 
     73                  return; 
     74              } 
     75          } 
     76          else 
     77          { 
     78              real_filename = fname; 
     79              subfile_offset = 0; 
     80              subfile_size = 0;  
    6481          } 
    6582 
    66           real_filename = strstr(fname,","); 
    67           if( real_filename != NULL ) 
    68               real_filename = strstr(real_filename+1,","); 
    69           if( real_filename != NULL ) 
    70               real_filename++; 
    71           else 
    72           { 
    73               kdu_error e; 
    74  
    75               e << "Could not find filename in subfile definition." << fname; 
    76               return; 
    77           } 
    78  
    79           file = VSIFOpenL( real_filename, "rb" ); 
     83          file = VSIFOpenL( real_filename, "r"); 
    8084          if( file == NULL ) 
    8185          { 
     
    8690          } 
    8791 
    88           capabilities = KDU_SOURCE_CAP_SEQUENTIAL; 
    89           if (allow_seeks) 
    90               capabilities |= KDU_SOURCE_CAP_SEEKABLE; 
     92          capabilities = KDU_SOURCE_CAP_SEQUENTIAL | KDU_SOURCE_CAP_SEEKABLE; 
    9193 
    9294          seek_origin = subfile_offset; 
     
    122124      {  
    123125        if (file == NULL) return -1; 
    124         kdu_long result = VSIFTell( file ); 
     126        kdu_long result = VSIFTellL( file ); 
    125127        if (!absolute)  
    126128            result -= seek_origin;