Jetmapping

Image position & Offset Calculation


In [103]:
def calc_pos_off(wrap_mode=True, bits_per_pixel=2, g_RAM_FRAME_SIZE=256, image_base_x_offset=4, wrap_begin=3, wrap_end=200, loop=100):
  if bits_per_pixel == 1:
    pixel_per_byte = 8
  elif bits_per_pixel == 2:
    pixel_per_byte = 4
  elif bits_per_pixel == 4:
    pixel_per_byte = 2
  image_offset_x = image_base_x_offset * pixel_per_byte
  x_position     = 0
  wrap_counter   = 0
  print("---------------------------------")
  print("   i |  x_pos | img_off | wrp_cnt   - Wrapmode {} - {}Bits/Pixel - {}Pixel/Byte".format(wrap_mode, bits_per_pixel, pixel_per_byte))
  print("-----|--------|---------|--------")
  for i in range(loop):  # Calculate me the next x position
    # Print stuff
    print("{:4} | {:6} | {:7} | {:7}".format(i, x_position, image_offset_x, wrap_counter))
    # Do calculations each loop
    if (bits_per_pixel == 1):    # 8 Pixel/Byte
      if wrap_mode and (x_position + (g_RAM_FRAME_SIZE/1)  > (wrap_end)):
        image_offset_x = (image_base_x_offset*pixel_per_byte) + x_position + (g_RAM_FRAME_SIZE/1) - wrap_end + wrap_begin
        x_position = x_position + (g_RAM_FRAME_SIZE/1) - wrap_end + wrap_begin
        wrap_counter = wrap_counter + 1
      else:
        x_position = x_position + (g_RAM_FRAME_SIZE/1)
        image_offset_x = (image_base_x_offset*pixel_per_byte) + x_position + (g_RAM_FRAME_SIZE/1)
    elif (bits_per_pixel == 2):  # 4 Pixel/Byte
      if wrap_mode and (x_position + (g_RAM_FRAME_SIZE/2)  > (wrap_end)):
        image_offset_x = (image_base_x_offset*pixel_per_byte) + x_position + (g_RAM_FRAME_SIZE/2) - wrap_end + wrap_begin
        x_position = x_position + (g_RAM_FRAME_SIZE/2) - wrap_end + wrap_begin
        wrap_counter = wrap_counter + 1
      else:
        x_position = x_position + (g_RAM_FRAME_SIZE/2)
        image_offset_x = (image_base_x_offset*pixel_per_byte) + x_position + (g_RAM_FRAME_SIZE/2)
    else:                       # 2 Pixel/Byte
      if wrap_mode and (x_position + (g_RAM_FRAME_SIZE/4)  > (wrap_end)):
        image_offset_x = (image_base_x_offset*pixel_per_byte) + x_position + (g_RAM_FRAME_SIZE/4) - wrap_end + wrap_begin
        x_position = x_position + (g_RAM_FRAME_SIZE/4) - wrap_end + wrap_begin
        wrap_counter = wrap_counter + 1
      else:
        x_position = x_position + (g_RAM_FRAME_SIZE/4)
        image_offset_x = (image_base_x_offset*pixel_per_byte) + x_position + (g_RAM_FRAME_SIZE/4)

In [104]:
g_RAM_FRAME_SIZE = 256
image_base_x_offset = 4
loop = 10
wrap_begin = 10
wrap_end   = 200

calc_pos_off(False, 4, g_RAM_FRAME_SIZE, image_base_x_offset, wrap_begin, wrap_end, loop)
calc_pos_off(True, 4, g_RAM_FRAME_SIZE, image_base_x_offset, wrap_begin, wrap_end, loop)
calc_pos_off(False, 2, g_RAM_FRAME_SIZE, image_base_x_offset, wrap_begin, wrap_end, loop)
calc_pos_off(True, 2, g_RAM_FRAME_SIZE, image_base_x_offset, wrap_begin, wrap_end, loop)
calc_pos_off(False, 1, g_RAM_FRAME_SIZE, image_base_x_offset, wrap_begin, wrap_end, loop)
calc_pos_off(True, 1, g_RAM_FRAME_SIZE, image_base_x_offset, wrap_begin, wrap_end, loop)


---------------------------------
   i |  x_pos | img_off | wrp_cnt   - Wrapmode False - 4Bits/Pixel - 2Pixel/Byte
-----|--------|---------|--------
   0 |      0 |       8 |       0
   1 |     64 |     136 |       0
   2 |    128 |     200 |       0
   3 |    192 |     264 |       0
   4 |    256 |     328 |       0
   5 |    320 |     392 |       0
   6 |    384 |     456 |       0
   7 |    448 |     520 |       0
   8 |    512 |     584 |       0
   9 |    576 |     648 |       0
---------------------------------
   i |  x_pos | img_off | wrp_cnt   - Wrapmode True - 4Bits/Pixel - 2Pixel/Byte
