src/video/SDL_RLEaccel.c
changeset 944 cdea7cbc3e23
parent 880 9ef41050100c
child 1155 91569ec25acd
equal deleted inserted replaced
943:715c32d8f26c 944:cdea7cbc3e23
  1830  * Un-RLE a surface with pixel alpha
  1830  * Un-RLE a surface with pixel alpha
  1831  * This may not give back exactly the image before RLE-encoding; all
  1831  * This may not give back exactly the image before RLE-encoding; all
  1832  * completely transparent pixels will be lost, and colour and alpha depth
  1832  * completely transparent pixels will be lost, and colour and alpha depth
  1833  * may have been reduced (when encoding for 16bpp targets).
  1833  * may have been reduced (when encoding for 16bpp targets).
  1834  */
  1834  */
  1835 static void UnRLEAlpha(SDL_Surface *surface)
  1835 static SDL_bool UnRLEAlpha(SDL_Surface *surface)
  1836 {
  1836 {
  1837     Uint8 *srcbuf;
  1837     Uint8 *srcbuf;
  1838     Uint32 *dst;
  1838     Uint32 *dst;
  1839     SDL_PixelFormat *sf = surface->format;
  1839     SDL_PixelFormat *sf = surface->format;
  1840     RLEDestFormat *df = surface->map->sw_data->aux_data;
  1840     RLEDestFormat *df = surface->map->sw_data->aux_data;
  1851     } else {
  1851     } else {
  1852 	uncopy_opaque = uncopy_transl = uncopy_32;
  1852 	uncopy_opaque = uncopy_transl = uncopy_32;
  1853     }
  1853     }
  1854 
  1854 
  1855     surface->pixels = malloc(surface->h * surface->pitch);
  1855     surface->pixels = malloc(surface->h * surface->pitch);
       
  1856     if ( !surface->pixels ) {
       
  1857         return(SDL_FALSE);
       
  1858     }
  1856     /* fill background with transparent pixels */
  1859     /* fill background with transparent pixels */
  1857     memset(surface->pixels, 0, surface->h * surface->pitch);
  1860     memset(surface->pixels, 0, surface->h * surface->pitch);
  1858 
  1861 
  1859     dst = surface->pixels;
  1862     dst = surface->pixels;
  1860     srcbuf = (Uint8 *)(df + 1);
  1863     srcbuf = (Uint8 *)(df + 1);
  1874 	    }
  1877 	    }
  1875 	    if(run) {
  1878 	    if(run) {
  1876 		srcbuf += uncopy_opaque(dst + ofs, srcbuf, run, df, sf);
  1879 		srcbuf += uncopy_opaque(dst + ofs, srcbuf, run, df, sf);
  1877 		ofs += run;
  1880 		ofs += run;
  1878 	    } else if(!ofs)
  1881 	    } else if(!ofs)
  1879 		return;
  1882 		return(SDL_TRUE);
  1880 	} while(ofs < w);
  1883 	} while(ofs < w);
  1881 
  1884 
  1882 	/* skip padding if needed */
  1885 	/* skip padding if needed */
  1883 	if(bpp == 2)
  1886 	if(bpp == 2)
  1884 	    srcbuf += (unsigned long)srcbuf & 2;
  1887 	    srcbuf += (unsigned long)srcbuf & 2;
  1895 		ofs += run;
  1898 		ofs += run;
  1896 	    }
  1899 	    }
  1897 	} while(ofs < w);
  1900 	} while(ofs < w);
  1898 	dst += surface->pitch >> 2;
  1901 	dst += surface->pitch >> 2;
  1899     }
  1902     }
       
  1903     /* Make the compiler happy */
       
  1904     return(SDL_TRUE);
  1900 }
  1905 }
  1901 
  1906 
  1902 void SDL_UnRLESurface(SDL_Surface *surface, int recode)
  1907 void SDL_UnRLESurface(SDL_Surface *surface, int recode)
  1903 {
  1908 {
  1904     if ( (surface->flags & SDL_RLEACCEL) == SDL_RLEACCEL ) {
  1909     if ( (surface->flags & SDL_RLEACCEL) == SDL_RLEACCEL ) {
  1910 		SDL_Rect full;
  1915 		SDL_Rect full;
  1911 		unsigned alpha_flag;
  1916 		unsigned alpha_flag;
  1912 
  1917 
  1913 		/* re-create the original surface */
  1918 		/* re-create the original surface */
  1914 		surface->pixels = malloc(surface->h * surface->pitch);
  1919 		surface->pixels = malloc(surface->h * surface->pitch);
       
  1920 		if ( !surface->pixels ) {
       
  1921 			/* Oh crap... */
       
  1922 			surface->flags |= SDL_RLEACCEL;
       
  1923 			return;
       
  1924 		}
  1915 
  1925 
  1916 		/* fill it with the background colour */
  1926 		/* fill it with the background colour */
  1917 		SDL_FillRect(surface, NULL, surface->format->colorkey);
  1927 		SDL_FillRect(surface, NULL, surface->format->colorkey);
  1918 
  1928 
  1919 		/* now render the encoded surface */
  1929 		/* now render the encoded surface */
  1922 		full.h = surface->h;
  1932 		full.h = surface->h;
  1923 		alpha_flag = surface->flags & SDL_SRCALPHA;
  1933 		alpha_flag = surface->flags & SDL_SRCALPHA;
  1924 		surface->flags &= ~SDL_SRCALPHA; /* opaque blit */
  1934 		surface->flags &= ~SDL_SRCALPHA; /* opaque blit */
  1925 		SDL_RLEBlit(surface, &full, surface, &full);
  1935 		SDL_RLEBlit(surface, &full, surface, &full);
  1926 		surface->flags |= alpha_flag;
  1936 		surface->flags |= alpha_flag;
  1927 	    } else
  1937 	    } else {
  1928 		UnRLEAlpha(surface);
  1938 		if ( !UnRLEAlpha(surface) ) {
       
  1939 		    /* Oh crap... */
       
  1940 		    surface->flags |= SDL_RLEACCEL;
       
  1941 		    return;
       
  1942 		}
       
  1943 	    }
  1929 	}
  1944 	}
  1930 
  1945 
  1931 	if ( surface->map && surface->map->sw_data->aux_data ) {
  1946 	if ( surface->map && surface->map->sw_data->aux_data ) {
  1932 	    free(surface->map->sw_data->aux_data);
  1947 	    free(surface->map->sw_data->aux_data);
  1933 	    surface->map->sw_data->aux_data = NULL;
  1948 	    surface->map->sw_data->aux_data = NULL;