|
|
|
|
@ -121,6 +121,39 @@ int VideoFrame::TestScreen(int w, int h) {
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
int VideoFrame::CopyTo(VideoFrame *dest, int destw, int desth) {
|
|
|
|
|
unsigned char *destptr;
|
|
|
|
|
if (dest == NULL) return 0;
|
|
|
|
|
|
|
|
|
|
dest->SetSize(destw, desth);
|
|
|
|
|
destptr = dest->GetPixBuf();
|
|
|
|
|
if (destptr == NULL) return 0;
|
|
|
|
|
|
|
|
|
|
float scale_x = (float)width / destw;
|
|
|
|
|
float scale_y = (float)height / desth;
|
|
|
|
|
|
|
|
|
|
for (int dy = 0; dy < dest->height; ++dy) {
|
|
|
|
|
for (int dx = 0; dx < dest->width; ++dx) {
|
|
|
|
|
// Map destination coordinates back to source coordinates
|
|
|
|
|
int sx = (int)(dx * scale_x);
|
|
|
|
|
int sy = (int)(dy * scale_y);
|
|
|
|
|
|
|
|
|
|
// Bounds checking (should be unnecessary with correct scale calculation)
|
|
|
|
|
if (sx >= width) sx = width - 1;
|
|
|
|
|
if (sy >= height) sy = height - 1;
|
|
|
|
|
|
|
|
|
|
// Calculate byte index in the source and destination buffers
|
|
|
|
|
int src_idx = 3*((sy * width) + sx);
|
|
|
|
|
int dest_idx = 3*((dy * destw) + dx);
|
|
|
|
|
|
|
|
|
|
// Copy the pixel data (e.g., all 3 RGB bytes)
|
|
|
|
|
memcpy(&destptr[dest_idx], &mem[src_idx], 3);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return 1;
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
/*********************************************************************/
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|