OpenASIP 2.2
Loading...
Searching...
No Matches
Public Member Functions | Private Member Functions | List of all members
MifImageWriter Class Reference

#include <MifImageWriter.hh>

Inheritance diagram for MifImageWriter:
Inheritance graph
Collaboration diagram for MifImageWriter:
Collaboration graph

Public Member Functions

 MifImageWriter (const BitVector &bits, int rowLength)
 
virtual ~MifImageWriter ()
 
virtual void writeImage (std::ostream &stream) const
 
- Public Member Functions inherited from AsciiImageWriter
 AsciiImageWriter (const BitVector &bits, int rowLength)
 
virtual ~AsciiImageWriter ()
 
- Public Member Functions inherited from BitImageWriter
virtual ~BitImageWriter ()
 

Private Member Functions

void writeHeader (std::ostream &stream) const
 

Additional Inherited Members

- Protected Member Functions inherited from AsciiImageWriter
const BitVectorbits () const
 
int rowLength () const
 
void writeSequence (std::ostream &stream, int length, bool padEnd=false) const
 
void writeHexSequence (std::ostream &stream, int length, bool padEnd=false) const
 

Detailed Description

Definition at line 17 of file MifImageWriter.hh.

Constructor & Destructor Documentation

◆ MifImageWriter()

MifImageWriter::MifImageWriter ( const BitVector bits,
int  rowLength 
)

The constructor.

Parameters
bitsThe bits to be written.
rowLengthThe length of the row in the output stream.

Definition at line 38 of file MifImageWriter.cc.

◆ ~MifImageWriter()

MifImageWriter::~MifImageWriter ( )
virtual

The destructor.

Definition at line 45 of file MifImageWriter.cc.

45 {
46}

Member Function Documentation

◆ writeHeader()

void MifImageWriter::writeHeader ( std::ostream &  stream) const
private

Writes the MIF header to the given stream.

Parameters
streamThe output stream.

Definition at line 88 of file MifImageWriter.cc.

88 {
89 int wordCount = static_cast<int>(ceil((float)bits().size() / rowLength()));
90 stream << COMMENT << endl
91 << WIDTH << rowLength() << ";" << endl;
92
93 // empty MIF is invalid
94 if (wordCount == 0) {
95 stream << DEPTH << "1" << ";" << endl;
96 } else {
97 stream << DEPTH << wordCount << ";" << endl;
98 }
99
100 stream << A_RADIX << endl
101 << D_RADIX << endl << endl
102 << BEGIN << endl;
103}
const string DEPTH
const string BEGIN
const string A_RADIX
const string WIDTH
const string COMMENT
const string D_RADIX

References A_RADIX, BEGIN, AsciiImageWriter::bits(), COMMENT, D_RADIX, DEPTH, AsciiImageWriter::rowLength(), and WIDTH.

Referenced by writeImage().

Here is the call graph for this function:

◆ writeImage()

void MifImageWriter::writeImage ( std::ostream &  stream) const
virtual

Writes the bits to the given stream.

Parameters
streamThe output stream.

Reimplemented from AsciiImageWriter.

Definition at line 53 of file MifImageWriter.cc.

53 {
54 int wordCount =
55 static_cast<int>(ceil((float)bits().size() / rowLength()));
56 writeHeader(stream);
57
58 int address = 0;
59 if (wordCount == 0) {
60 // empty MIF is invalid, fill one row with zeroes
61 stream << address << INDENT << ":" << INDENT;
62 for (int i = 0; i < rowLength(); i++) {
63 stream << "0";
64 }
65 stream << ";" << endl;
66 } else {
67 bool padEndings = false;
68 for (int i = 0; i < wordCount-1; i++) {
69 stream << address << INDENT << ":" << INDENT;
70 writeSequence(stream, rowLength(), padEndings);
71 stream << ";" << endl;
72 address++;
73 }
74 // last line might need to be padded
75 padEndings = true;
76 stream << address << INDENT << ":" << INDENT;
77 writeSequence(stream, rowLength(), padEndings);
78 stream << ";" << endl;
79 }
80 stream << END << endl;
81}
#define INDENT
const string END
void writeSequence(std::ostream &stream, int length, bool padEnd=false) const
void writeHeader(std::ostream &stream) const

References AsciiImageWriter::bits(), END, INDENT, AsciiImageWriter::rowLength(), writeHeader(), and AsciiImageWriter::writeSequence().

Here is the call graph for this function:

The documentation for this class was generated from the following files: