this is probably trivial but for some reason i just can't see the right way. i tried a couple of ways but no luck
i want to make a gimp plugin that can read (writing would be the next stage) wavefront images. rla and rlb which are almost the same. of course i had a closer look at the other gimp plugins for file formats but different formats are, well, different so i didn't see enough similarities to apply it to this case.
i have a sample here from wavefront (full demo attached):
all fine and cozy. i do of course not want to write to a dump file but hand it over to gimp. the gimp stuff is as follows:
the important part here is the last one which actually puts the data into gimp. data is guchar i.e. glib's unsigned char. as a pointer.
the thing that made me struggle now is to change the fwrites into something else that i can use for writing to some dummy variable i allocated in advance or whatever else does the job.
also i wanna emphasize that this is not a commercial project in any way. in fact i'd like to share the finished product here in case i get it done somehow
any ideas or help in whichever way would be welcome
i want to make a gimp plugin that can read (writing would be the next stage) wavefront images. rla and rlb which are almost the same. of course i had a closer look at the other gimp plugins for file formats but different formats are, well, different so i didn't see enough similarities to apply it to this case.
i have a sample here from wavefront (full demo attached):
Code: Select all
for (scan = rlb_head.window.bottom; scan <= rlb_head.window.top; scan++) {
/* check for black regions outside active window */
if ((scan < rlb_head.active_window.bottom) || (scan > rlb_head.active_window.top)) {
/* write out a blank scanline */
fwrite(blank, 4, width, out);
} else {
/* seek to file location */
if (fseek(fp, (long) offset[scan - bottom], 0)) {
printf("rlb file incomplete!\n");
exit(-7);
}
/* read red scanline */
fread(&len, sizeof(short), 1, fp);
fread(buf, sizeof(U_CHAR), (int) len, fp);
decode(buf, red, (int) len);
/* read green scanline */
fread(&len, sizeof(short), 1, fp);
fread(buf, sizeof(U_CHAR), (int) len, fp);
decode(buf, green, (int) len);
/* read blue scanline */
fread(&len, sizeof(short), 1, fp);
fread(buf, sizeof(U_CHAR), (int) len, fp);
decode(buf, blue, (int) len);
/* read matte scanline */
fread(&len, sizeof(short), 1, fp);
fread(buf, sizeof(U_CHAR), (int) len, fp);
decode(buf, matte, (int) len);
/* write out RGBM for each pixel */
for (x = rlb_head.window.left; x <= rlb_head.window.right; x++) {
if ((x < rlb_head.active_window.left) || (x > rlb_head.active_window.right)) {
fwrite(blank, 4, 1, out);
} else {
fwrite(&red[x - left], 1, 1, out);
fwrite(&green[x - left], 1, 1, out);
fwrite(&blue[x - left], 1, 1, out);
fwrite(&matte[x - left], 1, 1, out);
}
}
}
}
all fine and cozy. i do of course not want to write to a dump file but hand it over to gimp. the gimp stuff is as follows:
Code: Select all
image_ID = gimp_image_new(width, height, imgtype);
gimp_image_set_filename(image_ID, filename);
layer_ID = gimp_layer_new(image_ID, _("Background"), width, height, gdtype, 100, GIMP_NORMAL_MODE);
gimp_image_add_layer(image_ID, layer_ID, 0);
drawable = gimp_drawable_get(layer_ID);
gimp_pixel_rgn_init(&pixel_rgn, drawable, 0, 0, drawable->width, drawable->height, TRUE, FALSE);
tile_height = gimp_tile_height();
...
gimp_pixel_rgn_set_rect(&pixel_rgn, data, 0, 0, width, height);
the important part here is the last one which actually puts the data into gimp. data is guchar i.e. glib's unsigned char. as a pointer.
the thing that made me struggle now is to change the fwrites into something else that i can use for writing to some dummy variable i allocated in advance or whatever else does the job.
also i wanna emphasize that this is not a commercial project in any way. in fact i'd like to share the finished product here in case i get it done somehow
any ideas or help in whichever way would be welcome
r-a-c.de