LCOV - code coverage report
Current view: top level - sd/source/ui/slidesorter/cache - SlsBitmapCompressor.hxx (source / functions) Hit Total Coverage
Test: commit c8344322a7af75b84dd3ca8f78b05543a976dfd5 Lines: 4 13 30.8 %
Date: 2015-06-13 12:38:46 Functions: 5 17 29.4 %
Legend: Lines: hit not hit

          Line data    Source code
       1             : /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
       2             : /*
       3             :  * This file is part of the LibreOffice project.
       4             :  *
       5             :  * This Source Code Form is subject to the terms of the Mozilla Public
       6             :  * License, v. 2.0. If a copy of the MPL was not distributed with this
       7             :  * file, You can obtain one at http://mozilla.org/MPL/2.0/.
       8             :  *
       9             :  * This file incorporates work covered by the following license notice:
      10             :  *
      11             :  *   Licensed to the Apache Software Foundation (ASF) under one or more
      12             :  *   contributor license agreements. See the NOTICE file distributed
      13             :  *   with this work for additional information regarding copyright
      14             :  *   ownership. The ASF licenses this file to you under the Apache
      15             :  *   License, Version 2.0 (the "License"); you may not use this file
      16             :  *   except in compliance with the License. You may obtain a copy of
      17             :  *   the License at http://www.apache.org/licenses/LICENSE-2.0 .
      18             :  */
      19             : 
      20             : #ifndef INCLUDED_SD_SOURCE_UI_SLIDESORTER_CACHE_SLSBITMAPCOMPRESSOR_HXX
      21             : #define INCLUDED_SD_SOURCE_UI_SLIDESORTER_CACHE_SLSBITMAPCOMPRESSOR_HXX
      22             : 
      23             : #include <sal/types.h>
      24             : #include <boost/shared_ptr.hpp>
      25             : 
      26             : class Bitmap;
      27             : 
      28             : namespace sd { namespace slidesorter { namespace cache {
      29             : 
      30             : class BitmapReplacement;
      31             : 
      32             : /** This interface class provides the minimal method set for classes that
      33             :     implement the compression and decompression of preview bitmaps.
      34             : */
      35          64 : class BitmapCompressor
      36             : {
      37             : public:
      38             :     /** Compress the given bitmap into a replacement format that is specific
      39             :         to the compressor class.
      40             :     */
      41             :     virtual ::boost::shared_ptr<BitmapReplacement> Compress (const Bitmap& rBitmap) const = 0;
      42             : 
      43             :     /** Decompress the given replacement data into a preview bitmap.
      44             :         Depending on the compression technique the returned bitmap may
      45             :         differ from the original bitmap given to the Compress() method.  It
      46             :         may even of the wrong size or empty or the NULL pointer.  It is the
      47             :         task of the caller to create a new preview bitmap if the returned
      48             :         one is not as desired.
      49             :     */
      50             :     virtual Bitmap Decompress (const BitmapReplacement& rBitmapData)const=0;
      51             : 
      52             :     /** Return whether the compression and decompression is lossless.  This
      53             :         value is used by the caller of Decompress() to decide whether to use
      54             :         the returned bitmap as is or if a new preview has to be created.
      55             :     */
      56             :     virtual bool IsLossless() const = 0;
      57             : 
      58             : protected:
      59          64 :     ~BitmapCompressor() {}
      60             : };
      61             : 
      62             : /** Interface for preview bitmap replacements.  Each bitmap
      63             :     compressor/decompressor has to provide an implementation that is
      64             :     suitable to store the compressed bitmaps.
      65             : */
      66           0 : class BitmapReplacement
      67             : {
      68             : public:
      69           0 :     virtual sal_Int32 GetMemorySize() const { return 0; }
      70             : 
      71             : protected:
      72           0 :     ~BitmapReplacement() {}
      73             : };
      74             : 
      75             : /** This is one trivial bitmap compressor.  It stores bitmaps unmodified
      76             :     instead of compressing them.
      77             :     This compressor is lossless.
      78             : */
      79           0 : class NoBitmapCompression
      80             :     : public BitmapCompressor
      81             : {
      82             :     class DummyReplacement;
      83             : public:
      84           0 :     virtual ~NoBitmapCompression() {}
      85             :     virtual ::boost::shared_ptr<BitmapReplacement> Compress (const Bitmap& rpBitmap) const SAL_OVERRIDE;
      86             :     virtual Bitmap Decompress (const BitmapReplacement& rBitmapData) const SAL_OVERRIDE;
      87             :     virtual bool IsLossless() const SAL_OVERRIDE;
      88             : };
      89             : 
      90             : /** This is another trivial bitmap compressor.  Instead of compressing a
      91             :     bitmap, it throws the bitmap away.  Its Decompress() method returns a
      92             :     NULL pointer.  The caller has to create a new preview bitmap instead.
      93             :     This compressor clearly is not lossless.
      94             : */
      95           0 : class CompressionByDeletion
      96             :     : public BitmapCompressor
      97             : {
      98             : public:
      99           0 :     virtual ~CompressionByDeletion() {}
     100             :     virtual ::boost::shared_ptr<BitmapReplacement> Compress (const Bitmap& rBitmap) const SAL_OVERRIDE;
     101             :     virtual Bitmap Decompress (const BitmapReplacement& rBitmapData) const SAL_OVERRIDE;
     102             :     virtual bool IsLossless() const SAL_OVERRIDE;
     103             : };
     104             : 
     105             : /** Compress a preview bitmap by reducing its resolution.  While the aspect
     106             :     ratio is maintained the horizontal resolution is scaled down to 100
     107             :     pixels.
     108             :     This compressor is not lossless.
     109             : */
     110           0 : class ResolutionReduction
     111             :     : public BitmapCompressor
     112             : {
     113             :     class ResolutionReducedReplacement;
     114             :     static const sal_Int32 mnWidth = 100;
     115             : public:
     116           0 :     virtual ~ResolutionReduction() {}
     117             :     virtual ::boost::shared_ptr<BitmapReplacement> Compress (const Bitmap& rpBitmap) const SAL_OVERRIDE;
     118             :     /** Scale the replacement bitmap up to the original size.
     119             :     */
     120             :     virtual Bitmap Decompress (const BitmapReplacement& rBitmapData) const SAL_OVERRIDE;
     121             :     virtual bool IsLossless() const SAL_OVERRIDE;
     122             : };
     123             : 
     124             : /** Compress preview bitmaps using the PNG format.
     125             :     This compressor is lossless.
     126             : */
     127          64 : class PngCompression
     128             :     : public BitmapCompressor
     129             : {
     130             :     class PngReplacement;
     131             : public:
     132         128 :     virtual ~PngCompression() {}
     133             :     virtual ::boost::shared_ptr<BitmapReplacement> Compress (const Bitmap& rBitmap) const SAL_OVERRIDE;
     134             :     virtual Bitmap Decompress (const BitmapReplacement& rBitmapData) const SAL_OVERRIDE;
     135             :     virtual bool IsLossless() const SAL_OVERRIDE;
     136             : };
     137             : 
     138             : } } } // end of namespace ::sd::slidesorter::cache
     139             : 
     140             : #endif
     141             : 
     142             : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.11