Let me give you an example, this is how I’m getting the canvas previews out.
def gen_preview(outdir, db):
conn = sqlite3.connect(db)
cur = conn.cursor()
preview_q = 'SELECT ImageData, ImageWidth, ImageHeight FROM CanvasPreview;'
cur.execute(preview_q)
rows = cur.fetchall()
for (i, row) in enumerate(rows):
with open(os.path.join(outdir, 'canvas_preview{0}.png'), 'wb+') as f:
f.write(row[0])
Note that the Python code simply exists to prototype, once I have something that works really well I will rewrite it in a language that is much easier to link against, either Rust, C++ or Go
But as you can see it’s really not that difficult it’s just there are a lot of columns that contain enumerations and I can’t tell what the numbers are supposed to mean. Also the pixel formats are sometimes very strange. Like even weird stuff like BGR565. And that’s just a constant. So what I’m having to do is, every time I figure out what blend mode is right, I mark that down and create a constant for it. I don’t even know necessarily that I’m matching exactly what is in Clip Studio but I know enough about raster graphics to know I have to be close lol.
Maybe you’re mistaken about my intention, I want to have the final format contain everything that the original did to the extent that is possible. Meaning, the same layer names, the same hierarchy, blend modes set rather than enforced etc. That way you can truly transition from CLIP STUDIO to Krita. The point is not to just get a full resolution raster out of it because I can just ask the artist for that
Seems simple yes.
But I’m curious about a file with miscellaneous properties, layers, color spaces, color profiles, …
If you have CSP files you can share (or someone else) taking a look inside that could be funny
Krita file format is not really the best one for that…
I’ve already written a Krita file decoder here (not only the preview, but practically everything in KRA file)
It’s not complete (written 2 year ago and file format may have new data entry now)
But I can tell you if you want to write a KRA file it could takes time if you want to implement everything, also taking in account all possible combination of color spaces, layers types, properties…
I meant something vaguely like this Python script using the Krita API, at least for testing the output quickly:
from Krita import *
app = Krita.instance()
# create a document with variables we read from the file at some point
app.createDocument(width, height, name, colorModel, colorDepth, profile, resolution)
# create a layer with variables and data we read at some point
node = doc.createNode(layerName, layerType)
node.setPixelData(layerData, posX, posY, width, height)
I’m with @Grum999. Make the library that decodes the format. Then have an app or utility in the lib that outputs simple documents with all the csp info (xml or whatever + png or other). That way you can figure out the decoding faster. Then, when you know the lib works (I mean all the possible csp options), make the translation code to other known formats. In my opinion thinking about other apps formats now is like putting the cart before the horse. Csp has a lot of options per document, some of which are exclusive to csp, so in any case you have to implement a way to output all of that in a somewhat raw (but legible) fashion.
Edit: furthermore, if you achieve that, i’m sure other people will appear that will quickly use the lib to add support to other apps.