forked from Galleondragon/qb64
-
Notifications
You must be signed in to change notification settings - Fork 24
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
256 color image artifacts (dots and transparency) #26
Labels
bug
Something isn't working
Comments
@a740g created a QB64-PE issue here: QB64-Phoenix-Edition/QB64pe#175 Thank you @a740g regardless of where it gets fixed :) |
As a work-around until this bug is fixed, we can use this approach (again thanks @a740g for the example): CANVAS& = _NEWIMAGE(800, 600, 32)
SCREEN CANVAS&
speed = 7
limit = 30
w = 512
h = 256
x = (800-w) \ 2
y = (600-h) \ 2
img& = _LOADIMAGE("STARFIGHTER-RGB32b.png", 32)
_PUTIMAGE (x,y), img&, CANVAS&
DO
_LIMIT limit
FOR i = &H75 TO &HFF STEP speed
oldC& = _RGB32(i, i, i)
iStep = i+speed
IF iStep > &HFE THEN iStep = &HFF
newC& = _RGB32(iStep, iStep, iStep)
ReplaceColorInBitmap CANVAS&, oldC&, newC&
_PRINTSTRING (0, 500), HEX$(oldC&) + " -> " + HEX$(newC&), CANVAS&
NEXT i
FOR i = &HFF TO &H75 STEP -speed
oldC& = _RGB32(i, i, i)
iStep = i-speed
IF iStep < &H76 THEN iStep = &H75
newC& = _RGB32(iStep, iStep, iStep)
ReplaceColorInBitmap CANVAS&, oldC&, newC&
_PRINTSTRING (0, 500), HEX$(oldC&) + " -> " + HEX$(newC&), CANVAS&
NEXT i
LOOP UNTIL _KEYHIT = 27
SUB ReplaceColorInBitmap (img&, srcColor&, destColor&)
bpp = _PIXELSIZE(img&) : w = _WIDTH(img&) : h = _HEIGHT(img&)
' Only 32bpp images allowed
IF bpp <> 4 THEN EXIT SUB
' Setup buffer and offset
DIM buffer AS _MEM
buffer = _MEMIMAGE(img&)
DIM AS _OFFSET o, oLast
o = buffer.OFFSET ' Start here
oLast = buffer.OFFSET + w * h * bpp ' Stop here
' s = Source, c = Check, d = Destination
DIM AS _UNSIGNED _BYTE sR, sG, sB, cR, cG, cB, dR, dG, dB
' Source color RGB
sR = _RED(srcColor&)
sG = _GREEN(srcColor&)
sB = _BLUE(srcColor&)
' Destination color RGB
dR = _RED(destColor&)
dG = _GREEN(destColor&)
dB = _BLUE(destColor&)
' Check every color in the image
DO
' Get colors from image
cB = _MEMGET(buffer, o, _UNSIGNED _BYTE) : o = o + 1
cG = _MEMGET(buffer, o, _UNSIGNED _BYTE) : o = o + 1
cR = _MEMGET(buffer, o, _UNSIGNED _BYTE) : o = o + 1
' Check if they match and...
IF (sR = cR AND sG = cG AND sB = cB) THEN
' ...replace if they do
o = o - 3
_MEMPUT buffer, o, dB AS _UNSIGNED _BYTE : o = o + 1
_MEMPUT buffer, o, dG AS _UNSIGNED _BYTE : o = o + 1
_MEMPUT buffer, o, dR AS _UNSIGNED _BYTE : o = o + 1
END IF
o = o + 1
LOOP UNTIL o = oLast
_MEMFREE buffer
END SUB |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
QB64 Version: v2.1
OS: Windows 11 Pro 21H2 (OS Build 22000.856)
(but it also is confirmed to happen on MacOS Monterey too)
Issues:
Using

_LOADIMAGE
with a 256 indexed color image and using_PUTIMAGE
to blit it onto a 32 bit image renders visible artifacts in the resulting image consisting of little dots.Moreover, the transparency isn't working, the source image has a index 0 of pure black, but observe in the screenshots it is some different color not black.

Attempting the work-around mentioned by @a740g in discord resulted in some weird artifacts:
As discussed on discord, @a740g mentioned:
Source:
Screenshots

Here is the image displayed with artifacts:
Here is the source image:

To Reproduce
Steps to reproduce the behavior:
Expected behavior
Attaching the PNG as a zip just in case save for web modifies it.
STARFIGHTER-VGA.zip
The text was updated successfully, but these errors were encountered: