MCPcopy Create free account
hub / github.com/DentonW/DevIL / ILAPIENTRY ilSetAlpha

Function ILAPIENTRY ilSetAlpha

DevIL/src-IL/src/il_manip.cpp:962–1044  ·  view source on GitHub ↗

sets the Alpha value to a specific value for each pixel in the image

Source from the content-addressed store, hash-verified

960
961// sets the Alpha value to a specific value for each pixel in the image
962ILboolean ILAPIENTRY ilSetAlpha(ILdouble AlphaValue)
963{
964 ILboolean ret = IL_TRUE;
965 ILuint i,Size;
966 ILimage *Image = iCurImage;
967 ILuint AlphaOff;
968
969 if (Image == NULL) {
970 ilSetError(IL_ILLEGAL_OPERATION);
971 return IL_FALSE;
972 }
973
974 AlphaValue = IL_CLAMP(AlphaValue);
975
976 switch (Image->Format)
977 {
978 case IL_RGB:
979 ret = ilConvertImage(IL_RGBA, Image->Type);
980 case IL_RGBA:
981 AlphaOff = 4;
982 break;
983 case IL_BGR:
984 ret = ilConvertImage(IL_BGRA, Image->Type);
985 case IL_BGRA:
986 AlphaOff = 4;
987 break;
988 case IL_LUMINANCE:
989 ret = ilConvertImage(IL_LUMINANCE_ALPHA, Image->Type);
990 case IL_LUMINANCE_ALPHA:
991 AlphaOff = 2;
992 break;
993 case IL_ALPHA:
994 AlphaOff = 1;
995 case IL_COLOUR_INDEX: //@TODO use palette with alpha
996 ret = ilConvertImage(IL_RGBA, Image->Type);
997 AlphaOff = 4;
998 break;
999 }
1000 if (ret == IL_FALSE) {
1001 // Error has been set by ilConvertImage.
1002 return IL_FALSE;
1003 }
1004 Size = Image->Width * Image->Height * Image->Depth * Image->Bpp;
1005
1006 switch (iCurImage->Type)
1007 {
1008 case IL_BYTE:
1009 case IL_UNSIGNED_BYTE: {
1010 const ILbyte alpha = (ILubyte)(AlphaValue * IL_MAX_UNSIGNED_BYTE + .5);
1011 for (i = AlphaOff-1; i < Size; i += AlphaOff)
1012 Image->Data[i] = alpha;
1013 break;
1014 }
1015 case IL_SHORT:
1016 case IL_UNSIGNED_SHORT: {
1017 const ILushort alpha = (ILushort)(AlphaValue * IL_MAX_UNSIGNED_SHORT + .5);
1018 for (i = AlphaOff-1; i < Size; i += AlphaOff)
1019 ((ILushort*)Image->Data)[i] = alpha;

Callers

nothing calls this directly

Calls 1

ilSetErrorFunction · 0.85

Tested by

no test coverage detected