// File: /workspace/github_c_makefile_star2_O2/enzo1982[P]smooth/classes/graphics/backends/xlib/bitmapxlib.cpp
// Function: smooth::GUI::BitmapXLib::CreateBitmap(smooth::GUI::Size const&, int)
S::Bool S::GUI::BitmapXLib::CreateBitmap(const Size &nSize, Int nDepth)
{
	if (display == NIL) return False;

	DeleteBitmap();

	if (nDepth == -1)		  nDepth = XDefaultDepth(display, XDefaultScreen(display));
	if (nDepth != 24 && nDepth != 32) nDepth = 24;

	/* Find best fit for pixel format.
	 */
	int			 count	 = 0;
	int			 index	 = 0;
	XPixmapFormatValues	*formats = XListPixmapFormats(display, &count);

	for (Int i = 0; i < count; i++)
	{
		if (Math::Abs(formats[i].depth - nDepth) < Math::Abs(formats[index].depth - nDepth)) index = i;

		if (formats[i].depth == nDepth) break;
	}

	/* Allocate and create image.
	 */
	bytes	= new UnsignedByte [nSize.cy * nSize.cx * (formats[index].bits_per_pixel / 8) + nSize.cy * (((nSize.cx * formats[index].bits_per_pixel) % formats[index].scanline_pad) / 8)];
	bitmap	= XCreateImage(display, XDefaultVisual(display, XDefaultScreen(display)), formats[index].depth, ZPixmap, 0, (char *) bytes, nSize.cx, nSize.cy, formats[index].scanline_pad, 0);

	if (bitmap == NIL) { delete [] (UnsignedByte *) bytes; XFree(formats); return False; }

	size	= nSize;
	depth	= formats[index].depth;
	bpp	= formats[index].bits_per_pixel;
	align	= formats[index].scanline_pad / 8;

	XFree(formats);

	return True;
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x28, %rsp
cmpq $0x0, 0x20(%rdi)
je 0xb7e2c
movl %edx, %ebp
movq %rsi, %r14
movq %rdi, %rbx
movq (%rdi), %rax
callq *0x18(%rax)
cmpl $-0x1, %ebp
jne 0xb7d90
movq 0x20(%rbx), %r15
movq %r15, %rdi
callq 0x59060
movq %r15, %rdi
movl %eax, %esi
callq 0x5a340
movl %eax, %ebp
xorl %eax, %eax
cmpl $0x20, %ebp
sete %al
leal 0x18(,%rax,8), %ebp
leaq 0x24(%rsp), %r12
andl $0x0, (%r12)
movq 0x20(%rbx), %rdi
movq %r12, %rsi
callq 0x584f0
movq %rax, %r15
movslq (%r12), %rax
xorl %ecx, %ecx
movq %r15, %rdx
xorl %esi, %esi
xorl %r9d, %r9d
cmpq %rax, %rcx
jge 0xb7e33
movslq %esi, %rdi
imulq $0xc, %rdi, %rdi
movl (%r15,%rdi), %r8d
movl %r8d, %edi
subl %ebp, %edi
movl $0x0, %r10d
subl %ebp, %r8d
je 0xb7def
sarl $0x1f, %edi
orl $0x1, %edi
movl %edi, %r10d
movl (%rdx), %edi
movl %edi, %r11d
subl %ebp, %r11d
sarl $0x1f, %r11d
orl $0x1, %r11d
movl %edi, %r12d
subl %ebp, %r12d
cmovel %r9d, %r11d
imull %r12d, %r11d
imull %r8d, %r10d
movl %ecx, %r8d
cmpl %r10d, %r11d
jl 0xb7e1c
movl %esi, %r8d
incq %rcx
addq $0xc, %rdx
movl %r8d, %esi
cmpl %ebp, %edi
jne 0xb7dc6
jmp 0xb7e36
xorl %ebp, %ebp
jmp 0xb7f0c
movl %esi, %r8d
movl (%r14), %edi
movslq %r8d, %rax
imulq $0xc, %rax, %r13
movl 0x4(%r15,%r13), %ecx
pushq $0x8
popq %r8
movl %ecx, %eax
cltd
idivl %r8d
movl %eax, %esi
imull %edi, %esi
imull %edi, %ecx
movl %ecx, %eax
cltd
idivl 0x8(%r15,%r13)
movl %edx, %eax
cltd
idivl %r8d
addl %esi, %eax
imull 0x4(%r14), %eax
movslq %eax, %rdi
callq 0x577a0
movq %rax, 0x18(%rbx)
movq 0x20(%rbx), %r12
movq %r12, %rdi
callq 0x59060
movq %r12, %rdi
movl %eax, %esi
callq 0x58550
movq 0x18(%rbx), %r9
movl (%r14), %ecx
movl 0x4(%r14), %esi
movl (%r15,%r13), %edx
movl 0x8(%r15,%r13), %edi
movl %edi, 0x10(%rsp)
movl %esi, 0x8(%rsp)
andl $0x0, 0x18(%rsp)
movl %ecx, (%rsp)
pushq $0x2
popq %rcx
movq %r12, %rdi
movq %rax, %rsi
xorl %r8d, %r8d
callq 0x5a470
movq %rax, 0x28(%rbx)
testq %rax, %rax
setne %bpl
je 0xb7ef6
movq %r15, %rax
addq %r13, %rax
movq (%r14), %rcx
movq %rcx, 0x10(%rbx)
movb (%rax), %cl
movb %cl, 0xa(%rbx)
movb 0x4(%rax), %cl
movb %cl, 0xb(%rbx)
movl 0x8(%rax), %eax
cltd
pushq $0x8
popq %rcx
idivl %ecx
movb %al, 0xc(%rbx)
jmp 0xb7f04
movq 0x18(%rbx), %rdi
testq %rdi, %rdi
je 0xb7f04
callq 0x572d0
movq %r15, %rdi
callq 0x59110
movl %ebp, %eax
addq $0x28, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
nop