It is currently Thu Oct 19, 2017 8:43 pm

All times are UTC - 7 hours



Forum rules


Related:



Post new topic Reply to topic  [ 95 posts ]  Go to page 1, 2, 3, 4, 5 ... 7  Next
Author Message
PostPosted: Wed Feb 04, 2015 8:45 pm 
Offline
User avatar

Joined: Thu Dec 25, 2014 10:26 pm
Posts: 309
Location: Canada
I wanted to share something I've created that may be potentially marginally useful to some people. I encountered a lot of frustration while originally searching for tools to help with creating SNES sprites, and though I spent a good full day just trying every bit of software I could find nothing seemed to be good for simply editing tiles and converting between a visual and assembly format. So I made a spreadsheet and some macros, which seems to be my solution to everything these days.

Notable features include the ability to import from and export to 16-colour bitmaps (up to 128px wide x 32px tall though could be expanded), exporting as a ".inc" text file of bytes, converting cell colours to two-byte hex values, switching between different palettes and exchanging colours. And honestly, I just find it so much easier to edit in spreadsheet form than any software I've ever used.

The only setup required is to tell it where to save files to. The root path is a global variable at the top of the visual basic file.

If you think it's useful, feel free to suggest other features that could be included. If you think it's redundant then I'm open to suggestions of what to use instead.

EDIT: There have been SEVERAL updates since this first post, I recommend "V2" on this page over the file attached in this post, and the Tiled translation file has been attached here as well


Attachments:
File comment: Tools to translate maps between SNES format and Tiled TMX format
MapReaderTILED.xlsm [424.13 KiB]
Downloaded 44 times
SNESImageMacros.xlsm [175.33 KiB]
Downloaded 128 times


Last edited by Khaz on Sat Dec 17, 2016 10:54 am, edited 4 times in total.
Top
 Profile  
 
 Post subject: Re: Graphics in Excel
PostPosted: Wed Feb 04, 2015 8:51 pm 
Offline
User avatar

