xref: /aoo42x/main/basebmp/source/debug.cxx (revision 69de5a4c)
1*69de5a4cSAndrew Rist /**************************************************************
2cdf0e10cSrcweir  *
3*69de5a4cSAndrew Rist  * Licensed to the Apache Software Foundation (ASF) under one
4*69de5a4cSAndrew Rist  * or more contributor license agreements.  See the NOTICE file
5*69de5a4cSAndrew Rist  * distributed with this work for additional information
6*69de5a4cSAndrew Rist  * regarding copyright ownership.  The ASF licenses this file
7*69de5a4cSAndrew Rist  * to you under the Apache License, Version 2.0 (the
8*69de5a4cSAndrew Rist  * "License"); you may not use this file except in compliance
9*69de5a4cSAndrew Rist  * with the License.  You may obtain a copy of the License at
10*69de5a4cSAndrew Rist  *
11*69de5a4cSAndrew Rist  *   http://www.apache.org/licenses/LICENSE-2.0
12*69de5a4cSAndrew Rist  *
13*69de5a4cSAndrew Rist  * Unless required by applicable law or agreed to in writing,
14*69de5a4cSAndrew Rist  * software distributed under the License is distributed on an
15*69de5a4cSAndrew Rist  * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16*69de5a4cSAndrew Rist  * KIND, either express or implied.  See the License for the
17*69de5a4cSAndrew Rist  * specific language governing permissions and limitations
18*69de5a4cSAndrew Rist  * under the License.
19*69de5a4cSAndrew Rist  *
20*69de5a4cSAndrew Rist  *************************************************************/
21*69de5a4cSAndrew Rist 
22*69de5a4cSAndrew Rist 
23cdf0e10cSrcweir 
24cdf0e10cSrcweir #include <osl/diagnose.h>
25cdf0e10cSrcweir 
26cdf0e10cSrcweir #include <basegfx/point/b2ipoint.hxx>
27cdf0e10cSrcweir #include <basegfx/vector/b2ivector.hxx>
28cdf0e10cSrcweir 
29cdf0e10cSrcweir #include <basebmp/scanlineformats.hxx>
30cdf0e10cSrcweir #include <basebmp/color.hxx>
31cdf0e10cSrcweir #include <basebmp/bitmapdevice.hxx>
32cdf0e10cSrcweir #include <basebmp/debug.hxx>
33cdf0e10cSrcweir 
34cdf0e10cSrcweir #include <iomanip>
35cdf0e10cSrcweir 
36cdf0e10cSrcweir namespace basebmp
37cdf0e10cSrcweir {
38cdf0e10cSrcweir     namespace
39cdf0e10cSrcweir     {
getFormatString(sal_Int32 nScanlineFormat)40cdf0e10cSrcweir         static const char* getFormatString( sal_Int32 nScanlineFormat )
41cdf0e10cSrcweir         {
42cdf0e10cSrcweir             switch( nScanlineFormat )
43cdf0e10cSrcweir             {
44cdf0e10cSrcweir                 case Format::ONE_BIT_MSB_GREY:
45cdf0e10cSrcweir                     return "ONE_BIT_MSB_GREY";
46cdf0e10cSrcweir                 case Format::ONE_BIT_LSB_GREY:
47cdf0e10cSrcweir                     return "ONE_BIT_LSB_GREY";
48cdf0e10cSrcweir                 case Format::ONE_BIT_MSB_PAL:
49cdf0e10cSrcweir                     return "ONE_BIT_MSB_PAL";
50cdf0e10cSrcweir                 case Format::ONE_BIT_LSB_PAL:
51cdf0e10cSrcweir                     return "ONE_BIT_LSB_PAL";
52cdf0e10cSrcweir                 case Format::FOUR_BIT_MSB_GREY:
53cdf0e10cSrcweir                     return "FOUR_BIT_MSB_GREY";
54cdf0e10cSrcweir                 case Format::FOUR_BIT_LSB_GREY:
55cdf0e10cSrcweir                     return "FOUR_BIT_LSB_GREY";
56cdf0e10cSrcweir                 case Format::FOUR_BIT_MSB_PAL:
57cdf0e10cSrcweir                     return "FOUR_BIT_MSB_PAL";
58cdf0e10cSrcweir                 case Format::FOUR_BIT_LSB_PAL:
59cdf0e10cSrcweir                     return "FOUR_BIT_LSB_PAL";
60cdf0e10cSrcweir                 case Format::EIGHT_BIT_PAL:
61cdf0e10cSrcweir                     return "EIGHT_BIT_PAL";
62cdf0e10cSrcweir                 case Format::EIGHT_BIT_GREY:
63cdf0e10cSrcweir                     return "EIGHT_BIT_GREY";
64cdf0e10cSrcweir                 case Format::SIXTEEN_BIT_LSB_TC_MASK:
65cdf0e10cSrcweir                     return "SIXTEEN_BIT_LSB_TC_MASK";
66cdf0e10cSrcweir                 case Format::SIXTEEN_BIT_MSB_TC_MASK:
67cdf0e10cSrcweir                     return "SIXTEEN_BIT_MSB_TC_MASK";
68cdf0e10cSrcweir                 case Format::TWENTYFOUR_BIT_TC_MASK:
69cdf0e10cSrcweir                     return "TWENTYFOUR_BIT_TC_MASK";
70cdf0e10cSrcweir                 case Format::THIRTYTWO_BIT_TC_MASK:
71cdf0e10cSrcweir                     return "THIRTYTWO_BIT_TC_MASK";
72cdf0e10cSrcweir                 default:
73cdf0e10cSrcweir                     return "<unknown>";
74cdf0e10cSrcweir             }
75cdf0e10cSrcweir         }
76cdf0e10cSrcweir     }
77cdf0e10cSrcweir 
debugDump(const BitmapDeviceSharedPtr & rDevice,std::ostream & rOutputStream)78cdf0e10cSrcweir     void debugDump( const BitmapDeviceSharedPtr& rDevice,
79cdf0e10cSrcweir                     std::ostream&                rOutputStream )
80cdf0e10cSrcweir     {
81cdf0e10cSrcweir         const basegfx::B2IVector aSize( rDevice->getSize() );
82cdf0e10cSrcweir         const bool               bTopDown( rDevice->isTopDown() );
83cdf0e10cSrcweir         const sal_Int32          nScanlineFormat( rDevice->getScanlineFormat() );
84cdf0e10cSrcweir 
85cdf0e10cSrcweir         rOutputStream
86cdf0e10cSrcweir             << "/* basebmp::BitmapDevice content dump */" << std::endl
87cdf0e10cSrcweir             << "/* Width   = " << aSize.getX() << " */" << std::endl
88cdf0e10cSrcweir             << "/* Height  = " << aSize.getY() << " */" << std::endl
89cdf0e10cSrcweir             << "/* TopDown = " << bTopDown << " */" << std::endl
90cdf0e10cSrcweir             << "/* Format  = " << getFormatString(nScanlineFormat) << " */" << std::endl
91cdf0e10cSrcweir             << "/* (dumped entries are already mapped RGBA color values) */" << std::endl
92cdf0e10cSrcweir             << std::endl;
93cdf0e10cSrcweir 
94cdf0e10cSrcweir         rOutputStream << std::hex;
95cdf0e10cSrcweir         for( int y=0; y<aSize.getY(); ++y )
96cdf0e10cSrcweir         {
97cdf0e10cSrcweir             for( int x=0; x<aSize.getX(); ++x )
98cdf0e10cSrcweir                 rOutputStream << std::setw(8) << (sal_uInt32)rDevice->getPixel( basegfx::B2IPoint(x,y) ).toInt32() << " ";
99cdf0e10cSrcweir             rOutputStream << std::endl;
100cdf0e10cSrcweir         }
101cdf0e10cSrcweir     }
102cdf0e10cSrcweir }
103