193 #include "allheaders.h" 231 pix_malloc(
size_t size)
308 PROCNAME(
"pixCreate");
311 return (
PIX *)ERROR_PTR(
"pixd not made", procName, NULL);
312 memset(pixd->
data, 0, 4LL * pixd->
wpl * pixd->
h);
339 PROCNAME(
"pixCreateNoInit");
341 return (
PIX *)ERROR_PTR(
"pixd not made", procName, NULL);
342 wpl = pixGetWpl(pixd);
343 if ((data = (l_uint32 *)pix_malloc(4LL * wpl * height)) == NULL) {
345 return (
PIX *)ERROR_PTR(
"pix_malloc fail for data", procName, NULL);
371 PROCNAME(
"pixCreateTemplate");
374 return (
PIX *)ERROR_PTR(
"pixs not defined", procName, NULL);
377 return (
PIX *)ERROR_PTR(
"pixd not made", procName, NULL);
378 memset(pixd->
data, 0, 4LL * pixd->
wpl * pixd->
h);
402 PROCNAME(
"pixCreateTemplateNoInit");
405 return (
PIX *)ERROR_PTR(
"pixs not defined", procName, NULL);
409 return (
PIX *)ERROR_PTR(
"pixd not made", procName, NULL);
411 pixCopyResolution(pixd, pixs);
413 pixCopyText(pixd, pixs);
414 pixCopyInputFormat(pixd, pixs);
445 l_uint64 wpl64, bignum;
448 PROCNAME(
"pixCreateHeader");
450 if ((depth != 1) && (depth != 2) && (depth != 4) && (depth != 8)
451 && (depth != 16) && (depth != 24) && (depth != 32))
452 return (
PIX *)ERROR_PTR(
"depth must be {1, 2, 4, 8, 16, 24, 32}",
455 return (
PIX *)ERROR_PTR(
"width must be > 0", procName, NULL);
457 return (
PIX *)ERROR_PTR(
"height must be > 0", procName, NULL);
460 wpl64 = ((l_uint64)width * (l_uint64)depth + 31) / 32;
461 if (wpl64 > ((1LL << 29) - 1)) {
462 L_ERROR(
"requested w = %d, h = %d, d = %d\n",
463 procName, width, height, depth);
464 return (
PIX *)ERROR_PTR(
"wpl >= 2^29", procName, NULL);
466 wpl = (l_int32)wpl64;
467 bignum = 4LL * wpl * height;
468 if (bignum > ((1LL << 31) - 1)) {
469 L_ERROR(
"requested w = %d, h = %d, d = %d\n",
470 procName, width, height, depth);
471 return (
PIX *)ERROR_PTR(
"requested bytes >= 2^31", procName, NULL);
474 if ((pixd = (
PIX *)LEPT_CALLOC(1,
sizeof(
PIX))) == NULL)
475 return (
PIX *)ERROR_PTR(
"LEPT_CALLOC fail for pixd", procName, NULL);
476 pixSetWidth(pixd, width);
477 pixSetHeight(pixd, height);
478 pixSetDepth(pixd, depth);
479 pixSetWpl(pixd, wpl);
480 if (depth == 24 || depth == 32)
517 PROCNAME(
"pixClone");
520 return (
PIX *)ERROR_PTR(
"pixs not defined", procName, NULL);
521 pixChangeRefcount(pixs, 1);
547 PROCNAME(
"pixDestroy");
550 L_WARNING(
"ptr address is null!\n", procName);
554 if ((pix = *ppix) == NULL)
581 pixChangeRefcount(pix, -1);
582 if (pixGetRefcount(pix) <= 0) {
632 l_uint32 *datas, *datad;
637 return (
PIX *)ERROR_PTR(
"pixs not defined", procName, pixd);
642 bytes = 4 * pixGetWpl(pixs) * pixGetHeight(pixs);
647 return (
PIX *)ERROR_PTR(
"pixd not made", procName, NULL);
650 memcpy(datad, datas, bytes);
661 return (
PIX *)ERROR_PTR(
"reallocation of data failed", procName, NULL);
666 pixCopyResolution(pixd, pixs);
667 pixCopyInputFormat(pixd, pixs);
668 pixCopyText(pixd, pixs);
673 memcpy(datad, datas, bytes);
699 l_int32 w, h, d, wpl, bytes;
702 PROCNAME(
"pixResizeImageData");
705 return ERROR_INT(
"pixs not defined", procName, 1);
707 return ERROR_INT(
"pixd not defined", procName, 1);
714 wpl = pixGetWpl(pixs);
716 if ((data = (l_uint32 *)pix_malloc(bytes)) == NULL)
717 return ERROR_INT(
"pix_malloc fail for data", procName, 1);
720 pixSetWidth(pixd, w);
721 pixSetHeight(pixd, h);
722 pixSetDepth(pixd, d);
723 pixSetWpl(pixd, wpl);
726 pixCopyResolution(pixd, pixs);
751 PROCNAME(
"pixCopyColormap");
754 return ERROR_INT(
"pixs not defined", procName, 1);
756 return ERROR_INT(
"pixd not defined", procName, 1);
761 if ((cmaps = pixGetColormap(pixs)) == NULL)
765 return ERROR_INT(
"cmap not valid", procName, 1);
768 return ERROR_INT(
"cmapd not made", procName, 1);
784 PROCNAME(
"pixSizesEqual");
787 return ERROR_INT(
"pix1 and pix2 not both defined", procName, 0);
792 if ((pixGetWidth(pix1) != pixGetWidth(pix2)) ||
793 (pixGetHeight(pix1) != pixGetHeight(pix2)) ||
794 (pixGetDepth(pix1) != pixGetDepth(pix2)))
863 PROCNAME(
"pixTransferAllData");
866 return ERROR_INT(
"&pixs not defined", procName, 1);
867 if ((pixs = *ppixs) == NULL)
868 return ERROR_INT(
"pixs not defined", procName, 1);
870 return ERROR_INT(
"pixd not defined", procName, 1);
872 return ERROR_INT(
"pixd == pixs", procName, 1);
874 if (pixGetRefcount(pixs) == 1) {
886 nbytes = 4 * pixGetWpl(pixs) * pixGetHeight(pixs);
890 pixCopyText(pixd, pixs);
894 pixCopyResolution(pixd, pixs);
897 pixCopyInputFormat(pixd, pixs);
948 PROCNAME(
"pixSwapAndDestroy");
951 return ERROR_INT(
"&pixd not defined", procName, 1);
953 return ERROR_INT(
"&pixs not defined", procName, 1);
955 return ERROR_INT(
"pixs not defined", procName, 1);
957 return ERROR_INT(
"&pixd == &pixs", procName, 1);
970 pixGetWidth(
const PIX *pix)
972 PROCNAME(
"pixGetWidth");
975 return ERROR_INT(
"pix not defined", procName, 0);
982 pixSetWidth(
PIX *pix,
985 PROCNAME(
"pixSetWidth");
988 return ERROR_INT(
"pix not defined", procName, 1);
991 return ERROR_INT(
"width must be >= 0", procName, 1);
1000 pixGetHeight(
const PIX *pix)
1002 PROCNAME(
"pixGetHeight");
1005 return ERROR_INT(
"pix not defined", procName, 0);
1012 pixSetHeight(
PIX *pix,
1015 PROCNAME(
"pixSetHeight");
1018 return ERROR_INT(
"pix not defined", procName, 1);
1021 return ERROR_INT(
"h must be >= 0", procName, 1);
1030 pixGetDepth(
const PIX *pix)
1032 PROCNAME(
"pixGetDepth");
1035 return ERROR_INT(
"pix not defined", procName, 0);
1042 pixSetDepth(
PIX *pix,
1045 PROCNAME(
"pixSetDepth");
1048 return ERROR_INT(
"pix not defined", procName, 1);
1050 return ERROR_INT(
"d must be >= 1", procName, 1);
1070 PROCNAME(
"pixGetDimensions");
1076 return ERROR_INT(
"pix not defined", procName, 1);
1077 if (pw) *pw = pix->
w;
1078 if (ph) *ph = pix->
h;
1079 if (pd) *pd = pix->
d;
1097 PROCNAME(
"pixSetDimensions");
1100 return ERROR_INT(
"pix not defined", procName, 1);
1101 if (w > 0) pixSetWidth(pix, w);
1102 if (h > 0) pixSetHeight(pix, h);
1103 if (d > 0) pixSetDepth(pix, d);
1119 PROCNAME(
"pixCopyDimensions");
1122 return ERROR_INT(
"pixd not defined", procName, 1);
1124 return ERROR_INT(
"pixs not defined", procName, 1);
1128 pixSetWidth(pixd, pixGetWidth(pixs));
1129 pixSetHeight(pixd, pixGetHeight(pixs));
1130 pixSetDepth(pixd, pixGetDepth(pixs));
1131 pixSetWpl(pixd, pixGetWpl(pixs));
1137 pixGetSpp(
const PIX *pix)
1139 PROCNAME(
"pixGetSpp");
1142 return ERROR_INT(
"pix not defined", procName, 0);
1168 PROCNAME(
"pixSetSpp");
1171 return ERROR_INT(
"pix not defined", procName, 1);
1173 return ERROR_INT(
"spp must be >= 1", procName, 1);
1191 PROCNAME(
"pixCopySpp");
1194 return ERROR_INT(
"pixd not defined", procName, 1);
1196 return ERROR_INT(
"pixs not defined", procName, 1);
1200 pixSetSpp(pixd, pixGetSpp(pixs));
1206 pixGetWpl(
const PIX *pix)
1208 PROCNAME(
"pixGetWpl");
1211 return ERROR_INT(
"pix not defined", procName, 0);
1220 PROCNAME(
"pixSetWpl");
1223 return ERROR_INT(
"pix not defined", procName, 1);
1231 pixGetRefcount(
const PIX *pix)
1233 PROCNAME(
"pixGetRefcount");
1236 return ERROR_INT(
"pix not defined", procName, 0);
1242 pixChangeRefcount(
PIX *pix,
1245 PROCNAME(
"pixChangeRefcount");
1248 return ERROR_INT(
"pix not defined", procName, 1);
1256 pixGetXRes(
const PIX *pix)
1258 PROCNAME(
"pixGetXRes");
1261 return ERROR_INT(
"pix not defined", procName, 0);
1267 pixSetXRes(
PIX *pix,
1270 PROCNAME(
"pixSetXRes");
1273 return ERROR_INT(
"pix not defined", procName, 1);
1281 pixGetYRes(
const PIX *pix)
1283 PROCNAME(
"pixGetYRes");
1286 return ERROR_INT(
"pix not defined", procName, 0);
1292 pixSetYRes(
PIX *pix,
1295 PROCNAME(
"pixSetYRes");
1298 return ERROR_INT(
"pix not defined", procName, 1);
1317 PROCNAME(
"pixGetResolution");
1319 if (pxres) *pxres = 0;
1320 if (pyres) *pyres = 0;
1321 if (!pxres && !pyres)
1322 return ERROR_INT(
"no output requested", procName, 1);
1324 return ERROR_INT(
"pix not defined", procName, 1);
1325 if (pxres) *pxres = pix->
xres;
1326 if (pyres) *pyres = pix->
yres;
1343 PROCNAME(
"pixSetResolution");
1346 return ERROR_INT(
"pix not defined", procName, 1);
1347 if (xres > 0) pix->
xres = xres;
1348 if (yres > 0) pix->
yres = yres;
1354 pixCopyResolution(
PIX *pixd,
1357 PROCNAME(
"pixCopyResolution");
1360 return ERROR_INT(
"pixs not defined", procName, 1);
1362 return ERROR_INT(
"pixd not defined", procName, 1);
1366 pixSetXRes(pixd, pixGetXRes(pixs));
1367 pixSetYRes(pixd, pixGetYRes(pixs));
1373 pixScaleResolution(
PIX *pix,
1377 PROCNAME(
"pixScaleResolution");
1380 return ERROR_INT(
"pix not defined", procName, 1);
1382 if (pix->
xres != 0 && pix->
yres != 0) {
1383 pix->
xres = (l_uint32)(xscale * (l_float32)(pix->
xres) + 0.5);
1384 pix->
yres = (l_uint32)(yscale * (l_float32)(pix->
yres) + 0.5);
1391 pixGetInputFormat(
const PIX *pix)
1393 PROCNAME(
"pixGetInputFormat");
1396 return ERROR_INT(
"pix not defined", procName, 0);
1402 pixSetInputFormat(
PIX *pix,
1405 PROCNAME(
"pixSetInputFormat");
1408 return ERROR_INT(
"pix not defined", procName, 1);
1415 pixCopyInputFormat(
PIX *pixd,
1418 PROCNAME(
"pixCopyInputFormat");
1421 return ERROR_INT(
"pixs not defined", procName, 1);
1423 return ERROR_INT(
"pixd not defined", procName, 1);
1427 pixSetInputFormat(pixd, pixGetInputFormat(pixs));
1433 pixSetSpecial(
PIX *pix,
1436 PROCNAME(
"pixSetSpecial");
1439 return ERROR_INT(
"pix not defined", procName, 1);
1461 PROCNAME(
"pixGetText");
1464 return (
char *)ERROR_PTR(
"pix not defined", procName, NULL);
1484 const char *textstring)
1486 PROCNAME(
"pixSetText");
1489 return ERROR_INT(
"pix not defined", procName, 1);
1512 const char *textstring)
1516 PROCNAME(
"pixAddText");
1519 return ERROR_INT(
"pix not defined", procName, 1);
1523 LEPT_FREE(newstring);
1529 pixCopyText(
PIX *pixd,
1532 PROCNAME(
"pixCopyText");
1535 return ERROR_INT(
"pixs not defined", procName, 1);
1537 return ERROR_INT(
"pixd not defined", procName, 1);
1547 pixGetColormap(
PIX *pix)
1549 PROCNAME(
"pixGetColormap");
1552 return (
PIXCMAP *)ERROR_PTR(
"pix not defined", procName, NULL);
1576 PROCNAME(
"pixSetColormap");
1579 return ERROR_INT(
"pix not defined", procName, 1);
1598 PROCNAME(
"pixDestroyColormap");
1601 return ERROR_INT(
"pix not defined", procName, 1);
1603 if ((cmap = pix->
colormap) != NULL) {
1626 PROCNAME(
"pixGetData");
1629 return (l_uint32 *)ERROR_PTR(
"pix not defined", procName, NULL);
1651 PROCNAME(
"pixSetData");
1654 return ERROR_INT(
"pix not defined", procName, 1);
1680 l_int32 count, bytes;
1681 l_uint32 *data, *datas;
1683 PROCNAME(
"pixExtractData");
1686 return (l_uint32 *)ERROR_PTR(
"pixs not defined", procName, NULL);
1688 count = pixGetRefcount(pixs);
1693 bytes = 4 * pixGetWpl(pixs) * pixGetHeight(pixs);
1695 if ((data = (l_uint32 *)pix_malloc(bytes)) == NULL)
1696 return (l_uint32 *)ERROR_PTR(
"data not made", procName, NULL);
1697 memcpy(data, datas, bytes);
1723 PROCNAME(
"pixFreeData");
1726 return ERROR_INT(
"pix not defined", procName, 1);
1817 PROCNAME(
"pixGetLinePtrs");
1819 if (psize) *psize = 0;
1821 return (
void **)ERROR_PTR(
"pix not defined", procName, NULL);
1823 h = pixGetHeight(pix);
1824 if (psize) *psize = h;
1825 if ((lines = (
void **)LEPT_CALLOC(h,
sizeof(
void *))) == NULL)
1826 return (
void **)ERROR_PTR(
"lines not made", procName, NULL);
1827 wpl = pixGetWpl(pix);
1829 for (i = 0; i < h; i++)
1830 lines[i] = (
void *)(data + i * wpl);
1839 extern const char *ImageFileFormatExtensions[];
1858 PROCNAME(
"pixPrintStreamInfo");
1861 return ERROR_INT(
"fp not defined", procName, 1);
1863 return ERROR_INT(
"pix not defined", procName, 1);
1866 fprintf(fp,
" Pix Info for %s:\n", text);
1867 fprintf(fp,
" width = %d, height = %d, depth = %d, spp = %d\n",
1868 pixGetWidth(pix), pixGetHeight(pix), pixGetDepth(pix),
1870 fprintf(fp,
" wpl = %d, data = %p, refcount = %d\n",
1871 pixGetWpl(pix),
pixGetData(pix), pixGetRefcount(pix));
1872 fprintf(fp,
" xres = %d, yres = %d\n", pixGetXRes(pix), pixGetYRes(pix));
1873 if ((cmap = pixGetColormap(pix)) != NULL)
1876 fprintf(fp,
" no colormap\n");
1877 informat = pixGetInputFormat(pix);
1878 fprintf(fp,
" input format: %d (%s)\n", informat,
1879 ImageFileFormatExtensions[informat]);
1881 fprintf(fp,
" text: %s\n", textdata);
l_ok pixResizeImageData(PIX *pixd, const PIX *pixs)
pixResizeImageData()
l_int32 pixFreeData(PIX *pix)
pixFreeData()
l_int32 pixSetData(PIX *pix, l_uint32 *data)
pixSetData()
struct PixColormap * colormap
void ** pixGetLinePtrs(PIX *pix, l_int32 *psize)
pixGetLinePtrs()
l_ok pixcmapWriteStream(FILE *fp, PIXCMAP *cmap)
pixcmapWriteStream()
void(* dealloc_fn)(void *)
l_uint32 * pixExtractData(PIX *pixs)
pixExtractData()
PIX * pixCreate(l_int32 width, l_int32 height, l_int32 depth)
pixCreate()
void pixcmapDestroy(PIXCMAP **pcmap)
pixcmapDestroy()
l_uint32 * pixGetData(PIX *pix)
pixGetData()
PIX * pixCreateTemplate(PIX *pixs)
pixCreateTemplate()
l_ok pixSetColormap(PIX *pix, PIXCMAP *colormap)
pixSetColormap()
PIX * pixCreateTemplateNoInit(PIX *pixs)
pixCreateTemplateNoInit()
l_ok pixSetDimensions(PIX *pix, l_int32 w, l_int32 h, l_int32 d)
pixSetDimensions()
static struct PixMemoryManager pix_mem_manager
l_ok pixSetText(PIX *pix, const char *textstring)
pixSetText()
l_ok pixGetResolution(const PIX *pix, l_int32 *pxres, l_int32 *pyres)
pixGetResolution()
l_ok pixDestroyColormap(PIX *pix)
pixDestroyColormap()
static void pixFree(PIX *pix)
pixFree()
l_ok pixcmapIsValid(PIXCMAP *cmap, l_int32 *pvalid)
pixcmapIsValid()
PIX * pixCreateHeader(l_int32 width, l_int32 height, l_int32 depth)
pixCreateHeader()
l_ok pixSetPadBits(PIX *pix, l_int32 val)
pixSetPadBits()
PIX * pixCreateNoInit(l_int32 width, l_int32 height, l_int32 depth)
pixCreateNoInit()
PIX * pixClone(PIX *pixs)
pixClone()
l_ok stringReplace(char **pdest, const char *src)
stringReplace()
void pixDestroy(PIX **ppix)
pixDestroy()
l_ok pixCopyColormap(PIX *pixd, PIX *pixs)
pixCopyColormap()
l_ok pixGetDimensions(const PIX *pix, l_int32 *pw, l_int32 *ph, l_int32 *pd)
pixGetDimensions()
l_ok pixSwapAndDestroy(PIX **ppixd, PIX **ppixs)
pixSwapAndDestroy()
char * pixGetText(PIX *pix)
pixGetText()
l_ok pixPrintStreamInfo(FILE *fp, PIX *pix, const char *text)
pixPrintStreamInfo()
char * stringJoin(const char *src1, const char *src2)
stringJoin()
void *(* alloc_fn)(size_t)
PIX * pixCopy(PIX *pixd, PIX *pixs)
pixCopy()
l_ok pixSetResolution(PIX *pix, l_int32 xres, l_int32 yres)
pixSetResolution()
PIXCMAP * pixcmapCopy(PIXCMAP *cmaps)
pixcmapCopy()
l_ok pixCopyDimensions(PIX *pixd, const PIX *pixs)
pixCopyDimensions()
l_ok pixCopySpp(PIX *pixd, const PIX *pixs)
pixCopySpp()
l_ok pixTransferAllData(PIX *pixd, PIX **ppixs, l_int32 copytext, l_int32 copyformat)
pixTransferAllData()
l_int32 pixSizesEqual(const PIX *pix1, const PIX *pix2)
pixSizesEqual()
void setPixMemoryManager(alloc_fn allocator, dealloc_fn deallocator)
setPixMemoryManager()
l_ok pixAddText(PIX *pix, const char *textstring)
pixAddText()