starbugs / icedcoffee

A lightweight OpenGL user interface framework written in Objective-C

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

malloc calls in ICTexture2D.m are not needed...

jsfunfun opened this issue · comments

heh - just leaving a tip.. the malloc calls to create buffers for the 32 bit to 16 bit color conversion are entirely unnecessary. think about it.. you are 'compacting' data.. you can do an in-place 32 to 16 bit, adjust anything your code 'thinks' is 4 bytes wide on that 'inPixel32' mem block... code should be:

// no... tempData = malloc(POTHigh * POTWide * 2);
inPixel32 = (unsigned int_)data;
outPixel16 = (unsigned short_)data; // no... cast data to ushort* ... tempData;
for(unsigned int i = 0; i < POTWide * POTHigh; ++i, ++inPixel32)
_outPixel16++ =
((((_inPixel32 >> 0) & 0xFF) >> 3) << 11) | // R
((((_inPixel32 >> 8) & 0xFF) >> 3) << 6) | // G
((((_inPixel32 >> 16) & 0xFF) >> 3) << 1) | // B
((((*inPixel32 >> 24) & 0xFF) >> 7) << 0); // A

// no... free(data);
// no... data = tempData;

Cheers - JS

Hey, thanks for pointing this out. The code has been imported from cocos2d and I've never touched it or looked at it profoundly. I will merge your changes in one of the next versions of the framework.

Thanks,
Tobias