summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorFridrich Štrba <fridrich.strba@bluewin.ch>2011-01-14 12:30:55 +0100
committerFridrich Štrba <fridrich.strba@bluewin.ch>2011-01-14 12:30:55 +0100
commit3c7c50b77bfe4256bbe381937f944ce3b1815b19 (patch)
tree5603041f720b4bdcc037c480c7ec55a72c8b2d13
parenta528cce721e6c9eddafefe82164ca189daa108b5 (diff)
Determining the size of some variable-length functions in Pict1
-rw-r--r--src/lib/Pict1Parser.cpp142
-rw-r--r--src/lib/Pict1Parser.h11
-rw-r--r--src/lib/PictXParser.cpp4
3 files changed, 112 insertions, 45 deletions
diff --git a/src/lib/Pict1Parser.cpp b/src/lib/Pict1Parser.cpp
index 360ca07..7f7665a 100644
--- a/src/lib/Pict1Parser.cpp
+++ b/src/lib/Pict1Parser.cpp
@@ -1,7 +1,5 @@
/* libpict
- * Copyright (C) 2006 Ariya Hidayat (ariya@kde.org)
- * Copyright (C) 2005 Fridrich Strba (fridrich.strba@bluewin.ch)
- * Copyright (C) 2004 Marc Oude Kotte (marc@solcon.nl)
+ * Copyright (C) 2011 Fridrich Strba (fridrich.strba@bluewin.ch)
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Library General Public
@@ -18,11 +16,6 @@
* Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
* Boston, MA 02111-1301 USA
*
- * For further information visit http://libpict.sourceforge.net
- */
-
-/* "This product is not manufactured, approved, or supported by
- * Corel Corporation or Corel Corporation Limited."
*/
#include "Pict1Parser.h"
@@ -31,7 +24,8 @@
#include <libwpg/libwpg.h>
Pict1Parser::Pict1Parser(WPXInputStream *input, libwpg::WPGPaintInterface* painter):
- PictXParser(input, painter)
+ PictXParser(input, painter),
+ m_recordSize(0)
{
}
@@ -164,32 +158,42 @@ bool Pict1Parser::parse()
while(!m_input->atEOS())
{
-#ifdef DEBUG
- long recordPos = m_input->tell();
-#endif
+ long initialPosition = m_input->tell();
int recordType = readU8();
if (recordType == 0xff)
break;
// search function to handler this record
int index = -1;
- for(int i = 0; (index < 0) && handlers[i].name; i++)
+ for(int i=0; i < (int)(sizeof(handlers)/sizeof(RecordHandler)); i++)
+ {
if(handlers[i].type == recordType)
+ {
index = i;
+ break;
+ }
+ }
- if(index < 0)
- ;
- else
+ if(index >= 0)
{
+ PICT_DEBUG_MSG(("Position: 0x%.8x, Opcode: 0x%.2x, Opcode Name: %s\n", (int)initialPosition, recordType, handlers[index].name));
+ m_recordSize = handlers[index].size;
Method recordHandler = handlers[index].handler;
- if(!recordHandler)
- ;
- else
+ if(recordHandler)
{
// invoke the handler for this record
(this->*recordHandler)();
}
+ if (m_recordSize <= 0) // we were not able to compute variable record size
+ return false;
+ else
+ {
+ m_input->seek(initialPosition + m_recordSize, WPX_SEEK_SET);
+ m_recordSize = 0;
+ }
}
+ else
+ return false;
}
return true;
}
@@ -200,6 +204,8 @@ void Pict1Parser::handleNOP()
void Pict1Parser::handleClipRgn()
{
+ m_recordSize = (int)readU16() + 1;
+ PICT_DEBUG_MSG(("Size of the data: %i\n", m_recordSize));
}
void Pict1Parser::handleBkPat()
@@ -266,7 +272,6 @@ void Pict1Parser::handlePicVersion()
{
}
-
void Pict1Parser::handleLine()
{
}
@@ -283,21 +288,32 @@ void Pict1Parser::handleShortLineFrom()
{
}
-
void Pict1Parser::handleLongText()
{
+ m_input->seek(6, WPX_SEEK_CUR);
+ m_recordSize = (int)readU16() + 6;
+ PICT_DEBUG_MSG(("Size of the data: %i\n", m_recordSize));
}
void Pict1Parser::handleDHText()
{
+ m_input->seek(2, WPX_SEEK_CUR);
+ m_recordSize = (int)readU16() + 3;
+ PICT_DEBUG_MSG(("Size of the data: %i\n", m_recordSize));
}
void Pict1Parser::handleDVText()
{
+ m_input->seek(2, WPX_SEEK_CUR);
+ m_recordSize = (int)readU16() + 3;
+ PICT_DEBUG_MSG(("Size of the data: %i\n", m_recordSize));
}
void Pict1Parser::handleDHDVText()
{
+ m_input->seek(3, WPX_SEEK_CUR);
+ m_recordSize = (int)readU16() + 4;
+ PICT_DEBUG_MSG(("Size of the data: %i\n", m_recordSize));
}
@@ -321,7 +337,6 @@ void Pict1Parser::handleFillRect()
{
}
-
void Pict1Parser::handleFrameSameRect()
{
}
@@ -342,7 +357,6 @@ void Pict1Parser::handleFillSameRect()
{
}
-
void Pict1Parser::handleFrameRRect()
{
}
@@ -363,7 +377,6 @@ void Pict1Parser::handleFillRRect()
{
}
-
void Pict1Parser::handleFrameSameRRect()
{
}
@@ -384,7 +397,6 @@ void Pict1Parser::handleFillSameRRect()
{
}
-
void Pict1Parser::handleFrameOval()
{
}
@@ -405,7 +417,6 @@ void Pict1Parser::handleFillOval()
{
}
-
void Pict1Parser::handleFrameSameOval()
{
}
@@ -426,7 +437,6 @@ void Pict1Parser::handleFillSameOval()
{
}
-
void Pict1Parser::handleFrameArc()
{
}
@@ -447,7 +457,6 @@ void Pict1Parser::handleFillArc()
{
}
-
void Pict1Parser::handleFrameSameArc()
{
}
@@ -468,28 +477,36 @@ void Pict1Parser::handleFillSameArc()
{
}
-
void Pict1Parser::handleFramePoly()
{
+ m_recordSize = (int)readU16() + 1;
+ PICT_DEBUG_MSG(("Size of the data: %i\n", m_recordSize));
}
void Pict1Parser::handlePaintPoly()
{
+ m_recordSize = (int)readU16() + 1;
+ PICT_DEBUG_MSG(("Size of the data: %i\n", m_recordSize));
}
void Pict1Parser::handleErasePoly()
{
+ m_recordSize = (int)readU16() + 1;
+ PICT_DEBUG_MSG(("Size of the data: %i\n", m_recordSize));
}
void Pict1Parser::handleInvertPoly()
{
+ m_recordSize = (int)readU16() + 1;
+ PICT_DEBUG_MSG(("Size of the data: %i\n", m_recordSize));
}
void Pict1Parser::handleFillPoly()
{
+ m_recordSize = (int)readU16() + 1;
+ PICT_DEBUG_MSG(("Size of the data: %i\n", m_recordSize));
}
-
void Pict1Parser::handleFrameSamePoly()
{
}
@@ -510,25 +527,34 @@ void Pict1Parser::handleFillSamePoly()
{
}
-
void Pict1Parser::handleFrameRgn()
{
+ m_recordSize = (int)readU16() + 1;
+ PICT_DEBUG_MSG(("Size of the data: %i\n", m_recordSize));
}
void Pict1Parser::handlePaintRgn()
{
+ m_recordSize = (int)readU16() + 1;
+ PICT_DEBUG_MSG(("Size of the data: %i\n", m_recordSize));
}
void Pict1Parser::handleEraseRgn()
{
+ m_recordSize = (int)readU16() + 1;
+ PICT_DEBUG_MSG(("Size of the data: %i\n", m_recordSize));
}
void Pict1Parser::handleInvertRgn()
{
+ m_recordSize = (int)readU16() + 1;
+ PICT_DEBUG_MSG(("Size of the data: %i\n", m_recordSize));
}
void Pict1Parser::handleFillRgn()
{
+ m_recordSize = (int)readU16() + 1;
+ PICT_DEBUG_MSG(("Size of the data: %i\n", m_recordSize));
}
@@ -552,25 +578,72 @@ void Pict1Parser::handleFillSameRgn()
{
}
-
void Pict1Parser::handleBitsRect()
{
+ unsigned short rowBytes = readU16();
+ PICT_DEBUG_MSG(("Row bytes: %i\n", rowBytes));
+ unsigned short bounds_top = readU16();
+ PICT_DEBUG_MSG(("Bounds.top: %i\n", bounds_top));
+ readU16();
+ unsigned short bounds_bottom = readU16();
+ PICT_DEBUG_MSG(("Bounds.bottom: %i\n", bounds_bottom));
+ readU16();
+ m_input->seek(18, WPX_SEEK_CUR);
+ m_recordSize = 29 + (0x7fff & rowBytes)*((bounds_bottom > bounds_top) ? bounds_bottom - bounds_top : bounds_top - bounds_bottom);
+ PICT_DEBUG_MSG(("Size of the data: %i\n", m_recordSize));
}
void Pict1Parser::handleBitsRgn()
{
+ unsigned short rowBytes = readU16();
+ PICT_DEBUG_MSG(("Row bytes: %i\n", rowBytes));
+ unsigned short bounds_top = readU16();
+ PICT_DEBUG_MSG(("Bounds.top: %i\n", bounds_top));
+ readU16();
+ unsigned short bounds_bottom = readU16();
+ PICT_DEBUG_MSG(("Bounds.bottom: %i\n", bounds_bottom));
+ readU16();
+ m_input->seek(18, WPX_SEEK_CUR);
+ m_recordSize = 29 + (0x7fff & rowBytes)*((bounds_bottom > bounds_top) ? (int)(bounds_bottom - bounds_top) : (int)(bounds_top - bounds_bottom));
+ m_recordSize += readU16();
+ PICT_DEBUG_MSG(("Size of the data: %i\n", m_recordSize));
}
-
void Pict1Parser::handlePackBitsRect()
{
+ unsigned short rowBytes = readU16();
+ PICT_DEBUG_MSG(("Row bytes: %i\n", rowBytes));
+ unsigned short bounds_top = readU16();
+ PICT_DEBUG_MSG(("Bounds.top: %i\n", bounds_top));
+ readU16();
+ unsigned short bounds_bottom = readU16();
+ PICT_DEBUG_MSG(("Bounds.bottom: %i\n", bounds_bottom));
+ readU16();
+ m_input->seek(18, WPX_SEEK_CUR);
+#if 0
+ m_recordSize = 29 + (0x7fff & rowBytes)*((bounds_bottom > bounds_top) ? bounds_bottom - bounds_top : bounds_top - bounds_bottom);
+#endif
+ PICT_DEBUG_MSG(("Size of the data: %i\n", m_recordSize));
}
void Pict1Parser::handlePackBitsRgn()
{
+ unsigned short rowBytes = readU16();
+ PICT_DEBUG_MSG(("Row bytes: %i\n", rowBytes));
+ unsigned short bounds_top = readU16();
+ PICT_DEBUG_MSG(("Bounds.top: %i\n", bounds_top));
+ readU16();
+ unsigned short bounds_bottom = readU16();
+ PICT_DEBUG_MSG(("Bounds.bottom: %i\n", bounds_bottom));
+ readU16();
+ m_input->seek(18, WPX_SEEK_CUR);
+#if 0
+ m_recordSize = 29 + (0x7fff & rowBytes)*((bounds_bottom > bounds_top) ? bounds_bottom - bounds_top : bounds_top - bounds_bottom);
+ m_recordSize += readU16();
+#endif
+ PICT_DEBUG_MSG(("Size of the data: %i\n", m_recordSize));
}
-
void Pict1Parser::handleShortComment()
{
}
@@ -579,7 +652,6 @@ void Pict1Parser::handleLongComment()
{
}
-
void Pict1Parser::handleEndOfPicture()
{
}
diff --git a/src/lib/Pict1Parser.h b/src/lib/Pict1Parser.h
index 5475cd9..a2ab682 100644
--- a/src/lib/Pict1Parser.h
+++ b/src/lib/Pict1Parser.h
@@ -1,7 +1,5 @@
/* libpict
- * Copyright (C) 2006 Ariya Hidayat (ariya@kde.org)
- * Copyright (C) 2005 Fridrich Strba (fridrich.strba@bluewin.ch)
- * Copyright (C) 2004 Marc Oude Kotte (marc@solcon.nl)
+ * Copyright (C) 2011 Fridrich Strba (fridrich.strba@bluewin.ch)
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Library General Public
@@ -18,11 +16,6 @@
* Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
* Boston, MA 02111-1301 USA
*
- * For further information visit http://libpict.sourceforge.net
- */
-
-/* "This product is not manufactured, approved, or supported by
- * Corel Corporation or Corel Corporation Limited."
*/
#ifndef __PICT1PARSER_H__
@@ -152,6 +145,8 @@ private:
void handleLongComment();
void handleEndOfPicture();
+
+ int m_recordSize;
};
#endif // __PICT1PARSER_H__
diff --git a/src/lib/PictXParser.cpp b/src/lib/PictXParser.cpp
index 1f137d1..e9b208d 100644
--- a/src/lib/PictXParser.cpp
+++ b/src/lib/PictXParser.cpp
@@ -55,7 +55,7 @@ unsigned short PictXParser::readU16()
{
unsigned short p0 = (unsigned short)readU8();
unsigned short p1 = (unsigned short)readU8();
- return (unsigned short)(p0|(p1<<8));
+ return (unsigned short)(p1|(p0<<8));
}
unsigned int PictXParser::readU32()
@@ -64,7 +64,7 @@ unsigned int PictXParser::readU32()
unsigned int p1 = (unsigned int)readU8();
unsigned int p2 = (unsigned int)readU8();
unsigned int p3 = (unsigned int)readU8();
- return (unsigned long)(p0|(p1<<8)|(p2<<16)|(p3<<24));
+ return (unsigned long)(p3|(p2<<8)|(p1<<16)|(p0<<24));
}
short PictXParser::readS16()