ON4QZ / QSSTV

Receive and transmit images over radio using analog SSTV or digital DRM
GNU General Public License v3.0
82 stars 10 forks source link

Query: template file format documentation #45

Open sjlongland opened 3 months ago

sjlongland commented 3 months ago

Hi,

A silly question, is there some documentation on how the template files are constructed? I have a number of stock images and I'd like to mass-create different templates based on those stock images.

I already have a netpbm-based pipeline orchestrated with make that can take those stock images, pad or crop images to 4:3 aspect ratio, scale to 320×240px, add a 16px header and apply a call-sign watermark.

There are two call-signs I use: my normal one VK4MSL, but 3 days a year, ACMA's class license permits us to substitute VK with AX, and so I've got watermarks and headers with AX4MSL.

The challenge is creating the templates is a manual process. At best I can open up a template based on one of the VK-watermarked stock images, delete the background image, insert an AX-watermarked image, send it to the back, expand it, then save the resulting template as a new file. This is tedious.

Pixel-positions of text fields in the template do not change between the VK and AX variants. Assuming the positioning and font selection information of each text field and replay field is known, how would one go about constructing a template file?

hspil commented 3 months ago

Based on a cursory glance at what I think is the relevant code, I get the impression is that it is .png, just like "Save as Image" just with a different file extension.
I'm reading editor.cpp and it seems like very similar code is being used for editor::slotFileSaveImage() and editor::slotFileSaveTemplate()

sjlongland commented 3 months ago

Yep, it could be a PNG extension that describes the template… but it's not just a PNG. PNGs from what I understand don't natively implement templating.

Likely there's some custom "chunk" format used to describe the different elements of the template that's embedded in the PNG. Macromedia Fireworks used to do something similar to implement layers, but this was an extension of, rather than a built-in feature of, the PNG format.

dl8dtl commented 3 months ago

Actual saving happens in editorScene::save. Based on the templ parameter, it eventually dispatches to:

  if(!f.open(QIODevice::WriteOnly)) return false;
  QDataStream str(&f);
  str.setVersion(QDataStream::Qt_4_4);
  // Header with a "magic number" and a version
  str << (quint32) MAGICNUMBER;
  str <<  CONFIGVERSION;
  str << (quint16) QDataStream::Qt_4_4;
  graphItemBase *it;
  foreach(QGraphicsItem *t,items())
    {
      it=qgraphicsitem_cast<graphItemBase *>(t);
      if(t->type()>graphItemBase::BASE)
        {
          it->save(str);
        }
    }
  f.close();

So the actual code to write things out is in graphItemBase::save.