NSImage ChatGPT etc.

Updates on the progress of this project
Post Reply
User avatar
OpenXTalkPaul
Posts: 1485
Joined: Sat Sep 11, 2021 4:19 pm
Contact:

NSImage ChatGPT etc.

Post by OpenXTalkPaul »

I'm currently using ChatGPT as much as possible to do the rather tedious work of wrapping lots and lots of API methods, properties, tons of constants, those sorts of things while there's a free preview available to the public to use/test. It's extremely helpful.

So using that I've been getting into some CoreImage stuff via Extension Builder on macOS.
Which prompted a new Extension Builder library to translate some Python Script I had tried out (ran the Python from a script in OXT). This is likely the beginnings of a much larger library for Image related tasks using the macOS APIs. I'm considering using it to also wrap something in a more cross platform library, such as ImageMagick/GrahicsMagick. But some of the macOS stuff is already functional.

The AI dutifully hammered out the constants declarations for all of the official NSImageNamed images provided by macOS for use in apps built for Apple platforms. However I found a much cooler list on GitHub that included undocumented constants as well. The demo stack retrieves these into a image PNG data (and can also write out all available resolution "representations" to a TIFF file)

https://hetima.github.io/fucking_nsimage_syntax/
Screen Shot 2023-02-15 at 10.47.11 AM.png
Screen Shot 2023-02-15 at 10.47.11 AM.png (585.49 KiB) Viewed 6697 times
Kinda funny to see that macOS still includes NeXT icons, lol.
User avatar
OpenXTalkPaul
Posts: 1485
Joined: Sat Sep 11, 2021 4:19 pm
Contact:

Re: NSImage ChatGPT etc.

Post by OpenXTalkPaul »

Screen Shot 2023-02-17 at 10.04.08 AM.png
Screen Shot 2023-02-17 at 10.04.08 AM.png (217.65 KiB) Viewed 6682 times
So once I figured out how to pass image data between an image control, to NSImage->NSBitmappedImageRep->CGImageRef-> and finally CIImage, where Apple's Core Image framework can do all sorts of things to that data, and then how to convert the CI image object back to data fit for placing back into the image control (formatted as PNG,GIF,JPEG data blob) or writing to disk (TIFF format, for example, is not supported by our image control but you can write the data out to a .tif file just fine), Things are moved along rather quickly, and now we have some bolder plate code for applying CIFilters to an image in a image control (or from the disk file if it's a 'reference control'). It renders effects on 128x128pxel image in basically realtime so moving a slider knob is fairly in sync with what is being displayed in my output image object.

Bottom line is the image on the right was created by script from the one to its left without any Photoshop being involved.
Like the existing CoreImage effects support in the visual effects command, this doesn't function on non-Apple platforms, however theoretically at least some of this (and maybe some other Builder libraries ) could work on other platforms if we included bindings for GNUStep's UI library, which does contain open-source implementations of some of the objects this uses like NSImage / NSBitmappedImageRepresentations.

I guess I should take some time to look again at how CoreImage syntax was previously implemented in the visual effects command (which still works fine, but has anyone even use it beyond demo stacks?). I'd like to try to stay consistent with syntax any long-time xTalk scripted might be already familiar with. The library needs a way to chain these filters together so we can apply multiple filters in a singe pass though so it will probably wind up being some sort of strings items/lines or a array (I'd prefer an easily inspectable text formatting).

from the dictionary:

Code: Select all

-- MacOS only.
visual effect "CIPageCurlTransition" slow with Angle 1.0 and Radius 70 and Extent "30,30,300,300"
go next card
lock screen for visual effect in rect "30,30,300,300"
go previous card
unlock screen with visual effect "CIModTransition" with Angle -1 and Radius 70
User avatar
richmond62
Posts: 2619
Joined: Sun Sep 12, 2021 11:03 am
Location: Bulgaria
Contact:

