Commit f8d5cdf1 authored by kraus's avatar kraus
Browse files

fixing binary format of Portable Bitmap

parent a7080a2f
...@@ -599,13 +599,11 @@ namespace mslang { ...@@ -599,13 +599,11 @@ namespace mslang {
Mask *pixmap = static_cast<Mask*>(fun); Mask *pixmap = static_cast<Mask*>(fun);
std::string str(it, end); std::string str(it, end);
std::cout << str << std::endl;
boost::regex argument("'([^\\0]+)'(\\).*)"); boost::regex argument("'([^\\0]+)'(\\).*)");
boost::smatch what; boost::smatch what;
if (!boost::regex_match(str, what, argument)) return false; if (!boost::regex_match(str, what, argument)) return false;
std::string filename = what[1]; std::string filename = what[1];
std::cout << filename << std::endl;
if (!boost::filesystem::exists(filename)) { if (!boost::filesystem::exists(filename)) {
ERRORMSG("file '" << filename << "' doesn't exists" << endl); ERRORMSG("file '" << filename << "' doesn't exists" << endl);
return false; return false;
...@@ -731,19 +729,23 @@ namespace mslang { ...@@ -731,19 +729,23 @@ namespace mslang {
0.0), 0.0),
bb_m.center_m)); bb_m.center_m));
bool allNonEmpty = true;
for (unsigned int i = 0; i < 4u; ++ i) { for (unsigned int i = 0; i < 4u; ++ i) {
next[i].transferIfInside(objects_m); next[i].transferIfInside(objects_m);
if (next[i].objects_m.size() == 0) { }
allNonEmpty = false;
for (unsigned int j = 0; j < i; ++ j) { bool allEmpty = true;
objects_m.merge(next[j].objects_m); for (unsigned int i = 0; i < 4u; ++ i) {
} if (next[i].objects_m.size() != 0) {
allEmpty = false;
break; break;
} }
} }
if (!allNonEmpty) { if (allEmpty) {
for (unsigned int i = 0; i < 4u; ++ i) {
objects_m.merge(next[i].objects_m);
}
delete[] next; delete[] next;
return; return;
} }
......
...@@ -194,9 +194,9 @@ namespace mslang { ...@@ -194,9 +194,9 @@ namespace mslang {
out << "# level: " << level_m << ", size: " << objects_m.size() << std::endl; out << "# level: " << level_m << ", size: " << objects_m.size() << std::endl;
bb_m.writeGnuplot(out); bb_m.writeGnuplot(out);
out << "# num holes: " << objects_m.size() << std::endl; out << "# num holes: " << objects_m.size() << std::endl;
for (const Base *obj: objects_m) { // for (const Base *obj: objects_m) {
obj->writeGnuplot(out); // obj->writeGnuplot(out);
} // }
out << std::endl; out << std::endl;
if (nodes_m != 0) { if (nodes_m != 0) {
......
...@@ -88,20 +88,22 @@ void PortableBitmapReader::readImageAscii(std::istream &in) { ...@@ -88,20 +88,22 @@ void PortableBitmapReader::readImageAscii(std::istream &in) {
void PortableBitmapReader::readImageBinary(std::istream &in) { void PortableBitmapReader::readImageBinary(std::istream &in) {
static const unsigned int sizeChar = sizeof(char) * 8; static const unsigned int sizeChar = sizeof(char) * 8;
unsigned int trueSize = (height_m * width_m); unsigned int numBytes = width_m / sizeChar;
unsigned int size = trueSize / sizeChar; if (numBytes * sizeChar != width_m)
if (size * sizeChar != trueSize) ++ numBytes;
++ size;
unsigned int numPixels = 0; unsigned int numPixels = 0;
for (unsigned int i = 0; i < size; ++ i) { for (unsigned int i = 0; i < height_m; ++ i) {
char c; for (unsigned int j = 0; j < numBytes; ++ j) {
in >> c; unsigned char c;
in >> c;
unsigned int numBits = std::min(sizeChar, trueSize - numPixels);
for (unsigned int j = sizeChar; j > 0 ; -- j) {
for (unsigned int j = numBits; j > 0 ; -- j, ++ numPixels) { pixels_m[numPixels ++] = ((c >> (j - 1)) & 1);
pixels_m[numPixels] = ((c >> (numBits - 1)) & 1); if (numPixels % width_m == 0) {
break;
}
}
} }
} }
} }
\ No newline at end of file
...@@ -33,7 +33,6 @@ int main(int argc, char *argv[]) ...@@ -33,7 +33,6 @@ int main(int argc, char *argv[])
std::istreambuf_iterator<char>()); std::istreambuf_iterator<char>());
const unsigned int method = (atoi(argv[2]) == 0 ? 0: 1); const unsigned int method = (atoi(argv[2]) == 0 ? 0: 1);
std::cout << method << std::endl;
const unsigned int N = atoi(argv[3]); const unsigned int N = atoi(argv[3]);
// std::string str("repeat( translate(union(rectangle(0.1, 0.1), ellipse(0.1, 0.1)), -0.01, -0.02), 2, 0.1, 0.2)"); // std::string str("repeat( translate(union(rectangle(0.1, 0.1), ellipse(0.1, 0.1)), -0.01, -0.02), 2, 0.1, 0.2)");
...@@ -42,8 +41,8 @@ int main(int argc, char *argv[]) ...@@ -42,8 +41,8 @@ int main(int argc, char *argv[])
str = boost::regex_replace(str, boost::regex("\\s"), std::string(""), boost::match_default | boost::format_all); str = boost::regex_replace(str, boost::regex("\\s"), std::string(""), boost::match_default | boost::format_all);
if (parse(str, fun)) { if (parse(str, fun)) {
fun->print(0); // fun->print(0);
std::cout << "\n" << std::endl; // std::cout << "\n" << std::endl;
std::vector<mslang::Base*> baseBlocks; std::vector<mslang::Base*> baseBlocks;
fun->apply(baseBlocks); fun->apply(baseBlocks);
...@@ -86,7 +85,7 @@ int main(int argc, char *argv[]) ...@@ -86,7 +85,7 @@ int main(int argc, char *argv[])
mslang::QuadTree tree; mslang::QuadTree tree;
tree.bb_m = mslang::BoundingBox(llc, urc); tree.bb_m = mslang::BoundingBox(llc, urc);
std::cout << tree.bb_m << std::endl;
tree.objects_m.insert(tree.objects_m.end(), baseBlocks.begin(), baseBlocks.end()); tree.objects_m.insert(tree.objects_m.end(), baseBlocks.begin(), baseBlocks.end());
tree.buildUp(); tree.buildUp();
...@@ -95,7 +94,7 @@ int main(int argc, char *argv[]) ...@@ -95,7 +94,7 @@ int main(int argc, char *argv[])
out.close(); out.close();
if (false) { if (true) {
out.open("particles.gpl"); out.open("particles.gpl");
gsl_rng *rng = gsl_rng_alloc(gsl_rng_default); gsl_rng *rng = gsl_rng_alloc(gsl_rng_default);
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment