summaryrefslogtreecommitdiff
path: root/src/im_format_krn.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_krn.cpp
parent62783aee16f96fe5e513fb230b8efddaa02981df (diff)
New: ASCII compression for RAW format to access text data instead of binary.
Diffstat (limited to 'src/im_format_krn.cpp')
-rw-r--r--src/im_format_krn.cpp77
1 files changed, 8 insertions, 69 deletions
diff --git a/src/im_format_krn.cpp b/src/im_format_krn.cpp
index 21261a8..a47d650 100644
--- a/src/im_format_krn.cpp
+++ b/src/im_format_krn.cpp
@@ -2,7 +2,7 @@
* \brief KRN - IM Kernel File Format
*
* See Copyright Notice in im_lib.h
- * $Id: im_format_krn.cpp,v 1.2 2008/12/03 15:45:34 scuri Exp $
+ * $Id: im_format_krn.cpp,v 1.3 2009/10/01 14:15:47 scuri Exp $
*/
#include "im_format.h"
@@ -17,66 +17,6 @@
#include <memory.h>
#include <math.h>
-static int iKRNReadNextInteger(imBinFile* handle, int *value)
-{
- int c = 0, found = 0;
- static char buffer[10];
-
- while (!found)
- {
- imBinFileRead(handle, &buffer[c], 1, 1);
-
- /* if it's a number increments the number of characters readed */
- if ((buffer[c] >= (int)'0' && buffer[c] <= (int)'9') || buffer[c] == (int)'-')
- c++;
- else
- {
- /* if it's not a number and we readed some characters convert them to an integer */
- if (c > 0)
- {
- buffer[c] = 0;
- *value = atoi(buffer);
- found = 1;
- }
- }
-
- if (imBinFileError(handle) || c > 10)
- return 0;
- }
-
- return 1;
-}
-
-static int iKRNReadNextReal(imBinFile* handle, float *value)
-{
- int c = 0, found = 0;
- static char buffer[16];
-
- while (!found)
- {
- imBinFileRead(handle, &buffer[c], 1, 1);
-
- /* if it's a number increments the number of characters readed */
- if ((buffer[c] >= (int)'0' && buffer[c] <= (int)'9') || buffer[c] == (int)'-' || buffer[c] == (int)'.')
- c++;
- else
- {
- /* if it's not a number and we readed some characters convert them to an integer */
- if (c > 0)
- {
- buffer[c] = 0;
- *value = (float)atof(buffer);
- found = 1;
- }
- }
-
- if (imBinFileError(handle) || c > 16)
- return 0;
- }
-
- return 1;
-}
-
static int iKRNReadDescription(imBinFile* handle, char* comment, int *size)
{
imbyte byte_value = 0;
@@ -239,14 +179,14 @@ int imFileFormatKRN::ReadImageInfo(int index)
if (desc_size)
attrib_table->Set("Description", IM_BYTE, desc_size, desc);
- if (!iKRNReadNextInteger(handle, &this->width))
+ if (!imBinFileReadInteger(handle, &this->width))
return IM_ERR_ACCESS;
- if (!iKRNReadNextInteger(handle, &this->height))
+ if (!imBinFileReadInteger(handle, &this->height))
return IM_ERR_ACCESS;
int type;
- if (!iKRNReadNextInteger(handle, &type))
+ if (!imBinFileReadInteger(handle, &type))
return IM_ERR_ACCESS;
if (type == 0)
@@ -303,7 +243,7 @@ int imFileFormatKRN::ReadImageData(void* data)
if (this->file_data_type == IM_INT)
{
int value;
- if (!iKRNReadNextInteger(handle, &value))
+ if (!imBinFileReadInteger(handle, &value))
return IM_ERR_ACCESS;
((int*)this->line_buffer)[col] = value;
@@ -311,7 +251,7 @@ int imFileFormatKRN::ReadImageData(void* data)
else
{
float value;
- if (!iKRNReadNextReal(handle, &value))
+ if (!imBinFileReadFloat(handle, &value))
return IM_ERR_ACCESS;
((float*)this->line_buffer)[col] = value;
@@ -351,11 +291,10 @@ int imFileFormatKRN::WriteImageData(void* data)
if (!imBinFilePrintf(handle, "%f ", (double)value))
return IM_ERR_ACCESS;
}
-
- if (col == this->width-1)
- imBinFileWrite(handle, (void*)"\n", 1, 1);
}
+ imBinFileWrite(handle, (void*)"\n", 1, 1);
+
if (imBinFileError(handle))
return IM_ERR_ACCESS;