I wrote the following script for my personal need.
(This is not a pixel_perfect feature and code not cleaned up)
also I do not really understand bytearray part. so sorry if there are any mistakes.
If anyone is interested, please try it.
(usage)
copy all code ā save it in any folder you want. named (e.g.) removedoubles.py
ā enable ten script plugin ā assign above script ā drawing
ā press the specified shortcut key
I tried LibreSprite but I still like Krita
and I hope pixel perfect feature will be officially implemented someday.
sorry for my bad English.
from krita import *
from PyQt5.QtCore import QByteArray
doc = Krita.instance().activeDocument()
currentLayer = doc.activeNode()
def remove_doubles():
byte_ = QByteArray(b'\x00\x00\x00\x00')#transparent
black_byte_ = QByteArray(b'\x00\x00\x00\xff')#black
t = b'\x00\x00\x00\x00'
b = b'\x00\x00\x00\xff'
for i in range(doc.width()):
for j in range(doc.height()):
r = currentLayer.pixelData(i+1, j+0, 1,1)
l = currentLayer.pixelData(i-1, j+0, 1,1)
u = currentLayer.pixelData(i+0, j-1, 1,1)
d = currentLayer.pixelData(i+0, j+1, 1,1)
ru = currentLayer.pixelData(i+1, j-1, 1,1)
rd = currentLayer.pixelData(i+1, j+1, 1,1)
lu = currentLayer.pixelData(i-1, j-1, 1,1)
ld = currentLayer.pixelData(i-1, j+1, 1,1)
if r == t and \
l == t and \
u == t and \
d == t and \
ru == t and \
rd == t and \
lu == t and \
ld == t:
currentLayer.setPixelData(byte_, i, j, 1, 1)
elif r == b and \
l == t and \
u == t and \
d == b and \
ru == t and \
rd == t and \
lu == t and \
ld == t:
currentLayer.setPixelData(byte_, i, j, 1, 1)
elif l == b and \
r == t and \
u == t and \
d == b and \
ru == t and \
rd == t and \
lu == t and \
ld == t:
currentLayer.setPixelData(byte_, i, j, 1, 1)
elif r == b and \
l == t and \
d == t and \
u == b and \
ru == t and \
rd == t and \
lu == t and \
ld == t:
currentLayer.setPixelData(byte_, i, j, 1, 1)
elif l == b and \
r == t and \
d == t and \
u == b and \
ru == t and \
rd == t and \
lu == t and \
ld == t:
currentLayer.setPixelData(byte_, i, j, 1, 1)
elif l == b and \
r == t and \
d == t and \
u == b and \
ru == b and \
rd == t and \
lu == t and \
ld == b:
currentLayer.setPixelData(byte_, i, j, 1, 1)
elif l == b and \
r == t and \
u == t and \
d == b and \
rd == b and \
ru == t and \
ld == t and \
lu == b:
currentLayer.setPixelData(byte_, i, j, 1, 1)
elif l == b and \
r == t and \
u == t and \
d == b and \
rd == b and \
ru == t and \
ld == t and \
lu == t:
currentLayer.setPixelData(byte_, i, j, 1, 1)
elif r == b and \
l == t and \
u == t and \
d == b and \
ru == b and \
rd == t and \
lu == t:
currentLayer.setPixelData(byte_, i, j, 1, 1)
elif l == b and \
r == t and \
d == t and \
u == b and \
rd == t and \
ru == b and \
ld == t and \
lu == t:
currentLayer.setPixelData(byte_, i, j, 1, 1)
elif r == b and \
l == t and \
d == t and \
u == b and \
rd == t and \
ru == t and \
ld == t and \
lu == b:
currentLayer.setPixelData(byte_, i, j, 1, 1)
elif r == b and \
l == t and \
d == t and \
u == b and \
rd == b and \
ru == t and \
ld == t and \
lu == t:
currentLayer.setPixelData(byte_, i, j, 1, 1)
elif l == b and \
r == t and \
d == t and \
u == b and \
rd == t and \
ru == t and \
ld == b and \
lu == t:
currentLayer.setPixelData(byte_, i, j, 1, 1)
doc.refreshProjection()
doc.waitForDone()
QMessageBox.information(QWidget(), "", "completed")
remove_doubles()