vcl/source/filter/jpeg/jpeg.cxx |   48 +++++++++++++++++++++++-----------------
 vcl/source/filter/jpeg/jpeg.hxx |   24 +++++++++-----------
 vcl/source/filter/jpeg/jpegc.c  |   22 ++++++++++--------
 3 files changed, 51 insertions(+), 43 deletions(-)

New commits:
commit a05ebaa139562c8b8b208d967daa08e0b3992d05
Author: Tomaž Vajngerl <qui...@gmail.com>
Date:   Tue Apr 2 20:48:02 2013 +0200

    Jpeg filter: destroy cinfo at setjmp + minor code clenups
    
    Change-Id: Iceaaf6cf98a4c64a17e88e4d3191cd7649940e82

diff --git a/vcl/source/filter/jpeg/jpeg.cxx b/vcl/source/filter/jpeg/jpeg.cxx
index 837e7c5..a4d1b2d 100644
--- a/vcl/source/filter/jpeg/jpeg.cxx
+++ b/vcl/source/filter/jpeg/jpeg.cxx
@@ -73,7 +73,7 @@ typedef struct
   JOCTET * buffer;                  /* start of buffer */
 } my_destination_mgr;
 
-typedef my_destination_mgr * my_dest_ptr;
+typedef my_destination_mgr* my_dest_ptr;
 
 extern "C" void init_destination (j_compress_ptr cinfo)
 {
@@ -281,7 +281,7 @@ JPEGReader::JPEGReader( SvStream& rStm, void* 
/*pCallData*/, sal_Bool bSetLS ) :
         nLastLines      ( 0 ),
         bSetLogSize     ( bSetLS )
 {
-    maUpperName = rtl::OUString("SVIJPEG");
+    maUpperName = OUString("SVIJPEG");
     nFormerPos = nLastPos;
 }
 
@@ -483,10 +483,10 @@ ReadState JPEGReader::Read( Graphic& rGraphic )
     long        nEndPos;
     long        nLines;
     ReadState   eReadState;
-    sal_Bool        bRet = sal_False;
-    sal_uInt8       cDummy;
+    sal_Bool    bRet = sal_False;
+    sal_uInt8   cDummy;
 
-#if 1 // TODO: is it possible to get rid of this seek to the end?
+    // TODO: is it possible to get rid of this seek to the end?
     // check if the stream's end is already available
     rIStm.Seek( STREAM_SEEK_TO_END );
     rIStm >> cDummy;
@@ -505,7 +505,7 @@ ReadState JPEGReader::Read( Graphic& rGraphic )
 
     // seek back to the original position
     rIStm.Seek( nLastPos );
-#endif
+
 
     Size aPreviewSize = GetPreviewSize();
     SetJpegPreviewSizeHint( aPreviewSize.Width(), aPreviewSize.Height() );
@@ -526,16 +526,20 @@ ReadState JPEGReader::Read( Graphic& rGraphic )
         pAcc = NULL;
 
         if( rIStm.GetError() == ERRCODE_IO_PENDING )
+        {
             rGraphic = CreateIntermediateGraphic( aBmp, nLines );
+        }
         else
+        {
             rGraphic = aBmp;
+        }
 
         bRet = sal_True;
     }
     else if( rIStm.GetError() == ERRCODE_IO_PENDING )
         bRet = sal_True;
 
-    // Status setzen ( Pending hat immer Vorrang )
+    // Set status ( Pending has priority )
     if( rIStm.GetError() == ERRCODE_IO_PENDING )
     {
         eReadState = JPEGREAD_NEED_MORE;
@@ -553,13 +557,13 @@ ReadState JPEGReader::Read( Graphic& rGraphic )
     return eReadState;
 }
 
