Ariznaf:
Dado que dentro de FastDraw, extra sólo se usa sumado a width, en vez de calcular extra, pasa directamente stride a FastDraw y sustituye width+extra por stride y width2+extra2 por stride2 en cada ocurrencia (eso vale porque en ese punto width y width2 ya estaban multiplicados por 3 y 6 respectivamente). Eso simplifica y optimiza un poco el código y además puede que solucione el problema. Era una optimización básica que tenía pendiente hacer cuando te pasé el código. Nunca pensé que pudiera fallar con anchos de imagen impar, la verdad.
Si sigue fallando, comenta todo el bloque de código inicial que comprueba los límites del buffer y centra la salida (la primera vez que se llama zoom=1, x=0, y=0 y no hay límites que puedan fallar) para ver si está ahí el fallo (mucho más probable ahí que en el resto de la función). Comenta todo esto:
Código:
if(x<0) x=0;
if(y<0) y=0;
if(z>1){
// Solution for out of bounds with zoom > 1.0
if((int)(x+zf*(w+0.5))>=width2) x=(int)(width2-w*zf);
if((int)(y+zf*(h+0.5))>=height2) y=(int)(height2-h*zf);
}else{
// Solution for out of bounds with zoom <= 1.0
if((int)(x+zf*(w-0.5))>=width2) {w=(int)(width2*z-x);}
if((int)(y+zf*(h-0.5))>=height2) {h=(int)(height2*z-y);}
}
// Center render in buffer
cx=(int)((float)width/2-(int)((float)width2*z/2.0));
cy=(int)((float)height/2-(int)((float)height2*z/2.0));
if(cx<0) cx=0;
if(cy<0) cy=0;
if((int)(cx+width2*z)>=width) cx=0;
if((int)(cy+height2*z)>=height) cy=0;
Si todo eso falla sustituye la llamada en C# a FastDraw por llamadas a estas funciones que te pongo abajo según sea de 8 ó 16 bits el buffer (supongo que la de 8 no te hace falta), que es lo más simple (y rápido) que se puede hacer:
Código:
DLLIMPORT void Test8bits(PX8 *buffer, PX8 *buffer2, int width, int height, int stride, int stride2){
int i,w;
w=width*3;
for(i=0;i<height;i++) memcpy(buffer+=stride,buffer2+=stride2,w);
}
DLLIMPORT void Test16bits(PX8 *buffer, PX16 *buffer2, int width, int height, int stride, int stride2){
int i,j,w;
w=width*3;
for(i=0;i<height;i++){
for(j=0;j<w;j++) buffer[j]=(PX8)(buffer2[j]>>8);
buffer+=stride;
buffer2+=stride2;
}
}
Eso debería servir para aislar el problema. Una vez aislado, arreglarlo tiene que ser muy fácil.
Si sigue fallando el error tiene que estar en C#, bien en cómo se llama a fastdraw, bien en cómo se preparan los buffers, bien en un error de GDI+.
Un saludo:
Marcadores