Convert from Mono12 pixel format to RGBA lazarus / 39-Graphics ---------------------------------------------------------------------- BlueIcaro · 2021-03-26 14:47 Hello, I have a buffer from a camera with a image in Mono12 or in Mono8 pixel format. I want to save it in jpeg. For convert from Mono8 to RGBA, I wrote: Code: [Select]Imagen := TFPMemoryImage.Create(g_Frames.Width, g_Frames.Height);     fpCol.Alpha := $FFFF;     if PixelFormat[0] = 'Mono8' then     begin       src := pInt8(g_Frames.buffer);// pInt8 is a pointer to shortInt       for Y := 0 to g_Frames.Height - 1 do       begin         for X := 0 to g_Frames.Width - 1 do         begin           fpCol.Red := Abs(src^ * $101);           fpCol.Green := Abs(src^ * $101);           fpCol.Blue := Abs(src^ * $101);           Imagen[x, y] := fpCol;           Inc(src);         end;       end;     end                                        After thar I write the image to file, like this: Code: [Select] jpeg := TFPWriterJPEG.Create;     Imagen.SaveToFile('pepe.jpg', jpeg);     Imagen.Free;      But How Can I convert from Mono12 to RGA. Thanks in advance /BlueIcaro ---------------------------------------------------------------------- BlueIcaro · 2021-03-26 16:08 Hello, I found the solution by my self. Code: [Select]if PixelFormat[0] = 'Mono8' then     begin       src := pInt8(g_Frames.buffer);       for Y := 0 to g_Frames.Height - 1 do       begin         for X := 0 to g_Frames.Width - 1 do         begin           fpCol.Red := Abs(src^ * $100);           fpCol.Green := Abs(src^ * $100);           fpCol.Blue := Abs(src^ * $100);           Imagen[x, y] := fpCol;           Inc(src);         end;       end;     end     else     begin       src16 := pInt12(g_Frames.buffer);       for Y := 0 to g_Frames.Height - 1 do       begin         for X := 0 to g_Frames.Width - 1 do         begin           color := src16^;           Color := Color shl 4;           fpCol.Red := Abs(color);           fpCol.Green := Abs(color);           fpCol.Blue := Abs(color);           Imagen[x, y] := fpCol;           Inc(src16);         end;       end;     end;     jpeg := TFPWriterJPEG.Create;     Imagen.SaveToFile('pepe.jpg', jpeg);     Imagen.Free;   end;                                                    /BlueIcaro ---------------------------------------------------------------------- marcov · 2021-03-26 16:18 Note that there is packed mono12 and normal mono12. Normal mono 12 has a 12-bit pixels per word, and the other bits zeroed or not important. However it can vary with camera if the upper or lower bits are used Packed mono12 packs two 12-bit pixels in a 3 bytes.  So the 2nd byte holds 4-bits of the first and 4-bits of the second pixel. Usually it is the highest bits of the first pixel in the lowest 4-bits and the lowest of the second pixel in the highest 4-bits, but depending on logic and sensor-logic connection this may vary in theory. packed mono12 exists e.g. in e.g. linescan cameras. ---------------------------------------------------------------------- BlueIcaro · 2021-03-26 19:26 Hi,  thanks marcov for the info. My camera sends the image un mono12, without any package.  And I don't need to swap the bytes. So I tested it and it's works fine. The camera (industrial camera) has a viewer program. I make a photo with this software, and it's the same photo that I make with my program. /BlueIcaro ---------------------------------------------------------------------- marcov · 2021-03-26 19:30 I don't even convert simple cases anymore. I do my measurements in 16-bit with some ANDs, and handle displaying in the opengl shader. ---------------------------------------------------------------------- BlueIcaro · 2021-03-26 19:37 My program, will run on a Nvida Jetson Nano, without gui. The photo will be send to other program (wrote in pyhton by other coworker) which will analize the photo, using AI. The coworker programs needs the photo in jpeg, I don't know why. That main problem is haven't GUI. So many library like  bgrabitmap , and vampire, etc. need a gui to work. QuoteI don't even convert simple cases anymore. I do my measurements in 16-bit with some ANDs, and handle displaying in the opengl shader. But your idea songs good. I would like more about it. Do you have any info/link/demo to take a look? May be in next project, I 'll have to make a program with the camera, and I have gui. Or may be I can use the gpu (shaders) to make something /BlueIcaro ---------------------------------------------------------------------- marcov · 2021-03-26 19:55 Some older code is in the first post here: https://forum.lazarus.freepascal.org/index.php/topic,30556.msg194627.h tml#msg194627 later I integrated the code into my work framework, and I currently don't have a standalone version. It is windows only, but that is mostly due the basic context routines and some of the font stuff. I advise to first play on windows before trying to port anything. ---------------------------------------------------------------------- lainz · 2021-03-26 23:18 Quote from: BlueIcaro on March 26, 2021, 08:37:51 pmThat main problem is haven't GUI. So many library like  bgrabitmap , and vampire, etc. need a gui to work. You can use BGRABitmap4NoGui target, that will work? ---------------------------------------------------------------------- BlueIcaro · 2021-03-27 14:35 Hi, if you create a program, add as requirmient BGRABitmaPack, and try this code: Code: [Select]program Project1; {$mode objfpc}{$H+} uses   {$IFDEF UNIX}{$IFDEF UseCThreads}   cthreads,   {$ENDIF}{$ENDIF}   Classes   { you can add units after this },   BGRABitmap; begin end.         As soon as you try to compile, you got a lot of errors, most of then talking Wsregister control QuoteCompilar proyecto, Objetivo: C:\Users\Jorge\AppData\Local\Temp\project1.exe: Código de salida 1, Errores: 16 project1.lpr(14,1) Error: Undefined symbol: WSRegisterCustomImageListResolution project1.lpr(14,1) Error: Undefined symbol: WSRegisterMenuItem project1.lpr(14,1) Error: Undefined symbol: WSRegisterMenu project1.lpr(14,1) Error: Undefined symbol: WSRegisterMainMenu project1.lpr(14,1) Error: Undefined symbol: WSRegisterPopupMenu project1.lpr(14,1) Error: Undefined symbol: WSRegisterDragImageListResolution project1.lpr(14,1) Error: Undefined symbol: WSRegisterLazAccessibleObject project1.lpr(14,1) Error: Undefined symbol: WSRegisterControl project1.lpr(14,1) Error: Undefined symbol: WSRegisterWinControl project1.lpr(14,1) Error: Undefined symbol: WSRegisterGraphicControl project1.lpr(14,1) Error: Undefined symbol: WSRegisterCustomControl project1.lpr(14,1) Error: Undefined symbol: WSRegisterScrollingWinControl project1.lpr(14,1) Error: Undefined symbol: WSRegisterScrollBox project1.lpr(14,1) Error: Undefined symbol: WSRegisterCustomFrame project1.lpr(14,1) Error: Undefined symbol: WSRegisterCustomForm project1.lpr(14,1) Error: Undefined symbol: WSRegisterHintWindow This test I did in w10 Lazarus 2.12, with BGRAbitmap install using OP. But In linux I have the same problem as I remember. I don't have linux in this PC. /BlueIcaro ---------------------------------------------------------------------- Fred vS · 2021-03-27 15:29 Hello. Tested your code in Linux (with light modifs for using cthreads) and there is no problem at compil + run. I dont have a Windows machine to test it now. Tested on Windows and all is ok too. 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 Project1; {$mode objfpc}{$H+} uses  {$IFDEF UNIX}  cthreads,  {$ENDIF}  Classes  { you can add units after this },  BGRABitmap; beginend.       I used fpc 3.2.0, Lazarus 2.0.10 and trunk BGRABitmap : https://github.com/bgrabitmap/bgrabitmap/tree/dev-bgrabitmap. [EDIT] Tested with Lazarus 2.0.12 and all is ok too here. Fre;D ---------------------------------------------------------------------- BlueIcaro · 2021-03-28 11:08 Hi Fred, I was making some test on Linux, and I found that OpenGl library was missing on my linux pc. After installing it, following this help https://wiki.lazarus.freepascal.org/BGRABitmap_and_OpenGL it's works fine! /BlueIcaro. P.D. In windows I don't know it doen't work. ---------------------------------------------------------------------- Fred vS · 2021-03-28 12:15 Quote from: BlueIcaro on March 28, 2021, 01:08:38 pmHi Fred, I was making some test on Linux, and I found that OpenGl library was missing on my linux pc. Does your application needs OpenGL? If no, OpenGL should not need to be installed. I will un-install  OpenGL and test a simple BGRABitmap application, if it fails to compile like you pointed, I will create a issue. Quote from: BlueIcaro on March 28, 2021, 01:08:38 pmP.D. In windows I don't know it doen't work. Hum, strange, here on Windows 10 all works out of the box.  Fre;D ---------------------------------------------------------------------- Fred vS · 2021-03-28 13:33 Hello BlueIcaro. OK, libGl.so  and OpenGL friends are uninstalled. Tested to run some applications that need OpenGL and, as expected, they crash or give error messages. So trying to compile your demo-test: 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 Project1; {$mode objfpc}{$H+} uses  {$IFDEF UNIX}  cthreads,  {$ENDIF}  Classes  { you can add units after this },   BGRABitmap; beginend.  And ... compilation is ok, runs ok too (as expected). QuoteHint: Start of reading config file /etc/fpc.cfg Hint: End of reading config file /etc/fpc.cfg Free Pascal Compiler version 3.2.0 [2020/06/20] for x86_64 Copyright (c) 1993-2020 by Florian Klaempfl and others. Target OS: Linux for x86-64 Compiling project1.pas Linking project1 14 lines compiled, 0.7 sec 2 hint(s) issued [EDIT] Here the command-line used: 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 -oproject1-Fu/home/fred/bgrabitmap-master/bgrabitmap- Fu/home/fred/lazarus/2.0.12/components/lazutils-Mobjfpc -Sh -Fcutf8 -B -XX -Xs -CX -vewinh-FUunits project1.pas Fre;D