starbugs / icedcoffee

A lightweight OpenGL user interface framework written in Objective-C
BSD 3-Clause "New" or "Revised" License
47 stars 7 forks source link

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

Open jsfunfun opened 11 years ago

jsfunfun commented 11 years ago

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

starbugs commented 11 years ago

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