comparison src/video/SDL_RLEaccel.c @ 2266:e61ad15a205f

More work in progress integrating SDL_Surface and the new SDL_Texture API
author Sam Lantinga <slouken@libsdl.org>
date Sat, 18 Aug 2007 01:44:21 +0000
parents bee005ace1bf
children c785543d1843
comparison
equal deleted inserted replaced
2265:265bb136af92 2266:e61ad15a205f
903 #undef RLESKIP 903 #undef RLESKIP
904 904
905 } 905 }
906 } 906 }
907 907
908 alpha = (src->flags & SDL_SRCALPHA) == SDL_SRCALPHA 908 alpha = src->map->info.a;
909 ? src->map->info.a : 255;
910 /* if left or right edge clipping needed, call clip blit */ 909 /* if left or right edge clipping needed, call clip blit */
911 if (srcrect->x || srcrect->w != src->w) { 910 if (srcrect->x || srcrect->w != src->w) {
912 RLEClipBlit(w, srcbuf, dst, dstbuf, srcrect, alpha); 911 RLEClipBlit(w, srcbuf, dst, dstbuf, srcrect, alpha);
913 } else { 912 } else {
914 SDL_PixelFormat *fmt = src->format; 913 SDL_PixelFormat *fmt = src->format;
1801 } 1800 }
1802 1801
1803 int 1802 int
1804 SDL_RLESurface(SDL_Surface * surface) 1803 SDL_RLESurface(SDL_Surface * surface)
1805 { 1804 {
1806 int retcode; 1805 int flags;
1807 1806
1808 /* Clear any previous RLE conversion */ 1807 /* Clear any previous RLE conversion */
1809 if ((surface->flags & SDL_RLEACCEL) == SDL_RLEACCEL) { 1808 if ((surface->flags & SDL_RLEACCEL) == SDL_RLEACCEL) {
1810 SDL_UnRLESurface(surface, 1); 1809 SDL_UnRLESurface(surface, 1);
1811 } 1810 }
1812 1811
1813 /* We don't support RLE encoding of bitmaps */ 1812 /* We don't support RLE encoding of bitmaps */
1814 if (surface->format->BitsPerPixel < 8) { 1813 if (surface->format->BitsPerPixel < 8) {
1815 return (-1); 1814 return -1;
1816 } 1815 }
1817 1816
1818 /* Lock the surface if it's in hardware */ 1817 /* Make sure the pixels are available */
1819 if (SDL_MUSTLOCK(surface)) { 1818 if (!surface->pixels) {
1820 if (SDL_LockSurface(surface) < 0) { 1819 return -1;
1821 return (-1); 1820 }
1821
1822 /* If we don't have colorkey or blending, nothing to do... */
1823 flags = surface->map->info.flags;
1824 if(!(flags & (SDL_COPY_COLORKEY|SDL_COPY_BLEND))) {
1825 return -1;
1826 }
1827
1828 /* Pass on combinations not supported */
1829 if ((flags & SDL_COPY_MODULATE_COLOR) ||
1830 (flags & (SDL_COPY_ADD|SDL_COPY_MOD)) ||
1831 (flags & SDL_COPY_NEAREST)) {
1832 return -1;
1833 }
1834
1835 /* Encode and set up the blit */
1836 if (!surface->format->Amask || !(flags & SDL_COPY_BLEND)) {
1837 if (!surface->map->identity) {
1838 return -1;
1822 } 1839 }
1823 } 1840 if (RLEColorkeySurface(surface) < 0) {
1824 1841 return -1;
1825 /* Encode */ 1842 }
1826 if ((surface->flags & SDL_SRCCOLORKEY) == SDL_SRCCOLORKEY) { 1843 surface->map->blit = SDL_RLEBlit;
1827 retcode = RLEColorkeySurface(surface); 1844 surface->map->info.flags |= SDL_COPY_RLE_COLORKEY;
1828 } else { 1845 } else {
1829 if ((surface->flags & SDL_SRCALPHA) == SDL_SRCALPHA 1846 if (RLEAlphaSurface(surface) < 0) {
1830 && surface->format->Amask != 0) 1847 return -1;
1831 retcode = RLEAlphaSurface(surface); 1848 }
1832 else 1849 surface->map->blit = SDL_RLEAlphaBlit;
1833 retcode = -1; /* no RLE for per-surface alpha sans ckey */ 1850 surface->map->info.flags |= SDL_COPY_RLE_ALPHAKEY;
1834 } 1851 }
1835
1836 /* Unlock the surface if it's in hardware */
1837 if (SDL_MUSTLOCK(surface)) {
1838 SDL_UnlockSurface(surface);
1839 }
1840
1841 if (retcode < 0)
1842 return -1;
1843 1852
1844 /* The surface is now accelerated */ 1853 /* The surface is now accelerated */
1845 surface->flags |= SDL_RLEACCEL; 1854 surface->flags |= SDL_RLEACCEL;
1846 1855
1847 return (0); 1856 return (0);
1929 } 1938 }
1930 1939
1931 void 1940 void
1932 SDL_UnRLESurface(SDL_Surface * surface, int recode) 1941 SDL_UnRLESurface(SDL_Surface * surface, int recode)
1933 { 1942 {
1934 if ((surface->flags & SDL_RLEACCEL) == SDL_RLEACCEL) { 1943 if (surface->flags & SDL_RLEACCEL) {
1935 surface->flags &= ~SDL_RLEACCEL; 1944 surface->flags &= ~SDL_RLEACCEL;
1936 1945
1937 if (recode && !(surface->flags & SDL_PREALLOC)) { 1946 if (recode && !(surface->flags & SDL_PREALLOC)) {
1938 if ((surface->flags & SDL_SRCCOLORKEY) == SDL_SRCCOLORKEY) { 1947 if (surface->map->info.flags & SDL_COPY_RLE_COLORKEY) {
1939 SDL_Rect full; 1948 SDL_Rect full;
1940 unsigned alpha_flag;
1941 1949
1942 /* re-create the original surface */ 1950 /* re-create the original surface */
1943 surface->pixels = SDL_malloc(surface->h * surface->pitch); 1951 surface->pixels = SDL_malloc(surface->h * surface->pitch);
1944 if (!surface->pixels) { 1952 if (!surface->pixels) {
1945 /* Oh crap... */ 1953 /* Oh crap... */
1952 1960
1953 /* now render the encoded surface */ 1961 /* now render the encoded surface */
1954 full.x = full.y = 0; 1962 full.x = full.y = 0;
1955 full.w = surface->w; 1963 full.w = surface->w;
1956 full.h = surface->h; 1964 full.h = surface->h;
1957 alpha_flag = surface->flags & SDL_SRCALPHA;
1958 surface->flags &= ~SDL_SRCALPHA; /* opaque blit */
1959 SDL_RLEBlit(surface, &full, surface, &full); 1965 SDL_RLEBlit(surface, &full, surface, &full);
1960 surface->flags |= alpha_flag;
1961 } else { 1966 } else {
1962 if (!UnRLEAlpha(surface)) { 1967 if (!UnRLEAlpha(surface)) {
1963 /* Oh crap... */ 1968 /* Oh crap... */
1964 surface->flags |= SDL_RLEACCEL; 1969 surface->flags |= SDL_RLEACCEL;
1965 return; 1970 return;
1966 } 1971 }
1967 } 1972 }
1968 } 1973 }
1969 1974 surface->map->info.flags &= (SDL_COPY_RLE_COLORKEY|SDL_COPY_RLE_ALPHAKEY);
1970 if (surface->map && surface->map->data) { 1975
1976 if (surface->map->data) {
1971 SDL_free(surface->map->data); 1977 SDL_free(surface->map->data);
1972 surface->map->data = NULL; 1978 surface->map->data = NULL;
1973 } 1979 }
1974 } 1980 }
1975 } 1981 }