Denis Dos Santos Silva
2023-09-18 15:49:12 UTC
hi all!
why this works? =)
/// image.c
/// ...
typedef struct {
int w;
int h;
unsigned char channels;
unsigned char *data;
int err;
} image_t;
int image_copy(const image_t* source, const image_t* target, int xoffset, int yoffset) {
register int sindex;
register int tindex = 0;
register int y1, x1;
if (!source || !target)
return -1;
for (int y=0; y<target->h; y++) {
for (int x=0; x<target->w; x++) {
#if 1
y1 = y+yoffset;
x1 = x+xoffset;
sindex = (y1 * source->w + x1) * 3;
if (sindex > (source->w * source->h * 3))
continue;
// change value of element of const struct
source->data[sindex+0] = target->data[tindex++];
source->data[sindex+1] = target->data[tindex++];
source->data[sindex+2] = target->data[tindex++];
#endif
}
}
return 0;
}
/// <eof>
why this works? =)
/// image.c
/// ...
typedef struct {
int w;
int h;
unsigned char channels;
unsigned char *data;
int err;
} image_t;
int image_copy(const image_t* source, const image_t* target, int xoffset, int yoffset) {
register int sindex;
register int tindex = 0;
register int y1, x1;
if (!source || !target)
return -1;
for (int y=0; y<target->h; y++) {
for (int x=0; x<target->w; x++) {
#if 1
y1 = y+yoffset;
x1 = x+xoffset;
sindex = (y1 * source->w + x1) * 3;
if (sindex > (source->w * source->h * 3))
continue;
// change value of element of const struct
source->data[sindex+0] = target->data[tindex++];
source->data[sindex+1] = target->data[tindex++];
source->data[sindex+2] = target->data[tindex++];
#endif
}
}
return 0;
}
/// <eof>