4KB Explosions Contest

General discussion about LÖVE, Lua, game development, puns, and unicorns.
User avatar
tentus
Inner party member
Posts: 1060
Joined: Sun Oct 31, 2010 7:56 pm
Location: Appalachia
Contact:

Re: 4KB Explosions Contest

Post 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...
Kurosuke needs beta testers
User avatar
thelinx
The Strongest
Posts: 857
Joined: Fri Sep 26, 2008 3:56 pm
Location: Sweden

Re: 4KB Explosions Contest

Post by thelinx »

tentus wrote:Would you mind compressing the other one, for comparison's sake?
The other one being?
User avatar
TechnoCat
Inner party member
Posts: 1611
Joined: Thu Jul 30, 2009 12:31 am
Location: Milwaukee, WI
Contact:

Re: 4KB Explosions Contest

Post 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
windwaker.png (518 Bytes) Viewed 2930 times
User avatar
tentus
Inner party member
Posts: 1060
Joined: Sun Oct 31, 2010 7:56 pm
Location: Appalachia
Contact:

Re: 4KB Explosions Contest

Post 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.
Kurosuke needs beta testers
User avatar
kikito
Inner party member
Posts: 3153
Joined: Sat Oct 03, 2009 5:22 pm
Location: Madrid, Spain
Contact:

Re: 4KB Explosions Contest

Post 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.
Last edited by kikito on Tue Jan 11, 2011 6:38 pm, edited 1 time in total.
When I write def I mean function.
User avatar
Robin
The Omniscient
Posts: 6506
Joined: Fri Feb 20, 2009 4:29 pm
Location: The Netherlands
Contact:

Re: 4KB Explosions Contest

Post 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.
Last edited by Robin on Tue Jan 11, 2011 6:45 pm, edited 1 time in total.
Help us help you: attach a .love.
User avatar
TechnoCat
Inner party member
Posts: 1611
Joined: Thu Jul 30, 2009 12:31 am
Location: Milwaukee, WI
Contact:

Re: 4KB Explosions Contest

Post 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!
How come you never call anymore? We used to be such great pals!
windwaker.gif (453 Bytes) Viewed 2917 times
User avatar
Robin
The Omniscient
Posts: 6506
Joined: Fri Feb 20, 2009 4:29 pm
Location: The Netherlands
Contact:

Re: 4KB Explosions Contest

Post by Robin »

TechnoCat wrote:*Ring ring ring* Hey, it's me gif!
PNG or GIF GTFO. :P
Help us help you: attach a .love.
User avatar
tentus
Inner party member
Posts: 1060
Joined: Sun Oct 31, 2010 7:56 pm
Location: Appalachia
Contact:

Re: 4KB Explosions Contest

Post 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.
Kurosuke needs beta testers
User avatar
TechnoCat
Inner party member
Posts: 1611
Joined: Thu Jul 30, 2009 12:31 am
Location: Milwaukee, WI
Contact:

Re: 4KB Explosions Contest

Post 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.
Post Reply

Who is online

Users browsing this forum: Amazon [Bot], Bing [Bot] and 4 guests