Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 0 additions & 16 deletions src/animation/fortplot_animation_constants.f90

This file was deleted.

12 changes: 11 additions & 1 deletion src/animation/fortplot_animation_core.f90
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
module fortplot_animation_core
use iso_fortran_env, only: real64, wp => real64
use iso_c_binding, only: c_char, c_int, c_null_char
use fortplot_animation_constants
use fortplot_constants, only: MILLISECONDS_PER_SECOND
use fortplot_figure_core, only: figure_t, plot_data_t
! savefig is part of figure_t, not rendering module
Expand All @@ -11,6 +10,17 @@ module fortplot_animation_core
implicit none
private

! Animation configuration constants (consolidated from fortplot_animation_constants)
integer, parameter, public :: DEFAULT_FRAME_INTERVAL_MS = 50
integer, parameter, public :: DEFAULT_ANIMATION_FPS = 10
integer, parameter, public :: MIN_VALID_VIDEO_SIZE = 100
integer, parameter, public :: MIN_EXPECTED_VIDEO_SIZE = 1000
integer, parameter, public :: MAX_FILENAME_LENGTH = 255

! Enhanced recovery constants for exponential backoff
integer, parameter, public :: MAX_RETRY_ATTEMPTS = 3
integer, parameter, public :: BASE_RETRY_DELAY_MS = 100

! Animation callback interface
abstract interface
subroutine animate_interface(frame)
Expand Down
5 changes: 3 additions & 2 deletions src/animation/fortplot_animation_pipeline.f90
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
module fortplot_animation_pipeline
use iso_fortran_env, only: real64, wp => real64
use fortplot_animation_constants
use fortplot_animation_core, only: animation_t, DEFAULT_FRAME_INTERVAL_MS, DEFAULT_ANIMATION_FPS, &
MIN_VALID_VIDEO_SIZE, MIN_EXPECTED_VIDEO_SIZE, MAX_FILENAME_LENGTH, &
MAX_RETRY_ATTEMPTS, BASE_RETRY_DELAY_MS
use fortplot_constants, only: MILLISECONDS_PER_SECOND
use fortplot_animation_core, only: animation_t
use fortplot_animation_rendering, only: render_frame_to_png
use fortplot_animation_validation, only: validate_generated_video_enhanced
use fortplot_pipe, only: open_ffmpeg_pipe, write_png_to_pipe, close_ffmpeg_pipe
Expand Down
3 changes: 2 additions & 1 deletion src/animation/fortplot_animation_validation.f90
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
module fortplot_animation_validation
use iso_fortran_env, only: real64, wp => real64
use fortplot_animation_constants
use fortplot_animation_core, only: MIN_VALID_VIDEO_SIZE, MIN_EXPECTED_VIDEO_SIZE, &
MAX_FILENAME_LENGTH, MAX_RETRY_ATTEMPTS, BASE_RETRY_DELAY_MS
use fortplot_logging, only: log_error, log_info, log_warning
implicit none
private
Expand Down
31 changes: 19 additions & 12 deletions src/backends/raster/fortplot_png.f90
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ module fortplot_png
use iso_c_binding
use fortplot_context, only: setup_canvas
use fortplot_raster, only: raster_context, create_raster_canvas, raster_draw_axes_and_labels, raster_render_ylabel
use fortplot_zlib, only: zlib_compress, crc32_calculate
use fortplot_zlib_core, only: zlib_compress, crc32_calculate
use fortplot_logging, only: log_error, log_info
use, intrinsic :: iso_fortran_env, only: wp => real64, int8, int32
implicit none
Expand Down Expand Up @@ -107,7 +107,7 @@ subroutine build_png_buffer(width, height, compressed_data, compressed_size, png
png_buffer(pos:pos+7) = png_signature
pos = pos + 8

! Build IHDR data
! Build IHDR data using the exact working approach
w_be = to_big_endian(width)
h_be = to_big_endian(height)
ihdr_data(1:4) = transfer(w_be, ihdr_data(1:4))
Expand Down Expand Up @@ -214,15 +214,19 @@ subroutine write_chunk_to_buffer(buffer, pos, chunk_type, data, data_len)
integer(1), intent(in) :: data(:)
integer, intent(in) :: data_len

integer :: length_be, crc_val, crc_be
integer :: length_be, crc_val, crc_be, i
integer(1) :: type_bytes(4)

! Convert chunk type to bytes
type_bytes = transfer(chunk_type, type_bytes)
! Convert chunk type to bytes (using correct ASCII conversion)
do i = 1, 4
type_bytes(i) = int(iachar(chunk_type(i:i)), 1)
end do

! Write length (big endian)
length_be = to_big_endian(data_len)
buffer(pos:pos+3) = transfer(length_be, buffer(pos:pos+3))
! Write length (big endian) - write bytes directly
buffer(pos) = int(ibits(data_len, 24, 8), 1)
buffer(pos+1) = int(ibits(data_len, 16, 8), 1)
buffer(pos+2) = int(ibits(data_len, 8, 8), 1)
buffer(pos+3) = int(ibits(data_len, 0, 8), 1)
pos = pos + 4

! Write chunk type
Expand All @@ -235,10 +239,12 @@ subroutine write_chunk_to_buffer(buffer, pos, chunk_type, data, data_len)
pos = pos + data_len
end if

! Calculate and write CRC
! Calculate and write CRC (write bytes directly in big-endian order)
crc_val = calculate_chunk_crc(type_bytes, data, data_len)
crc_be = to_big_endian(crc_val)
buffer(pos:pos+3) = transfer(crc_be, buffer(pos:pos+3))
buffer(pos) = int(ibits(crc_val, 24, 8), 1)
buffer(pos+1) = int(ibits(crc_val, 16, 8), 1)
buffer(pos+2) = int(ibits(crc_val, 8, 8), 1)
buffer(pos+3) = int(ibits(crc_val, 0, 8), 1)
pos = pos + 4
end subroutine write_chunk_to_buffer

Expand Down Expand Up @@ -330,6 +336,8 @@ subroutine write_chunk(unit, chunk_type, chunk_data, data_size)
if (allocated(full_data)) deallocate(full_data)
end subroutine write_chunk



function to_big_endian(value) result(be_value)
integer, intent(in) :: value
integer :: be_value
Expand All @@ -343,7 +351,6 @@ function to_big_endian(value) result(be_value)
be_value = transfer(bytes, be_value)
end function to_big_endian


function calculate_crc32(data, len) result(crc)
integer(1), intent(in) :: data(*)
integer, intent(in) :: len
Expand Down
2 changes: 1 addition & 1 deletion src/backends/raster/fortplot_raster_rendering.f90
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ module fortplot_raster_rendering
use fortplot_margins, only: plot_area_t
use fortplot_colormap, only: colormap_value_to_color
use fortplot_interpolation, only: interpolate_z_bilinear
use fortplot_raster_drawing, only: color_to_byte, draw_filled_quad_raster
use fortplot_raster_primitives, only: color_to_byte, draw_filled_quad_raster
use, intrinsic :: iso_fortran_env, only: wp => real64
implicit none

Expand Down
10 changes: 5 additions & 5 deletions src/external/fortplot_zlib.f90
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
module fortplot_zlib
!! Pure Fortran implementation of zlib compression, decompression, and CRC32
!! Refactored for file size compliance (Issue #884) - delegates to specialized modules
module fortplot_zlib_bridge
!! Bridge module to re-export from the main fortplot_zlib_core
!! This maintains compatibility while using the working full implementation
use fortplot_zlib_core, only: zlib_compress, crc32_calculate
implicit none

private
private
public :: zlib_compress, crc32_calculate

end module fortplot_zlib
end module fortplot_zlib_bridge
Loading
Loading