/** @internal @This handles data. * * @param upipe description structure of the pipe * @param uref uref structure describing the picture * @param upump_p reference to pump that generated the buffer * @return true if the packet was handled */ static bool upipe_audiobar_handle(struct upipe *upipe, struct uref *uref, struct upump **upump_p) { struct upipe_audiobar *upipe_audiobar = upipe_audiobar_from_upipe(upipe); const char *def; if (unlikely(ubase_check(uref_flow_get_def(uref, &def)))) { UBASE_FATAL(upipe, uref_sound_flow_get_channels(uref, &upipe_audiobar->channels)) uref_sound_flow_clear_format(uref); UBASE_FATAL(upipe, uref_attr_import(uref, upipe_audiobar->flow_def_config)) uref_pic_flow_clear_format(uref); UBASE_FATAL(upipe, uref_pic_flow_set_planes(uref, 0)) UBASE_FATAL(upipe, uref_pic_flow_set_macropixel(uref, 1)) UBASE_FATAL(upipe, uref_pic_flow_add_plane(uref, 1, 1, 1, "y8")) UBASE_FATAL(upipe, uref_pic_flow_add_plane(uref, 2, 1, 1, "u8")) UBASE_FATAL(upipe, uref_pic_flow_add_plane(uref, 2, 1, 1, "v8")) UBASE_FATAL(upipe, uref_pic_flow_add_plane(uref, 1, 1, 1, "a8")) UBASE_FATAL(upipe, uref_pic_set_progressive(uref)) upipe_audiobar->hsize = upipe_audiobar->vsize = upipe_audiobar->sep_width = upipe_audiobar->pad_width = UINT64_MAX; upipe_audiobar_require_flow_format(upipe, uref); return true; } if (!upipe_audiobar->ubuf_mgr) return false; if (unlikely(upipe_audiobar->hsize == UINT64_MAX)) return false; struct ubuf *ubuf = ubuf_pic_alloc(upipe_audiobar->ubuf_mgr, upipe_audiobar->hsize, upipe_audiobar->vsize); uref_attach_ubuf(uref, ubuf); uint8_t *dst[4]; size_t strides[4]; uint8_t hsubs[4]; uint8_t vsubs[4]; static const char *chroma[4] = { "y8", "u8", "v8", "a8" }; for (int i = 0; i < 4; i++) { if (unlikely(!ubase_check(uref_pic_plane_write(uref, chroma[i], 0, 0, -1, -1, &dst[i])) || !ubase_check(uref_pic_plane_size(uref, chroma[i], &strides[i], &hsubs[i], &vsubs[i], NULL)))) { upipe_throw_fatal(upipe, UBASE_ERR_ALLOC); uref_free(uref); return true; } } uint8_t alpha = upipe_audiobar->alpha; uint64_t h = upipe_audiobar->vsize; const int hred = h - (iec_scale(-8.) * h); const int hyellow = h - (iec_scale(-18.) * h); uint8_t transparent[4] = { 0x10, 0x80, 0x80, 0 }; uint8_t black[4] = { 0x10, 0x80, 0x80, alpha }; uint8_t red[2][4] = { { 76, 85, 0xff, alpha }, { 37, 106, 191, alpha } }; uint8_t green[2][4] = { { 150, 44, 21, alpha }, { 74, 85, 74, alpha } }; uint8_t yellow[2][4] = { { 226, 1, 148, alpha }, { 112, 64, 138, alpha } }; uint64_t pts = 0; if (unlikely(!ubase_check(uref_clock_get_pts_prog(uref, &pts)))) { upipe_warn(upipe, "unable to read pts"); } for (uint8_t chan = 0; chan < upipe_audiobar->channels; chan++) { double amplitude = 0.; if (unlikely(!ubase_check(uref_amax_get_amplitude(uref, &litude, chan)))) upipe_warn_va(upipe, "unable to get amplitude for channel %"PRIu8", assuming silence", chan); double scale = log10(amplitude) * 20; // IEC-268-18 return time speed is 20dB per 1.7s (+/- .3) if (upipe_audiobar->peak_date[chan]) upipe_audiobar->peak[chan] -= 20 * (pts - upipe_audiobar->peak_date[chan]) / (1.7 * UCLOCK_FREQ); upipe_audiobar->peak_date[chan] = pts; if (scale >= upipe_audiobar->peak[chan]) /* higher than lowered peak */ upipe_audiobar->peak[chan] = scale; else /* Current amplitude can not go below the lowered peak value */ scale = upipe_audiobar->peak[chan]; scale = iec_scale(scale); const int hmax = h - scale * h; for (int row = 0; row < h; row++) { bool bright = row > hmax; const uint8_t *color = row < hred ? red[!bright] : row < hyellow ? yellow[!bright] : green[!bright]; copy_color(dst, strides, hsubs, vsubs, color, row, chan * upipe_audiobar->chan_width, upipe_audiobar->chan_width); if (chan && upipe_audiobar->sep_width) copy_color(dst, strides, hsubs, vsubs, black, row, chan * upipe_audiobar->chan_width - upipe_audiobar->sep_width / 2, upipe_audiobar->sep_width); if (chan == upipe_audiobar->channels - 1 && upipe_audiobar->pad_width) copy_color(dst, strides, hsubs, vsubs, transparent, row, (chan + 1) * upipe_audiobar->chan_width, upipe_audiobar->pad_width); } } /* dB marks */ for (int i = 1; i <= 6; i++) { int row = h - (iec_scale(-10 * i) * h); copy_color(dst, strides, hsubs, vsubs, black, row, 0, upipe_audiobar->hsize); } for (int i = 0; i < 4; i++) ubuf_pic_plane_unmap(ubuf, chroma[i], 0, 0, -1, -1); upipe_audiobar_output(upipe, uref, upump_p); return true; }
static void gimp_brush_clipboard_buffer_changed (Gimp *gimp, GimpBrush *brush) { gint width; gint height; if (brush->mask) { temp_buf_free (brush->mask); brush->mask = NULL; } if (brush->pixmap) { temp_buf_free (brush->pixmap); brush->pixmap = NULL; } if (gimp->global_buffer) { TileManager *tiles = gimp_buffer_get_tiles (gimp->global_buffer); GimpImageType type = gimp_buffer_get_image_type (gimp->global_buffer); width = MIN (gimp_buffer_get_width (gimp->global_buffer), 1024); height = MIN (gimp_buffer_get_height (gimp->global_buffer), 1024); brush->mask = temp_buf_new (width, height, 1, 0, 0, NULL); brush->pixmap = temp_buf_new (width, height, 3, 0, 0, NULL); /* copy the alpha channel into the brush's mask */ if (GIMP_IMAGE_TYPE_HAS_ALPHA (type)) { PixelRegion bufferPR; PixelRegion maskPR; pixel_region_init (&bufferPR, tiles, 0, 0, width, height, FALSE); pixel_region_init_temp_buf (&maskPR, brush->mask, 0, 0, width, height); extract_alpha_region (&bufferPR, NULL, &maskPR); } else { PixelRegion maskPR; guchar opaque = OPAQUE_OPACITY; pixel_region_init_temp_buf (&maskPR, brush->mask, 0, 0, width, height); color_region (&maskPR, &opaque); } /* copy the color channels into the brush's pixmap */ if (GIMP_IMAGE_TYPE_IS_RGB (type)) { PixelRegion bufferPR; PixelRegion pixmapPR; pixel_region_init (&bufferPR, tiles, 0, 0, width, height, FALSE); pixel_region_init_temp_buf (&pixmapPR, brush->pixmap, 0, 0, width, height); if (GIMP_IMAGE_TYPE_HAS_ALPHA (type)) copy_color (&bufferPR, &pixmapPR); else copy_region (&bufferPR, &pixmapPR); } else { PixelRegion bufferPR; PixelRegion tempPR; TempBuf *temp = temp_buf_new (width, height, 1, 0, 0, NULL); pixel_region_init (&bufferPR, tiles, 0, 0, width, height, FALSE); pixel_region_init_temp_buf (&tempPR, temp, 0, 0, width, height); if (GIMP_IMAGE_TYPE_HAS_ALPHA (type)) copy_component (&bufferPR, &tempPR, 0); else copy_region (&bufferPR, &tempPR); temp_buf_copy (temp, brush->pixmap); temp_buf_free (temp); } } else { guchar color = 0; width = 17; height = 17; brush->mask = temp_buf_new (width, height, 1, 0, 0, &color); } brush->x_axis.x = width / 2; brush->x_axis.y = 0; brush->y_axis.x = 0; brush->y_axis.y = height / 2; gimp_data_dirty (GIMP_DATA (brush)); }
// Cube face will be identified using their face center void createCube() { //const int color_scheme[] = {11, 12, 13, 1, 3, 14}; GLfloat cube_color_buffer[108]; int start = 0; for (int i=0; i<6; i++) { if (color_scheme[i] == 1) { start = copy_color(start, BLACK_COLOR, cube_color_buffer); } else if (color_scheme[i] == 2) { start = copy_color(start, RED_COLOR, cube_color_buffer); } else if (color_scheme[i] == 3) { start = copy_color(start, GREEN_COLOR, cube_color_buffer); } else if (color_scheme[i] == 4) { start = copy_color(start, YELLOW_COLOR, cube_color_buffer); } else if (color_scheme[i] == 5) { start = copy_color(start, BLUE_COLOR, cube_color_buffer); } else if (color_scheme[i] == 6) { start = copy_color(start, MAGENTA_COLOR, cube_color_buffer); } else if (color_scheme[i] == 7) { start = copy_color(start, CYAN_COLOR, cube_color_buffer); } else if (color_scheme[i] == 8) { start = copy_color(start, DARK_GRAY_COLOR, cube_color_buffer); } else if (color_scheme[i] == 9) { start = copy_color(start, LIGHT_GRAY_COLOR, cube_color_buffer); } else if (color_scheme[i] == 10) { start = copy_color(start, BROWN_COLOR, cube_color_buffer); } else if (color_scheme[i] == 11) { start = copy_color(start, ORANGE_COLOR, cube_color_buffer); } else if (color_scheme[i] == 12) { start = copy_color(start, PINK_COLOR, cube_color_buffer); } else if (color_scheme[i] == 13) { start = copy_color(start, PURPLE_COLOR, cube_color_buffer); } else if (color_scheme[i] == 14) { start = copy_color(start, WHITE_COLOR, cube_color_buffer); } } const GLfloat cube_vertex_buffer[] = { // X = l/2, Y = h/2, Z = 0 0, 0, 0, length, 0, 0, length, height, 0, 0, 0, 0, 0, height, 0, length, height, 0, // X = l/2, Y = h/2, Z = b 0, 0, breadth, length, 0, breadth, length, height, breadth, 0, 0, breadth, 0, height, breadth, length, height, breadth, 0, 0, 0, 0, 0, breadth, 0, height, breadth, 0, 0, 0, 0, height, 0, 0, height, breadth, length, 0, 0, length, 0, breadth, length, height, breadth, length, 0, 0, length, height, 0, length, height, breadth, 0, height, 0, length, height, 0, length, height, breadth, 0, height, 0, 0, height, breadth, length, height, breadth, 0, 0, 0, length, 0, 0, length, 0, breadth, 0, 0, 0, 0, 0, breadth, length, 0, breadth, }; cube = create3DObject(GL_TRIANGLES, 36, cube_vertex_buffer, cube_color_buffer, GL_FILL); }
void keyboard(unsigned char key, int x, int y) { (void)x; (void)y; switch(key) { case ESCAPE: exit(0); break; case '1': g_object_index = OBJECT_SPHERE; copy_color(g_object, g_object_sphere); break; case '2': g_object_index = OBJECT_TORUS; copy_color(g_object, g_object_torus); break; case '3': g_object_index = OBJECT_LINES; copy_color(g_object, g_object_lines); break; case '4': g_object_index = OBJECT_CUBE; copy_color(g_object, g_object_cube); break; case '5': g_object_index = OBJECT_SPIRAL; copy_color(g_object, g_object_spiral); break; case '6': g_object_index = OBJECT_PARABOLOID; copy_color(g_object, g_object_paraboloid); break; case '7': g_object_index = OBJECT_CHAOS; copy_color(g_object, g_object_chaos); break; case 'A': case 'a': g_zSpeed -=SPEED_DELTA; break; case 'D': case 'd': g_zSpeed += SPEED_DELTA; break; case 'W': case 'w': g_ySpeed -= SPEED_DELTA; break; case 'S': case 's': g_ySpeed += SPEED_DELTA; break; case 'T': case 't': if(g_morphing_types == point_morphing) g_morphing_types = line_morphing; else g_morphing_types = point_morphing; break; default: break; } }