---------------------------------------------------------------------* * 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
| 1259 | * </pre> |
| 1260 | */ |
| 1261 | l_int32 |
| 1262 | ioFormatTest(const char *filename) |
| 1263 | { |
| 1264 | l_int32 w, h, d, depth, equal, problems; |
| 1265 | l_float32 diff; |
| 1266 | BOX *box; |
| 1267 | PIX *pixs, *pixc, *pix1, *pix2; |
| 1268 | PIXCMAP *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); |
nothing calls this directly
no test coverage detected