Recent

Author Topic: Image manipulation in Lazarus  (Read 35515 times)

Leledumbo

  • Hero Member
  • *****
  • Posts: 8310
  • Programming + Glam Metal + Tae Kwon Do = Me
RE: Re: RE: Re: Image manipulation in Lazarus
« Reply #15 on: January 15, 2008, 04:47:34 am »
I'm sorry, what are these:
Code: [Select]

bmp.SaveToStream(memstream);
memstream.position := 0;
bmp.LoadFromStream(memstream);

for?

theo

  • Global Moderator
  • Hero Member
  • *****
  • Posts: 1891
RE: Re: RE: Re: Image manipulation in Lazarus
« Reply #16 on: January 15, 2008, 01:03:12 pm »
http://wiki.lazarus.freepascal.org/Developing_with_Graphics#Drawing_color_transparent_bitmaps
Quote

Notice the memory operations performed with the TMemoryStream. They are necessary to ensure the correct loading of the image.

Leledumbo

  • Hero Member
  • *****
  • Posts: 8310
  • Programming + Glam Metal + Tae Kwon Do = Me
RE: Re: RE: Re: Image manipulation in Lazarus
« Reply #17 on: January 21, 2008, 09:30:55 am »
I've finally found the easiest way, Vampyre Imaging Library
This one really has everything needed to manipulate images! Thanks for everyone's response.

anna

  • Sr. Member
  • ****
  • Posts: 426
Re: RE: Re: RE: Re: Image manipulation in Lazarus
« Reply #18 on: May 11, 2013, 12:50:10 pm »
Hi, i'm trying to convert binary to image to store my data on image-hosting . So my example. Put Button1 on Form1. Copy click handler:
Code: [Select]
uses
  Classes, SysUtils, LCLType, LResources, Forms, Controls, Graphics, Dialogs,
  Buttons, FPImage, IntfGraphics,Math, StdCtrls,

  graphtype,windows;   

{...}

procedure TForm1.Button1Click(Sender: TObject);
var
  IntfImg1, IntfImg2: TLazIntfImage;

var
    ms:tmemorystream;
    dwFileCont:dword;

    lRawImage: TRawImage;
    AUXw,AUXh:integer;
    s_unique_num:string;
    Frequency,Duration:dword;
begin
  try
    Ms := TMemoryStream.Create;
    ms.LoadFromFile(ExtractFilePath(paramstr(0))+'project1.exe');
    dwFileCont:=pdword(pdword(@ms)^+4)^;

        AUXw :=trunc(sqrt(ms.Size/4));
        AUXh:= AUXw;
        if  4*AUXw*AUXh<ms.Size then  AUXw:=AUXw+1;
        if  4*AUXw*AUXh<ms.Size then  AUXh:=AUXh+1;

        lRawImage.Init;
        lRawImage.Description.Init_BPP32_A8R8G8B8_BIO_TTB(AUXw,AUXh);
        lRawImage.CreateData(True);
        lRawImage.Data:=pbyte(dwFileCont);
        IntfImg1 := TLazIntfImage.Create(0,0);
        IntfImg1.SetRawImage(lRawImage);
        //sleep(dword(lRawImage.data));
        s_unique_num:=FormatDateTime('yymmddhhnnss', now);
        IntfImg1.SaveToFile(ExtractFilePath(paramstr(0))+'testimage'+s_unique_num+'.png');

        lRawImage.Init;
        lRawImage.Description.Init_BPP32_A8R8G8B8_BIO_TTB(0,0);
        lRawImage.CreateData(false);
        IntfImg2:=TLazIntfImage.Create(0,0);
        IntfImg2.SetRawImage(lRawImage);
        IntfImg2.LoadFromFile(ExtractFilePath(paramstr(0))+'testimage'+s_unique_num+'.png');
        IntfImg2.GETRawImage(lRawImage);
        //sleep(dword(lRawImage.data));


  finally
    IntfImg1.Free;
    IntfImg2.Free;
    //Ms.Free;  {stupid SIGSEG error}

    (*
    Duration:=$64;
    Frequency:=$417;
    windows.beep(Frequency,Duration);
    Duration:=$64;
    Frequency:=$455;
    windows.beep(Frequency,Duration);
    Duration:=$64;
    Frequency:=$497;
    windows.beep(Frequency,Duration);
                *)

    Duration:=$64;
    Frequency:=$82D;
    windows.beep(Frequency,Duration);
    Duration:=$64;
    Frequency:=$7B8;
    windows.beep(Frequency,Duration);
    Duration:=$64;
    Frequency:=$741;
    windows.beep(Frequency,Duration);
                (*
    Duration:=$1F4;
    Frequency:=$28;
    windows.beep(Frequency,Duration);
                *)
  end;

end;     

