<div dir="ltr"><div class="gmail_default" style="font-size:small">Hey Andrew:</div><div class="gmail_default" style="font-size:small">If you get a stable patch, GG would very much like to have it !! THANKS, Phyllis/gg<br></div></div><br><div class="gmail_quote"><div dir="ltr" class="gmail_attr">On Mon, Mar 16, 2020 at 1:56 PM Andrew Randrianasulu <<a href="mailto:randrianasulu@gmail.com">randrianasulu@gmail.com</a>> wrote:<br></div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex"><br>
Oh, I was setting functions in wrong order:<br>
<br>
<br>
int FilePNG::write_frame(VFrame *frame, VFrame *data, FrameWriterUnit *unit)<br>
{<br>
PNGUnit *png_unit = (PNGUnit*)unit;<br>
png_structp png_ptr = 0;<br>
png_infop info_ptr = 0;<br>
VFrame *output_frame;<br>
int result = 1;<br>
int is_float = (frame->get_color_model() == BC_RGBA_FLOAT || frame->get_color_model() == BC_RGB_FLOAT);<br>
<br>
data->set_compressed_size(0);<br>
//printf("FilePNG::write_frame 1\n");<br>
native_cmodel = asset->png_use_alpha ? BC_RGBA8888 : BC_RGB888;<br>
if (is_float)<br>
native_cmodel = asset->png_use_alpha ? BC_RGBA16161616 : BC_RGB161616;<br>
<br>
if(frame->get_color_model() != native_cmodel)<br>
{<br>
if(!png_unit->temp_frame) png_unit->temp_frame =<br>
new VFrame(asset->width, asset->height, native_cmodel, 0);<br>
<br>
png_unit->temp_frame->transfer_from(frame);<br>
output_frame = png_unit->temp_frame;<br>
}<br>
else<br>
output_frame = frame;<br>
<br>
//printf("FilePNG::write_frame 1\n");<br>
png_ptr = png_create_write_struct(PNG_LIBPNG_VER_STRING, 0, 0, 0);<br>
if( png_ptr ) {<br>
if( !setjmp(png_jmpbuf(png_ptr)) ) {<br>
info_ptr = png_create_info_struct(png_ptr);<br>
png_set_write_fn(png_ptr, data,<br>
(png_rw_ptr)write_function, (png_flush_ptr)flush_function);<br>
png_set_compression_level(png_ptr, asset->png_compression);<br>
<br>
png_set_IHDR(png_ptr, info_ptr, asset->width, asset->height, is_float ? 16 : 8,<br>
asset->png_use_alpha ? PNG_COLOR_TYPE_RGB_ALPHA : PNG_COLOR_TYPE_RGB,<br>
PNG_INTERLACE_NONE, PNG_COMPRESSION_TYPE_DEFAULT, PNG_FILTER_TYPE_DEFAULT);<br>
png_write_info(png_ptr, info_ptr);<br>
if(is_float)<br>
png_set_swap(png_ptr); <======<br>
png_write_image(png_ptr, output_frame->get_rows());<br>
png_write_end(png_ptr, info_ptr);<br>
result = 0;<br>
}<br>
png_destroy_write_struct(&png_ptr, &info_ptr);<br>
}<br>
if( result ) {<br>
char error[256]; png_error(png_ptr, error);<br>
fprintf(stderr, "FilePNG::write_frame failed: %s\n", error);<br>
}<br>
//printf("FilePNG::write_frame 3 %d\n", data->get_compressed_size());<br>
return result;<br>
}<br>
<br>
hint found via<br>
<br>
<a href="https://github.com/GNOME/gimp/blob/mainline/plug-ins/common/file-png.c" rel="noreferrer" target="_blank">https://github.com/GNOME/gimp/blob/mainline/plug-ins/common/file-png.c</a><br>
<br>
png_set_swap must come AFTER png_write_info!<br>
<br>
<br>
<br>
---------- Пересланное сообщение ----------<br>
<br>
Тема: Writing 16-bit per component png?<br>
Дата: Понедельник 16 марта 2020<br>
Отправитель: Andrew Randrianasulu <<a href="mailto:randrianasulu@gmail.com" target="_blank">randrianasulu@gmail.com</a>><br>
Получатель: "Cinelerra.GG" <<a href="mailto:cin@lists.cinelerra-gg.org" target="_blank">cin@lists.cinelerra-gg.org</a>><br>
<br>
Probably stupid misuse of libpng api on my side ...<br>
<br>
I tried to add support for writing 16 bit per component PNGs into Cin.<br>
<br>
int FilePNG::write_frame(VFrame *frame, VFrame *data, FrameWriterUnit *unit)<br>
{<br>
PNGUnit *png_unit = (PNGUnit*)unit;<br>
png_structp png_ptr = 0;<br>
png_infop info_ptr = 0;<br>
VFrame *output_frame;<br>
int result = 1;<br>
int is_float = (frame->get_color_model() == BC_RGBA_FLOAT || frame->get_color_model() == BC_RGB_FLOAT);<br>
<br>
==== here I try to get idea if project's colormodel actually *-FLOAT or not ====<br>
<br>
data->set_compressed_size(0);<br>
//printf("FilePNG::write_frame 1\n");<br>
native_cmodel = asset->png_use_alpha ? BC_RGBA8888 : BC_RGB888;<br>
if (is_float)<br>
native_cmodel = asset->png_use_alpha ? BC_RGBA16161616 : BC_RGB161616;<br>
<br>
=== here I try to set native_colormodel to wide-channel integer format, if input was FP ====<br>
<br>
if(frame->get_color_model() != native_cmodel)<br>
{<br>
if(!png_unit->temp_frame) png_unit->temp_frame =<br>
new VFrame(asset->width, asset->height, native_cmodel, 0);<br>
<br>
png_unit->temp_frame->transfer_from(frame);<br>
output_frame = png_unit->temp_frame;<br>
}<br>
else<br>
output_frame = frame;<br>
<br>
//printf("FilePNG::write_frame 1\n");<br>
png_ptr = png_create_write_struct(PNG_LIBPNG_VER_STRING, 0, 0, 0);<br>
if( png_ptr ) {<br>
if( !setjmp(png_jmpbuf(png_ptr)) ) {<br>
info_ptr = png_create_info_struct(png_ptr);<br>
png_set_write_fn(png_ptr, data,<br>
(png_rw_ptr)write_function, (png_flush_ptr)flush_function);<br>
png_set_compression_level(png_ptr, asset->png_compression);<br>
<br>
png_set_IHDR(png_ptr, info_ptr, asset->width, asset->height, is_float ? 16 : 8,<br>
asset->png_use_alpha ? PNG_COLOR_TYPE_RGB_ALPHA : PNG_COLOR_TYPE_RGB,<br>
PNG_INTERLACE_NONE, PNG_COMPRESSION_TYPE_DEFAULT, PNG_FILTER_TYPE_DEFAULT);<br>
<br>
==== here I try to call libpng with different bit depth depending on is_float ======<br>
<br>
png_write_info(png_ptr, info_ptr);<br>
png_write_image(png_ptr, output_frame->get_rows());<br>
png_write_end(png_ptr, info_ptr);<br>
result = 0;<br>
}<br>
png_destroy_write_struct(&png_ptr, &info_ptr);<br>
}<br>
if( result ) {<br>
char error[256]; png_error(png_ptr, error);<br>
fprintf(stderr, "FilePNG::write_frame failed: %s\n", error);<br>
}<br>
//printf("FilePNG::write_frame 3 %d\n", data->get_compressed_size());<br>
return result;<br>
}<br>
<br>
I also modified <br>
<br>
<br>
int FilePNG::get_best_colormodel(Asset *asset, int driver)<br>
{<br>
if(asset->png_use_alpha)<br>
//return BC_RGBA8888;<br>
return BC_RGBA16161616;<br>
else<br>
//return BC_RGB888;<br>
return BC_RGB161616;<br>
}<br>
<br>
but probably those changes alone not enough, I get wrong colors or <br>
completely transparent picture in resulted png ?<br>
<br>
-------------------------------------------------------<br>
-- <br>
Cin mailing list<br>
<a href="mailto:Cin@lists.cinelerra-gg.org" target="_blank">Cin@lists.cinelerra-gg.org</a><br>
<a href="https://lists.cinelerra-gg.org/mailman/listinfo/cin" rel="noreferrer" target="_blank">https://lists.cinelerra-gg.org/mailman/listinfo/cin</a><br>
</blockquote></div>