void Image_flipX(Image *self) { size_t y; size_t w = self->width; size_t h = self->height; int componentCount = self->componentCount; uint8_t *bytes = UArray_mutableBytes(self->byteArray); uint8_t buf[4]; for (y = 0; y < h; y ++) { size_t x; for (x = 0; x < w/2; x ++) { uint8_t *a = bytes + componentCount * (y * w) + x * componentCount; uint8_t *b = bytes + componentCount * (y * w) + (w - x) * componentCount; memcpy(buf, a, componentCount); memcpy(a, b, componentCount); memcpy(b, buf, componentCount); } } }
IOIMAGE_API IoObject *IoImage_filterKirsch(IoImage *self, IoObject *locals, IoMessage *m) { /*doc Image filterKirsch(a) Returns new image as a result of applying Kirsch filter. The argument denotes direction: 0, 1, 2, ... -> 0, pi / 4, pi / 2, ... */ int a = IoMessage_locals_intArgAt_(m, locals, 0); a = ((a % 8) + 8) % 8; static int mapOfPixels[8] = {0, 1, 2, 5, 8, 7, 6, 3}; static int contentsOfPixels[8] = {3, 3, 3, 3, -5, -5, -5, 3}; UArray* filter = UArray_new(); UArray_setItemType_(filter, CTYPE_int8_t); UArray_setEncoding_(filter, CENCODING_NUMBER); UArray_setSize_(filter, 9); int8_t *filterBytes = UArray_mutableBytes(filter); int i; for(i = 0; i < 8; i++) { filterBytes[(i + a) % 8] = contentsOfPixels[i]; } IoImage* toReturn = IoImage_newWithImage_(IOSTATE, Image_applyLinearFilter(DATA(self)->image, 3, 3, filter)); UArray_free(filter); return toReturn; }