| 214 | } |
| 215 | |
| 216 | void surfacecpy(surface_t* dest, surface_t* src, vector2i_t offset){ |
| 217 | if(dest->height == src->height && dest->width == src->width && offset.x == 0 && offset.y == 0) { |
| 218 | memcpy_optimized(dest->buffer, src->buffer, dest->width * dest->height); |
| 219 | return; |
| 220 | } |
| 221 | |
| 222 | int rowSize = ((offset.x + src->width) > dest->width) ? dest->width - offset.x : src->width; |
| 223 | int rowOffset = 0; |
| 224 | |
| 225 | if(offset.x < 0){ |
| 226 | rowOffset = -offset.x * 4; |
| 227 | rowSize += offset.x; |
| 228 | offset.x = 0; |
| 229 | } |
| 230 | |
| 231 | int i = 0; |
| 232 | |
| 233 | if(offset.y < 0){ |
| 234 | i += offset.y; |
| 235 | offset.y = 0; |
| 236 | } |
| 237 | |
| 238 | for(; i < src->height && i < dest->height - offset.y; i++){ |
| 239 | if(rowSize <= 0) return; |
| 240 | |
| 241 | memcpy_optimized(dest->buffer + ((i+offset.y)*(dest->width*4) + offset.x*4), src->buffer + i*src->width*4 + rowOffset, rowSize); |
| 242 | } |
| 243 | } |
| 244 | |
| 245 | void surfacecpy(surface_t* dest, surface_t* src, vector2i_t offset, rect_t srcRegion){ |
| 246 | if(offset.x >= dest->width || offset.y >= dest->height || srcRegion.pos.x >= src->width || srcRegion.pos.y >= src->height) return; |