Changeset 13921

Show
Ignore:
Timestamp:
03/03/08 18:02:42 (4 months ago)
Author:
warmerdam
Message:

add vsil read/write support (#2255)

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • branches/1.5/gdal/frmts/jp2kak/jp2kakdataset.cpp

    r13206 r13921  
    4343 
    4444#include "subfile_source.h" 
     45#include "vsil_target.h" 
    4546 
    4647// Application level includes 
     
    11671168            try 
    11681169            { 
    1169                 poRawInput = new subfile_source( poOpenInfo->pszFilename ); 
     1170                poRawInput = new subfile_source(); 
     1171                poRawInput->open( poOpenInfo->pszFilename ); 
    11701172                poRawInput->seek( 0 ); 
    11711173 
     
    11921194    KakaduInitialize(); 
    11931195         
     1196/* -------------------------------------------------------------------- */ 
     1197/*      If we think this should be access via vsil, then open it        */ 
     1198/*      accordingly.                                                    */ 
     1199/* -------------------------------------------------------------------- */ 
     1200    if( poOpenInfo->fp == NULL 
     1201        && poRawInput == NULL 
     1202        && !bIsJPIP ) 
     1203    { 
     1204        try 
     1205        { 
     1206            poRawInput = new subfile_source; 
     1207            poRawInput->open( poOpenInfo->pszFilename ); 
     1208            poRawInput->seek( 0 ); 
     1209        } 
     1210        catch( ... ) 
     1211        { 
     1212            return NULL; 
     1213        } 
     1214    } 
     1215 
    11941216/* -------------------------------------------------------------------- */ 
    11951217/*      If the header is a JP2 header, mark this as a JP2 dataset.      */ 
     
    23532375    kdu_codestream         oCodeStream; 
    23542376 
     2377    vsil_target            oVSILTarget; 
     2378 
    23552379    if( !pfnProgress( 0.0, NULL, pProgressData ) ) 
    23562380        return NULL; 
     
    23582382    try 
    23592383    { 
     2384        oVSILTarget.open( pszFilename, "w" ); 
     2385 
    23602386        if( bIsJP2 ) 
    23612387        { 
    23622388#ifdef KAKADU4 
    2363             family.open( pszFilename ); 
     2389            family.open( &oVSILTarget ); 
    23642390 
    23652391            jp2_out.open( &family ); 
     
    23722398        else if( bIsJPX ) 
    23732399        { 
    2374             jpx_family.open( pszFilename ); 
     2400            jpx_family.open( &oVSILTarget ); 
    23752401 
    23762402            jpx_out.open( &jpx_family ); 
     
    23802406        else 
    23812407        { 
    2382             jpc_out.open( pszFilename ); 
    2383             poOutputFile = &jpc_out; 
     2408            poOutputFile = &oVSILTarget; 
    23842409        } 
    23852410 
     
    27092734        poOutputFile->close(); 
    27102735    } 
     2736 
     2737    oVSILTarget.close(); 
    27112738 
    27122739    if( !pfnProgress( 1.0, NULL, pProgressData ) ) 
  • branches/1.5/gdal/frmts/jp2kak/subfile_source.h

    r10645 r13921  
    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;