community icon indicating copy to clipboard operation
community copied to clipboard

TextureRegion.pixels data is wrong

Open fuzzyTew opened this issue 5 years ago • 2 comments

Software Versions

  • Python: 3.8.6
  • OS: RHEL 7.7
  • Kivy: 2.0.0rc4 1a7cd9cfdeaac07df0913f1901856991a0d46436
  • Kivy installation method: pip3 install . in git source tree

Describe the bug The Texture and TextureRegion classes both have their pixels property documented with "The origin of the image is at the bottom left". However, TextureRegion is not obeying this on my system. TextureRegion.pixels is returning a flipped image, with [0] being the upper left, for me. I also seem to be getting corrupt data from TextureRegion.pixels.

Expected behavior Orientation of TextureRegion.pixels should be in line with documentation, and be blittable without producing flipping or corruption.

To Reproduce

from kivy.base import EventLoop
from kivy.graphics.texture import Texture
import numpy as np

dims = (2,2)

EventLoop.ensure_window()

# create texture
texture = Texture.create(dims)

# fill texture with ascending values
texture.blit_buffer(np.arange(dims[0]*dims[1]*4,dtype=np.uint8), dims, 'rgba')

# display content as a 2d array
print("Texture.pixels = \n", np.frombuffer(texture.pixels, dtype=np.uint8).reshape(dims[0],dims[1]*4))

# access whole texture as a region
region = texture.get_region(0,0,*dims)

# display region content as a 2d array
print("TextureRegion.pixels = \n", np.frombuffer(region.pixels, dtype=np.uint8).reshape(dims[0],dims[1]*4))
[INFO   ] [Logger      ] Record log in /home/user/.kivy/logs/kivy_20-11-08_1.txt
[INFO   ] [Kivy        ] Installed at "/home/user/.local/lib/python3.8/site-packages/kivy/__init__.py"
[INFO   ] [Python      ] v3.8.6+ (heads/3.8:e4008404fb, Sep 28 2020, 15:39:17) 
[GCC 7.3.1 20180303 (Red Hat 7.3.1-5)]
[INFO   ] [Python      ] Interpreter at "/usr/local/bin/python3"
[INFO   ] [Factory     ] 186 symbols loaded
pygame 2.0.0 (SDL 2.0.12, python 3.8.6)
Hello from the pygame community. https://www.pygame.org/contribute.html
[INFO   ] [Image       ] Providers: img_tex, img_dds, img_pygame, img_pil (img_ffpyplayer ignored)
[INFO   ] [Window      ] Provider: pygame
[WARNING] [Deprecated  ] Pygame has been deprecated and will be removed after 1.11.0: Call to deprecated function __init__ in /home/user/.local/lib/python3.8/site-packages/kivy/core/window/window_pygame.py line 42.Called from /home/user/.local/lib/python3.8/site-packages/kivy/core/__init__.py line 70 by core_select_lib().
[INFO   ] [GL          ] Using the "OpenGL" graphics system
[INFO   ] [GL          ] Backend used <gl>
[INFO   ] [GL          ] OpenGL version <b'3.0 Mesa 18.3.4'>
[INFO   ] [GL          ] OpenGL vendor <b'Intel Open Source Technology Center'>
[INFO   ] [GL          ] OpenGL renderer <b'Mesa DRI Intel(R) HD Graphics 620 (Kaby Lake GT2) '>
[INFO   ] [GL          ] OpenGL parsed version: 3, 0
[INFO   ] [GL          ] Shading version <b'1.30'>
[INFO   ] [GL          ] Texture max size <16384>
[INFO   ] [GL          ] Texture max units <32>
[WARNING] [Deprecated  ] Pygame has been deprecated and will be removed after 1.11.0: Call to deprecated function __init__ in /home/user/.local/lib/python3.8/site-packages/kivy/core/image/img_pygame.py line 27.Called from /home/user/.local/lib/python3.8/site-packages/kivy/core/image/__init__.py line 460 by load().
[INFO   ] [Window      ] virtual keyboard not allowed, single mode, not docked
Texture.pixels = 
 [[ 0  1  2  3  4  5  6  7]
 [ 8  9 10 11 12 13 14 15]]
TextureRegion.pixels = 
 [[ 0  0  0 11  1  1  1 15]
 [ 0  0  0  3  0  0  0  7]]

Additional context

fuzzyTew avatar Nov 08 '20 23:11 fuzzyTew

Hello, I will try doing this issue, could someone assign it to me ? Thank you!!

pinheiroju avatar Oct 10 '24 14:10 pinheiroju

@pinheiroju I would recommend you just go for it and issue a PR. No need to wait for a maintainer to assign it.

ElliotGarbus avatar Oct 10 '24 16:10 ElliotGarbus