Example #1
0
bool Image::writePNG(const char *path) {
    const char *cpath = platformCStringPath(path);
    
    assertmsg( buffer!=0 , "image not initialized?" );
    assertmsg( width <= 2048 && height <= 2048, "image too big" );
    

    /*Same as lodepng_encode_file, but always encodes from 32-bit RGBA raw image.*/
    unsigned error;
    error = lodepng_encode32_file( cpath, buffer, width, height );
    if(error) {
        fprintf(stderr, "lodepng_encode32_file failed%d", error );
        return false;
    }
    return true;
}
Example #2
0
bool Image::loadPNG( const char *path, bool multiply_color_by_alpha ) {
    const char *cpath = platformCStringPath(path);
    FILE *fp = fopen(cpath,"rb");
    if(!fp) {
        print( "Image::loadPNG: can't open file:%s", cpath );
        return false;
    }

    unsigned error;
    unsigned char* image_data;
    unsigned w, h;

    error = lodepng_decode32_file(&image_data, &w, &h, cpath );

    if(error) {
        fprintf(stderr, "decoder error %u: %s\n", error, lodepng_error_text(error) );
        FREE(image_data);
        fclose(fp);
        return false;
    }

    width = w;
    height = h;

    if( multiply_color_by_alpha ) multiplyAlphaRGBA(image_data,width,height);

    ensureBuffer();
#define IMAGE_BUFFER_COPY \
    for(int i=0;i<width*height;i++){ \
        int x = i % width; \
        int y = (i / width); \
        int ii = y * width + x; \
        buffer[ii*4+0] = image_data[i*4+0]; /*r*/   \
        buffer[ii*4+1] = image_data[i*4+1]; /*g*/   \
        buffer[ii*4+2] = image_data[i*4+2]; /*b*/   \
        buffer[ii*4+3] = image_data[i*4+3]; /*a*/   \
    }

    IMAGE_BUFFER_COPY;
    
    // clean up
    FREE(image_data);
    fclose(fp);
    strncpy( last_load_file_path, path, sizeof(last_load_file_path) );
    return true;
}
Example #3
0
Sound *SoundSystem::newSound( const char *path, float vol, bool use_stream_currently_ignored ) {
#if !defined(__linux__)    
    const char *cpath = platformCStringPath(path);
#endif
    
#ifdef USE_FMOD    
    FMOD_RESULT r;    
	FMOD_SOUND *s;
	r = FMOD_System_CreateSound(sys, cpath, FMOD_SOFTWARE, 0, &s );
    if( r != FMOD_OK ) {
        print("newSound: can't create sound:'%s'", cpath );
    }
	FMOD_ERRCHECK(r);
	FMOD_Sound_SetMode( s, FMOD_LOOP_OFF );
#endif
#ifdef USE_UNTZ
    UNTZ::Sound *s = UNTZ::Sound::create( cpath, true );
#endif
#ifdef USE_OPENAL
    ALSound *s = ALSound::create( cpath );
#endif
#ifdef __linux__
    void *s = this; // TODO: implement virtual sound
#endif    
    if(!s) {
        print("newSound failed for '%s'", path );
        return 0;
    }
    Sound *out = new Sound(this);
	out->sound = s;    
	out->default_volume = vol;
    out->id = id_gen;
    strncpy( out->last_load_file_path, path, sizeof(out->last_load_file_path) );
    id_gen++;
    append(out);
	return out;
}