Re: NSImage ChatGPT etc.

Post by richmond62 »

MacOS containing NeXT icons is no odder than human embryos having tails, or humans having non-functional appendixes.
https://richmondmathewson.owlstown.net/
User avatar
OpenXTalkPaul
Posts: 1485
Joined: Sat Sep 11, 2021 4:19 pm
Contact:

Re: NSImage ChatGPT etc.

Post by OpenXTalkPaul »

richmond62 wrote: Fri Feb 17, 2023 6:53 pm MacOS containing NeXT icons is no odder than human embryos having tails, or humans having non-functional appendixes.
I just would have thought someone at Apple would've tried to trim some fat at some point since the macOS Installer just kept getting more and more bloated over the years. But it's cool that that's still there after three decades, felt a bit like finding an Easter Egg!

Core Image filtering is working nicely, just added a handler for passing arbitrary amount of filters and parameters in as strings.
Used from a stack Scrollbar script it looks like this:

Code: Select all

on scrollbarDrag pNewPosition
   put the short name of (the owner of me ) into tFilterName
   get CoreImageFilterWithParamsList( the long id of image "Test Image", \
        "CIMotionBlur inputRadius="& pNewPosition &" inputAngle=" & the thumbPosition of scrollbar "ScrollbarB")
   set the text of image "Test Image Out" to it    
end scrollbarDrag
User avatar
OpenXTalkPaul
Posts: 1485
Joined: Sat Sep 11, 2021 4:19 pm
Contact:

Re: NSImage ChatGPT etc.

Post by OpenXTalkPaul »

Filtered Image 1.png
Filtered Image 1.png (44.53 KiB) Viewed 6660 times
Filtered Image 2.png
Filtered Image 2.png (29.46 KiB) Viewed 6660 times
This might seem like I'm having too much fun here, but I can tell you I've used image manipulating scripts and automation stuff for decades in real-world production work-flows with PhotoScript (early 1990s), then PhotoShop Scripting/Actions later. This here is a lot like adding Photoshop filters to the OpenXTalk arsenal of capabilities, and the 'CIColor objects' are CMYK (printing press) color aware. But it certainly is a lot of fun to play with filters too!

I want to try wrap the text recognizer filter to get some basic OCR (optical character recognition) capability.

I will probably put this aside after the still image filter category (which is like 100 or so filters), but Core Image Filters can also be used with CoreVideo for filtering movies.
User avatar
richmond62
Posts: 2619
Joined: Sun Sep 12, 2021 11:03 am
Location: Bulgaria
Contact:

Re: NSImage ChatGPT etc.

Post by richmond62 »

Why does the URL in the first posting contain the 'F' word? :lol:
https://richmondmathewson.owlstown.net/
User avatar
OpenXTalkPaul
Posts: 1485
Joined: Sat Sep 11, 2021 4:19 pm
Contact:

Re: NSImage ChatGPT etc.

Post by OpenXTalkPaul »

richmond62 wrote: Tue Feb 21, 2023 7:11 pm Why does the URL in the first posting contain the 'F' word? :lol:
:lol: That's how I found it. You would have to ask the person who created that list to be sure but I imagine it's due to frustration with Apple's documentation!

I found this better site from the author of DropDMG created and it's a much more complete documentation of CIFilters than Apple's official (and no longer updated) docs:
https://cifilter.io born of same sort of frustration https://mjtsai.com/blog/2019/04/16/core ... reference/
And his docs are open-source https://github.com/noahsark769/cifilter.io so maybe I'll contribute to it if I find some info is missing.

I was more curious about how they found all of those undocumented constants names (like the NeXT ones), like did they manually sift though every .h header file in the OS collecting them all or what?

ANARCHY IN THE OXT!
Filtered Image.png
Filtered Image.png (38.46 KiB) Viewed 6656 times
Post Reply

Who is online

Users browsing this forum: No registered users and 5 guests