fix jpeg structs to better adapt to jpeglib versions and platforms

--- specifically fixing jpeglib version 8 on x86_64
This commit is contained in:
Matthew Flatt 2011-02-16 07:30:34 -07:00
parent 7af41fddc3
commit e59b96e26c

View File

@ -100,20 +100,24 @@
(unless (member JPEG_LIB_VERSION '(62 64 70 80))
(error 'jpeg "unsupported library version: ~e" JPEG_LIB_VERSION))
(define _scaled_size
(case JPEG_LIB_VERSION
[(62 64) _int]
[else (make-cstruct-type (list _int _int))]))
(define-syntax-rule (cstruct-type/version elem ...)
(make-cstruct-type (flatten-type (list (cstruct-type/version-elem elem) ...))))
(define _prog_scan_size
(define-syntax cstruct-type/version-elem
(syntax-rules (unquote)
[(_ (unquote ([vers (elem ...)] ...)))
(case JPEG_LIB_VERSION
[(62 64 70) (make-cstruct-type (list _int _int _int _int))]
[else (make-cstruct-type (list _int _int _int _int _int _pointer _int))]))
[vers (list (cstruct-type/version-elem elem) ...)]
...)]
[(_ [name type]) type]))
(define _comp_info_size
(case JPEG_LIB_VERSION
[(62 64 70) _pointer]
[else (make-cstruct-type (list _pointer _jbool))]))
(define (flatten-type l)
(cond
[(null? l) null]
[(list? (car l))
(append (flatten-type (car l)) (flatten-type (cdr l)))]
[else
(cons (car l) (flatten-type (cdr l)))]))
(define-cstruct _jpeg_decompress_struct ([err _jpeg_error_mgr-pointer]
[mem _jpeg_memory_mgr-pointer]
@ -150,7 +154,7 @@
[enable_2pass_quant _jbool]
[output_width _JDIMENSION]
[output_height _JDIMENSION]
[output_height _JDIMENSION] ; <-
[out_color_components _int]
[output_components _int]
[rec_outbuf_height _int]
@ -158,6 +162,11 @@
[actual_number_of_colors _int]
[colormap _pointer]
;; We don't need to refer to any of the remaining
;; fields, and the specific set of fields depends
;; on the version
[rest
(cstruct-type/version
[output_scanline _JDIMENSION]
[input_scan_number _int]
@ -184,8 +193,10 @@
[data_precision _int]
[comp_info&is_baseline _comp_info_size]
[comp_info _pointer]
,([(62 64 70) ()]
[else ([is_baseline _jbool])])
[progressive_mode _jbool]
[arith_code _jbool]
@ -258,7 +269,9 @@
[max_h_samp_factor _int]
[max_v_samp_factor _int]
[min_DCT_scaled_size _scaled_size]
,([(62 64) ([min_DCT_scaled_size _int])]
[else ([min_DCT_h_scaled_size _int]
[min_DCT_v_scaled_size _int])])
[total_iMCU_rows _JDIMENSION]
[sample_range_limit _pointer]
@ -286,7 +299,16 @@
[MCU_membership_9 _int]
[MCU_membership_10 _int]
[prog_scan _prog_scan_size] ; Ss, Se, Ah, Al
[Ss _int]
[Se _int]
[Ah _int]
[Al _int]
,([(62 64 70) ()]
[else
([block_size _int]
[natural_order _pointer]
[lim_Se _int])])
[unread_marker _int]
@ -300,7 +322,7 @@
[idct _pointer]
[upsample _pointer]
[cconvert _pointer]
[cquantize _pointer]))
[cquantize _pointer])]))
(define _j_decompress_ptr _jpeg_decompress_struct-pointer)
@ -317,44 +339,6 @@
(define (jpeg_decompress_struct-src m)
(ptr-cast (jpeg_decompress_struct-src* m) _jpeg_source_mgr-pointer))
(define-cstruct _jpeg7_compression_params ([scale_num _uint]
[scale_denom _uint]
[jpeg_width _JDIMENSION]
[jpeg_height _JDIMENSION]
[data_precision _int]))
(define _compression_params_t
(case JPEG_LIB_VERSION
[(62 64) _int] ; just data_precission
[else _jpeg7_compression_params]))
(define-cstruct _quant_tbl_62_t ([quant_tbl_ptrs_1 _pointer]
[quant_tbl_ptrs_2 _pointer]
[quant_tbl_ptrs_3 _pointer]
[quant_tbl_ptrs_4 _pointer]))
(define-cstruct (_quant_tbl_70_t _quant_tbl_62_t) ([q_scale_factor_1 _int]
[q_scale_factor_2 _int]
[q_scale_factor_3 _int]
[q_scale_factor_4 _int]))
(define _quant_tbl_t
(case JPEG_LIB_VERSION
[(62 64) _quant_tbl_62_t]
[else _quant_tbl_70_t]))
(define _sampling_t
(case JPEG_LIB_VERSION
[(62 64) _jbool] ; just CCIR601_sampling
[else (make-cstruct-type (list _jbool _jbool))])) ; CCIR601_sampling and do_fancy_downsampling
(define-cstruct _factors_62_t ([max_h_samp_factor _int]
[max_v_samp_factor _int]))
(define-cstruct (_factors_70_t _factors_62_t) ([scaled _scaled_size]))
(define _factors_t
(case JPEG_LIB_VERSION
[(62 64) _factors_62_t]
[else _factors_70_t]))
(define-cstruct _jpeg_compress_struct ([err _jpeg_error_mgr-pointer]
[mem _jpeg_memory_mgr-pointer]
[progress _pointer] ; _jpeg_progress_mgr_pointer
@ -367,18 +351,40 @@
[image_width _JDIMENSION]
[image_height _JDIMENSION]
[input_components _int]
[in_color_space _J_COLOR_SPACE]
[in_color_space _J_COLOR_SPACE] ; <-
[input_gamma _double]
[compression_params _compression_params_t]
;; We don't need to refer to any of the remaining
;; fields, and the specific set of fields depends
;; on the version
[rest
(cstruct-type/version
,([(62 64) ()]
[else
([scale_num _uint]
[scale_denom _uint]
[jpeg_width _JDIMENSION]
[jpeg_height _JDIMENSION])])
[data_precission _int]
[num_components _int]
[jpeg_color_space _J_COLOR_SPACE]
[comp_info _pointer]
[quant_tbl _quant_tbl_t]
[quant_tbl_ptrs_1 _pointer]
[quant_tbl_ptrs_2 _pointer]
[quant_tbl_ptrs_3 _pointer]
[quant_tbl_ptrs_4 _pointer]
,([(62 64) ()]
[else
([q_scale_factor_1 _int]
[q_scale_factor_2 _int]
[q_scale_factor_3 _int]
[q_scale_factor_4 _int])])
[dc_huff_tbl_ptrs_1 _pointer]
[dc_huff_tbl_ptrs_2 _pointer]
@ -446,7 +452,11 @@
[raw_data_in _jbool]
[arith_code _jbool]
[optimize_coding _jbool]
[sampling _sampling_t]
[CCIR601_sampling _jbool]
,([(62 64) ()]
[else
([do_fancy_downsampling _jbool])])
[smoothing_factor _int]
[dct_method _J_DCT_METHOD]
@ -464,7 +474,13 @@
[next_scanline _JDIMENSION]
[progressive_mode _jbool]
[factors _factors_t]
[max_h_samp_factor _int]
[max_v_samp_factor _int]
,([(62 64) ()]
[else ([min_DCT_h_scaled_size _int]
[min_DCT_v_scaled_size _int])])
[total_iMCU_rows _JDIMENSION]
@ -490,7 +506,16 @@
[MCU_membership_9 _int]
[MCU_membership_10 _int]
[prog_scan _prog_scan_size] ; Ss, Se, Ah, Al
[Ss _int]
[Se _int]
[Ah _int]
[Al _int]
,([(62 64 70) ()]
[else
([block_size _int]
[natural_order _pointer]
[lim_Se _int])])
[master _pointer]
[main _pointer]
@ -502,7 +527,7 @@
[fdct _pointer]
[entropy _pointer]
[script_space _pointer]
[script_space_size _int]))
[script_space_size _int])]))
(define _j_compress_ptr _jpeg_compress_struct-pointer)