2021-01-23 11:16:35 +03:00
|
|
|
|
/* Written by turbocat2001 (Logaev Maxim) */
|
|
|
|
|
|
2020-11-13 20:47:07 +03:00
|
|
|
|
#include <stdio.h>
|
|
|
|
|
#include <stdlib.h>
|
|
|
|
|
#include <stddef.h>
|
|
|
|
|
#include <clayer/libimg.h>
|
|
|
|
|
#include <kos32sys1.h>
|
|
|
|
|
|
2021-01-23 11:16:35 +03:00
|
|
|
|
#define NEW_IMG_H 128
|
|
|
|
|
#define NEW_IMG_W 128
|
|
|
|
|
|
|
|
|
|
#define IMG_H 256
|
|
|
|
|
#define IMG_W 256
|
|
|
|
|
|
|
|
|
|
Image *image_blend; // Create image struct
|
2020-11-13 20:47:07 +03:00
|
|
|
|
|
2021-01-23 11:16:35 +03:00
|
|
|
|
struct kolibri_system_colors sys_color_table; // Create system colors table
|
2020-11-13 20:47:07 +03:00
|
|
|
|
|
2021-01-23 11:16:35 +03:00
|
|
|
|
char* load_img(char* fname, int32_t* read_sz){ // Image file upload function
|
2020-11-13 20:47:07 +03:00
|
|
|
|
FILE *f = fopen(fname, "rb");
|
|
|
|
|
if (!f) {
|
|
|
|
|
printf("Can't open file: %s\n", fname);
|
2021-01-23 11:16:35 +03:00
|
|
|
|
exit(0);
|
2020-11-13 20:47:07 +03:00
|
|
|
|
}
|
|
|
|
|
if (fseek(f, 0, SEEK_END)) {
|
|
|
|
|
printf("Can't SEEK_END file: %s\n", fname);
|
2021-01-23 11:16:35 +03:00
|
|
|
|
exit(0);
|
2020-11-13 20:47:07 +03:00
|
|
|
|
}
|
|
|
|
|
int filesize = ftell(f);
|
|
|
|
|
rewind(f);
|
|
|
|
|
char* fdata = malloc(filesize);
|
|
|
|
|
if(!fdata) {
|
|
|
|
|
printf("No memory for file %s\n", fname);
|
2021-01-23 11:16:35 +03:00
|
|
|
|
exit(0);
|
2020-11-13 20:47:07 +03:00
|
|
|
|
}
|
|
|
|
|
*read_sz = fread(fdata, 1, filesize, f);
|
|
|
|
|
if (ferror(f)) {
|
|
|
|
|
printf("Error reading file %s\n", fname);
|
2021-01-23 11:16:35 +03:00
|
|
|
|
exit(0);
|
2020-11-13 20:47:07 +03:00
|
|
|
|
}
|
|
|
|
|
fclose(f);
|
|
|
|
|
return fdata;
|
|
|
|
|
}
|
|
|
|
|
|
2021-01-23 11:16:35 +03:00
|
|
|
|
void DrawGUI(){
|
2020-11-13 20:47:07 +03:00
|
|
|
|
BeginDraw();
|
2021-01-23 11:16:35 +03:00
|
|
|
|
DrawWindow(10, 40, (IMG_W+NEW_IMG_W)+50, IMG_H+50, "Libimg", sys_color_table.work_area, 0x34);
|
|
|
|
|
img_draw(image_blend, 10, 10, IMG_W*2, IMG_H , 0, 0); // Draw blended image to window
|
2020-11-13 20:47:07 +03:00
|
|
|
|
EndDraw();
|
|
|
|
|
}
|
|
|
|
|
|
2021-01-23 11:16:35 +03:00
|
|
|
|
int main(){
|
|
|
|
|
if (kolibri_libimg_init() == -1){
|
2020-11-13 20:47:07 +03:00
|
|
|
|
printf("Error loading lib_img.obj\n");
|
2021-01-23 11:16:35 +03:00
|
|
|
|
exit(0);
|
2020-11-13 20:47:07 +03:00
|
|
|
|
}
|
2021-01-23 11:16:35 +03:00
|
|
|
|
|
|
|
|
|
get_system_colors(&sys_color_table); // Get system colors theme
|
|
|
|
|
set_event_mask(0xC0000027);
|
2020-11-13 20:47:07 +03:00
|
|
|
|
|
2021-01-23 11:16:35 +03:00
|
|
|
|
uint32_t img_size;
|
|
|
|
|
void *file_data = load_img("logo.png", &img_size); // Get RAW data and size
|
|
|
|
|
|
|
|
|
|
Image* image = img_decode(file_data, img_size, 0); // Decode RAW data to Image data
|
|
|
|
|
|
|
|
|
|
if (image->Type != IMAGE_BPP32) {
|
|
|
|
|
image = img_convert(image, NULL, IMAGE_BPP32, 0, 0); // Convert image to format BPP32
|
|
|
|
|
if (!image) {
|
|
|
|
|
printf("Сonvert error!: \n");
|
|
|
|
|
exit(0);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
image_blend = img_create(IMG_W+NEW_IMG_W, IMG_H, IMAGE_BPP32); // Create an empty layer
|
|
|
|
|
img_fill_color(image_blend, IMG_W+NEW_IMG_W, IMG_H, sys_color_table.work_area); // Fill the layer with one color
|
|
|
|
|
img_blend(image_blend, image, 0, 0, 0, 0, IMG_W, IMG_H); // Blending images to display the alpha channel.
|
|
|
|
|
/* Reduce image size from 256x256 to 128x128 */
|
|
|
|
|
image = img_scale(image, 0, 0, IMG_W, IMG_H, NULL, LIBIMG_SCALE_STRETCH , LIBIMG_INTER_BILINEAR, NEW_IMG_W, NEW_IMG_H);
|
|
|
|
|
img_blend(image_blend, image, 256, 0, 0, 0, NEW_IMG_W, NEW_IMG_H);
|
|
|
|
|
img_destroy(image); // Destroy image structure
|
|
|
|
|
free(file_data); // Free allocated file_data buffer
|
|
|
|
|
|
|
|
|
|
/* Main event loop */
|
|
|
|
|
while (1) {
|
|
|
|
|
switch(get_os_event()){
|
2020-11-13 20:47:07 +03:00
|
|
|
|
case KOLIBRI_EVENT_REDRAW:
|
2021-01-23 11:16:35 +03:00
|
|
|
|
DrawGUI();
|
2020-11-13 20:47:07 +03:00
|
|
|
|
break;
|
|
|
|
|
case KOLIBRI_EVENT_BUTTON:
|
2021-01-23 11:16:35 +03:00
|
|
|
|
if (get_os_button() == 1){
|
|
|
|
|
return 0;
|
|
|
|
|
}
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
exit(0);
|
2020-11-13 20:47:07 +03:00
|
|
|
|
}
|