Advertisement
Dr_Davenstein

ChatGPT 64-bit rotozoom lol

Jan 16th, 2023
2,906
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. 'Testing chatGPT FreeBASIC/inline asm code generation... lol
  2.  
  3. Sub RotoZoom(src() As Integer, angle As Single, zoom As Single)
  4.  
  5.     ' Get the dimensions of the source image
  6.     Dim As Integer w = UBound(src, 1) + 1
  7.     Dim As Integer h = UBound(src, 2) + 1
  8.  
  9.     ' Create a destination image of the same size
  10.     Dim As Integer dest(w-1, h-1) As Integer
  11.  
  12.     ' Precalculate trigonometric values
  13.     Dim As Single cosA = Cos(angle)
  14.     Dim As Single sinA = Sin(angle)
  15.     Dim As Single zoom_inv = 1/zoom
  16.  
  17.     ' Rotation and Scaling using assembly
  18.     Asm
  19.         mov eax, w
  20.         mov edx, h
  21.         mov r8d, cosA
  22.         mov r9d, sinA
  23.         mov xmm1, zoom_inv
  24.  
  25.         ; Iterate over the destination image pixels
  26.         xor rdi, rdi ; rdi = y
  27.         @loopY:
  28.         xor rbx, rbx ; rbx = x
  29.         @loopX:
  30.  
  31.         ; Calculate the source pixel coordinates
  32.         mov rcx, rbx
  33.         mov r10, rax
  34.         mov r11, xmm1
  35.         mul r10
  36.         sub rcx, rdi
  37.         mov r10d, r9d
  38.         mul r10d
  39.         mov tx, rcx
  40.  
  41.         mov rcx, rbx
  42.         mov r10, rdi
  43.         mul r11
  44.         mov r10d, r8d
  45.         sub rcx, r10d
  46.         mov r10d, r9d
  47.         mul r10d
  48.         mov ty, rcx
  49.  
  50.         ; Check if the source pixel coordinates are inside the bounds of the source image
  51.         cmp tx, eax
  52.         jae @continue
  53.         cmp ty, edx
  54.         jae @continue
  55.         ; Get the color of the source pixel and assign it to the destination pixel
  56.         mov r8d, tx
  57.         mov r9d, ty
  58.         mov eax, src(r8d, r9d)
  59.         mov dest(rbx, rdi), eax
  60.         jmp @end
  61.         @continue:
  62.         ; Assign a transparent color to the destination pixel
  63.         mov dest(rbx, rdi), -1
  64.         @end:
  65.         ; Next pixel
  66.         inc rbx
  67.         cmp rbx, rax
  68.         jl @loopX
  69.         inc rdi
  70.         cmp rdi, rdx
  71.         jl @loopY
  72.     End Asm
  73.     ' The result image is stored in dest()
  74. End Sub
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement