Add split image functionality
This commit is contained in:
parent
d76264adeb
commit
3b30b6b78e
|
@ -4,7 +4,7 @@
|
|||
<key>satnogs_noaa_apt_sync</key>
|
||||
<category>[satnogs]</category>
|
||||
<import>import satnogs</import>
|
||||
<make>satnogs.noaa_apt_sync($*filename,$*filename_png, $width, $height)</make>
|
||||
<make>satnogs.noaa_apt_sync($*filename,$*filename_png, $width, $height, $split)</make>
|
||||
<param>
|
||||
<name>Output Data Filename</name>
|
||||
<key>filename</key>
|
||||
|
@ -27,6 +27,21 @@
|
|||
<key>height</key>
|
||||
<type>int</type>
|
||||
</param>
|
||||
<param>
|
||||
<name>Split Images</name>
|
||||
<key>split</key>
|
||||
<value>False</value>
|
||||
<type>bool</type>
|
||||
<hide>part</hide>
|
||||
<option>
|
||||
<name>Yes</name>
|
||||
<key>True</key>
|
||||
</option>
|
||||
<option>
|
||||
<name>No</name>
|
||||
<key>False</key>
|
||||
</option>
|
||||
</param>
|
||||
<sink>
|
||||
<name>in</name>
|
||||
<type>float</type>
|
||||
|
|
|
@ -703,7 +703,7 @@ namespace gr {
|
|||
* class. satnogs::noaa_apt_sync::make is the public interface for
|
||||
* creating new instances.
|
||||
*/
|
||||
static sptr make( const char *filename, const char *filename_png, size_t width, size_t height);
|
||||
static sptr make( const char *filename, const char *filename_png, size_t width, size_t height, bool split);
|
||||
};
|
||||
|
||||
} // namespace satnogs
|
||||
|
|
|
@ -694,10 +694,10 @@ namespace gr
|
|||
|
||||
noaa_apt_sync::sptr
|
||||
noaa_apt_sync::make (const char *filename, const char *filename_png,
|
||||
size_t width, size_t height)
|
||||
size_t width, size_t height, bool split)
|
||||
{
|
||||
return gnuradio::get_initial_sptr (
|
||||
new noaa_apt_sync_impl (filename, filename_png, width, height));
|
||||
new noaa_apt_sync_impl (filename, filename_png, width, height, split));
|
||||
}
|
||||
|
||||
/*
|
||||
|
@ -705,7 +705,8 @@ namespace gr
|
|||
*/
|
||||
noaa_apt_sync_impl::noaa_apt_sync_impl (const char *filename,
|
||||
const char *filename_png,
|
||||
size_t width, size_t height) :
|
||||
size_t width, size_t height,
|
||||
bool split) :
|
||||
gr::sync_block ("noaa_apt_sync",
|
||||
gr::io_signature::make (1, 1, sizeof(float)),
|
||||
gr::io_signature::make (0, 0, 0)),
|
||||
|
@ -722,7 +723,8 @@ namespace gr
|
|||
d_temp_min_value (100),
|
||||
d_filename_png (filename_png),
|
||||
d_width (width),
|
||||
d_height (height)
|
||||
d_height (height),
|
||||
d_split (split)
|
||||
{
|
||||
d_out = fopen (filename, "wb");
|
||||
}
|
||||
|
@ -744,6 +746,8 @@ namespace gr
|
|||
png_byte color_type;
|
||||
png_byte bit_depth;
|
||||
png_bytep * row_pointers;
|
||||
png_bytep * row_pointers_left;
|
||||
png_bytep * row_pointers_right;
|
||||
size_t num_pictures = 0;
|
||||
int height = size / d_width;
|
||||
int picture_modulo = 0;
|
||||
|
@ -761,77 +765,216 @@ namespace gr
|
|||
if (size % d_width > 0) {
|
||||
row_modulo = size % d_width;
|
||||
}
|
||||
for (int image = 0; image < num_pictures; image++) {
|
||||
if (file.read (buffer.data (), size)) {
|
||||
FILE *fp;
|
||||
std::string fn;
|
||||
if (num_pictures == 1) {
|
||||
fp = fopen (d_filename_png, "wb");
|
||||
if (file.read (buffer.data (), size)) {
|
||||
for (int image = 0; image < num_pictures; image++) {
|
||||
if (d_split == false) {
|
||||
FILE *fp;
|
||||
std::string fn;
|
||||
if (num_pictures == 1) {
|
||||
fp = fopen (d_filename_png, "wb");
|
||||
}
|
||||
else {
|
||||
std::string fn (d_filename_png);
|
||||
std::size_t found = fn.find (".");
|
||||
if (found == std::string::npos)
|
||||
fn.append (std::to_string (image));
|
||||
else {
|
||||
fn.insert (found, std::to_string (image));
|
||||
}
|
||||
fp = fopen (fn.c_str (), "wb");
|
||||
|
||||
if ((image == num_pictures - 1) && (picture_modulo > 0)) {
|
||||
height = picture_modulo;
|
||||
}
|
||||
else {
|
||||
height = d_height;
|
||||
}
|
||||
}
|
||||
if (!fp)
|
||||
printf ("Error opening file\n");
|
||||
png_ptr = png_create_write_struct (PNG_LIBPNG_VER_STRING, NULL,
|
||||
NULL,
|
||||
NULL);
|
||||
|
||||
if (!png_ptr)
|
||||
printf ("[write_png_file] png_create_write_struct failed");
|
||||
|
||||
info_ptr = png_create_info_struct (png_ptr);
|
||||
if (!info_ptr)
|
||||
printf ("[write_png_file] png_create_info_struct failed");
|
||||
|
||||
if (setjmp(png_jmpbuf(png_ptr)))
|
||||
printf ("[write_png_file] Error during init_io");
|
||||
|
||||
png_init_io (png_ptr, fp);
|
||||
if (setjmp(png_jmpbuf(png_ptr)))
|
||||
printf ("[write_png_file] Error during writing header");
|
||||
png_set_IHDR (png_ptr, info_ptr, d_width, height, 8,
|
||||
PNG_COLOR_TYPE_GRAY,
|
||||
PNG_INTERLACE_NONE,
|
||||
PNG_COMPRESSION_TYPE_BASE,
|
||||
PNG_FILTER_TYPE_BASE);
|
||||
|
||||
png_write_info (png_ptr, info_ptr);
|
||||
|
||||
if (setjmp(png_jmpbuf(png_ptr)))
|
||||
printf ("[write_png_file] Error during writing bytes");
|
||||
row_pointers = (png_bytep*) malloc (sizeof(png_bytep) * height);
|
||||
for (int y = 0; y < height; y++) {
|
||||
row_pointers[y] = (png_byte*) malloc (
|
||||
png_get_rowbytes (png_ptr, info_ptr));
|
||||
if ((image == num_pictures - 1) && (y == height - 1)
|
||||
&& (row_modulo != 0)) {
|
||||
memcpy (
|
||||
row_pointers[y],
|
||||
buffer.data () + image * d_width * d_height + y * d_width,
|
||||
row_modulo * sizeof(uint8_t));
|
||||
memset (row_pointers[y] + row_modulo, 0,
|
||||
(d_width - row_modulo) * sizeof(uint8_t));
|
||||
}
|
||||
else {
|
||||
memcpy (
|
||||
row_pointers[y],
|
||||
buffer.data () + image * d_width * d_height + y * d_width,
|
||||
d_width * sizeof(uint8_t));
|
||||
}
|
||||
}
|
||||
png_write_image (png_ptr, row_pointers);
|
||||
if (setjmp(png_jmpbuf(png_ptr)))
|
||||
printf ("[write_png_file] Error during end of write");
|
||||
png_write_end (png_ptr, NULL);
|
||||
fclose (fp);
|
||||
}
|
||||
else {
|
||||
png_structp png_ptr_left;
|
||||
png_structp png_ptr_right;
|
||||
png_infop info_ptr_left;
|
||||
png_infop info_ptr_right;
|
||||
FILE *fp_left;
|
||||
FILE *fp_right;
|
||||
std::string fn (d_filename_png);
|
||||
fn.append (std::to_string (image));
|
||||
fp = fopen (fn.c_str (), "wb");
|
||||
if ((image == num_pictures - 1) && (picture_modulo > 0)) {
|
||||
height = picture_modulo;
|
||||
std::string fn_left (d_filename_png);
|
||||
std::string fn_right (d_filename_png);
|
||||
if (num_pictures == 1) {
|
||||
std::size_t found = fn.find (".");
|
||||
if (found == std::string::npos) {
|
||||
fn_left.append ("_left");
|
||||
fn_right.append ("_right");
|
||||
}
|
||||
else {
|
||||
fn_left.insert (found, "_left");
|
||||
fn_right.insert (found, "_right");
|
||||
}
|
||||
}
|
||||
else {
|
||||
height = d_height;
|
||||
std::size_t found = fn.find (".");
|
||||
if (found == std::string::npos) {
|
||||
fn_left.append (std::to_string (image).append ("_left"));
|
||||
fn_right.append (std::to_string (image).append ("_right"));
|
||||
}
|
||||
else {
|
||||
fn_left.insert (found, std::to_string (image).append ("_left"));
|
||||
fn_right.insert (found,
|
||||
std::to_string (image).append ("_right"));
|
||||
}
|
||||
if ((image == num_pictures - 1) && (picture_modulo > 0)) {
|
||||
height = picture_modulo;
|
||||
}
|
||||
else {
|
||||
height = d_height;
|
||||
}
|
||||
}
|
||||
}
|
||||
if (!fp)
|
||||
printf ("Error opening file\n");
|
||||
png_ptr = png_create_write_struct (PNG_LIBPNG_VER_STRING, NULL, NULL,
|
||||
NULL);
|
||||
fp_left = fopen (fn_left.c_str (), "wb");
|
||||
fp_right = fopen (fn_right.c_str (), "wb");
|
||||
if ((!fp_left) && (!fp_right))
|
||||
printf ("Error opening file\n");
|
||||
png_ptr_left = png_create_write_struct (PNG_LIBPNG_VER_STRING, NULL,
|
||||
NULL,
|
||||
NULL);
|
||||
png_ptr_right = png_create_write_struct (PNG_LIBPNG_VER_STRING,
|
||||
NULL,
|
||||
NULL,
|
||||
NULL);
|
||||
|
||||
if (!png_ptr)
|
||||
printf ("[write_png_file] png_create_write_struct failed");
|
||||
if ((!png_ptr_left) && (!png_ptr_right))
|
||||
printf ("[write_png_file] png_create_write_struct failed");
|
||||
|
||||
info_ptr = png_create_info_struct (png_ptr);
|
||||
if (!info_ptr)
|
||||
printf ("[write_png_file] png_create_info_struct failed");
|
||||
info_ptr_left = png_create_info_struct (png_ptr_left);
|
||||
info_ptr_right = png_create_info_struct (png_ptr_right);
|
||||
if ((!info_ptr_left) && (!info_ptr_right) && (!info_ptr))
|
||||
printf ("[write_png_file] png_create_info_struct failed");
|
||||
|
||||
if (setjmp(png_jmpbuf(png_ptr)))
|
||||
printf ("[write_png_file] Error during init_io");
|
||||
if (setjmp(
|
||||
png_jmpbuf(png_ptr_left)) && (setjmp(png_jmpbuf(png_ptr_right))))
|
||||
printf ("[write_png_file] Error during init_io");
|
||||
|
||||
png_init_io (png_ptr, fp);
|
||||
if (setjmp(png_jmpbuf(png_ptr)))
|
||||
printf ("[write_png_file] Error during writing header");
|
||||
png_set_IHDR (png_ptr, info_ptr, d_width, height, 8,
|
||||
PNG_COLOR_TYPE_GRAY,
|
||||
PNG_INTERLACE_NONE,
|
||||
PNG_COMPRESSION_TYPE_BASE,
|
||||
PNG_FILTER_TYPE_BASE);
|
||||
png_init_io (png_ptr_left, fp_left);
|
||||
png_init_io (png_ptr_right, fp_right);
|
||||
|
||||
png_write_info (png_ptr, info_ptr);
|
||||
if (setjmp(
|
||||
png_jmpbuf(png_ptr_left)) && (setjmp(png_jmpbuf(png_ptr_right))))
|
||||
printf ("[write_png_file] Error during writing header");
|
||||
png_set_IHDR (png_ptr_left, info_ptr_left, d_width / 2, height, 8,
|
||||
PNG_COLOR_TYPE_GRAY,
|
||||
PNG_INTERLACE_NONE,
|
||||
PNG_COMPRESSION_TYPE_BASE,
|
||||
PNG_FILTER_TYPE_BASE);
|
||||
png_set_IHDR (png_ptr_right, info_ptr_right, d_width / 2, height, 8,
|
||||
PNG_COLOR_TYPE_GRAY,
|
||||
PNG_INTERLACE_NONE,
|
||||
PNG_COMPRESSION_TYPE_BASE,
|
||||
PNG_FILTER_TYPE_BASE);
|
||||
|
||||
if (setjmp(png_jmpbuf(png_ptr)))
|
||||
printf ("[write_png_file] Error during writing bytes");
|
||||
row_pointers = (png_bytep*) malloc (sizeof(png_bytep) * height);
|
||||
for (int y = 0; y < height; y++) {
|
||||
row_pointers[y] = (png_byte*) malloc (
|
||||
png_get_rowbytes (png_ptr, info_ptr));
|
||||
if ((image == num_pictures - 1) && (y == height - 1)
|
||||
&& (row_modulo != 0)) {
|
||||
memcpy (row_pointers[y],
|
||||
png_write_info (png_ptr_left, info_ptr_left);
|
||||
png_write_info (png_ptr_right, info_ptr_right);
|
||||
|
||||
if (setjmp(png_jmpbuf(png_ptr_left))
|
||||
&& (setjmp(png_jmpbuf(png_ptr_right))))
|
||||
printf ("[write_png_file] Error during writing bytes");
|
||||
row_pointers_left = (png_bytep*) malloc (
|
||||
sizeof(png_bytep) * height);
|
||||
row_pointers_right = (png_bytep*) malloc (
|
||||
sizeof(png_bytep) * height);
|
||||
for (int y = 0; y < height; y++) {
|
||||
row_pointers_left[y] = (png_byte*) malloc (
|
||||
(d_width / 2) * sizeof(png_byte));
|
||||
row_pointers_right[y] = (png_byte*) malloc (
|
||||
(d_width / 2) * sizeof(png_byte));
|
||||
if ((image == num_pictures - 1) && (y == height - 1)
|
||||
&& (row_modulo != 0)) {
|
||||
if (row_modulo < (d_width / 2)) {
|
||||
memcpy (
|
||||
row_pointers_left[y],
|
||||
buffer.data () + image * d_width * d_height + y * d_width,
|
||||
row_modulo * sizeof(uint8_t));
|
||||
memset (
|
||||
buffer.data () + image * d_width * d_height + y * d_width
|
||||
+ row_modulo,
|
||||
0, (d_width - row_modulo) * sizeof(uint8_t));
|
||||
}
|
||||
else {
|
||||
memcpy (row_pointers[y],
|
||||
buffer.data () + image * d_width * d_height + y * d_width,
|
||||
d_width * sizeof(uint8_t));
|
||||
memset (row_pointers_left[y] + row_modulo, 0,
|
||||
((d_width / 2) - row_modulo) * sizeof(uint8_t));
|
||||
memset (row_pointers_right[y] + row_modulo, 0,
|
||||
(d_width / 2) * sizeof(uint8_t));
|
||||
}
|
||||
}
|
||||
else {
|
||||
memcpy (
|
||||
row_pointers_left[y],
|
||||
buffer.data () + image * d_width * d_height + y * d_width,
|
||||
(d_width / 2) * sizeof(uint8_t));
|
||||
memcpy (
|
||||
row_pointers_right[y],
|
||||
buffer.data () + image * d_width * d_height + y * d_width
|
||||
+ (d_width / 2),
|
||||
(d_width / 2) * sizeof(uint8_t));
|
||||
}
|
||||
}
|
||||
png_write_image (png_ptr_left, row_pointers_left);
|
||||
png_write_image (png_ptr_right, row_pointers_right);
|
||||
if (setjmp(
|
||||
png_jmpbuf(png_ptr_left)) && setjmp(png_jmpbuf(png_ptr_right)))
|
||||
printf ("[write_png_file] Error during end of write");
|
||||
png_write_end (png_ptr_left, NULL);
|
||||
png_write_end (png_ptr_right, NULL);
|
||||
fclose (fp_left);
|
||||
fclose (fp_right);
|
||||
}
|
||||
png_write_image (png_ptr, row_pointers);
|
||||
if (setjmp(png_jmpbuf(png_ptr)))
|
||||
printf ("[write_png_file] Error during end of write");
|
||||
png_write_end (png_ptr, NULL);
|
||||
fclose (fp);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -881,7 +1024,6 @@ namespace gr
|
|||
}
|
||||
}
|
||||
}
|
||||
|
||||
return noutput_items;
|
||||
}
|
||||
|
||||
|
|
|
@ -701,9 +701,10 @@ namespace gr {
|
|||
const char* d_filename_png;
|
||||
size_t d_width;
|
||||
size_t d_height;
|
||||
bool d_split;
|
||||
|
||||
public:
|
||||
noaa_apt_sync_impl( const char *filename, const char *filename_png, size_t width, size_t height);
|
||||
noaa_apt_sync_impl( const char *filename, const char *filename_png, size_t width, size_t height, bool split);
|
||||
~noaa_apt_sync_impl();
|
||||
void produce_image();
|
||||
|
||||
|
|
Loading…
Reference in New Issue