Skip to content

Commit

Permalink
Initial Commit
Browse files Browse the repository at this point in the history
  • Loading branch information
Kirbyrawr committed Oct 28, 2023
0 parents commit 3cbf93a
Show file tree
Hide file tree
Showing 6 changed files with 180 additions and 0 deletions.
17 changes: 17 additions & 0 deletions LICENSE.MD
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
The "Jai Creative License" (JCL)

Copyright [2023] [Jai B. (Kirbyrawr)]

With this license, you are free to:

- Use, modify, and distribute this software.
- Create derivative works from this software.
- Use this software for any purpose, commercially or otherwise.

All we ask is:

- Keep the original copyright notice intact.
- Give credit to the original creator, [Your Full Name], when you share or publish this software or any derivative works.
- Use this software in good faith and avoid using it for malicious purposes.

No warranties are given. The license provides the software "as is" without any warranties, express or implied.
43 changes: 43 additions & 0 deletions README.MD
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
# RGB565Preview Plugin for Krita

The RGB565Preview plugin for Krita is a simple yet powerful tool that allows you to view your current document in real-time with colors converted to RGB565 format.

## Installation

Installing the RGB565Preview plugin is a straightforward process:

1. Download the latest release of the plugin from the Releases page.

2. Open Krita.

3. Go to `Tools`, then select `Scripts`, and choose `Import Python Plugin from File`.

4. Locate the downloaded plugin zip file and click `Open`.

5. The plugin is now installed and ready to use.

## Usage

Once installed, here's how to use the RGB565Preview plugin:

1. Open a document in Krita that you want to preview in RGB565 format.

2. Go to `Tools`, then select `Scripts`, and choose `RGB565 Preview`.

3. A new Docker window will appear, displaying your document in real-time with colors converted to RGB565.

4. To close the RGB565Preview Docker, simply click the "X" button in the top-right corner of the Docker window.

## Feedback and Issues

