SimplyImage *simply_res_add_image(SimplyRes *self, uint32_t id, int16_t width, int16_t height, uint8_t *pixels, uint16_t pixels_length) { SimplyImage *image = (SimplyImage*) list1_find(self->images, id_filter, (void*)(uintptr_t) id); if (image) { destroy_image(self, image); } CreateDataContext context = { .size = GSize(width, height), .data_length = pixels_length, .data = pixels, }; image = IF_SDK_3_ELSE(create_image(self, create_bitmap_with_png_data, &context), create_image(self, create_bitmap_with_data, &context)); if (image) { image->id = id; add_image(self, image); } return image; } void simply_res_remove_image(SimplyRes *self, uint32_t id) { SimplyImage *image = (SimplyImage*) list1_find(self->images, id_filter, (void*)(uintptr_t) id); if (image) { destroy_image(self, image); } }
/* We create a sprite for the title and an animation * with 6 frames. * We also create a mask image for a spot and fade-in * effect. */ static int prepare_title(struct game_title* title) { int f; title->sprite = create_sprite(create_image("res/title.png"), 70, 15); if (title->sprite == NULL) goto error; title->bling = create_animation(); if (title->bling == NULL) goto error; add_frame(title->bling, 0, SECOND / 2, NULL); for (f = 5; f >= 0; f--) add_frame(title->bling, f, SECOND / 10, NULL); title->bling->mode = FREEZE_LAST_FRAME; title->mask = create_target_image(192, 108, color_from_RGB(50, 50, 50)); if (title->mask == NULL) goto error; set_blend_mode(title->mask, MULTIPLY); title->spot = create_image("res/spot.png"); if (title->spot == NULL) goto error; set_blend_mode(title->spot, ADD); return 0; error: ERROR("Unable to prepare title"); cleanup_title(title); return -1; }
TEST(PermutationTest, Multiplication) { Permutation p = Permutation(create_image(3, 1, 0, 2)); Permutation q = Permutation(create_image(3, 0, 2, 1)); Permutation product = p * q; EXPECT_EQ(1, product(0)); EXPECT_EQ(2, product(1)); EXPECT_EQ(0, product(2)); }
static pixman_bool_t do_check (int i) { pixman_image_t *source, *dest, *mask; pixman_op_t op; int x, y, width, height; pixman_image_t *dest_copy; pixman_bool_t result = TRUE; pixman_bool_t component_alpha; prng_srand (i); op = RANDOM_ELT (operators); x = prng_rand_n (MAX_WIDTH); y = prng_rand_n (MAX_HEIGHT); width = prng_rand_n (MAX_WIDTH) + 4; height = prng_rand_n (MAX_HEIGHT) + 4; source = create_image (NULL); mask = create_image (NULL); dest = create_image (&dest_copy); if (x >= dest->bits.width) x = dest->bits.width / 2; if (y >= dest->bits.height) y = dest->bits.height / 2; if (x + width > dest->bits.width) width = dest->bits.width - x; if (y + height > dest->bits.height) height = dest->bits.height - y; component_alpha = prng_rand_n (2); pixman_image_set_component_alpha (mask, component_alpha); pixman_image_composite32 (op, source, mask, dest, 0, 0, 0, 0, x, y, width, height); if (!verify (i, op, source, mask, dest, dest_copy, x, y, width, height, component_alpha)) { result = FALSE; } pixman_image_unref (source); pixman_image_unref (mask); pixman_image_unref (dest); pixman_image_unref (dest_copy); return result; }
int main(int argc, char* argv[]) { void* img = (void*)malloc(5000000); create_image(img, 5000000); char* outp = "initrd.img"; char* tdir = NULL; for(int i = 1; i < argc; i++) { if(strcmp(argv[i], "-d") == 0) { tdir = argv[++i]; } else if (strcmp(argv[i], "-o") == 0) { outp = argv[++i]; } } FILE* dmp = fopen(outp,"w"); process_directory(tdir, ""); fwrite(img,1, 5000000,dmp); fclose(dmp); return 0; }
void BackProjection::create_prob() { int i, j; input = (unsigned char *)malloc(r * c * sizeof(unsigned char)); for (i = 0; i < r; i++) { for (j = 0; j < c; j++) { input[ i * c + j ] = FALSE; } } create_image(r, c, input, r < c ? r : c, r < c ? (F_TYPE) r / (F_TYPE) 4.0: (F_TYPE) c / (F_TYPE) 4.0); std::string inName = "BackProjection_ref_in.dat"; std::string bmpName = "BackProjection_ref_in.bmp"; printimage(r, c, input, inName.c_str()); write_bmp(bmpName.c_str(), input, r, c); rproj = (int *)malloc(r * sizeof(int)); cproj = (int *)malloc(c * sizeof(int)); uproj = (int *)malloc((r + c - 1) * sizeof(int)); dproj = (int *)malloc((r + c - 1) * sizeof(int)); rband = (int *)malloc(r * c * sizeof(int)); cband = (int *)malloc(c * sizeof(int)); uband = (int *)malloc((r + c - 1) * sizeof(int)); dband = (int *)malloc((r + c - 1) * sizeof(int)); makeband(r, c, rband, cband, uband, dband); create_input(r, c, input, rproj, cproj, uproj, dproj, uband, dband); }
/* * create new map from scratch, using %x and %y as position parameters * 0..nx-1 and 0..ny-1 */ local void do_create(int nx, int ny,int nz) { double m_min, m_max, total; real fin[5], fout; int ix, iy, iz; int badvalues; m_min = HUGE; m_max = -HUGE; total = 0.0; /* count total intensity in new map */ badvalues = 0; /* count number of bad operations */ if (nz > 0) { warning("cube"); if (!create_cube (&iptr, nx, ny, nz)) /* create default empty image */ error("Could not create 3D image from scratch"); #if 0 Axis(iptr) = 1; /* set linear axistype with a fits-style reference pixel */ #endif wcs_f2i(3,crpix,crval,cdelt,iptr); for (iz=0; iz<nz; iz++) { fin[2] = iz-crpix[2]+1; /* crpix is 1 for first pixel (FITS convention) */ for (iy=0; iy<ny; iy++) { fin[1] = iy-crpix[1]+1; for (ix=0; ix<nx; ix++) { fout = 0.0; CubeValue(iptr,ix,iy,iz) = fout; m_min = MIN(m_min,fout); /* and check for new minmax */ m_max = MAX(m_max,fout); total += fout; /* add up totals */ } } } } else { warning("2d-map"); if (!create_image (&iptr, nx, ny)) error("Could not create 2D image from scratch"); wcs_f2i(2,crpix,crval,cdelt,iptr); for (iy=0; iy<ny; iy++) { fin[1] = iy; for (ix=0; ix<nx; ix++) { fout = 0.0; MapValue(iptr,ix,iy) = fout; m_min = MIN(m_min,fout); /* and check for new minmax */ m_max = MAX(m_max,fout); total += fout; /* add up totals */ } } } MapMin(iptr) = m_min; MapMax(iptr) = m_max; dprintf(1,"New min and max in map are: %f %f\n",m_min,m_max); dprintf(1,"New total brightness/mass is %f\n", total*Dx(iptr)*Dy(iptr)); if (badvalues) warning ("There were %d bad operations in dofie",badvalues); }
static void open_test_window (void) { GtkWidget *grid; int i; test_window = gtk_window_new (GTK_WINDOW_TOPLEVEL); gtk_window_set_title (GTK_WINDOW (test_window), "Tests"); g_signal_connect (test_window, "delete-event", G_CALLBACK (gtk_main_quit), test_window); gtk_window_set_resizable (GTK_WINDOW (test_window), FALSE); test_widgets[TEST_WIDGET_IMAGE] = create_image (); test_widgets[TEST_WIDGET_LABEL] = create_label (FALSE, FALSE); test_widgets[TEST_WIDGET_VERTICAL_LABEL] = create_label (TRUE, FALSE); test_widgets[TEST_WIDGET_WRAP_LABEL] = create_label (FALSE, TRUE); test_widgets[TEST_WIDGET_BUTTON] = create_button (); test_widgets[TEST_WIDGET_ALIGNMENT] = create_alignment (); grid = gtk_grid_new (); gtk_container_add (GTK_CONTAINER (test_window), grid); for (i = 0; i < TEST_WIDGET_LAST; ++i) { gtk_grid_attach (GTK_GRID (grid), test_widgets[i], i % 3, i / 3, 1, 1); } gtk_widget_show_all (test_window); }
frame_t create_frame_and_image(unsigned long index, const int w, const int h) { unsigned char* image_data = (unsigned char*)malloc(w * h); int i=0; for ( ; i<w * h ; ++i) image_data[i] = (13 * i + (1243 & i)) % 256; return create_frame(index, create_image(w, h, w, image_data, 1)); }
int main(int argc, char **argv) { srand(time(NULL)); clock_t beg, end; int size = 50; grid *grd = grid_allocate(size, size); beg = clock(); grid_create(grd, 0.6); cl_list* clusters = clusterization(grd); end = clock(); int i, j; for (i = 0; i < size; i++) { for (j = 0; j < size; j++) printf("%d", grd->cells[i * size + j]); printf("\n"); } cl_list_print(clusters); create_image("img.png", 2000, grd, clusters); grid_free(grd); printf("Finished in %g sec\n", (double)(end - beg) / CLOCKS_PER_SEC); return 0; }
int main(int argc, char **argv) { char *progname = argv[0]; /* process command line options */ options.vm = 0; options.extended = 0; while ((argc > 1) && (argv[1][0] == '-') && (argv[1][1] == '-')) { char *option = &argv[1][2]; if (strcmp(option, "vm") == 0) { options.vm = 1; } else if (strcmp(option, "extended") == 0) { options.extended = 1; } else { error("%s: invalid option\nusage: %s %s\n", progname, progname, ARGS); } argc--; argv++; } if (options.vm == 1) { error("%s: option --vm not implemented\n", progname); } if (argc < 3) { /* at least 3 args (createimage bootblock kernel) */ error("usage: %s %s\n", progname, ARGS); } create_image(argc - 1, argv + 1); return 0; }
// Save a raw image instance into a file bool save_image(const std::string &dest_filename, LLPointer<LLImageRaw> raw_image, int blocks_size, int precincts_size, int levels, bool reversible, bool output_stats) { LLPointer<LLImageFormatted> image = create_image(dest_filename); // Set the image codestream parameters on output in the case of a j2c image if (image->getCodec() == IMG_CODEC_J2C) { // That method doesn't exist (and likely, doesn't make sense) for any other image file format // hence the required cryptic cast. if ((blocks_size != -1) || (precincts_size != -1) || (levels != 0)) { ((LLImageJ2C*)(image.get()))->initEncode(*raw_image, blocks_size, precincts_size, levels); } ((LLImageJ2C*)(image.get()))->setReversible(reversible); } if (!image->encode(raw_image, 0.0f)) { return false; } if (output_stats) { output_image_stats(image, dest_filename); } return image->save(dest_filename); }
SimplyImage *simply_res_add_bundled_image(SimplyRes *self, uint32_t id) { SimplyImage *image = create_image(self, create_bitmap_with_id, (void*)(uintptr_t) id); if (image) { add_image(self, image); } return image; }
enum piglit_result piglit_display(void) { const unsigned w = 2; const unsigned h = 2; const unsigned cpp = 4; const unsigned fourcc = DRM_FORMAT_ARGB8888; const unsigned char *pixels = alloca(w * h * cpp); struct piglit_dma_buf *buf; EGLImageKHR img; enum piglit_result res; bool pass = true; res = piglit_create_dma_buf(w, h, fourcc, pixels, &buf); if (res != PIGLIT_PASS) return res; img = create_image(w, h, buf->fd, buf->stride[0], buf->offset[0]); if (!img) { piglit_destroy_dma_buf(buf); /* unsupported format (BAD_MATCH) is not an error. */ return piglit_check_egl_error(EGL_BAD_MATCH) ? PIGLIT_SKIP : PIGLIT_FAIL; } pass = try_as_texture_2d(img) && pass; pass = try_as_render_buffer(img) && pass; eglDestroyImageKHR(eglGetCurrentDisplay(), img); piglit_destroy_dma_buf(buf); return pass ? PIGLIT_PASS : PIGLIT_FAIL; }
image *scale_image_half(const image *img) { image *simg = create_image((img->width + 1) / 2, (img->height + 1) / 2); for (uint32_t y = 0; y < img->height; y += 2) { for (uint32_t x = 0; x < img->width; x += 2) { uint32_t p = y * img->width + x; uint32_t sp = y * img->width / 4 + x / 2; for (int c = 0; c < CHANNELS; c++) { simg->data[sp * CHANNELS + c] = ( img->data[p * CHANNELS + c] + (x + 1 == img->width ? 0 : img->data[(p + 1) * CHANNELS + c]) + (y + 1 == img->height ? 0 : img->data[(p + img->width) * CHANNELS + c]) + (x + 1 == img->width || y + 1 == img->height ? 0 : img->data[(p + img->width + 1) * CHANNELS + c]) ) / 4; } } } return simg; }
int main(int argc, char* argv[]) { create_image_world(); int image = create_image(100, 100); for(int x = 0; x < 100; x++) { for(int y = 0; y < 100; y++) { if (x == y) { set_pixel(image, x, y, 255, 0, 0, 255); } else if (x+y == 100) { set_pixel(image, x, y, 255, 255, 0, 0); } else { set_pixel(image, x, y, 255, 0, 255, 0); } } } put_image(image, get_screen_width()/2-get_image_width(image)/2, get_screen_height()/2-get_image_height(image)/2); return p1world_shutdown(); }
/** * hibernation_snapshot - Quiesce devices and create a hibernation image. * @platform_mode: If set, use platform driver to prepare for the transition. * * This routine must be called with pm_mutex held. */ int hibernation_snapshot(int platform_mode) { pm_message_t msg = PMSG_RECOVER; int error; error = platform_begin(platform_mode); if (error) goto Close; error = dpm_prepare(PMSG_FREEZE); if (error) goto Complete_devices; /* Preallocate image memory before shutting down devices. */ error = hibernate_preallocate_memory(); if (error) goto Complete_devices; suspend_console(); ftrace_stop(); pm_restrict_gfp_mask(); error = dpm_suspend(PMSG_FREEZE); if (error) goto Recover_platform; if (hibernation_test(TEST_DEVICES)) goto Recover_platform; error = create_image(platform_mode); /* * Control returns here (1) after the image has been created or the * image creation has failed and (2) after a successful restore. */ Resume_devices: /* We may need to release the preallocated image pages here. */ if (error || !in_suspend) swsusp_free(); msg = in_suspend ? (error ? PMSG_RECOVER : PMSG_THAW) : PMSG_RESTORE; dpm_resume(msg); if (error || !in_suspend) pm_restore_gfp_mask(); ftrace_start(); resume_console(); Complete_devices: dpm_complete(msg); Close: platform_end(platform_mode); return error; Recover_platform: platform_recover(platform_mode); goto Resume_devices; }
void Parser::DefineBitsJPEG3(Environment& env) { auto cid = env.stream.read_uint16(); auto size = env.stream.read_uint32(); auto image = create_image(env.stream, env.tag, cid, size); if( image != nullptr ) env.player.set_character(image->get_character_id(), image); }
void mini_control_cover_set(minicontrol *mc, const char* path) { if (!path) elm_object_part_content_set(mc->layout, "swallow.cover", create_icon(mc->layout, "background_cone.png")); else elm_object_part_content_set(mc->layout, "swallow.cover", create_image(mc->layout, path)); }
int main(int argc, char* argv[]) { process_options(argc, argv); create_image_preprocess(); create_image(); output_image(); return 0; }
void EGL_SEND(int size, int frames) { int sock, i, j, s; socklen_t slen; char buf[100], *sbuf; printf("-> Start...\n"); #if SOCKET_TCP struct sockaddr_in server; if ( (sock = socket(PF_INET, SOCK_STREAM, IPPROTO_TCP)) < 0 ) { return; } memset(&server, 0, sizeof(server)); server.sin_family = AF_INET; inet_aton(IP_ADDRESS,&server.sin_addr); // server.sin_addr.s_addr = inet(IP_ADDRESS);//htonl(INADDR_ANY); server.sin_port = htons(PORT); #else struct sockaddr_un server; sock = socket(AF_UNIX, SOCK_STREAM, 0); if (sock < 0) { perror("opening stream socket"); return; } make_unix_domain_addr(NAME, &server, &slen); #endif if (connect(sock, (struct sockaddr *) &server, sizeof(server)) < 0) { close(sock); perror("connecting stream socket"); return; } printf("-> Connected...\n"); sprintf(buf, HEAD, size, size,1.0); if (send(sock, buf, 26, 0) < 0) perror("writing on stream socket"); printf("-> Send size done...\n"); printf("-> Send frame\n"); if (frames == -1) frames = 65535; sbuf = (char*) malloc(size * size); for (i = 0; i < frames; i++) { create_image(sbuf, i, size); s = send(sock, sbuf, size * size, 0); if (s < 0) break; sleep(1); } free(sbuf); close(sock); }
TEST(PermutationTest, OutputOperator) { std::stringstream ss; ss << Permutation(create_image(6, 0, 2, 3, 1, 5, 4)); EXPECT_STREQ("(1 2 3)(4 5)", ss.str().c_str()); ss.str(""); ss << Permutation(); EXPECT_STREQ("Id", ss.str().c_str()); }
TEST(PermutationTest, Inverse) { Permutation p = Permutation(create_image(3, 1, 2, 0)); Permutation inverse = p.inverse(); EXPECT_EQ(2, inverse(0)); EXPECT_EQ(0, inverse(1)); EXPECT_EQ(1, inverse(2)); }
static struct wizard* create_wizard(void) { struct wizard* wizard = calloc(1, sizeof(*wizard)); if (wizard == NULL) goto error; wizard->sprite = create_sprite(create_image("res/wizard.png"), 32, 32); if (wizard->sprite == NULL) goto error; wizard->walk_right = create_animation(); if (wizard->walk_right == NULL) goto error; add_frame(wizard->walk_right, 4, 200, &PREP_SPEED); add_frame(wizard->walk_right, 0, 200, &NORMAL_SPEED); /* <------+ */ add_frame(wizard->walk_right, 1, 200, &NORMAL_SPEED); /* | */ add_frame(wizard->walk_right, 2, 200, &NORMAL_SPEED); /* | */ add_frame(wizard->walk_right, 3, 200, &NORMAL_SPEED); /* <--+ | */ add_frame(wizard->walk_right, 4, 200, &BRAKE_SPEED); /* | | */ wizard->walk_right->loop_from = 1; /* --------------------------|---+ */ wizard->walk_right->loop_to = 4; /* --------------------------+ */ wizard->walk_left = create_animation(); if (wizard->walk_left == NULL) goto error; add_frame(wizard->walk_left, 15, 200, &PREP_SPEED_L); add_frame(wizard->walk_left, 11, 200, &NORMAL_SPEED_L); /* <------+ */ add_frame(wizard->walk_left, 10, 200, &NORMAL_SPEED_L); /* | */ add_frame(wizard->walk_left, 9, 200, &NORMAL_SPEED_L); /* | */ add_frame(wizard->walk_left, 8, 200, &NORMAL_SPEED_L); /* <--+ | */ add_frame(wizard->walk_left, 15, 200, &BRAKE_SPEED_L); /* | | */ wizard->walk_left->loop_from = 1; /* -----------------------------|---+ */ wizard->walk_left->loop_to = 4; /* -----------------------------+ */ wizard->stand = create_animation(); if (wizard->stand == NULL) goto error; add_frame(wizard->stand, 5, 100, &NO_SPEED); /* <---+ */ wizard->stand->mode = FREEZE_LAST_FRAME; /* ------------+ */ wizard->spell = create_animation(); if (wizard->spell == NULL) goto error; add_frame(wizard->spell, 5, 200, &NO_SPEED); add_frame(wizard->spell, 6, 200, &NO_SPEED); add_frame(wizard->spell, 7, 100, &NO_SPEED); /* <--+ */ add_frame(wizard->spell, 6, 200, &NO_SPEED); /* | */ wizard->spell->loop_from = 2; /* ----------------------+ */ wizard->spell->loop_to = 2; /* ----------------------+ */ play_animation(wizard->sprite, wizard->stand); wizard->pos.x = 0; wizard->pos.y = BASE_Y; return wizard; error: destroy_wizard(wizard); ERROR("Unable to create wizard"); return NULL; }
/* create_sample is our game state's initialization function * and will return a fully ready instance of struct state for us * to work with in each frame. */ static void* create_sample(void) { struct state* state = malloc(sizeof(struct state)); state->space = cpSpaceNew(); state->tile_img = create_image("res/particle.png"); state->mouse_body = cpBodyNewKinematic(); init_tiles(state); init_walls(state); return state; }
int expose_hook(t_env *e) { if (!e->img_ptr) create_image(e); cast(e, e->begin_list); mlx_do_sync(e->mlx); mlx_put_image_to_window(e->mlx, e->win, e->img_ptr, 0, 0); ft_bzero(e->img, (WIN_X * e->bpp / 8 + WIN_Y * e->sl)); return (1); }
/* * Class: Test * Method: create_image * Signature: (III[Ljava/lang/Byte;I)J */ JNIEXPORT jlong JNICALL Java_Test_create_1image(JNIEnv * env, jclass klass, jint width, jint height, jint stride, jbyteArray byteData, jint imageOwnsData) { // works ok, explicit copy //unsigned char* data = (unsigned char*)malloc(height * stride); //(*env)->GetByteArrayRegion(env, byteData, 0, height * stride, data); unsigned char* data = (unsigned char*)(*env)->GetByteArrayElements(env, byteData, 0); jlong result = (jlong)create_image(width, height, stride, data, 0); (*env)->ReleaseByteArrayElements(env, byteData, data, 0); return result; }
// Test that SkImage encoding observes custom pixel serializers. DEF_TEST(Image_Encode_Serializer, reporter) { MockSerializer serializer([]() -> SkData* { return SkData::NewWithCString(kSerializedData); }); SkAutoTUnref<SkImage> image(create_image()); SkAutoTUnref<SkData> encoded(image->encode(&serializer)); SkAutoTUnref<SkData> reference(SkData::NewWithCString(kSerializedData)); REPORTER_ASSERT(reporter, serializer.didEncode()); REPORTER_ASSERT(reporter, encoded); REPORTER_ASSERT(reporter, encoded->size() > 0); REPORTER_ASSERT(reporter, encoded->equals(reference)); }
/* * Calculate and set the AFE offset. * * low: known-good AFE offset-register value. See note. * high: known-good AFE offset-register value. See note. * * Note: * 'low' and 'high' depend on the scanner model. * Choose them so that * 1. both produce black pixel samples > 0, and never zero. * 2. 'low' produces a a darker black level than 'high', * 3. 'low' and 'high' values are as far apart as possible, * for better precision. * Example: For CanoScan 4400F, select low = 75, high = 0. * Notice that the 'low' register value is not necessarily * less than the 'high' register value. It is what comes * out of the scanner that counts. */ static int calc_afe_blacklevel(struct gl843_device *dev, struct calibration_info *cal, uint8_t low, uint8_t high) { int ret, i; struct gl843_image *img; struct img_stat lo_stat, hi_stat; DBG(DBG_msg, "Calibrating A/D-converter black level.\n"); CHK_MEM(img = create_image(cal->width, cal->height, PXFMT_RGB16)); /* Scan with the lamp off to produce black pixels. */ CHK(set_lamp(dev, LAMP_OFF, 0)); /* Sample 'low' black level */ for (i = 0; i < 3; i++) { CHK(write_afe_gain(dev, i, 1.0)); CHK(write_afe(dev, 32 + i, low)); /* Set 'low' black level */ } CHK(scan_img(dev, img, 10000)); get_image_stats(img, &lo_stat); /* Sample 'high' black level */ for (i = 0; i < 3; i++) { CHK(write_afe(dev, 32 + i, high)); /* Set 'high' black level */ } CHK(scan_img(dev, img, 10000)); get_image_stats(img, &hi_stat); /* Use the line equation to find and set the best offset value */ for (i = 0; i < 3; i++) { double m, c; /* y = mx + c */ int o; /* offset */ m = (hi_stat.avg[i] - lo_stat.avg[i]) / (high - low); c = lo_stat.avg[i] - m * low; o = (int) satf(-c / m + 0.5, 0, 255); cal->offset[i] = o; CHK(write_afe(dev, 32 + i, o)); DBG(DBG_info, "AFE %s offset = %d\n", idx_name(i), o); } ret = 0; chk_failed: free(img); return ret; chk_mem_failed: ret = LIBUSB_ERROR_NO_MEM; goto chk_failed; }
/* **level\_data** is created and populated with * level specific entities. Some entities require further * initialization, such as the timeline. * A timeline allows creating a sequence of events * on a, well.. time line. Each event has a start time, * duration and callback function the will get called * each time the timeline is updated and if the event * is active. * We use a timeline to animate the title, creating 3 * events: (1) slide the title into the screen (2) * make the title "bling" and (3) slide the title out * of the screen. * Using the SECOND and SECONDS constant is for * the sake of readability only. */ static struct level_data* create_level_data(void) { struct level_data* ldata = calloc(1, sizeof(*ldata)); if (ldata == NULL) goto error; ldata->wizard = create_wizard(); if (ldata->wizard == NULL) goto cleanup_level_data; if (prepare_title(&ldata->title) != 0) goto cleanup_level_data; if (prepare_tree(&ldata->tree) != 0) goto cleanup_level_data; ldata->grass_tile = create_image("res/grass_tile.png"); if (ldata->grass_tile == NULL) goto cleanup_level_data; ldata->earth_tile = create_image("res/earth_tile.png"); if (ldata->earth_tile == NULL) goto cleanup_level_data; play_animation(ldata->tree.sprite, ldata->tree.windblow); ldata->timeline = create_timeline(); if (ldata->timeline == NULL) goto cleanup_level_data; append_event(ldata->timeline, 0, 1 * SECOND, before_title_in); append_event(ldata->timeline, 0, 1 * SECOND, slide_title_in); append_event(ldata->timeline, 0, 4 * SECONDS, bling_title); append_event(ldata->timeline, 0, 1 * SECOND, slide_title_out); ldata->font = create_font("res/font.png", 32, 4); if (ldata->font == NULL) goto cleanup_level_data; ldata->music = create_sound("res/wizard.ogg"); play_sound(ldata->music, -1); return ldata; cleanup_level_data: destroy_level_data(ldata); error: ERROR("Unable to create level data"); return NULL; }