Changeset 13918
- Timestamp:
- 03/03/08 16:05:51 (4 months ago)
- Files:
-
- trunk/gdal/frmts/jp2kak/jp2kakdataset.cpp (modified) (28 diffs)
- trunk/gdal/frmts/jp2kak/subfile_source.h (modified) (4 diffs)
- trunk/gdal/frmts/jp2kak/vsil_target.h (added)
Legend:
- Unmodified
- Added
- Removed
- Modified
- Copied
- Moved
trunk/gdal/frmts/jp2kak/jp2kakdataset.cpp
r13883 r13918 43 43 44 44 #include "subfile_source.h" 45 #include "vsil_target.h" 45 46 46 47 // Application level includes … … 53 54 #include "roi_sources.h" 54 55 55 #ifdef J2_INPUT_MAX_BUFFER_BYTES 56 # define KAKADU4 57 58 # ifdef JP2_COMPRESSION_TYPE_NONE 59 # define KAKADU41 60 # endif 61 #endif 62 63 #if defined(KAKADU4) && defined(WIN32) && !defined(KAKADU41) 56 #if defined(WIN32) 64 57 # define USE_JPIP 65 58 #endif … … 70 63 # define kdu_client void 71 64 #endif 65 66 // #define KAKADU_JPX 1 72 67 73 68 CPL_CVSID("$Id$"); … … 109 104 kdu_compressed_source *poInput; 110 105 kdu_compressed_source *poRawInput; 111 #ifdef KAKADU4112 106 jp2_family_src *family; 113 #endif114 107 kdu_client *jpip_client; 115 108 kdu_dims dims; … … 325 318 { 326 319 int nRedIndex=-1, nGreenIndex=-1, nBlueIndex=-1, nLutIndex; 327 #ifdef KAKADU41328 320 int nCSI; 329 #endif330 321 331 322 if( oJP2Channels.get_num_colours() == 3 ) 332 323 { 333 #ifdef KAKADU41334 324 oJP2Channels.get_colour_mapping( 0, nRedIndex, nLutIndex, nCSI ); 335 325 oJP2Channels.get_colour_mapping( 1, nGreenIndex, nLutIndex, nCSI ); 336 326 oJP2Channels.get_colour_mapping( 2, nBlueIndex, nLutIndex, nCSI ); 337 #else338 oJP2Channels.get_colour_mapping( 0, nRedIndex, nLutIndex );339 oJP2Channels.get_colour_mapping( 1, nGreenIndex, nLutIndex );340 oJP2Channels.get_colour_mapping( 2, nBlueIndex, nLutIndex );341 #endif342 327 } 343 328 else 344 329 { 345 #ifdef KAKADU41346 330 oJP2Channels.get_colour_mapping( 0, nRedIndex, nLutIndex, nCSI ); 347 #else348 oJP2Channels.get_colour_mapping( 0, nRedIndex, nLutIndex );349 #endif350 331 if( nBand == 1 ) 351 332 eInterp = GCI_GrayIndex; … … 377 358 color_idx < oJP2Channels.get_num_colours(); color_idx++ ) 378 359 { 379 #ifdef KAKADU41380 360 if( oJP2Channels.get_opacity_mapping( color_idx, opacity_idx, 381 361 lut_idx, nCSI ) ) … … 390 370 eInterp = GCI_AlphaBand; 391 371 } 392 #else393 if( oJP2Channels.get_opacity_mapping( color_idx, opacity_idx,394 lut_idx ) )395 {396 if( opacity_idx == nBand - 1 )397 eInterp = GCI_AlphaBand;398 }399 if( oJP2Channels.get_premult_mapping( color_idx, opacity_idx,400 lut_idx ) )401 {402 if( opacity_idx == nBand - 1 )403 eInterp = GCI_AlphaBand;404 }405 #endif406 372 } 407 373 } … … 941 907 nGCPCount = 0; 942 908 pasGCPList = NULL; 943 #ifdef KAKADU4944 909 family = NULL; 945 #endif946 910 947 911 bGeoTransformValid = FALSE; … … 976 940 poInput->close(); 977 941 delete poInput; 978 #ifdef KAKADU4979 942 if( family ) 980 943 { … … 982 945 delete family; 983 946 } 984 #endif985 947 if( poRawInput != NULL ) 986 948 delete poRawInput; … … 1150 1112 /* Handle setting up datasource for JPIP. */ 1151 1113 /* -------------------------------------------------------------------- */ 1114 KakaduInitialize(); 1115 1152 1116 pszExtension = CPLGetExtension( poOpenInfo->pszFilename ); 1153 1117 if( poOpenInfo->nHeaderBytes < 16 ) … … 1164 1128 static GByte abySubfileHeader[16]; 1165 1129 1166 KakaduInitialize();1167 1130 try 1168 1131 { 1169 poRawInput = new subfile_source( poOpenInfo->pszFilename ); 1132 poRawInput = new subfile_source; 1133 poRawInput->open( poOpenInfo->pszFilename ); 1170 1134 poRawInput->seek( 0 ); 1171 1135 … … 1190 1154 } 1191 1155 1192 KakaduInitialize(); 1193 1156 /* -------------------------------------------------------------------- */ 1157 /* If we think this should be access via vsil, then open it */ 1158 /* accordingly. */ 1159 /* -------------------------------------------------------------------- */ 1160 if( poOpenInfo->fp == NULL 1161 && poRawInput == NULL 1162 && !bIsJPIP ) 1163 { 1164 try 1165 { 1166 poRawInput = new subfile_source; 1167 poRawInput->open( poOpenInfo->pszFilename ); 1168 poRawInput->seek( 0 ); 1169 } 1170 catch( ... ) 1171 { 1172 return NULL; 1173 } 1174 } 1175 1194 1176 /* -------------------------------------------------------------------- */ 1195 1177 /* If the header is a JP2 header, mark this as a JP2 dataset. */ … … 1206 1188 jp2_channels oJP2Channels; 1207 1189 1208 #ifdef KAKADU41209 1190 jp2_family_src *family = NULL; 1210 #endif1211 1191 1212 1192 try … … 1277 1257 jp2_source *jp2_src; 1278 1258 1279 #ifdef KAKADU41280 1259 family = new jp2_family_src; 1281 1260 if( poRawInput != NULL ) … … 1286 1265 jp2_src->open( family ); 1287 1266 jp2_src->read_header(); 1288 #else 1289 jp2_src = new jp2_source; 1290 jp2_src->open( poOpenInfo->pszFilename, true ); 1291 #endif 1267 1292 1268 poInput = jp2_src; 1293 1269 … … 1337 1313 poDS->jpip_client = jpip_client; 1338 1314 1339 #ifdef KAKADU41340 1315 poDS->family = family; 1341 #endif 1316 1342 1317 /* -------------------------------------------------------------------- */ 1343 1318 /* Get overall image size. */ … … 1961 1936 /* Write to a box on the JP2 file. */ 1962 1937 /* -------------------------------------------------------------------- */ 1963 #ifdef KAKADU41964 1938 jp2_out->open_next( nBoxType ); 1965 1939 … … 1968 1942 1969 1943 jp2_out->close(); 1970 #else1971 jp2_output_box &uuid_box = jp2_out->open_box( nBoxType );1972 1973 uuid_box.write( (kdu_byte *) poBox->GetWritableData(),1974 poBox->GetDataLength() );1975 1976 uuid_box.close();1977 #endif1978 1944 1979 1945 delete poBox; … … 2343 2309 /* Open output file, and setup codestream. */ 2344 2310 /* -------------------------------------------------------------------- */ 2345 #ifdef KAKADU42346 2311 jp2_family_tgt family; 2347 #endif 2348 #ifdef KAKADU42 2312 #ifdef KAKADU_JPX 2349 2313 jpx_family_tgt jpx_family; 2350 2314 jpx_target jpx_out; … … 2356 2320 kdu_compressed_target *poOutputFile = NULL; 2357 2321 jp2_target jp2_out; 2358 kdu_simple_file_target jpc_out;2359 2322 int bIsJP2 = !EQUAL(CPLGetExtension(pszFilename),"jpc") 2360 2323 && !bIsJPX; 2361 2324 kdu_codestream oCodeStream; 2362 2325 2326 vsil_target oVSILTarget; 2327 2363 2328 if( !pfnProgress( 0.0, NULL, pProgressData ) ) 2364 2329 return NULL; … … 2366 2331 try 2367 2332 { 2333 oVSILTarget.open( pszFilename, "w" ); 2334 2368 2335 if( bIsJP2 ) 2369 2336 { 2370 #ifdef KAKADU4 2371 family.open( pszFilename);2337 //family.open( pszFilename ); 2338 family.open( &oVSILTarget ); 2372 2339 2373 2340 jp2_out.open( &family ); 2374 #else2375 jp2_out.open( pszFilename );2376 #endif2377 2341 poOutputFile = &jp2_out; 2378 2342 } 2379 #ifdef KAKADU 422343 #ifdef KAKADU_JPX 2380 2344 else if( bIsJPX ) 2381 2345 { … … 2387 2351 #endif 2388 2352 else 2389 { 2390 jpc_out.open( pszFilename ); 2391 poOutputFile = &jpc_out; 2392 } 2353 poOutputFile = &oVSILTarget; 2393 2354 2394 2355 oCodeStream.create(&oSizeParams, poOutputFile ); … … 2561 2522 } 2562 2523 2563 #ifdef KAKADU42564 2524 if( bIsJP2 ) 2565 2525 { 2566 2526 jp2_out.write_header(); 2567 2527 } 2568 #endif2569 2528 2570 2529 /* -------------------------------------------------------------------- */ … … 2630 2589 /* Open codestream box. */ 2631 2590 /* -------------------------------------------------------------------- */ 2632 #ifdef KAKADU42633 2591 if( bIsJP2 ) 2634 2592 jp2_out.open_codestream(); 2635 #endif2636 2593 2637 2594 /* -------------------------------------------------------------------- */ … … 2709 2666 { 2710 2667 jp2_out.close(); 2711 #ifdef KAKADU42712 2668 family.close(); 2713 #endif2714 2669 } 2715 2670 else … … 2717 2672 poOutputFile->close(); 2718 2673 } 2674 2675 oVSILTarget.close(); 2719 2676 2720 2677 if( !pfnProgress( 1.0, NULL, pProgressData ) ) … … 2753 2710 "JPEG-2000 (based on Kakadu)" ); 2754 2711 poDriver->SetMetadataItem( GDAL_DMD_HELPTOPIC, 2755 "frmt_jp eg2000.html" );2712 "frmt_jp2kak.html" ); 2756 2713 poDriver->SetMetadataItem( GDAL_DMD_CREATIONDATATYPES, 2757 2714 "Byte Int16 UInt16" ); 2758 2715 poDriver->SetMetadataItem( GDAL_DMD_MIMETYPE, "image/jp2" ); 2759 2716 poDriver->SetMetadataItem( GDAL_DMD_EXTENSION, "jp2" ); 2717 2718 poDriver->SetMetadataItem( GDAL_DCAP_VIRTUALIO, "YES" ); 2760 2719 2761 2720 poDriver->SetMetadataItem( GDAL_DMD_CREATIONOPTIONLIST, trunk/gdal/frmts/jp2kak/subfile_source.h
r10645 r13918 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;
