错误的颜色在OS X上使用Pygame进行抗锯齿 [英] Wrong colors antialiasing with Pygame on OS X

查看:137
本文介绍了错误的颜色在OS X上使用Pygame进行抗锯齿的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在运行OS X的Macbook Pro(非视网膜)上使用Pygame.当我尝试创建抗锯齿线或圆时,它似乎是错误的颜色.这是一个示例:

I'm using Pygame on a Macbook Pro (non-retina) running OS X. When I try to create an antialiased line or circle, it seems to be coming out as the wrong color. Here's an example:

import sys, pygame, random, math
import pygame.gfxdraw

black = (0,0,0)
white = (255, 255, 255)
green = (0, 255, 0)


pygame.init()

size = width, height = 800, 600

screen = pygame.display.set_mode(size)

# make the background
background = pygame.Surface(screen.get_size())
#background.fill(black)
background.fill(white)

while 1:
    # handle single events
    for event in pygame.event.get():
        if event.type == pygame.QUIT: sys.exit()

        if event.type == pygame.KEYDOWN:
            if event.key == pygame.K_ESCAPE: sys.exit()

    screen.blit(background, (0, 0))

    pygame.draw.line(screen, green, [0, 0], [50,30], 1)
    pygame.draw.aaline(screen, green, [0, 50],[50, 80], True)

    pygame.draw.circle(screen, black, [100, 100], 10)
    pygame.gfxdraw.aacircle(screen, 100, 130, 10, black)

    pygame.display.flip()

哪个会导致:

推荐答案

尽管搜索了pygame的源代码,但仍找不到原因.

Haven't been able to find the cause for this despite searching through the pygame source code.

我确实设法提出了一种解决方法.实际上是两个.

I did manage to come up with a workaround though. Two actually.

pygame.gfxdraw模块中似乎存在一个错误,当蓝色的值为0时,会导致OS X中的颜色混乱.如果将black更改为(0,0,1),则圆已经看起来好多了,但仍然略带蓝色.将其更改为(0,0,2),它将几乎完全变成黑色.对我来说意义不大,但确实有效.

There seems to be a bug in the pygame.gfxdraw module that causes colors to be messed up in OS X when the value for blue is 0. If you change your black to (0,0,1), the circle will already look much better, but still have a slight blueish tinge. Change it to (0,0,2) and it will appear pretty much completely black. Makes little sense to me but it works.

编辑:用于不包含任何蓝色的背景色.看起来,在包含> 0蓝色的背景RGB上,圆圈至少需要一定数量的蓝色才能防止该错误.例如,要在(50,50,50)背景上获得黑色aacircle,我能够获得的最接近的颜色是对圆圈使用(0,0,50).较低的蓝色量将导致明亮的蓝色伪像.

That's for background colors that don't contain any blue. It appears that on background RGBs containing >0 blue, the circle needs at least that amount of blue to prevent the bug. For example, to get a black aacircle on a (50,50,50) background, the closest I was able to get was by using (0,0,50) for the circle. Any lower amount of blue will result in bright blue artifacts.

不过,添加蓝色无助于修复pygame.draw.aaline的行为.这必须是一个单独的错误.但是,pygame.gfxdraw.line也是抗锯齿的.改用该方法,将green更改为(0,255,1),青色线现在将变为绿色.

Adding blue doesn't help for fixing pygame.draw.aaline's behavior though. This must be a separate bug. However, pygame.gfxdraw.line is also anti-aliased. Use that method instead, change green to (0,255,1) and the cyan line will now be green.

这篇关于错误的颜色在OS X上使用Pygame进行抗锯齿的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