Grid Sage Forums

Grid Sage Forums

  • November 23, 2024, 08:31:06 AM
  • Welcome, Guest
Please login or register.

Login with username, password and session length
Advanced search  

News:

LINKS: Website | Steam | Wiki

Author Topic: A quick PNG to REX (xp) converter  (Read 5832 times)

thebracket

  • Unaware
  • *
  • Supported Cogmind Alpha Access 2015-2017 (Prime Tier)
  • Posts: 11
  • One Knight in the Dungeon, Nox Futura dev.
    • View Profile
    • One Knight in the Dungeon
A quick PNG to REX (xp) converter
« on: August 10, 2016, 11:37:45 AM »

Hey,

I don't know if this is useful to anyone, but for my current project I wanted to turn some PNGs into REX files. So I threw together a tool, and put it up on GitHub in case anyone can benefit from it. You can find the tool here: https://github.com/thebracket/png2rex

Basically, it lets you turn:


into this:


There's nothing super clever about it. It reads an RGBA PNG, and converts the RGB parts directly. The Alpha channel is transparent at 0, 1/4 filled at 25%, 1/2 filled at 75%, and a filled cell otherwise. Primitive, but it gets the job done!
Logged

Kyzrati

  • Administrator
  • True Cogmind
  • *****
  • Posts: 4477
    • View Profile
    • Cogmind
Re: A quick PNG to REX (xp) converter
« Reply #1 on: August 10, 2016, 09:06:06 PM »

Nice!

I added a similar feature to REXPaint a few months back, though mine is a little more complicated to use since it's intended for importing screenshots of other roguelikes (so on a cellwise basis rather than pixelwise).

I can see yours coming in handy for a lot more people, though :D. I'll add it to the resource lists.

Edit: Ooh, I just looked at the details and you even have translucency with CP437 tiles; that's awesome.
« Last Edit: August 13, 2016, 09:02:05 AM by Kyzrati »
Logged
Josh Ge, Developer - Dev Blog | @GridSageGames | Patreon

gumix

  • Cyborg
  • ***
  • Posts: 134
    • View Profile
Re: A quick PNG to REX (xp) converter
« Reply #2 on: August 12, 2016, 03:24:38 PM »

@Kyzrati The Kitty png import thing should be considered as a part of next major RP release. Very handy indeed!

@thebracked I love the idea, I can think of a small improvement: user defined alpha ramp in form of simple string (for odd users not using full cp437, I know at least one such guy).
Logged

thebracket

  • Unaware
  • *
  • Supported Cogmind Alpha Access 2015-2017 (Prime Tier)
  • Posts: 11
  • One Knight in the Dungeon, Nox Futura dev.
    • View Profile
    • One Knight in the Dungeon
Re: A quick PNG to REX (xp) converter
« Reply #3 on: August 13, 2016, 08:04:46 AM »

