Hi, I had attached the image along this mail. Its part of cocos2d-iphone project (https://github.com/ANindie/cocos2d-GNUstep/raw/1219df69bd64feb6aa2ae83073e1f9e380e6f9ad/src/Resources/Images/stars2-grayscale.png). As per 'Gimp 'it contains 2 channels, alpha and luminosity. 64*64 pixels. GNUstep NSBitmapimagerep reports that samplesPerPixel=2, BytesPerRow=128. So I tried to use the data provided by NSBitmapimagerep to generate RBGA pixel data. Either my approach going wrong or NSBitmapimagerep doesn't give proper data. Also I tried rendering image assuming BytesPerRow = 64*4 half of the image renders properly rest is black/garbage.
On 2/12/11, Gregory Casamento <[email protected]> wrote: > Which image? I don't see an attachment or a link. > > On Thursday, February 10, 2011, indieAN <[email protected]> wrote: >> Hi, >> I trying to render a gray scale image (contains 2 channels luminosity >> and alpha) using opengl. Actually this image is a png image. I am >> decoding it using nsbitmaprep. But only garbage gets rendered. Can any >> body tell whats wrong with following code. Or their is bug in >> nsbitmapImagerep for rendering grayscale? >> >> >> -(id) initPremultipliedATextureWithBitmap:(NSBitmapImageRep*)bitmap >> pixelsWide:(NSUInteger)POTWide pixelsHigh:(NSUInteger)POTHigh >> { >> >> short bytesPerPixel = [bitmap bitsPerPixel]>>3;//2 >> unsigned char * data = calloc(1, POTHigh * POTWide * 4); >> const unsigned char * originaldata = [bitmap bitmapData]; >> >> >> >> NSSize size=NSMakeSize([bitmap pixelsWide],[bitmap >> pixelsHigh]); //64*64 >> NSUInteger bytesPerRow = [bitmap bytesPerRow];//128 >> NSUInteger pixelPerRow = bytesPerRow / bytesPerPixel;//64 >> CCTexture2DPixelFormat pixelFormat; >> >> NSUInteger inputPixelPerRow = POTWide * 4; >> >> >> >> int spp = [bitmap samplesPerPixel]; //2 >> >> >> #define FLIPPED_BITMAP 0 >> int i; >> >> for (i = 0; i < size.height ; i++) >> { >> >> >> #if FLIPPED_BITMAP >> int vrow=(int)size.height -i-1; >> #else >> int vrow=i; >> #endif >> >> >> if(spp == 2) >> { >> >> >> unsigned char * dest = data + (vrow * POTWide * 4); >> const unsigned char * src = originaldata + (i * bytesPerRow); >> >> int k=0; >> for(k=0; k<size.width ; k++) >> { >> >> *(dest +k*4+3)=*(src+k*2+1); //alpha >> >> *(dest +k*4) = *(src+k*2+2);//r >> *(dest +k*4 + 1) = *(src+k*2);//g >> *(dest +k*4 + 2) = *(src+k*2);//b >> >> } >> } >> else >> memcpy(data + (vrow * POTWide * 4), originaldata + (i * >> bytesPerRow), bytesPerRow); >> } >> >> >> >> self = [self initWithData:data pixelFormat:pixelFormat >> pixelsWide:POTWide pixelsHigh:POTHigh contentSize:size >> unpackRowLength:POTWide]; >> >> >> return self; >> }; >> >> Thanks in advance. >> -indieAN >> https://github.com/ANindie/cocos2d-GNUstep >> >> >> >> _______________________________________________ >> Discuss-gnustep mailing list >> [email protected] >> http://lists.gnu.org/mailman/listinfo/discuss-gnustep >> > > -- > Gregory Casamento - GNUstep Lead/Principal Consultant, OLC, Inc. > yahoo/skype: greg_casamento, aol: gjcasa > (240)274-9630 (Cell) >
<<attachment: stars2-grayscale.png>>
_______________________________________________ Discuss-gnustep mailing list [email protected] http://lists.gnu.org/mailman/listinfo/discuss-gnustep
