图像结构

发布于 2024-07-21 23:57:50 字数 1287 浏览 1 评论 0原文

使用java和jna我调用一个函数: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 find this

这里,potrace_word 是一个无符号的 potracelib.h 中定义的整数类型。 它通常等于本地人 机器字(即,32 位 32 位架构)。 在下面的 解释时,我们假设类型 potrace_word 保存 N 位。

尺寸为 w*h 的位图为 从下到上分为 h 水平扫描线。 每条扫描线是 从左到右分成块 N 个像素。 每个这样的 N 个像素块 存储为单个 potrace_word, 与块的最左边的像素 对应最重要的 这个词的一点,以及最右边的 对应块的像素 该词的最低有效位。 “亮”(或“黑”)的像素 “前景”)用位表示 值 1。“关闭”的像素( “白色”或“背景”)是 由位值 0 表示。如果 扫描线中的位数不是 能被N整除,那么最右边的 扫描线的字被填充在 正确的零。 数据为 扫描线 0(最底部的扫描线) 从地图[0]开始。 数据为 扫描线 1 从 map[dy] 开始。 数据 对于扫描线 2 从 map[2*dy] 开始, 等等。 请注意 dy 可以是 正或负,取决于 关于应用程序希望如何放置 取出内存中的图像数据。

但我不明白如何在 java 地图中表示。

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 */
}

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 */
}

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

離殇 2024-07-28 23:57:50

这是存储 2 色图像的一种非常标准的方法,就像从传真编码的 tiff 中获得的图像一样。 “map”应该是一个无符号 32 位整数数组。 我认为 Java 不允许你声明 uint32,但在这种情况下这并不重要,因为你关心的只是位。

将“Map”声明为整数数组。 为了将其变成图像,您可以一次检查数组中的一个位。 如果数组中第一个 int 的位 0(我假设是 Intel 机器)是“1”,则图像左下角的像素应设置为黑色。 如果它是“0”,则将该像素设置为白色。 每个 int 将为您提供 32 个像素。 如果图像的宽度不能被 32 整除,则需要跳过。 这就是“map[2*dy]”告诉你的。

因此,例如,如果图像宽度为 55,则使用 map[0] 设置 32 像素,然后使用 map[1] 设置 23 像素,然后从图像的下一行(靠近底部的一行)开始地图的第一位[2]。 (对于 55 像素宽的图像,dy 为 2,假设为 32 位整数)

在循环中执行此操作,将图像底部调整为高度值。

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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文