<commit_before>/* example for how to use the imxvpuapi decoder interface to decode JPEGs
 * Copyright (C) 2014 <NAME>
 *
 * This library is free software; you can redistribute it and/or
 * modify it under the terms of the GNU Lesser General Public
 * License as published by the Free Software Foundation; either
 * version 2.1 of the License, or (at your option) any later version.
 *
 * This library is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 * Lesser General Public License for more details.
 *
 * You should have received a copy of the GNU Lesser General Public
 * License along with this library; if not, write to the Free Software
 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301
 * USA
 */


#include <stdio.h>
#include <stdlib.h>
#include "main.h"
#include "imxvpuapi/imxvpuapi_jpeg.h"



/* This is a simple example of how to decode JPEGs with the imxvpuapi library.
 * It reads the given JPEG file and configures the VPU to decode MJPEG data.
 * Then, the decoded pixels are written to the output file, in PPM format.
 *
 * Note that using the JPEG decoder is optional, and it is perfectly OK to use
 * the lower-level video decoder API for JPEGs as well. (In fact, this is what
 * the JPEG decoder does internally.) The JPEG decoder is considerably easier
 * to use, with less boilerplate code, however. */



struct _Context
{
	FILE *fin, *fout;
	ImxVpuJPEGDecoder *jpeg_decoder;
};


Context* init(FILE *input_file, FILE *output_file)
{
	Context *ctx;

	ctx = calloc(1, sizeof(Context));
	ctx->fin = input_file;
	ctx->fout = output_file;

	/* Open the JPEG decoder */
	imx_vpu_jpeg_dec_open(&(ctx->jpeg_decoder), NULL, 0);

	return ctx;
}


Retval run(Context *ctx)
{
	long size;
	void *buf;
	ImxVpuEncodedFrame encoded_frame;
	ImxVpuPicture decoded_picture;
	ImxVpuJPEGInfo info;
	uint8_t *mapped_virtual_address;
	size_t num_out_byte;


	/* Determine size of the input file to be able to read all of its bytes in one go */
	fseek(ctx->fin, 0, SEEK_END);
	size = ftell(ctx->fin);
	fseek(ctx->fin, 0, SEEK_SET);

	/* Allocate buffer for the input data, and read the data into it */
	buf = malloc(size);
	fread(buf, 1, size, ctx->fin);

	/* Setup encoded frame information */
	encoded_frame.data.virtual_address = buf;
	encoded_frame.data_size = size;
	/* Codec data is out-of-band data that is typically stored in a separate space
	 * in containers for each elementary stream; JPEG data does not need it */
	encoded_frame.codec_data = NULL;
	encoded_frame.codec_data_size = 0;

	fprintf(stderr, "encoded input frame:  size: %u byte\n", encoded_frame.data_size);

	/* Perform the actual JPEG decoding */
	dec_ret = imx_vpu_jpeg_dec_decode(ctx->jpeg_decoder, &encoded_frame, &decoded_picture);

	if ((dec_ret != IMX_VPU_DEC_RETURN_CODE_OK) || (decoded_picture.framebuffer == NULL))
	{
		if (dec_ret == IMX_VPU_DEC_RETURN_CODE_OK)
			fprintf(stderr, "could not decode this JPEG image : unspecified error (framebuffer is NULL)\n");
		else
			fprintf(stderr, "could not decode this JPEG image : %s\n", imx_vpu_dec_error_string(dec_ret));
		return RETVAL_ERROR;
	}<commit_msg>Fix typo<commit_after>/* example for how to use the imxvpuapi decoder interface to decode JPEGs
 * Copyright (C) 2014 <NAME>
 *
 * This library is free software; you can redistribute it and/or
 * modify it under the terms of the GNU Lesser General Public
 * License as published by the Free Software Foundation; either
 * version 2.1 of the License, or (at your option) any later version.
 *
 * This library is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 * Lesser General Public License for more details.
 *
 * You should have received a copy of the GNU Lesser General Public
 * License along with this library; if not, write to the Free Software
 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301
 * USA
 */


#include <stdio.h>
#include <stdlib.h>
#include "main.h"
#include "imxvpuapi/imxvpuapi_jpeg.h"



/* This is a simple example of how to decode JPEGs with the imxvpuapi library.
 * It reads the given JPEG file and configures the VPU to decode MJPEG data.
 * Then, the decoded pixels are written to the output file, in PPM format.
 *
 * Note that using the JPEG decoder is optional, and it is perfectly OK to use
 * the lower-level video decoder API for JPEGs as well. (In fact, this is what
 * the JPEG decoder does internally.) The JPEG decoder is considerably easier
 * to use, with less boilerplate code, however. */



struct _Context
{
	FILE *fin, *fout;
	ImxVpuJPEGDecoder *jpeg_decoder;
};


Context* init(FILE *input_file, FILE *output_file)
{
	Context *ctx;

	ctx = calloc(1, sizeof(Context));
	ctx->fin = input_file;
	ctx->fout = output_file;

	/* Open the JPEG decoder */
	imx_vpu_jpeg_dec_open(&(ctx->jpeg_decoder), NULL, 0);

	return ctx;
}


Retval run(Context *ctx)
{
	long size;
	void *buf;
	ImxVpuEncodedFrame encoded_frame;
	ImxVpuPicture decoded_picture;
	ImxVpuJPEGInfo info;
	uint8_t *mapped_virtual_address;
	size_t num_out_byte;


	/* Determine size of the input file to be able to read all of its bytes in one go */
	fseek(ctx->fin, 0, SEEK_END);
	size = ftell(ctx->fin);
	fseek(ctx->fin, 0, SEEK_SET);

	/* Allocate buffer for the input data, and read the data into it */
	buf = malloc(size);
	fread(buf, 1, size, ctx->fin);

	/* Setup encoded frame information */
	encoded_frame.data.virtual_address = buf;
	encoded_frame.data_size = size;
	/* Codec data is out-of-band data that is typically stored in a separate space
	 * in containers for each elementary stream; JPEG data does not need it */
	encoded_frame.codec_data = NULL;
	encoded_frame.codec_data_size = 0;

	fprintf(stderr, "encoded input frame:  size: %u byte\n", encoded_frame.data_size);

	/* Perform the actual JPEG decoding */
	ImxVpuDecReturnCodes dec_ret = imx_vpu_jpeg_dec_decode(ctx->jpeg_decoder, &encoded_frame, &decoded_picture);

	if ((dec_ret != IMX_VPU_DEC_RETURN_CODE_OK) || (decoded_picture.framebuffer == NULL))
	{
		if (dec_ret == IMX_VPU_DEC_RETURN_CODE_OK)
			fprintf(stderr, "could not decode this JPEG image : unspecified error (framebuffer is NULL)\n");
		else
			fprintf(stderr, "could not decode this JPEG image : %s\n", imx_vpu_dec_error_string(dec_ret));
		return RETVAL_ERROR;
	}
{'fraction_non_alphanumeric': 0.08798283261802575, 'fraction_numerical': 0.007357449417535254, 'mean_word_length': 4.249396621078037, 'pattern_counts': {'":': 0, '<': 9, '<?xml version=': 0, '>': 25, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '783885', 'n_tokens_mistral': 2204, 'n_tokens_neox': 2063, 'n_words': 814}