/* ======================================= 生成 DX8 图形离屏表面 ======================================= */ CR_API iGFX2_DX8S* create_dx8_bitmap ( __CR_IN__ iGFX2_DX8M* device, __CR_IN__ sD3D8_TEXR* texture, __CR_IN__ bool_t dynamic ) { iGFX2_DX8S* rett; /* 必须是 2D 贴图 */ if (texture->face != 1) return (NULL); /* 生成对象并设置图片参数 */ rett = struct_new(iGFX2_DX8S); if (rett == NULL) return (NULL); if (!image_set(&rett->__back__, NULL, (leng_t)(-1L), 0, 0, texture->info.Width, texture->info.Height, image_d3d_to_crh(texture->info.Format), FALSE, 8)) { rect_set_wh(&rett->__back__.clip_win, 0, 0, texture->info.Width, texture->info.Height); struct_cpy(&rett->__back__.position, &rett->__back__.clip_win, sRECT); } /* 返回生成的对象 */ rett->__vptr__ = &s_bitmap_vtbl; rett->m_flags = dynamic ? D3DLOCK_DISCARD : 0; rett->m_device = device; rett->m_texture = texture; return (rett); }
//! pembuatan view GtkWidget *tableCreate (void){ table = struct_new(table_); databaseCreate(); GtkTreeModel *model; table->view = gtk_tree_view_new(); //header GtkTreeViewColumn *col = tableCreateHeader(table->view); /* connect a cell data function */ model = create_and_fill_model(""); gtk_tree_view_set_model(GTK_TREE_VIEW(table->view), model); g_object_unref(model); /* destroy model automatically with view */ gtk_tree_selection_set_mode(gtk_tree_view_get_selection(GTK_TREE_VIEW(table->view)),GTK_SELECTION_SINGLE); gtk_tree_view_set_headers_clickable (table->view,TRUE); gtk_tree_view_set_rules_hint (table->view,TRUE); gtk_tree_view_set_grid_lines(table->view, GTK_TREE_VIEW_GRID_LINES_HORIZONTAL ); g_object_set( table->view ,"hover-selection" , TRUE,NULL); g_signal_connect(table->view, "button-press-event", (GCallback) table_onButtonPressed, NULL); return table->view; }
static gboolean table_onButtonPressed(GtkWidget *treeview, GdkEventButton *event, gpointer userdata){ dataToSend_ *dataToSend; /* single click with the right mouse button? */ if (event->type == GDK_BUTTON_PRESS && event->button == 3){ g_print ("Single right click on the tree view.\n"); if (1){ GtkTreeSelection *selection; selection = gtk_tree_view_get_selection(GTK_TREE_VIEW(treeview)); //! Note: gtk_tree_selection_count_selected_rows() does not exist in gtk+-2.0, only in gtk+ >= v2.2 if (gtk_tree_selection_count_selected_rows(selection) <= 1){ GtkTreePath *path; //! Get tree path for row that was clicked if (gtk_tree_view_get_path_at_pos(GTK_TREE_VIEW(treeview),(gint) event->x, (gint) event->y,&path, NULL, NULL, NULL)){ gtk_tree_selection_unselect_all(selection); gtk_tree_selection_select_path(selection, path); gtk_tree_path_free(path); GtkTreeModel *model; GtkTreeIter iter; if (gtk_tree_selection_get_selected(selection, &model, &iter)){ dataToSend = struct_new(dataToSend_); gtk_tree_model_get (model, &iter, 0, &dataToSend->id, -1); gtk_tree_model_get (model, &iter, 5, &dataToSend->file, -1); } } } } table_popup_menu(treeview, event, dataToSend); return TRUE; /* we handled this */ } return FALSE; /* we did not handle this */ }
/* =============================================================== */ atree_unit<T>* insert (atree_unit<T>* node, const T* obj, size_t idx) { cnode_ptr next; atree_unit<T>* nnew; list2<cnode_ptr>* list; list2_unit<cnode_ptr>* unit; nnew = struct_new(atree_unit<T>); if (nnew == NULL) return (NULL); next.ptr = (void*)nnew; list = &node->next; if (idx >= list->size()) { unit = list->append(&next); } else if (idx == 0) { unit = list->sthead(&next); } else { unit = list->get(idx); unit = list->insert(unit, &next); } if (unit == NULL) { mem_free(nnew); return (NULL); } m_cnts += 1; nnew->node = unit; nnew->uppe = node; nnew->deep = node->deep + 1; mem_cpy(&nnew->user, obj, sizeof(T)); nnew->next.init(); return (nnew); }
static Interpreter __Interpreter_new (Value filePath) { Interpreter node = struct_new(Interpreter); InitFunc func = NULL; node->filePath = filePath; at_currentInterpreter = node; yylineno = 1; if (filePath) { if (func = LIB_getInitFunc(filePath->u.string)) { node->result = func(); return node; } yyin = fopen(filePath->u.string, "rt"); if (!yyin) { perror(filePath->u.string); return NULL; } yyrestart(yyin); yyparse(); fclose(yyin); } else { //yyin = stdin; printf("Interpreter._new: yyparse\n"); //yyrestart(yyin); yyparse(); printf("Interpreter._new: yyparse end\n"); } node->result = Procedure_eval(node->proc, node->proc->exp); return node; }
/* ======================================= SZ20 文件读取 ======================================= */ CR_API sFMT_DAT* load_ms_sz20 ( __CR_IO__ iDATIN* datin, __CR_IN__ const sLOADER* param ) { leng_t pksz; leng_t unsz; void_t* data; void_t* temp; sFMT_DAT* rett; sSZ20_HDR head; /* 这个参数可能为空 */ if (datin == NULL) return (NULL); /* 读取 & 检查头部 */ if (!(CR_VCALL(datin)->geType(datin, &head, sSZ20_HDR))) return (NULL); if (mem_cmp(head.tag, "SZ\x20\x88\xF0\x27\x33\xD1", 8) != 0) return (NULL); /* 读取所有后续数据 */ temp = CR_VCALL(datin)->get(datin, &pksz, FALSE); if (temp == NULL) return (NULL); /* 分配目标数据缓冲 */ head.unsize = DWORD_LE(head.unsize); data = mem_malloc32(head.unsize); if (data == NULL) { mem_free(temp); return (NULL); } unsz = (leng_t)(head.unsize); pksz = uncompr_lzss(data, unsz, temp, pksz, 0x20); mem_free(temp); if (pksz != unsz) goto _failure; /* 返回读取的文件数据 */ rett = struct_new(sFMT_DAT); if (rett == NULL) goto _failure; CR_NOUSE(param); rett->type = CR_FMTZ_DEC; rett->unsz = unsz; rett->pksz = dati_get_size(datin); rett->data = data; rett->infor = "Microsoft Compressed (SZ20) file"; return (rett); _failure: mem_free(data); return (NULL); }
void waktuCreate(GtkWidget* widget){ waktu = struct_new(waktu_); curtime = time(NULL); loctime = localtime(&curtime); waktu->tanggal = strdup(""); waktuUpdate(); childCreate(widget); alarmCreate(widget); }
/* ======================================= TGL IEL1 文件读取 ======================================= */ CR_API sFMT_DAT* load_tgl_iel1 ( __CR_IO__ iDATIN* datin, __CR_IN__ const sLOADER* param ) { leng_t pksz; leng_t unsz; void_t* data; void_t* temp; sFMT_DAT* rett; sIEL1_HDR head; /* 这个参数可能为空 */ if (datin == NULL) return (NULL); /* 读取 & 检查头部 */ if (!(CR_VCALL(datin)->geType(datin, &head, sIEL1_HDR))) return (NULL); if (head.magic != mk_tag4("IEL1")) return (NULL); /* 读取所有后续数据 */ temp = CR_VCALL(datin)->get(datin, &pksz, FALSE); if (temp == NULL) return (NULL); /* 分配目标数据缓冲 */ head.unsize = DWORD_LE(head.unsize); data = mem_malloc32(head.unsize); if (data == NULL) { mem_free(temp); return (NULL); } unsz = (leng_t)(head.unsize); pksz = uncompr_lzss(data, unsz, temp, pksz, 0); mem_free(temp); if (pksz != unsz) goto _failure; /* 返回读取的文件数据 */ rett = struct_new(sFMT_DAT); if (rett == NULL) goto _failure; CR_NOUSE(param); rett->type = CR_FMTZ_DEC; rett->unsz = unsz; rett->pksz = dati_get_size(datin); rett->data = data; rett->infor = "TGL LZSS Compressed file (IEL1)"; return (rett); _failure: mem_free(data); return (NULL); }
//! ketika tombol add di tekan maka akan kesini gboolean modifAdd(gpointer call,GtkWidget* parent){ gboolean status = FALSE; //modifGetWidgetLama(parent); modifStruct_ *modif = struct_new(modifStruct_); GtkWidget *w = modifGetDialogWithStruct(parent , modif ,"Menambah Data"); gtk_widget_show_all(w); gint result = gtk_dialog_run ((GtkDialog *) w); // block if (result==GTK_RESPONSE_OK){ //! mencari total row const gchar *exe = "select max(id) from isi "; databaseExe(exe); char **data = databaseGetData(); int totalRow = databaseGetTotalRow(); databaseFreeData(); //! mengambil data char *filename; char* jamchar = globalPutZeroToWkt(gtk_spin_button_get_value_as_int((GtkSpinButton *) modif->jam)); char* mntchar = globalPutZeroToWkt(gtk_spin_button_get_value_as_int((GtkSpinButton *) modif->mnt)); gchar *jamMnt = g_strdup_printf ("%s:%s", jamchar,mntchar); gchar * hari = gtk_combo_box_get_active_text ( (GtkComboBox *) modif->hari); gchar * bagian = gtk_combo_box_get_active_text ( (GtkComboBox *) modif->bagian ); gint total = gtk_spin_button_get_value_as_int ( (GtkSpinButton *) modif->total); filename = fuGetNameFile( gtk_button_get_label( (GtkButton *) modif->filePilih)); //! insert into database gint idHari = databaseGetIdHari(hari); GValueArray* varr = g_value_array_new (-1); GValue a = {0}; g_assert (!G_VALUE_HOLDS_STRING (&a)); g_value_init (&a, G_TYPE_INT); g_value_set_int (&a, totalRow+1); //! 1 varr = g_value_array_append(varr,&a); g_value_set_int (&a, idHari); //! 2 varr = g_value_array_append(varr,&a); g_value_set_int (&a, total); //! 3 varr = g_value_array_append(varr,&a); g_value_unset (&a); g_value_init (&a, G_TYPE_STRING); g_value_set_string (&a, jamMnt); //! 4 varr = g_value_array_append(varr,&a); g_value_set_string (&a, bagian); //! 5 varr = g_value_array_append(varr,&a); g_value_set_string (&a, filename); //! 6 varr = g_value_array_append(varr,&a); GValueArray *hasil = databaseGetDatasFromDb("insert into isi (id,dal,X,jam,bagian,alarm) values (?,?,?,?,?,?)" , varr , &status); status = TRUE; //! free g_value_array_free (varr); g_value_array_free (hasil); g_free(jamMnt); g_free(hari); g_free(bagian); } g_free(modif); gtk_widget_destroy(w); return status; }
Procedure Procedure_new (Procedure meta, Assoc assoc, Value at, Value me, Exp exp) { Procedure node = struct_new(Procedure); node->meta = meta; node->assoc = assoc; node->at = at; node->me = me; node->exp = exp; node->active = 1; return node; }
//! pertama int databaseCreate(){ g_print("Database Create\n."); lastHeaderNumber = 0; sort = FALSE; sqlite = struct_new(sqlite_); if( sqlite3_open ("dal", & sqlite->db) != 0){ //! do something g_print("Could not open database."); return -1; } return 0; }
Interpreter Interpreter_init () { if (__interpreterTable) return __interpreterTable; Interpreter self = struct_new(Interpreter); Assoc assoc = Assoc_new(); Assoc_set(assoc, Value_string("True"), at_True); Assoc_set(assoc, Value_string("Number"), at_Number); Assoc_set(assoc, Value_string("String"), at_String); Assoc_set(assoc, Value_string("Array"), at_Array); Assoc_set(assoc, Value_string("Function"), at_Function); self->proc = (at_rootProcedure = Procedure_new(NULL, assoc, NULL, NULL, NULL)); __interpreterTable = self; return self; }
/* ================== */ bool init (const T* obj) { m_root = struct_new(atree_unit<T>); if (m_root == NULL) return (false); m_cnts = 1; m_root->node = NULL; m_root->uppe = NULL; m_root->deep = 0; mem_cpy(&m_root->user, obj, sizeof(T)); m_root->next.init(); return (true); }
int main(){ printf("Debug On"); circular_vector* addr = struct_init(); unsigned long pin[8] = {8,7,6,5,4,3,2,1}; unsigned long pos[8] = {42,42,42,42,42,42,42,42}; struct_new(addr,STRUCT_AVANT); struct_next(addr); struct_set_From_Array(addr,pin,pos); struct_list(addr); struct_free_circular_vector(addr); }
/* ======================================= KrKr XP3 文件读取 ======================================= */ CR_API sFMT_PRT* load_krkr_xp3 ( __CR_IO__ iDATIN* datin, __CR_IN__ const sLOADER* param ) { int16u idx; int16u len; int32u attr; int64u tots; int64u tsz1; int64u tsz2; int64u pksz; int64u unsz; leng_t back; sARRAY list; byte_t* info; byte_t* pntr; wide_t* name; sXP3_HDR head; iPAK_XP3* port; sFMT_PRT* rett; sPAK_XP3_FILE temp; /* 必须使用自己私有的读取接口 */ datin = create_file_inX(param); if (datin == NULL) return (NULL); array_initT(&list, sPAK_XP3_FILE); list.free = xp3_free; /* 读取文件头信息 */ if (!(CR_VCALL(datin)->geType(datin, &head, sXP3_HDR))) goto _failure1; if (mem_cmp(head.tag, "XP3\r\n \n\x1A\x8B\x67\x01", 11) != 0) goto _failure1; head.idx_pos = QWORD_LE(head.idx_pos); /* 读取文件索引表 */ if (!CR_VCALL(datin)->seek64(datin, head.idx_pos, SEEK_SET)) goto _failure1; if (!CR_VCALL(datin)->getb_no(datin, head.tag)) goto _failure1; if (head.tag[0]) { /* ZLib 压缩的索引表 */ if (!CR_VCALL(datin)->getq_le(datin, &pksz)) goto _failure1; if (!CR_VCALL(datin)->getq_le(datin, &unsz)) goto _failure1; pntr = (byte_t*)mem_malloc64(pksz); if (pntr == NULL) goto _failure1; back = CR_VCALL(datin)->read(datin, pntr, (leng_t)pksz); if (back != (leng_t)pksz) { mem_free(pntr); goto _failure1; } info = (byte_t*)mem_malloc64(unsz); if (info == NULL) { mem_free(pntr); goto _failure1; } back = uncompr_zlib(info, (leng_t)unsz, pntr, (leng_t)pksz); mem_free(pntr); if (back != (leng_t)unsz) goto _failure2; } else { /* 直接读起索引表 */ if (!CR_VCALL(datin)->getq_le(datin, &unsz)) goto _failure1; info = (byte_t*)mem_malloc64(unsz); if (info == NULL) goto _failure1; back = CR_VCALL(datin)->read(datin, info, (leng_t)unsz); if (back != (leng_t)unsz) goto _failure2; } /* 设置加密类型 (如果有的话) */ if (param->aprm != NULL && *(byte_t*)param->aprm != 0x00) attr = PAK_FILE_ENC; else attr = 0; /* 加载文件信息表 */ for (pntr = info, pksz = 0; pksz < unsz;) { /* "File" 数据块 */ if (mem_cmp(pntr, "File", 4) != 0) break; mem_cpy(&tots, pntr + 4, sizeof(int64u)); tots = QWORD_LE(tots); pntr += 12; pksz += 12; if (tots <= 12 + 22 + 12 + 28 || tots > unsz - pksz) goto _failure2; /* "info" 文件总信息 */ if (mem_cmp(pntr, "info", 4) != 0) goto _failure2; mem_cpy(&tsz1, pntr + 4, sizeof(int64u)); tsz1 = QWORD_LE(tsz1); pntr += 12; pksz += 12; if (tsz1 <= 22 || tsz1 > tots - 12 - 12 - 28) goto _failure2; /* 填充一些文件信息结构成员 */ struct_zero(&temp, sPAK_XP3_FILE); mem_cpy(&temp.protect, pntr + 0, sizeof(int32u)); mem_cpy(&temp.base.size, pntr + 4, sizeof(int64u)); mem_cpy(&temp.base.pack, pntr + 12, sizeof(int64u)); temp.base.skip = sizeof(sPAK_XP3_FILE); temp.base.attr = attr; temp.protect = DWORD_LE(temp.protect); temp.base.size = QWORD_LE(temp.base.size); temp.base.pack = QWORD_LE(temp.base.pack); /* 读取文件名 UTF-16 无\0结尾 */ mem_cpy(&len, pntr + 20, sizeof(int16u)); len = WORD_LE(len); if ((int64u)len > tsz1 - 22) goto _failure2; name = str_allocW(len + 1); if (name == NULL) goto _failure2; for (idx = 0; idx < len; idx++) { mem_cpy(&name[idx], pntr + 22 + ((leng_t)idx) * 2, 2); name[idx] = WORD_LE(name[idx]); } name[idx] = 0x0000; temp.base.name = utf16_to_utf8(name); mem_free(name); if (temp.base.name == NULL) goto _failure2; pntr += (leng_t)tsz1; pksz += (leng_t)tsz1; /* "segm" 文件分段信息 */ if (mem_cmp(pntr, "segm", 4) != 0) goto _failure3; mem_cpy(&tsz2, pntr + 4, sizeof(int64u)); tsz2 = QWORD_LE(tsz2); pntr += 12; pksz += 12; if (tsz2 < 28 || tsz2 % 28 != 0 || tsz2 > tots - 12 - tsz1 - 12) goto _failure3; /* 读取所有分段信息 */ temp.segm_lst = mem_talloc64(tsz2 / 28, sPAK_XP3_SEGM); if (temp.segm_lst == NULL) goto _failure3; temp.segm_cnt = (leng_t)(tsz2 / 28); mem_cpy(temp.segm_lst, pntr, (leng_t)tsz2); for (back = 0; back < temp.segm_cnt; back++) { temp.segm_lst[back].zlib = DWORD_LE(temp.segm_lst[back].zlib); temp.segm_lst[back].offset = QWORD_LE(temp.segm_lst[back].offset); temp.segm_lst[back].unsize = QWORD_LE(temp.segm_lst[back].unsize); temp.segm_lst[back].pksize = QWORD_LE(temp.segm_lst[back].pksize); if (temp.segm_lst[back].unsize > temp.base.size) goto _failure4; if (temp.segm_lst[back].pksize > temp.base.pack) goto _failure4; } pntr += (leng_t)tsz2; pksz += (leng_t)tsz2; /* 其他非重要数据段 */ if (tots > 12 + tsz1 + 12 + tsz2) { tots -= 12 + tsz1 + 12 + tsz2; /* "adlr" 附加数据 */ if (mem_cmp(pntr, "adlr", 4) == 0) { if (tots < 16) goto _failure4; mem_cpy(&temp.adlr_key, pntr + 4, sizeof(int32u)); temp.adlr_key = DWORD_LE(temp.adlr_key); } pntr += (leng_t)tots; pksz += (leng_t)tots; } /* 用第一段设置剩下的成员 */ temp.base.offs = temp.segm_lst[0].offset; if (temp.segm_lst[0].zlib) { if (attr == 0) temp.base.memo = "ZLib"; else temp.base.memo = "ZLib + Encrypt"; temp.base.attr |= PAK_FILE_CMP; } else { if (attr == 0) temp.base.memo = "Store"; else temp.base.memo = "Encrypt"; } /* 文件信息压入列表 */ if (array_push_growT(&list, sPAK_XP3_FILE, &temp) == NULL) goto _failure4; } mem_free(info); /* 固定一下列表大小 */ if (!array_no_growT(&list, sPAK_XP3_FILE)) goto _failure1; /* 生成读包接口对象 */ port = struct_new(iPAK_XP3); if (port == NULL) goto _failure1; port->m_file = datin; port->m_cnt = array_get_sizeT(&list, sPAK_XP3_FILE); port->pack.__filelst__ = array_get_dataT(&list, sPAK_FILE); port->pack.__vptr__ = &s_pack_vtbl; if (!pack_init_list((iPACKAGE*)port, TRUE)) { mem_free(port); goto _failure1; } /* 设置解密回调 (传入名称字符串) */ if (attr != 0) { decode_setup(port, (ansi_t*)param->aprm); } else { port->decode_file = NULL; port->decode_block = NULL; } /* 返回读取的文件数据 */ rett = struct_new(sFMT_PRT); if (rett == NULL) { iPAK_XP3_release((iPACKAGE*)port); return (NULL); } rett->type = CR_FMTZ_PRT; rett->port = (iPORT*)port; rett->more = "iPACKAGE"; rett->infor = "KiriKiri2 XP3 Archive (XP3)"; return (rett); _failure4: mem_free(temp.segm_lst); _failure3: mem_free(temp.base.name); _failure2: mem_free(info); _failure1: array_freeT(&list, sPAK_XP3_FILE); CR_VCALL(datin)->release(datin); return (NULL); }
/* ======================================= TGL CGR 文件读取 ======================================= */ CR_API sFMT_PIC* load_tgl_cgr ( __CR_IO__ iDATIN* datin, __CR_IN__ const sLOADER* param ) { int32u wnh[2]; uint_t ww, hh; /*************/ byte_t* line; fsize_t size; sFMT_PIC* rett; sFMT_FRAME temp; /* 这个参数可能为空 */ if (datin == NULL) return (NULL); /* 只能根据文件大小来判断 */ size = dati_get_size(datin); if (size <= 0x600 + 12) return (NULL); if (!CR_VCALL(datin)->seek(datin, 0x600, SEEK_SET)) return (NULL); if (CR_VCALL(datin)->read(datin, wnh, 8) != 8) return (NULL); wnh[0] = DWORD_LE(wnh[0]); wnh[1] = DWORD_LE(wnh[1]); size = wnh[0]; size *= wnh[1]; size += 0x600 + 12; if (size != dati_get_size(datin)) return (NULL); /* 对宽高的截断检查 */ if (cut_int32_u(&ww, wnh[0])) return (NULL); if (cut_int32_u(&hh, wnh[1])) return (NULL); /* 定位到调色板 */ if (!CR_VCALL(datin)->rewind(datin)) return (NULL); /* 生成图片对象 */ mem_zero(temp.wh, sizeof(temp.wh)); temp.fmt = CR_PIC_PALS; temp.bpp = 8; temp.clr = "P"; temp.wh[0] = 8; temp.pic = image_new(0, 0, ww, hh, CR_INDEX8, FALSE, 4); if (temp.pic == NULL) return (NULL); /* 读取调色板数据 */ if (CR_VCALL(datin)->read(datin, temp.pic->pal, 1024) != 1024) goto _failure; line = temp.pic->data; pal_4b_alp_sw(temp.pic->pal, TRUE, 0xFF, 256); /* 定位到图片数据 */ if (!CR_VCALL(datin)->seek(datin, 0x600 + 12, SEEK_SET)) goto _failure; /* 读取图片数据 */ for (; hh != 0; hh--) { if (CR_VCALL(datin)->read(datin, line, ww) != ww) goto _failure; line += temp.pic->bpl; } /* 返回读取的文件数据 */ rett = struct_new(sFMT_PIC); if (rett == NULL) goto _failure; rett->frame = struct_dup(&temp, sFMT_FRAME); if (rett->frame == NULL) { mem_free(rett); goto _failure; } CR_NOUSE(param); rett->type = CR_FMTZ_PIC; rett->count = 1; rett->infor = "TGL CGR Image File (CGR)"; return (rett); _failure: image_del(temp.pic); return (NULL); }
/* ======================================= PNG 文件读取 ======================================= */ CR_API sFMT_PIC* load_cr_png ( __CR_IO__ iDATIN* datin, __CR_IN__ const sLOADER* param ) { leng_t nbpl; leng_t sbpp; leng_t dptr; uint_t fcrh; uint_t index; uchar* image; uchar* sdata; uchar* ddata; leng_t dsize; int32u ssize; uint_t ww, hh; byte_t pal[768]; /* ----------- */ fsize_t fsze; sPNG_HDR head; sFMT_PIC* rett; sFMT_FRAME temp; /* 这个参数可能为空 */ if (datin == NULL) return (NULL); /* 读取 & 检查头部 */ if (!(CR_VCALL(datin)->geType(datin, &head, sPNG_HDR))) return (NULL); if (mem_cmp(&head, "\x89PNG\r\n\x1A\n\0\0\0\x0DIHDR", 16) != 0) return (NULL); if (head.info.compr != 0 || head.info.filter != 0 || head.info.interlace != 0) return (NULL); /* 对宽高的截断检查 */ if (cut_int32_u(&ww, DWORD_BE(head.info.w))) return (NULL); if (cut_int32_u(&hh, DWORD_BE(head.info.h))) return (NULL); /* 生成图片对象 */ mem_zero(temp.wh, sizeof(temp.wh)); switch (head.info.color) { case 0: /* 灰度图像 */ if (head.info.depth != 1 && head.info.depth != 2 && head.info.depth != 4 && head.info.depth != 8 && head.info.depth != 16) return (NULL); fcrh = CR_INDEX8; temp.fmt = CR_PIC_GREY; temp.bpp = head.info.depth; temp.clr = "I"; temp.wh[0] = head.info.depth; break; case 2: /* 真彩图像 */ if (head.info.depth != 8 && head.info.depth != 16) return (NULL); fcrh = CR_ARGB888; temp.fmt = CR_PIC_ARGB; temp.bpp = head.info.depth * 3; temp.clr = "BGR"; temp.wh[0] = head.info.depth; temp.wh[1] = head.info.depth; temp.wh[2] = head.info.depth; break; case 3: /* 索引图像 */ if (head.info.depth != 1 && head.info.depth != 2 && head.info.depth != 4 && head.info.depth != 8) return (NULL); fcrh = CR_INDEX8; temp.fmt = CR_PIC_PALS; temp.bpp = head.info.depth; temp.clr = "P"; temp.wh[0] = head.info.depth; break; case 4: /* α灰度图像 */ if (head.info.depth != 8 && head.info.depth != 16) return (NULL); fcrh = CR_ARGB8888; temp.fmt = CR_PIC_GREY; temp.bpp = head.info.depth * 2; temp.clr = "AI"; temp.wh[0] = head.info.depth; temp.wh[1] = head.info.depth; break; case 6: /* α真彩图像 */ if (head.info.depth != 8 && head.info.depth != 16) return (NULL); fcrh = CR_ARGB8888; temp.fmt = CR_PIC_ARGB; temp.bpp = head.info.depth * 4; temp.clr = "ABGR"; temp.wh[0] = head.info.depth; temp.wh[1] = head.info.depth; temp.wh[2] = head.info.depth; temp.wh[3] = head.info.depth; break; default: return (NULL); } sbpp = (temp.bpp - 1) / 8 + 1; temp.pic = image_new(0, 0, ww, hh, fcrh, FALSE, 4); if (temp.pic == NULL) return (NULL); /* 生成灰度调色板 */ if (temp.fmt == CR_PIC_GREY) pal_set_gray8(temp.pic->pal, 256); /* 分配 IDAT 的内存 */ fsze = dati_get_size(datin); if (fsze <= sizeof(sPNG_HDR) + sizeof(sIEND) * 2) goto _failure1; fsze -= sizeof(sPNG_HDR) + sizeof(sIEND) * 2; ddata = (byte_t*)mem_malloc64(fsze); if (ddata == NULL) goto _failure1; dsize = (leng_t)fsze; /* 读取数据块 */ dptr = 0; fcrh = 256; /* 这个保存调色板颜色数 */ do { /* 数据块大小 */ if (!(CR_VCALL(datin)->geType(datin, &head.info, sCHUNK))) goto _failure2; ssize = DWORD_BE(head.info.head.size); if (ssize > fsze) goto _failure2; if (head.info.head.name == mk_tag4("PLTE")) { /* 调色板, 安全检查 */ if (ssize > 768 || ssize % 3 != 0) goto _failure2; if (CR_VCALL(datin)->read(datin, pal, ssize) != ssize) goto _failure2; /* 转换到 4B 格式 */ fcrh = (uint_t)ssize / 3; pal_3b_to_4b_sw(temp.pic->pal, pal, fcrh); } else if (head.info.head.name == mk_tag4("IDAT")) { /* 检查缓冲溢出 */ if (dsize < ssize) goto _failure2; if (CR_VCALL(datin)->read(datin, ddata + dptr, ssize) != ssize) goto _failure2; dptr += ssize; dsize -= ssize; } else if (head.info.head.name == mk_tag4("tRNS")) { /* 透明数据 */ if (head.info.color == 0) { if (ssize != 2) goto _failure2; if (CR_VCALL(datin)->read(datin, pal, 2) != 2) goto _failure2; /* 调色板的这个颜色为透明色 */ if (head.info.depth != 16) temp.pic->pal[pal[1]] &= CDWORD_LE(0x00FFFFFFUL); } else if (head.info.color == 2) { if (ssize != 6) goto _failure2; if (CR_VCALL(datin)->read(datin, pal, 6) != 6) goto _failure2; /* 这个颜色为透明色, 这里只能展开来写 否则 C++Builder 2010 编译器编译时会崩溃 */ if (head.info.depth != 16) { temp.pic->keycolor = pal[1]; temp.pic->keycolor <<= 8; temp.pic->keycolor |= pal[3]; temp.pic->keycolor <<= 8; temp.pic->keycolor |= pal[5]; temp.pic->keycolor |= 0xFF000000UL; temp.pic->keycolor = DWORD_LE(temp.pic->keycolor); } } else if (head.info.color == 3) { if (ssize > fcrh) goto _failure2; if (CR_VCALL(datin)->read(datin, pal, ssize) != ssize) goto _failure2; /* 设置调色板的 Alpha 通道 */ for (fcrh = (uint_t)ssize, index = 0; index < fcrh; index++) ((uchar*)temp.pic->pal)[index * 4 + 3] = pal[index]; } else { goto _failure2; } } else { /* 跳过其他数据块 */ if (!CR_VCALL(datin)->seek(datin, ssize, SEEK_CUR)) goto _failure2; } /* 跳过 CRC-32 */ if (!CR_VCALL(datin)->seek(datin, 4, SEEK_CUR)) goto _failure2; } while (head.info.head.name != mk_tag4("IEND")); /* 无 IDAT 块 */ if (dptr == 0) goto _failure2; /* 分配带 filter 的图形内存 */ if (cut_mad(&dsize, ww, sbpp * hh, hh)) goto _failure2; sdata = (byte_t*)mem_malloc(dsize); if (sdata == NULL) goto _failure2; /* 解压图形数据 */ dptr = uncompr_zlib(sdata, dsize, ddata, dptr); mem_free(ddata); ddata = sdata; if (dptr <= hh) goto _failure2; image = temp.pic->data; /* 文件解码完毕, 解析图片的像素数据 */ if (temp.pic->fmt == CR_INDEX8) { switch (head.info.depth) { case 1: if (ww % 8 == 0) nbpl = ww / 8; else nbpl = ww / 8 + 1; if (!png_filter(ddata, nbpl, 1, hh, dptr)) goto _failure2; for (index = hh; index != 0; index--) { sdata = (uchar*)font1_h2l(image, sdata, ww); image += temp.pic->bpl; } break; case 2: if (ww % 4 == 0) nbpl = ww / 4; else nbpl = ww / 4 + 1; if (!png_filter(ddata, nbpl, 1, hh, dptr)) goto _failure2; for (index = hh; index != 0; index--) { sdata = (uchar*)font2_h2l(image, sdata, ww); image += temp.pic->bpl; } break; case 4: if (ww % 2 == 0) nbpl = ww / 2; else nbpl = ww / 2 + 1; if (!png_filter(ddata, nbpl, 1, hh, dptr)) goto _failure2; for (index = hh; index != 0; index--) { sdata = (uchar*)font4_h2l(image, sdata, ww); image += temp.pic->bpl; } break; case 8: nbpl = ww; if (!png_filter(ddata, nbpl, 1, hh, dptr)) goto _failure2; for (index = hh; index != 0; index--) { mem_cpy(image, sdata, nbpl); sdata += nbpl; image += temp.pic->bpl; } break; default: case 16: nbpl = ww; nbpl *= 2; if (!png_filter(ddata, nbpl, 2, hh, dptr)) goto _failure2; for (index = hh; index != 0; index--) { for (fcrh = 0; fcrh < ww; fcrh++, sdata += 2) image[fcrh] = sdata[0]; image += temp.pic->bpl; } break; } } else { nbpl = ww * sbpp; if (!png_filter(ddata, nbpl, sbpp, hh, dptr)) goto _failure2; nbpl = ww * temp.pic->bpc; switch (head.info.color) { case 2: if (head.info.depth == 8) { /* 直接逐行复制 */ for (index = hh; index != 0; index--) { for (dsize = 0; dsize < nbpl; dsize += 3) { image[dsize + 0] = sdata[2]; image[dsize + 1] = sdata[1]; image[dsize + 2] = sdata[0]; sdata += 3; } image += temp.pic->bpl; } } else { /* 跳开一个像素复制 */ for (index = hh; index != 0; index--) { for (dsize = 0; dsize < nbpl; dsize += 3) { image[dsize + 0] = sdata[4]; image[dsize + 1] = sdata[2]; image[dsize + 2] = sdata[0]; sdata += 6; } image += temp.pic->bpl; } } break; case 4: if (head.info.depth == 8) { /* 直接逐行复制 */ for (index = hh; index != 0; index--) { for (dsize = 0; dsize < nbpl; dsize += 4) { image[dsize + 0] = sdata[0]; image[dsize + 1] = sdata[0]; image[dsize + 2] = sdata[0]; image[dsize + 3] = sdata[1]; sdata += 2; } image += temp.pic->bpl; } } else { /* 跳开一个像素复制 */ for (index = hh; index != 0; index--) { for (dsize = 0; dsize < nbpl; dsize += 4) { image[dsize + 0] = sdata[0]; image[dsize + 1] = sdata[0]; image[dsize + 2] = sdata[0]; image[dsize + 3] = sdata[2]; sdata += 4; } image += temp.pic->bpl; } } break; default: case 6: if (head.info.depth == 8) { /* 直接逐行复制 */ for (index = hh; index != 0; index--) { for (dsize = 0; dsize < nbpl; dsize += 4) { image[dsize + 0] = sdata[2]; image[dsize + 1] = sdata[1]; image[dsize + 2] = sdata[0]; image[dsize + 3] = sdata[3]; sdata += 4; } image += temp.pic->bpl; } } else { /* 跳开一个像素复制 */ for (index = hh; index != 0; index--) { for (dsize = 0; dsize < nbpl; dsize += 4) { image[dsize + 0] = sdata[4]; image[dsize + 1] = sdata[2]; image[dsize + 2] = sdata[0]; image[dsize + 3] = sdata[6]; sdata += 8; } image += temp.pic->bpl; } } break; } } mem_free(ddata); /* 返回读取的文件数据 */ rett = struct_new(sFMT_PIC); if (rett == NULL) goto _failure1; rett->frame = struct_dup(&temp, sFMT_FRAME); if (rett->frame == NULL) { mem_free(rett); goto _failure1; } CR_NOUSE(param); rett->type = CR_FMTZ_PIC; rett->count = 1; rett->infor = "Portable Network Graphics (PNG)"; return (rett); _failure2: mem_free(ddata); _failure1: image_del(temp.pic); return (NULL); }
/* ======================================= RAR 文件读取 ======================================= */ CR_API sFMT_PRT* load_rar ( __CR_IO__ iDATIN* datin, __CR_IN__ const sLOADER* param ) { HANDLE rar; sARRAY list; int32u attr; sint_t retc; leng_t fpos; iPAK_RAR* port; sFMT_PRT* rett; sPAK_RAR_FILE temp; RARHeaderDataEx info; RAROpenArchiveDataEx open; /* 只支持磁盘文件 */ if (param->type != CR_LDR_ANSI && param->type != CR_LDR_WIDE) return (NULL); /* 列表模式打开 RAR 文件 */ struct_zero(&open, RAROpenArchiveDataEx); if (param->type == CR_LDR_ANSI) open.ArcName = (ansi_t*)param->name.ansi; else open.ArcNameW = (wide_t*)param->name.wide; open.OpenMode = RAR_OM_LIST; rar = RAROpenArchiveEx(&open); if (rar == NULL) return (NULL); if (param->aprm != NULL && *(byte_t*)param->aprm != 0x00) { RARSetPassword(rar, (ansi_t*)param->aprm); attr = PAK_FILE_ENC; } else { attr = 0; } /* 开始逐个文件读取信息并定位 */ array_initT(&list, sPAK_RAR_FILE); list.free = rar_free; struct_zero(&info, RARHeaderDataEx); for (fpos = 0; ; fpos++) { /* 读取一个文件记录头 */ retc = RARReadHeaderEx(rar, &info); if (retc == ERAR_END_ARCHIVE) break; if (retc != ERAR_SUCCESS) goto _failure1; /* 目录文件不加入列表 */ if (info.Flags & RHDF_DIRECTORY) { retc = RARProcessFile(rar, RAR_SKIP, NULL, NULL); if (retc != ERAR_SUCCESS) goto _failure1; continue; } /* 文件名统一使用 UTF-8 编码 */ struct_zero(&temp, sPAK_RAR_FILE); temp.base.name = local_to_utf8(param->page, info.FileName); if (temp.base.name == NULL) goto _failure1; /* 设置公用文件属性 (偏移没有实际用处) */ temp.base.skip = sizeof(sPAK_RAR_FILE); temp.base.attr = attr; temp.base.offs = 0; temp.base.pack = mk_size(info.PackSizeHigh, info.PackSize); temp.base.size = mk_size(info.UnpSizeHigh, info.UnpSize); if (info.Method != 0x30) temp.base.attr |= PAK_FILE_CMP; if (info.Flags & RHDF_ENCRYPTED) temp.base.attr |= PAK_FILE_ENC; else temp.base.attr &= ~PAK_FILE_ENC; switch (info.Method) { case 0x30: temp.base.memo = "Storing"; break; case 0x31: temp.base.memo = "Fastest compression"; break; case 0x32: temp.base.memo = "Fast compression"; break; case 0x33: temp.base.memo = "Normal compression"; break; case 0x34: temp.base.memo = "Good compression"; break; case 0x35: temp.base.memo = "Best compression"; break; default: temp.base.memo = "Unknown compression"; break; } /* 设置私有文件属性 */ temp.id = fpos; temp.crc32 = (int32u)(info.FileCRC); temp.fattr = (int32u)(info.FileAttr); temp.ftime = (int16u)(info.FileTime & 0xFFFF); temp.fdate = (int16u)(info.FileTime >> 16); temp.htype = (int32u)(info.HashType); mem_cpy(temp.hash, info.Hash, sizeof(temp.hash)); /* 文件信息压入列表 */ if (array_push_growT(&list, sPAK_RAR_FILE, &temp) == NULL) { mem_free(temp.base.name); goto _failure1; } /* 跳过当前已读文件 */ retc = RARProcessFile(rar, RAR_SKIP, NULL, NULL); if (retc != ERAR_SUCCESS && retc != ERAR_BAD_DATA) goto _failure1; } /* 固定一下列表大小 */ if (!array_no_growT(&list, sPAK_RAR_FILE)) goto _failure1; /* 生成读包接口对象 */ port = struct_new(iPAK_RAR); if (port == NULL) goto _failure1; /* 保存需要用到的参数 */ port->m_temp = NULL; if (attr == 0) { port->m_pass = NULL; } else { port->m_pass = str_dupA((ansi_t*)param->aprm); if (port->m_pass == NULL) goto _failure2; } if (param->type == CR_LDR_ANSI) { port->m_wide = NULL; port->m_ansi = str_dupA(param->name.ansi); if (port->m_ansi == NULL) goto _failure3; } else { port->m_ansi = NULL; port->m_wide = str_dupW(param->name.wide); if (port->m_wide == NULL) goto _failure3; } port->m_rar = NULL; port->m_cur = (leng_t)-1; port->m_cnt = array_get_sizeT(&list, sPAK_RAR_FILE); port->pack.__filelst__ = array_get_dataT(&list, sPAK_FILE); port->pack.__vptr__ = &s_pack_vtbl; if (!pack_init_list((iPACKAGE*)port, TRUE)) goto _failure4; RARCloseArchive(rar); /* 返回读取的文件数据 */ rett = struct_new(sFMT_PRT); if (rett == NULL) { iPAK_RAR_release((iPACKAGE*)port); return (NULL); } CR_NOUSE(datin); rett->type = CR_FMTZ_PRT; rett->port = (iPORT*)port; rett->more = "iPACKAGE"; rett->infor = "Roshal ARchive (RAR)"; return (rett); _failure4: TRY_FREE(port->m_ansi); TRY_FREE(port->m_wide); _failure3: TRY_FREE(port->m_pass); _failure2: mem_free(port); _failure1: array_freeT(&list, sPAK_RAR_FILE); RARCloseArchive(rar); return (NULL); }
//! edit gboolean modifEdi(GtkWidget* parent , gpointer data){ gboolean status = FALSE; gint id = GPOINTER_TO_INT(data); gint result = GTK_RESPONSE_OK; if(data == NULL){ GtkWidget *comboId = gtk_combo_box_new (); GtkWidget *dialog = modifGetPilihanId(comboId); gtk_widget_show_all(dialog); result = gtk_dialog_run (dialog); // block id = globalConStrToInt(gtk_combo_box_get_active_text(comboId)); gtk_widget_destroy(dialog); } if(result==GTK_RESPONSE_OK){ modifStruct_ *modif = struct_new(modifStruct_); gchar *title = g_strdup_printf ("Edit Data dengan id %d", id); GtkWidget *dialog = modifGetDialogWithStruct(parent , modif , title); //! mengambil data dari database GValueArray* varr = g_value_array_new (-1); GValue a = {0}; g_assert (!G_VALUE_HOLDS_STRING (&a)); g_value_init (&a, G_TYPE_INT); g_value_set_int (&a, id ); varr = g_value_array_append(varr,&a); gchar *sql = g_strdup_printf ("%s and isi.id=?", globalGetDefCom() ); GValueArray *hasil = databaseGetDatasFromDb( sql , varr , &status); modifSetItemToWidget(modif,hasil); //! show gtk_widget_show_all(dialog); result = gtk_dialog_run (dialog); // block if (result==GTK_RESPONSE_OK){ //! sekarang kita akan masuk pada database //! mengambil data char *filename; char* jamchar = globalPutZeroToWkt(gtk_spin_button_get_value_as_int(modif->jam)); char* mntchar = globalPutZeroToWkt(gtk_spin_button_get_value_as_int(modif->mnt)); gchar *jamMnt = g_strdup_printf ("%s:%s", jamchar,mntchar); gchar * hari = gtk_combo_box_get_active_text ( modif->hari); gchar * bagian = gtk_combo_box_get_active_text ( modif->bagian ); gint total = gtk_spin_button_get_value_as_int (modif->total); filename = fuGetNameFile( gtk_button_get_label(modif->filePilih)); //! update database gint idHari = databaseGetIdHari(hari); GValueArray* varr = g_value_array_new (-1); GValue a = {0}; g_assert (!G_VALUE_HOLDS_STRING (&a)); g_value_init (&a, G_TYPE_INT); g_value_set_int (&a, idHari); //! 1 varr = g_value_array_append(varr,&a); g_value_set_int (&a, total); //! 2 varr = g_value_array_append(varr,&a); g_value_unset (&a); g_value_init (&a, G_TYPE_STRING); g_value_set_string (&a, jamMnt); //! 3 varr = g_value_array_append(varr,&a); g_value_set_string (&a, bagian); //! 4 varr = g_value_array_append(varr,&a); g_value_set_string (&a, filename); //! 5 varr = g_value_array_append(varr,&a); g_value_unset (&a); g_value_init (&a, G_TYPE_INT); g_value_set_int (&a, id); //! 6 varr = g_value_array_append(varr,&a); GValueArray *hasil = databaseGetDatasFromDb("update isi set dal=? , X=?,jam=?,bagian=?,alarm=? where id = ?" , varr,&status); //! free g_value_array_free (varr); g_value_array_free (hasil); //! aslinya harus di cek kembali status = TRUE; } else{ } //! free all g_value_array_free (varr); g_value_array_free (hasil); gtk_widget_destroy(dialog); } return TRUE; }
/*-------------------------------------------------------------------------*/ struct_t * struct_new_anonymous (int num_members) /* Create an empty anonymous struct instance with <num_members> * and return its pointer. * Return NULL when out of memory. * * The returned struct will have one reference. */ { struct_type_t * pType; struct_t * pStruct; int i; char buf[100]; Bool gotError; (void) ref_mstring(STR_ANONYMOUS); (void) ref_mstring(STR_ANONYMOUS); pType = struct_new_type( STR_ANONYMOUS , STR_ANONYMOUS , 0 , NULL, num_members, NULL); if (pType == NULL) return NULL; pStruct = struct_new(pType); free_struct_type(pType); /* struct_new() added one ref, but since this is an anonymous * struct, the struct instance will hold the only ref. */ if (pStruct == NULL) { // the type was not referenced by struct_new() in this case, so it must // not be freed. return NULL; } /* Create default members */ gotError = MY_FALSE; for (i = 0; i < num_members; i++) { sprintf(buf, "m-%d", i); pType->member[i].name = new_tabled(buf); if (!pType->member[i].name) { debug_message("(%s:%d) Out of memory (%zu bytes) for member name\n" , __FILE__, __LINE__, strlen(buf) ); gotError = MY_TRUE; break; } pType->member[i].type = lpctype_mixed; } if (gotError) { free_struct(pStruct); pStruct = NULL; } return pStruct; } /* struct_new_anonymous() */
/* ======================================= TGL IPAC 文件读取 ======================================= */ CR_API sFMT_PRT* load_tgl_ipac ( __CR_IO__ iDATIN* datin, __CR_IN__ const sLOADER* param ) { int16u idx; int16u cnt; int32u offs; int32u size; sFMT_PRT* rett; sIPAC_HDR head; iPAK_IPAC* port; sPAK_FILE* list; ansi_t str[17]; /* 必须使用自己私有的读取接口 */ datin = create_file_inX(param); if (datin == NULL) return (NULL); /* 读取 & 检查头部 */ if (!(CR_VCALL(datin)->geType(datin, &head, sIPAC_HDR))) goto _failure1; if (head.magic != mk_tag4("IPAC")) goto _failure1; /* 分配子文件属性表 */ cnt = WORD_LE(head.count); if (cnt != 0) { list = mem_talloc(cnt, sPAK_FILE); if (list == NULL) goto _failure1; str[16] = CR_AC(NIL); mem_tzero(list, cnt, sPAK_FILE); } else { list = NULL; /* 支持空的包文件 */ } /* 加载文件信息表 */ for (idx = 0; idx < cnt; idx++) { /* 读取文件名不保证\0结尾 */ if (CR_VCALL(datin)->read(datin, str, 16) != 16) goto _failure2; /* 文件的包内偏移和大小 */ if (!CR_VCALL(datin)->getd_le(datin, &offs)) goto _failure2; if (!CR_VCALL(datin)->getd_le(datin, &size)) goto _failure2; /* 文件名统一使用 UTF-8 编码 */ list[idx].name = local_to_utf8(param->page, str); if (list[idx].name == NULL) goto _failure2; /* 设置公用文件属性 */ list[idx].skip = sizeof(sPAK_FILE); list[idx].attr = 0; list[idx].offs = offs; list[idx].pack = size; list[idx].size = size; list[idx].memo = "Store"; } /* 生成读包接口对象 */ port = struct_new(iPAK_IPAC); if (port == NULL) goto _failure2; port->m_cnt = cnt; port->m_file = datin; port->pack.__filelst__ = list; port->pack.__vptr__ = &s_pack_vtbl; if (!pack_init_list((iPACKAGE*)port, TRUE)) { mem_free(port); goto _failure2; } /* 返回读取的文件数据 */ rett = struct_new(sFMT_PRT); if (rett == NULL) { iPAK_IPAC_release((iPACKAGE*)port); return (NULL); } rett->type = CR_FMTZ_PRT; rett->port = (iPORT*)port; rett->more = "iPACKAGE"; rett->infor = "TGL IPAC Archive (IPAC)"; return (rett); _failure2: if (list != NULL) { for (cnt = 0; cnt < idx; cnt++) { TRY_FREE(list[cnt].find); mem_free(list[cnt].name); } mem_free(list); } _failure1: CR_VCALL(datin)->release(datin); return (NULL); }
/* ======================================= 生成 DX8 图形绘制接口 ======================================= */ CR_API iGFX2_DX8M* create_dx8_canvas ( __CR_IN__ const sDX8_HDLE* hdle, __CR_IN__ uint_t scn_cw, __CR_IN__ uint_t scn_ch, __CR_IN__ bool_t full ) { RECT rect; HRESULT retc; sD3D8_TEXR* fill; iGFX2_DX8M* rett; /* 使用伪全屏 */ if (full) { scn_cw = GetSystemMetrics(SM_CXSCREEN); scn_ch = GetSystemMetrics(SM_CYSCREEN); if (!SetWindowPos(hdle->hwnd, HWND_TOP, 0, 0, scn_cw, scn_ch, SWP_SHOWWINDOW)) return (NULL); } else if (scn_cw == 0 || scn_ch == 0) { /* 非法宽高, 获取窗口大小 */ if (!GetClientRect(hdle->hwnd, &rect)) return (NULL); scn_cw = rect.right; scn_ch = rect.bottom; } /* 生成对象 */ rett = struct_new(iGFX2_DX8M); if (rett == NULL) return (NULL); struct_zero(&rett->__back__, sIMAGE); /* 创建 D3D8 设备 */ if (hdle->main == NULL) { rett->m_main = hdle->call->create_main(hdle->hwnd, FALSE, scn_cw, scn_ch, D3DFMT_UNKNOWN, D3DFMT_UNKNOWN, FALSE, D3DMULTISAMPLE_NONE); if (rett->m_main == NULL) goto _failure1; } else { rett->m_main = hdle->main; } /* 创建填充用的纹理 */ fill = hdle->call->create_tex2(rett->m_main, 1, 1, D3DFMT_A8R8G8B8, D3DPOOL_MANAGED, 0, 1); if (fill == NULL) goto _failure2; rett->m_fill = (iGFX2*)create_dx8_bitmap(rett, fill, FALSE); if (rett->m_fill == NULL) { hdle->call->release_texr(fill); goto _failure2; } if (!CR_VCALL(rett->m_fill)->clear(rett->m_fill, 0xFFFFFFFFUL, 0)) goto _failure3; /* 生成精灵绘制对象 */ retc = D3DXCreateSprite(rett->m_main->dev, &rett->m_sprt); if (FAILED(retc)) goto _failure3; /* 返回生成的对象 */ rett->__vptr__ = &s_canvas_vtbl; struct_cpy(&rett->m_hdle, hdle, sDX8_HDLE); rect_set_wh(&rett->__back__.clip_win, 0, 0, scn_cw, scn_ch); struct_cpy(&rett->__back__.position, &rett->__back__.clip_win, sRECT); return (rett); _failure3: CR_VCALL(rett->m_fill)->release(rett->m_fill); _failure2: if (hdle->main == NULL) hdle->call->release_main(rett->m_main); _failure1: mem_free(rett); return (NULL); }
/* --------------------------------------- 获取图片帧 --------------------------------------- */ static sFMT_PIC* iPIC_AIA_get ( __CR_IN__ iPICTURE* that, __CR_IN__ int32u index ) { leng_t bpln; leng_t paln; int32u* dest; iPIC_AIA* real; sFMT_PIC* rett; sAIA_IDX* attr; sFMT_FRAME temp; /* 帧号过滤 */ if (index >= that->__count__) return (NULL); /* 生成图片对象 */ real = (iPIC_AIA*)that; mem_zero(temp.wh, sizeof(temp.wh)); temp.fmt = CR_PIC_ARGB; temp.bpp = 32; temp.clr = "ARGB"; temp.wh[0] = 8; temp.wh[1] = 8; temp.wh[2] = 8; temp.wh[3] = 8; temp.pic = image_new(0, 0, real->m_ww, real->m_hh, CR_ARGB8888, FALSE, 4); if (temp.pic == NULL) return (NULL); mem_zero(temp.pic->data, temp.pic->size); /* 解码图形数据 */ attr = &real->m_attr[index]; bpln = (leng_t)real->m_ww; paln = (leng_t)attr->pal_idx; dest = (int32u*)(temp.pic->data); dest += attr->y1 * bpln + attr->x1; if (!decode_aia(dest, &real->m_dats[attr->offset], real->m_size - attr->offset, &real->m_pals[paln * 256], attr->x2, attr->y2, real->m_ww - attr->x2)) goto _failure; /* 返回读取的文件数据 */ rett = struct_new(sFMT_PIC); if (rett == NULL) goto _failure; rett->frame = struct_dup(&temp, sFMT_FRAME); if (rett->frame == NULL) { mem_free(rett); goto _failure; } rett->type = CR_FMTZ_PIC; rett->count = 1; rett->infor = "FALCOM YS AIA Image File (*.AIA)"; return (rett); _failure: image_del(temp.pic); return (NULL); }
/* ======================================= FALCOM AIA 文件读取 ======================================= */ CR_API sFMT_PRT* load_flc_aia ( __CR_IO__ iDATIN* datin, __CR_IN__ const sLOADER* param ) { leng_t back; leng_t size; byte_t* pals; byte_t* dats; uint_t ww, hh; int32u idx, cnt; /* ----------- */ fdist_t offs; sAIA_HDR head; sAIA_IDX* attr; sFMT_PRT* rett; iPIC_AIA* port; /* 这个参数可能为空 */ if (datin == NULL) return (NULL); /* 读取 & 检查头部 */ if (!(CR_VCALL(datin)->geType(datin, &head, sAIA_HDR))) return (NULL); if (head.magic != mk_tag4("AIA")) return (NULL); offs = DWORD_LE(head.idx_num); offs *= sizeof(int32u) * 4; if (head.version == CWORD_LE(0x140)) { offs += 32; pals = (byte_t*)(&head.img_size); dats = (byte_t*)(&head.scale1); mem_cpy(pals, dats, 4); pals = (byte_t*)(&head.ww2); mem_cpy(dats, pals, 4); head.ww2 = head.hh2 = 0; head.scale2 = 0.0f; } else if (head.version == CWORD_LE(0x150)) { offs += 40; } else { return (NULL); } /* 定位到已知数据区域 */ if (!CR_VCALL(datin)->seek(datin, offs, SEEK_SET)) return (NULL); /* 读取所有帧属性数据 */ head.img_num = DWORD_LE(head.img_num); attr = mem_talloc32(head.img_num, sAIA_IDX); if (attr == NULL) return (NULL); /* 准备好一些属性值 */ ww = WORD_LE(head.ww1); hh = WORD_LE(head.hh1); head.pal_num = DWORD_LE(head.pal_num); head.img_size = DWORD_LE(head.img_size); /* 逐个读入有效的帧属性 */ for (cnt = idx = 0; idx < head.img_num; idx++) { back = CR_VCALL(datin)->read(datin, &attr[cnt], sizeof(sAIA_IDX)); if (back != sizeof(sAIA_IDX)) goto _failure1; /* 跳过非法的废帧 */ attr[cnt].offset = DWORD_LE(attr[cnt].offset); if (attr[cnt].offset >= head.img_size) continue; attr[cnt].pal_idx = WORD_LE(attr[cnt].pal_idx); if ((int32u)attr[cnt].pal_idx >= head.pal_num) continue; /* 跳过废帧 (请自己定义帧序号) */ attr[cnt].x1 = WORD_LE(attr[cnt].x1); attr[cnt].y1 = WORD_LE(attr[cnt].y1); attr[cnt].x2 = WORD_LE(attr[cnt].x2); attr[cnt].y2 = WORD_LE(attr[cnt].y2); if ((uint_t)attr[cnt].x2 > ww || (uint_t)attr[cnt].y2 > hh || attr[cnt].x1 >= attr[cnt].x2 || attr[cnt].y1 >= attr[cnt].y2) continue; attr[cnt].x2 = attr[cnt].x2 - attr[cnt].x1; attr[cnt].y2 = attr[cnt].y2 - attr[cnt].y1; cnt += 1; } /* 空图片检查 */ if (cnt == 0) goto _failure1; /* 读取所有调色板数据 */ pals = (byte_t*)mem_calloc32(head.pal_num, 1024); if (pals == NULL) goto _failure1; size = (leng_t)head.pal_num; size *= 1024; if (CR_VCALL(datin)->read(datin, pals, size) != size) goto _failure2; for (back = 0; back < size; back += 4) pals[back + 3] = 0xFF; /* 读取所有图形数据 */ dats = (byte_t*)mem_malloc32(head.img_size); if (dats == NULL) goto _failure2; size = (leng_t)head.img_size; if (CR_VCALL(datin)->read(datin, dats, size) != size) goto _failure3; /* 生成多帧图片接口对象 */ port = struct_new(iPIC_AIA); if (port == NULL) goto _failure3; port->m_ww = ww; port->m_hh = hh; port->m_attr = attr; port->m_dats = dats; port->m_pals = (int32u*)pals; port->m_size = head.img_size; port->pics.__count__ = cnt; port->pics.__vptr__ = &s_pics_vtbl; /* 返回读取的文件数据 */ rett = struct_new(sFMT_PRT); if (rett == NULL) { iPIC_AIA_release((iPICTURE*)port); return (NULL); } CR_NOUSE(param); rett->type = CR_FMTZ_PRT; rett->port = (iPORT*)port; rett->more = "iPICTURE"; rett->infor = "FALCOM YS AIA Image File (*.AIA)"; return (rett); _failure3: mem_free(dats); _failure2: mem_free(pals); _failure1: mem_free(attr); return (NULL); }
/* ======================================= FMODEx 文件读取 ======================================= */ CR_API sFMT_PRT* load_fmodex ( __CR_IO__ iDATIN* datin, __CR_IN__ const sLOADER* param ) { uint_t size; void_t* data; ansi_t* path; sFMT_PRT* rett; FMOD_MODE mode; iXMM_FMOD* port; FMOD_SOUND* sound; FMOD_RESULT result; FMOD_CHANNEL* channel; FMOD_CREATESOUNDEXINFO ex_info; /* 必须先初始化 */ if (s_fmodex == NULL) return (NULL); mode = FMOD_LOOP_OFF | FMOD_2D | FMOD_HARDWARE | FMOD_ACCURATETIME; /* 不支持文件区段功能 */ switch (param->type) { case CR_LDR_ANSI: data = NULL; result = FMOD_System_CreateStream(s_fmodex, param->name.ansi, mode, NULL, &sound); break; case CR_LDR_WIDE: data = NULL; path = utf16_to_local(CR_LOCAL, param->name.wide); if (path == NULL) return (NULL); result = FMOD_System_CreateStream(s_fmodex, path, mode, NULL, &sound); mem_free(path); break; case CR_LDR_BUFF: if (cut_size(&size, param->buff.size)) return (NULL); data = mem_dup(param->buff.data, param->buff.size); if (data == NULL) return (NULL); path = (ansi_t*)data; mode |= FMOD_OPENMEMORY; mem_zero(&ex_info, sizeof(ex_info)); ex_info.cbsize = sizeof(ex_info); ex_info.length = size; result = FMOD_System_CreateStream(s_fmodex, path, mode, &ex_info, &sound); break; default: return (NULL); } /* 无法支持的格式 */ if (result != FMOD_OK) goto _failure1; /* 生成播放通道对象 */ result = FMOD_System_PlaySound(s_fmodex, FMOD_CHANNEL_FREE, sound, TRUE, &channel); if (result != FMOD_OK) goto _failure2; /* 生成媒体播放接口对象 */ port = struct_new(iXMM_FMOD); if (port == NULL) goto _failure3; struct_zero(port, iXMM_FMOD); port->m_dat = data; port->m_snd = sound; port->m_chn = channel; if (!fmodex_info(port)) { iXMM_FMOD_release((iXMMEDIA*)port); return (NULL); } port->xmms.__volume__ = 100; port->xmms.__vptr__ = &s_xmms_vtbl; /* 返回读取的文件数据 */ rett = struct_new(sFMT_PRT); if (rett == NULL) { iXMM_FMOD_release((iXMMEDIA*)port); return (NULL); } CR_NOUSE(datin); rett->type = CR_FMTZ_PRT; rett->port = (iPORT*)port; rett->more = "iXMMEDIA"; rett->infor = port->m_inf; return (rett); _failure3: FMOD_Channel_Stop(channel); _failure2: FMOD_Sound_Release(sound); _failure1: TRY_FREE(data); return (NULL); }
/* ======================================= 生成 FB 图形绘制接口 ======================================= */ CR_API iGFX2_FB* create_fb_canvas ( __CR_IN__ const ansi_t* fb ) { iGFX2_FB* rett; /* 创建对象 */ rett = struct_new(iGFX2_FB); if (rett == NULL) return (NULL); struct_zero(&rett->__back__, sIMAGE); /* 初始化 FB */ if (fb == NULL) fb = "/dev/fb0"; rett->m_file = open(fb, O_RDWR); if (rett->m_file < 0) return (NULL); if (ioctl(rett->m_file, FBIOGET_FSCREENINFO, &rett->m_finfo) < 0) goto _failure; if (ioctl(rett->m_file, FBIOGET_VSCREENINFO, &rett->m_vinfo) < 0) goto _failure; if (rett->m_vinfo.bits_per_pixel <= 8 || rett->m_vinfo.red.msb_right || rett->m_vinfo.green.msb_right || rett->m_vinfo.blue.msb_right) goto _failure; /* 填充参数结构 */ rett->__back__.bpl = rett->m_finfo.line_length; if (rett->__back__.bpl % 16 == 0) rett->__back__.align = 16; else if (rett->__back__.bpl % 8 == 0) rett->__back__.align = 8; else if (rett->__back__.bpl % 4 == 0) rett->__back__.align = 4; rect_set_wh(&rett->__back__.clip_win, 0, 0, rett->m_vinfo.xres, rett->m_vinfo.yres); struct_cpy(&rett->__back__.position, &rett->__back__.clip_win, sRECT); rett->__back__.size = rett->__back__.bpl; rett->__back__.size *= rett->m_vinfo.yres; /* 识别颜色格式 */ if (rett->m_vinfo.bits_per_pixel == 16) { if (rett->m_vinfo.red.length == 5 && rett->m_vinfo.green.length == 6 && rett->m_vinfo.blue.length == 5 && rett->m_vinfo.red.offset == 11 && rett->m_vinfo.green.offset == 5 && rett->m_vinfo.blue.offset == 0) { rett->__back__.fmt = CR_ARGB565; rett->__vptr__ = &s_img16_vtbl; } else if (rett->m_vinfo.red.length == 5 && rett->m_vinfo.green.length == 5 && rett->m_vinfo.blue.length == 5 && rett->m_vinfo.red.offset == 10 && rett->m_vinfo.green.offset == 5 && rett->m_vinfo.blue.offset == 0) { if (rett->m_vinfo.transp.length == 0) { rett->__back__.fmt = CR_ARGBX555; rett->__vptr__ = &s_img15_vtbl; } else { rett->__back__.fmt = CR_ARGB1555; rett->__vptr__ = &s_img17_vtbl; } } else if (rett->m_vinfo.red.length == 4 && rett->m_vinfo.green.length == 4 && rett->m_vinfo.blue.length == 4 && rett->m_vinfo.red.offset == 8 && rett->m_vinfo.green.offset == 4 && rett->m_vinfo.blue.offset == 0) { rett->__back__.fmt = CR_ARGB4444; rett->__vptr__ = &s_img12_vtbl; } else { goto _failure; } rett->__back__.bpc = 2; } else if (rett->m_vinfo.bits_per_pixel == 32) { rett->__back__.bpc = 4; rett->__back__.fmt = CR_ARGB8888; rett->__vptr__ = &s_img32_vtbl; } else if (rett->m_vinfo.bits_per_pixel == 24) { rett->__back__.bpc = 3; rett->__back__.fmt = CR_ARGB888; rett->__vptr__ = &s_img24_vtbl; } else { goto _failure; } rett->__back__.data = (byte_t*)mem_malloc(rett->__back__.size + 16); if (rett->__back__.data == NULL) goto _failure; mem_zero(rett->__back__.data, rett->__back__.size); /* 映射前台缓冲 */ rett->m_size = (uint_t)rett->__back__.size; rett->m_main = mmap(NULL, rett->m_size, PROT_READ | PROT_WRITE, MAP_SHARED, rett->m_file, 0); if (rett->m_main == MAP_FAILED) { mem_free(rett->__back__.data); goto _failure; } mem_zero(rett->m_main, rett->m_size); return (rett); _failure: close(rett->m_file); return (NULL); }
/*-------------------------------------------------------------------------*/ svalue_t * x_map_struct (svalue_t *sp, int num_arg) /* EFUN map() on structs * * mixed * map(struct arg, string func, string|object ob, mixed extra...) * mixed * map(struct arg, closure cl, mixed extra...) * mixed * map(struct arr, mapping map [, int col]) * * Map the elements of <arr> through a filter defined by the other * arguments, and return an array of the elements returned by the filter. * * The filter can be a function call: * * <obj>-><fun>(elem, <extra>...) * * or a mapping query: * * <map>[elem[,idx]] * * In the mapping case, if <map>[elem[,idx]] does not exist, the original * value is returned in the result. * [Note: argument type and range checking for idx is done in v_map()] * * <obj> can both be an object reference or a filename. If <ob> is * omitted, or neither an object nor a string, then this_object() is used. * * As a bonus, all references to destructed objects in <arr> are replaced * by proper 0es. */ { struct_t *st; struct_t *res; svalue_t *arg; svalue_t *v, *w, *x; mp_int cnt; inter_sp = sp; arg = sp - num_arg + 1; st = arg->u.strct; cnt = (mp_int)struct_size(st); if (arg[1].type == T_MAPPING) { /* --- Map through mapping --- */ mapping_t *m; p_int column = 0; /* mapping column to use */ m = arg[1].u.map; if (num_arg > 2) column = arg[2].u.number; res = struct_new(st->type); if (!res) errorf("(map_struct) Out of memory: struct[%"PRIdMPINT"] for result\n", cnt); push_struct(inter_sp, res); /* In case of errors */ for (w = st->member, x = res->member; --cnt >= 0; w++, x++) { if (destructed_object_ref(w)) assign_svalue(w, &const0); v = get_map_value(m, w); if (v == &const0) assign_svalue_no_free(x, w); else assign_svalue_no_free(x, v + column); } if (num_arg > 2) free_svalue(arg+2); free_svalue(arg+1); /* the mapping */ sp = arg; } else { /* --- Map through function call --- */ callback_t cb; int error_index; error_index = setup_efun_callback(&cb, arg+1, num_arg-1); if (error_index >= 0) { vefun_bad_arg(error_index+2, arg); /* NOTREACHED */ return arg; } inter_sp = sp = arg+1; put_callback(sp, &cb); num_arg = 2; res = struct_new(st->type); if (!res) errorf("(map_struct) Out of memory: struct[%"PRIdMPINT"] for result\n", cnt); push_struct(inter_sp, res); /* In case of errors */ /* Loop through arr and res, mapping the values from arr */ for (w = st->member, x = res->member; --cnt >= 0; w++, x++) { if (current_object->flags & O_DESTRUCTED) continue; if (destructed_object_ref(w)) assign_svalue(w, &const0); if (!callback_object(&cb)) errorf("object used by map_array destructed"); push_svalue(w); v = apply_callback(&cb, 1); if (v) { transfer_svalue_no_free(x, v); v->type = T_INVALID; } } free_callback(&cb); } /* The arguments have been removed already, now just replace * the struct on the stack with the result. */ free_struct(st); arg->u.strct = res; /* Keep svalue type T_STRUCT */ return arg; } /* x_map_struct () */