浏览代码

REDESIGNED: ImageFromImage(), optimized #1218

pull/1280/head
raysan5 5 年前
父节点
当前提交
691c1f9391
共有 1 个文件被更改,包括 15 次插入2 次删除
  1. +15
    -2
      src/textures.c

+ 15
- 2
src/textures.c 查看文件

@ -776,9 +776,22 @@ Image ImageCopy(Image image)
// Create an image from another image piece
Image ImageFromImage(Image image, Rectangle rec)
{
Image result = ImageCopy(image);
Image result = { 0 };
int bytesPerPixel = GetPixelDataSize(1, 1, image.format);
// TODO: Check rec is valid?
ImageCrop(&result, rec);
result.width = rec.width;
result.height = rec.height;
result.data = RL_CALLOC(rec.width*rec.height*bytesPerPixel, 1);
result.format = image.format;
result.mipmaps = 1;
for (int y = 0; y < rec.height; y++)
{
memcpy(((unsigned char *)result.data) + y*(int)rec.width*bytesPerPixel, ((unsigned char *)image.data) + ((y + (int)rec.y)*image.width + (int)rec.x)*bytesPerPixel, (int)rec.width*bytesPerPixel);
}
return result;
}

正在加载...
取消
保存