Exemplo n.º 1
0
/*!
 * \brief   pixReadMemJpeg()
 *
 * \param[in]    data const; jpeg-encoded
 * \param[in]    size of data
 * \param[in]    cmflag colormap flag 0 means return RGB image if color;
 *                      1 means create a colormap and return
 *                      an 8 bpp colormapped image if color
 * \param[in]    reduction scaling factor: 1, 2, 4 or 8
 * \param[out]   pnwarn [optional] number of warnings
 * \param[in]    hint a bitwise OR of L_JPEG_* values; 0 for default
 * \return  pix, or NULL on error
 *
 * <pre>
 * Notes:
 *      (1) The %size byte of %data must be a null character.
 *      (2) The only hint flag so far is L_JPEG_READ_LUMINANCE,
 *          given in the enum in imageio.h.
 *      (3) See pixReadJpeg() for usage.
 * </pre>
 */
PIX *
pixReadMemJpeg(const l_uint8  *data,
               size_t          size,
               l_int32         cmflag,
               l_int32         reduction,
               l_int32        *pnwarn,
               l_int32         hint)
{
l_int32   ret;
l_uint8  *comment;
FILE     *fp;
PIX      *pix;

    PROCNAME("pixReadMemJpeg");

    if (pnwarn) *pnwarn = 0;
    if (!data)
        return (PIX *)ERROR_PTR("data not defined", procName, NULL);

    if ((fp = fopenReadFromMemory(data, size)) == NULL)
        return (PIX *)ERROR_PTR("stream not opened", procName, NULL);
    pix = pixReadStreamJpeg(fp, cmflag, reduction, pnwarn, hint);
    if (pix) {
        ret = fgetJpegComment(fp, &comment);
        if (!ret && comment) {
            pixSetText(pix, (char *)comment);
            LEPT_FREE(comment);
        }
    }
    fclose(fp);
    if (!pix) L_ERROR("pix not read\n", procName);
    return pix;
}
Exemplo n.º 2
0
/*!
 * \brief   readHeaderMemJpeg()
 *
 * \param[in]    data const; jpeg-encoded
 * \param[in]    size of data
 * \param[out]   pw [optional]
 *           [out]   ph ([optional]
 *           [out]   pspp ([optional]  samples/pixel
 * \param[out]   pycck [optional]  1 if ycck color space; 0 otherwise
 * \param[out]   pcmyk [optional]  1 if cmyk color space; 0 otherwise
 * \return  0 if OK, 1 on error
 */
l_int32
readHeaderMemJpeg(const l_uint8  *data,
                  size_t          size,
                  l_int32        *pw,
                  l_int32        *ph,
                  l_int32        *pspp,
                  l_int32        *pycck,
                  l_int32        *pcmyk)
{
l_int32  ret;
FILE    *fp;

    PROCNAME("readHeaderMemJpeg");

    if (pw) *pw = 0;
    if (ph) *ph = 0;
    if (pspp) *pspp = 0;
    if (pycck) *pycck = 0;
    if (pcmyk) *pcmyk = 0;
    if (!data)
        return ERROR_INT("data not defined", procName, 1);
    if (!pw && !ph && !pspp && !pycck && !pcmyk)
        return ERROR_INT("no results requested", procName, 1);

    if ((fp = fopenReadFromMemory(data, size)) == NULL)
        return ERROR_INT("stream not opened", procName, 1);
    ret = freadHeaderJpeg(fp, pw, ph, pspp, pycck, pcmyk);
    fclose(fp);
    return ret;
}
Exemplo n.º 3
0
/*!
 * \brief   readHeaderMemPnm()
 *
 * \param[in]    data const; pnm-encoded
 * \param[in]    size of data
 * \param[out]   pw [optional]
 *           [out]   ph ([optional]
 *           [out]   pd ([optional]
 *           [out]   ptype ([optional] pnm type
 * \param[out]   pbps [optional]  bits/sample
 * \param[out]   pspp [optional]  samples/pixel
 * \return  0 if OK, 1 on error
 */
l_int32
readHeaderMemPnm(const l_uint8  *data,
                 size_t          size,
                 l_int32        *pw,
                 l_int32        *ph,
                 l_int32        *pd,
                 l_int32        *ptype,
                 l_int32        *pbps,
                 l_int32        *pspp)
{
l_int32  ret;
FILE    *fp;

    PROCNAME("readHeaderMemPnm");

    if (!data)
        return ERROR_INT("data not defined", procName, 1);

    if ((fp = fopenReadFromMemory(data, size)) == NULL)
        return ERROR_INT("stream not opened", procName, 1);
    ret = freadHeaderPnm(fp, pw, ph, pd, ptype, pbps, pspp);
    fclose(fp);
    if (ret)
        return ERROR_INT("header data read failed", procName, 1);
    return 0;
}
Exemplo n.º 4
0
/*!
 * \brief   pixReadMemPnm()
 *
 * \param[in]    data const; pnm-encoded
 * \param[in]    size of data
 * \return  pix, or NULL on error
 *
 * <pre>
 * Notes:
 *      (1) The %size byte of %data must be a null character.
 * </pre>
 */
PIX *
pixReadMemPnm(const l_uint8  *data,
              size_t          size)
{
FILE  *fp;
PIX   *pix;

    PROCNAME("pixReadMemPnm");

    if (!data)
        return (PIX *)ERROR_PTR("data not defined", procName, NULL);
    if ((fp = fopenReadFromMemory(data, size)) == NULL)
        return (PIX *)ERROR_PTR("stream not opened", procName, NULL);
    pix = pixReadStreamPnm(fp);
    fclose(fp);
    if (!pix) L_ERROR("pix not read\n", procName);
    return pix;
}
Exemplo n.º 5
0
/*!
 * \brief   recogReadMem()
 *
 * \param[in]    data  serialization of recog (not ascii)
 * \param[in]    size  of data in bytes
 * \return  recog, or NULL on error
 */
L_RECOG *
recogReadMem(const l_uint8  *data,
             size_t          size)
{
FILE     *fp;
L_RECOG  *recog;

    PROCNAME("recogReadMem");

    if (!data)
        return (L_RECOG *)ERROR_PTR("data not defined", procName, NULL);
    if ((fp = fopenReadFromMemory(data, size)) == NULL)
        return (L_RECOG *)ERROR_PTR("stream not opened", procName, NULL);

    recog = recogReadStream(fp);
    fclose(fp);
    if (!recog) L_ERROR("recog not read\n", procName);
    return recog;
}
Exemplo n.º 6
0
/*!
 * \brief   numaaReadMem()
 *
 * \param[in]    data  numaa serialization; in ascii
 * \param[in]    size  of data; can use strlen to get it
 * \return  naa, or NULL on error
 */
NUMAA *
numaaReadMem(const l_uint8  *data,
             size_t          size)
{
FILE   *fp;
NUMAA  *naa;

    PROCNAME("numaaReadMem");

    if (!data)
        return (NUMAA *)ERROR_PTR("data not defined", procName, NULL);
    if ((fp = fopenReadFromMemory(data, size)) == NULL)
        return (NUMAA *)ERROR_PTR("stream not opened", procName, NULL);

    naa = numaaReadStream(fp);
    fclose(fp);
    if (!naa) L_ERROR("naa not read\n", procName);
    return naa;
}