But it does not save PNG-image with thansparency. Transparent-byte swithced to $FF everywhere:
http://img826.imageshack.us/img826/6610/38724552.png (I've uncommented second sleep and set breakpoint on "sleep" procedure).
« Last Edit: May 11, 2013, 12:55:35 pm by anna »
WinXP SP3 Pro Russian 32-bit (5.1.2600)

anna

  • Sr. Member
  • ****
  • Posts: 426
Re: RE: Re: RE: Re: Image manipulation in Lazarus
« Reply #19 on: May 11, 2013, 03:16:50 pm »
Where is sources for these files:
"C:\lazarus\fpc\2.7.1\units\i386-win32\fcl-image\fpimage.o" "C:\lazarus\fpc\2.7.1\units\i386-win32\fcl-image\fpimage.ppu"
Lazarus' debugger can't set breakpoint on source code of fpimage unit. Why?

Also I cannot see blue dots by left side of source of fpimage unit. So this unit is not recompiled by running project. Why?
WinXP SP3 Pro Russian 32-bit (5.1.2600)

anna

  • Sr. Member
  • ****
  • Posts: 426
Re: RE: Re: RE: Re: Image manipulation in Lazarus
« Reply #20 on: May 11, 2013, 03:58:28 pm »
I solve my problem by adding special saving procedure:
 
  procedure SaveToPng(const src_SaveToPng: TLazIntfImage; PngFileName: String);
    var
      png : TPortableNetworkGraphic;
    begin
      png := TPortableNetworkGraphic.Create;
      try
        png.Assign(src_SaveToPng);
        png.SaveToFile(PngFileName);
      finally
        png.Free;
      end;
    end; 


But why TLazIntfImage does not have this feature? Why I myst go roundabout road ?
« Last Edit: May 11, 2013, 04:50:18 pm by anna »
WinXP SP3 Pro Russian 32-bit (5.1.2600)

Leledumbo

  • Hero Member
  • *****
  • Posts: 8310
  • Programming + Glam Metal + Tae Kwon Do = Me
Re: Image manipulation in Lazarus
« Reply #21 on: May 11, 2013, 05:43:35 pm »
Quote
Where is sources for these files
$(fpcdir)/packages/fcl-image, I think you can easily guess from the unit path.
Quote
Lazarus' debugger can't set breakpoint on source code of fpimage unit. Why?
The units are probably not compiled with debugging information, which I guess is the default if you don't supply additional compiler option when building the package. I assume you compile from source, if you get the compiler (probably the ide as well) elsewhere, it's likely no other option is given.
Quote
Also I cannot see blue dots by left side of source of fpimage unit. So this unit is not recompiled by running project. Why?
fpc (rtl and packages) units are plain units, they're not shipped in lazarus package form. The ide NEVER feeds their source to the compiler (which is a good thing), unless you specify in your project's unit path (which is a bad thing), it only uses the source for autocompletion.

anna

  • Sr. Member
  • ****
  • Posts: 426
Re: Image manipulation in Lazarus
« Reply #22 on: May 11, 2013, 05:49:30 pm »
I have another question. How to save 64-bit image? Even with special saving procedure, it saves 32-bit image. Is there 64-bit Init procedure?Maybe I must make it by hands:

procedure TRawImageDescription.Init_BPP64_A16R16G16B16_BIO_TTB(AWidth, AHeight: integer);
begin
  FillChar(Self, SizeOf(Self), 0);
  Format := ricfRGBA;
  Depth := 64; // used bits per pixel
  Width := AWidth;
  Height := AHeight;
  BitOrder := riboBitsInOrder;
  ByteOrder := riboLSBFirst;
  LineOrder := riloTopToBottom;
  BitsPerPixel := 64; // bits per pixel. can be greater than Depth.
  LineEnd := rileDWordBoundary;
  RedPrec := 16; // red precision. bits for red
  RedShift := 16;
  GreenPrec := 16;
  GreenShift := 32; // bitshift. Direction: from least to most signifikant
  BluePrec := 16;
  BlueShift := 48;
  AlphaPrec := 16;
  AlphaShift := 0;
//  MaskBitsPerPixel := 0;
end;     



I have added this init , but project saves 32-bit. And why GraphType unit recompiled? As you said it impossible. Ah?


As I can see TLazIntfImage just adds one more byte for each in RawDate. So TLazIntfImage is not fully 64-bit component - it just 32bit+ duplicate. Isn't it?
« Last Edit: May 11, 2013, 05:58:35 pm by anna »
WinXP SP3 Pro Russian 32-bit (5.1.2600)

Fred vS

  • Hero Member
  • *****
  • Posts: 2089
    • StrumPract is the musicians best friend
Re: Image manipulation in Lazarus
« Reply #23 on: May 11, 2013, 06:26:08 pm »
Quote
So TLazIntfImage is not fully 64-bit component - it just 32bit+ duplicate. Isn't it?