If you encounter any issues or have suggestions for improvements, please [create an issue](https://github.com/your-plugin-repo/issues) on the plugin's GitHub repository. Your feedback is important and helps me make the plugin better.

## Credits

This plugin was primarily created by [Jai (Kirbyrawr)](https://github.com/Kirbyrawr) with the assistance of ChatGPT AI. I would like to extend my thanks to the [KritaCustomPreview](https://github.com/Rolodophone/KritaCustomPreview) repository for providing the foundation for this plugin.

## License

This project is licensed under The "Jai Creative License" (JCL), a custom license. Please refer to [LICENSE.md](LICENSE.md) for more details.

Enjoy using the RGB565Preview plugin for Krita! If you find it helpful, please consider supporting the development by contributing or sharing it with others.
8 changes: 8 additions & 0 deletions pykrita/rgb565preview.desktop
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
[Desktop Entry]
Type=Service
ServiceTypes=Krita/PythonPlugin
X-KDE-Library=rgb565preview
X-Python-2-Compatible=false
X-Krita-Manual=manual.html
Name=RGB565 Viewer
Comment=A docker for displaying a preview of the image in RGB565 Format in real time.
1 change: 1 addition & 0 deletions pykrita/rgb565preview/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
from .rgb565preview import *
45 changes: 45 additions & 0 deletions pykrita/rgb565preview/manual.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>RGB565Preview Plugin Manual</title>
</head>
<body>
<h1>RGB565Preview Plugin for Krita</h1>

<p>The RGB565Preview plugin for Krita is a simple yet powerful tool that allows you to view your current document in real-time with colors converted to RGB565 format.</p>

<h2>Installation</h2>

<ol>
<li>Download the latest release of the plugin from the Releases page.
<li>Open Krita.</li>
<li>Go to <em>Tools</em>, then select <em>Scripts</em>, and choose <em>Import Python Plugin from File</em>.</li>
<li>Locate the downloaded plugin zip file and click <em>Open</em>.</li>
<li>The plugin is now installed and ready to use.</li>
</ol>

<h2>Usage</h2>

<ol>
<li>Open a document in Krita that you want to preview in RGB565 format.</li>
<li>Go to <em>Tools</em>, then select <em>Scripts</em>, and choose <em>RGB565 Preview</em>.</li>
<li>A new Docker window will appear, displaying your document in real-time with colors converted to RGB565.</li>
<li>To close the RGB565Preview Docker, simply click the "X" button in the top-right corner of the Docker window.</li>
</ol>

<h2>Feedback and Issues</h2>

<p>If you encounter any issues or have suggestions for improvements, please <a href="https://github.com/your-plugin-repo/issues">create an issue</a> on the plugin's GitHub repository. Your feedback is important and helps me make the plugin better.</p>

<h2>Credits</h2>

<p>This plugin was primarily created by <a href="https://github.com/Kirbyrawr">Jai (Kirbyrawr)</a> with the assistance of ChatGPT AI. I would like to extend my thanks to the <a href="https://github.com/Rolodophone/KritaCustomPreview">KritaCustomPreview</a> repository for providing the foundation for this plugin.</p>

<h2>License</h2>

<p>This project is licensed under The "Jai Creative License" (JCL), a custom license. Please refer to <a href="LICENSE.md">LICENSE.md</a> for more details.</p>

<p>Enjoy using the RGB565Preview plugin for Krita! If you find it helpful, please consider supporting the development by contributing or sharing it with others.</p>
</body>
</html>
66 changes: 66 additions & 0 deletions pykrita/rgb565preview/rgb565preview.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
from PyQt5.QtCore import Qt, QThread, pyqtSignal, QTimer
from PyQt5.QtGui import QImage, QPixmap, QImageReader
from PyQt5.QtWidgets import QWidget, QVBoxLayout, QLabel
from krita import Krita, DockWidget, DockWidgetFactory, DockWidgetFactoryBase

KI = Krita.instance()

class ImageProcessingThread(QThread):
imageProcessed = pyqtSignal(QImage)

def run(self, image):
resultImage = self.convertToRGB565(image)
self.imageProcessed.emit(resultImage)

def convertToRGB565(self, image):
width, height = image.width(), image.height()
buffer = bytearray(width * height * 2) # 2 bytes for each pixel
image = image.convertToFormat(QImage.Format_RGB16)
ptr = image.constBits()
ptr.setsize(width * height * 2)
buffer[:] = ptr.asarray()
return QImage(buffer, width, height, QImage.Format_RGB16)

def get_scaled_image(image, scale_factor):
scaled_image = image.scaled(int(image.width() * scale_factor), int(image.height() * scale_factor))
return scaled_image

class RGB565Preview(DockWidget):
def __init__(self):
super().__init__()
self.setWindowTitle("RGB565 Preview")

layout = QVBoxLayout()
self.previewLabel = QLabel(self)
self.previewLabel.setAlignment(Qt.AlignCenter)
layout.addWidget(self.previewLabel)
widget = QWidget(self)
widget.setLayout(layout)
self.setWidget(widget)

self.processingThread = ImageProcessingThread()
self.processingThread.imageProcessed.connect(self.updatePreview)

self.prevImageData = None
self.timer = QTimer(self)
self.timer.timeout.connect(self.checkForUpdate)
self.timer.start(1000) # Update every 1 second to reduce frequency

def canvasChanged(self, canvas):
pass

def checkForUpdate(self):
doc = KI.activeDocument()
if doc:
image = doc.projection(0, 0, doc.width(), doc.height()).convertToFormat(QImage.Format_RGBA8888)
scaled_image = get_scaled_image(image, 0.5) # Scale down by 50%
currImageData = scaled_image.bits().asstring(scaled_image.byteCount())
if self.prevImageData != currImageData:
self.processingThread.run(scaled_image)
self.prevImageData = currImageData

def updatePreview(self, resultImage):
pixmap = QPixmap.fromImage(resultImage)
self.previewLabel.setPixmap(pixmap.scaled(self.previewLabel.width(), self.previewLabel.height(), Qt.KeepAspectRatio))

KI.addDockWidgetFactory(DockWidgetFactory("rgb565preview", DockWidgetFactoryBase.DockRight, RGB565Preview))

0 comments on commit 3cbf93a

Please sign in to comment.