Mercurial > sdl-ios-xcode
comparison src/video/SDL_video.c @ 541:796f2fe699be
Support 1-bit alpha on surfaces passed to SDL_WM_SetIcon() (thanks Glenn!)
author | Sam Lantinga <slouken@libsdl.org> |
---|---|
date | Sun, 17 Nov 2002 17:55:45 +0000 |
parents | dad72daf44b3 |
children | 969fbd4dcd4e |
comparison
equal
deleted
inserted
replaced
540:4bcfb93e0dfe | 541:796f2fe699be |
---|---|
1638 *icon = video->wm_icon; | 1638 *icon = video->wm_icon; |
1639 } | 1639 } |
1640 } | 1640 } |
1641 } | 1641 } |
1642 | 1642 |
1643 /* Utility function used by SDL_WM_SetIcon() */ | 1643 /* Utility function used by SDL_WM_SetIcon(); |
1644 static void CreateMaskFromColorKey(SDL_Surface *icon, Uint8 *mask) | 1644 * flags & 1 for color key, flags & 2 for alpha channel. */ |
1645 static void CreateMaskFromColorKeyOrAlpha(SDL_Surface *icon, Uint8 *mask, int flags) | |
1645 { | 1646 { |
1646 int x, y; | 1647 int x, y; |
1647 Uint32 colorkey; | 1648 Uint32 colorkey; |
1648 #define SET_MASKBIT(icon, x, y, mask) \ | 1649 #define SET_MASKBIT(icon, x, y, mask) \ |
1649 mask[(y*((icon->w+7)/8))+(x/8)] &= ~(0x01<<(7-(x%8))) | 1650 mask[(y*((icon->w+7)/8))+(x/8)] &= ~(0x01<<(7-(x%8))) |
1665 case 2: { Uint16 *pixels; | 1666 case 2: { Uint16 *pixels; |
1666 for ( y=0; y<icon->h; ++y ) { | 1667 for ( y=0; y<icon->h; ++y ) { |
1667 pixels = (Uint16 *)icon->pixels + | 1668 pixels = (Uint16 *)icon->pixels + |
1668 y*icon->pitch/2; | 1669 y*icon->pitch/2; |
1669 for ( x=0; x<icon->w; ++x ) { | 1670 for ( x=0; x<icon->w; ++x ) { |
1670 if ( *pixels++ == colorkey ) { | 1671 if ( (flags & 1) && *pixels == colorkey ) { |
1672 SET_MASKBIT(icon, x, y, mask); | |
1673 } else if((flags & 2) && (*pixels & icon->format->Amask) == 0) { | |
1671 SET_MASKBIT(icon, x, y, mask); | 1674 SET_MASKBIT(icon, x, y, mask); |
1672 } | 1675 } |
1676 pixels++; | |
1673 } | 1677 } |
1674 } | 1678 } |
1675 } | 1679 } |
1676 break; | 1680 break; |
1677 | 1681 |
1678 case 4: { Uint32 *pixels; | 1682 case 4: { Uint32 *pixels; |
1679 for ( y=0; y<icon->h; ++y ) { | 1683 for ( y=0; y<icon->h; ++y ) { |
1680 pixels = (Uint32 *)icon->pixels + | 1684 pixels = (Uint32 *)icon->pixels + |
1681 y*icon->pitch/4; | 1685 y*icon->pitch/4; |
1682 for ( x=0; x<icon->w; ++x ) { | 1686 for ( x=0; x<icon->w; ++x ) { |
1683 if ( *pixels++ == colorkey ) { | 1687 if ( (flags & 1) && *pixels == colorkey ) { |
1688 SET_MASKBIT(icon, x, y, mask); | |
1689 } else if((flags & 2) && (*pixels & icon->format->Amask) == 0) { | |
1684 SET_MASKBIT(icon, x, y, mask); | 1690 SET_MASKBIT(icon, x, y, mask); |
1685 } | 1691 } |
1692 pixels++; | |
1686 } | 1693 } |
1687 } | 1694 } |
1688 } | 1695 } |
1689 break; | 1696 break; |
1690 } | 1697 } |
1700 | 1707 |
1701 if ( icon && video->SetIcon ) { | 1708 if ( icon && video->SetIcon ) { |
1702 /* Generate a mask if necessary, and create the icon! */ | 1709 /* Generate a mask if necessary, and create the icon! */ |
1703 if ( mask == NULL ) { | 1710 if ( mask == NULL ) { |
1704 int mask_len = icon->h*(icon->w+7)/8; | 1711 int mask_len = icon->h*(icon->w+7)/8; |
1712 int flags = 0; | |
1705 mask = (Uint8 *)malloc(mask_len); | 1713 mask = (Uint8 *)malloc(mask_len); |
1706 if ( mask == NULL ) { | 1714 if ( mask == NULL ) { |
1707 return; | 1715 return; |
1708 } | 1716 } |
1709 memset(mask, ~0, mask_len); | 1717 memset(mask, ~0, mask_len); |
1710 if ( icon->flags & SDL_SRCCOLORKEY ) { | 1718 if ( icon->flags & SDL_SRCCOLORKEY ) flags |= 1; |
1711 CreateMaskFromColorKey(icon, mask); | 1719 if ( icon->flags & SDL_SRCALPHA ) flags |= 2; |
1720 if( flags ) { | |
1721 CreateMaskFromColorKeyOrAlpha(icon, mask, flags); | |
1712 } | 1722 } |
1713 video->SetIcon(video, icon, mask); | 1723 video->SetIcon(video, icon, mask); |
1714 free(mask); | 1724 free(mask); |
1715 } else { | 1725 } else { |
1716 video->SetIcon(this, icon, mask); | 1726 video->SetIcon(this, icon, mask); |