Modify image obtained with getImage(), and save it as a bytearray again.
#1
Hi! I´m triying to modify an addon to improve it (Ambibox addon). My problem is that I need to obtain an image from Kodi using:

Code:
image = self.capture.getImage()

Then, I want to crop it, so I do the following code (using PIL):

Code:
img_buf = PILImage.frombuffer('RGBA', (self.mmap_width, self.mmap_height), image, 'raw', 'RGBA', 0, 1)
img_a = img_buf.tostring()
img_f = PILImage.fromstring('RGBA', (self.mmap_width, self.mmap_height), img_a, 'raw', 'BGRA', 0, 1)
box = (0, 35, 480, 234)
img_sb =img_f.crop(box)

After this, I need to obtain the same data type as I obtained with getImage(), converting img_sb into it, because addon write it into a byte buffer, but I don´t know how to reconvert it. The addon do the following:

Code:
self.copy_to_mmap(img_sb)

And then, the method it uses is:

Code:
def ctype_copy_to_mmap(self, image):
        T = (ctypes.c_uint8 * (self.mmap_length + 11))
        U = (ctypes.c_uint8 * self.rc_length)
        dest = T.from_buffer(self.inDataMap)
        src = U.from_buffer(image)
        if self.mmap_address == 0:
            self.mmap_address = ctypes.addressof(dest) + 11
        ctypes.memmove(self.mmap_address, ctypes.addressof(src), self.rc_length)
        self.inDataMap[0] = TERM

And without conversion, I have the following error:

Code:
src = U.from_buffer(image)
TypeError: expected a writeable buffer object

I don´t know how I can make it to work again with the cropped image.
Reply

Logout Mark Read Team Forum Stats Members Help
Modify image obtained with getImage(), and save it as a bytearray again.0