/* jpeg.c
 * This file is part of Amsam photo cropping program
 * Copyright 2021, 2023, 2024, 2025, 2026 Nandakumar Edamana
 * Distributed under GNU General Public License, version 3
 */ 

#include <assert.h>
#include <stdarg.h>
#include <stdbool.h>

#include "jpeg.h"

void raw_jpeg_document_construct(RawJpegDocument *this, int width, int height)
{
	this->width = width;
	this->height = height;
	unsigned char * *_tmp_1 = (unsigned char * *) calloc((size_t) height, sizeof(unsigned char *));
	if (_tmp_1 == NULL) {
		perror(NULL);
		exit(EXIT_FAILURE);
	}

	this->lines = _tmp_1;

	for (int y = 0; y < height; y += 1) {
		unsigned char *_tmp_2 = (unsigned char *) calloc((size_t) (3 * width), sizeof(unsigned char));
		if (_tmp_2 == NULL) {
			perror(NULL);
			exit(EXIT_FAILURE);
		}

		this->lines[y] = _tmp_2;
	}
}

void raw_jpeg_document_destruct(RawJpegDocument *this)
{
	for (int y = 0; y < this->height; y += 1) {
		free(this->lines[y]);
	}
}
