grit - GBA Raster Image Transmogrifier

Grit and its GUI version Wingrit are my image converters for the GBA (and NDS I guess). They can do most of the simple things like reading an image (pretty much any type of bitmap thanks to FreeImage) and converting it to binary data of various bitdepths which can be directly put into VRAM, but also more complicated matters such as tiling and metatiling (for 1D object mapping for example), making a tilemap along with a reduced tileset (or using an external tileset), popular map layouts, and compression compatible with the GBA's BIOS routines. The capability for an NDS alphabit has been added recently as well. Output can be C/asm arrays, raw binary, GBFS, and a RIFF-based format called GRF.

Not good enough? Well, the source code is available too, so you're free to modify it. The code should be platform independent right now, or at least very nearly so; the catch being that you might have add or remove some type definitions and maybe create your own makefile for compilation.

Documentation

grit-readme.txt, wingrit-readme.txt, Manuals,

Grit Downloads

Current version: 0.8.6

Previous versions

30 thoughts on “grit - GBA Raster Image Transmogrifier

  1. Pingback: Embedding graphics in the DS using grit

  2. To make Grit compile with GCC 4.4, I had to make the following changes:

    srcgrit/cli.cpp, line 11, add #include
    srcgrit/grit_main.cpp, line 793, add a cast to first argument:
    args.insert((strvec::iterator)&args[ii], files.begin(), files.end());

  3. Because I'm getting this error when I try to compile on linux:

    srcgrit/grit_main.cpp: 793: error: no matching function for call to 'std::vector<char*,std::allocator >::insert(char**, __gnu_cxx::__normal_iterator<char**, std::vector<char*, std::allocator > >, __gnu_cxx::__normal_iterator<char**, std::vector<char*, std::allocator > > >)
    /usr/include/c++/4.3/bits/vector.tcc:94: note: candidates are: __gnu_cxx::__normal_iterator<typename std::_Vector_base::__normal_iterator<typename std::_Vector_base > std::vector::insert(__gnu_cxx::normal_iterator<typename std::_Vector_base::_Tp_alloc_type::pointer, std::vector >, const_Tp&) [with _Tp = char*, _Alloc = std::allocator]

    C++ libs related?

  4. I'm using gcc 4.3 but carl's fix mentioned above works.
    Should've tried that, sorry!

  5. Pingback: (Quick) Getting started: NDS Programming « embedded programming on the nds

  6. I cannot compile grit on linux:
    either it stops with

    g++  -s -static -o grit build/grit_main.o build/cli.o build/fi.o  -L. -lgrit -lcldib -lfreeimage
    /usr/lib/gcc/x86_64-pc-linux-gnu/4.3.4/../../../../x86_64-pc-linux-gnu/bin/ld: cannot find -lfreeimage

    , indicating that libfreeimage is only bundled as Windows-dll.

    having installed freeimage-3.13.1 via http://bugs.gentoo.org/show_bug.cgi?id=307487, compilations stops with

    g++  -s -static -o grit build/grit_main.o build/cli.o build/fi.o  -L. -lgrit -lcldib -lfreeimage                                                                            
    ./libgrit.a(grit_xp.o): In function `grit_xp_h(GritRec*)':                                                                                                                  
    grit_xp.cpp:(.text+0x1a6b): warning: the use of `tmpnam'
    is dangerous, better use `mkstemp'                                                                                  
    /usr/lib/gcc/x86_64-pc-linux-gnu/4.3.4/../../../../lib64/libfreeimage.a(PluginEXR.o): In function `C_OStream::write(char const*, int)'
    :                                      
    (.text+0x26a): undefined reference to `Iex::throwErrnoExc(std::basic_string<char, std::char_traits<char>, std::allocator<char> > const&)'

    and lots of other undefined references in libfreeimage.a (complete buildlog at

    The makefile looks like you link statically on linux anyway, so how about bundling libfreeimage.a in a usable version as well ?

  7. Unfortunately, I'm limited to Windows, so I can't really help much with linux. That's more wintermute's department. Unfortunately, mkstemp() isn't standard, which is why I'm using tmpnam. IIRC, the warning isn't that serious.

    The slew of errors in FreeImage looks like an improper build of the library, particularly of some of the sub-libraries it uses (libpng and libjpeg, for example). But again I can't built on linux, so there's little I can do here. This is also the reason I can't bundle a linux-usable libfreeimage.a – well, that and I don't know if it'll work for the various linuxes out there. I imagine if there were a one-size-fits-all that it'd have been included in the FreeImage distribution.

    You may have better luck on the devkitPro forum.

  8. 'Cause I keep getting an error message saying it was configured incorrectly and should reinstall...

  9. You did something kind of silly when you where naming your classes in cldib... In cldib_wu.c and cldib_quant.h you use the WuQuantizer class which is the same name as freeimage which is WuQuantizer which ended up as a what I like to call a naming collision.

    The fix is simple just change the name of WuQuantizer to some like this CldibWuQuantizer. This should get rid of the compiler linker error and it will compile to linux just fine. Here a list of files that need to be edited.

    cldib_wu.cpp
    cldib_quant.h
    cldi_conv.cpp line 344

  10. Is there a way of using transparency info in the png, to set the transparency of the loaded texture?

  11. Alas, no.

    It's something I've been meaning to do, but this is not a minor operation, and time has been kind of lacking :\

  12. To get this working in CentOS 6, had to install freeimage-dev from EPEL, and make the following chagnes to the makefile:

    LIBDIRS := .
    change to
    LIBDIRS := . /usr/lib/

    $(CXX) $(LDFLAGS) -o $@ $(GRIT_OBJ) $(LIBPATHS) -lgrit -lcldib -lfreeimage
    change to
    $(CXX) $(LDFLAGS) -o $@ $(GRIT_OBJ) $(LIBPATHS) -lgrit -lcldib -shared -lfreeimage

    -T

  13. Note on compiling for OSX 10.6 and newer:

    sudo port install freeimage

    In Makefile change OSX section to:

    ifneq (,$(findstring Darwin,$(UNAME)))
    SDK := /Developer/SDKs/MacOSX10.6.sdk
    OSXCFLAGS := -mmacosx-version-min=10.6 -isysroot $(SDK) -arch x86_64
    OSXCXXFLAGS := $(OSXCFLAGS)
    CXXFLAGS += -fvisibility=hidden
    LDFLAGS += -mmacosx-version-min=10.6 -Wl,-syslibroot,$(SDK) -arch x86_64
    endif

    In Makefile, change LIBDIRS to:

    LIBDIRS := . /opt/local/lib

    Then make clean, make, and good to go!

  14. Pingback: How do I display a 16-bit image on the screen? : Answers to your coding questions…

  15. Just compiled on OS X 10.9 with instructions similar to the above comment. The SDK directory is now:

    SDK := /Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.9.sdk

    and also I used Homebrew instead of MacPorts to install libfreeimage, which places it in /usr/local/lib instead of /opt/local/lib, so I set LIBDIRS accordingly.

  16. I have a problem with make to Linux:

    g++ -E -MMD -MF build/grit_main.d -Icldib -Ilibgrit -Iextlib -DGRIT_VERSION=\"0.8.6\" -DGRIT_BUILD=\"20100317\" srcgrit/grit_main.cpp > /dev/null
    g++ -Icldib -Ilibgrit -Iextlib -DGRIT_VERSION=\"0.8.6\" -DGRIT_BUILD=\"20100317\" -o build/grit_main.o -c srcgrit/grit_main.cpp
    g++ -s -static -o grit build/grit_main.o build/cli.o build/fi.o -L. -L/usr/lib -lgrit -lcldib -shared -lfreeimage
    ./libgrit.a(grit_xp.o) : Dans la fonction « grit_xp_c(GritRec*) » :
    grit_xp.cpp:(.text+0x6f2): avertissement : the use of `tmpnam' is dangerous, better use `mkstemp'
    /usr/bin/ld: /usr/lib/gcc/x86_64-linux-gnu/7/crtbeginT.o: relocation R_X86_64_32 against symbole caché `__TMC_END__' can not be used when making a shared object
    /usr/bin/ld : échec de l'édition de liens finale : Section non-représentable sur la sortie
    collect2: error: ld returned 1 exit status
    Makefile:127: recipe for target 'grit' failed
    make: *** [grit] Error 1

  17. I'm impressed, I have to admit. Rarely do I come across a blog that's both equally educative and entertaining,
    and without a doubt, you've hit the nail on the
    head. The problem is something which too few people are speaking intelligently about.
    I'm very happy that I stumbled across this in my hunt
    for something concerning this.

  18. I'm amazed, I must say. Seldom do I come across a blog that's both equally
    educative and entertaining, and without a doubt,
    you've hit the nail on the head. The problem is something that not
    enough people are speaking intelligently about.
    Now i'm very happy I stumbled across this in my search for
    something concerning this.

  19. I've recently built on MacOS 10.14 following these changes:
    install freeimage using brew: brew install freeimage
    find the xcode sdk path by running: xcrun --show-sdk-path
    the path I got was: "/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.14.sdk"
    Use that path to make the following changes in the makefile:

    Line 4 -----------------------------------------------------------
    From:
    CXXFLAGS := -Icldib -Ilibgrit -Iextlib

    To :
    CXXFLAGS := -Icldib -Ilibgrit -Iextlib -stdlib=libc++

    Lines 32-36 -----------------------------------------------------------
    From:
    SDK := /Developer/SDKs/MacOSX10.4u.sdk
    OSXCFLAGS := -mmacosx-version-min=10.4 -isysroot $(SDK) -arch i386 -arch ppc
    OSXCXXFLAGS := $(OSXCFLAGS)
    CXXFLAGS += -fvisibility=hidden
    LDFLAGS += -mmacosx-version-min=10.4 -Wl,-syslibroot,$(SDK) -arch i386 -arch ppc

    To:
    SDK := /Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.14.sdk
    OSXCFLAGS := -mmacosx-version-min=10.9 -isysroot $(SDK) -arch x86_64
    OSXCXXFLAGS := $(OSXCFLAGS)
    CXXFLAGS += -fvisibility=hidden
    LDFLAGS += -mmacosx-version-min=10.9 -Wl,-syslibroot,$(SDK) -arch x86_64

    Note: use the path you got from running "xcrun --show-sdk-path" on the SDK := line

    Line 102 -----------------------------------------------------------
    From:
    LIBDIRS := .

    To:
    LIBDIRS := . /usr/local/lib

    Line 108 -----------------------------------------------------------
    From:
    CPPFLAGS += $(INCLUDE)

    To:
    CPPFLAGS += $(INCLUDE) -stdlib=libc++

    Hope this helps others looking to build in MacOS.

  20. Hi!

    So I'm coding some virtual boy. I'm having trouble understanding how I can get the color value of each pixel from the data of: "grit my_image.png -fh! -ftc -gB2 -p!"
    I tried doing like gameboy does like here https://www.huderlem.com/demos/gameboy2bpp.html, but it does not correctly show the image I made via GRIT.

    "title_screen_384x224Tiles" is the array generated by the above grit on an image which is 384x224 pixels.
    Here's my function so far:
    https://pastebin.com/sAyCD6NE

    Can you help me write a function to get the color value for each pixel so I can print it into the framebuffer like I'm trying in that pastebin.

Leave a Reply

Your email address will not be published. Required fields are marked *