Copy Link
Add to Bookmark
Report

Saturn Graphics converter v0.25 by Charles Doty

SegaSaturn's profile picture
Published in 
SegaSaturn
 · 4 years ago

Saturn Graphics converter v0.25 by Charles Doty (cdoty@netzero.net)

SSConv will convert 24 bit raw files to 15 bit files for the Saturn. SSConv can output a binary or C file. It also supports transparent settings (Sprite).

To use 'SSConv' type:

SSConv Filein.Raw Fileout.bin Sprite Type [Array Name]\n" );
Filein.Raw is the name of a raw 24 bit image.\n");
Fileout.Bin is the name of Saturn image to save.\n");
Sprite is TRUE or FALSE. This is used to make 0 bytes transparent.\n");
Type is BIN or C. BIN produces a binary file, C produces a C array.\n");
[Array Name] is the name of the C array. Only needed for C array files.\n");

SSConv will then convert the image to the Saturn format as either a binary file or C array text file. If Sprite is TRUE than the upper bit of the pixel is only set on no transparent (Color Red = 0, Green = 0 Blue = 0) pixels.

SSConv will only run under Windows 9x/NT (2000 is untested), as a console application.

Also included in the archive is the source to 'SSConv'.

Please e-mail me (cdoty@netzero.net), if you find a problem with 'SSConv'.


SSCONV.CPP


 
#include <stdio.h>
#include <string.h>
#include <windows.h>

#define DATAPERLINE 8

BOOL Sprite = FALSE; // Is this a sprite image?

void Usage();
void FlipBuffer(DWORD length, WORD *buffer);

void main(int argc, char *argv[])
{
char filename[128];
char savefile[128];

if (argc < 5)
{
Usage();
}

strcpy(filename, argv[1]);
strcpy(savefile, argv[2]);

FILE *handle = fopen(filename, "rb");

if (NULL == handle)
{
printf("Unable to open %s\n", filename);

exit(0);
}

fseek(handle, 0, SEEK_END);
DWORD length = ftell(handle);
rewind(handle);

if (length <= 0)
{
fclose(handle);
printf("%s is not a valid file\n.", filename);

return;
}

if (!strcmp(argv[3], "TRUE"))
{
Sprite = TRUE;
}

printf("Converting File...");

char *buffer = new char[length];

WORD *image = new WORD[length / 3];

WORD *buf16 = image;

fread(buffer, 1, length, handle);
fclose(handle);

for (DWORD loop = 0; loop < length; loop += 3)
{
unsigned char red = buffer[loop];
unsigned char green = buffer[loop + 1];
unsigned char blue = buffer[loop + 2];

red = (red >> 3) & 0x1f;
green = (green >> 3) & 0x1f;
blue = (blue >> 3) & 0x1f;

unsigned short pixel = ((blue << 10) + (green << 5) + red);

if (FALSE == Sprite || *buf16 != 0)
{
*buf16 = 0x8000 | pixel;
}

else
{
*buf16 = pixel;
}

buf16++;
}

printf("Completed.\nWriting File...");

if (!strcmp(argv[4], "BIN"))
{
FlipBuffer(length / 3, image);

handle = fopen(savefile, "wb");

if (NULL == handle)
{
printf("Unable to create %s\n.", savefile);

return;
}

fwrite(image, 2, length / 3, handle);

fclose(handle);
}

else
{
if (argc < 6)
{
Usage();
}

handle = fopen(savefile, "wt");

if (NULL == handle)
{
printf("Unable to create %s\n.", savefile);

return;
}

fprintf(handle, "// Source File: %s\n\n", argv[1]);

fprintf(handle, "unsigned short %s[] =\n", argv[5]);
fprintf(handle, "{\n ");

for (loop = 0; loop < length / 3; loop++)
{
fprintf(handle, "0x%04X", image[loop]);

if (loop < (length / 3) - 1)
{
fprintf(handle, ", ");

if (0 == ((loop + 1) % DATAPERLINE))
{
fprintf(handle, "\n ");
}
}
}

fprintf(handle, "\n};\n\n");
fprintf(handle, "unsigned long %sSize = %d;\n", argv[5], length / 3);
}

printf("Completed.\n");

fclose(handle);
}

void Usage()
{
printf("SSConv (v0.25) Saturn Image converter by Charles Doty (cdoty@netzero.net).\n\n");
printf(" Usage: SSConv Filein.Raw Fileout.bin Sprite Type [Array Name]\n" );
printf(" Filein.Raw is the name of a raw 24 bit image.\n");
printf(" Fileout.Bin is the name of Saturn image to save.\n");
printf(" Sprite is TRUE or FALSE. This is used to make 0 bytes transparent.\n");
printf(" Type is BIN or C. BIN produces a binary file, C produces a C array.\n");
printf(" [Array Name] is the name of the C array. Only needed for C array files.\n");

exit(0);
}

void FlipBuffer(DWORD length, WORD *buffer)
{
for (DWORD loop = 0; loop < length; loop ++)
{
WORD pixel = *buffer;

*buffer = ((pixel & 0xff) << 8) | ((pixel & 0xff00) >> 8);

buffer++;
}
}

← previous
next →
loading
sending ...
New to Neperos ? Sign Up for free
download Neperos App from Google Play
install Neperos as PWA

Let's discover also

Recent Articles

Recent Comments

Neperos cookies
This website uses cookies to store your preferences and improve the service. Cookies authorization will allow me and / or my partners to process personal data such as browsing behaviour.

By pressing OK you agree to the Terms of Service and acknowledge the Privacy Policy

By pressing REJECT you will be able to continue to use Neperos (like read articles or write comments) but some important cookies will not be set. This may affect certain features and functions of the platform.
OK
REJECT