Var process_result_set (MYSQL_CONN *conn, MYSQL_RES *res_set) { MYSQL_ROW row; unsigned int i; int len = 0; int count = 1; int lcv = 1; len = mysql_num_rows(res_set); Var r; r.type = TYPE_LIST; if (len < 1) { r = new_list(0); mysql_free_result (res_set); return r; } r = new_list(len); while ((row = mysql_fetch_row (res_set)) != NULL) { r.v.list[count].type = TYPE_LIST; r.v.list[count].v.list = process_row(res_set,(const MYSQL_ROW*)row).v.list; count++; } mysql_free_result (res_set); return r; }
/* API for executing the query. If there is no response processing * expected, set callback as NULL */ vps_error vfmdb_execute_query(void *stmt, int (*sql_cb)(void*, int, uint8_t**, char**), void *arg) { int rc = 0; int process = 1; while (process) { rc = sqlite3_step(stmt); // Execute the statement. switch (rc) { case SQLITE_DONE: process = 0; rc = 0; /* success */ break; case SQLITE_ROW: process_row(stmt, sql_cb, arg); break; default: // SQLITE_BUSY: reset? to try again? vps_trace(VPS_ERROR, "sqlite error in switch:%s\n", sqlite3_errmsg(g_db)); process = 0; break; } } sqlite3_finalize(stmt); stmt = NULL; return rc; }
static void add_to_image(mdjvu_image_t image, mdjvu_bitmap_t bitmap, int32 dpi, mdjvu_split_options_t opt, int32 blit_shift_x, int32 blit_shift_y, int big) { int32 max_shape_size = opt ? * (int32 *) opt : 0; int32 width = mdjvu_bitmap_get_width(bitmap); int32 height = mdjvu_bitmap_get_height(bitmap); unsigned char **buf, **window_base, **window_buf, **map; int32 window_shift = 0, y = 0, i; if (!max_shape_size) max_shape_size = dpi; if (max_shape_size > height) max_shape_size = height; /* n-th line will be unpacked into buf[n % max_shape_size] + 1. * ( +1 is to make the left margin) * buf[max_shape_size] will always be blank. * * window_base[window_shift - 1] * points to buf[max_shape_size] + 1 (blank line) - top margin * window_base[window_shift + max_shape_size] * points to buf[max_shape_size] + 1 (blank line) - bottom margin * window_base[window_shift + i] * points to buf[(window_shift + i) % max_shape_size] + 1. */ /* map has the right margin of 1 */ map = mdjvu_create_2d_array(width + 1, max_shape_size); /* buf has left, right and bottom margins of 1 */ buf = mdjvu_create_2d_array(width + 2, max_shape_size + 1); window_buf = (unsigned char **) malloc(2 * (max_shape_size + 2) * sizeof(unsigned char *)); window_base = window_buf + 1; /* Unpack initial portion of the bitmap; bind the window to the buffer */ for (i = 0; i < max_shape_size; i++) { window_base[i] = window_base[max_shape_size + i] = buf[i] + 1; mdjvu_bitmap_unpack_row(bitmap, buf[i] + 1, i); } /* Setup top and bottom white margins */ window_base[-1] = window_base[2 * max_shape_size - 1] = buf[max_shape_size] + 1; /* The "window moving" loop. * We're moving a (width x max_shape_size) window through the image. */ while(1) { /* Extract some shapes from the window * (shapes touching the topmost row will be affected). */ unsigned char *top_margin_save = /* make the top margin */ window_base[window_shift - 1]; /* (save what was there) */ unsigned char *bot_margin_save = /* same with the bottom margin */ window_base[window_shift + max_shape_size]; int32 old_window_shift; window_base[window_shift - 1] = buf[max_shape_size] + 1; /* clear them */ window_base[window_shift + max_shape_size] = buf[max_shape_size] + 1; process_row(window_base + window_shift, map, /* index of a row to process: */ 0, width, max_shape_size, image, 0, y, max_shape_size, blit_shift_x, blit_shift_y, dpi, opt, big); window_base[window_shift - 1] = top_margin_save; /* restore margins */ window_base[window_shift + max_shape_size] = bot_margin_save; /* Shift the window */ y++; old_window_shift = window_shift; window_shift = y % max_shape_size; if (y + max_shape_size > height) break; /* Unpack a new row into the bottom window row */ mdjvu_bitmap_unpack_row(bitmap, buf[old_window_shift] + 1, y + max_shape_size - 1); } /* Process the last window fully */ for (i = 0; y + i < height; i++) { process_row(window_base + window_shift, map, /* index of a row to process: */ i, width, max_shape_size, image, 0, y, max_shape_size, blit_shift_x, blit_shift_y, dpi, opt, big); } /* Clean up */ free(window_buf); mdjvu_destroy_2d_array(map); mdjvu_destroy_2d_array(buf); }
static void blur (GimpDrawable *drawable) { gint i, ii, channels; gint x1, y1, x2, y2; GimpPixelRgn rgn_in, rgn_out; guchar **row; guchar *outrow; gint width, height; gimp_progress_init ("My Blur..."); /* Gets upper left and lower right coordinates, * and layers number in the image */ gimp_drawable_mask_bounds (drawable->drawable_id, &x1, &y1, &x2, &y2); width = x2 - x1; height = y2 - y1; channels = gimp_drawable_bpp (drawable->drawable_id); /* Allocate a big enough tile cache */ gimp_tile_cache_ntiles (2 * (drawable->width / gimp_tile_width () + 1)); /* Initialises two PixelRgns, one to read original data, * and the other to write output data. That second one will * be merged at the end by the call to * gimp_drawable_merge_shadow() */ gimp_pixel_rgn_init (&rgn_in, drawable, x1, y1, width, height, FALSE, FALSE); gimp_pixel_rgn_init (&rgn_out, drawable, x1, y1, width, height, TRUE, TRUE); /* Allocate memory for input and output tile rows */ init_mem (&row, &outrow, width * channels); for (ii = -radius; ii <= radius; ii++) { gimp_pixel_rgn_get_row (&rgn_in, row[radius + ii], x1, y1 + CLAMP (ii, 0, height - 1), width); } for (i = 0; i < height; i++) { /* To be done for each tile row */ process_row (row, outrow, x1, y1, width, height, channels, i); gimp_pixel_rgn_set_row (&rgn_out, outrow, x1, i + y1, width); /* shift tile rows to insert the new one at the end */ shuffle (&rgn_in, row, x1, y1, width, height, i); if (i % 10 == 0) gimp_progress_update ((gdouble) i / (gdouble) height); } /* We could also put that in a separate function but it's * rather simple */ for (ii = 0; ii < 2 * radius + 1; ii++) g_free (row[ii]); g_free (row); g_free (outrow); /* Update the modified region */ gimp_drawable_flush (drawable); gimp_drawable_merge_shadow (drawable->drawable_id, TRUE); gimp_drawable_update (drawable->drawable_id, x1, y1, width, height); }