예제 #1
0
int
main(int argc, const char *argv[]) {

    struct cmdlineInfo cmdline;
    FILE * ifP;   
        /* The program's regular input file.  Could be a seekable copy of
           it in a temporary file.
        */
    FILE * bdfP;
        /* The border file.  NULL if none. */
    int eof;    /* no more images in input stream */
    int beof;   /* no more images in borderfile stream */

    pm_proginit(&argc, argv);

    parseCommandLine(argc, argv, &cmdline);

    ifP = pm_openr_seekable(cmdline.inputFilespec);

    if (cmdline.borderfile)
        bdfP = pm_openr(cmdline.borderfile);
    else
        bdfP = NULL;

    eof = beof = FALSE;
    while (!eof) {
        cropOneImage(cmdline, ifP, bdfP, stdout);

        pnm_nextimage(ifP, &eof);

        if (bdfP) {
            pnm_nextimage(bdfP, &beof);
            
            if (eof != beof) {
                if (!eof)
                    pm_error("Input file has more images than border file."); 
                else
                    pm_error("Border file has more images than image file.");
            }
        }
    }

    pm_close(stdout);
    pm_close(ifP);
    if (bdfP)
        pm_close(bdfP);

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

    struct cmdlineInfo cmdline;

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

    pm_proginit(&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;
}
예제 #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
파일: 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;
}
예제 #5
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;
}
예제 #6
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;
}
예제 #7
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;
}
예제 #8
0
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);
    }
}
예제 #9
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);
    }
}
예제 #10
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;
}
예제 #11
0
static void
computeHistogram(FILE *         const ifP,
                 int *          const formatP,
                 struct pam *   const freqPamP,
                 tupletable2 *  const colorfreqtableP) {
/*----------------------------------------------------------------------------
  Make a histogram of the colors in the image stream in the file '*ifP'.
  
  Return as *freqPamP a description of the tuple values in the histogram.
  Only the fields of *freqPamP that describe individual tuples are
  meaningful (depth, maxval, tuple type);

  As a fringe benefit, also return the format of the input file as
  *formatP.
----------------------------------------------------------------------------*/
    unsigned int imageSeq;
    struct pam firstPam;
    tuplehash tuplehash;
    unsigned int colorCount;
    int eof;
    
    pm_message("making histogram...");

    tuplehash = pnm_createtuplehash();
    colorCount = 0;

    eof = FALSE;

    for (imageSeq = 0; !eof; ++imageSeq) {
        struct pam inpam;
        
        pm_message("Scanning image %u", imageSeq);

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

        if (imageSeq == 0)
            firstPam = inpam;
        else
            validateCompatibleImage(&inpam, &firstPam, imageSeq);
    
        addImageColorsToHash(&inpam, tuplehash, &colorCount);

        pm_message("%u colors so far", colorCount);

        pnm_nextimage(ifP, &eof);
    }
    colorfreqtableP->table =
        pnm_tuplehashtotable(&firstPam, tuplehash, colorCount);
    colorfreqtableP->size = colorCount;

    pnm_destroytuplehash(tuplehash);

    pm_message("%u colors found", colorfreqtableP->size);
    
    freqPamP->size   = sizeof(*freqPamP);
    freqPamP->len    = PAM_STRUCT_SIZE(tuple_type);
    freqPamP->maxval = firstPam.maxval;
    freqPamP->bytes_per_sample = pnm_bytespersample(freqPamP->maxval);
    freqPamP->depth  = firstPam.depth;
    STRSCPY(freqPamP->tuple_type, firstPam.tuple_type);
    
    *formatP = firstPam.format;
}
예제 #12
0
int
main(int argc, const char *argv[]) {
    CmdlineInfo cmdline;
    const char * inputFileDescription;
    FILE * ifP;
    TIFF * tifP;
    int ofd;
    int eof;
    unsigned int imageSeq;
    
    pm_proginit(&argc, argv);

    parseCommandLine(argc, argv, &cmdline);

    ifP = pm_openr_seekable(cmdline.inputFileName);

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

    switch (cmdline.writeMethod) {
    case DIRECT_APPEND:
        createTiffGeneratorDirect(cmdline.output, MUST_EXIST,  &tifP, &ofd);
        break;
    case DIRECT_CREATE:
        createTiffGeneratorDirect(cmdline.output, MAY_CREATE,  &tifP, &ofd);
        break;
    case TMPFILE:
        createTiffGeneratorTmpfile(&tifP, &ofd);
        break;
    }

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

    while (!eof) {
        bool success;

        pnm_nextimage(ifP, &eof);

        if (!eof) {
            if (imageSeq > 0)
                validateReadableOutputFile(ofd);

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

            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(cmdline.writeMethod, tifP, ofd);
    pm_close(ifP);

    return 0;
}