Exemplo n.º 1
0
void graphics_darken(GBitmap *bitmap) {
  static int count = 0;
  count = (count + 1) % 4;
  uint16_t row_size_bytes = gbitmap_get_bytes_per_row(bitmap);
  uint8_t *imagebuffer = gbitmap_get_data(bitmap);
  GRect bounds = gbitmap_get_bounds(bitmap);

  for (int y = bounds.origin.y; y < bounds.origin.y + bounds.size.h; y++) {
    for (int x = bounds.origin.x; x < bounds.origin.x + bounds.size.w; x++) {
      if ((x + y) % 4 == count) {
        uint8_t *line = imagebuffer + (row_size_bytes * y);
        GColor pixel = (GColor)line[x];
        if (pixel.a > 0) {
          pixel.a--;
        } else if (pixel.g >= pixel.r && pixel.g > 0) {
          pixel.g--;
        } else if (pixel.r >= pixel.b && pixel.r > 0) {
          pixel.r--;
        } else if (pixel.b > 0) {
          pixel.b--;
        }
        line[x] = pixel.argb;
      }
    }
  }
}
Exemplo n.º 2
0
static void draw_pixel(GBitmap *buffer, GPoint point, GColor color) {
    if(point.y >=0 && point.y <= 167 && point.x >= 0 && point.x <= 143) {
        uint8_t *data = gbitmap_get_data(buffer);
        uint16_t bpr = gbitmap_get_bytes_per_row(buffer);
        data[point.y * bpr + point.x] = color.argb;
    }
}
Exemplo n.º 3
0
void graphics_draw_pixel_color(GBitmap *bitmap, GPoint point, GColor color) {
  uint16_t row_size_bytes = gbitmap_get_bytes_per_row(bitmap);
  uint8_t *imagebuffer = gbitmap_get_data(bitmap);
  GRect bounds = gbitmap_get_bounds(bitmap);
  if (grect_contains_point(&bounds, &point)) {
    uint8_t *line = imagebuffer + (row_size_bytes * point.y);
    line[point.x] = color.argb;
  }
}
Exemplo n.º 4
0
void paint(void) {
    render_prep_frame();

    clear_framebuffer();

    // Get the projection matrix_t
    static fix16_t angle = 0;
    
    int delta = g_angle_z - g_angle_z_smoothed;
    if (delta > ACCEL_SMOOTH_CAP)
        delta = ACCEL_SMOOTH_CAP;
    else if (delta < -ACCEL_SMOOTH_CAP)
        delta = -ACCEL_SMOOTH_CAP;
    g_angle_z_smoothed += delta;        
    
    fix16_t pitch = (g_angle_z_smoothed * -14) - 3000;
    if (pitch < -17000) pitch = -17000;
    if (pitch >  11000) pitch = 11000;

    render_create_3d_transform(
        &g_last_transform, 
        &g_holomesh->transforms[holomesh_transform_perspective_pebble_aspect], 
        pitch,
        angle);

    angle += fix16_one >> 6;

    // Set up viewport
    viewport_t viewport;
    viewport_init(&viewport, c_viewportWidth, c_viewportHeight);

    // Transform the mesh
    render_transform_hulls_info_t t;
    t.transformed_points = g_transformed_points;

    render_transform_hulls(
        g_holomesh->hulls.ptr, 
        g_holomesh->hulls.size, 
        &viewport, 
        &g_last_transform, 
        &t);
    
    render_frame_buffer_t fb;
    fb.data = gbitmap_get_data(frameBufferBitmap);
    fb.row_stride = gbitmap_get_bytes_per_row(frameBufferBitmap);

    // Render the mesh
    render_draw_mesh_solid(
        &fb,
        &viewport,
        g_holomesh,
        (const vec3_t* const*) g_transformed_points);

    g_hologram_frame++;
}
static void render_layer_update(Layer* layer, GContext *ctx) {
  GRect bounds = layer_get_bounds(layer);

  // Capture the graphics context framebuffer
  GBitmap *framebuffer = graphics_capture_frame_buffer(ctx);

  //backup old framebuffer format data
  uint8_t *orig_addr = gbitmap_get_data(framebuffer);
  GBitmapFormat orig_format = gbitmap_get_format(framebuffer);
  uint16_t orig_stride = gbitmap_get_bytes_per_row(framebuffer);

  //Release the framebuffer now that we are free to modify it
  graphics_release_frame_buffer(ctx, framebuffer);

#if 0 // BUG: Currently not working
  GBitmap *render_bitmap = gbitmap_create_blank(bounds.size, GBitmapFormat8BitCircular);
#else
  GBitmap *render_bitmap = gbitmap_create_blank(bounds.size, GBitmapFormat8Bit);
#endif

  //replace screen bitmap with our offscreen render bitmap
  gbitmap_set_data(framebuffer, gbitmap_get_data(render_bitmap),
    gbitmap_get_format(render_bitmap), gbitmap_get_bytes_per_row(render_bitmap), false);

  graphics_context_set_compositing_mode(ctx, GCompOpAssign);
  digital_update_proc(layer, ctx);

  //restore original context bitmap
  gbitmap_set_data(framebuffer, orig_addr, orig_format, orig_stride, false);

  //draw the bitmap to the screen
  graphics_context_set_compositing_mode(ctx, GCompOpSet);
  // Make the render_bitmap transparent
  bitmap_make_semi_transparent(render_bitmap);
  graphics_draw_bitmap_in_rect(ctx, render_bitmap, bounds);
  gbitmap_destroy(render_bitmap);
}
Exemplo n.º 6
0
static void update_proc_frame_buffer(Layer *layer, GContext *ctx){
#if defined(PBL_ROUND)
	update_proc_round_frame_buffer(layer, ctx);
#else
  GBitmap *fb = graphics_capture_frame_buffer(ctx);
	if (fb!=NULL){
	  GRect bounds=gbitmap_get_bounds(fb);
	  uint8_t *pos = gbitmap_get_data(fb);
	  for (int16_t y = bounds.origin.y; y < bounds.size.h; y++) {
		  for (int16_t x = bounds.origin.x; x < gbitmap_get_bytes_per_row(fb); x++){
			  memset(++pos, rand(), 1);
		  }
    }
	  graphics_release_frame_buffer(ctx, fb);
  }
#endif
}