pve, pygl
This commit is contained in:
		
							
								
								
									
										15
									
								
								pve/__init__.py
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										15
									
								
								pve/__init__.py
									
									
									
									
									
										Normal file
									
								
							@ -0,0 +1,15 @@
 | 
			
		||||
# People's Video Editor: high quality, GPU accelerated mp4 editor
 | 
			
		||||
# Copyright (C) 2025 Roz K <roz@rozk.net>
 | 
			
		||||
#
 | 
			
		||||
# This file is part of People's Video Editor.
 | 
			
		||||
#
 | 
			
		||||
# People's Video Editor is free software: you can redistribute it and/or modify it under the terms of the
 | 
			
		||||
# GNU General Public License as published by the Free Software Foundation, either version 3 of the License,
 | 
			
		||||
# or (at your option) any later version.
 | 
			
		||||
#
 | 
			
		||||
# People's Video Editor is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY;
 | 
			
		||||
# without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
 | 
			
		||||
# See the GNU General Public License for more details.
 | 
			
		||||
#
 | 
			
		||||
# You should have received a copy of the GNU General Public License along with People's Video Editor.
 | 
			
		||||
# If not, see <https://www.gnu.org/licenses/>.
 | 
			
		||||
							
								
								
									
										61
									
								
								pve/mesh.py
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										61
									
								
								pve/mesh.py
									
									
									
									
									
										Normal file
									
								
							@ -0,0 +1,61 @@
 | 
			
		||||
# People's Video Editor: high quality, GPU accelerated mp4 editor
 | 
			
		||||
# Copyright (C) 2025 Roz K <roz@rozk.net>
 | 
			
		||||
#
 | 
			
		||||
# This file is part of People's Video Editor.
 | 
			
		||||
#
 | 
			
		||||
# People's Video Editor is free software: you can redistribute it and/or modify it under the terms of the
 | 
			
		||||
# GNU General Public License as published by the Free Software Foundation, either version 3 of the License,
 | 
			
		||||
# or (at your option) any later version.
 | 
			
		||||
#
 | 
			
		||||
# People's Video Editor is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY;
 | 
			
		||||
# without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
 | 
			
		||||
# See the GNU General Public License for more details.
 | 
			
		||||
#
 | 
			
		||||
# You should have received a copy of the GNU General Public License along with People's Video Editor.
 | 
			
		||||
# If not, see <https://www.gnu.org/licenses/>.
 | 
			
		||||
 | 
			
		||||
#TODO: split channels
 | 
			
		||||
 | 
			
		||||
from shape import Vertex, Shape
 | 
			
		||||
 | 
			
		||||
from array import array
 | 
			
		||||
 | 
			
		||||
class Mesh:
 | 
			
		||||
    __slots__ = '_array', '_view', '_size'
 | 
			
		||||
 | 
			
		||||
    def __init__(self, shape):
 | 
			
		||||
        #TODO: cpp
 | 
			
		||||
        if shape.cutouts:
 | 
			
		||||
            raise NotImplementedError
 | 
			
		||||
        if shape.size > 4:
 | 
			
		||||
            raise NotImplementedError
 | 
			
		||||
 | 
			
		||||
        self._array = array(Vertex.Type, 2 * 3 * Vertex.Channels)
 | 
			
		||||
        self._view = memoryview(self._array)
 | 
			
		||||
        self._size = self.view.nbytes
 | 
			
		||||
        tl = shape[0]
 | 
			
		||||
        tr = shape[1]
 | 
			
		||||
        br = shape[2]
 | 
			
		||||
        bl = shape[3]
 | 
			
		||||
        self.set(0, 0, tl)
 | 
			
		||||
        self.set(0, 1, tr)
 | 
			
		||||
        self.set(0, 2, br)
 | 
			
		||||
        self.set(1, 0, br)
 | 
			
		||||
        self.set(1, 1, bl)
 | 
			
		||||
        self.set(1, 2, tl)
 | 
			
		||||
 | 
			
		||||
    def __del__(self):
 | 
			
		||||
        del self._view
 | 
			
		||||
        del self._array
 | 
			
		||||
 | 
			
		||||
    def set(self, triangle, index, vertex):
 | 
			
		||||
        index = (triangle * 3 + index) * Vertex.Channels
 | 
			
		||||
        self._view[index:(index + Vertex.Channels)] = vertex
 | 
			
		||||
 | 
			
		||||
    @property
 | 
			
		||||
    def size(self):
 | 
			
		||||
        return self._size
 | 
			
		||||
 | 
			
		||||
    @property
 | 
			
		||||
    def view(self):
 | 
			
		||||
        return self._view
 | 
			
		||||
							
								
								
									
										131
									
								
								pve/pixmap.py
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										131
									
								
								pve/pixmap.py
									
									
									
									
									
										Normal file
									
								
							@ -0,0 +1,131 @@
 | 
			
		||||
