cuticle/hi/img.c
mid 3993163d6d Start Windows compatibility
screen_capture_lite turned out to be pretty broken and so I brought back
my old X11 implementation for the Window node, for Unices only.
Hopefully SCL actually works on Windows because lemme tell you, I do not
want to go knee-deep in that.

Additionally, SAIL was replaced with stb_image because I couldn't get
SAIL to build under MinGW.
2025-10-12 11:23:49 +03:00

43 lines
990 B
C

#include"img.h"
#include<mm_malloc.h>
#include<string.h>
#include<assert.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, 16);
img->owned = !data;
assert(stride % 16 == 0);
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);
}
}