// File: /workspace/github_c_makefile_star2_O1/enzo1982[P]smooth/classes/graphics/imageloader/webp.cpp
// Function: smooth::GUI::ImageLoaderWebP::Load()
const S::GUI::Bitmap &S::GUI::ImageLoaderWebP::Load()
{
	/* Make sure bitmap is initialized.
	 */
	bitmap = NIL;

	/* Check if we either have a file or a buffer to load.
	 */
	if (!gotFileName && !gotBuffer) return bitmap;

	/* Load file into buffer.
	 */
	if (gotFileName)
	{
		InStream	 in(STREAM_FILE, fileName, IS_READ);

		buffer.Resize(in.Size());
		in.InputData(buffer, buffer.Size());
	}

	/* Init WebP decoder.
	 */
	WebPDecoderConfig config;
	WebPInitDecoderConfig(&config);

	if (WebPGetFeatures(buffer, buffer.Size(), &config.input) != VP8_STATUS_OK) return bitmap;

	/* Decode image in RGBA format.
	 */
	config.output.colorspace = MODE_RGBA;

	if (WebPDecode(buffer, buffer.Size(), &config) != VP8_STATUS_OK) return bitmap;

	/* Copy decoded image to bitmap.
	 */
	bitmap.CreateBitmap(Size(config.input.width, config.input.height));

	for (Int y = 0; y < config.input.height; y++)
	{
		Int	 lineOffset = 4 * y * config.input.width;

		for (Int x = 0; x < config.input.width; x++)
		{
			bitmap.SetPixel(Point(x, y), Color(config.output.u.RGBA.rgba[lineOffset + 4 * x + 3] << 24 | config.output.u.RGBA.rgba[lineOffset + 4 * x + 2] << 16 | config.output.u.RGBA.rgba[lineOffset + 4 * x + 1] << 8 | config.output.u.RGBA.rgba[lineOffset + 4 * x], Color::RGBA));
		}
	}

	WebPFreeDecBuffer(&config.output);

	return bitmap;
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x128, %rsp            # imm = 0x128
movq %rdi, %r14
leaq 0x40(%rdi), %rbx
movq %rbx, %rdi
xorl %esi, %esi
callq 0x56740
movb 0x38(%r14), %al
testb %al, %al
je 0x62cf1
leaq 0x8(%r14), %rdx
leaq 0x20(%rsp), %r15
movq %r15, %rdi
movl $0x3, %esi
movl $0x2, %ecx
callq 0x58730
leaq 0x20(%r14), %rdi
cmpw $0x0, 0x8(%r15)
je 0x62d02
movl 0x30(%rsp), %esi
jmp 0x62d11
cmpb $0x1, 0x39(%r14)
jne 0x62e7f
testb %al, %al
jne 0x62cc4
jmp 0x62d3e
movw $0x5, 0x118(%rsp)
movl $0xffffffff, %esi       # imm = 0xFFFFFFFF
callq 0x62eaa
movq 0x28(%r14), %rax
testq %rax, %rax
je 0x62d24
movq (%rax), %rsi
jmp 0x62d26
xorl %esi, %esi
movl 0x30(%r14), %edx
leaq 0x20(%rsp), %rdi
callq 0x56f50
leaq 0x20(%rsp), %rdi
callq 0x555b0
leaq 0x20(%rsp), %rdi
movl $0x209, %esi            # imm = 0x209
callq 0x58450
movq 0x28(%r14), %rax
testq %rax, %rax
je 0x62d5b
movq (%rax), %rdi
jmp 0x62d5d
xorl %edi, %edi
movslq 0x30(%r14), %rsi
leaq 0x20(%rsp), %rdx
movl $0x209, %ecx            # imm = 0x209
callq 0x58b20
testl %eax, %eax
jne 0x62e7f
movl $0x1, 0x48(%rsp)
movq 0x28(%r14), %rax
testq %rax, %rax
je 0x62d8e
movq (%rax), %rdi
jmp 0x62d90
xorl %edi, %edi
movslq 0x30(%r14), %rsi
leaq 0x20(%rsp), %rdx
callq 0x56d50
testl %eax, %eax
jne 0x62e7f
leaq 0x48(%rsp), %r14
movq -0x28(%r14), %rax
leaq 0x10(%rsp), %rsi
movq %rax, (%rsi)
movq %rbx, %rdi
movl $0xffffffff, %edx       # imm = 0xFFFFFFFF
callq 0x57c20
cmpl $0x0, -0x24(%r14)
jle 0x62e75
movq $0x0, (%rsp)
leaq 0x8(%rsp), %r15
leaq 0x10(%rsp), %r12
xorl %ebp, %ebp
movl 0x20(%rsp), %r14d
testl %r14d, %r14d
jle 0x62e5e
imull (%rsp), %r14d
addq $0x3, %r14
xorl %r13d, %r13d
movl %r13d, 0x8(%rsp)
movl %ebp, 0xc(%rsp)
movq 0x58(%rsp), %rax
addq %r14, %rax
movzbl (%rax,%r13,4), %ecx
shll $0x18, %ecx
movzbl -0x1(%rax,%r13,4), %edx
shll $0x10, %edx
movslq %ecx, %rcx
orq %rdx, %rcx
movzbl -0x2(%rax,%r13,4), %edx
shll $0x8, %edx
orq %rcx, %rdx
movzbl -0x3(%rax,%r13,4), %eax
orq %rdx, %rax
movq %rax, 0x18(%rsp)
movl $0x1, 0x10(%rsp)
movq %rbx, %rdi
movq %r15, %rsi
movq %r12, %rdx
callq 0x56080
incq %r13
movslq 0x20(%rsp), %rax
cmpq %rax, %r13
jl 0x62df9
incl %ebp
movq (%rsp), %rax
addl $0x4, %eax
movq %rax, (%rsp)
cmpl 0x24(%rsp), %ebp
jl 0x62de3
leaq 0x48(%rsp), %rdi
callq 0x57c60
movq %rbx, %rax
addq $0x128, %rsp            # imm = 0x128
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movq %rax, %rbx
leaq 0x20(%rsp), %rdi
callq 0x555b0
movq %rbx, %rdi
callq 0x57090
nop