summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJohannes Hofmann <Johannes.Hofmann@gmx.de>2008-07-05 21:52:55 +0200
committerJohannes Hofmann <Johannes.Hofmann@gmx.de>2008-07-05 21:52:55 +0200
commit29ecf5a14953471a061e5022563a6edd09d9dbef (patch)
tree7b03df7c40b4fd8f8050b770e9edea5d48b4eba2
parentdb527409f2c6f21195245484e936573a3c76f028 (diff)
OutputImage cleanup
-rw-r--r--src/JPEGOutputImage.H14
-rw-r--r--src/JPEGOutputImage.cxx37
-rw-r--r--src/OutputImage.H2
-rw-r--r--src/OutputImage.cxx2
-rw-r--r--src/PreviewOutputImage.H16
-rw-r--r--src/TIFFOutputImage.H14
-rw-r--r--src/TIFFOutputImage.cxx13
7 files changed, 40 insertions, 58 deletions
diff --git a/src/JPEGOutputImage.H b/src/JPEGOutputImage.H
index 06499ca..6e713de 100644
--- a/src/JPEGOutputImage.H
+++ b/src/JPEGOutputImage.H
@@ -24,19 +24,15 @@ class JPEGOutputImage : public OutputImage {
FILE *fp;
int quality;
- public:
- JPEGOutputImage(const char *file, int quality = 90);
-
- ~JPEGOutputImage();
-
protected:
- int init_internal(int w, int h);
-
+ int init_internal();
int set_pixel_internal(int x, int r, int g, int b);
-
int next_line_internal();
-
int done_internal();
+
+ public:
+ JPEGOutputImage(const char *file, int quality = 90);
+ ~JPEGOutputImage();
};
#endif
diff --git a/src/JPEGOutputImage.cxx b/src/JPEGOutputImage.cxx
index 0f3cf18..263eeb3 100644
--- a/src/JPEGOutputImage.cxx
+++ b/src/JPEGOutputImage.cxx
@@ -21,31 +21,26 @@ JPEGOutputImage::JPEGOutputImage(const char *f, int q) {
}
JPEGOutputImage::~JPEGOutputImage() {
- if (row) {
+ if (row)
free(row);
- }
- if (file) {
+ if (file)
free(file);
- }
}
int
-JPEGOutputImage::init_internal(int w1, int h1) {
- if (row) {
+JPEGOutputImage::init_internal() {
+ if (row)
free(row);
- row = NULL;
- }
+ row = NULL;
- row = (unsigned char*) malloc(sizeof(char) * 3 * W);
+ row = (unsigned char*) calloc(3 * W, sizeof(char));
if (!row) {
- perror("malloc");
+ perror("calloc");
return 1;
}
- memset(row, 0, sizeof(char) * 3 * W);
- if (fp) {
+ if (fp)
fclose(fp);
- }
if ((fp = fopen(file, "wb")) == NULL) {
fprintf(stderr, "can't open %s\n", file);
@@ -92,18 +87,18 @@ JPEGOutputImage::done_internal() {
jpeg_finish_compress(&cinfo);
jpeg_destroy_compress(&cinfo);
- if (fp) {
+ if (fp)
fclose(fp);
- fp = NULL;
- }
- if (row) {
+ fp = NULL;
+
+ if (row)
free(row);
- }
+ row = NULL;
- if (fp) {
+ if (fp)
fclose(fp);
- fp = NULL;
- }
+ fp = NULL;
+
return 0;
}
diff --git a/src/OutputImage.H b/src/OutputImage.H
index 443f6f6..0718074 100644
--- a/src/OutputImage.H
+++ b/src/OutputImage.H
@@ -14,7 +14,7 @@ class OutputImage {
protected:
int W, H, line;
- virtual int init_internal(int w1, int h1) {return 0;};
+ virtual int init_internal() {return 0;};
virtual int set_pixel_internal(int x, int r, int g, int b) {return 0;};
virtual int next_line_internal() {return 0;};
virtual int done_internal() {return 0;};
diff --git a/src/OutputImage.cxx b/src/OutputImage.cxx
index d1c2f43..04ee471 100644
--- a/src/OutputImage.cxx
+++ b/src/OutputImage.cxx
@@ -22,7 +22,7 @@ OutputImage::init(int w1, int h1) {
line = 0;
initialized = 1;
- return init_internal(w1, h1);
+ return init_internal();
}
int
diff --git a/src/PreviewOutputImage.H b/src/PreviewOutputImage.H
index 53b58db..b4bca3b 100644
--- a/src/PreviewOutputImage.H
+++ b/src/PreviewOutputImage.H
@@ -19,21 +19,17 @@ class PreviewOutputImage : public OutputImage , public Fl_Widget {
uchar *data;
int d;
- public:
- PreviewOutputImage(int X, int Y, int W, int H);
-
- ~PreviewOutputImage();
-
- void draw();
-
protected:
int init_internal(int w, int h);
-
int set_pixel_internal(int x, int r, int g, int b);
-
int next_line_internal();
-
int done_internal();
+
+ public:
+ PreviewOutputImage(int X, int Y, int W, int H);
+ ~PreviewOutputImage();
+
+ void draw();
};
#endif
diff --git a/src/TIFFOutputImage.H b/src/TIFFOutputImage.H
index 9b0f83b..b5409eb 100644
--- a/src/TIFFOutputImage.H
+++ b/src/TIFFOutputImage.H
@@ -19,19 +19,15 @@ class TIFFOutputImage : public OutputImage {
char *file;
TIFF *tiff;
- public:
- TIFFOutputImage(const char *file, int b = 8);
-
- ~TIFFOutputImage();
-
protected:
- int init_internal(int w, int h);
-
+ int init_internal();
int set_pixel_internal(int x, int r, int g, int b);
-
int next_line_internal();
-
int done_internal();
+
+ public:
+ TIFFOutputImage(const char *file, int b = 8);
+ ~TIFFOutputImage();
};
#endif
diff --git a/src/TIFFOutputImage.cxx b/src/TIFFOutputImage.cxx
index b8effed..999e05a 100644
--- a/src/TIFFOutputImage.cxx
+++ b/src/TIFFOutputImage.cxx
@@ -27,18 +27,17 @@ TIFFOutputImage::~TIFFOutputImage() {
}
int
-TIFFOutputImage::init_internal(int w1, int h1) {
+TIFFOutputImage::init_internal() {
if (row) {
free(row);
row = NULL;
}
- row = (unsigned char*) malloc(sizeof(char) * (bitspersample / 8) * 4 * w1);
+ row = (unsigned char*) calloc((bitspersample / 8) * 4 * W, sizeof(char));
if (!row) {
- perror("malloc");
+ perror("calloc");
return 1;
}
- memset(row, 0, sizeof(char) * (bitspersample / 8) * 4 * w1);
if (tiff) {
TIFFClose(tiff);
@@ -49,8 +48,8 @@ TIFFOutputImage::init_internal(int w1, int h1) {
return 1;
}
- TIFFSetField(tiff, TIFFTAG_IMAGEWIDTH, w1);
- TIFFSetField(tiff, TIFFTAG_IMAGELENGTH, h1);
+ TIFFSetField(tiff, TIFFTAG_IMAGEWIDTH, W);
+ TIFFSetField(tiff, TIFFTAG_IMAGELENGTH, H);
TIFFSetField(tiff, TIFFTAG_COMPRESSION, COMPRESSION_DEFLATE);
TIFFSetField(tiff, TIFFTAG_PLANARCONFIG, PLANARCONFIG_CONTIG);
TIFFSetField(tiff, TIFFTAG_PHOTOMETRIC, PHOTOMETRIC_RGB);
@@ -83,7 +82,7 @@ int
TIFFOutputImage::next_line_internal() {
TIFFWriteEncodedStrip(tiff, line - 1 , row, W * (bitspersample / 8) * 4);
- memset(row, 0, sizeof(char) * 4 * W);
+ memset(row, 0, (bitspersample / 8) * 4 * W * sizeof(char));
return 0;
}