xref: /AOO41X/main/basebmp/source/debug.cxx (revision 1ecadb572e7010ff3b3382ad9bf179dbc6efadbb)
1 /*************************************************************************
2  *
3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4  *
5  * Copyright 2000, 2010 Oracle and/or its affiliates.
6  *
7  * OpenOffice.org - a multi-platform office productivity suite
8  *
9  * This file is part of OpenOffice.org.
10  *
11  * OpenOffice.org is free software: you can redistribute it and/or modify
12  * it under the terms of the GNU Lesser General Public License version 3
13  * only, as published by the Free Software Foundation.
14  *
15  * OpenOffice.org is distributed in the hope that it will be useful,
16  * but WITHOUT ANY WARRANTY; without even the implied warranty of
17  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
18  * GNU Lesser General Public License version 3 for more details
19  * (a copy is included in the LICENSE file that accompanied this code).
20  *
21  * You should have received a copy of the GNU Lesser General Public License
22  * version 3 along with OpenOffice.org.  If not, see
23  * <http://www.openoffice.org/license.html>
24  * for a copy of the LGPLv3 License.
25  *
26  ************************************************************************/
27 
28 #include <osl/diagnose.h>
29 
30 #include <basegfx/point/b2ipoint.hxx>
31 #include <basegfx/vector/b2ivector.hxx>
32 
33 #include <basebmp/scanlineformats.hxx>
34 #include <basebmp/color.hxx>
35 #include <basebmp/bitmapdevice.hxx>
36 #include <basebmp/debug.hxx>
37 
38 #include <iomanip>
39 
40 namespace basebmp
41 {
42     namespace
43     {
44         static const char* getFormatString( sal_Int32 nScanlineFormat )
45         {
46             switch( nScanlineFormat )
47             {
48                 case Format::ONE_BIT_MSB_GREY:
49                     return "ONE_BIT_MSB_GREY";
50                 case Format::ONE_BIT_LSB_GREY:
51                     return "ONE_BIT_LSB_GREY";
52                 case Format::ONE_BIT_MSB_PAL:
53                     return "ONE_BIT_MSB_PAL";
54                 case Format::ONE_BIT_LSB_PAL:
55                     return "ONE_BIT_LSB_PAL";
56                 case Format::FOUR_BIT_MSB_GREY:
57                     return "FOUR_BIT_MSB_GREY";
58                 case Format::FOUR_BIT_LSB_GREY:
59                     return "FOUR_BIT_LSB_GREY";
60                 case Format::FOUR_BIT_MSB_PAL:
61                     return "FOUR_BIT_MSB_PAL";
62                 case Format::FOUR_BIT_LSB_PAL:
63                     return "FOUR_BIT_LSB_PAL";
64                 case Format::EIGHT_BIT_PAL:
65                     return "EIGHT_BIT_PAL";
66                 case Format::EIGHT_BIT_GREY:
67                     return "EIGHT_BIT_GREY";
68                 case Format::SIXTEEN_BIT_LSB_TC_MASK:
69                     return "SIXTEEN_BIT_LSB_TC_MASK";
70                 case Format::SIXTEEN_BIT_MSB_TC_MASK:
71                     return "SIXTEEN_BIT_MSB_TC_MASK";
72                 case Format::TWENTYFOUR_BIT_TC_MASK:
73                     return "TWENTYFOUR_BIT_TC_MASK";
74                 case Format::THIRTYTWO_BIT_TC_MASK:
75                     return "THIRTYTWO_BIT_TC_MASK";
76                 default:
77                     return "<unknown>";
78             }
79         }
80     }
81 
82     void debugDump( const BitmapDeviceSharedPtr& rDevice,
83                     std::ostream&                rOutputStream )
84     {
85         const basegfx::B2IVector aSize( rDevice->getSize() );
86         const bool               bTopDown( rDevice->isTopDown() );
87         const sal_Int32          nScanlineFormat( rDevice->getScanlineFormat() );
88 
89         rOutputStream
90             << "/* basebmp::BitmapDevice content dump */" << std::endl
91             << "/* Width   = " << aSize.getX() << " */" << std::endl
92             << "/* Height  = " << aSize.getY() << " */" << std::endl
93             << "/* TopDown = " << bTopDown << " */" << std::endl
94             << "/* Format  = " << getFormatString(nScanlineFormat) << " */" << std::endl
95             << "/* (dumped entries are already mapped RGBA color values) */" << std::endl
96             << std::endl;
97 
98         rOutputStream << std::hex;
99         for( int y=0; y<aSize.getY(); ++y )
100         {
101             for( int x=0; x<aSize.getX(); ++x )
102                 rOutputStream << std::setw(8) << (sal_uInt32)rDevice->getPixel( basegfx::B2IPoint(x,y) ).toInt32() << " ";
103             rOutputStream << std::endl;
104         }
105     }
106 }
107