-JPEGWriter::JPEGWriter( SvStream& rStm, const uno::Sequence< 
beans::PropertyValue >* pFilterData, bool* pExportWasGrey ) :
-        rOStm       ( rStm ),
+JPEGWriter::JPEGWriter( SvStream& rStream, const uno::Sequence< 
beans::PropertyValue >* pFilterData, bool* pExportWasGrey ) :
+        rOStm       ( rStream ),
         pAcc        ( NULL ),
         pBuffer     ( NULL ),
         pExpWasGrey ( pExportWasGrey )
 {
-    FilterConfigItem aConfigItem( (uno::Sequence< beans::PropertyValue 
>*)pFilterData );
+    FilterConfigItem aConfigItem( (uno::Sequence< beans::PropertyValue >*) 
pFilterData );
     bGreys = aConfigItem.ReadInt32( "ColorMode", 0 ) != 0;
     nQuality = aConfigItem.ReadInt32( "Quality", 75 );
     aChromaSubsampling = aConfigItem.ReadInt32( "ChromaSubsamplingMode", 0 );
@@ -586,12 +590,14 @@ void* JPEGWriter::GetScanline( long nY )
     if( pAcc )
     {
         if( bNative )
+        {
             pScanline = pAcc->GetScanline( nY );
+        }
         else if( pBuffer )
         {
             BitmapColor aColor;
             long        nWidth = pAcc->Width();
-            sal_uInt8*      pTmp = pBuffer;
+            sal_uInt8*  pTmp = pBuffer;
 
             if( pAcc->HasPalette() )
             {
@@ -599,10 +605,11 @@ void* JPEGWriter::GetScanline( long nY )
                 {
                     aColor = pAcc->GetPaletteColor( (sal_uInt8) 
pAcc->GetPixel( nY, nX ) );
                     *pTmp++ = aColor.GetRed();
-                    if ( bGreys )
-                        continue;
-                    *pTmp++ = aColor.GetGreen();
-                    *pTmp++ = aColor.GetBlue();
+                    if ( !bGreys )
+                    {
+                        *pTmp++ = aColor.GetGreen();
+                        *pTmp++ = aColor.GetBlue();
+                    }
                 }
             }
             else
@@ -611,10 +618,11 @@ void* JPEGWriter::GetScanline( long nY )
                 {
                     aColor = pAcc->GetPixel( nY, nX );
                     *pTmp++ = aColor.GetRed();
-                    if ( bGreys )
-                        continue;
-                    *pTmp++ = aColor.GetGreen();
-                    *pTmp++ = aColor.GetBlue();
+                    if ( !bGreys )
+                    {
+                        *pTmp++ = aColor.GetGreen();
+                        *pTmp++ = aColor.GetBlue();
+                    }
                 }
             }
 
@@ -631,7 +639,7 @@ sal_Bool JPEGWriter::Write( const Graphic& rGraphic )
 
     if ( xStatusIndicator.is() )
     {
-        rtl::OUString aMsg;
+        OUString aMsg;
         xStatusIndicator->start( aMsg, 100 );
     }
 
diff --git a/vcl/source/filter/jpeg/jpeg.hxx b/vcl/source/filter/jpeg/jpeg.hxx
index b77f6c3..e2f11b6 100644
--- a/vcl/source/filter/jpeg/jpeg.hxx
+++ b/vcl/source/filter/jpeg/jpeg.hxx
@@ -56,9 +56,6 @@ public:
     void*               CreateBitmap( void* JPEGCreateBitmapParam );
 
 public:
-
-
-
                         JPEGReader( SvStream& rStm, void* pCallData, sal_Bool 
bSetLogSize );
     virtual             ~JPEGReader();
 
@@ -84,24 +81,25 @@ class JPEGWriter
 
 public:
 
-    void*               GetScanline( long nY );
+    void*       GetScanline( long nY );
+
+                JPEGWriter( SvStream& rOStm,
+                            const ::com::sun::star::uno::Sequence< 
::com::sun::star::beans::PropertyValue >* pFilterData,
+                            bool* pExportWasGrey = NULL );
 
-                        JPEGWriter( SvStream& rOStm, const 
::com::sun::star::uno::Sequence< ::com::sun::star::beans::PropertyValue >* 
pFilterData,
-                                    bool* pExportWasGrey = NULL );
-                        ~JPEGWriter() {};
+                ~JPEGWriter() {};
 
-    sal_Bool                Write( const Graphic& rGraphic );
+    sal_Bool    Write( const Graphic& rGraphic );
 };
 
 #endif // _JPEGPRIVATE
 
 sal_Bool ImportJPEG( SvStream& rStream, Graphic& rGraphic, void* pCallerData, 
sal_Int32 nImportFlags );
 
-sal_Bool ExportJPEG( SvStream& rStream,
-                 const Graphic& rGraphic,
-                 const ::com::sun::star::uno::Sequence< 
::com::sun::star::beans::PropertyValue >* pFilterData,
-                 bool* pExportWasGrey = NULL
-                );
+sal_Bool ExportJPEG(SvStream& rStream,
+                    const Graphic& rGraphic,
+                    const ::com::sun::star::uno::Sequence< 
::com::sun::star::beans::PropertyValue >* pFilterData,
+                    bool* pExportWasGrey = NULL);
 
 #endif // _JPEG_HXX
 
diff --git a/vcl/source/filter/jpeg/jpegc.c b/vcl/source/filter/jpeg/jpegc.c
index a18f197..29d4ef0 100644
--- a/vcl/source/filter/jpeg/jpegc.c
+++ b/vcl/source/filter/jpeg/jpegc.c
@@ -35,8 +35,7 @@ struct my_error_mgr
 void jpeg_svstream_src (j_decompress_ptr cinfo, void* infile);
 void jpeg_svstream_dest (j_compress_ptr cinfo, void* outfile);
 
-METHODDEF( void )
-my_error_exit (j_common_ptr cinfo)
+METHODDEF( void ) my_error_exit (j_common_ptr cinfo)
 {
     my_error_ptr myerr = (my_error_ptr) cinfo->err;
     (*cinfo->err->output_message) (cinfo);
@@ -44,8 +43,7 @@ my_error_exit (j_common_ptr cinfo)
 }
 
 
-METHODDEF( void )
-my_output_message (j_common_ptr cinfo)
+METHODDEF( void ) my_output_message (j_common_ptr cinfo)
 {
     char buffer[JMSG_LENGTH_MAX];
     (*cinfo->err->format_message) (cinfo, buffer);
@@ -76,7 +74,10 @@ void ReadJPEG( void* pJPEGReader, void* pIStm, long* pLines )
     long nScanLineBufferComponents = 0;
 
     if ( setjmp( jerr.setjmp_buffer ) )
+    {
+        jpeg_destroy_decompress( &cinfo );
         return;
+    }
 
     cinfo.err = jpeg_std_error( &jerr.pub );
     jerr.pub.error_exit = my_error_exit;
@@ -144,7 +145,7 @@ void ReadJPEG( void* pJPEGReader, void* pIStm, long* pLines 
)
 
     if ( cinfo.out_color_space == JCS_CMYK )
     {
-            nScanLineBufferComponents = cinfo.output_width * 4;
+        nScanLineBufferComponents = cinfo.output_width * 4;
         pScanLineBuffer = rtl_allocateMemory( nScanLineBufferComponents );
     }
 
@@ -187,14 +188,12 @@ void ReadJPEG( void* pJPEGReader, void* pIStm, long* 
pLines )
     }
 
     if ( pDIB )
-    {
         jpeg_finish_decompress( &cinfo );
-    }
     else
-    {
         jpeg_abort_decompress( &cinfo );
-    }
-    if (pScanLineBuffer!=NULL) {
+
+    if (pScanLineBuffer!=NULL)
+    {
         rtl_freeMemory( pScanLineBuffer );
         pScanLineBuffer=NULL;
     }
@@ -212,7 +211,10 @@ long WriteJPEG( void* pJPEGWriter, void* pOStm,
     long                        nY;
 
     if ( setjmp( jerr.setjmp_buffer ) )
+    {
+        jpeg_destroy_compress( &cinfo );
         return 0;
+    }
 
     cinfo.err = jpeg_std_error( &jerr.pub );
     jerr.pub.error_exit = my_error_exit;
_______________________________________________
Libreoffice-commits mailing list
libreoffice-comm...@lists.freedesktop.org
http://lists.freedesktop.org/mailman/listinfo/libreoffice-commits

Reply via email to