MCPcopy Create free account
hub / github.com/creatale/node-dv / ioFormatTest

Function ioFormatTest

deps/leptonica/src/readfile.c:1261–1573  ·  view source on GitHub ↗

---------------------------------------------------------------------* * Test function for I/O with different formats * *---------------------------------------------------------------------*/ ! * \brief ioFormatTest() * * \param[in] filename input file * \return 0 if OK; 1 on error or if the test fails * * * Notes: * (1) This writes and reads a se

Source from the content-addressed store, hash-verified

1259 * </pre>
1260 */
1261l_int32
1262ioFormatTest(const char *filename)
1263{
1264l_int32 w, h, d, depth, equal, problems;
1265l_float32 diff;
1266BOX *box;
1267PIX *pixs, *pixc, *pix1, *pix2;
1268PIXCMAP *cmap;
1269
1270 PROCNAME("ioFormatTest");
1271
1272 if (!filename)
1273 return ERROR_INT("filename not defined", procName, 1);
1274
1275 /* Read the input file and limit the size */
1276 if ((pix1 = pixRead(filename)) == NULL)
1277 return ERROR_INT("pix1 not made", procName, 1);
1278 pixGetDimensions(pix1, &w, &h, NULL);
1279 if (w > 250 && h > 250) { /* take the central 250 x 250 region */
1280 box = boxCreate(w / 2 - 125, h / 2 - 125, 250, 250);
1281 pixs = pixClipRectangle(pix1, box, NULL);
1282 boxDestroy(&box);
1283 } else {
1284 pixs = pixClone(pix1);
1285 }
1286 pixDestroy(&pix1);
1287
1288 lept_mkdir("lept/format");
1289
1290 /* Note that the reader automatically removes colormaps
1291 * from 1 bpp BMP images, but not from 8 bpp BMP images.
1292 * Therefore, if our 8 bpp image initially doesn't have a
1293 * colormap, we are going to need to remove it from any
1294 * pix read from a BMP file. */
1295 pixc = pixClone(pixs); /* laziness */
1296
1297 /* This does not test the alpha layer pixels, because most
1298 * formats don't support it. Remove any alpha. */
1299 if (pixGetSpp(pixc) == 4)
1300 pixSetSpp(pixc, 3);
1301 cmap = pixGetColormap(pixc); /* colormap; can be NULL */
1302 d = pixGetDepth(pixc);
1303
1304 problems = FALSE;
1305
1306 /* ----------------------- BMP -------------------------- */
1307
1308 /* BMP works for 1, 2, 4, 8 and 32 bpp images.
1309 * It always writes colormaps for 1 and 8 bpp, so we must
1310 * remove it after readback if the input image doesn't have
1311 * a colormap. Although we can write/read 2 bpp BMP, nobody
1312 * else can read them! */
1313 if (d == 1 || d == 8) {
1314 L_INFO("write/read bmp\n", procName);
1315 pixWrite(FILE_BMP, pixc, IFF_BMP);
1316 pix1 = pixRead(FILE_BMP);
1317 if (!cmap)
1318 pix2 = pixRemoveColormap(pix1, REMOVE_CMAP_BASED_ON_SRC);

Callers

nothing calls this directly

Calls 15

pixReadFunction · 0.85
pixGetDimensionsFunction · 0.85
boxCreateFunction · 0.85
pixClipRectangleFunction · 0.85
boxDestroyFunction · 0.85
pixCloneFunction · 0.85
pixDestroyFunction · 0.85
lept_mkdirFunction · 0.85
pixGetSppFunction · 0.85
pixSetSppFunction · 0.85
pixGetColormapFunction · 0.85
pixGetDepthFunction · 0.85

Tested by

no test coverage detected