Repair the colors of a Dos program ported to ptcGraph unit lazarus / 39-Graphics ---------------------------------------------------------------------- Roland57 · 2020-10-26 12:43 Hello! I try to update a Dos program originally based on the Graph unit. I am on Linux. Since I had problems with the VGA library missing or not correctly installed, I decided to try to use ptcGraph and I had the joy to see "my" old program compiling and running! There is just a problem with colors, and I would need your advice on the method to repair the colors of the game. Currently all is blue on the screen.  If I remember correctly, ptcGraph uses 16-bit colors. Are there existing functions to convert 32-bit colors to 16-bit? Any help or suggestion on this problem or on any another problem that you would detect is welcome. It seems that there also some memory leaks. I attach the source, and a screenshot of the original program that I found on the web. ---------------------------------------------------------------------- Thaddy · 2020-10-26 14:53 32 to 16 leads to extreme data loss for the color. you can use "nearest neighbour" and the likes to smoothen any transitions. It is better to upscale any new  colors than trying to downscale them. ---------------------------------------------------------------------- circular · 2020-10-26 17:55 Hello Roland, Hope you're alright. I cannot find the definition of ptcGraph that would contain setColor function nor the color constants. I see in the code "setcolor(yellow)" or things like that. Why would the constant not agree with the function? Anyway to convert from 32 bit to 16 bit you could do something like: Code: Pascal  [Select][+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i function From32To16(AColor: longint): word;var red, green, blue, red5, green6, blue5: byte;begin  red := AColor and $ff;  green := (AColor sur 8) and $ff;  blue := (AColor sur 16) and $ff;  red5 := red shr 3;  green6 := green shr 2;  blue5 := blue shr 3;  result := red5 + (green6 shl 5) + (blue5 shl 11);end; @Thaddy: in this case we don't care about loss of precision for the colors to distinguish blue, yellow, white etc. as you can see from the screenshot. ---------------------------------------------------------------------- Thaddy · 2020-10-26 19:29 Quote from: circular on October 26, 2020, 06:55:40 pm@Thaddy: in this case we don't care about loss of precision for the colors to distinguish blue, yellow, white etc. as you can see from the screenshot. ptc differs in color definition compared to, say, Dos vs different Unix terminals. Has to do with the weight encodings (like 888, 565 and family) so you can get very different colors depending on definition. That is what I am trying to point out.... And ptc has most definitely the encoding values in the header files. ---------------------------------------------------------------------- Roland57 · 2020-10-26 20:04 @Thaddy, circular Thank you for your answers. Quote from: circular on October 26, 2020, 06:55:40 pmHope you're alright. Yes, I am well, thank you.  Quote from: circular on October 26, 2020, 06:55:40 pmI cannot find the definition of ptcGraph that would contain setColor function nor the color constants. I see in the code "setcolor(yellow)" or things like that. Why would the constant not agree with the function? Good question. I don't know. Maybe it's because of the compilation mode that I used (-Mtp)? Thank you for your function. I used it to build a source code with 256 predefined 16-bit colors. Now the colors of the program are OK (excepted when I compile to 32-bit, I dont know why). ---------------------------------------------------------------------- Fred vS · 2020-10-26 20:25 Hello Roland. Once again, VERY impressive. I did use fpc 64bit with that command: Code: Pascal  [Select][+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i fpc -Mtp -FUunits -B nero5.pas  -CX -XX -Xs I was not able to resize-close the window but many things work, sure you will find all. Chapeau. Fre;D ---------------------------------------------------------------------- Fred vS · 2020-10-26 20:58 Re-hello. Compiling with fpc 32 bit gives better result vs fpc 64, see picture. All works, even close the app (but not resizing). ---------------------------------------------------------------------- circular · 2020-10-26 23:28 When trying to compile, it says it cannot find the unit ptccrt and ptcgraph. Though I have those units. ---------------------------------------------------------------------- Fred vS · 2020-10-26 23:48 Quote from: circular on October 27, 2020, 12:28:00 amWhen trying to compile, it says it cannot find the unit ptccrt and ptcgraph. Though I have those units.  Huh, I did get those errors too using fpc 32 bit on my multi-arch Debian OS, I needed to change config of fpc.cfg. ---------------------------------------------------------------------- Fred vS · 2020-10-26 23:55 Note also that I needed to install on my Debian multi-arch this package that was missing: Code: Pascal  [Select][+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i $ sudo apt- get install libxxf86dga1:i386 [EDIT] All is ok too with fpc 64 bit (I dont know why I got strange result before). Using this: Code: Pascal  [Select][+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i /usr/lib/fpc/3.2.1/ppcx64 -Mtp -FUunits -B -CX -XX -Xs -ghl nero5.pas (But there is many memory leaks.) ---------------------------------------------------------------------- Roland57 · 2020-10-27 07:41 Thank you for testing, Fred. I retouched many little things. There remains ony one small memory leak: I don't find where it comes from. The -Mtp option is no longer needed. You can use -Mobjfpc. I played with the different graphic modes offered by ptcGraph. I see now that it was possible to use a 8-bit color mode. Maybe it would have been a more logical choice (if we keep the original colors). If you prefer fullscreen, change this value to 0: Code: Pascal  [Select][+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i procedure set_to_graphics_mode;{ ... }begin  opt := 2; ---------------------------------------------------------------------- Roland57 · 2020-10-27 07:45 Quote from: circular on October 26, 2020, 06:55:40 pmI cannot find the definition of ptcGraph that would contain setColor function nor the color constants. I see in the code "setcolor(yellow)" or things like that. Why would the constant not agree with the function? I think these constants are for the 8-bit color mode. ---------------------------------------------------------------------- PascalDragon · 2020-10-27 08:15 Quote from: Roland57 on October 27, 2020, 08:45:06 amQuote from: circular on October 26, 2020, 06:55:40 pmI cannot find the definition of ptcGraph that would contain setColor function nor the color constants. I see in the code "setcolor(yellow)" or things like that. Why would the constant not agree with the function? I think these constants are for the 8-bit color mode. The color constants are for SetPalette and GetPalette and thus for paletted color modes (like the 8-bit one). Routines that directly take color values (like SetColor) take 32-bit RGB values on most platforms (at least those where FPC_GRAPH_SUPPORTS_TRUECOLOR is defined, on others like i8086-msdos it's 16-bit). ---------------------------------------------------------------------- Roland57 · 2020-10-27 09:00 Quote from: PascalDragon on October 27, 2020, 09:15:52 amThe color constants are for SetPalette and GetPalette and thus for paletted color modes (like the 8-bit one). Routines that directly take color values (like SetColor) take 32-bit RGB values on most platforms (at least those where FPC_GRAPH_SUPPORTS_TRUECOLOR is defined, on others like i8086-msdos it's 16-bit). Thank you for your answer. Something is not clear for me. If ptcGraph expects 32-bits colors, I should get an unexpected visual result, since I use 16-bit values for the SetColor procedure, shouldn't I? ---------------------------------------------------------------------- Roland57 · 2020-10-27 10:48 I used to believe that ptcGraph supported only 16-bit colors. It isn't true. Here is a little program which make a list of all modes available. I did find it on a russian forum. Code: Pascal  [Select][+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i { http://www.freepascal.ru/article/freepascal/20120215095658/ } program gmodeinfo; uses{$IFDEF UNIX}  CThreads,{$ENDIF}  SysUtils, ptcGraph; var  ModeInfo: PModeInfo; // Сюда будет заносится информация о видеорежимах  Rez: string; begin  ModeInfo := QueryAdapterInfo;    if ModeInfo = nil then    WriteLn('Не удалось получить информацию у видеоадаптера...')  else  begin    //WriteLn('№ драйвера ', '№ режима ', 'Разрешение ', '  Цветов');    WriteLn('Driver num ', 'Mode num ', 'Resolution ', '  Colors', '          Mode name');    WriteLn('------- ---------------------------------------------------');    while ModeInfo^.Next <> nil do    begin      Write(ModeInfo^.DriverNumber: 10);      Write(ModeInfo^.ModeNumber: 9);      Rez := IntToStr(ModeInfo^.MaxX + 1) + 'x' + IntToStr(ModeInfo^.MaxY + 1);    Write(Rez: 11);      Write(ModeInfo^.MaxColor: 9);      WriteLn(' ' + ModeInfo^.ModeName: 19);      ModeInfo := ModeInfo^.Next;    end;  end;end.  And here is the result for me: Code: Text  [Select][+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i Driver num Mode num Resolution   Colors          Mode name----------------------------------------------------------         1        0    320x200        4   320 x 200 CGA C0         1        1  320x200        4   320 x 200 CGA C1         1        2    320x200      4   320 x 200 CGA C2         1        3    320x200        4   320 x 200 CGA C3         1        4    640x200        2      640 x 200 CGA         2        0    320x200        4   320 x 200 CGA C0         2        1    320x200        4   320 x 200 CGA C1         2        2  320x200        4   320 x 200 CGA C2         2        3    320x200      4   320 x 200 CGA C3         2        4    640x200        2      640 x 200 CGA         2        5    640x480        2     640 x 480 MCGA         7        0    720x348        2 720 x 348 HERCULES         3        0    640x200       16      640 x 200 EGA         3        1  640x350       16      640 x 350 EGA         9        0    640x200     16      640 x 200 EGA         9        1    640x350       16      640 x 350 EGA         9        2    640x480       16      640 x 480 VGA         6        0    320x200      256      320 x 200 VGA         6        1    320x200      256    320 x 200 ModeX        10      256  640x400      256     640 x 400 VESA        10      257    640x480    256     640 x 480 VESA        10      269    320x200    32768     320 x 200 VESA        10      272    640x480    32768     640 x 480 VESA        10      270    320x200    65536     320 x 200 VESA        10      273    640x480    65536     640 x 480 VESA        10      271  320x200 16777216     320 x 200 VESA        10      274    640x480 16777216     640 x 480 VESA        10      258    800x600       16   800 x 600 VESA        10      259    800x600      256     800 x 600 VESA        10      275    800x600    32768     800 x 600 VESA        10      276    800x600    65536     800 x 600 VESA        10      277  800x600 16777216     800 x 600 VESA        10      260   1024x768     16    1024 x 768 VESA        10      261   1024x768      256    1024 x 768 VESA        10      278   1024x768    32768    1024 x 768 VESA        10      279   1024x768    65536    1024 x 768 VESA        10      280   1024x768 16777216    1024 x 768 VESA        10      512  720x480       16     720 x 480 VESA        10      513    720x480    256     720 x 480 VESA        10      514    720x480    32768     720 x 480 VESA        10      515    720x480    65536     720 x 480 VESA        10      516    720x480 16777216     720 x 480 VESA        10      517    848x480       16     848 x 480 VESA        10      518  848x480      256     848 x 480 VESA        10      519    848x480    32768     848 x 480 VESA        10      520    848x480    65536     848 x 480 VESA        10      521    848x480 16777216     848 x 480 VESA        10      522   1152x768       16    1152 x 768 VESA        10      523   1152x768      256    1152 x 768 VESA        10      524 1152x768    32768    1152 x 768 VESA        10      525   1152x768    65536    1152 x 768 VESA        10      526   1152x768 16777216    1152 x 768 VESA        10      527   1280x720       16    1280 x 720 VESA        10      528   1280x720      256    1280 x 720 VESA        10      529   1280x720    32768    1280 x 720 VESA        10      530 1280x720    65536    1280 x 720 VESA        10      531   1280x720 16777216    1280 x 720 VESA        10      532   1366x768       16    1366 x 768 VESA        10      533   1366x768      256    1366 x 768 VESA        10      534   1366x768    32768    1366 x 768 VESA        10      535   1366x768    65536    1366 x 768 VESA ---------------------------------------------------------------------- Roland57 · 2020-10-27 11:49 I changed the graphic mode to 16 colors. Now you really have the feeling of a Dos program. ---------------------------------------------------------------------- Fred vS · 2020-10-27 13:55 QuoteThere remains ony one small memory leak: I don't find where it comes from. Imho, it comes from engine88.pas You may try this: Code: Pascal  [Select][+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i program nero5_test;uses  cthreads,  engine88; beginend. Compile it with this: Code: Bash  [Select][+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i $ fpc -ghl nero5_test.pas I get that: Quotefred@fiens $ ./nero5_test Heap dump by heaptrc unit of nero5_test 1260 memory blocks allocated : 115031/117752 1259 memory blocks freed     : 114983/117704 1 unfreed memory blocks : 48 True heap size : 229376 True free heap : 229120 Should be : 229136 Call trace for block $00007FD7F1068F00 size 48 But I did not investigate where is the guilty. Fre;D ---------------------------------------------------------------------- Fred vS · 2020-10-27 14:13 Hum, in engine88.pas, in uses section there is: Code: Pascal  [Select][+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i uses  sysutils, ptccrt, ptcgraph; Now doing this: Code: Pascal  [Select][+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i program nero5_test; uses cthreads,  ptccrt; beginend.  Compile it with: Code: Bash  [Select][+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i $ fpc -ghl nero5_test.pas Gives the same result: Quotefred@fiens ~/roland> /home/fred/roland/nero5_test Heap dump by heaptrc unit of /home/fred/roland/nero5_test 1260 memory blocks allocated : 115031/117752 1259 memory blocks freed     : 114983/117704 1 unfreed memory blocks : 48 True heap size : 229376 True free heap : 229120 Should be : 229136 Call trace for block $00007F008E667F00 size 48 Conclusion: I fear that the memory leak is in ptccrt Fre;D ---------------------------------------------------------------------- Fred vS · 2020-10-27 14:44 It is me again! Continuing the battle: In ptccrt.pp in uses section there is: Code: Pascal  [Select][+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i uses  ptcgraph, ptc, ptcwrapper, ... And doing this:     Code: Pascal  [Select][+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i program nero5_test;         uses     cthreads,     ptcgraph;   begin  end.  Gives:    Code: Pascal  [Select][+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i fred@fiens ./nero5_testHeap dump by heaptrc unit of nero5_test1259 memory blocks allocated : 111191/1139121258 memory blocks freed     : 111143/1138641 unfreed memory blocks : 48True heap size : 229376True free heap : 229120Should be : 229136Call trace for block $00007F0409FDDF00 size 48 Re-conclusion, the memory leak is in ptcgraph.pp (and not in ptc.pp, ptcwrapper.pp that are in uses section of ptcgraph.pp) There is something missing in Finalization section of ptcgraph.pp. For the sport, I let you find where. Fre;D ---------------------------------------------------------------------- Roland57 · 2020-10-27 17:26 Thank your for your search Fred. So we should add this? Code: Pascal  [Select][+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i // ptcgraph.ppfinalization  PTCFormat8.Destroy;  PTCFormat15.Destroy;  PTCFormat16.Destroy; I would like to test, but I don't know what is the procedure to test a modification in FPC units. ---------------------------------------------------------------------- Fred vS · 2020-10-27 17:42 Quote from: Roland57 on October 27, 2020, 06:26:19 pmThank your for your search Fred. So we should add this? Code: Pascal  [Select][+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i // ptcgraph.ppfinalization  PTCFormat8.Destroy;  PTCFormat15.Destroy;  PTCFormat16.Destroy; Hello Roland. I did try this already but sadly it does not compile, even using .free; Quoteptcgraph.pp(3467,15) Error: (5038) identifier idents no member "Destroy" I did a fast investigation but without luck, this memory leak is well hidden. QuoteI would like to test, but I don't know what is the procedure to test a modification in FPC units. I do a easy way, to be sure to not touch at the original source. So, copy in the root directory of project all files that are in:  Code: Pascal  [Select][+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i /fpc/src/packages/graph/src/ptcgraph/*.* and in: Code: Pascal  [Select][+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i /fpc/src/packages/graph/src/inc/*.* And tune those files then compile. ---------------------------------------------------------------------- Fred vS · 2020-10-27 18:00 [EDIT] Removed previous attachment, there was some file missing. Hello Roland. Here your project in attachment with all the needed files. Fre;D ---------------------------------------------------------------------- Roland57 · 2020-10-27 18:28 Thank you Fred. ---------------------------------------------------------------------- Fred vS · 2020-10-27 19:26 Quote from: Roland57 on October 27, 2020, 07:28:44 pmThank you Fred. With pleasure (if we find the guilty). Something smells not good, in ptcgraph.pp and TPTCWrapperThread: Using this to test the unit: Code: Pascal  [Select][+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i program nero5_test;uses cthreads,  ptcgraph; beginend. And in ptcgraph.pp, If you use that code (removing all other lines in initialization and finalization): Code: Pascal  [Select][+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i ...initialization  PTCWrapperObject := TPTCWrapperThread.Create; finalization  PTCWrapperObject.Terminate;  PTCWrapperObject.WaitFor;  PTCWrapperObject.Free;end. The memory leak is still there. So, imho, there is something not freed in PTCWrapperObject. Fre;D ---------------------------------------------------------------------- Fred vS · 2020-10-27 19:46 Hello Roland! I get it! The terrorist was inside fpc/src/packages/ptc/src/ptcwrapper/ptcwrapper.pp Here the code: Code: Pascal  [Select][+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i constructor TPTCWrapperThread.Create;begin  FOpen := False;  FNeedsUpdate := False;   FOpenRequest.Processed := True;  FCloseRequest.Processed := True;  FOptionRequest.Processed := True;  FGetModesRequest.Processed := True;  FMoveMouseToRequest.Processed := True;   FSurfaceCriticalSection := TCriticalSection.Create; // HUH DONT FORGET IT   inherited Create(False);end; .... destructor TPTCWrapperThread.Destroy;begin  FSurfaceCriticalSection.free; // THIS WAS MISSING  inherited;end;  Doing this, no more memory leak. Quote       You have played FREEWARE program NERO 5.                    Feel free to give it to your friends too!                           Send your feedback to:                                                                      OR  Jari Huikari, Jenkkakuja 1 B 34, 40520  JKL, FINLAND, EUROPE Heap dump by heaptrc unit of /home/fred/roland/nero5 3066 memory blocks allocated : 627850/630696 3066 memory blocks freed     : 627850/630696 0 unfreed memory blocks : 0 True heap size : 196608 True free heap : 196608 Included fixed ptcwrapper.pp, just add it in your root directory project. Fre.D ---------------------------------------------------------------------- circular · 2020-10-27 19:59 Good job Fred ---------------------------------------------------------------------- Thaddy · 2020-10-27 20:06 at least 16777216 values are errors in the test..... ---------------------------------------------------------------------- Roland57 · 2020-10-27 20:14 Congratulations inspector Fred! Excellent job. Quote from: Thaddy on October 27, 2020, 09:06:37 pmat least 16777216 values are errors in the test..... Sorry, I don't understand. ---------------------------------------------------------------------- BobDog · 2020-10-27 20:27 Hi Roland. For a bit of an experiment converting 32 bit colours to 16 bit (256) colours. I set up the converting array from freebasic. Code: Pascal  [Select][+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i   program To256; uses Windows;      typecolour =packed recordcase integer of0:(r,g,b:byte);1:(c:longword);end;   function SetDCBrushColor(p:hdc;colour:COLORREF): COLORREF; stdcall external 'gdi32.dll' name 'SetDCBrushColor';  function SetDCPenColor(p:hdc;colour:COLORREF): COLORREF; stdcall external 'gdi32.dll' name 'SetDCPenColor';  function closest(v:colour):longword;forward;    type circle=object x:integer; y:integer ; r:integer; c:colour; procedure draw(h:hdc); procedure draw256(h:hdc); end;  procedure circle.draw(h:hdc) ; begin  SetDCBrushColor(h,c.c);  SetDCPenColor(h,c.c); ellipse(h,trunc(x- r)+50,trunc(y-r),trunc(x+r)+50,trunc(y+r)); end;   procedure circle.draw256(h:hdc) ; begin  SetDCBrushColor(h,closest(c));  SetDCPe nColor(h,closest(c)); ellipse(h,trunc(x-r+400),trunc(y- r),trunc(x+r+400),trunc(y+r)); end; // constants    const    DC_BRUSH=18;    const    DC_PEN=19;     const clr:array[0..255] of col our=((r:0;g:0;b:0),(r:0;g:170;b:0),(r:0;g:0;b:170),(r:0;g:170;b:170),( r:170;g:0;b:0),(r:170;g:170;b:0),(r:170;g:0;b:85),(r:170;g:170;b:170), (r:85;g:85;b:85),(r:85;g:255;b:85),(r:85;g:85;b:255),(r:85;g:255;b:255 ),(r:255;g:85;b:85),(r:255;g:255;b:85),(r:255;g:85;b:255),(r:255;g:255 ;b:255),(r:0;g:0;b:0),(r:20;g:20;b:20),(r:32;g:32;b:32),(r:44;g:44;b:4 4),(r:56;g:56;b:56),(r:68;g:68;b:68),(r:80;g:80;b:80),(r:97;g:97;b:97) ,(r:113;g:113;b:113),(r:129;g:129;b:129),(r:145;g:145;b:145),(r:161;g: 161;b:161),(r:182;g:182;b:182),(r:202;g:202;b:202),(r:226;g:226;b:226) ,(r:255;g:255;b:255),(r:0;g:255;b:0),(r:64;g:255;b:0),(r:125;g:255;b:0 ),(r:190;g:255;b:0),(r:255;g:255;b:0),(r:255;g:190;b:0),(r:255;g:125;b :0),(r:255;g:64;b:0),(r:255;g:0;b:0),(r:255;g:0;b:64),(r:255;g:0;b:125 ),(r:255;g:0;b:190),(r:255;g:0;b:255),(r:190;g:0;b:255),(r:125;g:0;b:2 55),(r:64;g:0;b:255),(r:0;g:0;b:255),(r:0;g:64;b:255),(r:0;g:125;b:255 ),(r:0;g:190;b:255),(r:0;g:255;b:255),(r:0;g:255;b:190),(r:0;g:255;b:1 25),(r:0;g:255;b:64),(r:125;g:255;b:125),(r:157;g:255;b:125),(r:190;g: 255;b:125),(r:222;g:255;b:125),(r:255;g:255;b:125),(r:255;g:222;b:125) ,(r:255;g:190;b:125),(r:255;g:157;b:125),(r:255;g:125;b:125),(r:255;g: 125;b:157),(r:255;g:125;b:190),(r:255;g:125;b:222),(r:255;g:125;b:255) ,(r:222;g:125;b:255),(r:190;g:125;b:255),(r:157;g:125;b:255),(r:125;g: 125;b:255),(r:125;g:157;b:255),(r:125;g:190;b:255),(r:125;g:222;b:255) ,(r:125;g:255;b:255),(r:125;g:255;b:222),(r:125;g:255;b:190),(r:125;g: 255;b:157),(r:182;g:255;b:182),(r:198;g:255;b:182),(r:218;g:255;b:182) ,(r:234;g:255;b:182),(r:255;g:255;b:182),(r:255;g:234;b:182),(r:255;g: 218;b:182),(r:255;g:198;b:182),(r:255;g:182;b:182),(r:255;g:182;b:198) ,(r:255;g:182;b:218),(r:255;g:182;b:234),(r:255;g:182;b:255),(r:234;g: 182;b:255),(r:218;g:182;b:255),(r:198;g:182;b:255),(r:182;g:182;b:255) ,(r:182;g:198;b:255),(r:182;g:218;b:255),(r:182;g:234;b:255),(r:182;g: 255;b:255),(r:182;g:255;b:234),(r:182;g:255;b:218),(r:182;g:255;b:198) ,(r:0;g:113;b:0),(r:28;g:113;b:0),(r:56;g:113;b:0),(r:85;g:113;b:0),(r :113;g:113;b:0),(r:113;g:85;b:0),(r:113;g:56;b:0),(r:113;g:28;b:0),(r: 113;g:0;b:0),(r:113;g:0;b:28),(r:113;g:0;b:56),(r:113;g:0;b:85),(r:113 ;g:0;b:113),(r:85;g:0;b:113),(r:56;g:0;b:113),(r:28;g:0;b:113),(r:0;g: 0;b:113),(r:0;g:28;b:113),(r:0;g:56;b:113),(r:0;g:85;b:113),(r:0;g:113 ;b:113),(r:0;g:113;b:85),(r:0;g:113;b:56),(r:0;g:113;b:28),(r:56;g:113 ;b:56),(r:68;g:113;b:56),(r:85;g:113;b:56),(r:97;g:113;b:56),(r:113;g: 113;b:56),(r:113;g:97;b:56),(r:113;g:85;b:56),(r:113;g:68;b:56),(r:113 ;g:56;b:56),(r:113;g:56;b:68),(r:113;g:56;b:85),(r:113;g:56;b:97),(r:1 13;g:56;b:113),(r:97;g:56;b:113),(r:85;g:56;b:113),(r:68;g:56;b:113),( r:56;g:56;b:113),(r:56;g:68;b:113),(r:56;g:85;b:113),(r:56;g:97;b:113) ,(r:56;g:113;b:113),(r:56;g:113;b:97),(r:56;g:113;b:85),(r:56;g:113;b: 68),(r:80;g:113;b:80),(r:89;g:113;b:80),(r:97;g:113;b:80),(r:105;g:113 ;b:80),(r:113;g:113;b:80),(r:113;g:105;b:80),(r:113;g:97;b:80),(r:113; g:89;b:80),(r:113;g:80;b:80),(r:113;g:80;b:89),(r:113;g:80;b:97),(r:11 3;g:80;b:105),(r:113;g:80;b:113),(r:105;g:80;b:113),(r:97;g:80;b:113), (r:89;g:80;b:113),(r:80;g:80;b:113),(r:80;g:89;b:113),(r:80;g:97;b:113 ),(r:80;g:105;b:113),(r:80;g:113;b:113),(r:80;g:113;b:105),(r:80;g:113 ;b:97),(r:80;g:113;b:89),(r:0;g:64;b:0),(r:16;g:64;b:0),(r:32;g:64;b:0 ),(r:48;g:64;b:0),(r:64;g:64;b:0),(r:64;g:48;b:0),(r:64;g:32;b:0),(r:6 4;g:16;b:0),(r:64;g:0;b:0),(r:64;g:0;b:16),(r:64;g:0;b:32),(r:64;g:0;b :48),(r:64;g:0;b:64),(r:48;g:0;b:64),(r:32;g:0;b:64),(r:16;g:0;b:64),( r:0;g:0;b:64),(r:0;g:16;b:64),(r:0;g:32;b:64),(r:0;g:48;b:64),(r:0;g:6 4;b:64),(r:0;g:64;b:48),(r:0;g:64;b:32),(r:0;g:64;b:16),(r:32;g:64;b:3 2),(r:40;g:64;b:32),(r:48;g:64;b:32),(r:56;g:64;b:32),(r:64;g:64;b:32) ,(r:64;g:56;b:32),(r:64;g:48;b:32),(r:64;g:40;b:32),(r:64;g:32;b:32),( r:64;g:32;b:40),(r:64;g:32;b:48),(r:64;g:32;b:56),(r:64;g:32;b:64),(r: 56;g:32;b:64),(r:48;g:32;b:64),(r:40;g:32;b:64),(r:32;g:32;b:64),(r:32 ;g:40;b:64),(r:32;g:48;b:64),(r:32;g:56;b:64),(r:32;g:64;b:64),(r:32;g :64;b:56),(r:32;g:64;b:48),(r:32;g:64;b:40),(r:44;g:64;b:44),(r:48;g:6 4;b:44),(r:52;g:64;b:44),(r:60;g:64;b:44),(r:64;g:64;b:44),(r:64;g:60; b:44),(r:64;g:52;b:44),(r:64;g:48;b:44),(r:64;g:44;b:44),(r:64;g:44;b: 48),(r:64;g:44;b:52),(r:64;g:44;b:60),(r:64;g:44;b:64),(r:60;g:44;b:64 ),(r:52;g:44;b:64),(r:48;g:44;b:64),(r:44;g:44;b:64),(r:44;g:48;b:64), (r:44;g:52;b:64),(r:44;g:60;b:64),(r:44;g:64;b:64),(r:44;g:64;b:60),(r :44;g:64;b:52),(r:44;g:64;b:48),(r:0;g:0;b:0),(r:0;g:0;b:0),(r:0;g:0;b :0),(r:0;g:0;b:0),(r:0;g:0;b:0),(r:0;g:0;b:0),(r:0;g:0;b:0),(r:0;g:0;b :0));  function closest(v:colour):longword;function dist(cc:colour;pv:colour):single ;var s:single;begins:= (cc.r-pv.r)*(cc.r-pv.r) +(cc.g-pv.g)*(cc.g-pv.g)+(cc.b-pv.b)*(cc.b-pv.b) ;exit(s);end;varres:longword;n:longword;dt :single =1e20;distance:single=0;    begin    res:=0;    for n :=0 to 255 do  begin        distance:=dist(clr[n],v);        if (dt > distance) then // catch the smallest         begin           dt := distance;res:=clr[n].c;         end;    end;    exit(res)end; function rgb(r:byte;g:byte;b:byte):longword;var return:colour;beginreturn.r:=r; return.g:=g;return.b:=b; exit(return.c);end; procedure hidecursor(); var    consoleHandle:handle;     info:CONSOLE_CURSOR_INFO ;     begin     consolehandle := GetStdHandle(STD_OUTPUT_HANDLE);     info.dwSize := 100;     info.bVisible := FALSE ;     SetConsoleCursorInfo(consoleHandle, @info);     End; procedure setupcircles(var a:array of circle) ;var i:integer;beginfor i:=1 to length(a) dobegina[i].x:=5+random(300);a[i] .y:=50+random(500);a[i].r:=3+random(10);a[i].c.c:=rgb(random(255),rand om(255),random(255));end;end; varp:hwnd;h:hdc;circles:array[1..5000] of circle;i:integer; begin    p := GetConsoleWindow();    setwindowpos(p, HWND_TOPMOST, 100, 100, 800, 600, SWP_SHOWWINDOW);    hidecursor();    h:=GetDC(p);    setupcircles(circles);    SelectObject(h,GetStockObject(DC_BRUSH));    SelectObject(h,GetStockObject(DC_PEN));    write('         32 bit');  writeln('                                           256 colours');  for i:=1 to length(circles) do circles[i].draw(h);    for i:=1 to length(circles) do circles[i].draw256(h);readln;end. I don't suppose it is any good to you, just ignore it, it is a mess around for fun. I might try it out on a bitmap. ---------------------------------------------------------------------- Roland57 · 2020-10-27 21:35 Quote from: BobDog on October 27, 2020, 09:27:00 pmHi Roland. For a bit of an experiment converting 32 bit colours to 16 bit (256) colours. I set up the converting array from freebasic. Hi. Thank you for your code. I cannot try it at once (because I am on Linux) but I keep it. ---------------------------------------------------------------------- Seenkao · 2020-10-28 01:21 Небольшой вопрос. А почему бы не сделать как в 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. ---------------------------------------------------------------------- Roland57 · 2020-10-28 06:28 Quote from: Seenkao on October 28, 2020, 02:21:23 amA 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][+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i function Color16(const r, g, b: byte): word;var  r1, g1, b1: byte;begin  r1 := Round((r / 255) * 31);  g1 := Round((g / 255) * 63);  b1 := Round((b / 255) * 31);  result := (r1 shl 11) or (g1 shl 5) or b1; end; var  blue: word; begin  blue := Color16(0, 0, 255);  WriteLn(blue);end. ---------------------------------------------------------------------- Seenkao · 2020-10-28 09:55 Проверьте, будет работать или нет. Google translate: Check if it will work or not.