<commit_before>#!/usr/bin/env python
# -*- coding: utf-8 -*-

from libavg import app, avg
from PIL import Image

# Demonstrates interoperability with pillow (https://pillow.readthedocs.org/index.html)

class MyMainDiv(app.MainDiv):
    def onInit(self):
        self.toggleTouchVisualization()
        bmp = avg.Bitmap("rgb24-64x64.png")
        pixels = bmp.getPixels(False)
        image = Image.frombytes("RGBA", (64,64), pixels)
        # Need to swap red and blue.
        b,g,r,a = image.split()
        image = Image.merge("RGBA", (r,g,b,a))

        image.save("foo.jpg")

    def onExit(self):
        pass

    def onFrame(self):
        pass

app.App().run(MyMainDiv())


<commit_msg>Added bmp.setPixels() call to pillow sample (implements #711).<commit_after>#!/usr/bin/env python
# -*- coding: utf-8 -*-

from libavg import app, avg
from PIL import Image

# Demonstrates interoperability with pillow (https://pillow.readthedocs.org/index.html)

class MyMainDiv(app.MainDiv):
    def onInit(self):
        self.toggleTouchVisualization()
        bmp = avg.Bitmap("rgb24-64x64.png")
        pixels = bmp.getPixels(False)
        image = Image.frombytes("RGBA", (64,64), pixels)
        # Need to swap red and blue.
        b,g,r,a = image.split()
        image = Image.merge("RGBA", (r,g,b,a))

        image.save("foo.jpg")
        bmp.setPixels(image.tobytes())
        node = avg.ImageNode(parent=self)
        node.setBitmap(bmp)

    def onExit(self):
        pass

    def onFrame(self):
        pass

app.App().run(MyMainDiv())



{'fraction_non_alphanumeric': 0.14534883720930233, 'fraction_numerical': 0.01614987080103359, 'mean_word_length': 2.679334916864608, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 2, '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': '7210283', 'n_tokens_mistral': 562, 'n_tokens_neox': 537, 'n_words': 111}