コード例 #1
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;
}
コード例 #2
0
ファイル: pamtotiff.c プロジェクト: moseymosey/netpbm
static void
analyzeColorsInRgbInput(struct pam *        const pamP,
                        struct cmdlineInfo  const cmdline,
                        int                 const maxcolors, 
                        tupletable *        const chvP, 
                        unsigned int *      const colorsP, 
                        bool *              const grayscaleP) {
/*----------------------------------------------------------------------------
   Same as analyzeColors(), except assuming input image has R/G/B tuples.
-----------------------------------------------------------------------------*/
    if (cmdline.color && cmdline.truecolor) {
        *chvP = NULL;
        *grayscaleP = FALSE;
    } else {
        tupletable chv;
        bool grayscale;

        pm_message("computing colormap...");
        chv = pnm_computetuplefreqtable2(pamP, NULL, maxcolors,
                                         pamP->maxval,
                                         colorsP);
        if (chv == NULL) {
            grayscale = FALSE;
        } else {
            unsigned int i;
            pm_message("%u color%s found", 
                       *colorsP, *colorsP == 1 ? "" : "s");
            grayscale = TRUE;  /* initial assumption */
            for (i = 0; i < *colorsP && grayscale; ++i) {
                if (!pnm_rgbtupleisgray(chv[i]->tuple))
                    grayscale = FALSE;
            }
        }
        *grayscaleP = grayscale;

        if (grayscale || cmdline.truecolor) {
            *chvP = NULL;
            if (chv)
                pnm_freetupletable(pamP, chv);
        } else {
            /* He wants a colormap.  But can we give it to him? */
            if (chv)
                *chvP = chv;
            else {
                pm_message("Too many colors - "
                           "proceeding to write a 24-bit RGB file.");
                pm_message("If you want an 8-bit palette file, "
                           "try doing a 'pnmquant %d'.",
                           maxcolors);
                *chvP = NULL;
            }
        }
    }
}
コード例 #3
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;
}
コード例 #4
0
ファイル: pamtotiff.c プロジェクト: moseymosey/netpbm
static void
convertImage(FILE *             const ifP,
             TIFF *             const tifP,
             const char *       const inputFileDescription,
             struct cmdlineInfo const cmdline) {

    tupletable chv;
    tuplehash cht;
    unsigned short ** tiffColorMap;  /* malloc'ed */
    struct pam pam;
    unsigned int colors;
    bool grayscale;
    unsigned short photometric;
    unsigned short samplesperpixel;
    unsigned short bitspersample;
    unsigned short tiff_maxval;
    /* This is the maxval of the samples in the tiff file.  It is 
       determined solely by the bits per sample ('bitspersample').
       */
    int bytesperrow;
    pm_filepos rasterPos;

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

    pm_tell2(ifP, &rasterPos, sizeof(rasterPos));

    analyzeColors(&pam, cmdline, MAXCOLORS, &chv, &colors, &grayscale);

    /* Go back to beginning of raster */
    pm_seek2(ifP, &rasterPos, sizeof(rasterPos));  

    /* Figure out TIFF parameters. */

    computeRasterParm(&pam, chv, colors, grayscale, 
                      cmdline.compression,
                      cmdline.minisblack, cmdline.miniswhite,
                      cmdline.indexsizeAllowed,
                      &samplesperpixel, &bitspersample, &photometric,
                      &bytesperrow);

    tiff_maxval = pm_bitstomaxval(bitspersample);

    if (!chv) {
        cht = NULL;
        tiffColorMap = NULL;
    } else {
        createTiffColorMap(&pam, bitspersample, chv, colors, &tiffColorMap);

        /* Convert color vector to color hash table, for fast lookup. */
        cht = pnm_computetupletablehash(&pam, chv, colors);
        pnm_freetupletable(&pam, chv);
    }

    setTiffFields(tifP, cmdline, &pam, bitspersample, photometric,
                  samplesperpixel, tiffColorMap, inputFileDescription,
                  cmdline.taglist);

    writeScanLines(&pam, tifP, cht,
                   tiff_maxval, bitspersample, photometric, bytesperrow, 
                   cmdline.fillorder);

    if (tiffColorMap)
        destroyTiffColorMap(&pam, tiffColorMap);
}
コード例 #5
0
ファイル: libpammap.c プロジェクト: jhbsz/DIR-850L_A1
void
pnm_freetupletable2(struct pam * const pamP,
                    tupletable2  const tupletable) {

    pnm_freetupletable(pamP, tupletable.table);
}