Branch data Line data Source code
1 : : /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 : : /*************************************************************************
3 : : *
4 : : * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
5 : : *
6 : : * Copyright 2000, 2010 Oracle and/or its affiliates.
7 : : *
8 : : * OpenOffice.org - a multi-platform office productivity suite
9 : : *
10 : : * This file is part of OpenOffice.org.
11 : : *
12 : : * OpenOffice.org is free software: you can redistribute it and/or modify
13 : : * it under the terms of the GNU Lesser General Public License version 3
14 : : * only, as published by the Free Software Foundation.
15 : : *
16 : : * OpenOffice.org is distributed in the hope that it will be useful,
17 : : * but WITHOUT ANY WARRANTY; without even the implied warranty of
18 : : * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19 : : * GNU Lesser General Public License version 3 for more details
20 : : * (a copy is included in the LICENSE file that accompanied this code).
21 : : *
22 : : * You should have received a copy of the GNU Lesser General Public License
23 : : * version 3 along with OpenOffice.org. If not, see
24 : : * <http://www.openoffice.org/license.html>
25 : : * for a copy of the LGPLv3 License.
26 : : *
27 : : ************************************************************************/
28 : :
29 : : #ifndef SD_SLIDESORTER_BITMAP_COMPRESSOR_HXX
30 : : #define SD_SLIDESORTER_BITMAP_COMPRESSOR_HXX
31 : :
32 : : #include <sal/types.h>
33 : : #include <tools/gen.hxx>
34 : : #include <boost/shared_ptr.hpp>
35 : :
36 : :
37 : : class Bitmap;
38 : :
39 : : namespace sd { namespace slidesorter { namespace cache {
40 : :
41 : : class BitmapReplacement;
42 : :
43 : :
44 : : /** This interface class provides the minimal method set for classes that
45 : : implement the compression and decompression of preview bitmaps.
46 : : */
47 : 126 : class BitmapCompressor
48 : : {
49 : : public:
50 : : /** Compress the given bitmap into a replacement format that is specific
51 : : to the compressor class.
52 : : */
53 : : virtual ::boost::shared_ptr<BitmapReplacement> Compress (const Bitmap& rBitmap) const = 0;
54 : :
55 : : /** Decompress the given replacement data into a preview bitmap.
56 : : Depending on the compression technique the returned bitmap may
57 : : differ from the original bitmap given to the Compress() method. It
58 : : may even of the wrong size or empty or the NULL pointer. It is the
59 : : task of the caller to create a new preview bitmap if the returned
60 : : one is not as desired.
61 : : */
62 : : virtual Bitmap Decompress (const BitmapReplacement& rBitmapData)const=0;
63 : :
64 : : /** Return whether the compression and decompression is lossless. This
65 : : value is used by the caller of Decompress() to decide whether to use
66 : : the returned bitmap as is or if a new preview has to be created.
67 : : */
68 : : virtual bool IsLossless (void) const = 0;
69 : :
70 : : protected:
71 : 126 : ~BitmapCompressor() {}
72 : : };
73 : :
74 : :
75 : :
76 : : /** Interface for preview bitmap replacements. Each bitmap
77 : : compressor/decompressor has to provide an implementation that is
78 : : suitable to store the compressed bitmaps.
79 : : */
80 : 0 : class BitmapReplacement
81 : : {
82 : : public:
83 : 0 : virtual sal_Int32 GetMemorySize (void) const { return 0; }
84 : :
85 : : protected:
86 : 0 : ~BitmapReplacement() {}
87 : : };
88 : :
89 : :
90 : :
91 : :
92 : : /** This is one trivial bitmap compressor. It stores bitmaps unmodified
93 : : instead of compressing them.
94 : : This compressor is lossless.
95 : : */
96 : 0 : class NoBitmapCompression
97 : : : public BitmapCompressor
98 : : {
99 : : class DummyReplacement;
100 : : public:
101 [ # # ]: 0 : virtual ~NoBitmapCompression() {}
102 : : virtual ::boost::shared_ptr<BitmapReplacement> Compress (const Bitmap& rpBitmap) const;
103 : : virtual Bitmap Decompress (const BitmapReplacement& rBitmapData) const;
104 : : virtual bool IsLossless (void) const;
105 : : };
106 : :
107 : :
108 : :
109 : :
110 : : /** This is another trivial bitmap compressor. Instead of compressing a
111 : : bitmap, it throws the bitmap away. Its Decompress() method returns a
112 : : NULL pointer. The caller has to create a new preview bitmap instead.
113 : : This compressor clearly is not lossless.
114 : : */
115 : 0 : class CompressionByDeletion
116 : : : public BitmapCompressor
117 : : {
118 : : public:
119 [ # # ]: 0 : virtual ~CompressionByDeletion() {}
120 : : virtual ::boost::shared_ptr<BitmapReplacement> Compress (const Bitmap& rBitmap) const;
121 : : virtual Bitmap Decompress (const BitmapReplacement& rBitmapData) const;
122 : : virtual bool IsLossless (void) const;
123 : : };
124 : :
125 : :
126 : :
127 : :
128 : : /** Compress a preview bitmap by reducing its resolution. While the aspect
129 : : ratio is maintained the horizontal resolution is scaled down to 100
130 : : pixels.
131 : : This compressor is not lossless.
132 : : */
133 : 0 : class ResolutionReduction
134 : : : public BitmapCompressor
135 : : {
136 : : class ResolutionReducedReplacement;
137 : : static const sal_Int32 mnWidth = 100;
138 : : public:
139 [ # # ]: 0 : virtual ~ResolutionReduction() {}
140 : : virtual ::boost::shared_ptr<BitmapReplacement> Compress (const Bitmap& rpBitmap) const;
141 : : /** Scale the replacement bitmap up to the original size.
142 : : */
143 : : virtual Bitmap Decompress (const BitmapReplacement& rBitmapData) const;
144 : : virtual bool IsLossless (void) const;
145 : : };
146 : :
147 : :
148 : :
149 : :
150 : : /** Compress preview bitmaps using the PNG format.
151 : : This compressor is lossless.
152 : : */
153 : 126 : class PngCompression
154 : : : public BitmapCompressor
155 : : {
156 : : class PngReplacement;
157 : : public:
158 [ - + ]: 252 : virtual ~PngCompression() {}
159 : : virtual ::boost::shared_ptr<BitmapReplacement> Compress (const Bitmap& rBitmap) const;
160 : : virtual Bitmap Decompress (const BitmapReplacement& rBitmapData) const;
161 : : virtual bool IsLossless (void) const;
162 : : };
163 : :
164 : :
165 : : } } } // end of namespace ::sd::slidesorter::cache
166 : :
167 : : #endif
168 : :
169 : : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|