void ControllerMappingLoader::load(const std::string& filename) { VFS* vfs = VFS::instance(); std::unique_ptr<RawData> data(vfs->open(filename)); size_t datalen = data->getDataLength(); std::unique_ptr<uint8_t[]> darray(new uint8_t[datalen]); data->readInto(darray.get(), datalen); SDL_RWops* rwops = SDL_RWFromConstMem(darray.get(), static_cast<int>(datalen)); if (SDL_GameControllerAddMappingsFromRW(rwops, 0) == -1) { throw SDLException(std::string("Error when loading gamecontroller mappings: ") + SDL_GetError()); } SDL_FreeRW(rwops); }
JSBool webRspGetImg(JSContext *cx, uintN argc, jsval *vp) { SDL_Texture *tx = NULL; JSObject * object = NULL; jsval vl; JS_GetProperty(cx,JS_GetGlobalObject(cx),"Image",&vl); object = JS_New(cx,JSVAL_TO_OBJECT(vl),0,NULL); if(object){ JSObject *ob = NULL; ob = JSVAL_TO_OBJECT(JS_THIS(cx,vp)); if(ob){ CURLMsg *msg; msg = (CURLMsg*) JS_GetPrivate(cx,ob); if(msg){ rqPrivate *rq = NULL; curl_easy_getinfo(msg->easy_handle,CURLINFO_PRIVATE,(char**)&rq); if(rq){ SDL_RWops* rwop = NULL; rwop = SDL_RWFromConstMem(rq->data,rq->size); if(rwop){ tx = IMG_LoadTexture_RW(renderer,rwop,1); //tx = IMG_LoadTextureTyped_RW(renderer,rwop,1,"JPEG"); SDL_RenderCopy(renderer,tx,NULL,NULL); if(tx){ JS_SetPrivate(cx,object,tx); imageAddProps(cx,object); print("hi\n"); JS_SET_RVAL(cx,vp,OBJECT_TO_JSVAL(object)); } } } } } } return JS_TRUE; }
Audio::SID AudioSDLMixer::loadSample(const char *data, unsigned dsize) { EJS_CHECK(data&&(dsize>0)); Audio::SID sid=Audio::INVALID_SID; for (unsigned i=0;i<samples.size();++i) if (!samples[i]) sid=i; bool push=false; if (sid==INVALID_SID) { push=true; sid=samples.size(); if (sid==INVALID_SID) { EJS_WARN(std::string("Couldn't load sample:")+SDL_GetError()); return sid; } } SDL_RWops* rw=SDL_RWFromConstMem(data,dsize); if (!rw) { EJS_WARN(std::string("Couldn't load sample:")+SDL_GetError()); return Audio::INVALID_SID; } // TODO: is it also freed on error? Mix_Chunk *r=Mix_LoadWAV_RW(rw, 1); if (!r) { EJS_WARN(std::string("Couldn't load sample:")+SDL_GetError()); return Audio::INVALID_SID; } if (push) samples.push_back(r); else samples[sid]=r; return sid; }
SDL_Surface *WadImageCache::image_from_desc(WadImageDescriptor& desc) { SDL_Surface *surface = NULL; OpenedFile wad_file; if (open_wad_file_for_reading(desc.file, wad_file)) { struct wad_header header; if (read_wad_header(wad_file, &header)) { struct wad_data *wad; wad = read_indexed_wad_from_file(wad_file, &header, desc.index, true); if (wad) { void *data; size_t length; data = extract_type_from_wad(wad, desc.tag, &length); if (data && length) { SDL_RWops *rwops = SDL_RWFromConstMem(data, length); #ifdef HAVE_SDL_IMAGE surface = IMG_Load_RW(rwops, 1); #else surface = SDL_LoadBMP_RW(rwops, 1); #endif } free_wad(wad); } } close_wad_file(wad_file); } clear_game_error(); return surface; }
BOOL C4SoundEffect::Load(BYTE *pData, size_t iDataLen, BOOL fStatic, bool fRaw) { // Sound check if (!Config.Sound.RXSound) return FALSE; // load directly from memory #ifdef HAVE_LIBSDL_MIXER // Be paranoid about SDL_Mixer initialisation if (!Application.MusicSystem.MODInitialized) { Clear(); return FALSE; } if (!(pSample = Mix_LoadWAV_RW(SDL_RWFromConstMem(pData, iDataLen), 1))) { Clear(); return FALSE; } // FIXME: Is this actually correct? Length = 1000 * pSample->alen / (44100 * 2); SampleRate = 0; #endif *Name = '\0'; // Set usage time UsageTime = Game.Time; Static = fStatic; return TRUE; }
void process_network_physics_model( void *data) { init_physics_wad_data(); if(data) { // check for M1 physics SDL_RWops *ops = SDL_RWFromConstMem(data, 8); uint32 cookie = SDL_ReadBE32(ops); if(cookie == M1_PHYSICS_MAGIC_COOKIE) { uint32 length= SDL_ReadBE32(ops); SDL_RWclose(ops); uint8 *s= (uint8 *)data; import_m1_physics_data_from_network(&s[8], length); return; } else { SDL_RWclose(ops); } struct wad_header header; struct wad_data *wad; wad= inflate_flat_data(data, &header); if(wad) { import_physics_wad_data(wad); free_wad(wad); /* Note that the flat data points into the wad. */ } } }
/** * Load sample with given name. * @param name audio name used inside fokker.dks * @return loaded sample or NULL on error. */ sb_sample *sdl_sample_load(const char *name) { #ifdef HAVE_SDL_MIXER int len, ret; uint8_t *p; sb_sample *sample; ret = dksopen(name); if (ret != 1) { return NULL; } len = dkssize(); p = (uint8_t *) walloc(len); ret = dksread(p, len); assert(ret == 1); dksclose(); sample = (sb_sample *) walloc(sizeof(sb_sample)); sample->chunk = Mix_LoadWAV_RW(SDL_RWFromConstMem(p, len), 1); if (sample->chunk == NULL) { fprintf(stderr, "sdl_sample_load: %s\n", Mix_GetError()); exit(1); } free(p); return sample; #else return NULL; #endif }
/** * @brief Tests opening from memory. * * \sa * http://wiki.libsdl.org/moin.cgi/SDL_RWFromConstMem * http://wiki.libsdl.org/moin.cgi/SDL_RWClose */ int rwops_testConstMem (void) { SDL_RWops *rw; int result; /* Open handle */ rw = SDL_RWFromConstMem( RWopsHelloWorldCompString, sizeof(RWopsHelloWorldCompString)-1 ); SDLTest_AssertPass("Call to SDL_RWFromConstMem() succeeded"); SDLTest_AssertCheck(rw != NULL, "Verify opening memory with SDL_RWFromConstMem does not return NULL"); /* Bail out if NULL */ if (rw == NULL) return TEST_ABORTED; /* Check type */ SDLTest_AssertCheck(rw->type == SDL_RWOPS_MEMORY_RO, "Verify RWops type is SDL_RWOPS_MEMORY_RO; expected: %d, got: %d", SDL_RWOPS_MEMORY_RO, rw->type); /* Run generic tests */ _testGenericRWopsValidations( rw, 0 ); /* Close handle */ result = SDL_RWclose(rw); SDLTest_AssertPass("Call to SDL_RWclose() succeeded"); SDLTest_AssertCheck(result == 0, "Verify result value is 0; got: %d", result); return TEST_COMPLETED; }
static void start(sstate *data) { // data->sample = Sound_NewSampleFromFile("rain.mtm", NULL, 65536); data->rw = SDL_RWFromConstMem(song, song_size); data->sample = Sound_NewSample(data->rw, ".mtm", NULL, 65536); if (data->sample == NULL) { fprintf(stderr, "Failed to init sound: %s\n", Sound_GetError()); return; } data->devformat.freq = data->sample->actual.rate; data->devformat.format = data->sample->actual.format; data->devformat.channels = data->sample->actual.channels; data->devformat.samples = 4096; /* I just picked a largish number here. */ data->devformat.callback = audio_callback; data->devformat.userdata = data; if (SDL_OpenAudio(&data->devformat, NULL) < 0) { fprintf(stderr, "Couldn't open audio device: %s.\n", SDL_GetError()); Sound_FreeSample(data->sample); return; } SDL_PauseAudio(0); data->done_flag = 0; }
bool Bitmap::Load(unsigned id, Type type) { assert(IsScreenInitialized()); Reset(); ResourceLoader::Data data = ResourceLoader::Load(id); if (data.first == NULL) return false; #ifdef WIN32 const BITMAPINFO *info = (const BITMAPINFO *)data.first; if (data.second < sizeof(*info)) return false; int pitch = (((info->bmiHeader.biWidth * info->bmiHeader.biBitCount + 7) / 8 - 1) | 3) + 1; int data_size = pitch * info->bmiHeader.biHeight; /* duplicate the BMP file and re-insert the BITMAPFILEHEADER which is not included in this .EXE file */ size_t size = data.second; BITMAPFILEHEADER *header = (BITMAPFILEHEADER *)malloc(sizeof(*header) + size); if (header == NULL) /* out of memory */ return false; /* byte order? this constant is correct according to MSDN */ header->bfType = 0x4D42; header->bfSize = sizeof(*header) + size; header->bfReserved1 = 0; header->bfReserved2 = 0; header->bfOffBits = sizeof(BITMAPFILEHEADER) + size - data_size; memcpy(header + 1, data.first, data.second); const void *bmp_data = header; size_t bmp_size = sizeof(*header) + size; #else const void *bmp_data = data.first; size_t bmp_size = data.second; #endif SDL_RWops *rw = SDL_RWFromConstMem(bmp_data, bmp_size); #ifdef WIN32 SDL_Surface *original = ::SDL_LoadBMP_RW(rw, 1); free(header); #else SDL_Surface *original = ::IMG_LoadPNG_RW(rw); SDL_RWclose(rw); #endif if (original == NULL) return false; Load(original, type); return true; }
SDL_RWops* sound_archive::load_sound(size_t iIndex) { if(iIndex >= sound_file_count) return nullptr; sound_dat_sound_info *pFile = sound_files + iIndex; return SDL_RWFromConstMem(data + pFile->position, pFile->length); }
static TTF_Font * Load_Font(int ptsize) { SDL_RWops *sdlrwmem = NULL; sdlrwmem = SDL_RWFromConstMem(&FontDump, FontSize); return TTF_OpenFontRW(sdlrwmem, 1, ptsize); }
SDL_Surface* get_image(void* img, int size) { SDL_Surface* pic; pic = SDL_LoadBMP_RW(SDL_RWFromConstMem(img, size), 1); return pic; }
SDL_RWops* THSoundArchive::loadSound(size_t iIndex) { if(iIndex >= m_iFileCount) return NULL; th_fileinfo_t *pFile = m_pFiles + iIndex; return SDL_RWFromConstMem(m_pData + pFile->position, pFile->length); }
void ImageLoader::load(IResource* res) { VFS* vfs = VFS::instance(); Image* img = dynamic_cast<Image*>(res); //Have to save the images x and y shift or it gets lost when it's //loaded again. int32_t xShiftSave = img->getXShift(); int32_t yShiftSave = img->getYShift(); if(!img->isSharedImage()) { const std::string& filename = img->getName(); boost::scoped_ptr<RawData> data (vfs->open(filename)); size_t datalen = data->getDataLength(); boost::scoped_array<uint8_t> darray(new uint8_t[datalen]); data->readInto(darray.get(), datalen); SDL_RWops* rwops = SDL_RWFromConstMem(darray.get(), static_cast<int>(datalen)); SDL_Surface* surface = IMG_Load_RW(rwops, false); if (!surface) { throw SDLException(std::string("Fatal Error when loading image into a SDL_Surface: ") + SDL_GetError()); } RenderBackend* rb = RenderBackend::instance(); // in case of SDL we don't need to convert the surface if (rb->getName() == "SDL") { img->setSurface(surface); // in case of OpenGL we need a 32bit surface } else { SDL_PixelFormat dst_format = rb->getPixelFormat(); SDL_PixelFormat src_format = *surface->format; uint8_t dstbits = dst_format.BitsPerPixel; uint8_t srcbits = src_format.BitsPerPixel; if (srcbits != 32 || dst_format.Rmask != src_format.Rmask || dst_format.Gmask != src_format.Gmask || dst_format.Bmask != src_format.Bmask || dst_format.Amask != src_format.Amask) { dst_format.BitsPerPixel = 32; SDL_Surface* conv = SDL_ConvertSurface(surface, &dst_format, 0); dst_format.BitsPerPixel = dstbits; if (!conv) { throw SDLException(std::string("Fatal Error when converting surface to the screen format: ") + SDL_GetError()); } img->setSurface(conv); SDL_FreeSurface(surface); } else { img->setSurface(surface); } } SDL_FreeRW(rwops); } //restore saved x and y shifts img->setXShift(xShiftSave); img->setYShift(yShiftSave); }
SDL_Surface * BitmapHandler::loadBitmapFromDir(std::string path, std::string fname, bool setKey) { if(!fname.size()) { logGlobal->warnStream() << "Call to loadBitmap with void fname!"; return NULL; } if (!CResourceHandler::get()->existsResource(ResourceID(path + fname, EResType::IMAGE))) { return nullptr; } SDL_Surface * ret=NULL; auto readFile = CResourceHandler::get()->loadData( ResourceID(path + fname, EResType::IMAGE)); if (isPCX(readFile.first.get())) { //H3-style PCX ret = loadH3PCX(readFile.first.get(), readFile.second); if (ret) { if(ret->format->BytesPerPixel == 1 && setKey) { const SDL_Color &c = ret->format->palette->colors[0]; SDL_SetColorKey(ret,SDL_SRCCOLORKEY,SDL_MapRGB(ret->format, c.r, c.g, c.b)); } } else logGlobal->errorStream()<<"Failed to open "<<fname<<" as H3 PCX!"; } else { //loading via SDL_Image CFileInfo info(CResourceHandler::get()->getResourceName(ResourceID(path + fname, EResType::IMAGE))); ret = IMG_LoadTyped_RW( //create SDL_RW with our data (will be deleted by SDL) SDL_RWFromConstMem((void*)readFile.first.get(), readFile.second), 1, // mark it for auto-deleting &info.getExtension()[0] + 1); //pass extension without dot (+1 character) if (ret) { if (ret->format->palette) { //set correct value for alpha\unused channel for (int i=0; i< ret->format->palette->ncolors; i++) ret->format->palette->colors[i].unused = 255; } } else { logGlobal->errorStream()<<"Failed to open "<<fname<<" via SDL_Image"; } } SDL_SetColorKey(ret, SDL_SRCCOLORKEY, SDL_MapRGB(ret->format, 0, 255, 255)); return ret; }
int main(int argc, char **argv) { SDL_Init(SDL_INIT_AUDIO); int ret = Mix_OpenAudio(0, 0, 0, 0); // we ignore all these.. assert(ret == 0); { SDL_RWops * ops = SDL_RWFromFile("sound.ogg", "r"); sound = Mix_LoadWAV_RW(ops, 0); SDL_FreeRW(ops); assert(sound); } { struct stat info; int result = stat("noise.ogg", &info); char * bytes = malloc( info.st_size ); FILE * f = fopen( "noise.ogg", "rb" ); fread( bytes, 1, info.st_size, f ); fclose(f); SDL_RWops * ops = SDL_RWFromConstMem(bytes, info.st_size); sound3 = Mix_LoadWAV_RW(ops, 0); SDL_FreeRW(ops); free(bytes); } { music = Mix_LoadMUS("the_entertainer.ogg"); } sound2 = Mix_LoadWAV("sound2.wav"); assert(sound2); int channel = play(); printf( "Pausing Channel %d", channel ); Mix_Pause(channel); int paused = Mix_Paused(channel); printf( "Channel %d %s", channel, paused ? "is paused" : "is NOT paused" ); assert(paused); Mix_Resume(channel); paused = Mix_Paused(channel); printf( "Channel %d %s", channel, paused ? "is paused" : "is NOT paused" ); assert(paused == 0); if (argc == 12121) play2(); // keep it alive emscripten_run_script("element = document.createElement('input');" "element.setAttribute('type', 'button');" "element.setAttribute('value', 'replay!');" "element.setAttribute('onclick', 'Module[\"_play\"]()');" "document.body.appendChild(element);"); printf("you should hear two sounds. press the button to replay!\n"); return 0; }
TTF_Font * CTrueTypeFont::loadFont(const JsonNode &config) { int pointSize = config["size"].Float(); if(!TTF_WasInit() && TTF_Init()==-1) throw std::runtime_error(std::string("Failed to initialize true type support: ") + TTF_GetError() + "\n"); return TTF_OpenFontRW(SDL_RWFromConstMem(data.first.get(), data.second), 1, pointSize); }
/** * Loads a sound file from a specified memory chunk. * @param data Pointer to the sound file in memory * @param size Size of the sound file in bytes. */ void Sound::load(const void *data, unsigned int size) { SDL_RWops *rw = SDL_RWFromConstMem(data, size); _sound = Mix_LoadWAV_RW(rw, 1); if (_sound == 0) { throw Exception(Mix_GetError()); } }
void Texture::LoadTexture_fromMemoryPage(const MemoryPage& input_page, const ScreenVideo& makerVideo) throw(Error){ this->Clean(); if(makerVideo.m_renderer==nullptr) throw Error("Texture","LoadTexture_fromMemoryPage","Impossibile caricare una texture con uno specifico renderer nullo!"); if(makerVideo.m_renderer!=m_render) m_render = makerVideo.m_renderer; if(input_page.GetSize()==0) return; if(m_render==nullptr) throw Error("Texture","LoadTexture_fromMemoryPage","Impossibile caricare la texture richiesta!\nRenderer non inizializzato!"); SDL_RWops* data_access = SDL_RWFromConstMem(input_page.Get_PtrMemory(),input_page.GetSize()); if(data_access==nullptr){ throw Error("Texture","LoadTexture_fromMemoryPage","Pagina di memoria corrotta!\n%s",SDL_GetError()); }else{ SDL_Surface* image_load = IMG_Load_RW(data_access,1); if(image_load==nullptr){ throw Error("Texture","LoadTexture_fromMemoryPage","Impossibile caricare correttamente la texture richiesta\n%s",SDL_GetError()); }else{ SDL_Surface* image_opt = SDL_ConvertSurfaceFormat(image_load,SDL_PIXELFORMAT_RGBA8888,0); SDL_FreeSurface(image_load); image_load=nullptr; if(image_opt==nullptr){ throw Error("Texture","LoadTexture_fromMemoryPage","Impossibile ottimizzare correttamente la texture richiesta\n%s",SDL_GetError()); } this->m_texture = SDL_CreateTexture(m_render,SDL_PIXELFORMAT_RGBA8888,SDL_TEXTUREACCESS_STREAMING,image_opt->w,image_opt->h); if(this->m_texture==nullptr){ SDL_FreeSurface(image_opt); throw Error("Texture","LoadTexture_fromMemoryPage","Impossibile creare una texture grafica!\n%s",SDL_GetError()); } void* data_pixel_texture; int pitch_pixel_texture; if(SDL_LockTexture(m_texture,NULL,&data_pixel_texture,&pitch_pixel_texture)!=0){ SDL_FreeSurface(image_opt); SDL_DestroyTexture(m_texture); throw Error("Texture","LoadTexture_fromMemoryPage","Impossibile scrivere la texture grafica!\n%s",SDL_GetError()); } memcpy(data_pixel_texture,image_opt->pixels,image_opt->pitch * image_opt->h); SDL_UnlockTexture(m_texture); data_pixel_texture=nullptr; m_w_size = image_opt->w; m_h_size = image_opt->h; m_w_size_scaled = image_opt->w; m_h_size_scaled = image_opt->h; m_drawnable_area.Set_AllComponent(0,0,image_opt->w,image_opt->h); m_alpha_mod = SDL_ALPHA_OPAQUE; SDL_FreeSurface(image_opt); image_opt=nullptr; SDL_SetTextureBlendMode(m_texture,SDL_BLENDMODE_BLEND); } } }
/** * Loads a music file from a specified memory chunk. * @param data Pointer to the music file in memory * @param size Size of the music file in bytes. */ void Music::load(const void *data, unsigned int size) { SDL_RWops *rwops = SDL_RWFromConstMem(data, size); _music = Mix_LoadMUS_RW(rwops); SDL_FreeRW(rwops); if (_music == 0) { throw Exception(Mix_GetError()); } }
void SDLCardView::SetIdentityCard(IdentityCard& card) { m_Card = card; SDL_RWops* pixelsWop = SDL_RWFromConstMem(card.m_Photo.photo.ToCString(), card.m_Photo.photo.Length()); m_pIdentityPhotoSurface = IMG_LoadJPG_RW(pixelsWop); m_pIdentityPhotoTexture = SDL_CreateTextureFromSurface(m_pRenderer, m_pIdentityPhotoSurface); m_IsCardSet = true; }
font font::open_font(istream& thefile,int ptsize,long index) { thefile.seekg(0,ios::end); int filesize=thefile.tellg(); thefile.seekg(0,ios::beg); auto_ptr<vector<char> > filecont(new vector<char>(filesize)); thefile.read(&(*filecont)[0],filesize); SDL_RWops* wop=SDL_RWFromConstMem(&(*filecont)[0],filesize); TTF_Font* thefont = TTF_OpenFontIndexRW(wop,true,ptsize,index); return font().build(thefont,filecont); }
bool C4MusicFileSDL::Play(bool loop) { const SDL_version * link_version = Mix_Linked_Version(); if (link_version->major < 1 || (link_version->major == 1 && link_version->minor < 2) || (link_version->major == 1 && link_version->minor == 2 && link_version->patch < 7)) { // Check existance and try extracting it if (!FileExists(FileName)) if (!ExtractFile()) // Doesn't exist - or file is corrupt { LogF("Error reading %s", FileName); return false; } // Load Music = Mix_LoadMUS(SongExtracted ? Config.AtTempPath(C4CFN_TempMusic2) : FileName); // Load failed if (!Music) { LogF("SDL_mixer: %s", SDL_GetError()); return false; } // Play Song if (Mix_PlayMusic(Music, loop? -1 : 1) == -1) { LogF("SDL_mixer: %s", SDL_GetError()); return false; } } else { // Load Song // Fixme: Try loading this from the group incrementally for less lag size_t filesize; if (!C4Group_ReadFile(FileName, &Data, &filesize)) { LogF("Error reading %s", FileName); return false; } // Mix_FreeMusic frees the RWop Music = Mix_LoadMUS_RW(SDL_RWFromConstMem(Data, filesize)); if (!Music) { LogF("SDL_mixer: %s", SDL_GetError()); return false; } if (Mix_PlayMusic(Music, loop? -1 : 1) == -1) { LogF("SDL_mixer: %s", SDL_GetError()); return false; } } return true; }
void sprite_init(Sprite *sprite, int ox, int oy, int fx, int fy, int c, const void *mem, int len) { memset(sprite,0,sizeof(Sprite)); sprite->origin.x = ox; sprite->origin.y = oy; sprite->frame_size.x = fx; sprite->frame_size.y = fy; sprite->frame_count = c; sprite->source = IMG_Load_RW(SDL_RWFromConstMem( mem, len), 0); sprite->rotated = NULL; sprite_gen_rotation(sprite); }
glui32 glk_schannel_play_ext(schanid_t chan, glui32 snd, glui32 repeats, glui32 notify) { long len; glui32 type; char *buf = 0; if (!chan) { gli_strict_warning("schannel_play_ext: invalid id."); return 0; } /* stop previous noise */ glk_schannel_stop(chan); if (repeats == 0) return 1; /* load sound resource into memory */ type = load_sound_resource(snd, &len, &buf); chan->sdl_memory = (unsigned char*)buf; chan->sdl_rwops = SDL_RWFromConstMem(buf, len); chan->notify = notify; chan->resid = snd; chan->loop = repeats; switch (type) { case giblorb_ID_FORM: case giblorb_ID_AIFF: case giblorb_ID_WAVE: return play_sound(chan); break; case giblorb_ID_OGG: return play_compressed(chan, "OGG"); break; case giblorb_ID_MP3: return play_compressed(chan, "MP3"); break; case giblorb_ID_MOD: return play_mod(chan, len); break; default: gli_strict_warning("schannel_play_ext: unknown resource type."); } return 0; }
/** * Loads a music file from a specified memory chunk. * @param data Pointer to the music file in memory * @param size Size of the music file in bytes. */ void Music::load(const void *data, int size) { #ifndef __NO_MUSIC SDL_RWops *rwops = SDL_RWFromConstMem(data, size); _music = Mix_LoadMUS_RW(rwops); SDL_FreeRW(rwops); if (_music == 0) { throw Exception(Mix_GetError()); } #endif }
bool Bitmap::load(unsigned id) { reset(); #ifdef ENABLE_SDL ResourceLoader::Data data = ResourceLoader::Load(id); if (data.first == NULL) return false; #ifdef WIN32 const BITMAPINFO *info = (const BITMAPINFO *)data.first; if (data.second < sizeof(*info)) return false; int pitch = (((info->bmiHeader.biWidth * info->bmiHeader.biBitCount) / 8 - 1) | 3) + 1; int data_size = pitch * info->bmiHeader.biHeight; /* duplicate the BMP file and re-insert the BITMAPFILEHEADER which is not included in this .EXE file */ BITMAPFILEHEADER *header = (BITMAPFILEHEADER *)malloc(sizeof(*header) + size); if (header == NULL) /* out of memory */ return false; /* byte order? this constant is correct according to MSDN */ header->bfType = 0x4D42; header->bfSize = sizeof(*header) + size; header->bfReserved1 = 0; header->bfReserved2 = 0; header->bfOffBits = sizeof(BITMAPFILEHEADER) + size - data_size; memcpy(header + 1, data.first, data.second); const void *bmp_data = header; size_t bmp_size = sizeof(*header) + size; #else const void *bmp_data = data.first; size_t bmp_size = data.second; #endif SDL_RWops *rw = SDL_RWFromConstMem(bmp_data, bmp_size); surface = SDL_LoadBMP_RW(rw, 1); #ifdef WIN32 free(header); #endif return true; #else /* !ENABLE_SDL */ bitmap = ResourceLoader::LoadBitmap2(id); return bitmap != NULL; #endif /* !ENABLE_SDL */ }
void PixelBuffer::load( const std::vector<char>& buffer ) { // TODO: Proper error handling. if( S ) SDL_FreeSurface(S); SDL_RWops *rw = SDL_RWFromConstMem(&buffer[0],buffer.size()); cgeEnforce( rw ); SDL_Surface *raw = IMG_Load_RW(rw,0); SDL_FreeRW(rw); cgeEnforce( raw ); s_ = SDL_DisplayFormatAlpha(raw); SDL_FreeSurface(raw); cgeEnforce( s_ ); }
bool Wav::ParseData(const void *data, size_t size) { SDL_RWops *f = SDL_RWFromConstMem(data, size); if (f == NULL) { SDL_ERROR("SDL_RWFromConstMem failed"); return false; } bool ret = ParseData(f); SDL_RWclose(f); return false; }