discuss-gnustep
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Rendering grayscale on opengl using nsbitmaprep


From: Gregory Casamento
Subject: Re: Rendering grayscale on opengl using nsbitmaprep
Date: Sat, 12 Feb 2011 08:56:24 -0500

Which image?  I don't see an attachment or a link.

On Thursday, February 10, 2011, indieAN <an.indian.indie@gmail.com> 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
> Discuss-gnustep@gnu.org
> 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)



reply via email to

[Prev in Thread] Current Thread [Next in Thread]