#include"img.h" #include #include CUTIVIS CHiImage* CHi_Image_New(uint8_t bpc, uint8_t channels, uint16_t stride, uint16_t width, uint16_t height, void *data) { CHiImage *img = malloc(sizeof(*img)); img->bpc = bpc; img->channels = channels; img->stride = stride; img->width = width; img->height = height; if(data) img->data16 = data; else img->data16 = _mm_malloc(bpc * stride * height, 16); img->owned = !data; return img; } CUTIVIS void CHi_Image_Free(CHiImage *img) { if(img->owned) { _mm_free(img->data16); } free(img); } CUTIVIS void CHi_Restride(const void *oldbuf_, void *newbuf_, uint16_t oldStride, uint16_t newStride, uint16_t rows) { const uint8_t *oldbuf = oldbuf_; uint8_t *newbuf = newbuf_; if(oldStride == newStride && oldbuf == newbuf) { return; } while(rows) { uint16_t row = --rows; memmove(&newbuf[newStride * row], &oldbuf[oldStride * row], oldStride); } }