Exemplo n.º 1
0
static void
writepbmrow(FILE *       const fileP,
            const xel *  const xelrow,
            unsigned int const cols,
            bool         const plainFormat) {

    jmp_buf jmpbuf;
    jmp_buf * origJmpbufP;
    bit * bitrow;

    bitrow = pbm_allocrow(cols);
    
    if (setjmp(jmpbuf) != 0) {
        pbm_freerow(bitrow);
        pm_setjmpbuf(origJmpbufP);
        pm_longjmp();
    } else {
        unsigned int col;

        pm_setjmpbufsave(&jmpbuf, &origJmpbufP);

        for (col = 0; col < cols; ++col)
            bitrow[col] = PNM_GET1(xelrow[col]) == 0 ? PBM_BLACK : PBM_WHITE;
    
        pbm_writepbmrow(fileP, bitrow, cols, plainFormat);

        pm_setjmpbuf(origJmpbufP);
    }
    pbm_freerow(bitrow);
}    
Exemplo n.º 2
0
static void
writepgmrow(FILE *       const fileP, 
            const xel *  const xelrow, 
            unsigned int const cols, 
            xelval       const maxval, 
            int          const format, 
            bool         const plainFormat) {
    
    jmp_buf jmpbuf;
    jmp_buf * origJmpbufP;
    gray * grayrow;
    
    grayrow = pgm_allocrow(cols);
    
    if (setjmp(jmpbuf) != 0) {
        pgm_freerow(grayrow);
        pm_setjmpbuf(origJmpbufP);
        pm_longjmp();
    } else {
        unsigned int col;

        pm_setjmpbufsave(&jmpbuf, &origJmpbufP);
        
        for (col = 0; col < cols; ++col)
            grayrow[col] = PNM_GET1(xelrow[col]);
    
        pgm_writepgmrow(fileP, grayrow, cols, (gray) maxval, plainFormat);

        pm_setjmpbuf(origJmpbufP);
    }
    pgm_freerow(grayrow);
}
Exemplo n.º 3
0
static tuplehash
computetuplefreqhash(struct pam *   const pamP,
                     tuple **       const tupleArray, 
                     unsigned int   const maxsize, 
                     sample         const newMaxval,
                     unsigned int * const sizeP) {
/*----------------------------------------------------------------------------
  Compute a tuple frequency hash from a PAM.  This is a hash that gives
  you the number of times a given tuple value occurs in the PAM.  You can
  supply the input PAM in one of two ways:

  1) a two-dimensional array of tuples tupleArray[][];  In this case,
     'tupleArray' is non-NULL.

  2) an open PAM file, positioned to the raster.  In this case,
     'tupleArray' is NULL.  *pamP contains the file descriptor.
  
     We return with the file still open and its position undefined.  

  In either case, *pamP contains parameters of the tuple array.

  Return the number of unique tuple values found as *sizeP.

  However, if the number of unique tuple values is greater than 'maxsize', 
  return a null return value and *sizeP undefined.

  The tuple values that index the hash are scaled to a new maxval of
  'newMaxval'.  E.g.  if the input has maxval 100 and 'newMaxval' is
  50, and a particular tuple has sample value 50, it would be counted
  as sample value 25 in the hash.
-----------------------------------------------------------------------------*/
    tuplehash tuplefreqhash;
    tuple * rowbuffer;  /* malloc'ed */
        /* Buffer for a row read from the input file; undefined (but still
           allocated) if input is not from a file.
        */
    tuple color;  
        /* The color currently being added, scaled to the new maxval */
    jmp_buf jmpbuf;
    jmp_buf * origJmpbufP;
    
    /* Initialize to "none" for purposes of error recovery */
    tuplefreqhash = NULL;
    rowbuffer = NULL;
    color = NULL;

    if (setjmp(jmpbuf) == 0) {
        pm_setjmpbufsave(&jmpbuf, &origJmpbufP);
        computehashrecoverable(pamP, tupleArray, maxsize, newMaxval, sizeP,
                               &tuplefreqhash, &rowbuffer, &color);
        pm_setjmpbuf(origJmpbufP);
    } else {
        if (color) 
            pnm_freepamtuple(color);
        if (rowbuffer)
            pnm_freepamrow(rowbuffer);
        if (tuplefreqhash)
            pnm_destroytuplehash(tuplefreqhash);
        pm_longjmp();
    }
    return tuplefreqhash;
}