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 :
27 : class Bitmap;
28 :
29 : namespace sd { namespace slidesorter { namespace cache {
30 :
31 : class BitmapReplacement;
32 :
33 :
34 : /** This interface class provides the minimal method set for classes that
35 : implement the compression and decompression of preview bitmaps.
36 : */
37 0 : class BitmapCompressor
38 : {
39 : public:
40 : /** Compress the given bitmap into a replacement format that is specific
41 : to the compressor class.
42 : */
43 : virtual ::boost::shared_ptr<BitmapReplacement> Compress (const Bitmap& rBitmap) const = 0;
44 :
45 : /** Decompress the given replacement data into a preview bitmap.
46 : Depending on the compression technique the returned bitmap may
47 : differ from the original bitmap given to the Compress() method. It
48 : may even of the wrong size or empty or the NULL pointer. It is the
49 : task of the caller to create a new preview bitmap if the returned
50 : one is not as desired.
51 : */
52 : virtual Bitmap Decompress (const BitmapReplacement& rBitmapData)const=0;
53 :
54 : /** Return whether the compression and decompression is lossless. This
55 : value is used by the caller of Decompress() to decide whether to use
56 : the returned bitmap as is or if a new preview has to be created.
57 : */
58 : virtual bool IsLossless (void) const = 0;
59 :
60 : protected:
61 0 : ~BitmapCompressor() {}
62 : };
63 :
64 :
65 :
66 : /** Interface for preview bitmap replacements. Each bitmap
67 : compressor/decompressor has to provide an implementation that is
68 : suitable to store the compressed bitmaps.
69 : */
70 0 : class BitmapReplacement
71 : {
72 : public:
73 0 : virtual sal_Int32 GetMemorySize (void) const { return 0; }
74 :
75 : protected:
76 0 : ~BitmapReplacement() {}
77 : };
78 :
79 :
80 :
81 :
82 : /** This is one trivial bitmap compressor. It stores bitmaps unmodified
83 : instead of compressing them.
84 : This compressor is lossless.
85 : */
86 0 : class NoBitmapCompression
87 : : public BitmapCompressor
88 : {
89 : class DummyReplacement;
90 : public:
91 0 : virtual ~NoBitmapCompression() {}
92 : virtual ::boost::shared_ptr<BitmapReplacement> Compress (const Bitmap& rpBitmap) const SAL_OVERRIDE;
93 : virtual Bitmap Decompress (const BitmapReplacement& rBitmapData) const SAL_OVERRIDE;
94 : virtual bool IsLossless (void) const SAL_OVERRIDE;
95 : };
96 :
97 :
98 :
99 :
100 : /** This is another trivial bitmap compressor. Instead of compressing a
101 : bitmap, it throws the bitmap away. Its Decompress() method returns a
102 : NULL pointer. The caller has to create a new preview bitmap instead.
103 : This compressor clearly is not lossless.
104 : */
105 0 : class CompressionByDeletion
106 : : public BitmapCompressor
107 : {
108 : public:
109 0 : virtual ~CompressionByDeletion() {}
110 : virtual ::boost::shared_ptr<BitmapReplacement> Compress (const Bitmap& rBitmap) const SAL_OVERRIDE;
111 : virtual Bitmap Decompress (const BitmapReplacement& rBitmapData) const SAL_OVERRIDE;
112 : virtual bool IsLossless (void) const SAL_OVERRIDE;
113 : };
114 :
115 :
116 :
117 :
118 : /** Compress a preview bitmap by reducing its resolution. While the aspect
119 : ratio is maintained the horizontal resolution is scaled down to 100
120 : pixels.
121 : This compressor is not lossless.
122 : */
123 0 : class ResolutionReduction
124 : : public BitmapCompressor
125 : {
126 : class ResolutionReducedReplacement;
127 : static const sal_Int32 mnWidth = 100;
128 : public:
129 0 : virtual ~ResolutionReduction() {}
130 : virtual ::boost::shared_ptr<BitmapReplacement> Compress (const Bitmap& rpBitmap) const SAL_OVERRIDE;
131 : /** Scale the replacement bitmap up to the original size.
132 : */
133 : virtual Bitmap Decompress (const BitmapReplacement& rBitmapData) const SAL_OVERRIDE;
134 : virtual bool IsLossless (void) const SAL_OVERRIDE;
135 : };
136 :
137 :
138 :
139 :
140 : /** Compress preview bitmaps using the PNG format.
141 : This compressor is lossless.
142 : */
143 0 : class PngCompression
144 : : public BitmapCompressor
145 : {
146 : class PngReplacement;
147 : public:
148 0 : virtual ~PngCompression() {}
149 : virtual ::boost::shared_ptr<BitmapReplacement> Compress (const Bitmap& rBitmap) const SAL_OVERRIDE;
150 : virtual Bitmap Decompress (const BitmapReplacement& rBitmapData) const SAL_OVERRIDE;
151 : virtual bool IsLossless (void) const SAL_OVERRIDE;
152 : };
153 :
154 :
155 : } } } // end of namespace ::sd::slidesorter::cache
156 :
157 : #endif
158 :
159 : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|