void stretch_image_plane(const uint8_t * src, uint8_t *dst, int src_w, int src_h, int dst_w, int dst_h) { int dw = dst_w; int dh = dst_h; uint8_t *dst_end = dst + dst_w*dst_h; int src_w2 = src_w*2; int dst_w2 = dst_w*2; int src_h2 = src_h*2; int dst_h2 = dst_h*2; int qw = src_w2 / dst_w2; int rw = src_w2 - qw*dst_w2; int qh = src_h2 / dst_h2; int rh = src_h2 - qh*dst_h2; for (;;) { const uint8_t *s = src; uint8_t *dst_line_end = dst + dst_w; for (;;) { *dst++ = *s; if (dst >= dst_line_end) { dw = dst_w; break; } s += qw; dw += rw; if (dw >= dst_w2) { dw -= dst_w2; s++; } } if (dst >= dst_end) break; src += qh*src_w; dh += rh; if (dh >= dst_h2) { dh -= dst_h2; src += src_w; } } }