ugBASIC 1.18
An isomorphic BASIC language compiler for retrocomputers
Loading...
Searching...
No Matches
image_descriptor_create.c
Go to the documentation of this file.
1/*****************************************************************************
2 * ugBASIC - an isomorphic BASIC language compiler for retrocomputers *
3 *****************************************************************************
4 * Copyright 2021-2026 Marco Spedaletti (asimov@mclink.it)
5 *
6 * Licensed under the Apache License, Version 2.0 (the "License");
7 * you may not use this file except in compliance with the License.
8 * You may obtain a copy of the License at
9 *
10 * http://www.apache.org/licenses/LICENSE-2.0
11 *
12 * Unless required by applicable law or agreed to in writing, software
13 * distributed under the License is distributed on an "AS IS" BASIS,
14 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15 * See the License for the specific language governing permissions and
16 * limitations under the License.
17 *----------------------------------------------------------------------------
18 * Concesso in licenza secondo i termini della Licenza Apache, versione 2.0
19 * (la "Licenza"); è proibito usare questo file se non in conformità alla
20 * Licenza. Una copia della Licenza è disponibile all'indirizzo:
21 *
22 * http://www.apache.org/licenses/LICENSE-2.0
23 *
24 * Se non richiesto dalla legislazione vigente o concordato per iscritto,
25 * il software distribuito nei termini della Licenza è distribuito
26 * "COSÌ COM'È", SENZA GARANZIE O CONDIZIONI DI ALCUN TIPO, esplicite o
27 * implicite. Consultare la Licenza per il testo specifico che regola le
28 * autorizzazioni e le limitazioni previste dalla medesima.
29 ****************************************************************************/
30
31/****************************************************************************
32 * INCLUDE SECTION
33 ****************************************************************************/
34
35#include "../../ugbc.h"
37
38/****************************************************************************
39 * CODE SECTION
40 ****************************************************************************/
41
42ImageDescriptor * image_descriptor_create( Environment * _environment, char * _filename, int _flags ) {
43
44 ImageDescriptor * result = malloc( sizeof( ImageDescriptor ) );
45 memset( result, 0, sizeof( ImageDescriptor ) );
46
47 // We must load the target dependent version of the images.
48 char * lookedFilename = resource_load_asserts( _environment, _filename );
49
50 // If present, we can calculate the effective size.
51 result->fileSize = file_get_size( _environment, lookedFilename );
52
53 // Now we can decode the image using the external library.
54 result->data = stbi_load( lookedFilename, &result->width, &result->height, &result->depth, 0 );
55 result->size = result->width * result->height * result->depth;
57 result->colorsCount = MAX_PALETTE;
58 result->colorsCount = rgbi_extract_palette( _environment, result->data, result->width, result->height, result->depth, result->colors, result->colorsCount, 1 );
59
60 // If we are unable to decode the image, we stop the compilation.
61 if ( !result->data ) {
63 }
64
65 // If the image has to be post processed, we do it:
66 // - X FLIP
67 if( _flags & FLAG_FLIP_X ) {
68 result = image_descriptor_flip_x( _environment, result );
69 }
70 // - Y FLIP
71 if( _flags & FLAG_FLIP_Y ) {
72 result = image_descriptor_flip_y( _environment, result );
73 }
74
75 // ADI INFO
76 adiline4("LI:%s:%s:%x:%x", _filename, lookedFilename, result->fileSize, result->size );
77
78 return result;
79
80}
RGBi * malloc_palette(int _size)
Allocate a palette space.
char * resource_load_asserts(Environment *_environment, char *_filename)
int rgbi_extract_palette(Environment *_environment, unsigned char *_source, int _width, int _height, int _depth, RGBi _palette[], int _palette_size, int _sorted)
Extract the color palette from the given image.
int file_get_size(Environment *_environment, char *_filename)
ImageDescriptor * image_descriptor_create(Environment *_environment, char *_filename, int _flags)
ImageDescriptor * image_descriptor_flip_x(Environment *_environment, ImageDescriptor *_source_image)
ImageDescriptor * image_descriptor_flip_y(Environment *_environment, ImageDescriptor *_source_image)
STBIDEF stbi_uc * stbi_load(char const *filename, int *x, int *y, int *channels_in_file, int desired_channels)
int colorsCount
Definition ugbc.h:918
RGBi * colors
Definition ugbc.h:917
char * data
Definition ugbc.h:911
void * malloc(YYSIZE_T)
#define adiline4(s, a, b, c, d)
Definition ugbc.h:4202
struct _ImageDescriptor ImageDescriptor
#define CRITICAL_IMAGE_LOAD_UNKNOWN_FORMAT(f)
Definition ugbc.h:3501
struct _Environment Environment
Structure of compilation environment.
#define FLAG_FLIP_X
Definition ugbc.h:4553
#define MAX_PALETTE
Definition ugbc.h:568
#define FLAG_FLIP_Y
Definition ugbc.h:4554