diff --git a/goo/JpegWriter.cc b/goo/JpegWriter.cc
index 64df68a..be84704 100644
--- a/goo/JpegWriter.cc
+++ b/goo/JpegWriter.cc
@@ -26,7 +26,14 @@ void outputMessage(j_common_ptr cinfo)
 	error(-1, "%s", buffer);
 }
 
+JpegWriter::JpegWriter(int quality, bool progressive)
+{
+	this->quality = quality;
+	this->progressive = progressive;
+}
+
 JpegWriter::JpegWriter()
+: progressive(false), quality(-1)
 {
 }
 
@@ -59,10 +66,14 @@ bool JpegWriter::init(FILE *f, int width, int height, int hDPI, int vDPI)
 	jpeg_set_defaults(&cinfo);
 	
 	// Set quality
-	//jpeg_set_quality(&cinfo, 80, true);
+	if( quality < 0 || quality > 100 ) { 
+		jpeg_set_quality(&cinfo, quality, true);
+	}
 	
 	// Use progressive mode
-	//jpeg_simple_progression(&cinfo);
+	if( progressive) {
+		jpeg_simple_progression(&cinfo);
+	}
 	
 	// Get ready for data
 	jpeg_start_compress(&cinfo, TRUE);
diff --git a/goo/JpegWriter.h b/goo/JpegWriter.h
index 36049b5..7870ca1 100644
--- a/goo/JpegWriter.h
+++ b/goo/JpegWriter.h
@@ -27,6 +27,7 @@ extern "C" {
 class JpegWriter : public ImgWriter
 {
 	public:
+		JpegWriter(int quality, bool progressive);
 		JpegWriter();
 		~JpegWriter();
 		
@@ -38,6 +39,8 @@ class JpegWriter : public ImgWriter
 		bool close();
 	
 	private:
+		bool progressive;
+		int quality;
 		struct jpeg_compress_struct cinfo;
 		struct jpeg_error_mgr jerr;
 };
diff --git a/splash/SplashBitmap.cc b/splash/SplashBitmap.cc
index 6832293..ccde61a 100644
--- a/splash/SplashBitmap.cc
+++ b/splash/SplashBitmap.cc
@@ -286,6 +286,7 @@ SplashError SplashBitmap::writeImgFile(SplashImageFileFormat format, char *fileN
 
 SplashError SplashBitmap::writeImgFile(SplashImageFileFormat format, FILE *f, int hDPI, int vDPI) {
   ImgWriter *writer;
+	SplashError e;
   
   switch (format) {
     #ifdef ENABLE_LIBPNG
@@ -306,14 +307,19 @@ SplashError SplashBitmap::writeImgFile(SplashImageFileFormat format, FILE *f, in
       error(-1, "Support for this image type not compiled in");
       return splashErrGeneric;
   }
-  
+
+	e = writeImgFile(writer, f, hDPI, vDPI);
+	delete writer;
+	return e;
+}
+
+SplashError SplashBitmap::writeImgFile(ImgWriter *writer, FILE *f, int hDPI, int vDPI) {
   if (mode != splashModeRGB8 && mode != splashModeMono8 && mode != splashModeMono1 && mode != splashModeXBGR8) {
     error(-1, "unsupported SplashBitmap mode");
     return splashErrGeneric;
   }
 
   if (!writer->init(f, width, height, hDPI, vDPI)) {
-    delete writer;
     return splashErrGeneric;
   }
 
@@ -330,7 +336,6 @@ SplashError SplashBitmap::writeImgFile(SplashImageFileFormat format, FILE *f, in
       }
       if (!writer->writePointers(row_pointers, height)) {
         delete[] row_pointers;
-        delete writer;
         return splashErrGeneric;
       }
       delete[] row_pointers;
@@ -350,7 +355,6 @@ SplashError SplashBitmap::writeImgFile(SplashImageFileFormat format, FILE *f, in
 
         if (!writer->writeRow(&row)) {
           delete[] row;
-          delete writer;
           return splashErrGeneric;
         }
       }
@@ -371,7 +375,6 @@ SplashError SplashBitmap::writeImgFile(SplashImageFileFormat format, FILE *f, in
 
         if (!writer->writeRow(&row)) {
           delete[] row;
-          delete writer;
           return splashErrGeneric;
         }
       }
@@ -392,7 +395,6 @@ SplashError SplashBitmap::writeImgFile(SplashImageFileFormat format, FILE *f, in
 
         if (!writer->writeRow(&row)) {
           delete[] row;
-          delete writer;
           return splashErrGeneric;
         }
       }
@@ -406,11 +408,8 @@ SplashError SplashBitmap::writeImgFile(SplashImageFileFormat format, FILE *f, in
   }
   
   if (writer->close()) {
-    delete writer;
     return splashErrGeneric;
   }
 
-  delete writer;
-
   return splashOk;
 }
diff --git a/splash/SplashBitmap.h b/splash/SplashBitmap.h
index c25e325..78942c6 100644
--- a/splash/SplashBitmap.h
+++ b/splash/SplashBitmap.h
@@ -30,6 +30,7 @@
 #endif
 
 #include "SplashTypes.h"
+#include "goo/ImgWriter.h"
 #include <stdio.h>
 
 //------------------------------------------------------------------------
@@ -62,6 +63,7 @@ public:
   
   SplashError writeImgFile(SplashImageFileFormat format, char *fileName, int hDPI, int vDPI);
   SplashError writeImgFile(SplashImageFileFormat format, FILE *f, int hDPI, int vDPI);
+	SplashError writeImgFile(ImgWriter *writer, FILE *f, int hDPI, int vDPI);
 
   void getPixel(int x, int y, SplashColorPtr pixel);
   Guchar getAlpha(int x, int y);
