<commit_before>#include "simply_res.h"

#include "util/window.h"

#include <pebble.h>

static bool id_filter(List1Node *node, void *data) {
  return (((SimplyImage*) node)->id == (uint32_t)(uintptr_t) data);
}

static void destroy_image(SimplyRes *self, SimplyImage *image) {
  list1_remove(&self->images, &image->node);
  free(image->bitmap.addr);
  free(image);
}

GBitmap *simply_res_add_bundled_image(SimplyRes *self, uint32_t id) {
  SimplyImage *image = malloc(sizeof(*image));
  if (!image) {
    return NULL;
  }

  GBitmap *bitmap = gbitmap_create_with_resource(id);
  if (!bitmap) {
    free(image);
    return NULL;
  }

  image->bitmap = *bitmap;
  free(bitmap);

  window_stack_schedule_top_window_render();

  return &image->bitmap;
}

GBitmap *simply_res_add_image(SimplyRes *self, uint32_t id, int16_t width, int16_t height, uint32_t *pixels) {
  SimplyImage *image = (SimplyImage*) list1_find(self->images, id_filter, (void*)(uintptr_t) id);
  if (image) {
    free(image->bitmap.addr);
    image->bitmap.addr = NULL;<commit_msg>Add simply res bundled images to image cache on load<commit_after>#include "simply_res.h"

#include "util/window.h"

#include <pebble.h>

static bool id_filter(List1Node *node, void *data) {
  return (((SimplyImage*) node)->id == (uint32_t)(uintptr_t) data);
}

static void destroy_image(SimplyRes *self, SimplyImage *image) {
  list1_remove(&self->images, &image->node);
  free(image->bitmap.addr);
  free(image);
}

GBitmap *simply_res_add_bundled_image(SimplyRes *self, uint32_t id) {
  SimplyImage *image = malloc(sizeof(*image));
  if (!image) {
    return NULL;
  }

  GBitmap *bitmap = gbitmap_create_with_resource(id);
  if (!bitmap) {
    free(image);
    return NULL;
  }

  *image = (SimplyImage) {
    .id = id,
    .bitmap = *bitmap,
  };

  list1_prepend(&self->images, &image->node);

  window_stack_schedule_top_window_render();

  return &image->bitmap;
}

GBitmap *simply_res_add_image(SimplyRes *self, uint32_t id, int16_t width, int16_t height, uint32_t *pixels) {
  SimplyImage *image = (SimplyImage*) list1_find(self->images, id_filter, (void*)(uintptr_t) id);
  if (image) {
    free(image->bitmap.addr);
    image->bitmap.addr = NULL;
{'fraction_non_alphanumeric': 0.14882032667876588, 'fraction_numerical': 0.014065335753176044, 'mean_word_length': 4.88, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 24, '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': '626855', 'n_tokens_mistral': 841, 'n_tokens_neox': 840, 'n_words': 165}