Page 1 of 2

CGA

Posted: Thu Feb 21, 2013 2:53 am
by J. Baker

Code: Select all

Procedure CGA(color)
  
  DivideR.i = Red(color)
  DivideG.i = Green(color)
  DivideB.i = Blue(color)
  
      If DivideR.i > 0 And DivideR.i < 128 And DivideG.i > 0 And DivideG.i < 128 And DivideB.i > 0 And DivideB.i < 128
          DivideR.i = DivideR.i * 1.33
          DivideG.i = DivideG.i * 1.33
          DivideB.i = DivideB.i * 1.33
      EndIf
      
      If DivideR.i >= 170
        cgaR = 255
      ElseIf DivideR.i > 127 And DivideB.i < 170 Or DivideG.i < 170
        cgaR = 170
      Else
        If DivideG.i >= 170 Or DivideB.i >= 170
          cgaR = 85
        Else
          cgaR = 0
        EndIf
      EndIf
      
      If DivideG.i >= 170
        cgaG = 255
      ElseIf DivideG.i > 127 And DivideR.i < 170 Or DivideB.i < 170
       cgaG = 170
      Else
        If DivideR.i >= 170 Or DivideB.i >= 170
          cgaG = 85
        Else
          cgaG = 0
        EndIf
      EndIf
      
      If DivideB.i >= 170
        cgaB = 255
      ElseIf DivideB.i > 127 And DivideR.i < 170 Or DivideG.i < 170
       cgaB = 170
      Else
        If DivideR.i >= 170 Or DivideG.i >= 170
          cgaB = 85
        Else
          cgaB = 0
        EndIf
      EndIf     
      
  If cgaR = 170 And cgaG = 170 And cgaB = 0
     cgaG = 85
  EndIf
  
  ProcedureReturn RGB(cgaR, cgaG, cgaB)
  
EndProcedure

UseJPEGImageDecoder()
UsePNGImageDecoder()
UsePNGImageEncoder()

FileName$ = GetHomeDirectory() + "Desktop/image.png"

LoadImage(0, FileName$)

