-=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- (c) WidthPadding Industries 1987 0|612|0 -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- Socoder -> Blitz -> converting colours... Page : 1 2 Next Prev Posted : Sunday, 26 July 2009, 06:58 spinal Im trying to reduce regular colours down to a websafe palette... where am i going wrong? ; attempt to convert regular colours to websafe palette. Graphics 640,480,0,2 Dim pal(215,2) For t=0 To 215 Read pal(t,0),pal(t,1),pal(t,2) Next ; r/43, g/43, b/43 For r=0 To 255 For b=0 To 255 col = ((b/43)*36) +((g/43)*6)+ (r/43) Color pal(col,0),pal(col,1),pal(col,2) Plot r,g Next Next While Not KeyHit(1) Wend End ; WebSafe Palette (216 Colours) Data 0,0,0 Data 51,0,0 Data 102,0,0 Data 153,0,0 Data 204,0,0 Data 255,0,0 Data 0,51,0 Data 51,51,0 Data 102,51,0 Data 153,51,0 Data 204,51,0 Data 255,51,0 Data 0,102,0 Data 51,102,0 Data 102,102,0 Data 153,102,0 Data 204,102,0 Data 255,102,0 Data 0,153,0 Data 51,153,0 Data 102,153,0 Data 153,153,0 Data 204,153,0 Data 255,153,0 Data 0,204,0 Data 51,204,0 Data 102,204,0 Data 153,204,0 Data 204,204,0 Data 255,204,0 Data 0,255,0 Data 51,255,0 Data 102,255,0 Data 153,255,0 Data 204,255,0 Data 255,255,0 Data 0,0,51 Data 51,0,51 Data 102,0,51 Data 153,0,51 Data 204,0,51 Data 255,0,51 Data 0,51,51 Data 51,51,51 Data 102,51,51 Data 153,51,51 Data 204,51,51 Data 255,51,51 Data 0,102,51 Data 51,102,51 Data 102,102,51 Data 153,102,51 Data 204,102,51 Data 255,102,51 Data 0,153,51 Data 51,153,51 Data 102,153,51 Data 153,153,51 Data 204,153,51 Data 255,153,51 Data 0,204,51 Data 51,204,51 Data 102,204,51 Data 153,204,51 Data 204,204,51 Data 255,204,51 Data 0,255,51 Data 51,255,51 Data 102,255,51 Data 153,255,51 Data 204,255,51 Data 255,255,51 Data 0,0,102 Data 51,0,102 Data 102,0,102 Data 153,0,102 Data 204,0,102 Data 255,0,102 Data 0,51,102 Data 51,51,102 Data 102,51,102 Data 153,51,102 Data 204,51,102 Data 255,51,102 Data 0,102,102 Data 51,102,102 Data 102,102,102 Data 153,102,102 Data 204,102,102 Data 255,102,102 Data 0,153,102 Data 51,153,102 Data 102,153,102 Data 153,153,102 Data 204,153,102 Data 255,153,102 Data 0,204,102 Data 51,204,102 Data 102,204,102 Data 153,204,102 Data 204,204,102 Data 255,204,102 Data 0,255,102 Data 51,255,102 Data 102,255,102 Data 153,255,102 Data 204,255,102 Data 255,255,102 Data 0,0,153 Data 51,0,153 Data 102,0,153 Data 153,0,153 Data 204,0,153 Data 255,0,153 Data 0,51,153 Data 51,51,153 Data 102,51,153 Data 153,51,153 Data 204,51,153 Data 255,51,153 Data 0,102,153 Data 51,102,153 Data 102,102,153 Data 153,102,153 Data 204,102,153 Data 255,102,153 Data 0,153,153 Data 51,153,153 Data 102,153,153 Data 153,153,153 Data 204,153,153 Data 255,153,153 Data 0,204,153 Data 51,204,153 Data 102,204,153 Data 153,204,153 Data 204,204,153 Data 255,204,153 Data 0,255,153 Data 51,255,153 Data 102,255,153 Data 153,255,153 Data 204,255,153 Data 255,255,153 Data 0,0,204 Data 51,0,204 Data 102,0,204 Data 153,0,204 Data 204,0,204 Data 255,0,204 Data 0,51,204 Data 51,51,204 Data 102,51,204 Data 153,51,204 Data 204,51,204 Data 255,51,204 Data 0,102,204 Data 51,102,204 Data 102,102,204 Data 153,102,204 Data 204,102,204 Data 255,102,204 Data 0,153,204 Data 51,153,204 Data 102,153,204 Data 153,153,204 Data 204,153,204 Data 255,153,204 Data 0,204,204 Data 51,204,204 Data 102,204,204 Data 153,204,204 Data 204,204,204 Data 255,204,204 Data 0,255,204 Data 51,255,204 Data 102,255,204 Data 153,255,204 Data 204,255,204 Data 255,255,204 Data 0,0,255 Data 51,0,255 Data 102,0,255 Data 153,0,255 Data 204,0,255 Data 255,0,255 Data 0,51,255 Data 51,51,255 Data 102,51,255 Data 153,51,255 Data 204,51,255 Data 255,51,255 Data 0,102,255 Data 51,102,255 Data 102,102,255 Data 153,102,255 Data 204,102,255 Data 255,102,255 Data 0,153,255 Data 51,153,255 Data 102,153,255 Data 153,153,255 Data 204,153,255 Data 255,153,255 Data 0,204,255 Data 51,204,255 Data 102,204,255 Data 153,204,255 Data 204,204,255 Data 255,204,255 Data 0,255,255 Data 51,255,255 Data 102,255,255 Data 153,255,255 Data 204,255,255 Data 255,255,255 --v -=-=- Check out my excellent homepage! Posted : Sunday, 26 July 2009, 07:07 Jayenkai ; attempt to convert regular colours to websafe palette. Graphics 640,480,0,2 SetBuffer BackBuffer() Dim pal(215,2) For t=0 To 215 Read pal(t,0),pal(t,1),pal(t,2) Next ; r/43, g/43, b/43 six=6 ;switch to 1 for full square For x=0 To 255/six For y=0 To 255 r=x*six:b=y g=((((y*6) Mod 255)/43)*36) col = ((b/43)*36) +((g/43)*6)+ (r/43) Color pal(col,0),pal(col,1),pal(col,2) Plot x,y Next Flip Next While Not KeyHit(1) Wend End ; WebSafe Palette (216 Colours) Data 0,0,0 Data 51,0,0 Data 102,0,0 Data 153,0,0 Data 204,0,0 Data 255,0,0 Data 0,51,0 Data 51,51,0 Data 102,51,0 Data 153,51,0 Data 204,51,0 Data 255,51,0 Data 0,102,0 Data 51,102,0 Data 102,102,0 Data 153,102,0 Data 204,102,0 Data 255,102,0 Data 0,153,0 Data 51,153,0 Data 102,153,0 Data 153,153,0 Data 204,153,0 Data 255,153,0 Data 0,204,0 Data 51,204,0 Data 102,204,0 Data 153,204,0 Data 204,204,0 Data 255,204,0 Data 0,255,0 Data 51,255,0 Data 102,255,0 Data 153,255,0 Data 204,255,0 Data 255,255,0 Data 0,0,51 Data 51,0,51 Data 102,0,51 Data 153,0,51 Data 204,0,51 Data 255,0,51 Data 0,51,51 Data 51,51,51 Data 102,51,51 Data 153,51,51 Data 204,51,51 Data 255,51,51 Data 0,102,51 Data 51,102,51 Data 102,102,51 Data 153,102,51 Data 204,102,51 Data 255,102,51 Data 0,153,51 Data 51,153,51 Data 102,153,51 Data 153,153,51 Data 204,153,51 Data 255,153,51 Data 0,204,51 Data 51,204,51 Data 102,204,51 Data 153,204,51 Data 204,204,51 Data 255,204,51 Data 0,255,51 Data 51,255,51 Data 102,255,51 Data 153,255,51 Data 204,255,51 Data 255,255,51 Data 0,0,102 Data 51,0,102 Data 102,0,102 Data 153,0,102 Data 204,0,102 Data 255,0,102 Data 0,51,102 Data 51,51,102 Data 102,51,102 Data 153,51,102 Data 204,51,102 Data 255,51,102 Data 0,102,102 Data 51,102,102 Data 102,102,102 Data 153,102,102 Data 204,102,102 Data 255,102,102 Data 0,153,102 Data 51,153,102 Data 102,153,102 Data 153,153,102 Data 204,153,102 Data 255,153,102 Data 0,204,102 Data 51,204,102 Data 102,204,102 Data 153,204,102 Data 204,204,102 Data 255,204,102 Data 0,255,102 Data 51,255,102 Data 102,255,102 Data 153,255,102 Data 204,255,102 Data 255,255,102 Data 0,0,153 Data 51,0,153 Data 102,0,153 Data 153,0,153 Data 204,0,153 Data 255,0,153 Data 0,51,153 Data 51,51,153 Data 102,51,153 Data 153,51,153 Data 204,51,153 Data 255,51,153 Data 0,102,153 Data 51,102,153 Data 102,102,153 Data 153,102,153 Data 204,102,153 Data 255,102,153 Data 0,153,153 Data 51,153,153 Data 102,153,153 Data 153,153,153 Data 204,153,153 Data 255,153,153 Data 0,204,153 Data 51,204,153 Data 102,204,153 Data 153,204,153 Data 204,204,153 Data 255,204,153 Data 0,255,153 Data 51,255,153 Data 102,255,153 Data 153,255,153 Data 204,255,153 Data 255,255,153 Data 0,0,204 Data 51,0,204 Data 102,0,204 Data 153,0,204 Data 204,0,204 Data 255,0,204 Data 0,51,204 Data 51,51,204 Data 102,51,204 Data 153,51,204 Data 204,51,204 Data 255,51,204 Data 0,102,204 Data 51,102,204 Data 102,102,204 Data 153,102,204 Data 204,102,204 Data 255,102,204 Data 0,153,204 Data 51,153,204 Data 102,153,204 Data 153,153,204 Data 204,153,204 Data 255,153,204 Data 0,204,204 Data 51,204,204 Data 102,204,204 Data 153,204,204 Data 204,204,204 Data 255,204,204 Data 0,255,204 Data 51,255,204 Data 102,255,204 Data 153,255,204 Data 204,255,204 Data 255,255,204 Data 0,0,255 Data 51,0,255 Data 102,0,255 Data 153,0,255 Data 204,0,255 Data 255,0,255 Data 0,51,255 Data 51,51,255 Data 102,51,255 Data 153,51,255 Data 204,51,255 Data 255,51,255 Data 0,102,255 Data 51,102,255 Data 102,102,255 Data 153,102,255 Data 204,102,255 Data 255,102,255 Data 0,153,255 Data 51,153,255 Data 102,153,255 Data 153,153,255 Data 204,153,255 Data 255,153,255 Data 0,204,255 Data 51,204,255 Data 102,204,255 Data 153,204,255 Data 204,204,255 Data 255,204,255 Data 0,255,255 Data 51,255,255 Data 102,255,255 Data 153,255,255 Data 204,255,255 Data 255,255,255 --v -=-=- ''Load, Next List!'' Posted : Monday, 27 July 2009, 05:08 spinal The Results..... I have managed to use simple pattern dithering to reduce an image from true colour down to 216 websafe colours. ; attempt to convert regular colours to websafe palette. Graphics 640,480,0,2 Dim matrix2(7,7) For y=0 To 7 For x=0 To 7 Read matrix2(x,y) Next Next Dim pal(215,2) For t=0 To 215 Read pal(t,0),pal(t,1),pal(t,2) Next picture = LoadImage("test.bmp") DrawImage picture,0,0 For x=0 To 255 For y=0 To 191 GetColor x,y r=ColorRed() g=ColorGreen() b=ColorBlue() r=r+(matrix2(x Mod 8, y Mod 8)-32) g=g+(matrix2(x Mod 8, y Mod 8)-32) b=b+(matrix2(x Mod 8, y Mod 8)-32) If r>255 Then r=255 If g>255 Then g=255 If b>255 Then b=255 If r<0 Then r=0 If g<0 Then g=0 If b<0 Then b=0 col = ((b/43)*36) +((g/43)*6)+ (r/43) Color pal(col,0),pal(col,1),pal(col,2) Plot x,y+200 Next Next While Not KeyHit(1) Wend End ; dithering threashold Data 1,49,13,61,4,52,16,64 Data 33,17,45,29,36,20,48,32 Data 9,57,5,53,12,60,8,56 Data 41,25,37,21,44,28,40,24 Data 3,51,15,63,2,50,14,62 Data 35,16,47,31,34,18,46,30 Data 11,59,7,55,10,58,6,54 Data 43,27,39,23,42,26,38,22 ; WebSafe Palette (216 Colours) Data 0,0,0 Data 51,0,0 Data 102,0,0 Data 153,0,0 Data 204,0,0 Data 255,0,0 Data 0,51,0 Data 51,51,0 Data 102,51,0 Data 153,51,0 Data 204,51,0 Data 255,51,0 Data 0,102,0 Data 51,102,0 Data 102,102,0 Data 153,102,0 Data 204,102,0 Data 255,102,0 Data 0,153,0 Data 51,153,0 Data 102,153,0 Data 153,153,0 Data 204,153,0 Data 255,153,0 Data 0,204,0 Data 51,204,0 Data 102,204,0 Data 153,204,0 Data 204,204,0 Data 255,204,0 Data 0,255,0 Data 51,255,0 Data 102,255,0 Data 153,255,0 Data 204,255,0 Data 255,255,0 Data 0,0,51 Data 51,0,51 Data 102,0,51 Data 153,0,51 Data 204,0,51 Data 255,0,51 Data 0,51,51 Data 51,51,51 Data 102,51,51 Data 153,51,51 Data 204,51,51 Data 255,51,51 Data 0,102,51 Data 51,102,51 Data 102,102,51 Data 153,102,51 Data 204,102,51 Data 255,102,51 Data 0,153,51 Data 51,153,51 Data 102,153,51 Data 153,153,51 Data 204,153,51 Data 255,153,51 Data 0,204,51 Data 51,204,51 Data 102,204,51 Data 153,204,51 Data 204,204,51 Data 255,204,51 Data 0,255,51 Data 51,255,51 Data 102,255,51 Data 153,255,51 Data 204,255,51 Data 255,255,51 Data 0,0,102 Data 51,0,102 Data 102,0,102 Data 153,0,102 Data 204,0,102 Data 255,0,102 Data 0,51,102 Data 51,51,102 Data 102,51,102 Data 153,51,102 Data 204,51,102 Data 255,51,102 Data 0,102,102 Data 51,102,102 Data 102,102,102 Data 153,102,102 Data 204,102,102 Data 255,102,102 Data 0,153,102 Data 51,153,102 Data 102,153,102 Data 153,153,102 Data 204,153,102 Data 255,153,102 Data 0,204,102 Data 51,204,102 Data 102,204,102 Data 153,204,102 Data 204,204,102 Data 255,204,102 Data 0,255,102 Data 51,255,102 Data 102,255,102 Data 153,255,102 Data 204,255,102 Data 255,255,102 Data 0,0,153 Data 51,0,153 Data 102,0,153 Data 153,0,153 Data 204,0,153 Data 255,0,153 Data 0,51,153 Data 51,51,153 Data 102,51,153 Data 153,51,153 Data 204,51,153 Data 255,51,153 Data 0,102,153 Data 51,102,153 Data 102,102,153 Data 153,102,153 Data 204,102,153 Data 255,102,153 Data 0,153,153 Data 51,153,153 Data 102,153,153 Data 153,153,153 Data 204,153,153 Data 255,153,153 Data 0,204,153 Data 51,204,153 Data 102,204,153 Data 153,204,153 Data 204,204,153 Data 255,204,153 Data 0,255,153 Data 51,255,153 Data 102,255,153 Data 153,255,153 Data 204,255,153 Data 255,255,153 Data 0,0,204 Data 51,0,204 Data 102,0,204 Data 153,0,204 Data 204,0,204 Data 255,0,204 Data 0,51,204 Data 51,51,204 Data 102,51,204 Data 153,51,204 Data 204,51,204 Data 255,51,204 Data 0,102,204 Data 51,102,204 Data 102,102,204 Data 153,102,204 Data 204,102,204 Data 255,102,204 Data 0,153,204 Data 51,153,204 Data 102,153,204 Data 153,153,204 Data 204,153,204 Data 255,153,204 Data 0,204,204 Data 51,204,204 Data 102,204,204 Data 153,204,204 Data 204,204,204 Data 255,204,204 Data 0,255,204 Data 51,255,204 Data 102,255,204 Data 153,255,204 Data 204,255,204 Data 255,255,204 Data 0,0,255 Data 51,0,255 Data 102,0,255 Data 153,0,255 Data 204,0,255 Data 255,0,255 Data 0,51,255 Data 51,51,255 Data 102,51,255 Data 153,51,255 Data 204,51,255 Data 255,51,255 Data 0,102,255 Data 51,102,255 Data 102,102,255 Data 153,102,255 Data 204,102,255 Data 255,102,255 Data 0,153,255 Data 51,153,255 Data 102,153,255 Data 153,153,255 Data 204,153,255 Data 255,153,255 Data 0,204,255 Data 51,204,255 Data 102,204,255 Data 153,204,255 Data 204,204,255 Data 255,204,255 Data 0,255,255 Data 51,255,255 Data 102,255,255 Data 153,255,255 Data 204,255,255 Data 255,255,255 --v -=-=- Check out my excellent homepage! Posted : Monday, 27 July 2009, 05:18 Jayenkai Neat  Posted : Monday, 27 July 2009, 06:30 Phoenix Why would you want to use the websafe palette? Is IE6 being the bottleneck once again? YouTube is phasing out support for that browser, so I think it's fairly safe for everyone to do that by now. Posted : Monday, 27 July 2009, 07:18 spinal It's for a DS project, I'm struggling with one of the graphic modes, so I'm using 8bit instead. However, I need to keep a few palette entries spare for a different part of the display and the websafe palette was the first thing that popped into my head for using less than 256 colours. ...I think the output from the code is quite good considering i'm not searching the palette for the best match colour. -=-=- Check out my excellent homepage! Posted : Friday, 20 November 2009, 08:43 spinal - Update - I just attempted to do some floyd Stienberg dithering to the same websafe palette. The results came out quite good I think. All I really did was to BASICify some of the source from ownloadcode/Floyd-Steinberg_dithering_©" target="_blank">https://en.literateprograms.org/Special ownloadcode/Floyd-Steinberg_dithering_© I didn't expect it to work first time  Graphics 640,480,0,2 Dim pal(215,2) For t=0 To 215 Read pal(t,0),pal(t,1),pal(t,2) Next Dim bitmap(256,192,2) ;R,G,B for each pixel in the image picture = LoadImage("test.bmp") ResizeImage picture, 256,192 DrawImage picture,0,0 For x=0 To 255 For y=0 To 191 GetColor x,y bitmap(x,y,0)=ColorRed() bitmap(x,y,1)=ColorGreen() bitmap(x,y,2)=ColorBlue() Next Next For x=0 To 255 For y=0 To 191 col = ((bitmap(x,y,2)/43)*36) +((bitmap(x,y,1)/43)*6)+ (bitmap(x,y,0)/43) Color pal(col,0),pal(col,1),pal(col,2) Plot x,y+200 compute_disperse(x, y, 0, col) compute_disperse(x, y, 1, col) compute_disperse(x, y, 2, col) Next Next While Not KeyHit(1) Wend End Function plus_truncate(a, b) number = a+b If number <0 Then number =0 If number >255 Then number =255 Return number End Function Function compute_disperse(x, y, channel, index) err = bitmap(x, y, channel) - pal(index, channel) If x+1 < 256 Then ; 256 = image width bitmap(x+1, y, channel) = plus_truncate(bitmap(x+1, y, channel), (err*7)/8) End If If y+1 < 192 Then If x-1 > 0 Then bitmap(x-1, y+1, channel) = plus_truncate(bitmap(x-1, y+1, channel), (err*3)/8) End If bitmap(x, y+1, channel) = plus_truncate(bitmap(x, y+1, channel), (err*5)/8) If x+1 < 256 Then ; 256 = image width bitmap(x+1, y+1, channel) = plus_truncate(bitmap(x+1, y+1, channel), err/8) End If End If End Function ; WebSafe Palette (216 Colours) Data 0,0,0 Data 51,0,0 Data 102,0,0 Data 153,0,0 Data 204,0,0 Data 255,0,0 Data 0,51,0 Data 51,51,0 Data 102,51,0 Data 153,51,0 Data 204,51,0 Data 255,51,0 Data 0,102,0 Data 51,102,0 Data 102,102,0 Data 153,102,0 Data 204,102,0 Data 255,102,0 Data 0,153,0 Data 51,153,0 Data 102,153,0 Data 153,153,0 Data 204,153,0 Data 255,153,0 Data 0,204,0 Data 51,204,0 Data 102,204,0 Data 153,204,0 Data 204,204,0 Data 255,204,0 Data 0,255,0 Data 51,255,0 Data 102,255,0 Data 153,255,0 Data 204,255,0 Data 255,255,0 Data 0,0,51 Data 51,0,51 Data 102,0,51 Data 153,0,51 Data 204,0,51 Data 255,0,51 Data 0,51,51 Data 51,51,51 Data 102,51,51 Data 153,51,51 Data 204,51,51 Data 255,51,51 Data 0,102,51 Data 51,102,51 Data 102,102,51 Data 153,102,51 Data 204,102,51 Data 255,102,51 Data 0,153,51 Data 51,153,51 Data 102,153,51 Data 153,153,51 Data 204,153,51 Data 255,153,51 Data 0,204,51 Data 51,204,51 Data 102,204,51 Data 153,204,51 Data 204,204,51 Data 255,204,51 Data 0,255,51 Data 51,255,51 Data 102,255,51 Data 153,255,51 Data 204,255,51 Data 255,255,51 Data 0,0,102 Data 51,0,102 Data 102,0,102 Data 153,0,102 Data 204,0,102 Data 255,0,102 Data 0,51,102 Data 51,51,102 Data 102,51,102 Data 153,51,102 Data 204,51,102 Data 255,51,102 Data 0,102,102 Data 51,102,102 Data 102,102,102 Data 153,102,102 Data 204,102,102 Data 255,102,102 Data 0,153,102 Data 51,153,102 Data 102,153,102 Data 153,153,102 Data 204,153,102 Data 255,153,102 Data 0,204,102 Data 51,204,102 Data 102,204,102 Data 153,204,102 Data 204,204,102 Data 255,204,102 Data 0,255,102 Data 51,255,102 Data 102,255,102 Data 153,255,102 Data 204,255,102 Data 255,255,102 Data 0,0,153 Data 51,0,153 Data 102,0,153 Data 153,0,153 Data 204,0,153 Data 255,0,153 Data 0,51,153 Data 51,51,153 Data 102,51,153 Data 153,51,153 Data 204,51,153 Data 255,51,153 Data 0,102,153 Data 51,102,153 Data 102,102,153 Data 153,102,153 Data 204,102,153 Data 255,102,153 Data 0,153,153 Data 51,153,153 Data 102,153,153 Data 153,153,153 Data 204,153,153 Data 255,153,153 Data 0,204,153 Data 51,204,153 Data 102,204,153 Data 153,204,153 Data 204,204,153 Data 255,204,153 Data 0,255,153 Data 51,255,153 Data 102,255,153 Data 153,255,153 Data 204,255,153 Data 255,255,153 Data 0,0,204 Data 51,0,204 Data 102,0,204 Data 153,0,204 Data 204,0,204 Data 255,0,204 Data 0,51,204 Data 51,51,204 Data 102,51,204 Data 153,51,204 Data 204,51,204 Data 255,51,204 Data 0,102,204 Data 51,102,204 Data 102,102,204 Data 153,102,204 Data 204,102,204 Data 255,102,204 Data 0,153,204 Data 51,153,204 Data 102,153,204 Data 153,153,204 Data 204,153,204 Data 255,153,204 Data 0,204,204 Data 51,204,204 Data 102,204,204 Data 153,204,204 Data 204,204,204 Data 255,204,204 Data 0,255,204 Data 51,255,204 Data 102,255,204 Data 153,255,204 Data 204,255,204 Data 255,255,204 Data 0,0,255 Data 51,0,255 Data 102,0,255 Data 153,0,255 Data 204,0,255 Data 255,0,255 Data 0,51,255 Data 51,51,255 Data 102,51,255 Data 153,51,255 Data 204,51,255 Data 255,51,255 Data 0,102,255 Data 51,102,255 Data 102,102,255 Data 153,102,255 Data 204,102,255 Data 255,102,255 Data 0,153,255 Data 51,153,255 Data 102,153,255 Data 153,153,255 Data 204,153,255 Data 255,153,255 Data 0,204,255 Data 51,204,255 Data 102,204,255 Data 153,204,255 Data 204,204,255 Data 255,204,255 Data 0,255,255 Data 51,255,255 Data 102,255,255 Data 153,255,255 Data 204,255,255 Data 255,255,255 --v -=-=- Check out my excellent homepage! Posted : Friday, 20 November 2009, 09:01 HoboBen Nice - I think you did a better job than Paint Shop Pro's dithering, too -=-=- blog | work | code | more code Posted : Saturday, 21 November 2009, 17:54 CodersRule Yeah looks nice, just looks like you took the image and added a texture to it  Posted : Sunday, 22 November 2009, 02:07 spinal It looks a bit speckly to me, perhaps later I will try some sort of custom palette, maybe use only the 256 most used colours or something. -=-=- Check out my excellent homepage! Posted : Monday, 30 November 2009, 14:57 spinal OK, here's a bash at using 256 most used colours from the image. ; attempt to convert 16bit colour to 8bit Graphics 640,480,0,2 Dim pal(256,2) Dim bitmap(256,192,2) ;R,G,B for each pixel in the image Dim colorList(16777216) ; for counting colours Dim colorValue(16777216) ; for the actual colours picture = LoadImage("test.bmp") ResizeImage picture, 256,192 DrawBlock picture,0,0 For x=0 To 255 For y=0 To 191 GetColor x,y r=ColorRed() g=ColorGreen() b=ColorBlue() bitmap(x,y,0)=r bitmap(x,y,1)=g bitmap(x,y,2)=b r=(r/8)*8 g=(g/8)*8 b=(b/8)*8 colorList( (r Shl 16)+ (g Shl 8)+ b) = colorList( (r Shl 16)+ (g Shl 8)+ b) + 1 Next Next For t = 1 To 16777216 colorValue(t) =t Next Color 255,255,255 Print "Sorting..." quicksort(0,16777215) ; as the sorted sorts smallest to largest, we use the LAST 256 colours For t=0 To 255 pal(t,0) = (colorValue(16777215-t) Shr 16) And 255 pal(t,1) = (colorValue(16777215-t) Shr 8) And 255 pal(t,2) = ColorValue(16777215-t) And 255 Color pal(t,0), pal(t,1), pal(t,2) Rect t*2,0,2,2,1 Next p=0 For t = 1 To 16777216 If colorList(t) >0 Then p=p+1 Next Color 255,255,255 Print p + " colors used" For x=0 To 255 For y=0 To 191 ; col = ((bitmap(x,y,2)/43)*36) +((bitmap(x,y,1)/43)*6)+ (bitmap(x,y,0)/43) col = FindNearestColour(bitmap(x,y,0),bitmap(x,y,1),bitmap(x,y,2)) Color pal(col,0),pal(col,1),pal(col,2) Plot x,y+200 ; compute_disperse(x, y, 0, col) ; compute_disperse(x, y, 1, col) ; compute_disperse(x, y, 2, col) Next Next For t = 1 To 16777216 colorList(t) =0 Next For x=0 To 255 For y=0 To 191 GetColor x,y + 200 r=ColorRed() g=ColorGreen() b=ColorBlue() bitmap(x,y,0)=r bitmap(x,y,1)=g bitmap(x,y,2)=b r=(r/8)*8 g=(g/8)*8 b=(b/8)*8 colorList( (r Shl 16)+ (g Shl 8)+ b) = colorList( (r Shl 16)+ (g Shl 8)+ b) + 1 Next Next p=0 For t = 1 To 16777216 If colorList(t) >0 Then p=p+1 Next Color 255,255,255 Print p + " colors used" Print "Done!" While Not KeyHit(1) Wend End ;We will actually search through the colours. It is much slower, but far more accurate. Function FindNearestColour(r,g,b) minDistanceSquared = 255*255 + 255*255 + 255*255 + 1 ; furthes possible colour difference For i = 0 To 215 ; 215 colours in websafe palette rdiff = r - pal(i,0) gdiff = g - pal(i,1) bdiff = b - pal(i,2) DistanceSquared = rdiff*rdiff + gdiff*gdiff + bdiff*bdiff If DistanceSquared < minDistanceSquared Then minDistanceSquared = DistanceSquared bestIndex = i End If Next Return bestIndex End Function Function plus_truncate(a, b) number = a+b If number <0 Then number =0 If number >255 Then number =255 Return number End Function Function compute_disperse(x, y, channel, index) err = bitmap(x, y, channel) - pal(index, channel) If x+1 < 256 Then ; 256 = image width bitmap(x+1, y, channel) = plus_truncate(bitmap(x+1, y, channel), (err*7)/8) End If If y+1 < 192 Then If x-1 > 0 Then bitmap(x-1, y+1, channel) = plus_truncate(bitmap(x-1, y+1, channel), (err*3)/8) End If bitmap(x, y+1, channel) = plus_truncate(bitmap(x, y+1, channel), (err*5)/8) If x+1 < 256 Then ; 256 = image width bitmap(x+1, y+1, channel) = plus_truncate(bitmap(x+1, y+1, channel), err/8) End If End If End Function Function quicksort(l,r) Local p,q,h p=l q=r x=colorList((l+r)/2) Repeat While colorList(p)q Then Exit ;SWAP------------------ h=colorList(q) colorList(q)=colorList(p) colorList(p)=h h=colorValue(q) colorValue(q)=colorValue(p) colorValue(p)=h ;---------------------- p=p+1 q=q-1 If q<0 Then Exit Forever If l0 Then colorList(t) =0 ; reset the colours p=p+1 End If Next totalcolours = p Color 255,255,255 Print " "+ totalcolours + " colors" For x=0 To 255 For y=0 To 191 GetColor x,y r=ColorRed() g=ColorGreen() b=ColorBlue() bitmap(x,y,0)=r bitmap(x,y,1)=g bitmap(x,y,2)=b ;PSP uses only 5bits per channel, so thats what i'll do r=r/8*8 g=g/8*8 b=b/8*8 colorList( (r Shl 16)+ (g Shl 8)+ b) = colorList( (r Shl 16)+ (g Shl 8)+ b) + 1 Next Next Color 255,255,255 Print " Sorting palette" quicksort(0,16777215) p=0 offset = -1 For t = 1 To 16777215 If colorList(t) >0 Then If offset=-1 Then offset = t p=p+1 End If Next ;quicksort2(offset,16777215) x = p/248 For t = 0 To 255 Step 50 pal(t/50,0) = t pal(t/50,1) = t pal(t/50,2) = t Next pal(6,0) = 255 : pal(6,1) = 255 : pal(6,2) = 255 pal(7,0) = 255 : pal(7,1) = 0 : pal(7,2) = 255 For t = 0 To 248 s = offset + (x*t) pal(t+8,0) = (colorValue(s) Shr 16) And 255 pal(t+8,1) = (colorValue(s) Shr 8) And 255 pal(t+8,2) = ColorValue(s) And 255 Next ; sort the palette a little, make it look nice, not actually needed though For x=0 To 255 For y=0 To 255 br = (pal(y,0)+ pal(y,0)+ pal(y,1)+ pal(y,1)+ pal(y,1)+ pal(y,2))/6 br1 = (pal(y+1,0)+pal(y+1,0)+pal(y+1,1)+pal(y+1,1)+pal(y+1,1)+pal(y+1,2))/6 If br < br1 Then temp0 = pal(y+1,0) temp1 = pal(y+1,1) temp2 = pal(y+1,2) pal(y+1,0) = pal(y,0) pal(y+1,1) = pal(y,1) pal(y+1,2) = pal(y,2) pal(y,0) = temp0 pal(y,1) = temp1 pal(y,2) = temp2 End If Next Next Color 128,128,128 Rect 264,62,129,129,1 t=0 For y = 0 To 15 For x = 0 To 15 Color pal(t,0), pal(t,1), pal(t,2) Rect 265 + (x*8), 63 + (y*8),7,7,1 t=t+1 Next Next For x=0 To 255 For y=0 To 191 ; col = ((bitmap(x,y,2)/43)*36) +((bitmap(x,y,1)/43)*6)+ (bitmap(x,y,0)/43) ; for websafe palette col = FindNearestColour(bitmap(x,y,0),bitmap(x,y,1),bitmap(x,y,2)) Color pal(col,0),pal(col,1),pal(col,2) Plot x+401,y compute_disperse2(x, y, 0, col) compute_disperse2(x, y, 1, col) compute_disperse2(x, y, 2, col) Next Next Color 255,255,255 Print " Done!" While Not KeyHit(1) Delay 2 Wend End ;We will actually search through the colours. It is much slower, but far more accurate. Function FindNearestColour(r,g,b) minDistanceSquared = 255*255 + 255*255 + 255*255 + 1 ; furthes possible colour difference For i = 0 To 255 ; 215 colours in websafe palette rdiff = r - pal(i,0) gdiff = g - pal(i,1) bdiff = b - pal(i,2) DistanceSquared = rdiff*rdiff + gdiff*gdiff + bdiff*bdiff If DistanceSquared < minDistanceSquared Then minDistanceSquared = DistanceSquared bestIndex = i End If Next Return bestIndex End Function Function plus_truncate(a, b) number = a+b If number <0 Then number =0 If number >255 Then number =255 Return number End Function Function compute_disperse(x, y, channel, index) err = bitmap(x, y, channel) - pal(index, channel) If x+1 < 256 Then ; 256 = image width bitmap(x+1, y, channel) = plus_truncate(bitmap(x+1, y, channel), (err*7)/16) End If If y+1 < 192 Then If x-1 > 0 Then bitmap(x-1, y+1, channel) = plus_truncate(bitmap(x-1, y+1, channel), (err*3)/16) End If bitmap(x, y+1, channel) = plus_truncate(bitmap(x, y+1, channel), (err*5)/16) If x+1 < 256 Then ; 256 = image width bitmap(x+1, y+1, channel) = plus_truncate(bitmap(x+1, y+1, channel), err/16) End If End If End Function Function compute_disperse2(x, y, channel, index) err = bitmap(x, y, channel) - pal(index, channel) If x+1 < 256 Then ; 256 = image width bitmap(x+1, y, channel) = plus_truncate(bitmap(x+1, y, channel), (err*7)/16) End If If y+1 < 192 Then If x-2 > 0 Then bitmap(x-2, y+1, channel) = plus_truncate(bitmap(x-2, y+1, channel), err/16) End If bitmap(x, y+1, channel) = plus_truncate(bitmap(x, y+1, channel), (err*5)/16) If x+1 < 256 Then ; 256 = image width bitmap(x-1, y+1, channel) = plus_truncate(bitmap(x-1, y+1, channel), (err*3)/16) End If End If End Function Function quicksort(l,r) Local p,q,h p=l q=r x=colorList((l+r)/2) Repeat While colorList(p)q Then Exit ;SWAP------------------ h=colorList(q) colorList(q)=colorList(p) colorList(p)=h h=colorValue(q) colorValue(q)=colorValue(p) colorValue(p)=h ;---------------------- p=p+1 q=q-1 If q<0 Then Exit Forever If lq Then Exit ;SWAP------------------ h=colorList(q) colorList(q)=colorList(p) colorList(p)=h h=colorValue(q) colorValue(q)=colorValue(p) colorValue(p)=h ;---------------------- p=p+1 q=q-1 If q<0 Then Exit Forever If l0 Then If offset=-1 Then offset = t p=p+1 End If Next ; I forced some colours here, I want to make sure there are some greys ; in each palette, it helps the output, also, magenta because I need it sometimes. pal(0,0) = 0 : pal(0,1) = 0 : pal(0,2) = 0 pal(1,0) = 42 : pal(1,1) = 42 : pal(1,2) = 42 pal(2,0) = 85 : pal(2,1) = 85 : pal(2,2) = 85 pal(3,0) = 127 : pal(3,1) = 127 : pal(3,2) = 127 pal(4,0) = 170 : pal(4,1) = 170 : pal(4,2) = 170 pal(5,0) = 213 : pal(5,1) = 213 : pal(5,2) = 213 pal(6,0) = 255 : pal(6,1) = 255 : pal(6,2) = 255 pal(7,0) = 255 : pal(7,1) = 0 : pal(7,2) = 255 If p > 248 Then useDither = 1 x = p/248 For t = 0 To 248 s = offset + (x*t) pal(t+8,0) = ((colorValue(s) Shr 10) And 31)*8 pal(t+8,1) = ((colorValue(s) Shr 5) And 31)*8 pal(t+8,2) = (ColorValue(s) And 31)*8 Next Else useDither = 0 For t = 0 To p s = offset +t pal(t+8,0) = ((colorValue(s) Shr 10) And 31)*8 pal(t+8,1) = ((colorValue(s) Shr 5) And 31)*8 pal(t+8,2) = (ColorValue(s) And 31)*8 Next End If ; sort the palette a little, make it look nice, not actually needed though ; simple bubble sort will do Repeat x=0 For y=0 To 254 br = (pal(y,0)+ pal(y,0)+ pal(y,1)+ pal(y,1)+ pal(y,1)+ pal(y,2))/6 br1 = (pal(y+1,0)+pal(y+1,0)+pal(y+1,1)+pal(y+1,1)+pal(y+1,1)+pal(y+1,2))/6 If br < br1 Then temp0 = pal(y+1,0) temp1 = pal(y+1,1) temp2 = pal(y+1,2) pal(y+1,0) = pal(y,0) pal(y+1,1) = pal(y,1) pal(y+1,2) = pal(y,2) pal(y,0) = temp0 pal(y,1) = temp1 pal(y,2) = temp2 x=1 End If Next Until x=0 SetBuffer FrontBuffer() Color 128,128,128 Rect pwidth + 7,62,129,129,1 t=0 For y = 0 To 15 For x = 0 To 15 Color pal(t,0), pal(t,1), pal(t,2) Rect pwidth + 8 + (x*8), 63 + (y*8),7,7,1 t=t+1 Next Next For x=0 To pwidth For y=0 To pheight col = FindNearestColour(bitmap(x,y,0),bitmap(x,y,1),bitmap(x,y,2)) Color pal(col,0),pal(col,1),pal(col,2) Plot x,y + pheight + 8 If useDither = 1 Then Select style Case 1 compute_disperse(x, y, 0, col) compute_disperse(x, y, 1, col) compute_disperse(x, y, 2, col) Case 2 compute_disperse2(x, y, 0, col) compute_disperse2(x, y, 1, col) compute_disperse2(x, y, 2, col) Case 3 compute_disperse3(x, y, 0, col) compute_disperse3(x, y, 1, col) compute_disperse3(x, y, 2, col) Case 4 compute_disperse4(x, y, 0, col) compute_disperse4(x, y, 1, col) compute_disperse4(x, y, 2, col) End Select End If Next Next While Not KeyHit(1) Delay 2 Wend End Function FindNearestColour(r,g,b) minDistanceSquared = 255*255 + 255*255 + 255*255 + 1 ; furthes possible colour difference For i = 0 To 255 rdiff = r - pal(i,0) gdiff = g - pal(i,1) bdiff = b - pal(i,2) DistanceSquared = rdiff*rdiff + gdiff*gdiff + bdiff*bdiff If DistanceSquared < minDistanceSquared Then minDistanceSquared = DistanceSquared bestIndex = i End If Next Return bestIndex End Function Function quicksort(l,r) Local p,q,h p=l q=r x=colorList((l+r)/2) Repeat While colorList(p)q Then Exit ;SWAP------------------ h=colorList(q) colorList(q)=colorList(p) colorList(p)=h h=colorValue(q) colorValue(q)=colorValue(p) colorValue(p)=h ;---------------------- p=p+1 q=q-1 If q<0 Then Exit Forever If l255 Then number =255 Return number End Function Function compute_disperse(x, y, channel, index) ;Floyd Steinberg ; * 7 ; 3 5 1 (1/16) err = bitmap(x, y, channel) - pal(index, channel) If x+1 < pwidth Then bitmap(x+1, y, channel) = plus_truncate(bitmap(x+1, y, channel), (err*7)/16) End If If y+1 < pheight Then If x-1 > 0 Then bitmap(x-1, y+1, channel) = plus_truncate(bitmap(x-1, y+1, channel), (err*3)/16) End If bitmap(x, y+1, channel) = plus_truncate(bitmap(x, y+1, channel), (err*5)/16) If x+1 < pwidth Then bitmap(x+1, y+1, channel) = plus_truncate(bitmap(x+1, y+1, channel), err/16) End If End If End Function Function compute_disperse2(x, y, channel, index) ;Stucki ; * 8 4 ; 2 4 8 4 2 ; 1 2 4 2 1 (1/42) err = bitmap(x, y, channel) - pal(index, channel) If x+1 < pwidth Then bitmap(x+1, y, channel) = plus_truncate(bitmap(x+1, y, channel), (err*8)/42) If x+2 < pwidth Then bitmap(x+2, y, channel) = plus_truncate(bitmap(x+2, y, channel), (err*4)/42) If y+1 < pheight Then If x-2 > 0 Then bitmap(x-2, y+1, channel) = plus_truncate(bitmap(x-2, y+1, channel), (err*2)/42) If x-1 > 0 Then bitmap(x-1, y+1, channel) = plus_truncate(bitmap(x-1, y+1, channel), (err*4)/42) bitmap(x, y+1, channel) = plus_truncate(bitmap(x, y+1, channel), (err*8)/42) If x+1 < pwidth Then bitmap(x+1, y+1, channel) = plus_truncate(bitmap(x+1, y+1, channel), (err*4)/42) If x+2 < pwidth Then bitmap(x+2, y+1, channel) = plus_truncate(bitmap(x+2, y+1, channel), (err*2)/42) End If If y+2 < pheight Then If x-2 > 0 Then bitmap(x-2, y+2, channel) = plus_truncate(bitmap(x-2, y+2, channel), (err*1)/42) If x-1 > 0 Then bitmap(x-1, y+2, channel) = plus_truncate(bitmap(x-1, y+2, channel), (err*2)/42) bitmap(x, y+2, channel) = plus_truncate(bitmap(x, y+2, channel), (err*4)/42) If x+1 < pwidth Then bitmap(x+1, y+2, channel) = plus_truncate(bitmap(x+1, y+2, channel), (err*2)/42) If x+2 < pwidth Then bitmap(x+2, y+2, channel) = plus_truncate(bitmap(x+2, y+2, channel), (err*1)/42) End If End Function Function compute_disperse3(x, y, channel, index) ;Burkes ; * 8 4 ; 2 4 8 4 2 (1/32) err = bitmap(x, y, channel) - pal(index, channel) If x+1 < pwidth Then bitmap(x+1, y, channel) = plus_truncate(bitmap(x+1, y, channel), (err*8)/32) If x+2 < pwidth Then bitmap(x+2, y, channel) = plus_truncate(bitmap(x+2, y, channel), (err*4)/32) If y+1 < pheight Then If x-2 > 0 Then bitmap(x-2, y+1, channel) = plus_truncate(bitmap(x-2, y+1, channel), (err*2)/32) If x-1 > 0 Then bitmap(x-1, y+1, channel) = plus_truncate(bitmap(x-1, y+1, channel), (err*4)/32) bitmap(x, y+1, channel) = plus_truncate(bitmap(x, y+1, channel), (err*8)/32) If x+1 < pwidth Then bitmap(x+1, y+1, channel) = plus_truncate(bitmap(x+1, y+1, channel), (err*4)/32) If x+2 < pwidth Then bitmap(x+2, y+1, channel) = plus_truncate(bitmap(x+2, y+1, channel), (err*2)/32) End If End Function Function compute_disperse4(x, y, channel, index) ;Sierra - Filter Lite ; * 2 ; 1 1 (1/4) err = bitmap(x, y, channel) - pal(index, channel) If x+1 < pwidth Then bitmap(x+1, y, channel) = plus_truncate(bitmap(x+1, y, channel), (err*2)/4) If y+1 < pheight Then If x-1 > 0 Then bitmap(x-1, y+1, channel) = plus_truncate(bitmap(x-1, y+1, channel), err/4) bitmap(x, y+1, channel) = plus_truncate(bitmap(x, y+1, channel), err/4) End If End Function --v -=-=- Check out my excellent homepage! Posted : Wednesday, 09 December 2009, 14:06 JL235 They look awesome. At first I was confused because I couldn't tell if the ones on the right were meant to be the 256 colour versions or the originals. At a glance some of those really do look the same. One small point, some of pallettes seem to contain a bright pink colour even though it's not used in the picture. Is that a bug? Posted : Wednesday, 09 December 2009, 14:39 Afr0 Diablos: That's probably the default masking colour. -=-=- Afr0 Games Project Dollhouse on Github - Please fork! Posted : Wednesday, 09 December 2009, 14:47 spinal I forced a few grey values and bright pink (255,0,255) into the palette, I need it for a project i'm working on, it doesn't hurt the image at all. -=-=- Check out my excellent homepage! Posted : Monday, 08 August 2011, 05:06 Jayenkai Super useful for rerendering iOS backgrounds for DS Thanks again, Spinal! -=-=- ''Load, Next List!'' Posted : Monday, 08 August 2011, 10:25 CodersRule Forgot about this thread. It really is quite spify. Posted : Monday, 08 August 2011, 13:37 spinal woohoo! Two yeas later and still working  Posted : Tuesday, 09 August 2011, 12:30 rockford Has it really been two years! Time flies. Posted : Tuesday, 09 August 2011, 12:59 Jayenkai lol, same thought from me the other day.. "oh, yeah, Spinal made something for that a few months ago... *searches*... How long!!!!?!!" -=-=- ''Load, Next List!'' Posted : Wednesday, 10 August 2011, 05:59 spinal I never would have predicted how well the colour reduction would have worked though, it does indeed seem to be better than some commercial software -=-=- Check out my excellent homepage! Page : 1 2 Next Prev