Ejemplo n.º 1
0
static int stbi__process_marker_withmeta(stbi__jpeg *z, int m,std::function<void(ArrayBridge<uint8>&&)> HandleAppMarker)
{
	// check for comment block or APP blocks
	if ((m >= 0xE0 && m <= 0xEF) || m == 0xFE) {
		
		int length = stbi__get16be(z->s)-2;
		if ( HandleAppMarker )
		{
			auto* Data = (unsigned char*)stbi__malloc( length );
			if (!Data)
				return stbi__err("outofmem", "Out of memory");

			if (!stbi__getn(z->s, Data, length ))
			{
				STBI_FREE(Data);
				return stbi__err("failedtoreadapp", "Failed to read APP data");
			}
			
			auto DataArray = GetRemoteArray( Data, length );
			HandleAppMarker( GetArrayBridge(DataArray) );
			STBI_FREE(Data);
		}
		else
		{
			stbi__skip(z->s, length );
		}
		return 1;
	}
	
	return stbi__process_marker( z, m );
}
Ejemplo n.º 2
0
int
main(void)
{
    zplPlatform p_ = {0};
    zplPlatform *p = &p_;
    
    zpl_platform_init_with_software(p, "Test", WIN_WIDTH, WIN_HEIGHT, 0);
    
    b32 IsRunning = true;
    u32 *pixels = p->sw_framebuffer.memory;
    
    Rect window_rect = {
        .x = 0, .y = 0,
        .w = p->window_width, .h = p->window_height
    };
    
    i32 player_size = 64;
    i32 player_x = window_rect.w/2 - player_size/2; 
    i32 player_y = window_rect.h/2 - player_size/2; 
    i32 player_speed = 2; 
    
    Rect player_rect = {
        .x = player_x, .y = player_y,
        .w = player_size, .h = player_size
    };
    
    i32 font_x, font_y, font_n;
    u8 *font = stbi_load("font.bmp", &font_x, &font_y, &font_n, 4);
    
    i32 image_x, image_y, image_n;
    u8 *image_data = stbi_load("test0.jpg", &image_x, &image_y, &image_n, 4);
    u32 *filt_mem = zpl_malloc(image_x*image_y*4);
    
    f64 filter[5][5] = {
        -1, -1, -1, -1,  0,
        -1, -1, -1,  0,  1,
        -1, -1,  0,  1,  1,
        -1,  0,  1,  1,  1,
        0,  1,  1,  1,  1
    };
    
    zpl_image_rgb_filter(cast(u32 *)image_data, image_x, image_y,
                         filt_mem,
                         &filter[0][0], 5, 5,
                         1.0, 128.0);
    
    zpl_memcopy(image_data, filt_mem, image_x*image_y*4);
    
    Rect image_rect = {
        .x = 10, .y = 10,
        .w = image_x, .h = image_y
    };
    
    i32 gif_x, gif_y, gif_frames, gif_cursor = 0, gif_cd = 0;
    zplGifResult *gif = zpl_image_gif_load("test1.gif", &gif_x, &gif_y, &gif_frames);
    zplGifResult *gif_ptr = gif;
    //u32 *blur_mem = zpl_malloc(gif_x*gif_y*64);
    
    
    zplGifResult *node = gif;
    for(; node; node = node->next) {
        u8 *old_mem = node->data;
        u8 *new_mem = zpl_malloc(gif_x*gif_y*64);
        
        zpl_image_rgb_resize(cast(u32 *)old_mem, gif_x, gif_y,
                             cast(u32 *)new_mem, gif_x*4, gif_y*4, 
                             512, new_mem);
        
        node->data = new_mem;
        
        STBI_FREE(old_mem);
    }
    
    //zpl_mfree(blur_mem);
    zpl_mfree(filt_mem);
    
    gif_x *= 4;
    gif_y *= 4;
    
    Rect gif_rect = {
        .x = image_x+10, .y = 10,
        .w = gif_x, .h = gif_y
    };
    
    zplString str = 0;
    str = zpl_string_make(zpl_heap_allocator(), "Hello World!");
    
    while (IsRunning) {
        zpl_platform_update(p);
        
        if (p->keys[zplKey_Escape] == true ||
            p->keys[zplKey_Space]  == true) {
            IsRunning = false;
        }
        else if (p->window_is_closed) {
            IsRunning = false;
        }
        
        // NOTE(ZaKlaus): player controls
        if(p->keys[zplKey_A]) {
            player_x -= player_speed;
        }
        if (p->keys[zplKey_D]) {
            player_x += player_speed;
        }
        if (p->keys[zplKey_W]) {
            player_y -= player_speed;
        }
        if (p->keys[zplKey_S]) {
            player_y += player_speed;
        }
        
        slider = zpl_clamp(slider, 0, 255);
        
        /**/ if (p->keys[zplKey_K]) {
            slider--;
        }
        else if (p->keys[zplKey_L]) {
            slider++;
        }
        
        player_x = zpl_clamp(player_x, 0, p->window_width -player_size);
        player_y = zpl_clamp(player_y, 0, p->window_height-player_size);
        
        player_rect.x = player_x;
        player_rect.y = player_y;
        
        // NOTE(ZaKlaus): gif playback
        
        //gif_delay = &gif_data[(slider+1) * 4 * gif_x * gif_y + pad];
        //u8 delay[2] = { *(gif_delay), *(gif_delay+1) };
        
        if (gif_cursor == gif_frames-1) {
            gif_cursor = 0;
            gif_ptr = gif;
        }
        else {
            if (!gif_cd) {
                ++gif_cursor;
                gif_ptr = gif_ptr->next;
            }
        }
        
        if (!gif_cd) {
            gif_cd  = gif_ptr->delay;
        }
        else {
            gif_cd -= 2;
        }
        
        // NOTE(ZaKlaus): clear the screen
        fill_rect(pixels, 0x000000, window_rect);
        
        // NOTE(ZaKlaus): draw the image
        paint_rect(pixels, cast(u32 *)image_data, image_x, image_rect);
        
        // NOTE(ZaKlaus): draw the gif
        paint_rect(pixels, cast(u32 *)gif_ptr->data, gif_x, gif_rect);
        
        // NOTE(ZaKlaus): render the player
        fill_rect(pixels, 0xFF0000, player_rect);
        
        Rect font_rect = {
            .x = 10, .y = WIN_HEIGHT - 100,
            .w = 32, .h = 32
        };
        
        draw_text(pixels, cast(u32 *)font, str, font_x, font_rect);
        
        zpl_platform_display(p);
        
        zpl_sleep_ms(16);
    }
    
    zpl_image_gif_free(gif, true);
    
    return 0;
}