summaryrefslogtreecommitdiff
path: root/dgedit/canvas.cc
diff options
context:
space:
mode:
authordeva <deva>2010-01-04 16:04:54 +0000
committerdeva <deva>2010-01-04 16:04:54 +0000
commitc393edc920f8ee126d1bced3500b6bc1ecf86f83 (patch)
tree6a59779b286693c243049af7864635b5f4328a52 /dgedit/canvas.cc
parent2c2985610520acae8b83fa454343039a3109d24f (diff)
Optimized mipmap generation on load.
Diffstat (limited to 'dgedit/canvas.cc')
-rw-r--r--dgedit/canvas.cc66
1 files changed, 25 insertions, 41 deletions
diff --git a/dgedit/canvas.cc b/dgedit/canvas.cc
index 08005c7..4c63e5e 100644
--- a/dgedit/canvas.cc
+++ b/dgedit/canvas.cc
@@ -83,27 +83,27 @@ Canvas::~Canvas()
#define VALU(x) (x*4+1)
#define POWL(x) (x*4+2)
#define POWU(x) (x*4+3)
-/*
-static void genmipmap(float *in, size_t insz, float **out, size_t *outsz)
+
+static void genmipmap(float *in, size_t insz, float *out, size_t outsz)
{
- *outsz = (insz / 2) * 4;
- *out = new float[*outsz];
- float *lookup = *out;
+ float *lookup = out;
- for(size_t i = 0; i < *outsz / 4; i++) {
+ for(size_t i = 0; i < outsz; i++) {
lookup[VALL(i)] = 0.0;
lookup[VALU(i)] = 0.0;
lookup[POWL(i)] = 0.0;
lookup[POWU(i)] = 0.0;
- for(size_t j = i * 2; j < i*2+2 && j < insz / 4; j++) {
+
+ for(size_t j = i * (insz / outsz); j < (i+1)*(insz / outsz); j++) {
if(in[VALU(j)] > lookup[VALU(i)]) lookup[VALU(i)] = in[VALU(j)];
if(in[VALL(j)] < lookup[VALL(i)]) lookup[VALL(i)] = in[VALL(j)];
if(in[POWU(j)] > 0) lookup[POWU(i)] += in[POWU(j)];
if(in[POWL(j)] < 0) lookup[POWL(i)] += in[POWL(j)];
}
+
}
}
-*/
+
void Canvas::load(QString file)
{
if(data) {
@@ -133,49 +133,33 @@ void Canvas::load(QString file)
sf_close(fh);
+ size_t lastsz = 0;
for(size_t dev = 2; dev <= MIPMAPS; dev*=2) {
size_t mipmapsize = size/dev;
float *lookup = new float[mipmapsize * 4];
- for(size_t i = 0; i < mipmapsize; i++) {
- lookup[VALL(i)] = 0.0;
- lookup[VALU(i)] = 0.0;
- lookup[POWL(i)] = 0.0;
- lookup[POWU(i)] = 0.0;
- for(size_t j = i * dev; j < (i + 1) * dev; j++) {
- if(data[j] > lookup[VALU(i)]) lookup[VALU(i)] = data[j];
- if(data[j] < lookup[VALL(i)]) lookup[VALL(i)] = data[j];
- if(data[j] > 0) lookup[POWU(i)] += data[j];
- if(data[j] < 0) lookup[POWL(i)] += data[j];
+
+ if(dev == 2) {
+ for(size_t i = 0; i < mipmapsize; i++) {
+ lookup[VALL(i)] = 0.0;
+ lookup[VALU(i)] = 0.0;
+ lookup[POWL(i)] = 0.0;
+ lookup[POWU(i)] = 0.0;
+ for(size_t j = i * dev; j < (i + 1) * dev; j++) {
+ if(data[j] > lookup[VALU(i)]) lookup[VALU(i)] = data[j];
+ if(data[j] < lookup[VALL(i)]) lookup[VALL(i)] = data[j];
+ if(data[j] > 0) lookup[POWU(i)] += data[j];
+ if(data[j] < 0) lookup[POWL(i)] += data[j];
+ }
}
+ } else {
+ genmipmap(mipmaps[dev/2], lastsz, lookup, mipmapsize);
}
+ lastsz = mipmapsize;
mipmaps[dev] = lookup;
}
- /*
-
- size_t sz = (size / 2) * 4;
- mipmaps[2] = new float[sz];
- float *lookup = mipmaps[2];
- for(size_t i = 0; i < sz; i++) {
- lookup[VALL(i)] = 0.0;
- lookup[VALU(i)] = 0.0;
- lookup[POWL(i)] = 0.0;
- lookup[POWU(i)] = 0.0;
- for(size_t j = i * 2; j < (i + 1) * 2; j++) {
- if(data[j] > lookup[VALU(i)]) lookup[VALU(i)] = data[j];
- if(data[j] < lookup[VALL(i)]) lookup[VALL(i)] = data[j];
- if(data[j] > 0) lookup[POWU(i)] += data[j];
- if(data[j] < 0) lookup[POWL(i)] += data[j];
- }
- }
- size_t dev = 3;
- do {
- genmipmap(mipmaps[dev], sz, &mipmaps[dev], &sz);
- dev++;
- } while(sz > 2);
- */
updateWav();
update();
}