コード例 #1
0
int
main(int argc, char **argv) {

    FILE * ifP; 
    struct cmdlineInfo cmdline;
    struct pam inpam, outpam;
    int eof;  /* No more images in input stream */

    pnm_init(&argc, argv);

    parseCommandLine(argc, argv, &cmdline);

    if (cmdline.simple || cmdline.local)
        ifP = pm_openr(cmdline.inputFileName);
    else
        ifP = pm_openr_seekable(cmdline.inputFileName);

    /* Threshold each image in the PAM file */
    eof = FALSE;
    while (!eof) {
        pnm_readpaminit(ifP, &inpam, PAM_STRUCT_SIZE(tuple_type));

        /* Set output image parameters for a bilevel image */
        outpam.size        = sizeof(outpam);
        outpam.len         = PAM_STRUCT_SIZE(tuple_type);
        outpam.file        = stdout;
        outpam.format      = PAM_FORMAT;
        outpam.plainformat = 0;
        outpam.height      = inpam.height;
        outpam.width       = inpam.width;
        outpam.maxval      = 1;
        outpam.bytes_per_sample = 1;

        if (inpam.depth > 1) {
            strcpy(outpam.tuple_type, "BLACKANDWHITE_ALPHA");
            outpam.depth = 2;
        } else {
            strcpy(outpam.tuple_type, "BLACKANDWHITE");
            outpam.depth = 1;
        }

        pnm_writepaminit(&outpam);

        /* Do the thresholding */

        if (cmdline.simple)
            thresholdSimple(&inpam, &outpam, cmdline.threshold);
        else if (cmdline.local || cmdline.dual)
            thresholdLocal(&inpam, &outpam, cmdline);
        else
            thresholdIterative(&inpam, &outpam, cmdline.verbose);

        pnm_nextimage(ifP, &eof);
    }

    pm_close(ifP);

    return 0;
}
コード例 #2
0
int
main(int           argc,
     const char ** argv) {

    struct cmdlineInfo cmdline;
    FILE * ifP;
    tuple ** outTuples;        /* Output image */
    scaler * scalerP;
    struct pam inpam;
    struct pam outpam;

    pm_proginit(&argc, argv);

    parseCommandLine(argc, argv, &cmdline);

    ifP = pm_openr(cmdline.inputFileName);

    pnm_readpaminit(ifP, &inpam, PAM_STRUCT_SIZE(allocation_depth));

    pnm_setminallocationdepth(&inpam, 3);
    
    outpam.size               = sizeof(outpam);
    outpam.len                = PAM_STRUCT_SIZE(tuple_type);
    outpam.file               = stdout;
    outpam.width              = inpam.width;
    outpam.height             = inpam.height;
    outpam.depth              = 3;
    outpam.maxval             =
        pm_lcm(cmdline.colorRes.c[RED]-1,
               cmdline.colorRes.c[GRN]-1,
               cmdline.colorRes.c[BLU]-1,
               PPM_MAXMAXVAL);
    outpam.bytes_per_sample   = inpam.bytes_per_sample;
    STRSCPY(outpam.tuple_type, "RGB");
    outpam.format             = RPPM_FORMAT;
    outpam.plainformat        = false;

    scaler_create(outpam.maxval, cmdline.colorRes, &scalerP);

    ditherImage(&inpam, scalerP, cmdline.dim, cmdline.colorRes,
                &outpam, &outTuples);

    pnm_writepam(&outpam, outTuples);

    scaler_destroy(scalerP);

    pnm_freepamarray(outTuples, &outpam);

    pm_close(ifP);

    return 0;
}
コード例 #3
0
ファイル: pamsharpness.c プロジェクト: moseymosey/netpbm
int
main(int argc, char **argv) {

    struct cmdlineInfo cmdline;
    FILE * ifP;
    tuplen ** tuplenarray;
    struct pam inpam;
    double sharpness;

	pnm_init(&argc, argv);

    parseCommandLine(argc, argv, &cmdline);

    ifP = pm_openr(cmdline.inputFilespec);

	tuplenarray = pnm_readpamn(ifP, &inpam, PAM_STRUCT_SIZE(tuple_type));

    if (inpam.height < 3 || inpam.width < 3)
        pm_error("sharpness is undefined for an image less than 3 pixels "
                 "in all directions.  This image is %d x %d",
                 inpam.width, inpam.height);

    computeSharpness(&inpam, tuplenarray, &sharpness);

    printf("Sharpness = %f\n", sharpness);

	pnm_freepamarrayn(tuplenarray, &inpam);
    pm_close(ifP);
	return 0;
}
コード例 #4
0
ファイル: pamunlookup.c プロジェクト: gguillotte/netpbm-code
static void
getLookup(const char * const lookupFileName, 
          tuple ***    const lookupP,
          struct pam * const lookuppamP) {
/*----------------------------------------------------------------------------
   Get the lookup image (the one that maps integers to tuples, e.g. a
   color index / color map / palette) from the file named 
   'lookupFileName'.

   Return the image as *lookupP and *lookuppamP.
-----------------------------------------------------------------------------*/
    FILE *  lookupfileP;

    struct pam inputLookuppam;
    tuple ** inputLookup;

    lookupfileP = pm_openr(lookupFileName);
    inputLookup = pnm_readpam(lookupfileP, 
                              &inputLookuppam, PAM_STRUCT_SIZE(tuple_type));

    pm_close(lookupfileP);
    
    if (inputLookuppam.height != 1)
        pm_error("The lookup table image must be one row.  "
                 "Yours is %u rows.", 
                 inputLookuppam.height);

    *lookupP = inputLookup;
    *lookuppamP = inputLookuppam;
}
コード例 #5
0
static void
wipeoutLr(FILE * const ifP,
          FILE * const ofP) {
    
    /* left-right we can read row-by-row */

    struct pam inpam, outpam;
    tuple ** tuples;
    tuple * tuplerow;
    unsigned int row;

    pnm_readpaminit(ifP, &inpam, PAM_STRUCT_SIZE(tuple_type));

    outpam = inpam;
    outpam.file = ofP;

    pnm_writepaminit(&outpam);

    tuplerow = pnm_allocpamrow(&inpam);

    for (row = 0; row < inpam.height; ++row) {
        pnm_readpamrow(&inpam, tuplerow);

        wipeRowByCol(inpam, tuples, tuplerow);

        pnm_writepamrow(&outpam, tuplerow);
    }

    pnm_freepamrow(tuplerow);
}
コード例 #6
0
ファイル: pamsplit.c プロジェクト: jhbsz/DIR-850L_A1
static void
extractOneImage(FILE * const infileP,
                FILE * const outfileP) {

    struct pam inpam;
    struct pam outpam;
    enum pm_check_code checkRetval;
    
    unsigned int row;
    tuple * tuplerow;

    pnm_readpaminit(infileP, &inpam, PAM_STRUCT_SIZE(tuple_type));

    pnm_checkpam(&inpam, PM_CHECK_BASIC, &checkRetval);

    outpam = inpam;
    outpam.file = outfileP;

    pnm_writepaminit(&outpam);

    tuplerow = pnm_allocpamrow(&inpam);
    for (row = 0; row < inpam.height; ++row) {
        pnm_readpamrow(&inpam, tuplerow);
        pnm_writepamrow(&outpam, tuplerow);
    }
    pnm_freepamrow(tuplerow);
}
コード例 #7
0
ファイル: pamstereogram.c プロジェクト: jhbsz/DIR-850L_A1
static void
createoutputGenerator(struct cmdlineInfo const cmdline,
                      const struct pam * const inPamP,
                      outGenerator **    const outputGeneratorPP) {

    outGenerator * outGenP;

    MALLOCVAR_NOFAIL(outGenP);

    outGenP->pam.size   = sizeof(struct pam);
    outGenP->pam.len    = PAM_STRUCT_SIZE(tuple_type);
    outGenP->pam.file   = stdout;
    outGenP->pam.height = inPamP->height + 3 * abs(cmdline.guidesize);
    /* Allow room for guides. */
    outGenP->pam.width  = inPamP->width;

    if (cmdline.patFilespec) {
        /* Background pixels should come from the pattern file. */

        initPatternPixel(outGenP, cmdline);
    } else {
        /* Background pixels should be generated randomly */

        initRandomColor(outGenP, inPamP, cmdline);
    }

    outGenP->pam.bytes_per_sample = pnm_bytespersample(outGenP->pam.maxval);

    *outputGeneratorPP = outGenP;
}
コード例 #8
0
ファイル: pamstereogram.c プロジェクト: jhbsz/DIR-850L_A1
static void
initPatternPixel(outGenerator *     const outGenP,
                 struct cmdlineInfo const cmdline) {

    struct patternPixelState * stateP;
    FILE * patternFileP;

    MALLOCVAR_NOFAIL(stateP);

    patternFileP = pm_openr(cmdline.patFilespec);

    stateP->patTuples =
        pnm_readpam(patternFileP,
                    &stateP->patPam, PAM_STRUCT_SIZE(tuple_type));

    pm_close(patternFileP);

    stateP->xshift     = cmdline.xshift;
    stateP->yshift     = cmdline.yshift;
    stateP->magnifypat = cmdline.magnifypat;

    outGenP->stateP          = stateP;
    outGenP->getTuple        = &patternPixel;
    outGenP->terminateState  = &termPatternPixel;
    outGenP->pam.format      = stateP->patPam.format;
    outGenP->pam.plainformat = stateP->patPam.plainformat;
    outGenP->pam.depth       = stateP->patPam.depth;
    outGenP->pam.maxval      = stateP->patPam.maxval;
    strcpy(outGenP->pam.tuple_type, stateP->patPam.tuple_type);

    if (cmdline.verbose)
        reportImageParameters("Pattern file", &stateP->patPam);
}
コード例 #9
0
static void
colormapToImage(int                const format,
                const struct pam * const colormapPamP,
                tupletable2        const colormap,
                bool               const sort,
                bool               const square,
                struct pam *       const outpamP, 
                tuple ***          const outputRasterP) {
/*----------------------------------------------------------------------------
   Create a tuple array and pam structure for an image which includes
   one pixel of each of the colors in the colormap 'colormap'.

   May rearrange the contents of 'colormap'.
-----------------------------------------------------------------------------*/
    outpamP->size             = sizeof(*outpamP);
    outpamP->len              = PAM_STRUCT_SIZE(tuple_type);
    outpamP->format           = format,
    outpamP->plainformat      = FALSE;
    outpamP->depth            = colormapPamP->depth;
    outpamP->maxval           = colormapPamP->maxval;
    outpamP->bytes_per_sample = pnm_bytespersample(outpamP->maxval);
    STRSCPY(outpamP->tuple_type, colormapPamP->tuple_type);

    if (sort)
        sortColormap(colormap, outpamP->depth);

    if (square) 
        colormapToSquare(outpamP, colormap, outputRasterP);
    else 
        colormapToSingleRow(outpamP, colormap, outputRasterP);
}
コード例 #10
0
ファイル: pampick.c プロジェクト: chneukirchen/netpbm-mirror
static void
extractOneImage(FILE * const infileP,
                FILE * const outfileP) {
/*----------------------------------------------------------------------------
  Copy a complete image from input stream *infileP to output stream
  *outfileP.

  But if outfileP == NULL, just read the image and discard it.
-----------------------------------------------------------------------------*/
    struct pam inpam;
    struct pam outpam;
    enum pm_check_code checkRetval;
    
    unsigned int row;
    tuple * tuplerow;

    pnm_readpaminit(infileP, &inpam, PAM_STRUCT_SIZE(tuple_type));

    pnm_checkpam(&inpam, PM_CHECK_BASIC, &checkRetval);

    outpam = inpam;
    outpam.file = outfileP;

    if (outfileP)
        pnm_writepaminit(&outpam);

    tuplerow = pnm_allocpamrow(&inpam);
    for (row = 0; row < inpam.height; ++row) {
        pnm_readpamrow(&inpam, tuplerow);
        if (outfileP)
            pnm_writepamrow(&outpam, tuplerow);
    }
    pnm_freepamrow(tuplerow);
}
コード例 #11
0
ファイル: pamtilt.c プロジェクト: jhbsz/DIR-850L_A1
static void
readRelevantPixels(const char *   const inputFilename,
                   unsigned int   const hstepReq,
                   unsigned int   const vstepReq,
                   unsigned int * const hstepP,
                   unsigned int * const vstepP,
                   sample ***     const pixelsP,
                   struct pam *   const pamP,
                   unsigned int * const hsamplesP) {
/*----------------------------------------------------------------------------
  load the image, saving only the pixels we might actually inspect
-----------------------------------------------------------------------------*/
    FILE * ifP;
    unsigned int hstep;
    unsigned int vstep;

    ifP = pm_openr(inputFilename);
    pnm_readpaminit(ifP, pamP, PAM_STRUCT_SIZE(tuple_type));
    computeSteps(pamP, hstepReq, vstepReq, &hstep, &vstep);

    load(pamP, hstep, pixelsP, hsamplesP);

    *hstepP = hstep;
    *vstepP = vstep;
    
    pm_close(ifP);
}
コード例 #12
0
ファイル: pnmremap.c プロジェクト: gguillotte/netpbm-code
static void
processMapFile(const char *   const mapFileName,
               struct pam *   const outpamCommonP,
               tupletable *   const colormapP,
               unsigned int * const colormapSizeP,
               tuple *        const firstColorP) {
/*----------------------------------------------------------------------------
   Read a color map from the file named 'mapFileName'.  It's a map that
   associates each color in that file with a unique whole number.  Return the
   map as *colormapP, with the number of entries in it as *colormapSizeP.

   Also determine the first color (top left) in the map file and return that
   as *firstColorP.
-----------------------------------------------------------------------------*/
    FILE * mapfile;
    struct pam mappam;
    tuple ** maptuples;
    tuple firstColor;

    mapfile = pm_openr(mapFileName);
    maptuples = pnm_readpam(mapfile, &mappam, PAM_STRUCT_SIZE(tuple_type));
    pm_close(mapfile);

    computeColorMapFromMap(&mappam, maptuples, colormapP, colormapSizeP);

    firstColor = pnm_allocpamtuple(&mappam);
    pnm_assigntuple(&mappam, firstColor, maptuples[0][0]);
    *firstColorP = firstColor;

    pnm_freepamarray(maptuples, &mappam);

    *outpamCommonP = mappam; 
    outpamCommonP->file = stdout;
}
コード例 #13
0
int 
main(int argc, const char **argv) {

    struct CmdlineInfo cmdline;
    struct pam * imgPam;  /* malloced */
    struct pam outimg;
    unsigned int fileCt;
    Coord * coords;  /* malloced */
    FILE * headerFileP;
    FILE * dataFileP;
    const char ** names; /* malloced */
    unsigned int qfactor;  /* In per cent */

    pm_proginit(&argc, argv);

    parseCommandLine(argc, argv, &cmdline);

    headerFileP = cmdline.header ? pm_openw(cmdline.header) : NULL;
    dataFileP = cmdline.data ? pm_openw(cmdline.data) : NULL;

    qfactor = qfactorFromQuality(cmdline.quality, cmdline.quality2);

    openFiles(cmdline, &fileCt, &imgPam, &names);

    readFileHeaders(imgPam, fileCt);

    sortImagesByArea(fileCt, imgPam, names);

    findpack(imgPam, fileCt, &coords, cmdline.quality2, qfactor);

    computeOutputType(&outimg.maxval, &outimg.format, outimg.tuple_type,
                      &outimg.depth, fileCt, imgPam);

    computeOutputDimensions(&outimg.width, &outimg.height, fileCt,
                            imgPam, coords);
    outimg.size = sizeof(outimg);
    outimg.len = PAM_STRUCT_SIZE(allocation_depth);
    pnm_setminallocationdepth(&outimg, outimg.depth);
    outimg.plainformat = false;
    outimg.file = stdout;
 
    writePam(&outimg, fileCt, coords, imgPam);

    if (dataFileP)
        writeData(dataFileP, outimg.width, outimg.height,
                  fileCt, names, coords, imgPam);

    if (headerFileP)
        writeHeader(headerFileP, cmdline.prefix, outimg.width, outimg.height,
                    fileCt, names, coords, imgPam);

    closeFiles(imgPam, fileCt, headerFileP, dataFileP);

    free(coords);
    free(imgPam);
    free(names);

    return 0;
}
コード例 #14
0
ファイル: pamdeinterlace.c プロジェクト: jhbsz/DIR-850L_A1
int
main(int argc, char *argv[]) {

    FILE * ifP;
    tuple * tuplerow;   /* Row from input image */
    unsigned int row;
    struct cmdlineInfo cmdline;
    struct pam inpam;  
    struct pam outpam;

    pnm_init( &argc, argv );

    parseCommandLine(argc, argv, &cmdline);

    ifP = pm_openr(cmdline.inputFilespec);
    
    pnm_readpaminit(ifP, &inpam, PAM_STRUCT_SIZE(tuple_type));

    tuplerow = pnm_allocpamrow(&inpam);

    outpam = inpam;    /* Initial value -- most fields should be same */
    outpam.file = stdout;
    if (inpam.height % 2 == 0)
        outpam.height = inpam.height / 2;
    else {
        if (cmdline.rowsToTake == ODD)
            outpam.height = inpam.height / 2;
        else
            outpam.height = inpam.height / 2 + 1;
    }

    pnm_writepaminit(&outpam);

    {
        unsigned int modulusToTake;
            /* The row number mod 2 of the rows that are supposed to go into
               the output.
            */

        switch (cmdline.rowsToTake) {
        case EVEN: modulusToTake = 0; break;
        case ODD:  modulusToTake = 1; break;
        default: pm_error("INTERNAL ERROR: invalid rowsToTake");
        }

        /* Read input and write out rows extracted from it */
        for (row = 0; row < inpam.height; row++) {
            pnm_readpamrow(&inpam, tuplerow);
            if (row % 2 == modulusToTake)
                pnm_writepamrow(&outpam, tuplerow);
        }
    }
    pnm_freepamrow(tuplerow);
    pm_close(inpam.file);
    pm_close(outpam.file);
    
    return 0;
}
コード例 #15
0
ファイル: pamgradient.c プロジェクト: jhbsz/DIR-850L_A1
int
main(int argc, char *argv[]) {

    struct cmdlineInfo cmdline;
    struct pam pam;
    tuple * tupleRow;
    tuple * leftEdge;
    tuple * rightEdge;
    unsigned int row;
    
    pnm_init(&argc, argv);

    parseCommandLine(argc, argv, &cmdline);

    pam.size             = sizeof pam;
    pam.len              = PAM_STRUCT_SIZE(tuple_type);
    pam.file             = stdout;
    pam.plainformat      = 0;
    pam.width            = cmdline.cols;
    pam.height           = cmdline.rows;
    pam.maxval           = cmdline.maxval;
    pam.bytes_per_sample = pnm_bytespersample(pam.maxval);
    pam.format           = PAM_FORMAT;
    if (isgray(&pam, cmdline.colorTopLeft)
            && isgray(&pam, cmdline.colorTopRight)
            && isgray(&pam, cmdline.colorBottomLeft)
            && isgray(&pam, cmdline.colorBottomRight)) {
        pam.depth = 1;
        strcpy(pam.tuple_type, PAM_PGM_TUPLETYPE);
    } else {
        pam.depth = 3;
        strcpy(pam.tuple_type, PAM_PPM_TUPLETYPE);
    }

    pnm_writepaminit(&pam);
    
    tupleRow = pnm_allocpamrow(&pam);

    leftEdge  = createEdge(&pam,
                           cmdline.colorTopLeft, cmdline.colorBottomLeft);
    rightEdge = createEdge(&pam,
                           cmdline.colorTopRight, cmdline.colorBottomRight);

    /* interpolate each row between the left edge and the right edge */
    for (row = 0; row < pam.height; ++row) {
        interpolate(&pam, tupleRow, leftEdge[row], rightEdge[row]);
        pnm_writepamrow(&pam, tupleRow); 
    }

    pm_close(stdout);
    pnm_freepamrow(rightEdge);
    pnm_freepamrow(leftEdge);
    pnm_freepamrow(tupleRow);

    freeCmdline(cmdline);

    return 0;
}
コード例 #16
0
static void
writeAnaglyph( FILE *       const ofP,
               gray **      const grayArray,
               gray         const maxGrayVal,
               int          const eyeSep,
               int          const swapEyes,
               struct pam * const pamP) {
/*----------------------------------------------------------------------
  Output an anaglyphic stereogram from the given grayscale array and
  eye-separation value.
------------------------------------------------------------------------*/
    struct pam   outPam;
    tuple      * tuplerow;

    outPam.size        = sizeof(struct pam);
    outPam.len         = PAM_STRUCT_SIZE(tuple_type);
    outPam.file        = ofP;
    outPam.format      = PAM_FORMAT;
    outPam.plainformat = 0;
    outPam.height      = pamP->height;
    outPam.width       = pamP->width - eyeSep;
        /* Avoid color bands on the left/right edges. */
    outPam.depth       = 3;
    outPam.maxval      = (sample) maxGrayVal;
    strcpy(outPam.tuple_type, PAM_PPM_TUPLETYPE);

    pnm_writepaminit( &outPam );

    tuplerow = pnm_allocpamrow( &outPam );

    if (swapEyes) {
        unsigned int row;

        for (row = 0; row < outPam.height; ++row) {
            unsigned int col;
            for (col = 0; col < outPam.width; ++col) {
                tuplerow[col][PAM_RED_PLANE] = grayArray[row][col+eyeSep];
                tuplerow[col][PAM_GRN_PLANE] = grayArray[row][col];
                tuplerow[col][PAM_BLU_PLANE] = grayArray[row][col];
            }
            pnm_writepamrow( &outPam, tuplerow );
        }
    } else {
        unsigned int row;
        for (row = 0; row < outPam.height; ++row) {
            unsigned int col;
            for (col = 0; col < outPam.width; ++col) {
                tuplerow[col][PAM_RED_PLANE] = grayArray[row][col];
                tuplerow[col][PAM_GRN_PLANE] = grayArray[row][col+eyeSep];
                tuplerow[col][PAM_BLU_PLANE] = grayArray[row][col+eyeSep];
            }
            pnm_writepamrow( &outPam, tuplerow );
        }
    }
    pnm_freepamrow( tuplerow );
}
コード例 #17
0
static void
readFileHeaders(struct pam * const imgPam,
                unsigned int const fileCt) {

    unsigned int i;

    for (i = 0; i < fileCt; ++i)
        pnm_readpaminit(imgPam[i].file, &imgPam[i],
                        PAM_STRUCT_SIZE(tuple_type));
}
コード例 #18
0
ファイル: pamtotga.c プロジェクト: Eleanor66613/CS131
int
main(int argc, char *argv[]) {

    struct cmdlineInfo cmdline;
    FILE * ifP;
    tuple ** tuples;
    struct pam pam;
    int ncolors;
    tupletable chv;
    tuplehash cht;
    struct ImageHeader tgaHeader;
    enum TGAbaseImageType baseImgType;
    bool withAlpha;
    const char *outName;

    pnm_init( &argc, argv );

    parseCommandLine(argc, argv, &cmdline);

    ifP = pm_openr(cmdline.inputFilespec);

    computeOutName(cmdline, &outName);

    tuples = pnm_readpam(ifP, &pam, PAM_STRUCT_SIZE(tuple_type));
    pm_close(ifP);

    computeImageType_cht(&pam, cmdline, tuples, 
                         &baseImgType, &withAlpha, &chv, &cht, &ncolors);

    /* Do the Targa header */
    computeTgaHeader(&pam, baseImgType, withAlpha, !cmdline.norle,
                     ncolors, 0, outName, &tgaHeader);
    writeTgaHeader(tgaHeader);
    
    if (baseImgType == TGA_MAP_TYPE) {
        /* Write out the Targa colormap. */
        int i;
        for (i = 0; i < ncolors; ++i)
            putMapEntry(&pam, chv[i]->tuple, tgaHeader.CoSize);
    }

    writeTgaRaster(&pam, tuples, cht, baseImgType, withAlpha, 
                   !cmdline.norle, 0);

    if (cht)
        pnm_destroytuplehash(cht);
    if (chv)
        pnm_freetupletable(&pam, chv);

    releaseTgaHeader(tgaHeader);
    strfree(outName);
    pnm_freepamarray(tuples, &pam);

    return 0;
}
コード例 #19
0
ファイル: pnmremap.c プロジェクト: gguillotte/netpbm-code
static void
remap(FILE *             const ifP,
      const struct pam * const outpamCommonP,
      tupletable         const colormap, 
      unsigned int       const colormapSize,
      bool               const floyd,
      bool               const randomize,
      tuple              const defaultColor,
      bool               const verbose) {
/*----------------------------------------------------------------------------
   Remap the pixels from the raster on *ifP to the 'colormapSize' colors in
   'colormap'.

   Where the input pixel's color is in the map, just use that for the output.
   Where it isn't, use 'defaultColor', except if that is NULL, use the
   closest color in the map to the input color.

   But if 'floyd' is true and 'defaultColor' is NULL, also do Floyd-Steinberg
   dithering on the output so the aggregate color of a region is about the
   same as that of the input even though the individual pixels have different
   colors.
-----------------------------------------------------------------------------*/
    int eof;
    eof = FALSE;
    while (!eof) {
        struct pam inpam, outpam;
        unsigned int missingCount;
            /* Number of pixels that were mapped to 'defaultColor' because
               they weren't present in the color map.
            */

        pnm_readpaminit(ifP, &inpam, PAM_STRUCT_SIZE(allocation_depth));
    
        outpam = *outpamCommonP;
        outpam.width  = inpam.width;
        outpam.height = inpam.height;

        pnm_writepaminit(&outpam);

        /* Set up so input buffers have extra space as needed to
           convert the input to the output depth.
        */
        pnm_setminallocationdepth(&inpam, outpam.depth);
    
        copyRaster(&inpam, &outpam, colormap, colormapSize, floyd,
                   randomize, defaultColor, &missingCount);
        
        if (verbose)
            pm_message("%u pixels not matched in color map", missingCount);
        
        pnm_nextimage(ifP, &eof);
    }
}
コード例 #20
0
ファイル: pamtopnm.c プロジェクト: cjd8363/Global-Illum
int
main(int argc, char *argv[]) {

    struct cmdlineInfo cmdline;
    FILE* ifP;
    struct pam inpam;   /* Input PAM image */
    struct pam outpam;  /* Output PNM image */

    pnm_init(&argc, argv);

    parseCommandLine(argc, argv, &cmdline);

    ifP = pm_openr(cmdline.inputFilespec);

    pnm_readpaminit(ifP, &inpam, PAM_STRUCT_SIZE(tuple_type));

    validateTupleType(inpam, cmdline.assume);

    outpam = inpam;
    outpam.file = stdout;
    
    if (inpam.depth < 3) {
        outpam.depth = 1;
        if (inpam.maxval == 1)
            outpam.format = PBM_FORMAT;
        else 
            outpam.format = PGM_FORMAT;
    } else {
        outpam.depth = 3;
        outpam.format = PPM_FORMAT;
    }

    pnm_writepaminit(&outpam);

    {
        tuple *tuplerow;
        
        tuplerow = pnm_allocpamrow(&inpam);      
        { 
            int row;
            
            for (row = 0; row < inpam.height; row++) {
                pnm_readpamrow(&inpam, tuplerow);
                pnm_writepamrow(&outpam, tuplerow);
            }
        }
        pnm_freepamrow(tuplerow);        
    }
    return 0;
}
コード例 #21
0
ファイル: pamunlookup.c プロジェクト: gguillotte/netpbm-code
static void
doUnlookup(struct pam * const inpamP,
           tuplehash    const lookupHash,
           sample       const maxIndex,
           FILE *       const ofP) {

    struct pam outpam;
    unsigned int row;
    tuple * inrow;
    tuple * outrow;

    inrow = pnm_allocpamrow(inpamP);

    outpam.size = sizeof(outpam);
    outpam.len = PAM_STRUCT_SIZE(tuple_type);
    outpam.file = ofP;
    outpam.format = PAM_FORMAT;
    outpam.height = inpamP->height;
    outpam.width = inpamP->width;
    outpam.depth = 1;
    outpam.maxval = maxIndex + 1;  /* +1 for missing color */
    strcpy(outpam.tuple_type, "INDEX");

    pnm_writepaminit(&outpam);

    outrow = pnm_allocpamrow(&outpam);

    for (row = 0; row < inpamP->height; ++row) {
        unsigned int col;
        
        pnm_readpamrow(inpamP, inrow);

        for (col = 0; col < inpamP->width; ++col) {
            int found;
            int index;
            pnm_lookuptuple(inpamP, lookupHash, inrow[col], &found, &index);

            if (found) {
                assert(index <= outpam.maxval);
                outrow[col][0] = index;
            } else
                outrow[col][0] = maxIndex + 1;
        }
        pnm_writepamrow(&outpam, outrow);
    }

    pnm_freepamrow(outrow);
    pnm_freepamrow(inrow);
}
コード例 #22
0
static void
writeImgPam(IPDB * const pdbP,
            FILE * const ofP) {

    struct pam pam;
    tuple * tupleRow;
    unsigned int row;
    uint8_t * imgRow;

    MALLOCARRAY(imgRow, ipdb_width(pdbP));

    pam.size             = sizeof(pam);
    pam.len              = PAM_STRUCT_SIZE(tuple_type);
    pam.file             = ofP;
    pam.plainformat      = 0;
    pam.width            = ipdb_width(pdbP);
    pam.height           = ipdb_height(pdbP);
    pam.depth            = 1;
    pam.maxval           = ipdb_type(pdbP) == IMG_MONO ? 1 : 255;
    pam.bytes_per_sample = pnm_bytespersample(pam.maxval);
    pam.format           = PAM_FORMAT;
    strcpy(pam.tuple_type,
           ipdb_type(pdbP) == IMG_MONO ?
           PAM_PBM_TUPLETYPE : PAM_PGM_TUPLETYPE);

    pnm_writepaminit(&pam);
    
    tupleRow = pnm_allocpamrow(&pam);

    for (row = 0; row < pam.height; ++row) {
        unsigned int col;


        if (ipdb_type(pdbP) == IMG_MONO)
            mrow(pdbP, row, imgRow);
        else if (ipdb_type(pdbP) == IMG_GRAY)
            grow(pdbP, row, imgRow);
        else
            g16row(pdbP, row, imgRow);

        for (col = 0; col < pam.width; ++col)
            tupleRow[col][0] = imgRow[col];
        
        pnm_writepamrow(&pam, tupleRow);
    }
    pnm_freepamrow(tupleRow);

    free(imgRow);
}
コード例 #23
0
ファイル: pamtodjvurle.c プロジェクト: cjd8363/Global-Illum
int 
main(int argc, char *argv[]) {

    FILE * const rlefile = stdout;

    struct cmdlineInfo cmdline;
    FILE *ifP;                 /* Input (Netpbm) file */
    struct pam pam;            /* Description of the image */
    tuple ** tupleArray;       /* The image raster */
    tupletable colormap;       /* List of all of the colors used */
    unsigned int numColors;    /* Number of unique colors in the color map */
    tuplehash colorhash; 
        /* Mapping from color to index into colormap[] */
    tuple transcolor;
        /* Color that should be considered transparent */

    pnm_init (&argc, argv);

    parseCommandLine(argc, argv, &cmdline);

    ifP = pm_openr(cmdline.inputFilespec);

    tupleArray = pnm_readpam(ifP, &pam, PAM_STRUCT_SIZE(tuple_type));

    transcolor = pnm_parsecolor(cmdline.transparent, pam.maxval);
    
    computeColorMap(&pam, tupleArray, &numColors, &colormap, &colorhash,
                    cmdline.showcolormap);
    
    makeDjvurleHeader(rlefile, &pam, numColors, colormap);

    /* Write the raster */

    {
        unsigned int row;
        for (row = 0; row < pam.height; ++row)
            writeDjvurleRow(rlefile, &pam, tupleArray[row], colorhash, 
                            transcolor);
    }
    /* Clean up */
    
    pnm_freepamarray(tupleArray, &pam);
    pnm_freetupletable(&pam, colormap);
    pnm_destroytuplehash(colorhash);
    pnm_freepamtuple(transcolor);
    pm_close(ifP);

    return 0;
}
コード例 #24
0
ファイル: pambackground.c プロジェクト: Eleanor66613/CS131
static void
initOutpam(const struct pam * const inpamP,
           struct pam *       const outpamP) {

    outpamP->file             = stdout;
    outpamP->format           = PAM_FORMAT;
    outpamP->plainformat      = 0;
    outpamP->width            = inpamP->width;
    outpamP->height           = inpamP->height;
    outpamP->depth            = 1;
    outpamP->maxval           = 1;
    outpamP->bytes_per_sample = pnm_bytespersample(outpamP->maxval);
    outpamP->len              = PAM_STRUCT_SIZE(bytes_per_sample);
    outpamP->size             = sizeof(*outpamP);
}
コード例 #25
0
ファイル: pamgauss.c プロジェクト: ownclo/jpeg-on-steroids
int
main(int argc, char **argv) {

    struct cmdlineInfo cmdline;
    struct pam pam;
    int row;
    double normalizer;
    tuplen * tuplerown;
    
    pnm_init(&argc, argv);
   
    parseCommandLine(argc, argv, &cmdline);

    pam.size        = sizeof(pam);
    pam.len         = PAM_STRUCT_SIZE(tuple_type);
    pam.file        = stdout;
    pam.format      = PAM_FORMAT;
    pam.plainformat = 0;
    pam.width       = cmdline.width;
    pam.height      = cmdline.height;
    pam.depth       = 1;
    pam.maxval      = cmdline.maxval;
    strcpy(pam.tuple_type, cmdline.tupletype);

    normalizer = imageNormalizer(&pam, cmdline.sigma);
    
    pnm_writepaminit(&pam);
   
    tuplerown = pnm_allocpamrown(&pam);

    for (row = 0; row < pam.height; ++row) {
        int col;
        for (col = 0; col < pam.width; ++col) {
            double const gauss1 = gauss(distFromCenter(&pam, col, row),
                                        cmdline.sigma);

            tuplerown[col][0] = gauss1 * normalizer;
        }
        pnm_writepamrown(&pam, tuplerown);
    }
    
    pnm_freepamrown(tuplerown);

    return 0;
}
コード例 #26
0
ファイル: jpeg2ktopam.c プロジェクト: Eleanor66613/CS131
int
main(int argc, char **argv)
{
    struct cmdlineInfo cmdline;
    struct pam outpam;
    int * jasperCmpt;  /* malloc'ed */
       /* jaspercmpt[P] is the component number for use with the
          Jasper library that corresponds to Plane P of the PAM.  
       */
    jas_image_t * jasperP;

    pnm_init(&argc, argv);
    
    parseCommandLine(argc, argv, &cmdline);
    
    { 
        int rc;
        
        rc = jas_init();
        if ( rc != 0 )
            pm_error("Failed to initialize Jasper library.  "
                     "jas_init() returns rc %d", rc );
    }
    
    jas_setdbglevel(cmdline.debuglevel);
    
    readJpc(cmdline.inputFilename, &jasperP);

    outpam.file = stdout;
    outpam.size = sizeof(outpam);
    outpam.len  = PAM_STRUCT_SIZE(tuple_type);

    computeOutputParm(jasperP, &outpam, &jasperCmpt);

    pnm_writepaminit(&outpam);
    
    convertToPamPnm(&outpam, jasperP, jasperCmpt);
    
    free(jasperCmpt);
	jas_image_destroy(jasperP);

    pm_close(stdout);
    
    return 0;
}
コード例 #27
0
ファイル: pamfile.c プロジェクト: jhbsz/DIR-850L_A1
static void
doOneImage(const char * const name,
           unsigned int const imageDoneCount,
           FILE *       const fileP,
           bool         const allimages,
           bool         const justCount,
           bool         const wantComments,
           bool *       const eofP) {
                    
    struct pam pam;
    const char * comments;
    enum pm_check_code checkRetval;

    pam.comment_p = &comments;

    pnm_readpaminit(fileP, &pam, PAM_STRUCT_SIZE(comment_p));
        
    if (!justCount) {
        if (allimages)
            printf("%s:\tImage %d:\t", name, imageDoneCount);
        else 
            printf("%s:\t", name);
            
        dumpHeader(pam);
        if (wantComments)
            dumpComments(comments);
    }
    strfree(comments);

    pnm_checkpam(&pam, PM_CHECK_BASIC, &checkRetval);
    if (allimages) {
        tuple * tuplerow;
        unsigned int row;
        
        tuplerow = pnm_allocpamrow(&pam);
        
        for (row = 0; row < pam.height; ++row) 
            pnm_readpamrow(&pam, tuplerow);
        
        pnm_freepamrow(tuplerow);
        
        pnm_nextimage(fileP, eofP);
    }
}
コード例 #28
0
ファイル: pamunlookup.c プロジェクト: gguillotte/netpbm-code
int
main(int argc, const char ** const argv) {

    struct CmdlineInfo cmdline;
    struct pam inpam;
    FILE * ifP;
    struct pam lookuppam;
    tuple ** lookup;

    tuplehash lookupHash;
    
    pm_proginit(&argc, argv);

    parseCommandLine(argc, argv, &cmdline);

    ifP = pm_openr(cmdline.inputFileName);

    pnm_readpaminit(ifP, &inpam, PAM_STRUCT_SIZE(tuple_type));

    getLookup(cmdline.lookupfile, &lookup, &lookuppam);

    if (inpam.depth != lookuppam.depth)
        pm_error("The lookup image has depth %u, but the input image "
                 "has depth %u.  They must be the same",
                 lookuppam.depth, inpam.depth);
    if (!streq(inpam.tuple_type, lookuppam.tuple_type))
        pm_error("The lookup image has tupel type '%s', "
                 "but the input image "
                 "has tuple type '%s'.  They must be the same",
                 lookuppam.tuple_type, inpam.tuple_type);

    makeReverseLookupHash(&lookuppam, lookup, &lookupHash);

    doUnlookup(&inpam, lookupHash, lookuppam.width-1, stdout);

    pm_close(ifP);

    pnm_destroytuplehash(lookupHash);
    pnm_freepamarray(lookup, &lookuppam);
    
    return 0;
}
コード例 #29
0
ファイル: pamtopfm.c プロジェクト: gguillotte/netpbm-code
int
main(int argc, char **argv ) {

    struct cmdlineInfo cmdline;
    FILE* ifP;
    struct pam pam;
    pfmSample * pfmRowBuffer;
    unsigned int pfmSamplesPerRow;
    unsigned int pfmRow;
    tuplen ** tuplenArray;

    pnm_init(&argc, argv);

    machineEndianness = thisMachineEndianness();

    parseCommandLine(argc, argv, &cmdline);

    ifP = pm_openr(cmdline.inputFilespec);

    tuplenArray = pnm_readpamn(ifP, &pam, PAM_STRUCT_SIZE(tuple_type));

    writePfmHeader(stdout,
                   makePfmHeader(&pam, cmdline.scale, cmdline.endian));

    pfmSamplesPerRow = pam.width * pam.depth;

    MALLOCARRAY_NOFAIL(pfmRowBuffer, pfmSamplesPerRow);

    /* PFMs are upside down like BMPs */
    for (pfmRow = 0; pfmRow < pam.height; ++pfmRow)
        writePfmRow(&pam, stdout, pfmRow, pfmSamplesPerRow,
                    tuplenArray, cmdline.endian, cmdline.scale,
                    pfmRowBuffer);

    pnm_freepamarrayn(tuplenArray, &pam);
    free(pfmRowBuffer);

    pm_close(stdout);
    pm_close(pam.file);

    return 0;
}
コード例 #30
0
static void
wipeoutTb(FILE * const ifP,
          FILE * const ofP) {

    /* top-bottom we have to read the full image */

    struct pam inpam, outpam;
    tuple ** tuples;
    
    tuples = pnm_readpam(ifP, &inpam, PAM_STRUCT_SIZE(tuple_type));

    outpam = inpam; 
    outpam.file = ofP;

    wipeImgByRow(inpam, tuples);

    pnm_writepam(&outpam, tuples);
       
    pnm_freepamarray(tuples, &inpam);
}