IPP Software Navigation Tools IPP Links Communication Pan-STARRS Links

Ignore:
Timestamp:
Jun 3, 2015, 8:20:19 PM (11 years ago)
Author:
eugene
Message:

adding GZIP_2 and getting RICE_1 to work (mostly)

File:
1 edited

Legend:

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

    r38356 r38362  
    33# include <zlib.h>
    44# define VERBOSE_DUMP 0
     5
     6int gfits_distribute_gzp2 (Matrix *matrix, char *raw, int Nraw, int raw_bitpix, int *otile, int oblank, int *ztile, int zblank, float zscale, float zzero);
    57
    68# define ESCAPE { \
     
    321323
    322324    // copy the uncompressed pixels into their correct locations           
    323     if (!gfits_distribute_data (matrix, out, Nout, raw_bitpix, otile, oblank, ztile, zblank, zscale, zzero)) ESCAPE;
     325    if (!strcasecmp(cmptype, "GZIP_2")) {
     326      if (!gfits_distribute_gzp2 (matrix, out, Nout, raw_bitpix, otile, oblank, ztile, zblank, zscale, zzero)) ESCAPE;
     327    } else {
     328      if (!gfits_distribute_data (matrix, out, Nout, raw_bitpix, otile, oblank, ztile, zblank, zscale, zzero)) ESCAPE;
     329    }
    324330
    325331    if (VERBOSE_DUMP && (row == 0)) {
     
    359365int gfits_distribute_data (Matrix *matrix, char *raw, int Nraw, int raw_bitpix, int *otile, int oblank, int *ztile, int zblank, float zscale, float zzero) {
    360366
    361   int i, j, start, offset, coord, Nline;
     367  int i, j;
    362368  int *counter = NULL;
    363369  int *Ztile = NULL;
     
    374380
    375381  // number of lines in the tile (in pixels)
    376   Nline = 1;
     382  int Nline = 1;
    377383  for (i = 1; i < matrix->Naxes; i++) {
    378384    Nline *= Ztile[i];
     
    385391  // start = otile[0]*ztile[0] + otile[1]*ztile[1]*Naxis[0] + otile[2]*ztile[2]*Naxis[0]*Naxis[1] + ...;
    386392  // start = otile[0]*ztile[0] + Naxis[0]*(otile[1]*ztile[1] + Naxis[1]*(otile[2]*ztile[2] + ...));
    387   start = otile[matrix->Naxes-1]*ztile[matrix->Naxes-1];
     393  int start = otile[matrix->Naxes-1]*ztile[matrix->Naxes-1];
    388394  for (i = matrix->Naxes - 2; i >= 0; i--) {
    389     coord = otile[i]*ztile[i];
     395    int coord = otile[i]*ztile[i];
    390396    start = start*matrix->Naxis[i] + coord;
    391397  }
    392398 
    393399  // pixel offset in output array relative to tile start
    394   offset = 0;
     400  int offset = 0;
    395401
    396402  // we need to set up switches for all of the possible combinations:
     
    466472}
    467473
     474// bitpix is the input data size/type
     475int gfits_distribute_gzp2 (Matrix *matrix, char *raw, int Nraw, int raw_bitpix, int *otile, int oblank, int *ztile, int zblank, float zscale, float zzero) {
     476
     477  int i, j, k;
     478  int *counter = NULL;
     479  int *Ztile = NULL;
     480
     481  ALLOCATE (counter, int, matrix->Naxes);
     482  ALLOCATE (Ztile, int, matrix->Naxes);
     483
     484  // counter for current row in tile to copy
     485  // true sizes of this tile (in pixels)
     486  for (i = 0; i < matrix->Naxes; i++) {
     487    counter[i] = 0;
     488    Ztile[i] = MIN ((matrix->Naxis[i] - otile[i]*ztile[i]), ztile[i]);
     489  }
     490
     491  // number of lines in the tile (in pixels)
     492  int Nline = 1;
     493  int Npix = matrix->Naxis[0];
     494  for (i = 1; i < matrix->Naxes; i++) {
     495    Nline *= Ztile[i];
     496    Npix  *= matrix->Naxis[i];
     497  }
     498
     499  // double check reported size (needs the Isize)
     500  assert (Nraw == Ztile[0]*Nline);
     501
     502  // set the starting point of the tile:
     503  // start = otile[0]*ztile[0] + otile[1]*ztile[1]*Naxis[0] + otile[2]*ztile[2]*Naxis[0]*Naxis[1] + ...;
     504  // start = otile[0]*ztile[0] + Naxis[0]*(otile[1]*ztile[1] + Naxis[1]*(otile[2]*ztile[2] + ...));
     505  int start = otile[matrix->Naxes-1]*ztile[matrix->Naxes-1];
     506  for (i = matrix->Naxes - 2; i >= 0; i--) {
     507    int coord = otile[i]*ztile[i];
     508    start = start*matrix->Naxis[i] + coord;
     509  }
     510 
     511  int size = 0;
     512  switch (raw_bitpix) {
     513    case   8: size = 1; break;
     514    case  16: size = 2; break;
     515    case  32: size = 4; break;
     516    case -32: size = 4; break;
     517    case -64: size = 8; break;
     518    default: abort();
     519  }
     520
     521  // pixel offset in output array relative to tile start
     522  int offset = 0;
     523
     524  static int pass = 0;
     525  for (k = 0; k < size; k++) {
     526    for (i = 0; i < Nline; i++) {
     527# ifdef BYTE_SWAP     
     528      char *srcptr = &matrix->buffer[size*(offset + start) + (size - k - 1)];
     529# else
     530      char *srcptr = &matrix->buffer[size*(offset + start) + k];
     531# endif
     532      char *rawptr = &raw[i*size*Ztile[0] + k*Nraw];   
     533      for (j = 0; j < Ztile[0]; j++, srcptr += size, rawptr ++) {               
     534        if (FALSE && (i == 0) && (j < 4) && (pass == 0)) {
     535          fprintf (stderr, "0x%02hhx -> 0x%02hhx\n", (int)(srcptr - matrix->buffer), (int)(rawptr - raw));
     536        }
     537        *srcptr = *rawptr;
     538        myAssert (srcptr - matrix->buffer < Npix*size, "memory overrun");
     539        myAssert (rawptr - raw < Nraw*size, "memory overrun");
     540      }
     541
     542      // update the counters, carrying to the next dimension if needed
     543      for (j = 1; j < matrix->Naxes; j++) {
     544        counter[j] ++;
     545        if (counter[j] == Ztile[j]) {
     546          counter[j] = 0;
     547        } else {
     548          break;
     549        }
     550      }
     551      if (j == matrix->Naxes) assert (i == Nline - 1); // we should be done here...
     552
     553      // Naxes = 3
     554      // offset = counter[1]*matrix->Naxis[0] + counter[2]*matrix->Naxis[0]*matrix->Naxis[1] +
     555      // offset = matrix->Naxis[0]*(counter[1] + matrix->Naxis[1]*(counter[2] + matrix->Naxis[2]*...))
     556
     557      // determine the offset of the next line relative to the start position
     558      offset = counter[matrix->Naxes - 1];
     559      for (j = matrix->Naxes - 2; j >= 0; j--) {
     560        offset = offset*matrix->Naxis[j] + counter[j];
     561      }     
     562    }
     563  }
     564  pass ++;
     565
     566  free (counter);
     567  free (Ztile);
     568  return (TRUE);
     569}
     570
Note: See TracChangeset for help on using the changeset viewer.