From 738cc1b4965ed38546274d24a7fcfd979553cff7 Mon Sep 17 00:00:00 2001 From: ketmar Date: Mon, 12 Oct 2009 17:39:56 +0300 Subject: [PATCH] seems that import at least can parse CursorFX file --- src/xcr/xcrthemefx.cpp | 66 +++++++++++++++++++++++++++++++++++++++++++++----- 1 file changed, 60 insertions(+), 6 deletions(-) diff --git a/src/xcr/xcrthemefx.cpp b/src/xcr/xcrthemefx.cpp index ff255d1..81d3794 100644 --- a/src/xcr/xcrthemefx.cpp +++ b/src/xcr/xcrthemefx.cpp @@ -22,13 +22,37 @@ #include "xcrtheme.h" +static const char *curShapeName[] = { + "standard arrow", + "help arrow (the one with '?')", + "working arrow", + "busy cursor", + "precision select", + "text select", + "handwriting", + "unavailable", + "north (vert) resize", + "south resize", + "west (vert-means horiz?) resize", + "east resize", + "north-west resize", + "south-east resize", + "north-east resize", + "south-west resize", + "move", + "alternate select", + "hand", + "button" +}; + + /////////////////////////////////////////////////////////////////////////////// static QByteArray zlibInflate (const void *buf, int bufSz, int destSz) { QByteArray res; z_stream stream; int err; - res.reserve(destSz+1); + res.resize(destSz+1); stream.next_in = (Bytef *)buf; stream.avail_in = bufSz; stream.zalloc = (alloc_func)0; @@ -39,13 +63,16 @@ static QByteArray zlibInflate (const void *buf, int bufSz, int destSz) { err = inflateInit(&stream); if (err != Z_OK) return QByteArray(); err = inflate(&stream, Z_SYNC_FLUSH); + fprintf(stderr, "inflate result: %i\n", err); switch (err) { case Z_STREAM_END: err = inflateEnd(&stream); + fprintf(stderr, "Z_STREAM_END: inflate result: %i\n", err); if (err != Z_OK) return QByteArray(); break; case Z_OK: err = inflateEnd(&stream); + fprintf(stderr, "Z_OK: inflate result: %i\n", err); if (err != Z_OK) return QByteArray(); break; default: return QByteArray(); @@ -77,6 +104,7 @@ XCursorThemeFX::XCursorThemeFX (const QString &aFileName) : XCursorTheme() { bool XCursorThemeFX::parseCursorFXTheme (const QString &aFileName) { + qDebug() << "loading" << aFileName; QFile fl(aFileName); if (!fl.open(QIODevice::ReadOnly)) return false; // shit! QByteArray ba(fl.readAll()); @@ -101,21 +129,27 @@ bool XCursorThemeFX::parseCursorFXTheme (const QString &aFileName) { quint32 ihdrSize = baGetDW(ba, pos); // now read data pos = mainHdrSize; + qDebug() << "reading data from" << pos; QByteArray unp(zlibInflate(ba.constData()+pos, ba.size()-pos, unDataSize)); - if (unp.isEmpty()) return false; + if (unp.isEmpty()) { + qWarning() << "CursorFX: can't depack data"; + return false; + } // process resources pos = ihdrSize; + qDebug() << "resources started at hex" << QString::number(pos, 16); while (pos <= unp.size()-12) { quint32 ipos = pos; // will be fixed later quint32 rtype = baGetDW(unp, pos); - /*quint32 basicHdrSize = */baGetDW(unp, pos); + quint32 basicHdrSize = baGetDW(unp, pos); quint32 itemSize = baGetDW(unp, pos); + qDebug() << "pos hex:" << QString::number(pos, 16) << "rtype:" << rtype << "bhdrsz hex:" << QString::number(basicHdrSize, 16) << "itemsz hex:" << QString::number(itemSize, 16); if (itemSize < 12) { // invalid data qWarning() << "CursorFX: invalid data chunk size"; return false; } - pos += itemSize; // skip it + pos = ipos+itemSize; // skip it if (rtype != 2) continue; // not cursor resource if (itemSize < 0x4c) { qWarning() << "CursorFX: invalid cursor chunk size:" << itemSize; @@ -130,13 +164,23 @@ bool XCursorThemeFX::parseCursorFXTheme (const QString &aFileName) { } quint32 curShape = baGetDW(unp, cps); quint32 curType = baGetDW(unp, cps); - if (curType != 1) continue; // we need only 'normal' cursors if (curShape > 19) { qWarning() << "CursorFX: unknown cursor shape:" << curShape; return false; } + if (curType != 1) { + qDebug() << "skiping 'press' cursor; shape no" << curShape << "named" << curShapeName[curShape]; + continue; + // we need only 'normal' cursors + } + qDebug() << "cursor shape:" << curShape; const char **nlst = findCursorByFXId((int)curShape); - if (!nlst) continue; // unknown cursor type, skip it + if (!nlst) { + // unknown cursor type, skip it + qWarning() << "CursorFX: skiping cursor shape:" << curShapeName[curShape]; + continue; + } + qDebug() << "importing cursor" << *nlst; cps += 4; // skip unknown field quint32 frameCnt = baGetDW(unp, cps); if (frameCnt < 1) frameCnt = 1; // just in case @@ -151,6 +195,16 @@ bool XCursorThemeFX::parseCursorFXTheme (const QString &aFileName) { quint32 imgDataSize = baGetDW(unp, cps); quint32 addonOfs = baGetDW(unp, cps); quint32 addonLen = baGetDW(unp, cps); + qDebug() << + "cursor data:" << + "\n frames:" << frameCnt << + "\n width:" << imgWdt << + "\n height:" << imgHgt << + "\n delay:" << imgDelay << + "\n flags:" << QString::number(aniFlags, 2) << + "\n xhot:" << imgXHot << + "\n yhot:" << imgYHot + ; // now check if we have enought data if (ipos+realHdrSize+imgDataSize > (quint32)pos) { qWarning() << "CursorFX: cursor data too big"; -- 2.11.4.GIT