What OS do you use ? It seems that, for the Windows Lazarus 64 bit version, the default compiler is 32 bit. You have to compile the fpc-source 64 bit to have a real 64 bit compiler.

But maybe that has nothing to do with your problem... :-[
I use Lazarus 2.0.6 32/64 and FPC 3.2.0 32/64 on Debian 10.2 64 bit, Windows 10, Windows 7 32/64, Windows XP 32,  FreeBSD 64 and Mac OS X Snow Leopard 32.
Widgetset: fpGUI, MSEgui, Win32, GTK2, Qt, Carbon.

https://github.com/fredvs
https://gitlab.com/fredvs

anna

  • Sr. Member
  • ****
  • Posts: 426
Re: Image manipulation in Lazarus
« Reply #24 on: May 11, 2013, 06:39:48 pm »
Quote
So TLazIntfImage is not fully 64-bit component - it just 32bit+ duplicate. Isn't it?

What OS do you use ? It seems that, for the Windows Lazarus 64 bit version, the default compiler is 32 bit. You have to compile the fpc-source 64 bit to have a real 64 bit compiler.

But maybe that has nothing to do with your problem... :-[
My OS is WinXP SP3 Pro Russian 32-bit. Lazarus: Lazarus-1.1-41044-fpc-2.7.1-20130506-win32.exe
But on my 32-bit system I can see 64-bit PNG files. So colours is not connected with OS' Bit depth
WinXP SP3 Pro Russian 32-bit (5.1.2600)

User137

  • Hero Member
  • *****
  • Posts: 1791
    • Nxpascal home
Re: Image manipulation in Lazarus
« Reply #25 on: May 11, 2013, 06:42:08 pm »
Is there no Load.../SaveToStream()? You wouldn't need anything related to RawImage in your code then.

Fred vS

  • Hero Member
  • *****
  • Posts: 2089
    • StrumPract is the musicians best friend
Re: Image manipulation in Lazarus
« Reply #26 on: May 11, 2013, 06:45:42 pm »
Quote
My OS is WinXP SP3 Pro Russian 32-bit. Lazarus: Lazarus-1.1-41044-fpc-2.7.1-20130506-win32.exe

Ok, so nothing to do with your problem...

PS : Could you add that description of your system in your profile ?
(Profile > Forum Profile > Signature)

Thanks
I use Lazarus 2.0.6 32/64 and FPC 3.2.0 32/64 on Debian 10.2 64 bit, Windows 10, Windows 7 32/64, Windows XP 32,  FreeBSD 64 and Mac OS X Snow Leopard 32.
Widgetset: fpGUI, MSEgui, Win32, GTK2, Qt, Carbon.

https://github.com/fredvs
https://gitlab.com/fredvs

Leledumbo

  • Hero Member
  • *****
  • Posts: 8310
  • Programming + Glam Metal + Tae Kwon Do = Me
Re: Image manipulation in Lazarus
« Reply #27 on: May 11, 2013, 06:55:08 pm »
Quote
And why GraphType unit recompiled? As you said it impossible. Ah?
GraphType is not part of fcl-image, it's part of LCL.
Quote
So TLazIntfImage is not fully 64-bit component - it just 32bit+ duplicate. Isn't it?
Perhaps, 64-bit image is just too much I guess. Unless the writing/reading method is separated per depth/bpp, it could be a noticable slow down.
 
@Fred:
What anna means is 64-bit image, it's not related to architecture.
« Last Edit: May 11, 2013, 06:57:01 pm by Leledumbo »

taazz

  • Hero Member
  • *****
  • Posts: 5365
Re: Image manipulation in Lazarus
« Reply #28 on: May 11, 2013, 06:55:44 pm »
I do not think that there exists any graphics card that supports 64bit images. Just to make sure what you are saying a 64bit image should be what photoshop call a 16bit color depth. aka 2 bytes per color (including alpha channel) instead of one.
This is not support currently and it will probably not be supported until the hardware starts to support that kind of color depth.
Good judgement is the result of experience … Experience is the result of bad judgement.

OS : Windows 7 64 bit
Laz: Lazarus 1.4.4 FPC 2.6.4 i386-win32-win32/win64

anna

  • Sr. Member
  • ****
  • Posts: 426
Re: Image manipulation in Lazarus
« Reply #29 on: May 11, 2013, 07:05:55 pm »
This is not support currently
First image in google my Opera Browser can show and Opera even says right color depth:
http://img819.imageshack.us/img819/7910/55140694.png

For my problem it is not important to see all 2^64 colours. It's important to restore correctly data encrypted  inside of  image. I am using OllyDBG to test decrypted data. And it absolutelly not equal input data (in my example it is project executable).
« Last Edit: May 11, 2013, 07:08:58 pm by anna »
WinXP SP3 Pro Russian 32-bit (5.1.2600)

 

TinyPortal © 2005-2018