IPP Software Navigation Tools IPP Links Communication Pan-STARRS Links

Ignore:
Timestamp:
Jan 24, 2008, 5:45:18 PM (18 years ago)
Author:
eugene
Message:

cleaning up the image/screen relationships and remap functions

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/Ohana/src/kapa2/src/Remap24.c

    r16011 r16228  
    11# include "Ximage.h"
    2 
    3 static float slope = 1.0;
    4 static float start = 0.0;
    5 static int MaxValue = 255;
    6 
    7 // XXX inline this if needed
    8 static int PixelLookup(float value) {
    9   int out;
    10   out = MIN (MAX (slope * value - start, 0), MaxValue);
    11   return (out);
    12 }
    132
    143void Remap24 (Graphic *graphic, KapaImageWidget *image, Matrix *matrix) {
     
    176  int i_start, i_end, j_start, j_end;
    187  int dropback, extra;  /* this is a bit of a kludge... */
    19   int dx, dy, DX, DY, pixelN;
    20   double expand, Rx, Ry, X, Y;
     8  int dx, dy, DX, DY;
     9  double expand, Sx, Sy, Ix, Iy;
    2110  int expand_in, expand_out;
    2211  unsigned char *out_pix, *out_pix2, *data;
    23   float *imdata, *in_pix, *in_pix2;
    24   unsigned char pixel1[256], pixel2[256], pixel3[256];
     12  unsigned short *in_pix, *in_pix2;
     13  unsigned char *pixel1, *pixel2, *pixel3;
    2514  unsigned char pixvalue1, pixvalue2, pixvalue3;
    26   unsigned long back;
    2715  unsigned char back1, back2, back3;
    2816
     17  ALLOCATE (pixel1, unsigned char, graphic[0].Npixels);
     18  ALLOCATE (pixel2, unsigned char, graphic[0].Npixels);
     19  ALLOCATE (pixel3, unsigned char, graphic[0].Npixels);
     20
    2921  // local arrays for pixel values
    30   for (i = 0; i < 256; i++) { /* set up pixel array */
     22  for (i = 0; i < graphic[0].Npixels; i++) { /* set up pixel array */
    3123    pixel1[i] = 0x0000ff &  graphic[0].cmap[i].pixel;
    3224    pixel2[i] = 0x0000ff & (graphic[0].cmap[i].pixel >> 8);
    3325    pixel3[i] = 0x0000ff & (graphic[0].cmap[i].pixel >> 16);
    3426  }
    35   back = graphic[0].back;
    36   back1 = 0x0000ff & back;
    37   back2 = 0x0000ff & (back >> 8);
    38   back3 = 0x0000ff & (back >> 16);
    39 
    40   // define the color transform parameters
    41   MaxValue = graphic[0].Npixels - 1;
    42   if (image[0].image[0].range != 0.0) {
    43     slope = graphic[0].Npixels / image[0].image[0].range;
    44     start = graphic[0].Npixels * image[0].image[0].zero / image[0].image[0].range;
    45   } else {
    46     slope = 1.0;
    47     start = image[0].image[0].zero;
    48   }
     27  back1 = 0x0000ff & (graphic[0].back >>  0);
     28  back2 = 0x0000ff & (graphic[0].back >>  8);
     29  back3 = 0x0000ff & (graphic[0].back >> 16);
    4930
    5031  // set up expansions
     
    7051
    7152  /* X,Y are the image coordinates of the first image pixel */
    72   X = MAX(0.5*(DX - dx*expand) - image[0].X, 0);
    73   if ((int)X != X)
    74     X = (int) X + 1;
     53  Ix = MAX(0.5*(DX - dx*expand) - image[0].X, 0);
     54  if ((int)Ix != Ix)
     55    Ix = (int) Ix + 1;
    7556  else
    76     X = (int) X;
    77   Y = MAX(0.5*(DY - dy*expand) - image[0].Y, 0);
    78   if ((int)Y != Y)
    79     Y = (int) Y + 1;
     57    Ix = (int) Ix;
     58  Iy = MAX(0.5*(DY - dy*expand) - image[0].Y, 0);
     59  if ((int)Iy != Iy)
     60    Iy = (int) Iy + 1;
    8061  else
    81     Y = (int) Y;
     62    Iy = (int) Iy;
    8263
    83   /* Rx,Ry are the screen coordinates of the first image pixel */
    84   Rx = (X + image[0].X - 0.5*DX)/expand + 0.5*dx;
    85   Ry = (Y + image[0].Y - 0.5*DY)/expand + 0.5*dy;
     64  /* Sx,Sy are the screen coordinates of the first image pixel */
     65  Sx = (Ix + image[0].X - 0.5*DX)/expand + 0.5*dx;
     66  Sy = (Iy + image[0].Y - 0.5*DY)/expand + 0.5*dy;
    8667
    87   i_start = MIN (MAX (Rx, 0), dx - expand_out + 1);
    88   j_start = MIN (MAX (Ry, 0), dy - expand_out + 1);
     68  i_start = MIN (MAX (Sx, 0), dx - expand_out + 1);
     69  j_start = MIN (MAX (Sy, 0), dy - expand_out + 1);
    8970 
    9071  if (image[0].expand > 0) {
    91     i_end = MAX (MIN (i_start + ((int)(expand*(dx-i_start)))/expand, expand_out*(DX-X) + Rx), 0);
    92     j_end = MAX (MIN (j_start + ((int)(expand*(dy-j_start)))/expand, expand_out*(DY-Y) + Ry), 0);
     72    i_end = MAX (MIN (i_start + ((int)(expand*(dx-i_start)))/expand, expand_out*(DX-Ix) + Sx), 0);
     73    j_end = MAX (MIN (j_start + ((int)(expand*(dy-j_start)))/expand, expand_out*(DY-Iy) + Sy), 0);
    9374  } else {
    94     i_end = MAX (MIN (dx, (DX-X)/expand + Rx), 0);
    95     j_end = MAX (MIN (dy, (DY-Y)/expand + Ry), 0);
     75    i_end = MAX (MIN (dx, (DX-Ix)/expand + Sx), 0);
     76    j_end = MAX (MIN (dy, (DY-Iy)/expand + Sy), 0);
    9677  }   
    9778
     
    10081
    10182  data = out_pix = (unsigned char *) image[0].picture.data;
    102   imdata  = (float *) matrix[0].buffer;
    103   in_pix  = &imdata[DX*(int)MAX(Y,0) + (int)MAX(X,0)];
     83  in_pix  = &image[0].pixmap[DX*(int)MAX(Iy,0) + (int)MAX(Ix,0)];
    10484
    10585  /********** below we do the mapping from buffer pixels (in) to picture pixels (out) **********/
     
    133113    if (expand_out == 1) {
    134114      for (i = i_start; i < i_end; i++, in_pix2+= expand_in, out_pix+=3) {
    135         pixelN = PixelLookup(*in_pix2);
    136         out_pix[0] = pixel1[pixelN];
    137         out_pix[1] = pixel2[pixelN];
    138         out_pix[2] = pixel3[pixelN];
     115        out_pix[0] = pixel1[*in_pix2];
     116        out_pix[1] = pixel2[*in_pix2];
     117        out_pix[2] = pixel3[*in_pix2];
    139118      }
    140119    } else {
    141120      for (i = i_start; i < i_end; i+= expand_out, in_pix2++, out_pix+= 3*expand_out) {
    142         pixelN = PixelLookup(*in_pix2);
    143         pixvalue1 = pixel1[pixelN];
    144         pixvalue2 = pixel2[pixelN];
    145         pixvalue3 = pixel3[pixelN];
     121        pixvalue1 = pixel1[*in_pix2];
     122        pixvalue2 = pixel2[*in_pix2];
     123        pixvalue3 = pixel3[*in_pix2];
    146124        out_pix2 = out_pix;
    147125        for (jj = 0; jj < expand_out; jj++, out_pix2+=3*(dx-expand_out)+extra) {
     
    185163  image[0].picture.pix = XCreateImage (graphic[0].display, graphic[0].visual, graphic[0].depth, ZPixmap, 0,
    186164                                        image[0].picture.data, image[0].picture.dx, image[0].picture.dy, 32, 0);
     165
     166  free (pixel1);
     167  free (pixel2);
     168  free (pixel3);
    187169}
    188170
Note: See TracChangeset for help on using the changeset viewer.