cuticle/hi/img.c

40 lines
937 B
C
Raw Normal View History

2024-06-26 20:47:26 +03:00
#include"img.h"
#include<mm_malloc.h>
#include<string.h>
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);
}
}