-----|--------|---------|--------
   0 |      0 |       8 |       0
   1 |     64 |     136 |       0
   2 |    128 |     200 |       0
   3 |    192 |     264 |       0
   4 |     66 |      74 |       1
   5 |    130 |     202 |       1
   6 |    194 |     266 |       1
   7 |     68 |      76 |       2
   8 |    132 |     204 |       2
   9 |    196 |     268 |       2
---------------------------------
   i |  x_pos | img_off | wrp_cnt   - Wrapmode False - 2Bits/Pixel - 4Pixel/Byte
-----|--------|---------|--------
   0 |      0 |      16 |       0
   1 |    128 |     272 |       0
   2 |    256 |     400 |       0
   3 |    384 |     528 |       0
   4 |    512 |     656 |       0
   5 |    640 |     784 |       0
   6 |    768 |     912 |       0
   7 |    896 |    1040 |       0
   8 |   1024 |    1168 |       0
   9 |   1152 |    1296 |       0
---------------------------------
   i |  x_pos | img_off | wrp_cnt   - Wrapmode True - 2Bits/Pixel - 4Pixel/Byte
-----|--------|---------|--------
   0 |      0 |      16 |       0
   1 |    128 |     272 |       0
   2 |     66 |      82 |       1
   3 |    194 |     338 |       1
   4 |    132 |     148 |       2
   5 |     70 |      86 |       3
   6 |    198 |     342 |       3
   7 |    136 |     152 |       4
   8 |     74 |      90 |       5
   9 |     12 |      28 |       6
---------------------------------
   i |  x_pos | img_off | wrp_cnt   - Wrapmode False - 1Bits/Pixel - 8Pixel/Byte
-----|--------|---------|--------
   0 |      0 |      32 |       0
   1 |    256 |     544 |       0
   2 |    512 |     800 |       0
   3 |    768 |    1056 |       0
   4 |   1024 |    1312 |       0
   5 |   1280 |    1568 |       0
   6 |   1536 |    1824 |       0
   7 |   1792 |    2080 |       0
   8 |   2048 |    2336 |       0
   9 |   2304 |    2592 |       0
---------------------------------
   i |  x_pos | img_off | wrp_cnt   - Wrapmode True - 1Bits/Pixel - 8Pixel/Byte
-----|--------|---------|--------
   0 |      0 |      32 |       0
   1 |     66 |      98 |       1
   2 |    132 |     164 |       2
   3 |    198 |     230 |       3
   4 |    264 |     296 |       4
   5 |    330 |     362 |       5
   6 |    396 |     428 |       6
   7 |    462 |     494 |       7
   8 |    528 |     560 |       8
   9 |    594 |     626 |       9

Offset Calculation

Reverse print direction


In [102]:
def calc_off(bits_per_pixel=2, g_RAM_FRAME_SIZE=256, image_base_x_offset=4, loop=100):
  if bits_per_pixel == 1:
    pixel_per_byte = 8
  elif bits_per_pixel == 2:
    pixel_per_byte = 4
  elif bits_per_pixel == 4:
    pixel_per_byte = 2
  image_offset_x   = image_base_x_offset * pixel_per_byte
  x_position       = 0
  print("--------------")
  print("   i | img_off    - {}Bits/Pixel - {}Pixel/Byte".format(bits_per_pixel, pixel_per_byte))
  print("-----|--------")
  for i in range(loop):  # Calculate me the next x position
    # Print stuff
    print("{:4} | {:6}".format(i, image_offset_x))
    # Do calculations each loop
    if (bits_per_pixel == 1):   # 8 Pixel/Byte
      image_offset_x <= image_offset_x - g_RAM_FRAME_SIZE/1
    elif (bits_per_pixel == 2): # 4 Pixel/Byte
      image_offset_x <= image_offset_x - g_RAM_FRAME_SIZE/2
    else:                       # 2 Pixel/Byte
      image_offset_x <= image_offset_x - g_RAM_FRAME_SIZE/4


  File "<ipython-input-102-8e710a04aac0>", line 4
    if bits_per_pixel == 2:
                           ^
IndentationError: unindent does not match any outer indentation level

In [ ]:
g_RAM_FRAME_SIZE = 256
image_base_x_offset = 4
loop = 10

wrap_begin = 10
wrap_end   = 200
calc_pos_off(False, 2, g_RAM_FRAME_SIZE, image_base_x_offset, wrap_begin, wrap_end, loop)
calc_pos_off(True, 2, g_RAM_FRAME_SIZE, image_base_x_offset, wrap_begin, wrap_end, loop)
calc_pos_off(False, 4, g_RAM_FRAME_SIZE, image_base_x_offset, wrap_begin, wrap_end, loop)
calc_pos_off(True, 4, g_RAM_FRAME_SIZE, image_base_x_offset, wrap_begin, wrap_end, loop)
calc_pos_off(False, 8, g_RAM_FRAME_SIZE, image_base_x_offset, wrap_begin, wrap_end, loop)
calc_pos_off(True, 8, g_RAM_FRAME_SIZE, image_base_x_offset, wrap_begin, wrap_end, loop)