Author Topic: Lazarus, Vampyre & MacOS?  (Read 8620 times)

Offline mos

  • Imaging User
  • *
  • Posts: 23
    • View Profile
Lazarus, Vampyre & MacOS?
« on: 22 October 2008, 19:32:37 »
Granted that I have not a Mac, but it's possible to compile Vampyre Library under MacOS with Lazarus?


Thanks

Offline Galfar

  • Administrator
  • Imaging User
  • *****
  • Posts: 351
    • View Profile
    • Galfar's Homepage
Re: Lazarus, Vampyre & MacOS?
« Reply #1 on: 22 October 2008, 21:33:36 »
Well, I don't know. I don't have a Mac either. It compiles in BSD Unix so I think it should work
in Mac OS X with none or little changes. Some file loaders in Imaging presume little endian machine so
newer Intel Mac would probably be needed.
Could someone with Mac test it?

Offline mos

  • Imaging User
  • *
  • Posts: 23
    • View Profile
Re: Lazarus, Vampyre & MacOS?
« Reply #2 on: 28 January 2009, 19:48:02 »
I'm trying the library under Mac OS X 10.5.4 Leopard (Intel), the compilation process work fine but the image colors are not correct.
In the attached file you can see the result with your Tigers.jpg.

Have you got any suggestion?


Thanks and goodbye

Offline Galfar

  • Administrator
  • Imaging User
  • *****
  • Posts: 351
    • View Profile
    • Galfar's Homepage
Re: Lazarus, Vampyre & MacOS?
« Reply #3 on: 28 January 2009, 20:11:15 »
Try to just save the loaded image without converting it to TBitmap (Image.Picture.Assign in your code)
and see if the saved images is garbled in the same way.

Also you can try loading/saving different image file formats, not just JPEG.

Thanks for Mac testing.

Offline mos

  • Imaging User
  • *
  • Posts: 23
    • View Profile
Re: Lazarus, Vampyre & MacOS?
« Reply #4 on: 30 January 2009, 13:54:35 »
I try this code:

Code: [Select]
...
    Image1: TImage;
    FBitmap1: TImagingBitmap;
    FImage1: TMultiImage;
...

  FImage1 := TMultiImage.Create;
  FBitmap1 := TImagingBitmap.Create;
  Image1.Picture.Graphic := FBitmap1;

  FImage1.LoadMultiFromFile('Tigers.jpg');
  Image1.Picture.Graphic.Assign(FImage1);

  Image1.Picture.SaveToFile('Tigers-1.jpg');
  FImage1.SaveToFile('Tigers-2.jpg');

in the attached files you can see the images displayed using the Preview of OSX.
The size of Tigers-1.jpg is 888KB, the size of Tigers-2.jpg is 48 and original Tigers.jpg size is 46KB.

So I think that problem is on conversion to bitmap, is it right?

Offline mos

  • Imaging User
  • *
  • Posts: 23
    • View Profile
Re: Lazarus, Vampyre & MacOS?
« Reply #5 on: 30 January 2009, 17:22:38 »
I also try this Low Level Interface of library:

Code: [Select]
  ImgJpeg := TImagingJpeg.Create;
  InitImage(ImgData);
  LoadImageFromFile('img002.jpg', ImgData);
  SaveImageToFile('img002-1.jpg', ImgData);
  ImgJpeg.AssignFromImageData(ImgData);
  ImgJpeg.SaveToFile('img002-2.jpg');
  Image1.Picture.Graphic := ImgJpeg;
  Image1.Picture.SaveToFile('img002-3.jpg');

and all the saved images (img002-1.jpg, img002-2.jpg, img002-3.jpg) are corrects.
Only the displayed image is garbled.

Instead if I use TImage component with this code:

Code: [Select]
Image1.Picture.LoadFromFile('img002.jpg');

the displayed image is ok.


« Last Edit: 30 January 2009, 17:32:18 by mos »

Offline Galfar

  • Administrator
  • Imaging User
  • *****
  • Posts: 351
    • View Profile
    • Galfar's Homepage
Re: Lazarus, Vampyre & MacOS?
« Reply #6 on: 31 January 2009, 13:46:19 »
Quote
The size of Tigers-1.jpg is 888KB
This is too much for JPEG, looks more like a BMP (original Tigers.jpg is 641x472 which with 24bit colors is approx 888KB).
Oh I see, it's TImagingBitmap so the image is always saved as bitmap regardless of file extension.

Yes, you're right, the problem is somewhere in image->TBitmap conversion.
I use Lazarus' RawImage interface for this, so I would guess it should work, but apparently it doesn't.
Which LCL widget set do you use in Mac OS X? Is Carbon used there as a default?

Offline mos

  • Imaging User
  • *
  • Posts: 23
    • View Profile
Re: Lazarus, Vampyre & MacOS?
« Reply #7 on: 31 January 2009, 14:05:49 »
I work on this platform:

Mac OSX 10.5.4 + XCode 3.0
Lazarus 0.9.26 (Carbon LCL Widget)
Imaging Library 0.26.2


Can you suggest me other test to find where is the problem?





Offline Galfar

  • Administrator
  • Imaging User
  • *****
  • Posts: 351
    • View Profile
    • Galfar's Homepage
