####################################################
# ArtiLED Python Screen Library v1.03 (22-02-2026) #
# Written by: Michel van Osenbruggen               #
# Copyright 2026 ArtiLED B.V. All Rights Reserved  #
####################################################

import numpy as np

##################
# LEFT AND RIGHT #
##################

#Get Left Half of Screen
def left_half(img_arr):
    cols = img_arr.shape[1]
    left_arr = img_arr[:, :cols//2]
    return left_arr

#Get Right Half of Screen
def right_half(img_arr):
    cols = img_arr.shape[1]
    right_arr = img_arr[:, cols//2:]
    return right_arr

#Get Left and Right Half of Screen
def left_and_right_half(img_arr):
    cols = img_arr.shape[1]
    left_arr = img_arr[:, :cols//2]
    right_arr = img_arr[:, cols//2:]
    return left_arr, right_arr

#Get Left Third of Screen
def left_third(img_arr):
    cols = img_arr.shape[1]
    third = cols//3
    left_arr = img_arr[:, :third]
    return left_arr

#Get Right Third of Screen
def right_third(img_arr):
    cols = img_arr.shape[1]
    third = cols//3
    right_arr = img_arr[:, 2*third:]
    return right_arr

#Get Center Third of Screen
def center_third(img_arr):
    cols = img_arr.shape[1]
    center_arr = img_arr[:, cols//3:2*cols//3]
    return center_arr

#Get Left Center Right Third of Screen
def left_center_right_third(img_arr):
    cols = img_arr.shape[1]
    left_arr = img_arr[:, :cols//3]
    center_arr = img_arr[:, cols//3:2*cols//3]
    right_arr = img_arr[:, 2*cols//3:]
    return left_arr, center_arr, right_arr

#Get Left and Right Third of Screen
def left_and_right_third(img_arr):
    cols = img_arr.shape[1]
    third = cols//3
    left_arr = img_arr[:, :third]
    right_arr = img_arr[:, 2*third:]
    return left_arr, right_arr

#Get Left and Right Two Third of Screen
def left_and_right_two_third(img_arr):
    cols = img_arr.shape[1]
    left_arr = img_arr[:, :2*cols//3]
    right_arr = img_arr[:, cols//3:]
    return left_arr, right_arr

# Get Left Quarter of Screen
def left_quarter(img_arr):
    cols = img_arr.shape[1]
    quarter = cols // 4
    left_arr = img_arr[:, :quarter]
    return left_arr

# Get Right Quarter of Screen
def right_quarter(img_arr):
    cols = img_arr.shape[1]
    quarter = cols // 4
    right_arr = img_arr[:, 3*quarter:]
    return right_arr

# Get Left-Center Quarter of Screen
def left_center_quarter(img_arr):
    cols = img_arr.shape[1]
    quarter = cols // 4
    left_center_arr = img_arr[:, quarter:2*quarter]
    return left_center_arr

# Get Right-Center Quarter of Screen
def right_center_quarter(img_arr):
    cols = img_arr.shape[1]
    quarter = cols // 4
    right_center_arr = img_arr[:, 2*quarter:3*quarter]
    return right_center_arr

# Get all Quarters of Screen
def all_quarters(img_arr):
    cols = img_arr.shape[1]
    quarter = cols // 4
    left_arr = img_arr[:, :quarter]
    left_center_arr = img_arr[:, quarter:2*quarter]
    right_center_arr = img_arr[:, 2*quarter:3*quarter]
    right_arr = img_arr[:, 3*quarter:]
    return left_arr, left_center_arr, right_center_arr, right_arr

# Get Left and Right Quarters
def left_and_right_quarter(img_arr):
    cols = img_arr.shape[1]
    quarter = cols // 4
    left_arr = img_arr[:, :quarter]
    right_arr = img_arr[:, 3*quarter:]
    return left_arr, right_arr

# Get Left Fifth of Screen
def left_fifth(img_arr):
    cols = img_arr.shape[1]
    fifth = cols // 5
    left_arr = img_arr[:, :fifth]
    return left_arr

# Get Second Fifth of Screen
def second_fifth(img_arr):
    cols = img_arr.shape[1]
    fifth = cols // 5
    second_arr = img_arr[:, fifth:2*fifth]
    return second_arr

# Get Center Fifth of Screen
def center_fifth(img_arr):
    cols = img_arr.shape[1]
    fifth = cols // 5
    middle_arr = img_arr[:, 2*fifth:3*fifth]
    return middle_arr

# Get Fourth Fifth of Screen
def fourth_fifth(img_arr):
    cols = img_arr.shape[1]
    fifth = cols // 5
    fourth_arr = img_arr[:, 3*fifth:4*fifth]
    return fourth_arr

# Get Right Fifth of Screen
def right_fifth(img_arr):
    cols = img_arr.shape[1]
    fifth = cols // 5
    right_arr = img_arr[:, 4*fifth:]
    return right_arr

# Get all Fifths of Screen
def all_fifths(img_arr):
    cols = img_arr.shape[1]
    fifth = cols // 5
    left_arr = img_arr[:, :fifth]
    second_arr = img_arr[:, fifth:2*fifth]
    center_arr = img_arr[:, 2*fifth:3*fifth]
    fourth_arr = img_arr[:, 3*fifth:4*fifth]
    right_arr = img_arr[:, 4*fifth:]
    return left_arr, second_arr, center_arr, fourth_arr, right_arr

# Get Left and Right Fifth
def left_and_right_fifth(img_arr):
    cols = img_arr.shape[1]
    fifth = cols // 5
    left_fifth = img_arr[:, :fifth]
    right_fifth = img_arr[:, 4*fifth:]
    return left_fifth, right_fifth

###################
# UPPER AND LOWER #
###################

#Get Upper Half of Screen
def upper_half(img_arr):
    rows = img_arr.shape[0]
    upper_arr = img_arr[:rows//2, :]
    return upper_arr

#Get Lower Half of Screen
def lower_half(img_arr):
    rows = img_arr.shape[0]
    lower_arr = img_arr[rows//2:, :]
    return lower_arr

#Get Upper and Lower Half of Screen
def upper_and_lower_half(img_arr):
    rows = img_arr.shape[0]
    upper_arr = img_arr[:rows//2, :]
    lower_arr = img_arr[rows//2:, :]
    return upper_arr, lower_arr

#Get Upper Third of Screen
def upper_third(img_arr):
    rows = img_arr.shape[0]
    third_rows = int(rows / 3)
    upper_arr = img_arr[:third_rows, :]
    return upper_arr

#Get Lower Third of Screen
def lower_third(img_arr):
    rows = img_arr.shape[0]
    third_rows = int(rows / 3)
    lower_arr = img_arr[third_rows:, :]
    return lower_arr

#Get Upper Two Third of Screen
def upper_two_third(img_arr):
    rows = img_arr.shape[0]
    two_thirds_rows = int(rows * (2/3))
    upper_arr = img_arr[:two_thirds_rows, :]
    return upper_arr

#Get Lower Two Third of Screen
def lower_two_third(img_arr):
    rows = img_arr.shape[0]
    two_thirds_rows = int(rows * (2/3))
    lower_arr = img_arr[two_thirds_rows:, :]
    return lower_arr

#Get Upper and Lower Third of Screen
def upper_and_lower_third(img_arr):
    rows = img_arr.shape[0]
    third_rows = int(rows / 3)
    upper_arr = img_arr[:third_rows, :]
    lower_arr = img_arr[third_rows:, :]
    return upper_arr, lower_arr

#Get Upper and Lower Two Third of Screen
def upper_and_lower_two_third(img_arr):
    rows = img_arr.shape[0]
    two_thirds_rows = int(rows * (2/3))
    upper_arr = img_arr[:two_thirds_rows, :]
    lower_arr = img_arr[two_thirds_rows:, :]
    return upper_arr, lower_arr

#Get Upper Middle Lower Third of Screen
def upper_middle_lower_third(img_arr):
    rows = img_arr.shape[0]
    upper_arr = img_arr[:rows//3, :]
    middle_arr = img_arr[rows//3:2*rows//3, :]
    lower_arr = img_arr[2*rows//3:, :]
    return upper_arr, middle_arr, lower_arr

# Get Upper Quarter of Screen
def upper_quarter(img_arr):
    rows = img_arr.shape[0]
    quarter_rows = int(rows / 4)
    upper_arr = img_arr[:quarter_rows, :]
    return upper_arr

# Get Lower Quarter of Screen
def lower_quarter(img_arr):
    rows = img_arr.shape[0]
    quarter_rows = int(rows / 4)
    lower_arr = img_arr[3*quarter_rows:, :]
    return lower_arr

# Get Upper Middle Quarter of Screen
def upper_middle_quarter(img_arr):
    rows = img_arr.shape[0]
    quarter_rows = int(rows / 4)
    upper_middle_arr = img_arr[quarter_rows:2*quarter_rows, :]
    return upper_middle_arr

# Get Lower-Middle Quarter of Screen
def lower_middle_quarter(img_arr):
    rows = img_arr.shape[0]
    quarter_rows = int(rows / 4)
    lower_middle_arr = img_arr[2*quarter_rows:3*quarter_rows, :]
    return lower_middle_arr

# Get Upper and Lower Quarters
def upper_and_lower_quarter(img_arr):
    rows = img_arr.shape[0]
    quarter_rows = int(rows / 4)
    upper_arr = img_arr[:quarter_rows, :]
    lower_arr = img_arr[3*quarter_rows:, :]
    return upper_arr, lower_arr

# Get Upper Fifth of Screen
def upper_fifth(img_arr):
    rows = img_arr.shape[0]
    fifth_rows = int(rows / 5)
    upper_arr = img_arr[:fifth_rows, :]
    return upper_arr

# Get Upper Second Fifth of Screen
def upper_second_fifth(img_arr):
    rows = img_arr.shape[0]
    fifth_rows = int(rows / 5)
    upper_second_arr = img_arr[fifth_rows:2*fifth_rows, :]
    return upper_second_arr

# Get Middle Fifth of Screen
def middle_fifth(img_arr):
    rows = img_arr.shape[0]
    fifth_rows = int(rows / 5)
    middle_arr = img_arr[2*fifth_rows:3*fifth_rows, :]
    return middle_arr

# Get Lower Fourth Fifth of Screen
def lower_fourth_fifth(img_arr):
    rows = img_arr.shape[0]
    fifth_rows = int(rows / 5)
    lower_fourth_arr = img_arr[3*fifth_rows:4*fifth_rows, :]
    return lower_fourth_arr

# Get Lower Fifth of Screen
def lower_fifth(img_arr):
    rows = img_arr.shape[0]
    fifth_rows = int(rows / 5)
    lower_arr = img_arr[4*fifth_rows:, :]
    return lower_arr

# Get Upper and Lower Fifths
def upper_and_lower_fifth(img_arr):
    rows = img_arr.shape[0]
    fifth_rows = int(rows / 5)
    upper_arr = img_arr[:fifth_rows, :]
    lower_arr = img_arr[4*fifth_rows:, :]
    return upper_arr, lower_arr

# Get all Vertical Fifths of Screen
def all_vertical_fifths(img_arr):
    rows = img_arr.shape[0]
    fifth_rows = int(rows / 5)
    upper_arr = img_arr[:fifth_rows, :]
    second_arr = img_arr[fifth_rows:2*fifth_rows, :]
    middle_arr = img_arr[2*fifth_rows:3*fifth_rows, :]
    fourth_arr = img_arr[3*fifth_rows:4*fifth_rows, :]
    lower_arr = img_arr[4*fifth_rows:, :]
    return upper_arr, second_arr, middle_arr, fourth_arr, lower_arr

#############
# ALL PARTS #
#############

#Get Four Parts of Screen
def all_parts_half(img_arr):
    rows = img_arr.shape[0]
    cols = img_arr.shape[1]
    upper_left = img_arr[:rows//2, :cols//2]
    upper_right = img_arr[:rows//2, cols//2:]
    lower_left = img_arr[rows//2:, :cols//2]
    lower_right = img_arr[rows//2:, cols//2:]
    return upper_left, upper_right, lower_left, lower_right

#Get Nine Parts of Screen
def all_parts_thirds(img_arr):
    rows = img_arr.shape[0]
    cols = img_arr.shape[1]
    upper_left = img_arr[:rows//3, :cols//3]
    upper_center = img_arr[:rows//3, cols//3:2*cols//3]
    upper_right = img_arr[:rows//3, 2*cols//3:]
    middle_left = img_arr[rows//3:2*rows//3, :cols//3]
    middle_center = img_arr[rows//3:2*rows//3, cols//3:2*cols//3]
    middle_right = img_arr[rows//3:2*rows//3, 2*cols//3:]
    lower_left = img_arr[2*rows//3:, :cols//3]
    lower_center = img_arr[2*rows//3:, cols//3:2*cols//3]
    lower_right = img_arr[2*rows//3:, 2*cols//3:]
    return upper_left, upper_center, upper_right, middle_left, middle_center, middle_right, lower_left, lower_center, lower_right

def all_parts_quarters(img_arr):
    rows = img_arr.shape[0]
    cols = img_arr.shape[1]
    upper_left = img_arr[:rows//4, :cols//4]
    upper_center_left = img_arr[:rows//4, cols//4:2*cols//4]
    upper_center_right = img_arr[:rows//4, 2*cols//4:3*cols//4]
    upper_right = img_arr[:rows//4, 3*cols//4:]
    middle_left = img_arr[rows//4:2*rows//4, :cols//4]
    middle_center_left = img_arr[rows//4:2*rows//4, cols//4:2*cols//4]
    middle_center_right = img_arr[rows//4:2*rows//4, 2*cols//4:3*cols//4]
    middle_right = img_arr[rows//4:2*rows//4, 3*cols//4:]
    lower_left = img_arr[2*rows//4:3*rows//4, :cols//4]
    lower_center_left = img_arr[2*rows//4:3*rows//4, cols//4:2*cols//4]
    lower_center_right = img_arr[2*rows//4:3*rows//4, 2*cols//4:3*cols//4]
    lower_right = img_arr[2*rows//4:3*rows//4, 3*cols//4:]
    bottom_left = img_arr[3*rows//4:, :cols//4]
    bottom_center_left = img_arr[3*rows//4:, cols//4:2*cols//4]
    bottom_center_right = img_arr[3*rows//4:, 2*cols//4:3*cols//4]
    bottom_right = img_arr[3*rows//4:, 3*cols//4:]
    return upper_left, upper_center_left, upper_center_right, upper_right, middle_left, middle_center_left, middle_center_right, middle_right, lower_left, lower_center_left, lower_center_right, lower_right, bottom_left, bottom_center_left, bottom_center_right, bottom_right

def all_parts_fifths(img_arr):
    rows = img_arr.shape[0]
    cols = img_arr.shape[1]

    r1, r2, r3, r4 = rows//5, 2*rows//5, 3*rows//5, 4*rows//5
    c1, c2, c3, c4 = cols//5, 2*cols//5, 3*cols//5, 4*cols//5

    upper_left = img_arr[:r1, :c1]
    upper_center_left = img_arr[:r1, c1:c2]
    upper_center = img_arr[:r1, c2:c3]
    upper_center_right = img_arr[:r1, c3:c4]
    upper_right = img_arr[:r1, c4:]

    middle_upper_left = img_arr[r1:r2, :c1]
    middle_upper_center_left = img_arr[r1:r2, c1:c2]
    middle_upper_center = img_arr[r1:r2, c2:c3]
    middle_upper_center_right = img_arr[r1:r2, c3:c4]
    middle_upper_right = img_arr[r1:r2, c4:]

    center_left = img_arr[r2:r3, :c1]
    center_center_left = img_arr[r2:r3, c1:c2]
    center = img_arr[r2:r3, c2:c3]
    center_center_right = img_arr[r2:r3, c3:c4]
    center_right = img_arr[r2:r3, c4:]

    middle_lower_left = img_arr[r3:r4, :c1]
    middle_lower_center_left = img_arr[r3:r4, c1:c2]
    middle_lower_center = img_arr[r3:r4, c2:c3]
    middle_lower_center_right = img_arr[r3:r4, c3:c4]
    middle_lower_right = img_arr[r3:r4, c4:]

    lower_left = img_arr[r4:, :c1]
    lower_center_left = img_arr[r4:, c1:c2]
    lower_center = img_arr[r4:, c2:c3]
    lower_center_right = img_arr[r4:, c3:c4]
    lower_right = img_arr[r4:, c4:]

    return upper_left, upper_center_left, upper_center, upper_center_right, upper_right, middle_upper_left, middle_upper_center_left, middle_upper_center, middle_upper_center_right, middle_upper_right, center_left, center_center_left, center, center_center_right, center_right, middle_lower_left, middle_lower_center_left, middle_lower_center, middle_lower_center_right, middle_lower_right, lower_left, lower_center_left, lower_center, lower_center_right, lower_right

########
# FLIP #
########

def flip_x(img_arr):
    img_arr = np.fliplr(img_arr)
    return img_arr

def flip_y(img_arr):
    img_arr = np.flipud(img_arr)
    return img_arr

def flip_xy(img_arr):
    img_arr = np.flipud(np.fliplr(img_arr))
    return img_arr

