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

Function pixcompCreateFromFile

deps/leptonica/src/pixcomp.c:290–339  ·  view source on GitHub ↗

! * \brief pixcompCreateFromFile() * * \param[in] filename * \param[in] comptype IFF_DEFAULT, IFF_TIFF_G4, IFF_PNG, IFF_JFIF_JPEG * \return pixc, or NULL on error * * * Notes: * (1) Use %comptype == IFF_DEFAULT to have the compression * type automatically determined. * (2) If the comptype is invalid for this file, the default will * be substit

Source from the content-addressed store, hash-verified

288 * </pre>
289 */
290PIXC *
291pixcompCreateFromFile(const char *filename,
292 l_int32 comptype)
293{
294l_int32 format;
295size_t nbytes;
296l_uint8 *data;
297PIX *pix;
298PIXC *pixc;
299
300 PROCNAME("pixcompCreateFromFile");
301
302 if (!filename)
303 return (PIXC *)ERROR_PTR("filename not defined", procName, NULL);
304 if (comptype != IFF_DEFAULT && comptype != IFF_TIFF_G4 &&
305 comptype != IFF_PNG && comptype != IFF_JFIF_JPEG)
306 return (PIXC *)ERROR_PTR("invalid comptype", procName, NULL);
307
308 findFileFormat(filename, &format);
309 if (format == IFF_UNKNOWN) {
310 L_ERROR("unreadable file: %s\n", procName, filename);
311 return NULL;
312 }
313
314 /* Can we accept the encoded file directly? Remember that
315 * png is the "universal" compression type, so if requested
316 * it takes precedence. Otherwise, if the file is already
317 * compressed in g4 or jpeg, just accept the string. */
318 if ((format == IFF_TIFF_G4 && comptype != IFF_PNG) ||
319 (format == IFF_JFIF_JPEG && comptype != IFF_PNG))
320 comptype = format;
321 if (comptype != IFF_DEFAULT && comptype == format) {
322 data = l_binaryRead(filename, &nbytes);
323 if ((pixc = pixcompCreateFromString(data, nbytes, L_INSERT)) == NULL) {
324 LEPT_FREE(data);
325 return (PIXC *)ERROR_PTR("pixc not made (string)", procName, NULL);
326 }
327 return pixc;
328 }
329
330 /* Need to recompress in the default format */
331 if ((pix = pixRead(filename)) == NULL)
332 return (PIXC *)ERROR_PTR("pix not read", procName, NULL);
333 if ((pixc = pixcompCreateFromPix(pix, comptype)) == NULL) {
334 pixDestroy(&pix);
335 return (PIXC *)ERROR_PTR("pixc not made", procName, NULL);
336 }
337 pixDestroy(&pix);
338 return pixc;
339}
340
341
342/*!

Callers 1

pixacompCreateFromSAFunction · 0.85

Calls 6

findFileFormatFunction · 0.85
l_binaryReadFunction · 0.85
pixcompCreateFromStringFunction · 0.85
pixReadFunction · 0.85
pixcompCreateFromPixFunction · 0.85
pixDestroyFunction · 0.85

Tested by

no test coverage detected