• Welcome to Vampyre Imaging Library Forum. Please login or sign up.

Lazarus, Vampyre & MacOS?

Started by mos, 22 October 2008, 19:32:37

Previous topic - Next topic


Granted that I have not a Mac, but it's possible to compile Vampyre Library under MacOS with Lazarus?



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?


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


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.


I try this code:

    Image1: TImage;
    FBitmap1: TImagingBitmap;
    FImage1: TMultiImage;

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



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?


30 January 2009, 17:22:38 #5 Last Edit: 30 January 2009, 17:32:18 by mos
I also try this Low Level Interface of library:

  ImgJpeg := TImagingJpeg.Create;
  LoadImageFromFile('img002.jpg', ImgData);
  SaveImageToFile('img002-1.jpg', ImgData);
  Image1.Picture.Graphic := ImgJpeg;

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:


the displayed image is ok.


QuoteThe 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?


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?


This is the code in ImagingComponets.pas in ConvertdataToBitmap function:
  // Create 32bit raw image from image data
  FillChar(RawImage, SizeOf(RawImage), 0);
  with RawImage.Description do
    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;
  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
    Bitmap.Handle := ImgHandle;
    Bitmap.MaskHandle := ImgMaskHandle;

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?


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;
Image1.Picture.Graphic := ImgBmp;

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;
Image1.Picture.Graphic := ImgBmp;

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


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.



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).


Thank you very much, now I'm happy and I can continue to use your fantastic library!

Quick Reply

With Quick-Reply you can write a post when viewing a topic without loading a new page. You can still use bulletin board code and smileys as you would in a normal post.


Shortcuts: ALT+S save/post or ALT+P preview

SMF spam blocked by CleanTalk