static void coalesce_writes (uint32 fd, uint8 **bufpp, uint32 *lengthp, uint32 *offsetp) { dcache_entry_t *backwards_dps[MAX_BACKWARDS]; int backwards_index; dcache_entry_t *forwards_dps[MAX_FORWARDS]; int forwards_index; /* find beginning of run */ fill_run (backwards_dps, NELEM (backwards_dps), &backwards_index, -DCACHE_BLOCK_SIZE, *offsetp, fd); /* find ending of run */ fill_run (forwards_dps, NELEM (forwards_dps), &forwards_index, DCACHE_BLOCK_SIZE, *offsetp, fd); if (backwards_index > 0 || forwards_index > 0) { int n_bufs; uint8 *bufp; uint8 *outbufp; uint32 length; dcache_entry_t *d; int i; n_bufs = backwards_index + 1 + forwards_index; /* allocate space for run */ length = n_bufs * DCACHE_BLOCK_SIZE; bufp = malloc (length); outbufp = bufp; for (i = backwards_index - 1; i >= 0; --i) copy_buffer (&outbufp, backwards_dps[i]); d = dcache_entry_lookup (fd, *offsetp); copy_buffer (&outbufp, d); for (i = 0; i < forwards_index; ++i) copy_buffer (&outbufp, forwards_dps[i]); *bufpp = bufp; *lengthp = length; *offsetp -= DCACHE_BLOCK_SIZE * backwards_index; } }
int main () { #ifdef usestubs set_debug_traps(); breakpoint(); #endif (void) malloc (1); /* Initialize ascii_string. */ init_string (ascii_string, 120, 7, 8, 12, 10, 13, 9, 11, 120, 17); fill_run (ascii_string, 7, 26, 65); fill_run (ascii_string, 33, 26, 97); fill_run (ascii_string, 59, 10, 48); /* Initialize iso_8859_1_string. */ init_string (iso_8859_1_string, 120, 7, 8, 12, 10, 13, 9, 11, 162, 17); fill_run (iso_8859_1_string, 7, 26, 65); fill_run (iso_8859_1_string, 33, 26, 97); fill_run (iso_8859_1_string, 59, 10, 48); /* Initialize ebcdic_us_string. */ init_string (ebcdic_us_string, 167, 47, 22, 12, 37, 13, 5, 11, 74, 17); /* In EBCDIC, the upper-case letters are broken into three separate runs. */ fill_run (ebcdic_us_string, 7, 9, 193); fill_run (ebcdic_us_string, 16, 9, 209); fill_run (ebcdic_us_string, 25, 8, 226); /* The lower-case letters are, too. */ fill_run (ebcdic_us_string, 33, 9, 129); fill_run (ebcdic_us_string, 42, 9, 145); fill_run (ebcdic_us_string, 51, 8, 162); /* The digits, at least, are contiguous. */ fill_run (ebcdic_us_string, 59, 10, 240); /* Initialize ibm1047_string. */ init_string (ibm1047_string, 167, 47, 22, 12, 37, 13, 5, 11, 74, 17); /* In EBCDIC, the upper-case letters are broken into three separate runs. */ fill_run (ibm1047_string, 7, 9, 193); fill_run (ibm1047_string, 16, 9, 209); fill_run (ibm1047_string, 25, 8, 226); /* The lower-case letters are, too. */ fill_run (ibm1047_string, 33, 9, 129); fill_run (ibm1047_string, 42, 9, 145); fill_run (ibm1047_string, 51, 8, 162); /* The digits, at least, are contiguous. */ fill_run (ibm1047_string, 59, 10, 240); puts ("All set!"); /* all strings initialized */ }
static void render_blob_line (GimpBlob *blob, guchar *dest, gint x, gint y, gint width) { gint buf[4 * SUBSAMPLE]; gint *data = buf; gint n = 0; gint i, j; gint current = 0; /* number of filled rows at this point * in the scan line */ gint last_x; /* Sort start and ends for all lines */ j = y * SUBSAMPLE - blob->y; for (i = 0; i < SUBSAMPLE; i++) { if (j >= blob->height) break; if ((j > 0) && (blob->data[j].left <= blob->data[j].right)) { data[2 * n] = blob->data[j].left; data[2 * n + 1] = ROW_START; data[2 * SUBSAMPLE + 2 * n] = blob->data[j].right; data[2 * SUBSAMPLE + 2 * n + 1] = ROW_STOP; n++; } j++; } /* If we have less than SUBSAMPLE rows, compress */ if (n < SUBSAMPLE) { for (i = 0; i < 2 * n; i++) data[2 * n + i] = data[2 * SUBSAMPLE + i]; } /* Now count start and end separately */ n *= 2; insert_sort (data, n); /* Discard portions outside of tile */ while ((n > 0) && (data[0] < SUBSAMPLE*x)) { if (data[1] == ROW_START) current++; else current--; data += 2; n--; } while ((n > 0) && (data[2*(n-1)] >= SUBSAMPLE*(x+width))) n--; /* Render the row */ last_x = 0; for (i = 0; i < n;) { gint cur_x = data[2 * i] / SUBSAMPLE - x; gint pixel; /* Fill in portion leading up to this pixel */ if (current && cur_x != last_x) fill_run (dest + last_x, (255 * current) / SUBSAMPLE, cur_x - last_x); /* Compute the value for this pixel */ pixel = current * SUBSAMPLE; while (i<n) { gint tmp_x = data[2 * i] / SUBSAMPLE; if (tmp_x - x != cur_x) break; if (data[2 * i + 1] == ROW_START) { current++; pixel += ((tmp_x + 1) * SUBSAMPLE) - data[2 * i]; } else { current--; pixel -= ((tmp_x + 1) * SUBSAMPLE) - data[2 * i]; } i++; } dest[cur_x] = MAX (dest[cur_x], (pixel * 255) / (SUBSAMPLE * SUBSAMPLE)); last_x = cur_x + 1; } if (current != 0) fill_run (dest + last_x, (255 * current)/ SUBSAMPLE, width - last_x); }