[Author Prev][Author Next][Thread Prev][Thread Next][Author Index][Thread Index]
[pygame] PATCH: bug in pygame.image.frombuffer
- To: pygame-users@xxxxxxxx
- Subject: [pygame] PATCH: bug in pygame.image.frombuffer
- From: "Alistair Buxton" <a.j.buxton@xxxxxxxxx>
- Date: Fri, 15 Feb 2008 22:06:34 +0000
- Delivered-to: archiver@xxxxxxxx
- Delivered-to: pygame-users-outgoing@xxxxxxxx
- Delivered-to: pygame-users@xxxxxxxx
- Delivery-date: Fri, 15 Feb 2008 17:06:41 -0500
- Dkim-signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=gamma; h=domainkey-signature:received:received:message-id:date:from:to:subject:mime-version:content-type; bh=TRkgwzY1r8t2zcDFLHQ1fCY3dp+gBReRD+SuYQK2Qv8=; b=s0tlabywqovTlUjHo1jtyl8k5VAQbj/ebtS65RI3onXnmfaupNSX4G4m5TIitaorJqx/s8+3SQ3Xi/IhTBzRBW5uv4LWGPLp+Y4QBQn5pL3Sqltqbm812EbAej7F7gkF46S9OhvuZRn0SFn1NNG0rHtAXcTeoDOxPe1iOKE8sl4=
- Domainkey-signature: a=rsa-sha1; c=nofws; d=gmail.com; s=gamma; h=message-id:date:from:to:subject:mime-version:content-type; b=mxOCN88SnK5etMu/0g7RzlTglBtierh9JOmVeQ+Ad/xrTV00fYoGcGFHPtT1Gnfaw3leStrjx1juZu0bpUisz8HfsTFg5KEBBhEtXItXerNsrSbKw7kXVGPHyuMOo+FkjYGRUi3+WRn6KcnIUR+80YrJiEI3yF1GFjTiuK7IDLA=
- Reply-to: pygame-users@xxxxxxxx
- Sender: owner-pygame-users@xxxxxxxx
Hi,
Found a problem with pygame.image.frombuffer and 8 bit images. The
call to SDL_CreateRGBSurfaceFrom uses incorrect pitch, which causes
the image to be be corrupted. pygame.image.fromstring does not have
this problem so you can use that instead as a workaround. The bug is
present in latest subversion code.
Demo script and patch are attached.
--
Alistair Buxton
a.j.buxton@xxxxxxxxx
from struct import unpack
from imageop import mono2grey, scale
import pygame
from pygame.locals import *
pygame.init()
sx,sy = 320,320
screen = pygame.display.set_mode((sx,sy))
# 8x8 checkerboard
pixels = "\x00\xff\x00\xff\x00\xff\x00\xff\xff\x00\xff\x00\xff\x00\xff\x00"*4
# scale to 320x320
newpixels = scale(pixels, 1, 8, 8, 320, 320)
# this produces an image which is warped horizontally:
surface = pygame.image.frombuffer(newpixels, (320, 320), "P")
# this works ok:
#surface = pygame.image.fromstring(newpixels, (320, 320), "P")
surface.set_palette([(0,0,0), (255,255,255)]*128)
running = True
while running:
screen.fill((0,0,0))
screen.blit(surface, (0,0))
for event in pygame.event.get():
if event.type == QUIT:
running = 0
elif event.type == KEYDOWN:
if event.key == K_ESCAPE:
running = 0
pygame.display.flip()
pygame.time.delay(10)
Index: src/image.c
===================================================================
--- src/image.c (revision 1113)
+++ src/image.c (working copy)
@@ -938,7 +938,7 @@
(PyExc_ValueError,
"Buffer length does not equal format and resolution size");
- surf = SDL_CreateRGBSurfaceFrom (data, w, h, 8, 3, 0, 0, 0, 0);
+ surf = SDL_CreateRGBSurfaceFrom (data, w, h, 8, w, 0, 0, 0, 0);
}
else if (!strcmp (format, "RGB"))
{