the following code check all the tiles in one picture and make a new tileset with the uniques tiles only
hope you like
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