Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Weird behavior when displaying buffer #52

Open
RapierXbox opened this issue Jul 4, 2024 · 0 comments
Open

Weird behavior when displaying buffer #52

RapierXbox opened this issue Jul 4, 2024 · 0 comments

Comments

@RapierXbox
Copy link

RapierXbox commented Jul 4, 2024

I am trying to display a GIF that I converted to binary on my 128x32 OLED display. I am converting the GIF to raw bytes using this Python script. Each 512-byte sector in the file represents a frame. Here is my Python function:

    frames = []

    for frame in ImageSequence.Iterator(img):
        frame = frame.convert('1')

        original_width, original_height = frame.size
        aspect_ratio = original_width / original_height

        if aspect_ratio < (128 / 32):
            new_width = 128
            new_height = int(128 / aspect_ratio)
        else:
            new_height = 32
            new_width = int(32 * aspect_ratio)

        resized_frame = frame.resize((new_width, new_height), PIL.Image.LANCZOS)

        new_image = Image.new('1', (128, 32), color=1)

        paste_x = (128 - new_width) // 2
        paste_y = (32 - new_height) // 2

        new_image.paste(resized_frame, (paste_x, paste_y))

        frames.append(new_image)

    return frames

def RawToFrame(raw):
    data = []
    for byte in raw:
        data.extend([int(bit) for bit in f'{byte:08b}'])

    data = data[:128 * 32]

    frame = Image.new('1', (128, 32))
    frame.putdata(data)

    return frame

def GifToRaw(img, out_name):
    frames = GIFtoFrame(Image.open(img))
    raw = []
    for frame in frames:
        raw.extend(frame.tobytes())
    file = open(out_name + ".oled", 'wb')
    file.write(bytearray(raw))
    file.close()

After converting, I revert the raw file back to a GIF to verify its correctness, and it works fine. Here is my Arduino code:

for (size_t i = 0; i < oledfilepaths.size(); ++i) {
    String oledfilename = oledfilepaths[i].c_str();
    Serial.println("Opening: " + oledfilename);
    int frames = 0;
    int frame = 0;
    File oledfile = SD.open("/oled/" + oledfilename);
    frames = oledfile.size() / 512;
    for (frame; frame < frames; frame++) {
      uint8_t framedata[512];
      int readfile = oledfile.read(framedata, 512);
      obdDumpBuffer(&obd, framedata);
      delay(100);
    }
    oledfile.close();
  }

However, when displayed on the OLED, it comes out like this:
IMG_4759
This is the preview generated with Python:
testgif
Maybe the buffer is stored in a strange way, or perhaps I'm just not understanding it correctly.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant