Recent

Author Topic: Repair the colors of a Dos program ported to ptcGraph unit  (Read 4255 times)

Seenkao

  • Hero Member
  • *****
  • Posts: 544
    • New ZenGL.
Re: Repair the colors of a Dos program ported to ptcGraph unit
« Reply #30 on: October 28, 2020, 02:21:23 am »
Небольшой вопрос. А почему бы не сделать как в OpenGL?
Вы берёте максимальную составляющую за 1
Из заданного бита (пикселя) цвета выделяете составляющую для 32-х бит и восстанавливаете для 16-ти.

1 = 255 (R, G, B or alpha)
допустим R = 130, (подсчёт примерный)
составляющая 1 / 255 = 0.004 далее 0.004  * 130 = 0,52 (погрешность появляется, но можно делать точнее)
переводим в 16: 1 / 31 = 0.032 находим составляющую 0.52 / 0.032 = 16.25 округляем к ближайшему = 16

Для остальных цветов так же. Не забываем для R и B по 31, для G 63.
Возможно займёт порядочно времени по работе с большим объёмом.

Google translate
A small question. Why not do it like in OpenGL?
You take the maximum component for 1
From a given bit (pixel) of color, select a component for 32 bits and restore for 16 bits.

1 = 255 (R, G, B or alpha)
let's say R = 130, (approximate calculation)
component 1/255 = 0.004 further 0.004 * 130 = 0.52 (the error appears, but you can do it more precisely)
translate into 16: 1/31 = 0.032 find the component 0.52 / 0.032 = 16.25 round to the nearest = 16

For other colors the same. Don't forget 31 for R and B, 63 for G.
It may take a lot of time to work with a large volume.
Rus: Стремлюсь к созданию минимальных и достаточно быстрых приложений.

Eng: I strive to create applications that are minimal and reasonably fast.
Working on ZenGL

Roland57

  • Sr. Member
  • ****
  • Posts: 416
    • msegui.net
Re: Repair the colors of a Dos program ported to ptcGraph unit
« Reply #31 on: October 28, 2020, 07:28:15 am »
A small question. Why not do it like in OpenGL?

Thank you for your message. If I correctly understand, you would suggest to do the conversion from 32-bit to 16-bit color like this?

Code: Pascal  [Select][+][-]
  1. function Color16(const r, g, b: byte): word;
  2. var
  3.   r1, g1, b1: byte;
  4. begin
  5.   r1 := Round((r / 255) * 31);
  6.   g1 := Round((g / 255) * 63);
  7.   b1 := Round((b / 255) * 31);
  8.   result := (r1 shl 11) or (g1 shl 5) or b1;
  9. end;
  10.  
  11. var
  12.   blue: word;
  13.  
  14. begin
  15.   blue := Color16(0, 0, 255);
  16.   WriteLn(blue);
  17. end.
My projects are on Gitlab and on Codeberg.

Seenkao

  • Hero Member
  • *****
  • Posts: 544
    • New ZenGL.
Re: Repair the colors of a Dos program ported to ptcGraph unit
« Reply #32 on: October 28, 2020, 10:55:48 am »
Проверьте, будет работать или нет.

Google translate:
Check if it will work or not.  :)
Rus: Стремлюсь к созданию минимальных и достаточно быстрых приложений.

Eng: I strive to create applications that are minimal and reasonably fast.
Working on ZenGL

 

TinyPortal © 2005-2018