Skip to content

Commit

Permalink
Reworked the thumbnail encoding technique to not having to load any l…
Browse files Browse the repository at this point in the history
…ibraries, which caused errors before, anymore
  • Loading branch information
Molodos committed Dec 22, 2023
1 parent bda9775 commit 078f0de
Show file tree
Hide file tree
Showing 14 changed files with 31 additions and 174 deletions.
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -173,5 +173,5 @@ No personal data is being collected. The statistics data, that is collected, is
## License

This repository uses code snippets and image encoding binaries from Elegoo Cura MKS Plugin and is therefore released
under the **AGPL v3** license.
This repository uses code snippets from the Artillery Cura MKSWiFiPlugin and is therefore released under the **AGPL v3**
license.
3 changes: 3 additions & 0 deletions changelog.txt
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
[4.0.0]
- Reworked the thumbnail encoding technique to not having to load any libraries, which caused errors before, anymore

[3.6.2]
- Fixed a bug, that caused crashes when trying to generate thumbnails for some non-Elegoo printers
- Sped up the thumbnail generation process
Expand Down
Binary file removed lib_test/ColPic_X64.dll
Binary file not shown.
141 changes: 0 additions & 141 deletions lib_test/test_lib.py

This file was deleted.

3 changes: 2 additions & 1 deletion package_plugin/__main__.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,8 @@
PLUGIN_FILES: list[str] = ["__init__.py", "elegoo_neptune_thumbnails.py", "LICENSE", "plugin.json", "README.md",
"changelog.txt", "img/benchy.png", "img/cross.png", "img/bg_old.png", "img/bg_new.png",
"tools/__init__.py", "tools/settings.py", "tools/thumbnail_generator.py", "tools/gui.qml",
"tools/gui.py", "tools/statistics_sender.py", "img/sponsor_elegoo.png"]
"tools/gui.py", "tools/statistics_sender.py", "tools/lib_col_pic.py",
"img/sponsor_elegoo.png"]

