예제 #1
0
파일: misc.c 프로젝트: csiga/Eternal-Lands
int IMG_SavePNG (SDL_Surface *surface, const char *file)
{
	SDL_RWops *out = SDL_RWFromFile (file, "wb");
	int ret;
	if (out == NULL)
		return -1;
	ret = IMG_SavePNG_RW (surface, out);
	SDL_RWclose (out);
	return ret;
}
예제 #2
0
파일: IMG_savepng.c 프로젝트: Neurone/renpy
int IMG_SavePNG(const char *file, SDL_Surface *surf,int compression){
	SDL_RWops *fp;
	int ret;

	fp=SDL_RWFromFile(file,"wb");

	if( fp == NULL ) {
		return (-1);
	}

	ret=IMG_SavePNG_RW(fp,surf,compression);
	SDL_RWclose(fp);
	return ret;
}
예제 #3
0
int IMG_SavePNG(const char *file, SDL_Surface *surf,int compression){
#ifdef IMPLEMENT_SAVE_PNG
	SDL_RWops *fp;
	int ret;
	
	fp=SDL_RWFromFile(file,"wb");

	if( fp == NULL ) {
		return (-1);
	}

	ret=IMG_SavePNG_RW(fp,surf,compression);
	SDL_RWclose(fp);
	return ret;
#else
	return -1;
#endif
}
예제 #4
0
/** Write the specified surface to a file at the requested compression.
 *
 *  \param filename    The name of the file to save to.
 *  \param surf        The surface to write as a png.
 *  \param compression The compression level to write the png at. Set to -1 to use
 *                     zlib's default compression, othewise this should be in the
 *                     range 0 (no compression) to Z_BEST_COMPRESSION (usually 9).
 *  \return -1 on error, 0 if the png was saved successfully.
 */
int IMG_SavePNG(const char *filename, SDL_Surface *surf, int compression)
{
    int result;
    SDL_RWops *rout;
    
    // Open a RWops so we can write to a file using IMG_SavePNG_RW
    if(!(rout = SDL_RWFromFile(filename, "wb"))) 
    {
        return (-1);
    }

    // Write the png out...
    result = IMG_SavePNG_RW(rout, surf, compression);

    // and we're done
    SDL_RWclose(rout);
    return result;
}
예제 #5
0
int savePNG(const std::string &filename,
			const unsigned char * data,int w,int h,_XColorMode color,
			int compression)
{
	if(data == NULL) return XFalse;
	SDL_RWops *fp;
	int ret;

	if((fp = SDL_RWFromFile(filename.c_str(),"wb")) == NULL) return -1;
	SDL_Surface * picArm = NULL;
	switch(color)
	{
	case COLOR_RGB:
	case COLOR_BGR:
#if SDL_BYTEORDER == SDL_BIG_ENDIAN
		picArm = SDL_CreateRGBSurface(SDL_SWSURFACE,w,h,24,0xff000000, 0x00ff0000, 0x0000ff00, 0x00000000);
#else
		picArm = SDL_CreateRGBSurface(SDL_SWSURFACE,w,h,24,0x000000ff, 0x0000ff00, 0x00ff0000, 0x00000000);
#endif
		break;
	case COLOR_RGBA:
	case COLOR_BGRA:
#if SDL_BYTEORDER == SDL_BIG_ENDIAN
		picArm = SDL_CreateRGBSurface(SDL_SWSURFACE,w,h,32,0xff000000, 0x00ff0000, 0x0000ff00, 0x00000000);
#else
		picArm = SDL_CreateRGBSurface(SDL_SWSURFACE,w,h,32,0x000000ff, 0x0000ff00, 0x00ff0000, 0x00000000);
#endif
		break;
	default:	//其他格式不支持
		return -1;
		break;
	}
	//这里可以考虑保存成24位色提升效率
	memcpy(picArm->pixels,data,w * h * picArm->format->BytesPerPixel);

	ret = IMG_SavePNG_RW(fp,picArm,compression);
	SDL_FreeSurface(picArm);
	picArm = NULL;
	SDL_RWclose(fp);
	return ret;
}
예제 #6
0
static bool build_map_preview(std::ostringstream& ostream)
{
    SDL_Rect r = {0, 0, RENDER_WIDTH, RENDER_HEIGHT};
    SDL_Surface *surface = SDL_CreateRGBSurface(SDL_SWSURFACE, r.w, r.h, 32, 0xff0000, 0x00ff00, 0x0000ff, 0);
    if (!surface)
        return false;
	
    SDL_FillRect(surface, &r, SDL_MapRGB(surface->format, 0, 0, 0));
	
    struct overhead_map_data overhead_data;
    overhead_data.half_width = r.w >> 1;
    overhead_data.half_height = r.h >> 1;
    overhead_data.width = r.w;
    overhead_data.height = r.h;
    overhead_data.top = overhead_data.left = 0;
    overhead_data.scale = RENDER_SCALE;
    overhead_data.mode = _rendering_saved_game_preview;
    overhead_data.origin.x = local_player->location.x;
    overhead_data.origin.y = local_player->location.y;
	
    bool old_OGL_MapActive = OGL_MapActive;
    _set_port_to_custom(surface);
    OGL_MapActive = false;
    _render_overhead_map(&overhead_data);
    OGL_MapActive = old_OGL_MapActive;
    _restore_port();
	
    SDL_RWops *rwops = SDL_RWFromOStream(ostream);
#if defined(HAVE_PNG) && defined(HAVE_SDL_IMAGE_H)
    int ret = IMG_SavePNG_RW(rwops, surface, IMG_COMPRESS_DEFAULT, NULL, 0);
#else
    int ret = SDL_SaveBMP_RW(surface, rwops, false);
#endif
    SDL_FreeSurface(surface);
    SDL_RWclose(rwops);
	
    return (ret == 0);
}