Author Topic: Enlarging sprites?  (Read 27984 times)

0 Members and 2 Guests are viewing this topic.

Offline Runer112

  • Project Author
  • LV11 Super Veteran (Next: 3000)
  • ***********
  • Posts: 2289
  • Rating: +639/-31
    • View Profile
Re: Enlarging sprites?
« Reply #75 on: June 16, 2010, 12:51:59 am »
Here's a very slowed down example of horizontal zooming. Currently, it is doubling the X=24 column of pixels. After this, it would jump to the other side of the screen and double the X=71 (95-24) column, pushing pixels right instead of left. To end up with a fully 2x zoomed image, this is done on different pixel columns and until every column has been doubled.

Before a group of pixels flashes off, the data for those pixels is stored to a variable. (You can only see the flashes affect one or two pixels, but they in fact cover 8 pixels, because:) The pixels in this group are the pixels not being shifted and the single pixel being doubled in the byte containing the X=24 pixel, or in this case, all the pixels in the X=24 byte, because X=24 is the leftmost bit in the byte. We're removing them first so when the byte is multiplied by 2 and thus shifted left by one pixel, we can simply add back their values as they were without a shift. All the pixels to the right of and equal to X=24 will thus retain their values before the shift. Because we happen to be shifting a pixel that is the first bit in its byte, multiplying it by 2 will actually shift that pixel off the end of the byte. But we didn't lost it. Before we multiplied the byte by 2, we stored the value of the leftmost pixel (byte^128) to a variable so we could carry it over to the next byte. Therefore, we will end up with the X=24 pixel and the pixels to the right of it with the same value, but we will add back that carry-over value as the eight bit in the byte to the left, effectively doubling the X=24 pixel. We then move left byte by byte (8 pixels by 8 pixels), storing the leftmost bit, multiplying by 2, and adding back the leftmost bit from the previous byte, shifting bytes by 1 bit until we reach the edge of the screen. This will repeat for Y=0 to 63, then move to the other side of the screen and perform mirrored operations for X=71. This repeats until all pixel columns have been doubled and the outside pixels shifted out.
« Last Edit: June 16, 2010, 01:02:07 am by Runer112 »

Offline DJ Omnimaga

  • Clacualters are teh gr33t
  • CoT Emeritus
  • LV15 Omnimagician (Next: --)
  • *
  • Posts: 55943
  • Rating: +3154/-232
  • CodeWalrus founder & retired Omnimaga founder
    • View Profile
    • Dream of Omnimaga Music
Re: Enlarging sprites?
« Reply #76 on: June 16, 2010, 01:07:53 am »
mhmm I think I am starting to understand the concept a bit. One part I got confused at is how to only store certain pixels in particular. I'm glad you explained it in details. I am still confused at paragraph 2 sentence 4, though x.x

Also in which order do you double rows, btw, after 24 and 71? I assume it's 12 then 83, right? But what would be the exact order afterward?

Offline Runer112

  • Project Author
  • LV11 Super Veteran (Next: 3000)
  • ***********
  • Posts: 2289
  • Rating: +639/-31
    • View Profile
Re: Enlarging sprites?
« Reply #77 on: June 16, 2010, 01:14:00 am »
mhmm I think I am starting to understand the concept a bit. One part I got confused at is how to only store certain pixels in particular. I'm glad you explained it in details. I am still confused at paragraph 2 sentence 4, though x.x

If by sentence 4 you mean "All the pixels to the right of and equal to X=24 will thus retain their values before the shift," here's the explanation. We stored the values of all these pixels (because we happen to want to retain the position of every pixel in this byte, we will store byte^256) to a variable before turning them all of, because we don't want these pixels to move. We had to turn them all off so when we multiplied the byte by 2, the other pixels will be shifted, but 0's will be in the spaces of these pixels, so we can simply add back the value we stored earlier to get these pixels as they were without a shift.

Also in which order do you double rows, btw, after 24 and 71? I assume it's 12 then 83, right? But what would be the exact order afterward?

24,11,36,3,29,15,42,24,9,38,30,14,45,18,1,34,25,7,42,19,37,27,7,46,12,32,21,42,14,36,24,47

It may be easier to understand the following, though:
24,12,36,6,30,18,42,3,27,15,39,9,33,21,45,1,25,13,37,7,31,19,43,4,28,16,40,10,34,22,46,2,26,14,38,8,32,20,44,5,29,17,41,11,35,23,47

The second list is the order in which I'd want to do each pixel column in the original picture. However, because doubling columns before I get to a certain column means the column I really want has been shifted over, I had to account for this, thus the first list.
« Last Edit: June 16, 2010, 01:20:28 am by Runer112 »

Offline DJ Omnimaga

  • Clacualters are teh gr33t
  • CoT Emeritus
  • LV15 Omnimagician (Next: --)
  • *
  • Posts: 55943
  • Rating: +3154/-232
  • CodeWalrus founder & retired Omnimaga founder
    • View Profile
    • Dream of Omnimaga Music
Re: Enlarging sprites?
« Reply #78 on: June 16, 2010, 01:16:40 am »
ah ok thanks a lot ^^

At least now I understand what all that list data was for before the code :P


EDIT: wow didn't see the other post edit, only the last one. After paragraph 4 there was nothing x.x

I think I am starting to get it, altough this seems like a lot of stuff to do x.x

I will probably stay away from that stuff unless I absolutely want to make a game using such stuff and may just use your routine

Thanks anyway, though, for your help
« Last Edit: June 16, 2010, 01:40:40 am by DJ Omnimaga »

Offline ztrumpet

  • The Rarely Active One
  • CoT Emeritus
  • LV13 Extreme Addict (Next: 9001)
  • *
  • Posts: 5712
  • Rating: +364/-4
  • If you see this, send me a PM. Just for fun.
    • View Profile
Re: Enlarging sprites?
« Reply #79 on: June 16, 2010, 11:13:09 am »
Wow, that's complex Runner.  Great job making it work! :D