# People's Video Editor: high quality, GPU accelerated mp4 editor
 | 
			
		||||
# Copyright (C) 2025 Roz K <roz@rozk.net>
 | 
			
		||||
#
 | 
			
		||||
# This file is part of People's Video Editor.
 | 
			
		||||
#
 | 
			
		||||
# People's Video Editor is free software: you can redistribute it and/or modify it under the terms of the
 | 
			
		||||
# GNU General Public License as published by the Free Software Foundation, either version 3 of the License,
 | 
			
		||||
# or (at your option) any later version.
 | 
			
		||||
#
 | 
			
		||||
# People's Video Editor is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY;
 | 
			
		||||
# without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
 | 
			
		||||
# See the GNU General Public License for more details.
 | 
			
		||||
#
 | 
			
		||||
# You should have received a copy of the GNU General Public License along with People's Video Editor.
 | 
			
		||||
# If not, see <https://www.gnu.org/licenses/>.
 | 
			
		||||
 | 
			
		||||
from fractions import Fraction
 | 
			
		||||
 | 
			
		||||
class Geometry:
 | 
			
		||||
    __slots__ = '_width', '_height', '_ratio', '_size'
 | 
			
		||||
 | 
			
		||||
    def __init__(self, width = 0, height = 0, ratio = None):
 | 
			
		||||
        if width > 0 and height > 0:
 | 
			
		||||
            assert ratio is None
 | 
			
		||||
            self._width = width
 | 
			
		||||
            self._height = height
 | 
			
		||||
            self._ratio = Fraction(width, height).limit_denominator()
 | 
			
		||||
            self._size = width * height
 | 
			
		||||
        elif width > 0 and ratio:
 | 
			
		||||
            self._width = width
 | 
			
		||||
            self._height = round((width * ratio.numerator) / ratio.denominator)
 | 
			
		||||
            self._ratio = ratio
 | 
			
		||||
            self._size = width * self._height
 | 
			
		||||
        elif height > 0 and ratio:
 | 
			
		||||
            self._width = round((height * ratio.denominator) / ratio.numerator)
 | 
			
		||||
            self._height = height
 | 
			
		||||
            self._ratio = ratio
 | 
			
		||||
            self._size = self._width * height
 | 
			
		||||
        else:
 | 
			
		||||
            raise ValueError
 | 
			
		||||
 | 
			
		||||
    def __ge__(self, other):
 | 
			
		||||
        return (self._width >= other._width and self._height >= other._height)
 | 
			
		||||
 | 
			
		||||
    @property
 | 
			
		||||
    def width(self):
 | 
			
		||||
        return self._width
 | 
			
		||||
 | 
			
		||||
    @property
 | 
			
		||||
    def height(self):
 | 
			
		||||
        return self._height
 | 
			
		||||
 | 
			
		||||
    @property
 | 
			
		||||
    def ratio(self):
 | 
			
		||||
        return self._ratio
 | 
			
		||||
 | 
			
		||||
