/* 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; }
void CursorDescription::add_frame(const std::string &fullname, const ImageImportDescription &import_desc) { std::string path = PathHelp::get_fullpath(fullname, PathHelp::path_type_file); std::string filename = PathHelp::get_filename(fullname, PathHelp::path_type_file); FileSystem vfs(path); add_frame(filename, vfs, import_desc); }
void Sprite_Impl::add_gridclipped_frames(GraphicContext &gc, const Texture2D &texture, int xpos, int ypos, int width, int height, int xarray, int yarray, int array_skipframes, int xspace, int yspace) { int ystart = ypos; for(int y = 0; y < yarray; y++) { int xstart = xpos; for(int x = 0; x < xarray; x++) { if (y == yarray -1 && x >= xarray - array_skipframes) break; if(xstart + width > texture.get_width() || ystart + height > texture.get_height()) throw Exception("add_gridclipped_frames: Outside texture bounds"); add_frame(texture, Rect(xstart, ystart, xstart + width, ystart + height)); xstart += width + xspace; } ystart += height + yspace; } }
//---------------------------------------------------------------------- bool idaapi create_func_frame(func_t *pfn) { if ( pfn != NULL ) { if ( pfn->frame == BADNODE ) { ea_t ea = pfn->startEA; if ( ea + 12 < pfn->endEA) // minimum 4 + 4 + 2 + 2 bytes needed { insn_t insn[4]; for (int i=0; i<4; i++) { decode_insn(ea); insn[i] = cmd; ea += cmd.size; } if ( insn[0].itype == PIC_movff2 // movff FSR2L,POSTINC1 && insn[0].Op1.addr == PIC16_FSR2L && insn[0].Op2.addr == PIC16_POSTINC1 && insn[1].itype == PIC_movff2 // movff FSR1L,FSR2L && insn[1].Op1.addr == PIC16_FSR1L && insn[1].Op2.addr == PIC16_FSR2L && insn[2].itype == PIC_movlw // movlw <size> && insn[3].itype == PIC_addwf3 // addwf FSR1L,f && insn[3].Op1.addr == PIC16_FSR1L && insn[3].Op2.reg == F) { setflag((uint32 &)pfn->flags,FUNC_FRAME,1); return add_frame(pfn, insn[2].Op1.value, 0, 0); } } } } return 0; }
void H264Exporter::encode_frame(const uint8_t* data) { // Convert YUV to YUV420. for (uint32_t y = 0; y < _settings.height; ++y) { for (uint32_t x = 0; x < _settings.width; ++x) { _pic.img.plane[0][x + y * _settings.width] = data[4 * (x + y * _settings.width)]; } } for (uint32_t y = 0; y < _settings.height / 2; ++y) { for (uint32_t x = 0; x < _settings.width / 2; ++x) { auto c00 = 4 * (2 * x + 2 * y * _settings.width); auto c01 = 4 * (2 * x + (1 + 2 * y) * _settings.width); auto c10 = 4 * (1 + 2 * x + 2 * y * _settings.width); auto c11 = 4 * (1 + 2 * x + (1 + 2 * y) * _settings.width); _pic.img.plane[1][x + y * _settings.width / 2] = (data[1 + c00] + data[1 + c01] + data[1 + c10] + data[1 + c11]) / 4; _pic.img.plane[2][x + y * _settings.width / 2] = (data[2 + c00] + data[2 + c01] + data[2 + c10] + data[2 + c11]) / 4; } } _pic.i_pts = _frame; add_frame(&_pic); _frame++; }
bool idaapi create_func_frame(func_t *pfn) { if ( pfn == NULL ) return 0; ea_t ea = pfn->startEA; insn_t insn[4]; int i; for (i = 0; i < 4; i++) { decode_insn(ea); insn[i] = cmd; ea += cmd.size; } i = 0; ushort regsize = 0; // number of saved registers // first insn is not either push fp OR st fp, @-sp if ( (insn[i].itype != m32r_push || insn[i].Op1.reg != rFP ) && (insn[i].itype != m32r_st || insn[i].Op1.reg != rFP || insn[i].Op2.reg != rSP || insn[i].Op2.specflag1 != fRIAS)) { return 0; } regsize += 4; i++; // next insn is push lr OR st lr, @-sp if ( (insn[i].itype == m32r_push && insn[i].Op1.reg == rLR ) || (insn[i].itype == m32r_st && insn[i].Op1.reg == rFP && insn[i].Op2.reg == rLR && insn[i].Op2.specflag1 != fRIAS)) { regsize += 4; i++; } // next insn is not addi sp, #imm if ( insn[i].itype != m32r_addi || insn[i].Op1.reg != rSP ) return 0; sval_t offset = - (sval_t) insn[i].Op2.value; // toggle to the negative sign of the immediate operand of the addi insn if ( !is_invsign(insn[i].ea, get_flags_novalue(insn[i].ea), 2) ) toggle_sign(insn[i].ea, 2); i++; // next insn is not mv fp, sp if ( insn[i].itype != m32r_mv || insn[i].Op1.reg != rFP || insn[i].Op2.reg != rSP ) return 0; #if DEBUG msg("=> %d bytes\n", - (signed) insn[1].Op2.value); #endif pfn->flags |= (FUNC_FRAME | FUNC_BOTTOMBP); //setflag((uint32 &) pfn->flags, FUNC_FRAME | FUNC_BOTTOMBP, 1); return add_frame(pfn, offset, regsize, 0); }
void Sprite::set_frame(Frame f) { frames.clear(); _left=f.x_shift(); _top=f.y_shift(); _right=_left+f.width(); _bottom=_top+f.height(); add_frame(f); _counter=1; curframe=0; }
//---------------------------------------------------------------------- bool idaapi create_func_frame(func_t *pfn) { if ( pfn != NULL ) { setup_far_func(pfn); uval_t argsize = find_ret_purged(pfn); add_frame(pfn, 0, 0, argsize); } return true; }
H264Exporter::~H264Exporter() { // Flush encoder. while (x264_encoder_delayed_frames(_encoder)) { add_frame(nullptr); } x264_picture_clean(&_pic); x264_encoder_close(_encoder); _file.close(); }
//---------------------------------------------------------------------- bool create_func_frame(func_t *pfn) // create frame of newly created function { bool std_vars_func = true; if ( pfn != NULL ) { if ( pfn->frame == BADNODE ) { ea_t ea = pfn->startEA; int regsize = 0; while (ea < pfn->endEA) // check for register pushs { decode_insn(ea); ea += cmd.size; // считаем кол-во push if ( (cmd.itype == OAK_Dsp_push) && (cmd.Op1.type == o_reg) ) regsize++; else break; } ea = pfn->startEA; int16 localsize = 0; while (ea < pfn->endEA) // check for frame creation { decode_insn(ea); ea += cmd.size; // Попытка определить команду типа ADDV #,SP if ( (cmd.itype == OAK_Dsp_addv) && (cmd.Op1.type == o_imm) && (cmd.Op2.type == o_reg) && (cmd.Op2.reg == SP) ) { localsize = (uint16)cmd.Op1.value; break; } // Если встретили команду mov #, rb --> не надо создавать фрейм такой ф-ции, и объявлять локальные переменные if ( (cmd.itype == OAK_Dsp_mov) && (cmd.Op1.type == o_imm) && (cmd.Op2.type == o_reg) && (cmd.Op2.reg == RB) ) { std_vars_func = false; break; } } if (std_vars_func) { pfn->flags |= FUNC_FRAME; update_func(pfn); } add_frame(pfn, -localsize, (ushort)regsize, 0); } } return 0; }
static void add_follow_fields( GtkWidget *outer, t_ctxt *ctxt) /* * Add the fields specific to the at_msg action type which is used to * display a message to the user */ { GtkWidget *vbox; /* Follow-on mode box */ GtkWidget *none; /* Temp for button none */ GtkWidget *imm; /* Temp for button immediate */ GtkWidget *chain; /* Temp for button chain */ t_usr_ctxt *usr; usr = ctxt->usr; vbox = add_frame(outer, "Follow-on mode"); gtk_container_set_border_width(GTK_CONTAINER(vbox), PAD); none = gtk_radio_button_new_with_label(NULL, "None"); gtk_widget_set_tooltip_text(none, "This cue will wait for an explicit trigger"); imm = gtk_radio_button_new_with_label_from_widget( GTK_RADIO_BUTTON(none), "Immediate"); gtk_widget_set_tooltip_text(imm, "Start immediately after the preceeding cue (+ delay)"); chain = gtk_radio_button_new_with_label_from_widget( GTK_RADIO_BUTTON(none), "Chain"); gtk_widget_set_tooltip_text(chain, "Start after the preceeding cue has completed (+ delay)"); switch(usr->cue->follow) /* Set appropriate button */ { case fo_immediate: gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(imm), TRUE); break; case fo_chain: gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(chain), TRUE); break; default: gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(none), TRUE); } gtk_box_pack_start(GTK_BOX(vbox), none, FALSE, FALSE, 0); gtk_box_pack_start(GTK_BOX(vbox), imm, FALSE, FALSE, 0); gtk_box_pack_start(GTK_BOX(vbox), chain, FALSE, FALSE, 0); usr->fld_none = none; usr->fld_immediate = imm; usr->fld_chain = chain; } /* add_follow_fields() */
static int prepare_tree(struct tree* tree) { tree->sprite = create_sprite(create_image("res/tree.png"), 32, 32); if (tree->sprite == NULL) goto cleanup_sprite; tree->windblow = create_animation(); if (tree->windblow == NULL) goto cleanup_animation; add_frame(tree->windblow, 0, 1 * SECOND, NULL); add_frame(tree->windblow, 1, 1 * SECOND, NULL); tree->windblow->loop_from = 0; tree->windblow->loop_to = 1; return 0; cleanup_animation: destroy_animation(tree->windblow); cleanup_sprite: destroy_sprite(tree->sprite); error: ERROR("Unable to prepare tree"); return -1; }
int run_tac(unsigned start, unsigned var_count) { Tl_var result; int err = add_frame(new_frame(var_count), 0, &result); if (err != OK) return err; current_line = start; //printf("Interpreting from %d:\n", start); while ((current_line < maxline) && (current_line > 8)) { //printf(":%d:\n", current_line); Tl_var *op1 = decode_op1(ta_table[current_line].op1); Tl_var *op2 = decode_op2(ta_table[current_line].op2); Tl_var *dest = decode_dest(ta_table[current_line].dest); if (run_error != OK) return run_error; if ((op1 != NULL) && (!op1->defined)) { fprintf(stderr, "Uninitialized variable '%s'\n", ((Tlocal_sym_tab_node*)ta_table[current_line].op1)->name); return ERR_VARINIT; } if ((op2 != NULL) && (!op2->defined)) { fprintf(stderr, "Uninitialized variable '%s'\n", ((Tlocal_sym_tab_node*)ta_table[current_line].op1)->name); return ERR_VARINIT; } if (dest != NULL) dest->defined = 1; i_func f = ta_table[current_line].f; if (f == NULL) { fprintf(stderr, "Unknown instruction\n"); return ERR_RUN; } current_line++; f(op1, op2, dest); if (run_error != OK) return run_error; } return OK; }
//---------------------------------------------------------------------- bool idaapi create_func_frame(func_t *pfn) { int code = 0; if ( pfn->frame == BADNODE ) { size_t regs = 0; ea_t ea = pfn->startEA; bool bpused = false; while ( ea < pfn->endEA ) // skip all pushregs { // (must test that ea is lower // than pfn->endEA) decode_insn(ea); ea += cmd.size; switch ( cmd.itype ) { case H8_nop: continue; case H8_push: regs += get_dtyp_size(cmd.Op1.dtyp); continue; case H8_stm: if ( !issp(cmd.Op2.reg) ) break; regs += cmd.Op1.nregs * get_dtyp_size(cmd.Op1.dtyp); continue; case H8_mov: // mov.l er6, sp if ( cmd.Op1.type == o_reg && issp(cmd.Op1.reg) && cmd.Op2.type == o_reg && isbp(cmd.Op2.reg) ) bpused = true; break; default: break; } break; } uint32 frsize = 0; uint32 argsize = 0; if ( frsize != 0 || argsize != 0 || regs != 0 || bpused ) { setflag((uint32 &)pfn->flags,FUNC_FRAME,bpused); return add_frame(pfn, frsize, (ushort)regs, argsize); } } return code; }
WebmExporter::~WebmExporter() { if (_img) { vpx_img_free(_img); } // Flush encoder. while (add_frame(nullptr)) ; if (vpx_codec_destroy(&_codec)) { codec_error("failed to destroy codec"); return; } if (!_segment.Finalize()) { std::cerr << "couldn't finalise muxer segment" << std::endl; return; } _writer.Close(); }
History & History::add (const Vector<float> & present) { ASSERT_SIZE(present, m_size); // advance all frames for (Frame * f = m_frames; f; f = f->next) { f->time += 1; } // merge redundant frames of same rank for (Frame * f = m_frames; f and f->next; f = f->next) { Frame * g = f->next; if (g->rank != f->rank) { ASSERTW(g->rank == f->rank + 1, "found gap in history frames; try using higher density"); continue; } while (g->next and (g->next->rank == g->rank)) { f = g; g = g->next; } const float resolution = 0.25f; if (log_time(g->time) - log_time(f->time) < resolution) { merge_frames(f); } } // pop obsolete frames for (Frame * f = m_frames; f and f->next; f = f->next) { const float padding = 1; if (log_time(f->next->time) >= m_length + padding) { crop_to_frame(f); } } // add new frame add_frame(present); return * this; }
static void add_delay_fields( GtkWidget *outer, t_ctxt *ctxt) /* * Add the fields specific to the at_msg action type which is used to * display a message to the user */ { GtkWidget *vbox; /* Delay box */ GtkWidget *delay; /* Delay controls */ t_usr_ctxt *usr; usr = ctxt->usr; vbox = add_frame(outer, "Delay before actions start"); gtk_container_set_border_width(GTK_CONTAINER(vbox), PAD); delay = add_duration(usr->cue->delay, &(usr->fld_hours), &(usr->fld_mins), &(usr->fld_msecs)); gtk_box_pack_start(GTK_BOX(vbox), delay, FALSE, FALSE, 5); } /* add_delay_fields() */
//---------------------------------------------------------------------- bool create_func_frame(func_t *pfn) // create frame of newly created function { if ( pfn != NULL ) { if ( pfn->frame == BADNODE ) { ea_t ea = pfn->startEA; ushort regsize = 0; while (ea < pfn->endEA) // check for register pushs { decode_insn(ea); ea += cmd.size; // считаем кол-во push if ( ((cmd.itype == TMS320C3X_PUSH) || (cmd.itype == TMS320C3X_PUSHF)) && (cmd.Op1.type == o_reg) ) regsize++; else // варианты манипуляции с sp типа: LDI SP,AR3 ADDI #0001,SP игнорируем if ( ((cmd.Op1.type == o_reg) && (cmd.Op1.reg == sp)) || ((cmd.Op2.type == o_reg) && (cmd.Op2.reg == sp)) ) continue; else break; } ea = pfn->startEA; int localsize = 0; while (ea < pfn->endEA) // check for frame creation { decode_insn(ea); ea += cmd.size; // Попытка определить команду типа ADDI #0001,SP if ( (cmd.itype == TMS320C3X_ADDI) && (cmd.Op1.type == o_imm) && (cmd.Op2.type == o_reg) && (cmd.Op2.reg == sp) ) { localsize = (int)cmd.Op1.value; break; } } add_frame(pfn, localsize, regsize, 0); } } return 0; }
//---------------------------------------------------------------------- bool create_func_frame(func_t *pfn) { if ( pfn != NULL ) { if ( pfn->frame == BADNODE ) { ea_t ea = pfn->startEA; int regsize = 0; while (ea < pfn->endEA) // check for register pushs { if ( !decode_insn(ea) ) break; if (cmd.itype != TMS320C54_pshm ) break; if ( cmd.Op1.type != o_mem && cmd.Op1.type != o_mmr ) break; if ( get_mapped_register(cmd.Op1.addr) == rnone ) break; regsize++; ea += cmd.size; } int localsize = 0; while (ea < pfn->endEA) // check for frame creation { if (cmd.itype == TMS320C54_frame && cmd.Op1.type == o_imm) { localsize = -(int)cmd.Op1.value; break; } ea += cmd.size; if ( !decode_insn(ea) ) break; } add_frame(pfn, localsize+regsize, 0, 0); } } return 0; }
void setup_animations() { anm_gas_ball = malloc(sizeof(*anm_gas_ball)); anm_hand_punch = malloc(sizeof(*anm_hand_punch)); anm_blue_jelly_jiggle = malloc(sizeof(*anm_blue_jelly_jiggle)); new_animation(anm_gas_ball); add_frame(anm_gas_ball, TEX_GASEOUS_BALL_1, 1.0f); add_frame(anm_gas_ball, TEX_GASEOUS_BALL_2, 1.0f); new_animation(anm_hand_punch); add_frame(anm_hand_punch, TEX_FIST, 0.1f); add_frame(anm_hand_punch, TEX_PUNCH, 0.4f); new_animation(anm_blue_jelly_jiggle); add_frame(anm_blue_jelly_jiggle, TEX_BLUE_JELLY_1, 1.0f); add_frame(anm_blue_jelly_jiggle, TEX_BLUE_JELLY_2, 1.0f); }
void report_error_cb(JSContext* cx, const char* message, JSErrorReport* report) { /* Subtle note about JSREPORT_EXCEPTION: it triggers whenever exceptions * are raised, even if they're caught and the Mozilla docs say you can * ignore it. */ /* TODO What should we do about warnings? A callback somehow? */ if (report->flags & JSREPORT_WARNING) return; const char* srcfile = report->filename; const char* mesg = message; if(srcfile == NULL) srcfile = "<JavaScript>"; if(mesg == NULL) mesg = "Unknown JavaScript execution error"; if(!PyErr_Occurred()) { PyErr_SetString(JSError, message); } add_frame(srcfile, "JavaScript code", report->lineno); }
void WebmExporter::encode_frame(const uint8_t* data) { // Convert YUV to YUV420. for (uint32_t y = 0; y < _settings.height; ++y) { for (uint32_t x = 0; x < _settings.width; ++x) { _img->planes[VPX_PLANE_Y][x + y * _img->stride[VPX_PLANE_Y]] = data[4 * (x + y * _settings.width)]; } } for (uint32_t y = 0; y < _settings.height / 2; ++y) { for (uint32_t x = 0; x < _settings.width / 2; ++x) { auto c00 = 4 * (2 * x + 2 * y * _settings.width); auto c01 = 4 * (2 * x + (1 + 2 * y) * _settings.width); auto c10 = 4 * (1 + 2 * x + 2 * y * _settings.width); auto c11 = 4 * (1 + 2 * x + (1 + 2 * y) * _settings.width); _img->planes[VPX_PLANE_U][x + y * _img->stride[VPX_PLANE_U]] = (data[1 + c00] + data[1 + c01] + data[1 + c10] + data[1 + c11]) / 4; _img->planes[VPX_PLANE_V][x + y * _img->stride[VPX_PLANE_V]] = (data[2 + c00] + data[2 + c01] + data[2 + c10] + data[2 + c11]) / 4; } } add_frame(_img); }
int readInDatabase(struct frame_struct **db, char *Filename) { char frameName[512], sender[512], line[512]; char signalName[512],signedState, unit[512], receiverList[512]; int startBit=0,signalLength=0,byteOrder=0; float factor=0., offset=0., min=0., max=0.; char mux[4]; int muxId = 0; int frameId=0, len; FILE *fp; if(!(fp = fopen(Filename,"r"))) { fprintf(stderr, "Error opening %s\n", Filename); return 1; } while(fgets(line,511,fp)) { if(sscanf(line," BO_ %d %s %d %s",&frameId,frameName,&len,sender) == 4) { frameName[strlen(frameName)-1] = 0; add_frame(db, frameId, frameName); } else if(sscanf(line," SG_ %s : %d|%d@%d%c (%f,%f) [%f|%f] %s %s",signalName, &startBit, &signalLength,&byteOrder, &signedState, &factor, &offset, &min, &max, unit, receiverList ) > 5) { if (byteOrder == 0) { // following code is from https://github.com/julietkilo/CANBabel/blob/master/src/main/java/com/github/canbabel/canio/dbc/DbcReader.java: int pos = 7 - (startBit % 8) + (signalLength - 1); if (pos < 8) { startBit = startBit - signalLength + 1; } else { int cpos = 7 - (pos % 8); int bytes = (int)(pos / 8); startBit = cpos + (bytes * 8) + (int)(startBit/8) * 8; } } add_signal(*db, frameId, signalName, startBit, signalLength, byteOrder == 0, signedState == '-', factor, offset, min, max, unit, receiverList, 0,0); } else if(sscanf(line," SG_ %s %s : %d|%d@%d%c (%f,%f) [%f|%f] %s %s",signalName, mux, &startBit, &signalLength,&byteOrder, &signedState, &factor, &offset, &min, &max, unit, receiverList ) > 5) { if (byteOrder == 0) { // following code is from https://github.com/julietkilo/CANBabel/blob/master/src/main/java/com/github/canbabel/canio/dbc/DbcReader.java: int pos = 7 - (startBit % 8) + (signalLength - 1); if (pos < 8) { startBit = startBit - signalLength + 1; } else { int cpos = 7 - (pos % 8); int bytes = (int)(pos / 8); startBit = cpos + (bytes * 8) + (int)(startBit/8) * 8; } } if(mux[0] == 'M') { add_signal(*db, frameId, signalName, startBit, signalLength, byteOrder == 0, signedState == '-', factor, offset, min, max, unit, receiverList, 1, 0); } else if(mux[0] == 'm') { sscanf(mux, "m%d", &muxId); add_signal(*db, frameId, signalName, startBit, signalLength, byteOrder == 0, signedState == '-', factor, offset, min, max, unit, receiverList, 2, muxId); } } } return 0; }
void Sprite_Impl::add_alphaclipped_frames_free(GraphicContext &gc, const Texture2D &texture, int xpos, int ypos, float trans_limit) { PixelBuffer alpha_buffer = texture.get_pixeldata(gc, tf_rgba8).to_cpu(gc); int width = alpha_buffer.get_width(); int height = alpha_buffer.get_height(); std::vector<int> explored_vector; explored_vector.resize(width * height); int *explored = &(explored_vector[0]); memset(explored, 0, width * height * sizeof(int)); Vec4ub *data = alpha_buffer.get_data<Vec4ub>(); int x1, y1, x2, y2; bool more; for (int y=ypos; y < height; y++) { for (int x=xpos; x < width; x++) { if (explored[y*width+x] == 1) continue; explored[y*width+x] = 1; if (data[y*width+x].a <= trans_limit*255) continue; // Initialize the bounding box to the current pixel x1 = x2 = x; y1 = y2 = y; more = true; while (more) { // Assume that there are NO opaque pixels around the current bounding box more = false; // Scan under the current bounding box and see if there any non-transparent pixels for (int i = x1; i <= x2; i++) { if (y2 + 1 < height) { explored[(y2+1)*width+i] = 1; if (data[(y2+1)*width+i].a > trans_limit*255) { more = true; y2 = y2 + 1; } } } // Now scan the left and right sides of the current bounding box for (int j = y1; j <= y2; j++) { // Scan the right side if (x2 + 1 < width) { explored[j*width + x2+1] = 1; if (data[j*width + x2+1].a > trans_limit*255) { more = true; x2 = x2 + 1; } } // Scan the left side if (x1 - 1 >= 0) { explored[j*width + x1-1] = 1; if (data[j*width + x1-1].a > trans_limit*255) { more = true; x1 = x1 - 1; } } } } // Mark all pixels in the bounding box as being explored for (int i = x1; i <= x2; i++) { for (int j = y1; j <= y2; j++) { explored[j*width+i] = 1; } } add_frame(texture, Rect(x1, y1, x2, y2)); } } }
void Sprite_Impl::add_alphaclipped_frames(GraphicContext &gc, const Texture2D &texture, int xpos, int ypos, float trans_limit) { PixelBuffer alpha_buffer = texture.get_pixeldata(gc, tf_rgba8).to_cpu(gc); int begin = 0; bool prev_trans = true; int alpha_width = alpha_buffer.get_width(); int alpha_height = alpha_buffer.get_height(); bool found_opaque = false; bool found_trans = false; std::vector<int> opaque_row_vector; opaque_row_vector.resize(alpha_width); int *opaque_row = &(opaque_row_vector[0]); memset(opaque_row, 0, alpha_width*sizeof(int)); int cut_top = ypos; int cut_bottom = alpha_height; char *data = (char *) alpha_buffer.get_data(); for (int y=ypos; y < alpha_height; y++) { bool opaque_line = false; Vec4ub *line = (Vec4ub *) (data + alpha_buffer.get_pitch()*y); for (int x=0; x < alpha_width; x++) { if (line[x].a > trans_limit*255) { opaque_row[x] = 1; opaque_line = true; found_opaque = true; } } if (opaque_line == false) // cut something of top or bottom { if (found_opaque) { cut_bottom--; found_trans = true; } else cut_top ++; } else if (found_trans) { found_trans = false; cut_bottom = alpha_height; } } if (cut_top >= cut_bottom) throw Exception("add_alphaclipped_frames: Image contained only alpha!"); for(int x=xpos; x < alpha_width; x++) { if(opaque_row[x] && prev_trans) { begin = x; prev_trans = false; } else if (!opaque_row[x] && !prev_trans) { add_frame(texture, Rect(begin, cut_top, x+1, cut_bottom)); prev_trans = true; } } if (!prev_trans) { add_frame(texture, Rect(begin, cut_top, alpha_width, cut_bottom)); } }
Sprite::Sprite(Canvas &canvas, IODevice &file, const std::string &image_type, const ImageImportDescription &import_desc ) : impl(std::make_shared<Sprite_Impl>()) { add_frame(canvas, file, image_type, import_desc ); restart(); }
Sprite::Sprite(Canvas &canvas, const std::string &filename, const FileSystem &fs, const ImageImportDescription &import_desc) : impl(std::make_shared<Sprite_Impl>()) { add_frame(canvas, filename, fs, import_desc ); restart(); }
void CursorDescription::add_frame(IODevice &file, const std::string &image_type, const ImageImportDescription &import_desc) { PixelBuffer image = ImageProviderFactory::load(file, image_type); image = import_desc.process(image); add_frame(image); }
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; }
void CursorDescription::add_frame(const std::string &filename, FileSystem &fs, const ImageImportDescription &import_desc) { PixelBuffer image = ImageProviderFactory::load(filename, fs, ""); image = import_desc.process(image); add_frame(image); }