DUDS
Distributed Update of Data from Something
BppImageArchiveSequence.cpp
Go to the documentation of this file.
1 /*
2  * This file is part of the DUDS project. It is subject to the BSD-style
3  * license terms in the LICENSE file found in the top-level directory of this
4  * distribution and at https://github.com/jjackowski/duds/blob/master/LICENSE.
5  * No part of DUDS, including this file, may be copied, modified, propagated,
6  * or distributed except according to the terms contained in the LICENSE file.
7  *
8  * Copyright (C) 2019 Jeff Jackowski
9  */
12 #include <duds/general/Errors.hpp>
13 
14 namespace duds { namespace ui { namespace graphics {
15 
17  // prepare the iterator
18  iterator iter(this);
19  return ++iter;
20 }
21 
23  // past end check
24  if (!bias) {
26  }
27  std::istream *is = bias->is;
28  // read in name length
29  unsigned char nlen;
30  is->read((char*)&nlen, 1);
31  // read in the name
32  std::vector<char> buff(nlen);
33  is->read(&(buff[0]), nlen);
34  std::string name(buff.begin(), buff.end());
35  // EOF is only set after attempting to read more than the file holds, so
36  // it may be set now, but is not an error condition
37  if (is->eof()) {
38  // clear out data
39  bias->deref.first.clear();
40  bias->deref.second.reset();
41  bias = nullptr;
42  return *this;
43  }
44  // read in the dimensions
45  if (nlen < 4) {
46  buff.resize(4);
47  }
48  is->read(&(buff[0]), 4);
49  if (!is->good()) {
52  );
53  }
54  std::int16_t w = buff[0] | (buff[1] << 8);
55  std::int16_t h = buff[2] | (buff[3] << 8);
56  // calculate size
57  std::size_t imgwidth = w / 8 + ((w % 8) ? 1 : 0);
58  std::size_t length = imgwidth * h + 4;
59  // allocate space
60  buff.resize(length);
61  // read rest of image
62  is->read(&(buff[4]), length - 4);
63  if (!is->good() && !is->eof()) {
66  );
67  }
68  bias->deref.first = std::move(name);
69  // create image object
70  bias->deref.second = std::make_shared<BppImage>(buff);
71  return *this;
72 }
73 
75  // check for header
76  std::string str;
77  // do not read into the version value that follows the header
78  is->width(4);
79  (*is) >> str;
80  is->width(0);
81  if (str != "BPPI") {
83  }
84  // read version
85  char buff[4];
86  is->read(buff, 4);
87  if (!is->good()) {
89  }
90  std::uint32_t ver = buff[0] | (buff[1] << 8) | (buff[2] << 16) |
91  (buff[3] << 24);
92  // version check; only 0 is supported
93  if (ver != 0) {
96  );
97  }
98 }
99 
101  inf.open(path);
102  if (!inf.good()) {
105  );
106  }
107  is = &inf;
108  readHeader();
109 }
110 
111 } } }
iterator begin()
Parses the first image in the stream and returns an iterator to that data.
boost::error_info< struct Info_ArchiveImageName, std::string > ImageArchiveImageName
The name of the image involved in an ImageArchiveError.
An input iterator that will parse and supply image data from the stream.
move_impl move(unsigned int c, unsigned int r)
Display stream manipulator that moves the display cursor to the given location.
The base class for errors resulting from the attempt to read an image archive stream or file...
BppImageArchiveFile(const std::string &path)
Opens the given file and parses headers at the start.
boost::error_info< struct Info_ImageArcFileName, std::string > ImageArchiveFileName
The name of the image archive file involved in an ImageArchiveStreamError.
void readHeader()
Parses the headers used in BppImageArchive files.
std::istream * is
The stream which contains image data.
boost::error_info< struct Info_ImageArcName, std::uint32_t > ImageArchiveVersion
The name of the image involved in an ImageArchiveError.
An attempt was made to advance past the end of a archive stream.
iterator & operator++()
Pre-increment operator; parses the next image.
The stream appears to not be an image archive.
General graphics related code.
Definition: HD44780.hpp:15
General errors.
#define DUDS_THROW_EXCEPTION(x)
Works like BOOST_THROW_EXCEPTION, but includes a stack trace if DUDS_ERRORS_VERBOSE is defined...
Definition: Errors.hpp:48
The archive is in an unsupported version of the format.