WritePixel
BlitzMax Forums/BlitzMax Programming/WritePixel
| ||
I'm looking at the WritePixel source and wondering if Case PF_RGBA8888 shouldn't be raised to the top of the Select list? Isn't that the format most pixmaps use?Method WritePixel( x,y,argb ) Assert x>=0 And x<width And y>=0 And y<height Else "Pixmap coordinates out of bounds" Local p:Byte Ptr=PixelPtr(x,y) Select format Case PF_A8 p[0]=argb Shr 24 Case PF_I8 p[0]=( (argb Shr 16 & $ff)+(argb Shr 8 & $ff)+(argb & $ff) )/3 Case PF_RGB888 p[0]=argb Shr 16 ; p[1]=argb Shr 8 ; p[2]=argb Case PF_BGR888 p[0]=argb ; p[1]=argb Shr 8 ; p[2]=argb Shr 16 Case PF_RGBA8888 p[0]=argb Shr 16 ; p[1]=argb Shr 8 ; p[2]=argb ; p[3]=argb Shr 24 Case PF_BGRA8888 p[0]=argb ; p[1]=argb Shr 8 ; p[2]=argb Shr 16 ; p[3]=argb Shr 24 End Select End Method |
| ||
Good point? |
| ||
Case PF_RGBA8888 shouldn't be raised to the top of the Select list? Don't you mean, it should be at the top of the Select statement? |
| ||
Or mark could just make the compiler do jump tables in stead ;) hehe |
| ||
It kinda depends. I prefer RGBA myself but some macs and pc's default to like ARGB or ABGR formats. I don't really like that pixmap operations default to other formats. I think it should be standardized to RGBA. Note that graphics cards all use internal formats which may be different for images than for pixmaps. |
| ||
You'd actually be better off doing something like:local a:TPixmap=LoadPixmap("Pic.png") a=ConvertPixmap(a,PF_RGBA8888) local b:Byte Ptr=PixmapPixelPtr(a,0,0) local c:Int=PixmapPitch(a) 'then e.g. a[50+(50*c)]=$FF 'write one color component at the 50th component on line 50 Ie use pointers to write the bytes/integers in your preferred format - although this would potentially break if the pixmap system is changed somehow. |