A RetroSearch Logo

Home - News ( United States | United Kingdom | Italy | Germany ) - Football scores

Search Query:

Showing content from https://github.com/Aftersol/Simplified-QOI-Codec below:

Aftersol/Simplified-QOI-Codec: An QOI codec that doesn't requires any other dependencies

Simplified QOI Codec Library

A one header file library for encoding and decoding QOI files.

Place the qoi.h file into your project folder preferably in your project's include folder

Define the following below before you include qoi.h library in one of your source code file

#define  SIMPLIFIED_QOI_IMPLEMENTATION
#include "sQOI.h"
/* 	
	Assume you opened the file and
	allocated enough memory for the encoder
	before this code
*/

qoi_desc_t desc;
qoi_enc_t enc;
uint8_t* pixel_seek;

qoi_desc_init(&desc);
qoi_set_dimensions(&desc, width, height);
qoi_set_channels(&desc, channels);
qoi_set_colorspace(&desc, colorspace);

write_qoi_header(&desc, qoi_file);  

pixel_seek = file_buffer;
qoi_enc_init(&desc, &enc, qoi_file);

while (!qoi_enc_done(&enc))
{
	qoi_encode_chunk(&desc, &enc, pixel_seek);
	pixel_seek += desc.channels;
}

/* 
	Write the QOI file after encoding
	or do something else after encoding
*/
/* After reading a QOI file and placed in buffer */

qoi_desc_t desc;
qoi_dec_t dec;
qoi_pixel_t px;

uint8_t *bytes;
size_t rawImageLength, seek;

qoi_desc_init(&desc);

if (!read_qoi_header(&desc, qoi_bytes))
{
	printf("The file you opened is not a QOIF file\n");
	return;
}

raw_image_length = (size_t)desc.width * (size_t)desc.height * (size_t)desc.channels;

seek = 0;
if (raw_image_length == 0)
	return;

qoi_dec_init(&desc, &dec, qoi_bytes, buffer_size);
/* Creates a blank image for the decoder to work on */
bytes = (unsigned char*)malloc(raw_image_length * sizeof(unsigned char) + 4);

if (!bytes)
	return;

/* Keep decoding the pixels until
all pixels are done decompressing */
while (!qoi_dec_done(&dec))
{
	px = qoi_decode_chunk(&dec);
	/* Do something with the pixel values below */
	bytes[seek] = px.red;
	bytes[seek + 1] = px.green;
	bytes[seek + 2] = px.blue;
	
	if (desc.channels > 3) 
		bytes[seek + 3] = px.alpha;
	
	seek += desc.channels;
}

/* Use the pixels however you want after this code */
How To Run Example Programs
qoi_enc <input file> <width> <height> <channels> <colorspace> <output file>

Input file must be raw RGB or RGBA file

This program only outputs raw RGB or RGBA files depending on the amount of channels in a QOI file

qoi_dec <input file> <output file>

Thank you to the authors of the source code being used for inspiration for this source code

Example Project That Use This Library
  1. You must provide a pointer to an existing array to run this codec


RetroSearch is an open source project built by @garambo | Open a GitHub Issue

Search and Browse the WWW like it's 1997 | Search results from DuckDuckGo

HTML: 3.2 | Encoding: UTF-8 | Version: 0.7.4