Re: Lazarus, Vampyre & MacOS?
« Reply #8 on: 31 January 2009, 14:51:06 »
This is the code in ImagingComponets.pas in ConvertdataToBitmap function:
Code: [Select]
{$IFDEF COMPONENT_SET_LCL}
  // Create 32bit raw image from image data
  FillChar(RawImage, SizeOf(RawImage), 0);
  with RawImage.Description do
  begin
    Width := WorkData.Width;
    Height := WorkData.Height;
    BitsPerPixel := Info.BytesPerPixel * 8;
    Format := ricfRGBA;
    LineEnd := rileByteBoundary;
    BitOrder := riboBitsInOrder;
    ByteOrder := riboLSBFirst;
    LineOrder := riloTopToBottom;
    AlphaPrec := 8;
    RedPrec := 8;
    GreenPrec := 8;
    BluePrec := 8;
    AlphaShift := 24;
    RedShift := 16;
    GreenShift := 8;
    BlueShift := 0;
    Depth := 24;
  end;
  RawImage.Data := WorkData.Bits;
  RawImage.DataSize := WorkData.Size;

  // Create bitmap from raw image
  { If you get complitation error here upgrade to Lazarus 0.9.24+ }
  if RawImage_CreateBitmaps(RawImage, ImgHandle, ImgMaskHandle, False) then
  begin
    Bitmap.Handle := ImgHandle;
    Bitmap.MaskHandle := ImgMaskHandle;
  end;
{$ENDIF}
Maybe to create bitmaps for Carbon input image must be in slightly different format
than it is now (RawImage.Description used now describes ifA8R8G8B8 Imaging format).

I'll try to get MacOS working in VMWare so I could do some testing myself.
Any problems I might expect when installing and running Lazarus on MacOS?

Offline mos

  • Imaging User
  • *
  • Posts: 23
    • View Profile
Re: Lazarus, Vampyre & MacOS?
« Reply #9 on: 31 January 2009, 17:49:14 »
I also work on VMWare on WinXP+SP2, all works very fine, also Internet and local network.
But now my PC has got 4GB of RAM, because with 2GB I can't enable to install OSX on VMWare.
First I have installed XCode 3.0 then Lazarus 0.9.26 and at last Imaging Library.
In installation software I don't have found any problem, it's gone very smooth.

I continue with my tests:

First, I have converted Tigers.jpg to Tigers24.bmp (a 24 bit bitmap), so I have not any conversion in the code.

Then I execute this code:

ImgBmp: TImagingBitmap;
Image1: TImage;
...
ImgBmp := TImagingBitmap.Create;
ImgBmp.LoadFromFile('Tigers24.bmp');
Image1.Picture.Graphic := ImgBmp;
Image1.Picture.SaveToFile('Tigers24-3.bmp');

The image displayed on the form (Image1 instance of TImage) is garbled, instead Tigers24-3.bmp is correct.

After I execute this code:

ImgBmp: TBitmap;
Image1: TImage;
...
ImgBmp := TBitmap.Create;
ImgBmp.LoadFromFile('Tigers24.bmp');
Image1.Picture.Graphic := ImgBmp;
Image1.Picture.SaveToFile('Tigers24-3.bmp');

Where the only different is ImgBmp type. Both images, displayed and saved, are correct.


Offline Galfar

  • Administrator
  • Imaging User
  • *****
  • Posts: 351
    • View Profile
    • Galfar's Homepage
Re: Lazarus, Vampyre & MacOS?
« Reply #10 on: 1 February 2009, 02:13:28 »
I finally get MacOSX working in VMware.
I got the same results as you did. The problem is definitely where we suspected
(tried console app Imaging demos - these work fine).
See the messages in terminal on attached image: looks like during the
conversion it tries to create 6bits! per channel Carbon bitmap.
I'll have a look at Lazarus' source code regarding this conversion.
Maybe there's bug or it doesn't handle raw image with the parameters set by Imaging.

Can you change display resolution in your MacOSX VMware machine? I only get 1024x768 mode.



Offline mos

  • Imaging User
  • *
  • Posts: 23
    • View Profile
Re: Lazarus, Vampyre & MacOS?
« Reply #11 on: 1 February 2009, 13:07:36 »
With the 2nd method found on this tutorial http://pcwizcomputer.com/index.php?option=com_content&task=view&id=31&Itemid=32 I have set my resolution to 1440x900.


Offline Galfar

  • Administrator
  • Imaging User
  • *****
  • Posts: 351
    • View Profile
    • Galfar's Homepage
Re: Lazarus, Vampyre & MacOS?
« Reply #13 on: 2 February 2009, 00:01:57 »
Thanks for the tips!

I now know where these 6bits per channel came from. As stated in the docs you
linked Carbon bitmaps can only be 8/16/32 bit.
Raw image used by LCL to create Carbon bitmap has two fields
BitsPerPixel and Depth. Imaging sets BitsPerPixel to 32 and Depth to 24.
LCL apparently uses Depth/NumChannels as channel size when calling CGBitmapContextCreate
so we get 24/4 = 6 bits.

Fix for this is simple, just set Depth field to 32 (ImagingComponents.pas line 587).

Offline mos

  • Imaging User
  • *
  • Posts: 23
    • View Profile
Re: Lazarus, Vampyre & MacOS?
« Reply #14 on: 2 February 2009, 16:34:15 »
Thank you very much, now I'm happy and I can continue to use your fantastic library!