Gatiori
29th June 2007, 19:53
I want to make an Avisynth filter like "Minimum/Maximum" (photoshop). I know a little about programming in C++, but I don't know if it is possible optimize this filter.
If you help me to optimize this code, I will tanks you a lot.
This is very slow.
How to make more fast?.
This is the code for RGB24 and RGB32:
if (vi.IsRGB24()) {
for (h=0; h < src_height;h++) {
for (w = 0; w < src_width; w+=3) {
if (Radius>=0) {
l1=0;
}
else {
l1=255;
}
for (y=-abs(Radius); y<=abs(Radius);y++) {
for (x=-abs(Radius); x<=abs(Radius);x++) {
if (w+(x*3)>=0 && w+(x*3)<src_width && (h+y)<src_height && (h+y)>=0) {
b=*(srcp+w + (x*3)+(y*src_pitch));
g=*(srcp + w+1+(x*3)+(y*src_pitch));
r=*(srcp + w+2+(x*3)+(y*src_pitch));
l=(r+g+b)/3;
if ((l>l1 && Radius>=0) || (l<l1 && Radius<0)) {
x1=x;
y1=y;
l1=l;
}
}
}
}
*(dstp + w)= *(srcp + w+(x1*3)+(y1*src_pitch));
*(dstp + w+1)= *(srcp + w + 1+(x1*3)+(y1*src_pitch));
*(dstp + w+2)= *(srcp + w + 2+(x1*3)+(y1*src_pitch));
}
srcp = srcp + src_pitch;
dstp = dstp + dst_pitch;
}
}
if (vi.IsRGB32()) {
for (h=0; h < src_height;h++) {
for (w = 0; w < src_width/4; w+=1) {
if (Radius>=0) {
l1=-1; //*((unsigned int *)dstp + w)=0x00000000;
}
else {
l1=256;//*((unsigned int *)dstp + w)=0x00ffffff;
}
x1=0;
y1=0;
for (y=-abs(Radius); y<=abs(Radius);y++) {
for (x=-abs(Radius); x<=abs(Radius);x++) {
if (w+x>=0 && w+x<(src_width/4) && (h+y)<src_height && (h+y)>=0) {
// pix=*((unsigned int *)srcp + w);
pix=*((unsigned int *)srcp + w + x+(y*(src_pitch/4)));
b=pix%256;
g=(pix%(65536)-b)/256;
r=(pix-(pix%(65536)))/65536;
l=(r+g+b)/3;
if ((l>l1 && Radius>=0) || (l<l1 && Radius<0)) {
x1=x;
y1=y;
l1=l;
}
}
}
}
*((unsigned int *)dstp + w) = *((unsigned int *)srcp + w +x1+(y1*(src_pitch/4)));
}
srcp = srcp + src_pitch;
dstp = dstp + dst_pitch;
}
}
Help...
... please..
If you help me to optimize this code, I will tanks you a lot.
This is very slow.
How to make more fast?.
This is the code for RGB24 and RGB32:
if (vi.IsRGB24()) {
for (h=0; h < src_height;h++) {
for (w = 0; w < src_width; w+=3) {
if (Radius>=0) {
l1=0;
}
else {
l1=255;
}
for (y=-abs(Radius); y<=abs(Radius);y++) {
for (x=-abs(Radius); x<=abs(Radius);x++) {
if (w+(x*3)>=0 && w+(x*3)<src_width && (h+y)<src_height && (h+y)>=0) {
b=*(srcp+w + (x*3)+(y*src_pitch));
g=*(srcp + w+1+(x*3)+(y*src_pitch));
r=*(srcp + w+2+(x*3)+(y*src_pitch));
l=(r+g+b)/3;
if ((l>l1 && Radius>=0) || (l<l1 && Radius<0)) {
x1=x;
y1=y;
l1=l;
}
}
}
}
*(dstp + w)= *(srcp + w+(x1*3)+(y1*src_pitch));
*(dstp + w+1)= *(srcp + w + 1+(x1*3)+(y1*src_pitch));
*(dstp + w+2)= *(srcp + w + 2+(x1*3)+(y1*src_pitch));
}
srcp = srcp + src_pitch;
dstp = dstp + dst_pitch;
}
}
if (vi.IsRGB32()) {
for (h=0; h < src_height;h++) {
for (w = 0; w < src_width/4; w+=1) {
if (Radius>=0) {
l1=-1; //*((unsigned int *)dstp + w)=0x00000000;
}
else {
l1=256;//*((unsigned int *)dstp + w)=0x00ffffff;
}
x1=0;
y1=0;
for (y=-abs(Radius); y<=abs(Radius);y++) {
for (x=-abs(Radius); x<=abs(Radius);x++) {
if (w+x>=0 && w+x<(src_width/4) && (h+y)<src_height && (h+y)>=0) {
// pix=*((unsigned int *)srcp + w);
pix=*((unsigned int *)srcp + w + x+(y*(src_pitch/4)));
b=pix%256;
g=(pix%(65536)-b)/256;
r=(pix-(pix%(65536)))/65536;
l=(r+g+b)/3;
if ((l>l1 && Radius>=0) || (l<l1 && Radius<0)) {
x1=x;
y1=y;
l1=l;
}
}
}
}
*((unsigned int *)dstp + w) = *((unsigned int *)srcp + w +x1+(y1*(src_pitch/4)));
}
srcp = srcp + src_pitch;
dstp = dstp + dst_pitch;
}
}
Help...
... please..