-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
9d03654
commit d5d71dc
Showing
10 changed files
with
308 additions
and
95 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -3,4 +3,7 @@ build/ | |
.vscode/ | ||
.vs/ | ||
.idea/ | ||
*.femboy | ||
*.femboy | ||
*.jpg | ||
*.png | ||
*.ico |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
#include "convert.h" | ||
|
||
int convertJPEGToFemboy(const char *inputFile, const char *outputFile ) | ||
{ | ||
RGB *jpegPixels; | ||
int jpegWidth, jpegHeight; | ||
|
||
// Read JPEG file | ||
if (readJPEGFile(inputFile, &jpegWidth, &jpegHeight, &jpegPixels) != 0) | ||
{ | ||
fprintf(stderr, "Failed to read JPEG file\n"); | ||
return EXIT_FAILURE; | ||
} | ||
|
||
char outputFileWithExt[256]; | ||
strcpy(outputFileWithExt, outputFile); | ||
strcat(outputFileWithExt, ".femboy"); | ||
|
||
if (writeBinaryFile(outputFileWithExt, jpegWidth, jpegHeight, jpegPixels) != 0) | ||
{ | ||
fprintf(stderr, "Failed to write output file\n"); | ||
free(jpegPixels); | ||
return EXIT_FAILURE; | ||
} | ||
|
||
free(jpegPixels); | ||
|
||
return EXIT_SUCCESS; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
#ifndef HEADER_CONVERTER | ||
#define HEADER_CONVERTER | ||
|
||
#include "datastruct.h" | ||
#include "rdwr.h" | ||
#include <stddef.h> | ||
#include <stdio.h> | ||
#include <stdlib.h> | ||
#include <jpeglib.h> | ||
#include <string.h> | ||
|
||
int convertJPEGToFemboy(const char *inputFile, const char *outputFile); | ||
|
||
#endif //! HEADER_CONVERTER |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
#include "optimisation.h" | ||
|
||
/** | ||
* Applies uniform quantization to the given RGB pixel data. | ||
* Divides each color channel (R, G, B) by the specified number of colors, | ||
* rounds down to the nearest integer, then multiplies back. | ||
* This reduces the number of distinct colors in the image. | ||
*/ | ||
void applyQuantization(int width, int height, RGB *pixels, int numColors) | ||
{ | ||
int factor = 256 / numColors; | ||
|
||
for (int i = 0; i < width * height; ++i) | ||
{ | ||
pixels[i].r = (pixels[i].r / factor) * factor; | ||
pixels[i].g = (pixels[i].g / factor) * factor; | ||
pixels[i].b = (pixels[i].b / factor) * factor; | ||
} | ||
} | ||
|
||
/** | ||
* Performs chroma subsampling on the given RGB pixel data by averaging 2x2 blocks. | ||
* Reduces the horizontal and vertical resolution by half. | ||
*/ | ||
void chromaSubsampling(int width, int height, RGB *pixels) | ||
{ | ||
printf("Chroma subsampling...\n"); | ||
for (int i = 0; i < height; i += 2) | ||
{ | ||
for (int j = 0; j < width; j += 2) | ||
{ | ||
RGB avgColor; | ||
avgColor.r = (pixels[i * width + j].r + pixels[i * width + j + 1].r + | ||
pixels[(i + 1) * width + j].r + pixels[(i + 1) * width + j + 1].r) / | ||
4; | ||
|
||
avgColor.g = (pixels[i * width + j].g + pixels[i * width + j + 1].g + | ||
pixels[(i + 1) * width + j].g + pixels[(i + 1) * width + j + 1].g) / | ||
4; | ||
|
||
avgColor.b = (pixels[i * width + j].b + pixels[i * width + j + 1].b + | ||
pixels[(i + 1) * width + j].b + pixels[(i + 1) * width + j + 1].b) / | ||
4; | ||
|
||
pixels[i * width + j] = avgColor; | ||
pixels[i * width + j + 1] = avgColor; | ||
pixels[(i + 1) * width + j] = avgColor; | ||
pixels[(i + 1) * width + j + 1] = avgColor; | ||
} | ||
} | ||
printf("Done\n"); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
#ifndef HEADER_OPTIMISATION | ||
#define HEADER_OPTIMISATION | ||
|
||
#include "datastruct.h" | ||
#include <stdio.h> | ||
|
||
void applyQuantization(int width, int height, RGB *pixels, int numColors); | ||
void chromaSubsampling(int width, int height, RGB *pixels); | ||
|
||
#endif //! HEADER_OPTIMISATION |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,13 +1,16 @@ | ||
#ifndef READER_WRITER_HEADER | ||
#define READER_WRITER_HEADER | ||
|
||
#include "datastruct.h" | ||
#include "convert.h" | ||
#include "optimisation.h" | ||
#include <stdio.h> | ||
#include <stdlib.h> | ||
#include "datastruct.h" | ||
#include <string.h> | ||
|
||
void chromaSubsampling(int width, int height, RGB *pixels); | ||
void runLengthEncode(RGB *pixels, int size, RLE **encodedData, int *encodedSize); | ||
int writeBinaryFile(const char *filename, int width, int height, RGB *pixels); | ||
int readBinaryFile(const char *filename, int *width, int *height, RGB **pixels); | ||
int readJPEGFile(const char *filename, int *width, int *height, RGB **pixels); | ||
|
||
#endif // !READER_WRITER_HEADER |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.