Based on the concepts in my question here and the problems with the PNG files outlined in my other question here , I will try to load an RGBA image from two jpeg. One will contain RGB and the other only Alpha. I can either save the 2nd, either as a shade of gray, or as RGB, and pull the alpha data from the red component.
In the second step, I will save the raw image data to a file in the cache. Then I will do a test to quickly determine the loading of raw data or unzip jpegs and collect raw data. If I determine this faster, then with subsequent loads I can check for the presence of an unprocessed file in the cache. If not, I will skip this file.
I know how to load two jpeg into two UIImages. I'm not sure if this is the fastest or most efficient way to strip rgb from one UIImage to any channel of another UIImage that I use for alpha.
I see two possibilities. One of them would be in comment B below .. iterating over all pixels and copying red from alpha alpha to alpha in imageData data pairs.
Another thing is that there may be some kind of magic UIImage command for copying a channel from one channel to another. If I did this, it would be somewhere close to comment A.
Any ideas?
EDIT is also .. the process cannot destroy any RGB information. The whole reason I need this process is because PNG from Photoshop is chasing rgb with alpha and thus destroying rgb information. I use alpha for something other than alpha in the openGL user shader. So I'm looking for raw RGBA data that I can set for alpha to use as a mirror map, an irradiance map, or a height map, or something other than alpha.
Here's my starter code minus my error checking and other patented shit. I have an array of textures that I use to control everything about textures:
if (textureInfo[texIndex].generated==NO) { glGenTextures(1, &textureInfo[texIndex].texture); textureInfo[texIndex].generated=YES; } glBindTexture(GL_TEXTURE_2D, textureInfo[texIndex].texture); // glTexParameteri commands are here based on options for this texture NSString *path = [[NSBundle mainBundle] pathForResource:[NSString stringWithFormat:@"%@_RGB",name] ofType:type]; NSData *texData = [[NSData alloc] initWithContentsOfFile:path]; UIImage *imageRGB = [[UIImage alloc] initWithData:texData]; path = [[NSBundle mainBundle] pathForResource:[NSString stringWithFormat:@"%@_A",name] ofType:type]; texData = [[NSData alloc] initWithContentsOfFile:path]; UIImage *imageAlpha = [[UIImage alloc] initWithData:texData]; CGColorSpaceRef colorSpace = CGColorSpaceCreateDeviceRGB(); void *imageDataRGB = malloc( heightRGB * widthRGB * 4 ); void *imageDataAlpha = malloc( heightA * widthA * 4 ); CGContextRef thisContextRGB = CGBitmapContextCreate( imageDataRGB, widthRGB, heightRGB, 8, 4 * widthRGB, colorSpace, kCGImageAlphaPremultipliedLast | kCGBitmapByteOrder32Big ); CGContextRef thisContextA = CGBitmapContextCreate( imageDataAlpha, widthA, heightA, 8, 4 * widthA, colorSpace, kCGImageAlphaPremultipliedLast | kCGBitmapByteOrder32Big ); // **** A. In here I want to mix the two.. take the R of imageA and stick it in the Alpha of imageRGB. CGColorSpaceRelease( colorSpace ); CGContextClearRect( thisContextRGB, CGRectMake( 0, 0, widthRGB, heightRGB ) ); CGContextDrawImage( thisContextRGB, CGRectMake( 0, 0, widthRGB, heightRGB ), imageRGB.CGImage ); // **** B. OR maybe repeat the above 3 lines for the imageA.CGImage and then // **** It could be done in here by iterating through the data and copying the R byte of imageDataA on to the A byte of the imageDataRGB glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, widthRGB, heightRGB, 0, GL_RGBA, GL_UNSIGNED_BYTE, imageDataRGB); // **** In here I could save off the merged imageData to a binary file and load that later if it faster glBindTexture(GL_TEXTURE_2D, textureInfo[texIndex].texture); // Generates a full MipMap chain to the current bound texture. if (useMipmap) { glGenerateMipmap(GL_TEXTURE_2D); } CGContextRelease(thisContextRGB); CGContextRelease(thisContextA); free(imageDataRGB); free(imageDataAlpha);