Transparent image

i’ve seen it too late…;). @Michel Bujardet

I experimented again last night. The pixel method is slow, but it works. That will be OK for the moment.

Thank you Jean Paul. I wonder what is used to power the classic Transparent function.

I just found a CIFIlter solution for that problem. See the Chroma key filter entry here: https://developer.apple.com/library/content/documentation/GraphicsImaging/Conceptual/CoreImaging/ci_filer_recipes/ci_filter_recipes.html

The color cube isn’t the easiest of objects. I’ll try to look at it more closely the next days. Should make it possible to work in (almost) real-time.

Great news Ulrich !

I suspected there must be something available in the framework.

Thank you.

Don’t rejoice too early, Michel: I still ponder over the CLUT data in the ColorCube structure. If you should find any useful information beyond Apple’s documentation, let me know!

Sure. Thank you.

Ta-da!

(Removed every blue > 30 and < 128 and replaced it with transparency - it‘s the same image as above in this thread.)
I’ll upload it tomorrow to the repository and add a short explanation to the CIFIlter thread.

Ulrich, you’re a genius :slight_smile:

No, Michel, but thanks. It wasn’t complicated anymore when I tried to rebuild Apple’s demo in Xojo.

Let me admit I am a bit proud of the solution: The colorCube is a 3D color lookup table, like a colorspace model. Each side of the cube can be between 2 and 128 values long, which gives you the opportunity to define as litte as the two extreme values for each color channel or every second possible color in a 24 Bit color system.
You can, for example, create a colorCube with a size of 2. It will contain the RGB(A) values for all combinations of R, G and B being 0 and 1. If you want the colorCube to invert an image, simply invert the RGB values in the cube and white will become black and vice versa. Color values in between are calculated as Splines. A colorCube of size 3 will contain each RGB combination of the values 0, 0.5, 1.0 and so on …

It would be puzzling to set the values for selected color coordinates manually. That’s why you’ll find an AppleLibColorCube class that takes two parameters in its constructor:

Size As Integer (the size of a cube’s edge, a value between 2 and 128) and ColorChanger As ColorChangerDelegate.
The latter one is simply a method that takes a color and returns a color.

The AppleLibColorCube class simply builds a standard color cube of the specified size and calls the delegate for each step. It then takes the delegate’s return value and enters this color value into the current coordinates.
The delegate method for the image above was

 return if (input.Blue < 128 and input.Blue > 30 ,  RGB(255,255, 255, 255), Input)

In many cases it will be appropriate to examine the HSV values and determine if the Hue value is within a certain range, so you don’t change one single color but, like Apple’s demo shows, all greens or so.
The full code to use a CIColorCube filter is like

dim cube as new AppleLibColorCube(80, addressof colorchangeMethod) filter = new AppleCIColorCube(originalPicture, cube)
(and then take the filter.outputCIImage.toPicture/toiOSImage property)

The size defines the precision of the cube. Building a maximum size cube takes a short time, but usually you don’t need such big sizes. The rendering itself is amazingly fast, like with all CIFilters.

And now the bad news: I noticed I ruined my ScrollView on macOS and will try to fix it before I upload all the stuff. So much for genius :wink:

Sorry, Michel, this takes a bit longer than expected:
For one, a failed kext install yesterday forced me to spend the day with a TimeMachine rollback. I didn’t know safe mode is unavailable on an encrypted drive …
And then I realized I have to redesign my responder structure because it doesn’t work nicely with Inspector behavior and brings a lot of trouble with inheritances. If you should need the filters alone, I can send you the library privately. Otherwise this could take a few days.
At least, I spent the time the backup was installing with my laptop and added a few more filters for picture analysis: Pixel or area average colors, histograms and similar.

Ulrich, it is alright. There is this rule in computing that such things happen at the worst possible time. At any rate, I am still far from completing my project. Porting from Desktop to iOS seems easy on the surface, but the difference in UI are so many.

