used wrong stbi function this whole time. big performance

This commit is contained in:
Bryson Steck 2022-08-28 00:42:25 -06:00
parent 0461cec5fd
commit 86e969f105

14
uirc.c
View file

@ -46,7 +46,6 @@ bool singular = false;
bool rFlag = false; bool rFlag = false;
int getBcf(int width, int height) { int getBcf(int width, int height) {
int *widthFactors, *heightFactors;
unsigned int bcf; unsigned int bcf;
for (int i = 1; i <= width; i++) { for (int i = 1; i <= width; i++) {
for (int j = 1; j <= height; j++) { for (int j = 1; j <= height; j++) {
@ -66,32 +65,33 @@ bool compare_float(float a, float b) {
int readFile(char *file, bool rFlag, unsigned int req, char* url) { int readFile(char *file, bool rFlag, unsigned int req, char* url) {
char *displayfile; char *displayfile;
int result;
unsigned int width, height, channels, factor; unsigned int width, height, channels, factor;
unsigned char *img = stbi_load(file, &width, &height, &channels, 0); result = stbi_info(file, &width, &height, &channels);
if (img == NULL) { if (access(file, F_OK) != 0) {
if (req == 0) { if (req == 0) {
printf("FAIL\nuirc: request failed (%s), trying local fs instead\n", url); printf("FAIL\nuirc: request failed (%s), trying local fs instead\n", url);
return 4; return 4;
} else if (access(file, F_OK) != 0) { } else {
printf("uirc: %s: No such file or directory\n", file); printf("uirc: %s: No such file or directory\n", file);
exit(6); exit(6);
}
} else { } else {
if (access(file, R_OK) != 0) { if (access(file, R_OK) != 0) {
printf("uirc: %s: Permission denied\n", file); printf("uirc: %s: Permission denied\n", file);
exit(3); exit(3);
} else { }
if (result != 1) {
printf("uirc: %s: Not an image or unsupported image type\n", file); printf("uirc: %s: Not an image or unsupported image type\n", file);
exit(10); exit(10);
} }
} }
}
if (req == 0) if (req == 0)
printf("ok\n"); printf("ok\n");
factor = getBcf(width, height); factor = getBcf(width, height);
stbi_image_free(img);
double wuneven = ((float) height) / ((float) width); double wuneven = ((float) height) / ((float) width);
double huneven = ((float) width) / ((float) height); double huneven = ((float) width) / ((float) height);