Screenshots distorted if width not multiple of 4

Bug #1041710 reported by Jonathan
10
This bug affects 2 people
Affects Status Importance Assigned to Milestone
Armagetron Advanced
Fix Committed
Undecided
Unassigned

Bug Description

See http://forums3.armagetronad.net/viewtopic.php?f=49&t=22719 . There have been other examples in the past, but the only difference is that I bothered to report it this time.

OpenGL's GL_PACK_ALIGNMENT is set to 4. OpenGL will add 0-3 bytes at the end of each row to make a multiple of 4. The SDL surface uses the same logic, and reveals the number of bytes per row in its pitch field. The bug is that Armagetron assumes there are always 3*width bytes per row, which isn't true if width isn't a multiple of 4 (most commonly seen on 1366x768 displays). It should use the surface's pitch value instead.

In make_screenshot (rSysdep.cpp), this code is wrong:

        memcpy(reinterpret_cast<char *>(temp->pixels) + 3 * sr_screenWidth * idx,
               reinterpret_cast<char *>(image->pixels)+ 3
               * sr_screenWidth*(sr_screenHeight - idx-1),
               3*sr_screenWidth);

It should be:

        memcpy(reinterpret_cast<char *>(temp->pixels) + temp->pitch * idx,
               reinterpret_cast<char *>(image->pixels)
               + image->pitch*(sr_screenHeight - idx-1),
               3*sr_screenWidth); // Optionally, use the pitch of either surface here

Likewise, in SDL_SavePNG (also rSysdep.cpp):

        row_ptrs[i] = (png_byte *)image->pixels + (sr_screenHeight - i - 1)
                      * SCREENSHOT_BYTES_PER_PIXEL * sr_screenWidth;

It should be:

        row_ptrs[i] = (png_byte *)image->pixels + (sr_screenHeight - i - 1)
                      * image->pitch;

The bug has always existed. Verified 0.2.8, 0.4, trunk.

Revision history for this message
Matias Pino (pnoexz) wrote :

Cant reproduce as i cant set my screen width to a value not multiple of 4.

Revision history for this message
Jonathan (jonathan12) wrote :

You can set CUSTOM_SCREEN_[WIDTH|HEIGHT] to any resolution. Your custom resolution will appear among the others in the game. Pick it as window size, disable fullscreen, apply, and off you go.

Revision history for this message
David Brandes (brandesign) wrote :

With my new screen this bug affects me too. I tried Jonathans patch and it works.
Attached as .patch file.

Changed in armagetronad:
status: New → Confirmed
Revision history for this message
David Brandes (brandesign) wrote :

I didn't see before. Now the screenshots look a bit stretched.

Revision history for this message
Jonathan (jonathan12) wrote :

Jip: It does look a little narrow, but it should be the same in-game. You should set CUSTOM_SCREEN_ASPECT (which is pixel aspect ratio, not the screen's) to 1 for square pixels, assuming you use the custom mode. Nothing to do with screenshots, right?

Revision history for this message
David Brandes (brandesign) wrote :

I don't use custom mode, resolution is set to Desktop (1366x768) and CUSTOM_SCREEN_ASPECT is 1.
You are right, it looks the same in-game. Just didn't notice because it's moving fast.

Changed in armagetronad:
status: Confirmed → Fix Committed
To post a comment you must log in.
This report contains Public information  
Everyone can see this information.

Other bug subscribers

Remote bug watches

Bug watches keep track of this bug in other bug trackers.