void Vbo::ensureFreeCapacity(size_t capacity) { pack(); if (m_freeCapacity < capacity) resizeVbo(m_totalCapacity + (capacity - m_freeCapacity)); }
ListPanelActions::ListPanelActions(QObject *parent, FileManagerWindow *mainWindow) : ActionsBase(parent, mainWindow) { // set view type QSignalMapper *mapper = new QSignalMapper(this); connect(mapper, SIGNAL(mapped(int)), SLOT(setView(int))); QActionGroup *group = new QActionGroup(this); group->setExclusive(true); QList<KrViewInstance*> views = KrViewFactory::registeredViews(); for(int i = 0; i < views.count(); i++) { KrViewInstance *inst = views[i]; QAction *action = new QAction(QIcon::fromTheme(inst->icon()), inst->description(), group); action->setCheckable(true); connect(action, SIGNAL(triggered()), mapper, SLOT(map())); mapper->setMapping(action, inst->id()); _mainWindow->actions()->addAction("view" + QString::number(i), action); _mainWindow->actions()->setDefaultShortcut(action, inst->shortcut()); setViewActions.insert(inst->id(), action); } // standard actions actHistoryBackward = stdAction(KStandardAction::Back, _func, SLOT(historyBackward())); actHistoryForward = stdAction(KStandardAction::Forward, _func, SLOT(historyForward())); //FIXME: second shortcut for up: see actDirUp // KStandardAction::up( this, SLOT( dirUp() ), actionCollection )->setShortcut(Qt::Key_Backspace); /* Shortcut disabled because of the Terminal Emulator bug. */ actDirUp = stdAction(KStandardAction::Up, _func, SLOT(dirUp())); actHome = stdAction(KStandardAction::Home, _func, SLOT(home())); stdAction(KStandardAction::Cut, _func, SLOT(cut())); actCopy = stdAction(KStandardAction::Copy, _func, SLOT(copyToClipboard())); actPaste = stdAction(KStandardAction::Paste, _func, SLOT(pasteFromClipboard())); // Fn keys actF2 = action(i18n("Rename"), 0, Qt::Key_F2, _func, SLOT(rename()) , "F2_Rename"); actF3 = action(i18n("View File"), 0, Qt::Key_F3, _func, SLOT(view()), "F3_View"); actF4 = action(i18n("Edit File"), 0, Qt::Key_F4, _func, SLOT(edit()) , "F4_Edit"); actF5 = action(i18n("Copy to other panel"), 0, Qt::Key_F5, _func, SLOT(copyFiles()) , "F5_Copy"); actF6 = action(i18n("Move..."), 0, Qt::Key_F6, _func, SLOT(moveFiles()) , "F6_Move"); actShiftF5 = action(i18n("Copy by queue..."), 0, Qt::SHIFT + Qt::Key_F5, _func, SLOT(copyFilesByQueue()) , "F5_Copy_Queue"); actShiftF6 = action(i18n("Move by queue..."), 0, Qt::SHIFT + Qt::Key_F6, _func, SLOT(moveFilesByQueue()) , "F6_Move_Queue"); actF7 = action(i18n("New Directory..."), "folder-new", Qt::Key_F7, _func, SLOT(mkdir()) , "F7_Mkdir"); actF8 = action(i18n("Delete"), "edit-delete", Qt::Key_F8, _func, SLOT(deleteFiles()) , "F8_Delete"); actF9 = action(i18n("Start Terminal Here"), "utilities-terminal", Qt::Key_F9, _func, SLOT(terminal()) , "F9_Terminal"); action(i18n("&New Text File..."), "document-new", Qt::SHIFT + Qt::Key_F4, _func, SLOT(editNew()), "edit_new_file"); action(i18n("F3 View Dialog"), 0, Qt::SHIFT + Qt::Key_F3, _func, SLOT(viewDlg()), "F3_ViewDlg"); // file operations action(i18n("Right-click Menu"), 0, Qt::Key_Menu, _gui, SLOT(rightclickMenu()), "rightclick menu"); actProperties = action(i18n("&Properties..."), 0, Qt::ALT + Qt::Key_Return, _func, SLOT(properties()), "properties"); actCompDirs = action(i18n("&Compare Directories"), "kr_comparedirs", Qt::ALT + Qt::SHIFT + Qt::Key_C, _gui, SLOT(compareDirs()), "compare dirs"); actCalculate = action(i18n("Calculate &Occupied Space"), "accessories-calculator", 0, _func, SLOT(calcSpace()), "calculate"); actPack = action(i18n("Pac&k..."), "archive-insert", Qt::ALT + Qt::SHIFT + Qt::Key_P, _func, SLOT(pack()), "pack"); actUnpack = action(i18n("&Unpack..."), "archive-extract", Qt::ALT + Qt::SHIFT + Qt::Key_U, _func, SLOT(unpack()), "unpack"); actCreateChecksum = action(i18n("Create Checksum..."), "document-edit-sign", 0, _func, SLOT(createChecksum()), "create checksum"); actMatchChecksum = action(i18n("Verify Checksum..."), "document-edit-decrypt-verify", 0, _func, SLOT(matchChecksum()), "match checksum"); action(i18n("New Symlink..."), 0, Qt::CTRL + Qt::ALT + Qt::Key_S, _func, SLOT(krlink()), "new symlink"); actTest = action(i18n("T&est Archive"), "archive-extract", Qt::ALT + Qt::SHIFT + Qt::Key_E, _func, SLOT(testArchive()), "test archives"); // navigation actRoot = action(i18n("Root"), "folder-red", Qt::CTRL + Qt::Key_Backspace, _func, SLOT(root()), "root"); actCdToOther = action(i18n("Go to Other Panel's Directory"), 0, Qt::CTRL + Qt::Key_Equal, _func, SLOT(cdToOtherPanel()), "cd to other panel"); action(i18n("&Reload"), "view-refresh", Qt::CTRL + Qt::Key_R, _func, SLOT(refresh()), "std_redisplay"); actCancelRefresh = action(i18n("Cancel Refresh of View"), "dialog-cancel", 0, _gui, SLOT(inlineRefreshCancel()), "cancel refresh"); actFTPNewConnect = action(i18n("New Net &Connection..."), "network-connect", Qt::CTRL + Qt::Key_N, _func, SLOT(newFTPconnection()), "ftp new connection"); actFTPDisconnect = action(i18n("Disconnect &from Net"), "network-disconnect", Qt::SHIFT + Qt::CTRL + Qt::Key_F, _func, SLOT(FTPDisconnect()), "ftp disconnect"); action(i18n("Sync Panels"), 0, Qt::ALT + Qt::SHIFT + Qt::Key_O, _func, SLOT(syncOtherPanel()), "sync panels"); actJumpBack = action(i18n("Jump Back"), "go-jump", Qt::CTRL + Qt::Key_J, _gui, SLOT(jumpBack()), "jump_back"); actSetJumpBack = action(i18n("Set Jump Back Point"), "go-jump-definition", Qt::CTRL + Qt::SHIFT + Qt::Key_J, _gui, SLOT(setJumpBack()), "set_jump_back"); actSyncBrowse = action(i18n("S&ynchron Directory Changes"), "kr_syncbrowse_off", Qt::ALT + Qt::SHIFT + Qt::Key_Y, _gui, SLOT(toggleSyncBrowse()), "sync browse"); actLocationBar = action(i18n("Go to Location Bar"), 0, Qt::CTRL + Qt::Key_L, _gui, SLOT(editLocation()), "location_bar"); toggleAction(i18n("Toggle Popup Panel"), 0, Qt::ALT + Qt::Key_Down, _gui, SLOT(togglePanelPopup()), "toggle popup panel"); action(i18n("Bookmarks"), 0, Qt::CTRL + Qt::Key_D, _gui, SLOT(openBookmarks()), "bookmarks"); action(i18n("Left Bookmarks"), 0, 0, this, SLOT(openLeftBookmarks()), "left bookmarks"); action(i18n("Right Bookmarks"), 0, 0, this, SLOT(openRightBookmarks()), "right bookmarks"); action(i18n("History"), 0, Qt::CTRL + Qt::Key_H, _gui, SLOT(openHistory()), "history"); action(i18n("Left History"), 0, Qt::ALT + Qt::CTRL + Qt::Key_Left, this, SLOT(openLeftHistory()), "left history"); action(i18n("Right History"), 0, Qt::ALT + Qt::CTRL + Qt::Key_Right, this, SLOT(openRightHistory()), "right history"); action(i18n("Media"), 0, Qt::CTRL + Qt::Key_M, _gui, SLOT(openMedia()), "media"); action(i18n("Left Media"), 0, Qt::CTRL + Qt::SHIFT + Qt::Key_Left, this, SLOT(openLeftMedia()), "left media"); action(i18n("Right Media"), 0, Qt::CTRL + Qt::SHIFT + Qt::Key_Right, this, SLOT(openRightMedia()), "right media"); // and at last we can set the tool-tips actRoot->setToolTip(i18n("ROOT (/)")); actF2->setToolTip(i18n("Rename file, directory, etc.")); actF3->setToolTip(i18n("Open file in viewer.")); actF4->setToolTip("<qt>" + i18n("<p>Edit file.</p>" "<p>The editor can be defined in Konfigurator, " "default is <b>internal editor</b>.</p>") + "</qt>"); actF5->setToolTip(i18n("Copy file from one panel to the other.")); actF6->setToolTip(i18n("Move file from one panel to the other.")); actF7->setToolTip(i18n("Create directory in current panel.")); actF8->setToolTip(i18n("Delete file, directory, etc.")); actF9->setToolTip("<qt>" + i18n("<p>Open terminal in current directory.</p>" "<p>The terminal can be defined in Konfigurator, " "default is <b>konsole</b>.</p>") + "</qt>"); }
void PathManagerEvent::write(NetConnection*nc, BitStream *stream) { pack(nc, stream); }
static int j2k_encode_entry(Imaging im, ImagingCodecState state, ImagingIncrementalCodec encoder) { JPEG2KENCODESTATE *context = (JPEG2KENCODESTATE *)state->context; opj_stream_t *stream = NULL; opj_image_t *image = NULL; opj_codec_t *codec = NULL; opj_cparameters_t params; unsigned components; OPJ_COLOR_SPACE color_space; opj_image_cmptparm_t image_params[4]; unsigned xsiz, ysiz; unsigned tile_width, tile_height; unsigned tiles_x, tiles_y, num_tiles; unsigned x, y, tile_ndx; unsigned n; j2k_pack_tile_t pack; int ret = -1; stream = opj_stream_default_create(OPJ_FALSE); if (!stream) { state->errcode = IMAGING_CODEC_BROKEN; state->state = J2K_STATE_FAILED; goto quick_exit; } opj_stream_set_write_function(stream, j2k_write); opj_stream_set_skip_function(stream, j2k_skip); opj_stream_set_seek_function(stream, j2k_seek); opj_stream_set_user_data(stream, encoder); /* Setup an opj_image */ if (strcmp (im->mode, "L") == 0) { components = 1; color_space = OPJ_CLRSPC_GRAY; pack = j2k_pack_l; } else if (strcmp (im->mode, "LA") == 0) { components = 2; color_space = OPJ_CLRSPC_GRAY; pack = j2k_pack_la; } else if (strcmp (im->mode, "RGB") == 0) { components = 3; color_space = OPJ_CLRSPC_SRGB; pack = j2k_pack_rgb; } else if (strcmp (im->mode, "YCbCr") == 0) { components = 3; color_space = OPJ_CLRSPC_SYCC; pack = j2k_pack_rgb; } else if (strcmp (im->mode, "RGBA") == 0) { components = 4; color_space = OPJ_CLRSPC_SRGB; pack = j2k_pack_rgba; } else { state->errcode = IMAGING_CODEC_BROKEN; state->state = J2K_STATE_FAILED; goto quick_exit; } for (n = 0; n < components; ++n) { image_params[n].dx = image_params[n].dy = 1; image_params[n].w = im->xsize; image_params[n].h = im->ysize; image_params[n].x0 = image_params[n].y0 = 0; image_params[n].prec = 8; image_params[n].bpp = 8; image_params[n].sgnd = 0; } image = opj_image_create(components, image_params, color_space); /* Setup compression context */ context->error_msg = NULL; opj_set_default_encoder_parameters(¶ms); params.image_offset_x0 = context->offset_x; params.image_offset_y0 = context->offset_y; if (context->tile_size_x && context->tile_size_y) { params.tile_size_on = OPJ_TRUE; params.cp_tx0 = context->tile_offset_x; params.cp_ty0 = context->tile_offset_y; params.cp_tdx = context->tile_size_x; params.cp_tdy = context->tile_size_y; tile_width = params.cp_tdx; tile_height = params.cp_tdy; } else { params.cp_tx0 = 0; params.cp_ty0 = 0; params.cp_tdx = 1; params.cp_tdy = 1; tile_width = im->xsize; tile_height = im->ysize; } if (context->quality_layers && PySequence_Check(context->quality_layers)) { Py_ssize_t len = PySequence_Length(context->quality_layers); Py_ssize_t n; float *pq; if (len) { if (len > sizeof(params.tcp_rates) / sizeof(params.tcp_rates[0])) len = sizeof(params.tcp_rates)/sizeof(params.tcp_rates[0]); params.tcp_numlayers = (int)len; if (context->quality_is_in_db) { params.cp_disto_alloc = params.cp_fixed_alloc = 0; params.cp_fixed_quality = 1; pq = params.tcp_distoratio; } else { params.cp_disto_alloc = 1; params.cp_fixed_alloc = params.cp_fixed_quality = 0; pq = params.tcp_rates; } for (n = 0; n < len; ++n) { PyObject *obj = PySequence_ITEM(context->quality_layers, n); pq[n] = PyFloat_AsDouble(obj); } } } else { params.tcp_numlayers = 1; params.tcp_rates[0] = 0; params.cp_disto_alloc = 1; } if (context->num_resolutions) params.numresolution = context->num_resolutions; if (context->cblk_width >= 4 && context->cblk_width <= 1024 && context->cblk_height >= 4 && context->cblk_height <= 1024 && context->cblk_width * context->cblk_height <= 4096) { params.cblockw_init = context->cblk_width; params.cblockh_init = context->cblk_height; } if (context->precinct_width >= 4 && context->precinct_height >= 4 && context->precinct_width >= context->cblk_width && context->precinct_height > context->cblk_height) { params.prcw_init[0] = context->precinct_width; params.prch_init[0] = context->precinct_height; params.res_spec = 1; params.csty |= 0x01; } params.irreversible = context->irreversible; params.prog_order = context->progression; params.cp_cinema = context->cinema_mode; switch (params.cp_cinema) { case OPJ_OFF: params.cp_rsiz = OPJ_STD_RSIZ; break; case OPJ_CINEMA2K_24: case OPJ_CINEMA2K_48: params.cp_rsiz = OPJ_CINEMA2K; if (params.numresolution > 6) params.numresolution = 6; break; case OPJ_CINEMA4K_24: params.cp_rsiz = OPJ_CINEMA4K; if (params.numresolution > 7) params.numresolution = 7; break; } if (context->cinema_mode != OPJ_OFF) j2k_set_cinema_params(im, components, ¶ms); /* Set up the reference grid in the image */ image->x0 = params.image_offset_x0; image->y0 = params.image_offset_y0; image->x1 = xsiz = im->xsize + params.image_offset_x0; image->y1 = ysiz = im->ysize + params.image_offset_y0; /* Create the compressor */ codec = opj_create_compress(context->format); if (!codec) { state->errcode = IMAGING_CODEC_BROKEN; state->state = J2K_STATE_FAILED; goto quick_exit; } opj_set_error_handler(codec, j2k_error, context); opj_setup_encoder(codec, ¶ms, image); /* Start encoding */ if (!opj_start_compress(codec, image, stream)) { state->errcode = IMAGING_CODEC_BROKEN; state->state = J2K_STATE_FAILED; goto quick_exit; } /* Write each tile */ tiles_x = (im->xsize + (params.image_offset_x0 - params.cp_tx0) + tile_width - 1) / tile_width; tiles_y = (im->ysize + (params.image_offset_y0 - params.cp_ty0) + tile_height - 1) / tile_height; num_tiles = tiles_x * tiles_y; state->buffer = malloc (tile_width * tile_height * components); tile_ndx = 0; for (y = 0; y < tiles_y; ++y) { unsigned ty0 = params.cp_ty0 + y * tile_height; unsigned ty1 = ty0 + tile_height; unsigned pixy, pixh; if (ty0 < params.image_offset_y0) ty0 = params.image_offset_y0; if (ty1 > ysiz) ty1 = ysiz; pixy = ty0 - params.image_offset_y0; pixh = ty1 - ty0; for (x = 0; x < tiles_x; ++x) { unsigned tx0 = params.cp_tx0 + x * tile_width; unsigned tx1 = tx0 + tile_width; unsigned pixx, pixw; unsigned data_size; if (tx0 < params.image_offset_x0) tx0 = params.image_offset_x0; if (tx1 > xsiz) tx1 = xsiz; pixx = tx0 - params.image_offset_x0; pixw = tx1 - tx0; pack(im, state->buffer, pixx, pixy, pixw, pixh); data_size = pixw * pixh * components; if (!opj_write_tile(codec, tile_ndx++, state->buffer, data_size, stream)) { state->errcode = IMAGING_CODEC_BROKEN; state->state = J2K_STATE_FAILED; goto quick_exit; } } } if (!opj_end_compress(codec, stream)) { state->errcode = IMAGING_CODEC_BROKEN; state->state = J2K_STATE_FAILED; goto quick_exit; } state->errcode = IMAGING_CODEC_END; state->state = J2K_STATE_DONE; ret = (int)ImagingIncrementalCodecBytesInBuffer(encoder); quick_exit: if (codec) opj_destroy_codec(codec); if (image) opj_image_destroy(image); if (stream) opj_stream_destroy(stream); return ret; }
int _rfs_open(struct rfs_instance *instance, const char *path, int flags, uint64_t *desc) { if (instance->sendrecv.socket == -1) { return -ECONNABORTED; } unsigned path_len = strlen(path) + 1; uint16_t fi_flags = rfs_file_flags(flags); unsigned overall_size = sizeof(fi_flags) + path_len; struct rfs_command cmd = { cmd_open, overall_size }; char *buffer = malloc(cmd.data_len); pack(path, path_len, pack_16(&fi_flags, buffer )); send_token_t token = { 0 }; if (do_send(&instance->sendrecv, queue_data(buffer, overall_size, queue_cmd(&cmd, &token))) < 0) { free(buffer); return -ECONNABORTED; } free(buffer); struct rfs_answer ans = { 0 }; if (rfs_receive_answer(&instance->sendrecv, &ans) == -1) { return -ECONNABORTED; } if (ans.command != cmd_open) { return cleanup_badmsg(instance, &ans); } if (ans.ret == -1) { if (ans.ret_errno == -ENOENT) { delete_from_cache(&instance->attr_cache, path); } return -ans.ret_errno; } uint32_t stat_failed = 0; uint32_t user_len = 0; uint32_t group_len = 0; #define ans_buffer_size sizeof(*desc) \ + sizeof(stat_failed) + STAT_BLOCK_SIZE + sizeof(user_len) + sizeof(group_len) \ + (MAX_SUPPORTED_NAME_LEN + 1) + (MAX_SUPPORTED_NAME_LEN + 1) char ans_buffer[ans_buffer_size] = { 0 }; if (ans.data_len > sizeof(ans_buffer)) { return cleanup_badmsg(instance, &ans); } #undef ans_buffer_size if (rfs_receive_data(&instance->sendrecv, ans_buffer, ans.data_len) == -1) { return -ECONNABORTED; } struct stat stbuf = { 0 }; const char *user = unpack_32(&group_len, unpack_32(&user_len, unpack_stat(&stbuf, unpack_32(&stat_failed, unpack_64(desc, ans_buffer ))))); const char *group = user + user_len; DEBUG("handle: %llu\n", (long long unsigned)(*desc)); stbuf.st_uid = resolve_username(instance, user); stbuf.st_gid = resolve_groupname(instance, group, user); if (ans.ret_errno == 0) { if (stat_failed == 0) { cache_file(&instance->attr_cache, path, &stbuf); } resume_add_file_to_open_list(&instance->resume.open_files, path, flags, *desc); } else { delete_from_cache(&instance->attr_cache, path); } return ans.ret == -1 ? -ans.ret_errno : ans.ret; }
void process() { // SSL *NewFd=ssl; tap: pthread_mutex_lock(&pthreadMutex); pthread_cond_wait(&pthreadCond,&pthreadMutex); pthread_mutex_unlock(&pthreadMutex); int new_fd=tempsockfd; struct FilePackage sendPackage; SSL *ssl; // SSL_CTX *ctx; // ctx = SSL_CTX_new(SSLv23_server_method()); /* 基于 ctx 产生一个新的 SSL */ ssl = SSL_new(ctx); /* 将连接用户的 socket 加入到 SSL */ SSL_set_fd(ssl, new_fd); /* 建立 SSL 连接 */ if (SSL_accept(ssl) == -1) { perror("accept"); close(new_fd); } SSL *NewFd=ssl; ++CurrentClientNum; if(CurrentClientNum>MaxClientNum) /*客服端连接数达到最大*/ { sendPackage=pack('L'," "," ",0,2,1,""); SSL_write(NewFd,&sendPackage,sizeof(struct FilePackage)); --CurrentClientNum; /* 关闭 SSL 连接 */ SSL_shutdown(NewFd); /* 释放 SSL */ SSL_free(NewFd); close(new_fd); } // printf("~~~~~~~~~~~~~~~~~~~~~~~in~~~~~~~~~~~~~~~~~~~~~~~~~~~~\n"); while(1) { SSL_read(NewFd,&buff,sizeof(struct FilePackage)); // printf("11111%s",buff.username); // printf("%s\n",&buff); if(buff.cmd == 'Q' && buff.ack == '0') { // close(*NewFd); /* 关闭 SSL 连接 */ SSL_shutdown(NewFd); /* 释放 SSL */ SSL_free(NewFd); // MoveToIdle(); close(new_fd); break; } else { sendPackage=unpack(NewFd,buff); if(sendPackage.cmd!='\0') { SSL_write(NewFd,&sendPackage,sizeof(struct FilePackage)); } } } --CurrentClientNum; goto tap; /* 关闭 SSL 连接 */ // SSL_shutdown(NewFd); // /* 释放 SSL */ // SSL_free(NewFd); // close(new_fd); // close(*NewFd); //pthread_exit(0); }
/*获得密钥*/ void gkey(int nb,int nk,char *key) { int i,j,k,m,N; int C1,C2,C3; WORD CipherKey[8]; Nb=nb; Nk=nk; /* Nr is number of rounds Nr是加密的轮数*/ if (Nb>=Nk) Nr=6+Nb; else Nr=6+Nk; C1=1; if (Nb<8) { C2=2; C3=3; } else { C2=3; C3=4; } for (m=j=0;j<nb;j++,m+=3) { fi[m]=(j+C1)%nb; fi[m+1]=(j+C2)%nb; fi[m+2]=(j+C3)%nb; ri[m]=(nb+j-C1)%nb; ri[m+1]=(nb+j-C2)%nb; ri[m+2]=(nb+j-C3)%nb; } N=Nb*(Nr+1); for (i=j=0;i<Nk;i++,j+=4) { CipherKey[i]=pack((BYTE *)&key[j]); } for (i=0;i<Nk;i++) fkey[i]=CipherKey[i]; for (j=Nk,k=0;j<N;j+=Nk,k++) { fkey[j]=fkey[j-Nk]^SubByte(ROTL24(fkey[j-1]))^rco[k]; if (Nk<=6) { for (i=1;i<Nk && (i+j)<N;i++) fkey[i+j]=fkey[i+j-Nk]^fkey[i+j-1]; } else { for (i=1;i<4 &&(i+j)<N;i++) fkey[i+j]=fkey[i+j-Nk]^fkey[i+j-1]; if ((j+4)<N) fkey[j+4]=fkey[j+4-Nk]^SubByte(fkey[j+3]); for (i=5;i<Nk && (i+j)<N;i++) fkey[i+j]=fkey[i+j-Nk]^fkey[i+j-1]; } } for (j=0;j<Nb;j++) rkey[j+N-Nb]=fkey[j]; for (i=Nb;i<N-Nb;i+=Nb) { k=N-Nb-i; for (j=0;j<Nb;j++) rkey[k+j]=InvMixCol(fkey[i+j]); } for (j=N-Nb;j<N;j++) rkey[j-N+Nb]=fkey[j]; }
int edname(char *src, int kind, int change) { int but; REG OBJECT *obj; obj = get_tree( SAMENAME ); pack(src, 0); strcpy(src, (BYTE *)((TEDINFO *)(obj[FNAME].ob_spec))->te_ptext); strcpy(src, (BYTE *)((TEDINFO *)(obj[EDFNAME].ob_spec))->te_ptext); /* obj[COPY].ob_state = NORMAL; obj[SKIP].ob_state = NORMAL; obj[QUIT].ob_state = NORMAL; */ ((TEDINFO*)(obj[SNAME].ob_spec))->te_ptext = (LONG)get_fstring( ( change ) ? RNAME : NCONFLIC ); /* desk_mice( ARROW ); */ /* fm_draw( SAMENAME, FALSE ); */ switch( but = fmdodraw( SAMENAME, 0 ) ) { case COPY: if (!strcmp((BYTE *)((TEDINFO *)(obj[EDFNAME].ob_spec))->te_ptext, src)) { /* user edit the new name */ strcpy( (BYTE *)((TEDINFO *)(obj[EDFNAME].ob_spec))->te_ptext,src); strcpy( src, (BYTE *)((TEDINFO *)(cpbox[kind].ob_spec))->te_ptext); pack(src,1); backdir(fixdst); strcat(src, fixdst); but = CHECK; } else {/* check if the source and destination are the same */ if (kind == CPDIR) rmstarb(fixsrc); if (strcmp(fixsrc, fixdst))/* they are the same */ but = SKIP; if (kind == CPDIR) strcat(bckslsh, fixsrc); } break; case SKIP: case QUIT: break; } /* desk_mice( HOURGLASS ); */ if ( d_display ) { draw_loop( whandle, cpbox, 0, MAX_DEPTH, 0, 0, full.g_w, full.g_h ); /* fm_draw( CPBOX, FALSE ); */ } /* else namecon = TRUE; */ if (but != CHECK) pack(src, 1); return but; }
/** * Responds to the Create button */ void AddEditLightDialog::on_btnCreate_clicked() { //ConnectionNameFromSystemName.getPrefixFromName((String) prefixBox.getSelectedItem()) QString lightPrefix = ConnectionNameFromSystemName::getPrefixFromName(ui->prefixBox->currentText())+"L"; QString turnoutPrefix = ConnectionNameFromSystemName::getPrefixFromName(ui->prefixBox->currentText())+"T"; QString curAddress = ui->fieldHardwareAddress->text(); if (curAddress.length()<1) { log->warn("Hardware Address was not entered"); ui->status1->setText( tr("Error: No Hardware Address was entered.") ); ui->status2->setVisible(false); // addFrame.pack(); pack(); // addFrame.setVisible(true); setVisible(true); return; } QString suName = lightPrefix+curAddress; QString uName = ui->userName->text(); if (uName==("")) uName=""; // a blank field means no user name // Does System Name have a valid format if (!((ProxyLightManager*)InstanceManager::lightManagerInstance())->validSystemNameFormat(suName)) { // Invalid System Name format log->warn("Invalid Light system name format entered: "+suName); ui->status1->setText( tr("Error: System Name has an invalid format.") ); ui->status2->setText( tr("Please revise System Name and try again.") ); ui->status2->setVisible(true); // addFrame.pack(); pack(); // addFrame.setVisible(true); setVisible(true); return; } // Format is valid, normalize it QString sName = ((ProxyLightManager*)InstanceManager::lightManagerInstance())->normalizeSystemName(suName); // check if a Light with this name already exists AbstractLight* g = (AbstractLight*)((ProxyLightManager*)InstanceManager::lightManagerInstance())->getBySystemName(sName); if (g!=NULL) { // Light already exists ui->status1->setText( tr("Error: Light with this System Name already exists.") ); ui->status2->setText( tr("Press Edit to see User Name and Control information.") ); ui->status2->setVisible(true); // addFrame.pack(); pack(); // addFrame.setVisible(true); setVisible(true); return; } // check if Light exists under an alternate name if an alternate name exists QString altName = ((ProxyLightManager*)InstanceManager::lightManagerInstance())->convertSystemNameToAlternate(suName); if (altName != "") { g = (AbstractLight*)((ProxyLightManager*)InstanceManager::lightManagerInstance())->getBySystemName(altName); if (g!=NULL) { // Light already exists ui->status1->setText( tr("Error: Light")+" '"+altName+"' "+ tr("exists and is the same address.") ); ui->status2->setVisible(false); // addFrame.pack(); pack(); // addFrame.setVisible(true); setVisible(true); return; } } // check if a Light with the same user name exists if (uName!="") { g = (AbstractLight*)((ProxyLightManager*)InstanceManager::lightManagerInstance())->getByUserName(uName); if (g!=NULL) { // Light with this user name already exists ui->status1->setText( tr("Error: Light with this User Name already exists.") ); ui->status2->setText( tr("Please revise User Name and try again.") ); ui->status2->setVisible(true); // addFrame.pack(); pack(); // addFrame.setVisible(true); setVisible(true); return; } } // Does System Name correspond to configured hardware if (!((ProxyLightManager*)InstanceManager::lightManagerInstance())->validSystemNameConfig(sName)) { // System Name not in configured hardware ui->status1->setText( tr("Error: System Name doesn't refer to configured hardware.") ); ui->status2->setText( tr("Please revise System Name and try again.") ); ui->status2->setVisible(true); // addFrame.pack(); pack(); // addFrame.setVisible(true); setVisible(true); return; } // check if requested Light uses the same address as a Turnout QString testSN = turnoutPrefix+curAddress; Turnout* testT = ((ProxyTurnoutManager*)InstanceManager::turnoutManagerInstance())-> getBySystemName(testSN); if (testT != NULL) { // Address is already used as a Turnout log->warn("Requested Light "+sName+" uses same address as Turnout "+testT->getDisplayName()); if (!noWarn) { // int selectedValue = JOptionPane.showOptionDialog(addFrame, // tr("LightWarn5")+" "+sName+" "+tr("LightWarn6")+" "+ // testSN+".\n "+tr("LightWarn7"),tr("WarningTitle"), // JOptionPane.YES_NO_CANCEL_OPTION,JOptionPane.QUESTION_MESSAGE,null, // new Object[]{tr("ButtonYes"),tr("ButtonNo"), // tr("ButtonYesPlus")},tr("ButtonNo")); QMessageBox* msgBox = new QMessageBox( tr("Warning"), tr("Warning - Requested Light")+" "+sName+" "+tr("uses same address as Turnout")+" "+ testSN+".\n "+tr("Do you still want to add this Light?"),QMessageBox::Warning, QMessageBox::Yes, QMessageBox::No, QMessageBox::Cancel,this); //msgBox->setIcon(QMessageBox::Warning); QPushButton* buttonYesPlus = new QPushButton(tr("Yes - Stop Warnings")); msgBox->addButton(buttonYesPlus,QMessageBox::ActionRole); int selectedValue = msgBox->exec(); if (selectedValue == QMessageBox::No) return; // return without creating if "No" response if (msgBox->clickedButton() == buttonYesPlus) { // Suppress future warnings, and continue noWarn = true; } } // Light with this system name already exists as a turnout ui->status2->setText( tr("Warning: New Light refers to address already used by")+" "+testSN+"." ); ui->status2->setVisible(true); } // Check multiple Light creation request, if supported int numberOfLights = 1; int startingAddress = 0; if ( (((ProxyLightManager*)InstanceManager::lightManagerInstance())->allowMultipleAdditions(sName)) && ui->addRangeBox->isChecked() && (ui->fieldNumToAdd->value()>0) ) { // get number requested // try { numberOfLights = (ui->fieldNumToAdd->value()); // } catch (NumberFormatException ex) { // status1->setText(tr("LightError4")); // status2.setVisible(false); // addFrame.pack(); // addFrame.setVisible(true); // log.error("Unable to convert " + fieldNumToAdd.getText() + " to a number - Number to add"); // return; // } // convert numerical hardware address // try { startingAddress = ui->fieldHardwareAddress->text().toInt(); // } catch (NumberFormatException ex) { // status1->setText(tr("LightError18")); // status2.setVisible(false); // addFrame.pack(); // addFrame.setVisible(true); // log.error("Unable to convert " + fieldHardwareAddress.getText() + " to a number."); // return; // } // check that requested address range is available int add = startingAddress; QString testAdd = ""; for (int i = 0; i<numberOfLights; i++) { testAdd = lightPrefix+add; if (((ProxyLightManager*)InstanceManager::lightManagerInstance())->getBySystemName(testAdd)!=NULL) { ui->status1->setText(tr("Error: Requested range of hardware addresses is not free.")); ui->status2->setVisible(true); // addFrame.pack(); pack(); // addFrame.setVisible(true); setVisible(true); log->error("Range not available - "+testAdd+ " already exists."); return; } testAdd = turnoutPrefix+add; if (((ProxyTurnoutManager*)InstanceManager::turnoutManagerInstance())->getBySystemName(testAdd)!=NULL) { ui->status1->setText(tr("Error: Requested range of hardware addresses is not free.")); ui->status2->setVisible(true); //addFrame.pack(); //addFrame.setVisible(true); setVisible(true); log->error("Range not available - "+testAdd+ " already exists."); return; } add++; } } // Create a single new Light, or the first Light of a range // try { g = (AbstractLight*)((ProxyLightManager*)InstanceManager::lightManagerInstance())->newLight(sName,uName); // } catch (IllegalArgumentException ex) { if(g == NULL) { // user input no good handleCreateException(sName); return; // without creating } // set control information if any setLightControlInformation(g); clearLightControls(); g->activateLight(); lightCreatedOrUpdated = true; QString p; p = ui->fieldMinIntensity->text(); if (p==("")) p = "1.0"; g->setMinIntensity((p).toDouble()/ 100); p = ui->fieldMaxIntensity->text(); if (p==("")) p = "0.0"; if(p.toDouble() <= g->getMinIntensity()) { ui->status1->setText(tr("Max intensity must be greater than minimum")); handleCreateException(sName); return; // without creating } g->setMaxIntensity(p.toDouble() / 100); p = ui->fieldTransitionTime->text(); if (p==("")) p = "0"; // try { g->setTransitionTime(p.toDouble()); // } catch (IllegalArgumentException e1) { // // set rate to 0. // g.setTransitionTime(0.0); // } // provide feedback to user QString feedback = tr("New Light added:")+" "+sName+", "+uName; // create additional lights if requested if (numberOfLights>1) { QString sxName = ""; QString uxName = ""; if (uName=="") uxName = ""; for (int i = 1; i<numberOfLights; i++) { sxName = lightPrefix+(startingAddress+i); if (uName!="") uxName = uName+"+"+i; // try { g = (AbstractLight*)((ProxyLightManager*)InstanceManager::lightManagerInstance())->newLight(sxName,uxName); // } catch (IllegalArgumentException ex) { if(g == NULL) { // user input no good handleCreateException(sName); return; // without creating any more Lights } } feedback = feedback +" - "+sxName+", "+uxName; } ui->status1->setText(feedback); ui->status2->setText( "" ); ui->status2->setVisible(false); // addFrame.pack(); // addFrame.setVisible(true); setVisible(true); }
void Message <Args...>::pack (StreamBinOut & sbo, U val, Args2... args) { pack_one (sbo, val); pack (sbo, args...); }
Result mixdown_stereo(Left&& left, Right&& right, const f64x2x2& matrix) { return Result(internal::stereo_matrix{ matrix }, pack(std::forward<Left>(left), std::forward<Right>(right))); }
void Message <Args...>::pack (StreamBinOut & sbo, U val) { pack_one (sbo, val); pack (sbo); }
DetView::DetView(QWidget* p, SequenceObjectContext* ctx) : GSequenceLineViewAnnotated(p, ctx) { editor = new DetViewSequenceEditor(this); showComplementAction = new QAction(tr("Show complementary strand"), this); showComplementAction->setIcon(QIcon(":core/images/show_compl.png")); showComplementAction->setObjectName("complement_action"); connect(showComplementAction, SIGNAL(triggered(bool)), SLOT(sl_showComplementToggle(bool))); showTranslationAction = new QAction(tr("Show/hide translations"), this); showTranslationAction->setObjectName("translation_action"); connect(showTranslationAction, SIGNAL(triggered(bool)), SLOT(sl_showTranslationToggle(bool))); doNotTranslateAction = new QAction(tr("Do not translate"), this); doNotTranslateAction->setObjectName("do_not_translate_radiobutton"); doNotTranslateAction->setData(SequenceObjectContext::TS_DoNotTranslate); connect(doNotTranslateAction, SIGNAL(triggered(bool)), SLOT(sl_doNotTranslate())); doNotTranslateAction->setCheckable(true); doNotTranslateAction->setChecked(true); translateAnnotationsOrSelectionAction = new QAction(tr("Translate selection"), this); translateAnnotationsOrSelectionAction->setData(SequenceObjectContext::TS_AnnotationsOrSelection); connect(translateAnnotationsOrSelectionAction, SIGNAL(triggered(bool)), SLOT(sl_translateAnnotationsOrSelection())); translateAnnotationsOrSelectionAction->setCheckable(true); setUpFramesManuallyAction = new QAction(tr("Set up frames manually"), this); setUpFramesManuallyAction->setObjectName("set_up_frames_manuallt_radiobutton"); setUpFramesManuallyAction->setData(SequenceObjectContext::TS_SetUpFramesManually); connect(setUpFramesManuallyAction, SIGNAL(triggered(bool)), SLOT(sl_setUpFramesManually())); setUpFramesManuallyAction->setCheckable(true); showAllFramesAction = new QAction(tr("Show all frames"), this); showAllFramesAction->setObjectName("show_all_frames_radiobutton"); showAllFramesAction->setData(SequenceObjectContext::TS_ShowAllFrames); connect(showAllFramesAction, SIGNAL(triggered(bool)), SLOT(sl_showAllFrames())); showAllFramesAction->setCheckable(true); wrapSequenceAction = new QAction(tr("Wrap sequence"), this); wrapSequenceAction->setIcon(QIcon(":core/images/wrap_sequence.png")); wrapSequenceAction->setObjectName("wrap_sequence_action"); connect(wrapSequenceAction, SIGNAL(triggered(bool)), SLOT(sl_wrapSequenceToggle(bool))); showComplementAction->setCheckable(true); showTranslationAction->setCheckable(true); wrapSequenceAction->setCheckable(true); wrapSequenceAction->setChecked(true); bool hasComplement = ctx->getComplementTT() != NULL; showComplementAction->setChecked(hasComplement); bool hasAmino = ctx->getAminoTT() != NULL; showTranslationAction->setChecked(hasAmino); assert(ctx->getSequenceObject()!=NULL); featureFlags&=!GSLV_FF_SupportsCustomRange; renderArea = new DetViewRenderArea(this); renderArea->setObjectName("render_area_" + ctx->getSequenceObject()->getSequenceName()); connect(ctx, SIGNAL(si_aminoTranslationChanged()), SLOT(sl_onAminoTTChanged())); connect(ctx, SIGNAL(si_translationRowsChanged()), SLOT(sl_translationRowsChanged())); addActionToLocalToolbar(wrapSequenceAction); if (hasComplement) { addActionToLocalToolbar(showComplementAction); } if (hasAmino) { setupTranslationsMenu(); setupGeneticCodeMenu(); } addActionToLocalToolbar(editor->getEditAction()); verticalScrollBar = new GScrollBar(Qt::Vertical, this); verticalScrollBar->setObjectName("multiline_scrollbar"); scrollBar->setObjectName("singleline_scrollbar"); currentShiftsCounter = 0; numShiftsInOneLine = 1; verticalScrollBar->setHidden(!wrapSequenceAction->isChecked()); scrollBar->setHidden(wrapSequenceAction->isChecked()); pack(); updateActions(); // TODO_SVEDIT: check its required connect(ctx->getSequenceObject(), SIGNAL(si_sequenceChanged()), SLOT(sl_sequenceChanged())); setSizePolicy(QSizePolicy::Preferred, QSizePolicy::Expanding); }
void CtcpHandler::reply(const QString &bufname, const QString &ctcpTag, const QString &message) { QList<QByteArray> params; params << serverEncode(bufname) << lowLevelQuote(pack(serverEncode(ctcpTag), userEncode(bufname, message))); emit putCmd("NOTICE", params); }
Texture* TextureFilters::blur(Texture* texture, int passes, int direction, int width, int amplify) { passes += 1; direction += 1; passes = max(1, passes); width = max(1, width); Texture* in = texture->clone(); Texture* out = new Texture(); in->lock(); out->lock(); if (direction & 1) { // Repeat box blur for (int t = 0; t < passes; t++) { // For each line for (int y = 0; y < 256; y++) { DWORD r = 0, g = 0, b = 0; for (int x = 0; x < width; x++) { DWORD c = in->getPixel(x, y); r += c & 0xff; g += (c >> 8) & 0xff; b += (c >> 16) & 0xff; } for (int x = 0; x < 256; x++) { out->putPixel((x + width / 2) & 0xff, y, pack(r, g, b, width, amplify)); DWORD c1 = in->getPixel((x + width) & 0xff, y); DWORD c2 = in->getPixel(x, y); r += c1 & 0xff; g += (c1 >> 8) & 0xff; b += (c1 >> 16) & 0xff; r -= c2 & 0xff; g -= (c2 >> 8) & 0xff; b -= (c2 >> 16) & 0xff; } } { Texture *tmp = out; out = in; in = tmp; } } } if (direction & 2) { // Repeat box blur for (int t = 0; t < passes; t++) { // For each column for (int x = 0; x < 256; x++) { DWORD r = 0, g = 0, b = 0; for (int y = 0; y < width; y++) { DWORD c = in->getPixel(x, y); r += c & 0xff; g += (c >> 8) & 0xff; b += (c >> 16) & 0xff; } for (int y = 0; y < 256; y++) { out->putPixel(x, (y + width / 2) & 0xff, pack(r, g, b, width, amplify)); DWORD c1 = in->getPixel(x, (y + width) & 0xff); DWORD c2 = in->getPixel(x, y); r += c1 & 0xff; g += (c1 >> 8) & 0xff; b += (c1 >> 16) & 0xff; r -= c2 & 0xff; g -= (c2 >> 8) & 0xff; b -= (c2 >> 16) & 0xff; } } { Texture *tmp = out; out = in; in = tmp; } } } in->unlock(); out->unlock(); delete out; return in; }
void pack (const Elem* elem, std::vector<largest_id_type>& data, const ParallelMesh* mesh) { pack(elem, data, static_cast<const MeshBase*>(mesh)); }
/* * Select the appropriate copy function to use. */ static copyFunc pickCopyFunc(TIFF* in, TIFF* out, uint16 bitspersample, uint16 samplesperpixel) { uint16 shortv; uint32 w, l, tw, tl; int bychunk; (void) TIFFGetField(in, TIFFTAG_PLANARCONFIG, &shortv); if (shortv != config && bitspersample != 8 && samplesperpixel > 1) { fprintf(stderr, "%s: Can not handle different planar configuration w/ bits/sample != 8\n", TIFFFileName(in)); return (NULL); } TIFFGetField(in, TIFFTAG_IMAGEWIDTH, &w); TIFFGetField(in, TIFFTAG_IMAGELENGTH, &l); if (TIFFIsTiled(out)) { if (!TIFFGetField(in, TIFFTAG_TILEWIDTH, &tw)) tw = w; if (!TIFFGetField(in, TIFFTAG_TILELENGTH, &tl)) tl = l; bychunk = (tw == tilewidth && tl == tilelength); } else if (TIFFIsTiled(in)) { TIFFGetField(in, TIFFTAG_TILEWIDTH, &tw); TIFFGetField(in, TIFFTAG_TILELENGTH, &tl); bychunk = (tw == w && tl == rowsperstrip); } else { uint32 irps = (uint32) -1L; TIFFGetField(in, TIFFTAG_ROWSPERSTRIP, &irps); bychunk = (rowsperstrip == irps); } #define T 1 #define F 0 #define pack(a,b,c,d,e) ((long)(((a)<<11)|((b)<<3)|((c)<<2)|((d)<<1)|(e))) switch(pack(shortv,config,TIFFIsTiled(in),TIFFIsTiled(out),bychunk)) { /* Strips -> Tiles */ case pack(PLANARCONFIG_CONTIG, PLANARCONFIG_CONTIG, F,T,F): case pack(PLANARCONFIG_CONTIG, PLANARCONFIG_CONTIG, F,T,T): return cpContigStrips2ContigTiles; case pack(PLANARCONFIG_CONTIG, PLANARCONFIG_SEPARATE, F,T,F): case pack(PLANARCONFIG_CONTIG, PLANARCONFIG_SEPARATE, F,T,T): return cpContigStrips2SeparateTiles; case pack(PLANARCONFIG_SEPARATE, PLANARCONFIG_CONTIG, F,T,F): case pack(PLANARCONFIG_SEPARATE, PLANARCONFIG_CONTIG, F,T,T): return cpSeparateStrips2ContigTiles; case pack(PLANARCONFIG_SEPARATE, PLANARCONFIG_SEPARATE, F,T,F): case pack(PLANARCONFIG_SEPARATE, PLANARCONFIG_SEPARATE, F,T,T): return cpSeparateStrips2SeparateTiles; /* Tiles -> Tiles */ case pack(PLANARCONFIG_CONTIG, PLANARCONFIG_CONTIG, T,T,F): case pack(PLANARCONFIG_CONTIG, PLANARCONFIG_CONTIG, T,T,T): return cpContigTiles2ContigTiles; case pack(PLANARCONFIG_CONTIG, PLANARCONFIG_SEPARATE, T,T,F): case pack(PLANARCONFIG_CONTIG, PLANARCONFIG_SEPARATE, T,T,T): return cpContigTiles2SeparateTiles; case pack(PLANARCONFIG_SEPARATE, PLANARCONFIG_CONTIG, T,T,F): case pack(PLANARCONFIG_SEPARATE, PLANARCONFIG_CONTIG, T,T,T): return cpSeparateTiles2ContigTiles; case pack(PLANARCONFIG_SEPARATE, PLANARCONFIG_SEPARATE, T,T,F): case pack(PLANARCONFIG_SEPARATE, PLANARCONFIG_SEPARATE, T,T,T): return cpSeparateTiles2SeparateTiles; /* Tiles -> Strips */ case pack(PLANARCONFIG_CONTIG, PLANARCONFIG_CONTIG, T,F,F): case pack(PLANARCONFIG_CONTIG, PLANARCONFIG_CONTIG, T,F,T): return cpContigTiles2ContigStrips; case pack(PLANARCONFIG_CONTIG, PLANARCONFIG_SEPARATE, T,F,F): case pack(PLANARCONFIG_CONTIG, PLANARCONFIG_SEPARATE, T,F,T): return cpContigTiles2SeparateStrips; case pack(PLANARCONFIG_SEPARATE, PLANARCONFIG_CONTIG, T,F,F): case pack(PLANARCONFIG_SEPARATE, PLANARCONFIG_CONTIG, T,F,T): return cpSeparateTiles2ContigStrips; case pack(PLANARCONFIG_SEPARATE, PLANARCONFIG_SEPARATE, T,F,F): case pack(PLANARCONFIG_SEPARATE, PLANARCONFIG_SEPARATE, T,F,T): return cpSeparateTiles2SeparateStrips; /* Strips -> Strips */ case pack(PLANARCONFIG_CONTIG, PLANARCONFIG_CONTIG, F,F,F): return cpContig2ContigByRow; case pack(PLANARCONFIG_CONTIG, PLANARCONFIG_CONTIG, F,F,T): return cpDecodedStrips; case pack(PLANARCONFIG_CONTIG, PLANARCONFIG_SEPARATE, F,F,F): case pack(PLANARCONFIG_CONTIG, PLANARCONFIG_SEPARATE, F,F,T): return cpContig2SeparateByRow; case pack(PLANARCONFIG_SEPARATE, PLANARCONFIG_CONTIG, F,F,F): case pack(PLANARCONFIG_SEPARATE, PLANARCONFIG_CONTIG, F,F,T): return cpSeparate2ContigByRow; case pack(PLANARCONFIG_SEPARATE, PLANARCONFIG_SEPARATE, F,F,F): case pack(PLANARCONFIG_SEPARATE, PLANARCONFIG_SEPARATE, F,F,T): return cpSeparate2SeparateByRow; } #undef pack #undef F #undef T fprintf(stderr, "tiffcp: %s: Don't know how to copy/convert image.\n", TIFFFileName(in)); return (NULL); }
void RemoteCommandEvent::write(NetConnection* conn, BitStream *bstream) { pack(conn, bstream); }
/*解包函数*/ struct FilePackage unpack(SSL *NewFd,struct FilePackage tpack) { struct FilePackage sendPack; char username[20]="\0"; char userpwd[20]="\0"; char *pUser=tpack.buf; char pfilename[125]="\0"; // char userdir[50]="\0"; int filesize; int currentFsize=0; int fd; int fdlog; int flag=1; // printf("2222222%s",tpack.username); switch(tpack.cmd) { case 'L': /*登陆请求*/ { int i=0; while(*pUser!='*') /*从数据包中读取用户帐号与密码*/ { if(i<20) { username[i]=*pUser; ++i; ++pUser; } } ++pUser; i=0; /*跳过*号*/ while(*pUser!='#') { if(i<20) { userpwd[i]=*pUser; ++i; ++pUser; } } // strcat(userdir,"./"); // strcat(userdir,username); // while(flag!=0) // { if(CheckClient(username,userpwd)==1) { /*返回文件列表*/ //getlist(); sendPack = pack('L',"","",0,1,1,""); strcpy(filelist,""); // flag=1; // return sendPack; } else { sendPack=pack('L',"","",0,0,1,""); /*登陆失败*/ // return sendPack; // } } return sendPack; } break; case 'U': { struct statfs statfsbuf; int count=0; currentFsize=0; if(tpack.ack==9) { strcat(pfilename,tpack.username); // printf("111111111111111111%s\n",userdir); strcat(pfilename,"/"); strcat(pfilename,tpack.filename); // printf("22222222222222222222%s\n",pfilename); // printf("%s\n",pfilename); filesize=tpack.filesize; /*文件名已经存在以后实现*/ statfs("./",&statfsbuf); if((statfsbuf.f_bsize*statfsbuf.f_bfree)<=filesize) { printf("\033[31m磁盘空间不足\033[0m\n"); sendPack=pack('U',"","",0,1,1,""); SSL_write(NewFd,&sendPack,sizeof(struct FilePackage)); exit(1); } if((fd=open(pfilename,O_RDWR|O_CREAT,0777))<0) { perror("open error:\n"); } // printf("%d",fd); sendPack=pack('U',"","",0,0,1,""); SSL_write(NewFd,&sendPack,sizeof(struct FilePackage)); if((count=SSL_read(NewFd,&buff,sizeof(struct FilePackage)))==-1) { perror("read error:\n"); } // printf("%s",buff.buf); // printf("0000000000000cmd is:%c ack is:%d",buff.cmd,buff.ack); while(buff.ack==2) { // printf("-----------------%d\n",count); count=buff.filesize; // printf("---------------+%d\n",count); // strncpy(tFileBuf,buff.buf,count); // count=strlen(tFileBuf); // printf("%s\n",tFileBuf); // printf("1111111111cmd is:%c ack is:%d",buff.cmd,buff.ack); if(write(fd,buff.buf,count)==-1) { perror("wirte error:\n"); } if(SSL_read(NewFd,&buff,sizeof(struct FilePackage))==-1) { perror("read error:\n"); } }//文件上传结束 // memset(userdir,'\0',50); /*写入日志*/ char Log[200]="\0"; strcat(Log,""); strcat(Log,"Client IP: "); strcat(Log,clientIP); strcat(Log,"\n"); strcat(Log,"upload Date: "); strcat(Log,getCurrentTime()); strcat(Log,"File Name: "); strcat(Log,pfilename); strcat(Log," \n"); if((fdlog = open("./log.txt",O_WRONLY|O_APPEND)) == -1) { printf("\033[33mlog.sys file open error!\033[0m\n"); exit(-1); } if((write(fdlog,Log,strlen(Log)))<0) { perror("write long.txt error:\n"); exit(-1); } close(fdlog); if(buff.ack==4) { sendPack = pack('U',"","",0,3,1,""); close(fd); } return sendPack; } } break; case 'S': { // printf("33333333%s",tpack.username); getlist(tpack.username); sendPack = pack('S',filelist,"",0,1,strlen(filelist)+1,""); strcpy(filelist,""); return sendPack; } break; case 'D': { int Fd; char buf[1025]={'\0'}; int count=0; struct stat statbuf; char filename[125]="\0"; struct FilePackage data; if(tpack.ack==9) { strcat(filename,tpack.username); strcat(filename,"/"); strcat(filename,tpack.filename); } if(stat(filename,&statbuf)==-1) { sendPack = pack('D',"","",0,8,1,""); return sendPack; } // if(!S_ISREG(statbuf.st_mode)) // { // perror("*"); // } sendPack=pack('D', " ", filename, statbuf.st_size , 0,1,""); SSL_write(NewFd,&sendPack,sizeof(struct FilePackage)); if((Fd=open(filename,O_RDONLY))==-1) { perror("open error: \n"); } while((count=read(Fd,(void *)buf,1024))>0) { sendPack=pack('D', buf, filename, count , 2,count,""); if((SSL_write(NewFd,&sendPack,sizeof(struct FilePackage)))==-1) { perror("send login message:"); } } sendPack=pack('D', " ", filename, statbuf.st_size , 4,1,""); SSL_write(NewFd,&sendPack,sizeof(struct FilePackage)); // printf("senddata\n"); SSL_read(NewFd,&data,sizeof(struct FilePackage)); if(data.cmd == 'D' && data.ack == 3) { sendPack=pack('\0', "", "", 0,8,1,""); close(Fd); } // memset(userdir,'\0',50); /*写入日志*/ char Log[200]="\0"; strcat(Log,""); strcat(Log,"Client IP: "); strcat(Log,clientIP); strcat(Log,"\n"); strcat(Log,"download Date: "); strcat(Log,getCurrentTime()); strcat(Log,"File Name: "); strcat(Log,filename); strcat(Log," \n"); if((fdlog = open("./log.txt",O_WRONLY|O_APPEND)) == -1) { printf("\033[33mlog.txt file open error!\033[0m\n"); exit(-1); } if((write(fdlog,Log,strlen(Log)))<0) { perror("write long.txt error:\n"); exit(-1); } close(fdlog); return sendPack; } break; } }
void aes_ecb_decrypt(aes *a,MR_BYTE *buff) { int i,j,k; MR_WORD p[4],q[4],*x,*y,*t; #ifdef AES_NI_SUPPORT __m128i ky,m = _mm_loadu_si128((__m128i *) buff); ky = _mm_loadu_si128((__m128i *) &a->rkey[0]); m = _mm_xor_si128 (m, ky); k=NB; for (i=1;i<a->Nr;i++) { ky=_mm_loadu_si128((__m128i *) &a->rkey[k]); m =_mm_aesdec_si128 (m, ky); k+=4; } ky=_mm_loadu_si128((__m128i *) &a->rkey[k]); m=_mm_aesdeclast_si128(m, ky); _mm_storeu_si128((__m128i *)buff, m); #else for (i=j=0;i<NB;i++,j+=4) { p[i]=pack((MR_BYTE *)&buff[j]); p[i]^=a->rkey[i]; } k=NB; x=p; y=q; /* State alternates between x and y */ for (i=1;i<a->Nr;i++) { /* Nr is number of rounds. May be odd. */ #ifndef MR_SMALL_AES y[0]=a->rkey[k]^rtable[MR_TOBYTE(x[0])]^ rtable1[MR_TOBYTE(x[3]>>8)]^ rtable2[MR_TOBYTE(x[2]>>16)]^ rtable3[x[1]>>24]; y[1]=a->rkey[k+1]^rtable[MR_TOBYTE(x[1])]^ rtable1[MR_TOBYTE(x[0]>>8)]^ rtable2[MR_TOBYTE(x[3]>>16)]^ rtable3[x[2]>>24]; y[2]=a->rkey[k+2]^rtable[MR_TOBYTE(x[2])]^ rtable1[MR_TOBYTE(x[1]>>8)]^ rtable2[MR_TOBYTE(x[0]>>16)]^ rtable3[x[3]>>24]; y[3]=a->rkey[k+3]^rtable[MR_TOBYTE(x[3])]^ rtable1[MR_TOBYTE(x[2]>>8)]^ rtable2[MR_TOBYTE(x[1]>>16)]^ rtable3[x[0]>>24]; #else y[0]=a->rkey[k]^rtable[MR_TOBYTE(x[0])]^ ROTL8(rtable[MR_TOBYTE(x[3]>>8)])^ ROTL16(rtable[MR_TOBYTE(x[2]>>16)])^ ROTL24(rtable[x[1]>>24]); y[1]=a->rkey[k+1]^rtable[MR_TOBYTE(x[1])]^ ROTL8(rtable[MR_TOBYTE(x[0]>>8)])^ ROTL16(rtable[MR_TOBYTE(x[3]>>16)])^ ROTL24(rtable[x[2]>>24]); y[2]=a->rkey[k+2]^rtable[MR_TOBYTE(x[2])]^ ROTL8(rtable[MR_TOBYTE(x[1]>>8)])^ ROTL16(rtable[MR_TOBYTE(x[0]>>16)])^ ROTL24(rtable[x[3]>>24]); y[3]=a->rkey[k+3]^rtable[MR_TOBYTE(x[3])]^ ROTL8(rtable[MR_TOBYTE(x[2]>>8)])^ ROTL16(rtable[MR_TOBYTE(x[1]>>16)])^ ROTL24(rtable[x[0]>>24]); #endif k+=4; t=x; x=y; y=t; /* swap pointers */ } /* Last Round */ y[0]=a->rkey[k]^(MR_WORD)rbsub[MR_TOBYTE(x[0])]^ ROTL8((MR_WORD)rbsub[MR_TOBYTE(x[3]>>8)])^ ROTL16((MR_WORD)rbsub[MR_TOBYTE(x[2]>>16)])^ ROTL24((MR_WORD)rbsub[x[1]>>24]); y[1]=a->rkey[k+1]^(MR_WORD)rbsub[MR_TOBYTE(x[1])]^ ROTL8((MR_WORD)rbsub[MR_TOBYTE(x[0]>>8)])^ ROTL16((MR_WORD)rbsub[MR_TOBYTE(x[3]>>16)])^ ROTL24((MR_WORD)rbsub[x[2]>>24]); y[2]=a->rkey[k+2]^(MR_WORD)rbsub[MR_TOBYTE(x[2])]^ ROTL8((MR_WORD)rbsub[MR_TOBYTE(x[1]>>8)])^ ROTL16((MR_WORD)rbsub[MR_TOBYTE(x[0]>>16)])^ ROTL24((MR_WORD)rbsub[x[3]>>24]); y[3]=a->rkey[k+3]^(MR_WORD)rbsub[MR_TOBYTE(x[3])]^ ROTL8((MR_WORD)rbsub[MR_TOBYTE(x[2]>>8)])^ ROTL16((MR_WORD)rbsub[MR_TOBYTE(x[1]>>16)])^ ROTL24((MR_WORD)rbsub[x[0]>>24]); for (i=j=0;i<NB;i++,j+=4) { unpack(y[i],(MR_BYTE *)&buff[j]); x[i]=y[i]=0; /* clean up stack */ } #endif }
void gkey(int nb,int nk,char *key) { /* blocksize=32*nb bits. Key=32*nk bits */ /* currently nb,bk = 4, 6 or 8 */ /* key comes as 4*Nk bytes */ /* Key Scheduler. Create expanded encryption key */ int i,j,k,m,N; int C1,C2,C3; u32 CipherKey[8]; Nb=nb; Nk=nk; /* Nr is number of rounds */ if (Nb>=Nk) Nr=6+Nb; else Nr=6+Nk; C1=1; if (Nb<8) { C2=2; C3=3; } else { C2=3; C3=4; } /* pre-calculate forward and reverse increments */ for (m=j=0;j<nb;j++,m+=3) { fi[m]=(j+C1)%nb; fi[m+1]=(j+C2)%nb; fi[m+2]=(j+C3)%nb; ri[m]=(nb+j-C1)%nb; ri[m+1]=(nb+j-C2)%nb; ri[m+2]=(nb+j-C3)%nb; } N=Nb*(Nr+1); for (i=j=0;i<Nk;i++,j+=4) { CipherKey[i]=pack((u8 *)&key[j]); } for (i=0;i<Nk;i++) fkey[i]=CipherKey[i]; for (j=Nk,k=0;j<N;j+=Nk,k++) { fkey[j]=fkey[j-Nk]^SubByte(ROTL24(fkey[j-1]))^rco[k]; if (Nk<=6) { for (i=1;i<Nk && (i+j)<N;i++) fkey[i+j]=fkey[i+j-Nk]^fkey[i+j-1]; } else { for (i=1;i<4 &&(i+j)<N;i++) fkey[i+j]=fkey[i+j-Nk]^fkey[i+j-1]; if ((j+4)<N) fkey[j+4]=fkey[j+4-Nk]^SubByte(fkey[j+3]); for (i=5;i<Nk && (i+j)<N;i++) fkey[i+j]=fkey[i+j-Nk]^fkey[i+j-1]; } } /* now for the expanded decrypt key in reverse order */ for (j=0;j<Nb;j++) rkey[j+N-Nb]=fkey[j]; for (i=Nb;i<N-Nb;i+=Nb) { k=N-Nb-i; for (j=0;j<Nb;j++) rkey[k+j]=InvMixCol(fkey[i+j]); } for (j=N-Nb;j<N;j++) rkey[j-N+Nb]=fkey[j]; }
bool CCallback::teleportHero(const CGHeroInstance *who, const CGTownInstance *where) { CastleTeleportHero pack(who->id, where->id, 1); sendRequest(&pack); return true; }
int main(int argc, char* argv[]) { uint32 rowsperstrip = (uint32) -1; TIFF *in, *out; uint32 w, h; uint16 samplesperpixel; uint16 bitspersample; uint16 config; uint16 photometric; uint16* red; uint16* green; uint16* blue; tsize_t rowsize; register uint32 row; register tsample_t s; unsigned char *inbuf, *outbuf; char thing[1024]; int c; extern int optind; extern char *optarg; while ((c = getopt(argc, argv, "c:r:R:G:B:")) != -1) switch (c) { case 'c': /* compression scheme */ if (!processCompressOptions(optarg)) usage(); break; case 'r': /* rows/strip */ rowsperstrip = atoi(optarg); break; case 'R': RED = PCT(atoi(optarg)); break; case 'G': GREEN = PCT(atoi(optarg)); break; case 'B': BLUE = PCT(atoi(optarg)); break; case '?': usage(); /*NOTREACHED*/ } if (argc - optind < 2) usage(); in = TIFFOpen(argv[optind], "r"); if (in == NULL) return (-1); photometric = 0; TIFFGetField(in, TIFFTAG_PHOTOMETRIC, &photometric); if (photometric != PHOTOMETRIC_RGB && photometric != PHOTOMETRIC_PALETTE ) { fprintf(stderr, "%s: Bad photometric; can only handle RGB and Palette images.\n", argv[optind]); return (-1); } TIFFGetField(in, TIFFTAG_SAMPLESPERPIXEL, &samplesperpixel); if (samplesperpixel != 1 && samplesperpixel != 3) { fprintf(stderr, "%s: Bad samples/pixel %u.\n", argv[optind], samplesperpixel); return (-1); } TIFFGetField(in, TIFFTAG_BITSPERSAMPLE, &bitspersample); if (bitspersample != 8) { fprintf(stderr, " %s: Sorry, only handle 8-bit samples.\n", argv[optind]); return (-1); } TIFFGetField(in, TIFFTAG_IMAGEWIDTH, &w); TIFFGetField(in, TIFFTAG_IMAGELENGTH, &h); TIFFGetField(in, TIFFTAG_PLANARCONFIG, &config); out = TIFFOpen(argv[optind+1], "w"); if (out == NULL) return (-1); TIFFSetField(out, TIFFTAG_IMAGEWIDTH, w); TIFFSetField(out, TIFFTAG_IMAGELENGTH, h); TIFFSetField(out, TIFFTAG_BITSPERSAMPLE, 8); TIFFSetField(out, TIFFTAG_SAMPLESPERPIXEL, 1); TIFFSetField(out, TIFFTAG_PLANARCONFIG, PLANARCONFIG_CONTIG); cpTags(in, out); if (compression != (uint16) -1) { TIFFSetField(out, TIFFTAG_COMPRESSION, compression); switch (compression) { case COMPRESSION_JPEG: TIFFSetField(out, TIFFTAG_JPEGQUALITY, quality); TIFFSetField(out, TIFFTAG_JPEGCOLORMODE, jpegcolormode); break; case COMPRESSION_LZW: case COMPRESSION_DEFLATE: if (predictor != 0) TIFFSetField(out, TIFFTAG_PREDICTOR, predictor); break; } } TIFFSetField(out, TIFFTAG_PHOTOMETRIC, PHOTOMETRIC_MINISBLACK); sprintf(thing, "B&W version of %s", argv[optind]); TIFFSetField(out, TIFFTAG_IMAGEDESCRIPTION, thing); TIFFSetField(out, TIFFTAG_SOFTWARE, "tiff2bw"); outbuf = (unsigned char *)_TIFFmalloc(TIFFScanlineSize(out)); TIFFSetField(out, TIFFTAG_ROWSPERSTRIP, TIFFDefaultStripSize(out, rowsperstrip)); #define pack(a,b) ((a)<<8 | (b)) switch (pack(photometric, config)) { case pack(PHOTOMETRIC_PALETTE, PLANARCONFIG_CONTIG): case pack(PHOTOMETRIC_PALETTE, PLANARCONFIG_SEPARATE): TIFFGetField(in, TIFFTAG_COLORMAP, &red, &green, &blue); /* * Convert 16-bit colormap to 8-bit (unless it looks * like an old-style 8-bit colormap). */ if (checkcmap(in, 1<<bitspersample, red, green, blue) == 16) { int i; #define CVT(x) (((x) * 255L) / ((1L<<16)-1)) for (i = (1<<bitspersample)-1; i >= 0; i--) { red[i] = CVT(red[i]); green[i] = CVT(green[i]); blue[i] = CVT(blue[i]); } #undef CVT } inbuf = (unsigned char *)_TIFFmalloc(TIFFScanlineSize(in)); for (row = 0; row < h; row++) { if (TIFFReadScanline(in, inbuf, row, 0) < 0) break; compresspalette(outbuf, inbuf, w, red, green, blue); if (TIFFWriteScanline(out, outbuf, row, 0) < 0) break; } break; case pack(PHOTOMETRIC_RGB, PLANARCONFIG_CONTIG): inbuf = (unsigned char *)_TIFFmalloc(TIFFScanlineSize(in)); for (row = 0; row < h; row++) { if (TIFFReadScanline(in, inbuf, row, 0) < 0) break; compresscontig(outbuf, inbuf, w); if (TIFFWriteScanline(out, outbuf, row, 0) < 0) break; } break; case pack(PHOTOMETRIC_RGB, PLANARCONFIG_SEPARATE): rowsize = TIFFScanlineSize(in); inbuf = (unsigned char *)_TIFFmalloc(3*rowsize); for (row = 0; row < h; row++) { for (s = 0; s < 3; s++) if (TIFFReadScanline(in, inbuf+s*rowsize, row, s) < 0) return (-1); compresssep(outbuf, inbuf, inbuf+rowsize, inbuf+2*rowsize, w); if (TIFFWriteScanline(out, outbuf, row, 0) < 0) break; } break; } #undef pack TIFFClose(out); return (0); }
bool CCallback::moveHero(const CGHeroInstance *h, int3 dst) { MoveHero pack(dst,h->id); sendRequest(&pack); return true; }
/* * Release blocks associated with the inode ip and stored in the indirect * block bn. Blocks are free'd in LIFO order up to (but not including) * lastbn. If level is greater than SINGLE, the block is an indirect block * and recursive calls to indirtrunc must be used to cleanse other indirect * blocks. * * NB: triple indirect blocks are untested. */ static int ffs_indirtrunc(struct inode *ip, daddr_t lbn, daddr_t dbn, daddr_t lastbn, int level, int64_t *countp) { int i; struct buf *bp; struct fs *fs = ip->i_fs; int32_t *bap1 = NULL; int64_t *bap2 = NULL; struct vnode *vp; daddr_t nb, nlbn, last; char *copy = NULL; int64_t blkcount, factor, blocksreleased = 0; int nblocks; int error = 0, allerror = 0; const int needswap = UFS_FSNEEDSWAP(fs); #define RBAP(ip, i) (((ip)->i_ump->um_fstype == UFS1) ? \ ufs_rw32(bap1[i], needswap) : ufs_rw64(bap2[i], needswap)) #define BAP_ASSIGN(ip, i, value) \ do { \ if ((ip)->i_ump->um_fstype == UFS1) \ bap1[i] = (value); \ else \ bap2[i] = (value); \ } while(0) /* * Calculate index in current block of last * block to be kept. -1 indicates the entire * block so we need not calculate the index. */ factor = 1; for (i = SINGLE; i < level; i++) factor *= FFS_NINDIR(fs); last = lastbn; if (lastbn > 0) last /= factor; nblocks = btodb(fs->fs_bsize); /* * Get buffer of block pointers, zero those entries corresponding * to blocks to be free'd, and update on disk copy first. Since * double(triple) indirect before single(double) indirect, calls * to bmap on these blocks will fail. However, we already have * the on disk address, so we have to set the b_blkno field * explicitly instead of letting bread do everything for us. */ vp = ITOV(ip); error = ffs_getblk(vp, lbn, FFS_NOBLK, fs->fs_bsize, false, &bp); if (error) { *countp = 0; return error; } if (bp->b_oflags & (BO_DONE | BO_DELWRI)) { /* Braces must be here in case trace evaluates to nothing. */ trace(TR_BREADHIT, pack(vp, fs->fs_bsize), lbn); } else { trace(TR_BREADMISS, pack(vp, fs->fs_bsize), lbn); curlwp->l_ru.ru_inblock++; /* pay for read */ bp->b_flags |= B_READ; bp->b_flags &= ~B_COWDONE; /* we change blkno below */ if (bp->b_bcount > bp->b_bufsize) panic("ffs_indirtrunc: bad buffer size"); bp->b_blkno = dbn; BIO_SETPRIO(bp, BPRIO_TIMECRITICAL); VOP_STRATEGY(vp, bp); error = biowait(bp); if (error == 0) error = fscow_run(bp, true); } if (error) { brelse(bp, 0); *countp = 0; return (error); } if (ip->i_ump->um_fstype == UFS1) bap1 = (int32_t *)bp->b_data; else bap2 = (int64_t *)bp->b_data; if (lastbn >= 0) { copy = kmem_alloc(fs->fs_bsize, KM_SLEEP); memcpy((void *)copy, bp->b_data, (u_int)fs->fs_bsize); for (i = last + 1; i < FFS_NINDIR(fs); i++) BAP_ASSIGN(ip, i, 0); error = bwrite(bp); if (error) allerror = error; if (ip->i_ump->um_fstype == UFS1) bap1 = (int32_t *)copy; else bap2 = (int64_t *)copy; } /* * Recursively free totally unused blocks. */ for (i = FFS_NINDIR(fs) - 1, nlbn = lbn + 1 - i * factor; i > last; i--, nlbn += factor) { nb = RBAP(ip, i); if (nb == 0) continue; if (level > SINGLE) { error = ffs_indirtrunc(ip, nlbn, FFS_FSBTODB(fs, nb), (daddr_t)-1, level - 1, &blkcount); if (error) allerror = error; blocksreleased += blkcount; } if ((ip->i_ump->um_mountp->mnt_wapbl) && ((level > SINGLE) || (ITOV(ip)->v_type != VREG))) { UFS_WAPBL_REGISTER_DEALLOCATION(ip->i_ump->um_mountp, FFS_FSBTODB(fs, nb), fs->fs_bsize); } else ffs_blkfree(fs, ip->i_devvp, nb, fs->fs_bsize, ip->i_number); blocksreleased += nblocks; } /* * Recursively free last partial block. */ if (level > SINGLE && lastbn >= 0) { last = lastbn % factor; nb = RBAP(ip, i); if (nb != 0) { error = ffs_indirtrunc(ip, nlbn, FFS_FSBTODB(fs, nb), last, level - 1, &blkcount); if (error) allerror = error; blocksreleased += blkcount; } } if (copy != NULL) { kmem_free(copy, fs->fs_bsize); } else { brelse(bp, BC_INVAL); } *countp = blocksreleased; return (allerror); }
static enum piglit_result read_format(const struct format_info *tex_info, const struct read_format_info *read_info, uint32_t texels[][4], int num_texels) { size_t texels_size = num_texels * 4 * sizeof(uint32_t); char *expected; char *read; int i; int chans = 0; enum piglit_result result; if (!test_rg && (read_info->format == GL_RED_INTEGER || read_info->format == GL_RG_INTEGER)) { return PIGLIT_SKIP; } if (!test_rgb10_a2ui) { /* Packed integer pixel formats were introduced with * GL_texture_rgb10_a2ui. */ switch (read_info->type) { case GL_INT: case GL_UNSIGNED_INT: case GL_SHORT: case GL_UNSIGNED_SHORT: case GL_BYTE: case GL_UNSIGNED_BYTE: break; default: return PIGLIT_SKIP; } } /* FINISHME: Again, not really sure how to handle sign conversion. */ if (tex_info->sign != read_info->sign) return PIGLIT_SKIP; printf("Reading from %s to %s/%s\n", tex_info->name, read_info->format_name, read_info->type_name); expected = (char *)malloc(texels_size); read = (char *)malloc(texels_size); memset(expected, 0xd0, texels_size); memset(read, 0xd0, texels_size); glGetTexImage(GL_TEXTURE_2D, 0, read_info->format, read_info->type, read); switch (read_info->format) { case GL_RGBA_INTEGER: chans = 4; for (i = 0; i < num_texels; i++) { pack(read_info, expected, i, 0, chans, texels[i][0]); pack(read_info, expected, i, 1, chans, texels[i][1]); pack(read_info, expected, i, 2, chans, texels[i][2]); pack(read_info, expected, i, 3, chans, texels[i][3]); } break; case GL_BGRA_INTEGER: chans = 4; for (i = 0; i < num_texels; i++) { pack(read_info, expected, i, 0, chans, texels[i][2]); pack(read_info, expected, i, 1, chans, texels[i][1]); pack(read_info, expected, i, 2, chans, texels[i][0]); pack(read_info, expected, i, 3, chans, texels[i][3]); } break; case GL_RGB_INTEGER: chans = 3; for (i = 0; i < num_texels; i++) { pack(read_info, expected, i, 0, chans, texels[i][0]); pack(read_info, expected, i, 1, chans, texels[i][1]); pack(read_info, expected, i, 2, chans, texels[i][2]); } break; case GL_BGR_INTEGER: chans = 3; for (i = 0; i < num_texels; i++) { pack(read_info, expected, i, 0, chans, texels[i][2]); pack(read_info, expected, i, 1, chans, texels[i][1]); pack(read_info, expected, i, 2, chans, texels[i][0]); } break; case GL_RED_INTEGER: chans = 1; for (i = 0; i < num_texels; i++) { pack(read_info, expected, i, 0, chans, texels[i][0]); } break; case GL_GREEN_INTEGER: chans = 1; for (i = 0; i < num_texels; i++) { pack(read_info, expected, i, 0, chans, texels[i][1]); } break; case GL_BLUE_INTEGER: chans = 1; for (i = 0; i < num_texels; i++) { pack(read_info, expected, i, 0, chans, texels[i][2]); } break; case GL_ALPHA_INTEGER: chans = 1; for (i = 0; i < num_texels; i++) { pack(read_info, expected, i, 0, chans, texels[i][3]); } break; case GL_RG_INTEGER: chans = 2; for (i = 0; i < num_texels; i++) { pack(read_info, expected, i, 0, chans, texels[i][0]); pack(read_info, expected, i, 1, chans, texels[i][1]); } break; default: assert(0); return PIGLIT_SKIP; } if (memcmp(expected, read, num_texels * chans * read_info->size / 8)) { report_fail(tex_info, read_info, texels, read, expected, num_texels, chans); result = PIGLIT_FAIL; } else { result = PIGLIT_PASS; } free(read); free(expected); return result; }
// --------------------------------------------------------------------- // Driver for Packing // // Should return a 64 bit integer on a 64 bit platform. Could be fixed // later when 64-bit platforms are really available since it doesn't // affect object layout. // --------------------------------------------------------------------- NA_EIDPROC Long NAVersionedObject::drivePack(void *space, short isSpacePtr) { // ----------------------------------------------------------------- // If the object has already been packed, just convert the pointer // of the object to an offset and return its value. That value will // be used by the caller to replace the pointer stored there. // ----------------------------------------------------------------- if (isPacked()) { if (isSpacePtr) return ((Space *)space)->convertToOffset((char *)this); else return ((char *)space - (char *)this); } // ----------------------------------------------------------------- // Make sure the image size and the version ID are set properly // before proceeding on to pack the object. // ----------------------------------------------------------------- Int16 classSize = getClassSize(); if ((classSize % 8) != 0) assert((classSize % 8) == 0); setImageSize(classSize); populateImageVersionIDArray(); // ----------------------------------------------------------------- // Toggle the Endianness of the Version Header if it's not stored // in little-endian form. // // *** DON'T DO THIS JUST YET: PLAN IS TO SUPPORT THIS ONLY FROM // *** SECOND RELEASE. // ----------------------------------------------------------------- #ifndef NA_LITTLE_ENDIAN // toggleEndiannessOfVersionHeader(); #endif // ----------------------------------------------------------------- // Convert members of this object from local platform to reference // platform. // // *** DON'T DO THIS JUST YET: PLAN IS TO SUPPORT THIS ONLY FROM // *** SECOND RELEASE. // ----------------------------------------------------------------- // convertToReferencePlatform(); // ----------------------------------------------------------------- // Mark object as packed, despite it is not completely packed yet. // It is needed because the call that follows to the virtual method // pack() drives the packing of all objects referenced by this // object. If this object is subsequently referenced by another // object down the row, drivePack() will be called on this object // again. At that point of time, we should see the packed flag set // so that "double-packing" can be avoided. // ----------------------------------------------------------------- markAsPacked(); // ----------------------------------------------------------------- // pack() is a virtual method the subclass should redefine to drive // the packing of all objects it references by pointers and convert // those pointers to offsets. It should also convert the endianness // of its members to the reference if necessary. // ----------------------------------------------------------------- setIsSpacePtr( isSpacePtr !=0 ); Long offset = pack(space); // long offset = (isSpacePtr ? pack(space) : pack(space,0)); // ----------------------------------------------------------------- // Make sure the eyeCatcher_ field of the object is proper. Also // clean up the virtual table function pointer, so that the image // look identical each time. // ----------------------------------------------------------------- str_cpy_all(eyeCatcher_,VOBJ_EYE_CATCHER,VOBJ_EYE_CATCHER_SIZE); setVTblPtr(NULL); return offset; }
int pack(const std::wstring& outputFileName, const std::list<std::wstring>& inputFileList) { std::list<std::vector<char>> ls; std::list<unsigned long> lls; std::list<std::wstring>::const_iterator it = inputFileList.begin(); std::list<std::wstring>::const_iterator ie = inputFileList.end(); for (; it != ie; ++it) { if (!pack(*it, ls, lls)) { return -5; } } std::vector<DWORD> header; header.push_back(0xBAD2C0DE); header.push_back(0xDEC0D2BA); header.push_back(0xBABEFACE); header.push_back(0xCEFABEBA); std::vector<char> outputData(sizeof(DWORD) * (ls.size() * 3 + 4)); DWORD offset = outputData.size(); std::list<std::vector<char>>::const_iterator itL = ls.begin(); std::list<std::vector<char>>::const_iterator ieL = ls.end(); std::list<unsigned long>::const_iterator itLL = lls.begin(); for (; itL != ieL; ++itL, ++itLL) { const std::vector<char>& zdata = *itL; outputData.insert(outputData.end(), zdata.begin(), zdata.end()); header.push_back(offset); header.push_back(zdata.size()); header.push_back(*itLL); offset += zdata.size(); } memcpy(&outputData[0], &header[0], header.size() * sizeof(DWORD)); FILE *fOut = _wfopen(outputFileName.c_str(), L"w"); if (!fOut) { return -6; } fprintf(fOut, "static const unsigned char s_data_bin[] = {\n"); #define LINE_DIV 32 const unsigned char *pData = reinterpret_cast<unsigned char*>(&outputData[0]); int DataLen = outputData.size(); for (int i = 0; i < DataLen; i += LINE_DIV) { const unsigned char *ll = pData + i; if (i + LINE_DIV < DataLen) { fprintf(fOut, "0x%02x,0x%02x,0x%02x,0x%02x,0x%02x,0x%02x,0x%02x,0x%02x,0x%02x,0x%02x,0x%02x,0x%02x,0x%02x,0x%02x,0x%02x,0x%02x,0x%02x,0x%02x,0x%02x,0x%02x,0x%02x,0x%02x,0x%02x,0x%02x,0x%02x,0x%02x,0x%02x,0x%02x,0x%02x,0x%02x,0x%02x,0x%02x,\n", ll[0], ll[1], ll[2], ll[3], ll[4], ll[5], ll[6], ll[7], ll[8], ll[9], ll[10], ll[11], ll[12], ll[13], ll[14], ll[15], ll[16], ll[17], ll[18], ll[19], ll[20], ll[21], ll[22], ll[23], ll[24], ll[25], ll[26], ll[27], ll[28], ll[29], ll[30], ll[31]); } else { for (int j = i; j < DataLen; j++) { fprintf(fOut, "0x%02x,", ll[j - i]); } fprintf(fOut, "\n"); } } fprintf(fOut, "};\n\nconst unsigned char *get_data_bin(unsigned long *len)\n{\n\tif (len) *len = sizeof(s_data_bin);\n\treturn s_data_bin;\n}\n"); fclose(fOut); return 0; }
void RectangleUtils::pack(RectanglePointers& rects) { return pack(rects, getBoundingBox(rects)); }
static int tiffcmp(TIFF* tif1, TIFF* tif2) { uint16 config1, config2; tsize_t size1; uint32 s, row; unsigned char *buf1, *buf2; if (!CheckShortTag(tif1, tif2, TIFFTAG_BITSPERSAMPLE, "BitsPerSample")) return (0); if (!CheckShortTag(tif1, tif2, TIFFTAG_SAMPLESPERPIXEL, "SamplesPerPixel")) return (0); if (!CheckLongTag(tif1, tif2, TIFFTAG_IMAGEWIDTH, "ImageWidth")) return (0); if (!cmptags(tif1, tif2)) return (1); (void) TIFFGetField(tif1, TIFFTAG_BITSPERSAMPLE, &bitspersample); (void) TIFFGetField(tif1, TIFFTAG_SAMPLESPERPIXEL, &samplesperpixel); (void) TIFFGetField(tif1, TIFFTAG_IMAGEWIDTH, &imagewidth); (void) TIFFGetField(tif1, TIFFTAG_IMAGELENGTH, &imagelength); (void) TIFFGetField(tif1, TIFFTAG_PLANARCONFIG, &config1); (void) TIFFGetField(tif2, TIFFTAG_PLANARCONFIG, &config2); buf1 = (unsigned char *)_TIFFmalloc(size1 = TIFFScanlineSize(tif1)); buf2 = (unsigned char *)_TIFFmalloc(TIFFScanlineSize(tif2)); if (buf1 == NULL || buf2 == NULL) { fprintf(stderr, "No space for scanline buffers\n"); exit(-1); } if (config1 != config2 && bitspersample != 8 && samplesperpixel > 1) { fprintf(stderr, "Can't handle different planar configuration w/ different bits/sample\n"); goto bad; } #define pack(a,b) ((a)<<8)|(b) switch (pack(config1, config2)) { case pack(PLANARCONFIG_SEPARATE, PLANARCONFIG_CONTIG): for (row = 0; row < imagelength; row++) { if (TIFFReadScanline(tif2, buf2, row, 0) < 0) checkEOF(tif2, row, -1) for (s = 0; s < samplesperpixel; s++) { if (TIFFReadScanline(tif1, buf1, row, s) < 0) checkEOF(tif1, row, s) SeparateCompare(1, s, row, buf2, buf1); } } break; case pack(PLANARCONFIG_CONTIG, PLANARCONFIG_SEPARATE): for (row = 0; row < imagelength; row++) { if (TIFFReadScanline(tif1, buf1, row, 0) < 0) checkEOF(tif1, row, -1) for (s = 0; s < samplesperpixel; s++) { if (TIFFReadScanline(tif2, buf2, row, s) < 0) checkEOF(tif2, row, s) SeparateCompare(0, s, row, buf1, buf2); } } break; case pack(PLANARCONFIG_SEPARATE, PLANARCONFIG_SEPARATE): for (s = 0; s < samplesperpixel; s++) for (row = 0; row < imagelength; row++) { if (TIFFReadScanline(tif1, buf1, row, s) < 0) checkEOF(tif1, row, s) if (TIFFReadScanline(tif2, buf2, row, s) < 0) checkEOF(tif2, row, s) ContigCompare(s, row, buf1, buf2, size1); } break; case pack(PLANARCONFIG_CONTIG, PLANARCONFIG_CONTIG): for (row = 0; row < imagelength; row++) { if (TIFFReadScanline(tif1, buf1, row, 0) < 0) checkEOF(tif1, row, -1) if (TIFFReadScanline(tif2, buf2, row, 0) < 0) checkEOF(tif2, row, -1) ContigCompare(-1, row, buf1, buf2, size1); } break; } if (buf1) _TIFFfree(buf1); if (buf2) _TIFFfree(buf2); return (1); bad: if (stopondiff) exit(1); if (buf1) _TIFFfree(buf1); if (buf2) _TIFFfree(buf2); return (0); }