1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
3 * This file is part of the LibreOffice project.
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/.
9 * This file incorporates work covered by the following license notice:
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 .
20 #ifndef INCLUDED_SD_SOURCE_UI_SLIDESORTER_CACHE_SLSBITMAPCOMPRESSOR_HXX
21 #define INCLUDED_SD_SOURCE_UI_SLIDESORTER_CACHE_SLSBITMAPCOMPRESSOR_HXX
23 #include <sal/types.h>
24 #include <boost/shared_ptr.hpp>
28 namespace sd
{ namespace slidesorter
{ namespace cache
{
30 class BitmapReplacement
;
32 /** This interface class provides the minimal method set for classes that
33 implement the compression and decompression of preview bitmaps.
35 class BitmapCompressor
38 /** Compress the given bitmap into a replacement format that is specific
39 to the compressor class.
41 virtual ::boost::shared_ptr
<BitmapReplacement
> Compress (const Bitmap
& rBitmap
) const = 0;
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.
50 virtual Bitmap
Decompress (const BitmapReplacement
& rBitmapData
)const=0;
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.
56 virtual bool IsLossless() const = 0;
59 ~BitmapCompressor() {}
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.
66 class BitmapReplacement
69 virtual sal_Int32
GetMemorySize() const { return 0; }
72 ~BitmapReplacement() {}
75 /** This is one trivial bitmap compressor. It stores bitmaps unmodified
76 instead of compressing them.
77 This compressor is lossless.
79 class NoBitmapCompression
80 : public BitmapCompressor
82 class DummyReplacement
;
84 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
;
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.
95 class CompressionByDeletion
96 : public BitmapCompressor
99 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
;
105 /** Compress a preview bitmap by reducing its resolution. While the aspect
106 ratio is maintained the horizontal resolution is scaled down to 100
108 This compressor is not lossless.
110 class ResolutionReduction
111 : public BitmapCompressor
113 class ResolutionReducedReplacement
;
114 static const sal_Int32 mnWidth
= 100;
116 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.
120 virtual Bitmap
Decompress (const BitmapReplacement
& rBitmapData
) const SAL_OVERRIDE
;
121 virtual bool IsLossless() const SAL_OVERRIDE
;
124 /** Compress preview bitmaps using the PNG format.
125 This compressor is lossless.
128 : public BitmapCompressor
130 class PngReplacement
;
132 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
;
138 } } } // end of namespace ::sd::slidesorter::cache
142 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */