IPP Software Navigation Tools IPP Links Communication Pan-STARRS Links

Ignore:
Timestamp:
Jun 3, 2015, 7:00:55 AM (11 years ago)
Author:
eugene
Message:

get the input / output / compressed pixels sizes right and get the byteswaps right

File:
1 edited

Legend:

Unmodified
Added
Removed
  • branches/eam_branches/ohana.20150429/src/libfits/matrix/F_compress_M.c

    r38355 r38356  
    22# include <gfitsio.h>
    33# include <zlib.h>
     4# define VERBOSE_DUMP 0
    45
    56// the user needs to specify the various compression options:
     
    3334
    3435  Header *theader = ftable->header;
     36
     37  if (!gfits_cmptype_valid(zcmptype)) ESCAPE;
    3538
    3639  // determine the number of tiles (from ztile[] and image size)
     
    147150  int max_tile_size = gfits_imtile_maxsize (matrix, ztile);
    148151
    149   // size of a pixel in the image tile -- this is probably not needed
    150   int tile_pixsize = abs(header[0].bitpix) / 8;
    151 
    152152  // size of a pixel in the raw pixel buffer (before compression)
    153153  int raw_pixsize = gfits_uncompressed_data_pixsize (zcmptype, header[0].bitpix, NULL, NULL, 0);
     
    155155  int cmp_pixsize = gfits_compressed_data_pixsize (zcmptype, header[0].bitpix, NULL, NULL, 0);
    156156
    157   fprintf (stderr, "raw_pixsize: %d, cmp_pixsize: %d, tile_pixsize: %d, raw_bitpix: %d\n",
    158            raw_pixsize, cmp_pixsize, tile_pixsize, raw_bitpix);
     157  // size of a pixel in the image tile -- this is probably not needed
     158  // int tile_pixsize = abs(header[0].bitpix) / 8;
     159  // fprintf (stderr, "raw_pixsize: %d, cmp_pixsize: %d, tile_pixsize: %d, raw_bitpix: %d\n", raw_pixsize, cmp_pixsize, tile_pixsize, raw_bitpix);
    159160
    160161  // allocate the buffer for compression work
     
    177178    if (!gfits_collect_data (matrix, raw, Nraw, raw_bitpix, otile, oblank, ztile, zblank, zscale, zzero)) ESCAPE;
    178179
    179     if (0 && (i == 0)) {
     180    if (VERBOSE_DUMP && (i == 0)) {
    180181      int k;
    181182      fprintf (stderr, "cmp mat: ");
     
    189190    // gzip compresses bytes which are in BIG-ENDIAN order
    190191    if (!strcasecmp(zcmptype, "GZIP_1")) {
    191       if (!gfits_byteswap_zdata (raw, Nraw, raw_pixsize)) ESCAPE;
    192     }
    193     if (0 && (i == 0)) {
     192      // Nraw is number of pixels
     193      if (!gfits_byteswap_zdata (raw, Nraw * raw_pixsize, raw_pixsize)) ESCAPE;
     194    }
     195    int Nzdata = Nzdata_alloc; // available space, replaced with actual output size on compression
     196
     197    if (VERBOSE_DUMP && (i == 0)) {
    194198      int k;
    195199      fprintf (stderr, "cmp swp: ");
    196200      for (k = 0; k < 32; k++) { fprintf (stderr, "0x%02hhx ", raw[k]); }
    197201      fprintf (stderr, "\n");
     202      fprintf (stderr, "Nzdata: %d -> ", Nzdata);
    198203    }
    199204
    200205    // optname, optvalue = NULL, Noptions = 0 : defaults for RICE_1, HCOMPRESS_1
    201206
    202     int Nzdata = Nzdata_alloc; // available space, replaced with actual output size on compression
    203207    if (!gfits_compress_data (zdata, &Nzdata, zcmptype, NULL, NULL, 0, raw, Nraw, raw_pixsize, ztile[1], ztile[0])) ESCAPE;
    204     if (0 && (i == 0)) {
     208    if (VERBOSE_DUMP && (i == 0)) {
     209      int k;
     210      fprintf (stderr, "%d\n", Nzdata);
     211      fprintf (stderr, "cmp SWP: ");
     212      for (k = 0; k < 32; k++) { fprintf (stderr, "0x%02hhx ", zdata[k]); }
     213      fprintf (stderr, "\n");
     214    }
     215
     216    // all other compression modes require swapping after compression
     217    // (compresssion & decompression operate on native ENDIAN)
     218    if (strcasecmp(zcmptype, "GZIP_1")) {
     219      // Nzdata is number of bytes
     220      if (!gfits_byteswap_zdata (zdata, Nzdata, cmp_pixsize)) ESCAPE;
     221    }
     222
     223    if (VERBOSE_DUMP && (i == 0)) {
    205224      int k;
    206225      fprintf (stderr, "cmp dat: ");
     
    208227      fprintf (stderr, "\n");
    209228    }
    210 
    211229    if (!gfits_varlength_column_add_data (ftable, zdata, Nzdata, i, &zdef)) ESCAPE;
    212 
    213     // all other compression modes require swapping after compression
    214     // (compresssion & decompression operate on native ENDIAN)
    215     if (strcasecmp(zcmptype, "GZIP_1")) {
    216       if (!gfits_byteswap_zdata (zdata, Nzdata, cmp_pixsize)) ESCAPE;
    217     }
    218230
    219231    // update the otile[] counters, carrying to the next dimension if needed
     
    222234
    223235  if (!gfits_varlength_column_finish (ftable, &zdef)) ESCAPE;
    224   if (0) {
     236  if (VERBOSE_DUMP) {
    225237    int k;
    226238    fprintf (stderr, "cmp tbl: ");
Note: See TracChangeset for help on using the changeset viewer.