Page 3 of 14
Re: 4KB Explosions Contest
Posted: Tue Jan 11, 2011 6:21 pm
by tentus
TechnoCat wrote:tentus wrote:@kikito/Technocat: Bad aliasing drives me nuts. How would you do it in code, so I can see how the results turn out? Also, PNG-8 has some well-known gamma problems (
http://hsivonen.iki.fi/png-gamma/). This might not be true within Love, but I still shy away from the format.
You can't have soft edges with no alpha channel.
But an easy way to turn green into transparent would be to use
http://love2d.org/wiki/ImageData:mapPixel
Code: Select all
function pixelFunction(x, y, r, g, b, a)
if r==0 and g==255 and b==0 then
a = 0
return r, g, b, a
end
ImageData:mapPixel( pixelFunction )
Kikito suggested it could be done in Lua, if I understood him correctly. I'm guessing you'd have to track the previous pixel, and on color change you would use an intermediate alpha with the previous color? That would lead to serious blurring though...
Re: 4KB Explosions Contest
Posted: Tue Jan 11, 2011 6:26 pm
by thelinx
tentus wrote:Would you mind compressing the other one, for comparison's sake?
The other one being?
Re: 4KB Explosions Contest
Posted: Tue Jan 11, 2011 6:27 pm
by TechnoCat
tentus wrote:Kikito suggested it could be done in Lua, if I understood him correctly. I'm guessing you'd have to track the previous pixel, and on color change you would use an intermediate alpha with the previous color? That would lead to serious blurring though...
Another thing you can try is to make the image at half size, and then have LOVE scale it to 2x with linear filtering. Eh? Maybe have LOVE do the aliasing?
- windwaker.png (518 Bytes) Viewed 2939 times
Re: 4KB Explosions Contest
Posted: Tue Jan 11, 2011 6:31 pm
by tentus
TechnoCat wrote:
Another thing you can try is to make the image at half size, and then have LOVE scale it to 2x with linear filtering. Eh? Maybe have LOVE do the aliasing?
The designer in me unconditionally rejects this solution, which I feel kinda bad about. Sorry, but I couldn't live with that solution, it goes against every fiber of my body.
thelinx wrote:
The other one being?
The first image I posted,
http://love2d.org/forums/download/file.php?id=2240. It uses alpha rather than the g channel.
Re: 4KB Explosions Contest
Posted: Tue Jan 11, 2011 6:33 pm
by kikito
The only thing I can think about is storing a very basic image (maybe with an even smaller pallete, 8 colors or so) and then adding some blur. For example, the
box blur. I don't know the details of imagedata, but in pseudocode it's like this:
Code: Select all
function blur(sourceImage)
imageData = <create a new imagedata with the same with and height as sourceImage>
for each pixel(x,y) in sourceImage
-- "adjacent" can be 4 pixels, or 8 pixels, if you include the diagonal ones. In corners and borders, they're less pixels.
<obtain the r,g,b,a values of the pixels adjacent to (x,y) in sourceImage>
imageData[x][y] = <the average rgba values of the adjacent pixels in sourceImage>
end
return imagedata
end
EDIT:
tentus wrote:That would lead to serious blurring though...
The blur I'm proposing is 3-pixels wide, and we're talking about a smoke sprite that will be moving, changing in size, and fading. But if that's a problem the loop above can be changed so blurring only applies if at least one of the pixels has an alpha. This will blur the image borders, but leave the internal parts intact.
Re: 4KB Explosions Contest
Posted: Tue Jan 11, 2011 6:34 pm
by Robin
I don't know anything about this, but wouldn't it be possible to use the g-channel completely for alpha? As in:
Code: Select all
function pixelFunction(x, y, r, g, b, a)
return r, 0, b, g -- no green?
end
ImageData:mapPixel( pixelFunction )
Probably not, eh?
EDIT: 2525! OK, I'll stop now. No I won't.
Re: 4KB Explosions Contest
Posted: Tue Jan 11, 2011 6:37 pm
by TechnoCat
Robin wrote:I don't know anything about this, but wouldn't it be possible to use the g-channel completely for alpha? As in:
Code: Select all
function pixelFunction(x, y, r, g, b, a)
return r, 0, b, g -- no green?
end
ImageData:mapPixel( pixelFunction )
Probably not, eh?
Close, but it would probably need to be:
Code: Select all
function pixelFunction(x, y, r, g, b, a)
return r, r, b, g --double r or b to make it grey
end
ImageData:mapPixel( pixelFunction )
You could probably write the image out to take 4 bits per pixel in a binary file, 2 for greyscale, 2 for alpha. That could make a really small file.
*Ring ring ring* Hey, it's me gif!
- How come you never call anymore? We used to be such great pals!
- windwaker.gif (453 Bytes) Viewed 2926 times
Re: 4KB Explosions Contest
Posted: Tue Jan 11, 2011 6:43 pm
by Robin
TechnoCat wrote:*Ring ring ring* Hey, it's me gif!
PNG or
GIF GTFO.
Re: 4KB Explosions Contest
Posted: Tue Jan 11, 2011 6:44 pm
by tentus
TechnoCat wrote:Robin wrote:I don't know anything about this, but wouldn't it be possible to use the g-channel completely for alpha? As in:
Code: Select all
function pixelFunction(x, y, r, g, b, a)
return r, 0, b, g -- no green?
end
ImageData:mapPixel( pixelFunction )
Probably not, eh?
Close, but it would probably need to be:
Code: Select all
function pixelFunction(x, y, r, g, b, a)
return r, r, b, g --double r or b to make it grey
end
ImageData:mapPixel( pixelFunction )
You could probably write the image out to take 4 bits per pixel in a binary file, 2 for greyscale, 2 for alpha. That could make a really small file.
*Ring ring ring* Hey, it's me gif!
windwaker.gif
Wouldn't you also need to invert the g value, since 255 alpha is opaque?
Code: Select all
function pixelFunction(x, y, r, g, b, a)
return r, r, b, (255 - g) --double r or b to make it grey
end
ImageData:mapPixel( pixelFunction )
Also, I'm consistently surprised at how often I use GIF at work, it's a
great
image
format.
Re: 4KB Explosions Contest
Posted: Tue Jan 11, 2011 6:47 pm
by TechnoCat
tentus wrote:Wouldn't you also need to invert the g value, since 255 alpha is opaque?
Code: Select all
function pixelFunction(x, y, r, g, b, a)
return r, r, b, (255 - g) --double r or b to make it grey
end
ImageData:mapPixel( pixelFunction )
Also, I'm consistently surprised at how often I use GIF at work, it's a
great
image
format.
Yeah, you would have to figure something out to do it. It might not look correct in an image viewer, but look correct after you parse it depending on what you do.
I like how we're putting all hands on deck to undermine the avoidance of sprites.