The user-defined alpha ramp is a great idea (I'd thought about some sort of palette system, also, but I'm not sure how I'd best do that yet). I'll see if I can get that in there sometime soon; my time is a bit limited right now due to a sick baby, so I can't make any promises!
Logged

RM

  • Unaware
  • *
  • Posts: 3
    • View Profile
Re: A quick PNG to REX (xp) converter
« Reply #4 on: March 06, 2017, 03:25:58 PM »

This looks amazing - unfortunately, I haven't the slightest idea about how to go about building the source code! I attempted to follow the instructions on the Github page and downloaded CMake... Then realised I didn't have a clue how to go about downloading and installing the other required sources / libraries or even which compiler to use and where to enter the build command. As a non-coder, I find the Github layout quite confusing, so it may be that I'm missing the download link for the exe version? So, I humbly ask, has anyone compiled this PNG2REX utility and able to share it? Thank you.
Logged

Kyzrati

  • Administrator
  • True Cogmind
  • *****
  • Posts: 4477
    • View Profile
    • Cogmind
Re: A quick PNG to REX (xp) converter
« Reply #5 on: March 06, 2017, 09:05:12 PM »

I can't help with building it (maybe someone else here can/will), but in the meantime, REXPaint has a version of this feature built in to it, albeit without character-based dithering. So maybe you could try that.

The instructions are in the manual, Appendix G.

As of now it'll require that you append the "cell size" to the filename to work, so for example converting a regular image will mean appending "_1x1" for pixelwise conversion. (That said, for REXPaint's next release I've updated it to assume pixewise conversion if no cell size is appended, as that will be the most common use case.)

Example: On Windows, you can drop your imagename_1x1.png file in REXPaint's /images/ directory, create a .bat file in the main directory with the following contents
Code: [Select]
start REXPaint.exe -png2xp:imagename_1x1then run the .bat file and it'll output your .xp file. Just open/reopen REXPaint to see it.
Logged
Josh Ge, Developer - Dev Blog | @GridSageGames | Patreon

RM

  • Unaware
  • *
  • Posts: 3
    • View Profile
Re: A quick PNG to REX (xp) converter
« Reply #6 on: March 07, 2017, 02:11:38 AM »

Kyzrati, thanks for your guidance with this! I'll have another go of building it tonight. Thanks too for REXpaint, I've been tinkering with it non stop over the past few days and plan to use it exclusively for a game project I'm fleshing out. I totally overlooked the built in PNG import - awesome! Lack of dithering shouldn't be a problem, it'll be handy just to have my base image in the program to build on.
Logged

Kyzrati

  • Administrator
  • True Cogmind
  • *****
  • Posts: 4477
    • View Profile
    • Cogmind
Re: A quick PNG to REX (xp) converter
« Reply #7 on: March 07, 2017, 02:55:33 AM »

Cool, good luck with it, and yeah it can get pretty addictive :). Do eventually stop by to share what you're working on!

And coincidentally, I was actually just using this feature today--playing around with some ideas...


« Last Edit: March 07, 2017, 02:58:37 AM by Kyzrati »
Logged
Josh Ge, Developer - Dev Blog | @GridSageGames | Patreon

Widmo

  • Derelict
  • **
  • Wiki Contributor Shared a Confirmed Stealth Win Bug Hunter Supported Cogmind Alpha Access 2015-2017 (Prime Tier) Weekly Seed Participant
  • Posts: 83
    • View Profile
Re: A quick PNG to REX (xp) converter
« Reply #8 on: March 07, 2017, 04:26:59 PM »

Hey RM! What platform are you on? If you are on Linux, Mac or anything resembling Unix I could help you through building it.
Logged

RM

  • Unaware
  • *
  • Posts: 3
    • View Profile
Re: A quick PNG to REX (xp) converter
« Reply #9 on: March 08, 2017, 10:37:11 AM »

Kyzrati ~ Very nice ;D I just tried importing/converting some sprites of my own with REXpaint and, of course, it works perfectly - just what I needed! Also, I'd be glad to share some of my creations once I hone my skills a bit.


Widmo ~ Hey! Thank you kindly for offering to help, unfortunately I'm on Windows 10... Although every time I reformat or there's a major update, I seriously consider giving one of the alternatives a go...
Logged

Widmo

  • Derelict
  • **
  • Wiki Contributor Shared a Confirmed Stealth Win Bug Hunter Supported Cogmind Alpha Access 2015-2017 (Prime Tier) Weekly Seed Participant
  • Posts: 83
    • View Profile
Re: A quick PNG to REX (xp) converter
« Reply #10 on: March 08, 2017, 07:34:30 PM »

Ah, a pity. I am unfamiliar with development tools on Windows. Good luck building the program regardless!
Logged

Kyzrati

  • Administrator
  • True Cogmind
  • *****
  • Posts: 4477
    • View Profile
    • Cogmind
Re: A quick PNG to REX (xp) converter
« Reply #11 on: April 19, 2017, 06:36:11 PM »

Hey RM, another REXPaint user ("Santiago") has compiled thebracket's binaries if you'd like to use them. He comments:
Quote
I did manage to compile png2rex on windows. This is only the x64 build as I don't have the win32 libs installed but in case someone still wanted it. One is a static build the big one, the other a shared build. the png and zlib are still part of the exe on the shared but it depends on 2 mingw64 dll to run.

I've attached the files here.
Logged
Josh Ge, Developer - Dev Blog | @GridSageGames | Patreon