;ResizeImage(0, 320, 200)

  StartDrawing(ImageOutput(0))
   DrawingMode(#PB_2DDrawing_Default)
    For x = 0 To ImageWidth(0) - 1
      For y = 0 To ImageHeight(0) - 1
        c = Point(x, y)
          Plot(x, y , CGA(c))
      Next y
    Next x

SaveImage(0, FileName$ + "_cga.png", #PB_ImagePlugin_PNG, 0, 24)

FreeImage(0)

End

Re: CGA

Posted: Thu Feb 21, 2013 8:07 am
by dige
What is CGA? Looks like a posterize effect...

Re: CGA

Posted: Thu Feb 21, 2013 8:09 am
by wilbert
dige wrote:What is CGA? Looks like a posterize effect...
It's a very old type of graphics card that had only 16 colors.
http://en.wikipedia.org/wiki/Color_Graphics_Adapter

Re: CGA

Posted: Thu Feb 21, 2013 8:13 am
by BasicallyPure
I like it.
I see that it can be made to work using only integers with almost identical results.

Code: Select all

Procedure CGA(color)
   
   DivideR.i = Red(color)
   DivideG.i = Green(color)
   DivideB.i = Blue(color)
   
   If DivideR > 170 Or DivideG > 170 Or DivideB > 170
      cgaR = DivideR / 128 * 255
      cgaG = DivideG / 128 * 255
      cgaB = DivideB / 128 * 255
      If cgaR = 0
         cgaR = 85
      EndIf
      If cgaG = 0
         cgaG = 85
      EndIf
      If cgaB = 0
         cgaB = 85
      EndIf
   Else
      If DivideR > 85 And DivideR <= 170
         cgaR = 170
      Else
         cgaR = 0
      EndIf
      If DivideG > 85 And DivideG <= 170
         cgaG = 170
      Else
         cgaG = 0
      EndIf
      If DivideB > 85 And DivideB <= 170
         cgaB = 170
      Else
         cgaB = 0
      EndIf
   EndIf
   
   If cgaR = 170 And cgaG = 170 And cgaB = 0
      cgaG = 85
   EndIf
   
   ProcedureReturn RGB(cgaR, cgaG, cgaB)
   
EndProcedure

;UseJPEGImageDecoder()
UsePNGImageDecoder()
UsePNGImageEncoder()

FileName$ = GetHomeDirectory() + "Desktop/image.png"

LoadImage(0, FileName$)

;ResizeImage(0, 320, 200)

xMax = ImageWidth(0) - 1
yMax = ImageHeight(0) - 1

StartDrawing(ImageOutput(0))
   DrawingMode(#PB_2DDrawing_Default)
   For x = 0 To xMax
      For y = 0 To yMax
         c = Point(x, y)
         Plot(x, y , CGA(c))
      Next y
   Next x
StopDrawing()

SaveImage(0, FileName$ + "_cga.png", #PB_ImagePlugin_PNG, 0, 4)

FreeImage(0)

End
BP

Re: CGA

Posted: Thu Feb 21, 2013 9:04 am
by J. Baker
It does work nice with integers. Thanks BasicallyPure! ;)

Re: CGA

Posted: Thu Feb 21, 2013 10:04 am
by wilbert
Sorry to tell you but the conversion is incorrect.
If the input value is $FF0000, the output value still is $FF0000 while this is not a valid CGA color.

Re: CGA

Posted: Thu Feb 21, 2013 10:44 am
by J. Baker
wilbert wrote:Sorry to tell you but the conversion is incorrect.
If the input value is $FF0000, the output value still is $FF0000 while this is not a valid CGA color.
Nice catch wilbert. I think I fixed it. Just updated the code. ;)

EDIT: I just changed the values that were 0.75 to 0.66 as that was incorrect too. :oops:

Re: CGA

Posted: Thu Feb 21, 2013 11:47 am
by wilbert
Did you consider using a lookup table or is speed not that important ?

Re: CGA

Posted: Thu Feb 21, 2013 12:23 pm
by J. Baker
wilbert wrote:Did you consider using a lookup table or is speed not that important ?
I like speed but accuracy come first.

Also, there's still something wrong with the code. A pixel on the original image has a very low red and blue value but a high green value. But for some reason, the converted image is brown. Where or when did the red value turn to a much higher one is beyond me.

Re: CGA

Posted: Thu Feb 21, 2013 6:49 pm
by wilbert
I tried a lookup table but I doubt if it is faster (might as well be slower).
I also don't know if I got the table exactly right.

Code: Select all

Procedure CGA(color)
  !mov eax, [p.v_color]
  !and eax, 0xe0e0e0; convert b8g8r8 > r3g3b3
  
  !mov edx, eax
  !shr edx, 21
  
  !movzx ecx, ah
  !ror ecx, 2
  
  !or edx, ecx
  
  !movzx ecx, al
  !rol ecx, 1
  
  !or edx, ecx
  
  ; lookup in table r8g8b8[r3g3b3]
  CompilerIf #PB_Compiler_Processor = #PB_Processor_x86
    !lea eax, [cga_table512rgb]
    !mov eax, [eax + edx * 4]
  CompilerElse
    !lea rax, [cga_table512rgb]
    !mov eax, [rax + rdx * 4]
  CompilerEndIf
  
  !bswap eax; convert r8g8b8 > b8g8r8
  !shr eax, 8
  ProcedureReturn
  !cga_table512rgb:
  !dd 0x000000,0x000000,0x000000,0x0000AA,0x0000AA,0x0000AA,0x0000AA,0x0000AA
  !dd 0x000000,0x000000,0x000000,0x0000AA,0x0000AA,0x0000AA,0x0000AA,0x0000AA
  !dd 0x000000,0x000000,0x555555,0x555555,0x0000AA,0x0000AA,0x0000AA,0x5555FF
  !dd 0x00AA00,0x00AA00,0x555555,0x00AAAA,0x00AAAA,0x00AAAA,0x00AAAA,0x5555FF
  !dd 0x00AA00,0x00AA00,0x00AA00,0x00AAAA,0x00AAAA,0x00AAAA,0x00AAAA,0x00AAAA
  !dd 0x00AA00,0x00AA00,0x00AA00,0x00AAAA,0x00AAAA,0x00AAAA,0x00AAAA,0x00AAAA
  !dd 0x00AA00,0x00AA00,0x00AA00,0x00AAAA,0x00AAAA,0x00AAAA,0x00AAAA,0x55FFFF
  !dd 0x00AA00,0x00AA00,0x55FF55,0x55FF55,0x00AAAA,0x00AAAA,0x55FFFF,0x55FFFF
  !dd 0x000000,0x000000,0x000000,0x0000AA,0x0000AA,0x0000AA,0x0000AA,0x0000AA
  !dd 0x000000,0x000000,0x555555,0x555555,0x0000AA,0x0000AA,0x0000AA,0x5555FF
  !dd 0x000000,0x555555,0x555555,0x555555,0x555555,0x0000AA,0x5555FF,0x5555FF
  !dd 0x00AA00,0x555555,0x555555,0x555555,0x00AAAA,0x00AAAA,0x5555FF,0x5555FF
  !dd 0x00AA00,0x00AA00,0x555555,0x00AAAA,0x00AAAA,0x00AAAA,0x00AAAA,0x5555FF
  !dd 0x00AA00,0x00AA00,0x00AA00,0x00AAAA,0x00AAAA,0x00AAAA,0x00AAAA,0x55FFFF
  !dd 0x00AA00,0x00AA00,0x55FF55,0x55FF55,0x00AAAA,0x00AAAA,0x55FFFF,0x55FFFF
  !dd 0x00AA00,0x55FF55,0x55FF55,0x55FF55,0x55FF55,0x55FFFF,0x55FFFF,0x55FFFF
  !dd 0x000000,0x000000,0x555555,0x555555,0x0000AA,0x0000AA,0x0000AA,0x5555FF
  !dd 0x000000,0x555555,0x555555,0x555555,0x555555,0x0000AA,0x5555FF,0x5555FF
  !dd 0x555555,0x555555,0x555555,0x555555,0x555555,0x5555FF,0x5555FF,0x5555FF
  !dd 0x555555,0x555555,0x555555,0x555555,0x555555,0x5555FF,0x5555FF,0x5555FF
  !dd 0x00AA00,0x555555,0x555555,0x555555,0x00AAAA,0x00AAAA,0x5555FF,0x5555FF
  !dd 0x00AA00,0x00AA00,0x55FF55,0x55FF55,0x00AAAA,0x00AAAA,0x55FFFF,0x55FFFF
  !dd 0x00AA00,0x55FF55,0x55FF55,0x55FF55,0x55FF55,0x55FFFF,0x55FFFF,0x55FFFF
  !dd 0x55FF55,0x55FF55,0x55FF55,0x55FF55,0x55FF55,0x55FFFF,0x55FFFF,0x55FFFF
  !dd 0xAA0000,0xAA0000,0x555555,0xAA00AA,0xAA00AA,0xAA00AA,0xAA00AA,0x5555FF
  !dd 0xAA0000,0x555555,0x555555,0x555555,0xAA00AA,0xAA00AA,0x5555FF,0x5555FF
  !dd 0xAA5500,0x555555,0x555555,0x555555,0x555555,0x5555FF,0x5555FF,0x5555FF
  !dd 0xAA5500,0x555555,0x555555,0x555555,0x555555,0x5555FF,0x5555FF,0x5555FF
  !dd 0xAA5500,0x555555,0x555555,0x555555,0xAAAAAA,0xAAAAAA,0x5555FF,0x5555FF
  !dd 0x00AA00,0x55FF55,0x55FF55,0x55FF55,0xAAAAAA,0xAAAAAA,0xAAAAAA,0x55FFFF
  !dd 0x55FF55,0x55FF55,0x55FF55,0x55FF55,0x55FF55,0xAAAAAA,0x55FFFF,0x55FFFF
  !dd 0x55FF55,0x55FF55,0x55FF55,0x55FF55,0x55FF55,0x55FFFF,0x55FFFF,0x55FFFF
  !dd 0xAA0000,0xAA0000,0xAA0000,0xAA00AA,0xAA00AA,0xAA00AA,0xAA00AA,0xAA00AA
  !dd 0xAA0000,0xAA0000,0x555555,0xAA00AA,0xAA00AA,0xAA00AA,0xAA00AA,0x5555FF
  !dd 0xAA5500,0xAA5500,0x555555,0x555555,0xAA00AA,0xAA00AA,0x5555FF,0x5555FF
  !dd 0xAA5500,0xAA5500,0x555555,0x555555,0xAAAAAA,0xAAAAAA,0x5555FF,0x5555FF
  !dd 0xAA5500,0xAA5500,0x555555,0xAAAAAA,0xAAAAAA,0xAAAAAA,0xAAAAAA,0x5555FF
  !dd 0xAA5500,0xAA5500,0x55FF55,0xAAAAAA,0xAAAAAA,0xAAAAAA,0xAAAAAA,0xAAAAAA
  !dd 0x55FF55,0x55FF55,0x55FF55,0x55FF55,0xAAAAAA,0xAAAAAA,0xAAAAAA,0x55FFFF
  !dd 0x55FF55,0x55FF55,0x55FF55,0x55FF55,0x55FF55,0xAAAAAA,0x55FFFF,0x55FFFF
  !dd 0xAA0000,0xAA0000,0xAA0000,0xAA00AA,0xAA00AA,0xAA00AA,0xAA00AA,0xAA00AA
  !dd 0xAA0000,0xAA0000,0xAA0000,0xAA00AA,0xAA00AA,0xAA00AA,0xAA00AA,0xFF55FF
  !dd 0xAA5500,0xAA5500,0xAA5500,0xFF5555,0xAA00AA,0xAA00AA,0xFF55FF,0xFF55FF
  !dd 0xAA5500,0xAA5500,0xAA5500,0xFF5555,0xAAAAAA,0xAAAAAA,0xAAAAAA,0xFF55FF
  !dd 0xAA5500,0xAA5500,0xAA5500,0xAAAAAA,0xAAAAAA,0xAAAAAA,0xAAAAAA,0xAAAAAA
  !dd 0xAA5500,0xAA5500,0xAAAAAA,0xAAAAAA,0xAAAAAA,0xAAAAAA,0xAAAAAA,0xAAAAAA
  !dd 0xFFFF55,0xFFFF55,0xFFFF55,0xAAAAAA,0xAAAAAA,0xAAAAAA,0xAAAAAA,0xFFFFFF
  !dd 0xFFFF55,0xFFFF55,0xFFFF55,0xFFFF55,0xAAAAAA,0xAAAAAA,0xFFFFFF,0xFFFFFF
  !dd 0xAA0000,0xAA0000,0xAA0000,0xAA00AA,0xAA00AA,0xAA00AA,0xAA00AA,0xFF55FF
  !dd 0xAA0000,0xAA0000,0xFF5555,0xFF5555,0xAA00AA,0xAA00AA,0xFF55FF,0xFF55FF
  !dd 0xAA5500,0xFF5555,0xFF5555,0xFF5555,0xFF5555,0xFF55FF,0xFF55FF,0xFF55FF
  !dd 0xAA5500,0xFF5555,0xFF5555,0xFF5555,0xFF5555,0xAAAAAA,0xFF55FF,0xFF55FF
  !dd 0xAA5500,0xFF5555,0xFF5555,0xFF5555,0xAAAAAA,0xAAAAAA,0xAAAAAA,0xFF55FF
  !dd 0xAA5500,0xFFFF55,0xFFFF55,0xAAAAAA,0xAAAAAA,0xAAAAAA,0xAAAAAA,0xFFFFFF
  !dd 0xFFFF55,0xFFFF55,0xFFFF55,0xFFFF55,0xAAAAAA,0xAAAAAA,0xFFFFFF,0xFFFFFF
  !dd 0xFFFF55,0xFFFF55,0xFFFF55,0xFFFF55,0xFFFF55,0xFFFFFF,0xFFFFFF,0xFFFFFF
  !dd 0xAA0000,0xAA0000,0xFF5555,0xFF5555,0xAA00AA,0xAA00AA,0xFF55FF,0xFF55FF
  !dd 0xAA0000,0xFF5555,0xFF5555,0xFF5555,0xFF5555,0xFF55FF,0xFF55FF,0xFF55FF
  !dd 0xAA5500,0xFF5555,0xFF5555,0xFF5555,0xFF5555,0xFF55FF,0xFF55FF,0xFF55FF
  !dd 0xAA5500,0xFF5555,0xFF5555,0xFF5555,0xFF5555,0xFF55FF,0xFF55FF,0xFF55FF
  !dd 0xAA5500,0xFF5555,0xFF5555,0xFF5555,0xFF5555,0xAAAAAA,0xFF55FF,0xFF55FF
  !dd 0xFFFF55,0xFFFF55,0xFFFF55,0xFFFF55,0xAAAAAA,0xAAAAAA,0xFFFFFF,0xFFFFFF
  !dd 0xFFFF55,0xFFFF55,0xFFFF55,0xFFFF55,0xFFFF55,0xFFFFFF,0xFFFFFF,0xFFFFFF
  !dd 0xFFFF55,0xFFFF55,0xFFFF55,0xFFFF55,0xFFFF55,0xFFFFFF,0xFFFFFF,0xFFFFFF
EndProcedure

Re: CGA

Posted: Thu Feb 21, 2013 6:58 pm
by BasicallyPure
My assumptions are as follows:
for any color byte value CGA can only be 0 or 85 or 170 or 255.
so original byte values translate like this.
0 to 63 becomes 0
64 to 127 becomes 85
128 to 191 becomes 170
192 to 255 becomes 255

Try this. ( should be easy to do in assembly this way)

Code: Select all

Procedure CGA(color)
   
   R.i = Red(color)
   G.i = Green(color)
   B.i = Blue(color)
   
   cgaR.i = R / 64 * 85
   cgaG.i = G / 64 * 85
   cgaB.i = B / 64 * 85
   
   ProcedureReturn RGB(cgaR, cgaG, cgaB)
   
EndProcedure

UsePNGImageDecoder()
UsePNGImageEncoder()

FileName$ = GetHomeDirectory() + "Desktop/image.png"

LoadImage(0, FileName$)

xMax = ImageWidth(0) - 1
yMax = ImageHeight(0) - 1

StartDrawing(ImageOutput(0))
   DrawingMode(#PB_2DDrawing_Default)
   For x = 0 To xMax
      For y = 0 To yMax
         c = Point(x, y)
         Plot(x, y , CGA(c))
      Next y
   Next x
StopDrawing()

SaveImage(0, FileName$ + "_cga.png", #PB_ImagePlugin_PNG, 0, 4)

FreeImage(0)

End
As fast as I know how without assembly code.

Code: Select all

UsePNGImageDecoder()
UsePNGImageEncoder()

FileName$ = GetHomeDirectory() + "Desktop/image.png"

LoadImage(0, FileName$)

xMax = ImageWidth(0) - 1
yMax = ImageHeight(0) - 1

StartDrawing(ImageOutput(0))
   DrawingMode(#PB_2DDrawing_Default)
   For x = 0 To xMax
      For y = 0 To yMax
         color = Point(x, y)
         CGA = color & $0000FF / $000040 * $000055
         CGA + color & $00FF00 / $004000 * $005500
         CGA + color & $FF0000 / $400000 * $550000
         Plot(x, y , CGA)
      Next y
   Next x
StopDrawing()

SaveImage(0, FileName$ + "_cga.png", #PB_ImagePlugin_PNG, 0, 4)
FreeImage(0)
BP

Re: CGA

Posted: Thu Feb 21, 2013 9:31 pm
by J. Baker
All these codes seem to work, it's just accuracy of the conversion. So far, as close as I can get with accuracy is this. As you can see, I'm trying to find a way that if the original color is not truly black, to give it some kind of color value.

Image I've been testing.
Image

Code: Select all

Procedure CGA(color)
  
  DivideR.i = Red(color)
  DivideG.i = Green(color)
  DivideB.i = Blue(color)
  
      If DivideR.i > 170
        cgaR = 255
      ElseIf DivideR.i > 127 ;And DivideR.i < 171
        cgaR = 170
      Else
        If DivideG.i > 170 Or DivideB.i > 170
          cgaR = 85
        Else
          cgaR = 0
        EndIf
      EndIf
      
      If DivideG.i > 170
        cgaG = 255
      ElseIf DivideG.i > 127 ;And DivideG.i < 171
       cgaG = 170
      Else
        If DivideR.i > 170 Or DivideB.i > 170
          cgaG = 85
        Else
          cgaG = 0
        EndIf
      EndIf
      
      If DivideB.i > 170
        cgaB = 255
      ElseIf DivideB.i > 127 ;And DivideB.i < 171
       cgaB = 170
      Else
        If DivideR.i > 170 Or DivideG.i > 170
          cgaB = 85
        Else
          cgaB = 0
        EndIf
      EndIf
      
    MaxBlack = 64  
      
   If cgaR = 0 And cgaG = 0 And cgaB = 0
     If DivideR.i > MaxBlack Or DivideG.i > MaxBlack Or DivideB.i > MaxBlack
       If DivideB.i - DivideR.i > MaxBlack And DivideB.i - DivideG.i > MaxBlack
         cgaR = 0
         cgaG = 0
         cgaB = 170
       EndIf
       If DivideG.i - DivideR.i > MaxBlack And DivideG.i - DivideB.i > MaxBlack
         cgaR = 0
         cgaG = 170
         cgaB = 0
       EndIf
       If DivideG.i - DivideR.i > MaxBlack And DivideB.i - DivideR.i > MaxBlack
         cgaR = 0
         cgaG = 170
         cgaB = 170
       EndIf
       If DivideR.i - DivideG.i > MaxBlack And DivideR.i - DivideB.i > MaxBlack
         cgaR = 170
         cgaG = 0
         cgaB = 0
       EndIf
       If DivideR.i - DivideG.i > MaxBlack And DivideB.i - DivideG.i > MaxBlack
         cgaR = 170
         cgaG = 0
         cgaB = 170
       EndIf
       If DivideR.i - DivideG.i > MaxBlack / 2 And DivideR.i - DivideB.i > MaxBlack
         cgaR = 170
         cgaG = 85
         cgaB = 0
       EndIf
       If DivideR.i < MaxBlack And DivideR.i > 0 Or DivideG.i < MaxBlack And DivideG.i > 0 Or DivideB.i < MaxV And DivideB.i > 0
         cgaR = 170
         cgaG = 170
         cgaB = 170
       EndIf
     EndIf
   EndIf    
      
  If cgaR = 170 And cgaG = 170 And cgaB = 0
     cgaG = 85
  EndIf
  
  ProcedureReturn RGB(cgaR, cgaG, cgaB)
  
EndProcedure

UseJPEGImageDecoder()
UsePNGImageDecoder()
UsePNGImageEncoder()

FileName$ = GetHomeDirectory() + "Desktop/kq5.png"

LoadImage(0, FileName$)

;ResizeImage(0, 320, 240)

  StartDrawing(ImageOutput(0))
   DrawingMode(#PB_2DDrawing_Default)
    For x = 0 To ImageWidth(0) - 1
      For y = 0 To ImageHeight(0) - 1
        c = Point(x, y)
            Plot(x, y , CGA(c))
      Next y
    Next x

SaveImage(0, FileName$ + "_cga.png", #PB_ImagePlugin_PNG, 0, 4)

FreeImage(0)

End

Re: CGA

Posted: Fri Feb 22, 2013 3:15 am
by BasicallyPure
nothing black except when original color = 0

Code: Select all

UsePNGImageDecoder()
UsePNGImageEncoder()

FileName$ = GetHomeDirectory() + "Desktop/image.png"

LoadImage(0, FileName$)

xMax = ImageWidth(0) - 1
yMax = ImageHeight(0) - 1

StartDrawing(ImageOutput(0))
   DrawingMode(#PB_2DDrawing_Default)
   For x = 0 To xMax
      For y = 0 To yMax
         color = Point(x, y)
         If color = 0
            Plot(x, y, 0)
         Else
            R = Red(color)
            G = Green(color)
            B = Blue(color)
            CGA_R = R / $40 * $55
            CGA_G = G / $40 * $55
            CGA_B = B / $40 * $55
            
            If RGB(CGA_R, CGA_G, CGA_B) = 0
               If R > G And R > B
                  CGA_R = $55
               ElseIf G > R And G > B
                  CGA_G = $55
               Else
                  CGA_B = $55
               EndIf
            EndIf
            
            Plot(x, y , RGB(CGA_R, CGA_G, CGA_B))
         EndIf
      Next y
   Next x
StopDrawing()

SaveImage(0, FileName$ + "_cga.png", #PB_ImagePlugin_PNG, 0, 4)
FreeImage(0)

Re: CGA

Posted: Fri Feb 22, 2013 5:54 am
by wilbert
J. Baker wrote:All these codes seem to work, it's just accuracy of the conversion. So far, as close as I can get with accuracy is this. As you can see, I'm trying to find a way that if the original color is not truly black, to give it some kind of color value.
I used the method described here http://en.wikipedia.org/wiki/Color_quantization for a static palette to build the color table I used. It finds the closest palette entry.
But looking at the image you posted, that might not be what you want to do. The image is so colorful that you probably prefer a green pixel for a green pixel even if the brightness is off a lot and a gray pixel might in fact be closer.

Re: CGA

Posted: Fri Feb 22, 2013 6:47 am
by J. Baker
wilbert wrote:
J. Baker wrote:All these codes seem to work, it's just accuracy of the conversion. So far, as close as I can get with accuracy is this. As you can see, I'm trying to find a way that if the original color is not truly black, to give it some kind of color value.
I used the method described here http://en.wikipedia.org/wiki/Color_quantization for a static palette to build the color table I used. It finds the closest palette entry.
But looking at the image you posted, that might not be what you want to do. The image is so colorful that you probably prefer a green pixel for a green pixel even if the brightness is off a lot and a gray pixel might in fact be closer.
Yeah, that is what I'm talking about. I'm trying to write a procedure to do this but so far it's only half right.

Also, I don't need this code for anything. This is just a "challenge" really. Well, that and I do like 4bit graphics, Dos, ect. ;)

@BasicallyPure
Looks good but still some minor issues that I think could still be corrected with code. ;)