[Libreoffice-commits] core.git: include/vcl vcl/inc vcl/source

Tomaž Vajngerl (via logerrit) logerrit at kemper.freedesktop.org
Wed Mar 4 11:58:26 UTC 2020


 include/vcl/graphicfilter.hxx         |    1 
 include/vcl/pngread.hxx               |    2 -
 vcl/inc/graphic/GraphicReader.hxx     |   11 --------
 vcl/source/filter/graphicfilter.cxx   |   32 +----------------------
 vcl/source/filter/jpeg/JpegReader.cxx |    2 -
 vcl/source/filter/jpeg/jpeg.cxx       |    9 ------
 vcl/source/filter/jpeg/jpeg.h         |    2 -
 vcl/source/filter/jpeg/jpegc.cxx      |   44 ++------------------------------
 vcl/source/filter/png/pngread.cxx     |   46 +++++-----------------------------
 vcl/source/graphic/GraphicReader.cxx  |   27 -------------------
 10 files changed, 15 insertions(+), 161 deletions(-)

New commits:
commit 2876a0f79f94cdd139cc8fa40669acde9674bf8c
Author:     Tomaž Vajngerl <tomaz.vajngerl at collabora.co.uk>
AuthorDate: Tue Mar 3 22:01:37 2020 +0100
Commit:     Tomaž Vajngerl <quikee at gmail.com>
CommitDate: Wed Mar 4 12:57:43 2020 +0100

    graphic: remove preview when importing with GraphicFilter
    
    The property "PreviewSizeHint" and the enum value ForPreview in
    GraphicFilterImportFlags doesn't seem to be used from outside, so
    let's remove it as it simplifies the PNG and JPEG import filters.
    
    It is generally more recommended to load the bitmap file fully and
    only then resize it to a smaller (preview) size.
    
    Change-Id: I97f333686c25f7a7a4bdf6c6f0885154b515fd3d
    Reviewed-on: https://gerrit.libreoffice.org/c/core/+/89932
    Tested-by: Jenkins
    Reviewed-by: Tomaž Vajngerl <quikee at gmail.com>

diff --git a/include/vcl/graphicfilter.hxx b/include/vcl/graphicfilter.hxx
index 45fe8e261f9e..8a59d2461a2a 100644
--- a/include/vcl/graphicfilter.hxx
+++ b/include/vcl/graphicfilter.hxx
@@ -55,7 +55,6 @@ enum class GraphicFilterImportFlags
     NONE                   = 0x000,
     SetLogsizeForJpeg      = 0x001,
     DontSetLogsizeForJpeg  = 0x002,
-    ForPreview             = 0x004,
     /// Only create a bitmap, do not read pixel data.
     OnlyCreateBitmap       = 0x020,
     /// Read pixel data into an existing bitmap.
diff --git a/include/vcl/pngread.hxx b/include/vcl/pngread.hxx
index 31592d9f17ac..0fda677e2817 100644
--- a/include/vcl/pngread.hxx
+++ b/include/vcl/pngread.hxx
@@ -43,7 +43,7 @@ public:
 
     /* an empty preview size hint (=default) will read the whole image
     */
-    BitmapEx Read(const Size& i_rPreviewHint = Size());
+    BitmapEx Read();
 
     // retrieve every chunk that resides inside the PNG
     struct ChunkData
diff --git a/vcl/inc/graphic/GraphicReader.hxx b/vcl/inc/graphic/GraphicReader.hxx
index fe60ecf97b29..9576d42531d1 100644
--- a/vcl/inc/graphic/GraphicReader.hxx
+++ b/vcl/inc/graphic/GraphicReader.hxx
@@ -24,8 +24,6 @@
 #include <tools/gen.hxx>
 #include <memory>
 
-class ReaderData;
-
 class GraphicReader
 {
 public:
@@ -33,19 +31,10 @@ public:
 
     const OUString& GetUpperFilterName() const { return maUpperName; }
 
-    // TODO: when incompatible changes are possible again
-    // the preview size hint should be redone
-    void DisablePreviewMode();
-    void SetPreviewSize(const Size&);
-    Size GetPreviewSize() const;
-
 protected:
     OUString maUpperName;
 
     GraphicReader();
-
-private:
-    std::unique_ptr<ReaderData> mpReaderData;
 };
 
 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
