void text_display::paint_selection(QPainter &painter, selection &selection_area, const QColor &color) { if(focusPolicy() == Qt::NoFocus){ return; //Anything which doesn't accept focus can't be highlighted } QPoint position1 = clip_screen(nibble_to_screen(selection_area.get_start_aligned())); QPoint position2 = clip_screen(nibble_to_screen(selection_area.get_end_aligned())); QRegion area = QRect(0, position1.y(), get_line_characters() * editor_font::get_width(), position2.y() - position1.y() + editor_font::get_height()); if(position1.x()){ area -= QRect(0, position1.y(), position1.x(), editor_font::get_height()); } if(position2.x() < width()){ area -= QRect(position2.x(), position2.y(), get_line_characters() * editor_font::get_width() - position2.x(), editor_font::get_height()); } if(position2.y() >= get_rows() * editor_font::get_height()){ area -= QRect(0, get_rows() * editor_font::get_height(), get_line_characters() * editor_font::get_width(), position2.y()); } painter.setClipRegion(area); painter.fillRect(0, position1.y(), get_line_characters() * editor_font::get_width(), position2.y() - position1.y() + editor_font::get_height(), color); }
/*! * * @return A copy of the product */ Matrix Matrix::diag_mult(const std::vector<double> &diag) const{ Matrix temp(*this); for (int i=0; i<get_cols(); i++) for (int j=0; j<get_rows(); j++) temp(i,j) = (*this)(i*get_rows()+j)*diag[i]; return temp; }
/*! * A const function that sums all the elements on the diagonal of the matrix * @return The sum of all the diagonal elements of the matrix */ double Matrix::sum_diag() const{ double sum=0.0; if (get_rows() != get_cols()) throw std::out_of_range("Matrix needs to be square"); for (int i=0;i<get_rows();i++) sum += (*this)(i,i); return sum; }
/** * \brief * populate a matrix with a tile matrix */ static void tile_matrix(gf2matrix *out, const gf2matrix *tile) { int c = get_cols(tile); int r = get_rows(tile); int i, j; for (i = 0; i < get_rows(out); i += r) { for (j = 0; j < get_cols(out); j += c) { copy_matrix_to_offset(out, tile, i, j); } } }
matrix_t matrix_t::solve(matrix_t const &rhs) const { stack::fe_asserter dummy{}; // it appears as if dgesv works only for square matrices Oo // --> if the matrix was rectangular, then they system would be over/under determined // and we would need least squares instead (LAPACKE_dgels) stack_assert(get_rows() == get_cols()); stack_assert(this->get_rows() == rhs.get_rows()); // TODO assert that this matrix is not singular matrix_t A = this->clone(); // will be overwritten by LU factorization matrix_t b = rhs.clone(); // thes solution is overwritten in b vector_ll_t ipiv{A.get_rows()}; stack_assert(0 == LAPACKE_dgesv(LAPACK_COL_MAJOR, A.get_rows(), rhs.get_cols()/*nrhs*/, A.get_data(), A.ld(), ipiv.get_data(), b.get_data(), b.ld())); return b; }
void VFrame::to_ram() { #ifdef HAVE_GL switch(opengl_state) { // Only pbuffer is supported since this is only called after the // overlay operation onto the pbuffer. case VFrame::SCREEN: if(pbuffer) { enable_opengl(); printf("VFrame::to_ram %d %d\n", get_w(), get_h()); glReadPixels(0, 0, get_w(), get_h(), GL_RGB, GL_UNSIGNED_BYTE, get_rows()[0]); flip_vert(); } opengl_state = VFrame::RAM; return; } #endif }
void Matrix::printmi() const{ for (int i=0; i<get_rows(); i++) { for (int j=0; j<get_cols(); j++) printf(" %.3d ", (int) (*this)(i,j)); std::cout << std::endl; } }
/** * \brief combine A, B, C, D into a new matrix * in the following order: * | A B | * | C D | */ static gf2matrix *combine_matrices(const gf2matrix *A, const gf2matrix *B, const gf2matrix *C, const gf2matrix *D) { gf2matrix *result = NULL; assert(get_rows(A) + get_rows(C) == get_rows(B) + get_rows(D)); assert(get_cols(A) + get_cols(B) == get_cols(C) + get_cols(D)); result = new_matrix(get_rows(A) + get_rows(C), get_cols(A) + get_cols(B)); assert(copy_matrix_to_offset(result, A, 0, 0) ==0); assert(copy_matrix_to_offset(result, C, get_rows(A), 0) ==0); assert(copy_matrix_to_offset(result, B, 0, get_cols(A)) ==0); assert(copy_matrix_to_offset(result, D, get_rows(A), get_cols(A)) ==0); return result; }
int slice_matrix_vertically(gf2matrix *slices[], int count, const gf2matrix *src) { int i; const size_t slice_cols = get_cols(src) / count; for (i = 0; i < count; ++i) { size_t start_col = i * slice_cols; slices[i] = extract_region(NULL, src, 0, start_col, get_rows(src), slice_cols); } return 0; }
void VFrame::transfer_from(VFrame *frame) { BC_CModels::transfer(get_rows(), frame->get_rows(), y, u, v, frame->get_y(), frame->get_u(), frame->get_v(), 0, 0, frame->get_w(), frame->get_h(), 0, 0, w, h, frame->get_color_model(), color_model, 0, frame->get_bytes_per_line(), bytes_per_line); }
static gint compute_lines (ClutterFlowLayout *self, gfloat avail_width, gfloat avail_height) { ClutterFlowLayoutPrivate *priv = self->priv; if (priv->orientation == CLUTTER_FLOW_HORIZONTAL) return get_columns (self, avail_width); else return get_rows (self, avail_height); }
/* * Read database answer and fill the structure */ int db_oracle_store_result(const db_con_t* _h, db_res_t** _r) { dmap_t dmap; int rc; db_res_t* r; ora_con_t* con; OCIStmt* hs; if (!_h || !_r) { badparam: LM_ERR("invalid parameter\n"); return -1; } con = CON_ORA(_h); { query_data_t *pcb = con->pqdata; if (!pcb || !pcb->_rs) goto badparam; hs = *pcb->_rs; pcb->_rs = NULL; /* paranoid for next call */ } rc = -1; if (_r) *_r = NULL; /* unification for all errors */ r = db_new_result(); if (!r) { LM_ERR("no memory left\n"); goto done; } if (get_columns(con, r, hs, &dmap) < 0) { LM_ERR("error while getting column names\n"); goto done; } if (get_rows(con, r, hs, &dmap) < 0) { LM_ERR("error while converting rows\n"); db_free_columns(r); goto done; } rc = 0; *_r = r; done: OCIHandleFree(hs, OCI_HTYPE_STMT); return rc; }
int mul_array_by_matrix(uint8_t *result, const gf2matrix *m, const uint8_t *bytes) { /** * 1. convert the input byte array to a matrix (vector) * 2. multiply vector by m; obtain result matrix * 3. convert result matrix into byte array */ int i; int octets = get_rows(m) / 8; gf2matrix *prod; gf2matrix *vec = new_matrix(get_rows(m), 1); for (i = 0; i < octets; ++i) { byte2vector_offset(vec, bytes[i], i * 8); } prod = mul_matrices(NULL, m, vec); for (i = 0; i < octets; ++i) { vector2byte_offset(&result[i], prod, i * 8); } free_matrix(vec); free_matrix(prod); return 0; }
int main( int argc, char* argv[] ) { if ( !arg_quant_check( argc ) ) return 1; FILE *file = fopen(argv[1], "r"); if ( !file ) { printf("Cannot open the file\n"); return 1; } Matrix* matrix = create_matrix_from_file(file); float norm = norm_l(matrix,get_rows(matrix), get_cols(matrix)); printf("L-norm = %2.2f\n",norm); fclose(file); free_matrix(matrix); return 0; }
/* parses a line of the file * tries to set the corresponding row in the matrix * returns false on error */ bool parse_row(char* s, int row, LinearProgram* lp) { assert(lp_is_valid(lp)); assert(row >= 0); assert(row < get_rows(lp)); char* end_ptr; int cols = get_cols(lp); int i; for (i = 0; i < cols; i++) { num_t num = parse_num(s, &end_ptr); if (!is_num_valid(num, s, end_ptr)) { return false; } set_coef(lp, row, i, num); s = end_ptr; } s = parse_type(s, row, lp); if (NULL == s) { return false; } num_t num = parse_num(s, &end_ptr); if (!is_num_valid(num, s, end_ptr)) { return false; } s = end_ptr; s = skip_spaces(s); if ('\0' != *s) { return false; } set_rhs(lp, row, num); assert(lp_is_valid(lp)); return true; }
int mul_byte_by_matrix(uint8_t *result, const gf2matrix *m, uint8_t byte) { /** * 1. convert byte to a matrix (vector) * 2. multiply vector by m; obtain result matrix * 3. convert result matrix into byte array */ int i; int octets = get_rows(m) / 8; gf2matrix *vec = new_matrix(8, 1); byte2vector(vec, byte); gf2matrix *prod = mul_matrices(NULL, (gf2matrix *) m, vec); for (i = 0; i < octets; ++i) { vector2byte_offset(&result[i], prod, i * 8); } free_matrix(vec); free_matrix(prod); return 0; }
int VFrame::write_png(const char *path) { png_structp png_ptr = png_create_write_struct(PNG_LIBPNG_VER_STRING, 0, 0, 0); png_infop info_ptr = png_create_info_struct(png_ptr); FILE *out_fd = fopen(path, "w"); if(!out_fd) { printf("VFrame::write_png %d %s %s\n", __LINE__, path, strerror(errno)); return 1; } int png_cmodel = PNG_COLOR_TYPE_RGB; switch(get_color_model()) { case BC_RGB888: case BC_YUV888: png_cmodel = PNG_COLOR_TYPE_RGB; break; case BC_A8: png_cmodel = PNG_COLOR_TYPE_GRAY; break; } png_init_io(png_ptr, out_fd); png_set_compression_level(png_ptr, 9); png_set_IHDR(png_ptr, info_ptr, get_w(), get_h(), 8, png_cmodel, PNG_INTERLACE_NONE, PNG_COMPRESSION_TYPE_DEFAULT, PNG_FILTER_TYPE_DEFAULT); png_write_info(png_ptr, info_ptr); png_write_image(png_ptr, get_rows()); png_write_end(png_ptr, info_ptr); png_destroy_write_struct(&png_ptr, &info_ptr); fclose(out_fd); return 0; }
int make_block_invertible_matrix_pair(gf2matrix **m, gf2matrix **minv, int bits) { int rc = 0; int i, j; gf2matrix *out = NULL, *outinv = NULL; assert(bits % 4 == 0); assert(m); while (out == NULL || get_rows(out) != bits) { gf2matrix *temp = extend_block_invertible_by2(out); free_matrix(out); out = dup_matrix(temp); free_matrix(temp); } *m = out; if (minv) { outinv = invert_matrix(NULL, out); assert(outinv); *minv = outinv; } return rc; }
/* * keypad_scan: perform a single scan of keyboard. Returns keycode of * key that was pressed (or -1 if nothing). */ int keypad_scan( void ) { int row, col; int pressed = -1; leds_off( ); // turn off LEDs during scan keypad_write_cols( ~1 ); // single zero at column 0 data_h( ); // shift in ones for( col = 0; col < MAX_COLS; col++ ) { keypad_state[col] = get_rows( ); clk_h( ); clk_l( ); } keypad_write_cols( ~leds ); leds_on( ); // keyboard has been scanned, now look for pressed keys for( col = 0; col < MAX_COLS; col++ ) { uint8_t diff = keypad_state[col] ^ keypad_prev[col]; if( diff ) { for( row = 0; row < MAX_ROWS; row++ ) { uint8_t mask = 1 << row; if( diff & mask & keypad_state[col] ) pressed = row * 16 + col; } } keypad_prev[col] = keypad_state[col]; } return pressed; }
/* NB: may include invisible iters (because they are collapsed) */ static void tree_view_random_iter (GtkTreeView *treeview, GtkTreeIter *iter) { guint n_rows = get_rows (treeview); guint i = g_random_int_range (0, n_rows); GtkTreeModel *model; model = gtk_tree_view_get_model (treeview); if (!gtk_tree_model_get_iter_first (model, iter)) return; while (i-- > 0) { if (!tree_model_iter_step (model, iter)) { g_assert_not_reached (); return; } } return; }
static void clutter_flow_layout_get_preferred_width (ClutterLayoutManager *manager, ClutterContainer *container, gfloat for_height, gfloat *min_width_p, gfloat *nat_width_p) { ClutterFlowLayoutPrivate *priv = CLUTTER_FLOW_LAYOUT (manager)->priv; gint n_rows, line_item_count, line_count; gfloat total_min_width, total_natural_width; gfloat line_min_width, line_natural_width; gfloat max_min_width, max_natural_width; ClutterActor *actor, *child; ClutterActorIter iter; gfloat item_y; n_rows = get_rows (CLUTTER_FLOW_LAYOUT (manager), for_height); total_min_width = 0; total_natural_width = 0; line_min_width = 0; line_natural_width = 0; line_item_count = 0; line_count = 0; item_y = 0; actor = CLUTTER_ACTOR (container); /* clear the line width arrays */ if (priv->line_min != NULL) g_array_free (priv->line_min, TRUE); if (priv->line_natural != NULL) g_array_free (priv->line_natural, TRUE); priv->line_min = g_array_sized_new (FALSE, FALSE, sizeof (gfloat), 16); priv->line_natural = g_array_sized_new (FALSE, FALSE, sizeof (gfloat), 16); if (clutter_actor_get_n_children (actor) != 0) line_count = 1; max_min_width = max_natural_width = 0; clutter_actor_iter_init (&iter, actor); while (clutter_actor_iter_next (&iter, &child)) { gfloat child_min, child_natural; gfloat new_y, item_height; if (!CLUTTER_ACTOR_IS_VISIBLE (child)) continue; if (priv->orientation == CLUTTER_FLOW_VERTICAL && for_height > 0) { clutter_actor_get_preferred_height (child, -1, &child_min, &child_natural); if ((priv->snap_to_grid && line_item_count == n_rows) || (!priv->snap_to_grid && item_y + child_natural > for_height)) { total_min_width += line_min_width; total_natural_width += line_natural_width; g_array_append_val (priv->line_min, line_min_width); g_array_append_val (priv->line_natural, line_natural_width); line_min_width = line_natural_width = 0; line_item_count = 0; line_count += 1; item_y = 0; } if (priv->snap_to_grid) { new_y = ((line_item_count + 1) * (for_height + priv->row_spacing)) / n_rows; item_height = new_y - item_y - priv->row_spacing; } else { new_y = item_y + child_natural + priv->row_spacing; item_height = child_natural; } clutter_actor_get_preferred_width (child, item_height, &child_min, &child_natural); line_min_width = MAX (line_min_width, child_min); line_natural_width = MAX (line_natural_width, child_natural); item_y = new_y; line_item_count += 1; max_min_width = MAX (max_min_width, line_min_width); max_natural_width = MAX (max_natural_width, line_natural_width); } else { clutter_actor_get_preferred_width (child, for_height, &child_min, &child_natural); max_min_width = MAX (max_min_width, child_min); max_natural_width = MAX (max_natural_width, child_natural); total_min_width += max_min_width; total_natural_width += max_natural_width; line_count += 1; } } priv->col_width = max_natural_width; if (priv->max_col_width > 0 && priv->col_width > priv->max_col_width) priv->col_width = MAX (priv->max_col_width, max_min_width); if (priv->col_width < priv->min_col_width) priv->col_width = priv->min_col_width; if (priv->orientation == CLUTTER_FLOW_VERTICAL && for_height > 0) { /* if we have a non-full row we need to add it */ if (line_item_count > 0) { total_min_width += line_min_width; total_natural_width += line_natural_width; g_array_append_val (priv->line_min, line_min_width); g_array_append_val (priv->line_natural, line_natural_width); } priv->line_count = line_count; if (priv->line_count > 0) { gfloat total_spacing; total_spacing = priv->col_spacing * (priv->line_count - 1); total_min_width += total_spacing; total_natural_width += total_spacing; } } else { g_array_append_val (priv->line_min, line_min_width); g_array_append_val (priv->line_natural, line_natural_width); priv->line_count = line_count; if (priv->line_count > 0) { gfloat total_spacing; total_spacing = priv->col_spacing * (priv->line_count - 1); total_min_width += total_spacing; total_natural_width += total_spacing; } } CLUTTER_NOTE (LAYOUT, "Flow[w]: %d lines (%d per line): w [ %.2f, %.2f ] for h %.2f", n_rows, priv->line_count, total_min_width, total_natural_width, for_height); priv->req_height = for_height; if (min_width_p) *min_width_p = max_min_width; if (nat_width_p) *nat_width_p = total_natural_width; }
void VFrame::to_texture() { #ifdef HAVE_GL // Must be here so user can create textures without copying data by setting // opengl_state to TEXTURE. BC_Texture::new_texture(&texture, get_w(), get_h(), get_color_model()); // Determine what to do based on state switch(opengl_state) { case VFrame::TEXTURE: return; case VFrame::SCREEN: if((get_w() % 4) || (get_h() % 4)) { printf("VFrame::to_texture w=%d h=%d\n", get_w(), get_h()); return; } if(pbuffer) { enable_opengl(); screen_to_texture(); } opengl_state = VFrame::TEXTURE; return; } //printf("VFrame::to_texture %d\n", texture_id); switch(color_model) { case BC_RGB888: case BC_YUV888: glTexSubImage2D(GL_TEXTURE_2D, 0, 0, 0, get_w(), get_h(), GL_RGB, GL_UNSIGNED_BYTE, get_rows()[0]); break; case BC_RGBA8888: case BC_YUVA8888: glTexSubImage2D(GL_TEXTURE_2D, 0, 0, 0, get_w(), get_h(), GL_RGBA, GL_UNSIGNED_BYTE, get_rows()[0]); break; case BC_RGB_FLOAT: glTexSubImage2D(GL_TEXTURE_2D, 0, 0, 0, get_w(), get_h(), GL_RGB, GL_FLOAT, get_rows()[0]); break; case BC_RGBA_FLOAT: glTexSubImage2D(GL_TEXTURE_2D, 0, 0, 0, get_w(), get_h(), GL_RGBA, GL_FLOAT, get_rows()[0]); break; default: fprintf(stderr, "VFrame::to_texture: unsupported color model %d.\n", color_model); break; } opengl_state = VFrame::TEXTURE; #endif }
int VFrame::read_png(unsigned char *data) { png_structp png_ptr = png_create_read_struct(PNG_LIBPNG_VER_STRING, 0, 0, 0); png_infop info_ptr = png_create_info_struct(png_ptr); int new_color_model; int have_alpha = 0; image_offset = 0; image = data + 4; image_size = (((unsigned long)data[0]) << 24) | (((unsigned long)data[1]) << 16) | (((unsigned long)data[2]) << 8) | (unsigned char)data[3]; png_set_read_fn(png_ptr, this, PngReadFunction::png_read_function); png_read_info(png_ptr, info_ptr); w = png_get_image_width(png_ptr, info_ptr); h = png_get_image_height(png_ptr, info_ptr); int src_color_model = png_get_color_type(png_ptr, info_ptr); /* tell libpng to strip 16 bit/color files down to 8 bits/color */ png_set_strip_16(png_ptr); /* extract multiple pixels with bit depths of 1, 2, and 4 from a single * byte into separate bytes (useful for paletted and grayscale images). */ png_set_packing(png_ptr); /* expand paletted colors into true RGB triplets */ if (src_color_model == PNG_COLOR_TYPE_PALETTE) png_set_expand(png_ptr); /* expand grayscale images to the full 8 bits from 1, 2, or 4 bits/pixel */ if (src_color_model == PNG_COLOR_TYPE_GRAY && png_get_bit_depth(png_ptr, info_ptr) < 8) png_set_expand(png_ptr); if (src_color_model == PNG_COLOR_TYPE_GRAY || src_color_model == PNG_COLOR_TYPE_GRAY_ALPHA) png_set_gray_to_rgb(png_ptr); /* expand paletted or RGB images with transparency to full alpha channels * so the data will be available as RGBA quartets */ if (png_get_valid(png_ptr, info_ptr, PNG_INFO_tRNS)){ have_alpha = 1; png_set_expand(png_ptr); } switch(src_color_model) { case PNG_COLOR_TYPE_GRAY: case PNG_COLOR_TYPE_RGB: new_color_model = BC_RGB888; break; case PNG_COLOR_TYPE_GRAY_ALPHA: case PNG_COLOR_TYPE_RGB_ALPHA: default: new_color_model = BC_RGBA8888; break; case PNG_COLOR_TYPE_PALETTE: if(have_alpha) new_color_model = BC_RGBA8888; else new_color_model = BC_RGB888; } reallocate(NULL, 0, 0, 0, w, h, new_color_model, -1); png_read_image(png_ptr, get_rows()); png_destroy_read_struct(&png_ptr, &info_ptr, NULL); return 0; }
while (i-- > 0) { if (!tree_model_iter_step (model, iter)) { g_assert_not_reached (); return; } } return; } static void delete (GtkTreeView *treeview) { guint n_rows = get_rows (treeview); GtkTreeModel *model; GtkTreeIter iter; model = gtk_tree_view_get_model (treeview); tree_view_random_iter (treeview, &iter); n_rows -= count_children (model, &iter) + 1; log_operation (model, &iter, "remove"); gtk_tree_store_remove (GTK_TREE_STORE (model), &iter); set_rows (treeview, n_rows); } static void add_one (GtkTreeModel *model,
static bool sp_png_write_rgba_striped(SPDocument *doc, gchar const *filename, unsigned long int width, unsigned long int height, double xdpi, double ydpi, int (* get_rows)(guchar const **rows, void **to_free, int row, int num_rows, void *data), void *data) { struct SPEBP *ebp = (struct SPEBP *) data; FILE *fp; png_structp png_ptr; png_infop info_ptr; png_color_8 sig_bit; png_uint_32 r; g_return_val_if_fail(filename != NULL, false); g_return_val_if_fail(data != NULL, false); /* open the file */ Inkscape::IO::dump_fopen_call(filename, "M"); fp = Inkscape::IO::fopen_utf8name(filename, "wb"); g_return_val_if_fail(fp != NULL, false); /* Create and initialize the png_struct with the desired error handler * functions. If you want to use the default stderr and longjump method, * you can supply NULL for the last three parameters. We also check that * the library version is compatible with the one used at compile time, * in case we are using dynamically linked libraries. REQUIRED. */ png_ptr = png_create_write_struct(PNG_LIBPNG_VER_STRING, NULL, NULL, NULL); if (png_ptr == NULL) { fclose(fp); return false; } /* Allocate/initialize the image information data. REQUIRED */ info_ptr = png_create_info_struct(png_ptr); if (info_ptr == NULL) { fclose(fp); png_destroy_write_struct(&png_ptr, NULL); return false; } /* Set error handling. REQUIRED if you aren't supplying your own * error hadnling functions in the png_create_write_struct() call. */ if (setjmp(png_jmpbuf(png_ptr))) { // If we get here, we had a problem reading the file fclose(fp); png_destroy_write_struct(&png_ptr, &info_ptr); return false; } /* set up the output control if you are using standard C streams */ png_init_io(png_ptr, fp); /* Set the image information here. Width and height are up to 2^31, * bit_depth is one of 1, 2, 4, 8, or 16, but valid values also depend on * the color_type selected. color_type is one of PNG_COLOR_TYPE_GRAY, * PNG_COLOR_TYPE_GRAY_ALPHA, PNG_COLOR_TYPE_PALETTE, PNG_COLOR_TYPE_RGB, * or PNG_COLOR_TYPE_RGB_ALPHA. interlace is either PNG_INTERLACE_NONE or * PNG_INTERLACE_ADAM7, and the compression_type and filter_type MUST * currently be PNG_COMPRESSION_TYPE_BASE and PNG_FILTER_TYPE_BASE. REQUIRED */ png_set_IHDR(png_ptr, info_ptr, width, height, 8, /* bit_depth */ PNG_COLOR_TYPE_RGB_ALPHA, PNG_INTERLACE_NONE, PNG_COMPRESSION_TYPE_BASE, PNG_FILTER_TYPE_BASE); /* otherwise, if we are dealing with a color image then */ sig_bit.red = 8; sig_bit.green = 8; sig_bit.blue = 8; /* if the image has an alpha channel then */ sig_bit.alpha = 8; png_set_sBIT(png_ptr, info_ptr, &sig_bit); PngTextList textList; textList.add("Software", "www.inkscape.org"); // Made by Inkscape comment { const gchar* pngToDc[] = {"Title", "title", "Author", "creator", "Description", "description", //"Copyright", "", "Creation Time", "date", //"Disclaimer", "", //"Warning", "", "Source", "source" //"Comment", "" }; for (size_t i = 0; i < G_N_ELEMENTS(pngToDc); i += 2) { struct rdf_work_entity_t * entity = rdf_find_entity ( pngToDc[i + 1] ); if (entity) { gchar const* data = rdf_get_work_entity(doc, entity); if (data && *data) { textList.add(pngToDc[i], data); } } else { g_warning("Unable to find entity [%s]", pngToDc[i + 1]); } } struct rdf_license_t *license = rdf_get_license(doc); if (license) { if (license->name && license->uri) { gchar* tmp = g_strdup_printf("%s %s", license->name, license->uri); textList.add("Copyright", tmp); g_free(tmp); } else if (license->name) { textList.add("Copyright", license->name); } else if (license->uri) { textList.add("Copyright", license->uri); } } } if (textList.getCount() > 0) { png_set_text(png_ptr, info_ptr, textList.getPtext(), textList.getCount()); } /* other optional chunks like cHRM, bKGD, tRNS, tIME, oFFs, pHYs, */ /* note that if sRGB is present the cHRM chunk must be ignored * on read and must be written in accordance with the sRGB profile */ png_set_pHYs(png_ptr, info_ptr, unsigned(xdpi / 0.0254 + 0.5), unsigned(ydpi / 0.0254 + 0.5), PNG_RESOLUTION_METER); /* Write the file header information. REQUIRED */ png_write_info(png_ptr, info_ptr); /* Once we write out the header, the compression type on the text * chunks gets changed to PNG_TEXT_COMPRESSION_NONE_WR or * PNG_TEXT_COMPRESSION_zTXt_WR, so it doesn't get written out again * at the end. */ /* set up the transformations you want. Note that these are * all optional. Only call them if you want them. */ /* --- CUT --- */ /* The easiest way to write the image (you may have a different memory * layout, however, so choose what fits your needs best). You need to * use the first method if you aren't handling interlacing yourself. */ png_bytep* row_pointers = new png_bytep[ebp->sheight]; r = 0; while (r < static_cast<png_uint_32>(height)) { void *to_free; int n = get_rows((unsigned char const **) row_pointers, &to_free, r, height-r, data); if (!n) break; png_write_rows(png_ptr, row_pointers, n); g_free(to_free); r += n; } delete[] row_pointers; /* You can write optional chunks like tEXt, zTXt, and tIME at the end * as well. */ /* It is REQUIRED to call this to finish writing the rest of the file */ png_write_end(png_ptr, info_ptr); /* if you allocated any text comments, free them here */ /* clean up after the write, and free any memory allocated */ png_destroy_write_struct(&png_ptr, &info_ptr); /* close the file */ fclose(fp); /* that's it */ return true; }
/** * @detail * All variables are named as in the fore mentioned paper * 1. Use a row of blocks of Matrix M to create a matrix X * 2. Use a column of blocks of Matrix M to create a matrix Y * 3. Get invertible matrices P and Q such that P(X.Minv.Y)Q = [I 0] * (I is of r dimension; 0 is of 2-r dimension; 0 < r < 3) * 4. Define matrix A as follows: * a) if r = 0 then A = I * b) if r = 1 then A = [[1 1] [1 0]] * c) if r = 2 then A = [[0 1] [1 1]] * 5. Then the following is a (t+2, 2) block invertible matrix: * | M Y | * | X X.Minv.Y + Pinv.A.Qinv | */ static gf2matrix *extend_block_invertible_by2(const gf2matrix *m) { gf2matrix *result = NULL; gf2matrix *x = NULL, *y = NULL; int multiples = get_rows(m) / 2; int x_start = get_random(0, multiples - 1) * 2; int y_start = get_random(0, multiples - 1) * 2; if (!m) { gf2matrix *_2x2; get_2x2invertible_pair(get_random(0, MAX_2X2_INVERTIBLES - 1), &_2x2, NULL); result = dup_matrix(_2x2); return result; } /* print_matrix(m, "Extending m by 2:"); */ /* step 1 */ x = extract_block_row(NULL, x_start, m); assert(x); /* print_matrix(x, "X:"); */ /* step 2 */ y = extract_block_col(NULL, y_start, m); assert(y); /* print_matrix(y, "Y:"); */ { /* steps 3, 4, 5 */ int r; /* r is the rank of X.Minv.Y */ gf2matrix *i0mat = new_matrix(2, 2); gf2matrix *prod = new_matrix(2, 2); gf2matrix *temp = NULL; gf2matrix *mInv = invert_matrix(NULL, m); gf2matrix *xminvy = NULL; gf2matrix *a2 = NULL; { assert(mInv); /* calculate X.Minv.Y */ gf2matrix *minvy = mul_matrices(NULL, mInv, y); xminvy = mul_matrices(NULL, x, minvy); assert(xminvy); free_matrix(minvy); } /* print_matrix(xminvy, "xM-1y: "); */ r = calc_rank(xminvy); /* printf("rank of X.Minv.Y = %d\n", r); */ init_IO_matrix(i0mat, r); /* print_matrix(i0mat, "I0:"); */ a2 = make_A2_matrix(r); temp = new_matrix(2, 2); while (!result) { int i, j, i_tries, j_tries; for (i = get_random(0, MAX_2X2_INVERTIBLES - 1), i_tries = 0; i_tries < MAX_2X2_INVERTIBLES && !result; i = (i + 1) % MAX_2X2_INVERTIBLES, ++i_tries) { gf2matrix *q, *qinv; get_2x2invertible_pair(i, &q, &qinv); /* print_matrix(q, "Q:"); */ mul_matrices(temp, xminvy, q); assert(temp); for (j = get_random(0, MAX_2X2_INVERTIBLES - 1), j_tries = 0; j_tries < MAX_2X2_INVERTIBLES && !result; j = (j + 1) % MAX_2X2_INVERTIBLES, ++j_tries) { gf2matrix *p, *pinv; get_2x2invertible_pair(j, &p, &pinv); mul_matrices(prod, p, temp); assert(prod); /* print_matrix(p, "P:"); */ /* print_matrix(prod, "P.X.Minv.Y.Q:"); */ if (comp_matrices(prod, i0mat) == 0) { /* step 5 */ result = extend_by_blocks(m, x, y, xminvy, pinv, a2, qinv); assert(result); break; } } } } free_matrix(a2); free_matrix(xminvy); free_matrix(mInv); free_matrix(prod); free_matrix(temp); free_matrix(i0mat); if (!result) printf("incorrect matrix expansion algorithm"); } cleanup: free_matrix(y); free_matrix(x); return result; }
int VFrame::read_png(const unsigned char *data, long img_sz) { // Test for RAW format if(data[0] == 'R' && data[1] == 'A' && data[2] == 'W' && data[3] == ' ') { int new_color_model = BC_RGBA8888; w = data[4] | (data[5] << 8) | (data[6] << 16) | (data[7] << 24); h = data[8] | (data[9] << 8) | (data[10] << 16) | (data[11] << 24); int components = data[12]; new_color_model = components == 3 ? BC_RGB888 : BC_RGBA8888; // This shares the data directly // reallocate(data + 20, 0, 0, 0, w, h, new_color_model, -1); // Can't use shared data for theme since button constructions overlay the // images directly. reallocate(NULL, -1, 0, 0, 0, w, h, new_color_model, -1); memcpy(get_data(), data + 16, w * h * components); } else if(data[0] == 0x89 && data[1] == 'P' && data[2] == 'N' && data[3] == 'G') { int have_alpha = 0; png_structp png_ptr = png_create_read_struct(PNG_LIBPNG_VER_STRING, 0, 0, 0); png_infop info_ptr = png_create_info_struct(png_ptr); int new_color_model; image_offset = 0; image = data; image_size = img_sz; png_set_read_fn(png_ptr, this, PngReadFunction::png_read_function); png_read_info(png_ptr, info_ptr); w = png_get_image_width(png_ptr, info_ptr); h = png_get_image_height(png_ptr, info_ptr); int src_color_model = png_get_color_type(png_ptr, info_ptr); /* tell libpng to strip 16 bit/color files down to 8 bits/color */ png_set_strip_16(png_ptr); /* extract multiple pixels with bit depths of 1, 2, and 4 from a single * byte into separate bytes (useful for paletted and grayscale images). */ png_set_packing(png_ptr); /* expand paletted colors into true RGB triplets */ if (src_color_model == PNG_COLOR_TYPE_PALETTE) png_set_expand(png_ptr); /* expand grayscale images to the full 8 bits from 1, 2, or 4 bits/pixel */ if (src_color_model == PNG_COLOR_TYPE_GRAY && png_get_bit_depth(png_ptr, info_ptr) < 8) png_set_expand(png_ptr); if (src_color_model == PNG_COLOR_TYPE_GRAY || src_color_model == PNG_COLOR_TYPE_GRAY_ALPHA) png_set_gray_to_rgb(png_ptr); /* expand paletted or RGB images with transparency to full alpha channels * so the data will be available as RGBA quartets */ if (png_get_valid(png_ptr, info_ptr, PNG_INFO_tRNS)){ have_alpha = 1; png_set_expand(png_ptr); } switch(src_color_model) { case PNG_COLOR_TYPE_GRAY: case PNG_COLOR_TYPE_RGB: new_color_model = BC_RGB888; break; case PNG_COLOR_TYPE_GRAY_ALPHA: case PNG_COLOR_TYPE_RGB_ALPHA: default: new_color_model = BC_RGBA8888; break; case PNG_COLOR_TYPE_PALETTE: if(have_alpha) new_color_model = BC_RGBA8888; else new_color_model = BC_RGB888; } reallocate(NULL, -1, 0, 0, 0, w, h, new_color_model, -1); //printf("VFrame::read_png %d %d %d %p\n", __LINE__, w, h, get_rows()); png_read_image(png_ptr, get_rows()); png_destroy_read_struct(&png_ptr, &info_ptr, NULL); } else { printf("VFrame::read_png %d: unknown file format" " 0x%02x 0x%02x 0x%02x 0x%02x\n", __LINE__, data[4], data[5], data[6], data[7]); } return 0; }
QSize text_display::sizeHint () const { const int pad = 2; return QSize(editor_font::get_width() * get_line_characters() + pad, editor_font::get_height() * get_rows()); }
void text_display::paintEvent(QPaintEvent *event) { int offset = get_offset(); int end_offset = get_rows() * get_columns() + offset; QPainter painter(this); QColor text = palette().color(QPalette::WindowText); painter.setPen(text); painter.setFont(editor_font::get_font()); painter.setClipping(true); const bookmark_map *bookmarks = buffer->get_bookmark_map(); if(bookmarks){ for(const auto &bookmark : *bookmarks){ selection bookmark_selection = selection::create_selection( buffer->snes_to_pc(bookmark.address), bookmark.size); //non-sequential just skip if(bookmark_selection.get_end_byte() < offset || bookmark_selection.get_start_byte() > end_offset){ continue; } paint_selection(painter, bookmark_selection, bookmark.color); } } if(editor->is_comparing()){ auto diffs = editor->get_diff(); for(auto &diff : *diffs){ if(diff.get_end_byte() < offset){ continue; }else if(diff.get_start_byte() > end_offset){ //sequential, break early break; } paint_selection(painter, diff, diff_color); } } selection selection_area = get_selection(); selection_color.setAlpha(170); if(selection_area.is_active()){ paint_selection(painter, selection_area, selection_color); } painter.setClipRegion(event->region()); if(!selection_area.is_active()){ painter.setClipping(false); QPoint cursor_position = nibble_to_screen(get_cursor_nibble()); if(cursor_state && focusPolicy() != Qt::NoFocus){ painter.fillRect(cursor_position.x(), cursor_position.y(), cursor_width, editor_font::get_height(), text); } QRect active_line(0, cursor_position.y(), get_line_characters() * editor_font::get_width(), editor_font::get_height()); painter.fillRect(active_line, selection_color); } for(int i = offset, row = 0; i < end_offset; i += get_columns(), row++){ int real_row = i / get_columns(); if(!row_cache.contains(real_row)){ int line_end = i + get_columns(); if(line_end > buffer->size()){ line_end = buffer->size(); } QString line; QTextStream string_stream(&line); get_line(i, line_end, string_stream); QStaticText *text = new QStaticText(line); text->setTextFormat(Qt::PlainText); row_cache.insert(real_row, text); } if(row * editor_font::get_height() >= event->rect().y()){ painter.drawStaticText(0, row * editor_font::get_height(), *row_cache.object(real_row)); } } }
/** * \brief * Extract and copy a 2 by 2 block starting at the given start column * from the given src */ static gf2matrix *extract_block_col(gf2matrix *block, int start_col, const gf2matrix *src) { return extract_region(block, src, 0, start_col, get_rows(src), 2); }