[prev in list] [next in list] [prev in thread] [next in thread]
List: kde-kimageshop
Subject: LZF compression for data manager - need testing
From: Dmitry Kazakov <dimula73 () gmail ! com>
Date: 2010-06-27 12:26:57
Message-ID: AANLkTilsAYMclaYLKeOPOY6kFCqf3a8jJmN_TyxYTkO8 () mail ! gmail ! com
[Download RAW message or body]
[Attachment #2 (multipart/alternative)]
Hi!
Now, i activated LZF for the data manager. Here is the patch for testing.
Still not done:
1) I don't know how to disable compression of KoStore
2) No UI (and API) for saving with different tile-formats
--
Dmitry Kazakov
[Attachment #5 (text/html)]
Hi!<br><br>Now, i activated LZF for the data manager. Here is the patch for \
testing.<br><br>Still not done:<br>1) I don't know how to disable compression of \
KoStore<br>2) No UI (and API) for saving with different tile-formats<br> <br \
clear="all"><br>-- <br>Dmitry Kazakov<br>
--00151758f42cc7c197048a021ec1--
["0001-Made-LZF-compression-default-for-the-data-manager.patch" (text/x-patch)]
From 23a04b0020dcfad6a66b089ac3ca02cf1fd2691c Mon Sep 17 00:00:00 2001
From: Dmitry Kazakov <dima@laptop.(none)>
Date: Sun, 27 Jun 2010 16:19:32 +0400
Subject: [PATCH] Made LZF compression default for the data manager
---
krita/image/tiles3/kis_tiled_data_manager.cc | 116 ++++++++++++++++++--
krita/image/tiles3/kis_tiled_data_manager.h | 5 +-
krita/image/tiles3/swap/kis_tile_compressor_2.cpp | 4 +-
.../tiles3/swap/kis_tile_compressor_factory.h | 4 +
4 files changed, 117 insertions(+), 12 deletions(-)
diff --git a/krita/image/tiles3/kis_tiled_data_manager.cc \
b/krita/image/tiles3/kis_tiled_data_manager.cc index 607e87f..76d519c 100644
--- a/krita/image/tiles3/kis_tiled_data_manager.cc
+++ b/krita/image/tiles3/kis_tiled_data_manager.cc
@@ -117,9 +117,14 @@ bool KisTiledDataManager::write(KoStore *store)
QReadLocker locker(&m_lock);
if (!store) return false;
- char str[80];
- sprintf(str, "%d\n", m_hashTable->numTiles());
- store->write(str, strlen(str));
+ if(CURRENT_VERSION == LEGACY_VERSION) {
+ char str[80];
+ sprintf(str, "%d\n", m_hashTable->numTiles());
+ store->write(str, strlen(str));
+ }
+ else {
+ writeTilesHeader(store, m_hashTable->numTiles());
+ }
KisTileHashTableIterator iter(m_hashTable);
@@ -149,18 +154,26 @@ bool KisTiledDataManager::read(KoStore *store)
return false;
}
- char str[80];
- quint32 numTiles;
- stream->readLine(str, 79);
+ const qint32 maxLineLength = 79; // Legacy magic
+ QByteArray line = stream->readLine(maxLineLength);
+ line = line.trimmed();
+ quint32 numTiles;
qint32 tilesVersion = LEGACY_VERSION;
- if (str[0] == 'V') {
- sscanf(str, "VERSION %u", &tilesVersion);
- qFatal("Version %u is not implemented yet", tilesVersion);
+ if (line[0] == 'V') {
+ QList<QByteArray> lineItems = line.split(' ');
+
+ QString keyword = lineItems.takeFirst();
+ Q_ASSERT(keyword == "VERSION");
+
+ tilesVersion = lineItems.takeFirst().toInt();
+
+ if(!processTilesHeader(stream, numTiles))
+ return false;
}
else {
- sscanf(str, "%u", &numTiles);
+ numTiles = line.toUInt();
}
KisAbstractTileCompressorSP compressor =
@@ -174,6 +187,89 @@ bool KisTiledDataManager::read(KoStore *store)
return true;
}
+bool KisTiledDataManager::writeTilesHeader(KoStore *store, quint32 numTiles)
+{
+ QString buffer;
+
+ buffer = QString("VERSION %1\n"
+ "TILEWIDTH %2\n"
+ "TILEHEIGHT %3\n"
+ "PIXELSIZE %4\n"
+ "DATA %5\n")
+ .arg(CURRENT_VERSION)
+ .arg(KisTileData::WIDTH)
+ .arg(KisTileData::HEIGHT)
+ .arg(pixelSize())
+ .arg(numTiles);
+
+ store->write(buffer.toAscii());
+ return true;
+}
+
+#define takeOneLine(stream, maxLine, keyword, value) \
+ do { \
+ QByteArray line = stream->readLine(maxLine); \
+ line = line.trimmed(); \
+ QList<QByteArray> lineItems = line.split(' '); \
+ keyword = lineItems.takeFirst(); \
+ value = lineItems.takeFirst().toInt(); \
+ } while(0) \
+
+
+bool KisTiledDataManager::processTilesHeader(QIODevice *stream, quint32 &numTiles)
+{
+ /**
+ * We assume that there is only one version of this header
+ * possible. In case we invent something new, it'll be quite easy
+ * to modify the behavior
+ */
+
+ const qint32 maxLineLength = 25;
+ const qint32 totalNumTests = 4;
+ bool foundDataMark = false;
+ qint32 testsPassed = 0;
+
+ QString keyword;
+ qint32 value;
+
+ while(!foundDataMark && stream->canReadLine()) {
+ takeOneLine(stream, maxLineLength, keyword, value);
+
+ if (keyword == "TILEWIDTH") {
+ if(value != KisTileData::WIDTH)
+ goto wrongString;
+ }
+ else if (keyword == "TILEHEIGHT") {
+ if(value != KisTileData::HEIGHT)
+ goto wrongString;
+ }
+ else if (keyword == "PIXELSIZE") {
+ if((quint32)value != pixelSize())
+ goto wrongString;
+ }
+ else if (keyword == "DATA") {
+ numTiles = value;
+ foundDataMark = true;
+ }
+ else {
+ goto wrongString;
+ }
+
+ testsPassed++;
+ }
+
+ if(testsPassed != totalNumTests) {
+ warnTiles << "Not enough fields of tiles header present"
+ << testsPassed << "of" << totalNumTests;
+ }
+
+ return testsPassed == totalNumTests;
+
+wrongString:
+ warnTiles << "Wrong string in tiles header:" << keyword << value;
+ return false;
+}
+
void KisTiledDataManager::purge(const QRect& area)
{
QWriteLocker locker(&m_lock);
diff --git a/krita/image/tiles3/kis_tiled_data_manager.h \
b/krita/image/tiles3/kis_tiled_data_manager.h index 832072d..322a4df 100644
--- a/krita/image/tiles3/kis_tiled_data_manager.h
+++ b/krita/image/tiles3/kis_tiled_data_manager.h
@@ -97,7 +97,7 @@ class KRITAIMAGE_EXPORT KisTiledDataManager : public KisShared
{
private:
static const qint32 LEGACY_VERSION = 1;
- static const qint32 CURRENT_VERSION = 1;
+ static const qint32 CURRENT_VERSION = 2;
protected:
/*FIXME:*/
@@ -320,6 +320,9 @@ private:
qint32 yToRow(qint32 y) const;
private:
+ bool writeTilesHeader(KoStore *store, quint32 numTiles);
+ bool processTilesHeader(QIODevice *stream, quint32 &numTiles);
+
qint32 divideRoundDown(qint32 x, const qint32 y) const;
KisTileDataWrapper pixelPtr(qint32 x, qint32 y,
enum KisTileDataWrapper::accessType type);
diff --git a/krita/image/tiles3/swap/kis_tile_compressor_2.cpp \
b/krita/image/tiles3/swap/kis_tile_compressor_2.cpp index cc60f8d..ad332e5 100644
--- a/krita/image/tiles3/swap/kis_tile_compressor_2.cpp
+++ b/krita/image/tiles3/swap/kis_tile_compressor_2.cpp
@@ -54,6 +54,9 @@ void KisTileCompressor2::writeTile(KisTileSP tile, KoStore *store)
void KisTileCompressor2::readTile(KoStore *store, KisTiledDataManager *dm)
{
+ const qint32 tileDataSize = TILE_DATA_SIZE(pixelSize(dm));
+ prepareStreamingBuffer(tileDataSize);
+
QIODevice *stream = store->device();
QByteArray header = stream->readLine(maxHeaderLength());
@@ -74,7 +77,6 @@ void KisTileCompressor2::readTile(KoStore *store, \
KisTiledDataManager *dm) stream->read(m_streamingBuffer.data(), dataSize);
tile->lockForWrite();
-
decompressTileData((quint8*)m_streamingBuffer.data(), dataSize, \
tile->tileData()); tile->unlock();
}
diff --git a/krita/image/tiles3/swap/kis_tile_compressor_factory.h \
b/krita/image/tiles3/swap/kis_tile_compressor_factory.h index 2e1b138..fb46e74 100644
--- a/krita/image/tiles3/swap/kis_tile_compressor_factory.h
+++ b/krita/image/tiles3/swap/kis_tile_compressor_factory.h
@@ -20,6 +20,7 @@
#define __KIS_TILE_COMPRESSOR_FACTORY_H
#include "tiles3/swap/kis_legacy_tile_compressor.h"
+#include "tiles3/swap/kis_tile_compressor_2.h"
class KRITAIMAGE_EXPORT KisTileCompressorFactory
{
@@ -29,6 +30,9 @@ public:
case 1:
return new KisLegacyTileCompressor();
break;
+ case 2:
+ return new KisTileCompressor2();
+ break;
default:
qFatal("Unknown version of the tiles");
};
--
1.6.4.2
_______________________________________________
kimageshop mailing list
kimageshop@kde.org
https://mail.kde.org/mailman/listinfo/kimageshop
[prev in list] [next in list] [prev in thread] [next in thread]
Configure |
About |
News |
Add a list |
Sponsored by KoreLogic