Uniformize indentation to 4 spaces

This commit is contained in:
Dorian Wouters 2016-01-27 16:40:24 +01:00
parent e86a4c9677
commit 71f11723be
2 changed files with 111 additions and 111 deletions

View File

@ -34,75 +34,75 @@ u16 pack_color(u8 r, u8 g, u8 b, u8 a, PixelFormat format) {
return r << 12 | g << 8 | b << 4 | a; return r << 12 | g << 8 | b << 4 | a;
} }
return 0; return 0;
} }
u8* load_image(const char* image, u32 width, u32 height) { u8* load_image(const char* image, u32 width, u32 height) {
unsigned char *img; unsigned char *img;
int imgWidth, imgHeight, imgDepth; int imgWidth, imgHeight, imgDepth;
img = stbi_load(image, &imgWidth, &imgHeight, &imgDepth, STBI_rgb_alpha); img = stbi_load(image, &imgWidth, &imgHeight, &imgDepth, STBI_rgb_alpha);
if(img == NULL) { if(img == NULL) {
printf("ERROR: Could not load image file: %s.\n", stbi_failure_reason()); printf("ERROR: Could not load image file: %s.\n", stbi_failure_reason());
return NULL; return NULL;
} }
if(width == 0) { if(width == 0) {
width = imgWidth; width = imgWidth;
} }
if(height == 0) { if(height == 0) {
height = imgHeight; height = imgHeight;
} }
if(imgWidth != width || imgHeight != height) { if(imgWidth != width || imgHeight != height) {
printf("ERROR: Image must be exactly %d x %d in size.\n", width, height); printf("ERROR: Image must be exactly %d x %d in size.\n", width, height);
return NULL; return NULL;
} }
if(imgDepth != STBI_rgb_alpha) { if(imgDepth != STBI_rgb_alpha) {
printf("ERROR: Decoded image does't match expected format (%d, wanted %d).\n", printf("ERROR: Decoded image does't match expected format (%d, wanted %d).\n",
imgDepth, STBI_rgb_alpha); imgDepth, STBI_rgb_alpha);
return NULL; return NULL;
} }
return img; return img;
} }
void free_image(u8* img) { void free_image(u8* img) {
stbi_image_free(img); stbi_image_free(img);
} }
u16* image_data_to_tiles(u8* img, u32 width, u32 height, PixelFormat format, u32* size) { u16* image_data_to_tiles(u8* img, u32 width, u32 height, PixelFormat format, u32* size) {
u16* converted = (u16*) malloc(width * height * sizeof(u16)); u16* converted = (u16*) malloc(width * height * sizeof(u16));
u32 n = 0; u32 n = 0;
for(int y = 0; y < height; y += 8) { for(int y = 0; y < height; y += 8) {
for(int x = 0; x < width; x += 8) { for(int x = 0; x < width; x += 8) {
for(int k = 0; k < 8 * 8; k++) { for(int k = 0; k < 8 * 8; k++) {
u32 xx = (u32) (TILE_ORDER[k] & 0x7); u32 xx = (u32) (TILE_ORDER[k] & 0x7);
u32 yy = (u32) (TILE_ORDER[k] >> 3); u32 yy = (u32) (TILE_ORDER[k] >> 3);
u8* pixel = img + (((y + yy) * width + (x + xx)) * 4); u8* pixel = img + (((y + yy) * width + (x + xx)) * 4);
converted[n++] = pack_color(pixel[0], pixel[1], pixel[2], pixel[3], format); converted[n++] = pack_color(pixel[0], pixel[1], pixel[2], pixel[3], format);
} }
} }
} }
if(size != NULL) { if(size != NULL) {
*size = width * height * (u32) sizeof(u16); *size = width * height * (u32) sizeof(u16);
} }
return converted; return converted;
} }
u16* image_to_tiles(const char* image, u32 width, u32 height, PixelFormat format, u32* size) { u16* image_to_tiles(const char* image, u32 width, u32 height, PixelFormat format, u32* size) {
u8* img = load_image(image, width, height); u8* img = load_image(image, width, height);
if(img == NULL) { if(img == NULL) {
return NULL; return NULL;
} }
u16* tiles = image_data_to_tiles(img, width, height, format, size); u16* tiles = image_data_to_tiles(img, width, height, format, size);
free_image(img); free_image(img);
return tiles; return tiles;
} }

View File

