From 71f11723beb1b320e36f24f382e7b1f46c0ca89e Mon Sep 17 00:00:00 2001 From: Dorian Wouters Date: Wed, 27 Jan 2016 16:40:24 +0100 Subject: [PATCH] Uniformize indentation to 4 spaces --- source/3ds/util.cpp | 96 ++++++++++++++++----------------- source/cmd.cpp | 126 ++++++++++++++++++++++---------------------- 2 files changed, 111 insertions(+), 111 deletions(-) diff --git a/source/3ds/util.cpp b/source/3ds/util.cpp index 28a3494..f48af88 100644 --- a/source/3ds/util.cpp +++ b/source/3ds/util.cpp @@ -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 0; + return 0; } u8* load_image(const char* image, u32 width, u32 height) { - unsigned char *img; - int imgWidth, imgHeight, imgDepth; + unsigned char *img; + 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) { - printf("ERROR: Could not load image file: %s.\n", stbi_failure_reason()); - return NULL; - } + if(img == NULL) { + printf("ERROR: Could not load image file: %s.\n", stbi_failure_reason()); + return NULL; + } - if(width == 0) { - width = imgWidth; - } + if(width == 0) { + width = imgWidth; + } - if(height == 0) { - height = imgHeight; - } + if(height == 0) { + height = imgHeight; + } - if(imgWidth != width || imgHeight != height) { - printf("ERROR: Image must be exactly %d x %d in size.\n", width, height); - return NULL; - } + if(imgWidth != width || imgHeight != height) { + printf("ERROR: Image must be exactly %d x %d in size.\n", width, height); + return NULL; + } - if(imgDepth != STBI_rgb_alpha) { - printf("ERROR: Decoded image does't match expected format (%d, wanted %d).\n", - imgDepth, STBI_rgb_alpha); - return NULL; - } + if(imgDepth != STBI_rgb_alpha) { + printf("ERROR: Decoded image does't match expected format (%d, wanted %d).\n", + imgDepth, STBI_rgb_alpha); + return NULL; + } - return img; + return 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* converted = (u16*) malloc(width * height * sizeof(u16)); - u32 n = 0; - for(int y = 0; y < height; y += 8) { - for(int x = 0; x < width; x += 8) { - for(int k = 0; k < 8 * 8; k++) { - u32 xx = (u32) (TILE_ORDER[k] & 0x7); - u32 yy = (u32) (TILE_ORDER[k] >> 3); + u16* converted = (u16*) malloc(width * height * sizeof(u16)); + u32 n = 0; + for(int y = 0; y < height; y += 8) { + for(int x = 0; x < width; x += 8) { + for(int k = 0; k < 8 * 8; k++) { + u32 xx = (u32) (TILE_ORDER[k] & 0x7); + u32 yy = (u32) (TILE_ORDER[k] >> 3); - u8* pixel = img + (((y + yy) * width + (x + xx)) * 4); - converted[n++] = pack_color(pixel[0], pixel[1], pixel[2], pixel[3], format); - } - } - } + u8* pixel = img + (((y + yy) * width + (x + xx)) * 4); + converted[n++] = pack_color(pixel[0], pixel[1], pixel[2], pixel[3], format); + } + } + } - if(size != NULL) { - *size = width * height * (u32) sizeof(u16); - } + if(size != NULL) { + *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) { - u8* img = load_image(image, width, height); - if(img == NULL) { - return NULL; - } + u8* img = load_image(image, width, height); + if(img == NULL) { + return NULL; + } - u16* tiles = image_data_to_tiles(img, width, height, format, size); - free_image(img); - return tiles; + u16* tiles = image_data_to_tiles(img, width, height, format, size); + free_image(img); + return tiles; } \ No newline at end of file diff --git a/source/cmd.cpp b/source/cmd.cpp index 1354296..fbb4fca 100644 --- a/source/cmd.cpp +++ b/source/cmd.cpp @@ -38,43 +38,43 @@ u8* convert_to_cwav(const std::string file, u32* size) { rewind(fd); // equivalent to SEEK_SET to pos 0 if (magic[0] == 'R' && magic[1] == 'I' && magic[2] == 'F' && magic[3] == 'F') { - WAV* wav = wav_read(fd); - if(wav != NULL) { - CWAV cwav; - cwav.channels = wav->format.numChannels; - cwav.sampleRate = wav->format.sampleRate; - cwav.bitsPerSample = wav->format.bitsPerSample; - cwav.dataSize = wav->data.chunkSize; - cwav.data = wav->data.data; + WAV* wav = wav_read(fd); + if(wav != NULL) { + CWAV cwav; + cwav.channels = wav->format.numChannels; + cwav.sampleRate = wav->format.sampleRate; + cwav.bitsPerSample = wav->format.bitsPerSample; + cwav.dataSize = wav->data.chunkSize; + 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') { - int error; - stb_vorbis* vorb = stb_vorbis_open_file(fd, false, &error, NULL); - if(vorb != NULL) { - stb_vorbis_info info = stb_vorbis_get_info(vorb); + int error; + stb_vorbis* vorb = stb_vorbis_open_file(fd, false, &error, NULL); + if(vorb != NULL) { + stb_vorbis_info info = stb_vorbis_get_info(vorb); - CWAV cwav; - cwav.channels = info.channels; - cwav.sampleRate = info.sample_rate; - cwav.bitsPerSample = 16; // stb_vorbis always outputs 16 bit samples - int sampleCount = stb_vorbis_stream_length_in_samples(vorb) * info.channels; - cwav.dataSize = sampleCount * 2; - cwav.data = (u8*) calloc(sampleCount, 2); - stb_vorbis_get_samples_short_interleaved(vorb, info.channels, (short*) cwav.data, sampleCount); + CWAV cwav; + cwav.channels = info.channels; + cwav.sampleRate = info.sample_rate; + cwav.bitsPerSample = 16; // stb_vorbis always outputs 16 bit samples + int sampleCount = stb_vorbis_stream_length_in_samples(vorb) * info.channels; + cwav.dataSize = sampleCount * 2; + cwav.data = (u8*) calloc(sampleCount, 2); + 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); - stb_vorbis_close(vorb); - } else { - printf("ERROR: Vorbis open failed, error %d.\n", error); - } + free(cwav.data); + stb_vorbis_close(vorb); + } else { + printf("ERROR: Vorbis open failed, error %d.\n", error); + } } 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); @@ -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) { - u8* icon48Data = load_image(icon.c_str(), 48, 48); - if(icon48Data == NULL) { - return 1; - } + u8* icon48Data = load_image(icon.c_str(), 48, 48); + if(icon48Data == NULL) { + return 1; + } u16* icon48 = image_data_to_tiles(icon48Data, 48, 48, RGB565, 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]; for(int y = 0; y < 48; y += 2) { for(int x = 0; x < 48; x += 2) { - int i1 = (y * 48 + x) * 4; - u8 r1 = icon48Data[i1 + 0]; - u8 g1 = icon48Data[i1 + 1]; - u8 b1 = icon48Data[i1 + 2]; - u8 a1 = icon48Data[i1 + 3]; + int i1 = (y * 48 + x) * 4; + u8 r1 = icon48Data[i1 + 0]; + u8 g1 = icon48Data[i1 + 1]; + u8 b1 = icon48Data[i1 + 2]; + u8 a1 = icon48Data[i1 + 3]; - int i2 = (y * 48 + (x + 1)) * 4; - u8 r2 = icon48Data[i2 + 0]; - u8 g2 = icon48Data[i2 + 1]; - u8 b2 = icon48Data[i2 + 2]; - u8 a2 = icon48Data[i2 + 3]; + int i2 = (y * 48 + (x + 1)) * 4; + u8 r2 = icon48Data[i2 + 0]; + u8 g2 = icon48Data[i2 + 1]; + u8 b2 = icon48Data[i2 + 2]; + u8 a2 = icon48Data[i2 + 3]; - int i3 = ((y + 1) * 48 + x) * 4; - u8 r3 = icon48Data[i3 + 0]; - u8 g3 = icon48Data[i3 + 1]; - u8 b3 = icon48Data[i3 + 2]; - u8 a3 = icon48Data[i3 + 3]; + int i3 = ((y + 1) * 48 + x) * 4; + u8 r3 = icon48Data[i3 + 0]; + u8 g3 = icon48Data[i3 + 1]; + u8 b3 = icon48Data[i3 + 2]; + u8 a3 = icon48Data[i3 + 3]; - int i4 = ((y + 1) * 48 + (x + 1)) * 4; - u8 r4 = icon48Data[i4 + 0]; - u8 g4 = icon48Data[i4 + 1]; - u8 b4 = icon48Data[i4 + 2]; - u8 a4 = icon48Data[i4 + 3]; + int i4 = ((y + 1) * 48 + (x + 1)) * 4; + u8 r4 = icon48Data[i4 + 0]; + u8 g4 = icon48Data[i4 + 1]; + u8 b4 = icon48Data[i4 + 2]; + u8 a4 = icon48Data[i4 + 3]; - int id = ((y / 2) * 24 + (x / 2)) * 4; - icon24Data[id + 0] = (u8) ((r1 + r2 + r3 + r4) / 4); - icon24Data[id + 1] = (u8) ((g1 + g2 + g3 + g4) / 4); - icon24Data[id + 2] = (u8) ((b1 + b2 + b3 + b4) / 4); - icon24Data[id + 3] = (u8) ((a1 + a2 + a3 + a4) / 4); + int id = ((y / 2) * 24 + (x / 2)) * 4; + icon24Data[id + 0] = (u8) ((r1 + r2 + r3 + r4) / 4); + icon24Data[id + 1] = (u8) ((g1 + g2 + g3 + g4) / 4); + icon24Data[id + 2] = (u8) ((b1 + b2 + b3 + b4) / 4); + icon24Data[id + 3] = (u8) ((a1 + a2 + a3 + a4) / 4); } } - u16* icon24 = image_data_to_tiles(icon24Data, 24, 24, RGB565, NULL); - if(icon24 == NULL) { - return 1; - } + u16* icon24 = image_data_to_tiles(icon24Data, 24, 24, RGB565, NULL); + if(icon24 == NULL) { + return 1; + } SMDH smdh; for(int i = 0; i < 0x10; i++) {