class Format:
 | 
			
		||||
    __slots__ = '_channels', '_depth', '_type', '_size'
 | 
			
		||||
 | 
			
		||||
    def __init__(self, channels, depth):
 | 
			
		||||
        self._channels = channels
 | 
			
		||||
        self._depth = depth
 | 
			
		||||
        if depth is 8:
 | 
			
		||||
            self._type = 'B'
 | 
			
		||||
            self._size = channels
 | 
			
		||||
        elif depth is 16:
 | 
			
		||||
            self._type = 'H'
 | 
			
		||||
            self._size = channels * 2
 | 
			
		||||
        else:
 | 
			
		||||
            raise ValueError
 | 
			
		||||
 | 
			
		||||
    def __eq__(self, other):
 | 
			
		||||
        return (self._channels == other._channels and self._depth == other._depth)
 | 
			
		||||
 | 
			
		||||
    @property
 | 
			
		||||
    def channels(self):
 | 
			
		||||
        return self._channels
 | 
			
		||||
 | 
			
		||||
    @property
 | 
			
		||||
    def depth(self):
 | 
			
		||||
        return self._depth
 | 
			
		||||
 | 
			
		||||
class Pixmap:
 | 
			
		||||
    __slots__ = '_geometry', '_format', '_line_size', '_bytes', '_view'
 | 
			
		||||
 | 
			
		||||
    def __init__(self, geometry, format):
 | 
			
		||||
        self._geometry = geometry
 | 
			
		||||
        self._format = format
 | 
			
		||||
        self._line_size = geometry._width * format._size
 | 
			
		||||
        self._bytes = bytearray(geometry._size * format._size)
 | 
			
		||||
        self._view = memoryview(self._bytes)
 | 
			
		||||
 | 
			
		||||
    def __del__(self):
 | 
			
		||||
        del self._view
 | 
			
		||||
        del self._bytes
 | 
			
		||||
 | 
			
		||||
    @property
 | 
			
		||||
    def geometry(self):
 | 
			
		||||
        return self._geometry
 | 
			
		||||
 | 
			
		||||
    @property
 | 
			
		||||
    def width(self):
 | 
			
		||||
        return self._geometry._width
 | 
			
		||||
 | 
			
		||||
    @property
 | 
			
		||||
    def height(self):
 | 
			
		||||
        return self._geometry._height
 | 
			
		||||
 | 
			
		||||
    @property
 | 
			
		||||
    def ratio(self):
 | 
			
		||||
        return self._geometry._ratio
 | 
			
		||||
 | 
			
		||||
    @property
 | 
			
		||||
    def format(self):
 | 
			
		||||
        return self._format
 | 
			
		||||
 | 
			
		||||
    @property
 | 
			
		||||
    def channels(self):
 | 
			
		||||
        return self._format._channels
 | 
			
		||||
 | 
			
		||||
    @property
 | 
			
		||||
    def depth(self):
 | 
			
		||||
        return self._format._depth
 | 
			
		||||
 | 
			
		||||
    @property
 | 
			
		||||
    def line_size(self):
 | 
			
		||||
        return self._line_size
 | 
			
		||||
 | 
			
		||||
    @property
 | 
			
		||||
    def view(self):
 | 
			
		||||
        return self._view
 | 
			
		||||
							
								
								
									
										164
									
								
								pve/shape.py
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										164
									
								
								pve/shape.py
									
									
									
									
									
										Normal file
									
								
							@ -0,0 +1,164 @@
 | 
			
		||||
# People's Video Editor: high quality, GPU accelerated mp4 editor
 | 
			
		||||
# Copyright (C) 2025 Roz K <roz@rozk.net>
 | 
			
		||||
#
 | 
			
		||||
# This file is part of People's Video Editor.
 | 
			
		||||
