r25067 by jghali - Code cleanup
scribus-commit
scribus-commit at lists.scribus.net
Sun Mar 27 14:24:10 UTC 2022
Author: jghali
Date: Sun Mar 27 14:24:10 2022
New Revision: 25067
URL: http://scribus.net/websvn/listing.php?repname=Scribus&sc=1&rev=25067
Log:
Code cleanup
Modified:
branches/Version15x/Scribus/scribus/scstreamfilter.cpp
branches/Version15x/Scribus/scribus/scstreamfilter.h
branches/Version15x/Scribus/scribus/scstreamfilter_ascii85.h
branches/Version15x/Scribus/scribus/scstreamfilter_flate.cpp
branches/Version15x/Scribus/scribus/scstreamfilter_flate.h
branches/Version15x/Scribus/scribus/scstreamfilter_jpeg.cpp
branches/Version15x/Scribus/scribus/scstreamfilter_jpeg.h
branches/Version15x/Scribus/scribus/scstreamfilter_rc4.cpp
branches/Version15x/Scribus/scribus/scstreamfilter_rc4.h
Modified: branches/Version15x/Scribus/scribus/scstreamfilter.cpp
URL: http://scribus.net/websvn/diff.php?repname=Scribus&rev=25067&path=/branches/Version15x/Scribus/scribus/scstreamfilter.cpp
==============================================================================
--- branches/Version15x/Scribus/scribus/scstreamfilter.cpp (original)
+++ branches/Version15x/Scribus/scribus/scstreamfilter.cpp Sun Mar 27 14:24:10 2022
@@ -13,21 +13,17 @@
using namespace std;
ScStreamFilter::ScStreamFilter(QDataStream* stream)
+ : m_filterMode (FilterToStream),
+ m_dataStream(stream)
{
- assert(stream != nullptr);
- m_dataStream = stream;
- m_filter = nullptr;
- m_filterMode = FilterToStream;
- m_writtenToStream = 0;
+ assert(m_dataStream != nullptr);
}
ScStreamFilter::ScStreamFilter(ScStreamFilter* filter)
+ : m_filterMode(FilterToFilter),
+ m_filter(filter)
{
- assert(filter != nullptr);
- m_dataStream = nullptr;
- m_filter = filter;
- m_filterMode = FilterToFilter;
- m_writtenToStream = 0;
+ assert(m_filter != nullptr);
}
bool ScStreamFilter::writeDataInternal(const char* data, int dataLen)
Modified: branches/Version15x/Scribus/scribus/scstreamfilter.h
URL: http://scribus.net/websvn/diff.php?repname=Scribus&rev=25067&path=/branches/Version15x/Scribus/scribus/scstreamfilter.h
==============================================================================
--- branches/Version15x/Scribus/scribus/scstreamfilter.h (original)
+++ branches/Version15x/Scribus/scribus/scstreamfilter.h Sun Mar 27 14:24:10 2022
@@ -13,26 +13,10 @@
class ScStreamFilter
{
-protected:
-
- typedef enum
- {
- FilterToStream = 0,
- FilterToFilter = 1
- } FilterMode;
-
- int m_writtenToStream;
- FilterMode m_filterMode;
- QDataStream* m_dataStream;
- ScStreamFilter* m_filter;
-
- bool writeDataInternal(const char* data, int dataLen);
-
public:
-
ScStreamFilter(QDataStream* stream);
ScStreamFilter(ScStreamFilter* filter);
- virtual ~ScStreamFilter() {};
+ virtual ~ScStreamFilter() = default;
virtual bool openFilter();
virtual bool closeFilter();
@@ -41,6 +25,20 @@
virtual bool writeData(const char* data, int dataLen) = 0;
int writtenToStream();
+
+protected:
+ enum FilterMode
+ {
+ FilterToStream = 0,
+ FilterToFilter = 1
+ };
+
+ int m_writtenToStream { 0 };
+ FilterMode m_filterMode;
+ QDataStream* m_dataStream { nullptr };
+ ScStreamFilter* m_filter { nullptr };
+
+ bool writeDataInternal(const char* data, int dataLen);
};
class ScNullEncodeFilter : public ScStreamFilter
@@ -49,7 +47,7 @@
ScNullEncodeFilter(QDataStream* stream) : ScStreamFilter(stream) {};
ScNullEncodeFilter(ScStreamFilter* filter) : ScStreamFilter(filter) {};
- virtual bool writeData(const char* data, int dataLen) { return writeDataInternal(data, dataLen); }
+ bool writeData(const char* data, int dataLen) override { return writeDataInternal(data, dataLen); }
};
#endif
Modified: branches/Version15x/Scribus/scribus/scstreamfilter_ascii85.h
URL: http://scribus.net/websvn/diff.php?repname=Scribus&rev=25067&path=/branches/Version15x/Scribus/scribus/scstreamfilter_ascii85.h
==============================================================================
--- branches/Version15x/Scribus/scribus/scstreamfilter_ascii85.h (original)
+++ branches/Version15x/Scribus/scribus/scstreamfilter_ascii85.h Sun Mar 27 14:24:10 2022
@@ -14,22 +14,21 @@
class ScASCII85EncodeFilter : public ScStreamFilter
{
-protected:
-
- QByteArray m_buffer;
- int m_buffer_pending;
-
- unsigned char m_four_tuple[4];
- int m_four_tuple_pending;
-
public:
ScASCII85EncodeFilter(QDataStream* stream);
ScASCII85EncodeFilter(ScStreamFilter* filter);
- virtual bool openFilter ();
- virtual bool closeFilter();
+ bool openFilter () override;
+ bool closeFilter() override;
- virtual bool writeData(const char* data, int dataLen);
+ bool writeData(const char* data, int dataLen) override;
+
+protected:
+ QByteArray m_buffer;
+ int m_buffer_pending { 0 };
+
+ unsigned char m_four_tuple[4] { 0 };
+ int m_four_tuple_pending { 0 };
};
#endif
Modified: branches/Version15x/Scribus/scribus/scstreamfilter_flate.cpp
URL: http://scribus.net/websvn/diff.php?repname=Scribus&rev=25067&path=/branches/Version15x/Scribus/scribus/scstreamfilter_flate.cpp
==============================================================================
--- branches/Version15x/Scribus/scribus/scstreamfilter_flate.cpp (original)
+++ branches/Version15x/Scribus/scribus/scstreamfilter_flate.cpp Sun Mar 27 14:24:10 2022
@@ -10,6 +10,7 @@
#include "scstreamfilter_flate.h"
#include <cstdlib>
+#include <cstring>
#include <zlib.h>
#include <QDataStream>
@@ -17,29 +18,27 @@
#define BUFFER_SIZE 16384
struct ScFlateEncodeFilterData
{
- z_stream zlib_stream;
- unsigned char input_buffer [BUFFER_SIZE];
- unsigned char output_buffer[BUFFER_SIZE];
+ z_stream zlib_stream;
+ unsigned char input_buffer [BUFFER_SIZE];
+ unsigned char output_buffer[BUFFER_SIZE];
};
ScFlateEncodeFilter::ScFlateEncodeFilter(QDataStream* stream)
: ScStreamFilter(stream)
{
- m_filterData = nullptr;
- m_openedFilter = false;
+
}
ScFlateEncodeFilter::ScFlateEncodeFilter(ScStreamFilter* filter)
: ScStreamFilter(filter)
{
- m_filterData = nullptr;
- m_openedFilter = false;
+
}
ScFlateEncodeFilter::~ScFlateEncodeFilter()
{
if (m_filterData && m_openedFilter)
- closeFilter();
+ ScFlateEncodeFilter::closeFilter();
freeData();
}
@@ -69,17 +68,18 @@
}
m_filterData->zlib_stream.next_in = m_filterData->input_buffer;
- m_filterData->zlib_stream.avail_in = 0;
- m_filterData->zlib_stream.next_out = m_filterData->output_buffer;
- m_filterData->zlib_stream.avail_out = BUFFER_SIZE;
+ m_filterData->zlib_stream.avail_in = 0;
+ m_filterData->zlib_stream.next_out = m_filterData->output_buffer;
+ m_filterData->zlib_stream.avail_out = BUFFER_SIZE;
m_openedFilter = ScStreamFilter::openFilter();
return m_openedFilter;
}
+
bool ScFlateEncodeFilter::closeFilter()
{
bool closeSucceed = writeDeflate(true);
- deflateEnd (&m_filterData->zlib_stream);
+ deflateEnd (&m_filterData->zlib_stream);
m_openedFilter = false;
closeSucceed &= ScStreamFilter::closeFilter();
return closeSucceed;
@@ -94,17 +94,18 @@
if (!m_filterData)
return false;
- while (dataLen) {
- count = dataLen;
- if (count > BUFFER_SIZE - m_filterData->zlib_stream.avail_in)
- count = BUFFER_SIZE - m_filterData->zlib_stream.avail_in;
- memcpy (m_filterData->input_buffer + m_filterData->zlib_stream.avail_in, p, count);
- p += count;
- m_filterData->zlib_stream.avail_in += count;
- dataLen -= count;
+ while (dataLen)
+ {
+ count = dataLen;
+ if (count > BUFFER_SIZE - m_filterData->zlib_stream.avail_in)
+ count = BUFFER_SIZE - m_filterData->zlib_stream.avail_in;
+ memcpy (m_filterData->input_buffer + m_filterData->zlib_stream.avail_in, p, count);
+ p += count;
+ m_filterData->zlib_stream.avail_in += count;
+ dataLen -= count;
- if (m_filterData->zlib_stream.avail_in == BUFFER_SIZE)
- deflateSuccess &= writeDeflate(false);
+ if (m_filterData->zlib_stream.avail_in == BUFFER_SIZE)
+ deflateSuccess &= writeDeflate(false);
}
return deflateSuccess;
@@ -114,25 +115,26 @@
{
int ret;
bool deflateSuccess = true;
- bool finished;
+ bool finished;
- do {
+ do
+ {
ret = deflate (&m_filterData->zlib_stream, flush ? Z_FINISH : Z_NO_FLUSH);
- if (flush || m_filterData->zlib_stream.avail_out == 0)
- {
+ if (flush || m_filterData->zlib_stream.avail_out == 0)
+ {
deflateSuccess &= writeDataInternal((const char*) m_filterData->output_buffer, BUFFER_SIZE - m_filterData->zlib_stream.avail_out);
- m_filterData->zlib_stream.next_out = m_filterData->output_buffer;
- m_filterData->zlib_stream.avail_out = BUFFER_SIZE;
- }
+ m_filterData->zlib_stream.next_out = m_filterData->output_buffer;
+ m_filterData->zlib_stream.avail_out = BUFFER_SIZE;
+ }
- finished = true;
- if (m_filterData->zlib_stream.avail_in != 0)
- finished = false;
- if (flush && ret != Z_STREAM_END)
- finished = false;
+ finished = true;
+ if (m_filterData->zlib_stream.avail_in != 0)
+ finished = false;
+ if (flush && ret != Z_STREAM_END)
+ finished = false;
- } while (!finished);
+ } while (!finished);
- m_filterData->zlib_stream.next_in = m_filterData->input_buffer;
+ m_filterData->zlib_stream.next_in = m_filterData->input_buffer;
return deflateSuccess;
}
Modified: branches/Version15x/Scribus/scribus/scstreamfilter_flate.h
URL: http://scribus.net/websvn/diff.php?repname=Scribus&rev=25067&path=/branches/Version15x/Scribus/scribus/scstreamfilter_flate.h
==============================================================================
--- branches/Version15x/Scribus/scribus/scstreamfilter_flate.h (original)
+++ branches/Version15x/Scribus/scribus/scstreamfilter_flate.h Sun Mar 27 14:24:10 2022
@@ -14,24 +14,23 @@
class ScFlateEncodeFilter : public ScStreamFilter
{
-protected:
-
- ScFlateEncodeFilterData* m_filterData;
-
- void freeData();
- bool m_openedFilter;
-
- bool writeDeflate(bool flush);
-
public:
ScFlateEncodeFilter(QDataStream* stream);
ScFlateEncodeFilter(ScStreamFilter* filter);
- ~ScFlateEncodeFilter();
+ ~ScFlateEncodeFilter() override;
- virtual bool openFilter ();
- virtual bool closeFilter();
+ bool openFilter() override;
+ bool closeFilter() override;
- virtual bool writeData(const char* data, int dataLen);
+ bool writeData(const char* data, int dataLen) override;
+
+protected:
+ bool m_openedFilter { false };
+ ScFlateEncodeFilterData* m_filterData { nullptr };
+
+ void freeData();
+
+ bool writeDeflate(bool flush);
};
#endif
Modified: branches/Version15x/Scribus/scribus/scstreamfilter_jpeg.cpp
URL: http://scribus.net/websvn/diff.php?repname=Scribus&rev=25067&path=/branches/Version15x/Scribus/scribus/scstreamfilter_jpeg.cpp
==============================================================================
--- branches/Version15x/Scribus/scribus/scstreamfilter_jpeg.cpp (original)
+++ branches/Version15x/Scribus/scribus/scstreamfilter_jpeg.cpp Sun Mar 27 14:24:10 2022
@@ -46,11 +46,11 @@
struct ScJpegDestinationMgr : public jpeg_destination_mgr
{
- ScJpegEncodeFilter *filter;
- JOCTET buffer[BUFFER_SIZE];
+ ScJpegEncodeFilter* filter { nullptr };
+ JOCTET buffer[BUFFER_SIZE];
public:
- ScJpegDestinationMgr(ScJpegEncodeFilter *);
+ ScJpegDestinationMgr(ScJpegEncodeFilter *);
static boolean jpegEmptyBuffer(j_compress_ptr cinfo);
static void jpegDestinationInit(j_compress_ptr);
@@ -63,49 +63,49 @@
boolean ScJpegDestinationMgr::jpegEmptyBuffer(j_compress_ptr cinfo)
{
- ScJpegDestinationMgr* dest = (ScJpegDestinationMgr*) cinfo->dest;
-
- bool written = dest->filter->writeDataInternal((const char*) dest->buffer, BUFFER_SIZE);
- if (!written)
- (*cinfo->err->error_exit)((j_common_ptr) cinfo);
-
- dest->next_output_byte = dest->buffer;
- dest->free_in_buffer = BUFFER_SIZE;
-
- return boolean(true);
+ ScJpegDestinationMgr* dest = (ScJpegDestinationMgr*) cinfo->dest;
+
+ bool written = dest->filter->writeDataInternal((const char*) dest->buffer, BUFFER_SIZE);
+ if (!written)
+ (*cinfo->err->error_exit)((j_common_ptr) cinfo);
+
+ dest->next_output_byte = dest->buffer;
+ dest->free_in_buffer = BUFFER_SIZE;
+
+ return boolean(true);
}
void ScJpegDestinationMgr::jpegDestinationTerm(j_compress_ptr cinfo)
{
- ScJpegDestinationMgr* dest = (ScJpegDestinationMgr*) cinfo->dest;
- int n = BUFFER_SIZE - dest->free_in_buffer;
-
- bool written = dest->filter->writeDataInternal((const char*) dest->buffer, n);
- if (!written)
- (*cinfo->err->error_exit)((j_common_ptr)cinfo);
+ ScJpegDestinationMgr* dest = (ScJpegDestinationMgr*) cinfo->dest;
+ int n = BUFFER_SIZE - dest->free_in_buffer;
+
+ bool written = dest->filter->writeDataInternal((const char*) dest->buffer, n);
+ if (!written)
+ (*cinfo->err->error_exit)((j_common_ptr)cinfo);
}
ScJpegDestinationMgr::ScJpegDestinationMgr(ScJpegEncodeFilter *filter)
{
jpeg_destination_mgr::empty_output_buffer = jpegEmptyBuffer;
- jpeg_destination_mgr::init_destination = jpegDestinationInit;
- jpeg_destination_mgr::term_destination = jpegDestinationTerm;
- this->filter = filter;
- next_output_byte = buffer;
- free_in_buffer = BUFFER_SIZE;
+ jpeg_destination_mgr::init_destination = jpegDestinationInit;
+ jpeg_destination_mgr::term_destination = jpegDestinationTerm;
+ this->filter = filter;
+ next_output_byte = buffer;
+ free_in_buffer = BUFFER_SIZE;
}
struct ScJpegEncodeFilterData
{
struct jpeg_compress_struct cinfo;
- struct ScJpegDestinationMgr* cdest;
+ struct ScJpegDestinationMgr* cdest { nullptr };
JSAMPROW row_pointer[1];
ScJpegEncodeFilterData();
~ScJpegEncodeFilterData();
};
-ScJpegEncodeFilterData::ScJpegEncodeFilterData() : cdest(nullptr)
+ScJpegEncodeFilterData::ScJpegEncodeFilterData()
{
row_pointer[0] = nullptr;
}
@@ -119,24 +119,22 @@
ScJpegEncodeFilter::ScJpegEncodeFilter(QDataStream* stream, unsigned int imgWidth, unsigned int imgHeight,
ScJpegEncodeFilter::Color color) : ScStreamFilter(stream), m_width(imgWidth), m_height(imgHeight),
- m_quality(75), m_color(color)
-{
- m_filterData = nullptr;
- m_openedFilter = false;
+ m_color(color)
+{
+
}
ScJpegEncodeFilter::ScJpegEncodeFilter(ScStreamFilter* filter, unsigned int imgWidth, unsigned int imgHeight,
ScJpegEncodeFilter::Color color) : ScStreamFilter(filter), m_width(imgWidth), m_height(imgHeight),
- m_quality(75), m_color(color)
-{
- m_filterData = nullptr;
- m_openedFilter = false;
+ m_color(color)
+{
+
}
ScJpegEncodeFilter::~ScJpegEncodeFilter()
{
if (m_filterData && m_openedFilter)
- closeFilter();
+ ScJpegEncodeFilter::closeFilter();
freeData();
}
Modified: branches/Version15x/Scribus/scribus/scstreamfilter_jpeg.h
URL: http://scribus.net/websvn/diff.php?repname=Scribus&rev=25067&path=/branches/Version15x/Scribus/scribus/scstreamfilter_jpeg.h
==============================================================================
--- branches/Version15x/Scribus/scribus/scstreamfilter_jpeg.h (original)
+++ branches/Version15x/Scribus/scribus/scstreamfilter_jpeg.h Sun Mar 27 14:24:10 2022
@@ -18,34 +18,33 @@
friend struct ScJpegDestinationMgr;
public:
-
- typedef enum {
+ enum Color
+ {
RGB,
CMYK,
GRAY
- } Color;
+ };
ScJpegEncodeFilter(QDataStream* stream, unsigned int imgWidth, unsigned int imgHeight, ScJpegEncodeFilter::Color color);
ScJpegEncodeFilter(ScStreamFilter* filter, unsigned int imgWidth, unsigned int imgHeight, ScJpegEncodeFilter::Color color);
- ~ScJpegEncodeFilter();
+ ~ScJpegEncodeFilter() override;
- virtual bool openFilter ();
- virtual bool closeFilter();
+ bool openFilter () override;
+ bool closeFilter() override;
- virtual bool writeData(const char* data, int dataLen);
+ bool writeData(const char* data, int dataLen) override;
void setQuality(int quality) { m_quality = qMin(qMax(0, quality), 100); }
protected:
-
- ScJpegEncodeFilterData* m_filterData;
+ bool m_openedFilter { false };
+ ScJpegEncodeFilterData* m_filterData { nullptr };
void freeData();
- bool m_openedFilter;
- unsigned int m_width;
- unsigned int m_height;
- int m_quality;
+ unsigned int m_width { 0 };
+ unsigned int m_height { 0 };
+ int m_quality { 75 };
Color m_color;
};
Modified: branches/Version15x/Scribus/scribus/scstreamfilter_rc4.cpp
URL: http://scribus.net/websvn/diff.php?repname=Scribus&rev=25067&path=/branches/Version15x/Scribus/scribus/scstreamfilter_rc4.cpp
==============================================================================
--- branches/Version15x/Scribus/scribus/scstreamfilter_rc4.cpp (original)
+++ branches/Version15x/Scribus/scribus/scstreamfilter_rc4.cpp Sun Mar 27 14:24:10 2022
@@ -22,21 +22,19 @@
ScRC4EncodeFilter::ScRC4EncodeFilter(QDataStream* stream, const char* key, unsigned int keyLen)
: ScStreamFilter(stream), m_key(key, keyLen)
{
- m_filterData = nullptr;
- m_openedFilter = false;
+
}
ScRC4EncodeFilter::ScRC4EncodeFilter(ScStreamFilter* filter, const char* key, unsigned int keyLen)
: ScStreamFilter(filter), m_key(key, keyLen)
{
- m_filterData = nullptr;
- m_openedFilter = false;
+
}
ScRC4EncodeFilter::~ScRC4EncodeFilter()
{
if (m_filterData && m_openedFilter)
- closeFilter();
+ ScRC4EncodeFilter::closeFilter();
freeData();
}
@@ -77,28 +75,29 @@
bool ScRC4EncodeFilter::writeData(const char* data, int dataLen)
{
bool rc4Success = true;
- unsigned int count;
- const unsigned char *p = (const unsigned char *) data;
+ unsigned int count;
+ const unsigned char *p = (const unsigned char *) data;
if (!m_filterData)
return false;
- while (dataLen) {
- count = dataLen;
- if (count > BUFFER_SIZE - m_filterData->available_in)
- count = BUFFER_SIZE - m_filterData->available_in;
- memcpy (m_filterData->input_buffer + m_filterData->available_in, p, count);
- p += count;
- m_filterData->available_in += count;
- dataLen -= count;
+ while (dataLen)
+ {
+ count = dataLen;
+ if (count > BUFFER_SIZE - m_filterData->available_in)
+ count = BUFFER_SIZE - m_filterData->available_in;
+ memcpy (m_filterData->input_buffer + m_filterData->available_in, p, count);
+ p += count;
+ m_filterData->available_in += count;
+ dataLen -= count;
- if (m_filterData->available_in == BUFFER_SIZE)
+ if (m_filterData->available_in == BUFFER_SIZE)
{
rc4_encrypt(&m_filterData->rc4_context, m_filterData->input_buffer, m_filterData->output_buffer, m_filterData->available_in);
rc4Success &= writeDataInternal((const char*) m_filterData->output_buffer, m_filterData->available_in);
m_filterData->available_in = 0;
}
- }
+ }
return rc4Success;
}
Modified: branches/Version15x/Scribus/scribus/scstreamfilter_rc4.h
URL: http://scribus.net/websvn/diff.php?repname=Scribus&rev=25067&path=/branches/Version15x/Scribus/scribus/scstreamfilter_rc4.h
==============================================================================
--- branches/Version15x/Scribus/scribus/scstreamfilter_rc4.h (original)
+++ branches/Version15x/Scribus/scribus/scstreamfilter_rc4.h Sun Mar 27 14:24:10 2022
@@ -16,23 +16,22 @@
class ScRC4EncodeFilter : public ScStreamFilter
{
+public:
+ ScRC4EncodeFilter(QDataStream* stream, const char* key, unsigned int keyLen);
+ ScRC4EncodeFilter(ScStreamFilter* filter, const char* key, unsigned int keyLen);
+ ~ScRC4EncodeFilter() override;
+
+ bool openFilter () override;
+ bool closeFilter() override;
+
+ bool writeData(const char* data, int dataLen) override;
+
protected:
-
- ScRC4EncodeFilterData* m_filterData;
+ bool m_openedFilter { false };
+ ScRC4EncodeFilterData* m_filterData { nullptr };
QByteArray m_key;
void freeData(void);
- bool m_openedFilter;
-
-public:
- ScRC4EncodeFilter(QDataStream* stream, const char* key, unsigned int keyLen);
- ScRC4EncodeFilter(ScStreamFilter* filter, const char* key, unsigned int keyLen);
- ~ScRC4EncodeFilter();
-
- virtual bool openFilter ();
- virtual bool closeFilter();
-
- virtual bool writeData(const char* data, int dataLen);
};
#endif
More information about the scribus-commit
mailing list