Author Topic: Tile\sprite Ripper  (Read 4904 times)

0 Members and 1 Guest are viewing this topic.

Offline Cobalt

  • QB64 Developer
  • Forum Resident
  • Posts: 878
  • At 60 I become highly radioactive!
    • View Profile
Tile\sprite Ripper
« on: August 17, 2018, 01:54:34 pm »
Okay, so here is a little program I wrote to rip a tile set from WarCraft 1 to use in my clone as I could not find the plains tile set already ripped(found the swamp tile set and everything else). Its not super efficient, but that was never my goal. Its not terribly customizable, but again not my goal, however it would not be too hard to set up a CONST area where custom values could be used for tile size, image size, ect... . The program does demonstrate some old classic sprite usage with GET\PUT if you just wanted to see how they can, and often were, used way back when. I do not advise there use 'mainstream' now with _putimage being, quite honestly, easier to use, though having its own restrictions. Like not being able to move something around the screen without first putting it on a different image layer.

Not really going to go over the code, just wanted to throw it out there maybe someone else could have a use for it. If you have any questions on parts of it go ahead and ask here. there are quite a few comments in the code but its my 'chicken scratches' so-to-speak so might not be clear to everybody. kind of fun to watch working with the delays on, I believe its like 15-20 mins with them set at there current values. my first run would have taken nearly 75 mins! cause I had them set sooo high. On the map I was using I forgot to move the cursor off the screen when I screen captured so it finds a lot of extra tiles, soooo I'm going to have to recapture the whole thing again. :-{
I've PNGed the map for size, for people with slower connections, and if you have trouble loading it download the latest DB(dirty build) or use build 82(20171106/82) cause that is what I am working with.

