# Path: flexlay/blitter.py
# def blit_clear(canvas):
#     pass
#     # print("clear(PixelBuffer canvas) not implemented", canvas)
#     # canvas.lock()
#     # buffer = static_cast<unsigned char*>(canvas.get_data())
#     # memset(buffer, 0, sizeof(unsigned char) * canvas.get_pitch() * canvas.height)
#     # canvas.unlock()
# 
# def blit_opaque(target, brush, x, y):
#     painter = QPainter(target.get_qimage())
#     painter.setCompositionMode(QPainter.CompositionMode_Source)
#     painter.drawImage(QPoint(x, y), brush.get_qimage())


from typing import Dict
from PyQt5.QtCore import QSize
from PyQt5.QtGui import QImage
from flexlay.blitter import blit_clear, blit_opaque
# Flexlay - A Generic 2D Game Editor
# Copyright (C) 2014 Ingo Ruhnke <grumbel@gmail.com>
#
# This program 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.
#
# This program 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 this program.  If not, see <http://www.gnu.org/licenses/>.






class PixelBuffer:

    cache: Dict[str, QImage] = {}

    @staticmethod
    def subregion_from_file(filename, x, y, w, h):
        source = PixelBuffer.from_file(filename)
        target = PixelBuffer(w, h)
        blit_clear(target)

# Path: flexlay/blitter.py
# def blit_clear(canvas):
#     pass
#     # print("clear(PixelBuffer canvas) not implemented", canvas)
#     # canvas.lock()
#     # buffer = static_cast<unsigned char*>(canvas.get_data())
#     # memset(buffer, 0, sizeof(unsigned char) * canvas.get_pitch() * canvas.height)
#     # canvas.unlock()
# 
# def blit_opaque(target, brush, x, y):
#     painter = QPainter(target.get_qimage())
#     painter.setCompositionMode(QPainter.CompositionMode_Source)
#     painter.drawImage(QPoint(x, y), brush.get_qimage())


# Path: flexlay/pixel_buffer.py
from typing import Dict
from PyQt5.QtCore import QSize
from PyQt5.QtGui import QImage
from flexlay.blitter import blit_clear, blit_opaque

# Flexlay - A Generic 2D Game Editor
# Copyright (C) 2014 Ingo Ruhnke <grumbel@gmail.com>
#
# This program 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.
#
# This program 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 this program.  If not, see <http://www.gnu.org/licenses/>.






class PixelBuffer:

    cache: Dict[str, QImage] = {}

    @staticmethod
    def subregion_from_file(filename, x, y, w, h):
        source = PixelBuffer.from_file(filename)
        target = PixelBuffer(w, h)
        blit_clear(target)

        blit_opaque(target, source, -x, -y)