BB bugged or just the command ?
Blitz3D Forums/Blitz3D Beginners Area/BB bugged or just the command ?
| ||
| ; Color, ColorRed(), ColorBlue(), ColorGreen() Example ; Gotta be in graphics mode Graphics 640,480, 8 Cls ; Let's set the color to something random SeedRnd MilliSecs() ; Seed the randomizer with the current system time in milliseconds. Red = Rnd(0,63) Green = Rnd(0,63) Blue = Rnd(0,63) Color Red,Green,Blue ; Now let's see what they are! Text 10,10,"This Text is printed in Red=" + ColorRed() + " Green=" + ColorGreen() + " Blue=" + ColorBlue() + "!" WaitKey Color 255,255,255 Print : Print : Print Print Red Print Green Print Blue WaitKey The purpose of this program whas to see how to use 8 bits, 256 colors mode. I need it for my tile/sprite ripper/editor. When i use Graphics 640,480 , i get 16 bits colors and colorred(), colorgreen(), colorblue() return the good value. When i use Graphics 640,480,8 , i get 16 bits colors and colorred(), colorgreen(), colorblue() return bads values (all at 255). And the colors palette is not good (allways white (36,28,50 for example this is not a white color palette) What is wrong with BB palette colors ? |
| ||
| BB does not support use of palettes, a depth of 8 with the Graphics command should throw a runtime error. |
| ||
| Ok Thank you Skidracer. Can i create a internal 256 colors in datas for example or do i must translate every 256 colors palette (from the bmp file) to a 16 bits colors values ? How can i test a grabimage with another ? Is the a command to test if a grabimage is the EXACT copy of another in memory ? With the handle of createimage or with a special command ? Do i must create my own function ? |
| ||
| Blitz translates the pixels from 8 to 16 bit at load time so you do not have to worry about palettes at all. You will need to code your own compare image command which would look something like: Function IdenticalImages(i1,i2) w=ImageWidth(i1) h=ImageHeight(i1) If w<>ImageWidth(i2) Return False If h<>ImageHeight(i2) Return False b1=ImageBuffer(i1) b2=ImageBuffer(i2) For y=0 To h-1 For x=0 To w-1 If ReadPixel(x,y,b1)<>ReadPixel(x,y,b2) Return False Next Next Return True End Function |
| ||
| Thanks a lot SkidRacer :-) |
| ||
| What I was reading about 8 bit colour, if you are planing on using it to speed up your program, most video cards don't show any speed increase with 8 bit colour over 16. And many actually show a decrease, in speed. The only real reason it is supported still is for backwards compatability, with older software. |
| ||
| I just need 8 bits colors because my editor will create tiles and sprites for a futur RPG game like "harvest moon" or snes/gba style. I must know where are the color used for each pixel of a tile, and because my ripper must know wich color is already used for mixing 2 tileset between us. With 16M o colors, how can i know witch color is used for tile xx and tile xy and reducing the palette (16M colors but colors sorted in the top of the color array data). I need to know that i a want to create a special data format library (multiTileSet in one file with 2000 different tiles in each tileSet) With this format of tileset (2000), maplevels can be very diversified with a lot of different architectural houses, for example and seasons. |
| ||
| OK! I understand! And that's 64K colours not 16M for 16 bit. |
| ||
| Thank for the info AbbaRue. Now i understand better the 16 bits colors mode. Never used before because Dos/vga whas an big graphics memory problem in others mode than ModeX. |
| ||
| the following code check all the tiles in one picture and make a new tileset with the uniques tiles only hope you like
Graphics 800,600,32,02
Global mytileset=CreateImage(640,480,1,2); or loadimage the tileset
;------------------------------------------
; this part create a 'tileset' remove it if you load one
SetBuffer ImageBuffer(mytileset)
For blah=1 To 150
Color 255,2552,55
Text Rand(640),Rand(480),"O"
Next
;-------------------------------------------
SetBuffer FrontBuffer()
comp$=comparetileset(mytileset,32,32)
maxtile_x=ImageWidth(mytileset)/32
maxtile_y=ImageHeight(mytileset)/32
maxtiles=maxtile_x*maxtile_y-1
Text 0,10,"found "+Len(comp$)/4+"of"+maxtiles+" tiles matching ("+(maxtiles-Len(comp$)/4)+")unique tiles)
Text 0,20,"press a key to compute new tileset"
Flip
WaitKey
newtileset=compute(mytileset,32,32,comp$)
Flip
WaitKey
End
Function comparetileset$(image,width,height)
DrawBlock mytileset,0,0
Flip
maxtile_x=ImageWidth(image)/width
maxtile_y=ImageHeight(image)/height
maxtiles=maxtile_x*maxtile_y-1
For tile=0 To maxtiles
find=False
For a=1 To Len(comp$)/4
If tile=unformat(comp$,a)
find=True
EndIf
Next
If find=False
yt=Int(tile/maxtile_x)
xt=tile-(yt*maxtile_x)
LockBuffer BackBuffer() ;ImageBuffer(image)
For tile2=0 To maxtiles
If tile2>=tile
find=False
For a=1 To Len(comp$)/4
If tile2=unformat(comp$,a)
find=True
EndIf
Next
If find=False
yt2=Int(tile2/maxtile_x)
xt2=tile2-(yt2*maxtile_x)
xc=0
yc=0
If tile<>tile2
Repeat
c1=ReadPixelFast(xt*width+xc,yt*height+yc,BackBuffer());,ImageBuffer(image))
c2=ReadPixelFast(xt2*width+xc,yt2*height+yc,BackBuffer());,ImageBuffer(image))
xc=xc+1
If xc>width-1
xc=0
yc=yc+1
EndIf
Until c1<>c2 Or yc>height-1
If yc>height-1
comp$=comp$+format$(tile2)
EndIf
EndIf
EndIf
EndIf
Next
UnlockBuffer BackBuffer() ;ImageBuffer(image)
EndIf
Next
Return comp$
End Function
Function format$(value)
Return String$("0",4-Len(Str(value)))+Str(value)
End Function
Function unformat(strin$,pos)
Return Mid(strin$,((pos-1)*4)+1,4)
End Function
Function compute(image,width,height,comp$)
maxtile_x=ImageWidth(image)/width
maxtile_y=ImageHeight(image)/height
temp=CreateImage(ImageWidth(image),ImageHeight(image),1,2)
maxtiles=(maxtile_x*maxtile_y)-1
Newpos=0
Color 255,255,255
Rect 0,0,800,600,1
For tile=0 To maxtiles
matching=False
For search=1 To Len(comp$)/4
If tile=unformat(comp$,search)
matching=True
EndIf
Next
If matching=False
yt=Int(tile/maxtile_x)
xt=tile-(yt*maxtile_x)
yt2=Int(Newpos/maxtile_x)
xt2=Newpos-(yt2*maxtile_x)
CopyRect xt*width,yt*height,width,height,xt2*width,yt2*height,ImageBuffer(image),BackBuffer();ImageBuffer(temp)
newpos=newpos+1
EndIf
Next
End Function
|
| ||
| 16 bit colour is stored in order, from left to right and top to bottom. Each 2 bytes represents one pixel. If you rip each 2 bytes into an array of (16 bit words) Those (16 bit words) are as good as an ID you can store in a table. Also you could cut down the number of colours to 256 by using a lookup table of 256 colours, and rounding each colour down to it's nearest colour in your table. Maybe this will help. |
| ||
| Thanks a lot Ford Escort for your code. I cannot run it because i get an error "Too many parameters" but i will examine the logic of it. Thanks AbbaRue, i will follow your tips. After all, i will in first time keep the 16 bits colors (because of the beautiful looking ;-) ) and see if that take not too much size for a 2000 tileset. |
| ||
| if you run b3D or bb just ignore the last parameters in the create image commands Global mytileset=CreateImage(640,480); instead of Global mytileset=CreateImage(640,480,1,2); and temp=CreateImage(ImageWidth(image),ImageHeight(image)) instead of temp=CreateImage(ImageWidth(image),ImageHeight(image),1,2) it's just additional parameters for blitzplus :) |
| ||
| Tanks a lot Ford Escort, now it work perfectli for BB3D :-) |