From: David Gow Date: Mon, 21 Apr 2014 04:35:36 +0000 (+0800) Subject: Merge branch 'master' of git.ucc.asn.au:ipdf/code X-Git-Url: https://git.ucc.asn.au/?p=ipdf%2Fcode.git;a=commitdiff_plain;h=aaa65d90ac812f924cbbc39bef7a5f8b6cad2da3;hp=6ad7439e8ebf969fcd2d3a710a4b16e2b1ee131f Merge branch 'master' of git.ucc.asn.au:ipdf/code Conflicts: src/Makefile src/main.h src/real.h src/screen.cpp src/view.h This was one hell of a merge. I have more code coming, but it breaks other things, so it'll take a little while. --- diff --git a/bin/ipdf b/bin/ipdf index cf8ff78..10e25fe 100755 Binary files a/bin/ipdf and b/bin/ipdf differ diff --git a/src/Makefile b/src/Makefile index f3c287c..90adae9 100644 --- a/src/Makefile +++ b/src/Makefile @@ -4,7 +4,7 @@ ARCH := $(shell uname -m) CXX = g++ -std=gnu++0x -g # -Wall -Werror -Wshadow -pedantic MAIN = main.o -OBJ = log.o document.o view.o screen.o vfpu.o stb_truetype.o +OBJ = log.o real.o document.o view.o screen.o vfpu.o stb_truetype.o LIB_x86_64 = ../contrib/lib/libSDL2-2.0.so.0 -lGL LIB_i386 = ../contrib/lib32/libSDL2-2.0.so.0 -lGL @@ -23,7 +23,7 @@ MAINRPATH := $(MAINRPATH_$(ARCH)) TESTRPATH := $(TESTRPATH_$(ARCH)) CFLAGS := $(CFLAGS_$(ARCH)) - +DEF = -DREAL=1 LINKOBJ = $(OBJPATHS) @@ -33,6 +33,15 @@ BIN = ../bin/ipdf all : $(BIN) +single : DEF = -DREAL=0 +single : $(BIN) + +double : DEF = -DREAL=1 +double : $(BIN) + +# The tests will compile with the default REAL definition +# To change that you can run as `make DEFS="REAL=X" tests/` where X is your chosen type +# But remember to make clean first. tests/% : tests/%.cpp ../obj/tests/%.o $(LINKOBJ) $(CXX) -o $@.test $(LINKOBJ) ../obj/$@.o $(LIB) $(TESTRPATH) @@ -46,7 +55,7 @@ $(BIN) : $(LINKOBJ) ../obj/$(MAIN) ../obj/%.o : %.cpp @mkdir -p $(dir $@) - $(CXX) $(CFLAGS) -c -MMD -o $@ $< + $(CXX) $(CFLAGS) $(DEF) -c -MMD -o $@ $< -include $(DEPS) diff --git a/src/ipdf.h b/src/ipdf.h index 7150944..c9a6a23 100644 --- a/src/ipdf.h +++ b/src/ipdf.h @@ -4,6 +4,10 @@ #include "common.h" #include "real.h" +#define C_RED Colour(1,0,0,1) +#define C_GREEN Colour(0,1,0,1) +#define C_BLUE Colour(0,0,1,1) + namespace IPDF { diff --git a/src/main.cpp b/src/main.cpp index 12d8d56..9cf0c68 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -2,16 +2,19 @@ #include // Because we can. int main(int argc, char ** argv) { + Debug("Compiled with REAL = %d => \"%s\"", REAL, g_real_name[REAL]); + Document doc; srand(time(NULL)); enum {OUTPUT_TO_BMP, LOOP} mode = LOOP; - Rect bounds(0,0,1,1); + Colour c(0,0,0,1); const char * input_bmp = NULL; const char * output_bmp = NULL; const char * input_filename = NULL; + float b[4] = {0,0,1,1}; int i = 0; while (++i < argc) @@ -49,6 +52,21 @@ int main(int argc, char ** argv) i += 4; break; } + case 'b': + { + Debug("Reading view bounds"); + for (int j = 1; j <= 4; ++j) + { + if (i+j >= argc) + Fatal("No %d bounds component following -b switch", j); + char * e; + b[j-1] = strtof(argv[i+j], &e); + if (*e != '\0') + Fatal("Bounds component %d not a valid float", j); + } + i += 4; + break; + } } } @@ -58,8 +76,9 @@ int main(int argc, char ** argv) } else { - doc.Add(RECT_FILLED, Rect(0.2,0.2,0.6,0.6)); + doc.Add(RECT_OUTLINE, Rect(0.5,0.5,1,1)); } + Rect bounds(b[0],b[1],b[2],b[3]); if (mode == LOOP) MainLoop(doc, bounds, c); diff --git a/src/main.h b/src/main.h index 46c1544..bfd9fac 100644 --- a/src/main.h +++ b/src/main.h @@ -13,13 +13,12 @@ inline void OverlayBMP(Document & doc, const char * input, const char * output, { View view(doc, bounds, c); Screen scr; - scr.RenderBMP(input); + if (input != NULL) + scr.RenderBMP(input); view.Render(); + if (output != NULL) + scr.ScreenShot(output); scr.Present(); - sleep(5); - scr.RenderBMP(input); - view.Render(); - scr.ScreenShot(output); } inline void MainLoop(Document & doc, const Rect & bounds = Rect(0,0,1,1), const Colour & c = Colour(0.f,0.f,0.f,1.f)) diff --git a/src/real.cpp b/src/real.cpp new file mode 100644 index 0000000..74c774b --- /dev/null +++ b/src/real.cpp @@ -0,0 +1,11 @@ +#include "real.h" + +namespace IPDF +{ + // Maps the REAL to a string + const char * g_real_name[] = { + "single", + "double" + }; + +} diff --git a/src/real.h b/src/real.h index 2a4877c..e6e69bc 100644 --- a/src/real.h +++ b/src/real.h @@ -3,20 +3,27 @@ #include "common.h" -namespace IPDF -{ +#define REAL_SINGLE 0 +#define REAL_DOUBLE 1 + +#ifndef REAL + #error "REAL was not defined!" +#endif -//#define REAL_SINGLE -#define REAL_DOUBLE -//#define REAL_HALF +namespace IPDF +{ + extern const char * g_real_name[]; -#ifdef REAL_SINGLE +#if REAL == REAL_SINGLE typedef float Real; inline float Float(Real r) {return r;} -#elif defined REAL_DOUBLE +#elif REAL == REAL_DOUBLE typedef double Real; inline double Float(Real r) {return r;} -#endif +#else + #error "Type of Real unspecified." +#endif //REAL + } #endif //_REAL_H diff --git a/src/screen.cpp b/src/screen.cpp index 2764ef7..07d3f94 100644 --- a/src/screen.cpp +++ b/src/screen.cpp @@ -2,6 +2,8 @@ #include "screen.h" #include "SDL_opengl.h" +#include // for access(2) +#include // for access(2) using namespace IPDF; using namespace std; @@ -140,8 +142,7 @@ void Screen::ScreenShot(const char * filename) const unsigned char * pixels = new unsigned char[w*h*4]; if (pixels == NULL) Fatal("Failed to allocate %d x %d x 4 = %d pixel array", w, h, w*h*4); - glReadBuffer(GL_FRONT); - glPixelStorei(GL_PACK_ALIGNMENT, 1); + for (int y = 0; y < h; ++y) { glReadPixels(0,h-y-1,w, 1, GL_RGBA, GL_UNSIGNED_BYTE, &pixels[y*w*4]); @@ -172,6 +173,11 @@ void Screen::ScreenShot(const char * filename) const */ void Screen::RenderBMP(const char * filename) const { + if (access(filename, R_OK) == -1) + { + Error("No such file \"%s\" - Nothing to render - You might have done this deliberately?", filename); + return; + } SDL_Surface * bmp = SDL_LoadBMP(filename); if (bmp == NULL) Fatal("Failed to load BMP from %s - %s", filename, SDL_GetError()); diff --git a/src/view.cpp b/src/view.cpp index 0354ee9..26e9507 100644 --- a/src/view.cpp +++ b/src/view.cpp @@ -11,17 +11,19 @@ void View::Translate(Real x, Real y) y *= m_bounds.h; m_bounds.x += x; m_bounds.y += y; + Debug("View Bounds => %s", m_bounds.Str().c_str()); } void View::ScaleAroundPoint(Real x, Real y, Real scaleAmt) { + // x and y are coordinates in the window // Convert to local coords. x *= m_bounds.w; y *= m_bounds.h; x += m_bounds.x; y += m_bounds.y; - Debug("Mouse wheel event %f %f %f\n", Float(x), Float(y), Float(scaleAmt)); + //Debug("Mouse wheel event %f %f %f\n", Float(x), Float(y), Float(scaleAmt)); Real top = y - m_bounds.y; Real left = x - m_bounds.x; @@ -33,6 +35,7 @@ void View::ScaleAroundPoint(Real x, Real y, Real scaleAmt) m_bounds.y = y - top; m_bounds.w *= scaleAmt; m_bounds.h *= scaleAmt; + Debug("View Bounds => %s", m_bounds.Str().c_str()); } Rect View::TransformToViewCoords(const Rect& inp) const diff --git a/src/view.h b/src/view.h index b099c18..c6c230d 100644 --- a/src/view.h +++ b/src/view.h @@ -10,7 +10,10 @@ namespace IPDF { public: View(Document & document, const Rect & bounds = Rect(0,0,1,1), const Colour & colour = Colour(0.f,0.f,0.f,1.f)) - : m_document(document), m_bounds(bounds), m_colour(colour), m_use_gpu_transform(false) {} + : m_document(document), m_bounds(bounds), m_colour(colour), m_use_gpu_transform(false) + { + Debug("View Created - Bounds => {%s}", m_bounds.Str().c_str()); + } virtual ~View() {} void Render();