<commit_before>﻿
_gfxRendererVars = {
  'tempImg': pygame.Surface((10, 10)),
  'events': [],
  'eventsLength': 0,
  'images': [],
  'textChars': [],
  'fontLookup': {},
  'fontCharLookupByStyle': {},
}

def gfxRendererSetData(events, eventsLength, images, textChars):
  _gfxRendererVars['events'] = events
  _gfxRendererVars['eventsLength'] = eventsLength
  _gfxRendererVars['images'] = images
  _gfxRendererVars['textChars'] = textChars

def gfxRender():
  screen = _global_vars['virtual_screen']
  tempImg = _gfxRendererVars['tempImg']
  events = _gfxRendererVars['events']
  eventsLength = _gfxRendererVars['eventsLength']
  images = _gfxRendererVars['images']
  textChars = _gfxRendererVars['textChars']
  tempImgWidth, tempImgHeight = tempImg.get_size()
  screenWidth, screenHeight = screen.get_size()

  if len(textChars) > 0:
    _gfxEnsureCharsLoaded(events, textChars)

  imageIndex = 0
  textIndex = 0
  i = 0
  while i < eventsLength:
    command = events[i]

    if command == 6:
      mask = events[i | 1]
      image = images[imageIndex][0][3]
      imageIndex += 1
      x = events[i | 8]
      y = events[i | 9]
      if mask == 0:
        # basic
        screen.blit(image, (x, y))
      elif mask == 1:
        # slice
        sx, sy, sw, sh = events[i | 2], events[i | 3], events[i | 4], events[i | 5]
        screen.blit(image, (x, y), (sx, sy, sw, sh))
      elif mask == 2:
        # stretch
        screen.blit(image, (x, y, events[i | 6], events[i | 7]))
      elif mask == 3:
        # slice and stretch
        sx, sy, sw, sh = events[i | 2], events[i | 3], events[i | 4], events[i | 5]
        screen.blit(image, (x, y, events[i | 6], events[i | 7]), (sx, sy, sw, sh))
      else:

        alpha = 255
        if (mask & 8) != 0:
          alpha = events[i | 11]

        if alpha > 0:

          w, h = image.get_size()
          if (mask & 1) != 0:
            sx, sy, sw, sh = events[i | 2], events[i | 3], events[i | 4], events[i | 5]
          else:
            sx, sy, sw, sh = 0, 0, w, h

          if (mask & 2) != 0:
            tw, th = events[i | 6], events[i | 7]
          else:
            tw, th = w, h

          if (mask & 4) != 0:
            angle = events[i | 10] / 1048576.0 * -180 / math.pi
          else:
            angle = None

          imgToBlit = None
          if angle != None:
            if mask == 4: # just rotation, not other transforms
              rotated = pygame.transform.rotate(image, angle)
              w, h = rotated.get_size()
              screen.blit(rotated, (x - w // 2, y - h // 2))
            else:
              rotatedTempImg = pygame.Surface((tw, th), pygame.SRCALPHA)
              rotatedTempImg.blit(image, (0, 0, tw, th), (sx, sy, sw, sh))
              rotated = pygame.transform.rotate(rotatedTempImg, angle)
              x -= rotated.get_width() // 2
              y -= rotated.get_height() // 2
              if alpha < 255:
                imgToBlit = rotated
              else:
                screen.blit(rotated, (x, y))
          else:
            imgToBlit = pygame.Surface((tw, th), pygame.SRCALPHA)
            imgToBlit.blit(image, (0, 0, tw, th), (sx, sy, sw, sh))

          if imgToBlit != None:
            w, h = imgToBlit.get_size()

            if w > tempImgWidth or h > tempImgHeight:
              tempImgWidth = max(tempImgWidth, w)
              tempImgHeight = max(tempImgHeight, h)
              tempImg = pygame.Surface((tempImgWidth, tempImgHeight)) # intentionally no alpha channel
            tempImg.blit(screen, (-x, -y, w, h))
            tempImg.blit(imgToBlit, (0, 0))
            tempImg.set_alpha(alpha)
            screen.blit(tempImg, (x, y, w, h), (0, 0, w, h))
    elif command < 3:
      alpha = events[i | 8]
      color = events[i | 5 : i | 8]
      area = events[i | 1: i | 5]
      if alpha == 255:
        if command == 1:
          if area[3] == 1:
            # PyGame has a bug where rectangles of height 1 do not get rendered.
            pygame.draw.line(screen, color, (area[0], area[1]), (area[0] + area[2], area[1]))
          else:
            pygame.draw.rect(screen, color, area)
        elif command == 2:
          pygame.draw.ellipse(screen, color, area)
      elif alpha > 0:
        wh = area[2:]
        t = pygame.Surface(wh) # intenionally no alpha channel
        t.blit(screen, (-area[0], -area[1]))
        if command == 1:
          t.fill(color)
        else:
          pygame.draw.ellipse(t, color, (0, 0, w[0], h[0]))
        t.set_alpha(alpha)
        screen.blit(t, area[:2])
    elif command == 4 or command == 5:

      # 4 -> triangle
      # 5 -> quad
      pts = [
        [events[i | 1], events[i | 2]],
        [events[i | 3], events[i | 4]],
        [events[i | 5], events[i | 6]]]

      if command == 4:
        rgb = events[i | 7 : i | 10]
        alpha = events[i | 10]
      else:<commit_msg>Crash when rendering ellipse in Python platform if alpha isn't 255.<commit_after>﻿
_gfxRendererVars = {
  'tempImg': pygame.Surface((10, 10)),
  'events': [],
  'eventsLength': 0,
  'images': [],
  'textChars': [],
  'fontLookup': {},
  'fontCharLookupByStyle': {},
}

def gfxRendererSetData(events, eventsLength, images, textChars):
  _gfxRendererVars['events'] = events
  _gfxRendererVars['eventsLength'] = eventsLength
  _gfxRendererVars['images'] = images
  _gfxRendererVars['textChars'] = textChars

def gfxRender():
  screen = _global_vars['virtual_screen']
  tempImg = _gfxRendererVars['tempImg']
  events = _gfxRendererVars['events']
  eventsLength = _gfxRendererVars['eventsLength']
  images = _gfxRendererVars['images']
  textChars = _gfxRendererVars['textChars']
  tempImgWidth, tempImgHeight = tempImg.get_size()
  screenWidth, screenHeight = screen.get_size()

  if len(textChars) > 0:
    _gfxEnsureCharsLoaded(events, textChars)

  imageIndex = 0
  textIndex = 0
  i = 0
  while i < eventsLength:
    command = events[i]

    if command == 6:
      mask = events[i | 1]
      image = images[imageIndex][0][3]
      imageIndex += 1
      x = events[i | 8]
      y = events[i | 9]
      if mask == 0:
        # basic
        screen.blit(image, (x, y))
      elif mask == 1:
        # slice
        sx, sy, sw, sh = events[i | 2], events[i | 3], events[i | 4], events[i | 5]
        screen.blit(image, (x, y), (sx, sy, sw, sh))
      elif mask == 2:
        # stretch
        screen.blit(image, (x, y, events[i | 6], events[i | 7]))
      elif mask == 3:
        # slice and stretch
        sx, sy, sw, sh = events[i | 2], events[i | 3], events[i | 4], events[i | 5]
        screen.blit(image, (x, y, events[i | 6], events[i | 7]), (sx, sy, sw, sh))
      else:

        alpha = 255
        if (mask & 8) != 0:
          alpha = events[i | 11]

        if alpha > 0:

          w, h = image.get_size()
          if (mask & 1) != 0:
            sx, sy, sw, sh = events[i | 2], events[i | 3], events[i | 4], events[i | 5]
          else:
            sx, sy, sw, sh = 0, 0, w, h

          if (mask & 2) != 0:
            tw, th = events[i | 6], events[i | 7]
          else:
            tw, th = w, h

          if (mask & 4) != 0:
            angle = events[i | 10] / 1048576.0 * -180 / math.pi
          else:
            angle = None

          imgToBlit = None
          if angle != None:
            if mask == 4: # just rotation, not other transforms
              rotated = pygame.transform.rotate(image, angle)
              w, h = rotated.get_size()
              screen.blit(rotated, (x - w // 2, y - h // 2))
            else:
              rotatedTempImg = pygame.Surface((tw, th), pygame.SRCALPHA)
              rotatedTempImg.blit(image, (0, 0, tw, th), (sx, sy, sw, sh))
              rotated = pygame.transform.rotate(rotatedTempImg, angle)
              x -= rotated.get_width() // 2
              y -= rotated.get_height() // 2
              if alpha < 255:
                imgToBlit = rotated
              else:
                screen.blit(rotated, (x, y))
          else:
            imgToBlit = pygame.Surface((tw, th), pygame.SRCALPHA)
            imgToBlit.blit(image, (0, 0, tw, th), (sx, sy, sw, sh))

          if imgToBlit != None:
            w, h = imgToBlit.get_size()

            if w > tempImgWidth or h > tempImgHeight:
              tempImgWidth = max(tempImgWidth, w)
              tempImgHeight = max(tempImgHeight, h)
              tempImg = pygame.Surface((tempImgWidth, tempImgHeight)) # intentionally no alpha channel
            tempImg.blit(screen, (-x, -y, w, h))
            tempImg.blit(imgToBlit, (0, 0))
            tempImg.set_alpha(alpha)
            screen.blit(tempImg, (x, y, w, h), (0, 0, w, h))
    elif command < 3:
      alpha = events[i | 8]
      color = events[i | 5 : i | 8]
      area = events[i | 1: i | 5]
      if alpha == 255:
        if command == 1:
          if area[3] == 1:
            # PyGame has a bug where rectangles of height 1 do not get rendered.
            pygame.draw.line(screen, color, (area[0], area[1]), (area[0] + area[2], area[1]))
          else:
            pygame.draw.rect(screen, color, area)
        elif command == 2:
          pygame.draw.ellipse(screen, color, area)
      elif alpha > 0:
        wh = area[2:]
        t = pygame.Surface(wh) # intenionally no alpha channel
        t.blit(screen, (-area[0], -area[1]))
        if command == 1:
          t.fill(color)
        else:
          pygame.draw.ellipse(t, color, (0, 0, area[2], area[3]))
        t.set_alpha(alpha)
        screen.blit(t, area[:2])
    elif command == 4 or command == 5:

      # 4 -> triangle
      # 5 -> quad
      pts = [
        [events[i | 1], events[i | 2]],
        [events[i | 3], events[i | 4]],
        [events[i | 5], events[i | 6]]]

      if command == 4:
        rgb = events[i | 7 : i | 10]
        alpha = events[i | 10]
      else:
{'fraction_non_alphanumeric': 0.14684886803997552, 'fraction_numerical': 0.02641240057107893, 'mean_word_length': 1.8742672919109027, 'pattern_counts': {'":': 0, '<': 9, '<?xml version=': 0, '>': 17, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '241506', 'n_tokens_mistral': 3553, 'n_tokens_neox': 3297, 'n_words': 907}