ImageEn for Delphi and C++ Builder ImageEn for Delphi and C++ Builder

 

ImageEn Forum
Profile    Join    Active Topics    Forum FAQ    Search this forumSearch
Forum membership is Free!  Click Join to sign-up
Username:
Password:
Save Password
Forgot your Password?

 All Forums
 ImageEn Library for Delphi, C++ and .Net
 ImageEn and IEvolution Support Forum
 JPEG2000 raw pixels without metadata
 New Topic  Reply to Topic
Author Previous Topic Topic Next Topic  

JanB

2 Posts

Posted - Mar 17 2024 :  11:06:02  Show Profile  Reply
Hello!

I try to access the pixel data of jp2 file. The jp2 file has additional xml informations at the beginning of the file.
Is there any way to access only the RGBA values of the jp2 file without the xml informations at the beginning?

Here 2 attempt which didn't seem to work:

var
  ABmp: TIEBitmap;
  ABytes, CurrBytePos: PByte;
  ARow: Integer;
  ASize: Int64;
begin
  ABmp := TIEBitmap.Create;
  ABytes := nil;
  try
    ABmp.Read('T33UUS_20240303T100819_TCI_10m.jp2');
    ASize := ABmp.Rowlen * ABmp.Height;
    GetMem(ABytes, ASize);
    CurrBytePos := ABytes;
    for ARow := 0 to ABmp.Height - 1 do begin
      Move(ABmp.ScanLine[0]^, CurrBytePos^, ABmp.Rowlen);
      inc(CurrBytePos, ABmp.Rowlen);
    end;
  finally
    ABmp.Free;
    if (Assigned(ABytes)) then
      FreeMem(ABytes);
  end;
end;



var
  ABmp: TIEBitmap;
  ABytes, CurrBytePos: PByte;
  ARow, ACol: Integer;
  ASize: Int64;
  ARGBA: TRGBA,
begin
  ABmp := TIEBitmap.Create;
  ABytes := nil;
  try
    ABmp.Read('T33UUS_20240303T100819_TCI_10m.jp2');
    ASize := ABmp.Rowlen * ABmp.Height;
    GetMem(ABytes, ASize);
    CurrBytePos := ABytes;
    for ARow := 0 to ABmp.Height - 1 do begin
      for ACol := 0 to ABmp.Width - 1 do begin
        ARGBA := AImage.IEBitmap.Pixels_ie32RGB[ACol, ARow];
        PRGBA(CurrBytePos)^ := ARGBA;
        inc(CurrBytePos, SizeOf(TRGBA));
      end;
    end;
  finally
    ABmp.Free;
    if (Assigned(ABytes)) then
      FreeMem(ABytes);
  end;
end;


I checked out the EncapsulateFromMemory method as well, but it seems to behave as the written code above.

Example File (128MB) so I uploaded it somewhere else:
https://www.file-upload.net/download-15285284/T33UUS_20240303T100819_TCI_10m.jp2.html

In additional I have to work with the raw pixels to perform other calculation after reading the files and I try to keep it as fast as possible. So the pixel data has to stay as they are, no transformations, that might change these values.

How can I access the raw pixel data from jp2 file?

Regards
Jan

JanB

2 Posts

Posted - Mar 17 2024 :  13:29:18  Show Profile  Reply
I checked my 2nd approach and it uses the wrong pixel data it should be Pixels_ie24RGB.

var
  ABmp: TIEBitmap;
  ABytes, CurrBytePos: PByte;
  ARow, ACol: Integer;
  ASize: Int64;
begin
  ABmp := TIEBitmap.Create;
  ABytes := nil;
  try
    ABmp.Read('T33UUS_20240303T100819_TCI_10m.jp2');
    ASize := ABmp.Rowlen * ABmp.Height;
    GetMem(ABytes, ASize);
    CurrBytePos := ABytes;
    for ARow := 0 to ABmp.Height - 1 do begin
      for ACol := 0 to ABmp.Width - 1 do begin
        case (ABmp.PixelFormat) of
          ie32RGB: begin
            PRGBA(CurrBytePos)^ := ABmp.Pixels_ie32RGB[ACol, ARow];
            inc(CurrBytePos, SizeOf(TRGBA));
          end; 
          ie24RGB: begin
            PRGB(CurrBytePos)^ := ABmp.Pixels_ie24RGB[ACol, ARow];
            inc(CurrBytePos, SizeOf(TRGB));
          end; 
        end;
      end;
    end;
  finally
    ABmp.Free;
    if (Assigned(ABytes)) then
      FreeMem(ABytes);
  end;
end;
Go to Top of Page

xequte

38608 Posts

Posted - Mar 17 2024 :  16:10:58  Show Profile  Reply
Hi

To avoid any pixel conversions, you should also be using:

Abmp.Params.NativePixelFormat := True;

https://www.imageen.com/help/TIOParams.NativePixelFormat.html

Nigel
Xequte Software
www.imageen.com
Go to Top of Page
  Previous Topic Topic Next Topic  
 New Topic  Reply to Topic
Jump To: