[prev in list] [next in list] [prev in thread] [next in thread]
List: kde-commits
Subject: koffice/krita/image/tiles3
From: Dmitry Kazakov <dimula73 () gmail ! com>
Date: 2010-06-23 11:31:07
Message-ID: 20100623113107.ECC41AC8DA () svn ! kde ! org
[Download RAW message or body]
SVN commit 1141740 by dkazakov:
Connected a legacy compressor to the data manager
M +9 -37 kis_tiled_data_manager.cc
M +5 -3 swap/kis_abstract_tile_compressor.h
M +6 -4 swap/kis_legacy_tile_compressor.cpp
M +2 -2 swap/kis_legacy_tile_compressor.h
M +38 -6 tests/kis_legacy_tile_compressor_test.cpp
--- trunk/koffice/krita/image/tiles3/kis_tiled_data_manager.cc #1141739:1141740
@@ -26,6 +26,7 @@
#include "kis_tiled_data_manager.h"
#include "kis_tiled_data_manager_p.h"
#include "kis_memento_manager.h"
+#include "swap/kis_legacy_tile_compressor.h"
#include <KoStore.h>
@@ -116,27 +117,17 @@
if (!store) return false;
char str[80];
-
sprintf(str, "%d\n", m_hashTable->numTiles());
store->write(str, strlen(str));
KisTileHashTableIterator iter(m_hashTable);
KisTileSP tile;
- qint32 x, y;
- qint32 width, height;
- const qint32 tileDataSize = KisTileData::HEIGHT * KisTileData::WIDTH * pixelSize();
+ KisLegacyTileCompressor compressor;
while (tile = iter.tile()) {
- tile->extent().getRect(&x, &y, &width, &height);
- sprintf(str, "%d,%d,%d,%d\n", x, y, width, height);
- store->write(str, strlen(str));
-
- tile->lockForRead();
- store->write((char *)tile->data(), tileDataSize);
- tile->unlock();
-
+ compressor.writeTile(tile, store);
++iter;
}
@@ -144,47 +135,28 @@
}
bool KisTiledDataManager::read(KoStore *store)
{
- QWriteLocker locker(&m_lock);
if (!store) return false;
+ clear();
- //clear(); - needed?
-
+ QWriteLocker locker(&m_lock);
KisMementoSP nothing = m_mementoManager->getMemento();
- KisTileSP tile;
- const qint32 tileDataSize = KisTileData::HEIGHT * KisTileData::WIDTH * pixelSize();
- qint32 x, y;
- qint32 width, height;
- char str[80];
-
QIODevice *stream = store->device();
if (!stream) {
m_mementoManager->commit();
return false;
}
+ char str[80];
quint32 numTiles;
stream->readLine(str, 79);
sscanf(str, "%u", &numTiles);
- for (quint32 i = 0; i < numTiles; i++) {
- stream->readLine(str, 79);
- sscanf(str, "%d,%d,%d,%d", &x, &y, &width, &height);
- // the following is only correct as long as tile size is not changed
- // The first time we change tilesize the dimensions just read needs to be respected
- // but for now we just assume that tiles are the same size as ever.
- qint32 row = yToRow(y);
- qint32 col = xToCol(x);
- bool created;
+ KisLegacyTileCompressor compressor;
- tile = m_hashTable->getTileLazy(col, row, created);
- if (created)
- updateExtent(col, row);
-
- tile->lockForWrite();
- store->read((char *)tile->data(), tileDataSize);
- tile->unlock();
+ for (quint32 i = 0; i < numTiles; i++) {
+ compressor.readTile(store, this);
}
m_mementoManager->commit();
--- trunk/koffice/krita/image/tiles3/swap/kis_abstract_tile_compressor.h #1141739:1141740
@@ -19,7 +19,7 @@
#ifndef __KIS_ABSTRACT_TILE_COMPRESSOR_H
#define __KIS_ABSTRACT_TILE_COMPRESSOR_H
-#include <QIODevice>
+#include <KoStore.h>
#include "krita_export.h"
#include "../kis_tile.h"
@@ -35,13 +35,15 @@
KisAbstractTileCompressor();
virtual ~KisAbstractTileCompressor();
+public:
+
/**
* Compresses the \a tile and writes it into the \a stream.
* Used by datamanager in load/save routines
*
* \see compressTile()
*/
- virtual void writeTile(KisTileSP tile, QIODevice *stream) = 0;
+ virtual void writeTile(KisTileSP tile, KoStore *store) = 0;
/**
* Decompresses the \a tile from the \a stream.
@@ -49,7 +51,7 @@
*
* \see decompressTile()
*/
- virtual void readTile(QIODevice *stream, KisTiledDataManager *dm) = 0;
+ virtual void readTile(KoStore *store, KisTiledDataManager *dm) = 0;
/**
* Compresses a \a tileData and writes it into the \a buffer.
--- trunk/koffice/krita/image/tiles3/swap/kis_legacy_tile_compressor.cpp #1141739:1141740
@@ -18,6 +18,7 @@
#include "kis_legacy_tile_compressor.h"
+#include <QIODevice>
#define TILE_DATA_SIZE(pixelSize) ((pixelSize) * KisTileData::WIDTH * KisTileData::HEIGHT)
@@ -29,7 +30,7 @@
{
}
-void KisLegacyTileCompressor::writeTile(KisTileSP tile, QIODevice *stream)
+void KisLegacyTileCompressor::writeTile(KisTileSP tile, KoStore *store)
{
const qint32 tileDataSize = TILE_DATA_SIZE(tile->pixelSize());
@@ -38,16 +39,16 @@
writeHeader(tile, headerBuffer);
- stream->write((char *)headerBuffer, strlen((char *)headerBuffer));
+ store->write((char *)headerBuffer, strlen((char *)headerBuffer));
tile->lockForRead();
- stream->write((char *)tile->data(), tileDataSize);
+ store->write((char *)tile->data(), tileDataSize);
tile->unlock();
delete[] headerBuffer;
}
-void KisLegacyTileCompressor::readTile(QIODevice *stream, KisTiledDataManager *dm)
+void KisLegacyTileCompressor::readTile(KoStore *store, KisTiledDataManager *dm)
{
const qint32 tileDataSize = TILE_DATA_SIZE(pixelSize(dm));
@@ -57,6 +58,7 @@
qint32 x, y;
qint32 width, height;
+ QIODevice *stream = store->device();
stream->readLine((char *)headerBuffer, bufferSize);
sscanf((char *) headerBuffer, "%d,%d,%d,%d", &x, &y, &width, &height);
--- trunk/koffice/krita/image/tiles3/swap/kis_legacy_tile_compressor.h #1141739:1141740
@@ -28,8 +28,8 @@
KisLegacyTileCompressor();
virtual ~KisLegacyTileCompressor();
- void writeTile(KisTileSP tile, QIODevice *stream);
- void readTile(QIODevice *stream, KisTiledDataManager *dm);
+ void writeTile(KisTileSP tile, KoStore *store);
+ void readTile(KoStore *store, KisTiledDataManager *dm);
void compressTileData(KisTileData *tileData,quint8 *buffer,
--- trunk/koffice/krita/image/tiles3/tests/kis_legacy_tile_compressor_test.cpp #1141739:1141740
@@ -22,6 +22,39 @@
#include "tiles3/kis_tiled_data_manager.h"
#include "tiles3/swap/kis_legacy_tile_compressor.h"
+#include <KoStore_p.h>
+
+class KoStoreFake : public KoStore
+{
+public:
+ KoStoreFake() {
+ d_ptr->stream = &m_buffer;
+ d_ptr->isOpen = true;
+ d_ptr->mode = KoStore::Write;
+ m_buffer.open(QIODevice::ReadWrite);
+ }
+ ~KoStoreFake() {
+ // Oh, no, please do not clean anything! :)
+ d_ptr->stream = 0;
+ d_ptr->isOpen = false;
+ }
+
+ void startReading() {
+ m_buffer.seek(0);
+ d_ptr->mode = KoStore::Read;
+ }
+
+ bool openWrite(const QString&) { return true; }
+ bool openRead(const QString&) { return true; }
+ bool closeRead() { return true; }
+ bool closeWrite() { return true; }
+ bool enterRelativeDirectory(const QString&) { return true; }
+ bool enterAbsoluteDirectory(const QString&) { return true; }
+ bool fileExists(const QString&) const { return true; }
+private:
+ QBuffer m_buffer;
+};
+
bool KisLegacyTileCompressorTest::memoryIsFilled(quint8 c, quint8 *mem, qint32 size)
{
for(; size > 0; size--)
@@ -48,14 +81,13 @@
tile00 = dm.getTile(0, 0, false);
QVERIFY(memoryIsFilled(oddPixel1, tile00->data(), TILESIZE));
- QBuffer buffer;
- buffer.open(QBuffer::ReadWrite);
+ KoStoreFake fakeStore;
KisLegacyTileCompressor compressor;
- compressor.writeTile(tile00, &buffer);
+ compressor.writeTile(tile00, &fakeStore);
tile00 = 0;
- buffer.seek(0);
+ fakeStore.startReading();
dm.clear();
@@ -63,7 +95,7 @@
QVERIFY(memoryIsFilled(defaultPixel, tile00->data(), TILESIZE));
tile00 = 0;
- compressor.readTile(&buffer, &dm);
+ compressor.readTile(&fakeStore, &dm);
tile00 = dm.getTile(0, 0, false);
QVERIFY(memoryIsFilled(oddPixel1, tile00->data(), TILESIZE));
@@ -81,7 +113,7 @@
* globalTileDataStore is not exported out of kritaimage.so,
* so we get it from the data manager
*/
- KisTiledDataManager dm(1, &oddPixel1);
+ KisTiledDataManager dm(pixelSize, &oddPixel1);
KisTileSP tile = dm.getTile(0, 0, true);
tile->lockForWrite();
[prev in list] [next in list] [prev in thread] [next in thread]
Configure |
About |
News |
Add a list |
Sponsored by KoreLogic