DOCS: Added docs to imgio and refactored some of the names and code of imgio
This commit is contained in:
+59
-20
@@ -2,12 +2,13 @@
|
||||
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
#include <turbojpeg.h>
|
||||
|
||||
#include "image/utils.h"
|
||||
|
||||
unsigned int*
|
||||
ppm_load(const char* file, PPM* m_attr)
|
||||
read_ppm(const char* file, PPM* m_attr)
|
||||
{
|
||||
LOG("Decoding");
|
||||
unsigned char red, green, blue;
|
||||
@@ -68,7 +69,7 @@ ppm_load(const char* file, PPM* m_attr)
|
||||
}
|
||||
|
||||
int
|
||||
ppm_save(const unsigned int* buf, const PPM img, char* name)
|
||||
write_ppm(const unsigned int* buf, const PPM img, const char* name)
|
||||
{
|
||||
if (!buf)
|
||||
{
|
||||
@@ -132,7 +133,7 @@ ppm_save(const unsigned int* buf, const PPM img, char* name)
|
||||
}
|
||||
|
||||
unsigned int*
|
||||
jpeg_load(JPEG* m_attr)
|
||||
read_jpeg(JPEG* m_attr)
|
||||
{
|
||||
LOG("Decoding");
|
||||
tjhandle tjdecompress = tj3Init(TJINIT_DECOMPRESS);
|
||||
@@ -175,7 +176,7 @@ jpeg_load(JPEG* m_attr)
|
||||
}
|
||||
|
||||
int
|
||||
jpeg_save(const unsigned int* src_buf, const JPEG* attr, const char* name)
|
||||
write_jpeg(const unsigned int* src_buf, const JPEG* attr, const char* name)
|
||||
{
|
||||
LOG("Encoding");
|
||||
tjhandle tjcompress = tj3Init(TJINIT_COMPRESS);
|
||||
@@ -219,44 +220,84 @@ jpeg_save(const unsigned int* src_buf, const JPEG* attr, const char* name)
|
||||
}
|
||||
|
||||
void
|
||||
transcode_to_jpeg(PPM* in, JPEG* out)
|
||||
transcode_to_jpeg(PPM* in)
|
||||
{
|
||||
if (!in || !out)
|
||||
size_t length = find_extension(in->name);
|
||||
char str2[length];
|
||||
for (int i = 0; i < length; i++)
|
||||
{
|
||||
str2[i] = in->name[i];
|
||||
}
|
||||
char* str3 = ".jpg";
|
||||
char* result = malloc(strlen(str2) + strlen(str3) + 1);
|
||||
if (result != NULL)
|
||||
{
|
||||
strcat(result, str2);
|
||||
strcat(result, str3);
|
||||
}
|
||||
else
|
||||
{
|
||||
LOGERROR(ERR_MALLOC_NULL);
|
||||
return;
|
||||
}
|
||||
JPEG img;
|
||||
if (!in)
|
||||
{
|
||||
LOGERROR(ERR_IMG_NULL);
|
||||
return;
|
||||
}
|
||||
unsigned int* dst = ppm_load(in->name, in);
|
||||
unsigned int* dst = read_ppm(in->name, in);
|
||||
if (!dst)
|
||||
{
|
||||
LOGERROR(ERR_BUF_NULL);
|
||||
return;
|
||||
}
|
||||
out->width = in->width;
|
||||
out->height = in->height;
|
||||
jpeg_save(dst, out, out->name);
|
||||
img.width = in->width;
|
||||
img.height = in->height;
|
||||
write_jpeg(dst, &img, result);
|
||||
free(dst);
|
||||
free(result);
|
||||
}
|
||||
|
||||
void
|
||||
transcode_to_ppm(JPEG* in, PPM* out)
|
||||
transcode_to_ppm(JPEG* in)
|
||||
{
|
||||
if (!in || !out)
|
||||
size_t length = find_extension(in->name);
|
||||
char str2[length];
|
||||
for (int i = 0; i < length; i++)
|
||||
{
|
||||
str2[i] = in->name[i];
|
||||
}
|
||||
char* str3 = ".ppm";
|
||||
char* result = malloc(strlen(str2) + strlen(str3) + 1);
|
||||
if (result != NULL)
|
||||
{
|
||||
strcat(result, str2);
|
||||
strcat(result, str3);
|
||||
}
|
||||
else
|
||||
{
|
||||
LOGERROR(ERR_MALLOC_NULL);
|
||||
return;
|
||||
}
|
||||
PPM img;
|
||||
if (!in)
|
||||
{
|
||||
LOGERROR(ERR_IMG_NULL);
|
||||
return;
|
||||
}
|
||||
unsigned int* dst = jpeg_load(in);
|
||||
unsigned int* dst = read_jpeg(in);
|
||||
if (!dst)
|
||||
{
|
||||
LOGERROR(ERR_BUF_NULL);
|
||||
return;
|
||||
}
|
||||
out->width = in->width;
|
||||
out->height = in->height;
|
||||
out->len = out->width * out->height;
|
||||
ppm_save(dst, *out, out->name);
|
||||
img.width = in->width;
|
||||
img.height = in->height;
|
||||
img.len = img.width * img.height;
|
||||
write_ppm(dst, img, result);
|
||||
free(dst);
|
||||
free(result);
|
||||
}
|
||||
|
||||
PPM
|
||||
@@ -268,8 +309,7 @@ inherit_from_jpeg(const JPEG* in, const char fmt)
|
||||
LOGERROR(ERR_IMG_NULL);
|
||||
return img;
|
||||
}
|
||||
PPM image = { .name = in->name,
|
||||
.width = in->width,
|
||||
PPM image = { .width = in->width,
|
||||
.height = in->height,
|
||||
.len = in->len,
|
||||
.fmt = fmt };
|
||||
@@ -286,7 +326,6 @@ inherit_from_ppm(const PPM* in)
|
||||
return blank;
|
||||
}
|
||||
JPEG image = {
|
||||
.name = in->name,
|
||||
.width = in->width,
|
||||
.height = in->height,
|
||||
.len = in->len,
|
||||
|
||||
Reference in New Issue
Block a user