- android - 多次调用 OnPrimaryClipChangedListener
- android - 无法更新 RecyclerView 中的 TextView 字段
- android.database.CursorIndexOutOfBoundsException : Index 0 requested, 光标大小为 0
- android - 使用 AppCompat 时,我们是否需要明确指定其 UI 组件(Spinner、EditText)颜色
我正在尝试使用 Scheme Script-Fu interface 将整数数组传递给 GIMP 插件.我有一个名为 main.c
的源代码文件,其中包含以下内容:
#include <libgimp/gimp.h>
#include <stdlib.h>
#include <stdio.h>
static void query (void);
static void run (
const gchar *name,
gint nparams,
const GimpParam *param,
gint *nreturn_vals,
GimpParam **return_vals
);
const GimpPlugInInfo PLUG_IN_INFO = {
NULL, /* init_proc */
NULL, /* quit_proc */
query, /* query_proc */
run, /* run_proc */
};
MAIN ()
static void query (void)
{
static GimpParamDef args[] = {
{
GIMP_PDB_INT32,
"run-mode",
"The run mode { RUN-INTERACTIVE (0), RUN-NONINTERACTIVE (1) }"
},
{
GIMP_PDB_INT8ARRAY,
"an array",
""
"an array"
}
};
gimp_install_procedure (
"my-test-plugin",
"My test plug-in",
"Description",
"Jane Doe <jane@doe.name>",
"Copyright (C) Jane Doe\n"
"http://foo.bar",
"2017",
g_strconcat("My test plug-in", "...", NULL),
"RGB*, GRAY*",
GIMP_PLUGIN,
G_N_ELEMENTS (args),
0,
args,
NULL
);
}
static void run (
const gchar *name,
gint nparams,
const GimpParam *param,
gint *nreturn_vals,
GimpParam **return_vals)
{
static GimpParam value;
value.type = GIMP_PDB_STATUS;
value.data.d_status = GIMP_PDB_SUCCESS;
*nreturn_vals = 1;
*return_vals = &value;
FILE* out = fopen("mylog.log", "w");
fprintf(out, "Parameter #0:\t%d\nParameter #1:\t", param[0].data.d_int32);
for (int i = 0; i < 16; ++i)
fprintf(out, "%d ", param[1].data.d_int8array[i]);
fprintf(out, "\n");
fclose(out);
}
我将文件编译并安装为 GIMP 插件,如下所示:
sudo apt install libgimp2.0-dev
gcc `gimptool-2.0 --cflags --libs` main.c
gimptool-2.0 --install-bin ./a.out
我正在 Debian 9 机器上执行此操作。当我尝试使用 Script-Fu 界面运行插件时:
(my-test-plugin 1 #(1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16))
创建了一个名为 mylog.log
的文件,内容如下:
Parameter #0: 1
Parameter #1: 1 0 0 0 0 0 0 0 64 201 246 126 174 85 0 0
而以下是预期的内容:
Parameter #0: 1
Parameter #1: 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16
我正在尝试使用 the gimp-plugin-morphop
GIMP plugin使用 Scheme Script-Fu interface .当我使用 GUI 时,插件按预期工作:
但是,当我使用以下 Script-Fu 脚本时:
(plug-in-morphop RUN-NONINTERACTIVE 1 2 6 7
#(-1 -1 -1 -1 -1 -1 -1
-1 1 -1 -1 -1 1 -1
-1 -1 0 0 0 -1 -1
-1 -1 0 0 0 -1 -1
-1 -1 0 0 0 -1 -1
-1 1 -1 -1 -1 1 -1
-1 -1 -1 -1 -1 -1 -1) 24 2)
插件没有产生预期的结果:
我修改了插件以查看实际区别是什么:
diff --git a/src/morphop-algorithms.c b/src/morphop-algorithms.c
index b927ba3..9dff320 100644
--- a/src/morphop-algorithms.c
+++ b/src/morphop-algorithms.c
@@ -166,7 +166,16 @@ void start_operation(GimpDrawable *drawable, GimpPreview *preview, MorphOpSettin
GimpPixelRgn src_rgn_c, dst_rgn_c;
guchar* src_preview_c = NULL, *dst_preview_c = NULL;
+ FILE* log = fopen("morphop-operation.log", "w");
int i, j;
+ for(i = 0; i < STRELEM_DEFAULT_SIZE; i++) {
+ for(j = 0; j < STRELEM_DEFAULT_SIZE; j++) {
+ fprintf(log, "%d ", settings.element.matrix[i][j]);
+ }
+ fprintf(log, "\n");
+ }
+ fclose(log);
+
// white structuring element
for(i = 0; i < STRELEM_DEFAULT_SIZE; i++) {
for(j = 0; j < STRELEM_DEFAULT_SIZE; j++) {
通过 GUI 使用模块后,morphop-operation.log
文件包含以下文本:
-1 -1 -1 -1 -1 -1 -1
-1 1 -1 -1 -1 1 -1
-1 -1 0 0 0 -1 -1
-1 -1 0 0 0 -1 -1
-1 -1 0 0 0 -1 -1
-1 1 -1 -1 -1 1 -1
-1 -1 -1 -1 -1 -1 -1
如预期。运行 Script-Fu 代码后,morphop-operation.log
文件包含以下文本:
-1 0 0 86 0 103 114
-1 64 0 0 0 45 112
-1 41 64 0 0 105 104
-1 8 42 33 0 110 111
-1 95 8 0 112 45 112
-1 36 95 0 108 109 0
-1 86 36 0 117 111 32
每行最右边的六个整数似乎是随机垃圾,每次调用都会发生变化。由于 settings.element.matrix
已经是接收到的数组的内部表示,我进一步修改了插件以直接显示接收到的数组:
diff --git a/src/morphop.c b/src/morphop.c
index 3895770..cb814b6 100644
--- a/src/morphop.c
+++ b/src/morphop.c
@@ -150,9 +150,16 @@ static void run (
}
msettings.operator = param[3].data.d_int32;
-
+
+ FILE* log = fopen("morphop-init.log", "w");
int i;
for (i = 0; i < STRELEM_DEFAULT_SIZE * STRELEM_DEFAULT_SIZE; i++) {
+ fprintf(log, "%d ", param[5].data.d_int8array[i]);
+ }
+ fprintf(log, "\n");
+ fclose(log);
+
+ for (i = 0; i < STRELEM_DEFAULT_SIZE * STRELEM_DEFAULT_SIZE; i++) {
msettings.element.matrix[i % STRELEM_DEFAULT_SIZE][(int)ceil((i + 1.0) / STRELEM_DEFAULT_SIZE) - 1] = param[5].data.d_int8array[i];
}
运行 Script-Fu 代码后,morphop-init.log
文件包含以下文本:
255 255 255 255 255 255 255 0 64 169 248 158 193 85 0 0 64 170 248 158 193 85 0 0 33 0 0 0 0 0 0 0 112 108 117 103 45 105 110 45 109 111 114 112 104 111 112 0 32
第八个之后的值似乎是随机垃圾,尽管有些值在多次运行后仍保持其值:
255 255 255 255 255 255 255 0 64 89 10 89 79 86 0 0 64 90 10 89 79 86 0 0 33 0 0 0 0 0 0 0 112 108 117 103 45 105 110 45 109 111 114 112 104 111 112 0 32
255 255 255 255 255 255 255 0 64 217 110 172 167 85 0 0 64 218 110 172 167 85 0 0 33 0 0 0 0 0 0 0 112 108 117 103 45 105 110 45 109 111 114 112 104 111 112 0 32
对我来说,这意味着数组以与插件预期的格式不同的格式传递。如何通过 Script-Fu 将数组传递到 GIMP 插件中,使其保持完整?
最佳答案
在 API 中,它是 necessary to pass the size of the array before the array .
--- /tmp/plugin.orig 2017-04-02 16:45:34.902108610 +0200
+++ /tmp/plugin.c 2017-04-02 16:43:26.510105281 +0200
@@ -30,6 +30,11 @@
"The run mode { RUN-INTERACTIVE (0), RUN-NONINTERACTIVE (1) }"
},
{
+ GIMP_PDB_INT32,
+ "array-size",
+ "The array bellow"
+ },
+ {
GIMP_PDB_INT8ARRAY,
"an array",
""
@@ -69,9 +74,9 @@
*return_vals = &value;
FILE* out = fopen("mylog.log", "w");
- fprintf(out, "Parameter #0:\t%d\nParameter #1:\t", param[0].data.d_int32);
+ fprintf(out, "Parameter #0:\t%d\nParameter #2:\t", param[0].data.d_int32);
for (int i = 0; i < 16; ++i)
- fprintf(out, "%d ", param[1].data.d_int8array[i]);
+ fprintf(out, "%d ", param[2].data.d_int8array[i]);
fprintf(out, "\n");
fclose(out);
}
然后:
> (my-test-plugin 1 16 #(1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16))
(#t)
结果:
$ cat mylog.log
Parameter #0: 1
Parameter #2: 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16
并且您可以通过使大小大于长度来验证参数是否隐式链接:
> (my-test-plugin 1 17 #(1 2 3 4 5 6 7 8 9 10 11 12 13 14 15))
Error: ( : 1) INT8 vector (argument 3) for function my-test-plugin has
size of 15 but expected size of 17
(前面的参数是 RUN-NONINTERACTIVE (1) 或元素大小 (7),解释了您的 2 个测试中可用数组内容的不同数量。)
关于scheme - 通过 Script-Fu 将数组传递给 GIMP 模块,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/43099467/
我正在尝试创建一个包含 int[][] 项的数组 即 int version0Indexes[][4] = { {1,2,3,4}, {5,6,7,8} }; int version1Indexes[
我有一个整数数组: private int array[]; 如果我还有一个名为 add 的方法,那么以下有什么区别: public void add(int value) { array[va
当您尝试在 JavaScript 中将一个数组添加到另一个数组时,它会将其转换为一个字符串。通常,当以另一种语言执行此操作时,列表会合并。 JavaScript [1, 2] + [3, 4] = "
根据我正在阅读的教程,如果您想创建一个包含 5 列和 3 行的表格来表示这样的数据... 45 4 34 99 56 3 23 99 43 2 1 1 0 43 67 ...它说你可以使用下
我通常使用 python 编写脚本/程序,但最近开始使用 JavaScript 进行编程,并且在使用数组时遇到了一些问题。 在 python 中,当我创建一个数组并使用 for x in y 时,我得
我有一个这样的数组: temp = [ 'data1', ['data1_a','data1_b'], ['data2_a','data2_b','data2_c'] ]; // 我想使用 toStr
rent_property (table name) id fullName propertyName 1 A House Name1 2 B
这个问题在这里已经有了答案: 关闭13年前。 Possible Duplicate: In C arrays why is this true? a[5] == 5[a] array[index] 和
使用 Excel 2013。经过多年的寻找和适应,我的第一篇文章。 我正在尝试将当前 App 用户(即“John Smith”)与他的电子邮件地址“jsmith@work.com”进行匹配。 使用两个
当仅在一个边距上操作时,apply 似乎不会重新组装 3D 数组。考虑: arr 1),但对我来说仍然很奇怪,如果一个函数返回一个具有尺寸的对象,那么它们基本上会被忽略。 最佳答案 这是一个不太理
我有一个包含 GPS 坐标的 MySQL 数据库。这是我检索坐标的部分 PHP 代码; $sql = "SELECT lat, lon FROM gps_data"; $stmt=$db->query
我需要找到一种方法来执行这个操作,我有一个形状数组 [批量大小, 150, 1] 代表 batch_size 整数序列,每个序列有 150 个元素长,但在每个序列中都有很多添加的零,以使所有序列具有相
我必须通过 url 中的 json 获取文本。 层次结构如下: 对象>数组>对象>数组>对象。 我想用这段代码获取文本。但是我收到错误 :org.json.JSONException: No valu
enter code here- (void)viewDidLoad { NSMutableArray *imageViewArray= [[NSMutableArray alloc] init];
知道如何对二维字符串数组执行修剪操作,例如使用 Java 流 API 进行 3x3 并将其收集回相同维度的 3x3 数组? 重点是避免使用显式的 for 循环。 当前的解决方案只是简单地执行一个 fo
已关闭。此问题需要 debugging details 。目前不接受答案。 编辑问题以包含 desired behavior, a specific problem or error, and the
我有来自 ASP.NET Web 服务的以下 XML 输出: 1710 1711 1712 1713
如果我有一个对象todo作为您状态的一部分,并且该对象包含数组列表,则列表内部有对象,在这些对象内部还有另一个数组listItems。如何更新数组 listItems 中 id 为“poi098”的对
我想将最大长度为 8 的 bool 数组打包成一个字节,通过网络发送它,然后将其解压回 bool 数组。已经在这里尝试了一些解决方案,但没有用。我正在使用单声道。 我制作了 BitArray,然后尝试
我们的数据库中有这个字段指示一周中的每一天的真/假标志,如下所示:'1111110' 我需要将此值转换为 boolean 数组。 为此,我编写了以下代码: char[] freqs = weekday
我是一名优秀的程序员,十分优秀!