crop_yuv420_sp
void crop_yuv420_sp(unsigned char *srcbuf, int src_width, int src_height, unsigned char *dstbuf, int x, int y, int w, int h) { int i; int dst_y_size = w * h; int dst_uv_size = (w / 2) * (h / 2); int src_y_line_size = src_width; int src_uv_line_size = src_width; // Crop Y component for (i = 0; i < h; i++) { memcpy(dstbuf + i * w, srcbuf + (y + i) * src_y_line_size + x, w); } // Crop UV component (interleaved) for (i = 0; i < h / 2; i++) { memcpy(dstbuf + dst_y_size + i * w, srcbuf + src_y_line_size * src_height + ((y / 2) + i) * src_uv_line_size + (x / 2) * 2, w); } }