#
 | 
			
		||||
# People's Video Editor is free software: you can redistribute it and/or modify it under the terms of the
 | 
			
		||||
# GNU General Public License as published by the Free Software Foundation, either version 3 of the License,
 | 
			
		||||
# or (at your option) any later version.
 | 
			
		||||
#
 | 
			
		||||
# People's Video Editor is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY;
 | 
			
		||||
# without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
 | 
			
		||||
# See the GNU General Public License for more details.
 | 
			
		||||
#
 | 
			
		||||
# You should have received a copy of the GNU General Public License along with People's Video Editor.
 | 
			
		||||
# If not, see <https://www.gnu.org/licenses/>.
 | 
			
		||||
 | 
			
		||||
#TODO: split channels
 | 
			
		||||
 | 
			
		||||
import itertools
 | 
			
		||||
from array import array
 | 
			
		||||
 | 
			
		||||
_X, _Y, _U, _V, _Channels = itertools.count(0)
 | 
			
		||||
_Type = 'f'
 | 
			
		||||
_Size = array(_Type).itemsize * _Channels
 | 
			
		||||
 | 
			
		||||
class Vertex:
 | 
			
		||||
    __slots__ = 'view'
 | 
			
		||||
 | 
			
		||||
    Type = _Type
 | 
			
		||||
    Channels = _Channels
 | 
			
		||||
    Size = _Size
 | 
			
		||||
 | 
			
		||||
    def __init__(self, view):
 | 
			
		||||
        assert isinstance(view, memoryview)
 | 
			
		||||
        self.view = view
 | 
			
		||||
 | 
			
		||||
    def __del__(self):
 | 
			
		||||
        del self._view
 | 
			
		||||
 | 
			
		||||
    @property
 | 
			
		||||
    def xy(self):
 | 
			
		||||
        return self.view[_X], self.view[_Y]
 | 
			
		||||
 | 
			
		||||
    @xy.setter
 | 
			
		||||
    def xy(self, value):
 | 
			
		||||
        self.view[_X], self.view[_Y] = value
 | 
			
		||||
 | 
			
		||||
    @property
 | 
			
		||||
    def x(self):
 | 
			
		||||
        return self.view[_X]
 | 
			
		||||
 | 
			
		||||
    @x.setter
 | 
			
		||||
    def x(self, value):
 | 
			
		||||
        self.view[_X] = value
 | 
			
		||||
 | 
			
		||||
    @property
 | 
			
		||||
    def y(self):
 | 
			
		||||
        return self.view[_Y]
 | 
			
		||||
 | 
			
		||||
    @y.setter
 | 
			
		||||
    def y(self, value):
 | 
			
		||||
        self.view[_Y] = value
 | 
			
		||||
 | 
			
		||||
    @property
 | 
			
		||||
    def uv(self):
 | 
			
		||||
        return self.view[_U], self.view[_V]
 | 
			
		||||
 | 
			
		||||
    @uv.setter
 | 
			
		||||
    def uv(self, value):
 | 
			
		||||
        self.view[_U], self.view[_V] = value
 | 
			
		||||
 | 
			
		||||
    @property
 | 
			
		||||
    def u(self):
 | 
			
		||||
        return self.view[_U]
 | 
			
		||||
 | 
			
		||||
    @u.setter
 | 
			
		||||
    def u(self, value):
 | 
			
		||||
        self.view[_U] = value
 | 
			
		||||
 | 
			
		||||
    @property
 | 
			
		||||
    def v(self):
 | 
			
		||||
        return self.view[_V]
 | 
			
		||||
 | 
			
		||||
    @v.setter
 | 
			
		||||
    def v(self, value):
 | 
			
		||||
        self.view[_V] = value
 | 
			
		||||
 | 
			
		||||
