summaryrefslogtreecommitdiff
path: root/src/im_format_raw.cpp
diff options
context:
space:
mode:
authorscuri <scuri>2009-10-01 14:14:53 +0000
committerscuri <scuri>2009-10-01 14:14:53 +0000
commit537ce7ddb32932a2100ae767b1eca51a9dd1c35f (patch)
tree0b487bef90b949fd8b97f180629a1b0bacefc78c /src/im_format_raw.cpp
parent62783aee16f96fe5e513fb230b8efddaa02981df (diff)
New: ASCII compression for RAW format to access text data instead of binary.
Diffstat (limited to 'src/im_format_raw.cpp')
-rw-r--r--src/im_format_raw.cpp94
1 files changed, 84 insertions, 10 deletions
diff --git a/src/im_format_raw.cpp b/src/im_format_raw.cpp
index 6a6a7fd..56a2096 100644
--- a/src/im_format_raw.cpp
+++ b/src/im_format_raw.cpp
@@ -2,7 +2,7 @@
* \brief RAW File Format
*
* See Copyright Notice in im_lib.h
- * $Id: im_format_raw.cpp,v 1.4 2009/09/10 17:33:35 scuri Exp $
+ * $Id: im_format_raw.cpp,v 1.5 2009/10/01 14:15:47 scuri Exp $
*/
#include "im_format.h"
@@ -15,9 +15,10 @@
#include <stdlib.h>
#include <string.h>
-static const char* iRAWCompTable[1] =
+static const char* iRAWCompTable[2] =
{
- "NONE"
+ "NONE",
+ "ASCII"
};
class imFileFormatRAW: public imFileFormatBase
@@ -49,7 +50,7 @@ public:
"RAW File Format",
"*.*;",
iRAWCompTable,
- 1,
+ 2,
1)
{}
~imFormatRAW() {}
@@ -213,15 +214,51 @@ int imFileFormatRAW::ReadImageData(void* data)
line_count *= 2;
}
+ int ascii;
+ if (imStrEqual(this->compression, "ASCII"))
+ ascii = 1;
+ else
+ ascii = 0;
+
imCounterTotal(this->counter, count, "Reading RAW...");
int row = 0, plane = 0;
for (int i = 0; i < count; i++)
{
- imBinFileRead(this->handle, (imbyte*)this->line_buffer, line_count, type_size);
-
- if (imBinFileError(this->handle))
- return IM_ERR_ACCESS;
+ if (ascii)
+ {
+ for (int col = 0; col < line_count; col++)
+ {
+ if (this->file_data_type == IM_FLOAT)
+ {
+ float value;
+ if (!imBinFileReadFloat(handle, &value))
+ return IM_ERR_ACCESS;
+
+ ((float*)this->line_buffer)[col] = value;
+ }
+ else
+ {
+ int value;
+ if (!imBinFileReadInteger(handle, &value))
+ return IM_ERR_ACCESS;
+
+ if (this->file_data_type == IM_INT)
+ ((int*)this->line_buffer)[col] = value;
+ else if (this->file_data_type == IM_USHORT)
+ ((imushort*)this->line_buffer)[col] = (imushort)value;
+ else
+ ((imbyte*)this->line_buffer)[col] = (unsigned char)value;
+ }
+ }
+ }
+ else
+ {
+ imBinFileRead(this->handle, (imbyte*)this->line_buffer, line_count, type_size);
+
+ if (imBinFileError(this->handle))
+ return IM_ERR_ACCESS;
+ }
imFileLineBufferRead(this, data, row, plane);
@@ -250,6 +287,12 @@ int imFileFormatRAW::WriteImageData(void* data)
line_count *= 2;
}
+ int ascii;
+ if (imStrEqual(this->compression, "ASCII"))
+ ascii = 1;
+ else
+ ascii = 0;
+
imCounterTotal(this->counter, count, "Writing RAW...");
int row = 0, plane = 0;
@@ -257,7 +300,38 @@ int imFileFormatRAW::WriteImageData(void* data)
{
imFileLineBufferWrite(this, data, row, plane);
- imBinFileWrite(this->handle, (imbyte*)this->line_buffer, line_count, type_size);
+ if (ascii)
+ {
+ for (int col = 0; col < line_count; col++)
+ {
+ if (this->file_data_type == IM_FLOAT)
+ {
+ float value = ((float*)this->line_buffer)[col];
+
+ if (!imBinFilePrintf(handle, "%f ", (double)value))
+ return IM_ERR_ACCESS;
+ }
+ else
+ {
+ int value;
+ if (this->file_data_type == IM_INT)
+ value = ((int*)this->line_buffer)[col];
+ else if (this->file_data_type == IM_USHORT)
+ value = ((imushort*)this->line_buffer)[col];
+ else
+ value = ((imbyte*)this->line_buffer)[col];
+
+ if (!imBinFilePrintf(handle, "%d ", value))
+ return IM_ERR_ACCESS;
+ }
+ }
+
+ imBinFileWrite(handle, (void*)"\n", 1, 1);
+ }
+ else
+ {
+ imBinFileWrite(this->handle, (imbyte*)this->line_buffer, line_count, type_size);
+ }
if (imBinFileError(this->handle))
return IM_ERR_ACCESS;
@@ -285,7 +359,7 @@ int imFormatRAW::CanWrite(const char* compression, int color_mode, int data_type
if (!compression || compression[0] == 0)
return IM_ERR_NONE;
- if (!imStrEqual(compression, "NONE"))
+ if (!imStrEqual(compression, "NONE") && !imStrEqual(compression, "ASCII"))
return IM_ERR_COMPRESS;
return IM_ERR_NONE;