Giter VIP home page Giter VIP logo

Comments (13)

luzpaz avatar luzpaz commented on August 22, 2024

Continuation...
So I reply to Richard directly (accidentally off-list) with

Yes please :)

So Richard replies

I can do an example that does a colorspace conversion.

Yes please :)

So I had a try at this just now, but my python knowledge is lacking.
I'm not sure how you get access to the raw bytes in an image from
python and what coding conventions you'd use in a library. Ideas
welcome here. I've included the incomplete code below. I'm happy to
add more functionality into libcolord if this is required (e.g. if we
want to pass an array of "ddd" to the process function).

Richard


import gi
gi.require_version('Colord', '1.0')

from gi.repository import Colord
from gi.repository import Gio

# load sRGB (without using the daemon)
icc_src = Colord.Icc.new()
h = Gio.file_new_for_path('/usr/share/color/icc/colord/sRGB.icc')
icc_src.load_file(h, Colord.IccLoadFlags.NONE)

# load AdobeRGB (without using the daemon)
icc_dst = Colord.Icc.new()
h = Gio.file_new_for_path('/usr/share/color/icc/colord/AdobeRGB1998.icc')
icc_dst.load_file(h, Colord.IccLoadFlags.NONE)

# set up the transform
transform = Colord.Transform.new()
transform.set_input_pixel_format(Colord.PIXEL_FORMAT_RGB24)
transform.set_input_icc(icc_src)
transform.set_output_icc(icc_dst)
transform.set_output_pixel_format(Colord.PIXEL_FORMAT_RGB24)
transform.set_rendering_intent(Colord.RenderingIntent.PERCEPTUAL)
transform.set_bpc(True)

# hmm, not sure how to make process() accept raw image data
data_in = [0.5,0.6,0.7]
transform.process(data_in, data_in, 1, 1, 1, None)

from swatchbooker.

luzpaz avatar luzpaz commented on August 22, 2024

Above Richard writes:

So I had a try at this just now, but my python knowledge is lacking.
I'm not sure how you get access to the raw bytes in an image from
python and what coding conventions you'd use in a library. Ideas
welcome here. I've included the incomplete code below. I'm happy to
add more functionality into libcolord if this is required (e.g. if we
want to pass an array of "ddd" to the process function).

So I'm CCing some possible help from friends:
@berteh
@sk1project
@aoloe
@QuLogic

from swatchbooker.

QuLogic avatar QuLogic commented on August 22, 2024

According to this, functions with bare gpointer should not be exposed over introspection. They should instead be annotated with the expected array dimensions. However, this seems a bit difficult since the function accepts an array in multiple dimensions with varied data types.

You can create the memory pointer using NumPy arrays. I'm not sure why the example uses [0.5, 0.6, 0.7]; the settings are PIXEL_FORMAT_RGB24 which should be 3 bytes of 0-255, not floats.

This works but since you are passing around pointers and stuff, you should check the caveats and ensure your array is allocated suitably:

data_in = np.array([0.5*255, 0.6*255, 0.7*255],
                   dtype=np.uint8)  # NOTE: Use correct type here, not floats!
print(data_in)
transform.process(data_in.ctypes.data, data_in.ctypes.data, 1, 1, 1, None)
print(data_in)

and outputs:

[127 153 178]
[134 152 176]

from swatchbooker.

olivierberten avatar olivierberten commented on August 22, 2024

There's now some bindings for Python3: https://bitbucket.org/johnpfjefferies/little-cms-python-bindings/

No idea what it would take to convert it to python 2...

from swatchbooker.

sk1project avatar sk1project commented on August 22, 2024

from swatchbooker.

olivierberten avatar olivierberten commented on August 22, 2024

True but since I have no clue about C programming or Python packaging, I have no idea how to use it with SwatchBooker.

PIL/Pillow also has lcms2 bindings but only with a limited set of features that don't match the few ones I need...

from swatchbooker.

sk1project avatar sk1project commented on August 22, 2024

from swatchbooker.

olivierberten avatar olivierberten commented on August 22, 2024

the functions I'm using in SwatchBooker are:

cmsOpenProfileFromFile
cmsCreate_sRGBProfile
cmsCreateLab4Profile
cmsCreateXYZProfile
cmsCreateTransform
cmsCloseProfile
cmsDoTransform
cmsDeleteTransform

from swatchbooker.

sk1project avatar sk1project commented on August 22, 2024

from swatchbooker.

olivierberten avatar olivierberten commented on August 22, 2024

PIL bitmaps are converted directly inside PIL but their binding don't expose the "simple" color transform functions...

In the meantime I did manage to have it working with an updated version of ctypesgen and the THR version of the functions so there's no emergency anymore.

Thank you anyway!

from swatchbooker.

olivierberten avatar olivierberten commented on August 22, 2024

Just released 0.7.5 with the lcms2 bindings.

from swatchbooker.

sk1project avatar sk1project commented on August 22, 2024

from swatchbooker.

sk1project avatar sk1project commented on August 22, 2024

from swatchbooker.

Related Issues (15)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.