protected void compress(ShortBuffer compressedData,int npix){
  compressedData.put(PLIO_HEADER);
  final int xe=npix - 1;
  int op=PLIO_HEADER.length;
  int pv=Math.max(0,nextPixel());
  int x1=0;
  int iz=0;
  int hi=1;
  int nv=0;
  for (int ip=0; ip <= xe; ++ip) {
    if (ip < xe) {
      nv=Math.max(0,nextPixel());
      if (nv == pv) {
        continue;
      }
      if (pv == 0) {
        pv=nv;
        x1=ip + 1;
        continue;
      }
    }
 else {
      if (pv == 0) {
        x1=xe + 1;
      }
    }
    int np=ip - x1 + 1;
    int nz=x1 - iz;
    boolean skip=false;
    if (pv > 0) {
      int dv=pv - hi;
      if (dv != 0) {
        hi=pv;
        if (Math.abs(dv) > LAST_VALUE_FITTING_IN_12_BIT) {
          compressedData.put(op,(short)((pv & LAST_VALUE_FITTING_IN_12_BIT) + FIRST_VALUE_WITH_13_BIT));
          ++op;
          compressedData.put(op,(short)(pv / FIRST_VALUE_WITH_13_BIT));
          ++op;
        }
 else {
          if (dv < 0) {
            compressedData.put(op,(short)(-dv + VALUE_OF_BIT_13_AND14_ON));
          }
 else {
            compressedData.put(op,(short)(dv + FIRST_VALUE_WITH_14_BIT));
          }
          ++op;
          if (np == 1 && nz == 0) {
            int v=compressedData.get(op - 1);
            compressedData.put(op - 1,(short)(v | FIRST_VALUE_WITH_15_BIT));
            skip=true;
          }
        }
      }
    }
    if (!skip) {
      if (nz > 0) {
        while (nz > 0) {
          compressedData.put(op,(short)Math.min(LAST_VALUE_FITTING_IN_12_BIT,nz));
          ++op;
          nz+=-LAST_VALUE_FITTING_IN_12_BIT;
        }
        if (np == 1 && pv > 0) {
          compressedData.put(op - 1,(short)(compressedData.get(op - 1) + N20481));
          skip=true;
        }
      }
    }
    if (!skip) {
      while (np > 0) {
        compressedData.put(op,(short)(Math.min(LAST_VALUE_FITTING_IN_12_BIT,np) + FIRST_VALUE_WITH_15_BIT));
        ++op;
        np+=-LAST_VALUE_FITTING_IN_12_BIT;
      }
    }
    x1=ip + 1;
    iz=x1;
    pv=nv;
  }
  compressedData.put(HEADER_SIZE_FIELD1,(short)(op % FIRST_VALUE_WITH_16_BIT));
  compressedData.put(HEADER_SIZE_FIELD2,(short)(op / FIRST_VALUE_WITH_16_BIT));
  compressedData.position(op);
}

protected void compress ( ShortBuffer compressedData , int npix ) { compressedData . put ( PLIO_HEADER ) ; final int xe = npix - 1 ; int op = PLIO_HEADER . length ; int pv = Math . max ( 0 , nextPixel ( ) ) ; int x1 = 0 ; int iz = 0 ; int hi = 1 ; int nv = 0 ; for ( int ip = 0 ; ip <= xe ; ++ ip ) { if ( ip < xe ) { nv = Math . max ( 0 , nextPixel ( ) ) ; if ( nv == pv ) { continue ; } if ( pv == 0 ) { pv = nv ; x1 = ip + 1 ; continue ; } } else { if ( pv == 0 ) { x1 = xe + 1 ; } } int np = ip - x1 + 1 ; int nz = x1 - iz ; boolean skip = false ; if ( pv > 0 ) { int dv = pv - hi ; if ( dv != 0 ) { hi = pv ; if ( Math . abs ( dv ) > LAST_VALUE_FITTING_IN_12_BIT ) { compressedData . put ( op , ( short ) ( ( pv & LAST_VALUE_FITTING_IN_12_BIT ) + FIRST_VALUE_WITH_13_BIT ) ) ; ++ op ; compressedData . put ( op , ( short ) ( pv / FIRST_VALUE_WITH_13_BIT ) ) ; ++ op ; } else { if ( dv < 0 ) { compressedData . put ( op , ( short ) ( - dv + VALUE_OF_BIT_13_AND14_ON ) ) ; } else { compressedData . put ( op , ( short ) ( dv + FIRST_VALUE_WITH_14_BIT ) ) ; } ++ op ; if ( np == 1 && nz == 0 ) { int v = compressedData . get ( op - 1 ) ; compressedData . put ( op - 1 , ( short ) ( v | FIRST_VALUE_WITH_15_BIT ) ) ; skip = true ; } } } } if ( ! skip ) { if ( nz > 0 ) { while ( nz > 0 ) { compressedData . put ( op , ( short ) Math . min ( LAST_VALUE_FITTING_IN_12_BIT , nz ) ) ; ++ op ; nz += - LAST_VALUE_FITTING_IN_12_BIT ; } if ( np == 1 && pv > 0 ) { compressedData . put ( op - 1 , ( short ) ( compressedData . get ( op - 1 ) + N20481 ) ) ; skip = true ; } } } if ( ! skip ) { while ( np > 0 ) { compressedData . put ( op , ( short ) ( Math . min ( LAST_VALUE_FITTING_IN_12_BIT , np ) + FIRST_VALUE_WITH_15_BIT ) ) ; ++ op ; np += - LAST_VALUE_FITTING_IN_12_BIT ; } } x1 = ip + 1 ; iz = x1 ; pv = nv ; } compressedData . put ( HEADER_SIZE_FIELD1 , ( short ) ( op % FIRST_VALUE_WITH_16_BIT ) ) ; compressedData . put ( HEADER_SIZE_FIELD2 , ( short ) ( op / FIRST_VALUE_WITH_16_BIT ) ) ; compressedData . position ( op ) ; }
pl_p2l - - convert a pixel tiledimageoperation to a line list . the length of the list is returned as the function value .
