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