Fixed bugs in AppCanvas::readColorPixels() and
AppCanvas::readDepthPixels() that caused a crash when the aspect ratio was not 1:1.
This commit is contained in:
@@ -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) {
|
||||
|
||||
@@ -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;
|
||||
};
|
||||
|
||||
|
||||
|
||||
@@ -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);
|
||||
}
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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;
|
||||
|
||||
Reference in New Issue
Block a user