I see myself creating everyday a new dialog, a new custom control. Today I was finishing a dialog where user picks between Camera, Camera Roll, PhotoLibrary, and Document folder. The first three are the existing control, the third one is an image picker I made for picture files in the document folder. I have been on that for a couple days, and just finished tonight…

And I am almost certain that you know these moments when nothing seems to work anymore and you don’t have a clue what you changed to make it happen. Well, after I thought I would never get my head around this, the weekend finally becomes a happy one. I trapped myself in my own wrappers. It worked out so nicely with the events being caught that I did not consider that from time to time you create views in code only, so if they rely on a custom class their events will always return the event default which is not necessarily the original class default.

After I thought I ruined the scrollview I found out that the imageView I took as contentView did never lose the focus because its custom event handler says so – if you create it in the IDE it will have a wrapper that handles it, but not if you create it in code. I had some sleepless nights because I could not stop pondering about what I changed and why the ScrollView did not respond to anything anymore except for resizes.

To handle all this stuff, the constructors of classes deriving from view and control classes will be extended with a “DontRegister” Boolean (Default False). If it is true, the standard classptr is used for their creation, so it will always return the correct class values. Their events will not fire then. Phew. May still take a few days, but I finally found it.

The good news is it should be quite easy to create own sub controls. Apple’s inheritance scheme is fully rebuilt, so you can just import responder, view or whatever superclass “delegate” methods are defined along the way.

It’s uploaded now, @Michel : The CIFilter demo in iOSlib is in beta. Some filters crash the demo, and it’s no fun waiting for them in Simulator where they are simulated via the CPU. But I made sure the CIColorCube filter does work. You should not use big cubes – they are likely to crash the device. So a cube of size 128 is way too much for an iPhone. I reduced it the demo to a size of 40 which works on an iPhone 6, but you might need to change the size for smaller iPhones. A few filters are disabled in the demo currently and I have to fine tune a few filter parameters to the device’s size.

iOS 10 is recommended for tests because many filters have been added recently. I’ll try to fix the conversion that doesn’t not work for endless images the next days.

Been there, done that… as a matter of fact… Am there RIGHT NOW :slight_smile:

He’s an idiot, I liked that logo the moment I first saw it. Nice clean edges, professional work, I salute you sir.[quote=292821:@Ulrich Bogun]The color cube isn’t the easiest of objects. I’ll try to look at it more closely the next days. Should make it possible to work in (almost) real-time.[/quote]
I used it once or twice, mainly to replicate the xojo RGBSurface.Transform function. But now I use the gradientMap filter , while you can only create a CIFilter gradient from two colors, you can combine gradient images into one.

[quote=294336:@Ulrich Bogun]It’s uploaded now, @Michel : The CIFilter demo in iOSlib is in beta. Some filters crash the demo, and it’s no fun waiting for them in Simulator where they are simulated via the CPU. But I made sure the CIColorCube filter does work. You should not use big cubes – they are likely to crash the device. So a cube of size 128 is way too much for an iPhone. I reduced it the demo to a size of 40 which works on an iPhone 6, but you might need to change the size for smaller iPhones. A few filters are disabled in the demo currently and I have to fine tune a few filter parameters to the device’s size.

iOS 10 is recommended for tests because many filters have been added recently. I’ll try to fix the conversion that doesn’t not work for endless images the next days.[/quote]

Super. Thank you Ulrich. I will download iOSLib now.

Ulrich, I downloaded the master from your git, but am a bit puzzled. When I start iOSLIb Unified, it wants the folder “Foundation protocols”. I searched for it an did not locate it. Then I click Open without selecting anything, and the project opens.

When I run, I get 6 errors :

The constructor of this class is protected, and can only be called from within its class
d = new iOSTableCellData

Oh sorry – I should install a note on that repository that it will be closed soon. Try this here please:

https://github.com/UBogun/Xojo-AppleLib

EDIT: Done – changed the repository info. See this thread here too please:
https://forum.xojo.com/35212-ioslib-is-dead

So I will change the info on my git which still points to the old repository. Thanks.