@ -38,43 +38,43 @@ u8* convert_to_cwav(const std::string file, u32* size) {
rewind(fd); // equivalent to SEEK_SET to pos 0 rewind(fd); // equivalent to SEEK_SET to pos 0
if (magic[0] == 'R' && magic[1] == 'I' && magic[2] == 'F' && magic[3] == 'F') { if (magic[0] == 'R' && magic[1] == 'I' && magic[2] == 'F' && magic[3] == 'F') {
WAV* wav = wav_read(fd); WAV* wav = wav_read(fd);
if(wav != NULL) { if(wav != NULL) {
CWAV cwav; CWAV cwav;
cwav.channels = wav->format.numChannels; cwav.channels = wav->format.numChannels;
cwav.sampleRate = wav->format.sampleRate; cwav.sampleRate = wav->format.sampleRate;
cwav.bitsPerSample = wav->format.bitsPerSample; cwav.bitsPerSample = wav->format.bitsPerSample;
cwav.dataSize = wav->data.chunkSize; cwav.dataSize = wav->data.chunkSize;
cwav.data = wav->data.data; cwav.data = wav->data.data;
ret = cwav_build(cwav, size); ret = cwav_build(cwav, size);
wav_free(wav); wav_free(wav);
} }
} else if (magic[0] == 'O' && magic[1] == 'g' && magic[2] == 'g' && magic[3] == 'S') { } else if (magic[0] == 'O' && magic[1] == 'g' && magic[2] == 'g' && magic[3] == 'S') {
int error; int error;
stb_vorbis* vorb = stb_vorbis_open_file(fd, false, &error, NULL); stb_vorbis* vorb = stb_vorbis_open_file(fd, false, &error, NULL);
if(vorb != NULL) { if(vorb != NULL) {
stb_vorbis_info info = stb_vorbis_get_info(vorb); stb_vorbis_info info = stb_vorbis_get_info(vorb);
CWAV cwav; CWAV cwav;
cwav.channels = info.channels; cwav.channels = info.channels;
cwav.sampleRate = info.sample_rate; cwav.sampleRate = info.sample_rate;
cwav.bitsPerSample = 16; // stb_vorbis always outputs 16 bit samples cwav.bitsPerSample = 16; // stb_vorbis always outputs 16 bit samples
int sampleCount = stb_vorbis_stream_length_in_samples(vorb) * info.channels; int sampleCount = stb_vorbis_stream_length_in_samples(vorb) * info.channels;
cwav.dataSize = sampleCount * 2; cwav.dataSize = sampleCount * 2;
cwav.data = (u8*) calloc(sampleCount, 2); cwav.data = (u8*) calloc(sampleCount, 2);
stb_vorbis_get_samples_short_interleaved(vorb, info.channels, (short*) cwav.data, sampleCount); stb_vorbis_get_samples_short_interleaved(vorb, info.channels, (short*) cwav.data, sampleCount);
ret = cwav_build(cwav, size); ret = cwav_build(cwav, size);
free(cwav.data); free(cwav.data);
stb_vorbis_close(vorb); stb_vorbis_close(vorb);
} else { } else {
printf("ERROR: Vorbis open failed, error %d.\n", error); printf("ERROR: Vorbis open failed, error %d.\n", error);
} }
} else { } else {
printf("ERROR: Audio file header '%c%c%c%c' unrecognized.\n", magic[0], magic[1], magic[2], magic[3]); printf("ERROR: Audio file header '%c%c%c%c' unrecognized.\n", magic[0], magic[1], magic[2], magic[3]);
} }
fclose(fd); fclose(fd);
@ -155,10 +155,10 @@ int cmd_make_banner(const std::string image, const std::string audio, const std:
} }
int cmd_make_smdh(const std::string shortTitle, const std::string longTitle, const std::string publisher, const std::string icon, SMDHRegionFlag regionFlags, u64 matchMakerId, u32 smdhFlags, u16 eulaVersion, u32 optimalBannerFrame, u32 streetpassId, const std::string output) { int cmd_make_smdh(const std::string shortTitle, const std::string longTitle, const std::string publisher, const std::string icon, SMDHRegionFlag regionFlags, u64 matchMakerId, u32 smdhFlags, u16 eulaVersion, u32 optimalBannerFrame, u32 streetpassId, const std::string output) {
u8* icon48Data = load_image(icon.c_str(), 48, 48); u8* icon48Data = load_image(icon.c_str(), 48, 48);
if(icon48Data == NULL) { if(icon48Data == NULL) {
return 1; return 1;
} }
u16* icon48 = image_data_to_tiles(icon48Data, 48, 48, RGB565, NULL); u16* icon48 = image_data_to_tiles(icon48Data, 48, 48, RGB565, NULL);
if(icon48 == NULL) { if(icon48 == NULL) {
@ -168,42 +168,42 @@ int cmd_make_smdh(const std::string shortTitle, const std::string longTitle, con
u8 icon24Data[24 * 24 * 4]; u8 icon24Data[24 * 24 * 4];
for(int y = 0; y < 48; y += 2) { for(int y = 0; y < 48; y += 2) {
for(int x = 0; x < 48; x += 2) { for(int x = 0; x < 48; x += 2) {
int i1 = (y * 48 + x) * 4; int i1 = (y * 48 + x) * 4;
u8 r1 = icon48Data[i1 + 0]; u8 r1 = icon48Data[i1 + 0];
u8 g1 = icon48Data[i1 + 1]; u8 g1 = icon48Data[i1 + 1];
u8 b1 = icon48Data[i1 + 2]; u8 b1 = icon48Data[i1 + 2];
u8 a1 = icon48Data[i1 + 3]; u8 a1 = icon48Data[i1 + 3];
int i2 = (y * 48 + (x + 1)) * 4; int i2 = (y * 48 + (x + 1)) * 4;
u8 r2 = icon48Data[i2 + 0]; u8 r2 = icon48Data[i2 + 0];
u8 g2 = icon48Data[i2 + 1]; u8 g2 = icon48Data[i2 + 1];
u8 b2 = icon48Data[i2 + 2]; u8 b2 = icon48Data[i2 + 2];
u8 a2 = icon48Data[i2 + 3]; u8 a2 = icon48Data[i2 + 3];
int i3 = ((y + 1) * 48 + x) * 4; int i3 = ((y + 1) * 48 + x) * 4;
u8 r3 = icon48Data[i3 + 0]; u8 r3 = icon48Data[i3 + 0];
u8 g3 = icon48Data[i3 + 1]; u8 g3 = icon48Data[i3 + 1];
u8 b3 = icon48Data[i3 + 2]; u8 b3 = icon48Data[i3 + 2];
u8 a3 = icon48Data[i3 + 3]; u8 a3 = icon48Data[i3 + 3];
int i4 = ((y + 1) * 48 + (x + 1)) * 4; int i4 = ((y + 1) * 48 + (x + 1)) * 4;
u8 r4 = icon48Data[i4 + 0]; u8 r4 = icon48Data[i4 + 0];
u8 g4 = icon48Data[i4 + 1]; u8 g4 = icon48Data[i4 + 1];
u8 b4 = icon48Data[i4 + 2]; u8 b4 = icon48Data[i4 + 2];
u8 a4 = icon48Data[i4 + 3]; u8 a4 = icon48Data[i4 + 3];
int id = ((y / 2) * 24 + (x / 2)) * 4; int id = ((y / 2) * 24 + (x / 2)) * 4;
icon24Data[id + 0] = (u8) ((r1 + r2 + r3 + r4) / 4); icon24Data[id + 0] = (u8) ((r1 + r2 + r3 + r4) / 4);
icon24Data[id + 1] = (u8) ((g1 + g2 + g3 + g4) / 4); icon24Data[id + 1] = (u8) ((g1 + g2 + g3 + g4) / 4);
icon24Data[id + 2] = (u8) ((b1 + b2 + b3 + b4) / 4); icon24Data[id + 2] = (u8) ((b1 + b2 + b3 + b4) / 4);
icon24Data[id + 3] = (u8) ((a1 + a2 + a3 + a4) / 4); icon24Data[id + 3] = (u8) ((a1 + a2 + a3 + a4) / 4);
} }
} }
u16* icon24 = image_data_to_tiles(icon24Data, 24, 24, RGB565, NULL); u16* icon24 = image_data_to_tiles(icon24Data, 24, 24, RGB565, NULL);
if(icon24 == NULL) { if(icon24 == NULL) {
return 1; return 1;
} }
SMDH smdh; SMDH smdh;
for(int i = 0; i < 0x10; i++) { for(int i = 0; i < 0x10; i++) {