diff --git a/vcl/source/filter/graphicfilter.cxx b/vcl/source/filter/graphicfilter.cxx
index 5597fb760b56..21f70c42f352 100644
--- a/vcl/source/filter/graphicfilter.cxx
+++ b/vcl/source/filter/graphicfilter.cxx
@@ -1410,7 +1410,7 @@ void GraphicFilter::preload()
 
 ErrCode GraphicFilter::ImportGraphic( Graphic& rGraphic, const OUString& rPath, SvStream& rIStream,
                                      sal_uInt16 nFormat, sal_uInt16* pDeterminedFormat, GraphicFilterImportFlags nImportFlags,
-                                     const css::uno::Sequence< css::beans::PropertyValue >* pFilterData,
+                                     const css::uno::Sequence< css::beans::PropertyValue >* /*pFilterData*/,
                                      WmfExternal const *pExtHeader )
 {
     OUString                       aFilterName;
@@ -1420,32 +1420,11 @@ ErrCode GraphicFilter::ImportGraphic( Graphic& rGraphic, const OUString& rPath,
     GfxLinkType                    eLinkType = GfxLinkType::NONE;
     const bool                     bLinkSet = rGraphic.IsGfxLink();
 
-    Size                aPreviewSizeHint( 0, 0 );
-
     std::unique_ptr<sal_uInt8[]> pGraphicContent;
     sal_Int32  nGraphicContentSize = 0;
 
     ResetLastError();
 
-    if ( pFilterData )
-    {
-        for ( const auto& rPropVal : *pFilterData )
-        {
-            if ( rPropVal.Name == "PreviewSizeHint" )
-            {
-                css::awt::Size aSize;
-                if ( rPropVal.Value >>= aSize )
-                {
-                    aPreviewSizeHint = Size( aSize.Width, aSize.Height );
-                    if ( aSize.Width || aSize.Height )
-                        nImportFlags |= GraphicFilterImportFlags::ForPreview;
-                    else
-                        nImportFlags &=~GraphicFilterImportFlags::ForPreview;
-                }
-            }
-        }
-    }
-
     std::shared_ptr<GraphicReader> pContext = rGraphic.GetReaderContext();
     bool  bDummyContext = rGraphic.IsDummyContext();
     if( !pContext || bDummyContext )
@@ -1501,13 +1480,6 @@ ErrCode GraphicFilter::ImportGraphic( Graphic& rGraphic, const OUString& rPath,
         {
             vcl::PNGReader aPNGReader( rIStream );
 
-            // ignore animation for previews and set preview size
-            if( aPreviewSizeHint.Width() || aPreviewSizeHint.Height() )
-            {
-                // position the stream at the end of the image if requested
-                aPNGReader.GetChunks();
-            }
-            else
             {
                 // check if this PNG contains a GIF chunk!
                 const std::vector<vcl::PNGReader::ChunkData>& rChunkData = aPNGReader.GetChunks();
@@ -1537,7 +1509,7 @@ ErrCode GraphicFilter::ImportGraphic( Graphic& rGraphic, const OUString& rPath,
 
             if ( eLinkType == GfxLinkType::NONE )
             {
-                BitmapEx aBmpEx( aPNGReader.Read( aPreviewSizeHint ) );
+                BitmapEx aBmpEx( aPNGReader.Read() );
                 if ( aBmpEx.IsEmpty() )
                     nStatus = ERRCODE_GRFILTER_FILTERERROR;
                 else
diff --git a/vcl/source/filter/jpeg/JpegReader.cxx b/vcl/source/filter/jpeg/JpegReader.cxx
index 6e9d5421510c..df7374770463 100644
--- a/vcl/source/filter/jpeg/JpegReader.cxx
+++ b/vcl/source/filter/jpeg/JpegReader.cxx
@@ -292,7 +292,7 @@ ReadState JPEGReader::Read( Graphic& rGraphic, GraphicFilterImportFlags nImportF
 
     // read the (partial) image
     long nLines;
-    ReadJPEG( this, &mrStream, &nLines, GetPreviewSize(), nImportFlags, ppAccess );
+    ReadJPEG( this, &mrStream, &nLines, nImportFlags, ppAccess );
 
     auto bUseExistingBitmap = static_cast<bool>(nImportFlags & GraphicFilterImportFlags::UseExistingBitmap);
     if (bUseExistingBitmap || !mpBitmap->IsEmpty())
diff --git a/vcl/source/filter/jpeg/jpeg.cxx b/vcl/source/filter/jpeg/jpeg.cxx
index eec0e7c3c4a7..e7158b858b68 100644
--- a/vcl/source/filter/jpeg/jpeg.cxx
+++ b/vcl/source/filter/jpeg/jpeg.cxx
@@ -36,15 +36,6 @@ VCL_DLLPUBLIC bool ImportJPEG( SvStream& rInputStream, Graphic& rGraphic, Graphi
         pJPEGReader = static_cast<JPEGReader*>( pContext.get() );
     }
 
-    if( nImportFlags & GraphicFilterImportFlags::ForPreview )
-    {
-        pJPEGReader->SetPreviewSize( Size(128,128) );
-    }
-    else
-    {
-        pJPEGReader->DisablePreviewMode();
-    }
-
     ReadState eReadState = pJPEGReader->Read( rGraphic, nImportFlags, ppAccess );
 
     if( eReadState == JPEGREAD_ERROR )
diff --git a/vcl/source/filter/jpeg/jpeg.h b/vcl/source/filter/jpeg/jpeg.h
index 9641d10337ac..e09755ab7a13 100644
--- a/vcl/source/filter/jpeg/jpeg.h
+++ b/vcl/source/filter/jpeg/jpeg.h
@@ -47,7 +47,7 @@ bool    WriteJPEG( JPEGWriter* pJPEGWriter, void* pOutputStream,
                    css::uno::Reference<css::task::XStatusIndicator> const & status);
 
 void    ReadJPEG( JPEGReader* pJPEGReader, void* pInputStream, long* pLines,
-                  Size const & previewSize, GraphicFilterImportFlags nImportFlags,
+                  GraphicFilterImportFlags nImportFlags,
                   BitmapScopedWriteAccess* ppAccess );
 
 void    Transform(void* pInputStream, void* pOutputStream, long nAngle);
diff --git a/vcl/source/filter/jpeg/jpegc.cxx b/vcl/source/filter/jpeg/jpegc.cxx
index 724f5b797ccc..1ab261e3c8ce 100644
--- a/vcl/source/filter/jpeg/jpegc.cxx
+++ b/vcl/source/filter/jpeg/jpegc.cxx
@@ -154,7 +154,7 @@ struct JpegStuff
 }
 
 static void ReadJPEG(JpegStuff& rContext, JPEGReader* pJPEGReader, void* pInputStream, long* pLines,
-              Size const & previewSize, GraphicFilterImportFlags nImportFlags,
+              GraphicFilterImportFlags nImportFlags,
               BitmapScopedWriteAccess* ppAccess)
 {
     if (setjmp(rContext.jerr.setjmp_buffer))
@@ -179,44 +179,6 @@ static void ReadJPEG(JpegStuff& rContext, JPEGReader* pJPEGReader, void* pInputS
     rContext.cinfo.raw_data_out = FALSE;
     rContext.cinfo.quantize_colors = FALSE;
 
-    /* change scale for preview import */
-    long nPreviewWidth = previewSize.Width();
-    long nPreviewHeight = previewSize.Height();
-    if( nPreviewWidth || nPreviewHeight )
-    {
-        if( nPreviewWidth == 0 )
-        {
-            nPreviewWidth = (rContext.cinfo.image_width * nPreviewHeight) / rContext.cinfo.image_height;
-            if( nPreviewWidth <= 0 )
-            {
-                nPreviewWidth = 1;
-            }
-        }
-        else if( nPreviewHeight == 0 )
-        {
-            nPreviewHeight = (rContext.cinfo.image_height * nPreviewWidth) / rContext.cinfo.image_width;
-            if( nPreviewHeight <= 0 )
-            {
-                nPreviewHeight = 1;
-            }
-        }
-
-        for (rContext.cinfo.scale_denom = 1; rContext.cinfo.scale_denom < 8; rContext.cinfo.scale_denom *= 2)
-        {
-            if (rContext.cinfo.image_width < nPreviewWidth * rContext.cinfo.scale_denom)
-                break;
-            if (rContext.cinfo.image_height < nPreviewHeight * rContext.cinfo.scale_denom)
-                break;
-        }
-
-        if (rContext.cinfo.scale_denom > 1)
-        {
-            rContext.cinfo.dct_method            = JDCT_FASTEST;
-            rContext.cinfo.do_fancy_upsampling   = FALSE;
-            rContext.cinfo.do_block_smoothing    = FALSE;
-        }
-    }
-
     jpeg_calc_output_dimensions(&rContext.cinfo);
 
     long nWidth = rContext.cinfo.output_width;
@@ -356,11 +318,11 @@ static void ReadJPEG(JpegStuff& rContext, JPEGReader* pJPEGReader, void* pInputS
 }
 
 void ReadJPEG( JPEGReader* pJPEGReader, void* pInputStream, long* pLines,
-               Size const & previewSize, GraphicFilterImportFlags nImportFlags,
+               GraphicFilterImportFlags nImportFlags,
                BitmapScopedWriteAccess* ppAccess )
 {
     JpegStuff aContext;
-    ReadJPEG(aContext, pJPEGReader, pInputStream, pLines, previewSize, nImportFlags, ppAccess);
+    ReadJPEG(aContext, pJPEGReader, pInputStream, pLines, nImportFlags, ppAccess);
 }
 
 bool WriteJPEG( JPEGWriter* pJPEGWriter, void* pOutputStream,
diff --git a/vcl/source/filter/png/pngread.cxx b/vcl/source/filter/png/pngread.cxx
index 0d85e7326db1..2aa4f9a6610f 100644
--- a/vcl/source/filter/png/pngread.cxx
+++ b/vcl/source/filter/png/pngread.cxx
@@ -162,7 +162,7 @@ private:
     void                ImplGetGamma();
     void                ImplGetBackground();
     sal_uInt8           ImplScaleColor();
-    bool                ImplReadHeader( const Size& rPreviewSizeHint );
+    bool                ImplReadHeader();
     bool                ImplReadPalette();
     void                ImplGetGrayPalette( sal_uInt16 );
     sal_uInt32          ImplReadsal_uInt32();
@@ -172,7 +172,7 @@ public:
     explicit PNGReaderImpl( SvStream& );
     ~PNGReaderImpl();
 
-    BitmapEx            GetBitmapEx( const Size& rPreviewSizeHint );
+    BitmapEx            GetBitmapEx();
     const std::vector<vcl::PNGReader::ChunkData>& GetAllChunks();
     void                SetIgnoreGammaChunk( bool bIgnore ){ mbIgnoreGammaChunk = bIgnore; };
 };
@@ -325,7 +325,7 @@ const std::vector< vcl::PNGReader::ChunkData >& PNGReaderImpl::GetAllChunks()
     return maChunkSeq;
 }
 
-BitmapEx PNGReaderImpl::GetBitmapEx( const Size& rPreviewSizeHint )
+BitmapEx PNGReaderImpl::GetBitmapEx()
 {
     // reset to the first chunk
     maChunkIter = maChunkSeq.begin();
@@ -334,7 +334,7 @@ BitmapEx PNGReaderImpl::GetBitmapEx( const Size& rPreviewSizeHint )
     if( mbStatus && ReadNextChunk() )
     {
         if (mnChunkType == PNGCHUNK_IHDR)
-            mbStatus = ImplReadHeader( rPreviewSizeHint );
+            mbStatus = ImplReadHeader();
         else
             mbStatus = false;
     }
@@ -442,7 +442,7 @@ BitmapEx PNGReaderImpl::GetBitmapEx( const Size& rPreviewSizeHint )
     return aRet;
 }
 
-bool PNGReaderImpl::ImplReadHeader( const Size& rPreviewSizeHint )
+bool PNGReaderImpl::ImplReadHeader()
 {
     if( mnChunkLen < 13 )
         return false;
@@ -603,38 +603,6 @@ bool PNGReaderImpl::ImplReadHeader( const Size& rPreviewSizeHint )
 
     mnScansize = static_cast< sal_uInt32 >( nScansize64 );
 
-    // calculate target size from original size and the preview hint
-    if( rPreviewSizeHint.Width() || rPreviewSizeHint.Height() )
-    {
-        Size aPreviewSize( rPreviewSizeHint.Width(), rPreviewSizeHint.Height() );
-        maTargetSize = maOrigSize;
-
-        if( aPreviewSize.Width() == 0 ) {
-            aPreviewSize.setWidth( ( maOrigSize.Width()*aPreviewSize.Height() )/maOrigSize.Height() );
-            if( aPreviewSize.Width() <= 0 )
-                aPreviewSize.setWidth( 1 );
-        } else if( aPreviewSize.Height() == 0 ) {
-            aPreviewSize.setHeight( ( maOrigSize.Height()*aPreviewSize.Width() )/maOrigSize.Width() );
-            if( aPreviewSize.Height() <= 0 )
-                aPreviewSize.setHeight( 1 );
-        }
-
-        if( aPreviewSize.Width() < maOrigSize.Width() && aPreviewSize.Height() < maOrigSize.Height() ) {
-            SAL_INFO( "vcl.gdi", "preview size " << aPreviewSize.Width() << " " << aPreviewSize.Height() );
-
-            for( int i = 1; i < 5; ++i )
-            {
-                if( (maTargetSize.Width() >> i) < aPreviewSize.Width() )
-                    break;
-                if( (maTargetSize.Height() >> i) < aPreviewSize.Height() )
-                    break;
-                mnPreviewShift = i;
-            }
-
-            mnPreviewMask = (1 << mnPreviewShift) - 1;
-        }
-    }
-
     maTargetSize.setWidth( (maOrigSize.Width() + mnPreviewMask) >> mnPreviewShift );
     maTargetSize.setHeight( (maOrigSize.Height() + mnPreviewMask) >> mnPreviewShift );
 
@@ -1727,9 +1695,9 @@ PNGReader::~PNGReader()
 {
 }
 
-BitmapEx PNGReader::Read( const Size& i_rPreviewSizeHint )
+BitmapEx PNGReader::Read()
 {
-    return mpImpl->GetBitmapEx( i_rPreviewSizeHint );
+    return mpImpl->GetBitmapEx();
 }
 
 const std::vector< vcl::PNGReader::ChunkData >& PNGReader::GetChunks() const
diff --git a/vcl/source/graphic/GraphicReader.cxx b/vcl/source/graphic/GraphicReader.cxx
index 060b8e32c2ba..9137ebd8a246 100644
--- a/vcl/source/graphic/GraphicReader.cxx
+++ b/vcl/source/graphic/GraphicReader.cxx
@@ -22,35 +22,8 @@
 #include <sal/config.h>
 #include <sal/log.hxx>
 
-class ReaderData
-{
-public:
-    Size maPreviewSize;
-};
-
 GraphicReader::GraphicReader() {}
 
 GraphicReader::~GraphicReader() {}
 
-void GraphicReader::DisablePreviewMode()
-{
-    if (mpReaderData)
-        mpReaderData->maPreviewSize = Size(0, 0);
-}
-
-void GraphicReader::SetPreviewSize(const Size& rSize)
-{
-    if (!mpReaderData)
-        mpReaderData.reset(new ReaderData);
-    mpReaderData->maPreviewSize = rSize;
-}
-
-Size GraphicReader::GetPreviewSize() const
-{
-    Size aSize(0, 0);
-    if (mpReaderData)
-        aSize = mpReaderData->maPreviewSize;
-    return aSize;
-}
-
 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */


More information about the Libreoffice-commits mailing list