1*3334a7e6SAndrew Rist /**************************************************************
2cdf0e10cSrcweir *
3*3334a7e6SAndrew Rist * Licensed to the Apache Software Foundation (ASF) under one
4*3334a7e6SAndrew Rist * or more contributor license agreements. See the NOTICE file
5*3334a7e6SAndrew Rist * distributed with this work for additional information
6*3334a7e6SAndrew Rist * regarding copyright ownership. The ASF licenses this file
7*3334a7e6SAndrew Rist * to you under the Apache License, Version 2.0 (the
8*3334a7e6SAndrew Rist * "License"); you may not use this file except in compliance
9*3334a7e6SAndrew Rist * with the License. You may obtain a copy of the License at
10*3334a7e6SAndrew Rist *
11*3334a7e6SAndrew Rist * http://www.apache.org/licenses/LICENSE-2.0
12*3334a7e6SAndrew Rist *
13*3334a7e6SAndrew Rist * Unless required by applicable law or agreed to in writing,
14*3334a7e6SAndrew Rist * software distributed under the License is distributed on an
15*3334a7e6SAndrew Rist * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16*3334a7e6SAndrew Rist * KIND, either express or implied. See the License for the
17*3334a7e6SAndrew Rist * specific language governing permissions and limitations
18*3334a7e6SAndrew Rist * under the License.
19*3334a7e6SAndrew Rist *
20*3334a7e6SAndrew Rist *************************************************************/
21*3334a7e6SAndrew Rist
22*3334a7e6SAndrew Rist
23cdf0e10cSrcweir
24cdf0e10cSrcweir #ifndef _SVIMBASE_HXX
25cdf0e10cSrcweir #define _SVIMBASE_HXX
26cdf0e10cSrcweir
27cdf0e10cSrcweir #include <vcl/bitmap.hxx>
28cdf0e10cSrcweir #include <vcl/salbtype.hxx>
29cdf0e10cSrcweir
30cdf0e10cSrcweir
31cdf0e10cSrcweir // -----------
32cdf0e10cSrcweir // - Defines -
33cdf0e10cSrcweir // -----------
34cdf0e10cSrcweir
35cdf0e10cSrcweir #define _SVHUGE
36cdf0e10cSrcweir
37cdf0e10cSrcweir // ----------------
38cdf0e10cSrcweir // - SimDepthType -
39cdf0e10cSrcweir // ----------------
40cdf0e10cSrcweir
41cdf0e10cSrcweir enum SimDepthType
42cdf0e10cSrcweir {
43cdf0e10cSrcweir SIM_DEPTH_1,
44cdf0e10cSrcweir SIM_DEPTH_4,
45cdf0e10cSrcweir SIM_DEPTH_8,
46cdf0e10cSrcweir SIM_DEPTH_24
47cdf0e10cSrcweir };
48cdf0e10cSrcweir
49cdf0e10cSrcweir // ------------
50cdf0e10cSrcweir // - SimColor -
51cdf0e10cSrcweir // ------------
52cdf0e10cSrcweir
53cdf0e10cSrcweir struct SimColor
54cdf0e10cSrcweir {
55cdf0e10cSrcweir sal_uInt8 cBlue;
56cdf0e10cSrcweir sal_uInt8 cGreen;
57cdf0e10cSrcweir sal_uInt8 cRed;
58cdf0e10cSrcweir };
59cdf0e10cSrcweir
60cdf0e10cSrcweir // ------------------------------------------------------------------------
61cdf0e10cSrcweir
operator ==(const SimColor & rCol1,const SimColor & rCol2)62cdf0e10cSrcweir inline sal_Bool operator==( const SimColor& rCol1, const SimColor& rCol2 )
63cdf0e10cSrcweir {
64cdf0e10cSrcweir return ( ( rCol1.cRed == rCol2.cRed ) &&
65cdf0e10cSrcweir ( rCol1.cGreen == rCol2.cGreen ) &&
66cdf0e10cSrcweir ( rCol1.cBlue == rCol2.cBlue ) );
67cdf0e10cSrcweir }
68cdf0e10cSrcweir
69cdf0e10cSrcweir // --------------
70cdf0e10cSrcweir // - SimPalette -
71cdf0e10cSrcweir // --------------
72cdf0e10cSrcweir
73cdf0e10cSrcweir struct SimPalette
74cdf0e10cSrcweir {
75cdf0e10cSrcweir sal_uIntPtr nColors;
76cdf0e10cSrcweir SimColor aColorArray[ 256 ];
77cdf0e10cSrcweir };
78cdf0e10cSrcweir
79cdf0e10cSrcweir // ---------------
80cdf0e10cSrcweir // - SvImageBase -
81cdf0e10cSrcweir // ---------------
82cdf0e10cSrcweir
83cdf0e10cSrcweir class SfxViewFrame;
84cdf0e10cSrcweir class SfxProgress;
85cdf0e10cSrcweir
86cdf0e10cSrcweir class SvImageBase
87cdf0e10cSrcweir {
88cdf0e10cSrcweir private:
89cdf0e10cSrcweir
90cdf0e10cSrcweir Bitmap aOutBitmap;
91cdf0e10cSrcweir HPBYTE pArray1;
92cdf0e10cSrcweir HPBYTE pArray2;
93cdf0e10cSrcweir HPBYTE pArray3;
94cdf0e10cSrcweir HPBYTE pArray4;
95cdf0e10cSrcweir HPBYTE pOrgArray;
96cdf0e10cSrcweir HPBYTE pDestArray;
97cdf0e10cSrcweir SimPalette* pPal1;
98cdf0e10cSrcweir SimPalette* pPal2;
99cdf0e10cSrcweir SimPalette* pPal3;
100cdf0e10cSrcweir SimPalette* pPal4;
101cdf0e10cSrcweir sal_uIntPtr nWidth1;
102cdf0e10cSrcweir sal_uIntPtr nWidth2;
103cdf0e10cSrcweir sal_uIntPtr nWidth3;
104cdf0e10cSrcweir sal_uIntPtr nWidth4;
105cdf0e10cSrcweir sal_uIntPtr nHeight1;
106cdf0e10cSrcweir sal_uIntPtr nHeight2;
107cdf0e10cSrcweir sal_uIntPtr nHeight3;
108cdf0e10cSrcweir sal_uIntPtr nHeight4;
109cdf0e10cSrcweir sal_uIntPtr nAlignedWidth1;
110cdf0e10cSrcweir sal_uIntPtr nAlignedWidth2;
111cdf0e10cSrcweir sal_uIntPtr nAlignedWidth3;
112cdf0e10cSrcweir sal_uIntPtr nAlignedWidth4;
113cdf0e10cSrcweir sal_uIntPtr nWhichOrg;
114cdf0e10cSrcweir SimDepthType eOrgDepth;
115cdf0e10cSrcweir SimDepthType eUndoDepth;
116cdf0e10cSrcweir SimDepthType eRedoDepth;
117cdf0e10cSrcweir sal_Bool bIsUndo;
118cdf0e10cSrcweir sal_Bool bIsRedo;
119cdf0e10cSrcweir sal_Bool bCreateUndo;
120cdf0e10cSrcweir sal_Bool bValid;
121cdf0e10cSrcweir sal_Bool bDitherAll;
122cdf0e10cSrcweir
123cdf0e10cSrcweir HPBYTE BitmapToArray24( const Bitmap& rBitmap, sal_uIntPtr* pWidth,
124cdf0e10cSrcweir sal_uIntPtr* pHeight, sal_uIntPtr* pAlignedWidth,
125cdf0e10cSrcweir SfxViewFrame *pFrame = NULL );
126cdf0e10cSrcweir sal_Bool Array24ToBitmap( HPBYTE pArray, Bitmap &rBitmap,
127cdf0e10cSrcweir const sal_uIntPtr nWidth, const sal_uIntPtr nHeight,
128cdf0e10cSrcweir const sal_uIntPtr nColorCount = 256,
129cdf0e10cSrcweir sal_uIntPtr nLast = 0, SfxProgress* pProgress = NULL );
130cdf0e10cSrcweir
131cdf0e10cSrcweir Bitmap CreateSaveBitmap( const SimDepthType eDepth, SfxViewFrame *pFrame = NULL );
132cdf0e10cSrcweir
133cdf0e10cSrcweir HPBYTE CreateArray24( sal_uIntPtr nWidth, sal_uIntPtr nHeight );
134cdf0e10cSrcweir void DeleteArray( HPBYTE pArray );
135cdf0e10cSrcweir
136cdf0e10cSrcweir SvImageBase(const SvImageBase& rSvImageBase);
137cdf0e10cSrcweir const SvImageBase& operator=(const SvImageBase& rSvImageBase);
138cdf0e10cSrcweir
139cdf0e10cSrcweir public:
140cdf0e10cSrcweir
141cdf0e10cSrcweir SvImageBase();
142cdf0e10cSrcweir SvImageBase( const Bitmap& rBitmap,
143cdf0e10cSrcweir const sal_uIntPtr nColorCount = 256,
144cdf0e10cSrcweir sal_uIntPtr nLast = 0, SfxProgress* pProgress = NULL );
145cdf0e10cSrcweir ~SvImageBase();
146cdf0e10cSrcweir
IsValid()147cdf0e10cSrcweir sal_Bool IsValid() { return bValid; }
148cdf0e10cSrcweir
GetOrgWidth() const149cdf0e10cSrcweir sal_uIntPtr GetOrgWidth() const { return nWhichOrg == 1 ? nWidth1 : nWidth2; }
GetDestWidth() const150cdf0e10cSrcweir sal_uIntPtr GetDestWidth() const { return nWhichOrg == 1 ? nWidth2 : nWidth1; }
151cdf0e10cSrcweir
GetOrgHeight() const152cdf0e10cSrcweir sal_uIntPtr GetOrgHeight() const { return nWhichOrg == 1 ? nHeight1 : nHeight2; }
GetDestHeight() const153cdf0e10cSrcweir sal_uIntPtr GetDestHeight() const { return nWhichOrg == 1 ? nHeight2 : nHeight1; }
154cdf0e10cSrcweir
GetOrgAlignedWidth() const155cdf0e10cSrcweir sal_uIntPtr GetOrgAlignedWidth() const { return nWhichOrg == 1 ? nAlignedWidth1 : nAlignedWidth2; }
GetDestAlignedWidth() const156cdf0e10cSrcweir sal_uIntPtr GetDestAlignedWidth() const { return nWhichOrg == 1 ? nAlignedWidth2 : nAlignedWidth1; }
157cdf0e10cSrcweir
GetOrgAlignedSize() const158cdf0e10cSrcweir sal_uIntPtr GetOrgAlignedSize() const { return GetOrgAlignedWidth() * GetOrgHeight(); }
GetDestAlignedSize() const159cdf0e10cSrcweir sal_uIntPtr GetDestAlignedSize() const { return GetDestAlignedWidth() * GetDestHeight(); }
160cdf0e10cSrcweir
161cdf0e10cSrcweir // Farbtiefe des Ausgangsbildes ermitteln und setzen
GetDepth() const162cdf0e10cSrcweir SimDepthType GetDepth() const { return eOrgDepth; }
SetDepth(const SimDepthType eDepth)163cdf0e10cSrcweir void SetDepth( const SimDepthType eDepth ) { eOrgDepth = eDepth; }
164cdf0e10cSrcweir
165cdf0e10cSrcweir // Farbtiefen nach Undo und Redo ermitteln und setzen
GetUndoDepth() const166cdf0e10cSrcweir SimDepthType GetUndoDepth() const { return eUndoDepth; }
SetUndoDepth(const SimDepthType eDepth)167cdf0e10cSrcweir void SetUndoDepth(const SimDepthType eDepth) { eUndoDepth = eDepth; }
168cdf0e10cSrcweir
GetRedoDepth() const169cdf0e10cSrcweir SimDepthType GetRedoDepth() const { return eRedoDepth; }
SetRedoDepth(const SimDepthType eDepth)170cdf0e10cSrcweir void SetRedoDepth(const SimDepthType eDepth) { eRedoDepth = eDepth; }
171cdf0e10cSrcweir
172cdf0e10cSrcweir // Vor- und Ruecklauf der Bildverarbeitung
173cdf0e10cSrcweir sal_Bool BeginProcessing( sal_Bool bUndo = sal_True );
174cdf0e10cSrcweir void EndProcessing();
175cdf0e10cSrcweir
176cdf0e10cSrcweir sal_Bool BeginProcessingExt(sal_uIntPtr nWidth, sal_uIntPtr nHeight, sal_Bool bUndo = sal_True);
EndProcessingExt()177cdf0e10cSrcweir void EndProcessingExt() { EndProcessing(); }
178cdf0e10cSrcweir
179cdf0e10cSrcweir // Zeiger auf Arrays zur Verfuegung stellen
GetOrgPointer()180cdf0e10cSrcweir HPBYTE GetOrgPointer() { return pOrgArray; }
GetDestPointer()181cdf0e10cSrcweir HPBYTE GetDestPointer() { return pDestArray; }
182cdf0e10cSrcweir
183cdf0e10cSrcweir // DIB-Erzeugung fuer Anzeige
184cdf0e10cSrcweir sal_Bool CreateOutBitmap( const sal_uIntPtr nColorCount = 256, sal_uIntPtr nLast = 0,
185cdf0e10cSrcweir SfxProgress* pProgress = NULL );
186cdf0e10cSrcweir
187cdf0e10cSrcweir // Undo-Verwaltung
188cdf0e10cSrcweir sal_Bool DoUndo( SfxProgress* pProgress = NULL );
189cdf0e10cSrcweir sal_Bool DoRedo( SfxProgress* pProgress = NULL );
190cdf0e10cSrcweir
191cdf0e10cSrcweir // DIB-Rueckgabe fuer Anzeige
192cdf0e10cSrcweir const Bitmap& GetOutBitmap() const;
193cdf0e10cSrcweir
194cdf0e10cSrcweir // DIB-Rueckgabe fuer Speicherung
195cdf0e10cSrcweir Bitmap GetSaveBitmap();
196cdf0e10cSrcweir
197cdf0e10cSrcweir // Palette besorgen
GetOrgPalette() const198cdf0e10cSrcweir SimPalette* GetOrgPalette() const { return nWhichOrg == 1 ? pPal1 : pPal2; }
GetDestPalette() const199cdf0e10cSrcweir SimPalette* GetDestPalette() const { return nWhichOrg == 1 ? pPal2 : pPal1; }
200cdf0e10cSrcweir };
201cdf0e10cSrcweir
202cdf0e10cSrcweir // ----------------
203cdf0e10cSrcweir // - DitherBitmap -
204cdf0e10cSrcweir // ----------------
205cdf0e10cSrcweir
206cdf0e10cSrcweir sal_Bool DitherBitmap( Bitmap& rBitmap, sal_Bool bDitherAlways = sal_False );
207cdf0e10cSrcweir
208cdf0e10cSrcweir #endif // _SVIMBASE_HXX
209