diff options
author | Tamito Kajiyama <rd6t-kjym@asahi-net.or.jp> | 2010-02-17 00:44:18 +0300 |
---|---|---|
committer | Tamito Kajiyama <rd6t-kjym@asahi-net.or.jp> | 2010-02-17 00:44:18 +0300 |
commit | 39ea873a8bc91a7fc4df7b1fa7a7a18239fddae1 (patch) | |
tree | 68a81953a98bc282e804c924b32781230ee74af1 /source | |
parent | ca908e21e215a87f0783fed47feed394ccdea4d6 (diff) |
Fixed bugs in AppCanvas::readColorPixels() and
AppCanvas::readDepthPixels() that caused a crash when
the aspect ratio was not 1:1.
Diffstat (limited to 'source')
5 files changed, 90 insertions, 52 deletions
diff --git a/source/blender/freestyle/intern/application/AppCanvas.cpp b/source/blender/freestyle/intern/application/AppCanvas.cpp index 4ee7244a7dd..4d4ab33cc59 100755 --- a/source/blender/freestyle/intern/application/AppCanvas.cpp +++ b/source/blender/freestyle/intern/application/AppCanvas.cpp @@ -111,46 +111,58 @@ void AppCanvas::Erase() void AppCanvas::readColorPixels(int x,int y,int w, int h, RGBImage& oImage) const { - float *rgb = new float[3*w*h]; - memset(rgb, 0, sizeof(float) * 3 * w * h); - if (_pass_diffuse) { - int rectx = width(), recty = height(); - int i, ii, j, jj; - for (j = 0; j < h; j++) { - jj = y + j; - if (jj < 0 || jj >= recty) - continue; - for (i = 0; i < w; i++) { - ii = x + i; - if (ii < 0 || ii >= rectx) - continue; - memcpy(rgb + (w * j + i) * 3, _pass_diffuse + (rectx * jj + ii) * 3, sizeof(float) * 3); - } - } - } - oImage.setArray(rgb, width(), height(), w,h, x, y, false); + float *rgb = new float[3*w*h]; + memset(rgb, 0, sizeof(float) * 3 * w * h); + int xsch = width(); + int ysch = height(); + if (_pass_diffuse.buf) { + int rectx = _pass_z.width; + int recty = _pass_z.height; + float xfac = ((float)rectx) / ((float)xsch); + float yfac = ((float)recty) / ((float)ysch); + printf("readColorPixels %d x %d @ (%d, %d) in %d x %d -- %d x %d @ %d%%\n", w, h, x, y, xsch, ysch, rectx, recty, (int)(xfac * 100.0f)); + int ii, jj; + for (int j = 0; j < h; j++) { + jj = (int)((y + j) * yfac); + if (jj < 0 || jj >= recty) + continue; + for (int i = 0; i < w; i++) { + ii = (int)((x + i) * xfac); + if (ii < 0 || ii >= rectx) + continue; + memcpy(rgb + (w * j + i) * 3, _pass_diffuse.buf + (rectx * jj + ii) * 3, sizeof(float) * 3); + } + } + } + oImage.setArray(rgb, xsch, ysch, w, h, x, y, false); } void AppCanvas::readDepthPixels(int x,int y,int w, int h, GrayImage& oImage) const { - float *z = new float[w*h]; - memset(z, 0, sizeof(float) * w * h); - if (_pass_z) { - int rectx = width(), recty = height(); - int i, ii, j, jj; - for (j = 0; j < h; j++) { - jj = y + j; - if (jj < 0 || jj >= recty) - continue; - for (i = 0; i < w; i++) { - ii = x + i; - if (ii < 0 || ii >= rectx) - continue; - z[w * j + i] = _pass_z[rectx * jj + ii]; - } - } - } - oImage.setArray(z, width(), height(), w,h, x, y, false); + float *z = new float[w*h]; + memset(z, 0, sizeof(float) * w * h); + int xsch = width(); + int ysch = height(); + if (_pass_z.buf) { + int rectx = _pass_z.width; + int recty = _pass_z.height; + float xfac = ((float)rectx) / ((float)xsch); + float yfac = ((float)recty) / ((float)ysch); + printf("readDepthPixels %d x %d @ (%d, %d) in %d x %d -- %d x %d @ %d%%\n", w, h, x, y, xsch, ysch, rectx, recty, (int)(xfac * 100.0f)); + int ii, jj; + for (int j = 0; j < h; j++) { + jj = (int)((y + j) * yfac); + if (jj < 0 || jj >= recty) + continue; + for (int i = 0; i < w; i++) { + ii = (int)((x + i) * xfac); + if (ii < 0 || ii >= rectx) + continue; + z[w * j + i] = _pass_z.buf[rectx * jj + ii]; + } + } + } + oImage.setArray(z, xsch, ysch, w, h, x, y, false); } void AppCanvas::RenderStroke(Stroke *iStroke) { diff --git a/source/blender/freestyle/intern/application/AppCanvas.h b/source/blender/freestyle/intern/application/AppCanvas.h index 7678014d4a0..b45aafbaf33 100755 --- a/source/blender/freestyle/intern/application/AppCanvas.h +++ b/source/blender/freestyle/intern/application/AppCanvas.h @@ -48,11 +48,21 @@ public: void setViewer(AppView *iViewer) ; // soc - void setPassDiffuse(float *p) {_pass_diffuse = p;} - void setPassZ(float *p) {_pass_z = p;} + void setPassDiffuse(float *buf, int width, int height) { + _pass_diffuse.buf = buf; + _pass_diffuse.width = width; + _pass_diffuse.height = height; + } + void setPassZ(float *buf, int width, int height) { + _pass_z.buf = buf; + _pass_z.width = width; + _pass_z.height = height; + } private: - float *_pass_diffuse; - float *_pass_z; + struct { + float *buf; + int width, height; + } _pass_diffuse, _pass_z; }; diff --git a/source/blender/freestyle/intern/application/Controller.cpp b/source/blender/freestyle/intern/application/Controller.cpp index bf8d30b243e..43f091d3fa1 100755 --- a/source/blender/freestyle/intern/application/Controller.cpp +++ b/source/blender/freestyle/intern/application/Controller.cpp @@ -176,18 +176,18 @@ void Controller::setView(AppView *iView) _Canvas->setViewer(_pView); } -void Controller::setPassDiffuse(float *pass) +void Controller::setPassDiffuse(float *buf, int width, int height) { AppCanvas *app_canvas = dynamic_cast<AppCanvas *>(_Canvas); assert(app_canvas != 0); - app_canvas->setPassDiffuse(pass); + app_canvas->setPassDiffuse(buf, width, height); } -void Controller::setPassZ(float *pass) +void Controller::setPassZ(float *buf, int width, int height) { AppCanvas *app_canvas = dynamic_cast<AppCanvas *>(_Canvas); assert(app_canvas != 0); - app_canvas->setPassZ(pass); + app_canvas->setPassZ(buf, width, height); } void Controller::setContext(bContext *C) @@ -367,6 +367,9 @@ void Controller::CloseFile() _SceneNumFaces = 0; _minEdgeSize = DBL_MAX; + // soc: reset passes + setPassDiffuse(NULL, 0, 0); + setPassZ(NULL, 0, 0); } @@ -867,4 +870,8 @@ void Controller::init_options(){ // soc: initialize canvas _Canvas->init(); + + // soc: initialize passes + setPassDiffuse(NULL, 0, 0); + setPassZ(NULL, 0, 0); } diff --git a/source/blender/freestyle/intern/application/Controller.h b/source/blender/freestyle/intern/application/Controller.h index 83a4f2754b9..9d1db24a026 100755 --- a/source/blender/freestyle/intern/application/Controller.h +++ b/source/blender/freestyle/intern/application/Controller.h @@ -70,8 +70,8 @@ public: ~Controller() ; void setView(AppView *iView); - void setPassDiffuse(float *p); - void setPassZ(float *p); + void setPassDiffuse(float *buf, int width, int height); + void setPassZ(float *buf, int width, int height); void setContext(bContext *C); //soc diff --git a/source/blender/freestyle/intern/blender_interface/FRS_freestyle.cpp b/source/blender/freestyle/intern/blender_interface/FRS_freestyle.cpp index b5f83374668..0ea3280c1bc 100644 --- a/source/blender/freestyle/intern/blender_interface/FRS_freestyle.cpp +++ b/source/blender/freestyle/intern/blender_interface/FRS_freestyle.cpp @@ -82,8 +82,8 @@ extern "C" { void init_view(Render* re){ float ycor = ((float)re->r.yasp) / ((float)re->r.xasp); - int width = re->scene->r.xsch; - int height = (int)(((float)re->scene->r.ysch) * ycor); + int width = re->r.xsch; + int height = (int)(((float)re->r.ysch) * ycor); freestyle_viewport[0] = freestyle_viewport[1] = 0; freestyle_viewport[2] = width; @@ -161,10 +161,19 @@ extern "C" { // set diffuse and z depth passes RenderLayer *rl = RE_GetRenderLayer(re->result, srl->name); - float *diffuse = RE_RenderLayerGetPass(rl, SCE_PASS_DIFFUSE); - float *z = RE_RenderLayerGetPass(rl, SCE_PASS_Z); - controller->setPassDiffuse(diffuse); - controller->setPassZ(z); + bool diffuse = false, z = false; + for (RenderPass *rpass = (RenderPass *)rl->passes.first; rpass; rpass = rpass->next) { + switch (rpass->passtype) { + case SCE_PASS_DIFFUSE: + controller->setPassDiffuse(rpass->rect, rpass->rectx, rpass->recty); + diffuse = true; + break; + case SCE_PASS_Z: + controller->setPassZ(rpass->rect, rpass->rectx, rpass->recty); + z = true; + break; + } + } cout << "Passes :" << endl; cout << " Diffuse = " << (diffuse ? "enabled" : "disabled") << endl; cout << " Z = " << (z ? "enabled" : "disabled") << endl; |