BUILD_NAME = os.path.join(PACKAGE_PATH, "ElegooNeptuneThumbnails.curapackage")
PLUGIN_BUILD_NAME = os.path.join(PACKAGE_PATH, "ElegooNeptuneThumbnails.zip")
Expand Down
Binary file modified package_plugin/base.curapackage
Binary file not shown.
Binary file modified package_plugin/base.zip
Binary file not shown.
Binary file removed package_plugin/libs/ColPic_X64.dll
Binary file not shown.
Binary file removed package_plugin/libs/libColPic.dylib
Binary file not shown.
Binary file removed package_plugin/libs/libColPic.so
Binary file not shown.
2 changes: 1 addition & 1 deletion package_plugin/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
"display_name": "Elegoo Neptune Thumbnails",
"package_id": "ElegooNeptune3Thumbnails",
"package_type": "plugin",
"package_version": "3.6.2",
"package_version": "4.0.0",
"sdk_version": 8,
"sdk_version_semver": "8.0.0",
"website": "https://github.com/Molodos/ElegooNeptuneThumbnails"
Expand Down
2 changes: 1 addition & 1 deletion plugin.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
"email": "[email protected]",
"website": "https://github.com/Molodos"
},
"version": "3.6.2",
"version": "4.0.0",
"description": "Adds Elegoo Neptune printer thumbnail to G-code. Contains options to display parameters like estimated print time or model height on the thumbnail",
"supported_sdk_versions": [
"8.0.0",
Expand Down
3 changes: 3 additions & 0 deletions lib_test/lib_col_pic.py → tools/lib_col_pic.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
# Copyright (c) 2023 Molodos
# The ElegooNeptuneThumbnails plugin is released under the terms of the AGPLv3 or higher.

def ColPic_EncodeStr(fromcolor16, picw, pich, outputdata: bytearray, outputmaxtsize, colorsmax):
qty = 0
temp = 0
Expand Down
47 changes: 19 additions & 28 deletions tools/thumbnail_generator.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,16 +3,15 @@

import math
from array import array
from ctypes import CDLL
from os import path

from PyQt6.QtCore import Qt, QByteArray, QBuffer, QIODeviceBase
from PyQt6.QtGui import QImage, QPainter, QColor, QFont

from UM.Application import Application
from UM.Logger import Logger
from UM.Platform import Platform
from cura.Snapshot import Snapshot
from . import lib_col_pic
from .settings import SettingsManager


Expand Down Expand Up @@ -83,7 +82,7 @@ def generate_gcode_prefix(cls, slice_data: SliceData) -> str:
else:
gcode_prefix += cls._parse_thumbnail_new(thumbnail, 200, 200, "gimage")
gcode_prefix += cls._parse_thumbnail_new(thumbnail, 160, 160, "simage")
gcode_prefix += ";Thumbnail generated by the ElegooNeptuneThumbnails plugin (https://github.com/Molodos/ElegooNeptuneThumbnails)\r\r"
gcode_prefix += f";Thumbnail generated by the {SettingsManager.get_settings().plugin_json['name']} plugin version {SettingsManager.get_settings().plugin_json['version']} (https://github.com/Molodos/ElegooNeptuneThumbnails)\r\r"

# Return
return gcode_prefix
Expand Down Expand Up @@ -249,13 +248,6 @@ def _parse_thumbnail_new(cls, img: QImage, width: int, height: int, img_type: st
"""
img_type = f";{img_type}:"

if Platform.isOSX():
p_dll = CDLL(path.abspath(path.join(path.dirname(__file__), "..", "libs", "libColPic.dylib")))
elif Platform.isLinux():
p_dll = CDLL(path.abspath(path.join(path.dirname(__file__), "..", "libs", "libColPic.so")))
else:
p_dll = CDLL(path.abspath(path.join(path.dirname(__file__), "..", "libs", "ColPic_X64.dll")))

result = ""
b_image = img.scaled(width, height, Qt.AspectRatioMode.KeepAspectRatio)
img_size = b_image.size()
Expand All @@ -269,30 +261,29 @@ def _parse_thumbnail_new(cls, img: QImage, width: int, height: int, img_type: st
b = pixel_color.blue() >> 3
rgb = (r << 11) | (g << 5) | b
color16.append(rgb)

# int ColPic_EncodeStr(U16* fromcolor16, int picw, int pich, U8* outputdata, int outputmaxtsize, int colorsmax);
from_color16 = color16.tobytes()
output_data = array('B', [0] * img_size.height() * img_size.width()).tobytes()
result_int = p_dll.ColPic_EncodeStr(from_color16, img_size.height(), img_size.width(), output_data,
img_size.height() * img_size.width(), 1024)
output_data = bytearray(img_size.height() * img_size.width() * 10)
result_int = lib_col_pic.ColPic_EncodeStr(color16, img_size.height(), img_size.width(), output_data,
img_size.height() * img_size.width() * 10, 1024)

data0 = str(output_data).replace('\\x00', '')
data1 = data0[2:len(data0) - 2]
each_max = 1024 - 8 - 1
max_line = int(len(data1) / each_max)
append_len = each_max - 3 - int(len(data1) % each_max)

for i in range(len(data1)):
if i == max_line * each_max:
result += '\r;' + img_type + data1[i]
elif i == 0:
result += img_type + data1[i]
elif i % each_max == 0:
result += '\r' + img_type + data1[i]
else:
result += data1[i]
append_len = each_max - 3 - int(len(data1) % each_max) + 10
j = 0
for i in range(len(output_data)):
if output_data[i] != 0:
if j == max_line * each_max:
result += '\r;' + img_type + chr(output_data[i])
elif j == 0:
result += img_type + chr(output_data[i])
elif j % each_max == 0:
result += '\r' + img_type + chr(output_data[i])
else:
result += chr(output_data[i])
j += 1
result += '\r;'
for j in range(append_len):
for m in range(append_len):
result += '0'

except Exception as e:
Expand Down

0 comments on commit 078f0de

Please sign in to comment.