[Bf-blender-cvs] SVN commit: /data/svn/bf-blender [26977] branches/soc-2008-mxcurioni/source /blender/freestyle/intern: Fixed bugs in AppCanvas::readColorPixels() and
Tamito Kajiyama
rd6t-kjym at asahi-net.or.jp
Tue Feb 16 22:44:18 CET 2010
Revision: 26977
http://projects.blender.org/plugins/scmsvn/viewcvs.php?view=rev&root=bf-blender&revision=26977
Author: kjym3
Date: 2010-02-16 22:44:18 +0100 (Tue, 16 Feb 2010)
Log Message:
-----------
Fixed bugs in AppCanvas::readColorPixels() and
AppCanvas::readDepthPixels() that caused a crash when
the aspect ratio was not 1:1.
Modified Paths:
--------------
branches/soc-2008-mxcurioni/source/blender/freestyle/intern/application/AppCanvas.cpp
branches/soc-2008-mxcurioni/source/blender/freestyle/intern/application/AppCanvas.h
branches/soc-2008-mxcurioni/source/blender/freestyle/intern/application/Controller.cpp
branches/soc-2008-mxcurioni/source/blender/freestyle/intern/application/Controller.h
branches/soc-2008-mxcurioni/source/blender/freestyle/intern/blender_interface/FRS_freestyle.cpp
Modified: branches/soc-2008-mxcurioni/source/blender/freestyle/intern/application/AppCanvas.cpp
===================================================================
--- branches/soc-2008-mxcurioni/source/blender/freestyle/intern/application/AppCanvas.cpp 2010-02-16 19:41:44 UTC (rev 26976)
+++ branches/soc-2008-mxcurioni/source/blender/freestyle/intern/application/AppCanvas.cpp 2010-02-16 21:44:18 UTC (rev 26977)
@@ -111,46 +111,58 @@
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) {
Modified: branches/soc-2008-mxcurioni/source/blender/freestyle/intern/application/AppCanvas.h
===================================================================
--- branches/soc-2008-mxcurioni/source/blender/freestyle/intern/application/AppCanvas.h 2010-02-16 19:41:44 UTC (rev 26976)
+++ branches/soc-2008-mxcurioni/source/blender/freestyle/intern/application/AppCanvas.h 2010-02-16 21:44:18 UTC (rev 26977)
@@ -48,11 +48,21 @@
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;
};
Modified: branches/soc-2008-mxcurioni/source/blender/freestyle/intern/application/Controller.cpp
===================================================================
--- branches/soc-2008-mxcurioni/source/blender/freestyle/intern/application/Controller.cpp 2010-02-16 19:41:44 UTC (rev 26976)
+++ branches/soc-2008-mxcurioni/source/blender/freestyle/intern/application/Controller.cpp 2010-02-16 21:44:18 UTC (rev 26977)
@@ -176,18 +176,18 @@
_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 @@
_SceneNumFaces = 0;
_minEdgeSize = DBL_MAX;
+ // soc: reset passes
+ setPassDiffuse(NULL, 0, 0);
+ setPassZ(NULL, 0, 0);
}
@@ -867,4 +870,8 @@
// soc: initialize canvas
_Canvas->init();
+
+ // soc: initialize passes
+ setPassDiffuse(NULL, 0, 0);
+ setPassZ(NULL, 0, 0);
}
Modified: branches/soc-2008-mxcurioni/source/blender/freestyle/intern/application/Controller.h
===================================================================
--- branches/soc-2008-mxcurioni/source/blender/freestyle/intern/application/Controller.h 2010-02-16 19:41:44 UTC (rev 26976)
+++ branches/soc-2008-mxcurioni/source/blender/freestyle/intern/application/Controller.h 2010-02-16 21:44:18 UTC (rev 26977)
@@ -70,8 +70,8 @@
~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
Modified: branches/soc-2008-mxcurioni/source/blender/freestyle/intern/blender_interface/FRS_freestyle.cpp
===================================================================
--- branches/soc-2008-mxcurioni/source/blender/freestyle/intern/blender_interface/FRS_freestyle.cpp 2010-02-16 19:41:44 UTC (rev 26976)
+++ branches/soc-2008-mxcurioni/source/blender/freestyle/intern/blender_interface/FRS_freestyle.cpp 2010-02-16 21:44:18 UTC (rev 26977)
@@ -82,8 +82,8 @@
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 @@
// 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;
More information about the Bf-blender-cvs
mailing list