ppm功能优化

This commit is contained in:
luoliangyi 2022-10-28 12:22:17 +08:00
parent cafac32f86
commit 023005b727
1 changed files with 1 additions and 6 deletions

View File

@ -132,19 +132,14 @@ static HGResult BnmLoadP6Image(FILE* file, HGPnmLoadInfo* info, HGUInt imgType,
HGImageInfo imgInfo; HGImageInfo imgInfo;
HGBase_GetImageInfo(image2, &imgInfo); HGBase_GetImageInfo(image2, &imgInfo);
HGByte* buf = new HGByte[width * 3];
for (HGUInt i = 0; i < height; ++i) for (HGUInt i = 0; i < height; ++i)
{ {
if (width * 3 != fread(buf, 1, width * 3, file)) if (width * 3 != fread(data + i * imgInfo.widthStep, 1, width * 3, file))
{ {
delete[] buf;
HGBase_DestroyImage(image2); HGBase_DestroyImage(image2);
return HGBASE_ERR_INVALIDDATA; return HGBASE_ERR_INVALIDDATA;
} }
memcpy(data + i * imgInfo.widthStep, buf, width * 3);
} }
delete[] buf;
ret = HGBase_CloneImage(image2, imgType, imgOrigin, image); ret = HGBase_CloneImage(image2, imgType, imgOrigin, image);
HGBase_DestroyImage(image2); HGBase_DestroyImage(image2);