浏览代码

REVIEW: ImageAlphaMask()

When adding alpha mask to GRAYSCALE image, if using ImageFormat(), it could change pixel values, now we avoid that, mask is just added as an extra channel
pull/986/head
Ray 5 年前
父节点
当前提交
12d3e21f1b
共有 1 个文件被更改,包括 8 次插入3 次删除
  1. +8
    -3
      src/textures.c

+ 8
- 3
src/textures.c 查看文件

@ -1181,13 +1181,18 @@ void ImageAlphaMask(Image *image, Image alphaMask)
// In case image is only grayscale, we just add alpha channel // In case image is only grayscale, we just add alpha channel
if (image->format == UNCOMPRESSED_GRAYSCALE) if (image->format == UNCOMPRESSED_GRAYSCALE)
{ {
n">ImageFormat(image, UNCOMPRESSED_GRAY_ALPHA);
kt">unsigned char *data = (unsigned char *)RL_MALLOC(image->width*image->height*2);
// Apply alpha mask to alpha channel // Apply alpha mask to alpha channel
for (int i = 0, k = 1; (i < mask.width*mask.height) || (i < image->width*image->height); i++, k += 2)
for (int i = 0, k = 0; (i < mask.width*mask.height) || (i < image->width*image->height); i++, k += 2)
{ {
((unsigned char *)image->data)[k] = ((unsigned char *)mask.data)[i];
data[k] = ((unsigned char *)image->data)[i];
data[k + 1] = ((unsigned char *)mask.data)[i];
} }
RL_FREE(image->data);
image->data = data;
image->format = UNCOMPRESSED_GRAY_ALPHA;
} }
else else
{ {

正在加载...
取消
保存