float x1 = x/(float)cx + 0.5f/(float)(cx*32);
float x2 = (x+w)/(float)cx - 0.5f/(float)(cx*32);
float y1 = y/(float)cy + 0.5f/(float)(cy*32);
float y2 = (y+h)/(float)cy - 0.5f/(float)(cy*32);
(edited)float x1 = x/(float)cx + 0.5f/(float)(ImageWidth);
float x2 = (x+w)/(float)cx - 0.5f/(float)(ImageWidth);
float y1 = y/(float)cy + 0.5f/(float)(ImageHeight);
float y2 = (y+h)/(float)cy - 0.5f/(float)(ImageHeight);
smth like this would be correct (edited)