Joined: Mon Sep 15, 2014 4:35 pm
Posts: 3071
Location: Nacogdoches, Texas
I don't have Excel on my computer so I can't look at it, but what do you mean? does each box (don't remember what they are called, if they even have a name) represent a pixel?


Top
 Profile  
 
 Post subject: Re: Graphics in Excel
PostPosted: Wed Feb 04, 2015 9:00 pm 
Offline
User avatar

Joined: Thu Dec 25, 2014 10:26 pm
Posts: 309
Location: Canada
Yup! Each cell is a pixel and you just type in the colour number in hex for it (0-F).


Top
 Profile  
 
 Post subject: Re: Graphics in Excel
PostPosted: Wed Feb 04, 2015 9:35 pm 
Offline

Joined: Sun Sep 19, 2004 11:12 pm
Posts: 19104
Location: NE Indiana, USA (NTSC)
Quote:
SNESImageMacros.xlsm

Image macros, eh? I don't have Excel on my machine either. Does it support Impact? :p


Attachments:
File comment: Photo by Evan-Amos, CC BY-SA 3.0
source: https://commons.wikimedia.org/wiki/File:SNES-Mod1-Console-Set.jpg

SNES Happiness in Slavery.jpg
SNES Happiness in Slavery.jpg [ 36.74 KiB | Viewed 2901 times ]
Top
 Profile  
 
 Post subject: Re: Graphics in Excel
PostPosted: Wed Feb 04, 2015 9:42 pm 
Offline
User avatar

Joined: Mon Sep 15, 2014 4:35 pm
Posts: 3071
Location: Nacogdoches, Texas
Quote:
HAPPINES IN SLAVERY

What? (Sorry for not getting the joke...)


Top
 Profile  
 
 Post subject: Re: Graphics in Excel
PostPosted: Wed Feb 04, 2015 9:44 pm 
Offline
User avatar

Joined: Thu Dec 25, 2014 10:26 pm
Posts: 309
Location: Canada
Yeeeah I figured most people wouldn't have it. I wish I knew of an open source alternative that has access to the same level of functionality you get from their macros like file input/output, the ability to control external programs, etc...

And, uh, impact... I'm guessing you mean the font. I don't think I, uh, do that. Yet.


Top
 Profile  
 
 Post subject: Re: Graphics in Excel
PostPosted: Wed Feb 04, 2015 9:50 pm 
Offline

Joined: Sun Sep 19, 2004 11:12 pm
Posts: 19104
Location: NE Indiana, USA (NTSC)
"Happiness in Slavery" is the title of a Nine Inch Nails song. Its use on a photo of a Super NES Control Deck alludes to the "PC master race" meme. So back to topic:

Khaz wrote:
Yeeeah I figured most people wouldn't have it. I wish I knew of an open source alternative that has access to the same level of functionality you get from their macros like file input/output, the ability to control external programs, etc...

Python.

Or client-side JavaScript. You can make versions of your tool that run on both cscript.exe and Node.


Top
 Profile  
 
 Post subject: Re: Graphics in Excel
PostPosted: Wed Feb 04, 2015 9:58 pm 
Offline
User avatar

Joined: Thu Dec 25, 2014 10:26 pm
Posts: 309
Location: Canada
I could theoretically look into learning python someday... Though a large part of what's so efficient about this setup is having the spreadsheet integrated into the program. I'm not sure what would be involved in interacting between something like python and a spreadsheet program. I suppose the practical advice then would be to skip the middleman and not involve a spreadsheet, and just write my own software... But then we get back to how my tool is probably redundant, if I could only figure out how the other dozen I tried are supposed to work.

I'm not sure when I'll have the motivation to put more into this since what I have is working for me quite nicely, but we'll see.


Top
 Profile  
 
 Post subject: Re: Graphics in Excel
PostPosted: Thu Feb 05, 2015 3:49 pm 
Offline

Joined: Mon Jul 02, 2012 7:46 am
Posts: 759
You might look into Open/LibreOffice. I know it supports a lot of the same macro functionality as MSOffice (though it might not use exactly the same syntax), and it's both free and cross-platform.


Top
 Profile  
 
 Post subject: Re: Graphics in Excel
PostPosted: Thu Feb 05, 2015 6:17 pm 
Offline
User avatar

Joined: Thu Dec 25, 2014 10:26 pm
Posts: 309
Location: Canada
I've used LibreOffice before but I wasn't aware it supported those kinds of macros.

After doing some experimenting most of what I have works just opening it in LibreOffice Calc without any changes other than removing the "Application" in "Application.InputBox". A couple relied on a Collection for hex conversion (hC) that doesn't work in Calc for no apparent reason, but it's easily cut out and replaced with manually substituting A-F for 10-15. Conditional formatting and cell colouring looks like it'll have to be completely rewritten though and I have no idea how to do it in calc and I can't find any decent documentation of their API (sic) for it and I can't find the record macro feature either because it's not where they say it is in the options menu.

And then I accidentally closed the window only to find that all the macros I just edited for a couple hours are now GONE. I have no idea what the hell happened. I opened and closed it several times between editing before with no problems. And now I don't want to even try without knowing for certain that it's not going to just lose everything all over again. I also don't even know what format I'm supposed to save it as, .xlsm isn't one of the options but if I change it then it seems to drop all the macros and all the formatting.

I keep trying to switch to alternatives like LibreOffice but to be honest it does something stupid like this to me every time I use it. And unlike MSOffice, searching for answers online will almost always get you nowhere...

EDIT: My version of LibreOffice is somehow hilariously out of date. I will try again, after some kind of break.


Top
 Profile  
 
 Post subject: Re: Graphics in Excel
PostPosted: Thu Feb 05, 2015 6:28 pm 
Offline

Joined: Mon Jul 02, 2012 7:46 am
Posts: 759
.xlsm is a MS Office format, the LibreOffice formats are .odX. If you're saving a full spreadsheet, it's .ods. I'm not sure if there's a file format for saving just a macro by itself. Saving as anything other formats will, of course, drop the macros because they don't support them. If you're editing within LibreOffice, it's best to stick with the native formats rather than trying to export/import the MS formats, as sometimes things will get lost in translation. Also, the LibreOffice forums are a great source of information. If you can't find what you're looking for, ask. This might be relevant to your conditional formatting issues.


Top
 Profile  
 
 Post subject: Re: Graphics in Excel
PostPosted: Fri Feb 06, 2015 1:36 am 
Offline
User avatar

Joined: Fri Nov 12, 2004 2:49 pm
Posts: 7231
Location: Chexbres, VD, Switzerland
Espozo wrote:
does each box (don't remember what they are called, if they even have a name) represent a pixel?

I think they are called "Cells"

(and english is not my language, thus you have no excuse for not knowing this :) )


Top
 Profile  
 
 Post subject: Re: Graphics in Excel
PostPosted: Sat Feb 07, 2015 9:06 pm 
Offline
User avatar

Joined: Thu Dec 25, 2014 10:26 pm
Posts: 309
Location: Canada
As a bleak update, please don't hold your breath for me to finish the .ods format of this.

Even with a whole lot more searching and reading, a lot of answers I need simply don't seem to be out there without literally contacting the people who wrote the program. What I have ALMOST works exactly as-is but the little finicky differences in what LibreOffice will accept is maddening. As of right now it is having seemingly self-contradicting problems in handling objects. For example, in MS VBA to assign an object to a variable you generally have to type "Set thing = Object" rather than just "thing = Object". But if you use "Set" in Libre it doesn't work, but then you take the "Set" out and it just gives you a different error.

I don't know Libre's macro language and I honestly just plain don't have the patience to learn it right now; not without a full listing of the objects they use and their internal parameters and functions. I mean, lacking that, programming is almost literally impossible. And while I'm at it I will state for the record this is precisely why I LOATHE programming anything at a level higher than assembly: You REQUIRE someone else to tell you in infinite detail exactly how these libraries you're using work, or else you'll lose an entire lifetime debugging in the dark. Microsoft's MSDN for Excel VBA is downright exhaustive and it STILL usually isn't enough for me to figure out these kinds of problems.

Long story short: An unregistered version of Excel 2010 will continue to function exactly the same after it's "trial period" has expired. If you have access to such a thing I recommend it. In the meantime I cannot bring myself to waste any more of my very short life on this conversion until I have some more complete resources to work from.

EDIT: Sorry for my earlier frustration. I'm not giving up. Just don't hold your breath, it might take a while.


Top
 Profile  
 
 Post subject: Re: Graphics in Excel
PostPosted: Thu Feb 19, 2015 9:15 pm 
Offline
User avatar

Joined: Thu Dec 25, 2014 10:26 pm
Posts: 309
Location: Canada
Alright, so... I can't say if an open source version of this is ever coming. I looked into converting it to LibreOffice but the short answer is that converting it is impossible and it will have to be entirely rewritten in a different language, probably python. There is support for Excel VBA, but it's not fully implemented and probably never will be.

I wish I could say that I'm going to take the time to redo this open-source, but when I think about how much time that takes out of my actual SNES programming I don't know if I can follow through. What I can do is post a new and improved version of my excel sheet, for those that can use it if any. (It says it was downloaded 15 times, hopefully at least one of those people found it useful.)

To give a better idea of what it is and how it works, I figure I'll just describe it all right here:

------

The basic idea is you have worksheets for tile editing (128 pixels wide by 32 tall, could be made taller) where each cell represents one pixel. You type a colour value (0-F) into a cell and the cell is automatically coloured with conditional formatting. This makes editing very easy to do, and allows you to copy/paste and move blocks of pixels around conveniently.

There is a main "Palettes" worksheet which contains a full set of 16 palettes of colours. Each tile sheet also contains a custom palette of colours in SNES Hex format below the drawing area. You can choose (using macros) whether the conditional formatting will draw from that palette, or one of the 16 palettes on the "Palettes" worksheet.

The macros included are as follows:

CreateBlankTileSheet - Self-explanatory, creates a new blank tile editor worksheet.

DrawTileSheet - Resets the conditional formatting of a tile editor worksheet to display the tiles in any of the 16 palettes on the "Palettes" sheet, or the custom palette on the tile sheet. Can be used in 16 or 4 colour mode: 4 colour mode is for BG palettes only (0-7) and interprets palette numbers as the SNES would (ie/ Palette 1 begins at colour 4).

(You can have multiple palette sheets, but note that the "DrawTileSheet" function will always reference the one titled "Palettes".)

DrawPaletteSheetFromHex - Updates the colours on the active palette sheet according to the hexadecimal values entered.

DrawPaletteSheetFromCellColors - On a palette sheet, you can colour the cell to the left of the colour number (the "Pal #" column) using Excel (Format Cells > Fill, Ctrl+1 is the keyboard shortcut), and then run this macro to update the Hex values to match that colour. This allows you to generate hex values for colours you select visually.

ImportPaletteSheet - Creates a new palette sheet from the specified input file. Must be a text file and generally must be formatted the same as the output of "ExportPaletteSheet" (no indentation, ".dw", one full palette per line).

ExportPaletteSheet - Exports all 16 palettes of the active palette sheet as a .inc (text) file. The file contains two labels, "BGPalettes:" and "SPRPalettes:", each of which are followed by 8 palettes in ".dw" format.

ImportBitmap - Creates a new tile sheet and imports the selected 16-colour (Windows-format) bitmap file into it. Loads the palette inside the bitmap file into the tile sheet's "Custom" palette.

ExportTilesAsBitmap - Exports either a single tile or the entire active tile sheet as a 16-colour (Windows-formatted) bitmap file. User is given the option of white, black or custom background colour.

ExportTilesAsInclude - Exports the active tile sheet in .inc (text) format. Can be run in 16 or 4 colour mode as desired. Gives the user the option of including the custom palette in the same file as well.

SwapColour - On a tile sheet, swaps every cell with a specified colour for another colour. (For example, enter A then B and every cell containing A will be overwritten with B.)

RefreshSheet - Mostly useless. Occasionally the conditional formatting wouldn't take effect for me. This macro just forces it to by re-writing the value of each cell.

------

The only thing you need to do before you get started is set the path to save to. It defaults to "E:\SNESDev\". If you want to change it, you need to edit line 3 of the VBA module, which you can access through Developer > Macros > Edit. (If there's no "Developer" tab at the top you need to enable it under File > Options > Customize Ribbon, on the right side.)

The only thing I can think of to improve this is to possibly add an "ImportTilesFromInclude" function, but I have had no need of it yet since I do all my editing in excel...

Would love feedback if anyone has it.


Attachments:
File comment: Excel Macros for SNES Graphics
SNESTileTools v2.xlsm [137.9 KiB]
Downloaded 102 times
Top
 Profile  
 
 Post subject: Re: Graphics in Excel
PostPosted: Thu Apr 02, 2015 5:39 pm 
Offline
User avatar

Joined: Thu Dec 25, 2014 10:26 pm
Posts: 309
Location: Canada
Wanted to kinda post something new and maybe get some opinions. I'm still doing all my things in Excel and for that I'm sorry, but until I find another intuitively-programmable spreadsheet program I'm afraid it's what I'm sticking with. Anyways to the point:

I'm not an artist by any means. I've somehow ground out some player sprites for my game that I'm pretty happy with, but building an entire world for him to live in still seems an impossible task to me. I've been thinking since the beginning trying to come up with some way I can get some help with that, specifically with designing some backgrounds. My first thought was to try to convert standard images manually into a SNES-friendly format, but I quickly gave up on that when I learned the SNES format. I've recently thought of un-giving-up.

Attached are two files that some might find interesting. ColorDemo is simple and what it sounds like, a few spreadsheets containing every color code supported by the SNES inside cells of that color, so you can just scroll around and pick a color visually if you want. (The different sheets are just different arrangements of the same colours.)

The second project is a bit more ambitious and the point of this post. I've built on my ImportBitmap macro from earlier and created a color-quantizer that will reduce a 24bpp Bitmap image to 15 colors (since color 0 is transparent) using a variation of the "k-means" algorithm. Currently it's limited to images 32x32 pixels in size. Right now the file is very crude. It contains three macros:

"ImportBitmap", basically the same as before, creates a new worksheet and draws the selected bitmap into it. (The difference here is that it's just directly coloring the cells where before I was using cell values and conditional formatting; in other words this isn't set up for output yet.)

"kMeansKwantize", which runs the quantization algorithm. Most of the data it's running through is displayed right on the sheet under the images, you can watch the process. It IS rather slow, as k-Means quantization is an iterative solution basically found through brute force, that may or may not find the optimal solution. You provide it a randomized starting state and it will try to optimize it, but it needs to be run repeatedly to find the best result since the starting state influences the outcome. The way it's set up right now it will go through up to 60 iterations trying to optimize the given starting state before giving up and trying again from the beginning, and it will make a total of 40 attempts before quitting which takes a few minutes. (If you started it and your computer is slow or the file is big and it won't stop I'm sorry, just press Ctrl+Brk.)

"reDrawQuantized" will draw the image in the quantized palettes for you to see. Import bitmap draws two versions of the file on the left, one in original 24bpp and one in SNES-style 15bpp. This macro draws two more on the right side for comparison - third over is current palette, rightmost is best palette. The one sucky part of this that could be fixed in a more legit release is that you have to select the same bitmap file again that you imported originally since it's a separate macro and the raw binary data isn't saved.

ANYWAYS. The big question anyone that read this far is wondering is "Why the hell would you bother when there are programs that quantize for you better and faster". My thought on this is that I can hopefully write a customized program specifically designed to import graphics to the SNES, which will allow you to generate a table of palettes for a much larger image and then assign each 16x16 block of the image a palette such that you're left with a completely assembled image - all you'd have to do is load the tiles, palettes and a tilemap into your game and you've got any arbitrary image file on screen.

In concept I am sure such a thing is possible, but I'm having a hard time right now coming up with a strategy for doing it. If you quantize the entire image all at once you'll end up with every tile containing mixed palettes, which is useless. If you break it down one tile at a time, each tile will generate a unique palette. What I need is a way to calculate a compromise between each piece's ideal palette to come up with a set of 2-to-3 (or up to 8 depending on whether it's just a static image or an actual "background") palettes that will best represent the whole image. I'm not sure where to start.

Does anyone have experience with this kind of project? Has it been done? Anyone know of a reason I should give up?


Attachments:
QuantizTest.xlsm [413.75 KiB]
Downloaded 99 times
ColorDemo.xlsx [1.09 MiB]
Downloaded 138 times
Top
 Profile  
 
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 95 posts ]  Go to page 1, 2, 3, 4, 5 ... 7  Next

All times are UTC - 7 hours


Who is online

Users browsing this forum: No registered users and 7 guests


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
Jump to:  
Powered by phpBB® Forum Software © phpBB Group