Image-WebP

 view release on metacpan or  search on metacpan

WebP.xs  view on Meta::CPAN

PROTOTYPES: DISABLE

void
xs_WebPGetInfo(data_sv, data_size)
    SV* data_sv
    size_t data_size
INIT:
    STRLEN actual_size;
    const uint8_t *data;
    int width = 0, height = 0, res;
PPCODE:
    data = (const uint8_t *)SvPVbyte(data_sv, actual_size);
    if (data_size > (size_t)actual_size) {
        croak("WebP data sizee exceeds the input buffer");
    }
    res = WebPGetInfo(data, data_size, &width, &height);
    XPUSHs(sv_2mortal(newSVnv(res)));
    XPUSHs(sv_2mortal(newSVnv(width)));
    XPUSHs(sv_2mortal(newSVnv(height)));


void
xs_WebPGetFeatures(data_sv, data_size)
    SV* data_sv
    size_t data_size
INIT:
      STRLEN actual_size;
      const uint8_t *data;
      int res;
      WebPBitstreamFeatures features = { 0 };
PPCODE:
    data = (const uint8_t *)SvPVbyte(data_sv, actual_size);
    if (data_size > (size_t)actual_size) {
        croak("WebP data size exceeds the input buffer");
    }
    res = WebPGetFeatures(data, data_size, &features);
    XPUSHs(sv_2mortal(newSVnv(res)));
    XPUSHs(sv_2mortal(newSVnv(features.width)));
    XPUSHs(sv_2mortal(newSVnv(features.height)));
    XPUSHs(sv_2mortal(newSVnv(features.has_alpha)));

WebP.xs  view on Meta::CPAN

    size_t data_size
    unsigned char format
INIT:
    STRLEN actual_size;
    const uint8_t *data;
    int width = 0, height = 0;
    int channels;
    size_t output_size;
    uint8_t *rgb_data;
    SV *decoded;
PPCODE:
    data = (const uint8_t *)SvPVbyte(data_sv, actual_size);
    if (data_size > (size_t)actual_size) {
        croak("WebP data size exceeds the input buffer");
    }
    switch (format) {
    case 1: channels = 4; rgb_data = WebPDecodeRGBA(data, data_size, &width, &height); break;
    case 2: channels = 4; rgb_data = WebPDecodeARGB(data, data_size, &width, &height); break;
    case 3: channels = 4; rgb_data = WebPDecodeBGRA(data, data_size, &width, &height); break;
    case 4: channels = 3; rgb_data = WebPDecodeRGB(data, data_size, &width, &height);  break;
    case 5: channels = 3; rgb_data = WebPDecodeBGR(data, data_size, &width, &height);  break;

WebP.xs  view on Meta::CPAN

    int enc_type
    float quality
INIT:
    STRLEN rgb_length;
    const uint8_t *rgb_data;
    uint8_t *data = NULL;
    int channels;
    size_t minimum_length;
    size_t size = 0;
    SV *encoded;
PPCODE:
    rgb_data = (const uint8_t *)SvPVbyte(rgb_sv, rgb_length);

    if (width <= 0 || height <= 0) {
        croak("WebP dimensions must be positive");
    }
    if (format == 1 || format == 2) {
        channels = 3;
    }
    else if (format == 3 || format == 4) {
        channels = 4;



( run in 0.994 second using v1.01-cache-2.11-cpan-4e7a2411597 )