예제 #1
0
파일: pamfile.c 프로젝트: jhbsz/DIR-850L_A1
int
main(int argc, char *argv[]) {

    struct cmdlineInfo cmdline;

    pnm_init(&argc, argv);

    parseCommandLine(argc, argv, &cmdline);

    if (cmdline.inputFileCount == 0)
        describeOneFile("stdin", stdin, cmdline.allimages || cmdline.count,
                        cmdline.count, cmdline.comments);
    else {
        unsigned int i;
        for (i = 0; i < cmdline.inputFileCount; ++i) {
            FILE * ifP;
            ifP = pm_openr(cmdline.inputFilespec[i]);
            describeOneFile(cmdline.inputFilespec[i], ifP, 
                            cmdline.allimages || cmdline.count,
                            cmdline.count, cmdline.comments);
            pm_close(ifP);
	    }
	}
    
    return 0;
}
예제 #2
0
int
main(int argc, char *argv[]) {

    struct cmdlineInfo cmdline;      /* Parsed command line */
    FILE * ifP;

    /* Parse the command line. */
    pnm_init(&argc, argv);

    parseCommandLine(argc, argv, &cmdline);

    if (cmdline.verbose)
        reportParameters(cmdline);

    srand(cmdline.randomseed);

    ifP = pm_openr(cmdline.inputFilespec);

    /* Produce a stereogram. */
    produceStereogram(ifP, cmdline);

    pm_close(ifP);

    return 0;
}
예제 #3
0
int
main(int argc, char *argv[]) {

    FILE* ifP;
    int eof;  /* No more images in input */
    unsigned int image_seq;  
        /* Sequence of current image in input file.  First = 0 */

    pnm_init( &argc, argv );

    parse_command_line(argc, argv, &cmdline);

    ifP = pm_openr(cmdline.input_file);

    eof = FALSE;
    for (image_seq = 0; !eof; image_seq++) {
        const char *output_file_name;  /* malloc'ed */
        compute_output_name(cmdline.output_file_pattern, cmdline.padname, 
                            image_seq,
                            &output_file_name);
        pm_message("WRITING %s\n", output_file_name);
        extract_one_image(ifP, output_file_name);
        strfree(output_file_name);
        pnm_nextimage(ifP, &eof);
    }

    pm_close(ifP);
    
    return 0;
}
예제 #4
0
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;
}
예제 #5
0
파일: pamcut.c 프로젝트: Eleanor66613/CS131
int
main(int argc, char *argv[]) {

    FILE * const ofP = stdout;

    struct cmdlineInfo cmdline;
    FILE* ifP;
    bool eof;

    pnm_init(&argc, argv);

    parseCommandLine(argc, argv, &cmdline);

    ifP = pm_openr(cmdline.inputFilespec);

    eof = FALSE;
    while (!eof) {
        cutOneImage(ifP, cmdline, ofP);
        pnm_nextimage(ifP, &eof);
    }

    pm_close(ifP);
    pm_close(ofP);
    
    return 0;
}
예제 #6
0
int
main(int argc, char ** argv) {

    struct cmdlineInfo cmdline;
    FILE * convFileP;
    const char * tempfileName;

    pnm_init(&argc, argv);

    parseCommandLine(argc, argv, &cmdline);

    if (cmdline.dump)
        convFileP = pm_openw(cmdline.dump);
    else
        pm_make_tmpfile(&convFileP, &tempfileName);
        
    writeConvolutionImage(convFileP, cmdline.width, cmdline.height,
                          PGM_FORMAT);

    pm_close(convFileP);

    if (cmdline.dump) {
        /* We're done.  Convolution image is in user's file */
    } else {
        pm_system_lp("pnmconvol", NULL, NULL, NULL, NULL,
                     "pnmconvol", tempfileName, cmdline.inputFilespec, NULL);

        unlink(tempfileName);
        strfree(tempfileName);
    }
    return 0;
}
예제 #7
0
파일: pampick.c 프로젝트: jhbsz/DIR-850L_A1
int
main(int argc, char *argv[]) {

    struct cmdlineInfo cmdline;

    bool eof;  /* No more images in input */
    unsigned int imageSeq;  
        /* Sequence of current image in input file.  First = 0 */

    pnm_init(&argc, argv);

    parseCommandLine(argc, argv, &cmdline);
    
    eof = FALSE;
    for (imageSeq = 0; !eof; ++imageSeq) {
        if (isMemberOfUintSet(&cmdline.imageSeqList, imageSeq)) {
            pm_message("Extracting Image #%u", imageSeq);

            extractOneImage(stdin, stdout);
        } else
            extractOneImage(stdin, NULL);

        pnm_nextimage(stdin, &eof);
    }

    failIfUnpickedImages(&cmdline.imageSeqList, imageSeq);

    destroyCmdline(&cmdline);

    pm_close(stdin);
    pm_close(stdout);
    
    return 0;
}
예제 #8
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;
}
예제 #9
0
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;
}
예제 #10
0
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;
}
예제 #11
0
int
main(int argc, char *argv[]) {
    struct cmdlineInfo cmdline;
    const char * inputFileDescription;
    FILE* ifP;
    TIFF* tifP;
    bool eof;
    unsigned int imageSeq;

    pnm_init(&argc, argv);

    parseCommandLine(argc, argv, &cmdline);
    
    ifP = pm_openr_seekable(cmdline.input_filespec);

    if (streq(cmdline.input_filespec, "-"))
        inputFileDescription = "Standard Input";
    else 
        inputFileDescription = cmdline.input_filespec;

    if (cmdline.append)
        validateReadableStdout();

    createTiffGenerator(STDOUT_FILENO, "Standard Output", cmdline.append,
                        &tifP);

    eof = FALSE;  /* initial assumption */
    imageSeq = 0;

    while (!eof) {
        bool success;

        if (cmdline.verbose)
            pm_message("Converting Image %u", imageSeq);

        pnm_nextimage(ifP, &eof);

        if (!eof) {
            if (imageSeq > 0)
                validateReadableStdout();

            convertImage(ifP, tifP, inputFileDescription, cmdline);
            
            success = TIFFWriteDirectory(tifP);
            if (!success)
                pm_error("Unable to write TIFF image %u to file.  "
                         "tifWriteDirectory() failed.", imageSeq);
            ++imageSeq;
        }
    }

    destroyTiffGenerator(tifP);
    pm_close(ifP);

    return 0;
}
예제 #12
0
int
main(int argc, char * argv[]) {

    FILE* ifp;
    const char *name;  /* malloc'ed */
    struct cmdline_info cmdline;

    pnm_init( &argc, argv );

    parseCommandLine(argc, argv, &cmdline);

    verbose = cmdline.verbose;

    ifp = pm_openr(cmdline.input_filespec);

    if (strcmp(cmdline.input_filespec, "-") == 0 )
        name = strdup("noname");
    else
        name = basebasename(cmdline.input_filespec);
    {
        int eof;  /* There are no more images in the input file */
        unsigned int image_seq;

        /* I don't know if this works at all for multi-image PNM input.
           Before July 2000, it ignored everything after the first image,
           so this probably is at least as good -- it should be identical
           for a single-image file, which is the only kind which was legal
           before July 2000.

           Maybe there needs to be some per-file header and trailers stuff
           in the Postscript program, with some per-page header and trailer
           stuff inside.  I don't know Postscript.  - Bryan 2000.06.19.
        */

        eof = FALSE;  /* There is always at least one image */
        for (image_seq = 0; !eof; image_seq++) {
            convertPage(ifp, cmdline.mustturn, cmdline.canturn, 
                        cmdline.psfilter,
                        cmdline.rle, cmdline.flate, cmdline.ascii85, 
                        cmdline.setpage, cmdline.showpage,
                        cmdline.center, cmdline.scale,
                        cmdline.dpiX, cmdline.dpiY,
                        cmdline.width, cmdline.height, 
                        cmdline.imagewidth, cmdline.imageheight, 
                        cmdline.equalpixels, name, 
                        cmdline.dict, cmdline.vmreclaim,
                        cmdline.levelSpec, cmdline.level);
            pnm_nextimage(ifp, &eof);
        }
    }
    strfree(name);

    pm_close(ifp);
    
    return 0;
}
예제 #13
0
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;
}
예제 #14
0
pnm
pnm_dup(pnm self)
{
    pnm result = pnm_init(self);

    memcpy(result->image, 
	   self->image, 
	   3*self->width*self->height*sizeof(unsigned short));

    return result;
}
예제 #15
0
int
main(int argc, char **argv) {

    FILE * ofP;
    struct cmdlineInfo cmdline;
    struct jpeg_decompress_struct cinfo;
    struct jpeg_error_mgr jerr;
    struct sourceManager * sourceManagerP;

    pnm_init(&argc, argv);

    parseCommandLine(argc, argv, &cmdline);

    if (cmdline.exif_filespec && streq(cmdline.exif_filespec, "-"))
        /* He's got exif going to stdout, so there can be no image output */
        ofP = NULL;
    else
        ofP = stdout;

    displayComments = cmdline.comments;

    /* Initialize the JPEG decompression object with default error handling. */
    cinfo.err = jpeg_std_error(&jerr);
    jpeg_create_decompress(&cinfo);

    if (cmdline.trace_level == 0 && cmdline.verbose) 
        cinfo.err->trace_level = 1;
    else 
        cinfo.err->trace_level = cmdline.trace_level;
    
    saveMarkers(&cinfo);

    sourceManagerP = dsCreateSource(cmdline.input_filespec);

    cinfo.src = dsJpegSourceMgr(sourceManagerP);

    convertImages(ofP, cmdline, &cinfo, sourceManagerP);

    jpeg_destroy_decompress(&cinfo);

    if (ofP) {
        int rc;
        rc = fclose(ofP);
        if (rc == EOF) 
            pm_error("Error writing output file.  Errno = %s (%d).",
                     strerror(errno), errno);
    }

    dsDestroySource(sourceManagerP);

    free(cmdline.input_filespec);
  
    exit(jerr.num_warnings > 0 ? EXIT_WARNING : EXIT_SUCCESS);
}
예제 #16
0
int
main(int argc, char **argv ) {

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

    machineEndianness = thisMachineEndianness();

    pnm_init(&argc, argv);

    parseCommandLine(argc, argv, &cmdline);

    ifP = pm_openr(cmdline.inputFilespec);

    readPfmHeader(ifP, &pfmHeader);

    if (cmdline.verbose)
        dumpPfmHeader(pfmHeader);

    initPam(&pam, 
            pfmHeader.width, pfmHeader.height, pfmHeader.color,
            cmdline.maxval);

    tuplenArray = pnm_allocpamarrayn(&pam);

    pfmSamplesPerRow = pam.width * pam.depth;
    
    MALLOCARRAY_NOFAIL(pfmRowBuffer, pfmSamplesPerRow);

    /* PFMs are upside down like BMPs */
    for (pfmRow = 0; pfmRow < pam.height; ++pfmRow)
        makePamRow(&pam, ifP, pfmRow, pfmSamplesPerRow,
                   tuplenArray, pfmHeader.endian, pfmHeader.scaleFactor,
                   pfmRowBuffer);

    pnm_writepamn(&pam, tuplenArray);

    pnm_freepamarrayn(tuplenArray, &pam);
    free(pfmRowBuffer);
    
    pm_close(ifP);
    pm_close(pam.file);

    return 0;
}
예제 #17
0
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;
}
예제 #18
0
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;
}
예제 #19
0
파일: pnmtohex.c 프로젝트: shugaoye/fbtest
int main(int argc, char *argv[])
{
    pnm_init(&argc, argv);

    if (argc < 3 || !(argc % 2)) {
	fprintf(stderr, "Usage: %s <filename> <name> ...\n", argv[0]);
	exit(1);
    }

    while (argc >= 2) {
	convert_image(argv[1], argv[2]);
	argv += 2;
	argc -= 2;
    }

    exit(0);
}
예제 #20
0
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;
}
예제 #21
0
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;
}
예제 #22
0
int
main(int argc, char * argv[]) {

    struct cmdlineInfo cmdline;
    FILE * ifP;
    xelval lmin, lmax;
    gray * lumamap;           /* Luminosity map */
    unsigned int * lumahist;  /* Histogram of luminosity values */
    int rows, cols;           /* Rows, columns of input image */
    xelval maxval;            /* Maxval of input image */
    int format;               /* Format indicator (PBM/PGM/PPM) */
    xel ** xels;              /* Pixel array */
    unsigned int pixelCount;

    pnm_init(&argc, argv);

    parseCommandLine(argc, argv, &cmdline);

    ifP = pm_openr(cmdline.inputFileName);

    xels = pnm_readpnm(ifP, &cols, &rows, &maxval, &format);

    pm_close(ifP);

    computeLuminosityHistogram(xels, rows, cols, maxval, format,
                               cmdline.gray, &lumahist, &lmin, &lmax,
                               &pixelCount);

    getMapping(cmdline.rmap, lumahist, maxval, pixelCount, &lumamap);

    if (cmdline.verbose)
        reportMap(lumahist, maxval, lumamap);

    remap(xels, cols, rows, maxval, format, !!cmdline.gray, lumamap);

    pnm_writepnm(stdout, xels, cols, rows, maxval, format, 0);

    if (cmdline.wmap)
        writeMap(cmdline.wmap, lumamap, maxval);

    pgm_freerow(lumamap);

    return 0;
}
예제 #23
0
int
main(int argc, char * argv[] ) {

    struct cmdlineInfo cmdline;
    FILE * ifP;
    int format;
    struct pam colormapPam;
    struct pam outpam;
    tuple ** colormapRaster;
    tupletable2 colormap;

    pnm_init(&argc, argv);

    parseCommandLine(argc, argv, &cmdline);

    ifP = pm_openr(cmdline.inputFilespec);

    computeColorMapFromInput(ifP,
                             cmdline.allcolors, cmdline.newcolors, 
                             cmdline.methodForLargest, 
                             cmdline.methodForRep,
                             &format, &colormapPam, &colormap);

    pm_close(ifP);

    colormapToImage(format, &colormapPam, colormap,
                    cmdline.sort, cmdline.square, &outpam, &colormapRaster);

    if (cmdline.verbose)
        pm_message("Generating %u x %u image", outpam.width, outpam.height);

    outpam.file = stdout;
    
    pnm_writepam(&outpam, colormapRaster);
    
    pnm_freetupletable2(&colormapPam, colormap);

    pnm_freepamarray(colormapRaster, &outpam);

    pm_close(stdout);

    return 0;
}
예제 #24
0
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;
}
예제 #25
0
int
main(int argc, char **argv)
{
    struct cmdlineInfo cmdline;
    FILE *ifP;
    struct pam inpam;
    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);
    
    ifP = pm_openr(cmdline.inputFilename);
    
    pnm_readpaminit(ifP, &inpam, PAM_STRUCT_SIZE(tuple_type));
    
    convertToJasperImage(&inpam, &jasperP);
    
    writeJpc(jasperP, cmdline, stdout);
    
	jas_image_destroy(jasperP);

    pm_close(ifP);

    pm_close(stdout);
    
    return 0;
}
예제 #26
0
int
main(int argc, char *argv[]) {

    struct cmdlineInfo cmdline;

    FILE * ifP;
    bool eof;  /* No more images in input */
    unsigned int imageSeq;  
        /* Sequence of current image in input file.  First = 0 */

    pnm_init(&argc, argv);

    parseCommandLine(argc, argv, &cmdline);
    
    ifP = pm_openr(cmdline.inputFileName);

    eof = FALSE;
    for (imageSeq = 0; !eof; ++imageSeq) {
        FILE * ofP;
        const char * outputFileName;  /* malloc'ed */

        computeOutputName(cmdline.outputFilePattern, cmdline.padname, 
                          imageSeq,
                          &outputFileName);
        pm_message("WRITING %s", outputFileName);

        ofP = pm_openw(outputFileName);
        extractOneImage(ifP, ofP);

        pm_close(ofP);
        strfree(outputFileName);

        pnm_nextimage(ifP, &eof);
    }
    pm_close(ifP);
    
    return 0;
}
예제 #27
0
int 
main (int argc, char **argv)
{
   char const         **image_template; /* template for input image files */
   char                *wfa_name;   /* filename of output WFA */
   float            quality;    /* approximation quality */
   fiasco_c_options_t  *options;    /* additional coder options */
   
   pnm_init(&argc, argv);
   
   init_error_handling (argv [0]);

   checkargs (argc, argv, &image_template, &wfa_name, &quality, &options);

   if (fiasco_coder (image_template, wfa_name, quality, options))
      return 0;
   else
   {
       fprintf (stderr, "%s", fiasco_get_error_message ());
      fprintf (stderr, "\n");
      return 1;
   }
}
예제 #28
0
int
main(int argc, char **argv) {

    struct cmdlineInfo cmdline;
    FILE * ifP;
    xmlTextReaderPtr xmlReaderP;

    pnm_init(&argc, argv);

    xmlInitParser();

    LIBXML_TEST_VERSION;

    parseCommandLine(argc, argv, &cmdline);
    
    traceDraw = cmdline.trace;

    ifP = pm_openr(cmdline.inputFileName);

    xmlReaderP = xmlReaderForFd(fileno(ifP), "SVG_IMAGE", NULL, 0);

    if (xmlReaderP) {
        processDocument(xmlReaderP, stdout);

        /* xmlTextReaderIsValid() does not appear to work.  It always says
           the document is invalid
        */

        xmlFreeTextReader(xmlReaderP);
    } else
        pm_error("Failed to create xmlReader");

    xmlCleanupParser();

    return 0;
}
예제 #29
0
int
main(int argc, char *argv[]) {

    struct cmdlineInfo cmdline;
    struct pam inpam;
    FILE * ifP;
    pm_filepos rasterpos;
    tuple backgroundColor;
    const unsigned char * const * pi;
    
    pnm_init(&argc, argv);

    parseCommandLine(argc, argv, &cmdline);

    ifP = pm_openr_seekable(cmdline.inputFileName);

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

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

    determineBackgroundColor(&inpam, cmdline.verbose, &backgroundColor);

    pm_seek2(ifP, &rasterpos, sizeof(rasterpos));

    findBackgroundPixels(&inpam, backgroundColor, cmdline.verbose, &pi);

    writeOutput(&inpam, pi);

    destroyPi(pi, inpam.height);

    pm_close(ifP);

    pnm_freepamtuple(backgroundColor);
    
    return 0;
}
예제 #30
0
파일: pnmcut.c 프로젝트: jhbsz/DIR-850L_A1
int
main(int argc, char *argv[]) {

    FILE* ifp;
    xel* xelrow;  /* Row from input image */
    xel* output_row;  /* Row of output image */
    xelval maxval;
    int rows, cols, format, row;
    int leftcol, rightcol, toprow, bottomrow;
    int output_cols;  /* Width of output image */
    struct cmdline_info cmdline;

    pnm_init( &argc, argv );

    parse_command_line(argc, argv, &cmdline);

    ifp = pm_openr(cmdline.input_filespec);

    pnm_readpnminit(ifp, &cols, &rows, &maxval, &format);
    xelrow = pnm_allocrow(cols);

    black_xel = pnm_blackxel(maxval, format);

    compute_cut_bounds(cols, rows, 
                       cmdline.left, cmdline.right, 
                       cmdline.top, cmdline.bottom, 
                       cmdline.width, cmdline.height, 
                       &leftcol, &rightcol, &toprow, &bottomrow);

    if (!cmdline.pad)
        reject_out_of_bounds(cols, rows, leftcol, rightcol, toprow, bottomrow);

    if (cmdline.verbose) {
        pm_message("Image goes from Row 0, Column 0 through Row %d, Column %d",
                   rows-1, cols-1);
        pm_message("Cutting from Row %d, Column %d through Row %d Column %d",
                   toprow, leftcol, bottomrow, rightcol);
    }

    output_cols = rightcol-leftcol+1;
    output_row = pnm_allocrow(output_cols);
    
    pnm_writepnminit(stdout, output_cols, bottomrow-toprow+1, 
                     maxval, format, 0 );

    /* Implementation note:  If speed is ever an issue, we can probably
       speed up significantly the non-padding case by writing a special
       case loop here for the case cmdline.pad == FALSE.
       */

    /* Write out top padding */
    write_black_rows(stdout, 0 - toprow, output_cols, output_row, 
                     maxval, format);
    
    /* Read input and write out rows extracted from it */
    for (row = 0; row < rows; row++) {
        pnm_readpnmrow(ifp, xelrow, cols, maxval, format);
        if (row >= toprow && row <= bottomrow) {
            int col;
            /* Put in left padding */
            for (col = leftcol; col < 0; col++) { 
                output_row[col-leftcol] = black_xel;
            }
            /* Put in extracted columns */
            for (col = MAX(leftcol, 0); col <= MIN(rightcol, cols-1); col++) {
                output_row[col-leftcol] = xelrow[col];
            }
            /* Put in right padding */
            for (col = MAX(cols, leftcol); col <= rightcol; col++) {
                output_row[col-leftcol] = black_xel;
            }
            pnm_writepnmrow(stdout, output_row, output_cols, 
                            maxval, format, 0);
        }
    }
    /* Note that we may be tempted just to quit after reaching the bottom
       of the extracted image, but that would cause a broken pipe problem
       for the process that's feeding us the image.
       */
    /* Write out bottom padding */
    write_black_rows(stdout, bottomrow - (rows-1), output_cols, output_row, 
                     maxval, format);

    pnm_freerow(output_row);
    pnm_freerow(xelrow);
    pm_close(ifp);
    pm_close(stdout);
    
    exit( 0 );
}