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 .
22 #include <sal/types.h>
27 namespace sd::slidesorter::cache
29 class BitmapReplacement
;
31 /** This interface class provides the minimal method set for classes that
32 implement the compression and decompression of preview bitmaps.
34 class BitmapCompressor
37 /** Compress the given bitmap into a replacement format that is specific
38 to the compressor class.
40 virtual std::shared_ptr
<BitmapReplacement
> Compress(const BitmapEx
& rBitmap
) const = 0;
42 /** Decompress the given replacement data into a preview bitmap.
43 Depending on the compression technique the returned bitmap may
44 differ from the original bitmap given to the Compress() method. It
45 may even of the wrong size or empty or the NULL pointer. It is the
46 task of the caller to create a new preview bitmap if the returned
47 one is not as desired.
49 virtual BitmapEx
Decompress(const BitmapReplacement
& rBitmapData
) const = 0;
51 /** Return whether the compression and decompression is lossless. This
52 value is used by the caller of Decompress() to decide whether to use
53 the returned bitmap as is or if a new preview has to be created.
55 virtual bool IsLossless() const = 0;
58 ~BitmapCompressor() {}
61 /** Interface for preview bitmap replacements. Each bitmap
62 compressor/decompressor has to provide an implementation that is
63 suitable to store the compressed bitmaps.
65 class BitmapReplacement
68 virtual sal_Int32
GetMemorySize() const { return 0; }
71 ~BitmapReplacement() {}
74 /** This is one trivial bitmap compressor. It stores bitmaps unmodified
75 instead of compressing them.
76 This compressor is lossless.
78 class NoBitmapCompression
: public BitmapCompressor
80 class DummyReplacement
;
83 virtual ~NoBitmapCompression() {}
84 virtual std::shared_ptr
<BitmapReplacement
> Compress(const BitmapEx
& rpBitmap
) const override
;
85 virtual BitmapEx
Decompress(const BitmapReplacement
& rBitmapData
) const override
;
86 virtual bool IsLossless() const override
;
89 /** This is another trivial bitmap compressor. Instead of compressing a
90 bitmap, it throws the bitmap away. Its Decompress() method returns a
91 NULL pointer. The caller has to create a new preview bitmap instead.
92 This compressor clearly is not lossless.
94 class CompressionByDeletion
: public BitmapCompressor
97 virtual ~CompressionByDeletion() {}
98 virtual std::shared_ptr
<BitmapReplacement
> Compress(const BitmapEx
& rBitmap
) const override
;
99 virtual BitmapEx
Decompress(const BitmapReplacement
& rBitmapData
) const override
;
100 virtual bool IsLossless() const override
;
103 /** Compress a preview bitmap by reducing its resolution. While the aspect
104 ratio is maintained the horizontal resolution is scaled down to 100
106 This compressor is not lossless.
108 class ResolutionReduction
: public BitmapCompressor
110 class ResolutionReducedReplacement
;
111 static const sal_Int32 mnWidth
= 100;
114 virtual ~ResolutionReduction() {}
115 virtual std::shared_ptr
<BitmapReplacement
> Compress(const BitmapEx
& rpBitmap
) const override
;
116 /** Scale the replacement bitmap up to the original size.
118 virtual BitmapEx
Decompress(const BitmapReplacement
& rBitmapData
) const override
;
119 virtual bool IsLossless() const override
;
122 /** Compress preview bitmaps using the PNG format.
123 This compressor is lossless.
125 class PngCompression
: public BitmapCompressor
127 class PngReplacement
;
130 virtual ~PngCompression() {}
131 virtual std::shared_ptr
<BitmapReplacement
> Compress(const BitmapEx
& rBitmap
) const override
;
132 virtual BitmapEx
Decompress(const BitmapReplacement
& rBitmapData
) const override
;
133 virtual bool IsLossless() const override
;
136 } // end of namespace ::sd::slidesorter::cache
138 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */