Revert "racket/draw: fix another problem with the JPEG binding"

This reverts commit c2468f1f9a.

The libjpeg documentation claims that it has no static state,
so atomic mode shouldn't be necessary. Also, the stress test is
still failing on some platforms, so there must be a different
problem than I thought.
This commit is contained in:
Matthew Flatt 2012-12-22 07:39:59 -07:00
parent 22d94193ed
commit a09c8f1857
2 changed files with 12 additions and 27 deletions

View File

@ -1,6 +1,5 @@
#lang racket/base #lang racket/base
(require racket/class (require racket/class
racket/port
racket/unsafe/ops racket/unsafe/ops
file/convertible file/convertible
(for-syntax racket/base) (for-syntax racket/base)
@ -369,10 +368,7 @@
(install-bytes-rows s w h rows b&w? alpha? pre? #f) (install-bytes-rows s w h rows b&w? alpha? pre? #f)
(values s b&w?))))] (values s b&w?))))]
[(jpeg jpeg/alpha) [(jpeg jpeg/alpha)
;; We'd like to read directly from `in', but we need to be able (let ([d (create-decompress in)])
;; to read in atomic mode:
(define bstr (port->bytes in))
(let ([d (create-decompress (open-input-bytes bstr))])
(dynamic-wind (dynamic-wind
void void
(lambda () (lambda ()
@ -591,10 +587,7 @@
proc proc
(cairo_surface_write_to_png_stream s proc)))])] (cairo_surface_write_to_png_stream s proc)))])]
[(jpeg) [(jpeg)
;; We'd like to write directly to `out', but we need to be able (let ([c (create-compress out)])
;; to write in atomic mode:
(define sp (open-output-bytes))
(let ([c (create-compress sp)])
(dynamic-wind (dynamic-wind
void void
(lambda () (lambda ()
@ -622,8 +615,7 @@
(bytes-set! bstr (+ ci 2) (bytes-ref dest (+ row (+ 4i B))))))) (bytes-set! bstr (+ ci 2) (bytes-ref dest (+ row (+ 4i B)))))))
(jpeg_write_scanlines c samps 1)))) (jpeg_write_scanlines c samps 1))))
(jpeg_finish_compress c)) (jpeg_finish_compress c))
(lambda () (destroy-compress c)))) (lambda () (destroy-compress c))))]
(write-bytes (get-output-bytes sp) out)]
[else (error (method-name 'bitmap% 'save-file) [else (error (method-name 'bitmap% 'save-file)
"kind saving not yet implemented: ~e" "kind saving not yet implemented: ~e"
kind)]))) kind)])))

View File

@ -623,7 +623,7 @@
(define create-decompress (define create-decompress
((allocator destroy-decompress) ((allocator destroy-decompress)
(lambda (in) ;; `in' will be read in atomic mode! (lambda (in)
(let ([m (ptr-cast (malloc _jpeg_decompress_struct 'raw) _jpeg_decompress_struct-pointer)] (let ([m (ptr-cast (malloc _jpeg_decompress_struct 'raw) _jpeg_decompress_struct-pointer)]
[s (ptr-cast (malloc _jpeg_source_mgr 'raw) _jpeg_source_mgr-pointer)] [s (ptr-cast (malloc _jpeg_source_mgr 'raw) _jpeg_source_mgr-pointer)]
[e (ptr-cast (malloc sizeof_jpeg_error_mgr 'raw) _jpeg_error_mgr-pointer)] [e (ptr-cast (malloc sizeof_jpeg_error_mgr 'raw) _jpeg_error_mgr-pointer)]
@ -640,21 +640,17 @@
(set-jpeg_source_mgr-next_input_byte! s #f) (set-jpeg_source_mgr-next_input_byte! s #f)
(set-jpeg_source_mgr-bytes_in_buffer! s 0) (set-jpeg_source_mgr-bytes_in_buffer! s 0)
(set-jpeg_source_mgr-init_source! s (cast init-source (set-jpeg_source_mgr-init_source! s (cast init-source
(_fun #:keep funs #:atomic? #t (_fun #:keep funs _j_decompress_ptr -> _void)
_j_decompress_ptr -> _void)
_fpointer)) _fpointer))
(set-jpeg_source_mgr-fill_input_buffer! s (cast fill-input-buffer (set-jpeg_source_mgr-fill_input_buffer! s (cast fill-input-buffer
(_fun #:keep funs #:atomic? #t (_fun #:keep funs _j_decompress_ptr -> _jbool)
_j_decompress_ptr -> _jbool)
_fpointer)) _fpointer))
(set-jpeg_source_mgr-skip_input_data! s (cast skip-input-data (set-jpeg_source_mgr-skip_input_data! s (cast skip-input-data
(_fun #:keep funs #:atomic? #t (_fun #:keep funs _j_decompress_ptr _long -> _void)
_j_decompress_ptr _long -> _void)
_fpointer)) _fpointer))
(set-jpeg_source_mgr-resync_to_restart! s jpeg_resync_to_restart) (set-jpeg_source_mgr-resync_to_restart! s jpeg_resync_to_restart)
(set-jpeg_source_mgr-term_source! s (cast term-source (set-jpeg_source_mgr-term_source! s (cast term-source
(_fun #:keep funs #:atomic? #t (_fun #:keep funs _j_decompress_ptr -> _void)
_j_decompress_ptr -> _void)
_fpointer)) _fpointer))
m)))) m))))
@ -669,7 +665,7 @@
(define create-compress (define create-compress
((allocator destroy-compress) ((allocator destroy-compress)
(lambda (out) ;; `out' will be written in atomic mode! (lambda (out)
(let ([m (ptr-cast (malloc _jpeg_compress_struct 'raw) _jpeg_compress_struct-pointer)] (let ([m (ptr-cast (malloc _jpeg_compress_struct 'raw) _jpeg_compress_struct-pointer)]
[d (ptr-cast (malloc _jpeg_destination_mgr 'raw) _jpeg_destination_mgr-pointer)] [d (ptr-cast (malloc _jpeg_destination_mgr 'raw) _jpeg_destination_mgr-pointer)]
[e (ptr-cast (malloc sizeof_jpeg_error_mgr 'raw) _jpeg_error_mgr-pointer)] [e (ptr-cast (malloc sizeof_jpeg_error_mgr 'raw) _jpeg_error_mgr-pointer)]
@ -686,16 +682,13 @@
(set-jpeg_destination_mgr-next_output_byte! d b) (set-jpeg_destination_mgr-next_output_byte! d b)
(set-jpeg_destination_mgr-free_in_buffer! d BUFFER-SIZE) (set-jpeg_destination_mgr-free_in_buffer! d BUFFER-SIZE)
(set-jpeg_destination_mgr-init_destination! d (cast init-destination (set-jpeg_destination_mgr-init_destination! d (cast init-destination
(_fun #:keep funs #:atomic? #t (_fun #:keep funs _j_compress_ptr -> _void)
_j_compress_ptr -> _void)
_fpointer)) _fpointer))
(set-jpeg_destination_mgr-empty_output_buffer! d (cast empty-output-buffer (set-jpeg_destination_mgr-empty_output_buffer! d (cast empty-output-buffer
(_fun #:keep funs #:atomic? #t (_fun #:keep funs _j_compress_ptr -> _jbool)
_j_compress_ptr -> _jbool)
_fpointer)) _fpointer))
(set-jpeg_destination_mgr-term_destination! d (cast term-destination (set-jpeg_destination_mgr-term_destination! d (cast term-destination
(_fun #:keep funs #:atomic? #t (_fun #:keep funs _j_compress_ptr -> _void)
_j_compress_ptr -> _void)
_fpointer)) _fpointer))
m)))) m))))