Skip to content
Snippets Groups Projects
utils.c 87.7 KiB
Newer Older
  • Learn to ignore specific revisions
  •             return fmt1;
        }
        return NULL;
    }
    
    /**
     * Read an image from a stream. 
     * @param gb byte stream containing the image
     * @param fmt image format, NULL if probing is required
     */
    int av_read_image(ByteIOContext *pb, const char *filename,
                      AVImageFormat *fmt,
                      int (*alloc_cb)(void *, AVImageInfo *info), void *opaque)
    {
        char buf[PROBE_BUF_SIZE];
        AVProbeData probe_data, *pd = &probe_data;
        offset_t pos;
        int ret;
    
        if (!fmt) {
    
            pd->filename = filename;
    
            pd->buf = buf;
            pos = url_ftell(pb);
            pd->buf_size = get_buffer(pb, buf, PROBE_BUF_SIZE);
            url_fseek(pb, pos, SEEK_SET);
            fmt = av_probe_image_format(pd);
        }
        if (!fmt)
            return AVERROR_NOFMT;
        ret = fmt->img_read(pb, alloc_cb, opaque);
        return ret;
    }
    
    /**
     * Write an image to a stream.
     * @param pb byte stream for the image output
     * @param fmt image format
     * @param img image data and informations
     */
    int av_write_image(ByteIOContext *pb, AVImageFormat *fmt, AVImageInfo *img)
    {
        return fmt->img_write(pb, img);
    }