// File: /workspace/github_c_makefile_star2_O3/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
cmpb $0x0, 0x38(%r14)
je 0x62d80
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 0x62d8c
movl 0x30(%rsp), %esi
jmp 0x62d9b
cmpb $0x0, 0x39(%r14)
jne 0x62dc8
jmp 0x62f07
movw $0x5, 0x118(%rsp)
movl $0xffffffff, %esi       # imm = 0xFFFFFFFF
callq 0x62f32
movq 0x28(%r14), %rax
testq %rax, %rax
je 0x62dae
movq (%rax), %rsi
jmp 0x62db0
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 0x62de5
movq (%rax), %rdi
jmp 0x62de7
xorl %edi, %edi
movslq 0x30(%r14), %rsi
leaq 0x20(%rsp), %rdx
movl $0x209, %ecx            # imm = 0x209
callq 0x58b20
testl %eax, %eax
jne 0x62f07
movl $0x1, 0x48(%rsp)
movq 0x28(%r14), %rax
testq %rax, %rax
je 0x62e18
movq (%rax), %rdi
jmp 0x62e1a
xorl %edi, %edi
movslq 0x30(%r14), %rsi
leaq 0x20(%rsp), %rdx
callq 0x56d50
testl %eax, %eax
jne 0x62f07
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
movl -0x24(%r14), %eax
testl %eax, %eax
jle 0x62efd
xorl %ecx, %ecx
movl 0x20(%rsp), %ebp
movq %rsp, %r15
leaq 0x10(%rsp), %r12
xorl %r14d, %r14d
testl %ebp, %ebp
jle 0x62eee
movq %rcx, 0x8(%rsp)
imull %ecx, %ebp
addq $0x3, %rbp
xorl %r13d, %r13d
movl %r13d, (%rsp)
movl %r14d, 0x4(%rsp)
movq 0x58(%rsp), %rax
addq %rbp, %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), %rcx
cmpq %rcx, %r13
jl 0x62e7e
movl 0x24(%rsp), %eax
movl %ecx, %ebp
movq 0x8(%rsp), %rcx
incl %r14d
addl $0x4, %ecx
cmpl %eax, %r14d
jl 0x62e6b
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