Code: QB64: [Select]
  1. 'WarCraft 1 Tile Ripper
  2. '2018 08 17 - 13:45 V1.0 Alpha Build 0001
  3. 'by Cobalt
  4. 'with help from:
  5. '  SMcNeill
  6. '  FellippeHeitor
  7. '  Petr
  8. '  www.QB64.org
  9.  
  10. map& = _LOADIMAGE("warmap01.png", 32)
  11. tile& = _NEWIMAGE(640, 480, 32)
  12. Zoom& = _NEWIMAGE(128, 128, 32)
  13.  
  14. SCREEN _NEWIMAGE(1024, 480, 32)
  15. CONST TRUE = -1, FALSE = NOT TRUE
  16.  
  17. _DONTBLEND 'for whatever reason this is needed for certain things to show up.
  18.  
  19. FOR Y%% = 0 TO 63
  20.  LINE (0, 400)-(1023, 415), _RGB32(0, 0, 0), BF
  21.  _PUTIMAGE (0, 400), map&, _DISPLAY, (0, 0 + 16 * Y%%)-(1023, 15 + 16 * Y%%)
  22.  
  23.  FOR X%% = 0 TO 63
  24.   'debug information
  25.   LOCATE 10, 1: PRINT peices%; X%%; Y%%
  26.  
  27.   'clear and display progress area
  28.   LINE (0, 416)-(1023, 431), _RGB(0, 0, 0), BF
  29.   LINE (0 + 16 * X%%, 416)-(15 + 16 * X%%, 431), _RGB32(200, 200, 15), BF
  30.  
  31.   _SOURCE map& 'get next test peice
  32.   GET (0 + (X%% * 16), 0 + (Y%% * 16))-(15 + (X%% * 16), 15 + (Y%% * 16)), temp()
  33.   'clear test area
  34.   LINE (300, 180)-(336, 216), _RGB32(0, 0, 0), BF
  35.   'put test peice for reference
  36.   PUT (320, 180), temp()
  37.  
  38.   newtile%% = TRUE
  39.   IF peices% = 0 THEN
  40.    'do not test for first tile as there is nothing to test yet.
  41.    _DEST tile&
  42.    PUT (0 + tx%% * 16, 0 + ty%% * 16), temp()
  43.    tx%% = tx%% + 1: peices% = peices% + 1
  44.    IF tx%% = 40 THEN ty%% = ty%% + 1: tx%% = 0
  45.   ELSE
  46.    'test the peice placing 2 copies of each found tile and XOR the test peice
  47.    ' over to see if it erases
  48.  
  49.    px%% = 0: py%% = 0
  50.    'first line of found tiles
  51.  
  52.    'cycle through test peices and check for match
  53.    FOR i% = 0 TO peices%
  54.     'progress bar for peices tested
  55.     LINE (0, 360)-(1023, 376), _RGB32(0, 0, 0), BF
  56.     LINE (0 + px%% * 16, 360)-(15 + px%% * 16, 375), _RGB32(0, 128, 255), BF
  57.     'current line of tiles to test
  58.     _PUTIMAGE (0, 344), tile&, _DISPLAY, (0, 0 + py%% * 16)-(639, 15 + py%% * 16)
  59.  
  60.     LOCATE 11, 1: PRINT i%, px%%, py%%
  61.     'clear test area
  62.     LINE (300, 200)-(336, 216), _RGB32(0, 0, 0), BF
  63.  
  64.     'current check image
  65.     LINE (299, 199)-(316, 216), _RGB32(255, 255, 0), B
  66.     _PUTIMAGE (300, 200), tile&, _DISPLAY, (0 + px%% * 16, 0 + py%% * 16)-(15 + px%% * 16, 15 + py%% * 16)
  67.     'place the test copy
  68.     LINE (319, 199)-(336, 216), _RGB32(RND * 255, 255, RND * 255), B
  69.     _PUTIMAGE (320, 200), tile&, _DISPLAY, (0 + px%% * 16, 0 + py%% * 16)-(15 + px%% * 16, 15 + py%% * 16)
  70.  
  71.     'put the tile to check over the test copy with XOR
  72.     PUT (320, 200), temp(), XOR
  73.     'zoom in on that area
  74.     _DEST Zoom&
  75.     LINE (0, 0)-(127, 127), _RGB32(0, 0, 0), BF 'clear zoom layer
  76.     _PUTIMAGE (0, 0), _DISPLAY, Zoom&, (299, 200)-(336, 215) 'put test area in zoom layer
  77.     _PUTIMAGE (0, 0)-(128, 64), Zoom&, _DISPLAY, (0, 0)-(37, 15) 'put enlarged image back on display
  78.  
  79.     'get the test copy to see if it was erased
  80.     GET (320, 200)-(335, 215), temp(257)
  81.  
  82.     IF TileCount2 = 0 THEN 'matchfound
  83.      newtile%% = FALSE
  84.      i% = peices% + 1
  85.     END IF
  86.     px%% = px%% + 1
  87.     IF px%% = 40 THEN py%% = py%% + 1: px%% = 0
  88.     _DELAY .025
  89.    NEXT i%
  90.  
  91.    IF newtile%% THEN 'no matches found
  92.     LOCATE 12, 1: PRINT TileCount2 'rgb brightness value(I think)
  93.     _DELAY .5
  94.     _DEST tile&
  95.     PUT (0 + tx%% * 16, 0 + ty%% * 16), temp()
  96.     tx%% = tx%% + 1: peices% = peices% + 1
  97.     IF tx%% = 40 THEN ty%% = ty%% + 1: tx%% = 0
  98.    END IF
  99.  
  100.   END IF
  101.   _DELAY .001
  102.   IF INKEY$ = CHR$(27) THEN Y%% = 65: X%% = 66
  103.   px%% = px%% + 1
  104.   IF px%% = 40 THEN py%% = py%% + 1: px%% = 0
  105.  
  106.  NEXT X%%
  107. NEXT Y%%
  108.  
  109. IF X%% < 65 THEN SCREEN tile& 'dont display if user pressed ESC
  110.  
  111. FUNCTION TileCount
  112.  FOR i% = 1 TO 255
  113.   r~%% = _RED(temp(i%))
  114.   g~%% = _GREEN(temp(i%))
  115.   b~%% = _BLUE(temp(i%))
  116.   v& = v& + (r~%% + b~%% + g~%%)
  117.  NEXT i%
  118.  TileCount = v&
  119.  
  120. FUNCTION TileCount2
  121.  FOR i% = 258 TO 513
  122.   r~%% = _RED(temp(i%))
  123.   g~%% = _GREEN(temp(i%))
  124.   b~%% = _BLUE(temp(i%))
  125.   v& = v& + (r~%% + b~%% + g~%%)
  126.  NEXT i%
  127.  TileCount2 = v&
  128.  
  129.  
.
warmap01.png
* warmap01.png (Filesize: 300.27 KB, Dimensions: 1024x1024, Views: 397)
Granted after becoming radioactive I only have a half-life!

Offline johnno56

  • Forum Resident
  • Posts: 1270
  • Live long and prosper.
    • View Profile
Re: Tile\sprite Ripper
« Reply #1 on: August 18, 2018, 05:00:11 am »
First thing: I 'still' play Warcraft 1 and 2... Cool games...
Second thing: When you said it could take some time, you were not wrong. I didn't time it but it took more than 30 mins.
Third thing: Final screen produced a very nice display of all the unique tiles... Nicely done.
Forth thing: After all that work, and producing all those tiles, when the program concluded so did the tiles... At least it produced a tileset... Cool...

Nice job.  ;)
Logic is the beginning of wisdom.

Offline Cobalt

  • QB64 Developer
  • Forum Resident
  • Posts: 878
  • At 60 I become highly radioactive!
    • View Profile
Re: Tile\sprite Ripper
« Reply #2 on: August 18, 2018, 01:35:40 pm »
Yeah didn't have it save the tiles yet, cause I needed to rebuild the map(see all those nice green pointers!). But yeah thouse delays REALLY make it crawl! They were only there mainly for debugging and so I could watch and make sure it was matching correctly. When removed it completes (on my older machine) in right around 1 minute. then you could always screen capture or Saveimage( http://qb64.org/wiki/SAVEIMAGE ) could be added.
Granted after becoming radioactive I only have a half-life!

Offline ExilePrisoner

  • Newbie
  • Posts: 6
    • View Profile
Re: Tile\sprite Ripper
« Reply #3 on: August 28, 2018, 08:08:20 am »
Hello
I run this program and get output to screen so i capoture it to picture for all here to see. Good program that i dont understand much as yet.
warcraftOnetiles.png
* warcraftOnetiles.png (Filesize: 52.97 KB, Dimensions: 1152x648, Views: 376)

Offline Cobalt

  • QB64 Developer
  • Forum Resident
  • Posts: 878
  • At 60 I become highly radioactive!
    • View Profile
Re: Tile\sprite Ripper
« Reply #4 on: August 28, 2018, 11:19:34 am »
Hello
I run this program and get output to screen so i capoture it to picture for all here to see. Good program that i dont understand much as yet.

Please tell me you turned off the _DELAYs before sitting clean through the whole process! Its fun to watch in my opinion but not practical at all with the delays.

I've actually finished this program a little more, the output is a bit cleaner and it saves the tile set with something SMcNeill put together a little ways back. the .BI goes at the top and the .BM goes at the bottom(get it 'BM'... bottom!) of a program. it can save in BMP and PNG(put the zlib.dll in the right folder) and now I have to find the updated Tile ripper cause its not on this machine. typed all this and now I'll just have to edit it when I find it. Ah well.

A few minutes later....

Found.... part of it.. not sure where the full one went, must not have been saved but the only difference was I set up some CONST values to control tile size, spacing, and line count(number of tiles per line) but this out puts a little cleaner by placing a space between each tile.
* StevesSaveImage.rar (Filesize: 47.42 KB, Downloads: 258)
« Last Edit: August 28, 2018, 11:36:59 am by Cobalt »
Granted after becoming radioactive I only have a half-life!