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 _SVIMBASE_HXX 25 #define _SVIMBASE_HXX 26 27 #include <vcl/bitmap.hxx> 28 #include <vcl/salbtype.hxx> 29 30 31 // ----------- 32 // - Defines - 33 // ----------- 34 35 #define _SVHUGE 36 37 // ---------------- 38 // - SimDepthType - 39 // ---------------- 40 41 enum SimDepthType 42 { 43 SIM_DEPTH_1, 44 SIM_DEPTH_4, 45 SIM_DEPTH_8, 46 SIM_DEPTH_24 47 }; 48 49 // ------------ 50 // - SimColor - 51 // ------------ 52 53 struct SimColor 54 { 55 sal_uInt8 cBlue; 56 sal_uInt8 cGreen; 57 sal_uInt8 cRed; 58 }; 59 60 // ------------------------------------------------------------------------ 61 62 inline sal_Bool operator==( const SimColor& rCol1, const SimColor& rCol2 ) 63 { 64 return ( ( rCol1.cRed == rCol2.cRed ) && 65 ( rCol1.cGreen == rCol2.cGreen ) && 66 ( rCol1.cBlue == rCol2.cBlue ) ); 67 } 68 69 // -------------- 70 // - SimPalette - 71 // -------------- 72 73 struct SimPalette 74 { 75 sal_uIntPtr nColors; 76 SimColor aColorArray[ 256 ]; 77 }; 78 79 // --------------- 80 // - SvImageBase - 81 // --------------- 82 83 class SfxViewFrame; 84 class SfxProgress; 85 86 class SvImageBase 87 { 88 private: 89 90 Bitmap aOutBitmap; 91 HPBYTE pArray1; 92 HPBYTE pArray2; 93 HPBYTE pArray3; 94 HPBYTE pArray4; 95 HPBYTE pOrgArray; 96 HPBYTE pDestArray; 97 SimPalette* pPal1; 98 SimPalette* pPal2; 99 SimPalette* pPal3; 100 SimPalette* pPal4; 101 sal_uIntPtr nWidth1; 102 sal_uIntPtr nWidth2; 103 sal_uIntPtr nWidth3; 104 sal_uIntPtr nWidth4; 105 sal_uIntPtr nHeight1; 106 sal_uIntPtr nHeight2; 107 sal_uIntPtr nHeight3; 108 sal_uIntPtr nHeight4; 109 sal_uIntPtr nAlignedWidth1; 110 sal_uIntPtr nAlignedWidth2; 111 sal_uIntPtr nAlignedWidth3; 112 sal_uIntPtr nAlignedWidth4; 113 sal_uIntPtr nWhichOrg; 114 SimDepthType eOrgDepth; 115 SimDepthType eUndoDepth; 116 SimDepthType eRedoDepth; 117 sal_Bool bIsUndo; 118 sal_Bool bIsRedo; 119 sal_Bool bCreateUndo; 120 sal_Bool bValid; 121 sal_Bool bDitherAll; 122 123 HPBYTE BitmapToArray24( const Bitmap& rBitmap, sal_uIntPtr* pWidth, 124 sal_uIntPtr* pHeight, sal_uIntPtr* pAlignedWidth, 125 SfxViewFrame *pFrame = NULL ); 126 sal_Bool Array24ToBitmap( HPBYTE pArray, Bitmap &rBitmap, 127 const sal_uIntPtr nWidth, const sal_uIntPtr nHeight, 128 const sal_uIntPtr nColorCount = 256, 129 sal_uIntPtr nLast = 0, SfxProgress* pProgress = NULL ); 130 131 Bitmap CreateSaveBitmap( const SimDepthType eDepth, SfxViewFrame *pFrame = NULL ); 132 133 HPBYTE CreateArray24( sal_uIntPtr nWidth, sal_uIntPtr nHeight ); 134 void DeleteArray( HPBYTE pArray ); 135 136 SvImageBase(const SvImageBase& rSvImageBase); 137 const SvImageBase& operator=(const SvImageBase& rSvImageBase); 138 139 public: 140 141 SvImageBase(); 142 SvImageBase( const Bitmap& rBitmap, 143 const sal_uIntPtr nColorCount = 256, 144 sal_uIntPtr nLast = 0, SfxProgress* pProgress = NULL ); 145 ~SvImageBase(); 146 147 sal_Bool IsValid() { return bValid; } 148 149 sal_uIntPtr GetOrgWidth() const { return nWhichOrg == 1 ? nWidth1 : nWidth2; } 150 sal_uIntPtr GetDestWidth() const { return nWhichOrg == 1 ? nWidth2 : nWidth1; } 151 152 sal_uIntPtr GetOrgHeight() const { return nWhichOrg == 1 ? nHeight1 : nHeight2; } 153 sal_uIntPtr GetDestHeight() const { return nWhichOrg == 1 ? nHeight2 : nHeight1; } 154 155 sal_uIntPtr GetOrgAlignedWidth() const { return nWhichOrg == 1 ? nAlignedWidth1 : nAlignedWidth2; } 156 sal_uIntPtr GetDestAlignedWidth() const { return nWhichOrg == 1 ? nAlignedWidth2 : nAlignedWidth1; } 157 158 sal_uIntPtr GetOrgAlignedSize() const { return GetOrgAlignedWidth() * GetOrgHeight(); } 159 sal_uIntPtr GetDestAlignedSize() const { return GetDestAlignedWidth() * GetDestHeight(); } 160 161 // Farbtiefe des Ausgangsbildes ermitteln und setzen 162 SimDepthType GetDepth() const { return eOrgDepth; } 163 void SetDepth( const SimDepthType eDepth ) { eOrgDepth = eDepth; } 164 165 // Farbtiefen nach Undo und Redo ermitteln und setzen 166 SimDepthType GetUndoDepth() const { return eUndoDepth; } 167 void SetUndoDepth(const SimDepthType eDepth) { eUndoDepth = eDepth; } 168 169 SimDepthType GetRedoDepth() const { return eRedoDepth; } 170 void SetRedoDepth(const SimDepthType eDepth) { eRedoDepth = eDepth; } 171 172 // Vor- und Ruecklauf der Bildverarbeitung 173 sal_Bool BeginProcessing( sal_Bool bUndo = sal_True ); 174 void EndProcessing(); 175 176 sal_Bool BeginProcessingExt(sal_uIntPtr nWidth, sal_uIntPtr nHeight, sal_Bool bUndo = sal_True); 177 void EndProcessingExt() { EndProcessing(); } 178 179 // Zeiger auf Arrays zur Verfuegung stellen 180 HPBYTE GetOrgPointer() { return pOrgArray; } 181 HPBYTE GetDestPointer() { return pDestArray; } 182 183 // DIB-Erzeugung fuer Anzeige 184 sal_Bool CreateOutBitmap( const sal_uIntPtr nColorCount = 256, sal_uIntPtr nLast = 0, 185 SfxProgress* pProgress = NULL ); 186 187 // Undo-Verwaltung 188 sal_Bool DoUndo( SfxProgress* pProgress = NULL ); 189 sal_Bool DoRedo( SfxProgress* pProgress = NULL ); 190 191 // DIB-Rueckgabe fuer Anzeige 192 const Bitmap& GetOutBitmap() const; 193 194 // DIB-Rueckgabe fuer Speicherung 195 Bitmap GetSaveBitmap(); 196 197 // Palette besorgen 198 SimPalette* GetOrgPalette() const { return nWhichOrg == 1 ? pPal1 : pPal2; } 199 SimPalette* GetDestPalette() const { return nWhichOrg == 1 ? pPal2 : pPal1; } 200 }; 201 202 // ---------------- 203 // - DitherBitmap - 204 // ---------------- 205 206 sal_Bool DitherBitmap( Bitmap& rBitmap, sal_Bool bDitherAlways = sal_False ); 207 208 #endif // _SVIMBASE_HXX 209