| 1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980 |
- #
- # Copyright 2026 Aarav Ravindra Kharade
- #
- # Licensed under the Apache License, Version 2.0 (the "License");
- # you may not use this file except in compliance with the License.
- # You may obtain a copy of the License at
- #
- # http://www.apache.org/licenses/LICENSE-2.0
- #
- # Unless required by applicable law or agreed to in writing, software
- # distributed under the License is distributed on an "AS IS" BASIS,
- # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- # See the License for the specific language governing permissions and
- # limitations under the License.
- #
- import struct
- import sys
- import os
- def convert_cur(cur_path, c_path):
- if not os.path.exists(cur_path):
- os.system("unzip -o 'arkrt/ArkGraphics/mousecursorpack.zip' -d /tmp/")
- cur_path = "/tmp/" + os.path.basename(cur_path)
- with open(cur_path, 'rb') as f:
- data = f.read()
- # Parse CUR header
- zero, type_, count = struct.unpack('<HHH', data[:6])
- if type_ != 2:
- print("Not a CUR file")
- return
- width, height, colors, res, hot_x, hot_y, size, offset = struct.unpack('<BBBBHHII', data[6:22])
- if width == 0: width = 256
- if height == 0: height = 256
-
- dib_size, w, h, planes, bpp, comp, img_size = struct.unpack('<IIIHHII', data[offset:offset+24])
- print(f"Found cursor: {w}x{h//2}, {bpp}bpp, Hotspot: {hot_x},{hot_y}")
-
- real_h = h // 2
- if bpp != 32:
- print("Only 32bpp cursors are supported!")
- return
-
- pixel_offset = offset + dib_size
- pixels = data[pixel_offset : pixel_offset + (w * real_h * 4)]
-
- row_bytes = w * 4
- rows = []
- for i in range(real_h):
- start = i * row_bytes
- rows.append(pixels[start:start+row_bytes])
-
- rows.reverse()
-
- out = f"// Auto-generated from {cur_path}\n"
- out += f"let cursorWidth = {w}\n"
- out += f"let cursorHeight = {real_h}\n"
- out += f"let cursorHotX = {hot_x}\n"
- out += f"let cursorHotY = {hot_y}\n"
-
- out += "let cursorData: [UInt32] = [\n"
- for row in rows:
- for i in range(0, len(row), 4):
- b, g, r, a = row[i:i+4]
- # Convert to ARGB for Swift UInt32 array
- pixel = (a << 24) | (r << 16) | (g << 8) | b
- out += f"0x{pixel:08X}, "
- out += "\n"
-
- out += "]\n"
-
- with open(c_path, 'w') as f:
- f.write(out)
- print("Done!")
- if __name__ == '__main__':
- convert_cur(sys.argv[1], sys.argv[2])
|