本文整理汇总了C++中pixRead函数的典型用法代码示例。如果您正苦于以下问题:C++ pixRead函数的具体用法?C++ pixRead怎么用?C++ pixRead使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了pixRead函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: main
int main(int argc, char** argv) {
const char* lang = "eng";
const char* image = NULL;
const char* outputbase = NULL;
const char* datapath = NULL;
bool list_langs = false;
bool print_parameters = false;
int arg_i = 1;
tesseract::PageSegMode pagesegmode = tesseract::PSM_AUTO;
tesseract::OcrEngineMode enginemode = tesseract::OEM_DEFAULT;
/* main() calls functions like ParseArgs which call exit().
* This results in memory leaks if vars_vec and vars_values are
* declared as auto variables (destructor is not called then). */
static GenericVector<STRING> vars_vec;
static GenericVector<STRING> vars_values;
#if !defined(DEBUG)
// Disable debugging and informational messages from Leptonica.
setMsgSeverity(L_SEVERITY_WARNING);
#endif
#if defined(HAVE_TIFFIO_H) && defined(_WIN32)
/* Show libtiff warnings on console (not in GUI). */
TIFFSetWarningHandler(Win32WarningHandler);
#endif /* HAVE_TIFFIO_H && _WIN32 */
ParseArgs(argc, argv, &lang, &image, &outputbase, &datapath, &list_langs,
&print_parameters, &vars_vec, &vars_values, &arg_i, &pagesegmode,
&enginemode);
bool banner = false;
if (outputbase != NULL && strcmp(outputbase, "-") &&
strcmp(outputbase, "stdout")) {
banner = true;
}
PERF_COUNT_START("Tesseract:main")
tesseract::TessBaseAPI api;
api.SetOutputName(outputbase);
int init_failed = api.Init(datapath, lang, enginemode, &(argv[arg_i]),
argc - arg_i, &vars_vec, &vars_values, false);
if (init_failed) {
fprintf(stderr, "Could not initialize tesseract.\n");
exit(1);
}
SetVariablesFromCLArgs(&api, argc, argv);
if (list_langs) {
PrintLangsList(&api);
exit(0);
}
if (print_parameters) {
FILE* fout = stdout;
fprintf(stdout, "Tesseract parameters:\n");
api.PrintVariables(fout);
api.End();
exit(0);
}
FixPageSegMode(&api, pagesegmode);
if (pagesegmode == tesseract::PSM_AUTO_ONLY) {
int ret_val = 0;
Pix* pixs = pixRead(image);
if (!pixs) {
fprintf(stderr, "Cannot open input file: %s\n", image);
exit(2);
}
api.SetImage(pixs);
tesseract::Orientation orientation;
tesseract::WritingDirection direction;
tesseract::TextlineOrder order;
float deskew_angle;
tesseract::PageIterator* it = api.AnalyseLayout();
if (it) {
it->Orientation(&orientation, &direction, &order, &deskew_angle);
tprintf(
"Orientation: %d\nWritingDirection: %d\nTextlineOrder: %d\n"
"Deskew angle: %.4f\n",
orientation, direction, order, deskew_angle);
} else {
ret_val = 1;
}
delete it;
pixDestroy(&pixs);
exit(ret_val);
}
// set in_training_mode to true when using one of these configs:
// ambigs.train, box.train, box.train.stderr, linebox, rebox
//.........这里部分代码省略.........
示例2: main
int main(int argc,
char **argv)
{
l_int32 i, j, sindex, wb, hb, ws, hs, delx, dely, x, y, y0;
PIX *pixs, *pixb, *pix1, *pix2;
PIXA *pixa;
PIXCMAP *cmap;
setLeptDebugOK(1);
lept_mkdir("lept/blend");
pixa = pixaCreate(0);
pixs = pixRead("rabi.png"); /* blendee */
pixb = pixRead("weasel4.11c.png"); /* blender */
/* Fade the blender */
pixcmapShiftIntensity(pixGetColormap(pixb), FADE_FRACTION);
/* Downscale the input */
wb = pixGetWidth(pixb);
hb = pixGetHeight(pixb);
pix1 = pixScaleToGray4(pixs);
/* Threshold to 5 levels, 4 bpp */
ws = pixGetWidth(pix1);
hs = pixGetHeight(pix1);
pix2 = pixThresholdTo4bpp(pix1, 5, 1);
pixaAddPix(pixa, pix2, L_COPY);
pixaAddPix(pixa, pixb, L_COPY);
cmap = pixGetColormap(pix2);
pixcmapWriteStream(stderr, cmap);
/* Overwrite the white pixels (at sindex in pix2) */
pixcmapGetIndex(cmap, 255, 255, 255, &sindex);
/* Blend the weasel 20 times */
delx = ws / NX;
dely = hs / NY;
for (i = 0; i < NY; i++) {
y = 20 + i * dely;
if (y >= hs + hb)
continue;
for (j = 0; j < NX; j++) {
x = 30 + j * delx;
y0 = y;
if (j & 1) {
y0 = y + dely / 2;
if (y0 >= hs + hb)
continue;
}
if (x >= ws + wb)
continue;
pixBlendCmap(pix2, pixb, x, y0, sindex);
}
}
pixaAddPix(pixa, pix2, L_COPY);
cmap = pixGetColormap(pix2);
pixcmapWriteStream(stderr, cmap);
fprintf(stderr, "Writing to: /tmp/lept/blend/blendcmap.pdf\n");
pixaConvertToPdf(pixa, 0, 1.0, L_FLATE_ENCODE, 0, "cmap-blendtest",
"/tmp/lept/blend/blendcmap.pdf");
pixDestroy(&pixs);
pixDestroy(&pixb);
pixDestroy(&pix1);
pixDestroy(&pix2);
pixaDestroy(&pixa);
return 0;
}
示例3: main
/**********************************************************************
* main()
*
**********************************************************************/
int main(int argc, char **argv) {
const char* lang = "eng";
const char* image = NULL;
const char* outputbase = NULL;
const char* datapath = NULL;
bool list_langs = false;
bool print_parameters = false;
GenericVector<STRING> vars_vec, vars_values;
int arg_i = 1;
tesseract::PageSegMode pagesegmode = tesseract::PSM_AUTO;
ParseArgs(argc, argv,
&lang, &image, &outputbase, &datapath,
&list_langs, &print_parameters,
&vars_vec, &vars_values, &arg_i, &pagesegmode);
bool banner = false;
if (outputbase != NULL && strcmp(outputbase, "-") &&
strcmp(outputbase, "stdout")) {
banner = true;
}
PERF_COUNT_START("Tesseract:main")
tesseract::TessBaseAPI api;
api.SetOutputName(outputbase);
int init_failed = api.Init(datapath, lang, tesseract::OEM_DEFAULT,
&(argv[arg_i]), argc - arg_i, &vars_vec, &vars_values, false);
if (init_failed) {
fprintf(stderr, "Could not initialize tesseract.\n");
exit(1);
}
SetVariablesFromCLArgs(&api, argc, argv);
if (list_langs) {
PrintLangsList(&api);
exit(0);
}
if (print_parameters) {
FILE* fout = stdout;
fprintf(stdout, "Tesseract parameters:\n");
api.PrintVariables(fout);
api.End();
exit(0);
}
FixPageSegMode(&api, pagesegmode);
if (pagesegmode == tesseract::PSM_AUTO_ONLY) {
int ret_val = 0;
Pix* pixs = pixRead(image);
if (!pixs) {
fprintf(stderr, "Cannot open input file: %s\n", image);
exit(2);
}
api.SetImage(pixs);
tesseract::Orientation orientation;
tesseract::WritingDirection direction;
tesseract::TextlineOrder order;
float deskew_angle;
tesseract::PageIterator* it = api.AnalyseLayout();
if (it) {
it->Orientation(&orientation, &direction, &order, &deskew_angle);
tprintf("Orientation: %d\nWritingDirection: %d\nTextlineOrder: %d\n" \
"Deskew angle: %.4f\n",
orientation, direction, order, deskew_angle);
} else {
ret_val = 1;
}
delete it;
pixDestroy(&pixs);
exit(ret_val);
}
// set in_training_mode to true when using one of these configs:
// ambigs.train, box.train, box.train.stderr, linebox, rebox
bool b = false;
bool in_training_mode =
(api.GetBoolVariable("tessedit_ambigs_training", &b) && b) ||
(api.GetBoolVariable("tessedit_resegment_from_boxes", &b) && b) ||
(api.GetBoolVariable("tessedit_make_boxes_from_boxes", &b) && b);
tesseract::PointerVector<tesseract::TessResultRenderer> renderers;
if (in_training_mode) {
//.........这里部分代码省略.........
示例4: jbWordsInTextlines
/*!
* \brief jbWordsInTextlines()
*
* \param[in] dirin directory of input pages
* \param[in] reduction 1 for full res; 2 for half-res
* \param[in] maxwidth of word mask components, to be kept
* \param[in] maxheight of word mask components, to be kept
* \param[in] thresh on correlation; 0.80 is reasonable
* \param[in] weight for handling thick text; 0.6 is reasonable
* \param[out] pnatl numa with textline index for each component
* \param[in] firstpage 0-based
* \param[in] npages use 0 for all pages in dirin
* \return classer for the set of pages
*
* <pre>
* Notes:
* (1) This is a high-level function. See prog/jbwords for example
* of usage.
* (2) Typically, words can be found reasonably well at a resolution
* of about 150 ppi. For highest accuracy, you should use 300 ppi.
* Assuming that the input images are 300 ppi, use reduction = 1
* for finding words at full res, and reduction = 2 for finding
* them at 150 ppi.
* </pre>
*/
JBCLASSER *
jbWordsInTextlines(const char *dirin,
l_int32 reduction,
l_int32 maxwidth,
l_int32 maxheight,
l_float32 thresh,
l_float32 weight,
NUMA **pnatl,
l_int32 firstpage,
l_int32 npages)
{
char *fname;
l_int32 nfiles, i, w, h;
BOXA *boxa;
JBCLASSER *classer;
NUMA *nai, *natl;
PIX *pix;
PIXA *pixa;
SARRAY *safiles;
PROCNAME("jbWordsInTextlines");
if (!pnatl)
return (JBCLASSER *)ERROR_PTR("&natl not defined", procName, NULL);
*pnatl = NULL;
if (!dirin)
return (JBCLASSER *)ERROR_PTR("dirin not defined", procName, NULL);
if (reduction != 1 && reduction != 2)
return (JBCLASSER *)ERROR_PTR("reduction not in {1,2}", procName, NULL);
safiles = getSortedPathnamesInDirectory(dirin, NULL, firstpage, npages);
nfiles = sarrayGetCount(safiles);
/* Classify components */
classer = jbCorrelationInit(JB_WORDS, maxwidth, maxheight, thresh, weight);
classer->safiles = sarrayCopy(safiles);
natl = numaCreate(0);
*pnatl = natl;
for (i = 0; i < nfiles; i++) {
fname = sarrayGetString(safiles, i, L_NOCOPY);
if ((pix = pixRead(fname)) == NULL) {
L_WARNING("image file %d not read\n", procName, i);
continue;
}
pixGetDimensions(pix, &w, &h, NULL);
if (reduction == 1) {
classer->w = w;
classer->h = h;
} else { /* reduction == 2 */
classer->w = w / 2;
classer->h = h / 2;
}
pixGetWordsInTextlines(pix, reduction, JB_WORDS_MIN_WIDTH,
JB_WORDS_MIN_HEIGHT, maxwidth, maxheight,
&boxa, &pixa, &nai);
jbAddPageComponents(classer, pix, boxa, pixa);
numaJoin(natl, nai, 0, -1);
pixDestroy(&pix);
numaDestroy(&nai);
boxaDestroy(&boxa);
pixaDestroy(&pixa);
}
sarrayDestroy(&safiles);
return classer;
}
示例5: main
main(int argc,
char **argv)
{
l_float32 sum, sumx, sumy, diff;
L_DEWARP *dew;
L_DEWARPA *dewa;
FPIX *fpixs, *fpixs2, *fpixs3, *fpixs4, *fpixg, *fpixd;
FPIX *fpix1, *fpix2, *fpixt1, *fpixt2;
DPIX *dpix, *dpix2;
L_KERNEL *kel, *kelx, *kely;
PIX *pixs, *pixs2, *pixs3, *pixt, *pixd, *pixg, *pixb, *pixn;
PIX *pixt1, *pixt2, *pixt3, *pixt4, *pixt5, *pixt6;
PIXA *pixa;
PTA *ptas, *ptad;
L_REGPARAMS *rp;
if (regTestSetup(argc, argv, &rp))
return 1;
pixa = pixaCreate(0);
/* Gaussian kernel */
kel = makeGaussianKernel(5, 5, 3.0, 4.0);
kernelGetSum(kel, &sum);
if (rp->display) fprintf(stderr, "Sum for 2d gaussian kernel = %f\n", sum);
pixt = kernelDisplayInPix(kel, 41, 2);
regTestWritePixAndCheck(rp, pixt, IFF_PNG); /* 0 */
pixSaveTiled(pixt, pixa, 1, 1, 20, 8);
pixDestroy(&pixt);
/* Separable gaussian kernel */
makeGaussianKernelSep(5, 5, 3.0, 4.0, &kelx, &kely);
kernelGetSum(kelx, &sumx);
if (rp->display) fprintf(stderr, "Sum for x gaussian kernel = %f\n", sumx);
kernelGetSum(kely, &sumy);
if (rp->display) fprintf(stderr, "Sum for y gaussian kernel = %f\n", sumy);
if (rp->display) fprintf(stderr, "Sum for x * y gaussian kernel = %f\n",
sumx * sumy);
pixt = kernelDisplayInPix(kelx, 41, 2);
regTestWritePixAndCheck(rp, pixt, IFF_PNG); /* 1 */
pixSaveTiled(pixt, pixa, 1, 0, 20, 8);
pixDestroy(&pixt);
pixt = kernelDisplayInPix(kely, 41, 2);
regTestWritePixAndCheck(rp, pixt, IFF_PNG); /* 2 */
pixSaveTiled(pixt, pixa, 1, 0, 20, 8);
pixDestroy(&pixt);
/* Use pixRasterop() to generate source image */
pixs = pixRead("test8.jpg");
pixs2 = pixRead("karen8.jpg");
pixRasterop(pixs, 150, 125, 150, 100, PIX_SRC, pixs2, 75, 100);
regTestWritePixAndCheck(rp, pixs, IFF_JFIF_JPEG); /* 3 */
/* Convolution directly with pix */
pixt1 = pixConvolve(pixs, kel, 8, 1);
regTestWritePixAndCheck(rp, pixt1, IFF_JFIF_JPEG); /* 4 */
pixSaveTiled(pixt1, pixa, 1, 1, 20, 8);
pixt2 = pixConvolveSep(pixs, kelx, kely, 8, 1);
regTestWritePixAndCheck(rp, pixt2, IFF_JFIF_JPEG); /* 5 */
pixSaveTiled(pixt2, pixa, 1, 0, 20, 8);
/* Convolution indirectly with fpix, using fpixRasterop()
* to generate the source image. */
fpixs = pixConvertToFPix(pixs, 3);
fpixs2 = pixConvertToFPix(pixs2, 3);
fpixRasterop(fpixs, 150, 125, 150, 100, fpixs2, 75, 100);
fpixt1 = fpixConvolve(fpixs, kel, 1);
pixt3 = fpixConvertToPix(fpixt1, 8, L_CLIP_TO_ZERO, 1);
regTestWritePixAndCheck(rp, pixt3, IFF_JFIF_JPEG); /* 6 */
pixSaveTiled(pixt3, pixa, 1, 1, 20, 8);
fpixt2 = fpixConvolveSep(fpixs, kelx, kely, 1);
pixt4 = fpixConvertToPix(fpixt2, 8, L_CLIP_TO_ZERO, 1);
regTestWritePixAndCheck(rp, pixt4, IFF_JFIF_JPEG); /* 7 */
pixSaveTiled(pixt4, pixa, 1, 0, 20, 8);
pixDestroy(&pixs2);
fpixDestroy(&fpixs2);
fpixDestroy(&fpixt1);
fpixDestroy(&fpixt2);
/* Comparison of results */
pixCompareGray(pixt1, pixt2, L_COMPARE_ABS_DIFF, 0, NULL,
&diff, NULL, NULL);
if (rp->display)
fprintf(stderr, "Ave diff of pixConvolve and pixConvolveSep: %f\n",
diff);
pixCompareGray(pixt3, pixt4, L_COMPARE_ABS_DIFF, 0, NULL,
&diff, NULL, NULL);
if (rp->display)
fprintf(stderr, "Ave diff of fpixConvolve and fpixConvolveSep: %f\n",
diff);
pixCompareGray(pixt1, pixt3, L_COMPARE_ABS_DIFF, 0, NULL,
&diff, NULL, NULL);
if (rp->display)
fprintf(stderr, "Ave diff of pixConvolve and fpixConvolve: %f\n", diff);
pixCompareGray(pixt2, pixt4, L_COMPARE_ABS_DIFF, GPLOT_PNG, NULL,
&diff, NULL, NULL);
if (rp->display)
fprintf(stderr, "Ave diff of pixConvolveSep and fpixConvolveSep: %f\n",
diff);
pixDestroy(&pixt1);
//.........这里部分代码省略.........
示例6: main
int main(int argc,
char **argv)
{
char label[512];
l_int32 rval, gval, bval, w, h, i, j, rwhite, gwhite, bwhite, count;
l_uint32 pixel;
GPLOT *gplot1, *gplot2;
NUMA *naseq, *na;
NUMAA *naa1, *naa2;
PIX *pixs, *pixt, *pixt0, *pixt1, *pixt2;
PIX *pixr, *pixg, *pixb;
PIXA *pixa;
PIXCMAP *cmap;
static char mainName[] = "colorspacetest";
if (argc != 2)
return ERROR_INT(" Syntax: colorspacetest filein", mainName, 1);
if ((pixs = pixRead(argv[1])) == NULL)
return ERROR_INT("pixs not made", mainName, 1);
/* Generate colors by sampling hue with max sat and value.
* This was used to make the color strip 19-colors.png. */
pixa = pixaCreate(19);
for (i = 0; i < 19; i++) {
convertHSVToRGB((240 * i / 18), 255, 255, &rval, &gval, &bval);
composeRGBPixel(rval, gval, bval, &pixel);
pixt1 = pixCreate(50, 100, 32);
pixSetAllArbitrary(pixt1, pixel);
pixaAddPix(pixa, pixt1, L_INSERT);
}
pixt2 = pixaDisplayTiledInRows(pixa, 32, 1100, 1.0, 0, 0, 0);
pixDisplayWrite(pixt2, 1);
pixDestroy(&pixt2);
pixaDestroy(&pixa);
/* Colorspace conversion in rgb */
pixDisplayWrite(pixs, 1);
pixt = pixConvertRGBToHSV(NULL, pixs);
pixDisplayWrite(pixt, 1);
pixConvertHSVToRGB(pixt, pixt);
pixDisplayWrite(pixt, 1);
pixDestroy(&pixt);
/* Colorspace conversion on a colormap */
pixt = pixOctreeQuantNumColors(pixs, 25, 0);
pixDisplayWrite(pixt, 1);
cmap = pixGetColormap(pixt);
pixcmapWriteStream(stderr, cmap);
pixcmapConvertRGBToHSV(cmap);
pixcmapWriteStream(stderr, cmap);
pixDisplayWrite(pixt, 1);
pixcmapConvertHSVToRGB(cmap);
pixcmapWriteStream(stderr, cmap);
pixDisplayWrite(pixt, 1);
pixDestroy(&pixt);
/* Color content extraction */
pixColorContent(pixs, 0, 0, 0, 0, &pixr, &pixg, &pixb);
pixDisplayWrite(pixr, 1);
pixDisplayWrite(pixg, 1);
pixDisplayWrite(pixb, 1);
pixDestroy(&pixr);
pixDestroy(&pixg);
pixDestroy(&pixb);
/* Color content measurement */
pixa = pixaCreate(20);
naseq = numaMakeSequence(100, 5, 20);
naa1 = numaaCreate(6);
naa2 = numaaCreate(6);
for (i = 0; i < 6; i++) {
na = numaCreate(20);
numaaAddNuma(naa1, na, L_COPY);
numaaAddNuma(naa2, na, L_INSERT);
}
pixGetDimensions(pixs, &w, &h, NULL);
for (i = 0; i < 20; i++) {
rwhite = 100 + 5 * i;
gwhite = 200 - 5 * i;
bwhite = 150;
pixt0 = pixGlobalNormRGB(NULL, pixs, rwhite, gwhite, bwhite, 255);
pixaAddPix(pixa, pixt0, L_INSERT);
pixt1 = pixColorMagnitude(pixs, rwhite, gwhite, bwhite,
L_MAX_DIFF_FROM_AVERAGE_2);
for (j = 0; j < 6; j++) {
pixt2 = pixThresholdToBinary(pixt1, 30 + 10 * j);
pixInvert(pixt2, pixt2);
pixCountPixels(pixt2, &count, NULL);
na = numaaGetNuma(naa1, j, L_CLONE);
numaAddNumber(na, (l_float32)count / (l_float32)(w * h));
numaDestroy(&na);
pixDestroy(&pixt2);
}
pixDestroy(&pixt1);
pixt1 = pixColorMagnitude(pixs, rwhite, gwhite, bwhite,
L_MAX_MIN_DIFF_FROM_2);
for (j = 0; j < 6; j++) {
pixt2 = pixThresholdToBinary(pixt1, 30 + 10 * j);
pixInvert(pixt2, pixt2);
//.........这里部分代码省略.........
示例7: regTestCheckFile
/*!
* regTestCheckFile()
*
* Input: rp (regtest parameters)
* localname (name of output file from reg test)
* Return: 0 if OK, 1 on error (a failure in comparison is not an error)
*
* Notes:
* (1) This function does one of three things, depending on the mode:
* * "generate": makes a "golden" file as a copy @localname.
* * "compare": compares @localname contents with the golden file
* * "display": makes the @localname file but does no comparison
* (2) The canonical format of the golden filenames is:
* /tmp/golden/<root of main name>_golden.<index>.<ext of localname>
* e.g.,
* /tmp/golden/maze_golden.0.png
* It is important to add an extension to the local name, because
* the extension is added to the name of the golden file.
*/
l_int32
regTestCheckFile(L_REGPARAMS *rp,
const char *localname)
{
char *ext;
char namebuf[256];
l_int32 ret, same, format;
PIX *pix1, *pix2;
PROCNAME("regTestCheckFile");
if (!rp)
return ERROR_INT("rp not defined", procName, 1);
if (!localname) {
rp->success = FALSE;
return ERROR_INT("local name not defined", procName, 1);
}
if (rp->mode != L_REG_GENERATE && rp->mode != L_REG_COMPARE &&
rp->mode != L_REG_DISPLAY) {
rp->success = FALSE;
return ERROR_INT("invalid mode", procName, 1);
}
rp->index++;
/* If display mode, no generation and no testing */
if (rp->mode == L_REG_DISPLAY) return 0;
/* Generate the golden file name; used in 'generate' and 'compare' */
splitPathAtExtension(localname, NULL, &ext);
snprintf(namebuf, sizeof(namebuf), "/tmp/golden/%s_golden.%d%s",
rp->testname, rp->index, ext);
FREE(ext);
/* Generate mode. No testing. */
if (rp->mode == L_REG_GENERATE) {
/* Save the file as a golden file */
/* fprintf(stderr, "%d: %s\n", rp->index, namebuf); */
ret = fileCopy(localname, namebuf);
if (!ret)
fprintf(stderr, "Copy: %s to %s\n", localname, namebuf);
return ret;
}
/* Compare mode: test and record on failure. GIF compression
* is lossless for images with up to 8 bpp (but not for RGB
* because it must generate a 256 color palette). Although
* the read/write cycle for GIF is idempotent in the image
* pixels for bpp <= 8, it is not idempotent in the actual
* file bytes. Tests comparing file bytes before and after
* a GIF read/write cycle will fail. So for GIF we uncompress
* the two images and compare the actual pixels. From my tests,
* PNG, in addition to being lossless, is idempotent in file
* bytes on read/write, so comparing the pixels is not necessary.
* (It also increases the regression test time by an an average
* of about 8%.) JPEG is lossy and not idempotent in the image
* pixels, so no tests are constructed that would require it. */
findFileFormat(localname, &format);
if (format == IFF_GIF) {
same = 0;
pix1 = pixRead(localname);
pix2 = pixRead(namebuf);
pixEqual(pix1, pix2, &same);
pixDestroy(&pix1);
pixDestroy(&pix2);
} else {
filesAreIdentical(localname, namebuf, &same);
}
if (!same) {
fprintf(rp->fp, "Failure in %s_reg, index %d: comparing %s with %s\n",
rp->testname, rp->index, localname, namebuf);
fprintf(stderr, "Failure in %s_reg, index %d: comparing %s with %s\n",
rp->testname, rp->index, localname, namebuf);
rp->success = FALSE;
}
return 0;
}
示例8: ioFormatTest
/*!
* ioFormatTest()
*
* Input: filename (input file)
* Return: 0 if OK; 1 on error or if the test fails
*
* Notes:
* (1) This writes and reads a set of output files losslessly
* in different formats to /tmp/format/, and tests that the
* result before and after is unchanged.
* (2) This should work properly on input images of any depth,
* with and without colormaps.
* (3) All supported formats are tested for bmp, png, tiff and
* non-ascii pnm. Ascii pnm also works (but who'd ever want
* to use it?) We allow 2 bpp bmp, although it's not
* supported elsewhere. And we don't support reading
* 16 bpp png, although this can be turned on in pngio.c.
* (4) This silently skips png or tiff testing if HAVE_LIBPNG
* or HAVE_LIBTIFF are 0, respectively.
*/
l_int32
ioFormatTest(const char *filename)
{
l_int32 d, equal, problems;
PIX *pixs, *pixc, *pix1, *pix2;
PIXCMAP *cmap;
PROCNAME("ioFormatTest");
if (!filename)
return ERROR_INT("filename not defined", procName, 1);
if ((pixs = pixRead(filename)) == NULL)
return ERROR_INT("pixs not made", procName, 1);
lept_mkdir("lept");
/* Note that the reader automatically removes colormaps
* from 1 bpp BMP images, but not from 8 bpp BMP images.
* Therefore, if our 8 bpp image initially doesn't have a
* colormap, we are going to need to remove it from any
* pix read from a BMP file. */
pixc = pixClone(pixs); /* laziness */
/* This does not test the alpha layer pixels, because most
* formats don't support it. Remove any alpha. */
if (pixGetSpp(pixc) == 4)
pixSetSpp(pixc, 3);
cmap = pixGetColormap(pixc); /* colormap; can be NULL */
d = pixGetDepth(pixc);
problems = FALSE;
/* ----------------------- BMP -------------------------- */
/* BMP works for 1, 2, 4, 8 and 32 bpp images.
* It always writes colormaps for 1 and 8 bpp, so we must
* remove it after readback if the input image doesn't have
* a colormap. Although we can write/read 2 bpp BMP, nobody
* else can read them! */
if (d == 1 || d == 8) {
L_INFO("write/read bmp\n", procName);
pixWrite(FILE_BMP, pixc, IFF_BMP);
pix1 = pixRead(FILE_BMP);
if (!cmap)
pix2 = pixRemoveColormap(pix1, REMOVE_CMAP_BASED_ON_SRC);
else
pix2 = pixClone(pix1);
pixEqual(pixc, pix2, &equal);
if (!equal) {
L_INFO(" **** bad bmp image: d = %d ****\n", procName, d);
problems = TRUE;
}
pixDestroy(&pix1);
pixDestroy(&pix2);
}
if (d == 2 || d == 4 || d == 32) {
L_INFO("write/read bmp\n", procName);
pixWrite(FILE_BMP, pixc, IFF_BMP);
pix1 = pixRead(FILE_BMP);
pixEqual(pixc, pix1, &equal);
if (!equal) {
L_INFO(" **** bad bmp image: d = %d ****\n", procName, d);
problems = TRUE;
}
pixDestroy(&pix1);
}
/* ----------------------- PNG -------------------------- */
#if HAVE_LIBPNG
/* PNG works for all depths, but here, because we strip
* 16 --> 8 bpp on reading, we don't test png for 16 bpp. */
if (d != 16) {
L_INFO("write/read png\n", procName);
pixWrite(FILE_PNG, pixc, IFF_PNG);
pix1 = pixRead(FILE_PNG);
pixEqual(pixc, pix1, &equal);
if (!equal) {
L_INFO(" **** bad png image: d = %d ****\n", procName, d);
//.........这里部分代码省略.........
示例9: pixReadHeader
/*!
* pixReadHeader()
*
* Input: filename (with full pathname or in local directory)
* &format (<optional return> file format)
* &w, &h (<optional returns> width and height)
* &bps <optional return> bits/sample
* &spp <optional return> samples/pixel (1, 3 or 4)
* &iscmap (<optional return> 1 if cmap exists; 0 otherwise)
* Return: 0 if OK, 1 on error
*
* Notes:
* (1) This reads the actual headers for jpeg, png, tiff and pnm.
* For bmp and gif, we cheat and read the entire file into a pix,
* from which we extract the "header" information.
*/
l_int32
pixReadHeader(const char *filename,
l_int32 *pformat,
l_int32 *pw,
l_int32 *ph,
l_int32 *pbps,
l_int32 *pspp,
l_int32 *piscmap)
{
l_int32 format, ret, w, h, d, bps, spp, iscmap;
l_int32 type; /* ignored */
FILE *fp;
PIX *pix;
PROCNAME("pixReadHeader");
if (pw) *pw = 0;
if (ph) *ph = 0;
if (pbps) *pbps = 0;
if (pspp) *pspp = 0;
if (piscmap) *piscmap = 0;
if (pformat) *pformat = 0;
iscmap = 0; /* init to false */
if (!filename)
return ERROR_INT("filename not defined", procName, 1);
if ((fp = fopenReadStream(filename)) == NULL)
return ERROR_INT("image file not found", procName, 1);
findFileFormatStream(fp, &format);
fclose(fp);
switch (format)
{
case IFF_BMP: /* cheating: reading the entire file */
if ((pix = pixRead(filename)) == NULL)
return ERROR_INT( "bmp: pix not read", procName, 1);
pixGetDimensions(pix, &w, &h, &d);
if (pixGetColormap(pix))
iscmap = 1;
pixDestroy(&pix);
bps = (d == 32) ? 8 : d;
spp = (d == 32) ? 3 : 1;
break;
case IFF_JFIF_JPEG:
ret = readHeaderJpeg(filename, &w, &h, &spp, NULL, NULL);
bps = 8;
if (ret)
return ERROR_INT( "jpeg: no header info returned", procName, 1);
break;
case IFF_PNG:
ret = readHeaderPng(filename, &w, &h, &bps, &spp, &iscmap);
if (ret)
return ERROR_INT( "png: no header info returned", procName, 1);
break;
case IFF_TIFF:
case IFF_TIFF_PACKBITS:
case IFF_TIFF_RLE:
case IFF_TIFF_G3:
case IFF_TIFF_G4:
case IFF_TIFF_LZW:
case IFF_TIFF_ZIP:
/* Reading page 0 by default; possibly redefine format */
ret = readHeaderTiff(filename, 0, &w, &h, &bps, &spp, NULL, &iscmap,
&format);
if (ret)
return ERROR_INT( "tiff: no header info returned", procName, 1);
break;
case IFF_PNM:
ret = readHeaderPnm(filename, &w, &h, &d, &type, &bps, &spp);
if (ret)
return ERROR_INT( "pnm: no header info returned", procName, 1);
break;
case IFF_GIF: /* cheating: reading the entire file */
if ((pix = pixRead(filename)) == NULL)
return ERROR_INT( "gif: pix not read", procName, 1);
pixGetDimensions(pix, &w, &h, &d);
pixDestroy(&pix);
iscmap = 1; /* always colormapped; max 256 colors */
spp = 1;
//.........这里部分代码省略.........
示例10: main
int main(int argc,
char **argv)
{
l_int32 type, comptype, d1, d2, same, first, last;
l_float32 fract, diff, rmsdiff;
char *filein1, *filein2, *fileout;
GPLOT *gplot;
NUMA *na1, *na2;
PIX *pixs1, *pixs2, *pixd;
static char mainName[] = "comparetest";
if (argc != 5)
return ERROR_INT(" Syntax: comparetest filein1 filein2 type fileout",
mainName, 1);
filein1 = argv[1];
filein2 = argv[2];
type = atoi(argv[3]);
pixd = NULL;
fileout = argv[4];
l_pngSetReadStrip16To8(0);
if ((pixs1 = pixRead(filein1)) == NULL)
return ERROR_INT("pixs1 not made", mainName, 1);
if ((pixs2 = pixRead(filein2)) == NULL)
return ERROR_INT("pixs2 not made", mainName, 1);
d1 = pixGetDepth(pixs1);
d2 = pixGetDepth(pixs2);
if (d1 == 1 && d2 == 1) {
pixEqual(pixs1, pixs2, &same);
if (same) {
fprintf(stderr, "Images are identical\n");
pixd = pixCreateTemplate(pixs1); /* write empty pix for diff */
}
else {
if (type == 0)
comptype = L_COMPARE_XOR;
else
comptype = L_COMPARE_SUBTRACT;
pixCompareBinary(pixs1, pixs2, comptype, &fract, &pixd);
fprintf(stderr, "Fraction of different pixels: %10.6f\n", fract);
}
pixWrite(fileout, pixd, IFF_PNG);
}
else {
if (type == 0)
comptype = L_COMPARE_ABS_DIFF;
else
comptype = L_COMPARE_SUBTRACT;
pixCompareGrayOrRGB(pixs1, pixs2, comptype, GPLOT_X11, &same, &diff,
&rmsdiff, &pixd);
if (type == 0) {
if (same)
fprintf(stderr, "Images are identical\n");
else {
fprintf(stderr, "Images differ: <diff> = %10.6f\n", diff);
fprintf(stderr, " <rmsdiff> = %10.6f\n", rmsdiff);
}
}
else { /* subtraction */
if (same)
fprintf(stderr, "pixs2 strictly greater than pixs1\n");
else {
fprintf(stderr, "Images differ: <diff> = %10.6f\n", diff);
fprintf(stderr, " <rmsdiff> = %10.6f\n", rmsdiff);
}
}
if (d1 != 16)
pixWrite(fileout, pixd, IFF_JFIF_JPEG);
else
pixWrite(fileout, pixd, IFF_PNG);
if (d1 != 16 && !same) {
na1 = pixCompareRankDifference(pixs1, pixs2, 1);
if (na1) {
fprintf(stderr, "na1[150] = %20.10f\n", na1->array[150]);
fprintf(stderr, "na1[200] = %20.10f\n", na1->array[200]);
fprintf(stderr, "na1[250] = %20.10f\n", na1->array[250]);
numaGetNonzeroRange(na1, 0.00005, &first, &last);
fprintf(stderr, "Nonzero diff range: first = %d, last = %d\n",
first, last);
na2 = numaClipToInterval(na1, first, last);
gplot = gplotCreate("/tmp/junkrank", GPLOT_X11,
"Pixel Rank Difference", "pixel val",
"rank");
gplotAddPlot(gplot, NULL, na2, GPLOT_LINES, "rank");
gplotMakeOutput(gplot);
gplotDestroy(&gplot);
numaDestroy(&na1);
numaDestroy(&na2);
}
}
}
pixDestroy(&pixs1);
pixDestroy(&pixs2);
pixDestroy(&pixd);
return 0;
}
示例11: main
int main(int argc,
char **argv) {
l_int32 w, h, x, y, i, n;
l_float32 *vc;
PIX *pix1, *pix2, *pix3, *pix4, *pix5;
PIXA *pixas, *pixa;
L_REGPARAMS *rp;
if (regTestSetup(argc, argv, &rp))
return 1;
pixas = pixaCreate(11);
for (i = 0; i < 10; i++) { /* this preserves any alpha */
pix1 = pixRead(fnames[i]);
pix2 = pixScaleBySamplingToSize(pix1, 250, 150);
pixaAddPix(pixas, pix2, L_INSERT);
pixDestroy(&pix1);
}
/* Add a transparent grid over the rgb image */
pix1 = pixaGetPix(pixas, 8, L_COPY);
pixGetDimensions(pix1, &w, &h, NULL);
pix2 = pixCreate(w, h, 1);
for (i = 0; i < 5; i++) {
y = h * (i + 1) / 6;
pixRenderLine(pix2, 0, y, w, y, 3, L_SET_PIXELS);
}
for (i = 0; i < 7; i++) {
x = w * (i + 1) / 8;
pixRenderLine(pix2, x, 0, x, h, 3, L_SET_PIXELS);
}
pix3 = pixConvertTo8(pix2, 0); /* 1 --> 0 ==> transparent */
pixSetRGBComponent(pix1, pix3, L_ALPHA_CHANNEL);
pixaAddPix(pixas, pix1, L_INSERT);
n = pixaGetCount(pixas);
pixDestroy(&pix2);
pixDestroy(&pix3);
#if DO_ALL
/* Display with and without removing alpha with white bg */
pix1 = pixaDisplayTiledInRows(pixas, 32, 1200, 1.0, 0, 25, 2);
regTestWritePixAndCheck(rp, pix1, IFF_PNG); /* 0 */
pixDisplayWithTitle(pix1, 0, 0, NULL, rp->display);
pixDestroy(&pix1);
pixa = pixaCreate(n);
for (i = 0; i < n; i++) {
pix1 = pixaGetPix(pixas, i, L_COPY);
pix2 = pixRemoveAlpha(pix1);
pixaAddPix(pixa, pix2, L_INSERT);
pixDestroy(&pix1);
}
pix1 = pixaDisplayTiledInRows(pixa, 32, 1200, 1.0, 0, 25, 2);
regTestWritePixAndCheck(rp, pix1, IFF_PNG); /* 1 */
pixDisplayWithTitle(pix1, 200, 0, NULL, rp->display);
pixDestroy(&pix1);
pixaDestroy(&pixa);
#endif
#if DO_ALL
/* Setting to gray */
pixa = pixaCreate(n);
for (i = 0; i < n; i++) {
pix1 = pixaGetPix(pixas, i, L_COPY);
pixSetAllGray(pix1, 170);
pix2 = pixRemoveAlpha(pix1);
pixaAddPix(pixa, pix2, L_INSERT);
pixDestroy(&pix1);
}
pix1 = pixaDisplayTiledInRows(pixa, 32, 1200, 1.0, 0, 25, 2);
regTestWritePixAndCheck(rp, pix1, IFF_PNG); /* 2 */
pixDisplayWithTitle(pix1, 400, 0, NULL, rp->display);
pixDestroy(&pix1);
pixaDestroy(&pixa);
#endif
#if DO_ALL
/* General scaling */
pixa = pixaCreate(n);
for (i = 0; i < n; i++) {
pix1 = pixaGetPix(pixas, i, L_COPY);
pix2 = pixScaleToSize(pix1, 350, 650);
pix3 = pixScaleToSize(pix2, 200, 200);
pix4 = pixRemoveAlpha(pix3);
pixaAddPix(pixa, pix4, L_INSERT);
pixDestroy(&pix1);
pixDestroy(&pix2);
pixDestroy(&pix3);
}
pix1 = pixaDisplayTiledInRows(pixa, 32, 1200, 1.0, 0, 25, 2);
regTestWritePixAndCheck(rp, pix1, IFF_PNG); /* 3 */
pixDisplayWithTitle(pix1, 600, 0, NULL, rp->display);
pixDestroy(&pix1);
pixaDestroy(&pixa);
#endif
#if DO_ALL
/* Scaling by sampling */
pixa = pixaCreate(n);
for (i = 0; i < n; i++) {
pix1 = pixaGetPix(pixas, i, L_COPY);
//.........这里部分代码省略.........
示例12: main
int main(int argc,
char **argv)
{
l_int32 i, w, h;
PIX *pix0, *pix1, *pix2, *pix3, *pix4, *pix5;
PIXA *pixa;
L_REGPARAMS *rp;
if (regTestSetup(argc, argv, &rp))
return 1;
pixa = pixaCreate(0);
/* Blending on a light image */
pix1 = pixRead("fish24.jpg");
pixGetDimensions(pix1, &w, &h, NULL);
for (i = 0; i < 3; i++) {
pix2 = pixRead(blenders[i]);
if (i == 2) {
pix3 = pixScale(pix2, 0.5, 0.5);
pixDestroy(&pix2);
pix2 = pix3;
}
pix3 = pixAddAlphaToBlend(pix2, 0.3, 0);
pix4 = pixMirroredTiling(pix3, w, h);
pix5 = pixBlendWithGrayMask(pix1, pix4, NULL, 0, 0);
pixaAddPix(pixa, pix5, L_INSERT);
regTestWritePixAndCheck(rp, pix5, IFF_JFIF_JPEG); /* 0 - 2 */
pixDisplayWithTitle(pix5, 200 * i, 0, NULL, rp->display);
pixDestroy(&pix2);
pixDestroy(&pix3);
pixDestroy(&pix4);
}
pixDestroy(&pix1);
/* Blending on a dark image */
pix0 = pixRead("karen8.jpg");
pix1 = pixScale(pix0, 2.0, 2.0);
pixGetDimensions(pix1, &w, &h, NULL);
for (i = 0; i < 2; i++) {
pix2 = pixRead(blenders[i]);
pix3 = pixAddAlphaToBlend(pix2, 0.3, 1);
pix4 = pixMirroredTiling(pix3, w, h);
pix5 = pixBlendWithGrayMask(pix1, pix4, NULL, 0, 0);
pixaAddPix(pixa, pix5, L_INSERT);
regTestWritePixAndCheck(rp, pix5, IFF_JFIF_JPEG); /* 3 - 4 */
pixDisplayWithTitle(pix5, 600 + 200 * i, 0, NULL, rp->display);
pixDestroy(&pix2);
pixDestroy(&pix3);
pixDestroy(&pix4);
}
pixaConvertToPdf(pixa, 100, 1.0, L_JPEG_ENCODE, 0,
"Blendings: blend4_reg", "/tmp/blend.pdf");
L_INFO("Output pdf: /tmp/blend.pdf\n", rp->testname);
pixDestroy(&pix0);
pixDestroy(&pix1);
pixaDestroy(&pixa);
return regTestCleanup(rp);
}
示例13: convertToPSEmbed
/*
* convertToPSEmbed()
*
* Input: filein (input image file -- any format)
* fileout (output ps file)
* level (compression: 1 (uncompressed), 2 or 3)
* Return: 0 if OK, 1 on error
*
* Notes:
* (1) This is a wrapper function that generates a PS file with
* a bounding box, from any input image file.
* (2) Do the best job of compression given the specified level.
* @level=3 does flate compression on anything that is not
* tiffg4 (1 bpp) or jpeg (8 bpp or rgb).
* (3) If @level=2 and the file is not tiffg4 or jpeg, it will
* first be written to file as jpeg with quality = 75.
* This will remove the colormap and cause some degradation
* in the image.
* (4) The bounding box is required when a program such as TeX
* (through epsf) places and rescales the image. It is
* sized for fitting the image to an 8.5 x 11.0 inch page.
*/
l_int32
convertToPSEmbed(const char *filein,
const char *fileout,
l_int32 level)
{
const char nametif[] = "/tmp/junk_convert_ps_embed.tif";
const char namejpg[] = "/tmp/junk_convert_ps_embed.jpg";
l_int32 d, format;
FILE *fp;
PIX *pix, *pixs;
PROCNAME("convertToPSEmbed");
if (!filein)
return ERROR_INT("filein not defined", procName, 1);
if (!fileout)
return ERROR_INT("fileout not defined", procName, 1);
if (level != 1 && level != 2 && level != 3) {
L_ERROR("invalid level specified; using level 2", procName);
level = 2;
}
if (level == 1) { /* no compression */
pixWritePSEmbed(filein, fileout);
return 0;
}
/* Find the format and write out directly if in jpeg or tiff g4 */
if ((fp = fopen(filein, "rb")) == NULL)
return ERROR_INT("filein not found", procName, 1);
findFileFormat(fp, &format);
fclose(fp);
if (format == IFF_JFIF_JPEG) {
convertJpegToPSEmbed(filein, fileout);
return 0;
}
else if (format == IFF_TIFF_G4) {
convertTiffG4ToPSEmbed(filein, fileout);
return 0;
}
/* If level 3, flate encode. */
if (level == 3) {
convertFlateToPSEmbed(filein, fileout);
return 0;
}
/* OK, it's level 2, so we must convert to jpeg or tiff g4 */
if ((pixs = pixRead(filein)) == NULL)
return ERROR_INT("image not read from file", procName, 1);
d = pixGetDepth(pixs);
if ((d == 2 || d == 4) && !pixGetColormap(pixs))
pix = pixConvertTo8(pixs, 0);
else if (d == 16)
pix = pixConvert16To8(pixs, 1);
else
pix = pixRemoveColormap(pixs, REMOVE_CMAP_BASED_ON_SRC);
d = pixGetDepth(pix);
if (d == 1) {
pixWrite(nametif, pix, IFF_TIFF_G4);
convertTiffG4ToPSEmbed(nametif, fileout);
}
else {
pixWrite(namejpg, pix, IFF_JFIF_JPEG);
convertJpegToPSEmbed(namejpg, fileout);
}
pixDestroy(&pix);
pixDestroy(&pixs);
return 0;
}
示例14: main
int main(int argc,
char **argv) {
l_int32 i, w, h, d, rotflag;
PIX *pixs, *pixt, *pixd;
l_float32 angle, deg2rad, pops, ang;
char *filein, *fileout;
static char mainName[] = "rotatetest1";
if (argc != 4)
return ERROR_INT(" Syntax: rotatetest1 filein angle fileout",
mainName, 1);
filein = argv[1];
angle = atof(argv[2]);
fileout = argv[3];
deg2rad = 3.1415926535 / 180.;
if ((pixs = pixRead(filein)) == NULL)
return ERROR_INT("pix not made", mainName, 1);
if (pixGetDepth(pixs) == 1) {
pixt = pixScaleToGray3(pixs);
pixDestroy(&pixs);
pixs = pixAddBorderGeneral(pixt, 1, 0, 1, 0, 255);
pixDestroy(&pixt);
}
pixGetDimensions(pixs, &w, &h, &d);
fprintf(stderr, "w = %d, h = %d\n", w, h);
#if 0
/* repertory of rotation operations to choose from */
pixd = pixRotateAM(pixs, deg2rad * angle, L_BRING_IN_WHITE);
pixd = pixRotateAMColor(pixs, deg2rad * angle, 0xffffff00);
pixd = pixRotateAMColorFast(pixs, deg2rad * angle, 255);
pixd = pixRotateAMCorner(pixs, deg2rad * angle, L_BRING_IN_WHITE);
pixd = pixRotateShear(pixs, w /2, h / 2, deg2rad * angle,
L_BRING_IN_WHITE);
pixd = pixRotate3Shear(pixs, w /2, h / 2, deg2rad * angle,
L_BRING_IN_WHITE);
pixRotateShearIP(pixs, w / 2, h / 2, deg2rad * angle); pixd = pixs;
#endif
#if 0
/* timing of shear rotation */
for (i = 0; i < NITERS; i++) {
pixd = pixRotateShear(pixs, (i * w) / NITERS,
(i * h) / NITERS, deg2rad * angle,
L_BRING_IN_WHITE);
pixDisplay(pixd, 100 + 20 * i, 100 + 20 * i);
pixDestroy(&pixd);
}
#endif
#if 0
/* timing of in-place shear rotation */
for (i = 0; i < NITERS; i++) {
pixRotateShearIP(pixs, w/2, h/2, deg2rad * angle, L_BRING_IN_WHITE);
/* pixRotateShearCenterIP(pixs, deg2rad * angle, L_BRING_IN_WHITE); */
pixDisplay(pixs, 100 + 20 * i, 100 + 20 * i);
}
pixd = pixs;
if (pixGetDepth(pixd) == 1)
pixWrite(fileout, pixd, IFF_PNG);
else
pixWrite(fileout, pixd, IFF_JFIF_JPEG);
pixDestroy(&pixs);
#endif
#if 0
/* timing of various rotation operations (choose) */
startTimer();
w = pixGetWidth(pixs);
h = pixGetHeight(pixs);
for (i = 0; i < NTIMES; i++) {
pixd = pixRotateShearCenter(pixs, deg2rad * angle, L_BRING_IN_WHITE);
pixDestroy(&pixd);
}
pops = (l_float32)(w * h * NTIMES / 1000000.) / stopTimer();
fprintf(stderr, "vers. 1, mpops: %f\n", pops);
startTimer();
w = pixGetWidth(pixs);
h = pixGetHeight(pixs);
for (i = 0; i < NTIMES; i++) {
pixRotateShearIP(pixs, w/2, h/2, deg2rad * angle, L_BRING_IN_WHITE);
}
pops = (l_float32)(w * h * NTIMES / 1000000.) / stopTimer();
fprintf(stderr, "shear, mpops: %f\n", pops);
pixWrite(fileout, pixs, IFF_PNG);
for (i = 0; i < NTIMES; i++) {
pixRotateShearIP(pixs, w/2, h/2, -deg2rad * angle, L_BRING_IN_WHITE);
}
pixWrite("/usr/tmp/junkout", pixs, IFF_PNG);
#endif
#if 0
/* area-mapping rotation operations */
pixd = pixRotateAM(pixs, deg2rad * angle, L_BRING_IN_WHITE);
/* pixd = pixRotateAMColorFast(pixs, deg2rad * angle, 255); */
if (pixGetDepth(pixd) == 1)
pixWrite(fileout, pixd, IFF_PNG);
//.........这里部分代码省略.........
示例15: main
main(int argc,
char **argv)
{
char *filein, *fileout;
l_int32 w, h;
l_float32 scale;
FILE *fp;
PIX *pix, *pixs, *pixd;
PIXCMAP *cmap;
static char mainName[] = "dithertest";
if (argc != 3)
exit(ERROR_INT(" Syntax: dithertest filein fileout", mainName, 1));
filein = argv[1];
fileout = argv[2];
if ((pix = pixRead(filein)) == NULL)
exit(ERROR_INT("pix not made", mainName, 1));
if (pixGetDepth(pix) != 8)
exit(ERROR_INT("pix not 8 bpp", mainName, 1));
pixs = pixGammaTRC(NULL, pix, GAMMA, 0, 255);
startTimer();
pixd = pixDitherToBinary(pixs);
fprintf(stderr, " time for binarized dither = %7.3f sec\n", stopTimer());
pixDisplayWrite(pixd, 1);
pixDestroy(&pixd);
/* Dither to 2 bpp, with colormap */
startTimer();
pixd = pixDitherTo2bpp(pixs, 1);
fprintf(stderr, " time for dither = %7.3f sec\n", stopTimer());
pixDisplayWrite(pixd, 1);
cmap = pixGetColormap(pixd);
pixcmapWriteStream(stderr, cmap);
pixDestroy(&pixd);
/* Dither to 2 bpp, without colormap */
startTimer();
pixd = pixDitherTo2bpp(pixs, 0);
fprintf(stderr, " time for dither = %7.3f sec\n", stopTimer());
pixDisplayWrite(pixd, 1);
pixDestroy(&pixd);
/* Dither to 2 bpp, without colormap; output in PostScript */
pixd = pixDitherTo2bpp(pixs, 0);
w = pixGetWidth(pixs);
h = pixGetHeight(pixs);
scale = L_MIN(FACTOR * 2550 / w, FACTOR * 3300 / h);
fp = lept_fopen(fileout, "wb+");
pixWriteStreamPS(fp, pixd, NULL, 300, scale);
lept_fclose(fp);
pixDestroy(&pixd);
/* Dither 2x upscale to 1 bpp */
startTimer();
pixd = pixScaleGray2xLIDither(pixs);
fprintf(stderr, " time for scale/dither = %7.3f sec\n", stopTimer());
pixDisplayWrite(pixd, 1);
pixDestroy(&pixd);
/* Dither 4x upscale to 1 bpp */
startTimer();
pixd = pixScaleGray4xLIDither(pixs);
fprintf(stderr, " time for scale/dither = %7.3f sec\n", stopTimer());
pixDisplayWrite(pixd, 1);
pixDestroy(&pixd);
pixDisplayMultiple("/tmp/junk_write_display*");
pixDestroy(&pix);
pixDestroy(&pixs);
return 0;
}