class Shape:
 | 
			
		||||
    __slots__ = '_array', '_view', '_size', '_cutouts'
 | 
			
		||||
 | 
			
		||||
    @classmethod
 | 
			
		||||
    def rectangle(cls, geometry):
 | 
			
		||||
        shape = cls(size = 4)
 | 
			
		||||
        tl = Vertex(shape[0])
 | 
			
		||||
        tl.xy = tl.uv = (0.0, 0.0)
 | 
			
		||||
        tr = Vertex(shape[1])
 | 
			
		||||
        tr.xy = tr.uv = (geometry._width, 0.0)
 | 
			
		||||
        br = Vertex(shape[2])
 | 
			
		||||
        br.xy = br.uv = (geometry._width, geometry._height)
 | 
			
		||||
        bl = Vertex(shape[3])
 | 
			
		||||
        bl.xy = bl.uv = (0.0, geometry._height)
 | 
			
		||||
        return shape
 | 
			
		||||
 | 
			
		||||
    def __init__(self, size = 0, cutouts = None):
 | 
			
		||||
        self._array = array(_Type, bytes(size * _Size))
 | 
			
		||||
        self._view = memoryview(self._array)
 | 
			
		||||
        self._size = size
 | 
			
		||||
        self._cutouts = list(cutouts) if cutouts else None
 | 
			
		||||
 | 
			
		||||
    def __del__(self):
 | 
			
		||||
        del self._view
 | 
			
		||||
        del self._array
 | 
			
		||||
        del self._cutouts
 | 
			
		||||
 | 
			
		||||
    def __len__(self):
 | 
			
		||||
        return self._size
 | 
			
		||||
 | 
			
		||||
    def __getitem__(self, index):
 | 
			
		||||
        index *= _Channels
 | 
			
		||||
        return self._view[index:(index + _Channels)]
 | 
			
		||||
 | 
			
		||||
    @property
 | 
			
		||||
    def size(self):
 | 
			
		||||
        return self._size
 | 
			
		||||
 | 
			
		||||
    @property
 | 
			
		||||
    def view(self):
 | 
			
		||||
        return self._view
 | 
			
		||||
 | 
			
		||||
    @property
 | 
			
		||||
    def cutouts(self):
 | 
			
		||||
        return list(self._cutouts) if self._cutouts else []
 | 
			
		||||
 | 
			
		||||
    @cutouts.setter
 | 
			
		||||
    def cutouts(self, value):
 | 
			
		||||
        self._cutouts = list(value) if value else None
 | 
			
		||||
 | 
			
		||||
    def append(self, count = 1):
 | 
			
		||||
        index = self._size
 | 
			
		||||
        self._view.release()
 | 
			
		||||
        self._array.frombytes(bytes(count * _Size))
 | 
			
		||||
        self._view = memoryview(self._array)
 | 
			
		||||
        self._size += count
 | 
			
		||||
        return index
 | 
			
		||||
 | 
			
		||||
    def insert(self, index, count = 1):
 | 
			
		||||
        index *= _Channels
 | 
			
		||||
        self._view.release()
 | 
			
		||||
        self._array[index:index] = array(_Type, bytes(count * _Size))
 | 
			
		||||
        self._view = memoryview(self._array)
 | 
			
		||||
        self._size += count
 | 
			
		||||
 | 
			
		||||
    def remove(self, index, count = 1):
 | 
			
		||||
        index *= _Channels
 | 
			
		||||
        self._view.release()
 | 
			
		||||
        del self._array[index:(index + count * _Channels)]
 | 
			
		||||
        self._view = memoryview(self._array)
 | 
			
		||||
        self._size -= count
 | 
			
		||||
 | 
			
		||||
    def clear(self):
 | 
			
		||||
        self._view.release()
 | 
			
		||||
        self._array = array(_Type)
 | 
			
		||||
        self._view = memoryview(self._array)
 | 
			
		||||
        self._size = 0
 | 
			
		||||
		Reference in New Issue
	
	Block a user