本文整理汇总了C++中ERROR_PTR函数的典型用法代码示例。如果您正苦于以下问题:C++ ERROR_PTR函数的具体用法?C++ ERROR_PTR怎么用?C++ ERROR_PTR使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了ERROR_PTR函数的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的C++代码示例。
示例1: gplotRead
/*!
* gplotRead()
*
* Input: filename
* Return: gplot, or NULL on error
*/
GPLOT *
gplotRead(const char *filename)
{
char buf[L_BUF_SIZE];
char *rootname, *title, *xlabel, *ylabel;
l_int32 outformat, ret, version;
FILE *fp;
GPLOT *gplot;
PROCNAME("gplotRead");
if (!filename)
return (GPLOT *)ERROR_PTR("filename not defined", procName, NULL);
if ((fp = fopen(filename, "r")) == NULL)
return (GPLOT *)ERROR_PTR("stream not opened", procName, NULL);
ret = fscanf(fp, "Gplot Version %d\n", &version);
if (ret != 1) {
fclose(fp);
return (GPLOT *)ERROR_PTR("not a gplot file", procName, NULL);
}
if (version != GPLOT_VERSION_NUMBER) {
fclose(fp);
return (GPLOT *)ERROR_PTR("invalid gplot version", procName, NULL);
}
fscanf(fp, "Rootname: %s\n", buf);
rootname = stringNew(buf);
fscanf(fp, "Output format: %d\n", &outformat);
fgets(buf, L_BUF_SIZE, fp); /* Title: ... */
title = stringNew(buf + 7);
title[strlen(title) - 1] = '\0';
fgets(buf, L_BUF_SIZE, fp); /* X axis label: ... */
xlabel = stringNew(buf + 14);
xlabel[strlen(xlabel) - 1] = '\0';
fgets(buf, L_BUF_SIZE, fp); /* Y axis label: ... */
ylabel = stringNew(buf + 14);
ylabel[strlen(ylabel) - 1] = '\0';
if (!(gplot = gplotCreate(rootname, outformat, title, xlabel, ylabel))) {
fclose(fp);
return (GPLOT *)ERROR_PTR("gplot not made", procName, NULL);
}
FREE(rootname);
FREE(title);
FREE(xlabel);
FREE(ylabel);
sarrayDestroy(&gplot->cmddata);
sarrayDestroy(&gplot->datanames);
sarrayDestroy(&gplot->plotdata);
sarrayDestroy(&gplot->plottitles);
numaDestroy(&gplot->plotstyles);
fscanf(fp, "Commandfile name: %s\n", buf);
stringReplace(&gplot->cmdname, buf);
fscanf(fp, "\nCommandfile data:");
gplot->cmddata = sarrayReadStream(fp);
fscanf(fp, "\nDatafile names:");
gplot->datanames = sarrayReadStream(fp);
fscanf(fp, "\nPlot data:");
gplot->plotdata = sarrayReadStream(fp);
fscanf(fp, "\nPlot titles:");
gplot->plottitles = sarrayReadStream(fp);
fscanf(fp, "\nPlot styles:");
gplot->plotstyles = numaReadStream(fp);
fscanf(fp, "Number of plots: %d\n", &gplot->nplots);
fscanf(fp, "Output file name: %s\n", buf);
stringReplace(&gplot->outname, buf);
fscanf(fp, "Axis scaling: %d\n", &gplot->scaling);
fclose(fp);
return gplot;
}
开发者ID:AbdelghaniDr,项目名称:mirror,代码行数:81,代码来源:gplot.c
示例2: sarrayMakeWplsCode
/*!
* sarrayMakeWplsCode()
*/
static SARRAY *
sarrayMakeWplsCode(SEL *sel)
{
char emptystring[] = "";
l_int32 i, j, ymax, dely, allvshifts;
l_int32 vshift[32];
SARRAY *sa;
PROCNAME("sarrayMakeWplsCode");
if (!sel)
return (SARRAY *)ERROR_PTR("sel not defined", procName, NULL);
for (i = 0; i < 32; i++)
vshift[i] = 0;
ymax = 0;
for (i = 0; i < sel->sy; i++) {
for (j = 0; j < sel->sx; j++) {
if (sel->data[i][j] == 1) {
dely = L_ABS(i - sel->cy);
if (dely < 32)
vshift[dely] = 1;
ymax = L_MAX(ymax, dely);
}
}
}
if (ymax > 31) {
L_WARNING("ymax > 31; truncating to 31\n", procName);
ymax = 31;
}
/* Test if this is a vertical brick */
allvshifts = TRUE;
for (i = 0; i < ymax; i++) {
if (vshift[i] == 0) {
allvshifts = FALSE;
break;
}
}
if ((sa = sarrayCreate(0)) == NULL)
return (SARRAY *)ERROR_PTR("sa not made", procName, NULL);
/* Add declarations */
if (allvshifts == TRUE) { /* packs them as well as possible */
if (ymax > 4)
sarrayAddString(sa, wpldecls[2], L_COPY);
if (ymax > 8)
sarrayAddString(sa, wpldecls[6], L_COPY);
if (ymax > 12)
sarrayAddString(sa, wpldecls[10], L_COPY);
if (ymax > 16)
sarrayAddString(sa, wpldecls[14], L_COPY);
if (ymax > 20)
sarrayAddString(sa, wpldecls[18], L_COPY);
if (ymax > 24)
sarrayAddString(sa, wpldecls[22], L_COPY);
if (ymax > 28)
sarrayAddString(sa, wpldecls[26], L_COPY);
if (ymax > 1)
sarrayAddString(sa, wpldecls[ymax - 2], L_COPY);
} else { /* puts them one/line */
for (i = 2; i <= ymax; i++) {
if (vshift[i])
sarrayAddString(sa, wplgendecls[i - 2], L_COPY);
}
}
sarrayAddString(sa, emptystring, L_COPY);
/* Add definitions */
for (i = 2; i <= ymax; i++) {
if (vshift[i])
sarrayAddString(sa, wpldefs[i - 2], L_COPY);
}
return sa;
}
开发者ID:AAAyag,项目名称:tess-two,代码行数:81,代码来源:fmorphauto.c
示例3: pixTestDFTGray
PIX *
pixTestDFTGray(PIX *pixs,
l_int32 shiftflag)
{
return (PIX *)ERROR_PTR("function not present", "pixTestDFTGray", NULL);
}
开发者ID:Hurricane86,项目名称:ipl,代码行数:6,代码来源:fourierstub.c
示例4: boxaDisplayTiled
/*!
* \brief boxaDisplayTiled()
*
* \param[in] boxas
* \param[in] pixa [optional] background for each box
* \param[in] first index of first box
* \param[in] last index of last box; use -1 to go to end
* \param[in] maxwidth of output image
* \param[in] linewidth width of box outlines, before scaling
* \param[in] scalefactor applied to every box; use 1.0 for no scaling
* \param[in] background 0 for white, 1 for black; this is the color
* of the spacing between the images
* \param[in] spacing between images, and on outside
* \param[in] border width of black border added to each image;
* use 0 for no border
* \return pixd of tiled images of boxes, or NULL on error
*
* <pre>
* Notes:
* (1) Displays each box separately in a tiled 32 bpp image.
* (2) If pixa is defined, it must have the same count as the boxa,
* and it will be a background over with each box is rendered.
* If pixa is not defined, the boxes will be rendered over
* blank images of identical size.
* (3) See pixaDisplayTiledInRows() for other parameters.
* </pre>
*/
PIX *
boxaDisplayTiled(BOXA *boxas,
PIXA *pixa,
l_int32 first,
l_int32 last,
l_int32 maxwidth,
l_int32 linewidth,
l_float32 scalefactor,
l_int32 background,
l_int32 spacing,
l_int32 border)
{
char buf[32];
l_int32 i, n, npix, w, h, fontsize;
L_BMF *bmf;
BOX *box;
BOXA *boxa;
PIX *pix1, *pix2, *pixd;
PIXA *pixat;
PROCNAME("boxaDisplayTiled");
if (!boxas)
return (PIX *)ERROR_PTR("boxas not defined", procName, NULL);
boxa = boxaSaveValid(boxas, L_COPY);
n = boxaGetCount(boxa);
if (pixa) {
npix = pixaGetCount(pixa);
if (n != npix) {
boxaDestroy(&boxa);
return (PIX *)ERROR_PTR("boxa and pixa counts differ",
procName, NULL);
}
}
first = L_MAX(0, first);
if (last < 0) last = n - 1;
if (first >= n) {
boxaDestroy(&boxa);
return (PIX *)ERROR_PTR("invalid first", procName, NULL);
}
if (last >= n) {
L_WARNING("last = %d is beyond max index = %d; adjusting\n",
procName, last, n - 1);
last = n - 1;
}
if (first > last) {
boxaDestroy(&boxa);
return (PIX *)ERROR_PTR("first > last", procName, NULL);
}
/* Because the bitmap font will be reduced when tiled, choose the
* font size inversely with the scale factor. */
if (scalefactor > 0.8)
fontsize = 6;
else if (scalefactor > 0.6)
fontsize = 10;
else if (scalefactor > 0.4)
fontsize = 14;
else if (scalefactor > 0.3)
fontsize = 18;
else fontsize = 20;
bmf = bmfCreate(NULL, fontsize);
pixat = pixaCreate(n);
boxaGetExtent(boxa, &w, &h, NULL);
for (i = first; i <= last; i++) {
box = boxaGetBox(boxa, i, L_CLONE);
if (!pixa) {
pix1 = pixCreate(w, h, 32);
pixSetAll(pix1);
} else {
pix1 = pixaGetPix(pixa, i, L_COPY);
//.........这里部分代码省略.........
开发者ID:pullmoll,项目名称:leptonica,代码行数:101,代码来源:boxfunc4.c
示例5: pixReadStream
/*!
* pixReadStream()
*
* Input: fp (file stream)
* hint (bitwise OR of L_HINT_* values for jpeg; use 0 for no hint)
* Return: pix if OK; null on error
*
* Notes:
* (1) The hint only applies to jpeg.
*/
PIX *
pixReadStream(FILE *fp,
l_int32 hint)
{
l_int32 format, ret;
l_uint8 *comment;
PIX *pix;
PROCNAME("pixReadStream");
if (!fp)
return (PIX *)ERROR_PTR("stream not defined", procName, NULL);
pix = NULL;
findFileFormatStream(fp, &format);
switch (format)
{
case IFF_BMP:
if ((pix = pixReadStreamBmp(fp)) == NULL )
return (PIX *)ERROR_PTR( "bmp: no pix returned", procName, NULL);
break;
case IFF_JFIF_JPEG:
if ((pix = pixReadStreamJpeg(fp, 0, 1, NULL, hint)) == NULL)
return (PIX *)ERROR_PTR( "jpeg: no pix returned", procName, NULL);
ret = fgetJpegComment(fp, &comment);
if (!ret && comment)
pixSetText(pix, (char *)comment);
FREE(comment);
break;
case IFF_PNG:
if ((pix = pixReadStreamPng(fp)) == NULL)
return (PIX *)ERROR_PTR("png: no pix returned", procName, NULL);
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:
if ((pix = pixReadStreamTiff(fp, 0)) == NULL) /* page 0 by default */
return (PIX *)ERROR_PTR("tiff: no pix returned", procName, NULL);
break;
case IFF_PNM:
if ((pix = pixReadStreamPnm(fp)) == NULL)
return (PIX *)ERROR_PTR("pnm: no pix returned", procName, NULL);
break;
case IFF_GIF:
if ((pix = pixReadStreamGif(fp)) == NULL)
return (PIX *)ERROR_PTR("gif: no pix returned", procName, NULL);
break;
case IFF_JP2:
if ((pix = pixReadStreamJp2k(fp, 1, NULL, 0, 0)) == NULL)
return (PIX *)ERROR_PTR("jp2: no pix returned", procName, NULL);
break;
case IFF_WEBP:
if ((pix = pixReadStreamWebP(fp)) == NULL)
return (PIX *)ERROR_PTR("webp: no pix returned", procName, NULL);
break;
case IFF_SPIX:
if ((pix = pixReadStreamSpix(fp)) == NULL)
return (PIX *)ERROR_PTR("spix: no pix returned", procName, NULL);
break;
case IFF_UNKNOWN:
return (PIX *)ERROR_PTR( "Unknown format: no pix returned",
procName, NULL);
break;
}
if (pix)
pixSetInputFormat(pix, format);
return pix;
}
开发者ID:xmarston,项目名称:BillRecognizer,代码行数:92,代码来源:readfile.c
示例6: selaAddBasic
/*!
* selaAddBasic()
*
* Input: sela (<optional>)
* Return: sela with additional sels, or null on error
*
* Notes:
* (1) Adds the following sels:
* - all linear (horiz, vert) brick sels that are
* necessary for decomposable sels up to size 63
* - square brick sels up to size 10
* - 4 diagonal sels
*/
SELA *
selaAddBasic(SELA *sela)
{
SEL *sel;
l_int32 i, size;
char name[L_BUF_SIZE];
PROCNAME("selaAddBasic");
if (!sela) {
if ((sela = selaCreate(0)) == NULL)
return (SELA *)ERROR_PTR("sela not made", procName, NULL);
}
/*--------------------------------------------------------------*
* Linear horizontal and vertical sels *
*--------------------------------------------------------------*/
for (i = 0; i < num_linear; i++) {
size = basic_linear[i];
sel = selCreateBrick(1, size, 0, size / 2, 1);
snprintf(name, L_BUF_SIZE, "sel_%dh", size);
selaAddSel(sela, sel, name, 0);
}
for (i = 0; i < num_linear; i++) {
size = basic_linear[i];
sel = selCreateBrick(size, 1, size / 2, 0, 1);
snprintf(name, L_BUF_SIZE, "sel_%dv", size);
selaAddSel(sela, sel, name, 0);
}
/*-----------------------------------------------------------*
* 2-d Bricks *
*-----------------------------------------------------------*/
for (i = 2; i <= 5; i++) {
sel = selCreateBrick(i, i, i / 2, i / 2, 1);
snprintf(name, L_BUF_SIZE, "sel_%d", i);
selaAddSel(sela, sel, name, 0);
}
/*-----------------------------------------------------------*
* Diagonals *
*-----------------------------------------------------------*/
/* 0c 1
1 0 */
sel = selCreateBrick(2, 2, 0, 0, 1);
selSetElement(sel, 0, 0, 0);
selSetElement(sel, 1, 1, 0);
selaAddSel(sela, sel, "sel_2dp", 0);
/* 1c 0
0 1 */
sel = selCreateBrick(2, 2, 0, 0, 1);
selSetElement(sel, 0, 1, 0);
selSetElement(sel, 1, 0, 0);
selaAddSel(sela, sel, "sel_2dm", 0);
/* Diagonal, slope +, size 5 */
sel = selCreate(5, 5, "sel_5dp");
sel->cy = 2;
sel->cx = 2;
selSetElement(sel, 0, 4, 1);
selSetElement(sel, 1, 3, 1);
selSetElement(sel, 2, 2, 1);
selSetElement(sel, 3, 1, 1);
selSetElement(sel, 4, 0, 1);
selaAddSel(sela, sel, "sel_5dp", 0);
/* Diagonal, slope -, size 5 */
sel = selCreate(5, 5, "sel_5dm");
sel->cy = 2;
sel->cx = 2;
selSetElement(sel, 0, 0, 1);
selSetElement(sel, 1, 1, 1);
selSetElement(sel, 2, 2, 1);
selSetElement(sel, 3, 3, 1);
selSetElement(sel, 4, 4, 1);
selaAddSel(sela, sel, "sel_5dm", 0);
return sela;
}
开发者ID:peterlee2008,项目名称:leptonica,代码行数:93,代码来源:sel2.c
示例7: pixRunlengthTransform
/*!
* pixRunlengthTransform()
*
* Input: pixs (1 bpp)
* color (0 for white runs, 1 for black runs)
* direction (L_HORIZONTAL_RUNS, L_VERTICAL_RUNS)
* depth (8 or 16 bpp)
* Return: pixd (8 or 16 bpp), or null on error
*
* Notes:
* (1) The dest Pix is 8 or 16 bpp, with the pixel values
* equal to the runlength in which it is a member.
* The length is clipped to the max pixel value if necessary.
* (2) The color determines if we're labelling white or black runs.
* (3) A pixel that is not a member of the chosen color gets
* value 0; it belongs to a run of length 0 of the
* chosen color.
* (4) To convert for maximum dynamic range, either linear or
* log, use pixMaxDynamicRange().
*/
PIX *
pixRunlengthTransform(PIX *pixs,
l_int32 color,
l_int32 direction,
l_int32 depth)
{
l_int32 i, j, w, h, wpld, bufsize, maxsize, n;
l_int32 *start, *end, *buffer;
l_uint32 *datad, *lined;
PIX *pixt, *pixd;
PROCNAME("pixRunlengthTransform");
if (!pixs)
return (PIX *)ERROR_PTR("pixs not defined", procName, NULL);
if (pixGetDepth(pixs) != 1)
return (PIX *)ERROR_PTR("pixs not 1 bpp", procName, NULL);
if (depth != 8 && depth != 16)
return (PIX *)ERROR_PTR("depth must be 8 or 16 bpp", procName, NULL);
pixGetDimensions(pixs, &w, &h, NULL);
if (direction == L_HORIZONTAL_RUNS)
maxsize = 1 + w / 2;
else if (direction == L_VERTICAL_RUNS)
maxsize = 1 + h / 2;
else
return (PIX *)ERROR_PTR("invalid direction", procName, NULL);
bufsize = L_MAX(w, h);
if ((pixd = pixCreate(w, h, depth)) == NULL)
return (PIX *)ERROR_PTR("pixd not made", procName, NULL);
datad = pixGetData(pixd);
wpld = pixGetWpl(pixd);
if ((start = (l_int32 *)CALLOC(maxsize, sizeof(l_int32))) == NULL)
return (PIX *)ERROR_PTR("start not made", procName, NULL);
if ((end = (l_int32 *)CALLOC(maxsize, sizeof(l_int32))) == NULL)
return (PIX *)ERROR_PTR("end not made", procName, NULL);
if ((buffer = (l_int32 *)CALLOC(bufsize, sizeof(l_int32))) == NULL)
return (PIX *)ERROR_PTR("buffer not made", procName, NULL);
/* Use fg runs for evaluation */
if (color == 0)
pixt = pixInvert(NULL, pixs);
else
pixt = pixClone(pixs);
if (direction == L_HORIZONTAL_RUNS) {
for (i = 0; i < h; i++) {
pixFindHorizontalRuns(pixt, i, start, end, &n);
runlengthMembershipOnLine(buffer, w, depth, start, end, n);
lined = datad + i * wpld;
if (depth == 8) {
for (j = 0; j < w; j++)
SET_DATA_BYTE(lined, j, buffer[j]);
} else { /* depth == 16 */
for (j = 0; j < w; j++)
SET_DATA_TWO_BYTES(lined, j, buffer[j]);
}
}
} else { /* L_VERTICAL_RUNS */
for (j = 0; j < w; j++) {
pixFindVerticalRuns(pixt, j, start, end, &n);
runlengthMembershipOnLine(buffer, h, depth, start, end, n);
if (depth == 8) {
for (i = 0; i < h; i++) {
lined = datad + i * wpld;
SET_DATA_BYTE(lined, j, buffer[i]);
}
} else { /* depth == 16 */
for (i = 0; i < h; i++) {
lined = datad + i * wpld;
SET_DATA_TWO_BYTES(lined, j, buffer[i]);
}
}
}
}
pixDestroy(&pixt);
FREE(start);
//.........这里部分代码省略.........
开发者ID:0xkasun,项目名称:Dummy_Tes,代码行数:101,代码来源:runlength.c
示例8: pixaaDisplayByPixa
/*!
* pixaaDisplayByPixa()
*
* Input: pixaa
* xspace between pix in pixa
* yspace between pixa
* max width of output pix
* Return: pix, or null on error
*
* Notes:
* (1) Displays each pixa on a line (or set of lines),
* in order from top to bottom. Within each pixa,
* the pix are displayed in order from left to right.
* (2) The size of each pix in each pixa is assumed to be
* approximately equal to the size of the first pix in
* the pixa. If this assumption is not correct, this
* function will not work properly.
* (3) This ignores the boxa of the pixaa.
*/
PIX *
pixaaDisplayByPixa(PIXAA *pixaa,
l_int32 xspace,
l_int32 yspace,
l_int32 maxw)
{
l_int32 i, j, npixa, npix;
l_int32 width, height, depth, nlines, lwidth;
l_int32 x, y, w, h, w0, h0;
PIX *pixt, *pixd;
PIXA *pixa;
PROCNAME("pixaaDisplayByPixa");
if (!pixaa)
return (PIX *)ERROR_PTR("pixaa not defined", procName, NULL);
if ((npixa = pixaaGetCount(pixaa)) == 0)
return (PIX *)ERROR_PTR("no components", procName, NULL);
/* Get size of output pix. The width is the minimum of the
* maxw and the largest pixa line width. The height is whatever
* it needs to be to accommodate all pixa. */
height = 2 * yspace;
width = 0;
for (i = 0; i < npixa; i++) {
pixa = pixaaGetPixa(pixaa, i, L_CLONE);
npix = pixaGetCount(pixa);
pixt = pixaGetPix(pixa, 0, L_CLONE);
if (i == 0)
depth = pixGetDepth(pixt);
w = pixGetWidth(pixt);
lwidth = npix * (w + xspace);
nlines = (lwidth + maxw - 1) / maxw;
if (nlines > 1)
width = maxw;
else
width = L_MAX(lwidth, width);
height += nlines * (pixGetHeight(pixt) + yspace);
pixDestroy(&pixt);
pixaDestroy(&pixa);
}
if ((pixd = pixCreate(width, height, depth)) == NULL)
return (PIX *)ERROR_PTR("pixd not made", procName, NULL);
/* Now layout the pix by pixa */
y = yspace;
for (i = 0; i < npixa; i++) {
x = 0;
pixa = pixaaGetPixa(pixaa, i, L_CLONE);
npix = pixaGetCount(pixa);
for (j = 0; j < npix; j++) {
pixt = pixaGetPix(pixa, j, L_CLONE);
if (j == 0) {
w0 = pixGetWidth(pixt);
h0 = pixGetHeight(pixt);
}
w = pixGetWidth(pixt);
if (width == maxw && x + w >= maxw) {
x = 0;
y += h0 + yspace;
}
h = pixGetHeight(pixt);
pixRasterop(pixd, x, y, w, h, PIX_PAINT, pixt, 0, 0);
pixDestroy(&pixt);
x += w0 + xspace;
}
y += h0 + yspace;
pixaDestroy(&pixa);
}
return pixd;
}
开发者ID:ONLYOFFICE,项目名称:core,代码行数:93,代码来源:pixafunc2.cpp
示例9: pixThinGeneral
/*!
* pixThinGeneral()
*
* Input: pixs (1 bpp)
* type (L_THIN_FG, L_THIN_BG)
* sela (of Sels for parallel composite HMTs)
* maxiters (max number of iters allowed; use 0 to iterate
* until completion)
* Return: pixd, or null on error
*
* Notes:
* (1) See notes in pixThin(). That function chooses among
* the best of the Sels for thinning.
* (2) This is a general function that takes a Sela of HMTs
* that are used in parallel for thinning from each
* of four directions. One iteration consists of four
* such parallel thins.
*/
PIX *
pixThinGeneral(PIX *pixs,
l_int32 type,
SELA *sela,
l_int32 maxiters)
{
l_int32 i, j, r, nsels, same;
PIXA *pixahmt;
PIX **pixhmt; /* array owned by pixahmt; do not destroy! */
PIX *pixd, *pixt;
SEL *sel, *selr;
PROCNAME("pixThinGeneral");
if (!pixs)
return (PIX *)ERROR_PTR("pixs not defined", procName, NULL);
if (pixGetDepth(pixs) != 1)
return (PIX *)ERROR_PTR("pixs not 1 bpp", procName, NULL);
if (type != L_THIN_FG && type != L_THIN_BG)
return (PIX *)ERROR_PTR("invalid fg/bg type", procName, NULL);
if (!sela)
return (PIX *)ERROR_PTR("sela not defined", procName, NULL);
if (maxiters == 0) maxiters = 10000;
/* Set up array of temp pix to hold hmts */
nsels = selaGetCount(sela);
pixahmt = pixaCreate(nsels);
for (i = 0; i < nsels; i++) {
pixt = pixCreateTemplate(pixs);
pixaAddPix(pixahmt, pixt, L_INSERT);
}
pixhmt = pixaGetPixArray(pixahmt);
if (!pixhmt)
return (PIX *)ERROR_PTR("pixhmt array not made", procName, NULL);
#if DEBUG_SELS
pixt = selaDisplayInPix(sela, 35, 3, 15, 4);
pixDisplayWithTitle(pixt, 100, 100, "allsels", 1);
pixDestroy(&pixt);
#endif /* DEBUG_SELS */
/* Set up initial image for fg thinning */
if (type == L_THIN_FG)
pixd = pixCopy(NULL, pixs);
else /* bg thinning */
pixd = pixInvert(NULL, pixs);
/* Thin the fg, with up to maxiters iterations */
for (i = 0; i < maxiters; i++) {
pixt = pixCopy(NULL, pixd); /* test for completion */
for (r = 0; r < 4; r++) { /* over 90 degree rotations of Sels */
for (j = 0; j < nsels; j++) { /* over individual sels in sela */
sel = selaGetSel(sela, j); /* not a copy */
selr = selRotateOrth(sel, r);
pixHMT(pixhmt[j], pixd, selr);
selDestroy(&selr);
if (j > 0)
pixOr(pixhmt[0], pixhmt[0], pixhmt[j]); /* accum result */
}
pixSubtract(pixd, pixd, pixhmt[0]); /* remove result */
}
pixEqual(pixd, pixt, &same);
pixDestroy(&pixt);
if (same) {
L_INFO("%d iterations to completion\n", procName, i);
break;
}
}
if (type == L_THIN_BG)
pixInvert(pixd, pixd);
pixaDestroy(&pixahmt);
return pixd;
}
开发者ID:0ximDigital,项目名称:appsScanner,代码行数:93,代码来源:ccthin.c
示例10: pixaDisplayTiledAndScaled
/*!
* pixaDisplayTiledAndScaled()
*
* Input: pixa
* outdepth (output depth: 1, 8 or 32 bpp)
* tilewidth (each pix is scaled to this width)
* ncols (number of tiles in each row)
* background (0 for white, 1 for black; this is the color
* of the spacing between the images)
* spacing (between images, and on outside)
* border (width of additional black border on each image;
* use 0 for no border)
* Return: pix of tiled images, or null on error
*
* Notes:
* (1) This can be used to tile a number of renderings of
* an image that are at different scales and depths.
* (2) Each image, after scaling and optionally adding the
* black border, has width 'tilewidth'. Thus, the border does
* not affect the spacing between the image tiles. The
* maximum allowed border width is tilewidth / 5.
*/
PIX *
pixaDisplayTiledAndScaled(PIXA *pixa,
l_int32 outdepth,
l_int32 tilewidth,
l_int32 ncols,
l_int32 background,
l_int32 spacing,
l_int32 border)
{
l_int32 x, y, w, h, wd, hd, d;
l_int32 i, n, nrows, maxht, ninrow, irow, bordval;
l_int32 *rowht;
l_float32 scalefact;
PIX *pix, *pixn, *pixt, *pixb, *pixd;
PIXA *pixan;
PROCNAME("pixaDisplayTiledAndScaled");
if (!pixa)
return (PIX *)ERROR_PTR("pixa not defined", procName, NULL);
if (outdepth != 1 && outdepth != 8 && outdepth != 32)
return (PIX *)ERROR_PTR("outdepth not in {1, 8, 32}", procName, NULL);
if (border < 0 || border > tilewidth / 5)
border = 0;
if ((n = pixaGetCount(pixa)) == 0)
return (PIX *)ERROR_PTR("no components", procName, NULL);
/* Normalize scale and depth for each pix; optionally add border */
pixan = pixaCreate(n);
bordval = (outdepth == 1) ? 1 : 0;
for (i = 0; i < n; i++) {
if ((pix = pixaGetPix(pixa, i, L_CLONE)) == NULL)
continue;
pixGetDimensions(pix, &w, &h, &d);
scalefact = (l_float32)(tilewidth - 2 * border) / (l_float32)w;
if (d == 1 && outdepth > 1 && scalefact < 1.0)
pixt = pixScaleToGray(pix, scalefact);
else
pixt = pixScale(pix, scalefact, scalefact);
if (outdepth == 1)
pixn = pixConvertTo1(pixt, 128);
else if (outdepth == 8)
pixn = pixConvertTo8(pixt, FALSE);
else /* outdepth == 32 */
pixn = pixConvertTo32(pixt);
pixDestroy(&pixt);
if (border)
pixb = pixAddBorder(pixn, border, bordval);
else
pixb = pixClone(pixn);
pixaAddPix(pixan, pixb, L_INSERT);
pixDestroy(&pix);
pixDestroy(&pixn);
}
if ((n = pixaGetCount(pixan)) == 0) { /* should not have changed! */
pixaDestroy(&pixan);
return (PIX *)ERROR_PTR("no components", procName, NULL);
}
/* Determine the size of each row and of pixd */
wd = tilewidth * ncols + spacing * (ncols + 1);
nrows = (n + ncols - 1) / ncols;
if ((rowht = (l_int32 *)CALLOC(nrows, sizeof(l_int32))) == NULL)
return (PIX *)ERROR_PTR("rowht array not made", procName, NULL);
maxht = 0;
ninrow = 0;
irow = 0;
for (i = 0; i < n; i++) {
pix = pixaGetPix(pixan, i, L_CLONE);
ninrow++;
pixGetDimensions(pix, &w, &h, NULL);
maxht = L_MAX(h, maxht);
if (ninrow == ncols) {
//.........这里部分代码省略.........
开发者ID:ONLYOFFICE,项目名称:core,代码行数:101,代码来源:pixafunc2.cpp
示例11: pixaaDisplay
/*!
* pixaaDisplay()
*
* Input: pixaa
* w, h (if set to 0, determines the size from the
* b.b. of the components in pixaa)
* Return: pix, or null on error
*
* Notes:
* (1) Each pix of the pixaa is displayed at the location given by
* its box, translated by the box of the containing pixa
* if it exists.
*/
PIX *
pixaaDisplay(PIXAA *pixaa,
l_int32 w,
l_int32 h)
{
l_int32 i, j, n, nbox, na, d, wmax, hmax, x, y, xb, yb, wb, hb;
BOXA *boxa1; /* top-level boxa */
BOXA *boxa;
PIX *pixt, *pixd;
PIXA *pixa;
PROCNAME("pixaaDisplay");
if (!pixaa)
return (PIX *)ERROR_PTR("pixaa not defined", procName, NULL);
n = pixaaGetCount(pixaa);
if (n == 0)
return (PIX *)ERROR_PTR("no components", procName, NULL);
/* If w and h not input, determine the minimum size required
* to contain the origin and all c.c. */
boxa1 = pixaaGetBoxa(pixaa, L_CLONE);
nbox = boxaGetCount(boxa1);
if (w == 0 || h == 0) {
if (nbox == n)
boxaGetExtent(boxa1, &w, &h, NULL);
else { /* have to use the lower-level boxa for each pixa */
wmax = hmax = 0;
for (i = 0; i < n; i++) {
pixa = pixaaGetPixa(pixaa, i, L_CLONE);
boxa = pixaGetBoxa(pixa, L_CLONE);
boxaGetExtent(boxa, &w, &h, NULL);
wmax = L_MAX(wmax, w);
hmax = L_MAX(hmax, h);
pixaDestroy(&pixa);
boxaDestroy(&boxa);
}
w = wmax;
h = hmax;
}
}
/* Get depth from first pix */
pixa = pixaaGetPixa(pixaa, 0, L_CLONE);
pixt = pixaGetPix(pixa, 0, L_CLONE);
d = pixGetDepth(pixt);
pixaDestroy(&pixa);
pixDestroy(&pixt);
if ((pixd = pixCreate(w, h, d)) == NULL)
return (PIX *)ERROR_PTR("pixd not made", procName, NULL);
x = y = 0;
for (i = 0; i < n; i++) {
pixa = pixaaGetPixa(pixaa, i, L_CLONE);
if (nbox == n)
boxaGetBoxGeometry(boxa1, i, &x, &y, NULL, NULL);
na = pixaGetCount(pixa);
for (j = 0; j < na; j++) {
pixaGetBoxGeometry(pixa, j, &xb, &yb, &wb, &hb);
pixt = pixaGetPix(pixa, j, L_CLONE);
pixRasterop(pixd, x + xb, y + yb, wb, hb, PIX_PAINT, pixt, 0, 0);
pixDestroy(&pixt);
}
pixaDestroy(&pixa);
}
boxaDestroy(&boxa1);
return pixd;
}
开发者ID:ONLYOFFICE,项目名称:core,代码行数:84,代码来源:pixafunc2.cpp
示例12: pixaDisplayTiledInRows
/*!
* pixaDisplayTiledInRows()
*
* Input: pixa
* outdepth (output depth: 1, 8 or 32 bpp)
* maxwidth (of output image)
* scalefactor (applied to every pix; use 1.0 for no scaling)
* background (0 for white, 1 for black; this is the color
* of the spacing between the images)
* spacing (between images, and on outside)
* border (width of black border added to each image;
* use 0 for no border)
* Return: pixd (of tiled images), or null on error
*
* Notes:
* (1) This saves a pixa to a single image file of width not to
* exceed maxwidth, with background color either white or black,
* and with each row tiled such that the top of each pix is
* aligned and separated by 'spacing' from the next one.
* A black border can be added to each pix.
* (2) All pix are converted to outdepth; existing colormaps are removed.
* (3) This does a reasonably spacewise-efficient job of laying
* out the individual pix images into a tiled composite.
*/
PIX *
pixaDisplayTiledInRows(PIXA *pixa,
l_int32 outdepth,
l_int32 maxwidth,
l_float32 scalefactor,
l_int32 background,
l_int32 spacing,
l_int32 border)
{
l_int32 h; /* cumulative height over all the rows */
l_int32 w; /* cumulative height in the current row */
l_int32 bordval, wtry, wt, ht;
l_int32 irow; /* index of current pix in current row */
l_int32 wmaxrow; /* width of the largest row */
l_int32 maxh; /* max height in row */
l_int32 i, j, index, n, x, y, nrows, ninrow;
NUMA *nainrow; /* number of pix in the row */
NUMA *namaxh; /* height of max pix in the row */
PIX *pix, *pixn, *pixt, *pixd;
PIXA *pixan;
PROCNAME("pixaDisplayTiledInRows");
if (!pixa)
return (PIX *)ERROR_PTR("pixa not defined", procName, NULL);
if (outdepth != 1 && outdepth != 8 && outdepth != 32)
return (PIX *)ERROR_PTR("outdepth not in {1, 8, 32}", procName, NULL);
if (border < 0)
border = 0;
if (scalefactor <= 0.0) scalefactor = 1.0;
if ((n = pixaGetCount(pixa)) == 0)
return (PIX *)ERROR_PTR("no components", procName, NULL);
/* Normalize depths, scale, remove colormaps; optionally add border */
pixan = pixaCreate(n);
bordval = (outdepth == 1) ? 1 : 0;
for (i = 0; i < n; i++) {
if ((pix = pixaGetPix(pixa, i, L_CLONE)) == NULL)
continue;
if (outdepth == 1)
pixn = pixConvertTo1(pix, 128);
else if (outdepth == 8)
pixn = pixConvertTo8(pix, FALSE);
else /* outdepth == 32 */
pixn = pixConvertTo32(pix);
pixDestroy(&pix);
if (scalefactor != 1.0)
pixt = pixScale(pixn, scalefactor, scalefactor);
else
pixt = pixClone(pixn);
if (border)
pixd = pixAddBorder(pixt, border, bordval);
else
pixd = pixClone(pixt);
pixDestroy(&pixn);
pixDestroy(&pixt);
pixaAddPix(pixan, pixd, L_INSERT);
}
if (pixaGetCount(pixan) != n) {
n = pixaGetCount(pixan);
L_WARNING_INT("only got %d components", procName, n);
if (n == 0) {
pixaDestroy(&pixan);
return (PIX *)ERROR_PTR("no components", procName, NULL);
}
}
/* Compute parameters for layout */
nainrow = numaCreate(0);
namaxh = numaCreate(0);
wmaxrow = 0;
w = h = spacing;
//.........这里部分代码省略.........
开发者ID:ONLYOFFICE,项目名称:core,代码行数:101,代码来源:pixafunc2.cpp
示例13: pixaDisplayTiled
/*!
* pixaDisplayTiled()
*
* Input: pixa
* maxwidth (of output image)
* background (0 for white, 1 for black)
* spacing
* Return: pix of tiled images, or null on error
*
* Notes:
* (1) This saves a pixa to a single image file of width not to
* exceed maxwidth, with background color either white or black,
* and with each subimage spaced on a regular lattice.
* (2) The lattice size is determined from the largest width and height,
* separately, of all pix in the pixa.
* (3) All pix in the pixa must be of equal depth.
* (4) If any pix has a colormap, all pix are rendered in rgb.
* (5) Careful: because no components are omitted, this is
* dangerous if there are thousands of small components and
* one or more very large one, because the size of the
* resulting pix can be huge!
*/
PIX *
pixaDisplayTiled(PIXA *pixa,
l_int32 maxwidth,
l_int32 background,
l_int32 spacing)
{
l_int32 w, h, wmax, hmax, wd, hd, d, hascmap;
l_int32 i, j, n, ni, ncols, nrows;
l_int32 ystart, xstart, wt, ht;
PIX *pix, *pixt, *pixd;
PIXA *pixat;
PROCNAME("pixaDisplayTiled");
if (!pixa)
return (PIX *)ERROR_PTR("pixa not defined", procName, NULL);
/* If any pix have colormaps, generate rgb */
if ((n = pixaGetCount(pixa)) == 0)
return (PIX *)ERROR_PTR("no components", procName, NULL);
pixaAnyColormaps(pixa, &hascmap);
if (hascmap) {
pixat = pixaCreate(n);
for (i = 0; i < n; i++) {
pixt = pixaGetPix(pixa, i, L_CLONE);
pix = pixConvertTo32(pixt);
pixaAddPix(pixat, pix, L_INSERT);
pixDestroy(&pixt);
}
}
else
pixat = pixaCopy(pixa, L_CLONE);
/* Find the largest width and height of the subimages */
wmax = hmax = 0;
for (i = 0; i < n; i++) {
pix = pixaGetPix(pixat, i, L_CLONE);
pixGetDimensions(pix, &w, &h, NULL);
if (i == 0)
d = pixGetDepth(pix);
else if (d != pixGetDepth(pix)) {
pixDestroy(&pix);
pixaDestroy(&pixat);
return (PIX *)ERROR_PTR("depths not equal", procName, NULL);
}
if (w > wmax)
wmax = w;
if (h > hmax)
hmax = h;
pixDestroy(&pix);
}
/* Get the number of rows and columns and the output image size */
spacing = L_MAX(spacing, 0);
ncols = (l_int32)((l_float32)(maxwidth - spacing) /
(l_float32)(wmax + spacing));
nrows = (n + ncols - 1) / ncols;
wd = wmax * ncols + spacing * (ncols + 1);
hd = hmax * nrows + spacing * (nrows + 1);
if ((pixd = pixCreate(wd, hd, d)) == NULL) {
pixaDestroy(&pixat);
return (PIX *)ERROR_PTR("pixd not made", procName, NULL);
}
#if 0
fprintf(stderr, " nrows = %d, ncols = %d, wmax = %d, hmax = %d\n",
nrows, ncols, wmax, hmax);
fprintf(stderr, " space = %d, wd = %d, hd = %d, n = %d\n",
space, wd, hd, n);
#endif
/* Reset the background color if necessary */
if ((background == 1 && d == 1) || (background == 0 && d != 1))
pixSetAll(pixd);
/* Blit the images to the dest */
for (i = 0, ni = 0; i < nrows; i++) {
ystart = spacing + i * (hmax + spacing);
//.........这里部分代码省略.........
开发者ID:ONLYOFFICE,项目名称:core,代码行数:101,代码来源:pixafunc2.cpp
示例14: pixaDisplayOnLattice
/*!
* pixaDisplayOnLattice()
*
* Input: pixa
* xspace
* yspace
* Return: pix of composite images, or null on error
*
* Notes:
* (1) This places each pix on sequentially on a regular lattice
* in the rendered composite. If a pix is too large to fit in the
* allocated lattice space, it is not rendered.
* (2) If any pix has a colormap, all pix are rendered in rgb.
* (3) This is useful when putting bitmaps of components,
* such as characters, into a single image.
*/
PIX *
pixaDisplayOnLattice(PIXA *pixa,
l_int32 xspace,
l_int32 yspace)
{
l_int32 n, nw, nh, w, h, d, wt, ht;
l_int32 index, i, j, hascmap;
PIX *pix, *pixt, *pixd;
PIXA *pixat;
PROCNAME("pixaDisplayOnLattice");
if (!pixa)
return (PIX *)ERROR_PTR("pixa not defined", procName, NULL);
/* If any pix have colormaps, generate rgb */
if ((n = pixaGetCount(pixa)) == 0)
return (PIX *)ERROR_PTR("no components", procName, NULL);
pixaAnyColormaps(pixa, &hascmap);
if (hascmap) {
pixat = pixaCreate(n);
for (i = 0; i < n; i++) {
pixt = pixaGetPix(pixa, i, L_CLONE);
pix = pixConvertTo32(pixt);
pixaAddPix(pixat, pix, L_INSERT);
pixDestroy(&pixt);
}
}
else
pixat = pixaCopy(pixa, L_CLONE);
nw = (l_int32)sqrt((l_float64)n);
nh = (n + nw - 1) / nw;
w = xspace * nw;
h = yspace * nh;
/* Use the first pix in pixa to determine the depth. */
pixaGetPixDimensions(pixat, 0, NULL, NULL, &d);
if ((pixd = pixCreate(w, h, d)) == NULL) {
pixaDestroy(&pixat);
return (PIX *)ERROR_PTR("pixd not made", procName, NULL);
}
index = 0;
for (i = 0; i < nh; i++) {
for (j = 0; j < nw && index < n; j++, index++) {
pixt = pixaGetPix(pixat, index, L_CLONE);
pixGetDimensions(pixt, &wt, &ht, NULL);
if (wt > xspace || ht > yspace) {
fprintf(stderr, "pix(%d) omitted; size %dx%d\n", index, wt, ht);
pixDestroy(&pixt);
continue;
}
pixRasterop(pixd, j * xspace, i * yspace, wt, ht,
PIX_PAINT, pixt, 0, 0);
pixDestroy(&pixt);
}
}
pixaDestroy(&pixat);
return pixd;
}
开发者ID:ONLYOFFICE,项目名称:core,代码行数:79,代码来源:pixafunc2.cpp
示例15: selaAddHitMiss
/*!
* selaAddHitMiss()
*
* Input: sela (<optional>)
* Return: sela with additional sels, or null on error
*/
SELA *
selaAddHitMiss(SELA *sela)
{
SEL *sel;
PROCNAME("selaAddHitMiss");
if (!sela) {
if ((sela = selaCreate(0)) == NULL)
return (SELA *)ERROR_PTR("sela not made", procName, NULL);
}
#if 0 /* use just for testing */
sel = selCreateBrick(3, 3, 1, 1, 2);
selaAddSel(sela, sel, "sel_bad", 0);
#endif
/*--------------------------------------------------------------*
* Isolated foreground pixel *
*--------------------------------------------------------------*/
sel = selCreateBrick(3, 3, 1, 1, SEL_MISS);
selSetElement(sel, 1, 1, SEL_HIT);
selaAddSel(sela, sel, "sel_3hm", 0);
/*--------------------------------------------------------------*
* Horizontal and vertical edges *
*--------------------------------------------------------------*/
sel = selCreateBrick(2, 3, 0, 1, SEL_HIT);
selSetElement(sel, 1, 0, SEL_MISS);
selSetElement(sel, 1, 1, SEL_MISS);
selSetElement(sel, 1, 2, SEL_MISS);
selaAddSel(sela, sel, "sel_3de", 0);
sel = selCreateBrick(2, 3, 1, 1, SEL_HIT);
selSetElement(sel, 0, 0, SEL_MISS);
selSetElement(sel, 0, 1, SEL_MISS);
selSetElement(sel, 0, 2, SEL_MISS);
selaAddSel(sela, sel, "sel_3ue", 0);
sel = selCreateBrick(3, 2, 1, 0, SEL_HIT);
selSetElement(sel, 0, 1, SEL_MISS);
selSetElement(sel, 1, 1, SEL_MISS);
selSetElement(sel, 2, 1, SEL_MISS);
selaAddSel(sela, sel, "sel_3re", 0);
sel = selCreateBrick(3, 2, 1, 1, SEL_HIT);
selSetElement(sel, 0, 0, SEL_MISS);
selSetElement(sel, 1, 0, SEL_MISS);
selSetElement(sel, 2, 0, SEL_MISS);
selaAddSel(sela, sel, "sel_3le", 0);
/*--------------------------------------------------------------*
* Slanted edge *
*--------------------------------------------------------------*/
sel = selCreateBrick(13, 6, 6, 2, SEL_DONT_CARE);
selSetElement(sel, 0, 3, SEL_MISS);
selSetElement(sel, 0, 5, SEL_HIT);
selSetElement(sel, 4, 2, SEL_MISS);
selSetElement(sel, 4, 4, SEL_HIT);
selSetElement(sel, 8, 1, SEL_MISS);
selSe
|
请发表评论