cheungxiongwei / libImageing

libImageing 使用 sse2 指令加速图像调整大小速度

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

How to use

#include <stdio.h>
#include "libImaging/Imaging.h"

// api
extern Imaging pillow_image_create_for_data(char *data, char* mode,int w, int h, int stride, int bottom_up);
extern void pillow_image_free(Imaging im);
extern int    pillow_image_width  (Imaging im);
extern int    pillow_image_height (Imaging im);
extern char*  pillow_image_mode   (Imaging im);
extern char** pillow_image_rows   (Imaging im);
extern Imaging pillow_resample(Imaging im, int w, int h, int cx, int cy, int cw, int ch, int filter);


struct ImageRGBX {
    int width;
    int height;
    int bytesPerLine;
    uint8_t *data;
};

void create(int width,int height,struct ImageRGBX *obj){
    obj->width = width;
    obj->height = height;
    obj->bytesPerLine = width * 4/*bytes*/;
    obj->data = calloc(height, obj->bytesPerLine);
}

void destroy(struct ImageRGBX *obj){
    free(obj->data);
}

int main() {

    // intput data
    struct ImageRGBX input;
    create(1920,1080,&input);

    char mode[IMAGING_MODE_LENGTH] = "RGB";// format
    Imaging handle = pillow_image_create_for_data(input.data,mode,input.width,input.height,input.bytesPerLine,0);

    // output resize data
    struct ImageRGBX output;
    create(640,480,&output);

    // resize
    Imaging out = pillow_resample(handle,output.width/*resize_width*/,output.height/*resize_height*/,0,0,input.width,input.height,IMAGING_TRANSFORM_BILINEAR);

    // copy
    for(int y = 0;y < out->ysize;y++){
        memcpy(output.data + y * output.bytesPerLine,out->image[y],output.bytesPerLine);
    }

    pillow_image_free(handle);
    pillow_image_free(out);

    destroy(&input);
    destroy(&output);
    return 0;
}

note

Only support Windows Platform

reference

https://uploadcare.com/blog/the-fastest-image-resize/

https://github.com/uploadcare/pillow-simd

About

libImageing 使用 sse2 指令加速图像调整大小速度

License:Other


Languages

Language:C 99.6%Language:CMake 0.4%