Logo Search packages:      
Sourcecode: libgphoto2 version File versions

static int gp_file_conversion_chuck ( CameraFile file,
unsigned char *  data 
) [static]

For internal use only.

Definition at line 727 of file gphoto2-file.c.

Referenced by gp_file_raw_to_ppm().

{
      int x, y;
      int p1, p2, p3, p4;
      int red, green, blue;

      /*
       * Added by Chuck -- 12-May-2000
       * Convert the colors based on location, and my wacky color table:
       *
       * Convert the 4 cells into a single RGB pixel.
       * Colors are encoded as follows:
       * 
       *          000000000000000000........33
       *          000000000011111111........11
       *          012345678901234567........89
       *          ----------------------------
       *    000     RGRGRGRGRGRGRGRGRG........RG
       *    001     GBGBGBGBGBGBGBGBGB........GB
       *    002     RGRGRGRGRGRGRGRGRG........RG
       *    003     GBGBGBGBGBGBGBGBGB........GB
       *    ...     ............................
       *    238     RGRGRGRGRGRGRGRGRG........RG
       *    239     GBGBGBGBGBGBGBGBGB........GB
       *
       * NOTE. Above is 320x240 resolution.  Just expand for 640x480.
       *
       * Use neighboring cells to generate color values for each pixel.
       * The neighbors are the (x-1, y-1), (x, y-1), (x-1, y), and (x, y).
       * The exception is when x or y are zero then the neighors used are
       * the +1 cells.
       */
      
      for (y = 0;y < file->height; y++)
            for (x = 0;x < file->width; x++) {
                  p1 = ((y==0?y+1:y-1)*file->width) + (x==0?x+1:x-1);
                  p2 = ((y==0?y+1:y-1)*file->width) +  x;
                  p3 = ( y            *file->width) + (x==0?x+1:x-1);
                  p4 = ( y            *file->width) +  x;

                  switch (((y & 1) << 1) + (x & 1)) {
                  case 0: /* even row, even col, red */
                        blue  = file->blue_table [file->data[p1]];
                        green = file->green_table[file->data[p2]];
                        green+= file->green_table[file->data[p3]];
                        red   = file->red_table  [file->data[p4]];
                        break;
                  case 1: /* even row, odd col, green */
                        green = file->green_table[file->data[p1]];
                        blue  = file->blue_table [file->data[p2]];
                        red   = file->red_table  [file->data[p3]];
                        green+= file->green_table[file->data[p4]];
                        break;
                  case 2: /* odd row, even col, green */
                        green = file->green_table[file->data[p1]];
                        red   = file->red_table  [file->data[p2]];
                        blue  = file->blue_table [file->data[p3]];
                        green+=file->green_table [file->data[p4]];
                        break;
                  case 3: /* odd row, odd col, blue */
                  default:
                        red   = file->red_table  [file->data[p1]];
                        green = file->green_table[file->data[p2]];
                        green+= file->green_table[file->data[p3]];
                        blue  = file->blue_table [file->data[p4]];
                        break;
                  }
                  *data++ = (unsigned char) red;
                  *data++ = (unsigned char) (green/2);
                  *data++ = (unsigned char) blue;
            }

      return (GP_OK);
}


Generated by  Doxygen 1.6.0   Back to index