Jump to content
John van de Waeter

iOS, Metal, Bitmaps, RGB becomes BGR?

Recommended Posts

Hi All,

 

I use Metal in a iOS FMX project like:

 

 if TUIScreen.Wrap(TUIScreen.OCClass.mainScreen).nativeScale=TUIScreen.Wrap(TUIScreen.OCClass.mainScreen).Scale
   then
    begin
      GlobalUseMetal:=true; 
      GlobalEventDrivenDisplayUpdates:=false;
      GlobalPreferredFramesPerSecond:=60;
    end;

 

I use Media-Camera action TakePhotoFromCamera OnDidFinishTaking and assign the bitmap to a TImage.Bitmap.

 

This used to work okay, but now on Delphi11 it produces an image in which Red and Blue are interchanged.

 

Same thing happens if I paste an image from the clipboard.

Same thing happens if I get an image from the gallery.

 

Image.Bitmap.Loadfromfile('animage.jpg') and dito .png works okay.

 

If I turn off Metal, all is okay. Tested on iPhone5 and iPhone8.

 

 

Any thougts?

tia, John

 

Edited by John van de Waeter

Share this post


Link to post

Do I understand you right, that with 10.4 all works fine, but now with Delphi 11 not? Then I think you should open a QR-Report at jira.

 

In fact on macOS the bitmaps are in BGR order, but pasting images from the clipboard or getting images from the gallery should take this into account.

Share this post


Link to post

Did you try to move the metal initialization into the .dpr file? I think it's mandatory.

Something like in this example (to adapt for your need)

{$IF defined(MACOS)}
	if TCustomContextMetal.IsMetalSupported then
	GlobalUseMetal := True;
{$ENDIF}
Application.Initialize;
Application.CreateForm(TFormMain, FormMain);
Application.Run;

 

I faced several problems when in the main application, it didn't work or even produced errors.
Someone here told me that, according to the documentation this has to be set into the DPR file.

 

 

 
  • Like 1

Share this post


Link to post

Hi John,

 

First word that popped into my head was, endianness.

Use to pass data between old mpus.

looking at timage.LoadFromStream, it calls the TBitmapCodecManager.LoadFromStream who then passes it off to the CodecClass

but that's where i stop as the function to get the correct CodecClass is in fact called GuessCodecClass() , so your guess is as good as mine..

frack it, flip all the bits..

 

Sorry, no help..

 

 

Share this post


Link to post

This is also happening with my app taking photos. When I include Metal support some of the colors are off. When I disable it, the color are right.

 

Thanks

Share this post


Link to post

This problem is automatically fixed when you replace the FMX canvas with the Skia4Delphi canvas.

 

program Poject1;

uses
  System.StartUpCopy,
  FMX.Forms,
  FMX.Types,
  Skia.FMX
  Unit1 in 'Unit1.pas' {Form1};

{$R *.res}

begin
  GlobalUseMetal := True;
  GlobalUseSkia := True;
  Application.Initialize;
  Application.CreateForm(TForm1, Form1);
  Application.Run;
end.

 

Share this post


Link to post

I used the Getit Package manager to install Skia. When I use GlobalUseSkia:=true I get

[DCC Error] MultiPic.dpr(31): E2003 Undeclared identifier: 'GlobalUseSkia'

 

Thanks

Share this post


Link to post
24 minutes ago, ginnix said:

I used the Getit Package manager to install Skia. When I use GlobalUseSkia:=true I get

[DCC Error] MultiPic.dpr(31): E2003 Undeclared identifier: 'GlobalUseSkia'

 

Thanks

The GetIt is out of date yet (version 2.0.1). You should download version 3, Skia4Delphi_3.0.0_Setup.exe, which you will find on the releases page: https://github.com/skia4delphi/skia4delphi/releases

Share this post


Link to post

I download version 3 and everything is working. 

 

Is there an example on how to move a Timage to the Skia canvas?

 

Thanks for this great software 🙂

Share this post


Link to post

Your TImage is already using Skia Canvas. When you replace the default Canvas of FMX to the Skia4Delphi Canvas (by setting 

GlobalUseSkia := True;), every control in form will be draw automatically using the Skia Canvas, including the TImage.
Edited by vfbb

Share this post


Link to post

It does not seem to work with the CameraComponent.

 

When I use Skia all the colors are wrong. When I disable Skia everything works.

 

  • Like 1

Share this post


Link to post
13 hours ago, ginnix said:

It does not seem to work with the CameraComponent.

 

When I use Skia all the colors are wrong. When I disable Skia everything works.

 

Thanks for the report. I'll check TCamera again. Any new issue you can report us in GitHub

Share this post


Link to post

There seems to be a problem with Skia and GlobalUseMetal  under ios when you use

both in a project.

 

The problem happens when you send the image to the photos app.

 

 if not TPlatformServices.Current.SupportsPlatformService(IFMXPhotoLibrary, Service) then
   exit;
   Service.AddImageToSavedPhotosAlbum(Image1.Bitmap);

 

The colors are wrong when you view the bitmap in Photos

 

Thanks

 

 

 

 

Share this post


Link to post

@ginnix Fixed this issue in new version v3.3.0

 

Quote

- Fixed wrong colors in iOS with services when using Skia4Delphi Canvas: IFMXTakenImageService, IFMXCameraService, IFMXPhotoLibrary and IFMXShareSheetActionsService;

 

Share this post


Link to post

 

11 hours ago, John van de Waeter said:

What is the minimal Android version supported?
On Android 6 I get an OpenGLES error (3009)...

It supports Android 4.1 JellyBean+. I will test it ASAP.

  • Thanks 1

Share this post


Link to post
On 4/5/2022 at 10:20 AM, John van de Waeter said:

Hi VFBB,

What is the minimal Android version supported?
On Android 6 I get an OpenGLES error (3009)...

Cheers,

John

 

The problem was fixed in new version 3.3.2.

Fix: We support Android 5+

 

Share this post


Link to post

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

×