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) _______________________________________________ Discuss-gnustep mailing list [email protected] http://lists.gnu.org/mailman/listinfo/discuss-gnustep
