main
Matthew Butterick 6 years ago
parent 621769a279
commit 9b85bb85f2

@ -22,7 +22,7 @@
[else (open-input-file src)]))
(cond
[(equal? (peek-bytes 2 0 data) (bytes #xff #xd8))
(make-object JPEG data label)]
(make-object JPEG (port->bytes data) label)]
[(equal? (peek-bytes 4 0 data) (apply bytes (cons #x89 (map char->integer '(#\P #\N #\G)))))
(make-object PNG data label)]
[else (raise-argument-error 'PDFImage-open "valid image format" src)]))

@ -1,4 +1,4 @@
#lang racket/base
#lang debug racket/base
(require "racket.rkt")
(provide JPEG)
@ -39,12 +39,11 @@
(define (read-16bit-integer [bytes-or-port #f])
(define signed #f) (define big-endian #t)
(integer-bytes->integer (read-bytes 2 (cond
[(bytes? bytes-or-port)
(open-input-bytes bytes-or-port)]
[(port? bytes-or-port) bytes-or-port]
[else
(current-input-port)])) signed big-endian))
(integer-bytes->integer
(read-bytes 2 (cond
[(bytes? bytes-or-port) (open-input-bytes bytes-or-port)]
[(port? bytes-or-port) bytes-or-port]
[else (current-input-port)])) signed big-endian))
(define/contract (embed this doc-in)
(object? . ->m . void?)
@ -72,4 +71,4 @@
(module+ test
(require rackunit)
(check-equal? (number->string (read-16bit-integer (bytes #x12 #x34 #x56)) 16) "1234")
(make-object JPEG (open-input-file "test/assets/test.jpeg")))
(make-object JPEG (open-input-file "../ptest/assets/test.jpeg")))
Loading…
Cancel
Save