/*! * pixReadStreamWebP() * * Input: stream corresponding to WebP image * Return: pix (32 bpp), or null on error */ PIX * pixReadStreamWebP(FILE *fp) { l_uint8 *filedata; size_t filesize; PIX *pix; PROCNAME("pixReadStreamWebP"); if (!fp) return (PIX *)ERROR_PTR("fp not defined", procName, NULL); /* Read data from file and decode into Y,U,V arrays */ rewind(fp); if ((filedata = l_binaryReadStream(fp, &filesize)) == NULL) return (PIX *)ERROR_PTR("filedata not read", procName, NULL); pix = pixReadMemWebP(filedata, filesize); FREE(filedata); return pix; }
/*! * pixReadMem() * * Input: data (const; encoded) * datasize (size of data) * Return: pix, or null on error * * Notes: * (1) This is a variation of pixReadStream(), where the data is read * from a memory buffer rather than a file. * (2) On windows, this only reads tiff formatted files directly from * memory. For other formats, it write to a temp file and * decompress from file. * (3) findFileFormatBuffer() requires up to 8 bytes to decide on * the format. That determines the constraint here. But in * fact the data must contain the entire compressed string for * the image. */ PIX * pixReadMem(const l_uint8 *data, size_t size) { l_int32 format; PIX *pix; PROCNAME("pixReadMem"); if (!data) return (PIX *)ERROR_PTR("data not defined", procName, NULL); if (size < 8) return (PIX *)ERROR_PTR("size < 8", procName, NULL); pix = NULL; findFileFormatBuffer(data, &format); switch (format) { case IFF_BMP: if ((pix = pixReadMemBmp(data, size)) == NULL ) return (PIX *)ERROR_PTR( "bmp: no pix returned", procName, NULL); break; case IFF_JFIF_JPEG: if ((pix = pixReadMemJpeg(data, size, READ_24_BIT_COLOR, 1, NULL, 0)) == NULL) return (PIX *)ERROR_PTR( "jpeg: no pix returned", procName, NULL); break; case IFF_PNG: if ((pix = pixReadMemPng(data, size)) == 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: /* Reading page 0 by default */ if ((pix = pixReadMemTiff(data, size, 0)) == NULL) return (PIX *)ERROR_PTR("tiff: no pix returned", procName, NULL); break; case IFF_PNM: if ((pix = pixReadMemPnm(data, size)) == NULL) return (PIX *)ERROR_PTR("pnm: no pix returned", procName, NULL); break; case IFF_GIF: if ((pix = pixReadMemGif(data, size)) == NULL) return (PIX *)ERROR_PTR("gif: no pix returned", procName, NULL); break; case IFF_JP2: if ((pix = pixReadMemJp2k(data, size, 1, NULL, 0)) == NULL) return (PIX *)ERROR_PTR("jp2k: no pix returned", procName, NULL); break; case IFF_WEBP: if ((pix = pixReadMemWebP(data, size)) == NULL) return (PIX *)ERROR_PTR("webp: no pix returned", procName, NULL); break; case IFF_SPIX: if ((pix = pixReadMemSpix(data, size)) == 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; } /* Set the input format. For tiff reading from memory we lose * the actual input format; for 1 bpp, default to G4. */ if (pix) { if (format == IFF_TIFF && pixGetDepth(pix) == 1) format = IFF_TIFF_G4; pixSetInputFormat(pix, format); } return pix; }