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: indieAN
Subject: Re: Rendering grayscale on opengl using nsbitmaprep
Date: Wed, 16 Feb 2011 01:04:21 +0530

Hi,
  I copied the source  of convertToFormatBitsPerSample and implemented
in a category to NSBitmapImageRep. Now I am converting 
all image format to a standard format using 

   bitmap = [bitmap convertToFormatBitsPerSample: 8
                                     samplesPerPixel: 4
                                            hasAlpha: YES
                                            isPlanar: NO
                                      colorSpaceName:
NSDeviceRGBColorSpace
                                        bitmapFormat:
NSAlphaNonpremultipliedBitmapFormat 
                                         bytesPerRow: 0
                                        bitsPerPixel: 0];


All other images (RBGA) renders great. But still no luck on this gray
scale image. I am assuming that above code converts gray scale image to
std RBGA format. So same rendering code should works (It is not included
here ). I am attaching output that got from rendering.

Thanks to all,
-ANIndie
 


On Mon, 2011-02-14 at 17:31 +0100, Fred Kiefer wrote:
> I tried to render your image with a normal GNUstep test application and
> it seems to display correctly. From that I would say that it gets loaded
> by the PNG code correctly. This makes me wonder why you think that there
> might be a bug in the grayscale rendering? As far as I see rendering
> isn't involved in your case. More likely the bug is in your own
> conversion code. I tried to have a quick look at your code, but could
> not make much sense out of it. Why would you want to put in the width
> and the hight separately from the image? As far as I know these values
> might be completely off.
> If you just want to learn how to convert between different image format,
> have a look that the method
> 
> - (NSBitmapImageRep *) _convertToFormatBitsPerSample: (int)bps
>                                      samplesPerPixel: (int)spp
>                                             hasAlpha: (BOOL)alpha
>                                             isPlanar: (BOOL)isPlanar
>                                       colorSpaceName:
> (NSString*)colorSpaceName
>                                         bitmapFormat:
> (NSBitmapFormat)bitmapFormat
>                                          bytesPerRow: (int)rowBytes
>                                         bitsPerPixel: (int)pixelBits
> 
> I added that to NSBitmapImage a few years ago just to document the
> proper way of conversion. Even in GNUstep itself we had a lot of
> incomplete image conversions.
> 
> Cheers
> Fred
> 
> 
> Am 13.02.2011 18:40, schrieb Indie AN:
> > 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 <greg.casamento@gmail.com> wrote:
> >> 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;
> >>> };

-- 
---


Attachment: Screenshot.png
Description: PNG image


reply via email to

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