Image resampling and resizing
Hmmm, I don't think so. I believe that j already accounts for the rgba because of it's relation to x and i. i is the index value which is multiplied by 4. Correct me if I'm wrong, however when I implement this I get overflows and if I check against them only the bottom row of the image is drawn and things in that row aren't correct either. Any other ideas?
Source is a char*.
Each pixel is 4 bytes wide. Therefore pixel 0 is at index 0, pixel 1 is at index 4, pixel 2 at index 8, etc. Therefore when you index individual pixels in your source image they should be 4 bytes apart. You increment j by one each loop, not 4.
You have another problem which I've also hinted at earlier. On the left hand side, x is 0. When you add subtract your radius from this (in yout inner loop) you get -2.
Really, the outer 2 (or radius) pixels are undefined. You need a way of dealing with this.
Each pixel is 4 bytes wide. Therefore pixel 0 is at index 0, pixel 1 is at index 4, pixel 2 at index 8, etc. Therefore when you index individual pixels in your source image they should be 4 bytes apart. You increment j by one each loop, not 4.
You have another problem which I've also hinted at earlier. On the left hand side, x is 0. When you add subtract your radius from this (in yout inner loop) you get -2.
Really, the outer 2 (or radius) pixels are undefined. You need a way of dealing with this.
Oops. My bad, I was 1/2 right anyway.
for(int j = - radius; j < radius; j++) { sr += source[(j*4)+x] * f.compute(x-j); sg += source[(j*4)+x+1] * f.compute(x-j); sb += source[(j*4)+x+2] * f.compute(x-j); sa += source[(j*4)+x+3] * f.compute(x-j);}
What I meant was:
The first line calculates the index, the second scales the index. This is wrong. What you want is to first scale the col, then calculate the index:
i = index(col,row,newWidth); int x = x0 + i * deltaX;
The first line calculates the index, the second scales the index. This is wrong. What you want is to first scale the col, then calculate the index:
newIndex = index(col,row,newWidth); oldIndex = index(col * deltaX,row,oldWidth) int x = x0 + oldIndex;
Ok, I edited my loops so it now looks like this:
My result is this. The colors are right, but my scaling is odd to say the least. Actually, I guess I do have a scaled x,y image in there...
for(int row = 0; row < height; row++) { for(int col = 0; col < newWidth; col++) { float sr = 0,sg = 0,sb = 0,sa = 0; i = index(col,row,newWidth); int x = x0 + i * deltaX; for(int j = x - radius; j < x+radius; j++) { if((j*4)>0 && (j*4)+3 < oldWidth * height * 4) { sr += source[(int)(j*4)] * f.compute(x-j); sg += source[(int)(j*4)+1] * (float)f.compute(x-j); sb += source[(int)(j*4)+2] * (float)f.compute(x-j); sa += source[(int)(j*4)+3] * (float)f.compute(x-j); } } result = (int)sr; result[i+1] = (int)sg; result[i+2] = (int)sb; result[i+3] = (int)sa; } }
My result is this. The colors are right, but my scaling is odd to say the least. Actually, I guess I do have a scaled x,y image in there...
Have you seen my last post? (next to last on page 1)
I think it explains why your image is scaled in y.
I think it explains why your image is scaled in y.
Yeah I just changed that, but it still seems to be scaling in y. I need to work with it a little more though as I'm probably screwing something up. Check back in like 5 or 10 minutes.
HA HA finally it is working (almost) perfectly. Changing the scaling stuff worked. I still get some odd colors at selected scales (like 33%), but i think this has to do with my radius choice. I'll play with it a little more. Once I have it working I'll post my code. You two (i'm assuming anonymous poster has been one consistent individual) are life savers.
So, Nick; how's University of Wisconsin-Madison treating you so far?
You might be interested in this snippet from the forum FAQ:
- you shouldn't ask for homework help.
Have a nice day.
You might be interested in this snippet from the forum FAQ:
- you shouldn't ask for homework help.
Have a nice day.
This topic is closed to new replies.
Advertisement
Popular Topics
Advertisement