Changeset 13920
- Timestamp:
- 03/03/08 17:45:40 (4 months ago)
- Files:
Legend:
- Unmodified
- Added
- Removed
- Modified
- Copied
- Moved
sandbox/warmerdam/1.4-esri/gdal/frmts/jp2kak/jp2kakdataset.cpp
r11731 r13920 46 46 #endif 47 47 #include "subfile_source.h" 48 #include "vsil_target.h" 48 49 49 50 // Application level includes … … 1094 1095 /* Check header */ 1095 1096 /* -------------------------------------------------------------------- */ 1096 if( poOpenInfo-> fp == NULL)1097 if( poOpenInfo->nHeaderBytes < (int) sizeof(jp2_header) ) 1097 1098 { 1098 1099 const char *pszExtension = NULL; … … 1123 1124 1124 1125 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") ) 1128 1131 return TRUE; 1129 1132 } … … 1152 1155 /* -------------------------------------------------------------------- */ 1153 1156 pszExtension = CPLGetExtension( poOpenInfo->pszFilename ); 1154 if( poOpenInfo-> fp == NULL)1157 if( poOpenInfo->nHeaderBytes < 16 ) 1155 1158 { 1156 1159 if( (EQUALN(poOpenInfo->pszFilename,"http://",7) … … 1168 1171 try 1169 1172 { 1170 poRawInput = new subfile_source( poOpenInfo->pszFilename ); 1173 poRawInput = new subfile_source(); 1174 poRawInput->open( poOpenInfo->pszFilename ); 1171 1175 poRawInput->seek( 0 ); 1172 1176 … … 1188 1192 else 1189 1193 { 1190 if( poOpenInfo->nHeaderBytes < 16 )1191 return NULL;1192 1193 1194 pabyHeader = poOpenInfo->pabyHeader; 1194 1195 } … … 1196 1197 KakaduInitialize(); 1197 1198 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 1198 1219 /* -------------------------------------------------------------------- */ 1199 1220 /* If the header is a JP2 header, mark this as a JP2 dataset. */ … … 1407 1428 /* Look for supporting coordinate system information. */ 1408 1429 /* -------------------------------------------------------------------- */ 1409 if( poOpenInfo-> fp != NULL)1430 if( poOpenInfo->nHeaderBytes > 0 ) 1410 1431 { 1411 1432 GDALJP2Metadata oJP2Geo; … … 2358 2379 kdu_codestream oCodeStream; 2359 2380 2381 vsil_target oVSILTarget; 2382 2360 2383 if( !pfnProgress( 0.0, NULL, pProgressData ) ) 2361 2384 return NULL; … … 2363 2386 try 2364 2387 { 2388 oVSILTarget.open( pszFilename, "w" ); 2389 2365 2390 if( bIsJP2 ) 2366 2391 { 2367 2392 #ifdef KAKADU4 2368 family.open( pszFilename);2393 family.open( &oVSILTarget ); 2369 2394 2370 2395 jp2_out.open( &family ); … … 2377 2402 else if( bIsJPX ) 2378 2403 { 2379 jpx_family.open( pszFilename);2404 jpx_family.open( &oVSILTarget ); 2380 2405 2381 2406 jpx_out.open( &jpx_family ); … … 2385 2410 else 2386 2411 { 2387 jpc_out.open( pszFilename ); 2388 poOutputFile = &jpc_out; 2412 poOutputFile = &oVSILTarget; 2389 2413 } 2390 2414 … … 2713 2737 poOutputFile->close(); 2714 2738 } 2739 2740 oVSILTarget.close(); 2715 2741 2716 2742 if( !pfnProgress( 1.0, NULL, pProgressData ) ) sandbox/warmerdam/1.4-esri/gdal/frmts/jp2kak/subfile_source.h
r10646 r13920 39 39 public: 40 40 subfile_source() { file = NULL; } 41 subfile_source(const char *fname, bool allow_seeks=true)42 { file = NULL; open(fname,allow_seeks); }43 44 45 41 ~subfile_source() { close(); } 46 42 … … 50 46 bool operator!() { return (file == NULL); } 51 47 52 void open(const char *fname , bool allow_seeks=true)48 void open(const char *fname ) 53 49 { 54 50 const char *real_filename; 55 51 close(); 56 52 57 if( sscanf( fname, "J2K_SUBFILE:%d,%d", 58 &subfile_offset, &subfile_size ) != 2 ) 53 if( EQUALN( fname, "J2K_SUBFILE:",12) ) 59 54 { 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; 64 81 } 65 82 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"); 80 84 if( file == NULL ) 81 85 { … … 86 90 } 87 91 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; 91 93 92 94 seek_origin = subfile_offset; … … 122 124 { 123 125 if (file == NULL) return -1; 124 kdu_long result = VSIFTell ( file );126 kdu_long result = VSIFTellL( file ); 125 127 if (!absolute) 126 128 result -= seek_origin;
