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