OpenASIP  2.0
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.

38  :
40 }

◆ ~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 }

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 }

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:
INDENT
const string INDENT
Definition: MifImageWriter.cc:27
AsciiImageWriter::AsciiImageWriter
AsciiImageWriter(const BitVector &bits, int rowLength)
Definition: AsciiImageWriter.cc:55
AsciiImageWriter::rowLength
int rowLength() const
Definition: AsciiImageWriter.cc:112
AsciiImageWriter::writeSequence
void writeSequence(std::ostream &stream, int length, bool padEnd=false) const
Definition: AsciiImageWriter.cc:129
MifImageWriter::writeHeader
void writeHeader(std::ostream &stream) const
Definition: MifImageWriter.cc:88
END
const string END
Definition: MifImageWriter.cc:26
D_RADIX
const string D_RADIX
Definition: MifImageWriter.cc:24
DEPTH
const string DEPTH
Definition: MifImageWriter.cc:22
WIDTH
const string WIDTH
Definition: MifImageWriter.cc:21
A_RADIX
const string A_RADIX
Definition: MifImageWriter.cc:23
AsciiImageWriter::bits
const BitVector & bits() const
Definition: AsciiImageWriter.cc:101
COMMENT
const string COMMENT
Definition: MifImageWriter.cc:20
BEGIN
const string BEGIN
Definition: MifImageWriter.cc:25