Subversion Repositories Kolibri OS

Rev

Rev 9620 | Show entire file | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed

Rev 9620 Rev 9766
Line 1... Line 1...
1
/* Written by turbocat2001 (Logaev Maxim) */
1
/* Written by turbocat2001 (Logaev Maxim) */
Line -... Line 2...
-
 
2
 
-
 
3
#include 
2
 
4
#include 
3
#include 
5
#include 
4
#include 
-
 
5
#include 
-
 
6
#include 
6
#include 
Line 7... Line 7...
7
#include 
7
#include 
8
 
8
 
Line 9... Line 9...
9
#define NEW_IMG_H 128 
9
#define NEW_IMG_H 128
10
#define NEW_IMG_W 128
10
#define NEW_IMG_W 128
Line 11... Line 11...
11
 
11
 
Line 12... Line 12...
12
#define IMG_H 256
12
#define IMG_H 256
Line 13... Line 13...
13
#define IMG_W 256
13
#define IMG_W 256
-
 
14
 
14
 
15
Image* image_blend; // Create image struct
15
Image *image_blend; // Create image struct
16
 
16
 
17
ksys_colors_table_t sys_color_table; // Create system colors table
17
ksys_colors_table_t sys_color_table;  // Create system colors table
18
 
18
 
19
void* load_img(char* fname, uint32_t* read_sz)
19
void* load_img(char* fname, uint32_t* read_sz){  // Image file upload function
20
{ // Image file upload function
Line 27... Line 28...
27
        return NULL;
28
        return NULL;
28
    }
29
    }
29
    int filesize = ftell(f);
30
    int filesize = ftell(f);
30
    rewind(f);
31
    rewind(f);
31
    void* fdata = malloc(filesize);
32
    void* fdata = malloc(filesize);
32
    if(!fdata) {
33
    if (!fdata) {
33
        printf("No memory for file %s\n", fname);
34
        printf("No memory for file %s\n", fname);
34
        return NULL;
35
        return NULL;
35
    }
36
    }
36
    *read_sz = fread(fdata, 1, filesize, f);
37
    *read_sz = fread(fdata, 1, filesize, f);
37
    if (ferror(f)) {
38
    if (ferror(f)) {
Line 40... Line 41...
40
    }
41
    }
41
    fclose(f);
42
    fclose(f);
42
    return fdata;
43
    return fdata;
43
}
44
}
Line 44... Line 45...
44
 
45
 
-
 
46
void draw_gui()
45
void draw_gui(){
47
{
46
    _ksys_start_draw();
48
    _ksys_start_draw();
47
    _ksys_create_window(10, 40, (IMG_W+NEW_IMG_W)+50, IMG_H+50, "Libimg", sys_color_table.work_area, 0x34);
49
    _ksys_create_window(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
50
    img_draw(image_blend, 10, 10, IMG_W * 2, IMG_H, 0, 0); // Draw blended image to window
49
    _ksys_end_draw();
51
    _ksys_end_draw();
Line 50... Line 52...
50
}
52
}
-
 
53
 
51
 
54
int main()
52
int main(){
55
{
53
    _ksys_get_system_colors(&sys_color_table); // Get system colors theme
56
    _ksys_get_system_colors(&sys_color_table); // Get system colors theme
54
    _ksys_set_event_mask(0xC0000027);
57
    _ksys_set_event_mask(0xC0000027);
55
    
58
 
56
    uint32_t img_size; 
59
    uint32_t img_size;
57
    void *file_data = load_img("logo.png", &img_size); // Get RAW data and size 
60
    void* file_data = load_img("logo.png", &img_size); // Get RAW data and size
58
    if(!file_data){
61
    if (!file_data) {
Line 59... Line 62...
59
        return 1;
62
        return 1;
60
    }
63
    }
61
 
64
 
62
    Image* image = img_decode(file_data, img_size, 0); // Decode RAW data to Image data
65
    Image* image = img_decode(file_data, img_size, 0); // Decode RAW data to Image data
63
    
66
 
64
    if (image->Type != IMAGE_BPP32) { 
67
    if (image->Type != IMAGE_BPP32) {
65
        image = img_convert(image, NULL, IMAGE_BPP32, 0, 0); // Convert image to format BPP32
68
        image = img_convert(image, NULL, IMAGE_BPP32, 0, 0); // Convert image to format BPP32
66
        if (!image) {
69
        if (!image) {
67
            printf("Сonvert error!: \n");  
70
            printf("Сonvert error!: \n");
68
            return 1;
71
            return 1;
69
        }
72
        }
70
    }
73
    }
71
    
74
 
72
    image_blend = img_create(IMG_W+NEW_IMG_W, IMG_H, IMAGE_BPP32);  // Create an empty layer
75
    image_blend = img_create(IMG_W + NEW_IMG_W, IMG_H, IMAGE_BPP32);                  // Create an empty layer
73
    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_fill_color(image_blend, IMG_W + NEW_IMG_W, IMG_H, sys_color_table.work_area); // Fill the layer with one color
74
    img_blend(image_blend, image, 0, 0, 0, 0, IMG_W, IMG_H);  // Blending images to display the alpha channel. 
77
    img_blend(image_blend, image, 0, 0, 0, 0, IMG_W, IMG_H);                          // Blending images to display the alpha channel.
75
    /* Reduce image size from 256x256 to 128x128 */
78
    /* Reduce image size from 256x256 to 128x128 */
76
    image = img_scale(image, 0, 0, IMG_W, IMG_H, NULL, LIBIMG_SCALE_STRETCH , LIBIMG_INTER_BILINEAR, NEW_IMG_W, NEW_IMG_H);
79
    image = img_scale(image, 0, 0, IMG_W, IMG_H, NULL, LIBIMG_SCALE_STRETCH, LIBIMG_INTER_BILINEAR, NEW_IMG_W, NEW_IMG_H);
77
    img_blend(image_blend, image, 256, 0, 0, 0, NEW_IMG_W, NEW_IMG_H); 
80
    img_blend(image_blend, image, 256, 0, 0, 0, NEW_IMG_W, NEW_IMG_H);
78
    img_destroy(image);  // Destroy image structure
81
    img_destroy(image); // Destroy image structure
79
    free(file_data);  // Free allocated file_data buffer 
82
    free(file_data);    // Free allocated file_data buffer
80
    
83
 
81
    /* Main event loop */
84
    /* Main event loop */
82
    while (1) {         
85
    while (1) {
83
		switch(_ksys_get_event()){
86
        switch (_ksys_get_event()) {
84
			case KSYS_EVENT_REDRAW:
87
        case KSYS_EVENT_REDRAW:
85
				draw_gui();
88
            draw_gui();
86
			break;
89
            break;
87
			
90
 
88
            case KSYS_EVENT_BUTTON:
91
        case KSYS_EVENT_BUTTON:
89
				if (_ksys_get_button()==1){
92
            if (_ksys_get_button() == 1) {
90
                    return 0;
93
                return 0;
91
                }
94
            }
92
			break;
95
            break;
93
        }
96
        }