OpenASIP
2.0
src
applibs
PIG
HexImageWriter.cc
Go to the documentation of this file.
1
/*
2
Copyright (c) 2002-2018 Tampere University
3
and Alexander Kobler.
4
5
This file is part of TTA-Based Codesign Environment (TCE).
6
7
Permission is hereby granted, free of charge, to any person obtaining a
8
copy of this software and associated documentation files (the "Software"),
9
to deal in the Software without restriction, including without limitation
10
the rights to use, copy, modify, merge, publish, distribute, sublicense,
11
and/or sell copies of the Software, and to permit persons to whom the
12
Software is furnished to do so, subject to the following conditions:
13
14
The above copyright notice and this permission notice shall be included in
15
all copies or substantial portions of the Software.
16
17
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
18
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
19
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
20
THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
21
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
22
FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
23
DEALINGS IN THE SOFTWARE.
24
*/
25
/**
26
* @file HexImageWriter.cc
27
*
28
* Implementation of HexImageWriter class.
29
*
30
* @author Alexander Kobler 2018
31
* @note rating: red
32
*/
33
34
#include <cmath>
35
#include <iostream>
36
#include <iomanip>
37
#include <numeric>
38
39
#include "
AsciiImageWriter.hh
"
40
#include "
HexImageWriter.hh
"
41
#include "
BitVector.hh
"
42
43
using namespace
std;
44
45
/**
46
* The constructor.
47
*
48
* @param bits The bits to write.
49
* @param rowLength Length of the rows to write.
50
*/
51
HexImageWriter::HexImageWriter
(
const
BitVector
& bits,
int
rowLength) :
52
AsciiImageWriter
(bits, rowLength) {
53
}
54
55
/**
56
* The destructor.
57
*/
58
HexImageWriter::~HexImageWriter
() {
59
}
60
61
62
/**
63
* Writes the bit image to the given stream.
64
*
65
* @param stream The stream to write.
66
*/
67
void
68
HexImageWriter::writeImage
(std::ostream& stream)
const
{
69
const
int
lineCount =
static_cast<
int
>
(
70
ceil(
static_cast<
double
>
(
bits
().size()) /
rowLength
()));
71
72
const
int
nibbleCount =
static_cast<
int
>
(
73
ceil(
static_cast<
double
>
(
rowLength
() / 4)));
74
75
if
(lineCount == 0) {
76
stream << std::hex << std::setfill(
'0'
)
77
<< std::setw(nibbleCount) << 0 << std::endl;
78
79
}
else
{
80
bool
padEndings =
false
;
81
82
for
(
int
i = 0; i < lineCount; ++i) {
83
writeHexSequence
(stream,
rowLength
(), padEndings);
84
stream << endl;
85
}
86
}
87
}
88
89
90
91
92
AsciiImageWriter.hh
BitVector
Definition:
BitVector.hh:44
AsciiImageWriter::rowLength
int rowLength() const
Definition:
AsciiImageWriter.cc:112
BitVector.hh
AsciiImageWriter::writeHexSequence
void writeHexSequence(std::ostream &stream, int length, bool padEnd=false) const
Definition:
AsciiImageWriter.cc:160
HexImageWriter::writeImage
virtual void writeImage(std::ostream &stream) const
Definition:
HexImageWriter.cc:68
AsciiImageWriter::bits
const BitVector & bits() const
Definition:
AsciiImageWriter.cc:101
AsciiImageWriter
Definition:
AsciiImageWriter.hh:45
HexImageWriter::HexImageWriter
HexImageWriter(const BitVector &bits, int rowLength)
Definition:
HexImageWriter.cc:51
HexImageWriter.hh
HexImageWriter::~HexImageWriter
virtual ~HexImageWriter()
Definition:
HexImageWriter.cc:58
Generated by
1.8.17