Subversion Repositories Kolibri OS

Rev

Rev 8187 | Go to most recent revision | Details | Compare with Previous | Last modification | View Log | RSS feed

Rev Author Line No. Line
8541 superturbo 1
/* Written by turbocat2001 (Logaev Maxim) */
2
 
8187 maxcodehac 3
#include 
4
#include 
5
#include 
6
#include 
7
#include 
8
 
8541 superturbo 9
#define NEW_IMG_H 128
10
#define NEW_IMG_W 128
8187 maxcodehac 11
 
8541 superturbo 12
#define IMG_H 256
13
#define IMG_W 256
8187 maxcodehac 14
 
8541 superturbo 15
Image *image_blend; // Create image struct
16
 
17
struct kolibri_system_colors sys_color_table;  // Create system colors table
18
 
19
char* load_img(char* fname, int32_t* read_sz){  // Image file upload function
8187 maxcodehac 20
    FILE *f = fopen(fname, "rb");
21
    if (!f) {
22
        printf("Can't open file: %s\n", fname);
8541 superturbo 23
        exit(0);
8187 maxcodehac 24
    }
25
    if (fseek(f, 0, SEEK_END)) {
26
        printf("Can't SEEK_END file: %s\n", fname);
8541 superturbo 27
        exit(0);
8187 maxcodehac 28
    }
29
    int filesize = ftell(f);
30
    rewind(f);
31
    char* fdata = malloc(filesize);
32
    if(!fdata) {
33
        printf("No memory for file %s\n", fname);
8541 superturbo 34
        exit(0);
8187 maxcodehac 35
    }
36
    *read_sz = fread(fdata, 1, filesize, f);
37
    if (ferror(f)) {
38
        printf("Error reading file %s\n", fname);
8541 superturbo 39
        exit(0);
8187 maxcodehac 40
    }
41
    fclose(f);
42
    return fdata;
43
}
44
 
8541 superturbo 45
void DrawGUI(){
8187 maxcodehac 46
    BeginDraw();
8541 superturbo 47
	DrawWindow(10, 40, (IMG_W+NEW_IMG_W)+50, IMG_H+50, "Libimg", sys_color_table.work_area, 0x34);
48
	img_draw(image_blend, 10, 10, IMG_W*2, IMG_H , 0, 0);  // Draw blended image to window
8187 maxcodehac 49
    EndDraw();
50
}
51
 
8541 superturbo 52
int main(){
53
    if (kolibri_libimg_init() == -1){
8187 maxcodehac 54
		printf("Error loading lib_img.obj\n");
8541 superturbo 55
        exit(0);
8187 maxcodehac 56
	}
8541 superturbo 57
 
58
	get_system_colors(&sys_color_table); // Get system colors theme
59
    set_event_mask(0xC0000027);
8187 maxcodehac 60
 
8541 superturbo 61
    uint32_t img_size;
62
    void *file_data = load_img("logo.png", &img_size); // Get RAW data and size
63
 
64
    Image* image = img_decode(file_data, img_size, 0); // Decode RAW data to Image data
65
 
66
    if (image->Type != IMAGE_BPP32) {
67
        image = img_convert(image, NULL, IMAGE_BPP32, 0, 0); // Convert image to format BPP32
68
        if (!image) {
69
             printf("Сonvert error!: \n");
70
             exit(0);
71
        }
72
    }
73
 
74
    image_blend = img_create(IMG_W+NEW_IMG_W, IMG_H, IMAGE_BPP32);  // Create an empty layer
75
    img_fill_color(image_blend, IMG_W+NEW_IMG_W, IMG_H, sys_color_table.work_area); // Fill the layer with one color
76
    img_blend(image_blend, image, 0, 0, 0, 0, IMG_W, IMG_H);  // Blending images to display the alpha channel.
77
    /* Reduce image size from 256x256 to 128x128 */
78
    image = img_scale(image, 0, 0, IMG_W, IMG_H, NULL, LIBIMG_SCALE_STRETCH , LIBIMG_INTER_BILINEAR, NEW_IMG_W, NEW_IMG_H);
79
    img_blend(image_blend, image, 256, 0, 0, 0, NEW_IMG_W, NEW_IMG_H);
80
    img_destroy(image);  // Destroy image structure
81
    free(file_data);  // Free allocated file_data buffer
82
 
83
    /* Main event loop */
84
    while (1) {
85
		switch(get_os_event()){
8187 maxcodehac 86
			case KOLIBRI_EVENT_REDRAW:
8541 superturbo 87
				DrawGUI();
8187 maxcodehac 88
				break;
89
			case KOLIBRI_EVENT_BUTTON:
8541 superturbo 90
				if (get_os_button() == 1){
91
                    return 0;
92
                }
93
				break;
94
        }
95
	}
96
	exit(0);
8187 maxcodehac 97
}