[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Gnash-commit] gnash ChangeLog libbase/jpeg.cpp libbase/jpeg.h
From: |
Sandro Santilli |
Subject: |
[Gnash-commit] gnash ChangeLog libbase/jpeg.cpp libbase/jpeg.h |
Date: |
Tue, 28 Aug 2007 10:20:57 +0000 |
CVSROOT: /sources/gnash
Module name: gnash
Changes by: Sandro Santilli <strk> 07/08/28 10:20:57
Modified files:
. : ChangeLog
libbase : jpeg.cpp jpeg.h
Log message:
* libbase/jpeg.{cpp,h}: cleanups, aimed at eventually implement
different inputs then tu_file (stream, buffer).
CVSWeb URLs:
http://cvs.savannah.gnu.org/viewcvs/gnash/ChangeLog?cvsroot=gnash&r1=1.4132&r2=1.4133
http://cvs.savannah.gnu.org/viewcvs/gnash/libbase/jpeg.cpp?cvsroot=gnash&r1=1.18&r2=1.19
http://cvs.savannah.gnu.org/viewcvs/gnash/libbase/jpeg.h?cvsroot=gnash&r1=1.6&r2=1.7
Patches:
Index: ChangeLog
===================================================================
RCS file: /sources/gnash/gnash/ChangeLog,v
retrieving revision 1.4132
retrieving revision 1.4133
diff -u -b -r1.4132 -r1.4133
--- ChangeLog 28 Aug 2007 09:38:01 -0000 1.4132
+++ ChangeLog 28 Aug 2007 10:20:56 -0000 1.4133
@@ -1,3 +1,8 @@
+2007-08-28 Sandro Santilli <address@hidden>
+
+ * libbase/jpeg.{cpp,h}: cleanups, aimed at eventually implement
+ different inputs then tu_file (stream, buffer).
+
2007-08-28 Zou Lunkai <address@hidden>
* testsuite/actionscript.all/case.as: more tests.
Index: libbase/jpeg.cpp
===================================================================
RCS file: /sources/gnash/gnash/libbase/jpeg.cpp,v
retrieving revision 1.18
retrieving revision 1.19
diff -u -b -r1.18 -r1.19
--- libbase/jpeg.cpp 18 Aug 2007 05:04:00 -0000 1.18
+++ libbase/jpeg.cpp 28 Aug 2007 10:20:57 -0000 1.19
@@ -23,23 +23,30 @@
namespace jpeg
{
- // jpeglib data source constructors, for using tu_file* instead
- // of stdio for jpeg IO.
- void setup_rw_source(jpeg_decompress_struct* cinfo, tu_file*
instream);
- void setup_rw_dest(jpeg_compress_struct* cinfo, tu_file* outstream);
+// Called when jpeglib has a fatal error.
+static void jpeg_error_exit(j_common_ptr cinfo);
+
+// Set up some error handlers for the jpeg lib.
+static void setup_jpeg_err(jpeg_error_mgr* jerr);
+
+
+/// input/output wrappers for tu_file
+namespace tu_file_wrappers
+{
+
// Helper object for reading jpeg image data. Basically a thin
static const int IO_BUF_SIZE = 4096;
// A jpeglib source manager that reads from a tu_file. Paraphrased
// from IJG jpeglib jdatasrc.c.
- class rw_source
+ class rw_source_tu_file
{
public:
struct jpeg_source_mgr m_pub; /* public fields */
- rw_source(tu_file* in)
+ rw_source_tu_file(tu_file* in)
:
m_in_stream(in),
m_start_of_file(true)
@@ -58,7 +65,7 @@
static void init_source(j_decompress_ptr cinfo)
{
- rw_source* src = (rw_source*) cinfo->src;
+ rw_source_tu_file* src = (rw_source_tu_file*)
cinfo->src;
src->m_start_of_file = true;
}
@@ -66,7 +73,7 @@
// when it needs more data from the file.
static boolean fill_input_buffer(j_decompress_ptr cinfo)
{
- rw_source* src = (rw_source*) cinfo->src;
+ rw_source_tu_file* src = (rw_source_tu_file*)
cinfo->src;
size_t bytes_read =
src->m_in_stream->read_bytes(src->m_buffer, IO_BUF_SIZE);
@@ -112,7 +119,7 @@
// uninteresting data.
static void skip_input_data(j_decompress_ptr cinfo, long
num_bytes)
{
- rw_source* src = (rw_source*) cinfo->src;
+ rw_source_tu_file* src = (rw_source_tu_file*)
cinfo->src;
// According to jpeg docs, large skips are
// infrequent. So let's just do it the simple
@@ -131,7 +138,7 @@
static void term_source(j_decompress_ptr /* cinfo */)
// Terminate the source. Make sure we get deleted.
{
- /*rw_source* src = (rw_source*) cinfo->src;
+ /*rw_source_tu_file* src = (rw_source_tu_file*)
cinfo->src;
assert(src);
// @@ it's kind of bogus to be deleting here
@@ -151,25 +158,29 @@
m_pub.bytes_in_buffer = 0;
m_pub.next_input_byte = NULL;
}
+
+ // Set up the given decompress object to read from the given
+ // stream.
+ static void setup(jpeg_decompress_struct* cinfo, tu_file*
instream)
+ {
+ // assert(cinfo->src == NULL);
+ cinfo->src = (jpeg_source_mgr*) (new
rw_source_tu_file(instream));
+ }
+
private:
tu_file* m_in_stream; /* source stream */
bool m_start_of_file; /* have we gotten any
data yet? */
JOCTET m_buffer[IO_BUF_SIZE]; /* start of buffer */
+
+
};
- void setup_rw_source(jpeg_decompress_struct* cinfo, tu_file*
instream)
- // Set up the given decompress object to read from the given
- // stream.
- {
- // assert(cinfo->src == NULL);
- cinfo->src = (jpeg_source_mgr*) (new rw_source(instream));
- }
// A jpeglib destination manager that writes to a tu_file.
// Paraphrased from IJG jpeglib jdatadst.c.
- class rw_dest
+ class rw_dest_tu_file
{
public:
struct jpeg_destination_mgr m_pub; /* public fields */
@@ -182,7 +193,7 @@
/// @param out
/// The output stream, externally owned.
///
- rw_dest(tu_file* out)
+ rw_dest_tu_file(tu_file* out)
:
m_out_stream(out)
{
@@ -197,24 +208,31 @@
static void init_destination(j_compress_ptr cinfo)
{
- rw_dest* dest = (rw_dest*) cinfo->dest;
+ rw_dest_tu_file* dest = (rw_dest_tu_file*)
cinfo->dest;
assert(dest);
dest->m_pub.next_output_byte = dest->m_buffer;
dest->m_pub.free_in_buffer = IO_BUF_SIZE;
}
+ // Set up the given compress object to write to the given
+ // output stream.
+ static void setup(j_compress_ptr cinfo, tu_file* outstream)
+ {
+ cinfo->dest = (jpeg_destination_mgr*) (new
rw_dest_tu_file(outstream));
+ }
+
/// Write the output buffer into the stream.
static boolean empty_output_buffer(j_compress_ptr cinfo)
{
- rw_dest* dest = (rw_dest*) cinfo->dest;
+ rw_dest_tu_file* dest = (rw_dest_tu_file*)
cinfo->dest;
assert(dest);
if (dest->m_out_stream->write_bytes(dest->m_buffer,
IO_BUF_SIZE) != IO_BUF_SIZE)
{
// Error.
// @@ bah, exceptions suck. TODO consider
alternatives.
- gnash::log_error("jpeg::rw_dest couldn't write
data.");
+ gnash::log_error("jpeg::rw_dest_tu_file
couldn't write data.");
return false;
}
@@ -230,7 +248,7 @@
///
static void term_destination(j_compress_ptr cinfo)
{
- rw_dest* dest = (rw_dest*) cinfo->dest;
+ rw_dest_tu_file* dest = (rw_dest_tu_file*)
cinfo->dest;
assert(dest);
// Write any remaining data.
@@ -239,7 +257,7 @@
if
(dest->m_out_stream->write_bytes(dest->m_buffer, datacount) != datacount)
{
// Error.
-
gnash::log_error("jpeg::rw_dest::term_destination couldn't write data.");
+
gnash::log_error("jpeg::rw_dest_tu_file::term_destination couldn't write
data.");
}
}
@@ -254,42 +272,11 @@
tu_file* m_out_stream;
JOCTET m_buffer[IO_BUF_SIZE]; /* start of buffer */
- };
-
-
- // Set up the given compress object to write to the given
- // output stream.
- void setup_rw_dest(j_compress_ptr cinfo, tu_file* outstream)
- {
- cinfo->dest = (jpeg_destination_mgr*) (new rw_dest(outstream));
- }
-
-
- //
- // Error handler
- //
-
-
- // Called when jpeglib has a fatal error.
- static void jpeg_error_exit(j_common_ptr cinfo);
-
- // Set up some error handlers for the jpeg lib.
- static void setup_jpeg_err(jpeg_error_mgr* jerr)
- {
- // Set up defaults.
- jpeg_std_error(jerr);
-
- jerr->error_exit = jpeg_error_exit;
- }
-
-
- //
- // wrappers
- //
+ };
/// Bascially this is a thin wrapper around jpeg_decompress object.
- class input_impl : public input
+ class input_tu_file : public input
{
public:
// State needed for input.
@@ -298,21 +285,14 @@
bool m_compressor_opened;
- /// This flag will be set to true by the error callback
- /// invoked by jpeg lib. Will be later used to throw
- /// a ParserException.
- ///
- bool errorOccurred;
-
enum SWF_DEFINE_BITS_JPEG2 { SWF_JPEG2 };
enum SWF_DEFINE_BITS_JPEG2_HEADER_ONLY { SWF_JPEG2_HEADER_ONLY
};
// Constructor. Read the header data from in, and
// prepare to read data.
- input_impl(tu_file* in)
+ input_tu_file(tu_file* in)
:
- m_compressor_opened(false),
- errorOccurred(false)
+ m_compressor_opened(false)
{
setup_jpeg_err(&m_jerr);
m_cinfo.err = &m_jerr;
@@ -321,7 +301,7 @@
// Initialize decompression object.
jpeg_create_decompress(&m_cinfo);
- setup_rw_source(&m_cinfo, in);
+ rw_source_tu_file::setup(&m_cinfo, in);
start_image();
}
@@ -334,10 +314,9 @@
// start_image() and finish_image() around any calls
// to get_width/height/components and read_scanline.
//
- input_impl(SWF_DEFINE_BITS_JPEG2_HEADER_ONLY /* e */, tu_file*
in)
+ input_tu_file(SWF_DEFINE_BITS_JPEG2_HEADER_ONLY /* e */,
tu_file* in)
:
- m_compressor_opened(false),
- errorOccurred(false)
+ m_compressor_opened(false)
{
setup_jpeg_err(&m_jerr);
m_cinfo.err = &m_jerr;
@@ -346,7 +325,7 @@
// Initialize decompression object.
jpeg_create_decompress(&m_cinfo);
- setup_rw_source(&m_cinfo, in);
+ rw_source_tu_file::setup(&m_cinfo, in);
// Read the encoding tables.
int ret = jpeg_read_header(&m_cinfo, FALSE);
@@ -367,7 +346,7 @@
break;
}
- if ( errorOccurred )
+ if ( _errorOccurred )
{
throw gnash::ParserException("errors during
JPEG header parsing");
}
@@ -377,11 +356,11 @@
}
// Destructor. Clean up our jpeg reader state.
- ~input_impl()
+ ~input_tu_file()
{
finish_image();
- rw_source* src = (rw_source*) m_cinfo.src;
+ rw_source_tu_file* src = (rw_source_tu_file*)
m_cinfo.src;
delete src;
m_cinfo.src = NULL;
@@ -395,7 +374,7 @@
// data, to avoid screwing up future reads.
void discard_partial_buffer()
{
- rw_source* src = (rw_source*) m_cinfo.src;
+ rw_source_tu_file* src = (rw_source_tu_file*)
m_cinfo.src;
// We only have to discard the input buffer after
reading the tables.
if (src)
@@ -438,14 +417,14 @@
}
}
- if ( errorOccurred )
+ if ( _errorOccurred )
{
throw gnash::ParserException("errors during
JPEG header parsing");
}
jpeg_start_decompress(&m_cinfo);
- if ( errorOccurred )
+ if ( _errorOccurred )
{
throw gnash::ParserException("errors during
JPEG decompression");
}
@@ -514,43 +493,9 @@
}
};
- static void jpeg_error_exit(j_common_ptr cinfo)
- {
- IF_VERBOSE_MALFORMED_SWF(
- gnash::log_swferror("Internal jpeg error: %s",
cinfo->err->jpeg_message_table[cinfo->err->msg_code]);
- );
-
- // Set a flag to stop parsing
- input_impl* impl = static_cast<input_impl*>(cinfo->client_data);
- impl->errorOccurred = true;
- }
-
-
-
- /*static*/
- input*
- input::create(tu_file* in)
- {
- input* ret = new input_impl(in);
- return ret;
- }
-
- /*static*/
- input*
- input::create_swf_jpeg2_header_only(tu_file* in)
- {
- input* ret = new input_impl(input_impl::SWF_JPEG2_HEADER_ONLY,
in);
- return ret;
- }
-
-
- // Default destructor.
- input::~input() {}
-
-
- class output_impl : public output
// Basically this is a thin wrapper around jpeg_compress
// object.
+ class output_tu_file : public output
{
public:
// State needed for output.
@@ -561,14 +506,14 @@
//
/// Read the header data from in, and
/// prepare to read data.
- output_impl(tu_file* out, int width, int height, int quality)
+ output_tu_file(tu_file* out, int width, int height, int quality)
{
m_cinfo.err = jpeg_std_error(&m_jerr);
// Initialize decompression object.
jpeg_create_compress(&m_cinfo);
- setup_rw_dest(&m_cinfo, out);
+ rw_dest_tu_file::setup(&m_cinfo, out);
m_cinfo.image_width = width;
m_cinfo.image_height = height;
m_cinfo.input_components = 3;
@@ -580,12 +525,12 @@
}
- ~output_impl()
+ ~output_tu_file()
// Destructor. Clean up our jpeg reader state.
{
jpeg_finish_compress(&m_cinfo);
/*
- rw_dest* src = (rw_source*) m_cinfo.dest;
+ rw_dest_tu_file* src = (rw_source_tu_file*)
m_cinfo.dest;
delete dest;
m_cinfo.dest = NULL;
*/
@@ -601,19 +546,62 @@
};
- /*static*/ output* output::create(tu_file* in, int width, int
height, int quality)
- // Create and return a jpeg-input object that will read from the
- // given input stream.
- {
- return new output_impl(in, width, height, quality);
- }
+} // namespace tu_file_wrappers
- // Default constructor.
- output::~output() {}
+
+// Set up some error handlers for the jpeg lib.
+static void setup_jpeg_err(jpeg_error_mgr* jerr)
+{
+ // Set up defaults.
+ jpeg_std_error(jerr);
+
+ jerr->error_exit = jpeg_error_exit;
+}
+
+
+static void jpeg_error_exit(j_common_ptr cinfo)
+{
+ IF_VERBOSE_MALFORMED_SWF(
+ gnash::log_swferror(_("Internal jpeg error: %s"),
+ cinfo->err->jpeg_message_table[cinfo->err->msg_code]);
+ );
+
+ // Set a flag to stop parsing
+ input* in = static_cast<input*>(cinfo->client_data);
+ in->errorOccurred();
}
+
+/*static*/
+input*
+input::create(tu_file* in)
+{
+ input* ret = new tu_file_wrappers::input_tu_file(in);
+ return ret;
+}
+
+/*static*/
+input*
+input::create_swf_jpeg2_header_only(tu_file* in)
+{
+ using tu_file_wrappers::input_tu_file;
+ input* ret = new input_tu_file(input_tu_file::SWF_JPEG2_HEADER_ONLY,
in);
+ return ret;
+}
+
+
+/*static*/
+output*
+output::create(tu_file* in, int width, int height, int quality)
+{
+ return new tu_file_wrappers::output_tu_file(in, width, height, quality);
+}
+
+} // namespace jpeg
+
+
// Local Variables:
// mode: C++
// c-basic-offset: 8
Index: libbase/jpeg.h
===================================================================
RCS file: /sources/gnash/gnash/libbase/jpeg.h,v
retrieving revision 1.6
retrieving revision 1.7
diff -u -b -r1.6 -r1.7
--- libbase/jpeg.h 15 May 2007 12:46:15 -0000 1.6
+++ libbase/jpeg.h 28 Aug 2007 10:20:57 -0000 1.7
@@ -29,8 +29,20 @@
public:
- /// Read header and create a jpeg input object.
+ input()
+ :
+ _errorOccurred(false)
+ {}
+
+ virtual ~input() {}
+
+
+ /// \brief
+ /// Create and return a jpeg-input object that will read from
the
+ /// given input stream.
//
+ /// The created input reads the jpeg header
+ ///
/// @return NULL on error
///
DSOEXPORT static input* create(tu_file* in);
@@ -45,8 +57,6 @@
///
DSOEXPORT static input* create_swf_jpeg2_header_only(tu_file*
in);
- virtual ~input();
-
/// Discard existing bytes in our buffer.
virtual void discard_partial_buffer() = 0;
@@ -56,6 +66,19 @@
virtual int get_height() const = 0;
virtual int get_width() const = 0;
virtual void read_scanline(unsigned char* rgb_data) = 0;
+
+ void errorOccurred()
+ {
+ _errorOccurred = true;
+ }
+
+ protected:
+
+ /// This flag will be set to true by the error callback
+ /// invoked by jpeg lib. Will be later used to throw
+ /// a ParserException.
+ ///
+ bool _errorOccurred;
};
@@ -63,15 +86,20 @@
class output
{
public:
- // Create an output object. Quality goes from 1-100.
+ /// Create an output object bount to a tu_file
+ //
+ /// @param quality
+ /// Quality goes from 1-100.
+ ///
DSOEXPORT static output* create(tu_file* out, int width,
int height, int quality);
- virtual ~output();
+ virtual ~output() {}
// ...
virtual void write_scanline(unsigned char* rgb_data) = 0;
};
-}
+
+} // namespace jpeg
#endif // JPEG_H
[Prev in Thread] |
Current Thread |
[Next in Thread] |
- [Gnash-commit] gnash ChangeLog libbase/jpeg.cpp libbase/jpeg.h,
Sandro Santilli <=