From 1b78acc2c01e168dc3d556a3501dc26791ebeb50 Mon Sep 17 00:00:00 2001 From: scrawl Date: Sat, 2 May 2015 18:06:17 +0200 Subject: [PATCH] Remove manual allocation for images --- components/fontloader/fontloader.cpp | 7 ++++--- components/resource/texturemanager.cpp | 13 +++++++------ 2 files changed, 11 insertions(+), 9 deletions(-) diff --git a/components/fontloader/fontloader.cpp b/components/fontloader/fontloader.cpp index e579de18f..080c64c4c 100644 --- a/components/fontloader/fontloader.cpp +++ b/components/fontloader/fontloader.cpp @@ -277,9 +277,10 @@ namespace Gui osg::ref_ptr image = new osg::Image; - unsigned char* bytes = (unsigned char*)calloc(width*height*4, sizeof(unsigned char)); - memcpy(bytes, &textureData[0], textureData.size()); - image->setImage(width, height, 1, GL_RGBA, GL_RGBA, GL_UNSIGNED_BYTE, bytes, osg::Image::USE_MALLOC_FREE); + image->allocateImage(width, height, 1, GL_RGBA, GL_UNSIGNED_BYTE); + assert (image->isDataContiguous()); + + memcpy(image->data(), &textureData[0], textureData.size()); osg::ref_ptr texture = new osg::Texture2D; texture->setImage(image); diff --git a/components/resource/texturemanager.cpp b/components/resource/texturemanager.cpp index d0d32a40e..b86b70cde 100644 --- a/components/resource/texturemanager.cpp +++ b/components/resource/texturemanager.cpp @@ -13,15 +13,16 @@ namespace { osg::ref_ptr warningImage = new osg::Image; - int width=8, height=8; - unsigned char* bytes = (unsigned char*)calloc(width*height*3, sizeof(unsigned char)); + int width = 8, height = 8; + warningImage->allocateImage(width, height, 1, GL_RGB, GL_UNSIGNED_BYTE); + assert (warningImage->isDataContiguous()); + unsigned char* data = warningImage->data(); for (int i=0;isetImage(width, height, 1, GL_RGB, GL_RGB, GL_UNSIGNED_BYTE, bytes, osg::Image::USE_MALLOC_FREE); osg::ref_ptr warningTexture = new osg::Texture2D; warningTexture->setImage(warningImage);