View Single Post
Old 17 May 2017, 23:08   #9
mark_k
Registered User
 
Join Date: Aug 2004
Location:
Posts: 2,482
Here are some notes on code in win32_scaler.cpp. If/when I ever finish getting WinUAE into a buildable state I can try this change myself...
Code:
	OffsetRect (zr, (int)(-filter_horiz_offset * aws), 0);	// filter_horiz_offset is float, aws is int
	OffsetRect (zr, 0, (int)(-filter_vert_offset * ahs));	// filter_vert_offset is float, ahs is int

	xs = dst_width;				// Both int
	if (xmult)				// xmult is float
		xs -= dst_width / xmult;	// int -= int / float;
	ys = dst_height;			// Both int
	if (ymult)				// ymult is float
		ys -= dst_height / ymult;	// int -= int / float;
	sizeoffset (dr, zr, xs, ys);

	filterxmult = xmult;			// Both float
	filterymult = ymult;			// Both float
	filteroffsetx += (dst_width - aw / filterxmult) / 2;	// float += (int - int / float) / 2;
	filteroffsety += (dst_height - ah / filterymult) / 2;	// float += (int - int / float) / 2;

end:

	if (getscalerect (&mrmx, &mrmy, &mrsx, &mrsy)) {
		sizeoffset (dr, zr, mrmx, mrmy);	// 3rd and 4th args are int but mrsx & mrsy are float
		OffsetRect (dr, mrsx, mrsy);		// 2nd and 3rd args are int but mrsx & mrsy are float
	}
To account for truncation when converting float to it, could/should some or all of these be changed, like this:
Code:
// NOTE: I'm just adding 0.5 here but you might need to properly
// round when a float can be either positive or negative

	OffsetRect (zr, (int)(-filter_horiz_offset * aws + 0.5), 0);	// Probably need to round here?
	OffsetRect (zr, 0, (int)(-filter_vert_offset * ahs + 0.5));	// Probably need to round here?

	xs = dst_width;
	if (xmult)
		xs -= dst_width / xmult + 0.5;
	ys = dst_height;
	if (ymult)
		ys -= dst_height / ymult + 0.5;
	sizeoffset (dr, zr, xs, ys);
	...
end:

	if (getscalerect (&mrmx, &mrmy, &mrsx, &mrsy)) {
		sizeoffset (dr, zr, mrmx + 0.5, mrmy + 0.5);
		OffsetRect (dr, mrsx + 0.5, mrsy + 0.5);
	}
getscalerect() just returns false if mask2texture is 0. [So is that statement relevant to this off-by-one issue?]

About sizeoffset()...
Suppose you call sizeoffset() with mrmx = 3.9 say. Then 3.9 (float) is truncated to 3 (int) for the function call.
Then the "int w" argument to sizeoffset() is 3, which means sizeoffset() calls OffsetRect() with 2nd arg 1.
Code:
static void sizeoffset (RECT *dr, RECT *zr, int w, int h)
{
	dr->right -= w;
	dr->bottom -= h;
	OffsetRect (zr, w / 2, h / 2);
}
mark_k is offline  
 
Page generated in 0.04795 seconds with 9 queries