<commit_before>/**
 * Hei Platform Library
 * Copyright (C) 2017-2021 <NAME> <<EMAIL>>
 * This software is licensed under MIT. See LICENSE for more details.
 */

#include <plcore/pl_filesystem.h>
#include <plcore/pl_image.h>

#include <errno.h>

#include "filesystem_private.h"
#include "image_private.h"

#define STBI_MALLOC( sz )        PlMAllocA( sz )
#define STBI_REALLOC( p, newsz ) PlReAllocA( p, newsz )
#define STBI_FREE( p )           PlFree( p )

#define STBIW_MALLOC( sz )        PlMAllocA( sz )
#define STBIW_REALLOC( p, newsz ) PlReAllocA( p, newsz )
#define STBIW_FREE( p )           PlFree( p )

#define STB_IMAGE_WRITE_IMPLEMENTATION
#if defined( STB_IMAGE_WRITE_IMPLEMENTATION )
#	include "stb_image_write.h"
#endif

#define STB_IMAGE_IMPLEMENTATION
#if defined( STB_IMAGE_IMPLEMENTATION )
#	include "stb_image.h"

static PLImage *LoadStbImage( PLFile *file ) {
	int x, y, component;
	unsigned char *data = stbi_load_from_memory( file->data, ( int ) file->size, &x, &y, &component, 4 );
	if ( data == NULL ) {
		PlReportErrorF( PL_RESULT_FILEREAD, "failed to read in image (%s)", stbi_failure_reason() );
		return NULL;
	}

	PLImage *image = PlCAllocA( 1, sizeof( PLImage ) );
	image->colour_format = PL_COLOURFORMAT_RGBA;<commit_msg>We need to be sure to cache the whole buffer here now.<commit_after>/**
 * Hei Platform Library
 * Copyright (C) 2017-2021 <NAME> <<EMAIL>>
 * This software is licensed under MIT. See LICENSE for more details.
 */

#include <plcore/pl_filesystem.h>
#include <plcore/pl_image.h>

#include <errno.h>

#include "filesystem_private.h"
#include "image_private.h"

#define STBI_MALLOC( sz )        PlMAllocA( sz )
#define STBI_REALLOC( p, newsz ) PlReAllocA( p, newsz )
#define STBI_FREE( p )           PlFree( p )

#define STBIW_MALLOC( sz )        PlMAllocA( sz )
#define STBIW_REALLOC( p, newsz ) PlReAllocA( p, newsz )
#define STBIW_FREE( p )           PlFree( p )

#define STB_IMAGE_WRITE_IMPLEMENTATION
#if defined( STB_IMAGE_WRITE_IMPLEMENTATION )
#	include "stb_image_write.h"
#endif

#define STB_IMAGE_IMPLEMENTATION
#if defined( STB_IMAGE_IMPLEMENTATION )
#	include "stb_image.h"

static PLImage *LoadStbImage( PLFile *file ) {
	size_t s = PlGetFileSize( file );
	if ( s >= INT32_MAX ) {
		PlReportBasicError( PL_RESULT_FILESIZE );
		return NULL;
	}

	void *tmp = PlMAllocA( s );
	PlReadFile( file, tmp, sizeof( char ), s );

	int x, y, component;
	unsigned char *data = stbi_load_from_memory( tmp, ( int ) s, &x, &y, &component, 4 );

	PlFree( tmp );

	if ( data == NULL ) {
		PlReportErrorF( PL_RESULT_FILEREAD, "failed to read in image (%s)", stbi_failure_reason() );
		return NULL;
	}

	PLImage *image = PlCAllocA( 1, sizeof( PLImage ) );
	image->colour_format = PL_COLOURFORMAT_RGBA;
{'fraction_non_alphanumeric': 0.12139992708713088, 'fraction_numerical': 0.008020415603353991, 'mean_word_length': 4.266794625719769, 'pattern_counts': {'":': 0, '<': 15, '<?xml version=': 0, '>': 20, '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': '202806', 'n_tokens_mistral': 1062, 'n_tokens_neox': 1030, 'n_words': 275}