Changeset 15655
- Timestamp:
- Nov 19, 2007, 8:02:41 PM (18 years ago)
- Location:
- trunk/Ohana/src/libfits
- Files:
-
- 2 edited
-
include/gfitsio.h (modified) (1 diff)
-
matrix/F_compress_M.c (modified) (11 diffs)
Legend:
- Unmodified
- Added
- Removed
-
trunk/Ohana/src/libfits/include/gfitsio.h
r15647 r15655 158 158 int gfits_extension_is_compressed PROTO((Header *header)); 159 159 int gfits_tile_size PROTO((Matrix *matrix, int *otile, int *ztile)); 160 int gfits_uncompressed_data_pixsize PROTO((char *cmptype)); 161 int gfits_vartable_heap_pixsize PROTO((char format)); 160 162 161 163 /******************************* Table functions *************/ -
trunk/Ohana/src/libfits/matrix/F_compress_M.c
r15649 r15655 37 37 float zscale, zzero; 38 38 39 int zdata_pixsize, odata_pixsize, idata_pixsize; 40 39 41 int *ztile = NULL; 40 42 int *otile = NULL; … … 43 45 char **optvalue = NULL; 44 46 char *out = NULL; 47 char *zdata = NULL; 45 48 46 49 // is ZIMAGE present? … … 161 164 } 162 165 163 // max_tile_size is in pixels 164 bytes_per_pixel = abs(header[0].bitpix) / 8; 165 ALLOCATE (out, char, bytes_per_pixel*max_tile_size); 166 // this takes place in three major steps: 167 // 1) read the table data : zdef.format tells the size of the varlength heap element 168 // 2) uncompress the data : pixel size depends on compression method 169 // 3) distribute data to the tiles : output pixel size depends on header.bitpix 170 171 // heapdata -> zdata -> odata -> idata 172 173 // heapdata.pixsize : zdef.format 174 // zdata.pixsize : depends on compression 175 // odata.pixsize : depends on compression 176 // idata.pixsize : header.bitpix 177 178 // size of an element in the vartable heap section 179 zdata_pixsize = gfits_vartable_heap_pixsize (zdef.format); 180 181 // size of a pixel in the final image 182 idata_pixsize = abs(header[0].bitpix) / 8; 183 184 // size of a pixel in the output from the decompression routine 185 odata_pixsize = gfits_uncompressed_data_pixsize (cmptype); 186 ALLOCATE (out, char, odata_pixsize*max_tile_size); 166 187 167 188 // uncompress the data … … 172 193 Nout = gfits_tile_size (matrix, otile, ztile); 173 194 174 switch (zdef.format) { 175 // gfits_varlength returns a pointer to a chunk of Nzdata of data elements starting at zdata. 176 // uncompress_data uncompresses from zdata to the temporary output buffer which must be allocated 177 178 // XXX need to have an API to send the user data 179 180 // XXX need to byte-swap the table column; this needs to be worked out more clearly 181 // in the APIs: do the table read / column extract functions swap or not?. we have 182 // put the byte-swapping in gifts_varlength_column_pointer, but this is fairly weak. 183 184 // XXX inconsistency between data element size between compressed data, uncompressed data, 185 // and output pixel data..... 186 187 case 'B': { 188 char *zdata; 189 zdata = gfits_varlength_column_pointer (ftable, &zdef, i, &Nzdata); 190 if (!zdata) return (FALSE); 191 if (!gfits_byteswap_zdata ((char *)zdata, Nzdata, 8)) return (FALSE); 192 if (!gfits_uncompress_data ((char *)zdata, Nzdata, cmptype, optname, optvalue, Noptions, out, &Nout, bytes_per_pixel)) return (FALSE); 193 if (!gfits_distribute_data (matrix, 8, out, Nout, otile, ztile, zscale, zzero)) return (FALSE); 194 // copy the uncompressed pixels into their correct locations 195 break; 196 } 197 198 case 'I': { 199 short *zdata; 200 zdata = gfits_varlength_column_pointer (ftable, &zdef, i, &Nzdata); 201 if (!zdata) return (FALSE); 202 if (!gfits_byteswap_zdata ((char *)zdata, Nzdata, 16)) return (FALSE); 203 if (!gfits_uncompress_data ((char *)zdata, Nzdata, cmptype, optname, optvalue, Noptions, out, &Nout, bytes_per_pixel)) return (FALSE); 204 if (!gfits_distribute_data (matrix, 16, out, Nout, otile, ztile, zscale, zzero)) return (FALSE); 205 // copy the uncompressed pixels into their correct locations 206 break; 207 } 208 209 case 'J': { 210 int *zdata; 211 if (!zdata) return (FALSE); 212 if (!gfits_byteswap_zdata ((char *)zdata, Nzdata, 32)) return (FALSE); 213 if (!gfits_uncompress_data ((char *)zdata, Nzdata, cmptype, optname, optvalue, Noptions, out, &Nout, bytes_per_pixel)) return (FALSE); 214 if (!gfits_distribute_data (matrix, 32, out, Nout, otile, ztile, zscale, zzero)) return (FALSE); 215 // copy the uncompressed pixels into their correct locations 216 break; 217 } 218 219 default: 220 fprintf (stderr, "invalid size for compressed data: %c\n", zdef.format); 221 return (FALSE); 222 } 195 zdata = gfits_varlength_column_pointer (ftable, &zdef, i, &Nzdata); 196 if (!zdata) return (FALSE); 197 198 // XXX not certain this is the correct place to do the swap (or if zdata_pixsize is 199 // the correct size to guide the swap) 200 if (!gfits_byteswap_zdata (zdata, Nzdata, zdata_pixsize)) return (FALSE); 201 202 // gfits_uncompress_data uncompresses from zdata to the temporary output buffer which must be allocated 203 if (!gfits_uncompress_data ((char *)zdata, Nzdata, cmptype, optname, optvalue, Noptions, out, &Nout, bytes_per_pixel)) return (FALSE); 204 205 // copy the uncompressed pixels into their correct locations 206 if (!gfits_distribute_data (matrix, odata_pixsize, out, Nout, otile, ztile, zscale, zzero)) return (FALSE); 223 207 224 208 // update the tile counters, carrying to the next dimension if needed … … 234 218 return (TRUE); 235 219 } 220 221 // gfits_varlength returns a pointer to a chunk of Nzdata of data elements starting at zdata. 222 223 // XXX need to have an API to send the user data 224 225 // XXX need to byte-swap the table column; this needs to be worked out more clearly 226 // in the APIs: do the table read / column extract functions swap or not?. we have 227 // put the byte-swapping in gifts_varlength_column_pointer, but this is fairly weak. 228 229 // XXX inconsistency between data element size between compressed data, uncompressed data, 230 // and output pixel data..... 236 231 237 232 int gfits_tile_size (Matrix *matrix, int *otile, int *ztile) { … … 321 316 for (i = 0; i < Nline; i++) { 322 317 switch (bitpix) { 323 case 8:318 case 1: 324 319 SETUP_INSIZE (char, 1); 325 320 break; 326 case 16:321 case 2: 327 322 SETUP_INSIZE (short, 2); 328 323 break; 329 case 32:324 case 4: 330 325 SETUP_INSIZE (int, 4); 331 326 break; … … 361 356 } 362 357 363 int gfits_byteswap_zdata (char *zdata, int Nzdata, int bitpix) {358 int gfits_byteswap_zdata (char *zdata, int Nzdata, int pixsize) { 364 359 365 360 # ifdef BYTE_SWAP … … 368 363 char tmp; 369 364 370 switch (bitpix) { 371 case +8: 372 case -8: 365 switch (pixsize) { 366 case 1: 373 367 break; 374 368 375 case +16: 376 case -16: 369 case 2: 377 370 for (i = 0; i < Nzdata; i+=2) { 378 371 tmp = zdata[i]; … … 382 375 break; 383 376 384 case +32: 385 case -32: 377 case 4: 386 378 for (i = 0; i < Nzdata; i+=4) { 387 379 tmp = zdata[i+1]; … … 394 386 break; 395 387 396 case +64: 397 case -64: 388 case 8: 398 389 for (i = 0; i < Nzdata; i+=8) { 399 390 tmp = zdata[i+0]; … … 444 435 return (FALSE); 445 436 } 437 438 int gfits_uncompressed_data_pixsize (char *cmptype) { 439 440 if (!strcasecmp(cmptype, "GZIP")) { 441 return (0); 442 } 443 if (!strcasecmp(cmptype, "RICE") || !strcasecmp(cmptype, "RICE_1")) { 444 return (4); 445 } 446 if (!strcasecmp(cmptype, "PLIO")) { 447 return (1); 448 } 449 if (!strcasecmp(cmptype, "HCOMPRESS")) { 450 return (4); 451 } 452 return (0); 453 } 454 455 int gfits_vartable_heap_pixsize (char format) { 456 457 if (format == 'B') { 458 return (1); 459 } 460 if (format == 'I') { 461 return (2); 462 } 463 if (format == 'J') { 464 return (4); 465 } 466 fprintf (stderr, "invalid size for compressed data: %c\n", format); 467 abort (); 468 }
Note:
See TracChangeset
for help on using the changeset viewer.
