Esempio n. 1
0
static void
copyPixelRow(JSAMPROW        const jpegbuffer,
             unsigned int    const width, 
             unsigned int    const samplesPerPixel, 
             enum colorspace const colorSpace,
             FILE *          const ofP,
             int             const format,
             xelval          const maxval) {

    JSAMPLE * ptr;
    unsigned int outputCursor;     /* Cursor into output buffer 'pnmbuffer' */

    ptr = &jpegbuffer[0];  /* Start at beginning of input row */
    
    for (outputCursor = 0; outputCursor < width; ++outputCursor) {
        xel currentPixel;
        if (samplesPerPixel >= 3) {
            const rgb_type * const rgb_p = read_rgb(ptr, colorSpace, maxval);
            PPM_ASSIGN(currentPixel, rgb_p->r, rgb_p->g, rgb_p->b);
        } else {
            PNM_ASSIGN1(currentPixel, GETJSAMPLE(*ptr));
        }
        ptr += samplesPerPixel;  /* move to next pixel of input */
        pnmbuffer[outputCursor] = currentPixel;
    }
    pnm_writepnmrow(ofP, pnmbuffer, width, maxval, format, FALSE);
}
Esempio n. 2
0
static void
copy_pixel_row(const JSAMPROW jpegbuffer, const int width, 
               const unsigned int samples_per_pixel, 
               const enum colorspace color_space,
               const unsigned int maxval,
               FILE * const output_file, const int output_type) {
  JSAMPLE *ptr;
  unsigned int output_cursor;     /* Cursor into output buffer 'pnmbuffer' */

  ptr = jpegbuffer;  /* Start at beginning of input row */

  for (output_cursor = 0; output_cursor < width; output_cursor++) {
      xel current_pixel;
      if (samples_per_pixel >= 3) {
          const rgb_type * const rgb_p = read_rgb(ptr, color_space, maxval);
          PPM_ASSIGN(current_pixel, rgb_p->r, rgb_p->g, rgb_p->b);
      } else {
          PNM_ASSIGN1(current_pixel, GETJSAMPLE(*ptr));
      }
      ptr += samples_per_pixel;  /* move to next pixel of input */
      pnmbuffer[output_cursor] = current_pixel;
  }
  pnm_writepnmrow(output_file, pnmbuffer, width,
                  maxval, output_type, FALSE);
}
Esempio n. 3
0
static void
makeNewXel(xel * const outputXelP, xel const curXel, xel const prevXel,
           double const fracnew0, double const omfracnew0, int const format) {
/*----------------------------------------------------------------------------
   Create an output xel as *outputXel, which is part curXel and part
   prevXel, the part given by the fractions omfracnew0 and fracnew0,
   respectively.  These fraction values are the numerator of a fraction
   whose denominator is SCALE.

   The format of the pixel is 'format'.
-----------------------------------------------------------------------------*/

    switch ( PNM_FORMAT_TYPE(format) ) {
    case PPM_TYPE:
        PPM_ASSIGN( *outputXelP,
                    ( fracnew0 * PPM_GETR(prevXel) 
                      + omfracnew0 * PPM_GETR(curXel) 
                      + HALFSCALE ) / SCALE,
                    ( fracnew0 * PPM_GETG(prevXel) 
                      + omfracnew0 * PPM_GETG(curXel) 
                      + HALFSCALE ) / SCALE,
                    ( fracnew0 * PPM_GETB(prevXel) 
                      + omfracnew0 * PPM_GETB(curXel) 
                      + HALFSCALE ) / SCALE );
        break;
        
    default:
        PNM_ASSIGN1( *outputXelP,
                     ( fracnew0 * PNM_GET1(prevXel) 
                       + omfracnew0 * PNM_GET1(curXel) 
                       + HALFSCALE ) / SCALE );
        break;
    }
}
Esempio n. 4
0
static void
writeConvolutionImage(FILE *       const cofp,
                      unsigned int const cols,
                      unsigned int const rows,
                      int          const format) {

    xelval const convmaxval = rows * cols * 2;
        /* normalizing factor for our convolution matrix */
    xelval const g = rows * cols + 1;
        /* weight of all pixels in our convolution matrix */
    int row;
    xel *outputrow;

    if (convmaxval > PNM_OVERALLMAXVAL)
        pm_error("The convolution matrix is too large.  "
                 "Width x Height x 2\n"
                 "must not exceed %d and it is %d.",
                 PNM_OVERALLMAXVAL, convmaxval);

    pnm_writepnminit(cofp, cols, rows, convmaxval, format, 0);
    outputrow = pnm_allocrow(cols);

    for (row = 0; row < rows; ++row) {
        unsigned int col;
        for (col = 0; col < cols; ++col)
            PNM_ASSIGN1(outputrow[col], g);
        pnm_writepnmrow(cofp, outputrow, cols, convmaxval, format, 0);
    }
    pnm_freerow(outputrow);
}
Esempio n. 5
0
static void
remap(xel **       const xels,
      unsigned int const cols,
      unsigned int const rows,
      xelval       const maxval,
      int          const format,
      bool         const monoOnly,
      const gray * const lumamap) {
/*----------------------------------------------------------------------------
   Update the array 'xels' to have the new intensities.
-----------------------------------------------------------------------------*/
    switch (PNM_FORMAT_TYPE(format)) {
    case PPM_TYPE: {
        unsigned int row;
        for (row = 0; row < rows; ++row) {
            unsigned int col;
            for (col = 0; col < cols; ++col) {
                xel const thisXel = xels[row][col];
                if (monoOnly && PPM_ISGRAY(thisXel)) {
                    /* Leave this pixel alone */
                } else {
                    struct hsv hsv;
                    xelval iv;

                    hsv = ppm_hsv_from_color(thisXel, maxval);
                    iv = MIN(maxval, ROUNDU(hsv.v * maxval));
                    
                    hsv.v = MIN(1.0, 
                                ((double) lumamap[iv]) / ((double) maxval));

                    xels[row][col] = ppm_color_from_hsv(hsv, maxval);
                }
            }
        }
    }
    break;

    case PBM_TYPE:
    case PGM_TYPE: {
        unsigned int row;
        for (row = 0; row < rows; ++row) {
            unsigned int col;
            for (col = 0; col < cols; ++col)
                PNM_ASSIGN1(xels[row][col],
                            lumamap[PNM_GET1(xels[row][col])]);
        }
    }
    break;
    }
}