IPP Software Navigation Tools IPP Links Communication Pan-STARRS Links

Changeset 38322


Ignore:
Timestamp:
May 25, 2015, 8:08:57 PM (11 years ago)
Author:
eugene
Message:

adding compression of images in prep for compression / uncompression of tables

Location:
branches/eam_branches/ohana.20150429/src/libfits
Files:
2 added
2 edited
1 moved

Legend:

Unmodified
Added
Removed
  • branches/eam_branches/ohana.20150429/src/libfits/doc/notes-compress.txt

    r15487 r38322  
     1
     220150525 :
     3
     4uncompression steps:
     5
     6 * read in a table: gfits_fread_ftable_data (f, &ftable, FALSE); (no byte swap)
     7 * uncompress the image: gfits_uncompress_image (&buf[0].header, &buf[0].matrix, &ftable);
     8   * get ZIMAGE from heaer & delete
     9   * get ZCMPTYPE
     10   * get ZBITPIX, ZNAXIS, ZNAXISnn
     11   * get ZTILEn (if missing ZTILE1 = Nx, others 1)
     12   * get ZNAME, ZVAL
     13   * ZSIMPLE, ZTENSION, ZEXTEND, ZBLOCKED, ZPCOUNT, ZGCOUNT, etc
     14   * ZSCALE, ZBLANK, OBLANK, ZZERO
     15
     16   * data is stored in fits table COMPRESSED_DATA (1PB, 1PI, 1PJ)
     17
     18------------------------------------------------
    119
    220TFORMn : rPt(e_max)
  • branches/eam_branches/ohana.20150429/src/libfits/extern/gzip.c

    r23816 r38322  
    151151    return err;
    152152}
     153
     154int gfits_compress (Bytef *dest, uLongf *destLen, const Bytef *source, uLong sourceLen)
     155{
     156  z_stream stream;
     157  int err;
     158
     159  stream.next_in = (Bytef*)source;
     160  stream.avail_in = (uInt)sourceLen;
     161
     162  /* Check for source > 64K on 16-bit machine: */
     163  if ((uLong)stream.avail_in != sourceLen) return Z_BUF_ERROR;
     164
     165  stream.next_out = dest;
     166  stream.avail_out = (uInt)*destLen; // allocated space
     167  if ((uLong)stream.avail_out != *destLen) return Z_BUF_ERROR;
     168
     169  stream.zalloc = (alloc_func)0;
     170  stream.zfree = (free_func)0;
     171
     172  err = deflateInit(&stream);
     173  if (err != Z_OK) return err;
     174
     175  // XXX this is written to do the compression in a single pass.  it could be re-done to have
     176  // the compression occur in a series of steps
     177  err = deflate(&stream, Z_FINISH);
     178  if (err != Z_STREAM_END) {
     179    deflateEnd(&stream);
     180    return err;
     181  }
     182  assert (stream.total_out <= *destLen);
     183  *destLen = stream.total_out;
     184 
     185  err = deflateEnd(&stream);
     186  return err;
     187}
  • branches/eam_branches/ohana.20150429/src/libfits/matrix/F_uncompress_M.c

    r38278 r38322  
    221221    ntile[i] = (matrix->Naxis[i] % ztile[i]) ? (matrix->Naxis[i] / ztile[i] + 1) : (matrix->Naxis[i] / ztile[i]);
    222222    max_tile_size *= ztile[i];
     223
     224    // ztile[i] is the default (or max) tile size in the i-th dimension
     225    // ntile[i] is the number of tiles in the i-th dimension
     226    // otile[i] is the current output tile counter in the i-th dimension
    223227  }
    224228
     
    282286  }
    283287  return (TRUE);
    284 }
    285 
    286 // gfits_varlength returns a pointer to a chunk of Nzdata of data elements starting at zdata.
    287 
    288 // XXX need to have an API to send the user data
    289 
    290 // XXX need to byte-swap the table column; this needs to be worked out more clearly
    291 // in the APIs: do the table read / column extract functions swap or not?.  we have
    292 // put the byte-swapping in gifts_varlength_column_pointer, but this is fairly weak.
    293 
    294 // XXX inconsistency between data element size between compressed data, uncompressed data,
    295 // and output pixel data.....
    296 
    297 // true sizes of this tile (in pixels)
    298 off_t gfits_tile_size (Matrix *matrix, int *otile, int *ztile) {
    299 
    300   off_t i, Npixels, Ndimen;
    301 
    302   Npixels = 1;
    303   for (i = 0; i < matrix->Naxes; i++) {
    304     Ndimen = MIN ((matrix->Naxis[i] - otile[i]*ztile[i]), ztile[i]);
    305     Npixels *= Ndimen;
    306   }
    307  
    308   return (Npixels);
    309288}
    310289
     
    424403}
    425404
    426 int gfits_byteswap_zdata (char *zdata, int Nzdata, int pixsize) {
    427 
    428 # define DOSWAP(A,B) { char tmp = A; A = B; B = tmp; }
    429 
    430 # ifdef BYTE_SWAP
    431 
    432   int i;
    433 
    434   switch (pixsize) {
    435     case 1:
    436       break;
    437 
    438     case 2:
    439       for (i = 0; i < 2*Nzdata; i+=2) {
    440         DOSWAP (zdata[i+0], zdata[i+1]);
    441       }
    442       break;
    443 
    444     case 4:
    445       for (i = 0; i < 4*Nzdata; i+=4) {
    446         DOSWAP (zdata[i+0], zdata[i+3]);
    447         DOSWAP (zdata[i+1], zdata[i+2]);
    448       }
    449       break;
    450 
    451     case 8:
    452       for (i = 0; i < 8*Nzdata; i+=8) {
    453         DOSWAP (zdata[i+0], zdata[i+7]);
    454         DOSWAP (zdata[i+1], zdata[i+6]);
    455         DOSWAP (zdata[i+2], zdata[i+5]);
    456         DOSWAP (zdata[i+3], zdata[i+4]);
    457       }
    458       break;
    459   }
    460 # endif
    461   return (TRUE);
    462 }
    463 
    464 int gfits_extension_is_compressed (Header *header) {
    465 
    466     int has_extension, has_extname, has_zimage, zimage;
    467     char extname[80], extension[80];
    468 
    469     has_extension = gfits_scan (header, "XTENSION", "%s", 1, extension);
    470     has_extname = gfits_scan (header, "EXTNAME", "%s", 1, extname);
    471     has_zimage  = gfits_scan_alt (header, "ZIMAGE", "%t", 1, &zimage);
    472 
    473     if (has_extension && !strcmp (extension, "IMAGE")) return (FALSE);
    474     if (has_zimage && zimage) return (TRUE);
    475     if (has_extname) {
    476         if (!strcmp (extname, "COMPRESSED_IMAGE")) return (TRUE);
    477     }
    478 
    479     return (FALSE);
    480 }
    481 
    482 int gfits_compressed_is_primary (Header *header) {
    483 
    484   int zimage = FALSE;
    485   // int ztension = FALSE;
    486 
    487     int has_zimage   = gfits_scan_alt (header, "ZIMAGE",   "%t", 1, &zimage);
    488     // int has_ztension = gfits_scan_alt (header, "ZTENSION", "%t", 1, &ztension);
    489 
    490     if (has_zimage && zimage) return (TRUE);
    491 
    492     return (FALSE);
    493 }
    494 
    495 int gfits_uncompressed_data_pixsize (char *cmptype, int out_bitpix, char **optname, char **optvalue, int Noptions) {
    496 
    497   int i, Nbyte;
    498 
    499   if (!strcasecmp(cmptype, "GZIP_1")) {
    500     if (out_bitpix == 8)  return (1);
    501     if (out_bitpix == 16) return (2);
    502     if (out_bitpix == 32) return (4);
    503     if (out_bitpix == -32) return (4);
    504     if (out_bitpix == -64) return (8);
    505     return (1);
    506   }
    507   if (!strcasecmp(cmptype, "RICE_1")) {
    508 
    509     // if BYTEPIX option is specified, use that for Nbyte
    510     for (i = 0; i < Noptions; i++) {
    511       if (!strcmp(optname[i], "BYTEPIX")) {
    512         Nbyte = atoi (optvalue[i]);
    513         return (Nbyte);
    514       }
    515     }
    516 
    517     return (4);
    518   }
    519   if (!strcasecmp(cmptype, "PLIO_1")) {
    520     return (4);
    521   }
    522   if (!strcasecmp(cmptype, "HCOMPRESS_1")) {
    523     if (out_bitpix == 8)  return (4);
    524     if (out_bitpix == 16) return (4);
    525     return (8);
    526   }
    527   return (0);
    528 }
    529 
    530 int gfits_vartable_heap_pixsize (char format) {
    531 
    532   if (format == 'B') {
    533       return (1);
    534   }
    535   if (format == 'I') {
    536       return (2);
    537   }
    538   if (format == 'J') {
    539       return (4);
    540   }
    541   fprintf (stderr, "invalid size for compressed data: %c\n", format); 
    542   abort ();
    543 }
Note: See TracChangeset for help on using the changeset viewer.