Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Couldn't set the value of 'bytes_per_pixel' and it's value alway equal 0 #209

Open
huyuhuster opened this issue Apr 6, 2021 · 1 comment

Comments

@huyuhuster
Copy link

memcpy (data, &priv->pointer[priv->read * priv->width * priv->height], priv->width * priv->height * priv->bytes_per_pixel);

I intended to use the memory in mode to read the NumPy buffer just as the example given in UFO tasks docs:

from gi.repository import Ufo
import numpy as np
import tifffile

ref = np.random.random((512, 512)).astype(np.float32)

pm = Ufo.PluginManager()
g = Ufo.TaskGraph()
sched = Ufo.Scheduler()
read = pm.get_task('memory-in')
write = pm.get_task('write')

read.props.pointer = ref.__array_interface__['data'][0]
read.props.width = ref.shape[1]
read.props.height = ref.shape[0]
read.props.number = 1

write.props.filename = 'out.tif'

g.connect_nodes(read, write)
sched.run(g)

out = tifffile.imread('out.tif')
assert np.sum(out - ref) == 0.0

But I got a zero value 'out.tif'. Then I debug the code, I found the problem occur at the memcpy where I labeled it. The bytes_per_pixel‘s value equals 0. I try to set bytes_per_pixel‘s value in Python code by:

read.props.bytes_per_pixel = 4

but it doesn't work.

So I try to set it in C codes by hard coded :

priv->bytes_per_pixel = 4

and it works.

@matze
Copy link
Contributor

matze commented Apr 6, 2021

The property is called bitdepth not bytes_per_pixel, so read.props.bitdepth = 32 should do the trick.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants