diff options
author | Babak Mahbod <bmahbod@openoffice.org> | 2001-02-14 18:39:49 +0000 |
---|---|---|
committer | Babak Mahbod <bmahbod@openoffice.org> | 2001-02-14 18:39:49 +0000 |
commit | 54748f685cb30a7513fd4de67e710201217c4f72 (patch) | |
tree | dc6442f295a3e9c48bac36f1f65269564441aa0a | |
parent | 787f510823f9337dc012fe8671e3b41a599b5e8e (diff) |
Better colour handling.
New constants.
New API utility files.
Make files updated.
---------------------------------------------------------------------
-rwxr-xr-x | vcl/aqua/inc/salcolorutils.hxx | 147 | ||||
-rwxr-xr-x | vcl/aqua/inc/salconst.h | 102 | ||||
-rw-r--r-- | vcl/aqua/inc/salgdi.h | 30 | ||||
-rwxr-xr-x | vcl/aqua/inc/salmathutils.hxx | 103 | ||||
-rwxr-xr-x | vcl/aqua/inc/salpixmaputils.hxx | 99 | ||||
-rw-r--r-- | vcl/aqua/inc/salvd.h | 5 | ||||
-rw-r--r-- | vcl/aqua/source/gdi/makefile.mk | 34 | ||||
-rw-r--r-- | vcl/aqua/source/gdi/salbmp.cxx | 964 | ||||
-rwxr-xr-x | vcl/aqua/source/gdi/salcolorutils.cxx | 1014 | ||||
-rw-r--r-- | vcl/aqua/source/gdi/salgdi.cxx | 1017 | ||||
-rwxr-xr-x | vcl/aqua/source/gdi/salgdiutils.cxx | 552 | ||||
-rwxr-xr-x | vcl/aqua/source/gdi/salmathutils.cxx | 201 | ||||
-rwxr-xr-x | vcl/aqua/source/gdi/salpixmaputils.cxx | 621 | ||||
-rw-r--r-- | vcl/aqua/source/gdi/salvd.cxx | 26 |
14 files changed, 2989 insertions, 1926 deletions
diff --git a/vcl/aqua/inc/salcolorutils.hxx b/vcl/aqua/inc/salcolorutils.hxx new file mode 100755 index 000000000000..b2f659e5a7f6 --- /dev/null +++ b/vcl/aqua/inc/salcolorutils.hxx @@ -0,0 +1,147 @@ +/************************************************************************* + * + * $RCSfile: salcolorutils.hxx,v $ + * + * $Revision: 1.1 $ + * + * last change: $Author: bmahbod $ $Date: 2001-02-14 19:39:47 $ + * + * The Contents of this file are made available subject to the terms of + * either of the following licenses + * + * - GNU Lesser General Public License Version 2.1 + * - Sun Industry Standards Source License Version 1.1 + * + * Sun Microsystems Inc., October, 2000 + * + * GNU Lesser General Public License Version 2.1 + * ============================================= + * Copyright 2000 by Sun Microsystems, Inc. + * 901 San Antonio Road, Palo Alto, CA 94303, USA + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License version 2.1, as published by the Free Software Foundation. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, + * MA 02111-1307 USA + * + * + * Sun Industry Standards Source License Version 1.1 + * ================================================= + * The contents of this file are subject to the Sun Industry Standards + * Source License Version 1.1 (the "License"); You may not use this file + * except in compliance with the License. You may obtain a copy of the + * License at http://www.openoffice.org/license.html. + * + * Software provided under this License is provided on an "AS IS" basis, + * WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, + * WITHOUT LIMITATION, WARRANTIES THAT THE SOFTWARE IS FREE OF DEFECTS, + * MERCHANTABLE, FIT FOR A PARTICULAR PURPOSE, OR NON-INFRINGING. + * See the License for the specific provisions governing your rights and + * obligations concerning the Software. + * + * The Initial Developer of the Original Code is: Sun Microsystems, Inc. + * + * Copyright: 2000 by Sun Microsystems, Inc. + * + * All Rights Reserved. + * + * Contributor(s): _______________________________________ + * + * + ************************************************************************/ + +#ifndef _SV_SALCOLORUTILS_HXX +#define _SV_SALCOLORUTILS_HXX + +#include <premac.h> +#include <QD/QD.h> +#include <postmac.h> + +#ifndef _SV_SALBTYPE_HXX +#include <salbtype.hxx> +#endif + +#ifndef _SV_SALGTYPE_HXX +#include <salgtype.hxx> +#endif + +// ------------------------------------------------------------------ + +SalColor RGBColor2SALColor ( const RGBColor *pRGBColor ); + +SalColor RGB8BitColor2SALColor ( const RGBColor *pRGBColor ); + +SalColor RGB16BitColor2SALColor ( const RGBColor *pRGBColor ); + +SalColor RGB32BitColor2SALColor ( const RGBColor *pRGBColor ); + +// ------------------------------------------------------------------ + +RGBColor SALColor2RGBColor ( const SalColor nSalColor ); + +RGBColor SALColor2RGB32bitColor ( const SalColor nSalColor ); + +RGBColor SALColor2RGB18bitColor ( const SalColor nSalColor ); + +RGBColor SALColor2RGB8bitColor ( const SalColor nSalColor ); + +// ------------------------------------------------------------------ + +SalColor GetROPSalColor ( SalROPColor nROPColor ); + +// ------------------------------------------------------------------ + +RGBColor BitmapColor2RGBColor ( const BitmapColor &rBitmapColor ); + +void RGBColor2BitmapColor ( const RGBColor *rRGBColor, + BitmapColor &rBitmapColor + ); + +// ------------------------------------------------------------------ + +short GetMinColorCount ( const short nPixMapColorDepth, + const BitmapPalette &rBitmapPalette + ); + +// ------------------------------------------------------------------ + +void SetBlackForeColor ( ); + +void SetWhiteBackColor ( ); + +RGBColor GetBlackColor ( ); + +RGBColor GetWhiteColor ( ); + +// ------------------------------------------------------------------ + +CTabHandle CopyGDeviceCTab ( ); + +CTabHandle GetCTabFromStdCLUT ( const short nBitDepth ); + +CTabHandle CopyCTabIndexed ( CTabHandle hCTab ); + +CTabHandle CopyCTabRGBDirect ( CTabHandle hCTab ); + +// ------------------------------------------------------------------ + +CTabHandle CopyPixMapCTab ( PixMapHandle hPixMap ); + +// ------------------------------------------------------------------ + +void SetBitmapBufferColorFormat ( const PixMapHandle mhPixMap, + BitmapBuffer *rBuffer + ); + +// ------------------------------------------------------------------ + +#endif // _SV_SALCOLORUTILS_HXX diff --git a/vcl/aqua/inc/salconst.h b/vcl/aqua/inc/salconst.h new file mode 100755 index 000000000000..e66c54bdb2f7 --- /dev/null +++ b/vcl/aqua/inc/salconst.h @@ -0,0 +1,102 @@ +/************************************************************************* + * + * $RCSfile: salconst.h,v $ + * + * $Revision: 1.1 $ + * + * last change: $Author: bmahbod $ $Date: 2001-02-14 19:39:47 $ + * + * The Contents of this file are made available subject to the terms of + * either of the following licenses + * + * - GNU Lesser General Public License Version 2.1 + * - Sun Industry Standards Source License Version 1.1 + * + * Sun Microsystems Inc., October, 2000 + * + * GNU Lesser General Public License Version 2.1 + * ============================================= + * Copyright 2000 by Sun Microsystems, Inc. + * 901 San Antonio Road, Palo Alto, CA 94303, USA + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License version 2.1, as published by the Free Software Foundation. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, + * MA 02111-1307 USA + * + * + * Sun Industry Standards Source License Version 1.1 + * ================================================= + * The contents of this file are subject to the Sun Industry Standards + * Source License Version 1.1 (the "License"); You may not use this file + * except in compliance with the License. You may obtain a copy of the + * License at http://www.openoffice.org/license.html. + * + * Software provided under this License is provided on an "AS IS" basis, + * WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, + * WITHOUT LIMITATION, WARRANTIES THAT THE SOFTWARE IS FREE OF DEFECTS, + * MERCHANTABLE, FIT FOR A PARTICULAR PURPOSE, OR NON-INFRINGING. + * See the License for the specific provisions governing your rights and + * obligations concerning the Software. + * + * The Initial Developer of the Original Code is: Sun Microsystems, Inc. + * + * Copyright: 2000 by Sun Microsystems, Inc. + * + * All Rights Reserved. + * + * Contributor(s): _______________________________________ + * + * + ************************************************************************/ + +#ifndef _SV_SALCONST_H +#define _SV_SALCONST_H + +// ------------------- +// - Constants - +// ------------------- + +const unsigned short kByteMask = 0xFF; + +const unsigned short kOneByte = 8; +const unsigned short kTwoBytes = 16; + +const unsigned short kOneBit = 1; +const unsigned short kFiveBits = 5; +const unsigned short kEightBits = 8; +const unsigned short kTenBits = 10; +const unsigned short kElevenBits = 11; + +const unsigned short kBlackAndWhite = 1; +const unsigned short kFourBitColor = 4; +const unsigned short kEightBitColor = 8; +const unsigned short kThousandsColor = 16; +const unsigned short kTrueColor = 32; + +const unsigned long k16BitRedColorMask = 0x00007c00; +const unsigned long k16BitGreenColorMask = 0x000003e0; +const unsigned long k16BitBlueColorMask = 0x0000001f; + +const unsigned long k32BitRedColorMask = 0x00ff0000; +const unsigned long k32BitGreenColorMask = 0x0000ff00; +const unsigned long k32BitBlueColorMask = 0x000000ff; + +const unsigned short kPixMapCmpSizeOneBit = 1; +const unsigned short kPixMapCmpSizeFourBits = 4; +const unsigned short kPixMapCmpSizeFiveBits = 5; +const unsigned short kPixMapCmpSizeEightBits = 8; + +const long kPixMapHRes = 72; +const long kPixMapVRes = 72; + +#endif // _SV_SALCONST_H diff --git a/vcl/aqua/inc/salgdi.h b/vcl/aqua/inc/salgdi.h index c60554f190da..0ceb92ce254f 100644 --- a/vcl/aqua/inc/salgdi.h +++ b/vcl/aqua/inc/salgdi.h @@ -2,9 +2,9 @@ * * $RCSfile: salgdi.h,v $ * - * $Revision: 1.22 $ + * $Revision: 1.23 $ * - * last change: $Author: bmahbod $ $Date: 2001-02-08 00:12:20 $ + * last change: $Author: bmahbod $ $Date: 2001-02-14 19:39:47 $ * * The Contents of this file are made available subject to the terms of * either of the following licenses @@ -75,32 +75,6 @@ #endif // ------------------- -// - Constants - -// ------------------- - -const unsigned short kByteMask = 0xFF; - -const unsigned short kOneByte = 8; -const unsigned short kTwoBytes = 16; - -const unsigned short kPixMapCmpSizeOneBit = 1; -const unsigned short kPixMapCmpSizeFourBits = 4; -const unsigned short kPixMapCmpSizeFiveBits = 5; -const unsigned short kPixMapCmpSizeEightBits = 8; - -const unsigned short kOneBit = 1; -const unsigned short kFiveBits = 5; -const unsigned short kEightBits = 8; -const unsigned short kTenBits = 10; -const unsigned short kElevenBits = 11; - -const unsigned short kBlackAndWhite = 1; -const unsigned short kFourBitColor = 4; -const unsigned short kEightBitColor = 8; -const unsigned short kThousandsColor = 16; -const unsigned short kTrueColor = 32; - -// ------------------- // - Structures - // ------------------- diff --git a/vcl/aqua/inc/salmathutils.hxx b/vcl/aqua/inc/salmathutils.hxx new file mode 100755 index 000000000000..afced28878d0 --- /dev/null +++ b/vcl/aqua/inc/salmathutils.hxx @@ -0,0 +1,103 @@ +/************************************************************************* + * + * $RCSfile: salmathutils.hxx,v $ + * + * $Revision: 1.1 $ + * + * last change: $Author: bmahbod $ $Date: 2001-02-14 19:39:48 $ + * + * The Contents of this file are made available subject to the terms of + * either of the following licenses + * + * - GNU Lesser General Public License Version 2.1 + * - Sun Industry Standards Source License Version 1.1 + * + * Sun Microsystems Inc., October, 2000 + * + * GNU Lesser General Public License Version 2.1 + * ============================================= + * Copyright 2000 by Sun Microsystems, Inc. + * 901 San Antonio Road, Palo Alto, CA 94303, USA + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License version 2.1, as published by the Free Software Foundation. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, + * MA 02111-1307 USA + * + * + * Sun Industry Standards Source License Version 1.1 + * ================================================= + * The contents of this file are subject to the Sun Industry Standards + * Source License Version 1.1 (the "License"); You may not use this file + * except in compliance with the License. You may obtain a copy of the + * License at http://www.openoffice.org/license.html. + * + * Software provided under this License is provided on an "AS IS" basis, + * WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, + * WITHOUT LIMITATION, WARRANTIES THAT THE SOFTWARE IS FREE OF DEFECTS, + * MERCHANTABLE, FIT FOR A PARTICULAR PURPOSE, OR NON-INFRINGING. + * See the License for the specific provisions governing your rights and + * obligations concerning the Software. + * + * The Initial Developer of the Original Code is: Sun Microsystems, Inc. + * + * Copyright: 2000 by Sun Microsystems, Inc. + * + * All Rights Reserved. + * + * Contributor(s): _______________________________________ + * + * + ************************************************************************/ + +#ifndef _SV_SALMATHUTILS_HXX +#define _SV_SALMATHUTILS_HXX + +// -------------------- +// - Structures - +// -------------------- + +// LRectCoor is an abreviation for rectangular coordinates +// represented as long integers + +struct LRectCoor +{ + long x; + long y; + long z; +}; + +// -------------------- +// - Type Definitions - +// -------------------- + +// LRectCoorVec is an abreviation for vectors in rectangular +// coordinates represented as long integers + +typedef struct LRectCoor LRectCoor; +typedef LRectCoor *LRectCoorVector; +typedef LRectCoorVector *LRectCoorTensor; + +// -------------------- +// - Function Headers - +// -------------------- + +void CSwap ( char &rX, char &rY ); +void UCSwap ( unsigned char &rX, unsigned char &rY ); +void SSwap ( short &rX, short &rY ); +void USSwap ( unsigned short &rX, unsigned short &rY ); +void LSwap ( long &rX, long &rY ); +void ULSwap ( unsigned long &rX, unsigned long &rY ); + +unsigned long Euclidian2Norm ( const LRectCoorVector pVec ); + +#endif // _SV_SALMATHUTILS_HXX diff --git a/vcl/aqua/inc/salpixmaputils.hxx b/vcl/aqua/inc/salpixmaputils.hxx new file mode 100755 index 000000000000..bf3e97652460 --- /dev/null +++ b/vcl/aqua/inc/salpixmaputils.hxx @@ -0,0 +1,99 @@ +/************************************************************************* + * + * $RCSfile: salpixmaputils.hxx,v $ + * + * $Revision: 1.1 $ + * + * last change: $Author: bmahbod $ $Date: 2001-02-14 19:39:48 $ + * + * The Contents of this file are made available subject to the terms of + * either of the following licenses + * + * - GNU Lesser General Public License Version 2.1 + * - Sun Industry Standards Source License Version 1.1 + * + * Sun Microsystems Inc., October, 2000 + * + * GNU Lesser General Public License Version 2.1 + * ============================================= + * Copyright 2000 by Sun Microsystems, Inc. + * 901 San Antonio Road, Palo Alto, CA 94303, USA + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License version 2.1, as published by the Free Software Foundation. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, + * MA 02111-1307 USA + * + * + * Sun Industry Standards Source License Version 1.1 + * ================================================= + * The contents of this file are subject to the Sun Industry Standards + * Source License Version 1.1 (the "License"); You may not use this file + * except in compliance with the License. You may obtain a copy of the + * License at http://www.openoffice.org/license.html. + * + * Software provided under this License is provided on an "AS IS" basis, + * WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, + * WITHOUT LIMITATION, WARRANTIES THAT THE SOFTWARE IS FREE OF DEFECTS, + * MERCHANTABLE, FIT FOR A PARTICULAR PURPOSE, OR NON-INFRINGING. + * See the License for the specific provisions governing your rights and + * obligations concerning the Software. + * + * The Initial Developer of the Original Code is: Sun Microsystems, Inc. + * + * Copyright: 2000 by Sun Microsystems, Inc. + * + * All Rights Reserved. + * + * Contributor(s): _______________________________________ + * + * + ************************************************************************/ + +#ifndef _SV_SALPIXMAPUTILS_HXX +#define _SV_SALPIXMAPUTILS_HXX + +#include <premac.h> +#include <QD/QD.h> +#include <postmac.h> + +#ifndef _GEN_HXX +#include <tools/gen.hxx> +#endif + +#ifndef _SV_SALBTYPE_HXX +#include <salbtype.hxx> +#endif + +#ifndef _SV_SALGTYPE_HXX +#include <salgtype.hxx> +#endif + +// ------------------------------------------------------------------ + + +PixMapHandle GetNewPixMap ( const Size &rPixMapSize, + const USHORT nPixMapBits, + const BitmapPalette &rBitmapPalette + ); + +PixMapHandle CopyPixMap ( PixMapHandle hPixMap ); + +PixMapHandle GetCGrafPortPixMap ( const Size &rPixMapSize, + const USHORT nPixMapBits, + const BitmapPalette &rBitmapPalette, + const CGrafPtr pCGraf + ); + +// ------------------------------------------------------------------ + +#endif // _SV_SALPIXMAPUTILS_HXX diff --git a/vcl/aqua/inc/salvd.h b/vcl/aqua/inc/salvd.h index d2bc171e1177..c1349b90bbca 100644 --- a/vcl/aqua/inc/salvd.h +++ b/vcl/aqua/inc/salvd.h @@ -2,9 +2,9 @@ * * $RCSfile: salvd.h,v $ * - * $Revision: 1.6 $ + * $Revision: 1.7 $ * - * last change: $Author: bmahbod $ $Date: 2001-01-25 05:22:31 $ + * last change: $Author: bmahbod $ $Date: 2001-02-14 19:39:48 $ * * The Contents of this file are made available subject to the terms of * either of the following licenses @@ -65,6 +65,7 @@ #ifndef _SV_SV_H #include <sv.h> #endif + #ifndef _SV_SALGDI_HXX #include <salgdi.hxx> #endif diff --git a/vcl/aqua/source/gdi/makefile.mk b/vcl/aqua/source/gdi/makefile.mk index 877fcb7ff11e..4229de8798b3 100644 --- a/vcl/aqua/source/gdi/makefile.mk +++ b/vcl/aqua/source/gdi/makefile.mk @@ -2,9 +2,9 @@ # # $RCSfile: makefile.mk,v $ # -# $Revision: 1.4 $ +# $Revision: 1.5 $ # -# last change: $Author: pluby $ $Date: 2000-11-02 06:43:26 $ +# last change: $Author: bmahbod $ $Date: 2001-02-14 19:39:49 $ # # The Contents of this file are made available subject to the terms of # either of the following licenses @@ -81,19 +81,29 @@ dummy: .ELSE # "$(OS)"!="MACOSX" -SLOFILES= $(SLO)$/salgdi.obj \ - $(SLO)$/VCLGraphics.obj \ - $(SLO)$/salvd.obj \ - $(SLO)$/salprn.obj \ - $(SLO)$/salbmp.obj \ +SLOFILES= $(SLO)$/salmathutils.obj \ + $(SLO)$/salrectangleutils.obj \ + $(SLO)$/salcolorutils.obj \ + $(SLO)$/salpixmaputils.obj \ + $(SLO)$/salgdiutils.obj \ + $(SLO)$/salgdi.obj \ + $(SLO)$/VCLGraphics.obj \ + $(SLO)$/salvd.obj \ + $(SLO)$/salprn.obj \ + $(SLO)$/salbmp.obj \ $(SLO)$/salogl.obj .IF "$(UPDATER)"=="YES" -OBJFILES= $(OBJ)$/salgdi.obj \ - $(OBJ)$/VCLGraphics.obj \ - $(OBJ)$/salvd.obj \ - $(OBJ)$/salprn.obj \ - $(OBJ)$/salbmp.obj \ +OBJFILES= $(OBJ)$/salmathutils.obj \ + $(OBJ)$/salrectangleutils.obj \ + $(OBJ)$/salcolorutils.obj \ + $(OBJ)$/salpixmaputils.obj \ + $(OBJ)$/salgdiutils.obj \ + $(OBJ)$/salgdi.obj \ + $(OBJ)$/VCLGraphics.obj \ + $(OBJ)$/salvd.obj \ + $(OBJ)$/salprn.obj \ + $(OBJ)$/salbmp.obj \ $(OBJ)$/salogl.obj .ENDIF diff --git a/vcl/aqua/source/gdi/salbmp.cxx b/vcl/aqua/source/gdi/salbmp.cxx index c8dfffca2ffa..945f09b3c8d4 100644 --- a/vcl/aqua/source/gdi/salbmp.cxx +++ b/vcl/aqua/source/gdi/salbmp.cxx @@ -2,9 +2,9 @@ * * $RCSfile: salbmp.cxx,v $ * - * $Revision: 1.19 $ + * $Revision: 1.20 $ * - * last change: $Author: bmahbod $ $Date: 2001-02-08 00:12:20 $ + * last change: $Author: bmahbod $ $Date: 2001-02-14 19:39:49 $ * * The Contents of this file are made available subject to the terms of * either of the following licenses @@ -61,793 +61,45 @@ #define _SV_SALBMP_CXX +#ifndef _SV_SALCONST_H +#include <salconst.h> +#endif + #ifndef _SV_SALBMP_HXX #include <salbmp.hxx> #endif + #ifndef _SV_SALBTYPE_HXX #include <salbtype.hxx> #endif + #ifndef _SV_SALDATA_HXX #include <saldata.hxx> #endif + #ifndef _SV_SALINST_HXX #include <salinst.hxx> #endif + #ifndef _SV_SALVD_HXX #include <salvd.hxx> #endif -// ================================================================== - -static inline short GetMinColorCount( const short nPixMapColorDepth, - const BitmapPalette& rBitmapPalette - ) -{ - short nBitmapPaletteCount = rBitmapPalette.GetEntryCount(); - short nBitmapPaletteMinCount = 0; - - if ( nPixMapColorDepth < nBitmapPaletteCount ) - { - nBitmapPaletteMinCount = nPixMapColorDepth; - } // if - else - { - nBitmapPaletteMinCount = nBitmapPaletteCount; - } // else - - return nBitmapPaletteMinCount; -} // GetMinColorCount - -// ================================================================== - -// ================================================================== - -static inline long GetNewPixMapBitDepth( const USHORT nPixMapBits ) -{ - long nPixMapBitDepth = 0; - - if ( nPixMapBits <= kThousandsColor ) - { - nPixMapBitDepth = (long)nPixMapBits; - } // if - else - { - nPixMapBitDepth = kTrueColor; - } // else - - return nPixMapBitDepth; -} // GetNewPixMapDepth - -// ------------------------------------------------------------------ - -static inline long GetNewPixMapOffset( const long nPixMapBitDepth, - const short nPixMapWidth - ) -{ - long nPixMapImageWidth = nPixMapBitDepth * (long)nPixMapWidth; - long nPixMapOffset = ( ( nPixMapImageWidth + 15L ) >> 4L ) << 1L; - - return nPixMapOffset; -} // GetNewPixMapOffset - -// ------------------------------------------------------------------ - -static inline long GetNewPixMapImageSize ( const short nPixMapHeight, - const long nPixMapRowOffset - ) -{ - long nPixMapImageSize = (long)nPixMapHeight * nPixMapRowOffset; - - return nPixMapImageSize; -} // GetNewPixMapImageSize - -// ------------------------------------------------------------------ - -static inline short GetNewPixMapRowBytes( const long nPixMapRowOffset ) -{ - short nPixMapRowBytes = (short)nPixMapRowOffset + 0x8000; - - return nPixMapRowBytes; -} // GetNewPixMapRowBytes - -// ------------------------------------------------------------------ - -static inline short GetNewPixMapColorDepth( const USHORT nPixMapBits ) -{ - short nPixMapColorDepth = 0; - - if ( nPixMapBits <= 8 ) - { - nPixMapColorDepth = 1 << ((short)nPixMapBits); - } - - return nPixMapColorDepth; -} // GetNewPixMapColorDepth - -// ------------------------------------------------------------------ - -static void GetNewPixMapBoudsRect( const short nPixMapWidth, - const short nPixMapHeight, - Rect *rPixMapBoundsRect - ) -{ - short nPixMapRectLeft = 0; - short nPixMapRectTop = 0; - short nPixMapRectRight = nPixMapWidth; - short nPixMapRectBottom = nPixMapHeight; - - // Set the dimensions of the PixMap - - MacSetRect( rPixMapBoundsRect, - nPixMapRectLeft, - nPixMapRectTop, - nPixMapRectRight, - nPixMapRectBottom - ); -} // GetNewPixMapBoudsRect - -// ------------------------------------------------------------------ - -static inline short GetNewPixMapCmpSize( const long nPixMapBitDepth ) -{ - short nPixMapCmpSize = 0; - - if ( nPixMapBitDepth <= kEightBitColor ) - { - nPixMapCmpSize = nPixMapBitDepth; - } // if - else if ( nPixMapBitDepth == kThousandsColor ) - { - nPixMapCmpSize = 5; - } // else if - else - { - nPixMapCmpSize = 8; - } // else - - return nPixMapCmpSize; -} // GetNewPixMapCmpSize - -// ------------------------------------------------------------------ - -static inline short GetNewPixMapCmpCount( const long nPixMapBitDepth ) -{ - short nPixMapCmpCount = 0; - - if ( nPixMapBitDepth <= kEightBitColor ) - { - nPixMapCmpCount = 1; - } // if - else - { - nPixMapCmpCount = 3; - } // else - - return nPixMapCmpCount; -} // GetNewPixMapCmpCount - -// ------------------------------------------------------------------ - -static inline short GetNewPixMapPixelType( const long nPixMapBitDepth ) -{ - short nPixMapPixelType = 0; - - if ( nPixMapBitDepth <= kEightBitColor ) - { - nPixMapPixelType = 0; - } // if - else - { - nPixMapPixelType = RGBDirect; - } // else - - return nPixMapPixelType; -} // GetNewPixMapPixelType - -// ------------------------------------------------------------------ - -static inline OSType GetNewPixMapPixelFormat( ) -{ - OSType nPixMapPixelFormat = NULL; - GDPtr pGDevice = NULL; - - pGDevice = *GetGDevice( ); - - if ( pGDevice != NULL ) - { - PixMapPtr pPixMap = NULL; - - pPixMap = *(*pGDevice).gdPMap; - - if ( pPixMap != NULL ) - { - nPixMapPixelFormat = pPixMap->pixelFormat; - } // if - } // if - - return nPixMapPixelFormat; -} // GetNewPixMapPixelFormat - -// ------------------------------------------------------------------ - -static CTabHandle CopyGDeviceCTab( ) -{ - GDPtr pGDevice = NULL; - CTabHandle hCTable = NULL; - - pGDevice = *GetGDevice ( ); - - if ( pGDevice != NULL ) - { - PixMapPtr pPixMap = NULL; - - pPixMap = *(*pGDevice).gdPMap; - - if ( pPixMap != NULL ) - { - CTabPtr pCTable = NULL; - - pCTable = *(*pPixMap).pmTable; - - if ( pCTable != NULL ) - { - const short nCTableSize = pCTable->ctSize + 1; - long nCTableHandleSize = 0; - - nCTableHandleSize = ( nCTableSize - * sizeof( ColorSpec ) - ) - + ( sizeof( ColorTable ) - - sizeof( CSpecArray ) - ); - - hCTable = (CTabHandle) NewHandleClear( nCTableHandleSize ); - - if ( ( hCTable != NULL ) && ( *hCTable != NULL ) ) - { - SInt8 nFlags = noErr; - - nFlags = HGetState( (Handle)hCTable ); - - if ( nFlags == noErr ) - { - unsigned long nCTableIndex; - - HLock( (Handle)hCTable ); - - (**hCTable).ctSize = pCTable->ctSize; - (**hCTable).ctFlags = pCTable->ctFlags; - (**hCTable).ctSeed = GetCTSeed(); - - for ( nCTableIndex = 0; - nCTableIndex < nCTableSize; - nCTableIndex++ - ) - { - (**hCTable).ctTable[nCTableIndex] - = pCTable->ctTable[nCTableIndex]; - } // for - - HSetState( (Handle)hCTable, nFlags ); - } // if - } // if - } // if - } // if - } // if - - return hCTable; -} // CopyGDeviceCTab - -// ------------------------------------------------------------------ - -static CTabHandle GetNewPixMapCTabCLUT( const short nPixMapBitDepth ) -{ - CTabHandle hPixMapCTab = NULL; - short nPixMapCLUTID = 0; - - nPixMapCLUTID = nPixMapBitDepth + 64; - - hPixMapCTab = GetCTable( nPixMapCLUTID ); - - return hPixMapCTab; -} // GetNewPixMapCTabCLUT - -// ------------------------------------------------------------------ - -static CTabHandle GetNewPixMapCTabBitmapPalette( const short nPixMapColorDepth, - const BitmapPalette &rBitmapPalette - ) -{ - CTabHandle hPixMapCTab = NULL; - - hPixMapCTab = (CTabHandle) NewHandleClear( sizeof( ColorTable ) - + sizeof( ColorSpec ) - * ( nPixMapColorDepth - 1 ) - ); - - if ( ( hPixMapCTab != NULL ) && ( *hPixMapCTab != NULL ) ) - { - SInt8 nFlags = noErr; - - nFlags = HGetState( (Handle)hPixMapCTab ); - - if ( nFlags == noErr ) - { - short nBitmapPaletteMinCount = GetMinColorCount(nPixMapColorDepth, rBitmapPalette); - short nBitmapPaletteColorVal = 0; - short nBitmapPaletteIndex = 0; - - HLock( (Handle)hPixMapCTab ); - - (**hPixMapCTab).ctSeed = GetCTSeed(); - (**hPixMapCTab).ctFlags = 0; - (**hPixMapCTab).ctSize = nPixMapColorDepth - 1; - - for ( nBitmapPaletteIndex = 0; - nBitmapPaletteIndex < nBitmapPaletteMinCount; - nBitmapPaletteIndex++ - ) - { - const BitmapColor &rBitmapPaletteColor = rBitmapPalette[nBitmapPaletteIndex]; - - (**hPixMapCTab).ctTable[nBitmapPaletteIndex].value - = nBitmapPaletteIndex; - - nBitmapPaletteColorVal - = rBitmapPaletteColor.GetRed(); - - (**hPixMapCTab).ctTable[nBitmapPaletteIndex].rgb.red - = ( nBitmapPaletteColorVal << 8 ) | nBitmapPaletteColorVal; - - nBitmapPaletteColorVal - = rBitmapPaletteColor.GetGreen(); - - (**hPixMapCTab).ctTable[nBitmapPaletteIndex].rgb.green - = ( nBitmapPaletteColorVal << 8 ) | nBitmapPaletteColorVal ; - - nBitmapPaletteColorVal - = rBitmapPaletteColor.GetBlue(); - - (**hPixMapCTab).ctTable[nBitmapPaletteIndex].rgb.blue - = ( nBitmapPaletteColorVal << 8 ) | nBitmapPaletteColorVal; - } // for - - HSetState( (Handle)hPixMapCTab, nFlags ); - } // if - } // if - - return hPixMapCTab; -} // GetNewPixMapCTabBitmapPalette - -// ------------------------------------------------------------------ - -static CTabHandle GetNewPixMapCTabRGBDirect( const short nPixMapCmpSize ) -{ - CTabHandle hPixMapCTab = NULL; - - hPixMapCTab = (CTabHandle)NewHandleClear( sizeof( ColorTable ) - - sizeof( CSpecArray ) - ); - - if ( ( hPixMapCTab != NULL ) && ( *hPixMapCTab != NULL ) ) - { - SInt8 nFlags = noErr; - - nFlags = HGetState( (Handle)hPixMapCTab ); - - if ( nFlags == noErr ) - { - HLock( (Handle)hPixMapCTab ); - - (**hPixMapCTab).ctSeed = 3 * nPixMapCmpSize; - (**hPixMapCTab).ctFlags = 0; - (**hPixMapCTab).ctSize = 0; - - HSetState( (Handle)hPixMapCTab, nFlags ); - } // if - } // if - - return hPixMapCTab; -} // GetNewPixMapCTabRGBDirect - -// ------------------------------------------------------------------ - -static CTabHandle GetNewPixMapCTab( const long nPixMapBitDepth, - const short nPixMapColorDepth, - const short nPixMapCmpSize, - const BitmapPalette &rBitmapPalette - ) -{ - CTabHandle hPixMapCTab = NULL; - - if ( nPixMapBitDepth <= kEightBitColor ) - { - hPixMapCTab = GetNewPixMapCTabBitmapPalette( nPixMapColorDepth, - rBitmapPalette - ); - - if ( hPixMapCTab == NULL ) - { - hPixMapCTab = GetNewPixMapCTabCLUT( nPixMapBitDepth ); - - if ( hPixMapCTab == NULL ) - { - hPixMapCTab = CopyGDeviceCTab( ); - } // if - } // if - } // if - else - { - hPixMapCTab = GetNewPixMapCTabRGBDirect( nPixMapCmpSize ); - } // else - - return hPixMapCTab; -} // GetNewPixMapCTab - -// ------------------------------------------------------------------ - -static PixMapHandle GetNewPixMap ( const Size &rPixMapSize, - const USHORT nPixMapBits, - const BitmapPalette &rBitmapPalette, - const SalGraphics *rSalGraphics - ) -{ - PixMapHandle hPixMap = NULL; - short nPixMapWidth = rPixMapSize.Width(); - short nPixMapHeight = rPixMapSize.Height(); - - if ( ( nPixMapWidth > 0 ) && ( nPixMapHeight > 0 ) ) - { - hPixMap = NewPixMap(); - - if ( ( hPixMap != NULL ) && ( *hPixMap != NULL ) ) - { - const long nPixMapBitDepth = GetNewPixMapBitDepth( nPixMapBits); - const long nPixMapRowOffset = GetNewPixMapOffset( nPixMapBitDepth, nPixMapWidth ); - const long nPixMapImageSize = GetNewPixMapImageSize( nPixMapHeight, nPixMapRowOffset ); - Ptr pPixMapData = NewPtrClear( nPixMapImageSize ); - - if ( pPixMapData != NULL ) - { - GWorldFlags nPixMapFlags = noErr; - - nPixMapFlags = GetPixelsState( hPixMap ); - - if ( nPixMapFlags == noErr ) - { - if ( LockPixels( hPixMap ) ) - { - const short nPixMapRowBytes = GetNewPixMapRowBytes( nPixMapRowOffset ); - const short nPixMapColorDepth = GetNewPixMapColorDepth( nPixMapBits ); - const short nPixMapCmpSize = GetNewPixMapCmpSize( nPixMapBitDepth ); - const short nPixMapCmpCount = GetNewPixMapCmpCount( nPixMapBitDepth ); - const short nPixMapPixelType = GetNewPixMapPixelType( nPixMapBitDepth ); - const OSType aPixMapPixelFormat = GetNewPixMapPixelFormat( ); - Rect aPixMapBoundsRect; - - GetNewPixMapBoudsRect( nPixMapWidth, nPixMapHeight, &aPixMapBoundsRect ); - - (**hPixMap).baseAddr = pPixMapData; // Pointer to pixels - (**hPixMap).rowBytes = nPixMapRowBytes; // Offset to next line - (**hPixMap).bounds = aPixMapBoundsRect; // Bounding bitmap rectangle - (**hPixMap).pmVersion = 0; // PixMap version number - (**hPixMap).packType = 0; // Defines packing format - (**hPixMap).packSize = 0; // Length of pixel data - (**hPixMap).hRes = 0x00480000; // Horizontal resolution (ppi) - (**hPixMap).vRes = 0x00480000; // Vertical resolution (ppi) - (**hPixMap).pixelType = nPixMapPixelType; // Defines pixel type - (**hPixMap).pixelSize = nPixMapBitDepth; // Number of bits in a pixel - (**hPixMap).cmpCount = nPixMapCmpCount; // Number of components in a pixel - (**hPixMap).cmpSize = nPixMapCmpSize; // Number of bits per component - (**hPixMap).pixelFormat = aPixMapPixelFormat; // Four character code representation - (**hPixMap).pmExt = NULL; // Handle to PixMap extension - - // Get the color table based on the desired screen depth - - (**hPixMap).pmTable = GetNewPixMapCTab( nPixMapBitDepth, - nPixMapColorDepth, - nPixMapCmpSize, - rBitmapPalette - ); - - SetPixelsState( hPixMap, nPixMapFlags ); - } // if - } // if - } // if - else - { - DisposePixMap( hPixMap ); - - hPixMap = NULL; - } // else - } // if - } // if - - return hPixMap; -} // GetNewPixMap - -// ================================================================== - -// ================================================================== - -static CTabHandle CopyPixMapCTab ( CTabHandle hPixMapCTab ) -{ - CTabHandle hPixMapCTabCopy = NULL; - - if ( ( hPixMapCTab != NULL ) && ( *hPixMapCTab != NULL ) ) - { - SInt8 nhPixMapCTabFlags = noErr; - - nhPixMapCTabFlags = HGetState( (Handle)hPixMapCTabCopy ); - - if ( nhPixMapCTabFlags == noErr ) - { - long nPortPixMapCTabSize = 0; - long nPortPixMapCTabHandleSize = 0; - - HLock( (Handle)hPixMapCTab ); - - nPortPixMapCTabSize = (**hPixMapCTab).ctSize + 1; - - nPortPixMapCTabHandleSize = ( nPortPixMapCTabSize - * sizeof( ColorSpec ) - ) - + ( sizeof( ColorTable ) - - sizeof( CSpecArray ) - ); - - hPixMapCTabCopy = (CTabHandle)NewHandleClear( nPortPixMapCTabHandleSize ); - - if ( ( hPixMapCTabCopy != NULL ) && ( *hPixMapCTabCopy != NULL ) ) - { - SInt8 nPortPixMapCTabCopyFlags = noErr; - - nPortPixMapCTabCopyFlags = HGetState( (Handle)hPixMapCTabCopy ); - - if ( nPortPixMapCTabCopyFlags == noErr ) - { - unsigned long nPortPixMapCTabIndex; - - HLock( (Handle)hPixMapCTabCopy ); - - (**hPixMapCTabCopy).ctSize = (**hPixMapCTab).ctSize; - (**hPixMapCTabCopy).ctFlags = (**hPixMapCTab).ctFlags; - (**hPixMapCTabCopy).ctSeed = GetCTSeed(); - - for ( nPortPixMapCTabIndex = 0; - nPortPixMapCTabIndex < nPortPixMapCTabSize; - nPortPixMapCTabIndex++ - ) - { - (**hPixMapCTabCopy).ctTable[nPortPixMapCTabIndex] - = (**hPixMapCTab).ctTable[nPortPixMapCTabIndex]; - } // for - - HSetState( (Handle)hPixMapCTabCopy, nPortPixMapCTabCopyFlags ); - } // if - } // if - - HSetState( (Handle)hPixMapCTab, nhPixMapCTabFlags ); - } // if - } // if - else - { - hPixMapCTabCopy = GetNewPixMapCTabCLUT( kEightBitColor ); - - if ( hPixMapCTabCopy == NULL ) - { - hPixMapCTabCopy = CopyGDeviceCTab( ); - } // if - } // else - - return hPixMapCTabCopy; -} // CopyPixMapCTab - -// ------------------------------------------------------------------ - -static CTabHandle CopyPixMapCTabRGBDirect ( CTabHandle hPixMapCTab ) -{ - CTabHandle hPixMapCTabCopy = NULL; - - if ( ( hPixMapCTab != NULL ) && ( *hPixMapCTab != NULL ) ) - { - SInt8 nhPixMapCTabFlags = noErr; - - nhPixMapCTabFlags = HGetState( (Handle)hPixMapCTabCopy ); - - if ( nhPixMapCTabFlags == noErr ) - { - HLock( (Handle)hPixMapCTab ); - - hPixMapCTabCopy = (CTabHandle)NewHandleClear( sizeof( ColorTable ) - - sizeof( CSpecArray ) - ); - - if ( ( hPixMapCTabCopy != NULL ) && ( *hPixMapCTabCopy != NULL ) ) - { - SInt8 nPortPixMapCTabCopyFlags = noErr; - - nPortPixMapCTabCopyFlags = HGetState( (Handle)hPixMapCTabCopy ); - - if ( nPortPixMapCTabCopyFlags == noErr ) - { - HLock( (Handle)hPixMapCTabCopy ); - - (**hPixMapCTabCopy).ctSeed = (**hPixMapCTab).ctSeed; - (**hPixMapCTabCopy).ctFlags = (**hPixMapCTab).ctFlags; - (**hPixMapCTabCopy).ctSize = (**hPixMapCTab).ctSize; - - HSetState( (Handle)hPixMapCTabCopy, nPortPixMapCTabCopyFlags ); - } // if - } // if - - HSetState( (Handle)hPixMapCTab, nhPixMapCTabFlags ); - } // if - } // if - - return hPixMapCTabCopy; -} // CopyPixMapCTabRGBDirect - -// ------------------------------------------------------------------ - -static CTabHandle CopyPixMapCTabHandle ( PixMapHandle hPixMap ) -{ - CTabHandle hPixMapCTabCopy = NULL; - short nPixMapBitDepth = GetPixDepth( hPixMap ); - - if ( nPixMapBitDepth <= kEightBitColor ) - { - hPixMapCTabCopy = CopyPixMapCTab( (**hPixMap).pmTable ); - } // if - else - { - hPixMapCTabCopy = CopyPixMapCTabRGBDirect( (**hPixMap).pmTable ); - } // else - - return hPixMapCTabCopy; -} // CopyPixMapCTabHandle - -// ------------------------------------------------------------------ - -static PixMapHandle CopyPixMap ( PixMapHandle hPixMap ) -{ - PixMapHandle hPixMapCopy = NULL; - GWorldFlags nPixMapFlags = noErr; - - nPixMapFlags = GetPixelsState( hPixMap ); - - if ( nPixMapFlags == noErr ) - { - if ( LockPixels( hPixMap ) ) - { - hPixMapCopy = NewPixMap(); - - if ( ( hPixMapCopy != NULL ) && ( *hPixMapCopy != NULL ) ) - { - const Rect aPixMapBoundsRect = (**hPixMap).bounds; - const long nPixMapBitDepth = (**hPixMap).pixelSize; - const long nPixMapWidth = aPixMapBoundsRect.right - aPixMapBoundsRect.left; - const long nPixMapHeight = aPixMapBoundsRect.bottom - aPixMapBoundsRect.top; - const long nPixMapRowOffset = GetNewPixMapOffset( nPixMapBitDepth, nPixMapWidth ); - const long nPixMapImageSize = GetNewPixMapImageSize( nPixMapHeight, nPixMapRowOffset ); - Ptr pPixMapDataCopy = NewPtrClear( nPixMapImageSize ); - - if ( pPixMapDataCopy != NULL ) - { - GWorldFlags nPixMapCopyFlags = noErr; - - nPixMapCopyFlags = GetPixelsState( hPixMapCopy ); - - if ( nPixMapCopyFlags == noErr ) - { - if ( LockPixels( hPixMapCopy ) ) - { - const Ptr pPixMapData = (**hPixMap).baseAddr; - - // Copy the data from the original port - - BlockMoveData( pPixMapData, pPixMapDataCopy, nPixMapImageSize ); - - (**hPixMapCopy).rowBytes = (**hPixMap).rowBytes; // Offset to next line - (**hPixMapCopy).bounds = (**hPixMap).bounds; // Bounding bitmap rectangle - (**hPixMapCopy).pmVersion = (**hPixMap).pmVersion; // PixMap version number - (**hPixMapCopy).packType = (**hPixMap).packType; // Defines packing format - (**hPixMapCopy).packSize = (**hPixMap).packSize; // Length of pixel data - (**hPixMapCopy).hRes = (**hPixMap).hRes; // Horizontal resolution (ppi) - (**hPixMapCopy).vRes = (**hPixMap).vRes; // Vertical resolution (ppi) - (**hPixMapCopy).pixelType = (**hPixMap).pixelType; // Defines pixel type - (**hPixMapCopy).pixelSize = (**hPixMap).pixelSize; // Number of bits in a pixel - (**hPixMapCopy).cmpCount = (**hPixMap).cmpCount; // Number of components in a pixel - (**hPixMapCopy).cmpSize = (**hPixMap).cmpSize; // Number of bits per component - (**hPixMapCopy).pixelFormat = (**hPixMap).pixelFormat; // Four character code representation - (**hPixMapCopy).pmExt = (**hPixMap).pmExt; // Handle to PixMap extension - - // Copy the color table from the original port - - (**hPixMapCopy).pmTable = CopyPixMapCTabHandle( hPixMap ); - - SetPixelsState( hPixMapCopy, nPixMapCopyFlags ); - } // if - else - { - DisposePtr( pPixMapDataCopy ); - } // else - } // if - else - { - DisposePtr( pPixMapDataCopy ); - } // else - } // if - else - { - DisposePixMap( hPixMapCopy ); - - hPixMapCopy = NULL; - } // else - } // if - - SetPixelsState( hPixMap, nPixMapFlags ); - } // if - } // if - - return hPixMapCopy; -} // CopyPixMap - -// ================================================================== - -// ================================================================== - -static PixMapHandle MallocPixMap ( const Size &rPixMapSize, - const USHORT nPixMapBits, - const BitmapPalette &rBitmapPalette, - const SalGraphics *rSalGraphics - ) -{ - PixMapHandle hNewPixMap = GetPortPixMap( rSalGraphics->maGraphicsData.mpCGrafPort ); - - if ( hNewPixMap == NULL ) - { - hNewPixMap = GetNewPixMap( rPixMapSize, - nPixMapBits, - rBitmapPalette, - rSalGraphics - ); - - if ( hNewPixMap == NULL ) - { - GDHandle hGDevice = GetGDevice( ); - - if ( ( hGDevice != NULL ) && ( *hGDevice != NULL ) ) - { - SInt8 nGDeviceFlags = noErr; - - nGDeviceFlags = HGetState( (Handle)hGDevice ); - - if ( nGDeviceFlags == noErr ) - { - PixMapHandle hPixMap = NULL; - - HLock( (Handle)hGDevice ); - - hPixMap = (**hGDevice).gdPMap; - - if ( ( hPixMap != NULL ) && ( *hPixMap != NULL ) ) - { - hNewPixMap = CopyPixMap( hPixMap ); - } // if +#ifndef _SV_SALCOLORUTILS_HXX +#include <salcolorutils.hxx> +#endif - HSetState( (Handle)hGDevice, nGDeviceFlags ); - } //if - } // if - } // if - } // if +#ifndef _SV_SALPIXMAPUTILS_HXX +#include <salpixmaputils.hxx> +#endif - return hNewPixMap; -} // MallocPixMap +#ifndef _SV_SALRECTANGLEUTILS_HXX +#include <salrectangleutils.hxx> +#endif -// ================================================================== +// ======================================================================= -// ================================================================== +// ======================================================================= SalBitmap::SalBitmap() : mpVirDev( 0 ), @@ -897,26 +149,29 @@ BOOL SalBitmap::Create( const Size& rSize, SalGraphics *pGraphics = GetGraphics(); - if ( ( pGraphics != NULL ) - && ( pGraphics->maGraphicsData.mpCGrafPort != NULL ) - ) + if ( pGraphics != NULL ) { - mhPixMap = MallocPixMap( rSize, - nBitCount, - rBitmapPalette, - pGraphics - ); + const CGrafPtr pCGraf = pGraphics->maGraphicsData.mpCGrafPort; - if ( ( mhPixMap != NULL ) && ( *mhPixMap != NULL ) ) + if ( pCGraf != NULL ) { - mnBitCount = GetPixDepth( mhPixMap); - maSize = rSize; + mhPixMap = GetCGrafPortPixMap( rSize, + nBitCount, + rBitmapPalette, + pCGraf + ); - bSalBitmapCreated = TRUE; - } // if + if ( ( mhPixMap != NULL ) && ( *mhPixMap != NULL ) ) + { + mnBitCount = GetPixDepth( mhPixMap); + maSize = rSize; - // Release the SalGraphics so that others can get a - // handle to it in future GetGraphics() calls + bSalBitmapCreated = TRUE; + } // if + + // Release the SalGraphics so that others can get a + // handle to it in future GetGraphics() calls + } // if ReleaseGraphics( pGraphics ); } // if @@ -943,19 +198,22 @@ BOOL SalBitmap::Create( const SalBitmap& rSalBmp, USHORT nSalBmpBitCount = 0; BOOL bSalBitmapCreated = FALSE; - if ( ( pGraphics != NULL ) - && ( pGraphics->maGraphicsData.mpCGrafPort != NULL ) - ) + if ( pGraphics != NULL ) { - mhPixMap = MallocPixMap( rSalBmp.GetSize(), - rSalBmp.GetBitCount(), - BitmapPalette(), - pGraphics - ); + const CGrafPtr pCGraf = pGraphics->maGraphicsData.mpCGrafPort; - if ( ( mhPixMap != NULL ) && ( *mhPixMap != NULL ) ) + if ( pCGraf != NULL ) { - nSalBmpBitCount = GetPixDepth( mhPixMap ); + mhPixMap = GetCGrafPortPixMap( rSalBmp.GetSize(), + rSalBmp.GetBitCount(), + BitmapPalette(), + pCGraf + ); + + if ( ( mhPixMap != NULL ) && ( *mhPixMap != NULL ) ) + { + nSalBmpBitCount = GetPixDepth( mhPixMap ); + } // if } // if } // if @@ -989,21 +247,11 @@ BOOL SalBitmap::Create( const SalBitmap& rSalBmp, USHORT nNewBitCount ) && ( pSrcGraphics->maGraphicsData.mpCGrafPort != NULL ) ) { - long nWidth = rSalBmp.GetSize().Width(); - long nHeight = rSalBmp.GetSize().Height(); SalTwoRect aTwoRect; // Get size of graphics to copy from - aTwoRect.mnSrcX = 0; - aTwoRect.mnDestX = 0; - aTwoRect.mnSrcY = 0; - aTwoRect.mnDestY = 0; - - aTwoRect.mnSrcWidth = nWidth; - aTwoRect.mnDestWidth = nWidth; - aTwoRect.mnSrcHeight = nHeight; - aTwoRect.mnDestHeight = nHeight; + GetTwoRectFromSalBmp( rSalBmp, &aTwoRect ); // Copy bits from source graphics @@ -1063,48 +311,7 @@ BitmapBuffer* SalBitmap::AcquireBuffer( BOOL bReadOnly ) { if ( LockPixels( mhPixMap ) ) { - const short nPixMapCmpCount = (**mhPixMap).cmpCount; - const short nPixMapCmpSize = (**mhPixMap).cmpSize; - - pBuffer->mnFormat = BMP_FORMAT_TOP_DOWN; - - if( nPixMapCmpCount == 1 ) - { - // Indexed color mode - - switch ( nPixMapCmpSize ) - { - case ( kPixMapCmpSizeOneBit ): - pBuffer->mnFormat |= BMP_FORMAT_1BIT_MSB_PAL; - break; - case ( kPixMapCmpSizeFourBits ): - pBuffer->mnFormat |= BMP_FORMAT_4BIT_MSN_PAL; - break; - case ( kPixMapCmpSizeEightBits ): - pBuffer->mnFormat |= BMP_FORMAT_8BIT_PAL; - break; - default: - break; - } // switch - } // if - else - { - // Direct color mode - - switch ( nPixMapCmpSize ) - { - case ( kPixMapCmpSizeFiveBits ): - pBuffer->mnFormat |= BMP_FORMAT_16BIT_TC_MASK; - pBuffer->maColorMask = ColorMask( 0x00007c00, 0x000003e0, 0x0000001f ); - break; - case ( kPixMapCmpSizeEightBits ): - pBuffer->mnFormat |= BMP_FORMAT_32BIT_TC_ARGB; - pBuffer->maColorMask = ColorMask( 0x00ff0000, 0x0000ff00, 0x000000ff ); - break; - default: - break; - } // switch; - } //else + SetBitmapBufferColorFormat( mhPixMap, pBuffer ); if ( BMP_SCANLINE_FORMAT( pBuffer->mnFormat ) ) { @@ -1136,28 +343,23 @@ BitmapBuffer* SalBitmap::AcquireBuffer( BOOL bReadOnly ) HLock( (Handle)hCTab ); - // Map each color in the QuickDraw color - // table to a BitmapColor + // Map each color in the QuickDraw color + // table to a BitmapColor - nCTabSize = (**hCTab).ctSize + 1; + nCTabSize = (**hCTab).ctSize + 1; - rBitmapPalette.SetEntryCount( nCTabSize ); + rBitmapPalette.SetEntryCount( nCTabSize ); - for ( nCTabIndex = 0; - nCTabIndex < nCTabSize; - nCTabIndex++ - ) - { - BitmapColor &rBitmapColor = rBitmapPalette[nCTabIndex]; - const RGBColor aRGBColor = (**hCTab).ctTable[nCTabIndex].rgb; - const BYTE nRedColor = (BYTE)( aRGBColor.red >> 8 ); - const BYTE nGreenColor = (BYTE)( aRGBColor.green >> 8 ); - const BYTE nBlueColor = (BYTE)( aRGBColor.blue >> 8 ); + for ( nCTabIndex = 0; + nCTabIndex < nCTabSize; + nCTabIndex++ + ) + { + BitmapColor &rBitmapColor = rBitmapPalette[nCTabIndex]; + const RGBColor aRGBColor = (**hCTab).ctTable[nCTabIndex].rgb; - rBitmapColor.SetRed ( nRedColor ); - rBitmapColor.SetGreen ( nGreenColor ); - rBitmapColor.SetBlue ( nBlueColor ); - } // for + RGBColor2BitmapColor( &aRGBColor, rBitmapColor ); + } // for HSetState( (Handle)hCTab, nCTabFlags ); } // if @@ -1167,6 +369,8 @@ BitmapBuffer* SalBitmap::AcquireBuffer( BOOL bReadOnly ) else { delete pBuffer; + + pBuffer = NULL; } // else SetPixelsState( mhPixMap, nPixMapFlags ); @@ -1229,34 +433,30 @@ void SalBitmap::ReleaseBuffer( BitmapBuffer* pBuffer, BOOL bReadOnly ) if ( nCTabFlags == noErr ) { const BitmapPalette &rBitmapPalette = pBuffer->maPalette; - const short nCTabSize = (**hCTab).ctSize + 1; - const short nCTabMinSize = GetMinColorCount( nCTabSize, rBitmapPalette ); + short nCTabSize = 0; + short nCTabMinSize = 0; short nCTabIndex; HLock( (Handle)hCTab ); + nCTabSize = (**hCTab).ctSize + 1; + nCTabMinSize = GetMinColorCount( nCTabSize, rBitmapPalette ); + for( nCTabIndex = 0; nCTabIndex < nCTabMinSize; nCTabIndex++ ) { - const BitmapColor &rBitmapColor = rBitmapPalette[nCTabIndex]; - const USHORT nBitmapRedColor = rBitmapColor.GetRed(); - const USHORT nBitmapGreenColor = rBitmapColor.GetGreen(); - const USHORT nBitmapBlueColor = rBitmapColor.GetBlue(); + const BitmapColor &rBitmapPaletteColor = rBitmapPalette[nCTabIndex]; (**hCTab).ctTable[nCTabIndex].value = nCTabIndex; - (**hCTab).ctTable[nCTabIndex].rgb.red - = (short)(( nBitmapRedColor << 8 ) | nBitmapRedColor); - - (**hCTab).ctTable[nCTabIndex].rgb.green - = (short)(( nBitmapGreenColor << 8 ) | nBitmapGreenColor) ; - - (**hCTab).ctTable[nCTabIndex].rgb.blue - = (short)(( nBitmapBlueColor << 8 ) | nBitmapBlueColor); + (**hCTab).ctTable[nCTabIndex].rgb + = BitmapColor2RGBColor( rBitmapPaletteColor ); } // for + CTabChanged( hCTab ); + HSetState( (Handle)hCTab, nCTabFlags ); } // if } // if @@ -1293,7 +493,7 @@ void SalBitmap::ReleaseBuffer( BitmapBuffer* pBuffer, BOOL bReadOnly ) ); pGDevice = *GetGDevice(); - pPixMap = *pGDevice->gdPMap; + pCTable = *pPixMap->pmTable; } // if } // if @@ -1343,6 +543,6 @@ void SalBitmap::ReleaseGraphics( SalGraphics* pGraphics ) } // if } // SalBitmap::ReleaseGraphics -// ================================================================== - +// ======================================================================= +// ======================================================================= diff --git a/vcl/aqua/source/gdi/salcolorutils.cxx b/vcl/aqua/source/gdi/salcolorutils.cxx new file mode 100755 index 000000000000..553e2224368b --- /dev/null +++ b/vcl/aqua/source/gdi/salcolorutils.cxx @@ -0,0 +1,1014 @@ +/************************************************************************* + * + * $RCSfile: salcolorutils.cxx,v $ + * + * $Revision: 1.1 $ + * last change: $Author: bmahbod $ $Date: 2001-02-14 19:39:49 $ + * + * The Contents of this file are made available subject to the terms of + * either of the following licenses + * + * - GNU Lesser General Public License Version 2.1 + * - Sun Industry Standards Source License Version 1.1 + * + * Sun Microsystems Inc., October, 2000 + * + * GNU Lesser General Public License Version 2.1 + * ============================================= + * Copyright 2000 by Sun Microsystems, Inc. + * 901 San Antonio Road, Palo Alto, CA 94303, USA + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License version 2.1, as published by the Free Software Foundation. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, + * MA 02111-1307 USA + * + * + * Sun Industry Standards Source License Version 1.1 + * ================================================= + * The contents of this file are subject to the Sun Industry Standards + * Source License Version 1.1 (the "License"); You may not use this file + * except in compliance with the License. You may obtain a copy of the + * License at http://www.openoffice.org/license.html. + * + * Software provided under this License is provided on an "AS IS" basis, + * WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, + * WITHOUT LIMITATION, WARRANTIES THAT THE SOFTWARE IS FREE OF DEFECTS, + * MERCHANTABLE, FIT FOR A PARTICULAR PURPOSE, OR NON-INFRINGING. + * See the License for the specific provisions governing your rights and + * obligations concerning the Software. + * + * The Initial Developer of the Original Code is: Sun Microsystems, Inc. + * + * Copyright: 2000 by Sun Microsystems, Inc. + * + * All Rights Reserved. + * + * Contributor(s): _______________________________________ + * + * + ************************************************************************/ + +#define _SV_SALCOLORUTILS_CXX + +#ifndef _SV_SALCONST_H +#include <salconst.h> +#endif + +#ifndef _SV_SALCOLORUTILS_HXX +#include <salmathutils.hxx> +#endif + +#ifndef _SV_SALCOLORUTILS_HXX +#include <salcolorutils.hxx> +#endif + +// ======================================================================= + +// ======================================================================= + +static unsigned long Compress32BitRGBColor ( const RGBColor *pRGBColor ) +{ + unsigned long nCTableIndex = 0; + + nCTableIndex = ( pRGBColor->red >> kOneByte ) << kTwoBytes; + nCTableIndex |= ( pRGBColor->green >> kOneByte ) << kOneByte; + nCTableIndex |= pRGBColor->blue >> kOneByte; + + return nCTableIndex; +} // Compress32BitRGBColor + +// ----------------------------------------------------------------------- + +static unsigned long Compress16BitRGBColor ( const RGBColor *pRGBColor ) +{ + unsigned long nCTableIndex = 0; + + nCTableIndex = ( pRGBColor->red >> kElevenBits ) << kTenBits; + nCTableIndex |= ( pRGBColor->green >> kElevenBits ) << kFiveBits; + nCTableIndex |= pRGBColor->blue >> kElevenBits; + + return nCTableIndex; +} // Compress16BitRGBColor + +// ----------------------------------------------------------------------- + +static void CompressRGBColor ( const PixMapPtr pPixMap, + const RGBColor *pRGBColor, + SalColor *rSalColor + ) +{ + if ( pPixMap->pixelSize == kTrueColor ) + { + *rSalColor = Compress32BitRGBColor( pRGBColor ); + } // if + else + { + *rSalColor = Compress16BitRGBColor( pRGBColor ); + } // else +} // CompressRGBColor + +// ----------------------------------------------------------------------- +// +// Here we shall utilize an approximation to Euclidian norm. Where as +// in a standard Euclidian norm one sums up the square of the RGB color +// distances before proceeding to take the square root, in our case, we +// only measure the RGB color difference before summing up the totals. +// This way of measuring distance is also called the "Manhattan distance." +// Manhattan distance takes advantage of the fact that the sum of the +// lengths of the three components of a 3D vector is a rough approxima- +// tion of the vector's length. +// +// ----------------------------------------------------------------------- + +static unsigned long RGBDistance ( const RGBColor *pRGBColor1, + const RGBColor *pRGBColor2 + ) +{ + unsigned long nRGBDist = 0; + LRectCoor aVec[2]; + + // Find |r'-r|, |g'-g|, and |b'-b| from (r,g,b) and (r',g',b') + // coordinates; where red lies on the x-axis, green lies on the + // y-axis, and blue lies on the z-axis of the RGB color cube. + + aVec[0].x = (long)pRGBColor1->red; + aVec[0].y = (long)pRGBColor1->green; + aVec[0].z = (long)pRGBColor1->blue; + + aVec[1].x = (long)pRGBColor2->red; + aVec[1].y = (long)pRGBColor2->green; + aVec[1].z = (long)pRGBColor2->blue; + + // Now Compute || (r',g',b') - (r,g,b) || + + nRGBDist = Euclidian2Norm( aVec ); + + return nRGBDist; +} // RGBDistance + +// ----------------------------------------------------------------------- + +static inline BOOL QDColorsMatch ( const RGBColor *pRGBColor1, + const RGBColor *pRGBColor2 + ) +{ + if ( ( pRGBColor2->red == pRGBColor1->red ) + && ( pRGBColor2->green == pRGBColor1->green ) + && ( pRGBColor2->blue == pRGBColor1->blue ) + ) + { + return TRUE; + } // if + else + { + return FALSE; + } // else +} // QDColorsMatch + +// ----------------------------------------------------------------------- + +static void GetBestSalColor ( const CTabPtr pCTable, + const RGBColor *pRGBColor, + unsigned long *pBestSalColor + ) +{ + unsigned short nCTableSize = 0; + unsigned long nCTableIndex = 0; + unsigned long nRGBNewDistance = 0; + unsigned long nRGBMinDistance = UID_MAX; + RGBColor *pRGBNextColor = NULL; + BOOL bRGBColorsMatch = FALSE; + + *pBestSalColor = 0; + + nCTableSize = pCTable->ctSize; + + while ( ( nCTableIndex < nCTableSize ) && ( bRGBColorsMatch == FALSE ) ) + { + pRGBNextColor = &pCTable->ctTable[nCTableIndex].rgb; + + bRGBColorsMatch = QDColorsMatch( pRGBColor, pRGBNextColor ); + + if ( bRGBColorsMatch == TRUE ) + { + *pBestSalColor = nCTableIndex; + } // if + else + { + nRGBNewDistance = RGBDistance( pRGBColor, pRGBNextColor ); + + if ( nRGBNewDistance < nRGBMinDistance ) + { + nRGBMinDistance = nRGBNewDistance; + *pBestSalColor = nCTableIndex; + } // if + + nCTableIndex++; + } //else + } // while +} // GetBestSalColor + +// ----------------------------------------------------------------------- + +static void GetCTableIndex ( const RGBColor *pRGBColor, + SalColor *rSalColor + ) +{ + GDPtr pGDevice = NULL; + + pGDevice = *GetGDevice(); + + if ( pGDevice != NULL ) + { + PixMapPtr pPixMap = *pGDevice->gdPMap; + + if ( pPixMap != NULL ) + { + CTabPtr pCTable = *pPixMap->pmTable; + + if ( pCTable != NULL ) + { + ITabPtr pITable = *pGDevice->gdITable; + + if ( pITable != NULL ) + { + // Is the inverse color table up-to-date? + + if ( pITable->iTabSeed != pCTable->ctSeed ) + { + // Update our inverse color table + + MakeITable( pPixMap->pmTable, + pGDevice->gdITable, + pGDevice->gdResPref + ); + + pGDevice = *GetGDevice(); + pITable = *pGDevice->gdITable; + pPixMap = *pGDevice->gdPMap; + pCTable = *pPixMap->pmTable; + } // if + } // if + + // Now we proceed to find the closest match in our + // color table. + + if ( pCTable != NULL ) + { + GetBestSalColor( pCTable, pRGBColor, rSalColor ); + + if ( *rSalColor > pCTable->ctSize ) + { + // Return the index for white color in case + // of an error + + *rSalColor = 255; + } // if + } // if + } // if + } // if + } // if +} // GetCTableIndex + +// ----------------------------------------------------------------------- +// +// Convert RGB color to Sal color. +// +// ----------------------------------------------------------------------- + +SalColor RGBColor2SALColor ( const RGBColor *pRGBColor ) +{ + GDPtr pGDevice = NULL; + SalColor nSalColor = 0; + + pGDevice = *GetGDevice( ); + + if ( pGDevice != NULL ) + { + PixMapPtr pPixMap = NULL; + + pPixMap = *(*pGDevice).gdPMap; + + if ( pPixMap != NULL ) + { + if ( pGDevice->gdType == directType ) + { + CompressRGBColor( pPixMap, pRGBColor, &nSalColor ); + } // if + else + { + GetCTableIndex( pRGBColor, &nSalColor ); + } // else + } // if + } // if + + return nSalColor; +} // RGBColor2SALColor + +// ======================================================================= + +// ======================================================================= + +SalColor RGB8BitColor2SALColor ( const RGBColor *pRGBColor ) +{ + GDPtr pGDevice = NULL; + SalColor nSalColor = 0; + + pGDevice = *GetGDevice( ); + + if ( pGDevice != NULL ) + { + PixMapPtr pPixMap = *(*pGDevice).gdPMap; + + if ( pPixMap != NULL ) + { + if ( pGDevice->gdType != directType ) + { + GetCTableIndex( pRGBColor, &nSalColor ); + } // else + } // if + } // if + + return nSalColor; +} // RGB8BitColor2SALColor + +// ----------------------------------------------------------------------- + +SalColor RGB16BitColor2SALColor ( const RGBColor *pRGBColor ) +{ + GDPtr pGDevice = NULL; + SalColor nSalColor = 0; + + pGDevice = *GetGDevice( ); + + if ( pGDevice != NULL ) + { + PixMapPtr pPixMap = *(*pGDevice).gdPMap; + + if ( pPixMap != NULL ) + { + if ( pGDevice->gdType == directType ) + { + if ( pPixMap->pixelSize == kThousandsColor ) + { + nSalColor = Compress16BitRGBColor( pRGBColor ); + } // if + } // if + } // if + } // if + + return nSalColor; +} // RGB16BitColor2SALColor + +// ----------------------------------------------------------------------- + +SalColor RGB32BitColor2SALColor ( const RGBColor *pRGBColor ) +{ + GDPtr pGDevice = NULL; + SalColor nSalColor = 0; + + pGDevice = *GetGDevice( ); + + if ( pGDevice != NULL ) + { + PixMapPtr pPixMap = *(*pGDevice).gdPMap; + + if ( pPixMap != NULL ) + { + if ( pGDevice->gdType == directType ) + { + if ( pPixMap->pixelSize == kTrueColor ) + { + nSalColor = Compress32BitRGBColor( pRGBColor ); + } // if + } // if + } // if + } // if + + return nSalColor; +} // RGB32BitColor2SALColor + +// ======================================================================= + +// ======================================================================= + +static unsigned short SalColorTo32BitDeviceColor ( SalColor *rSalColor ) +{ + unsigned short nDirectColor = 0; + unsigned short nUpperByte = 0; + unsigned short nLowerByte = 0; + + nLowerByte = *rSalColor & kByteMask; + nUpperByte = nLowerByte << kOneByte; + nDirectColor = nUpperByte | nLowerByte; + *rSalColor >>= kOneByte; + + return nDirectColor; +} // SalColorTo32BitDeviceColor + +// ----------------------------------------------------------------------- + +static void SalColor2DirectColor ( const SalColor nSalColor, + RGBColor *rRGBColor + ) +{ + SalColor nIndexedColor = nSalColor; + + rRGBColor->blue = SalColorTo32BitDeviceColor( &nIndexedColor ); + rRGBColor->green = SalColorTo32BitDeviceColor( &nIndexedColor ); + rRGBColor->red = SalColorTo32BitDeviceColor( &nIndexedColor ); + +} // SalColor2DirectColor + +// ----------------------------------------------------------------------- + +static unsigned short SalColorTo16BitDeviceColor ( SalColor *rSalColor ) +{ + unsigned short nColor16Bit = 0; + unsigned short nUpper5Bits = 0; + unsigned short nUpper10Bits = 0; + unsigned short nLower5Bits = 0; + + nUpper5Bits = *rSalColor << kElevenBits; + nUpper10Bits = nUpper5Bits | ( nUpper5Bits >> kFiveBits ); + nLower5Bits = nUpper10Bits >> kTenBits; + nColor16Bit = nUpper10Bits | nLower5Bits; + *rSalColor >>= kFiveBits; + + return nColor16Bit; +} + +// ----------------------------------------------------------------------- + +static void SalColor2ThousandsColor ( const SalColor nSalColor, + RGBColor *rRGBColor + ) +{ + SalColor nIndexedColor = nSalColor; + + rRGBColor->blue = SalColorTo16BitDeviceColor ( &nIndexedColor ); + rRGBColor->green = SalColorTo16BitDeviceColor ( &nIndexedColor ); + rRGBColor->red = SalColorTo16BitDeviceColor ( &nIndexedColor ); +} // SalColor2ThousandsColor + +// ----------------------------------------------------------------------- + +static void SalColor2EightBitColor ( const SalColor nSalColor, + RGBColor *rRGBColor + ) +{ + GDPtr pGDevice = NULL; + + pGDevice = *GetGDevice(); + + if ( pGDevice != NULL ) + { + CTabPtr pCTable = NULL; + PixMapPtr pPixMap = NULL; + + pPixMap = *(*pGDevice).gdPMap; + + if ( pPixMap != NULL ) + { + pCTable = *(*pPixMap).pmTable; + + if ( pCTable != NULL ) + { + if ( nSalColor <= pCTable->ctSize ) + { + RGBColor aRGBColor; + + aRGBColor = pCTable->ctTable[nSalColor].rgb; + rRGBColor->red = aRGBColor.red; + rRGBColor->green = aRGBColor.green; + rRGBColor->blue = aRGBColor.blue; + } // if + } // if + } // if + } // if +} // SalColor2EightBitColor + +// ----------------------------------------------------------------------- +// +// Here we will convert SAL color to either 8-bit or 32-bit color. +// For 16-bit color we shall let Mac OS compute the nearest color +// from that of 32-bit color using the Euclidean 2-norm in RGB color +// space. +// +// ----------------------------------------------------------------------- + +RGBColor SALColor2RGBColor ( const SalColor nSalColor ) +{ + GDPtr pGDevice = NULL; + RGBColor aRGBColor; + + memset( &aRGBColor, 0, sizeof(RGBColor) ); + + pGDevice = *GetGDevice(); + + if ( pGDevice != NULL ) + { + if ( pGDevice->gdType == directType ) + { + SalColor2DirectColor( nSalColor, &aRGBColor ); + } // if + else + { + SalColor2EightBitColor( nSalColor, &aRGBColor ); + } // else + } // if + + return aRGBColor; +} // SALColor2RGBColor + +// ======================================================================= + +// ======================================================================= + +RGBColor SALColor2RGB32bitColor ( const SalColor nSalColor ) +{ + RGBColor aRGBColor; + + SalColor2DirectColor ( nSalColor, &aRGBColor ); + + return aRGBColor; +} // SALColor2RGB32bitColor + +// ----------------------------------------------------------------------- + +RGBColor SALColor2RGB16bitColor ( const SalColor nSalColor ) +{ + RGBColor aRGBColor; + + SalColor2ThousandsColor ( nSalColor, &aRGBColor ); + + return aRGBColor; +} // SALColor2RGB16bitColor + +// ----------------------------------------------------------------------- + +RGBColor SALColor2RGB8bitColor ( const SalColor nSalColor ) +{ + RGBColor aRGBColor; + + SalColor2EightBitColor ( nSalColor, &aRGBColor ); + + return aRGBColor; +} // SALColor2RGB8bitColor + +// ======================================================================= + +// ======================================================================= + +SalColor GetROPSalColor( SalROPColor nROPColor ) +{ + SalColor nSalColor = 0; + + if ( nROPColor == SAL_ROP_0 ) + { + RGBColor aBlackColor; + + aBlackColor.red = 0x0000; + aBlackColor.green = 0x0000; + aBlackColor.blue = 0x0000; + + nSalColor = RGBColor2SALColor ( &aBlackColor ); + } // if + else + { + RGBColor aWhiteColor; + + aWhiteColor.red = 0xffff; + aWhiteColor.green = 0xffff; + aWhiteColor.blue = 0xffff; + + nSalColor = RGBColor2SALColor ( &aWhiteColor ); + } // else + + return nSalColor; +} // GetROPSalColor + +// ======================================================================= + +// ======================================================================= + +short GetMinColorCount( const short nPixMapColorDepth, + const BitmapPalette &rBitmapPalette + ) +{ + short nBitmapPaletteCount = rBitmapPalette.GetEntryCount(); + short nBitmapPaletteMinCount = 0; + + if ( nPixMapColorDepth < nBitmapPaletteCount ) + { + nBitmapPaletteMinCount = nPixMapColorDepth; + } // if + else + { + nBitmapPaletteMinCount = nBitmapPaletteCount; + } // else + + return nBitmapPaletteMinCount; +} // GetMinColorCount + +// ======================================================================= + +// ======================================================================= + +RGBColor BitmapColor2RGBColor ( const BitmapColor &rBitmapColor ) +{ + const USHORT nBitmapRedColor = rBitmapColor.GetRed(); + const USHORT nBitmapGreenColor = rBitmapColor.GetGreen(); + const USHORT nBitmapBlueColor = rBitmapColor.GetBlue(); + RGBColor aRGBColor; + + aRGBColor.red = (short)(( nBitmapRedColor << kOneByte ) | nBitmapRedColor ); + aRGBColor.green = (short)(( nBitmapGreenColor << kOneByte ) | nBitmapGreenColor ); + aRGBColor.blue = (short)(( nBitmapBlueColor << kOneByte ) | nBitmapBlueColor ); + + return aRGBColor; +} // BitmapColor2RGBColor + +// ------------------------------------------------------------------ + +void RGBColor2BitmapColor ( const RGBColor *rRGBColor, + BitmapColor &rBitmapColor + ) +{ + if ( rRGBColor != NULL ) + { + const BYTE nRedColor = (BYTE)( rRGBColor->red >> kOneByte ); + const BYTE nGreenColor = (BYTE)( rRGBColor->green >> kOneByte ); + const BYTE nBlueColor = (BYTE)( rRGBColor->blue >> kOneByte ); + + rBitmapColor.SetRed ( nRedColor ); + rBitmapColor.SetGreen ( nGreenColor ); + rBitmapColor.SetBlue ( nBlueColor ); + } // if +} // RGBColor2BitmapColor + +// ======================================================================= + +// ======================================================================= + +void SetBlackForeColor ( ) +{ + RGBColor aBlackForeColor; + + // Black color + + aBlackForeColor.red = 0x0000; + aBlackForeColor.green = 0x0000; + aBlackForeColor.blue = 0x0000; + + // Set foreground color to black + + RGBForeColor( &aBlackForeColor ); +} // SetBlackForeColor + +// ----------------------------------------------------------------------- + +void SetWhiteBackColor ( ) +{ + RGBColor aWhiteBackColor; + + // White color + + aWhiteBackColor.red = 0xffff; + aWhiteBackColor.green = 0xffff; + aWhiteBackColor.blue = 0xffff; + + // Set background color to white + + RGBBackColor( &aWhiteBackColor ); +} // SetWhiteBackColor + +// ======================================================================= + +// ======================================================================= + +RGBColor GetBlackColor ( ) +{ + RGBColor aBlackColor; + + aBlackColor.red = 0x0000; + aBlackColor.green = 0x0000; + aBlackColor.blue = 0x0000; + + return aBlackColor; +} // GetBlackColor + +// ----------------------------------------------------------------------- + +RGBColor GetWhiteColor ( ) +{ + RGBColor aWhiteColor; + + aWhiteColor.red = 0xffff; + aWhiteColor.green = 0xffff; + aWhiteColor.blue = 0xffff; + + return aWhiteColor; +} // GetWhiteColor + +// ======================================================================= + +// ======================================================================= + +CTabHandle CopyGDeviceCTab ( ) +{ + GDPtr pGDevice = NULL; + CTabHandle hCTable = NULL; + + pGDevice = *GetGDevice ( ); + + if ( pGDevice != NULL ) + { + PixMapPtr pPixMap = NULL; + + pPixMap = *(*pGDevice).gdPMap; + + if ( pPixMap != NULL ) + { + CTabPtr pCTable = NULL; + + pCTable = *(*pPixMap).pmTable; + + if ( pCTable != NULL ) + { + const short nCTableSize = pCTable->ctSize + 1; + long nCTableHandleSize = 0; + + nCTableHandleSize = ( nCTableSize + * sizeof( ColorSpec ) + ) + + ( sizeof( ColorTable ) + - sizeof( CSpecArray ) + ); + + hCTable = (CTabHandle) NewHandleClear( nCTableHandleSize ); + + if ( ( hCTable != NULL ) && ( *hCTable != NULL ) ) + { + SInt8 nFlags = noErr; + + nFlags = HGetState( (Handle)hCTable ); + + if ( nFlags == noErr ) + { + unsigned long nCTableIndex; + + HLock( (Handle)hCTable ); + + (**hCTable).ctSize = pCTable->ctSize; + (**hCTable).ctFlags = pCTable->ctFlags; + (**hCTable).ctSeed = GetCTSeed(); + + for ( nCTableIndex = 0; + nCTableIndex < nCTableSize; + nCTableIndex++ + ) + { + (**hCTable).ctTable[nCTableIndex] + = pCTable->ctTable[nCTableIndex]; + } // for + + HSetState( (Handle)hCTable, nFlags ); + } // if + } // if + } // if + } // if + } // if + + return hCTable; +} // CopyGDeviceCTab + +// ------------------------------------------------------------------ + +CTabHandle GetCTabFromStdCLUT ( const short nBitDepth ) +{ + CTabHandle hCTab = NULL; + short nCLUTID = 0; + + nCLUTID = nBitDepth + 64; + + hCTab = GetCTable( nCLUTID ); + + return hCTab; +} // GetCTabFromStdCLUT + +// ======================================================================= + +// ======================================================================= + +CTabHandle CopyCTabIndexed ( CTabHandle hCTab ) +{ + CTabHandle hCTabCopy = NULL; + + if ( ( hCTab != NULL ) && ( *hCTab != NULL ) ) + { + SInt8 nhCTabFlags = noErr; + + nhCTabFlags = HGetState( (Handle)hCTabCopy ); + + if ( nhCTabFlags == noErr ) + { + long nCTabSize = 0; + long nCTabHandleSize = 0; + + HLock( (Handle)hCTab ); + + nCTabSize = (**hCTab).ctSize + 1; + + nCTabHandleSize = ( nCTabSize + * sizeof( ColorSpec ) + ) + + ( sizeof( ColorTable ) + - sizeof( CSpecArray ) + ); + + hCTabCopy = (CTabHandle)NewHandleClear( nCTabHandleSize ); + + if ( ( hCTabCopy != NULL ) && ( *hCTabCopy != NULL ) ) + { + SInt8 nCTabCopyFlags = noErr; + + nCTabCopyFlags = HGetState( (Handle)hCTabCopy ); + + if ( nCTabCopyFlags == noErr ) + { + unsigned long nPortPixMapCTabIndex; + + HLock( (Handle)hCTabCopy ); + + (**hCTabCopy).ctSize = (**hCTab).ctSize; + (**hCTabCopy).ctFlags = (**hCTab).ctFlags; + (**hCTabCopy).ctSeed = GetCTSeed(); + + for ( nPortPixMapCTabIndex = 0; + nPortPixMapCTabIndex < nCTabSize; + nPortPixMapCTabIndex++ + ) + { + (**hCTabCopy).ctTable[nPortPixMapCTabIndex] + = (**hCTab).ctTable[nPortPixMapCTabIndex]; + } // for + + HSetState( (Handle)hCTabCopy, nCTabCopyFlags ); + } // if + } // if + + HSetState( (Handle)hCTab, nhCTabFlags ); + } // if + } // if + else + { + hCTabCopy = GetCTabFromStdCLUT( kEightBitColor ); + + if ( hCTabCopy == NULL ) + { + hCTabCopy = CopyGDeviceCTab( ); + } // if + } // else + + return hCTabCopy; +} // CopyCTabIndexed + +// ------------------------------------------------------------------ + +CTabHandle CopyCTabRGBDirect ( CTabHandle hCTab ) +{ + CTabHandle hCTabCopy = NULL; + + if ( ( hCTab != NULL ) && ( *hCTab != NULL ) ) + { + SInt8 nhCTabFlags = noErr; + + nhCTabFlags = HGetState( (Handle)hCTabCopy ); + + if ( nhCTabFlags == noErr ) + { + HLock( (Handle)hCTab ); + + hCTabCopy = (CTabHandle)NewHandleClear( sizeof( ColorTable ) + - sizeof( CSpecArray ) + ); + + if ( ( hCTabCopy != NULL ) && ( *hCTabCopy != NULL ) ) + { + SInt8 nCTabCopyFlags = noErr; + + nCTabCopyFlags = HGetState( (Handle)hCTabCopy ); + + if ( nCTabCopyFlags == noErr ) + { + HLock( (Handle)hCTabCopy ); + + (**hCTabCopy).ctSeed = (**hCTab).ctSeed; + (**hCTabCopy).ctFlags = (**hCTab).ctFlags; + (**hCTabCopy).ctSize = (**hCTab).ctSize; + + HSetState( (Handle)hCTabCopy, nCTabCopyFlags ); + } // if + } // if + + HSetState( (Handle)hCTab, nhCTabFlags ); + } // if + } // if + + return hCTabCopy; +} // CopyCTabRGBDirect + +// ======================================================================= + +// ======================================================================= + +CTabHandle CopyPixMapCTab ( PixMapHandle hPixMap ) +{ + CTabHandle hCTabCopy = NULL; + short nPixMapBitDepth = GetPixDepth( hPixMap ); + + if ( nPixMapBitDepth <= kEightBitColor ) + { + hCTabCopy = CopyCTabIndexed( (**hPixMap).pmTable ); + } // if + else + { + hCTabCopy = CopyCTabRGBDirect( (**hPixMap).pmTable ); + } // else + + return hCTabCopy; +} // CopyPixMapCTab + +// ======================================================================= + +// ======================================================================= + +void SetBitmapBufferColorFormat ( const PixMapHandle mhPixMap, + BitmapBuffer *rBuffer + ) +{ + const short nPixMapCmpCount = (**mhPixMap).cmpCount; + const short nPixMapCmpSize = (**mhPixMap).cmpSize; + + rBuffer->mnFormat = BMP_FORMAT_TOP_DOWN; + + if( nPixMapCmpCount == 1 ) + { + // Indexed color mode + + switch ( nPixMapCmpSize ) + { + case ( kPixMapCmpSizeOneBit ): + rBuffer->mnFormat |= BMP_FORMAT_1BIT_MSB_PAL; + break; + case ( kPixMapCmpSizeFourBits ): + rBuffer->mnFormat |= BMP_FORMAT_4BIT_MSN_PAL; + break; + case ( kPixMapCmpSizeEightBits ): + rBuffer->mnFormat |= BMP_FORMAT_8BIT_PAL; + break; + default: + break; + } // switch + } // if + else + { + // Direct color mode + + switch ( nPixMapCmpSize ) + { + case ( kPixMapCmpSizeFiveBits ): + rBuffer->mnFormat |= BMP_FORMAT_16BIT_TC_MASK; + rBuffer->maColorMask = ColorMask( k16BitRedColorMask, + k16BitGreenColorMask, + k16BitBlueColorMask + ); + break; + case ( kPixMapCmpSizeEightBits ): + rBuffer->mnFormat |= BMP_FORMAT_32BIT_TC_ARGB; + rBuffer->maColorMask = ColorMask( k32BitRedColorMask, + k32BitGreenColorMask, + k32BitBlueColorMask + ); + break; + default: + break; + } // switch; + } //else +} // SetBitmapBufferColorFormat + +// ======================================================================= + +// ======================================================================= + diff --git a/vcl/aqua/source/gdi/salgdi.cxx b/vcl/aqua/source/gdi/salgdi.cxx index ed45fb5b63ad..95123a58970a 100644 --- a/vcl/aqua/source/gdi/salgdi.cxx +++ b/vcl/aqua/source/gdi/salgdi.cxx @@ -2,8 +2,8 @@ * * $RCSfile: salgdi.cxx,v $ * - * $Revision: 1.49 $ - * last change: $Author: bmahbod $ $Date: 2001-02-08 00:12:20 $ + * $Revision: 1.50 $ + * last change: $Author: bmahbod $ $Date: 2001-02-14 19:39:49 $ * * The Contents of this file are made available subject to the terms of * either of the following licenses @@ -60,1008 +60,41 @@ #define _SV_SALGDI_CXX +#ifndef _SV_SALCONST_H +#include <salconst.h> +#endif + #ifndef _SV_SALBMP_HXX #include <salbmp.hxx> #endif + #ifndef _SV_SALDATA_HXX #include <saldata.hxx> #endif + #ifndef _SV_SALGDI_HXX #include <salgdi.hxx> #endif + #ifndef _SV_OUTFONT_HXX #include <outfont.hxx> #endif + #ifndef _SV_VCLGRAPHICS_H #include <VCLGraphics.h> #endif -// ======================================================================= - -// ======================================================================= - -static inline unsigned long AbsoluteValue ( const long nValue ) -{ - unsigned long nAbsValue = 0; - - if ( nValue < 0 ) - { - nAbsValue = -nValue; - } // if - else - { - nAbsValue = nValue; - } // else - - return nAbsValue; -} // AbsoluteValue - -// ----------------------------------------------------------------------- - -static inline BOOL Boolean2BOOL ( const Boolean bBooleanValue ) -{ - BOOL nBOOLValue; - - if ( bBooleanValue ) - { - nBOOLValue = TRUE; - } // if - else - { - nBOOLValue = FALSE; - } // else - - return nBOOLValue; -} // AbsoluteValue - -// ======================================================================= - -// ======================================================================= - -static inline void SetWhiteBackColor() -{ - RGBColor aWhiteBackColor; - - // White color - - aWhiteBackColor.red = 0xffff; - aWhiteBackColor.green = 0xffff; - aWhiteBackColor.blue = 0xffff; - - // Set background color to white - - RGBBackColor( &aWhiteBackColor ); -} // SetWhiteBackColor - -// ----------------------------------------------------------------------- - -static inline void SetBlackForeColor() -{ - RGBColor aBlackForeColor; - - // Black color - - aBlackForeColor.red = 0x0000; - aBlackForeColor.green = 0x0000; - aBlackForeColor.blue = 0x0000; - - // Set foreground color to black - - RGBForeColor( &aBlackForeColor ); -} // SetBlackForeColor - -// ======================================================================= - -// ======================================================================= - -static void CheckRectBounds ( Rect *rSrcRect, - Rect *rDstRect, - const Rect *rPortBoundsRect - ) - -{ - if ( rSrcRect->top < rPortBoundsRect->top ) - { - rDstRect->top += (rPortBoundsRect->top - rSrcRect->top); - rSrcRect->top = rPortBoundsRect->top; - } // if - - if ( rSrcRect->left < rPortBoundsRect->left ) - { - rDstRect->left += (rPortBoundsRect->left - rSrcRect->left); - rSrcRect->left = rPortBoundsRect->left; - } // if - - if ( rSrcRect->bottom > rPortBoundsRect->bottom ) - { - - rDstRect->bottom += (rPortBoundsRect->bottom - rSrcRect->bottom); - rSrcRect->bottom = rPortBoundsRect->bottom; - } // if - - if ( rSrcRect->right > rPortBoundsRect->right ) - { - rDstRect->right += (rPortBoundsRect->right - rSrcRect->right); - rSrcRect->right = rPortBoundsRect->right; - } // if -} // CheckRectBounds - -// ----------------------------------------------------------------------- - -static inline void GetQDRect ( const long nX, - const long nY, - const long nWidth, - const long nHeight, - Rect *rRect - ) -{ - SetRect( rRect, nX, nY, nX + nWidth, nY + nHeight ); -} // GetQDRect - -// ----------------------------------------------------------------------- - -static inline void SalTwoRect2QDDstRect ( const SalTwoRect *pPosAry, - Rect *rDstRect - ) -{ - SetRect( rDstRect, - pPosAry->mnDestX, - pPosAry->mnDestY, - pPosAry->mnDestX + pPosAry->mnDestWidth, - pPosAry->mnDestY + pPosAry->mnDestHeight - ); -} // GetSalSourceRect - -// ----------------------------------------------------------------------- - -static inline void SalTwoRect2QDSrcRect ( const SalTwoRect *pPosAry, - Rect *rSrcRect - ) -{ - SetRect( rSrcRect, - pPosAry->mnSrcX, - pPosAry->mnSrcY, - pPosAry->mnSrcX + pPosAry->mnSrcWidth, - pPosAry->mnSrcY + pPosAry->mnSrcHeight - ); -} // SalTwoRect2QDSrcRect - -// ----------------------------------------------------------------------- - -static inline short SelectCopyMode ( const SalGraphicsDataPtr pSalGraphicsData ) -{ - short nCopyMode = 0; - - if ( pSalGraphicsData->mnPenMode == patCopy ) - { - nCopyMode = srcCopy; - } // if - else - { - nCopyMode = srcXor; - } // else - - return nCopyMode; -} // SelectCopyMode - -// ======================================================================= - -// ======================================================================= - -static RgnHandle GetPolygonRgn ( const unsigned long nPolyCount, - const unsigned long *pPoints, - PCONSTSALPOINT *ppPtAry, - OSStatus *rQDStatus - ) -{ - RgnHandle hSrcRgnA = NULL; - - hSrcRgnA = NewRgn(); - - if ( hSrcRgnA != NULL ) - { - RgnHandle hSrcRgnB = NULL; - - hSrcRgnB = NewRgn(); - - if ( hSrcRgnB != NULL ) - { - unsigned short nPolyEdgeIndex = 0; - unsigned short nPolyIndex = 0; - unsigned short nPolyEdges = 0; - - for ( nPolyIndex = 0; - nPolyIndex < nPolyCount; - nPolyIndex++ - ) - { - const SalPoint *pPtAry = ppPtAry[nPolyIndex]; - - nPolyEdges = pPoints[nPolyIndex]; - - // Begin region construction - - OpenRgn(); - - // Begin polygon construction - - MoveTo( pPtAry[0].mnX, pPtAry[0].mnY ); - - for ( nPolyEdgeIndex = 1; - nPolyEdgeIndex < nPolyEdges; - nPolyEdgeIndex++ - ) - { - MacLineTo( pPtAry[nPolyEdgeIndex].mnX, - pPtAry[nPolyEdgeIndex].mnY - ); - } // for - - MacLineTo( pPtAry[0].mnX, pPtAry[0].mnY ); - - // End polygon construction - - CloseRgn( hSrcRgnB ); - - // End region construction - - *rQDStatus = QDErr(); - - if ( *rQDStatus == noErr ) - { - if ( nPolyIndex == 0 ) - { - MacCopyRgn( hSrcRgnB, hSrcRgnA ); - } // if - else - { - MacXorRgn( hSrcRgnA, hSrcRgnB, hSrcRgnA ); - } // else - } // if - } // for - - DisposeRgn( hSrcRgnB ); - - *rQDStatus = QDErr(); - - if ( *rQDStatus != noErr ) - { - DisposeRgn( hSrcRgnA ); - - hSrcRgnA = NULL; - } - - hSrcRgnB = NULL; - } // if - } // if - - return hSrcRgnA; -} // GetPolygonRgn - -// ======================================================================= - -// ======================================================================= - -static unsigned long Compress32BitRGBColor ( const RGBColor *pRGBColor ) -{ - unsigned long nCTableIndex = 0; - - nCTableIndex = ( pRGBColor->red >> kOneByte ) << kTwoBytes; - nCTableIndex |= ( pRGBColor->green >> kOneByte ) << kOneByte; - nCTableIndex |= pRGBColor->blue >> kOneByte; - - return nCTableIndex; -} // Compress32BitRGBColor - -// ----------------------------------------------------------------------- - -static unsigned long Compress16BitRGBColor ( const RGBColor *pRGBColor ) -{ - unsigned long nCTableIndex = 0; - - nCTableIndex = ( pRGBColor->red >> kElevenBits ) << kTenBits; - nCTableIndex |= ( pRGBColor->green >> kElevenBits ) << kFiveBits; - nCTableIndex |= pRGBColor->blue >> kElevenBits; - - return nCTableIndex; -} // Compress16BitRGBColor - -// ----------------------------------------------------------------------- - -static void CompressRGBColor ( const PixMapPtr pPixMap, - const RGBColor *pRGBColor, - SalColor *rSalColor - ) -{ - if ( pPixMap->pixelSize == kTrueColor ) - { - *rSalColor = Compress32BitRGBColor( pRGBColor ); - } // if - else - { - *rSalColor = Compress16BitRGBColor( pRGBColor ); - } // else -} // CompressRGBColor - -// ----------------------------------------------------------------------- - -static unsigned long RGBDistance ( const RGBColor *pRGBColor1, - const RGBColor *pRGBColor2 - ) -{ - unsigned long nRGBDist = 0; - long nDeltaRed = 0; - long nDeltaGreen = 0; - long nDeltaBlue = 0; - - nDeltaRed = (long)pRGBColor2->red - (long)pRGBColor1->red; - nDeltaGreen = (long)pRGBColor2->green - (long)pRGBColor1->green; - nDeltaBlue = (long)pRGBColor2->blue - (long)pRGBColor1->blue; - - nRGBDist = AbsoluteValue(nDeltaRed) - + AbsoluteValue(nDeltaGreen) - + AbsoluteValue(nDeltaBlue); - - return nRGBDist; -} // RGBDistance - -// ----------------------------------------------------------------------- - -static BOOL QDColorsMatch ( const RGBColor *pRGBColor1, - const RGBColor *pRGBColor2 - ) -{ - if ( ( pRGBColor2->red == pRGBColor1->red ) - && ( pRGBColor2->green == pRGBColor1->green ) - && ( pRGBColor2->blue == pRGBColor1->blue ) - ) - { - return TRUE; - } // if - else - { - return FALSE; - } // else -} // QDColorsMatch - -// ----------------------------------------------------------------------- - -static void GetBestSalColor ( const CTabPtr pCTable, - const RGBColor *pRGBColor, - unsigned long *pBestSalColor - ) -{ - unsigned short nCTableSize = 0; - unsigned long nCTableIndex = 0; - unsigned long nRGBNewDistance = 0; - unsigned long nRGBMinDistance = UID_MAX; - RGBColor *pRGBNextColor = NULL; - BOOL bRGBColorsMatch = FALSE; - - *pBestSalColor = 0; - - nCTableSize = pCTable->ctSize; - - while ( ( nCTableIndex < nCTableSize ) && ( bRGBColorsMatch == FALSE ) ) - { - pRGBNextColor = &pCTable->ctTable[nCTableIndex].rgb; - - bRGBColorsMatch = QDColorsMatch( pRGBColor, pRGBNextColor ); - - if ( bRGBColorsMatch == TRUE ) - { - *pBestSalColor = nCTableIndex; - } // if - else - { - nRGBNewDistance = RGBDistance( pRGBColor, pRGBNextColor ); - - if ( nRGBNewDistance < nRGBMinDistance ) - { - nRGBMinDistance = nRGBNewDistance; - *pBestSalColor = nCTableIndex; - } // if - - nCTableIndex++; - } //else - } // while -} // GetBestSalColor - -// ----------------------------------------------------------------------- - -static void GetCTableIndex ( const RGBColor *pRGBColor, - SalColor *rSalColor - ) -{ - GDPtr pGDevice = NULL; - - pGDevice = *GetGDevice(); - - if ( pGDevice != NULL ) - { - PixMapPtr pPixMap = *pGDevice->gdPMap; - - if ( pPixMap != NULL ) - { - CTabPtr pCTable = *pPixMap->pmTable; - - if ( pCTable != NULL ) - { - ITabPtr pITable = *pGDevice->gdITable; - - if ( pITable != NULL ) - { - // Is the inverse color table up-to-date? - - if ( pITable->iTabSeed != pCTable->ctSeed ) - { - // Update our inverse color table - - MakeITable( pPixMap->pmTable, - pGDevice->gdITable, - pGDevice->gdResPref - ); - - pGDevice = *GetGDevice(); - pITable = *pGDevice->gdITable; - pPixMap = *pGDevice->gdPMap; - pCTable = *pPixMap->pmTable; - } // if - } // if - - // Now we proceed to find the closest match in our - // color table using a basic 2-norm. Note that, - // here we shall utilize a psuedo Euclidean norm. - // Where as in a standard Euclidean norm one sums up - // the square of the RGB color distances before - // proceeding to take the square root, in our case, - // we only measure the RGB color difference before - // summing up the totals. - - if ( pCTable != NULL ) - { - GetBestSalColor( pCTable, pRGBColor, rSalColor ); - - if ( *rSalColor > pCTable->ctSize ) - { - *rSalColor = 255; - } // if - } // if - } // if - } // if - } // if -} // GetCTableIndex - -// ----------------------------------------------------------------------- -// -// Convert RGB color to Sal color. -// -// ----------------------------------------------------------------------- - -static SalColor RGBColor2SALColor ( const RGBColor *pRGBColor ) -{ - GDPtr pGDevice = NULL; - SalColor nSalColor = 0; - - pGDevice = *GetGDevice( ); - - if ( pGDevice != NULL ) - { - PixMapPtr pPixMap = NULL; - - pPixMap = *(*pGDevice).gdPMap; - - if ( pPixMap != NULL ) - { - if ( pGDevice->gdType == directType ) - { - CompressRGBColor( pPixMap, pRGBColor, &nSalColor ); - } // if - else - { - GetCTableIndex( pRGBColor, &nSalColor ); - } // else - } // if - } // if - - return nSalColor; -} // RGBColor2SALColor - -// ======================================================================= - -// ======================================================================= - -static unsigned short SalColorTo32BitDeviceColor ( SalColor *rSalColor ) -{ - unsigned short nDirectColor = 0; - unsigned short nUpperByte = 0; - unsigned short nLowerByte = 0; - - nLowerByte = *rSalColor & kByteMask; - nUpperByte = nLowerByte << kOneByte; - nDirectColor = nUpperByte | nLowerByte; - *rSalColor >>= kOneByte; - - return nDirectColor; -} // SalColorTo32BitDeviceColor - -// ----------------------------------------------------------------------- - -static void SalColor2DirectColor ( const SalColor nSalColor, - RGBColor *rRGBColor - ) -{ - SalColor nIndexedColor = nSalColor; - - rRGBColor->blue = SalColorTo32BitDeviceColor( &nIndexedColor ); - rRGBColor->green = SalColorTo32BitDeviceColor( &nIndexedColor ); - rRGBColor->red = SalColorTo32BitDeviceColor( &nIndexedColor ); - -} // SalColor2DirectColor - -// ----------------------------------------------------------------------- - -static void SalColor2EightBitColor ( const GDPtr pGDevice, - const SalColor nSalColor, - RGBColor *rRGBColor - ) -{ - CTabPtr pCTable = NULL; - PixMapPtr pPixMap = NULL; - - pPixMap = *(*pGDevice).gdPMap; - - if ( pPixMap != NULL ) - { - pCTable = *(*pPixMap).pmTable; - - if ( pCTable != NULL ) - { - if ( nSalColor <= pCTable->ctSize ) - { - RGBColor aRGBColor; - - aRGBColor = pCTable->ctTable[nSalColor].rgb; - rRGBColor->red = aRGBColor.red; - rRGBColor->green = aRGBColor.green; - rRGBColor->blue = aRGBColor.blue; - } // if - } // if - } // if -} // SalColor2EightBitColor - -// ----------------------------------------------------------------------- -// -// Here we will convert SAL color to either 8-bit or 32-bit color. -// For 16-bit color we shall let Mac OS compute the nearest color -// from that of 32-bit color using the Euclidean 2-norm in RGB color -// space. -// -// ----------------------------------------------------------------------- - -static RGBColor SALColor2RGBColor ( const SalColor nSalColor ) -{ - GDPtr pGDevice = NULL; - RGBColor aRGBColor; - - memset( &aRGBColor, 0, sizeof(RGBColor) ); - - pGDevice = *GetGDevice(); - - if ( pGDevice != NULL ) - { - if ( pGDevice->gdType == directType ) - { - SalColor2DirectColor( nSalColor, &aRGBColor ); - } // if - else - { - SalColor2EightBitColor( pGDevice, nSalColor, &aRGBColor ); - } // else - } // if - - return aRGBColor; -} // SALColor2RGBColor - -// ======================================================================= - -// ======================================================================= - -static SalColor GetROPSalColor( SalROPColor nROPColor ) -{ - SalColor nSalColor = 0; - - if ( nROPColor == SAL_ROP_0 ) - { - RGBColor aBlackColor; - - aBlackColor.red = 0x0000; - aBlackColor.green = 0x0000; - aBlackColor.blue = 0x0000; - - nSalColor = RGBColor2SALColor ( &aBlackColor ); - } // if - else - { - RGBColor aWhiteColor; - - aWhiteColor.red = 0xffff; - aWhiteColor.green = 0xffff; - aWhiteColor.blue = 0xffff; - - nSalColor = RGBColor2SALColor ( &aWhiteColor ); - } // else - - return nSalColor; -} // GetROPSalColor - -// ======================================================================= - -// ======================================================================= - -static OSStatus GetGDeviceBitDepth ( unsigned short *rGDeviceBitDepth ) -{ - GDPtr pGDevice = NULL; - OSStatus nOSStatus = noErr; - - pGDevice = *GetGDevice ( ); - - nOSStatus = QDErr(); - - if ( ( pGDevice != NULL ) && ( nOSStatus == noErr ) ) - { - *rGDeviceBitDepth = GetPixDepth( pGDevice->gdPMap ); - } // if - - return nOSStatus; -} // GetGDeviceBitDepth - -// ----------------------------------------------------------------------- - -static OSStatus GetGDeviceResolution ( long *rGDeviceHRes, - long *rGDeviceVRes - ) -{ - GDPtr pGDevice = NULL; - OSStatus nOSStatus = noErr; - - pGDevice = *GetGDevice ( ); - - nOSStatus = QDErr(); - - if ( ( pGDevice != NULL ) && ( nOSStatus == noErr ) ) - { - long nGDeviceTop = pGDevice->gdRect.top; - long nGDeviceLeft = pGDevice->gdRect.left; - long nGDeviceBottom = pGDevice->gdRect.bottom; - long nGDeviceRight = pGDevice->gdRect.right; - - // From the current GDevice get its horizontal resolution - - *rGDeviceHRes = AbsoluteValue( nGDeviceRight - nGDeviceLeft ); - - // From the current GDevice get its vertical resolution - - *rGDeviceVRes = AbsoluteValue( nGDeviceBottom - nGDeviceTop ); - } // if - - return nOSStatus; -} // GetGDeviceResolution - -// ======================================================================= - -// ======================================================================= - -static BOOL LockGraphics ( SalGraphics *rSalGraphics ) -{ - BOOL bCGrafPortLocked = FALSE; - - if ( ( rSalGraphics != NULL ) - && ( rSalGraphics->maGraphicsData.mpCGrafPort != NULL ) - ) - { - rSalGraphics->maGraphicsData.mnOSStatus - = LockPortBits( rSalGraphics->maGraphicsData.mpCGrafPort ); - - if ( rSalGraphics->maGraphicsData.mnOSStatus == noErr ) - { - rSalGraphics->maGraphicsData.mhGWorldPixMap - = GetPortPixMap( rSalGraphics->maGraphicsData.mpCGrafPort ); - - rSalGraphics->maGraphicsData.mnOSStatus = QDErr(); - - bCGrafPortLocked = TRUE; - } // if - } // if - - return bCGrafPortLocked; -} // LockGraphics - -// ----------------------------------------------------------------------- - -static BOOL UnlockGraphics ( SalGraphics *rSalGraphics ) -{ - BOOL bCGrafPortUnlocked = FALSE; - - if ( ( rSalGraphics->maGraphicsData.mpCGrafPort != NULL ) - && ( rSalGraphics->maGraphicsData.mnOSStatus == noErr ) - ) - { - rSalGraphics->maGraphicsData.mnOSStatus - = UnlockPortBits( rSalGraphics->maGraphicsData.mpCGrafPort ); - - bCGrafPortUnlocked = TRUE; - } // if - - return bCGrafPortUnlocked; -} // UnlockGraphics - -// ======================================================================= - -// ======================================================================= - -static BOOL BeginGraphics ( SalGraphicsDataPtr rSalGraphicsData ) -{ - BOOL bStartGraphics = FALSE; - - // Previous to entering this function, was there a QD error? - - if ( rSalGraphicsData->mnOSStatus == noErr ) - { - // Get the graph port and lock focus on it - - if ( rSalGraphicsData->mbWindow == TRUE ) - { - rSalGraphicsData->mpCGrafPort - = VCLGraphics_LockFocusCGrafPort( rSalGraphicsData->mhDC ); - } // if - - if ( rSalGraphicsData->mpCGrafPort != NULL ) - { - // Get the port pen attributes - - rSalGraphicsData->mnPenModePort - = GetPortPenMode( rSalGraphicsData->mpCGrafPort ); - - // Set the port pen mode to its new value - - SetPortPenMode( rSalGraphicsData->mpCGrafPort, - rSalGraphicsData->mnPenMode - ); - - // Set to the current offscreen world for Mac OS X - // only as everything is written to GWorld here - - SetGWorld( rSalGraphicsData->mpCGrafPort, NULL ); - - // Was there a QD error when we set the GWorld? - - rSalGraphicsData->mnOSStatus = QDErr(); - - if ( rSalGraphicsData->mnOSStatus == noErr ) - { - // Get the PixMap associated with this particular CGrafPort - - rSalGraphicsData->mhGWorldPixMap - = GetPortPixMap( rSalGraphicsData->mpCGrafPort ); - - rSalGraphicsData->mnOSStatus = QDErr(); - - if ( ( rSalGraphicsData->mnOSStatus == noErr ) - && ( rSalGraphicsData->mhGWorldPixMap != NULL ) - ) - { - // Get the current PixMap state, i.e., - // is it the memory associated with this - // PixMap is marked to be moved? - - rSalGraphicsData->mnGWorldFlags - = GetPixelsState( rSalGraphicsData->mhGWorldPixMap ); - - if ( rSalGraphicsData->mnGWorldFlags == noErr ) - { - Boolean bGWorldPixelsLocked = false; - - // if the PixMap is a relocatable block, - // then mark it as locked. - - bGWorldPixelsLocked - = LockPixels( rSalGraphicsData->mhGWorldPixMap ); - - // convert the locked flag from C boolean - // to C++ BOOL - - rSalGraphicsData->mbGWorldPixelsLocked - = Boolean2BOOL( bGWorldPixelsLocked ); - - // Set background color to white on this GWorld - - SetWhiteBackColor(); - - // Set foreground color to black on this GWorld - - SetBlackForeColor(); - - // If we get here then we may safely start drawing - // to our GWorld - - bStartGraphics = TRUE; - - // Now begin to set the clip region - - if ( ( rSalGraphicsData->mbClipRgnChanged == TRUE ) - && ( rSalGraphicsData->mhClipRgn != NULL ) - ) - { - // Set to the clip region - - SetClip( rSalGraphicsData->mhClipRgn ); - - // Was there an error after setting the clip region? - - rSalGraphicsData->mnOSStatus = QDErr(); - - // Set the new status flag for our port - - rSalGraphicsData->mbClipRgnChanged = FALSE; - } // if - } // if - } // if - } // if - } // if - } // if - - return bStartGraphics; -} // BeginGraphics - -// ----------------------------------------------------------------------- - -static BOOL EndGraphics ( SalGraphicsDataPtr rSalGraphicsData ) -{ - BOOL bEndGraphics = FALSE; - - // Previous to entering this function, was there a QD error? - - if ( rSalGraphicsData->mnOSStatus == noErr ) - { - // Unlock our CGrafPort - - if ( ( rSalGraphicsData->mhGWorldPixMap != NULL ) - && ( rSalGraphicsData->mnGWorldFlags == noErr ) - && ( rSalGraphicsData->mbGWorldPixelsLocked ) - ) - { - // Set pixel state to its original state - // thus unlocking the PixMap - - SetPixelsState( rSalGraphicsData->mhGWorldPixMap, - rSalGraphicsData->mnGWorldFlags - ); - - rSalGraphicsData->mnOSStatus = QDErr(); - } // if - - // Reset the port to its original attributes - - SetPortPenMode( rSalGraphicsData->mpCGrafPort, - rSalGraphicsData->mnPenModePort - ); - - // Unlock focus on the current NSView - - if ( rSalGraphicsData->mbWindow == TRUE ) - { - VCLGraphics_UnLockFocusCGrafPort( rSalGraphicsData->mhDC ); - } // if - - // When we get here then the QD port must have changed(?) - - PortChanged( rSalGraphicsData->mpCGrafPort ); - - // Flush the QuickDraw buffer - - QDFlushPortBuffer( rSalGraphicsData->mpCGrafPort, NULL ); - - // Was there an error after flushing the QuickDraw buffer - - rSalGraphicsData->mnOSStatus = QDErr(); - - // Set the new status flag for clip region - - rSalGraphicsData->mbClipRgnChanged = FALSE; - - // If we get here then we have safely written to our GWorld - - bEndGraphics = TRUE; - } // if - - return bEndGraphics; -} // EndGraphics - -// ======================================================================= - -// ======================================================================= - -static void InitBrush ( SalGraphicsDataPtr rSalGraphicsData ) -{ - RGBColor aBlackColor; - - aBlackColor.red = 0x0000; - aBlackColor.green = 0x0000; - aBlackColor.blue = 0x0000; - - rSalGraphicsData->mbBrushTransparent = FALSE; - rSalGraphicsData->maBrushColor = aBlackColor; -} // InitBrush - -// ----------------------------------------------------------------------- - -static void InitFont ( SalGraphicsDataPtr rSalGraphicsData ) -{ - RGBColor aBlackColor; - - aBlackColor.red = 0x0000; - aBlackColor.green = 0x0000; - aBlackColor.blue = 0x0000; - - rSalGraphicsData->maFontColor = aBlackColor; - rSalGraphicsData->mnFontID = kFontIDGeneva; - rSalGraphicsData->mnFontSize = 10; - rSalGraphicsData->mnFontStyle = normal; -} // InitFont - -// ----------------------------------------------------------------------- - -static void InitGWorld ( SalGraphicsDataPtr rSalGraphicsData ) -{ - rSalGraphicsData->mbGWorldPixelsLocked = FALSE; - rSalGraphicsData->mnGWorldFlags = noErr; - rSalGraphicsData->mhGWorldPixMap = NULL; -} // InitGWorld - -// ----------------------------------------------------------------------- - -static void InitPen ( SalGraphicsDataPtr rSalGraphicsData ) -{ - RGBColor aBlackColor; - - aBlackColor.red = 0x0000; - aBlackColor.green = 0x0000; - aBlackColor.blue = 0x0000; - - rSalGraphicsData->maPenColor = aBlackColor; - rSalGraphicsData->mnPenMode = patCopy; - rSalGraphicsData->mnPenModePort = patCopy; - rSalGraphicsData->mbPenTransparent = FALSE; -} // InitPen - -// ----------------------------------------------------------------------- - -static void InitQD ( SalGraphicsDataPtr rSalGraphicsData ) -{ - rSalGraphicsData->mhDC = NULL; - rSalGraphicsData->mpCGrafPort = NULL; - rSalGraphicsData->mpGWorld = NULL; -} // InitQD - -// ----------------------------------------------------------------------- - -static void InitRegions ( SalGraphicsDataPtr rSalGraphicsData ) -{ - rSalGraphicsData->mhClipRgn = NULL; - rSalGraphicsData->mbClipRgnChanged = FALSE; -} // InitRegions +#ifndef _SV_SALCOLORUTILS_HXX +#include <salcolorutils.hxx> +#endif -// ----------------------------------------------------------------------- +#ifndef _SV_SALRECTANGLEUTILS_HXX +#include <salrectangleutils.hxx> +#endif -static void InitStatusFlags ( SalGraphicsDataPtr rSalGraphicsData ) -{ - rSalGraphicsData->mbPrinter = FALSE; - rSalGraphicsData->mbVirDev = FALSE; - rSalGraphicsData->mbWindow = FALSE; - rSalGraphicsData->mbScreen = FALSE; - rSalGraphicsData->mnOSStatus = noErr; -} // InitStatusFlags +#ifndef _SV_SALGDIUTILS_HXX +#include <salgdiutils.hxx> +#endif // ======================================================================= @@ -1656,7 +689,7 @@ void SalGraphics::CopyBits( const SalTwoRect *pPosAry, GetPortBounds( pSrcGraphics->maGraphicsData.mpCGrafPort, &aPortBoundsRect ); - CheckRectBounds( &aSrcRect, &aDstRect, &aPortBoundsRect ); + CheckRectBounds( &aPortBoundsRect, &aSrcRect, &aDstRect ); nCopyMode = SelectCopyMode( &maGraphicsData ); @@ -1731,7 +764,7 @@ void SalGraphics::CopyArea( long nDstX, GetPortBounds( maGraphicsData.mpCGrafPort, &aPortBoundsRect ); - CheckRectBounds( &aSrcRect, &aDstRect, &aPortBoundsRect ); + CheckRectBounds( &aPortBoundsRect, &aSrcRect, &aDstRect ); nCopyMode = SelectCopyMode( &maGraphicsData ); @@ -1786,7 +819,7 @@ void SalGraphics::DrawBitmap( const SalTwoRect* pPosAry, GetPortBounds( pSrcGraphics->maGraphicsData.mpCGrafPort, &aPortBoundsRect ); - CheckRectBounds( &aSrcRect, &aDstRect, &aPortBoundsRect ); + CheckRectBounds( &aPortBoundsRect, &aSrcRect, &aDstRect ); nCopyMode = SelectCopyMode( &maGraphicsData ); @@ -1850,7 +883,7 @@ void SalGraphics::DrawBitmap( const SalTwoRect* pPosAry, GetPortBounds( pSrcGraphics->maGraphicsData.mpCGrafPort, &aPortBoundsRect ); - CheckRectBounds( &aSrcRect, &aDstRect, &aPortBoundsRect ); + CheckRectBounds( &aPortBoundsRect, &aSrcRect, &aDstRect ); aBackColor = SALColor2RGBColor( nTransparentColor ); @@ -1926,7 +959,7 @@ void SalGraphics::DrawBitmap( const SalTwoRect* pPosAry, &aPortBoundsRect ); - CheckRectBounds( &aSrcRect, &aDstRect, &aPortBoundsRect ); + CheckRectBounds( &aPortBoundsRect, &aSrcRect, &aDstRect ); nCopyMode = SelectCopyMode( &maGraphicsData ); @@ -2000,7 +1033,7 @@ void SalGraphics::DrawMask( const SalTwoRect* pPosAry, GetPortBounds( pSrcGraphics->maGraphicsData.mpCGrafPort, &aPortBoundsRect ); - CheckRectBounds( &aSrcRect, &aDstRect, &aPortBoundsRect ); + CheckRectBounds( &aPortBoundsRect, &aSrcRect, &aDstRect ); aMaskBackColor = SALColor2RGBColor( nMaskColor ); diff --git a/vcl/aqua/source/gdi/salgdiutils.cxx b/vcl/aqua/source/gdi/salgdiutils.cxx new file mode 100755 index 000000000000..4df8e058a932 --- /dev/null +++ b/vcl/aqua/source/gdi/salgdiutils.cxx @@ -0,0 +1,552 @@ +/************************************************************************* + * + * $RCSfile: salgdiutils.cxx,v $ + * + * $Revision: 1.1 $ + * last change: $Author: bmahbod $ $Date: 2001-02-14 19:39:49 $ + * + * The Contents of this file are made available subject to the terms of + * either of the following licenses + * + * - GNU Lesser General Public License Version 2.1 + * - Sun Industry Standards Source License Version 1.1 + * + * Sun Microsystems Inc., October, 2000 + * + * GNU Lesser General Public License Version 2.1 + * ============================================= + * Copyright 2000 by Sun Microsystems, Inc. + * 901 San Antonio Road, Palo Alto, CA 94303, USA + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License version 2.1, as published by the Free Software Foundation. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, + * MA 02111-1307 USA + * + * + * Sun Industry Standards Source License Version 1.1 + * ================================================= + * The contents of this file are subject to the Sun Industry Standards + * Source License Version 1.1 (the "License"); You may not use this file + * except in compliance with the License. You may obtain a copy of the + * License at http://www.openoffice.org/license.html. + * + * Software provided under this License is provided on an "AS IS" basis, + * WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, + * WITHOUT LIMITATION, WARRANTIES THAT THE SOFTWARE IS FREE OF DEFECTS, + * MERCHANTABLE, FIT FOR A PARTICULAR PURPOSE, OR NON-INFRINGING. + * See the License for the specific provisions governing your rights and + * obligations concerning the Software. + * + * The Initial Developer of the Original Code is: Sun Microsystems, Inc. + * + * Copyright: 2000 by Sun Microsystems, Inc. + * + * All Rights Reserved. + * + * Contributor(s): _______________________________________ + * + * + ************************************************************************/ + +#define _SV_SALGDIUTILS_CXX + +#ifndef _SV_SALCONST_H +#include <salconst.h> +#endif + +#ifndef _SV_SALDATA_HXX +#include <saldata.hxx> +#endif + +#ifndef _SV_SALGDI_HXX +#include <salgdi.hxx> +#endif + +#ifndef _SV_VCLGRAPHICS_H +#include <VCLGraphics.h> +#endif + +#ifndef _SV_SALCOLORUTILS_HXX +#include <salcolorutils.hxx> +#endif + +#ifndef _SV_SALGDIUTILS_HXX +#include <salgdiutils.hxx> +#endif + +// ======================================================================= + +// ======================================================================= + +short SelectCopyMode ( const SalGraphicsDataPtr pSalGraphicsData ) +{ + short nCopyMode = 0; + + if ( pSalGraphicsData->mnPenMode == patCopy ) + { + nCopyMode = srcCopy; + } // if + else + { + nCopyMode = srcXor; + } // else + + return nCopyMode; +} // SelectCopyMode + +// ======================================================================= + +// ======================================================================= + +RgnHandle GetPolygonRgn ( const unsigned long nPolyCount, + const unsigned long *pPoints, + PCONSTSALPOINT *ppPtAry, + OSStatus *rQDStatus + ) +{ + RgnHandle hSrcRgnA = NULL; + + hSrcRgnA = NewRgn(); + + if ( hSrcRgnA != NULL ) + { + RgnHandle hSrcRgnB = NULL; + + hSrcRgnB = NewRgn(); + + if ( hSrcRgnB != NULL ) + { + unsigned short nPolyEdgeIndex = 0; + unsigned short nPolyIndex = 0; + unsigned short nPolyEdges = 0; + + for ( nPolyIndex = 0; + nPolyIndex < nPolyCount; + nPolyIndex++ + ) + { + const SalPoint *pPtAry = ppPtAry[nPolyIndex]; + + nPolyEdges = pPoints[nPolyIndex]; + + // Begin region construction + + OpenRgn(); + + // Begin polygon construction + + MoveTo( pPtAry[0].mnX, pPtAry[0].mnY ); + + for ( nPolyEdgeIndex = 1; + nPolyEdgeIndex < nPolyEdges; + nPolyEdgeIndex++ + ) + { + MacLineTo( pPtAry[nPolyEdgeIndex].mnX, + pPtAry[nPolyEdgeIndex].mnY + ); + } // for + + MacLineTo( pPtAry[0].mnX, pPtAry[0].mnY ); + + // End polygon construction + + CloseRgn( hSrcRgnB ); + + // End region construction + + *rQDStatus = QDErr(); + + if ( *rQDStatus == noErr ) + { + if ( nPolyIndex == 0 ) + { + MacCopyRgn( hSrcRgnB, hSrcRgnA ); + } // if + else + { + MacXorRgn( hSrcRgnA, hSrcRgnB, hSrcRgnA ); + } // else + } // if + } // for + + DisposeRgn( hSrcRgnB ); + + *rQDStatus = QDErr(); + + if ( *rQDStatus != noErr ) + { + DisposeRgn( hSrcRgnA ); + + hSrcRgnA = NULL; + } + + hSrcRgnB = NULL; + } // if + } // if + + return hSrcRgnA; +} // GetPolygonRgn + +// ======================================================================= + +// ======================================================================= + +OSStatus GetGDeviceBitDepth ( unsigned short *rGDeviceBitDepth ) +{ + GDPtr pGDevice = NULL; + OSStatus nOSStatus = noErr; + + pGDevice = *GetGDevice ( ); + + nOSStatus = QDErr(); + + if ( ( pGDevice != NULL ) && ( nOSStatus == noErr ) ) + { + *rGDeviceBitDepth = GetPixDepth( pGDevice->gdPMap ); + } // if + + return nOSStatus; +} // GetGDeviceBitDepth + +// ----------------------------------------------------------------------- + +OSStatus GetGDeviceResolution ( long *rGDeviceHRes, + long *rGDeviceVRes + ) +{ + GDPtr pGDevice = NULL; + OSStatus nOSStatus = noErr; + + pGDevice = *GetGDevice ( ); + + nOSStatus = QDErr(); + + if ( ( pGDevice != NULL ) && ( nOSStatus == noErr ) ) + { + long nGDeviceTop = pGDevice->gdRect.top; + long nGDeviceLeft = pGDevice->gdRect.left; + long nGDeviceBottom = pGDevice->gdRect.bottom; + long nGDeviceRight = pGDevice->gdRect.right; + + // From the current GDevice get its horizontal resolution + + *rGDeviceHRes = abs( nGDeviceRight - nGDeviceLeft ); + + // From the current GDevice get its vertical resolution + + *rGDeviceVRes = abs( nGDeviceBottom - nGDeviceTop ); + } // if + + return nOSStatus; +} // GetGDeviceResolution + +// ======================================================================= + +// ======================================================================= + +BOOL LockGraphics ( SalGraphics *rSalGraphics ) +{ + BOOL bCGrafPortLocked = FALSE; + + if ( ( rSalGraphics != NULL ) + && ( rSalGraphics->maGraphicsData.mpCGrafPort != NULL ) + ) + { + rSalGraphics->maGraphicsData.mnOSStatus + = LockPortBits( rSalGraphics->maGraphicsData.mpCGrafPort ); + + if ( rSalGraphics->maGraphicsData.mnOSStatus == noErr ) + { + rSalGraphics->maGraphicsData.mhGWorldPixMap + = GetPortPixMap( rSalGraphics->maGraphicsData.mpCGrafPort ); + + rSalGraphics->maGraphicsData.mnOSStatus = QDErr(); + + bCGrafPortLocked = TRUE; + } // if + } // if + + return bCGrafPortLocked; +} // LockGraphics + +// ----------------------------------------------------------------------- + +BOOL UnlockGraphics ( SalGraphics *rSalGraphics ) +{ + BOOL bCGrafPortUnlocked = FALSE; + + if ( ( rSalGraphics->maGraphicsData.mpCGrafPort != NULL ) + && ( rSalGraphics->maGraphicsData.mnOSStatus == noErr ) + ) + { + rSalGraphics->maGraphicsData.mnOSStatus + = UnlockPortBits( rSalGraphics->maGraphicsData.mpCGrafPort ); + + bCGrafPortUnlocked = TRUE; + } // if + + return bCGrafPortUnlocked; +} // UnlockGraphics + +// ======================================================================= + +// ======================================================================= + +BOOL BeginGraphics ( SalGraphicsDataPtr rSalGraphicsData ) +{ + BOOL bStartGraphics = FALSE; + + // Previous to entering this function, was there a QD error? + + if ( rSalGraphicsData->mnOSStatus == noErr ) + { + // Get the graph port and lock focus on it + + if ( rSalGraphicsData->mbWindow == TRUE ) + { + rSalGraphicsData->mpCGrafPort + = VCLGraphics_LockFocusCGrafPort( rSalGraphicsData->mhDC ); + } // if + + if ( rSalGraphicsData->mpCGrafPort != NULL ) + { + // Get the port pen attributes + + rSalGraphicsData->mnPenModePort + = GetPortPenMode( rSalGraphicsData->mpCGrafPort ); + + // Set the port pen mode to its new value + + SetPortPenMode( rSalGraphicsData->mpCGrafPort, + rSalGraphicsData->mnPenMode + ); + + // Set to the current offscreen world for Mac OS X + // only as everything is written to GWorld here + + SetGWorld( rSalGraphicsData->mpCGrafPort, NULL ); + + // Was there a QD error when we set the GWorld? + + rSalGraphicsData->mnOSStatus = QDErr(); + + if ( rSalGraphicsData->mnOSStatus == noErr ) + { + // Get the PixMap associated with this particular CGrafPort + + rSalGraphicsData->mhGWorldPixMap + = GetPortPixMap( rSalGraphicsData->mpCGrafPort ); + + rSalGraphicsData->mnOSStatus = QDErr(); + + if ( ( rSalGraphicsData->mnOSStatus == noErr ) + && ( rSalGraphicsData->mhGWorldPixMap != NULL ) + ) + { + // Get the current PixMap state, i.e., + // is it the memory associated with this + // PixMap is marked to be moved? + + rSalGraphicsData->mnGWorldFlags + = GetPixelsState( rSalGraphicsData->mhGWorldPixMap ); + + if ( rSalGraphicsData->mnGWorldFlags == noErr ) + { + // if the PixMap is a relocatable block, + // then mark it as locked. + + if ( LockPixels( rSalGraphicsData->mhGWorldPixMap ) ) + { + rSalGraphicsData->mbGWorldPixelsLocked = TRUE; + } // if + else + { + rSalGraphicsData->mbGWorldPixelsLocked = FALSE; + } // else + + // Set background color to white on this GWorld + + SetWhiteBackColor(); + + // Set foreground color to black on this GWorld + + SetBlackForeColor(); + + // If we get here then we may safely start drawing + // to our GWorld + + bStartGraphics = TRUE; + + // Now begin to set the clip region + + if ( ( rSalGraphicsData->mbClipRgnChanged == TRUE ) + && ( rSalGraphicsData->mhClipRgn != NULL ) + ) + { + // Set to the clip region + + SetClip( rSalGraphicsData->mhClipRgn ); + + // Was there an error after setting the clip region? + + rSalGraphicsData->mnOSStatus = QDErr(); + + // Set the new status flag for our port + + rSalGraphicsData->mbClipRgnChanged = FALSE; + } // if + } // if + } // if + } // if + } // if + } // if + + return bStartGraphics; +} // BeginGraphics + +// ----------------------------------------------------------------------- + +BOOL EndGraphics ( SalGraphicsDataPtr rSalGraphicsData ) +{ + BOOL bEndGraphics = FALSE; + + // Previous to entering this function, was there a QD error? + + if ( rSalGraphicsData->mnOSStatus == noErr ) + { + // Unlock our CGrafPort + + if ( ( rSalGraphicsData->mhGWorldPixMap != NULL ) + && ( rSalGraphicsData->mnGWorldFlags == noErr ) + && ( rSalGraphicsData->mbGWorldPixelsLocked ) + ) + { + // Set pixel state to its original state + // thus unlocking the PixMap + + SetPixelsState( rSalGraphicsData->mhGWorldPixMap, + rSalGraphicsData->mnGWorldFlags + ); + + rSalGraphicsData->mnOSStatus = QDErr(); + } // if + + // Reset the port to its original attributes + + SetPortPenMode( rSalGraphicsData->mpCGrafPort, + rSalGraphicsData->mnPenModePort + ); + + // Unlock focus on the current NSView + + if ( rSalGraphicsData->mbWindow == TRUE ) + { + VCLGraphics_UnLockFocusCGrafPort( rSalGraphicsData->mhDC ); + } // if + + // When we get here then the QD port must have changed(?) + + PortChanged( rSalGraphicsData->mpCGrafPort ); + + // Flush the QuickDraw buffer + + QDFlushPortBuffer( rSalGraphicsData->mpCGrafPort, NULL ); + + // Was there an error after flushing the QuickDraw buffer + + rSalGraphicsData->mnOSStatus = QDErr(); + + // Set the new status flag for clip region + + rSalGraphicsData->mbClipRgnChanged = FALSE; + + // If we get here then we have safely written to our GWorld + + bEndGraphics = TRUE; + } // if + + return bEndGraphics; +} // EndGraphics + +// ======================================================================= + +// ======================================================================= + +void InitBrush ( SalGraphicsDataPtr rSalGraphicsData ) +{ + rSalGraphicsData->mbBrushTransparent = FALSE; + rSalGraphicsData->maBrushColor = GetBlackColor(); +} // InitBrush + +// ----------------------------------------------------------------------- + +void InitFont ( SalGraphicsDataPtr rSalGraphicsData ) +{ + rSalGraphicsData->maFontColor = GetBlackColor(); + rSalGraphicsData->mnFontID = kFontIDGeneva; + rSalGraphicsData->mnFontSize = 10; + rSalGraphicsData->mnFontStyle = normal; +} // InitFont + +// ----------------------------------------------------------------------- + +void InitGWorld ( SalGraphicsDataPtr rSalGraphicsData ) +{ + rSalGraphicsData->mbGWorldPixelsLocked = FALSE; + rSalGraphicsData->mnGWorldFlags = noErr; + rSalGraphicsData->mhGWorldPixMap = NULL; +} // InitGWorld + +// ----------------------------------------------------------------------- + +void InitPen ( SalGraphicsDataPtr rSalGraphicsData ) +{ + rSalGraphicsData->maPenColor = GetBlackColor(); + rSalGraphicsData->mnPenMode = patCopy; + rSalGraphicsData->mnPenModePort = patCopy; + rSalGraphicsData->mbPenTransparent = FALSE; +} // InitPen + +// ----------------------------------------------------------------------- + +void InitQD ( SalGraphicsDataPtr rSalGraphicsData ) +{ + rSalGraphicsData->mhDC = NULL; + rSalGraphicsData->mpCGrafPort = NULL; + rSalGraphicsData->mpGWorld = NULL; +} // InitQD + +// ----------------------------------------------------------------------- + +void InitRegions ( SalGraphicsDataPtr rSalGraphicsData ) +{ + rSalGraphicsData->mhClipRgn = NULL; + rSalGraphicsData->mbClipRgnChanged = FALSE; +} // InitRegions + +// ----------------------------------------------------------------------- + +void InitStatusFlags ( SalGraphicsDataPtr rSalGraphicsData ) +{ + rSalGraphicsData->mbPrinter = FALSE; + rSalGraphicsData->mbVirDev = FALSE; + rSalGraphicsData->mbWindow = FALSE; + rSalGraphicsData->mbScreen = FALSE; + rSalGraphicsData->mnOSStatus = noErr; +} // InitStatusFlags + +// ======================================================================= + +// ======================================================================= + diff --git a/vcl/aqua/source/gdi/salmathutils.cxx b/vcl/aqua/source/gdi/salmathutils.cxx new file mode 100755 index 000000000000..a62e1d6ffc0c --- /dev/null +++ b/vcl/aqua/source/gdi/salmathutils.cxx @@ -0,0 +1,201 @@ +/************************************************************************* + * + * $RCSfile: salmathutils.cxx,v $ + * + * $Revision: 1.1 $ + * last change: $Author: bmahbod $ $Date: 2001-02-14 19:39:49 $ + * + * The Contents of this file are made available subject to the terms of + * either of the following licenses + * + * - GNU Lesser General Public License Version 2.1 + * - Sun Industry Standards Source License Version 1.1 + * + * Sun Microsystems Inc., October, 2000 + * + * GNU Lesser General Public License Version 2.1 + * ============================================= + * Copyright 2000 by Sun Microsystems, Inc. + * 901 San Antonio Road, Palo Alto, CA 94303, USA + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License version 2.1, as published by the Free Software Foundation. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, + * MA 02111-1307 USA + * + * + * Sun Industry Standards Source License Version 1.1 + * ================================================= + * The contents of this file are subject to the Sun Industry Standards + * Source License Version 1.1 (the "License"); You may not use this file + * except in compliance with the License. You may obtain a copy of the + * License at http://www.openoffice.org/license.html. + * + * Software provided under this License is provided on an "AS IS" basis, + * WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, + * WITHOUT LIMITATION, WARRANTIES THAT THE SOFTWARE IS FREE OF DEFECTS, + * MERCHANTABLE, FIT FOR A PARTICULAR PURPOSE, OR NON-INFRINGING. + * See the License for the specific provisions governing your rights and + * obligations concerning the Software. + * + * The Initial Developer of the Original Code is: Sun Microsystems, Inc. + * + * Copyright: 2000 by Sun Microsystems, Inc. + * + * All Rights Reserved. + * + * Contributor(s): _______________________________________ + * + * + ************************************************************************/ + +#define _SV_SALMATHUTILS_CXX + +#ifndef _SV_SALCOLORUTILS_HXX +#include <salmathutils.hxx> +#endif + +// ======================================================================= + +// ======================================================================= + +// Storage free swapping using XOR + +void CSwap ( char &rX, char &rY ) +{ + rX ^= rY; + rY ^= rX; + rX ^= rY; +} // CSwap + +// ----------------------------------------------------------------------- + +// Storage free swapping using XOR + +void UCSwap ( unsigned char &rX, unsigned char &rY ) +{ + rX ^= rY; + rY ^= rX; + rX ^= rY; +} // UCSwap + +// ----------------------------------------------------------------------- + +// Storage free swapping using XOR + +void SSwap ( short &rX, short &rY ) +{ + rX ^= rY; + rY ^= rX; + rX ^= rY; +} // SSwap + +// ----------------------------------------------------------------------- + +// Storage free swapping using XOR + +void USSwap ( unsigned short &rX, unsigned short &rY ) +{ + rX ^= rY; + rY ^= rX; + rX ^= rY; +} // USSwap + +// ----------------------------------------------------------------------- + +// Storage free swapping using XOR + +void LSwap ( long &rX, long &rY ) +{ + rX ^= rY; + rY ^= rX; + rX ^= rY; +} // LSwap + +// ----------------------------------------------------------------------- + +// Storage free swapping using XOR + +void ULSwap ( unsigned long &rX, unsigned long &rY ) +{ + rX ^= rY; + rY ^= rX; + rX ^= rY; +} // ULSwap + +// ======================================================================= + +// ======================================================================= + +// ----------------------------------------------------------------------- +// +// This way of measuring distance is also called the "Manhattan distance." +// Manhattan distance takes advantage of the fact that the sum of the +// lengths of the three components of a 3D vector is a rough approxima- +// tion of the vector's length. +// +// ----------------------------------------------------------------------- + +unsigned long Euclidian2Norm ( const LRectCoorVector pVec ) +{ + unsigned long ndist = 0; + + if ( pVec ) + { + long nDX = 0; + long nDY = 0; + long nDZ = 0; + unsigned long nMax = 0; + unsigned long nMed = 0; + unsigned long nMin = 0; + + // Find |x'-x|, |y'-y|, and |z'-z| from (x,y,z) and (x',y',z') + + nDX = pVec[1].x - pVec[0].x; + nDY = pVec[1].y - pVec[0].y; + nDZ = pVec[1].z - pVec[0].z; + + nMax = (unsigned long)abs( nDX ); + nMed = (unsigned long)abs( nDY ); + nMin = (unsigned long)abs( nDZ ); + + // Sort them (3 compares, 0-3 swaps) + + if ( nMax < nMed ) + { + ULSwap( nMax, nMed ); + } // if + + if ( nMax < nMin ) + { + ULSwap( nMax, nMin ); + } // if + + // Approximate Euclidian distance: + // + // d = max + (11/32)*med + (1/4)*min + // + // with +/- 8% error, where the exact formulae for d is + // + // || (x',y',z') - (x,y,z) || = { |x'-x|^2 + |y'-y|^2 + |z'-z|^2 }^(1/2) + + ndist = nMax + ( nMin >> 2UL ) + + ( ( ( nMed << 3UL ) + ( nMed << 1UL ) + nMed ) >> 5UL ); + } // if + + return ndist; +} // RGBDistance + +// ======================================================================= + +// ======================================================================= + diff --git a/vcl/aqua/source/gdi/salpixmaputils.cxx b/vcl/aqua/source/gdi/salpixmaputils.cxx new file mode 100755 index 000000000000..5807093c52ed --- /dev/null +++ b/vcl/aqua/source/gdi/salpixmaputils.cxx @@ -0,0 +1,621 @@ +/************************************************************************* + * + * $RCSfile: salpixmaputils.cxx,v $ + * + * $Revision: 1.1 $ + * + * last change: $Author: bmahbod $ $Date: 2001-02-14 19:39:49 $ + * + * The Contents of this file are made available subject to the terms of + * either of the following licenses + * + * - GNU Lesser General Public License Version 2.1 + * - Sun Industry Standards Source License Version 1.1 + * + * Sun Microsystems Inc., October, 2000 + * + * GNU Lesser General Public License Version 2.1 + * ============================================= + * Copyright 2000 by Sun Microsystems, Inc. + * 901 San Antonio Road, Palo Alto, CA 94303, USA + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License version 2.1, as published by the Free Software Foundation. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, + * MA 02111-1307 USA + * + * + * Sun Industry Standards Source License Version 1.1 + * ================================================= + * The contents of this file are subject to the Sun Industry Standards + * Source License Version 1.1 (the "License"); You may not use this file + * except in compliance with the License. You may obtain a copy of the + * License at http://www.openoffice.org/license.html. + * + * Software provided under this License is provided on an "AS IS" basis, + * WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, + * WITHOUT LIMITATION, WARRANTIES THAT THE SOFTWARE IS FREE OF DEFECTS, + * MERCHANTABLE, FIT FOR A PARTICULAR PURPOSE, OR NON-INFRINGING. + * See the License for the specific provisions governing your rights and + * obligations concerning the Software. + * + * The Initial Developer of the Original Code is: Sun Microsystems, Inc. + * + * Copyright: 2000 by Sun Microsystems, Inc. + * + * All Rights Reserved. + * + * Contributor(s): _______________________________________ + * + * + ************************************************************************/ + +#define _SV_SALPIXMAPUTILS_CXX + +#ifndef _SV_SALCONST_H +#include <salconst.h> +#endif + +#ifndef _SV_SALCOLORUTILS_HXX +#include <salcolorutils.hxx> +#endif + +#ifndef _SV_SALPIXMAPUTILS_HXX +#include <salpixmaputils.hxx> +#endif + +// ======================================================================= + +// ======================================================================= + +static inline long GetPixMapHeight( const Rect *rPixMapBoundsRect ) +{ + long nPixMapHeight = rPixMapBoundsRect->bottom - rPixMapBoundsRect->top; + + return nPixMapHeight; +} // GetPixMapHeight + +// ------------------------------------------------------------------ + +static inline long GetPixMapWidth ( const Rect *rPixMapBoundsRect ) +{ + long nPixMapWidth = rPixMapBoundsRect->right - rPixMapBoundsRect->left; + + return nPixMapWidth; +} // GetPixMapWidth + +// ------------------------------------------------------------------ + +static inline Fixed GetPixMapRes( const long nPixMapRes ) +{ + Fixed aPixMapRes = Long2Fix( nPixMapRes ); + + return aPixMapRes; +} // GetPixMapHRes + +// ------------------------------------------------------------------ + +static inline long GetPixMapBitDepth( const USHORT nPixMapBits ) +{ + long nPixMapBitDepth = 0; + + if ( nPixMapBits <= kThousandsColor ) + { + nPixMapBitDepth = (long)nPixMapBits; + } // if + else + { + nPixMapBitDepth = kTrueColor; + } // else + + return nPixMapBitDepth; +} // GetNewPixMapDepth + +// ------------------------------------------------------------------ + +static inline long GetPixMapOffset ( const long nPixMapBitDepth, + const short nPixMapWidth + ) +{ + long nPixMapImageWidth = nPixMapBitDepth * (long)nPixMapWidth; + long nPixMapOffset = ( ( nPixMapImageWidth + 15L ) >> 4L ) << 1L; + + return nPixMapOffset; +} // GetPixMapOffset + +// ------------------------------------------------------------------ + +static inline long GetPixMapImageSize ( const short nPixMapHeight, + const long nPixMapRowOffset + ) +{ + long nPixMapImageSize = (long)nPixMapHeight * nPixMapRowOffset; + + return nPixMapImageSize; +} // GetPixMapImageSize + +// ------------------------------------------------------------------ + +static inline short GetPixMapRowBytes ( const long nPixMapRowOffset ) +{ + short nPixMapRowBytes = (short)nPixMapRowOffset + 0x8000; + + return nPixMapRowBytes; +} // GetPixMapRowBytes + +// ------------------------------------------------------------------ + +static inline short GetPixMapColorDepth ( const USHORT nPixMapBits ) +{ + short nPixMapColorDepth = 0; + + if ( nPixMapBits <= kEightBits ) + { + nPixMapColorDepth = kOneBit << ((short)nPixMapBits); + } + + return nPixMapColorDepth; +} // GetPixMapColorDepth + +// ------------------------------------------------------------------ + +static void GetPixMapBoudsRect ( const short nPixMapWidth, + const short nPixMapHeight, + Rect *rPixMapBoundsRect + ) +{ + short nPixMapRectLeft = 0; + short nPixMapRectTop = 0; + short nPixMapRectRight = nPixMapWidth; + short nPixMapRectBottom = nPixMapHeight; + + // Set the dimensions of the PixMap + + MacSetRect( rPixMapBoundsRect, + nPixMapRectLeft, + nPixMapRectTop, + nPixMapRectRight, + nPixMapRectBottom + ); +} // GetPixMapBoudsRect + +// ------------------------------------------------------------------ + +static inline short GetPixMapCmpSize ( const long nPixMapBitDepth ) +{ + short nPixMapCmpSize = 0; + + if ( nPixMapBitDepth <= kEightBitColor ) + { + nPixMapCmpSize = nPixMapBitDepth; + } // if + else if ( nPixMapBitDepth == kThousandsColor ) + { + nPixMapCmpSize = kPixMapCmpSizeFiveBits; + } // else if + else + { + nPixMapCmpSize = kPixMapCmpSizeEightBits; + } // else + + return nPixMapCmpSize; +} // GetPixMapCmpSize + +// ------------------------------------------------------------------ + +static inline short GetPixMapCmpCount ( const long nPixMapBitDepth ) +{ + short nPixMapCmpCount = 0; + + if ( nPixMapBitDepth <= kEightBitColor ) + { + nPixMapCmpCount = 1; + } // if + else + { + nPixMapCmpCount = 3; + } // else + + return nPixMapCmpCount; +} // GetPixMapCmpCount + +// ------------------------------------------------------------------ + +static inline short GetPixMapPixelType ( const long nPixMapBitDepth ) +{ + short nPixMapPixelType = 0; + + if ( nPixMapBitDepth <= kEightBitColor ) + { + nPixMapPixelType = 0; + } // if + else + { + nPixMapPixelType = RGBDirect; + } // else + + return nPixMapPixelType; +} // GetPixMapPixelType + +// ------------------------------------------------------------------ + +static inline OSType GetPixMapPixelFormat ( ) +{ + OSType nPixMapPixelFormat = NULL; + GDPtr pGDevice = NULL; + + pGDevice = *GetGDevice( ); + + if ( pGDevice != NULL ) + { + PixMapPtr pPixMap = NULL; + + pPixMap = *(*pGDevice).gdPMap; + + if ( pPixMap != NULL ) + { + nPixMapPixelFormat = pPixMap->pixelFormat; + } // if + } // if + + return nPixMapPixelFormat; +} // GetPixMapPixelFormat + +// ======================================================================= + +// ======================================================================= + +static CTabHandle GetPixMapCTabBitmapPalette ( const short nPixMapColorDepth, + const BitmapPalette &rBitmapPalette + ) +{ + CTabHandle hPixMapCTab = NULL; + + hPixMapCTab = (CTabHandle) NewHandleClear( sizeof( ColorTable ) + + sizeof( ColorSpec ) + * ( nPixMapColorDepth - 1 ) + ); + + if ( ( hPixMapCTab != NULL ) && ( *hPixMapCTab != NULL ) ) + { + SInt8 nFlags = noErr; + + nFlags = HGetState( (Handle)hPixMapCTab ); + + if ( nFlags == noErr ) + { + short nBitmapPaletteMinCount = GetMinColorCount(nPixMapColorDepth, rBitmapPalette); + short nBitmapPaletteIndex = 0; + + HLock( (Handle)hPixMapCTab ); + + (**hPixMapCTab).ctSeed = GetCTSeed(); + (**hPixMapCTab).ctFlags = 0; + (**hPixMapCTab).ctSize = nPixMapColorDepth - 1; + + for ( nBitmapPaletteIndex = 0; + nBitmapPaletteIndex < nBitmapPaletteMinCount; + nBitmapPaletteIndex++ + ) + { + const BitmapColor &rBitmapPaletteColor = rBitmapPalette[nBitmapPaletteIndex]; + + (**hPixMapCTab).ctTable[nBitmapPaletteIndex].value + = nBitmapPaletteIndex; + + (**hPixMapCTab).ctTable[nBitmapPaletteIndex].rgb + = BitmapColor2RGBColor( rBitmapPaletteColor ); + } // for + + HSetState( (Handle)hPixMapCTab, nFlags ); + } // if + } // if + + return hPixMapCTab; +} // GetPixMapCTabBitmapPalette + +// ------------------------------------------------------------------ + +static CTabHandle GetCTabRGBDirect ( const short nPixMapCmpSize ) +{ + CTabHandle hPixMapCTab = NULL; + + hPixMapCTab = (CTabHandle)NewHandleClear( sizeof( ColorTable ) + - sizeof( CSpecArray ) + ); + + if ( ( hPixMapCTab != NULL ) && ( *hPixMapCTab != NULL ) ) + { + SInt8 nFlags = noErr; + + nFlags = HGetState( (Handle)hPixMapCTab ); + + if ( nFlags == noErr ) + { + HLock( (Handle)hPixMapCTab ); + + (**hPixMapCTab).ctSeed = 3 * nPixMapCmpSize; + (**hPixMapCTab).ctFlags = 0; + (**hPixMapCTab).ctSize = 0; + + HSetState( (Handle)hPixMapCTab, nFlags ); + } // if + } // if + + return hPixMapCTab; +} // GetCTabRGBDirect + +// ------------------------------------------------------------------ + +static CTabHandle GetPixMapCTab ( const long nPixMapBitDepth, + const short nPixMapColorDepth, + const short nPixMapCmpSize, + const BitmapPalette &rBitmapPalette + ) +{ + CTabHandle hPixMapCTab = NULL; + + if ( nPixMapBitDepth <= kEightBitColor ) + { + hPixMapCTab = GetPixMapCTabBitmapPalette( nPixMapColorDepth, + rBitmapPalette + ); + + if ( hPixMapCTab == NULL ) + { + hPixMapCTab = GetCTabFromStdCLUT( nPixMapBitDepth ); + + if ( hPixMapCTab == NULL ) + { + hPixMapCTab = CopyGDeviceCTab( ); + } // if + } // if + } // if + else + { + hPixMapCTab = GetCTabRGBDirect( nPixMapCmpSize ); + } // else + + return hPixMapCTab; +} // GetPixMapCTab + +// ======================================================================= + +// ======================================================================= + +PixMapHandle GetNewPixMap ( const Size &rPixMapSize, + const USHORT nPixMapBits, + const BitmapPalette &rBitmapPalette + ) +{ + PixMapHandle hPixMap = NULL; + short nPixMapWidth = rPixMapSize.Width(); + short nPixMapHeight = rPixMapSize.Height(); + + if ( ( nPixMapWidth > 0 ) && ( nPixMapHeight > 0 ) ) + { + hPixMap = NewPixMap(); + + if ( ( hPixMap != NULL ) && ( *hPixMap != NULL ) ) + { + const long nPixMapBitDepth = GetPixMapBitDepth( nPixMapBits); + const long nPixMapRowOffset = GetPixMapOffset( nPixMapBitDepth, nPixMapWidth ); + const long nPixMapImageSize = GetPixMapImageSize( nPixMapHeight, nPixMapRowOffset ); + char *pPixMapData = NewPtrClear( nPixMapImageSize ); + + if ( pPixMapData != NULL ) + { + GWorldFlags nPixMapFlags = noErr; + + nPixMapFlags = GetPixelsState( hPixMap ); + + if ( nPixMapFlags == noErr ) + { + if ( LockPixels( hPixMap ) ) + { + const short nPixMapRowBytes = GetPixMapRowBytes( nPixMapRowOffset ); + const short nPixMapColorDepth = GetPixMapColorDepth( nPixMapBits ); + const short nPixMapCmpSize = GetPixMapCmpSize( nPixMapBitDepth ); + const short nPixMapCmpCount = GetPixMapCmpCount( nPixMapBitDepth ); + const short nPixMapPixelType = GetPixMapPixelType( nPixMapBitDepth ); + const OSType aPixMapPixelFormat = GetPixMapPixelFormat( ); + const Fixed aPixMapHRes = GetPixMapRes( kPixMapHRes ); + const Fixed aPixMapVRes = GetPixMapRes( kPixMapVRes ); + Rect aPixMapBoundsRect; + + GetPixMapBoudsRect( nPixMapWidth, nPixMapHeight, &aPixMapBoundsRect ); + + (**hPixMap).baseAddr = pPixMapData; // Pointer to pixels + (**hPixMap).rowBytes = nPixMapRowBytes; // Offset to next line + (**hPixMap).bounds = aPixMapBoundsRect; // Bounding bitmap rectangle + (**hPixMap).pmVersion = 0; // PixMap version number + (**hPixMap).packType = 0; // Defines packing format + (**hPixMap).packSize = 0; // Length of pixel data + (**hPixMap).hRes = aPixMapHRes; // Horizontal resolution (ppi) + (**hPixMap).vRes = aPixMapVRes; // Vertical resolution (ppi) + (**hPixMap).pixelType = nPixMapPixelType; // Defines pixel type + (**hPixMap).pixelSize = nPixMapBitDepth; // Number of bits in a pixel + (**hPixMap).cmpCount = nPixMapCmpCount; // Number of components in a pixel + (**hPixMap).cmpSize = nPixMapCmpSize; // Number of bits per component + (**hPixMap).pixelFormat = aPixMapPixelFormat; // Four character code representation + (**hPixMap).pmExt = NULL; // Handle to PixMap extension + + // Get the color table based on the desired screen depth + + (**hPixMap).pmTable = GetPixMapCTab( nPixMapBitDepth, + nPixMapColorDepth, + nPixMapCmpSize, + rBitmapPalette + ); + + SetPixelsState( hPixMap, nPixMapFlags ); + } // if + } // if + } // if + else + { + DisposePixMap( hPixMap ); + + hPixMap = NULL; + } // else + } // if + } // if + + return hPixMap; +} // GetNewPixMap + +// ======================================================================= + +// ======================================================================= + +PixMapHandle CopyPixMap ( PixMapHandle hPixMap ) +{ + PixMapHandle hPixMapCopy = NULL; + GWorldFlags nPixMapFlags = noErr; + + nPixMapFlags = GetPixelsState( hPixMap ); + + if ( nPixMapFlags == noErr ) + { + if ( LockPixels( hPixMap ) ) + { + hPixMapCopy = NewPixMap(); + + if ( ( hPixMapCopy != NULL ) && ( *hPixMapCopy != NULL ) ) + { + const Rect aPixMapBoundsRect = (**hPixMap).bounds; + const long nPixMapBitDepth = (**hPixMap).pixelSize; + const long nPixMapWidth = GetPixMapWidth( &aPixMapBoundsRect ); + const long nPixMapHeight = GetPixMapHeight( &aPixMapBoundsRect ); + const long nPixMapRowOffset = GetPixMapOffset( nPixMapBitDepth, nPixMapWidth ); + const long nPixMapImageSize = GetPixMapImageSize( nPixMapHeight, nPixMapRowOffset ); + char *pPixMapDataCopy = NewPtrClear( nPixMapImageSize ); + + if ( pPixMapDataCopy != NULL ) + { + GWorldFlags nPixMapCopyFlags = noErr; + + nPixMapCopyFlags = GetPixelsState( hPixMapCopy ); + + if ( nPixMapCopyFlags == noErr ) + { + if ( LockPixels( hPixMapCopy ) ) + { + const char *pPixMapData = (**hPixMap).baseAddr; + + // Copy the data from the original port + + BlockMoveData( pPixMapData, pPixMapDataCopy, nPixMapImageSize ); + + (**hPixMapCopy).rowBytes = (**hPixMap).rowBytes; // Offset to next line + (**hPixMapCopy).bounds = (**hPixMap).bounds; // Bounding bitmap rectangle + (**hPixMapCopy).pmVersion = (**hPixMap).pmVersion; // PixMap version number + (**hPixMapCopy).packType = (**hPixMap).packType; // Defines packing format + (**hPixMapCopy).packSize = (**hPixMap).packSize; // Length of pixel data + (**hPixMapCopy).hRes = (**hPixMap).hRes; // Horizontal resolution (ppi) + (**hPixMapCopy).vRes = (**hPixMap).vRes; // Vertical resolution (ppi) + (**hPixMapCopy).pixelType = (**hPixMap).pixelType; // Defines pixel type + (**hPixMapCopy).pixelSize = (**hPixMap).pixelSize; // Number of bits in a pixel + (**hPixMapCopy).cmpCount = (**hPixMap).cmpCount; // Number of components in a pixel + (**hPixMapCopy).cmpSize = (**hPixMap).cmpSize; // Number of bits per component + (**hPixMapCopy).pixelFormat = (**hPixMap).pixelFormat; // Four character code representation + (**hPixMapCopy).pmExt = (**hPixMap).pmExt; // Handle to PixMap extension + + // Copy the color table from the original port + + (**hPixMapCopy).pmTable = CopyPixMapCTab( hPixMap ); + + SetPixelsState( hPixMapCopy, nPixMapCopyFlags ); + } // if + else + { + DisposePtr( pPixMapDataCopy ); + + pPixMapDataCopy = NULL; + } // else + } // if + else + { + DisposePtr( pPixMapDataCopy ); + + pPixMapDataCopy = NULL; + } // else + } // if + else + { + DisposePixMap( hPixMapCopy ); + + hPixMapCopy = NULL; + } // else + } // if + + SetPixelsState( hPixMap, nPixMapFlags ); + } // if + } // if + + return hPixMapCopy; +} // CopyPixMap + +// ======================================================================= + +// ======================================================================= + +PixMapHandle GetCGrafPortPixMap ( const Size &rPixMapSize, + const USHORT nPixMapBits, + const BitmapPalette &rBitmapPalette, + const CGrafPtr pCGraf + ) +{ + PixMapHandle hNewPixMap = GetPortPixMap( pCGraf ); + + if ( hNewPixMap == NULL ) + { + hNewPixMap = GetNewPixMap( rPixMapSize, + nPixMapBits, + rBitmapPalette + ); + + if ( hNewPixMap == NULL ) + { + GDHandle hGDevice = GetGDevice( ); + + if ( ( hGDevice != NULL ) && ( *hGDevice != NULL ) ) + { + SInt8 nGDeviceFlags = noErr; + + nGDeviceFlags = HGetState( (Handle)hGDevice ); + + if ( nGDeviceFlags == noErr ) + { + PixMapHandle hPixMap = NULL; + + HLock( (Handle)hGDevice ); + + hPixMap = (**hGDevice).gdPMap; + + if ( ( hPixMap != NULL ) && ( *hPixMap != NULL ) ) + { + hNewPixMap = CopyPixMap( hPixMap ); + } // if + + HSetState( (Handle)hGDevice, nGDeviceFlags ); + } //if + } // if + } // if + } // if + + return hNewPixMap; +} // GetCGrafPortPixMap + +// ======================================================================= + +// ======================================================================= diff --git a/vcl/aqua/source/gdi/salvd.cxx b/vcl/aqua/source/gdi/salvd.cxx index 10ecfafecc21..fc4ae00ea51a 100644 --- a/vcl/aqua/source/gdi/salvd.cxx +++ b/vcl/aqua/source/gdi/salvd.cxx @@ -2,9 +2,9 @@ * * $RCSfile: salvd.cxx,v $ * - * $Revision: 1.9 $ + * $Revision: 1.10 $ * - * last change: $Author: bmahbod $ $Date: 2001-02-08 00:12:20 $ + * last change: $Author: bmahbod $ $Date: 2001-02-14 19:39:49 $ * * The Contents of this file are made available subject to the terms of * either of the following licenses @@ -61,12 +61,22 @@ #define _SV_SALVD_CXX +#ifndef _SV_SALCONST_H +#include <salconst.h> +#endif + +#ifndef _SV_SALCOLORUTILS_HXX +#include <salcolorutils.hxx> +#endif + #ifndef _SV_SALVD_HXX #include <salvd.hxx> #endif // ======================================================================= +// ======================================================================= + static BOOL InitVirtualDeviceGWorld ( SalVirDevDataPtr rSalVirDevData ) { BOOL bVirtualDeviceGWorldInited = FALSE; @@ -105,12 +115,6 @@ static BOOL InitVirtualDeviceGWorld ( SalVirDevDataPtr rSalVirDevData ) && ( pGWorld != NULL ) ) { - RGBColor aBlackColor; - - aBlackColor.red = 0x0000; - aBlackColor.green = 0x0000; - aBlackColor.blue = 0x0000; - // Lock the virtual GWorld's port bits rSalVirDevData->mpGraphics->maGraphicsData.mnOSStatus @@ -144,11 +148,11 @@ static BOOL InitVirtualDeviceGWorld ( SalVirDevDataPtr rSalVirDevData ) // Initialize the virtual port's brush attributes rSalVirDevData->mpGraphics->maGraphicsData.mbBrushTransparent = FALSE; - rSalVirDevData->mpGraphics->maGraphicsData.maBrushColor = aBlackColor; + rSalVirDevData->mpGraphics->maGraphicsData.maBrushColor = GetBlackColor( ); // Initialize the virtual port's font attributes - rSalVirDevData->mpGraphics->maGraphicsData.maFontColor = aBlackColor; + rSalVirDevData->mpGraphics->maGraphicsData.maFontColor = GetBlackColor( ); rSalVirDevData->mpGraphics->maGraphicsData.mnFontID = kFontIDGeneva; rSalVirDevData->mpGraphics->maGraphicsData.mnFontSize = 10; rSalVirDevData->mpGraphics->maGraphicsData.mnFontStyle = normal; @@ -261,3 +265,5 @@ BOOL SalVirtualDevice::SetSize( long nDX, long nDY ) // ======================================================================= +// ======================================================================= + |