tags:

views:

48

answers:

1

using java and jna I call a fonction : trace(potrace_ bitmap_s)

struct potrace_bitmap_s { 
int w, h; 
int dy; /* scanline offset in words */
potrace_word *map; /* pixel data, dy*h words */
};
typedef struct potrace_bitmap_s potrace_bitmap_t;

w, h: are width and height of a bitmap

in doc of library a found this

Here, potrace_word is an unsigned integer type defined in potracelib.h. It is usually equal to a native machine word (i.e., 32 bits on a 32-bit architecture). In the following explanation, we assume that the type potrace_word holds N bits.

A bitmap of dimensions w*h is divided, bottom to top, into h horizontal scanlines. Each scanline is divided, left to right, into blocks of N pixels. Each such block of N pixels is stored as a single potrace_word, with the leftmost pixels of the block corresponding to the most significant bit of the word, and the rightmost pixel of the block corresponding to the least significant bit of the word. Pixels that are “on” (or “black” or “foreground”) are represented by bit value 1. Pixels that are “off” (of “white” or “background”) are represented by bit value 0. If the number of bits in a scanline is not divisible by N, then the rightmost word of the scanline is padded on the right with zeros. The data for scanline 0 (the bottom-most scanline) begins at map[0]. The data for scanline 1 begins at map[dy]. The data for scanline 2 begins at map[2*dy], and so forth. Note that dy can be either positive or negative, depending on how an application wishes to lay out the image data in memory.

but I not understood how I can represente in java map.

public class Potrace_bitmap_t extends Structure{
    int w, h; /* width and height, in pixels */
    int dy; /* scanline offset in words */
    map ??; /* pixel data, dy*h words */
}
A: 

This is a pretty standard way of storing a 2 color image, like what you get from a fax-encoded tiff. The "map" is supposed to be an array of unsigned 32 bit integers. I don't think Java lets you declare uint32, but it doesn't really matter in this case, since all you care about is the bits.

Declare "Map" as an array of integers. To make this into an image, you can examine the bits in the array one at a time. If bit 0 (I am assuming an Intel machine) of the first int in the array is a "1", then the pixel in the lower left corner of the image should be set to black. If it is a "0", set that pixel to white. Each int will give you 32 pixels. If the width of the image is not divisible by 32, you will need to skip ahead. This is what "map[2*dy]" is telling you.

So, if the image width is 55 for example, you set 32 pixels with map[0], then set 23 pixels with map[1], then begin with the next line of the image (the one next to the bottom) at the first bit of map[2]. (dy for an image 55 pixels wide would be 2, assuming 32 bit integers)

Do this in a loop, bottom of the image to the height value.

R Ubben