overhaul plot organization
by moving needed C source to src/plot and building during `make', but stripping out the copies of gd, png, and zlib; instead, hook a dc<%>-based back end into plot
This commit is contained in:
parent
557b799939
commit
514706446e
|
@ -1,10 +1,10 @@
|
|||
|
||||
(module compile-unit mzscheme
|
||||
(require mzlib/unit
|
||||
mzlib/include
|
||||
mzlib/process
|
||||
mzlib/sendevent
|
||||
"private/dirs.ss"
|
||||
"private/stdio.rkt"
|
||||
"private/cmdargs.ss")
|
||||
|
||||
(require "compile-sig.ss")
|
||||
|
@ -266,7 +266,7 @@
|
|||
[else (bad-name name)])]))
|
||||
|
||||
(define-values (my-process* stdio-compile)
|
||||
(let-values ([(p* do-stdio) (include (build-path "private" "stdio.rkt"))])
|
||||
(let-values ([(p* do-stdio) (get-stdio)])
|
||||
(values
|
||||
p*
|
||||
(lambda (start-process quiet?)
|
||||
|
|
|
@ -1,10 +1,10 @@
|
|||
|
||||
(module link-unit mzscheme
|
||||
(require mzlib/unit
|
||||
mzlib/include
|
||||
mzlib/process
|
||||
mzlib/sendevent
|
||||
"private/dirs.ss"
|
||||
"private/stdio.rkt"
|
||||
"private/cmdargs.ss"
|
||||
"filename-version.ss")
|
||||
|
||||
|
@ -349,7 +349,7 @@
|
|||
in))
|
||||
libs
|
||||
output-strings)])
|
||||
(unless quiet?
|
||||
(unless #f ; quiet?
|
||||
(printf "link-extension: ~a\n" command))
|
||||
(stdio-link (lambda (quiet?)
|
||||
(apply my-process* command))
|
||||
|
@ -420,19 +420,14 @@
|
|||
(delete-file expfile))))))
|
||||
(error 'link-extension "can't find an installed linker")))))
|
||||
|
||||
(define (macos-link quiet? input-files output-file)
|
||||
(macos-make 'link-extension "linking-project" "so" quiet?
|
||||
input-files output-file null))
|
||||
|
||||
(define link-extension
|
||||
(case (system-type)
|
||||
[(unix windows macosx) unix/windows-link]
|
||||
[(macos) macos-link]))
|
||||
[(unix windows macosx) unix/windows-link]))
|
||||
|
||||
;; ---- some helpers:
|
||||
|
||||
(define-values (my-process* stdio-link)
|
||||
(let-values ([(p* do-stdio) (include (build-path "private" "stdio.rkt"))])
|
||||
(let-values ([(p* do-stdio) (get-stdio)])
|
||||
(values
|
||||
p*
|
||||
(lambda (start-process quiet?)
|
||||
|
@ -444,6 +439,4 @@
|
|||
(let ([f (build-path d (format "tmp~a.~a" n suffix))])
|
||||
(if (file-exists? f)
|
||||
(loop (add1 n))
|
||||
f)))))
|
||||
|
||||
(include (build-path "private" "macinc.rktl"))))
|
||||
f)))))))
|
||||
|
|
|
@ -1,3 +0,0 @@
|
|||
#lang setup/infotab
|
||||
|
||||
(define compile-omit-paths '("stdio.rkt"))
|
|
@ -1,64 +0,0 @@
|
|||
(define (cw-event . args)
|
||||
(apply send-event "CWIE" args))
|
||||
(define (cw . args)
|
||||
(apply cw-event "MMPR" args))
|
||||
|
||||
(define (ping-cw?)
|
||||
(with-handlers ([void (lambda (x) #f)])
|
||||
(cw "GDoc")
|
||||
#t))
|
||||
|
||||
(define (macos-make name base-project tmp-suffix quiet? input-files output-file includes)
|
||||
(define src-files (map path->complete-path input-files))
|
||||
(define dest-file (path->complete-path output-file))
|
||||
(define proj-dir (build-path (collection-path "dynext")))
|
||||
(define tmp-proj (build-path proj-dir "building-extension"))
|
||||
(define ext-out (build-path proj-dir (format "extension.~a" tmp-suffix)))
|
||||
(define debug-out (string-append ext-out ".xSYM"))
|
||||
(define data-out (string-append tmp-proj " Data"))
|
||||
(define (delete f)
|
||||
(cond
|
||||
[(file-exists? f) (delete-file f)]
|
||||
[(directory-exists? f) (map (lambda (i) (delete (build-path f i)))
|
||||
(directory-list f))
|
||||
(delete-directory f)]
|
||||
[else (void)]))
|
||||
|
||||
(when (string=? (system-library-subpath) "68k-mac")
|
||||
(error name "not supported for 68k-mac"))
|
||||
|
||||
(delete dest-file)
|
||||
(delete tmp-proj)
|
||||
(unless (copy-file (build-path proj-dir base-project)
|
||||
tmp-proj)
|
||||
(error name "couldn't create the CodeWarrior project"))
|
||||
|
||||
(with-handlers ([void (lambda (exn)
|
||||
(error name "~a" (exn-message exn)))])
|
||||
(let ([started? (ping-cw?)])
|
||||
(unless started?
|
||||
; Start CW
|
||||
(system "CWIE")
|
||||
(unless (ping-cw?)
|
||||
(sleep 1) ; wait a second...
|
||||
(unless (ping-cw?)
|
||||
(error name "couldn't start CodeWarrior; try starting CW, then leave it open while compiling"))))
|
||||
; Open the project
|
||||
(cw-event "aevt" "odoc" `#(file ,tmp-proj))
|
||||
(cw "SDfP" `#(file ,tmp-proj))
|
||||
(cw "AddF" (map (lambda (f) `#(file ,f)) src-files))
|
||||
(cw "Make")
|
||||
; Clean up
|
||||
(cw "ClsP")
|
||||
(unless started?
|
||||
(cw-event "aevt" "quit")
|
||||
(let loop () (sleep 1) (when (ping-cw?) (loop))))))
|
||||
|
||||
(delete tmp-proj)
|
||||
(delete debug-out)
|
||||
(delete data-out)
|
||||
|
||||
(unless (rename-file-or-directory ext-out dest-file)
|
||||
(unless (copy-file ext-out dest-file)
|
||||
(error name "couldn't move output to destination: ~a"
|
||||
output-file))))
|
|
@ -1,50 +1,56 @@
|
|||
#lang racket/base
|
||||
(require racket/system)
|
||||
|
||||
(values
|
||||
(if (member (system-library-subpath) '("rs6k-aix" "parisc-hpux"))
|
||||
(letrec ([pseudo-process*
|
||||
(lambda (c . args)
|
||||
(if (null? args)
|
||||
(let ([r (process* "/usr/bin/csh" "-t")])
|
||||
(display c (cadr r))
|
||||
(newline (cadr r))
|
||||
r)
|
||||
(apply pseudo-process* (string-append c " " (car args)) (cdr args))))])
|
||||
pseudo-process*)
|
||||
process*)
|
||||
|
||||
(lambda (start-process quiet? error)
|
||||
(let* ([l (start-process quiet?)]
|
||||
[in (car l)]
|
||||
[out (cadr l)]
|
||||
[in-error (cadddr l)]
|
||||
[control (cadddr (cdr l))]
|
||||
(provide get-stdio)
|
||||
|
||||
[collect-output (box "")]
|
||||
|
||||
[make-collector
|
||||
(lambda (in dest box)
|
||||
(thread (lambda ()
|
||||
(let loop ()
|
||||
(let ([t (read-line in 'any)])
|
||||
(unless (eof-object? t)
|
||||
(unless quiet? (fprintf (dest) "~a\n" t))
|
||||
(set-box! box (string-append (unbox box)
|
||||
(string #\newline) t))
|
||||
(loop)))))))]
|
||||
[in-thread (make-collector in current-output-port collect-output)]
|
||||
[in-error-thread (make-collector in-error current-error-port collect-output)])
|
||||
(define (get-stdio)
|
||||
(values
|
||||
(if (member (system-library-subpath) '("rs6k-aix" "parisc-hpux"))
|
||||
(letrec ([pseudo-process*
|
||||
(lambda (c . args)
|
||||
(if (null? args)
|
||||
(let ([r (process* "/usr/bin/csh" "-t")])
|
||||
(display c (cadr r))
|
||||
(newline (cadr r))
|
||||
r)
|
||||
(apply pseudo-process* (string-append c " " (car args)) (cdr args))))])
|
||||
pseudo-process*)
|
||||
process*)
|
||||
|
||||
(lambda (start-process quiet? error)
|
||||
(let* ([l (start-process quiet?)]
|
||||
[in (car l)]
|
||||
[out (cadr l)]
|
||||
[in-error (cadddr l)]
|
||||
[control (cadddr (cdr l))]
|
||||
|
||||
(close-output-port out)
|
||||
[collect-output (box "")]
|
||||
|
||||
[make-collector
|
||||
(lambda (in dest box)
|
||||
(thread (lambda ()
|
||||
(let loop ()
|
||||
(let ([t (read-line in 'any)])
|
||||
(unless (eof-object? t)
|
||||
(unless quiet? (fprintf (dest) "~a\n" t))
|
||||
(set-box! box (string-append (unbox box)
|
||||
(string #\newline) t))
|
||||
(loop)))))))]
|
||||
[in-thread (make-collector in current-output-port collect-output)]
|
||||
[in-error-thread (make-collector in-error current-error-port collect-output)])
|
||||
|
||||
(control 'wait)
|
||||
(close-output-port out)
|
||||
|
||||
(thread-wait in-thread)
|
||||
(thread-wait in-error-thread)
|
||||
(control 'wait)
|
||||
|
||||
(close-input-port in)
|
||||
(close-input-port in-error)
|
||||
(thread-wait in-thread)
|
||||
(thread-wait in-error-thread)
|
||||
|
||||
(close-input-port in)
|
||||
(close-input-port in-error)
|
||||
|
||||
(unless (eq? (control 'status) 'done-ok)
|
||||
(error (if quiet?
|
||||
(unbox collect-output)
|
||||
"command failed")))))))
|
||||
|
||||
(unless (eq? (control 'status) 'done-ok)
|
||||
(error (if quiet?
|
||||
(unbox collect-output)
|
||||
"command failed"))))))
|
||||
|
|
|
@ -26,7 +26,7 @@
|
|||
|
||||
(set-bin-files-delayed-lists!
|
||||
;; FIXME: hard-wired list of binary-specific files
|
||||
'(("racket/collects/sgl/compiled/gl-info_ss.zo")))
|
||||
'())
|
||||
|
||||
(expand-spec 'distributions)
|
||||
|
||||
|
|
|
@ -537,9 +537,6 @@ mr-extras :+= (- (+ (package: "mrlib/")
|
|||
|
||||
;; -------------------- sgl
|
||||
mr-extras :+= (package: "sgl/")
|
||||
;; gl-info.rkt doesn't exist, but gl-info.zo holds platform-dependent data
|
||||
platform-dependent :+= (and (collects: "sgl/")
|
||||
(srcfile: "sgl/gl-info"))
|
||||
|
||||
;; -------------------- syntax-color
|
||||
mz-extras :+= (package: "syntax-color")
|
||||
|
|
|
@ -1,10 +1,9 @@
|
|||
(module fit-low-level mzscheme
|
||||
(require mzlib/foreign mzlib/runtime-path)
|
||||
(module fit-low-level racket/base
|
||||
(require mzlib/foreign mzlib/runtime-path
|
||||
(for-syntax racket/base))
|
||||
(unsafe!)
|
||||
|
||||
(define-runtime-path libfit-path
|
||||
(build-path "compiled" "native" (system-library-subpath #f)
|
||||
(path-replace-suffix "libfit" (system-type 'so-suffix))))
|
||||
(define-runtime-path libfit-path '(so "libfit"))
|
||||
|
||||
(define libfit (ffi-lib libfit-path))
|
||||
|
||||
|
|
|
@ -1,7 +1,5 @@
|
|||
#lang setup/infotab
|
||||
|
||||
(define pre-install-collection "pre-installer.rkt")
|
||||
|
||||
(define scribblings '(("plot.scrbl" (multi-page) (gui-library 50))))
|
||||
|
||||
(define compile-omit-paths '("demos"))
|
||||
|
|
|
@ -1,11 +1,12 @@
|
|||
(module plplot mzscheme
|
||||
#lang racket/base
|
||||
(require mzlib/etc
|
||||
racket/list
|
||||
ffi/unsafe
|
||||
racket/runtime-path
|
||||
racket/class
|
||||
(for-syntax racket/base))
|
||||
|
||||
(require mzlib/etc mzlib/list mzlib/foreign mzlib/runtime-path)
|
||||
(unsafe!)
|
||||
|
||||
(define-runtime-path plplot-path
|
||||
(build-path "compiled" "native" (system-library-subpath #f)
|
||||
(path-replace-suffix "libplplot" (system-type 'so-suffix))))
|
||||
(define-runtime-path plplot-path '(so "libplplot"))
|
||||
(define-runtime-path font-dir "fonts")
|
||||
|
||||
(define libplplot (ffi-lib plplot-path))
|
||||
|
@ -29,6 +30,20 @@
|
|||
(ptr-set! p _byte len 0)
|
||||
malloced-bytes)))
|
||||
|
||||
(define-cstruct _dc_Dev
|
||||
([user_data _pointer]
|
||||
[drawLine _fpointer]
|
||||
[drawLines _fpointer]
|
||||
[fillPoly _fpointer]
|
||||
[setWidth _fpointer]
|
||||
[setColor _fpointer]
|
||||
[setColorRGB _fpointer]
|
||||
[startPage _fpointer]
|
||||
[endPage _fpointer]
|
||||
[endDoc _fpointer]))
|
||||
|
||||
(define _PLINT _int)
|
||||
|
||||
(define _plflt _double*)
|
||||
(define _plint _int)
|
||||
|
||||
|
@ -67,7 +82,7 @@
|
|||
(get-ffi-obj "c_plsfnam" libplplot (_fun _string -> _void)))
|
||||
|
||||
(define* pl-init-plot
|
||||
(get-ffi-obj "c_plinit" libplplot (_fun -> _void)))
|
||||
(get-ffi-obj "c_plinit" libplplot (_fun -> _dc_Dev-pointer)))
|
||||
|
||||
(define* pl-finish-plot
|
||||
(get-ffi-obj "c_plend" libplplot (_fun -> _void)))
|
||||
|
@ -314,6 +329,63 @@
|
|||
(plscmap1l 0 '(0.0 1.0) '(240 0) '(.6 .6) '(.8 .8))
|
||||
(pl-mesh3dc-int x-vals y-vals z-vals opts levels)))
|
||||
|
||||
(define (dc-draw-line dest x1 y1 x2 y2)
|
||||
(send (ptr-ref dest _racket) draw-line x1 y1 x2 y2))
|
||||
(define (dc-draw-multi dest xs ys n go)
|
||||
(let ([xs (cast xs _pointer (_vector o _short n))]
|
||||
[ys (cast ys _pointer (_vector o _short n))])
|
||||
(go (ptr-ref dest _racket)
|
||||
(for/list ([x (in-vector xs)]
|
||||
[y (in-vector ys)])
|
||||
(cons x y)))))
|
||||
(define (dc-draw-lines dest xs ys n)
|
||||
(dc-draw-multi dest xs ys n
|
||||
(lambda (dc l) (send dc draw-lines l))))
|
||||
(define (dc-fill-poly dest xs ys n)
|
||||
(dc-draw-multi dest xs ys n
|
||||
(lambda (dc l) (send dc draw-polygon l))))
|
||||
(define (dc-set-width dest w)
|
||||
(send (ptr-ref dest _racket) set-width w))
|
||||
(define (dc-set-color dest index)
|
||||
(send (ptr-ref dest _racket) set-index-color index))
|
||||
(define (dc-set-color/rgb dest r g b)
|
||||
(send (ptr-ref dest _racket) set-rgb-color r g b))
|
||||
(define (dc-start-page dest)
|
||||
(send (ptr-ref dest _racket) start-page))
|
||||
(define (dc-end-page dest)
|
||||
(send (ptr-ref dest _racket) end-page))
|
||||
(define (dc-end-doc dest)
|
||||
(send (ptr-ref dest _racket) end-doc)
|
||||
(free-immobile-cell dest))
|
||||
|
||||
(define draw_line (function-ptr dc-draw-line
|
||||
(_fun _pointer _short _short _short _short -> _void)))
|
||||
(define draw_lines (function-ptr dc-draw-lines
|
||||
(_fun _pointer _pointer _pointer _PLINT -> _void)))
|
||||
(define fill_poly (function-ptr dc-fill-poly
|
||||
(_fun _pointer _pointer _pointer _PLINT -> _void)))
|
||||
(define set_width (function-ptr dc-set-width
|
||||
(_fun _pointer _int -> _void)))
|
||||
(define set_color (function-ptr dc-set-color
|
||||
(_fun _pointer _int -> _void)))
|
||||
(define set_color_rgb (function-ptr dc-set-color/rgb
|
||||
(_fun _pointer _int _int _int -> _void)))
|
||||
(define start_page (function-ptr dc-start-page
|
||||
(_fun _pointer -> _void)))
|
||||
(define end_page (function-ptr dc-end-page
|
||||
(_fun _pointer -> _void)))
|
||||
(define end_doc (function-ptr dc-end-doc
|
||||
(_fun _pointer -> _void)))
|
||||
|
||||
)
|
||||
(provide init-dev!)
|
||||
(define (init-dev! dev obj)
|
||||
(set-dc_Dev-user_data! dev (malloc-immobile-cell obj))
|
||||
(set-dc_Dev-drawLine! dev draw_line)
|
||||
(set-dc_Dev-drawLines! dev draw_lines)
|
||||
(set-dc_Dev-fillPoly! dev fill_poly)
|
||||
(set-dc_Dev-setWidth! dev set_width)
|
||||
(set-dc_Dev-setColor! dev set_color)
|
||||
(set-dc_Dev-setColorRGB! dev set_color_rgb)
|
||||
(set-dc_Dev-startPage! dev start_page)
|
||||
(set-dc_Dev-endPage! dev end_page)
|
||||
(set-dc_Dev-endDoc! dev end_doc))
|
||||
|
|
|
@ -1,61 +0,0 @@
|
|||
#lang scheme/base
|
||||
(require scheme/runtime-path scheme/path scheme/file
|
||||
dynext/file dynext/link dynext/compile)
|
||||
|
||||
(define-runtime-path top-dir ".")
|
||||
(define (from-top . ps) (simplify-path (apply build-path top-dir ps) #f))
|
||||
|
||||
(define dir->libname '(["all" "libplplot"] ["fit" "libfit"]))
|
||||
(define src-dir (from-top "src"))
|
||||
(define tmp-dir (from-top "src/tmp"))
|
||||
(define sys-subpath (system-library-subpath #f))
|
||||
(define native-dir (from-top "compiled" "native" sys-subpath))
|
||||
|
||||
(define (build-library lib)
|
||||
(define libname (cond [(assoc (path->string lib) dir->libname) => cadr]
|
||||
[else (error 'plot-preinstaller
|
||||
"Found an unknown source directory: ~s\n"
|
||||
lib)]))
|
||||
(define so-name (build-path native-dir (append-extension-suffix libname)))
|
||||
(define c-files (filter (lambda (f)
|
||||
(regexp-match? "\\.[cC]$" (path->string f)))
|
||||
(directory-list)))
|
||||
(parameterize ([current-extension-compiler-flags
|
||||
(append (current-extension-compiler-flags)
|
||||
(case (system-type)
|
||||
[(windows) '("/DHAVE_LIBPNG" "/DPLD_png")]
|
||||
[else '("-DHAVE_LIBPNG" "-DPLD_png")]))]
|
||||
;; we compile a simple .so, not an extension
|
||||
[current-standard-link-libraries '()])
|
||||
(when (or (not (file-exists? so-name))
|
||||
(let ([so-time (file-or-directory-modify-seconds so-name)])
|
||||
(for/or ([f c-files])
|
||||
((file-or-directory-modify-seconds f) . > . so-time))))
|
||||
(printf "plot: compiling \"~a\" -> \"~a\"...\n"
|
||||
(find-relative-path (from-top) (current-directory))
|
||||
(find-relative-path (from-top) so-name))
|
||||
(make-directory* tmp-dir)
|
||||
(for ([c-file c-files])
|
||||
(let ([o-file (append-object-suffix (path-replace-suffix c-file #""))])
|
||||
;; first #t means quiet (here and in link-extension)
|
||||
(compile-extension #t c-file (build-path tmp-dir o-file) null)))
|
||||
(parameterize ([current-directory tmp-dir])
|
||||
(let* ([o-files (directory-list)]
|
||||
[flags (if (string=? "i386-cygwin" (path->string sys-subpath))
|
||||
;; DLL needs every dependence explicit:
|
||||
'("-lc" "-lm" "-lcygwin" "-lkernel32")
|
||||
null)])
|
||||
(link-extension #t (append o-files flags) so-name)))
|
||||
(delete-directory/files tmp-dir))))
|
||||
|
||||
(provide pre-installer)
|
||||
(define (pre-installer main-collects-parent-dir)
|
||||
(unless (directory-exists? src-dir)
|
||||
(error 'plot-preinstall "Could not find the source directory at \"~a\""
|
||||
src-dir))
|
||||
(unless (directory-exists? native-dir) (make-directory* native-dir))
|
||||
(parameterize ([current-directory src-dir])
|
||||
(for ([path (directory-list)])
|
||||
(when (directory-exists? path)
|
||||
(parameterize ([current-directory path])
|
||||
(build-library path))))))
|
1
collects/plot/src/.gitignore
vendored
1
collects/plot/src/.gitignore
vendored
|
@ -1 +0,0 @@
|
|||
/tmp/
|
|
@ -1,48 +0,0 @@
|
|||
/* adler32.c -- compute the Adler-32 checksum of a data stream
|
||||
* Copyright (C) 1995-2002 Mark Adler
|
||||
* For conditions of distribution and use, see copyright notice in zlib.h
|
||||
*/
|
||||
|
||||
/* @(#) $Id: adler32.c,v 1.1 2004/03/01 20:54:45 cozmic Exp $ */
|
||||
|
||||
#include "zlib.h"
|
||||
|
||||
#define BASE 65521L /* largest prime smaller than 65536 */
|
||||
#define NMAX 5552
|
||||
/* NMAX is the largest n such that 255n(n+1)/2 + (n+1)(BASE-1) <= 2^32-1 */
|
||||
|
||||
#define DO1(buf,i) {s1 += buf[i]; s2 += s1;}
|
||||
#define DO2(buf,i) DO1(buf,i); DO1(buf,i+1);
|
||||
#define DO4(buf,i) DO2(buf,i); DO2(buf,i+2);
|
||||
#define DO8(buf,i) DO4(buf,i); DO4(buf,i+4);
|
||||
#define DO16(buf) DO8(buf,0); DO8(buf,8);
|
||||
|
||||
/* ========================================================================= */
|
||||
uLong ZEXPORT adler32(adler, buf, len)
|
||||
uLong adler;
|
||||
const Bytef *buf;
|
||||
uInt len;
|
||||
{
|
||||
unsigned long s1 = adler & 0xffff;
|
||||
unsigned long s2 = (adler >> 16) & 0xffff;
|
||||
int k;
|
||||
|
||||
if (buf == Z_NULL) return 1L;
|
||||
|
||||
while (len > 0) {
|
||||
k = len < NMAX ? len : NMAX;
|
||||
len -= k;
|
||||
while (k >= 16) {
|
||||
DO16(buf);
|
||||
buf += 16;
|
||||
k -= 16;
|
||||
}
|
||||
if (k != 0) do {
|
||||
s1 += *buf++;
|
||||
s2 += s1;
|
||||
} while (--k);
|
||||
s1 %= BASE;
|
||||
s2 %= BASE;
|
||||
}
|
||||
return (s2 << 16) | s1;
|
||||
}
|
|
@ -1,68 +0,0 @@
|
|||
/* compress.c -- compress a memory buffer
|
||||
* Copyright (C) 1995-2002 Jean-loup Gailly.
|
||||
* For conditions of distribution and use, see copyright notice in zlib.h
|
||||
*/
|
||||
|
||||
/* @(#) $Id: compress.c,v 1.1 2004/03/01 20:54:45 cozmic Exp $ */
|
||||
|
||||
#include "zlib.h"
|
||||
|
||||
/* ===========================================================================
|
||||
Compresses the source buffer into the destination buffer. The level
|
||||
parameter has the same meaning as in deflateInit. sourceLen is the byte
|
||||
length of the source buffer. Upon entry, destLen is the total size of the
|
||||
destination buffer, which must be at least 0.1% larger than sourceLen plus
|
||||
12 bytes. Upon exit, destLen is the actual size of the compressed buffer.
|
||||
|
||||
compress2 returns Z_OK if success, Z_MEM_ERROR if there was not enough
|
||||
memory, Z_BUF_ERROR if there was not enough room in the output buffer,
|
||||
Z_STREAM_ERROR if the level parameter is invalid.
|
||||
*/
|
||||
int ZEXPORT compress2 (dest, destLen, source, sourceLen, level)
|
||||
Bytef *dest;
|
||||
uLongf *destLen;
|
||||
const Bytef *source;
|
||||
uLong sourceLen;
|
||||
int level;
|
||||
{
|
||||
z_stream stream;
|
||||
int err;
|
||||
|
||||
stream.next_in = (Bytef*)source;
|
||||
stream.avail_in = (uInt)sourceLen;
|
||||
#ifdef MAXSEG_64K
|
||||
/* Check for source > 64K on 16-bit machine: */
|
||||
if ((uLong)stream.avail_in != sourceLen) return Z_BUF_ERROR;
|
||||
#endif
|
||||
stream.next_out = dest;
|
||||
stream.avail_out = (uInt)*destLen;
|
||||
if ((uLong)stream.avail_out != *destLen) return Z_BUF_ERROR;
|
||||
|
||||
stream.zalloc = (alloc_func)0;
|
||||
stream.zfree = (free_func)0;
|
||||
stream.opaque = (voidpf)0;
|
||||
|
||||
err = deflateInit(&stream, level);
|
||||
if (err != Z_OK) return err;
|
||||
|
||||
err = deflate(&stream, Z_FINISH);
|
||||
if (err != Z_STREAM_END) {
|
||||
deflateEnd(&stream);
|
||||
return err == Z_OK ? Z_BUF_ERROR : err;
|
||||
}
|
||||
*destLen = stream.total_out;
|
||||
|
||||
err = deflateEnd(&stream);
|
||||
return err;
|
||||
}
|
||||
|
||||
/* ===========================================================================
|
||||
*/
|
||||
int ZEXPORT compress (dest, destLen, source, sourceLen)
|
||||
Bytef *dest;
|
||||
uLongf *destLen;
|
||||
const Bytef *source;
|
||||
uLong sourceLen;
|
||||
{
|
||||
return compress2(dest, destLen, source, sourceLen, Z_DEFAULT_COMPRESSION);
|
||||
}
|
|
@ -1,162 +0,0 @@
|
|||
/* crc32.c -- compute the CRC-32 of a data stream
|
||||
* Copyright (C) 1995-2002 Mark Adler
|
||||
* For conditions of distribution and use, see copyright notice in zlib.h
|
||||
*/
|
||||
|
||||
/* @(#) $Id: crc32.c,v 1.1 2004/03/01 20:54:46 cozmic Exp $ */
|
||||
|
||||
#include "zlib.h"
|
||||
|
||||
#define local static
|
||||
|
||||
#ifdef DYNAMIC_CRC_TABLE
|
||||
|
||||
local int crc_table_empty = 1;
|
||||
local uLongf crc_table[256];
|
||||
local void make_crc_table OF((void));
|
||||
|
||||
/*
|
||||
Generate a table for a byte-wise 32-bit CRC calculation on the polynomial:
|
||||
x^32+x^26+x^23+x^22+x^16+x^12+x^11+x^10+x^8+x^7+x^5+x^4+x^2+x+1.
|
||||
|
||||
Polynomials over GF(2) are represented in binary, one bit per coefficient,
|
||||
with the lowest powers in the most significant bit. Then adding polynomials
|
||||
is just exclusive-or, and multiplying a polynomial by x is a right shift by
|
||||
one. If we call the above polynomial p, and represent a byte as the
|
||||
polynomial q, also with the lowest power in the most significant bit (so the
|
||||
byte 0xb1 is the polynomial x^7+x^3+x+1), then the CRC is (q*x^32) mod p,
|
||||
where a mod b means the remainder after dividing a by b.
|
||||
|
||||
This calculation is done using the shift-register method of multiplying and
|
||||
taking the remainder. The register is initialized to zero, and for each
|
||||
incoming bit, x^32 is added mod p to the register if the bit is a one (where
|
||||
x^32 mod p is p+x^32 = x^26+...+1), and the register is multiplied mod p by
|
||||
x (which is shifting right by one and adding x^32 mod p if the bit shifted
|
||||
out is a one). We start with the highest power (least significant bit) of
|
||||
q and repeat for all eight bits of q.
|
||||
|
||||
The table is simply the CRC of all possible eight bit values. This is all
|
||||
the information needed to generate CRC's on data a byte at a time for all
|
||||
combinations of CRC register values and incoming bytes.
|
||||
*/
|
||||
local void make_crc_table()
|
||||
{
|
||||
uLong c;
|
||||
int n, k;
|
||||
uLong poly; /* polynomial exclusive-or pattern */
|
||||
/* terms of polynomial defining this crc (except x^32): */
|
||||
static const Byte p[] = {0,1,2,4,5,7,8,10,11,12,16,22,23,26};
|
||||
|
||||
/* make exclusive-or pattern from polynomial (0xedb88320L) */
|
||||
poly = 0L;
|
||||
for (n = 0; n < sizeof(p)/sizeof(Byte); n++)
|
||||
poly |= 1L << (31 - p[n]);
|
||||
|
||||
for (n = 0; n < 256; n++)
|
||||
{
|
||||
c = (uLong)n;
|
||||
for (k = 0; k < 8; k++)
|
||||
c = c & 1 ? poly ^ (c >> 1) : c >> 1;
|
||||
crc_table[n] = c;
|
||||
}
|
||||
crc_table_empty = 0;
|
||||
}
|
||||
#else
|
||||
/* ========================================================================
|
||||
* Table of CRC-32's of all single-byte values (made by make_crc_table)
|
||||
*/
|
||||
local const uLongf crc_table[256] = {
|
||||
0x00000000L, 0x77073096L, 0xee0e612cL, 0x990951baL, 0x076dc419L,
|
||||
0x706af48fL, 0xe963a535L, 0x9e6495a3L, 0x0edb8832L, 0x79dcb8a4L,
|
||||
0xe0d5e91eL, 0x97d2d988L, 0x09b64c2bL, 0x7eb17cbdL, 0xe7b82d07L,
|
||||
0x90bf1d91L, 0x1db71064L, 0x6ab020f2L, 0xf3b97148L, 0x84be41deL,
|
||||
0x1adad47dL, 0x6ddde4ebL, 0xf4d4b551L, 0x83d385c7L, 0x136c9856L,
|
||||
0x646ba8c0L, 0xfd62f97aL, 0x8a65c9ecL, 0x14015c4fL, 0x63066cd9L,
|
||||
0xfa0f3d63L, 0x8d080df5L, 0x3b6e20c8L, 0x4c69105eL, 0xd56041e4L,
|
||||
0xa2677172L, 0x3c03e4d1L, 0x4b04d447L, 0xd20d85fdL, 0xa50ab56bL,
|
||||
0x35b5a8faL, 0x42b2986cL, 0xdbbbc9d6L, 0xacbcf940L, 0x32d86ce3L,
|
||||
0x45df5c75L, 0xdcd60dcfL, 0xabd13d59L, 0x26d930acL, 0x51de003aL,
|
||||
0xc8d75180L, 0xbfd06116L, 0x21b4f4b5L, 0x56b3c423L, 0xcfba9599L,
|
||||
0xb8bda50fL, 0x2802b89eL, 0x5f058808L, 0xc60cd9b2L, 0xb10be924L,
|
||||
0x2f6f7c87L, 0x58684c11L, 0xc1611dabL, 0xb6662d3dL, 0x76dc4190L,
|
||||
0x01db7106L, 0x98d220bcL, 0xefd5102aL, 0x71b18589L, 0x06b6b51fL,
|
||||
0x9fbfe4a5L, 0xe8b8d433L, 0x7807c9a2L, 0x0f00f934L, 0x9609a88eL,
|
||||
0xe10e9818L, 0x7f6a0dbbL, 0x086d3d2dL, 0x91646c97L, 0xe6635c01L,
|
||||
0x6b6b51f4L, 0x1c6c6162L, 0x856530d8L, 0xf262004eL, 0x6c0695edL,
|
||||
0x1b01a57bL, 0x8208f4c1L, 0xf50fc457L, 0x65b0d9c6L, 0x12b7e950L,
|
||||
0x8bbeb8eaL, 0xfcb9887cL, 0x62dd1ddfL, 0x15da2d49L, 0x8cd37cf3L,
|
||||
0xfbd44c65L, 0x4db26158L, 0x3ab551ceL, 0xa3bc0074L, 0xd4bb30e2L,
|
||||
0x4adfa541L, 0x3dd895d7L, 0xa4d1c46dL, 0xd3d6f4fbL, 0x4369e96aL,
|
||||
0x346ed9fcL, 0xad678846L, 0xda60b8d0L, 0x44042d73L, 0x33031de5L,
|
||||
0xaa0a4c5fL, 0xdd0d7cc9L, 0x5005713cL, 0x270241aaL, 0xbe0b1010L,
|
||||
0xc90c2086L, 0x5768b525L, 0x206f85b3L, 0xb966d409L, 0xce61e49fL,
|
||||
0x5edef90eL, 0x29d9c998L, 0xb0d09822L, 0xc7d7a8b4L, 0x59b33d17L,
|
||||
0x2eb40d81L, 0xb7bd5c3bL, 0xc0ba6cadL, 0xedb88320L, 0x9abfb3b6L,
|
||||
0x03b6e20cL, 0x74b1d29aL, 0xead54739L, 0x9dd277afL, 0x04db2615L,
|
||||
0x73dc1683L, 0xe3630b12L, 0x94643b84L, 0x0d6d6a3eL, 0x7a6a5aa8L,
|
||||
0xe40ecf0bL, 0x9309ff9dL, 0x0a00ae27L, 0x7d079eb1L, 0xf00f9344L,
|
||||
0x8708a3d2L, 0x1e01f268L, 0x6906c2feL, 0xf762575dL, 0x806567cbL,
|
||||
0x196c3671L, 0x6e6b06e7L, 0xfed41b76L, 0x89d32be0L, 0x10da7a5aL,
|
||||
0x67dd4accL, 0xf9b9df6fL, 0x8ebeeff9L, 0x17b7be43L, 0x60b08ed5L,
|
||||
0xd6d6a3e8L, 0xa1d1937eL, 0x38d8c2c4L, 0x4fdff252L, 0xd1bb67f1L,
|
||||
0xa6bc5767L, 0x3fb506ddL, 0x48b2364bL, 0xd80d2bdaL, 0xaf0a1b4cL,
|
||||
0x36034af6L, 0x41047a60L, 0xdf60efc3L, 0xa867df55L, 0x316e8eefL,
|
||||
0x4669be79L, 0xcb61b38cL, 0xbc66831aL, 0x256fd2a0L, 0x5268e236L,
|
||||
0xcc0c7795L, 0xbb0b4703L, 0x220216b9L, 0x5505262fL, 0xc5ba3bbeL,
|
||||
0xb2bd0b28L, 0x2bb45a92L, 0x5cb36a04L, 0xc2d7ffa7L, 0xb5d0cf31L,
|
||||
0x2cd99e8bL, 0x5bdeae1dL, 0x9b64c2b0L, 0xec63f226L, 0x756aa39cL,
|
||||
0x026d930aL, 0x9c0906a9L, 0xeb0e363fL, 0x72076785L, 0x05005713L,
|
||||
0x95bf4a82L, 0xe2b87a14L, 0x7bb12baeL, 0x0cb61b38L, 0x92d28e9bL,
|
||||
0xe5d5be0dL, 0x7cdcefb7L, 0x0bdbdf21L, 0x86d3d2d4L, 0xf1d4e242L,
|
||||
0x68ddb3f8L, 0x1fda836eL, 0x81be16cdL, 0xf6b9265bL, 0x6fb077e1L,
|
||||
0x18b74777L, 0x88085ae6L, 0xff0f6a70L, 0x66063bcaL, 0x11010b5cL,
|
||||
0x8f659effL, 0xf862ae69L, 0x616bffd3L, 0x166ccf45L, 0xa00ae278L,
|
||||
0xd70dd2eeL, 0x4e048354L, 0x3903b3c2L, 0xa7672661L, 0xd06016f7L,
|
||||
0x4969474dL, 0x3e6e77dbL, 0xaed16a4aL, 0xd9d65adcL, 0x40df0b66L,
|
||||
0x37d83bf0L, 0xa9bcae53L, 0xdebb9ec5L, 0x47b2cf7fL, 0x30b5ffe9L,
|
||||
0xbdbdf21cL, 0xcabac28aL, 0x53b39330L, 0x24b4a3a6L, 0xbad03605L,
|
||||
0xcdd70693L, 0x54de5729L, 0x23d967bfL, 0xb3667a2eL, 0xc4614ab8L,
|
||||
0x5d681b02L, 0x2a6f2b94L, 0xb40bbe37L, 0xc30c8ea1L, 0x5a05df1bL,
|
||||
0x2d02ef8dL
|
||||
};
|
||||
#endif
|
||||
|
||||
/* =========================================================================
|
||||
* This function can be used by asm versions of crc32()
|
||||
*/
|
||||
const uLongf * ZEXPORT get_crc_table()
|
||||
{
|
||||
#ifdef DYNAMIC_CRC_TABLE
|
||||
if (crc_table_empty) make_crc_table();
|
||||
#endif
|
||||
return (const uLongf *)crc_table;
|
||||
}
|
||||
|
||||
/* ========================================================================= */
|
||||
#define DO1(buf) crc = crc_table[((int)crc ^ (*buf++)) & 0xff] ^ (crc >> 8);
|
||||
#define DO2(buf) DO1(buf); DO1(buf);
|
||||
#define DO4(buf) DO2(buf); DO2(buf);
|
||||
#define DO8(buf) DO4(buf); DO4(buf);
|
||||
|
||||
/* ========================================================================= */
|
||||
uLong ZEXPORT crc32(crc, buf, len)
|
||||
uLong crc;
|
||||
const Bytef *buf;
|
||||
uInt len;
|
||||
{
|
||||
if (buf == Z_NULL) return 0L;
|
||||
#ifdef DYNAMIC_CRC_TABLE
|
||||
if (crc_table_empty)
|
||||
make_crc_table();
|
||||
#endif
|
||||
crc = crc ^ 0xffffffffL;
|
||||
while (len >= 8)
|
||||
{
|
||||
DO8(buf);
|
||||
len -= 8;
|
||||
}
|
||||
if (len) do {
|
||||
DO1(buf);
|
||||
} while (--len);
|
||||
return crc ^ 0xffffffffL;
|
||||
}
|
|
@ -1,46 +0,0 @@
|
|||
/******************************************************************************
|
||||
*
|
||||
* File: csa.h
|
||||
*
|
||||
* Created: 16/10/2002
|
||||
*
|
||||
* Author: Pavel Sakov
|
||||
* CSIRO Marine Research
|
||||
*
|
||||
* Purpose: A header for csa library (2D data approximation with
|
||||
* bivariate cubic spline)
|
||||
*
|
||||
* Revisions: None
|
||||
*
|
||||
*****************************************************************************/
|
||||
|
||||
#if !defined(_CSA_H)
|
||||
#define _CSA_H
|
||||
|
||||
#if !defined(_POINT_STRUCT)
|
||||
#define _POINT_STRUCT
|
||||
typedef struct {
|
||||
double x;
|
||||
double y;
|
||||
double z;
|
||||
} point;
|
||||
#endif
|
||||
|
||||
extern int csa_verbose;
|
||||
extern char* csa_version;
|
||||
|
||||
struct csa;
|
||||
typedef struct csa csa;
|
||||
|
||||
csa* csa_create();
|
||||
void csa_destroy(csa* a);
|
||||
void csa_addpoints(csa* a, int n, point points[]);
|
||||
void csa_calculatespline(csa* a);
|
||||
void csa_approximate_point(csa* a, point* p);
|
||||
void csa_approximate_points(csa* a, int n, point* points);
|
||||
|
||||
void csa_setnmin(csa* a, int nmin);
|
||||
void csa_setnmax(csa* a, int nmax);
|
||||
void csa_setk(csa* a, int k);
|
||||
|
||||
#endif
|
|
@ -1,99 +0,0 @@
|
|||
/******************************************************************************
|
||||
*
|
||||
* File: csa.h
|
||||
*
|
||||
* Created: 16/10/2002
|
||||
*
|
||||
* Author: Pavel Sakov
|
||||
* CSIRO Marine Research
|
||||
*
|
||||
* Purpose: An "internal" header for csa library (2D data approximation
|
||||
* with bivariate cubic spline)
|
||||
*
|
||||
* Revisions: None
|
||||
*
|
||||
*****************************************************************************/
|
||||
|
||||
#if !defined(_CSA_INTERNAL_H)
|
||||
#define _CSA_INTERNAL_H
|
||||
|
||||
#include "csa.h"
|
||||
|
||||
struct square;
|
||||
typedef struct square square;
|
||||
|
||||
typedef struct {
|
||||
square* parent;
|
||||
int index; /* index within parent square; 0 <= index <=
|
||||
* 3 */
|
||||
point vertices[3];
|
||||
point middle; /* barycenter */
|
||||
double h; /* parent square edge length */
|
||||
double r; /* data visibility radius */
|
||||
|
||||
/*
|
||||
* points used -- in primary triangles only
|
||||
*/
|
||||
int nallocated;
|
||||
int npoints;
|
||||
point** points;
|
||||
|
||||
int primary; /* flag -- whether calculate spline
|
||||
* coefficients directly (by least squares
|
||||
* method) (primary = 1) or indirectly (from
|
||||
* * C1 smoothness conditions) (primary = 0)
|
||||
*/
|
||||
int hascoeffs; /* flag -- whether there are no NaNs among
|
||||
* the spline coefficients */
|
||||
int order; /* spline order -- for primary triangles
|
||||
* only */
|
||||
} triangle;
|
||||
|
||||
struct square {
|
||||
csa* parent;
|
||||
int i, j; /* indices */
|
||||
|
||||
int nallocated;
|
||||
int npoints;
|
||||
point** points;
|
||||
|
||||
int primary; /* flag -- whether this square contains a
|
||||
* primary triangle */
|
||||
|
||||
triangle* triangles[4];
|
||||
|
||||
double coeffs[25];
|
||||
};
|
||||
|
||||
struct csa {
|
||||
int verbose; /* flag */
|
||||
|
||||
double xmin;
|
||||
double xmax;
|
||||
double ymin;
|
||||
double ymax;
|
||||
|
||||
int nallocated;
|
||||
int npoints;
|
||||
point** points;
|
||||
|
||||
/*
|
||||
* squarization
|
||||
*/
|
||||
int ni;
|
||||
int nj;
|
||||
double h;
|
||||
square*** squares; /* square* [j][i] */
|
||||
|
||||
int npt; /* Number of Primary Triangles */
|
||||
triangle** pt; /* Primary Triangles -- triangle* [npt] */
|
||||
|
||||
/*
|
||||
* algorithm parameters
|
||||
*/
|
||||
int nmin;
|
||||
int nmax;
|
||||
double k;
|
||||
};
|
||||
|
||||
#endif
|
File diff suppressed because it is too large
Load Diff
|
@ -1,318 +0,0 @@
|
|||
/* deflate.h -- internal compression state
|
||||
* Copyright (C) 1995-2002 Jean-loup Gailly
|
||||
* For conditions of distribution and use, see copyright notice in zlib.h
|
||||
*/
|
||||
|
||||
/* WARNING: this file should *not* be used by applications. It is
|
||||
part of the implementation of the compression library and is
|
||||
subject to change. Applications should only use zlib.h.
|
||||
*/
|
||||
|
||||
/* @(#) $Id: deflate.h,v 1.1 2004/03/01 20:54:46 cozmic Exp $ */
|
||||
|
||||
#ifndef _DEFLATE_H
|
||||
#define _DEFLATE_H
|
||||
|
||||
#include "zutil.h"
|
||||
|
||||
/* ===========================================================================
|
||||
* Internal compression state.
|
||||
*/
|
||||
|
||||
#define LENGTH_CODES 29
|
||||
/* number of length codes, not counting the special END_BLOCK code */
|
||||
|
||||
#define LITERALS 256
|
||||
/* number of literal bytes 0..255 */
|
||||
|
||||
#define L_CODES (LITERALS+1+LENGTH_CODES)
|
||||
/* number of Literal or Length codes, including the END_BLOCK code */
|
||||
|
||||
#define D_CODES 30
|
||||
/* number of distance codes */
|
||||
|
||||
#define BL_CODES 19
|
||||
/* number of codes used to transfer the bit lengths */
|
||||
|
||||
#define HEAP_SIZE (2*L_CODES+1)
|
||||
/* maximum heap size */
|
||||
|
||||
#define MAX_BITS 15
|
||||
/* All codes must not exceed MAX_BITS bits */
|
||||
|
||||
#define INIT_STATE 42
|
||||
#define BUSY_STATE 113
|
||||
#define FINISH_STATE 666
|
||||
/* Stream status */
|
||||
|
||||
|
||||
/* Data structure describing a single value and its code string. */
|
||||
typedef struct ct_data_s {
|
||||
union {
|
||||
ush freq; /* frequency count */
|
||||
ush code; /* bit string */
|
||||
} fc;
|
||||
union {
|
||||
ush dad; /* father node in Huffman tree */
|
||||
ush len; /* length of bit string */
|
||||
} dl;
|
||||
} FAR ct_data;
|
||||
|
||||
#define Freq fc.freq
|
||||
#define Code fc.code
|
||||
#define Dad dl.dad
|
||||
#define Len dl.len
|
||||
|
||||
typedef struct static_tree_desc_s static_tree_desc;
|
||||
|
||||
typedef struct tree_desc_s {
|
||||
ct_data *dyn_tree; /* the dynamic tree */
|
||||
int max_code; /* largest code with non zero frequency */
|
||||
static_tree_desc *stat_desc; /* the corresponding static tree */
|
||||
} FAR tree_desc;
|
||||
|
||||
typedef ush Pos;
|
||||
typedef Pos FAR Posf;
|
||||
typedef unsigned IPos;
|
||||
|
||||
/* A Pos is an index in the character window. We use short instead of int to
|
||||
* save space in the various tables. IPos is used only for parameter passing.
|
||||
*/
|
||||
|
||||
typedef struct internal_state {
|
||||
z_streamp strm; /* pointer back to this zlib stream */
|
||||
int status; /* as the name implies */
|
||||
Bytef *pending_buf; /* output still pending */
|
||||
ulg pending_buf_size; /* size of pending_buf */
|
||||
Bytef *pending_out; /* next pending byte to output to the stream */
|
||||
int pending; /* nb of bytes in the pending buffer */
|
||||
int noheader; /* suppress zlib header and adler32 */
|
||||
Byte data_type; /* UNKNOWN, BINARY or ASCII */
|
||||
Byte method; /* STORED (for zip only) or DEFLATED */
|
||||
int last_flush; /* value of flush param for previous deflate call */
|
||||
|
||||
/* used by deflate.c: */
|
||||
|
||||
uInt w_size; /* LZ77 window size (32K by default) */
|
||||
uInt w_bits; /* log2(w_size) (8..16) */
|
||||
uInt w_mask; /* w_size - 1 */
|
||||
|
||||
Bytef *window;
|
||||
/* Sliding window. Input bytes are read into the second half of the window,
|
||||
* and move to the first half later to keep a dictionary of at least wSize
|
||||
* bytes. With this organization, matches are limited to a distance of
|
||||
* wSize-MAX_MATCH bytes, but this ensures that IO is always
|
||||
* performed with a length multiple of the block size. Also, it limits
|
||||
* the window size to 64K, which is quite useful on MSDOS.
|
||||
* To do: use the user input buffer as sliding window.
|
||||
*/
|
||||
|
||||
ulg window_size;
|
||||
/* Actual size of window: 2*wSize, except when the user input buffer
|
||||
* is directly used as sliding window.
|
||||
*/
|
||||
|
||||
Posf *prev;
|
||||
/* Link to older string with same hash index. To limit the size of this
|
||||
* array to 64K, this link is maintained only for the last 32K strings.
|
||||
* An index in this array is thus a window index modulo 32K.
|
||||
*/
|
||||
|
||||
Posf *head; /* Heads of the hash chains or NIL. */
|
||||
|
||||
uInt ins_h; /* hash index of string to be inserted */
|
||||
uInt hash_size; /* number of elements in hash table */
|
||||
uInt hash_bits; /* log2(hash_size) */
|
||||
uInt hash_mask; /* hash_size-1 */
|
||||
|
||||
uInt hash_shift;
|
||||
/* Number of bits by which ins_h must be shifted at each input
|
||||
* step. It must be such that after MIN_MATCH steps, the oldest
|
||||
* byte no longer takes part in the hash key, that is:
|
||||
* hash_shift * MIN_MATCH >= hash_bits
|
||||
*/
|
||||
|
||||
long block_start;
|
||||
/* Window position at the beginning of the current output block. Gets
|
||||
* negative when the window is moved backwards.
|
||||
*/
|
||||
|
||||
uInt match_length; /* length of best match */
|
||||
IPos prev_match; /* previous match */
|
||||
int match_available; /* set if previous match exists */
|
||||
uInt strstart; /* start of string to insert */
|
||||
uInt match_start; /* start of matching string */
|
||||
uInt lookahead; /* number of valid bytes ahead in window */
|
||||
|
||||
uInt prev_length;
|
||||
/* Length of the best match at previous step. Matches not greater than this
|
||||
* are discarded. This is used in the lazy match evaluation.
|
||||
*/
|
||||
|
||||
uInt max_chain_length;
|
||||
/* To speed up deflation, hash chains are never searched beyond this
|
||||
* length. A higher limit improves compression ratio but degrades the
|
||||
* speed.
|
||||
*/
|
||||
|
||||
uInt max_lazy_match;
|
||||
/* Attempt to find a better match only when the current match is strictly
|
||||
* smaller than this value. This mechanism is used only for compression
|
||||
* levels >= 4.
|
||||
*/
|
||||
# define max_insert_length max_lazy_match
|
||||
/* Insert new strings in the hash table only if the match length is not
|
||||
* greater than this length. This saves time but degrades compression.
|
||||
* max_insert_length is used only for compression levels <= 3.
|
||||
*/
|
||||
|
||||
int level; /* compression level (1..9) */
|
||||
int strategy; /* favor or force Huffman coding*/
|
||||
|
||||
uInt good_match;
|
||||
/* Use a faster search when the previous match is longer than this */
|
||||
|
||||
int nice_match; /* Stop searching when current match exceeds this */
|
||||
|
||||
/* used by trees.c: */
|
||||
/* Didn't use ct_data typedef below to supress compiler warning */
|
||||
struct ct_data_s dyn_ltree[HEAP_SIZE]; /* literal and length tree */
|
||||
struct ct_data_s dyn_dtree[2*D_CODES+1]; /* distance tree */
|
||||
struct ct_data_s bl_tree[2*BL_CODES+1]; /* Huffman tree for bit lengths */
|
||||
|
||||
struct tree_desc_s l_desc; /* desc. for literal tree */
|
||||
struct tree_desc_s d_desc; /* desc. for distance tree */
|
||||
struct tree_desc_s bl_desc; /* desc. for bit length tree */
|
||||
|
||||
ush bl_count[MAX_BITS+1];
|
||||
/* number of codes at each bit length for an optimal tree */
|
||||
|
||||
int heap[2*L_CODES+1]; /* heap used to build the Huffman trees */
|
||||
int heap_len; /* number of elements in the heap */
|
||||
int heap_max; /* element of largest frequency */
|
||||
/* The sons of heap[n] are heap[2*n] and heap[2*n+1]. heap[0] is not used.
|
||||
* The same heap array is used to build all trees.
|
||||
*/
|
||||
|
||||
uch depth[2*L_CODES+1];
|
||||
/* Depth of each subtree used as tie breaker for trees of equal frequency
|
||||
*/
|
||||
|
||||
uchf *l_buf; /* buffer for literals or lengths */
|
||||
|
||||
uInt lit_bufsize;
|
||||
/* Size of match buffer for literals/lengths. There are 4 reasons for
|
||||
* limiting lit_bufsize to 64K:
|
||||
* - frequencies can be kept in 16 bit counters
|
||||
* - if compression is not successful for the first block, all input
|
||||
* data is still in the window so we can still emit a stored block even
|
||||
* when input comes from standard input. (This can also be done for
|
||||
* all blocks if lit_bufsize is not greater than 32K.)
|
||||
* - if compression is not successful for a file smaller than 64K, we can
|
||||
* even emit a stored file instead of a stored block (saving 5 bytes).
|
||||
* This is applicable only for zip (not gzip or zlib).
|
||||
* - creating new Huffman trees less frequently may not provide fast
|
||||
* adaptation to changes in the input data statistics. (Take for
|
||||
* example a binary file with poorly compressible code followed by
|
||||
* a highly compressible string table.) Smaller buffer sizes give
|
||||
* fast adaptation but have of course the overhead of transmitting
|
||||
* trees more frequently.
|
||||
* - I can't count above 4
|
||||
*/
|
||||
|
||||
uInt last_lit; /* running index in l_buf */
|
||||
|
||||
ushf *d_buf;
|
||||
/* Buffer for distances. To simplify the code, d_buf and l_buf have
|
||||
* the same number of elements. To use different lengths, an extra flag
|
||||
* array would be necessary.
|
||||
*/
|
||||
|
||||
ulg opt_len; /* bit length of current block with optimal trees */
|
||||
ulg static_len; /* bit length of current block with static trees */
|
||||
uInt matches; /* number of string matches in current block */
|
||||
int last_eob_len; /* bit length of EOB code for last block */
|
||||
|
||||
#ifdef DEBUG
|
||||
ulg compressed_len; /* total bit length of compressed file mod 2^32 */
|
||||
ulg bits_sent; /* bit length of compressed data sent mod 2^32 */
|
||||
#endif
|
||||
|
||||
ush bi_buf;
|
||||
/* Output buffer. bits are inserted starting at the bottom (least
|
||||
* significant bits).
|
||||
*/
|
||||
int bi_valid;
|
||||
/* Number of valid bits in bi_buf. All bits above the last valid bit
|
||||
* are always zero.
|
||||
*/
|
||||
|
||||
} FAR deflate_state;
|
||||
|
||||
/* Output a byte on the stream.
|
||||
* IN assertion: there is enough room in pending_buf.
|
||||
*/
|
||||
#define put_byte(s, c) {s->pending_buf[s->pending++] = (c);}
|
||||
|
||||
|
||||
#define MIN_LOOKAHEAD (MAX_MATCH+MIN_MATCH+1)
|
||||
/* Minimum amount of lookahead, except at the end of the input file.
|
||||
* See deflate.c for comments about the MIN_MATCH+1.
|
||||
*/
|
||||
|
||||
#define MAX_DIST(s) ((s)->w_size-MIN_LOOKAHEAD)
|
||||
/* In order to simplify the code, particularly on 16 bit machines, match
|
||||
* distances are limited to MAX_DIST instead of WSIZE.
|
||||
*/
|
||||
|
||||
/* in trees.c */
|
||||
void _tr_init OF((deflate_state *s));
|
||||
int _tr_tally OF((deflate_state *s, unsigned dist, unsigned lc));
|
||||
void _tr_flush_block OF((deflate_state *s, charf *buf, ulg stored_len,
|
||||
int eof));
|
||||
void _tr_align OF((deflate_state *s));
|
||||
void _tr_stored_block OF((deflate_state *s, charf *buf, ulg stored_len,
|
||||
int eof));
|
||||
|
||||
#define d_code(dist) \
|
||||
((dist) < 256 ? _dist_code[dist] : _dist_code[256+((dist)>>7)])
|
||||
/* Mapping from a distance to a distance code. dist is the distance - 1 and
|
||||
* must not have side effects. _dist_code[256] and _dist_code[257] are never
|
||||
* used.
|
||||
*/
|
||||
|
||||
#ifndef DEBUG
|
||||
/* Inline versions of _tr_tally for speed: */
|
||||
|
||||
#if defined(GEN_TREES_H) || !defined(STDC)
|
||||
extern uch _length_code[];
|
||||
extern uch _dist_code[];
|
||||
#else
|
||||
extern const uch _length_code[];
|
||||
extern const uch _dist_code[];
|
||||
#endif
|
||||
|
||||
# define _tr_tally_lit(s, c, flush) \
|
||||
{ uch cc = (c); \
|
||||
s->d_buf[s->last_lit] = 0; \
|
||||
s->l_buf[s->last_lit++] = cc; \
|
||||
s->dyn_ltree[cc].Freq++; \
|
||||
flush = (s->last_lit == s->lit_bufsize-1); \
|
||||
}
|
||||
# define _tr_tally_dist(s, distance, length, flush) \
|
||||
{ uch len = (length); \
|
||||
ush dist = (distance); \
|
||||
s->d_buf[s->last_lit] = dist; \
|
||||
s->l_buf[s->last_lit++] = len; \
|
||||
dist--; \
|
||||
s->dyn_ltree[_length_code[len]+LITERALS+1].Freq++; \
|
||||
s->dyn_dtree[d_code(dist)].Freq++; \
|
||||
flush = (s->last_lit == s->lit_bufsize-1); \
|
||||
}
|
||||
#else
|
||||
# define _tr_tally_lit(s, c, flush) flush = _tr_tally(s, 0, c)
|
||||
# define _tr_tally_dist(s, distance, length, flush) \
|
||||
flush = _tr_tally(s, distance, length)
|
||||
#endif
|
||||
|
||||
#endif
|
File diff suppressed because it is too large
Load Diff
|
@ -1,626 +0,0 @@
|
|||
#ifndef GD_H
|
||||
#define GD_H 1
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C"
|
||||
{
|
||||
#endif
|
||||
|
||||
/* some might want to set DEFAULT_FONTPATH from configure in config.h */
|
||||
#ifndef DEFAULT_FONTPATH
|
||||
/* default fontpath for unix systems - whatever happened to standards ! */
|
||||
#define DEFAULT_FONTPATH "/usr/X11R6/lib/X11/fonts/TrueType:/usr/X11R6/lib/X11/fonts/truetype:/usr/X11R6/lib/X11/fonts/TTF:/usr/share/fonts/TrueType:/usr/share/fonts/truetype:/usr/openwin/lib/X11/fonts/TrueType:/usr/X11R6/lib/X11/fonts/Type1"
|
||||
#endif
|
||||
#ifndef PATHSEPARATOR
|
||||
#define PATHSEPARATOR ":"
|
||||
#endif
|
||||
|
||||
/* gd.h: declarations file for the graphic-draw module.
|
||||
* Permission to use, copy, modify, and distribute this software and its
|
||||
* documentation for any purpose and without fee is hereby granted, provided
|
||||
* that the above copyright notice appear in all copies and that both that
|
||||
* copyright notice and this permission notice appear in supporting
|
||||
* documentation. This software is provided "AS IS." Thomas Boutell and
|
||||
* Boutell.Com, Inc. disclaim all warranties, either express or implied,
|
||||
* including but not limited to implied warranties of merchantability and
|
||||
* fitness for a particular purpose, with respect to this code and accompanying
|
||||
* documentation. */
|
||||
|
||||
/* stdio is needed for file I/O. */
|
||||
#include <stdio.h>
|
||||
#include "gd_io.h"
|
||||
|
||||
/* The maximum number of palette entries in palette-based images.
|
||||
In the wonderful new world of gd 2.0, you can of course have
|
||||
many more colors when using truecolor mode. */
|
||||
|
||||
#define gdMaxColors 256
|
||||
|
||||
/* Image type. See functions below; you will not need to change
|
||||
the elements directly. Use the provided macros to
|
||||
access sx, sy, the color table, and colorsTotal for
|
||||
read-only purposes. */
|
||||
|
||||
/* If 'truecolor' is set true, the image is truecolor;
|
||||
pixels are represented by integers, which
|
||||
must be 32 bits wide or more.
|
||||
|
||||
True colors are repsented as follows:
|
||||
|
||||
ARGB
|
||||
|
||||
Where 'A' (alpha channel) occupies only the
|
||||
LOWER 7 BITS of the MSB. This very small
|
||||
loss of alpha channel resolution allows gd 2.x
|
||||
to keep backwards compatibility by allowing
|
||||
signed integers to be used to represent colors,
|
||||
and negative numbers to represent special cases,
|
||||
just as in gd 1.x. */
|
||||
|
||||
#define gdAlphaMax 127
|
||||
#define gdAlphaOpaque 0
|
||||
#define gdAlphaTransparent 127
|
||||
#define gdRedMax 255
|
||||
#define gdGreenMax 255
|
||||
#define gdBlueMax 255
|
||||
#define gdTrueColorGetAlpha(c) (((c) & 0x7F000000) >> 24)
|
||||
#define gdTrueColorGetRed(c) (((c) & 0xFF0000) >> 16)
|
||||
#define gdTrueColorGetGreen(c) (((c) & 0x00FF00) >> 8)
|
||||
#define gdTrueColorGetBlue(c) ((c) & 0x0000FF)
|
||||
|
||||
/* This function accepts truecolor pixel values only. The
|
||||
source color is composited with the destination color
|
||||
based on the alpha channel value of the source color.
|
||||
The resulting color is opaque. */
|
||||
|
||||
int gdAlphaBlend (int dest, int src);
|
||||
|
||||
typedef struct gdImageStruct
|
||||
{
|
||||
/* Palette-based image pixels */
|
||||
unsigned char **pixels;
|
||||
int sx;
|
||||
int sy;
|
||||
/* These are valid in palette images only. See also
|
||||
'alpha', which appears later in the structure to
|
||||
preserve binary backwards compatibility */
|
||||
int colorsTotal;
|
||||
int red[gdMaxColors];
|
||||
int green[gdMaxColors];
|
||||
int blue[gdMaxColors];
|
||||
int open[gdMaxColors];
|
||||
/* For backwards compatibility, this is set to the
|
||||
first palette entry with 100% transparency,
|
||||
and is also set and reset by the
|
||||
gdImageColorTransparent function. Newer
|
||||
applications can allocate palette entries
|
||||
with any desired level of transparency; however,
|
||||
bear in mind that many viewers, notably
|
||||
many web browsers, fail to implement
|
||||
full alpha channel for PNG and provide
|
||||
support for full opacity or transparency only. */
|
||||
int transparent;
|
||||
int *polyInts;
|
||||
int polyAllocated;
|
||||
struct gdImageStruct *brush;
|
||||
struct gdImageStruct *tile;
|
||||
int brushColorMap[gdMaxColors];
|
||||
int tileColorMap[gdMaxColors];
|
||||
int styleLength;
|
||||
int stylePos;
|
||||
int *style;
|
||||
int interlace;
|
||||
/* New in 2.0: thickness of line. Initialized to 1. */
|
||||
int thick;
|
||||
/* New in 2.0: alpha channel for palettes. Note that only
|
||||
Macintosh Internet Explorer and (possibly) Netscape 6
|
||||
really support multiple levels of transparency in
|
||||
palettes, to my knowledge, as of 2/15/01. Most
|
||||
common browsers will display 100% opaque and
|
||||
100% transparent correctly, and do something
|
||||
unpredictable and/or undesirable for levels
|
||||
in between. TBB */
|
||||
int alpha[gdMaxColors];
|
||||
/* Truecolor flag and pixels. New 2.0 fields appear here at the
|
||||
end to minimize breakage of existing object code. */
|
||||
int trueColor;
|
||||
int **tpixels;
|
||||
/* Should alpha channel be copied, or applied, each time a
|
||||
pixel is drawn? This applies to truecolor images only.
|
||||
No attempt is made to alpha-blend in palette images,
|
||||
even if semitransparent palette entries exist.
|
||||
To do that, build your image as a truecolor image,
|
||||
then quantize down to 8 bits. */
|
||||
int alphaBlendingFlag;
|
||||
/* Should the alpha channel of the image be saved? This affects
|
||||
PNG at the moment; other future formats may also
|
||||
have that capability. JPEG doesn't. */
|
||||
int saveAlphaFlag;
|
||||
|
||||
/* 2.0.12: anti-aliased globals */
|
||||
int AA;
|
||||
int AA_color;
|
||||
int AA_dont_blend;
|
||||
unsigned char **AA_opacity;
|
||||
int AA_polygon;
|
||||
/* Stored and pre-computed variables for determining the perpendicular
|
||||
distance from a point to the anti-aliased line being drawn: */
|
||||
int AAL_x1;
|
||||
int AAL_y1;
|
||||
int AAL_x2;
|
||||
int AAL_y2;
|
||||
int AAL_Bx_Ax;
|
||||
int AAL_By_Ay;
|
||||
int AAL_LAB_2;
|
||||
float AAL_LAB;
|
||||
|
||||
/* 2.0.12: simple clipping rectangle. These values
|
||||
must be checked for safety when set; please use
|
||||
gdImageSetClip */
|
||||
int cx1;
|
||||
int cy1;
|
||||
int cx2;
|
||||
int cy2;
|
||||
}
|
||||
gdImage;
|
||||
|
||||
typedef gdImage *gdImagePtr;
|
||||
|
||||
typedef struct
|
||||
{
|
||||
/* # of characters in font */
|
||||
int nchars;
|
||||
/* First character is numbered... (usually 32 = space) */
|
||||
int offset;
|
||||
/* Character width and height */
|
||||
int w;
|
||||
int h;
|
||||
/* Font data; array of characters, one row after another.
|
||||
Easily included in code, also easily loaded from
|
||||
data files. */
|
||||
char *data;
|
||||
}
|
||||
gdFont;
|
||||
|
||||
/* Text functions take these. */
|
||||
typedef gdFont *gdFontPtr;
|
||||
|
||||
/* For backwards compatibility only. Use gdImageSetStyle()
|
||||
for MUCH more flexible line drawing. Also see
|
||||
gdImageSetBrush(). */
|
||||
#define gdDashSize 4
|
||||
|
||||
/* Special colors. */
|
||||
|
||||
#define gdStyled (-2)
|
||||
#define gdBrushed (-3)
|
||||
#define gdStyledBrushed (-4)
|
||||
#define gdTiled (-5)
|
||||
|
||||
/* NOT the same as the transparent color index.
|
||||
This is used in line styles only. */
|
||||
#define gdTransparent (-6)
|
||||
|
||||
#define gdAntiAliased (-7)
|
||||
|
||||
/* Functions to manipulate images. */
|
||||
|
||||
/* Creates a palette-based image (up to 256 colors). */
|
||||
gdImagePtr gdImageCreate (int sx, int sy);
|
||||
|
||||
/* An alternate name for the above (2.0). */
|
||||
#define gdImageCreatePalette gdImageCreate
|
||||
|
||||
/* Creates a truecolor image (millions of colors). */
|
||||
gdImagePtr gdImageCreateTrueColor (int sx, int sy);
|
||||
|
||||
/* Creates an image from various file types. These functions
|
||||
return a palette or truecolor image based on the
|
||||
nature of the file being loaded. Truecolor PNG
|
||||
stays truecolor; palette PNG stays palette-based;
|
||||
JPEG is always truecolor. */
|
||||
gdImagePtr gdImageCreateFromPng (FILE * fd);
|
||||
gdImagePtr gdImageCreateFromPngCtx (gdIOCtxPtr in);
|
||||
gdImagePtr gdImageCreateFromWBMP (FILE * inFile);
|
||||
gdImagePtr gdImageCreateFromWBMPCtx (gdIOCtx * infile);
|
||||
gdImagePtr gdImageCreateFromJpeg (FILE * infile);
|
||||
gdImagePtr gdImageCreateFromJpegCtx (gdIOCtx * infile);
|
||||
|
||||
/* A custom data source. */
|
||||
/* The source function must return -1 on error, otherwise the number
|
||||
of bytes fetched. 0 is EOF, not an error! */
|
||||
/* context will be passed to your source function. */
|
||||
|
||||
typedef struct
|
||||
{
|
||||
int (*source) (void *context, char *buffer, int len);
|
||||
void *context;
|
||||
}
|
||||
gdSource, *gdSourcePtr;
|
||||
|
||||
gdImagePtr gdImageCreateFromPngSource (gdSourcePtr in);
|
||||
|
||||
gdImagePtr gdImageCreateFromGd (FILE * in);
|
||||
gdImagePtr gdImageCreateFromGdCtx (gdIOCtxPtr in);
|
||||
|
||||
gdImagePtr gdImageCreateFromGd2 (FILE * in);
|
||||
gdImagePtr gdImageCreateFromGd2Ctx (gdIOCtxPtr in);
|
||||
|
||||
gdImagePtr gdImageCreateFromGd2Part (FILE * in, int srcx, int srcy, int w,
|
||||
int h);
|
||||
gdImagePtr gdImageCreateFromGd2PartCtx (gdIOCtxPtr in, int srcx, int srcy,
|
||||
int w, int h);
|
||||
/* 2.0.10: prototype was missing */
|
||||
gdImagePtr gdImageCreateFromXpm (char *filename);
|
||||
gdImagePtr gdImageCreateFromXbm (FILE * in);
|
||||
|
||||
void gdImageDestroy (gdImagePtr im);
|
||||
|
||||
/* Replaces or blends with the background depending on the
|
||||
most recent call to gdImageAlphaBlending and the
|
||||
alpha channel value of 'color'; default is to overwrite.
|
||||
Tiling and line styling are also implemented
|
||||
here. All other gd drawing functions pass through this call,
|
||||
allowing for many useful effects. */
|
||||
|
||||
void gdImageSetPixel (gdImagePtr im, int x, int y, int color);
|
||||
|
||||
int gdImageGetPixel (gdImagePtr im, int x, int y);
|
||||
|
||||
void gdImageAABlend (gdImagePtr im);
|
||||
|
||||
void gdImageLine (gdImagePtr im, int x1, int y1, int x2, int y2, int color);
|
||||
|
||||
/* For backwards compatibility only. Use gdImageSetStyle()
|
||||
for much more flexible line drawing. */
|
||||
void gdImageDashedLine (gdImagePtr im, int x1, int y1, int x2, int y2,
|
||||
int color);
|
||||
/* Corners specified (not width and height). Upper left first, lower right
|
||||
second. */
|
||||
void gdImageRectangle (gdImagePtr im, int x1, int y1, int x2, int y2,
|
||||
int color);
|
||||
/* Solid bar. Upper left corner first, lower right corner second. */
|
||||
void gdImageFilledRectangle (gdImagePtr im, int x1, int y1, int x2, int y2,
|
||||
int color);
|
||||
void gdImageSetClip(gdImagePtr im, int x1, int y1, int x2, int y2);
|
||||
void gdImageGetClip(gdImagePtr im, int *x1P, int *y1P, int *x2P, int *y2P);
|
||||
int gdImageBoundsSafe (gdImagePtr im, int x, int y);
|
||||
void gdImageChar (gdImagePtr im, gdFontPtr f, int x, int y, int c,
|
||||
int color);
|
||||
void gdImageCharUp (gdImagePtr im, gdFontPtr f, int x, int y, int c,
|
||||
int color);
|
||||
void gdImageString (gdImagePtr im, gdFontPtr f, int x, int y,
|
||||
unsigned char *s, int color);
|
||||
void gdImageStringUp (gdImagePtr im, gdFontPtr f, int x, int y,
|
||||
unsigned char *s, int color);
|
||||
void gdImageString16 (gdImagePtr im, gdFontPtr f, int x, int y,
|
||||
unsigned short *s, int color);
|
||||
void gdImageStringUp16 (gdImagePtr im, gdFontPtr f, int x, int y,
|
||||
unsigned short *s, int color);
|
||||
|
||||
/* clean up after using fonts in gdImageStringFT() */
|
||||
void gdFreeFontCache ();
|
||||
|
||||
/* Calls gdImageStringFT. Provided for backwards compatibility only. */
|
||||
char *gdImageStringTTF (gdImage * im, int *brect, int fg, char *fontlist,
|
||||
double ptsize, double angle, int x, int y,
|
||||
char *string);
|
||||
|
||||
/* FreeType 2 text output */
|
||||
char *gdImageStringFT (gdImage * im, int *brect, int fg, char *fontlist,
|
||||
double ptsize, double angle, int x, int y,
|
||||
char *string);
|
||||
|
||||
/* 2.0.5: provides an extensible way to pass additional parameters.
|
||||
Thanks to Wez Furlong, sorry for the delay. */
|
||||
|
||||
typedef struct
|
||||
{
|
||||
int flags; /* Logical OR of gdFTEX_ values */
|
||||
double linespacing; /* fine tune line spacing for '\n' */
|
||||
int charmap; /* TBB: 2.0.12: may be gdFTEX_Unicode,
|
||||
gdFTEX_Shift_JIS, or gdFTEX_Big5;
|
||||
when not specified, maps are searched
|
||||
for in the above order. */
|
||||
}
|
||||
gdFTStringExtra, *gdFTStringExtraPtr;
|
||||
|
||||
#define gdFTEX_LINESPACE 1
|
||||
#define gdFTEX_CHARMAP 2
|
||||
|
||||
/* These are NOT flags; set one in 'charmap' if you set the
|
||||
gdFTEX_CHARMAP bit in 'flags'. */
|
||||
#define gdFTEX_Unicode 0
|
||||
#define gdFTEX_Shift_JIS 1
|
||||
#define gdFTEX_Big5 2
|
||||
|
||||
char *gdImageStringFTEx (gdImage * im, int *brect, int fg, char *fontlist,
|
||||
double ptsize, double angle, int x, int y,
|
||||
char *string, gdFTStringExtraPtr strex);
|
||||
|
||||
/* Point type for use in polygon drawing. */
|
||||
typedef struct
|
||||
{
|
||||
int x, y;
|
||||
}
|
||||
gdPoint, *gdPointPtr;
|
||||
|
||||
void gdImagePolygon (gdImagePtr im, gdPointPtr p, int n, int c);
|
||||
void gdImageFilledPolygon (gdImagePtr im, gdPointPtr p, int n, int c);
|
||||
|
||||
/* These functions still work with truecolor images,
|
||||
for which they never return error. */
|
||||
int gdImageColorAllocate (gdImagePtr im, int r, int g, int b);
|
||||
/* gd 2.0: palette entries with non-opaque transparency are permitted. */
|
||||
int gdImageColorAllocateAlpha (gdImagePtr im, int r, int g, int b, int a);
|
||||
/* Assumes opaque is the preferred alpha channel value */
|
||||
int gdImageColorClosest (gdImagePtr im, int r, int g, int b);
|
||||
/* Closest match taking all four parameters into account.
|
||||
A slightly different color with the same transparency
|
||||
beats the exact same color with radically different
|
||||
transparency */
|
||||
int gdImageColorClosestAlpha (gdImagePtr im, int r, int g, int b, int a);
|
||||
/* An alternate method */
|
||||
int gdImageColorClosestHWB (gdImagePtr im, int r, int g, int b);
|
||||
/* Returns exact, 100% opaque matches only */
|
||||
int gdImageColorExact (gdImagePtr im, int r, int g, int b);
|
||||
/* Returns an exact match only, including alpha */
|
||||
int gdImageColorExactAlpha (gdImagePtr im, int r, int g, int b, int a);
|
||||
/* Opaque only */
|
||||
int gdImageColorResolve (gdImagePtr im, int r, int g, int b);
|
||||
/* Based on gdImageColorExactAlpha and gdImageColorClosestAlpha */
|
||||
int gdImageColorResolveAlpha (gdImagePtr im, int r, int g, int b, int a);
|
||||
|
||||
/* A simpler way to obtain an opaque truecolor value for drawing on a
|
||||
truecolor image. Not for use with palette images! */
|
||||
|
||||
#define gdTrueColor(r, g, b) (((r) << 16) + \
|
||||
((g) << 8) + \
|
||||
(b))
|
||||
|
||||
/* Returns a truecolor value with an alpha channel component.
|
||||
gdAlphaMax (127, **NOT 255**) is transparent, 0 is completely
|
||||
opaque. */
|
||||
|
||||
#define gdTrueColorAlpha(r, g, b, a) (((a) << 24) + \
|
||||
((r) << 16) + \
|
||||
((g) << 8) + \
|
||||
(b))
|
||||
|
||||
void gdImageColorDeallocate (gdImagePtr im, int color);
|
||||
|
||||
/* Converts a truecolor image to a palette-based image,
|
||||
using a high-quality two-pass quantization routine
|
||||
which attempts to preserve alpha channel information
|
||||
as well as R/G/B color information when creating
|
||||
a palette. If ditherFlag is set, the image will be
|
||||
dithered to approximate colors better, at the expense
|
||||
of some obvious "speckling." colorsWanted can be
|
||||
anything up to 256. If the original source image
|
||||
includes photographic information or anything that
|
||||
came out of a JPEG, 256 is strongly recommended.
|
||||
|
||||
Better yet, don't use this function -- write real
|
||||
truecolor PNGs and JPEGs. The disk space gain of
|
||||
conversion to palette is not great (for small images
|
||||
it can be negative) and the quality loss is ugly. */
|
||||
|
||||
void gdImageTrueColorToPalette (gdImagePtr im, int ditherFlag,
|
||||
int colorsWanted);
|
||||
|
||||
/* Specifies a color index (if a palette image) or an
|
||||
RGB color (if a truecolor image) which should be
|
||||
considered 100% transparent. FOR TRUECOLOR IMAGES,
|
||||
THIS IS IGNORED IF AN ALPHA CHANNEL IS BEING
|
||||
SAVED. Use gdImageSaveAlpha(im, 0); to
|
||||
turn off the saving of a full alpha channel in
|
||||
a truecolor image. Note that gdImageColorTransparent
|
||||
is usually compatible with older browsers that
|
||||
do not understand full alpha channels well. TBB */
|
||||
void gdImageColorTransparent (gdImagePtr im, int color);
|
||||
|
||||
void gdImagePaletteCopy (gdImagePtr dst, gdImagePtr src);
|
||||
void gdImagePng (gdImagePtr im, FILE * out);
|
||||
void gdImagePngCtx (gdImagePtr im, gdIOCtx * out);
|
||||
/* 2.0.12: Compression level: 0-9 or -1, where 0 is NO COMPRESSION at all,
|
||||
1 is FASTEST but produces larger files, 9 provides the best
|
||||
compression (smallest files) but takes a long time to compress, and
|
||||
-1 selects the default compiled into the zlib library. */
|
||||
void gdImagePngEx (gdImagePtr im, FILE * out, int level);
|
||||
void gdImagePngCtxEx (gdImagePtr im, gdIOCtx * out, int level);
|
||||
|
||||
void gdImageWBMP (gdImagePtr image, int fg, FILE * out);
|
||||
void gdImageWBMPCtx (gdImagePtr image, int fg, gdIOCtx * out);
|
||||
|
||||
/* Guaranteed to correctly free memory returned
|
||||
by the gdImage*Ptr functions */
|
||||
void gdFree (void *m);
|
||||
|
||||
/* Best to free this memory with gdFree(), not free() */
|
||||
void *gdImageWBMPPtr (gdImagePtr im, int *size, int fg);
|
||||
|
||||
/* 100 is highest quality (there is always a little loss with JPEG).
|
||||
0 is lowest. 10 is about the lowest useful setting. */
|
||||
void gdImageJpeg (gdImagePtr im, FILE * out, int quality);
|
||||
void gdImageJpegCtx (gdImagePtr im, gdIOCtx * out, int quality);
|
||||
|
||||
/* Best to free this memory with gdFree(), not free() */
|
||||
void *gdImageJpegPtr (gdImagePtr im, int *size, int quality);
|
||||
|
||||
/* A custom data sink. For backwards compatibility. Use
|
||||
gdIOCtx instead. */
|
||||
/* The sink function must return -1 on error, otherwise the number
|
||||
of bytes written, which must be equal to len. */
|
||||
/* context will be passed to your sink function. */
|
||||
typedef struct
|
||||
{
|
||||
int (*sink) (void *context, const char *buffer, int len);
|
||||
void *context;
|
||||
}
|
||||
gdSink, *gdSinkPtr;
|
||||
|
||||
void gdImagePngToSink (gdImagePtr im, gdSinkPtr out);
|
||||
|
||||
void gdImageGd (gdImagePtr im, FILE * out);
|
||||
void gdImageGd2 (gdImagePtr im, FILE * out, int cs, int fmt);
|
||||
|
||||
/* Best to free this memory with gdFree(), not free() */
|
||||
void *gdImagePngPtr (gdImagePtr im, int *size);
|
||||
void *gdImagePngPtrEx (gdImagePtr im, int *size, int level);
|
||||
|
||||
/* Best to free this memory with gdFree(), not free() */
|
||||
void *gdImageGdPtr (gdImagePtr im, int *size);
|
||||
|
||||
/* Best to free this memory with gdFree(), not free() */
|
||||
void *gdImageGd2Ptr (gdImagePtr im, int cs, int fmt, int *size);
|
||||
|
||||
void gdImageEllipse (gdImagePtr im, int cx, int cy, int w, int h,
|
||||
int color);
|
||||
|
||||
/* Style is a bitwise OR ( | operator ) of these.
|
||||
gdArc and gdChord are mutually exclusive;
|
||||
gdChord just connects the starting and ending
|
||||
angles with a straight line, while gdArc produces
|
||||
a rounded edge. gdPie is a synonym for gdArc.
|
||||
gdNoFill indicates that the arc or chord should be
|
||||
outlined, not filled. gdEdged, used together with
|
||||
gdNoFill, indicates that the beginning and ending
|
||||
angles should be connected to the center; this is
|
||||
a good way to outline (rather than fill) a
|
||||
'pie slice'. */
|
||||
#define gdArc 0
|
||||
#define gdPie gdArc
|
||||
#define gdChord 1
|
||||
#define gdNoFill 2
|
||||
#define gdEdged 4
|
||||
|
||||
void gdImageFilledArc (gdImagePtr im, int cx, int cy, int w, int h, int s,
|
||||
int e, int color, int style);
|
||||
void gdImageArc (gdImagePtr im, int cx, int cy, int w, int h, int s, int e,
|
||||
int color);
|
||||
void gdImageFilledEllipse (gdImagePtr im, int cx, int cy, int w, int h,
|
||||
int color);
|
||||
void gdImageFillToBorder (gdImagePtr im, int x, int y, int border,
|
||||
int color);
|
||||
void gdImageFill (gdImagePtr im, int x, int y, int color);
|
||||
void gdImageCopy (gdImagePtr dst, gdImagePtr src, int dstX, int dstY,
|
||||
int srcX, int srcY, int w, int h);
|
||||
void gdImageCopyMerge (gdImagePtr dst, gdImagePtr src, int dstX, int dstY,
|
||||
int srcX, int srcY, int w, int h, int pct);
|
||||
void gdImageCopyMergeGray (gdImagePtr dst, gdImagePtr src, int dstX,
|
||||
int dstY, int srcX, int srcY, int w, int h,
|
||||
int pct);
|
||||
|
||||
/* Stretches or shrinks to fit, as needed. Does NOT attempt
|
||||
to average the entire set of source pixels that scale down onto the
|
||||
destination pixel. */
|
||||
void gdImageCopyResized (gdImagePtr dst, gdImagePtr src, int dstX, int dstY,
|
||||
int srcX, int srcY, int dstW, int dstH, int srcW,
|
||||
int srcH);
|
||||
|
||||
/* gd 2.0: stretches or shrinks to fit, as needed. When called with a
|
||||
truecolor destination image, this function averages the
|
||||
entire set of source pixels that scale down onto the
|
||||
destination pixel, taking into account what portion of the
|
||||
destination pixel each source pixel represents. This is a
|
||||
floating point operation, but this is not a performance issue
|
||||
on modern hardware, except for some embedded devices. If the
|
||||
destination is a palette image, gdImageCopyResized is
|
||||
substituted automatically. */
|
||||
void gdImageCopyResampled (gdImagePtr dst, gdImagePtr src, int dstX,
|
||||
int dstY, int srcX, int srcY, int dstW, int dstH,
|
||||
int srcW, int srcH);
|
||||
|
||||
/* gd 2.0.8: gdImageCopyRotated is added. Source
|
||||
is a rectangle, with its upper left corner at
|
||||
srcX and srcY. Destination is the *center* of
|
||||
the rotated copy. Angle is in degrees, same as
|
||||
gdImageArc. Floating point destination center
|
||||
coordinates allow accurate rotation of
|
||||
objects of odd-numbered width or height. */
|
||||
void gdImageCopyRotated (gdImagePtr dst,
|
||||
gdImagePtr src,
|
||||
double dstX, double dstY,
|
||||
int srcX, int srcY,
|
||||
int srcWidth, int srcHeight, int angle);
|
||||
|
||||
void gdImageSetBrush (gdImagePtr im, gdImagePtr brush);
|
||||
void gdImageSetTile (gdImagePtr im, gdImagePtr tile);
|
||||
void gdImageSetAntiAliased (gdImagePtr im, int c);
|
||||
void gdImageSetAntiAliasedDontBlend (gdImagePtr im, int c, int dont_blend);
|
||||
void gdImageSetStyle (gdImagePtr im, int *style, int noOfPixels);
|
||||
/* Line thickness (defaults to 1). Affects lines, ellipses,
|
||||
rectangles, polygons and so forth. */
|
||||
void gdImageSetThickness (gdImagePtr im, int thickness);
|
||||
/* On or off (1 or 0) for all three of these. */
|
||||
void gdImageInterlace (gdImagePtr im, int interlaceArg);
|
||||
void gdImageAlphaBlending (gdImagePtr im, int alphaBlendingArg);
|
||||
void gdImageSaveAlpha (gdImagePtr im, int saveAlphaArg);
|
||||
|
||||
/* Macros to access information about images. */
|
||||
|
||||
/* Returns nonzero if the image is a truecolor image,
|
||||
zero for a palette image. */
|
||||
|
||||
#define gdImageTrueColor(im) ((im)->trueColor)
|
||||
|
||||
#define gdImageSX(im) ((im)->sx)
|
||||
#define gdImageSY(im) ((im)->sy)
|
||||
#define gdImageColorsTotal(im) ((im)->colorsTotal)
|
||||
#define gdImageRed(im, c) ((im)->trueColor ? gdTrueColorGetRed(c) : \
|
||||
(im)->red[(c)])
|
||||
#define gdImageGreen(im, c) ((im)->trueColor ? gdTrueColorGetGreen(c) : \
|
||||
(im)->green[(c)])
|
||||
#define gdImageBlue(im, c) ((im)->trueColor ? gdTrueColorGetBlue(c) : \
|
||||
(im)->blue[(c)])
|
||||
#define gdImageAlpha(im, c) ((im)->trueColor ? gdTrueColorGetAlpha(c) : \
|
||||
(im)->alpha[(c)])
|
||||
#define gdImageGetTransparent(im) ((im)->transparent)
|
||||
#define gdImageGetInterlaced(im) ((im)->interlace)
|
||||
|
||||
/* These macros provide direct access to pixels in
|
||||
palette-based and truecolor images, respectively.
|
||||
If you use these macros, you must perform your own
|
||||
bounds checking. Use of the macro for the correct type
|
||||
of image is also your responsibility. */
|
||||
#define gdImagePalettePixel(im, x, y) (im)->pixels[(y)][(x)]
|
||||
#define gdImageTrueColorPixel(im, x, y) (im)->tpixels[(y)][(x)]
|
||||
|
||||
/* I/O Support routines. */
|
||||
|
||||
gdIOCtx *gdNewFileCtx (FILE *);
|
||||
gdIOCtx *gdNewDynamicCtx (int, void *);
|
||||
gdIOCtx *gdNewSSCtx (gdSourcePtr in, gdSinkPtr out);
|
||||
void *gdDPExtractData (struct gdIOCtx *ctx, int *size);
|
||||
|
||||
#define GD2_CHUNKSIZE 128
|
||||
#define GD2_CHUNKSIZE_MIN 64
|
||||
#define GD2_CHUNKSIZE_MAX 4096
|
||||
|
||||
#define GD2_VERS 2
|
||||
#define GD2_ID "gd2"
|
||||
|
||||
#define GD2_FMT_RAW 1
|
||||
#define GD2_FMT_COMPRESSED 2
|
||||
|
||||
/* Image comparison definitions */
|
||||
int gdImageCompare (gdImagePtr im1, gdImagePtr im2);
|
||||
|
||||
#define GD_CMP_IMAGE 1 /* Actual image IS different */
|
||||
#define GD_CMP_NUM_COLORS 2 /* Number of Colours in pallette differ */
|
||||
#define GD_CMP_COLOR 4 /* Image colours differ */
|
||||
#define GD_CMP_SIZE_X 8 /* Image width differs */
|
||||
#define GD_CMP_SIZE_Y 16 /* Image heights differ */
|
||||
#define GD_CMP_TRANSPARENT 32 /* Transparent colour */
|
||||
#define GD_CMP_BACKGROUND 64 /* Background colour */
|
||||
#define GD_CMP_INTERLACE 128 /* Interlaced setting */
|
||||
#define GD_CMP_TRUECOLOR 256 /* Truecolor vs palette differs */
|
||||
|
||||
/* resolution affects ttf font rendering, particularly hinting */
|
||||
#define GD_RESOLUTION 96 /* pixels per inch */
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif /* GD_H */
|
File diff suppressed because it is too large
Load Diff
|
@ -1,325 +0,0 @@
|
|||
|
||||
#ifdef HAVE_CONFIG_H
|
||||
#include "config.h"
|
||||
#endif
|
||||
|
||||
#include <stdio.h>
|
||||
#include <math.h>
|
||||
#include <string.h>
|
||||
#include <stdlib.h>
|
||||
#include "gd.h"
|
||||
|
||||
#define TRUE 1
|
||||
#define FALSE 0
|
||||
|
||||
/* Exported functions: */
|
||||
extern void gdImageGd (gdImagePtr im, FILE * out);
|
||||
|
||||
|
||||
/* Use this for commenting out debug-print statements. */
|
||||
/* Just use the first '#define' to allow all the prints... */
|
||||
/*#define GD2_DBG(s) (s) */
|
||||
#define GD2_DBG(s)
|
||||
|
||||
/* */
|
||||
/* Shared code to read color tables from gd file. */
|
||||
/* */
|
||||
int
|
||||
_gdGetColors (gdIOCtx * in, gdImagePtr im, int gd2xFlag)
|
||||
{
|
||||
int i;
|
||||
if (gd2xFlag)
|
||||
{
|
||||
int trueColorFlag;
|
||||
if (!gdGetByte (&trueColorFlag, in))
|
||||
{
|
||||
goto fail1;
|
||||
}
|
||||
/* 2.0.12: detect bad truecolor .gd files created by pre-2.0.12.
|
||||
Beginning in 2.0.12 truecolor is indicated by the initial 2-byte
|
||||
signature. */
|
||||
if (trueColorFlag != im->trueColor)
|
||||
{
|
||||
goto fail1;
|
||||
}
|
||||
/* This should have been a word all along */
|
||||
if (!im->trueColor)
|
||||
{
|
||||
if (!gdGetWord (&im->colorsTotal, in))
|
||||
{
|
||||
goto fail1;
|
||||
}
|
||||
}
|
||||
/* Int to accommodate truecolor single-color transparency */
|
||||
if (!gdGetInt (&im->transparent, in))
|
||||
{
|
||||
goto fail1;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
if (!gdGetByte (&im->colorsTotal, in))
|
||||
{
|
||||
goto fail1;
|
||||
}
|
||||
if (!gdGetWord (&im->transparent, in))
|
||||
{
|
||||
goto fail1;
|
||||
}
|
||||
if (im->transparent == 257)
|
||||
{
|
||||
im->transparent = (-1);
|
||||
}
|
||||
}
|
||||
GD2_DBG (printf
|
||||
("Pallette had %d colours (T=%d)\n", im->colorsTotal,
|
||||
im->transparent));
|
||||
if (im->trueColor)
|
||||
{
|
||||
return TRUE;
|
||||
}
|
||||
for (i = 0; (i < gdMaxColors); i++)
|
||||
{
|
||||
if (!gdGetByte (&im->red[i], in))
|
||||
{
|
||||
goto fail1;
|
||||
}
|
||||
if (!gdGetByte (&im->green[i], in))
|
||||
{
|
||||
goto fail1;
|
||||
}
|
||||
if (!gdGetByte (&im->blue[i], in))
|
||||
{
|
||||
goto fail1;
|
||||
}
|
||||
if (gd2xFlag)
|
||||
{
|
||||
if (!gdGetByte (&im->alpha[i], in))
|
||||
{
|
||||
goto fail1;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
for (i = 0; (i < im->colorsTotal); i++)
|
||||
{
|
||||
im->open[i] = 0;
|
||||
};
|
||||
|
||||
return TRUE;
|
||||
fail1:
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
/* */
|
||||
/* Use the common basic header info to make the image object. */
|
||||
/* */
|
||||
static gdImagePtr
|
||||
_gdCreateFromFile (gdIOCtx * in, int *sx, int *sy)
|
||||
{
|
||||
gdImagePtr im;
|
||||
int gd2xFlag = 0;
|
||||
int trueColorFlag = 0;
|
||||
if (!gdGetWord (sx, in))
|
||||
{
|
||||
goto fail1;
|
||||
}
|
||||
if ((*sx == 65535) || (*sx == 65534))
|
||||
{
|
||||
/* This is a gd 2.0 .gd file */
|
||||
gd2xFlag = 1;
|
||||
/* 2.0.12: 65534 signals a truecolor .gd file.
|
||||
There is a slight redundancy here but we can
|
||||
live with it. */
|
||||
if (*sx == 65534)
|
||||
{
|
||||
trueColorFlag = 1;
|
||||
}
|
||||
if (!gdGetWord (sx, in))
|
||||
{
|
||||
goto fail1;
|
||||
}
|
||||
}
|
||||
if (!gdGetWord (sy, in))
|
||||
{
|
||||
goto fail1;
|
||||
}
|
||||
|
||||
GD2_DBG (printf ("Image is %dx%d\n", *sx, *sy));
|
||||
if (trueColorFlag)
|
||||
{
|
||||
im = gdImageCreateTrueColor (*sx, *sy);
|
||||
}
|
||||
else
|
||||
{
|
||||
im = gdImageCreate (*sx, *sy);
|
||||
}
|
||||
if (!_gdGetColors (in, im, gd2xFlag))
|
||||
{
|
||||
goto fail2;
|
||||
}
|
||||
|
||||
return im;
|
||||
fail2:
|
||||
gdImageDestroy (im);
|
||||
fail1:
|
||||
return 0;
|
||||
}
|
||||
|
||||
gdImagePtr
|
||||
gdImageCreateFromGd (FILE * inFile)
|
||||
{
|
||||
gdImagePtr im;
|
||||
gdIOCtx *in;
|
||||
|
||||
in = gdNewFileCtx (inFile);
|
||||
im = gdImageCreateFromGdCtx (in);
|
||||
|
||||
in->gd_free (in);
|
||||
|
||||
return im;
|
||||
}
|
||||
|
||||
gdImagePtr
|
||||
gdImageCreateFromGdCtx (gdIOCtxPtr in)
|
||||
{
|
||||
int sx, sy;
|
||||
int x, y;
|
||||
gdImagePtr im;
|
||||
|
||||
/* Read the header */
|
||||
im = _gdCreateFromFile (in, &sx, &sy);
|
||||
|
||||
if (im == NULL)
|
||||
{
|
||||
goto fail1;
|
||||
};
|
||||
|
||||
/* Then the data... */
|
||||
/* 2.0.12: support truecolor properly in .gd as well as in .gd2.
|
||||
Problem reported by Andreas Pfaller. */
|
||||
if (im->trueColor)
|
||||
{
|
||||
for (y = 0; (y < sy); y++)
|
||||
{
|
||||
for (x = 0; (x < sx); x++)
|
||||
{
|
||||
int pix;
|
||||
if (!gdGetInt (&pix, in))
|
||||
{
|
||||
goto fail2;
|
||||
}
|
||||
im->tpixels[y][x] = pix;
|
||||
}
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
for (y = 0; (y < sy); y++)
|
||||
{
|
||||
for (x = 0; (x < sx); x++)
|
||||
{
|
||||
int ch;
|
||||
ch = gdGetC (in);
|
||||
if (ch == EOF)
|
||||
{
|
||||
goto fail2;
|
||||
}
|
||||
/* ROW-MAJOR IN GD 1.3 */
|
||||
im->pixels[y][x] = ch;
|
||||
}
|
||||
}
|
||||
}
|
||||
return im;
|
||||
|
||||
fail2:
|
||||
gdImageDestroy (im);
|
||||
fail1:
|
||||
return 0;
|
||||
}
|
||||
|
||||
void
|
||||
_gdPutColors (gdImagePtr im, gdIOCtx * out)
|
||||
{
|
||||
int i;
|
||||
|
||||
gdPutC (im->trueColor, out);
|
||||
if (!im->trueColor)
|
||||
{
|
||||
gdPutWord (im->colorsTotal, out);
|
||||
}
|
||||
gdPutInt (im->transparent, out);
|
||||
if (!im->trueColor)
|
||||
{
|
||||
for (i = 0; (i < gdMaxColors); i++)
|
||||
{
|
||||
gdPutC ((unsigned char) im->red[i], out);
|
||||
gdPutC ((unsigned char) im->green[i], out);
|
||||
gdPutC ((unsigned char) im->blue[i], out);
|
||||
gdPutC ((unsigned char) im->alpha[i], out);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
static void
|
||||
_gdPutHeader (gdImagePtr im, gdIOCtx * out)
|
||||
{
|
||||
/* 65535 indicates this is a gd 2.x .gd file.
|
||||
2.0.12: 65534 indicates truecolor. */
|
||||
if (im->trueColor)
|
||||
{
|
||||
gdPutWord (65534, out);
|
||||
}
|
||||
else
|
||||
{
|
||||
gdPutWord (65535, out);
|
||||
}
|
||||
gdPutWord (im->sx, out);
|
||||
gdPutWord (im->sy, out);
|
||||
|
||||
_gdPutColors (im, out);
|
||||
|
||||
}
|
||||
|
||||
static void
|
||||
_gdImageGd (gdImagePtr im, gdIOCtx * out)
|
||||
{
|
||||
int x, y;
|
||||
|
||||
_gdPutHeader (im, out);
|
||||
|
||||
for (y = 0; (y < im->sy); y++)
|
||||
{
|
||||
for (x = 0; (x < im->sx); x++)
|
||||
{
|
||||
/* ROW-MAJOR IN GD 1.3 */
|
||||
if (im->trueColor)
|
||||
{
|
||||
gdPutInt (im->tpixels[y][x], out);
|
||||
}
|
||||
else
|
||||
{
|
||||
gdPutC ((unsigned char) im->pixels[y][x], out);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void
|
||||
gdImageGd (gdImagePtr im, FILE * outFile)
|
||||
{
|
||||
gdIOCtx *out = gdNewFileCtx (outFile);
|
||||
_gdImageGd (im, out);
|
||||
out->gd_free (out);
|
||||
}
|
||||
|
||||
void *
|
||||
gdImageGdPtr (gdImagePtr im, int *size)
|
||||
{
|
||||
void *rv;
|
||||
gdIOCtx *out = gdNewDynamicCtx (2048, NULL);
|
||||
_gdImageGd (im, out);
|
||||
rv = gdDPExtractData (out, size);
|
||||
out->gd_free (out);
|
||||
return rv;
|
||||
}
|
File diff suppressed because it is too large
Load Diff
|
@ -1,179 +0,0 @@
|
|||
|
||||
|
||||
/*
|
||||
* io.c
|
||||
*
|
||||
* Implements the imple I/O 'helper' routines.
|
||||
*
|
||||
* Not really essential, but these routines were used extensively in GD,
|
||||
* so they were moved here. They also make IOCtx calls look better...
|
||||
*
|
||||
* Written (or, at least, moved) 1999, Philip Warner.
|
||||
*
|
||||
*/
|
||||
|
||||
#ifdef HAVE_CONFIG_H
|
||||
#include "config.h"
|
||||
#endif
|
||||
|
||||
#include <math.h>
|
||||
#include <string.h>
|
||||
#include <stdlib.h>
|
||||
#include "gd.h"
|
||||
|
||||
/* Use this for commenting out debug-print statements. */
|
||||
/* Just use the first '#define' to allow all the prints... */
|
||||
/*#define IO_DBG(s) (s) */
|
||||
#define IO_DBG(s)
|
||||
|
||||
|
||||
/*
|
||||
* Write out a word to the I/O context pointer
|
||||
*/
|
||||
void
|
||||
Putword (int w, gdIOCtx * ctx)
|
||||
{
|
||||
unsigned char buf[2];
|
||||
buf[0] = w & 0xff;
|
||||
buf[1] = (w / 256) & 0xff;
|
||||
(ctx->putBuf) (ctx, (char *) buf, 2);
|
||||
}
|
||||
|
||||
void
|
||||
Putchar (int c, gdIOCtx * ctx)
|
||||
{
|
||||
(ctx->putC) (ctx, c & 0xff);
|
||||
}
|
||||
|
||||
void
|
||||
gdPutC (const unsigned char c, gdIOCtx * ctx)
|
||||
{
|
||||
(ctx->putC) (ctx, c);
|
||||
}
|
||||
|
||||
void
|
||||
gdPutWord (int w, gdIOCtx * ctx)
|
||||
{
|
||||
IO_DBG (printf ("Putting word...\n"));
|
||||
(ctx->putC) (ctx, (unsigned char) (w >> 8));
|
||||
(ctx->putC) (ctx, (unsigned char) (w & 0xFF));
|
||||
IO_DBG (printf ("put.\n"));
|
||||
}
|
||||
|
||||
void
|
||||
gdPutInt (int w, gdIOCtx * ctx)
|
||||
{
|
||||
IO_DBG (printf ("Putting int...\n"));
|
||||
(ctx->putC) (ctx, (unsigned char) (w >> 24));
|
||||
(ctx->putC) (ctx, (unsigned char) ((w >> 16) & 0xFF));
|
||||
(ctx->putC) (ctx, (unsigned char) ((w >> 8) & 0xFF));
|
||||
(ctx->putC) (ctx, (unsigned char) (w & 0xFF));
|
||||
IO_DBG (printf ("put.\n"));
|
||||
}
|
||||
|
||||
int
|
||||
gdGetC (gdIOCtx * ctx)
|
||||
{
|
||||
return ((ctx->getC) (ctx));
|
||||
}
|
||||
|
||||
|
||||
|
||||
int
|
||||
gdGetByte (int *result, gdIOCtx * ctx)
|
||||
{
|
||||
int r;
|
||||
r = (ctx->getC) (ctx);
|
||||
if (r == EOF)
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
*result = r;
|
||||
return 1;
|
||||
}
|
||||
|
||||
int
|
||||
gdGetWord (int *result, gdIOCtx * ctx)
|
||||
{
|
||||
int r;
|
||||
r = (ctx->getC) (ctx);
|
||||
if (r == EOF)
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
*result = r << 8;
|
||||
r = (ctx->getC) (ctx);
|
||||
if (r == EOF)
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
*result += r;
|
||||
return 1;
|
||||
}
|
||||
|
||||
|
||||
int
|
||||
gdGetInt (int *result, gdIOCtx * ctx)
|
||||
{
|
||||
int r;
|
||||
r = (ctx->getC) (ctx);
|
||||
if (r == EOF)
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
*result = r << 24;
|
||||
|
||||
r = (ctx->getC) (ctx);
|
||||
if (r == EOF)
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
*result += r << 16;
|
||||
|
||||
r = (ctx->getC) (ctx);
|
||||
if (r == EOF)
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
*result += r << 8;
|
||||
|
||||
r = (ctx->getC) (ctx);
|
||||
if (r == EOF)
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
*result += r;
|
||||
|
||||
return 1;
|
||||
}
|
||||
|
||||
int
|
||||
gdPutBuf (const void *buf, int size, gdIOCtx * ctx)
|
||||
{
|
||||
IO_DBG (printf ("Putting buf...\n"));
|
||||
return (ctx->putBuf) (ctx, buf, size);
|
||||
IO_DBG (printf ("put.\n"));
|
||||
}
|
||||
|
||||
int
|
||||
gdGetBuf (void *buf, int size, gdIOCtx * ctx)
|
||||
{
|
||||
return (ctx->getBuf) (ctx, buf, size);
|
||||
}
|
||||
|
||||
|
||||
int
|
||||
gdSeek (gdIOCtx * ctx, const int pos)
|
||||
{
|
||||
IO_DBG (printf ("Seeking...\n"));
|
||||
return ((ctx->seek) (ctx, pos));
|
||||
IO_DBG (printf ("Done.\n"));
|
||||
}
|
||||
|
||||
long
|
||||
gdTell (gdIOCtx * ctx)
|
||||
{
|
||||
IO_DBG (printf ("Telling...\n"));
|
||||
return ((ctx->tell) (ctx));
|
||||
IO_DBG (printf ("told.\n"));
|
||||
}
|
|
@ -1,47 +0,0 @@
|
|||
#ifndef GD_IO_H
|
||||
#define GD_IO_H 1
|
||||
|
||||
#include <stdio.h>
|
||||
|
||||
#ifdef VMS
|
||||
#define Putchar gdPutchar
|
||||
#endif
|
||||
|
||||
typedef struct gdIOCtx
|
||||
{
|
||||
int (*getC) (struct gdIOCtx *);
|
||||
int (*getBuf) (struct gdIOCtx *, void *, int);
|
||||
|
||||
void (*putC) (struct gdIOCtx *, int);
|
||||
int (*putBuf) (struct gdIOCtx *, const void *, int);
|
||||
|
||||
/* seek must return 1 on SUCCESS, 0 on FAILURE. Unlike fseek! */
|
||||
int (*seek) (struct gdIOCtx *, const int);
|
||||
|
||||
long (*tell) (struct gdIOCtx *);
|
||||
|
||||
void (*gd_free) (struct gdIOCtx *);
|
||||
|
||||
}
|
||||
gdIOCtx;
|
||||
|
||||
typedef struct gdIOCtx *gdIOCtxPtr;
|
||||
|
||||
void Putword (int w, gdIOCtx * ctx);
|
||||
void Putchar (int c, gdIOCtx * ctx);
|
||||
|
||||
void gdPutC (const unsigned char c, gdIOCtx * ctx);
|
||||
int gdPutBuf (const void *, int, gdIOCtx *);
|
||||
void gdPutWord (int w, gdIOCtx * ctx);
|
||||
void gdPutInt (int w, gdIOCtx * ctx);
|
||||
|
||||
int gdGetC (gdIOCtx * ctx);
|
||||
int gdGetBuf (void *, int, gdIOCtx *);
|
||||
int gdGetByte (int *result, gdIOCtx * ctx);
|
||||
int gdGetWord (int *result, gdIOCtx * ctx);
|
||||
int gdGetInt (int *result, gdIOCtx * ctx);
|
||||
|
||||
int gdSeek (gdIOCtx * ctx, const int);
|
||||
long gdTell (gdIOCtx * ctx);
|
||||
|
||||
#endif
|
|
@ -1,421 +0,0 @@
|
|||
/*
|
||||
* io_dp.c
|
||||
*
|
||||
* Implements the dynamic pointer interface.
|
||||
*
|
||||
* Based on GD.pm code by Lincoln Stein for interfacing to libgd.
|
||||
* Added support for reading as well as support for 'tell' and 'seek'.
|
||||
*
|
||||
* As will all I/O modules, most functions are for local use only (called
|
||||
* via function pointers in the I/O context).
|
||||
*
|
||||
* gdDPExtractData is the exception to this: it will return the pointer to
|
||||
* the internal data, and reset the internal storage.
|
||||
*
|
||||
* Written/Modified 1999, Philip Warner.
|
||||
*
|
||||
*/
|
||||
|
||||
#ifdef HAVE_CONFIG_H
|
||||
#include "config.h"
|
||||
#endif
|
||||
|
||||
#include <math.h>
|
||||
#include <string.h>
|
||||
#include <stdlib.h>
|
||||
#include "gd.h"
|
||||
#include "gdhelpers.h"
|
||||
|
||||
#define TRUE 1
|
||||
#define FALSE 0
|
||||
|
||||
/* this is used for creating images in main memory */
|
||||
typedef struct dpStruct
|
||||
{
|
||||
void *data;
|
||||
int logicalSize;
|
||||
int realSize;
|
||||
int dataGood;
|
||||
int pos;
|
||||
}
|
||||
dynamicPtr;
|
||||
|
||||
typedef struct dpIOCtx
|
||||
{
|
||||
gdIOCtx ctx;
|
||||
dynamicPtr *dp;
|
||||
}
|
||||
dpIOCtx;
|
||||
|
||||
typedef struct dpIOCtx *dpIOCtxPtr;
|
||||
|
||||
|
||||
/* these functions operate on in-memory dynamic pointers */
|
||||
static int allocDynamic (dynamicPtr * dp, int initialSize, void *data);
|
||||
static int appendDynamic (dynamicPtr * dp, const void *src, int size);
|
||||
static int gdReallocDynamic (dynamicPtr * dp, int required);
|
||||
static int trimDynamic (dynamicPtr * dp);
|
||||
static void gdFreeDynamicCtx (struct gdIOCtx *ctx);
|
||||
static dynamicPtr *newDynamic (int initialSize, void *data);
|
||||
|
||||
static int dynamicPutbuf (struct gdIOCtx *, const void *, int);
|
||||
static void dynamicPutchar (struct gdIOCtx *, int a);
|
||||
|
||||
static int dynamicGetbuf (gdIOCtxPtr ctx, void *buf, int len);
|
||||
static int dynamicGetchar (gdIOCtxPtr ctx);
|
||||
|
||||
static int dynamicSeek (struct gdIOCtx *, const int);
|
||||
static long dynamicTell (struct gdIOCtx *);
|
||||
|
||||
/* return data as a dynamic pointer */
|
||||
gdIOCtx *
|
||||
gdNewDynamicCtx (int initialSize, void *data)
|
||||
{
|
||||
dpIOCtx *ctx;
|
||||
dynamicPtr *dp;
|
||||
|
||||
ctx = (dpIOCtx *) gdMalloc (sizeof (dpIOCtx));
|
||||
if (ctx == NULL)
|
||||
{
|
||||
return NULL;
|
||||
}
|
||||
|
||||
dp = newDynamic (initialSize, data);
|
||||
if (!dp)
|
||||
{
|
||||
gdFree (ctx);
|
||||
return NULL;
|
||||
};
|
||||
|
||||
ctx->dp = dp;
|
||||
|
||||
ctx->ctx.getC = dynamicGetchar;
|
||||
ctx->ctx.putC = dynamicPutchar;
|
||||
|
||||
ctx->ctx.getBuf = dynamicGetbuf;
|
||||
ctx->ctx.putBuf = dynamicPutbuf;
|
||||
|
||||
ctx->ctx.seek = dynamicSeek;
|
||||
ctx->ctx.tell = dynamicTell;
|
||||
|
||||
ctx->ctx.gd_free = gdFreeDynamicCtx;
|
||||
|
||||
return (gdIOCtx *) ctx;
|
||||
}
|
||||
|
||||
void *
|
||||
gdDPExtractData (struct gdIOCtx *ctx, int *size)
|
||||
{
|
||||
dynamicPtr *dp;
|
||||
dpIOCtx *dctx;
|
||||
void *data;
|
||||
|
||||
dctx = (dpIOCtx *) ctx;
|
||||
dp = dctx->dp;
|
||||
|
||||
/* clean up the data block and return it */
|
||||
if (dp->dataGood)
|
||||
{
|
||||
trimDynamic (dp);
|
||||
*size = dp->logicalSize;
|
||||
data = dp->data;
|
||||
}
|
||||
else
|
||||
{
|
||||
*size = 0;
|
||||
data = NULL;
|
||||
if (dp->data != NULL)
|
||||
{
|
||||
gdFree (dp->data);
|
||||
}
|
||||
}
|
||||
|
||||
dp->data = NULL;
|
||||
dp->realSize = 0;
|
||||
dp->logicalSize = 0;
|
||||
|
||||
return data;
|
||||
}
|
||||
|
||||
static void
|
||||
gdFreeDynamicCtx (struct gdIOCtx *ctx)
|
||||
{
|
||||
dynamicPtr *dp;
|
||||
dpIOCtx *dctx;
|
||||
|
||||
dctx = (dpIOCtx *) ctx;
|
||||
dp = dctx->dp;
|
||||
|
||||
gdFree (ctx);
|
||||
|
||||
/* clean up the data block and return it */
|
||||
if (dp->data != NULL)
|
||||
{
|
||||
gdFree (dp->data);
|
||||
dp->data = NULL;
|
||||
}
|
||||
|
||||
dp->realSize = 0;
|
||||
dp->logicalSize = 0;
|
||||
|
||||
gdFree (dp);
|
||||
|
||||
}
|
||||
|
||||
static long
|
||||
dynamicTell (struct gdIOCtx *ctx)
|
||||
{
|
||||
dpIOCtx *dctx;
|
||||
|
||||
dctx = (dpIOCtx *) ctx;
|
||||
return (dctx->dp->pos);
|
||||
}
|
||||
|
||||
static int
|
||||
dynamicSeek (struct gdIOCtx *ctx, const int pos)
|
||||
{
|
||||
int bytesNeeded;
|
||||
dynamicPtr *dp;
|
||||
dpIOCtx *dctx;
|
||||
|
||||
dctx = (dpIOCtx *) ctx;
|
||||
dp = dctx->dp;
|
||||
|
||||
if (!dp->dataGood)
|
||||
return FALSE;
|
||||
|
||||
bytesNeeded = pos;
|
||||
if (bytesNeeded > dp->realSize)
|
||||
{
|
||||
if (!gdReallocDynamic (dp, dp->realSize * 2))
|
||||
{
|
||||
dp->dataGood = FALSE;
|
||||
return FALSE;
|
||||
}
|
||||
}
|
||||
|
||||
/* if we get here, we can be sure that we have enough bytes
|
||||
to copy safely */
|
||||
|
||||
/* Extend the logical size if we seek beyond EOF. */
|
||||
if (pos > dp->logicalSize)
|
||||
{
|
||||
dp->logicalSize = pos;
|
||||
};
|
||||
|
||||
dp->pos = pos;
|
||||
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
/* return data as a dynamic pointer */
|
||||
static dynamicPtr *
|
||||
newDynamic (int initialSize, void *data)
|
||||
{
|
||||
dynamicPtr *dp;
|
||||
dp = (dynamicPtr *) gdMalloc (sizeof (dynamicPtr));
|
||||
if (dp == NULL)
|
||||
{
|
||||
return NULL;
|
||||
}
|
||||
|
||||
if (!allocDynamic (dp, initialSize, data))
|
||||
return NULL;
|
||||
|
||||
dp->pos = 0;
|
||||
|
||||
return dp;
|
||||
}
|
||||
|
||||
static int
|
||||
dynamicPutbuf (struct gdIOCtx *ctx, const void *buf, int size)
|
||||
{
|
||||
dpIOCtx *dctx;
|
||||
dctx = (dpIOCtx *) ctx;
|
||||
|
||||
appendDynamic (dctx->dp, buf, size);
|
||||
|
||||
if (dctx->dp->dataGood)
|
||||
{
|
||||
return size;
|
||||
}
|
||||
else
|
||||
{
|
||||
return -1;
|
||||
};
|
||||
|
||||
}
|
||||
|
||||
static void
|
||||
dynamicPutchar (struct gdIOCtx *ctx, int a)
|
||||
{
|
||||
unsigned char b;
|
||||
dpIOCtxPtr dctx;
|
||||
|
||||
b = a;
|
||||
dctx = (dpIOCtxPtr) ctx;
|
||||
|
||||
appendDynamic (dctx->dp, &b, 1);
|
||||
}
|
||||
|
||||
static int
|
||||
dynamicGetbuf (gdIOCtxPtr ctx, void *buf, int len)
|
||||
{
|
||||
int rlen, remain;
|
||||
dpIOCtxPtr dctx;
|
||||
dynamicPtr *dp;
|
||||
|
||||
dctx = (dpIOCtxPtr) ctx;
|
||||
dp = dctx->dp;
|
||||
|
||||
remain = dp->logicalSize - dp->pos;
|
||||
if (remain >= len)
|
||||
{
|
||||
rlen = len;
|
||||
}
|
||||
else
|
||||
{
|
||||
if (remain == 0)
|
||||
{
|
||||
return EOF;
|
||||
}
|
||||
rlen = remain;
|
||||
}
|
||||
|
||||
memcpy (buf, (void *) ((char *) dp->data + dp->pos), rlen);
|
||||
dp->pos += rlen;
|
||||
|
||||
return rlen;
|
||||
}
|
||||
|
||||
static int
|
||||
dynamicGetchar (gdIOCtxPtr ctx)
|
||||
{
|
||||
unsigned char b;
|
||||
int rv;
|
||||
|
||||
rv = dynamicGetbuf (ctx, &b, 1);
|
||||
|
||||
if (rv != 1)
|
||||
{
|
||||
return EOF;
|
||||
}
|
||||
else
|
||||
{
|
||||
return b; /* (b & 0xff); */
|
||||
}
|
||||
}
|
||||
|
||||
/* *********************************************************************
|
||||
|
||||
* InitDynamic - Return a dynamically resizable void*
|
||||
*
|
||||
* *********************************************************************
|
||||
*/
|
||||
static int
|
||||
allocDynamic (dynamicPtr * dp, int initialSize, void *data)
|
||||
{
|
||||
|
||||
if (data == NULL)
|
||||
{
|
||||
dp->logicalSize = 0;
|
||||
dp->dataGood = FALSE;
|
||||
dp->data = gdMalloc (initialSize);
|
||||
}
|
||||
else
|
||||
{
|
||||
dp->logicalSize = initialSize;
|
||||
dp->dataGood = TRUE;
|
||||
dp->data = data;
|
||||
}
|
||||
|
||||
if (dp->data != NULL)
|
||||
{
|
||||
dp->realSize = initialSize;
|
||||
dp->dataGood = TRUE;
|
||||
dp->pos = 0;
|
||||
return TRUE;
|
||||
}
|
||||
else
|
||||
{
|
||||
dp->realSize = 0;
|
||||
return FALSE;
|
||||
}
|
||||
}
|
||||
|
||||
/* append bytes to the end of a dynamic pointer */
|
||||
static int
|
||||
appendDynamic (dynamicPtr * dp, const void *src, int size)
|
||||
{
|
||||
int bytesNeeded;
|
||||
char *tmp;
|
||||
|
||||
if (!dp->dataGood)
|
||||
return FALSE;
|
||||
|
||||
/* bytesNeeded = dp->logicalSize + size; */
|
||||
bytesNeeded = dp->pos + size;
|
||||
|
||||
if (bytesNeeded > dp->realSize)
|
||||
{
|
||||
if (!gdReallocDynamic (dp, bytesNeeded * 2))
|
||||
{
|
||||
dp->dataGood = FALSE;
|
||||
return FALSE;
|
||||
}
|
||||
}
|
||||
|
||||
/* if we get here, we can be sure that we have enough bytes
|
||||
to copy safely */
|
||||
/*printf("Mem OK Size: %d, Pos: %d\n", dp->realSize, dp->pos); */
|
||||
|
||||
tmp = (char *) dp->data;
|
||||
memcpy ((void *) (tmp + (dp->pos)), src, size);
|
||||
dp->pos += size;
|
||||
|
||||
if (dp->pos > dp->logicalSize)
|
||||
{
|
||||
dp->logicalSize = dp->pos;
|
||||
};
|
||||
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
/* grow (or shrink) dynamic pointer */
|
||||
static int
|
||||
gdReallocDynamic (dynamicPtr * dp, int required)
|
||||
{
|
||||
void *newPtr;
|
||||
|
||||
/* First try gdRealloc(). If that doesn't work, make a new
|
||||
memory block and copy. */
|
||||
if ((newPtr = gdRealloc (dp->data, required)))
|
||||
{
|
||||
dp->realSize = required;
|
||||
dp->data = newPtr;
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
/* create a new pointer */
|
||||
newPtr = gdMalloc (required);
|
||||
if (!newPtr)
|
||||
{
|
||||
dp->dataGood = FALSE;
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
/* copy the old data into it */
|
||||
memcpy (newPtr, dp->data, dp->logicalSize);
|
||||
gdFree (dp->data);
|
||||
dp->data = newPtr;
|
||||
|
||||
dp->realSize = required;
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
/* trim pointer so that its real and logical sizes match */
|
||||
static int
|
||||
trimDynamic (dynamicPtr * dp)
|
||||
{
|
||||
return gdReallocDynamic (dp, dp->logicalSize);
|
||||
}
|
|
@ -1,147 +0,0 @@
|
|||
|
||||
/*
|
||||
* io_file.c
|
||||
*
|
||||
* Implements the file interface.
|
||||
*
|
||||
* As will all I/O modules, most functions are for local use only (called
|
||||
* via function pointers in the I/O context).
|
||||
*
|
||||
* Most functions are just 'wrappers' for standard file functions.
|
||||
*
|
||||
* Written/Modified 1999, Philip Warner.
|
||||
*
|
||||
*/
|
||||
|
||||
#ifdef HAVE_CONFIG_H
|
||||
#include "config.h"
|
||||
#endif
|
||||
|
||||
/* For platforms with incomplete ANSI defines. Fortunately,
|
||||
SEEK_SET is defined to be zero by the standard. */
|
||||
|
||||
#ifndef SEEK_SET
|
||||
#define SEEK_SET 0
|
||||
#endif /* SEEK_SET */
|
||||
|
||||
#include <math.h>
|
||||
#include <string.h>
|
||||
#include <stdlib.h>
|
||||
#include "gd.h"
|
||||
#include "gdhelpers.h"
|
||||
|
||||
/* this is used for creating images in main memory */
|
||||
|
||||
typedef struct fileIOCtx
|
||||
{
|
||||
gdIOCtx ctx;
|
||||
FILE *f;
|
||||
}
|
||||
fileIOCtx;
|
||||
|
||||
struct fileIOCtx *fileIOCtxPtr;
|
||||
|
||||
gdIOCtx *newFileCtx (FILE * f);
|
||||
|
||||
static int fileGetbuf (gdIOCtx *, void *, int);
|
||||
static int filePutbuf (gdIOCtx *, const void *, int);
|
||||
static void filePutchar (gdIOCtx *, int);
|
||||
static int fileGetchar (gdIOCtx * ctx);
|
||||
|
||||
static int fileSeek (struct gdIOCtx *, const int);
|
||||
static long fileTell (struct gdIOCtx *);
|
||||
static void gdFreeFileCtx (gdIOCtx * ctx);
|
||||
|
||||
/* return data as a dynamic pointer */
|
||||
gdIOCtx *
|
||||
gdNewFileCtx (FILE * f)
|
||||
{
|
||||
fileIOCtx *ctx;
|
||||
|
||||
ctx = (fileIOCtx *) gdMalloc (sizeof (fileIOCtx));
|
||||
if (ctx == NULL)
|
||||
{
|
||||
return NULL;
|
||||
}
|
||||
|
||||
ctx->f = f;
|
||||
|
||||
ctx->ctx.getC = fileGetchar;
|
||||
ctx->ctx.putC = filePutchar;
|
||||
|
||||
ctx->ctx.getBuf = fileGetbuf;
|
||||
ctx->ctx.putBuf = filePutbuf;
|
||||
|
||||
ctx->ctx.tell = fileTell;
|
||||
ctx->ctx.seek = fileSeek;
|
||||
|
||||
ctx->ctx.gd_free = gdFreeFileCtx;
|
||||
|
||||
return (gdIOCtx *) ctx;
|
||||
}
|
||||
|
||||
static void
|
||||
gdFreeFileCtx (gdIOCtx * ctx)
|
||||
{
|
||||
gdFree (ctx);
|
||||
}
|
||||
|
||||
|
||||
static int
|
||||
filePutbuf (gdIOCtx * ctx, const void *buf, int size)
|
||||
{
|
||||
fileIOCtx *fctx;
|
||||
fctx = (fileIOCtx *) ctx;
|
||||
|
||||
return fwrite (buf, 1, size, fctx->f);
|
||||
|
||||
}
|
||||
|
||||
static int
|
||||
fileGetbuf (gdIOCtx * ctx, void *buf, int size)
|
||||
{
|
||||
fileIOCtx *fctx;
|
||||
fctx = (fileIOCtx *) ctx;
|
||||
|
||||
return (fread (buf, 1, size, fctx->f));
|
||||
|
||||
}
|
||||
|
||||
static void
|
||||
filePutchar (gdIOCtx * ctx, int a)
|
||||
{
|
||||
unsigned char b;
|
||||
fileIOCtx *fctx;
|
||||
fctx = (fileIOCtx *) ctx;
|
||||
|
||||
b = a;
|
||||
|
||||
putc (b, fctx->f);
|
||||
}
|
||||
|
||||
static int
|
||||
fileGetchar (gdIOCtx * ctx)
|
||||
{
|
||||
fileIOCtx *fctx;
|
||||
fctx = (fileIOCtx *) ctx;
|
||||
|
||||
return getc (fctx->f);
|
||||
}
|
||||
|
||||
|
||||
static int
|
||||
fileSeek (struct gdIOCtx *ctx, const int pos)
|
||||
{
|
||||
fileIOCtx *fctx;
|
||||
fctx = (fileIOCtx *) ctx;
|
||||
return (fseek (fctx->f, pos, SEEK_SET) == 0);
|
||||
}
|
||||
|
||||
static long
|
||||
fileTell (struct gdIOCtx *ctx)
|
||||
{
|
||||
fileIOCtx *fctx;
|
||||
fctx = (fileIOCtx *) ctx;
|
||||
|
||||
return ftell (fctx->f);
|
||||
}
|
|
@ -1,168 +0,0 @@
|
|||
|
||||
/*
|
||||
* io_ss.c
|
||||
*
|
||||
* Implements the Source/Sink interface.
|
||||
*
|
||||
* As will all I/O modules, most functions are for local use only (called
|
||||
* via function pointers in the I/O context).
|
||||
*
|
||||
* The Source/Sink model is the primary 'user' interface for alternate data
|
||||
* sources; the IOCtx interface is intended (at least in version 1.5) to be
|
||||
* used internally until it settles down a bit.
|
||||
*
|
||||
* This module just layers the Source/Sink interface on top of the IOCtx; no
|
||||
* support is provided for tell/seek, so GD2 writing is not possible, and
|
||||
* retrieving parts of GD2 files is also not possible.
|
||||
*
|
||||
* A new SS context does not need to be created with both a Source and a Sink.
|
||||
*
|
||||
* Written/Modified 1999, Philip Warner.
|
||||
*
|
||||
*/
|
||||
|
||||
#ifdef HAVE_CONFIG_H
|
||||
#include "config.h"
|
||||
#endif
|
||||
|
||||
#include <math.h>
|
||||
#include <string.h>
|
||||
#include <stdlib.h>
|
||||
#include "gd.h"
|
||||
#include "gdhelpers.h"
|
||||
|
||||
/* this is used for creating images in main memory */
|
||||
|
||||
typedef struct ssIOCtx
|
||||
{
|
||||
gdIOCtx ctx;
|
||||
gdSourcePtr src;
|
||||
gdSinkPtr snk;
|
||||
}
|
||||
ssIOCtx;
|
||||
|
||||
typedef struct ssIOCtx *ssIOCtxPtr;
|
||||
|
||||
gdIOCtx *gdNewSSCtx (gdSourcePtr src, gdSinkPtr snk);
|
||||
|
||||
static int sourceGetbuf (gdIOCtx *, void *, int);
|
||||
static int sourceGetchar (gdIOCtx * ctx);
|
||||
static int sinkPutbuf (gdIOCtx * ctx, const void *buf, int size);
|
||||
static void sinkPutchar (gdIOCtx * ctx, int a);
|
||||
static void gdFreeSsCtx (gdIOCtx * ctx);
|
||||
|
||||
/* return data as a dynamic pointer */
|
||||
gdIOCtx *
|
||||
gdNewSSCtx (gdSourcePtr src, gdSinkPtr snk)
|
||||
{
|
||||
ssIOCtxPtr ctx;
|
||||
|
||||
ctx = (ssIOCtxPtr) gdMalloc (sizeof (ssIOCtx));
|
||||
if (ctx == NULL)
|
||||
{
|
||||
return NULL;
|
||||
}
|
||||
|
||||
ctx->src = src;
|
||||
ctx->snk = snk;
|
||||
|
||||
ctx->ctx.getC = sourceGetchar;
|
||||
ctx->ctx.getBuf = sourceGetbuf;
|
||||
|
||||
ctx->ctx.putC = sinkPutchar;
|
||||
ctx->ctx.putBuf = sinkPutbuf;
|
||||
|
||||
ctx->ctx.tell = NULL;
|
||||
ctx->ctx.seek = NULL;
|
||||
|
||||
ctx->ctx.gd_free = gdFreeSsCtx;
|
||||
|
||||
return (gdIOCtx *) ctx;
|
||||
}
|
||||
|
||||
static void
|
||||
gdFreeSsCtx (gdIOCtx * ctx)
|
||||
{
|
||||
gdFree (ctx);
|
||||
}
|
||||
|
||||
|
||||
static int
|
||||
sourceGetbuf (gdIOCtx * ctx, void *buf, int size)
|
||||
{
|
||||
ssIOCtx *lctx;
|
||||
int res;
|
||||
|
||||
lctx = (ssIOCtx *) ctx;
|
||||
|
||||
res = ((lctx->src->source) (lctx->src->context, buf, size));
|
||||
|
||||
/*
|
||||
** Translate the return values from the Source object:
|
||||
** 0 is EOF, -1 is error
|
||||
*/
|
||||
|
||||
if (res == 0)
|
||||
{
|
||||
return EOF;
|
||||
}
|
||||
else if (res < 0)
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
else
|
||||
{
|
||||
return res;
|
||||
};
|
||||
|
||||
}
|
||||
|
||||
static int
|
||||
sourceGetchar (gdIOCtx * ctx)
|
||||
{
|
||||
int res;
|
||||
unsigned char buf;
|
||||
|
||||
res = sourceGetbuf (ctx, &buf, 1);
|
||||
|
||||
if (res == 1)
|
||||
{
|
||||
return buf;
|
||||
}
|
||||
else
|
||||
{
|
||||
return EOF;
|
||||
};
|
||||
|
||||
}
|
||||
|
||||
static int
|
||||
sinkPutbuf (gdIOCtx * ctx, const void *buf, int size)
|
||||
{
|
||||
ssIOCtxPtr lctx;
|
||||
int res;
|
||||
|
||||
lctx = (ssIOCtx *) ctx;
|
||||
|
||||
res = (lctx->snk->sink) (lctx->snk->context, buf, size);
|
||||
|
||||
if (res <= 0)
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
else
|
||||
{
|
||||
return res;
|
||||
};
|
||||
|
||||
}
|
||||
|
||||
static void
|
||||
sinkPutchar (gdIOCtx * ctx, int a)
|
||||
{
|
||||
unsigned char b;
|
||||
|
||||
b = a;
|
||||
sinkPutbuf (ctx, &b, 1);
|
||||
|
||||
}
|
|
@ -1,850 +0,0 @@
|
|||
/*
|
||||
* gd_jpeg.c: Read and write JPEG (JFIF) format image files using the
|
||||
* gd graphics library (http://www.boutell.com/gd/).
|
||||
*
|
||||
* This software is based in part on the work of the Independent JPEG
|
||||
* Group. For more information on the IJG JPEG software (and JPEG
|
||||
* documentation, etc.), see ftp://ftp.uu.net/graphics/jpeg/.
|
||||
*
|
||||
* NOTE: IJG 12-bit JSAMPLE (BITS_IN_JSAMPLE == 12) mode is not
|
||||
* supported at all on read in gd 2.0, and is not supported on write
|
||||
* except for palette images, which is sort of pointless (TBB). Even that
|
||||
* has never been tested according to DB.
|
||||
*
|
||||
* Copyright 2000 Doug Becker, mailto:thebeckers@home.com
|
||||
*
|
||||
* Modification 4/18/00 TBB: JPEG_DEBUG rather than just DEBUG,
|
||||
* so VC++ builds don't spew to standard output, causing
|
||||
* major CGI brain damage
|
||||
*
|
||||
* 2.0.10: more efficient gdImageCreateFromJpegCtx, thanks to
|
||||
* Christian Aberger
|
||||
*/
|
||||
|
||||
#ifdef HAVE_CONFIG_H
|
||||
#include "config.h"
|
||||
#endif
|
||||
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <setjmp.h>
|
||||
#include <limits.h>
|
||||
#include <string.h>
|
||||
|
||||
#include "gd.h"
|
||||
/* TBB: move this up so include files are not brought in */
|
||||
/* JCE: arrange HAVE_LIBJPEG so that it can be set in gd.h */
|
||||
#ifdef HAVE_LIBJPEG
|
||||
#include "gdhelpers.h"
|
||||
|
||||
/* 1.8.1: remove dependency on jinclude.h */
|
||||
#include "jpeglib.h"
|
||||
#include "jerror.h"
|
||||
|
||||
static const char *const GD_JPEG_VERSION = "1.0";
|
||||
|
||||
typedef struct _jmpbuf_wrapper
|
||||
{
|
||||
jmp_buf jmpbuf;
|
||||
}
|
||||
jmpbuf_wrapper;
|
||||
|
||||
/* Called by the IJG JPEG library upon encountering a fatal error */
|
||||
static void
|
||||
fatal_jpeg_error (j_common_ptr cinfo)
|
||||
{
|
||||
jmpbuf_wrapper *jmpbufw;
|
||||
|
||||
fprintf (stderr, "gd-jpeg: JPEG library reports unrecoverable error: ");
|
||||
(*cinfo->err->output_message) (cinfo);
|
||||
fflush (stderr);
|
||||
|
||||
jmpbufw = (jmpbuf_wrapper *) cinfo->client_data;
|
||||
jpeg_destroy (cinfo);
|
||||
|
||||
if (jmpbufw != 0)
|
||||
{
|
||||
longjmp (jmpbufw->jmpbuf, 1);
|
||||
fprintf (stderr, "gd-jpeg: EXTREMELY fatal error: longjmp"
|
||||
" returned control; terminating\n");
|
||||
}
|
||||
else
|
||||
{
|
||||
fprintf (stderr, "gd-jpeg: EXTREMELY fatal error: jmpbuf"
|
||||
" unrecoverable; terminating\n");
|
||||
}
|
||||
|
||||
fflush (stderr);
|
||||
exit (99);
|
||||
}
|
||||
|
||||
/*
|
||||
* Write IM to OUTFILE as a JFIF-formatted JPEG image, using quality
|
||||
* QUALITY. If QUALITY is in the range 0-100, increasing values
|
||||
* represent higher quality but also larger image size. If QUALITY is
|
||||
* negative, the IJG JPEG library's default quality is used (which
|
||||
* should be near optimal for many applications). See the IJG JPEG
|
||||
* library documentation for more details. */
|
||||
|
||||
void
|
||||
gdImageJpeg (gdImagePtr im, FILE * outFile, int quality)
|
||||
{
|
||||
gdIOCtx *out = gdNewFileCtx (outFile);
|
||||
gdImageJpegCtx (im, out, quality);
|
||||
out->gd_free (out);
|
||||
}
|
||||
|
||||
void *
|
||||
gdImageJpegPtr (gdImagePtr im, int *size, int quality)
|
||||
{
|
||||
void *rv;
|
||||
gdIOCtx *out = gdNewDynamicCtx (2048, NULL);
|
||||
gdImageJpegCtx (im, out, quality);
|
||||
rv = gdDPExtractData (out, size);
|
||||
out->gd_free (out);
|
||||
return rv;
|
||||
}
|
||||
|
||||
void jpeg_gdIOCtx_dest (j_compress_ptr cinfo, gdIOCtx * outfile);
|
||||
|
||||
void
|
||||
gdImageJpegCtx (gdImagePtr im, gdIOCtx * outfile, int quality)
|
||||
{
|
||||
struct jpeg_compress_struct cinfo;
|
||||
struct jpeg_error_mgr jerr;
|
||||
int i, j, jidx;
|
||||
/* volatile so we can gdFree it on return from longjmp */
|
||||
volatile JSAMPROW row = 0;
|
||||
JSAMPROW rowptr[1];
|
||||
jmpbuf_wrapper jmpbufw;
|
||||
JDIMENSION nlines;
|
||||
char comment[255];
|
||||
|
||||
#ifdef JPEG_DEBUG
|
||||
printf ("gd-jpeg: gd JPEG version %s\n", GD_JPEG_VERSION);
|
||||
printf ("gd-jpeg: JPEG library version %d, %d-bit sample values\n",
|
||||
JPEG_LIB_VERSION, BITS_IN_JSAMPLE);
|
||||
if (!im->trueColor)
|
||||
{
|
||||
for (i = 0; i < im->colorsTotal; i++)
|
||||
{
|
||||
if (!im->open[i])
|
||||
printf ("gd-jpeg: gd colormap index %d: (%d, %d, %d)\n", i,
|
||||
im->red[i], im->green[i], im->blue[i]);
|
||||
}
|
||||
}
|
||||
#endif /* JPEG_DEBUG */
|
||||
|
||||
memset (&cinfo, 0, sizeof (cinfo));
|
||||
memset (&jerr, 0, sizeof (jerr));
|
||||
|
||||
cinfo.err = jpeg_std_error (&jerr);
|
||||
cinfo.client_data = &jmpbufw;
|
||||
if (setjmp (jmpbufw.jmpbuf) != 0)
|
||||
{
|
||||
/* we're here courtesy of longjmp */
|
||||
if (row)
|
||||
gdFree (row);
|
||||
return;
|
||||
}
|
||||
|
||||
cinfo.err->error_exit = fatal_jpeg_error;
|
||||
|
||||
jpeg_create_compress (&cinfo);
|
||||
|
||||
cinfo.image_width = im->sx;
|
||||
cinfo.image_height = im->sy;
|
||||
cinfo.input_components = 3; /* # of color components per pixel */
|
||||
cinfo.in_color_space = JCS_RGB; /* colorspace of input image */
|
||||
jpeg_set_defaults (&cinfo);
|
||||
if (quality >= 0)
|
||||
jpeg_set_quality (&cinfo, quality, TRUE);
|
||||
|
||||
/* If user requests interlace, translate that to progressive JPEG */
|
||||
if (gdImageGetInterlaced (im))
|
||||
{
|
||||
#ifdef JPEG_DEBUG
|
||||
printf ("gd-jpeg: interlace set, outputting progressive"
|
||||
" JPEG image\n");
|
||||
#endif
|
||||
jpeg_simple_progression (&cinfo);
|
||||
}
|
||||
|
||||
jpeg_gdIOCtx_dest (&cinfo, outfile);
|
||||
|
||||
row = (JSAMPROW) gdCalloc (1, cinfo.image_width * cinfo.input_components
|
||||
* sizeof (JSAMPLE));
|
||||
if (row == 0)
|
||||
{
|
||||
fprintf (stderr, "gd-jpeg: error: unable to allocate JPEG row "
|
||||
"structure: gdCalloc returns NULL\n");
|
||||
jpeg_destroy_compress (&cinfo);
|
||||
return;
|
||||
}
|
||||
|
||||
rowptr[0] = row;
|
||||
|
||||
jpeg_start_compress (&cinfo, TRUE);
|
||||
|
||||
sprintf (comment, "CREATOR: gd-jpeg v%s (using IJG JPEG v%d),",
|
||||
GD_JPEG_VERSION, JPEG_LIB_VERSION);
|
||||
if (quality >= 0)
|
||||
sprintf (comment + strlen (comment), " quality = %d\n", quality);
|
||||
else
|
||||
strcat (comment + strlen (comment), " default quality\n");
|
||||
jpeg_write_marker (&cinfo, JPEG_COM, (unsigned char *) comment,
|
||||
(unsigned int) strlen (comment));
|
||||
if (im->trueColor)
|
||||
{
|
||||
#if BITS_IN_JSAMPLE == 12
|
||||
fprintf (stderr,
|
||||
"gd-jpeg: error: jpeg library was compiled for 12-bit\n"
|
||||
"precision. This is mostly useless, because JPEGs on the web are\n"
|
||||
"8-bit and such versions of the jpeg library won't read or write\n"
|
||||
"them. GD doesn't support these unusual images. Edit your\n"
|
||||
"jmorecfg.h file to specify the correct precision and completely\n"
|
||||
"'make clean' and 'make install' libjpeg again. Sorry.\n");
|
||||
goto error;
|
||||
#endif /* BITS_IN_JSAMPLE == 12 */
|
||||
for (i = 0; i < im->sy; i++)
|
||||
{
|
||||
for (jidx = 0, j = 0; j < im->sx; j++)
|
||||
{
|
||||
int val = im->tpixels[i][j];
|
||||
row[jidx++] = gdTrueColorGetRed (val);
|
||||
row[jidx++] = gdTrueColorGetGreen (val);
|
||||
row[jidx++] = gdTrueColorGetBlue (val);
|
||||
}
|
||||
|
||||
nlines = jpeg_write_scanlines (&cinfo, rowptr, 1);
|
||||
if (nlines != 1)
|
||||
fprintf (stderr, "gd_jpeg: warning: jpeg_write_scanlines"
|
||||
" returns %u -- expected 1\n", nlines);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
for (i = 0; i < im->sy; i++)
|
||||
{
|
||||
for (jidx = 0, j = 0; j < im->sx; j++)
|
||||
{
|
||||
int idx = im->pixels[i][j];
|
||||
|
||||
/*
|
||||
* NB: Although gd RGB values are ints, their max value is
|
||||
* 255 (see the documentation for gdImageColorAllocate())
|
||||
* -- perfect for 8-bit JPEG encoding (which is the norm)
|
||||
*/
|
||||
#if BITS_IN_JSAMPLE == 8
|
||||
row[jidx++] = im->red[idx];
|
||||
row[jidx++] = im->green[idx];
|
||||
row[jidx++] = im->blue[idx];
|
||||
#elif BITS_IN_JSAMPLE == 12
|
||||
row[jidx++] = im->red[idx] << 4;
|
||||
row[jidx++] = im->green[idx] << 4;
|
||||
row[jidx++] = im->blue[idx] << 4;
|
||||
#else
|
||||
#error IJG JPEG library BITS_IN_JSAMPLE value must be 8 or 12
|
||||
#endif
|
||||
}
|
||||
|
||||
nlines = jpeg_write_scanlines (&cinfo, rowptr, 1);
|
||||
if (nlines != 1)
|
||||
fprintf (stderr, "gd_jpeg: warning: jpeg_write_scanlines"
|
||||
" returns %u -- expected 1\n", nlines);
|
||||
}
|
||||
}
|
||||
jpeg_finish_compress (&cinfo);
|
||||
jpeg_destroy_compress (&cinfo);
|
||||
gdFree (row);
|
||||
}
|
||||
|
||||
gdImagePtr
|
||||
gdImageCreateFromJpeg (FILE * inFile)
|
||||
{
|
||||
gdImagePtr im;
|
||||
gdIOCtx *in = gdNewFileCtx (inFile);
|
||||
im = gdImageCreateFromJpegCtx (in);
|
||||
in->gd_free (in);
|
||||
return im;
|
||||
}
|
||||
|
||||
void jpeg_gdIOCtx_src (j_decompress_ptr cinfo, gdIOCtx * infile);
|
||||
|
||||
/*
|
||||
* Create a gd-format image from the JPEG-format INFILE. Returns the
|
||||
* image, or NULL upon error.
|
||||
*/
|
||||
gdImagePtr
|
||||
gdImageCreateFromJpegCtx (gdIOCtx * infile)
|
||||
{
|
||||
struct jpeg_decompress_struct cinfo;
|
||||
struct jpeg_error_mgr jerr;
|
||||
jmpbuf_wrapper jmpbufw;
|
||||
/* volatile so we can gdFree them after longjmp */
|
||||
volatile JSAMPROW row = 0;
|
||||
volatile gdImagePtr im = 0;
|
||||
JSAMPROW rowptr[1];
|
||||
int i, j, retval;
|
||||
JDIMENSION nrows;
|
||||
|
||||
#ifdef JPEG_DEBUG
|
||||
printf ("gd-jpeg: gd JPEG version %s\n", GD_JPEG_VERSION);
|
||||
printf ("gd-jpeg: JPEG library version %d, %d-bit sample values\n",
|
||||
JPEG_LIB_VERSION, BITS_IN_JSAMPLE);
|
||||
#endif
|
||||
|
||||
memset (&cinfo, 0, sizeof (cinfo));
|
||||
memset (&jerr, 0, sizeof (jerr));
|
||||
|
||||
cinfo.err = jpeg_std_error (&jerr);
|
||||
cinfo.client_data = &jmpbufw;
|
||||
if (setjmp (jmpbufw.jmpbuf) != 0)
|
||||
{
|
||||
/* we're here courtesy of longjmp */
|
||||
if (row)
|
||||
gdFree (row);
|
||||
if (im)
|
||||
gdImageDestroy (im);
|
||||
return 0;
|
||||
}
|
||||
|
||||
cinfo.err->error_exit = fatal_jpeg_error;
|
||||
|
||||
jpeg_create_decompress (&cinfo);
|
||||
|
||||
jpeg_gdIOCtx_src (&cinfo, infile);
|
||||
|
||||
retval = jpeg_read_header (&cinfo, TRUE);
|
||||
if (retval != JPEG_HEADER_OK)
|
||||
fprintf (stderr, "gd-jpeg: warning: jpeg_read_header returns"
|
||||
" %d, expected %d\n", retval, JPEG_HEADER_OK);
|
||||
|
||||
if (cinfo.image_height > INT_MAX)
|
||||
fprintf (stderr, "gd-jpeg: warning: JPEG image height (%u) is"
|
||||
" greater than INT_MAX (%d) (and thus greater than"
|
||||
" gd can handle)", cinfo.image_height, INT_MAX);
|
||||
|
||||
if (cinfo.image_width > INT_MAX)
|
||||
fprintf (stderr, "gd-jpeg: warning: JPEG image width (%u) is"
|
||||
" greater than INT_MAX (%d) (and thus greater than"
|
||||
" gd can handle)\n", cinfo.image_width, INT_MAX);
|
||||
|
||||
im = gdImageCreateTrueColor ((int) cinfo.image_width,
|
||||
(int) cinfo.image_height);
|
||||
if (im == 0)
|
||||
{
|
||||
fprintf (stderr, "gd-jpeg error: cannot allocate gdImage" " struct\n");
|
||||
goto error;
|
||||
}
|
||||
|
||||
/*
|
||||
* Force the image into RGB colorspace, but don't
|
||||
* reduce the number of colors anymore (GD 2.0)
|
||||
*/
|
||||
cinfo.out_color_space = JCS_RGB;
|
||||
|
||||
if (jpeg_start_decompress (&cinfo) != TRUE)
|
||||
fprintf (stderr, "gd-jpeg: warning: jpeg_start_decompress"
|
||||
" reports suspended data source\n");
|
||||
|
||||
#ifdef JPEG_DEBUG
|
||||
printf ("gd-jpeg: JPEG image information:");
|
||||
if (cinfo.saw_JFIF_marker)
|
||||
printf (" JFIF version %d.%.2d",
|
||||
(int) cinfo.JFIF_major_version, (int) cinfo.JFIF_minor_version);
|
||||
else if (cinfo.saw_Adobe_marker)
|
||||
printf (" Adobe format");
|
||||
else
|
||||
printf (" UNKNOWN format");
|
||||
|
||||
printf (" %ux%u (raw) / %ux%u (scaled) %d-bit", cinfo.image_width,
|
||||
cinfo.image_height, cinfo.output_width,
|
||||
cinfo.output_height, cinfo.data_precision);
|
||||
printf (" %s", (cinfo.progressive_mode ? "progressive" : "baseline"));
|
||||
printf (" image, %d quantized colors, ", cinfo.actual_number_of_colors);
|
||||
|
||||
switch (cinfo.jpeg_color_space)
|
||||
{
|
||||
case JCS_GRAYSCALE:
|
||||
printf ("grayscale");
|
||||
break;
|
||||
|
||||
case JCS_RGB:
|
||||
printf ("RGB");
|
||||
break;
|
||||
|
||||
case JCS_YCbCr:
|
||||
printf ("YCbCr (a.k.a. YUV)");
|
||||
break;
|
||||
|
||||
case JCS_CMYK:
|
||||
printf ("CMYK");
|
||||
break;
|
||||
|
||||
case JCS_YCCK:
|
||||
printf ("YCbCrK");
|
||||
break;
|
||||
|
||||
default:
|
||||
printf ("UNKNOWN (value: %d)", (int) cinfo.jpeg_color_space);
|
||||
break;
|
||||
}
|
||||
printf (" colorspace\n");
|
||||
fflush (stdout);
|
||||
#endif /* JPEG_DEBUG */
|
||||
|
||||
/* REMOVED by TBB 2/12/01. This field of the structure is
|
||||
documented as private, and sure enough it's gone in the
|
||||
latest libjpeg, replaced by something else. Unfortunately
|
||||
there is still no right way to find out if the file was
|
||||
progressive or not; just declare your intent before you
|
||||
write one by calling gdImageInterlace(im, 1) yourself.
|
||||
After all, we're not really supposed to rework JPEGs and
|
||||
write them out again anyway. Lossy compression, remember? */
|
||||
#if 0
|
||||
gdImageInterlace (im, cinfo.progressive_mode != 0);
|
||||
#endif
|
||||
if (cinfo.output_components != 3)
|
||||
{
|
||||
fprintf (stderr, "gd-jpeg: error: JPEG color quantization"
|
||||
" request resulted in output_components == %d"
|
||||
" (expected 3)\n", cinfo.output_components);
|
||||
goto error;
|
||||
}
|
||||
|
||||
#if BITS_IN_JSAMPLE == 12
|
||||
fprintf (stderr, "gd-jpeg: error: jpeg library was compiled for 12-bit\n"
|
||||
"precision. This is mostly useless, because JPEGs on the web are\n"
|
||||
"8-bit and such versions of the jpeg library won't read or write\n"
|
||||
"them. GD doesn't support these unusual images. Edit your\n"
|
||||
"jmorecfg.h file to specify the correct precision and completely\n"
|
||||
"'make clean' and 'make install' libjpeg again. Sorry.\n");
|
||||
goto error;
|
||||
#endif /* BITS_IN_JSAMPLE == 12 */
|
||||
|
||||
row = gdCalloc (cinfo.output_width * 3, sizeof (JSAMPLE));
|
||||
if (row == 0)
|
||||
{
|
||||
fprintf (stderr, "gd-jpeg: error: unable to allocate row for"
|
||||
" JPEG scanline: gdCalloc returns NULL\n");
|
||||
goto error;
|
||||
}
|
||||
rowptr[0] = row;
|
||||
|
||||
for (i = 0; i < cinfo.output_height; i++)
|
||||
{
|
||||
register JSAMPROW currow = row;
|
||||
register int *tpix = im->tpixels[i];
|
||||
nrows = jpeg_read_scanlines (&cinfo, rowptr, 1);
|
||||
if (nrows != 1)
|
||||
{
|
||||
fprintf (stderr, "gd-jpeg: error: jpeg_read_scanlines"
|
||||
" returns %u, expected 1\n", nrows);
|
||||
goto error;
|
||||
}
|
||||
for (j = 0; j < cinfo.output_width; j++, currow += 3, tpix++)
|
||||
{
|
||||
*tpix = gdTrueColor (currow[0], currow[1], currow[2]);
|
||||
}
|
||||
}
|
||||
|
||||
if (jpeg_finish_decompress (&cinfo) != TRUE)
|
||||
fprintf (stderr, "gd-jpeg: warning: jpeg_finish_decompress"
|
||||
" reports suspended data source\n");
|
||||
|
||||
|
||||
jpeg_destroy_decompress (&cinfo);
|
||||
gdFree (row);
|
||||
return im;
|
||||
|
||||
error:
|
||||
jpeg_destroy_decompress (&cinfo);
|
||||
if (row)
|
||||
gdFree (row);
|
||||
if (im)
|
||||
gdImageDestroy (im);
|
||||
return 0;
|
||||
}
|
||||
|
||||
/*
|
||||
|
||||
* gdIOCtx JPEG data sources and sinks, T. Boutell
|
||||
* almost a simple global replace from T. Lane's stdio versions.
|
||||
*
|
||||
*/
|
||||
|
||||
/* Different versions of libjpeg use either 'jboolean' or 'boolean', and
|
||||
some platforms define 'boolean', and so forth. Deal with this
|
||||
madness by typedeffing 'safeboolean' to 'boolean' if HAVE_BOOLEAN
|
||||
is already set, because this is the test that libjpeg uses.
|
||||
Otherwise, typedef it to int, because that's what libjpeg does
|
||||
if HAVE_BOOLEAN is not defined. -TBB */
|
||||
|
||||
#ifdef HAVE_BOOLEAN
|
||||
typedef boolean safeboolean;
|
||||
#else
|
||||
typedef int safeboolean;
|
||||
#endif /* HAVE_BOOLEAN */
|
||||
|
||||
/* Expanded data source object for gdIOCtx input */
|
||||
|
||||
typedef struct
|
||||
{
|
||||
struct jpeg_source_mgr pub; /* public fields */
|
||||
|
||||
gdIOCtx *infile; /* source stream */
|
||||
unsigned char *buffer; /* start of buffer */
|
||||
safeboolean start_of_file; /* have we gotten any data yet? */
|
||||
|
||||
}
|
||||
my_source_mgr;
|
||||
|
||||
typedef my_source_mgr *my_src_ptr;
|
||||
|
||||
#define INPUT_BUF_SIZE 4096 /* choose an efficiently fread'able size */
|
||||
|
||||
/*
|
||||
* Initialize source --- called by jpeg_read_header
|
||||
* before any data is actually read.
|
||||
*/
|
||||
|
||||
void
|
||||
init_source (j_decompress_ptr cinfo)
|
||||
{
|
||||
my_src_ptr src = (my_src_ptr) cinfo->src;
|
||||
|
||||
/* We reset the empty-input-file flag for each image,
|
||||
* but we don't clear the input buffer.
|
||||
* This is correct behavior for reading a series of images from one source.
|
||||
*/
|
||||
src->start_of_file = TRUE;
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
* Fill the input buffer --- called whenever buffer is emptied.
|
||||
*
|
||||
* In typical applications, this should read fresh data into the buffer
|
||||
* (ignoring the current state of next_input_byte & bytes_in_buffer),
|
||||
* reset the pointer & count to the start of the buffer, and return TRUE
|
||||
* indicating that the buffer has been reloaded. It is not necessary to
|
||||
* fill the buffer entirely, only to obtain at least one more byte.
|
||||
*
|
||||
* There is no such thing as an EOF return. If the end of the file has been
|
||||
* reached, the routine has a choice of ERREXIT() or inserting fake data into
|
||||
* the buffer. In most cases, generating a warning message and inserting a
|
||||
* fake EOI marker is the best course of action --- this will allow the
|
||||
* decompressor to output however much of the image is there. However,
|
||||
* the resulting error message is misleading if the real problem is an empty
|
||||
* input file, so we handle that case specially.
|
||||
*
|
||||
* In applications that need to be able to suspend compression due to input
|
||||
* not being available yet, a FALSE return indicates that no more data can be
|
||||
* obtained right now, but more may be forthcoming later. In this situation,
|
||||
* the decompressor will return to its caller (with an indication of the
|
||||
* number of scanlines it has read, if any). The application should resume
|
||||
* decompression after it has loaded more data into the input buffer. Note
|
||||
* that there are substantial restrictions on the use of suspension --- see
|
||||
* the documentation.
|
||||
*
|
||||
* When suspending, the decompressor will back up to a convenient restart point
|
||||
* (typically the start of the current MCU). next_input_byte & bytes_in_buffer
|
||||
* indicate where the restart point will be if the current call returns FALSE.
|
||||
* Data beyond this point must be rescanned after resumption, so move it to
|
||||
* the front of the buffer rather than discarding it.
|
||||
*/
|
||||
|
||||
#define END_JPEG_SEQUENCE "\r\n[*]--:END JPEG:--[*]\r\n"
|
||||
safeboolean
|
||||
fill_input_buffer (j_decompress_ptr cinfo)
|
||||
{
|
||||
my_src_ptr src = (my_src_ptr) cinfo->src;
|
||||
/* 2.0.12: signed size. Thanks to Geert Jansen */
|
||||
/* 2.0.14: some platforms (mingw-msys) don't have ssize_t. Call
|
||||
an int an int. */
|
||||
int nbytes = 0;
|
||||
memset (src->buffer, 0, INPUT_BUF_SIZE);
|
||||
|
||||
while (nbytes < INPUT_BUF_SIZE)
|
||||
{
|
||||
|
||||
int got = gdGetBuf (src->buffer + nbytes,
|
||||
INPUT_BUF_SIZE - nbytes,
|
||||
src->infile);
|
||||
|
||||
if ((got == EOF) || (got == 0))
|
||||
{
|
||||
|
||||
/* EOF or error. If we got any data, don't worry about it.
|
||||
If we didn't, then this is unexpected. */
|
||||
if (!nbytes)
|
||||
{
|
||||
|
||||
nbytes = -1;
|
||||
|
||||
}
|
||||
|
||||
break;
|
||||
|
||||
}
|
||||
|
||||
nbytes += got;
|
||||
|
||||
}
|
||||
|
||||
if (nbytes <= 0)
|
||||
{
|
||||
if (src->start_of_file) /* Treat empty input file as fatal error */
|
||||
ERREXIT (cinfo, JERR_INPUT_EMPTY);
|
||||
WARNMS (cinfo, JWRN_JPEG_EOF);
|
||||
/* Insert a fake EOI marker */
|
||||
src->buffer[0] = (unsigned char) 0xFF;
|
||||
src->buffer[1] = (unsigned char) JPEG_EOI;
|
||||
nbytes = 2;
|
||||
}
|
||||
|
||||
src->pub.next_input_byte = src->buffer;
|
||||
src->pub.bytes_in_buffer = nbytes;
|
||||
src->start_of_file = FALSE;
|
||||
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
* Skip data --- used to skip over a potentially large amount of
|
||||
* uninteresting data (such as an APPn marker).
|
||||
*
|
||||
* Writers of suspendable-input applications must note that skip_input_data
|
||||
* is not granted the right to give a suspension return. If the skip extends
|
||||
* beyond the data currently in the buffer, the buffer can be marked empty so
|
||||
* that the next read will cause a fill_input_buffer call that can suspend.
|
||||
* Arranging for additional bytes to be discarded before reloading the input
|
||||
* buffer is the application writer's problem.
|
||||
*/
|
||||
|
||||
void
|
||||
skip_input_data (j_decompress_ptr cinfo, long num_bytes)
|
||||
{
|
||||
my_src_ptr src = (my_src_ptr) cinfo->src;
|
||||
|
||||
/* Just a dumb implementation for now. Not clear that being smart is worth
|
||||
* any trouble anyway --- large skips are infrequent.
|
||||
*/
|
||||
if (num_bytes > 0)
|
||||
{
|
||||
while (num_bytes > (long) src->pub.bytes_in_buffer)
|
||||
{
|
||||
num_bytes -= (long) src->pub.bytes_in_buffer;
|
||||
(void) fill_input_buffer (cinfo);
|
||||
/* note we assume that fill_input_buffer will never return FALSE,
|
||||
* so suspension need not be handled.
|
||||
*/
|
||||
}
|
||||
src->pub.next_input_byte += (size_t) num_bytes;
|
||||
src->pub.bytes_in_buffer -= (size_t) num_bytes;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
* An additional method that can be provided by data source modules is the
|
||||
* resync_to_restart method for error recovery in the presence of RST markers.
|
||||
* For the moment, this source module just uses the default resync method
|
||||
* provided by the JPEG library. That method assumes that no backtracking
|
||||
* is possible.
|
||||
*/
|
||||
|
||||
|
||||
/*
|
||||
* Terminate source --- called by jpeg_finish_decompress
|
||||
* after all data has been read. Often a no-op.
|
||||
*
|
||||
* NB: *not* called by jpeg_abort or jpeg_destroy; surrounding
|
||||
* application must deal with any cleanup that should happen even
|
||||
* for error exit.
|
||||
*/
|
||||
|
||||
void
|
||||
term_source (j_decompress_ptr cinfo)
|
||||
{
|
||||
|
||||
#if 0
|
||||
/* never used */
|
||||
my_src_ptr src = (my_src_ptr) cinfo->src;
|
||||
|
||||
#endif
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
* Prepare for input from a gdIOCtx stream.
|
||||
* The caller must have already opened the stream, and is responsible
|
||||
* for closing it after finishing decompression.
|
||||
*/
|
||||
|
||||
void
|
||||
jpeg_gdIOCtx_src (j_decompress_ptr cinfo, gdIOCtx * infile)
|
||||
{
|
||||
my_src_ptr src;
|
||||
|
||||
/* The source object and input buffer are made permanent so that a series
|
||||
* of JPEG images can be read from the same file by calling jpeg_gdIOCtx_src
|
||||
* only before the first one. (If we discarded the buffer at the end of
|
||||
* one image, we'd likely lose the start of the next one.)
|
||||
* This makes it unsafe to use this manager and a different source
|
||||
* manager serially with the same JPEG object. Caveat programmer.
|
||||
*/
|
||||
if (cinfo->src == NULL)
|
||||
{ /* first time for this JPEG object? */
|
||||
cinfo->src = (struct jpeg_source_mgr *)
|
||||
(*cinfo->mem->alloc_small) ((j_common_ptr) cinfo, JPOOL_PERMANENT,
|
||||
sizeof (my_source_mgr));
|
||||
src = (my_src_ptr) cinfo->src;
|
||||
src->buffer = (unsigned char *)
|
||||
(*cinfo->mem->alloc_small) ((j_common_ptr) cinfo, JPOOL_PERMANENT,
|
||||
INPUT_BUF_SIZE * sizeof (unsigned char));
|
||||
|
||||
}
|
||||
|
||||
src = (my_src_ptr) cinfo->src;
|
||||
src->pub.init_source = init_source;
|
||||
src->pub.fill_input_buffer = fill_input_buffer;
|
||||
src->pub.skip_input_data = skip_input_data;
|
||||
src->pub.resync_to_restart = jpeg_resync_to_restart; /* use default method */
|
||||
src->pub.term_source = term_source;
|
||||
src->infile = infile;
|
||||
src->pub.bytes_in_buffer = 0; /* forces fill_input_buffer on first read */
|
||||
src->pub.next_input_byte = NULL; /* until buffer loaded */
|
||||
}
|
||||
|
||||
/* Expanded data destination object for stdio output */
|
||||
|
||||
typedef struct
|
||||
{
|
||||
struct jpeg_destination_mgr pub; /* public fields */
|
||||
gdIOCtx *outfile; /* target stream */
|
||||
unsigned char *buffer; /* start of buffer */
|
||||
}
|
||||
my_destination_mgr;
|
||||
|
||||
typedef my_destination_mgr *my_dest_ptr;
|
||||
|
||||
#define OUTPUT_BUF_SIZE 4096 /* choose an efficiently fwrite'able size */
|
||||
|
||||
/*
|
||||
* Initialize destination --- called by jpeg_start_compress
|
||||
* before any data is actually written.
|
||||
*/
|
||||
|
||||
void
|
||||
init_destination (j_compress_ptr cinfo)
|
||||
{
|
||||
my_dest_ptr dest = (my_dest_ptr) cinfo->dest;
|
||||
|
||||
/* Allocate the output buffer --- it will be released when done with image */
|
||||
dest->buffer = (unsigned char *)
|
||||
(*cinfo->mem->alloc_small) ((j_common_ptr) cinfo, JPOOL_IMAGE,
|
||||
OUTPUT_BUF_SIZE * sizeof (unsigned char));
|
||||
|
||||
dest->pub.next_output_byte = dest->buffer;
|
||||
dest->pub.free_in_buffer = OUTPUT_BUF_SIZE;
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
* Empty the output buffer --- called whenever buffer fills up.
|
||||
*
|
||||
* In typical applications, this should write the entire output buffer
|
||||
* (ignoring the current state of next_output_byte & free_in_buffer),
|
||||
* reset the pointer & count to the start of the buffer, and return TRUE
|
||||
* indicating that the buffer has been dumped.
|
||||
*
|
||||
* In applications that need to be able to suspend compression due to output
|
||||
* overrun, a FALSE return indicates that the buffer cannot be emptied now.
|
||||
* In this situation, the compressor will return to its caller (possibly with
|
||||
* an indication that it has not accepted all the supplied scanlines). The
|
||||
* application should resume compression after it has made more room in the
|
||||
* output buffer. Note that there are substantial restrictions on the use of
|
||||
* suspension --- see the documentation.
|
||||
*
|
||||
* When suspending, the compressor will back up to a convenient restart point
|
||||
* (typically the start of the current MCU). next_output_byte & free_in_buffer
|
||||
* indicate where the restart point will be if the current call returns FALSE.
|
||||
* Data beyond this point will be regenerated after resumption, so do not
|
||||
* write it out when emptying the buffer externally.
|
||||
*/
|
||||
|
||||
safeboolean
|
||||
empty_output_buffer (j_compress_ptr cinfo)
|
||||
{
|
||||
my_dest_ptr dest = (my_dest_ptr) cinfo->dest;
|
||||
|
||||
if (gdPutBuf (dest->buffer, OUTPUT_BUF_SIZE, dest->outfile) !=
|
||||
(size_t) OUTPUT_BUF_SIZE)
|
||||
ERREXIT (cinfo, JERR_FILE_WRITE);
|
||||
|
||||
dest->pub.next_output_byte = dest->buffer;
|
||||
dest->pub.free_in_buffer = OUTPUT_BUF_SIZE;
|
||||
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
* Terminate destination --- called by jpeg_finish_compress
|
||||
* after all data has been written. Usually needs to flush buffer.
|
||||
*
|
||||
* NB: *not* called by jpeg_abort or jpeg_destroy; surrounding
|
||||
* application must deal with any cleanup that should happen even
|
||||
* for error exit.
|
||||
*/
|
||||
|
||||
void
|
||||
term_destination (j_compress_ptr cinfo)
|
||||
{
|
||||
my_dest_ptr dest = (my_dest_ptr) cinfo->dest;
|
||||
size_t datacount = OUTPUT_BUF_SIZE - dest->pub.free_in_buffer;
|
||||
|
||||
/* Write any data remaining in the buffer */
|
||||
if (datacount > 0)
|
||||
{
|
||||
if (gdPutBuf (dest->buffer, datacount, dest->outfile) != datacount)
|
||||
ERREXIT (cinfo, JERR_FILE_WRITE);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
* Prepare for output to a stdio stream.
|
||||
* The caller must have already opened the stream, and is responsible
|
||||
* for closing it after finishing compression.
|
||||
*/
|
||||
|
||||
void
|
||||
jpeg_gdIOCtx_dest (j_compress_ptr cinfo, gdIOCtx * outfile)
|
||||
{
|
||||
my_dest_ptr dest;
|
||||
|
||||
/* The destination object is made permanent so that multiple JPEG images
|
||||
* can be written to the same file without re-executing jpeg_stdio_dest.
|
||||
* This makes it dangerous to use this manager and a different destination
|
||||
* manager serially with the same JPEG object, because their private object
|
||||
* sizes may be different. Caveat programmer.
|
||||
*/
|
||||
if (cinfo->dest == NULL)
|
||||
{ /* first time for this JPEG object? */
|
||||
cinfo->dest = (struct jpeg_destination_mgr *)
|
||||
(*cinfo->mem->alloc_small) ((j_common_ptr) cinfo, JPOOL_PERMANENT,
|
||||
sizeof (my_destination_mgr));
|
||||
}
|
||||
|
||||
dest = (my_dest_ptr) cinfo->dest;
|
||||
dest->pub.init_destination = init_destination;
|
||||
dest->pub.empty_output_buffer = empty_output_buffer;
|
||||
dest->pub.term_destination = term_destination;
|
||||
dest->outfile = outfile;
|
||||
}
|
||||
|
||||
#endif /* HAVE_LIBJPEG */
|
|
@ -1,792 +0,0 @@
|
|||
|
||||
#ifdef HAVE_CONFIG_H
|
||||
#include "config.h"
|
||||
#endif
|
||||
|
||||
#include <stdio.h>
|
||||
#include <math.h>
|
||||
#include <string.h>
|
||||
#include <stdlib.h>
|
||||
#include "gd.h"
|
||||
|
||||
/* JCE: Arrange HAVE_LIBPNG so that it can be set in gd.h */
|
||||
#ifdef HAVE_LIBPNG
|
||||
|
||||
#include "gdhelpers.h"
|
||||
#include "png.h" /* includes zlib.h and setjmp.h */
|
||||
|
||||
#define TRUE 1
|
||||
#define FALSE 0
|
||||
|
||||
/*---------------------------------------------------------------------------
|
||||
|
||||
gd_png.c Copyright 1999 Greg Roelofs and Thomas Boutell
|
||||
|
||||
The routines in this file, gdImagePng*() and gdImageCreateFromPng*(),
|
||||
are drop-in replacements for gdImageGif*() and gdImageCreateFromGif*(),
|
||||
except that these functions are noisier in the case of errors (comment
|
||||
out all fprintf() statements to disable that).
|
||||
|
||||
GD 2.0 supports RGBA truecolor and will read and write truecolor PNGs.
|
||||
GD 2.0 supports 8 bits of color resolution per channel and
|
||||
7 bits of alpha channel resolution. Images with more than 8 bits
|
||||
per channel are reduced to 8 bits. Images with an alpha channel are
|
||||
only able to resolve down to '1/128th opaque' instead of '1/256th',
|
||||
and this conversion is also automatic. I very much doubt you can see it.
|
||||
Both tRNS and true alpha are supported.
|
||||
|
||||
Gamma is ignored, and there is no support for text annotations.
|
||||
|
||||
Last updated: 9 February 2001
|
||||
|
||||
---------------------------------------------------------------------------*/
|
||||
|
||||
#ifndef PNG_SETJMP_NOT_SUPPORTED
|
||||
typedef struct _jmpbuf_wrapper
|
||||
{
|
||||
jmp_buf jmpbuf;
|
||||
}
|
||||
jmpbuf_wrapper;
|
||||
|
||||
static jmpbuf_wrapper gdPngJmpbufStruct;
|
||||
|
||||
static void
|
||||
gdPngErrorHandler (png_structp png_ptr, png_const_charp msg)
|
||||
{
|
||||
jmpbuf_wrapper *jmpbuf_ptr;
|
||||
|
||||
/* This function, aside from the extra step of retrieving the "error
|
||||
* pointer" (below) and the fact that it exists within the application
|
||||
* rather than within libpng, is essentially identical to libpng's
|
||||
* default error handler. The second point is critical: since both
|
||||
* setjmp() and longjmp() are called from the same code, they are
|
||||
* guaranteed to have compatible notions of how big a jmp_buf is,
|
||||
* regardless of whether _BSD_SOURCE or anything else has (or has not)
|
||||
* been defined. */
|
||||
|
||||
fprintf (stderr, "gd-png: fatal libpng error: %s\n", msg);
|
||||
fflush (stderr);
|
||||
|
||||
jmpbuf_ptr = png_get_error_ptr (png_ptr);
|
||||
if (jmpbuf_ptr == NULL)
|
||||
{ /* we are completely hosed now */
|
||||
fprintf (stderr,
|
||||
"gd-png: EXTREMELY fatal error: jmpbuf unrecoverable; terminating.\n");
|
||||
fflush (stderr);
|
||||
exit (99);
|
||||
}
|
||||
|
||||
longjmp (jmpbuf_ptr->jmpbuf, 1);
|
||||
}
|
||||
#endif
|
||||
|
||||
static void
|
||||
gdPngReadData (png_structp png_ptr, png_bytep data, png_size_t length)
|
||||
{
|
||||
gdGetBuf (data, length, (gdIOCtx *) png_get_io_ptr (png_ptr));
|
||||
}
|
||||
|
||||
static void
|
||||
gdPngWriteData (png_structp png_ptr, png_bytep data, png_size_t length)
|
||||
{
|
||||
gdPutBuf (data, length, (gdIOCtx *) png_get_io_ptr (png_ptr));
|
||||
}
|
||||
|
||||
static void
|
||||
gdPngFlushData (png_structp png_ptr)
|
||||
{
|
||||
}
|
||||
|
||||
gdImagePtr
|
||||
gdImageCreateFromPng (FILE * inFile)
|
||||
{
|
||||
gdImagePtr im;
|
||||
gdIOCtx *in = gdNewFileCtx (inFile);
|
||||
im = gdImageCreateFromPngCtx (in);
|
||||
in->gd_free (in);
|
||||
return im;
|
||||
}
|
||||
|
||||
|
||||
/* This routine is based in part on the Chapter 13 demo code in "PNG: The
|
||||
* Definitive Guide" (http://www.cdrom.com/pub/png/pngbook.html).
|
||||
*/
|
||||
gdImagePtr
|
||||
gdImageCreateFromPngCtx (gdIOCtx * infile)
|
||||
{
|
||||
png_byte sig[8];
|
||||
png_structp png_ptr;
|
||||
png_infop info_ptr;
|
||||
png_uint_32 width, height, rowbytes;
|
||||
int bit_depth, color_type, interlace_type;
|
||||
int num_palette, num_trans;
|
||||
png_colorp palette;
|
||||
png_color_16p trans_gray_rgb;
|
||||
png_color_16p trans_color_rgb;
|
||||
png_bytep trans;
|
||||
png_bytep image_data = NULL;
|
||||
png_bytepp row_pointers = NULL;
|
||||
gdImagePtr im = NULL;
|
||||
int i, j, *open = NULL;
|
||||
volatile int transparent = -1;
|
||||
volatile int palette_allocated = FALSE;
|
||||
|
||||
/* Make sure the signature can't match by dumb luck -- TBB */
|
||||
/* GRR: isn't sizeof(infile) equal to the size of the pointer? */
|
||||
memset (infile, 0, sizeof (infile));
|
||||
|
||||
/* first do a quick check that the file really is a PNG image; could
|
||||
* have used slightly more general png_sig_cmp() function instead */
|
||||
gdGetBuf (sig, 8, infile);
|
||||
if (!png_check_sig (sig, 8))
|
||||
return NULL; /* bad signature */
|
||||
|
||||
#ifndef PNG_SETJMP_NOT_SUPPORTED
|
||||
png_ptr = png_create_read_struct (PNG_LIBPNG_VER_STRING, &gdPngJmpbufStruct,
|
||||
gdPngErrorHandler, NULL);
|
||||
#else
|
||||
png_ptr = png_create_read_struct (PNG_LIBPNG_VER_STRING, NULL, NULL, NULL);
|
||||
#endif
|
||||
if (png_ptr == NULL)
|
||||
{
|
||||
fprintf (stderr, "gd-png error: cannot allocate libpng main struct\n");
|
||||
return NULL;
|
||||
}
|
||||
|
||||
info_ptr = png_create_info_struct (png_ptr);
|
||||
if (info_ptr == NULL)
|
||||
{
|
||||
fprintf (stderr, "gd-png error: cannot allocate libpng info struct\n");
|
||||
png_destroy_read_struct (&png_ptr, NULL, NULL);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
/* we could create a second info struct here (end_info), but it's only
|
||||
* useful if we want to keep pre- and post-IDAT chunk info separated
|
||||
* (mainly for PNG-aware image editors and converters) */
|
||||
|
||||
/* setjmp() must be called in every non-callback function that calls a
|
||||
* PNG-reading libpng function */
|
||||
#ifndef PNG_SETJMP_NOT_SUPPORTED
|
||||
if (setjmp (gdPngJmpbufStruct.jmpbuf))
|
||||
{
|
||||
fprintf (stderr, "gd-png error: setjmp returns error condition\n");
|
||||
png_destroy_read_struct (&png_ptr, &info_ptr, NULL);
|
||||
return NULL;
|
||||
}
|
||||
#endif
|
||||
|
||||
png_set_sig_bytes (png_ptr, 8); /* we already read the 8 signature bytes */
|
||||
|
||||
png_set_read_fn (png_ptr, (void *) infile, gdPngReadData);
|
||||
png_read_info (png_ptr, info_ptr); /* read all PNG info up to image data */
|
||||
|
||||
png_get_IHDR (png_ptr, info_ptr, &width, &height, &bit_depth, &color_type,
|
||||
&interlace_type, NULL, NULL);
|
||||
if ((color_type == PNG_COLOR_TYPE_RGB) ||
|
||||
(color_type == PNG_COLOR_TYPE_RGB_ALPHA))
|
||||
{
|
||||
im = gdImageCreateTrueColor ((int) width, (int) height);
|
||||
}
|
||||
else
|
||||
{
|
||||
im = gdImageCreate ((int) width, (int) height);
|
||||
}
|
||||
if (im == NULL)
|
||||
{
|
||||
fprintf (stderr, "gd-png error: cannot allocate gdImage struct\n");
|
||||
png_destroy_read_struct (&png_ptr, &info_ptr, NULL);
|
||||
gdFree (image_data);
|
||||
gdFree (row_pointers);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
if (bit_depth == 16)
|
||||
png_set_strip_16 (png_ptr);
|
||||
else if (bit_depth < 8)
|
||||
png_set_packing (png_ptr); /* expand to 1 byte per pixel */
|
||||
switch (color_type)
|
||||
{
|
||||
case PNG_COLOR_TYPE_PALETTE:
|
||||
png_get_PLTE (png_ptr, info_ptr, &palette, &num_palette);
|
||||
#ifdef DEBUG
|
||||
fprintf (stderr, "gd-png color_type is palette, colors: %d\n",
|
||||
num_palette);
|
||||
#endif /* DEBUG */
|
||||
if (png_get_valid (png_ptr, info_ptr, PNG_INFO_tRNS))
|
||||
{
|
||||
/* gd 2.0: we support this rather thoroughly now. Grab the
|
||||
first fully transparent entry, if any, as the value of
|
||||
the simple-transparency index, mostly for backwards
|
||||
binary compatibility. The alpha channel is where it's
|
||||
really at these days. */
|
||||
int firstZero = 1;
|
||||
png_get_tRNS (png_ptr, info_ptr, &trans, &num_trans, NULL);
|
||||
for (i = 0; i < num_trans; ++i)
|
||||
{
|
||||
im->alpha[i] = gdAlphaMax - (trans[i] >> 1);
|
||||
if ((trans[i] == 0) && (firstZero))
|
||||
{
|
||||
/* 2.0.5: long-forgotten patch from Wez Furlong */
|
||||
transparent = i;
|
||||
firstZero = 0;
|
||||
}
|
||||
}
|
||||
}
|
||||
break;
|
||||
|
||||
case PNG_COLOR_TYPE_GRAY:
|
||||
case PNG_COLOR_TYPE_GRAY_ALPHA:
|
||||
/* create a fake palette and check for single-shade transparency */
|
||||
if ((palette =
|
||||
(png_colorp) gdMalloc (256 * sizeof (png_color))) == NULL)
|
||||
{
|
||||
fprintf (stderr, "gd-png error: cannot allocate gray palette\n");
|
||||
png_destroy_read_struct (&png_ptr, &info_ptr, NULL);
|
||||
return NULL;
|
||||
}
|
||||
palette_allocated = TRUE;
|
||||
if (bit_depth < 8)
|
||||
{
|
||||
num_palette = 1 << bit_depth;
|
||||
for (i = 0; i < 256; ++i)
|
||||
{
|
||||
j = (255 * i) / (num_palette - 1);
|
||||
palette[i].red = palette[i].green = palette[i].blue = j;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
num_palette = 256;
|
||||
for (i = 0; i < 256; ++i)
|
||||
{
|
||||
palette[i].red = palette[i].green = palette[i].blue = i;
|
||||
}
|
||||
}
|
||||
if (png_get_valid (png_ptr, info_ptr, PNG_INFO_tRNS))
|
||||
{
|
||||
png_get_tRNS (png_ptr, info_ptr, NULL, NULL, &trans_gray_rgb);
|
||||
if (bit_depth == 16) /* png_set_strip_16() not yet in effect */
|
||||
transparent = trans_gray_rgb->gray >> 8;
|
||||
else
|
||||
transparent = trans_gray_rgb->gray;
|
||||
/* Note slight error in 16-bit case: up to 256 16-bit shades
|
||||
* may get mapped to a single 8-bit shade, and only one of them
|
||||
* is supposed to be transparent. IOW, both opaque pixels and
|
||||
* transparent pixels will be mapped into the transparent entry.
|
||||
* There is no particularly good way around this in the case
|
||||
* that all 256 8-bit shades are used, but one could write some
|
||||
* custom 16-bit code to handle the case where there are gdFree
|
||||
* palette entries. This error will be extremely rare in
|
||||
* general, though. (Quite possibly there is only one such
|
||||
* image in existence.) */
|
||||
}
|
||||
break;
|
||||
|
||||
case PNG_COLOR_TYPE_RGB:
|
||||
case PNG_COLOR_TYPE_RGB_ALPHA:
|
||||
/* gd 2.0: we now support truecolor. See the comment above
|
||||
for a rare situation in which the transparent pixel may not
|
||||
work properly with 16-bit channels. */
|
||||
if (png_get_valid (png_ptr, info_ptr, PNG_INFO_tRNS))
|
||||
{
|
||||
png_get_tRNS (png_ptr, info_ptr, NULL, NULL, &trans_color_rgb);
|
||||
if (bit_depth == 16) /* png_set_strip_16() not yet in effect */
|
||||
transparent = gdTrueColor (trans_color_rgb->red >> 8,
|
||||
trans_color_rgb->green >> 8,
|
||||
trans_color_rgb->blue >> 8);
|
||||
else
|
||||
transparent = gdTrueColor (trans_color_rgb->red,
|
||||
trans_color_rgb->green,
|
||||
trans_color_rgb->blue);
|
||||
}
|
||||
break;
|
||||
}
|
||||
|
||||
png_read_update_info (png_ptr, info_ptr);
|
||||
|
||||
/* allocate space for the PNG image data */
|
||||
rowbytes = png_get_rowbytes (png_ptr, info_ptr);
|
||||
if ((image_data = (png_bytep) gdMalloc (rowbytes * height)) == NULL)
|
||||
{
|
||||
fprintf (stderr, "gd-png error: cannot allocate image data\n");
|
||||
png_destroy_read_struct (&png_ptr, &info_ptr, NULL);
|
||||
return NULL;
|
||||
}
|
||||
if ((row_pointers =
|
||||
(png_bytepp) gdMalloc (height * sizeof (png_bytep))) == NULL)
|
||||
{
|
||||
fprintf (stderr, "gd-png error: cannot allocate row pointers\n");
|
||||
png_destroy_read_struct (&png_ptr, &info_ptr, NULL);
|
||||
gdFree (image_data);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
/* set the individual row_pointers to point at the correct offsets */
|
||||
for (j = 0; j < height; ++j)
|
||||
{
|
||||
row_pointers[j] = image_data + j * rowbytes;
|
||||
}
|
||||
|
||||
png_read_image (png_ptr, row_pointers); /* read whole image... */
|
||||
png_read_end (png_ptr, NULL); /* ...done! */
|
||||
|
||||
if (!im->trueColor)
|
||||
{
|
||||
im->colorsTotal = num_palette;
|
||||
/* load the palette and mark all entries "open" (unused) for now */
|
||||
open = im->open;
|
||||
for (i = 0; i < num_palette; ++i)
|
||||
{
|
||||
im->red[i] = palette[i].red;
|
||||
im->green[i] = palette[i].green;
|
||||
im->blue[i] = palette[i].blue;
|
||||
open[i] = 1;
|
||||
}
|
||||
for (i = num_palette; i < gdMaxColors; ++i)
|
||||
{
|
||||
open[i] = 1;
|
||||
}
|
||||
}
|
||||
/* 2.0.12: Slaven Rezic: palette images are not the only images
|
||||
with a simple transparent color setting */
|
||||
im->transparent = transparent;
|
||||
im->interlace = (interlace_type == PNG_INTERLACE_ADAM7);
|
||||
|
||||
/* can't nuke structs until done with palette */
|
||||
png_destroy_read_struct (&png_ptr, &info_ptr, NULL);
|
||||
switch (color_type)
|
||||
{
|
||||
case PNG_COLOR_TYPE_RGB:
|
||||
for (j = 0; j < height; j++)
|
||||
{
|
||||
int boffset = 0;
|
||||
for (i = 0; i < width; i++)
|
||||
{
|
||||
register png_byte r = row_pointers[j][boffset++];
|
||||
register png_byte g = row_pointers[j][boffset++];
|
||||
register png_byte b = row_pointers[j][boffset++];
|
||||
im->tpixels[j][i] = gdTrueColor (r, g, b);
|
||||
}
|
||||
}
|
||||
break;
|
||||
case PNG_COLOR_TYPE_RGB_ALPHA:
|
||||
for (j = 0; j < height; j++)
|
||||
{
|
||||
int boffset = 0;
|
||||
for (i = 0; i < width; i++)
|
||||
{
|
||||
register png_byte r = row_pointers[j][boffset++];
|
||||
register png_byte g = row_pointers[j][boffset++];
|
||||
register png_byte b = row_pointers[j][boffset++];
|
||||
/* gd has only 7 bits of alpha channel resolution, and
|
||||
127 is transparent, 0 opaque. A moment of convenience,
|
||||
a lifetime of compatibility. */
|
||||
register png_byte a = gdAlphaMax -
|
||||
(row_pointers[j][boffset++] >> 1);
|
||||
im->tpixels[j][i] = gdTrueColorAlpha (r, g, b, a);
|
||||
}
|
||||
}
|
||||
break;
|
||||
default:
|
||||
/* Palette image, or something coerced to be one */
|
||||
for (j = 0; j < height; ++j)
|
||||
{
|
||||
for (i = 0; i < width; ++i)
|
||||
{
|
||||
register png_byte idx = row_pointers[j][i];
|
||||
im->pixels[j][i] = idx;
|
||||
open[idx] = 0;
|
||||
}
|
||||
}
|
||||
}
|
||||
#ifdef DEBUG
|
||||
if (!im->trueColor)
|
||||
{
|
||||
for (i = num_palette; i < gdMaxColors; ++i)
|
||||
{
|
||||
if (!open[i])
|
||||
{
|
||||
fprintf (stderr,
|
||||
"gd-png warning: image data references out-of-range"
|
||||
" color index (%d)\n", i);
|
||||
}
|
||||
}
|
||||
}
|
||||
#endif
|
||||
|
||||
if (palette_allocated)
|
||||
gdFree (palette);
|
||||
gdFree (image_data);
|
||||
gdFree (row_pointers);
|
||||
|
||||
return im;
|
||||
}
|
||||
|
||||
|
||||
void
|
||||
gdImagePngEx (gdImagePtr im, FILE * outFile, int level)
|
||||
{
|
||||
gdIOCtx *out = gdNewFileCtx (outFile);
|
||||
gdImagePngCtxEx (im, out, level);
|
||||
out->gd_free (out);
|
||||
}
|
||||
|
||||
void
|
||||
gdImagePng (gdImagePtr im, FILE * outFile)
|
||||
{
|
||||
gdIOCtx *out = gdNewFileCtx (outFile);
|
||||
gdImagePngCtxEx (im, out, -1);
|
||||
out->gd_free (out);
|
||||
}
|
||||
|
||||
void *
|
||||
gdImagePngPtr (gdImagePtr im, int *size)
|
||||
{
|
||||
void *rv;
|
||||
gdIOCtx *out = gdNewDynamicCtx (2048, NULL);
|
||||
gdImagePngCtxEx (im, out, -1);
|
||||
rv = gdDPExtractData (out, size);
|
||||
out->gd_free (out);
|
||||
return rv;
|
||||
}
|
||||
|
||||
void *
|
||||
gdImagePngPtrEx (gdImagePtr im, int *size, int level)
|
||||
{
|
||||
void *rv;
|
||||
gdIOCtx *out = gdNewDynamicCtx (2048, NULL);
|
||||
gdImagePngCtxEx (im, out, level);
|
||||
rv = gdDPExtractData (out, size);
|
||||
out->gd_free (out);
|
||||
return rv;
|
||||
}
|
||||
|
||||
void
|
||||
gdImagePngCtx (gdImagePtr im, gdIOCtx * outfile)
|
||||
{
|
||||
/* 2.0.13: 'return' here was an error, thanks to Kevin Smith */
|
||||
gdImagePngCtxEx (im, outfile, -1);
|
||||
}
|
||||
|
||||
/* This routine is based in part on code from Dale Lutz (Safe Software Inc.)
|
||||
* and in part on demo code from Chapter 15 of "PNG: The Definitive Guide"
|
||||
* (http://www.cdrom.com/pub/png/pngbook.html).
|
||||
*/
|
||||
void
|
||||
gdImagePngCtxEx (gdImagePtr im, gdIOCtx * outfile, int level)
|
||||
{
|
||||
int i, j, bit_depth = 0, interlace_type;
|
||||
int width = im->sx;
|
||||
int height = im->sy;
|
||||
int colors = im->colorsTotal;
|
||||
int *open = im->open;
|
||||
int mapping[gdMaxColors]; /* mapping[gd_index] == png_index */
|
||||
png_byte trans_values[256];
|
||||
png_color_16 trans_rgb_value;
|
||||
png_color palette[gdMaxColors];
|
||||
png_structp png_ptr;
|
||||
png_infop info_ptr;
|
||||
volatile int transparent = im->transparent;
|
||||
volatile int remap = FALSE;
|
||||
|
||||
|
||||
#ifndef PNG_SETJMP_NOT_SUPPORTED
|
||||
png_ptr = png_create_write_struct (PNG_LIBPNG_VER_STRING,
|
||||
&gdPngJmpbufStruct, gdPngErrorHandler,
|
||||
NULL);
|
||||
#else
|
||||
png_ptr = png_create_write_struct (PNG_LIBPNG_VER_STRING, NULL, NULL, NULL);
|
||||
#endif
|
||||
if (png_ptr == NULL)
|
||||
{
|
||||
fprintf (stderr, "gd-png error: cannot allocate libpng main struct\n");
|
||||
return;
|
||||
}
|
||||
|
||||
info_ptr = png_create_info_struct (png_ptr);
|
||||
if (info_ptr == NULL)
|
||||
{
|
||||
fprintf (stderr, "gd-png error: cannot allocate libpng info struct\n");
|
||||
png_destroy_write_struct (&png_ptr, (png_infopp) NULL);
|
||||
return;
|
||||
}
|
||||
|
||||
#ifndef PNG_SETJMP_NOT_SUPPORTED
|
||||
if (setjmp (gdPngJmpbufStruct.jmpbuf))
|
||||
{
|
||||
fprintf (stderr, "gd-png error: setjmp returns error condition\n");
|
||||
png_destroy_write_struct (&png_ptr, &info_ptr);
|
||||
return;
|
||||
}
|
||||
#endif
|
||||
|
||||
png_set_write_fn (png_ptr, (void *) outfile, gdPngWriteData,
|
||||
gdPngFlushData);
|
||||
|
||||
/* This is best for palette images, and libpng defaults to it for
|
||||
palette images anyway, so we don't need to do it explicitly.
|
||||
What to ideally do for truecolor images depends, alas, on the image.
|
||||
gd is intentionally imperfect and doesn't spend a lot of time
|
||||
fussing with such things. */
|
||||
/* png_set_filter(png_ptr, 0, PNG_FILTER_NONE); */
|
||||
|
||||
/* 2.0.12: this is finally a parameter */
|
||||
png_set_compression_level (png_ptr, level);
|
||||
|
||||
/* can set this to a smaller value without compromising compression if all
|
||||
* image data is 16K or less; will save some decoder memory [min == 8] */
|
||||
/* png_set_compression_window_bits(png_ptr, 15); */
|
||||
|
||||
if (!im->trueColor)
|
||||
{
|
||||
if (transparent >= im->colorsTotal ||
|
||||
(transparent >= 0 && open[transparent]))
|
||||
transparent = -1;
|
||||
}
|
||||
if (!im->trueColor)
|
||||
{
|
||||
for (i = 0; i < gdMaxColors; ++i)
|
||||
mapping[i] = -1;
|
||||
}
|
||||
if (!im->trueColor)
|
||||
{
|
||||
/* count actual number of colors used (colorsTotal == high-water mark) */
|
||||
colors = 0;
|
||||
for (i = 0; i < im->colorsTotal; ++i)
|
||||
{
|
||||
if (!open[i])
|
||||
{
|
||||
mapping[i] = colors;
|
||||
++colors;
|
||||
}
|
||||
}
|
||||
if (colors < im->colorsTotal)
|
||||
{
|
||||
remap = TRUE;
|
||||
}
|
||||
if (colors <= 2)
|
||||
bit_depth = 1;
|
||||
else if (colors <= 4)
|
||||
bit_depth = 2;
|
||||
else if (colors <= 16)
|
||||
bit_depth = 4;
|
||||
else
|
||||
bit_depth = 8;
|
||||
}
|
||||
interlace_type = im->interlace ? PNG_INTERLACE_ADAM7 : PNG_INTERLACE_NONE;
|
||||
|
||||
if (im->trueColor)
|
||||
{
|
||||
if (im->saveAlphaFlag)
|
||||
{
|
||||
png_set_IHDR (png_ptr, info_ptr, width, height, 8,
|
||||
PNG_COLOR_TYPE_RGB_ALPHA, interlace_type,
|
||||
PNG_COMPRESSION_TYPE_DEFAULT,
|
||||
PNG_FILTER_TYPE_DEFAULT);
|
||||
}
|
||||
else
|
||||
{
|
||||
png_set_IHDR (png_ptr, info_ptr, width, height, 8,
|
||||
PNG_COLOR_TYPE_RGB, interlace_type,
|
||||
PNG_COMPRESSION_TYPE_DEFAULT,
|
||||
PNG_FILTER_TYPE_DEFAULT);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
png_set_IHDR (png_ptr, info_ptr, width, height, bit_depth,
|
||||
PNG_COLOR_TYPE_PALETTE, interlace_type,
|
||||
PNG_COMPRESSION_TYPE_DEFAULT, PNG_FILTER_TYPE_DEFAULT);
|
||||
}
|
||||
if (im->trueColor && (!im->saveAlphaFlag) && (transparent >= 0))
|
||||
{
|
||||
/* 2.0.9: fixed by Thomas Winzig */
|
||||
trans_rgb_value.red = gdTrueColorGetRed (im->transparent);
|
||||
trans_rgb_value.green = gdTrueColorGetGreen (im->transparent);
|
||||
trans_rgb_value.blue = gdTrueColorGetBlue (im->transparent);
|
||||
png_set_tRNS (png_ptr, info_ptr, 0, 0, &trans_rgb_value);
|
||||
}
|
||||
if (!im->trueColor)
|
||||
{
|
||||
/* Oy veh. Remap the PNG palette to put the
|
||||
entries with interesting alpha channel
|
||||
values first. This minimizes the size
|
||||
of the tRNS chunk and thus the size
|
||||
of the PNG file as a whole. */
|
||||
int tc = 0;
|
||||
int i;
|
||||
int j;
|
||||
int k;
|
||||
for (i = 0; (i < im->colorsTotal); i++)
|
||||
{
|
||||
if ((!im->open[i]) && (im->alpha[i] != gdAlphaOpaque))
|
||||
{
|
||||
tc++;
|
||||
}
|
||||
}
|
||||
if (tc)
|
||||
{
|
||||
#if 0
|
||||
for (i = 0; (i < im->colorsTotal); i++)
|
||||
{
|
||||
trans_values[i] = 255 -
|
||||
((im->alpha[i] << 1) + (im->alpha[i] >> 6));
|
||||
}
|
||||
png_set_tRNS (png_ptr, info_ptr, trans_values, 256, NULL);
|
||||
#endif
|
||||
if (!remap)
|
||||
{
|
||||
remap = TRUE;
|
||||
}
|
||||
/* (Semi-)transparent indexes come up from the bottom
|
||||
of the list of real colors; opaque
|
||||
indexes come down from the top */
|
||||
j = 0;
|
||||
k = colors - 1;
|
||||
for (i = 0; (i < im->colorsTotal); i++)
|
||||
{
|
||||
if (!im->open[i])
|
||||
{
|
||||
if (im->alpha[i] != gdAlphaOpaque)
|
||||
{
|
||||
/* Andrew Hull: >> 6, not >> 7! (gd 2.0.5) */
|
||||
trans_values[j] = 255 -
|
||||
((im->alpha[i] << 1) + (im->alpha[i] >> 6));
|
||||
mapping[i] = j++;
|
||||
}
|
||||
else
|
||||
{
|
||||
mapping[i] = k--;
|
||||
}
|
||||
}
|
||||
}
|
||||
png_set_tRNS (png_ptr, info_ptr, trans_values, tc, NULL);
|
||||
}
|
||||
}
|
||||
|
||||
/* convert palette to libpng layout */
|
||||
if (!im->trueColor)
|
||||
{
|
||||
if (remap)
|
||||
for (i = 0; i < im->colorsTotal; ++i)
|
||||
{
|
||||
if (mapping[i] < 0)
|
||||
continue;
|
||||
palette[mapping[i]].red = im->red[i];
|
||||
palette[mapping[i]].green = im->green[i];
|
||||
palette[mapping[i]].blue = im->blue[i];
|
||||
}
|
||||
else
|
||||
for (i = 0; i < colors; ++i)
|
||||
{
|
||||
palette[i].red = im->red[i];
|
||||
palette[i].green = im->green[i];
|
||||
palette[i].blue = im->blue[i];
|
||||
}
|
||||
png_set_PLTE (png_ptr, info_ptr, palette, colors);
|
||||
}
|
||||
|
||||
/* write out the PNG header info (everything up to first IDAT) */
|
||||
png_write_info (png_ptr, info_ptr);
|
||||
|
||||
/* make sure < 8-bit images are packed into pixels as tightly as possible */
|
||||
png_set_packing (png_ptr);
|
||||
|
||||
/* This code allocates a set of row buffers and copies the gd image data
|
||||
* into them only in the case that remapping is necessary; in gd 1.3 and
|
||||
* later, the im->pixels array is laid out identically to libpng's row
|
||||
* pointers and can be passed to png_write_image() function directly.
|
||||
* The remapping case could be accomplished with less memory for non-
|
||||
* interlaced images, but interlacing causes some serious complications. */
|
||||
if (im->trueColor)
|
||||
{
|
||||
int channels = im->saveAlphaFlag ? 4 : 3;
|
||||
/* Our little 7-bit alpha channel trick costs us a bit here. */
|
||||
png_bytep *row_pointers;
|
||||
row_pointers = gdMalloc (sizeof (png_bytep) * height);
|
||||
if (row_pointers == NULL)
|
||||
{
|
||||
fprintf (stderr, "gd-png error: unable to allocate row_pointers\n");
|
||||
}
|
||||
for (j = 0; j < height; ++j)
|
||||
{
|
||||
int bo = 0;
|
||||
if ((row_pointers[j] =
|
||||
(png_bytep) gdMalloc (width * channels)) == NULL)
|
||||
{
|
||||
fprintf (stderr, "gd-png error: unable to allocate rows\n");
|
||||
for (i = 0; i < j; ++i)
|
||||
gdFree (row_pointers[i]);
|
||||
return;
|
||||
}
|
||||
for (i = 0; i < width; ++i)
|
||||
{
|
||||
unsigned char a;
|
||||
row_pointers[j][bo++] = gdTrueColorGetRed (im->tpixels[j][i]);
|
||||
row_pointers[j][bo++] = gdTrueColorGetGreen (im->tpixels[j][i]);
|
||||
row_pointers[j][bo++] = gdTrueColorGetBlue (im->tpixels[j][i]);
|
||||
if (im->saveAlphaFlag)
|
||||
{
|
||||
/* convert the 7-bit alpha channel to an 8-bit alpha channel.
|
||||
We do a little bit-flipping magic, repeating the MSB
|
||||
as the LSB, to ensure that 0 maps to 0 and
|
||||
127 maps to 255. We also have to invert to match
|
||||
PNG's convention in which 255 is opaque. */
|
||||
a = gdTrueColorGetAlpha (im->tpixels[j][i]);
|
||||
/* Andrew Hull: >> 6, not >> 7! (gd 2.0.5) */
|
||||
row_pointers[j][bo++] = 255 - ((a << 1) + (a >> 6));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
png_write_image (png_ptr, row_pointers);
|
||||
png_write_end (png_ptr, info_ptr);
|
||||
|
||||
for (j = 0; j < height; ++j)
|
||||
gdFree (row_pointers[j]);
|
||||
gdFree (row_pointers);
|
||||
}
|
||||
else
|
||||
{
|
||||
if (remap)
|
||||
{
|
||||
png_bytep *row_pointers;
|
||||
row_pointers = gdMalloc (sizeof (png_bytep) * height);
|
||||
if (row_pointers == NULL)
|
||||
{
|
||||
fprintf (stderr,
|
||||
"gd-png error: unable to allocate row_pointers\n");
|
||||
}
|
||||
for (j = 0; j < height; ++j)
|
||||
{
|
||||
if ((row_pointers[j] = (png_bytep) gdMalloc (width)) == NULL)
|
||||
{
|
||||
fprintf (stderr, "gd-png error: unable to allocate rows\n");
|
||||
for (i = 0; i < j; ++i)
|
||||
gdFree (row_pointers[i]);
|
||||
return;
|
||||
}
|
||||
for (i = 0; i < width; ++i)
|
||||
row_pointers[j][i] = mapping[im->pixels[j][i]];
|
||||
}
|
||||
|
||||
png_write_image (png_ptr, row_pointers);
|
||||
png_write_end (png_ptr, info_ptr);
|
||||
|
||||
for (j = 0; j < height; ++j)
|
||||
gdFree (row_pointers[j]);
|
||||
gdFree (row_pointers);
|
||||
}
|
||||
else
|
||||
{
|
||||
png_write_image (png_ptr, im->pixels);
|
||||
png_write_end (png_ptr, info_ptr);
|
||||
}
|
||||
}
|
||||
/* 1.6.3: maybe we should give that memory BACK! TBB */
|
||||
png_destroy_write_struct (&png_ptr, &info_ptr);
|
||||
}
|
||||
|
||||
|
||||
#endif /* HAVE_LIBPNG */
|
|
@ -1,58 +0,0 @@
|
|||
|
||||
#ifdef HAVE_CONFIG_H
|
||||
#include "config.h"
|
||||
#endif
|
||||
|
||||
#include <stdio.h>
|
||||
#include <math.h>
|
||||
#include <string.h>
|
||||
#include <stdlib.h>
|
||||
#include "gd.h"
|
||||
|
||||
#define TRUE 1
|
||||
#define FALSE 0
|
||||
|
||||
/* Exported functions: */
|
||||
extern void gdImagePngToSink (gdImagePtr im, gdSinkPtr out);
|
||||
extern gdImagePtr gdImageCreateFromPngSource (gdSourcePtr inSource);
|
||||
|
||||
/* Use this for commenting out debug-print statements. */
|
||||
/* Just use the first '#define' to allow all the prints... */
|
||||
/*#define GD_SS_DBG(s) (s) */
|
||||
#define GD_SS_DBG(s)
|
||||
|
||||
#ifdef HAVE_LIBPNG
|
||||
void
|
||||
gdImagePngToSink (gdImagePtr im, gdSinkPtr outSink)
|
||||
{
|
||||
gdIOCtx *out = gdNewSSCtx (NULL, outSink);
|
||||
gdImagePngCtx (im, out);
|
||||
out->gd_free (out);
|
||||
}
|
||||
|
||||
gdImagePtr
|
||||
gdImageCreateFromPngSource (gdSourcePtr inSource)
|
||||
{
|
||||
gdIOCtx *in = gdNewSSCtx (inSource, NULL);
|
||||
gdImagePtr im;
|
||||
|
||||
im = gdImageCreateFromPngCtx (in);
|
||||
|
||||
in->gd_free (in);
|
||||
|
||||
return im;
|
||||
}
|
||||
#else /* no HAVE_LIBPNG */
|
||||
void
|
||||
gdImagePngToSink (gdImagePtr im, gdSinkPtr outSink)
|
||||
{
|
||||
fprintf (stderr, "PNG support is not available\n");
|
||||
}
|
||||
|
||||
gdImagePtr
|
||||
gdImageCreateFromPngSource (gdSourcePtr inSource)
|
||||
{
|
||||
fprintf (stderr, "PNG support is not available\n");
|
||||
return NULL;
|
||||
}
|
||||
#endif /* HAVE_LIBPNG */
|
File diff suppressed because it is too large
Load Diff
|
@ -1,218 +0,0 @@
|
|||
|
||||
#ifdef HAVE_CONFIG_H
|
||||
#include "config.h"
|
||||
#endif
|
||||
|
||||
#include "gd.h"
|
||||
#include "gdhelpers.h"
|
||||
|
||||
#ifdef HAVE_LIBTTF
|
||||
#define NEED_CACHE 1
|
||||
#else
|
||||
#ifdef HAVE_LIBFREETYPE
|
||||
#define NEED_CACHE 1
|
||||
#endif
|
||||
#endif
|
||||
|
||||
#ifdef NEED_CACHE
|
||||
|
||||
/*
|
||||
* gdcache.c
|
||||
*
|
||||
* Caches of pointers to user structs in which the least-recently-used
|
||||
* element is replaced in the event of a cache miss after the cache has
|
||||
* reached a given size.
|
||||
*
|
||||
* John Ellson (ellson@graphviz.org) Oct 31, 1997
|
||||
*
|
||||
* Test this with:
|
||||
* gcc -o gdcache -g -Wall -DTEST gdcache.c
|
||||
*
|
||||
* The cache is implemented by a singly-linked list of elements
|
||||
* each containing a pointer to a user struct that is being managed by
|
||||
* the cache.
|
||||
*
|
||||
* The head structure has a pointer to the most-recently-used
|
||||
* element, and elements are moved to this position in the list each
|
||||
* time they are used. The head also contains pointers to three
|
||||
* user defined functions:
|
||||
* - a function to test if a cached userdata matches some keydata
|
||||
* - a function to provide a new userdata struct to the cache
|
||||
* if there has been a cache miss.
|
||||
* - a function to release a userdata struct when it is
|
||||
* no longer being managed by the cache
|
||||
*
|
||||
* In the event of a cache miss the cache is allowed to grow up to
|
||||
* a specified maximum size. After the maximum size is reached then
|
||||
* the least-recently-used element is discarded to make room for the
|
||||
* new. The most-recently-returned value is always left at the
|
||||
* beginning of the list after retrieval.
|
||||
*
|
||||
* In the current implementation the cache is traversed by a linear
|
||||
* search from most-recent to least-recent. This linear search
|
||||
* probably limits the usefulness of this implementation to cache
|
||||
* sizes of a few tens of elements.
|
||||
*/
|
||||
|
||||
#include "gdcache.h"
|
||||
|
||||
/*********************************************************/
|
||||
/* implementation */
|
||||
/*********************************************************/
|
||||
|
||||
|
||||
/* create a new cache */
|
||||
gdCache_head_t *
|
||||
gdCacheCreate (int size,
|
||||
gdCacheTestFn_t gdCacheTest,
|
||||
gdCacheFetchFn_t gdCacheFetch,
|
||||
gdCacheReleaseFn_t gdCacheRelease)
|
||||
{
|
||||
gdCache_head_t *head;
|
||||
|
||||
head = (gdCache_head_t *) gdMalloc (sizeof (gdCache_head_t));
|
||||
head->mru = NULL;
|
||||
head->size = size;
|
||||
head->gdCacheTest = gdCacheTest;
|
||||
head->gdCacheFetch = gdCacheFetch;
|
||||
head->gdCacheRelease = gdCacheRelease;
|
||||
return head;
|
||||
}
|
||||
|
||||
void
|
||||
gdCacheDelete (gdCache_head_t * head)
|
||||
{
|
||||
gdCache_element_t *elem, *prev;
|
||||
|
||||
elem = head->mru;
|
||||
while (elem)
|
||||
{
|
||||
(*(head->gdCacheRelease)) (elem->userdata);
|
||||
prev = elem;
|
||||
elem = elem->next;
|
||||
gdFree ((char *) prev);
|
||||
}
|
||||
gdFree ((char *) head);
|
||||
}
|
||||
|
||||
void *
|
||||
gdCacheGet (gdCache_head_t * head, void *keydata)
|
||||
{
|
||||
int i = 0;
|
||||
gdCache_element_t *elem, *prev = NULL, *prevprev = NULL;
|
||||
void *userdata;
|
||||
|
||||
elem = head->mru;
|
||||
while (elem)
|
||||
{
|
||||
if ((*(head->gdCacheTest)) (elem->userdata, keydata))
|
||||
{
|
||||
if (i)
|
||||
{ /* if not already most-recently-used */
|
||||
/* relink to top of list */
|
||||
prev->next = elem->next;
|
||||
elem->next = head->mru;
|
||||
head->mru = elem;
|
||||
}
|
||||
return elem->userdata;
|
||||
}
|
||||
prevprev = prev;
|
||||
prev = elem;
|
||||
elem = elem->next;
|
||||
i++;
|
||||
}
|
||||
userdata = (*(head->gdCacheFetch)) (&(head->error), keydata);
|
||||
if (!userdata)
|
||||
{
|
||||
/* if there was an error in the fetch then don't cache */
|
||||
return NULL;
|
||||
}
|
||||
if (i < head->size)
|
||||
{ /* cache still growing - add new elem */
|
||||
elem = (gdCache_element_t *) gdMalloc (sizeof (gdCache_element_t));
|
||||
}
|
||||
else
|
||||
{ /* cache full - replace least-recently-used */
|
||||
/* preveprev becomes new end of list */
|
||||
prevprev->next = NULL;
|
||||
elem = prev;
|
||||
(*(head->gdCacheRelease)) (elem->userdata);
|
||||
}
|
||||
/* relink to top of list */
|
||||
elem->next = head->mru;
|
||||
head->mru = elem;
|
||||
elem->userdata = userdata;
|
||||
return userdata;
|
||||
}
|
||||
|
||||
|
||||
|
||||
/*********************************************************/
|
||||
/* test stub */
|
||||
/*********************************************************/
|
||||
|
||||
|
||||
#ifdef TEST
|
||||
|
||||
#include <stdio.h>
|
||||
|
||||
typedef struct
|
||||
{
|
||||
int key;
|
||||
int value;
|
||||
}
|
||||
key_value_t;
|
||||
|
||||
static int
|
||||
cacheTest (void *map, void *key)
|
||||
{
|
||||
return (((key_value_t *) map)->key == *(int *) key);
|
||||
}
|
||||
|
||||
static void *
|
||||
cacheFetch (char **error, void *key)
|
||||
{
|
||||
key_value_t *map;
|
||||
|
||||
map = (key_value_t *) gdMalloc (sizeof (key_value_t));
|
||||
map->key = *(int *) key;
|
||||
map->value = 3;
|
||||
|
||||
*error = NULL;
|
||||
return (void *) map;
|
||||
}
|
||||
|
||||
static void
|
||||
cacheRelease (void *map)
|
||||
{
|
||||
gdFree ((char *) map);
|
||||
}
|
||||
|
||||
int
|
||||
main (char *argv[], int argc)
|
||||
{
|
||||
gdCache_head_t *cacheTable;
|
||||
int elem, key;
|
||||
|
||||
cacheTable = gdCacheCreate (3, cacheTest, cacheFetch, cacheRelease);
|
||||
|
||||
key = 20;
|
||||
elem = *(int *) gdCacheGet (cacheTable, &key);
|
||||
key = 30;
|
||||
elem = *(int *) gdCacheGet (cacheTable, &key);
|
||||
key = 40;
|
||||
elem = *(int *) gdCacheGet (cacheTable, &key);
|
||||
key = 50;
|
||||
elem = *(int *) gdCacheGet (cacheTable, &key);
|
||||
key = 30;
|
||||
elem = *(int *) gdCacheGet (cacheTable, &key);
|
||||
key = 30;
|
||||
elem = *(int *) gdCacheGet (cacheTable, &key);
|
||||
|
||||
gdCacheDelete (cacheTable);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
#endif /* TEST */
|
||||
#endif /* HAVE_LIBTTF */
|
|
@ -1,85 +0,0 @@
|
|||
/*
|
||||
* gdcache.h
|
||||
*
|
||||
* Caches of pointers to user structs in which the least-recently-used
|
||||
* element is replaced in the event of a cache miss after the cache has
|
||||
* reached a given size.
|
||||
*
|
||||
* John Ellson (ellson@graphviz.org) Oct 31, 1997
|
||||
*
|
||||
* Test this with:
|
||||
* gcc -o gdcache -g -Wall -DTEST gdcache.c
|
||||
*
|
||||
* The cache is implemented by a singly-linked list of elements
|
||||
* each containing a pointer to a user struct that is being managed by
|
||||
* the cache.
|
||||
*
|
||||
* The head structure has a pointer to the most-recently-used
|
||||
* element, and elements are moved to this position in the list each
|
||||
* time they are used. The head also contains pointers to three
|
||||
* user defined functions:
|
||||
* - a function to test if a cached userdata matches some keydata
|
||||
* - a function to provide a new userdata struct to the cache
|
||||
* if there has been a cache miss.
|
||||
* - a function to release a userdata struct when it is
|
||||
* no longer being managed by the cache
|
||||
*
|
||||
* In the event of a cache miss the cache is allowed to grow up to
|
||||
* a specified maximum size. After the maximum size is reached then
|
||||
* the least-recently-used element is discarded to make room for the
|
||||
* new. The most-recently-returned value is always left at the
|
||||
* beginning of the list after retrieval.
|
||||
*
|
||||
* In the current implementation the cache is traversed by a linear
|
||||
* search from most-recent to least-recent. This linear search
|
||||
* probably limits the usefulness of this implementation to cache
|
||||
* sizes of a few tens of elements.
|
||||
*/
|
||||
|
||||
/*********************************************************/
|
||||
/* header */
|
||||
/*********************************************************/
|
||||
|
||||
#ifdef HAVE_CONFIG_H
|
||||
#include "config.h"
|
||||
#endif
|
||||
|
||||
#include <stdlib.h>
|
||||
#ifndef NULL
|
||||
#define NULL (void *)0
|
||||
#endif
|
||||
|
||||
/* user defined function templates */
|
||||
typedef int (*gdCacheTestFn_t) (void *userdata, void *keydata);
|
||||
typedef void *(*gdCacheFetchFn_t) (char **error, void *keydata);
|
||||
typedef void (*gdCacheReleaseFn_t) (void *userdata);
|
||||
|
||||
/* element structure */
|
||||
typedef struct gdCache_element_s gdCache_element_t;
|
||||
struct gdCache_element_s
|
||||
{
|
||||
gdCache_element_t *next;
|
||||
void *userdata;
|
||||
};
|
||||
|
||||
/* head structure */
|
||||
typedef struct gdCache_head_s gdCache_head_t;
|
||||
struct gdCache_head_s
|
||||
{
|
||||
gdCache_element_t *mru;
|
||||
int size;
|
||||
char *error;
|
||||
gdCacheTestFn_t gdCacheTest;
|
||||
gdCacheFetchFn_t gdCacheFetch;
|
||||
gdCacheReleaseFn_t gdCacheRelease;
|
||||
};
|
||||
|
||||
/* function templates */
|
||||
gdCache_head_t *gdCacheCreate (int size,
|
||||
gdCacheTestFn_t gdCacheTest,
|
||||
gdCacheFetchFn_t gdCacheFetch,
|
||||
gdCacheReleaseFn_t gdCacheRelease);
|
||||
|
||||
void gdCacheDelete (gdCache_head_t * head);
|
||||
|
||||
void *gdCacheGet (gdCache_head_t * head, void *keydata);
|
File diff suppressed because it is too large
Load Diff
|
@ -1,29 +0,0 @@
|
|||
|
||||
#ifndef _GDFONTG_H_
|
||||
#define _GDFONTG_H_ 1
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C"
|
||||
{
|
||||
#endif
|
||||
|
||||
/*
|
||||
This is a header file for gd font, generated using
|
||||
bdftogd version 0.51 by Jan Pazdziora, adelton@fi.muni.cz
|
||||
from bdf font
|
||||
-Misc-Fixed-Bold-R-Normal-Sans-15-140-75-75-C-90-ISO8859-2
|
||||
at Mon Jan 26 14:45:58 1998.
|
||||
The original bdf was holding following copyright:
|
||||
"Libor Skarvada, libor@informatics.muni.cz"
|
||||
*/
|
||||
|
||||
|
||||
#include "gd.h"
|
||||
|
||||
extern gdFontPtr gdFontGiant;
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif
|
File diff suppressed because it is too large
Load Diff
|
@ -1,30 +0,0 @@
|
|||
|
||||
#ifndef _GDFONTL_H_
|
||||
#define _GDFONTL_H_ 1
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C"
|
||||
{
|
||||
#endif
|
||||
|
||||
/*
|
||||
This is a header file for gd font, generated using
|
||||
bdftogd version 0.5 by Jan Pazdziora, adelton@fi.muni.cz
|
||||
from bdf font
|
||||
-misc-fixed-medium-r-normal--16-140-75-75-c-80-iso8859-2
|
||||
at Tue Jan 6 19:39:27 1998.
|
||||
|
||||
The original bdf was holding following copyright:
|
||||
"Libor Skarvada, libor@informatics.muni.cz"
|
||||
*/
|
||||
|
||||
|
||||
#include "gd.h"
|
||||
|
||||
extern gdFontPtr gdFontLarge;
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif
|
File diff suppressed because it is too large
Load Diff
|
@ -1,28 +0,0 @@
|
|||
|
||||
#ifndef _GDFONTMB_H_
|
||||
#define _GDFONTMB_H_ 1
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C"
|
||||
{
|
||||
#endif
|
||||
|
||||
/*
|
||||
This is a header file for gd font, generated using
|
||||
bdftogd version 0.5 by Jan Pazdziora, adelton@fi.muni.cz
|
||||
from bdf font
|
||||
-misc-fixed-bold-r-normal-sans-13-94-100-100-c-70-iso8859-2
|
||||
at Thu Jan 8 13:54:57 1998.
|
||||
No copyright info was found in the original bdf.
|
||||
*/
|
||||
|
||||
|
||||
#include "gd.h"
|
||||
|
||||
extern gdFontPtr gdFontMediumBold;
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif
|
File diff suppressed because it is too large
Load Diff
|
@ -1,28 +0,0 @@
|
|||
|
||||
#ifndef _GDFONTS_H_
|
||||
#define _GDFONTS_H_ 1
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C"
|
||||
{
|
||||
#endif
|
||||
|
||||
/*
|
||||
This is a header file for gd font, generated using
|
||||
bdftogd version 0.5 by Jan Pazdziora, adelton@fi.muni.cz
|
||||
from bdf font
|
||||
-misc-fixed-medium-r-semicondensed-sans-12-116-75-75-c-60-iso8859-2
|
||||
at Thu Jan 8 14:13:20 1998.
|
||||
No copyright info was found in the original bdf.
|
||||
*/
|
||||
|
||||
|
||||
#include "gd.h"
|
||||
|
||||
extern gdFontPtr gdFontSmall;
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif
|
File diff suppressed because it is too large
Load Diff
|
@ -1,29 +0,0 @@
|
|||
|
||||
#ifndef _GDFONTT_H_
|
||||
#define _GDFONTT_H_ 1
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C"
|
||||
{
|
||||
#endif
|
||||
|
||||
/*
|
||||
This is a header file for gd font, generated using
|
||||
bdftogd version 0.5 by Jan Pazdziora, adelton@fi.muni.cz
|
||||
from bdf font
|
||||
-Misc-Fixed-Medium-R-Normal--8-80-75-75-C-50-ISO8859-2
|
||||
at Thu Jan 8 13:49:54 1998.
|
||||
The original bdf was holding following copyright:
|
||||
"Libor Skarvada, libor@informatics.muni.cz"
|
||||
*/
|
||||
|
||||
|
||||
#include "gd.h"
|
||||
|
||||
extern gdFontPtr gdFontTiny;
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif
|
|
@ -1,101 +0,0 @@
|
|||
|
||||
#ifdef HAVE_CONFIG_H
|
||||
#include "config.h"
|
||||
#endif
|
||||
|
||||
#include "gd.h"
|
||||
#include "gdhelpers.h"
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
|
||||
/* TBB: gd_strtok_r is not portable; provide an implementation */
|
||||
|
||||
#define SEP_TEST (separators[*((unsigned char *) s)])
|
||||
|
||||
char *
|
||||
gd_strtok_r (char *s, char *sep, char **state)
|
||||
{
|
||||
char separators[256];
|
||||
char *start;
|
||||
char *result = 0;
|
||||
memset (separators, 0, sizeof (separators));
|
||||
while (*sep)
|
||||
{
|
||||
separators[*((unsigned char *) sep)] = 1;
|
||||
sep++;
|
||||
}
|
||||
if (!s)
|
||||
{
|
||||
/* Pick up where we left off */
|
||||
s = *state;
|
||||
}
|
||||
start = s;
|
||||
/* 1. EOS */
|
||||
if (!(*s))
|
||||
{
|
||||
*state = s;
|
||||
return 0;
|
||||
}
|
||||
/* 2. Leading separators, if any */
|
||||
if (SEP_TEST)
|
||||
{
|
||||
do
|
||||
{
|
||||
s++;
|
||||
}
|
||||
while (SEP_TEST);
|
||||
/* 2a. EOS after separators only */
|
||||
if (!(*s))
|
||||
{
|
||||
*state = s;
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
/* 3. A token */
|
||||
result = s;
|
||||
do
|
||||
{
|
||||
/* 3a. Token at end of string */
|
||||
if (!(*s))
|
||||
{
|
||||
*state = s;
|
||||
return result;
|
||||
}
|
||||
s++;
|
||||
}
|
||||
while (!SEP_TEST);
|
||||
/* 4. Terminate token and skip trailing separators */
|
||||
*s = '\0';
|
||||
do
|
||||
{
|
||||
s++;
|
||||
}
|
||||
while (SEP_TEST);
|
||||
/* 5. Return token */
|
||||
*state = s;
|
||||
return result;
|
||||
}
|
||||
|
||||
void *
|
||||
gdCalloc (size_t nmemb, size_t size)
|
||||
{
|
||||
return calloc (nmemb, size);
|
||||
}
|
||||
|
||||
void *
|
||||
gdMalloc (size_t size)
|
||||
{
|
||||
return malloc (size);
|
||||
}
|
||||
|
||||
void *
|
||||
gdRealloc (void *ptr, size_t size)
|
||||
{
|
||||
return realloc (ptr, size);
|
||||
}
|
||||
|
||||
void
|
||||
gdFree (void *ptr)
|
||||
{
|
||||
free (ptr);
|
||||
}
|
|
@ -1,19 +0,0 @@
|
|||
#ifndef GDHELPERS_H
|
||||
#define GDHELPERS_H 1
|
||||
|
||||
/* sys/types.h is needed for size_t on Sparc-SunOS-4.1 */
|
||||
#include <sys/types.h>
|
||||
|
||||
/* TBB: strtok_r is not universal; provide an implementation of it. */
|
||||
|
||||
extern char *gd_strtok_r (char *s, char *sep, char **state);
|
||||
|
||||
/* These functions wrap memory management. gdFree is
|
||||
in gd.h, where callers can utilize it to correctly
|
||||
free memory allocated by these functions with the
|
||||
right version of free(). */
|
||||
void *gdCalloc (size_t nmemb, size_t size);
|
||||
void *gdMalloc (size_t size);
|
||||
void *gdRealloc (void *ptr, size_t size);
|
||||
|
||||
#endif /* GDHELPERS_H */
|
|
@ -1,660 +0,0 @@
|
|||
|
||||
/* gdkanji.c (Kanji code converter) */
|
||||
/* written by Masahito Yamaga (ma@yama-ga.com) */
|
||||
|
||||
#ifdef HAVE_CONFIG_H
|
||||
#include "config.h"
|
||||
#endif
|
||||
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
#include "gd.h"
|
||||
#include "gdhelpers.h"
|
||||
|
||||
#ifdef HAVE_ERRNO_H
|
||||
#include <errno.h>
|
||||
#endif
|
||||
|
||||
#include <stdarg.h>
|
||||
#if defined(HAVE_ICONV_H)
|
||||
#include <iconv.h>
|
||||
#endif
|
||||
|
||||
#ifndef HAVE_ICONV_T_DEF
|
||||
typedef void *iconv_t;
|
||||
#endif
|
||||
|
||||
#ifndef HAVE_ICONV
|
||||
#define ICONV_CONST /**/
|
||||
iconv_t iconv_open (const char *, const char *);
|
||||
size_t iconv (iconv_t, ICONV_CONST char **, size_t *, char **, size_t *);
|
||||
int iconv_close (iconv_t);
|
||||
|
||||
iconv_t
|
||||
iconv_open (const char *tocode, const char *fromcode)
|
||||
{
|
||||
return (iconv_t) (-1);
|
||||
}
|
||||
|
||||
size_t
|
||||
iconv (iconv_t cd, ICONV_CONST char **inbuf, size_t * inbytesleft,
|
||||
char **outbuf, size_t * outbytesleft)
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
|
||||
int
|
||||
iconv_close (iconv_t cd)
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
|
||||
#endif /* !HAVE_ICONV */
|
||||
|
||||
#define LIBNAME "any2eucjp()"
|
||||
|
||||
#if defined(__MSC__) || defined(__BORLANDC__) || defined(__TURBOC__) || defined(_Windows) || defined(MSDOS)
|
||||
#ifndef SJISPRE
|
||||
#define SJISPRE 1
|
||||
#endif
|
||||
#endif
|
||||
|
||||
#ifdef TRUE
|
||||
#undef TRUE
|
||||
#endif
|
||||
#ifdef FALSE
|
||||
#undef FALSE
|
||||
#endif
|
||||
|
||||
#define TRUE 1
|
||||
#define FALSE 0
|
||||
|
||||
#define NEW 1
|
||||
#define OLD 2
|
||||
#define ESCI 3
|
||||
#define NEC 4
|
||||
#define EUC 5
|
||||
#define SJIS 6
|
||||
#define EUCORSJIS 7
|
||||
#define ASCII 8
|
||||
|
||||
#define NEWJISSTR "JIS7"
|
||||
#define OLDJISSTR "jis"
|
||||
#define EUCSTR "eucJP"
|
||||
#define SJISSTR "SJIS"
|
||||
|
||||
#define ESC 27
|
||||
#define SS2 142
|
||||
|
||||
static void
|
||||
debug (const char *format, ...)
|
||||
{
|
||||
#ifdef DEBUG
|
||||
va_list args;
|
||||
|
||||
va_start (args, format);
|
||||
fprintf (stdout, "%s: ", LIBNAME);
|
||||
vfprintf (stdout, format, args);
|
||||
fprintf (stdout, "\n");
|
||||
va_end (args);
|
||||
#endif
|
||||
}
|
||||
|
||||
static void
|
||||
error (const char *format, ...)
|
||||
{
|
||||
va_list args;
|
||||
|
||||
va_start (args, format);
|
||||
fprintf (stderr, "%s: ", LIBNAME);
|
||||
vfprintf (stderr, format, args);
|
||||
fprintf (stderr, "\n");
|
||||
va_end (args);
|
||||
}
|
||||
|
||||
/* DetectKanjiCode() derived from DetectCodeType() by Ken Lunde. */
|
||||
|
||||
static int
|
||||
DetectKanjiCode (unsigned char *str)
|
||||
{
|
||||
static int whatcode = ASCII;
|
||||
int oldcode = ASCII;
|
||||
int c, i;
|
||||
char *lang = NULL;
|
||||
|
||||
c = '\1';
|
||||
i = 0;
|
||||
|
||||
if (whatcode != EUCORSJIS && whatcode != ASCII)
|
||||
{
|
||||
oldcode = whatcode;
|
||||
whatcode = ASCII;
|
||||
}
|
||||
|
||||
while ((whatcode == EUCORSJIS || whatcode == ASCII) && c != '\0')
|
||||
{
|
||||
if ((c = str[i++]) != '\0')
|
||||
{
|
||||
if (c == ESC)
|
||||
{
|
||||
c = str[i++];
|
||||
if (c == '$')
|
||||
{
|
||||
c = str[i++];
|
||||
if (c == 'B')
|
||||
whatcode = NEW;
|
||||
else if (c == '@')
|
||||
whatcode = OLD;
|
||||
}
|
||||
else if (c == '(')
|
||||
{
|
||||
c = str[i++];
|
||||
if (c == 'I')
|
||||
whatcode = ESCI;
|
||||
}
|
||||
else if (c == 'K')
|
||||
whatcode = NEC;
|
||||
}
|
||||
else if ((c >= 129 && c <= 141) || (c >= 143 && c <= 159))
|
||||
whatcode = SJIS;
|
||||
else if (c == SS2)
|
||||
{
|
||||
c = str[i++];
|
||||
if ((c >= 64 && c <= 126) || (c >= 128 && c <= 160)
|
||||
|| (c >= 224 && c <= 252))
|
||||
whatcode = SJIS;
|
||||
else if (c >= 161 && c <= 223)
|
||||
whatcode = EUCORSJIS;
|
||||
}
|
||||
else if (c >= 161 && c <= 223)
|
||||
{
|
||||
c = str[i++];
|
||||
if (c >= 240 && c <= 254)
|
||||
whatcode = EUC;
|
||||
else if (c >= 161 && c <= 223)
|
||||
whatcode = EUCORSJIS;
|
||||
else if (c >= 224 && c <= 239)
|
||||
{
|
||||
whatcode = EUCORSJIS;
|
||||
while (c >= 64 && c != '\0' && whatcode == EUCORSJIS)
|
||||
{
|
||||
if (c >= 129)
|
||||
{
|
||||
if (c <= 141 || (c >= 143 && c <= 159))
|
||||
whatcode = SJIS;
|
||||
else if (c >= 253 && c <= 254)
|
||||
whatcode = EUC;
|
||||
}
|
||||
c = str[i++];
|
||||
}
|
||||
}
|
||||
else if (c <= 159)
|
||||
whatcode = SJIS;
|
||||
}
|
||||
else if (c >= 240 && c <= 254)
|
||||
whatcode = EUC;
|
||||
else if (c >= 224 && c <= 239)
|
||||
{
|
||||
c = str[i++];
|
||||
if ((c >= 64 && c <= 126) || (c >= 128 && c <= 160))
|
||||
whatcode = SJIS;
|
||||
else if (c >= 253 && c <= 254)
|
||||
whatcode = EUC;
|
||||
else if (c >= 161 && c <= 252)
|
||||
whatcode = EUCORSJIS;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#ifdef DEBUG
|
||||
if (whatcode == ASCII)
|
||||
debug ("Kanji code not included.");
|
||||
else if (whatcode == EUCORSJIS)
|
||||
debug ("Kanji code not detected.");
|
||||
else
|
||||
debug ("Kanji code detected at %d byte.", i);
|
||||
#endif
|
||||
|
||||
if (whatcode == EUCORSJIS && oldcode != ASCII)
|
||||
whatcode = oldcode;
|
||||
|
||||
if (whatcode == EUCORSJIS)
|
||||
{
|
||||
if (getenv ("LC_ALL"))
|
||||
lang = getenv ("LC_ALL");
|
||||
else if (getenv ("LC_CTYPE"))
|
||||
lang = getenv ("LC_CTYPE");
|
||||
else if (getenv ("LANG"))
|
||||
lang = getenv ("LANG");
|
||||
|
||||
if (lang)
|
||||
{
|
||||
if (strcmp (lang, "ja_JP.SJIS") == 0 ||
|
||||
#ifdef hpux
|
||||
strcmp (lang, "japanese") == 0 ||
|
||||
#endif
|
||||
strcmp (lang, "ja_JP.mscode") == 0 ||
|
||||
strcmp (lang, "ja_JP.PCK") == 0)
|
||||
whatcode = SJIS;
|
||||
else if (strncmp (lang, "ja", 2) == 0)
|
||||
#ifdef SJISPRE
|
||||
whatcode = SJIS;
|
||||
#else
|
||||
whatcode = EUC;
|
||||
#endif
|
||||
}
|
||||
}
|
||||
|
||||
if (whatcode == EUCORSJIS)
|
||||
#ifdef SJISPRE
|
||||
whatcode = SJIS;
|
||||
#else
|
||||
whatcode = EUC;
|
||||
#endif
|
||||
|
||||
return whatcode;
|
||||
}
|
||||
|
||||
/* SJIStoJIS() is sjis2jis() by Ken Lunde. */
|
||||
|
||||
static void
|
||||
SJIStoJIS (int *p1, int *p2)
|
||||
{
|
||||
register unsigned char c1 = *p1;
|
||||
register unsigned char c2 = *p2;
|
||||
register int adjust = c2 < 159;
|
||||
register int rowOffset = c1 < 160 ? 112 : 176;
|
||||
register int cellOffset = adjust ? (31 + (c2 > 127)) : 126;
|
||||
|
||||
*p1 = ((c1 - rowOffset) << 1) - adjust;
|
||||
*p2 -= cellOffset;
|
||||
}
|
||||
|
||||
/* han2zen() was derived from han2zen() written by Ken Lunde. */
|
||||
|
||||
#define IS_DAKU(c) ((c >= 182 && c <= 196) || (c >= 202 && c <= 206) || (c == 179))
|
||||
#define IS_HANDAKU(c) (c >= 202 && c <= 206)
|
||||
|
||||
static void
|
||||
han2zen (int *p1, int *p2)
|
||||
{
|
||||
int c = *p1;
|
||||
int daku = FALSE;
|
||||
int handaku = FALSE;
|
||||
int mtable[][2] = {
|
||||
{129, 66},
|
||||
{129, 117},
|
||||
{129, 118},
|
||||
{129, 65},
|
||||
{129, 69},
|
||||
{131, 146},
|
||||
{131, 64},
|
||||
{131, 66},
|
||||
{131, 68},
|
||||
{131, 70},
|
||||
{131, 72},
|
||||
{131, 131},
|
||||
{131, 133},
|
||||
{131, 135},
|
||||
{131, 98},
|
||||
{129, 91},
|
||||
{131, 65},
|
||||
{131, 67},
|
||||
{131, 69},
|
||||
{131, 71},
|
||||
{131, 73},
|
||||
{131, 74},
|
||||
{131, 76},
|
||||
{131, 78},
|
||||
{131, 80},
|
||||
{131, 82},
|
||||
{131, 84},
|
||||
{131, 86},
|
||||
{131, 88},
|
||||
{131, 90},
|
||||
{131, 92},
|
||||
{131, 94},
|
||||
{131, 96},
|
||||
{131, 99},
|
||||
{131, 101},
|
||||
{131, 103},
|
||||
{131, 105},
|
||||
{131, 106},
|
||||
{131, 107},
|
||||
{131, 108},
|
||||
{131, 109},
|
||||
{131, 110},
|
||||
{131, 113},
|
||||
{131, 116},
|
||||
{131, 119},
|
||||
{131, 122},
|
||||
{131, 125},
|
||||
{131, 126},
|
||||
{131, 128},
|
||||
{131, 129},
|
||||
{131, 130},
|
||||
{131, 132},
|
||||
{131, 134},
|
||||
{131, 136},
|
||||
{131, 137},
|
||||
{131, 138},
|
||||
{131, 139},
|
||||
{131, 140},
|
||||
{131, 141},
|
||||
{131, 143},
|
||||
{131, 147},
|
||||
{129, 74},
|
||||
{129, 75}
|
||||
};
|
||||
|
||||
if (*p2 == 222 && IS_DAKU (*p1))
|
||||
daku = TRUE; /* Daku-ten */
|
||||
else if (*p2 == 223 && IS_HANDAKU (*p1))
|
||||
handaku = TRUE; /* Han-daku-ten */
|
||||
|
||||
*p1 = mtable[c - 161][0];
|
||||
*p2 = mtable[c - 161][1];
|
||||
|
||||
if (daku)
|
||||
{
|
||||
if ((*p2 >= 74 && *p2 <= 103) || (*p2 >= 110 && *p2 <= 122))
|
||||
(*p2)++;
|
||||
else if (*p2 == 131 && *p2 == 69)
|
||||
*p2 = 148;
|
||||
}
|
||||
else if (handaku && *p2 >= 110 && *p2 <= 122)
|
||||
(*p2) += 2;
|
||||
}
|
||||
|
||||
/* Recast strcpy to handle unsigned chars used below. */
|
||||
#define ustrcpy(A,B) (strcpy((char*)(A),(const char*)(B)))
|
||||
|
||||
static void
|
||||
do_convert (unsigned char *to, unsigned char *from, const char *code)
|
||||
{
|
||||
#ifdef HAVE_ICONV
|
||||
iconv_t cd;
|
||||
size_t from_len, to_len;
|
||||
|
||||
if ((cd = iconv_open (EUCSTR, code)) == (iconv_t) - 1)
|
||||
{
|
||||
error ("iconv_open() error");
|
||||
#ifdef HAVE_ERRNO_H
|
||||
if (errno == EINVAL)
|
||||
error ("invalid code specification: \"%s\" or \"%s\"", EUCSTR, code);
|
||||
#endif
|
||||
strcpy ((char *) to, (const char *) from);
|
||||
return;
|
||||
}
|
||||
|
||||
from_len = strlen ((const char *) from) + 1;
|
||||
to_len = BUFSIZ;
|
||||
|
||||
if ((int) (iconv (cd, (char **) &from, &from_len, (char **) &to, &to_len))
|
||||
== -1)
|
||||
{
|
||||
#ifdef HAVE_ERRNO_H
|
||||
if (errno == EINVAL)
|
||||
error ("invalid end of input string");
|
||||
else if (errno == EILSEQ)
|
||||
error ("invalid code in input string");
|
||||
else if (errno == E2BIG)
|
||||
error ("output buffer overflow at do_convert()");
|
||||
else
|
||||
#endif
|
||||
error ("something happen");
|
||||
strcpy ((char *) to, (const char *) from);
|
||||
return;
|
||||
}
|
||||
|
||||
if (iconv_close (cd) != 0)
|
||||
{
|
||||
error ("iconv_close() error");
|
||||
}
|
||||
#else
|
||||
int p1, p2, i, j;
|
||||
int jisx0208 = FALSE;
|
||||
int hankaku = FALSE;
|
||||
|
||||
j = 0;
|
||||
if (strcmp (code, NEWJISSTR) == 0 || strcmp (code, OLDJISSTR) == 0)
|
||||
{
|
||||
for (i = 0; from[i] != '\0' && j < BUFSIZ; i++)
|
||||
{
|
||||
if (from[i] == ESC)
|
||||
{
|
||||
i++;
|
||||
if (from[i] == '$')
|
||||
{
|
||||
jisx0208 = TRUE;
|
||||
hankaku = FALSE;
|
||||
i++;
|
||||
}
|
||||
else if (from[i] == '(')
|
||||
{
|
||||
jisx0208 = FALSE;
|
||||
i++;
|
||||
if (from[i] == 'I') /* Hankaku Kana */
|
||||
hankaku = TRUE;
|
||||
else
|
||||
hankaku = FALSE;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
if (jisx0208)
|
||||
to[j++] = from[i] + 128;
|
||||
else if (hankaku)
|
||||
{
|
||||
to[j++] = SS2;
|
||||
to[j++] = from[i] + 128;
|
||||
}
|
||||
else
|
||||
to[j++] = from[i];
|
||||
}
|
||||
}
|
||||
}
|
||||
else if (strcmp (code, SJISSTR) == 0)
|
||||
{
|
||||
for (i = 0; from[i] != '\0' && j < BUFSIZ; i++)
|
||||
{
|
||||
p1 = from[i];
|
||||
if (p1 < 127)
|
||||
to[j++] = p1;
|
||||
else if ((p1 >= 161) && (p1 <= 223))
|
||||
{ /* Hankaku Kana */
|
||||
to[j++] = SS2;
|
||||
to[j++] = p1;
|
||||
}
|
||||
else
|
||||
{
|
||||
p2 = from[++i];
|
||||
SJIStoJIS (&p1, &p2);
|
||||
to[j++] = p1 + 128;
|
||||
to[j++] = p2 + 128;
|
||||
}
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
error ("invalid code specification: \"%s\"", code);
|
||||
return;
|
||||
}
|
||||
|
||||
if (j >= BUFSIZ)
|
||||
{
|
||||
error ("output buffer overflow at do_convert()");
|
||||
ustrcpy (to, from);
|
||||
}
|
||||
else
|
||||
to[j] = '\0';
|
||||
#endif /* HAVE_ICONV */
|
||||
}
|
||||
|
||||
static int
|
||||
do_check_and_conv (unsigned char *to, unsigned char *from)
|
||||
{
|
||||
static unsigned char tmp[BUFSIZ];
|
||||
int p1, p2, i, j;
|
||||
int kanji = TRUE;
|
||||
|
||||
switch (DetectKanjiCode (from))
|
||||
{
|
||||
case NEW:
|
||||
debug ("Kanji code is New JIS.");
|
||||
do_convert (tmp, from, NEWJISSTR);
|
||||
break;
|
||||
case OLD:
|
||||
debug ("Kanji code is Old JIS.");
|
||||
do_convert (tmp, from, OLDJISSTR);
|
||||
break;
|
||||
case ESCI:
|
||||
debug
|
||||
("This string includes Hankaku-Kana (jisx0201) escape sequence [ESC] + ( + I.");
|
||||
do_convert (tmp, from, NEWJISSTR);
|
||||
break;
|
||||
case NEC:
|
||||
debug ("Kanji code is NEC Kanji.");
|
||||
error ("cannot convert NEC Kanji.");
|
||||
ustrcpy (tmp, from);
|
||||
kanji = FALSE;
|
||||
break;
|
||||
case EUC:
|
||||
debug ("Kanji code is EUC.");
|
||||
ustrcpy (tmp, from);
|
||||
break;
|
||||
case SJIS:
|
||||
debug ("Kanji code is SJIS.");
|
||||
do_convert (tmp, from, SJISSTR);
|
||||
break;
|
||||
case EUCORSJIS:
|
||||
debug ("Kanji code is EUC or SJIS.");
|
||||
ustrcpy (tmp, from);
|
||||
kanji = FALSE;
|
||||
break;
|
||||
case ASCII:
|
||||
debug ("This is ASCII string.");
|
||||
ustrcpy (tmp, from);
|
||||
kanji = FALSE;
|
||||
break;
|
||||
default:
|
||||
debug ("This string includes unknown code.");
|
||||
ustrcpy (tmp, from);
|
||||
kanji = FALSE;
|
||||
break;
|
||||
}
|
||||
|
||||
/* Hankaku Kana ---> Zenkaku Kana */
|
||||
if (kanji)
|
||||
{
|
||||
j = 0;
|
||||
for (i = 0; tmp[i] != '\0' && j < BUFSIZ; i++)
|
||||
{
|
||||
if (tmp[i] == SS2)
|
||||
{
|
||||
p1 = tmp[++i];
|
||||
if (tmp[i + 1] == SS2)
|
||||
{
|
||||
p2 = tmp[i + 2];
|
||||
if (p2 == 222 || p2 == 223)
|
||||
i += 2;
|
||||
else
|
||||
p2 = 0;
|
||||
}
|
||||
else
|
||||
p2 = 0;
|
||||
han2zen (&p1, &p2);
|
||||
SJIStoJIS (&p1, &p2);
|
||||
to[j++] = p1 + 128;
|
||||
to[j++] = p2 + 128;
|
||||
}
|
||||
else
|
||||
to[j++] = tmp[i];
|
||||
}
|
||||
|
||||
if (j >= BUFSIZ)
|
||||
{
|
||||
error ("output buffer overflow at Hankaku --> Zenkaku");
|
||||
ustrcpy (to, tmp);
|
||||
}
|
||||
else
|
||||
to[j] = '\0';
|
||||
}
|
||||
else
|
||||
ustrcpy (to, tmp);
|
||||
|
||||
return kanji;
|
||||
}
|
||||
|
||||
int
|
||||
any2eucjp (unsigned char *dest, unsigned char *src, unsigned int dest_max)
|
||||
{
|
||||
static unsigned char tmp_dest[BUFSIZ];
|
||||
int ret;
|
||||
|
||||
if (strlen ((const char *) src) >= BUFSIZ)
|
||||
{
|
||||
error ("input string too large");
|
||||
return -1;
|
||||
}
|
||||
if (dest_max > BUFSIZ)
|
||||
{
|
||||
error
|
||||
("invalid maximum size of destination\nit should be less than %d.",
|
||||
BUFSIZ);
|
||||
return -1;
|
||||
}
|
||||
ret = do_check_and_conv (tmp_dest, src);
|
||||
if (strlen ((const char *) tmp_dest) >= dest_max)
|
||||
{
|
||||
error ("output buffer overflow");
|
||||
ustrcpy (dest, src);
|
||||
return -1;
|
||||
}
|
||||
ustrcpy (dest, tmp_dest);
|
||||
return ret;
|
||||
}
|
||||
|
||||
#if 0
|
||||
unsigned int
|
||||
strwidth (unsigned char *s)
|
||||
{
|
||||
unsigned char *t;
|
||||
unsigned int i;
|
||||
|
||||
t = (unsigned char *) gdMalloc (BUFSIZ);
|
||||
any2eucjp (t, s, BUFSIZ);
|
||||
i = strlen (t);
|
||||
gdFree (t);
|
||||
return i;
|
||||
}
|
||||
|
||||
#ifdef DEBUG
|
||||
int
|
||||
main ()
|
||||
{
|
||||
unsigned char input[BUFSIZ];
|
||||
unsigned char *output;
|
||||
unsigned char *str;
|
||||
int c, i = 0;
|
||||
|
||||
while ((c = fgetc (stdin)) != '\n' && i < BUFSIZ)
|
||||
input[i++] = c;
|
||||
input[i] = '\0';
|
||||
|
||||
printf ("input : %d bytes\n", strlen ((const char *) input));
|
||||
printf ("output: %d bytes\n", strwidth (input));
|
||||
|
||||
output = (unsigned char *) gdMalloc (BUFSIZ);
|
||||
any2eucjp (output, input, BUFSIZ);
|
||||
str = output;
|
||||
while (*str != '\0')
|
||||
putchar (*(str++));
|
||||
putchar ('\n');
|
||||
gdFree (output);
|
||||
|
||||
return 0;
|
||||
}
|
||||
#endif
|
||||
#endif
|
|
@ -1,726 +0,0 @@
|
|||
|
||||
int gdCosT[] = {
|
||||
1024,
|
||||
1023,
|
||||
1023,
|
||||
1022,
|
||||
1021,
|
||||
1020,
|
||||
1018,
|
||||
1016,
|
||||
1014,
|
||||
1011,
|
||||
1008,
|
||||
1005,
|
||||
1001,
|
||||
997,
|
||||
993,
|
||||
989,
|
||||
984,
|
||||
979,
|
||||
973,
|
||||
968,
|
||||
962,
|
||||
955,
|
||||
949,
|
||||
942,
|
||||
935,
|
||||
928,
|
||||
920,
|
||||
912,
|
||||
904,
|
||||
895,
|
||||
886,
|
||||
877,
|
||||
868,
|
||||
858,
|
||||
848,
|
||||
838,
|
||||
828,
|
||||
817,
|
||||
806,
|
||||
795,
|
||||
784,
|
||||
772,
|
||||
760,
|
||||
748,
|
||||
736,
|
||||
724,
|
||||
711,
|
||||
698,
|
||||
685,
|
||||
671,
|
||||
658,
|
||||
644,
|
||||
630,
|
||||
616,
|
||||
601,
|
||||
587,
|
||||
572,
|
||||
557,
|
||||
542,
|
||||
527,
|
||||
512,
|
||||
496,
|
||||
480,
|
||||
464,
|
||||
448,
|
||||
432,
|
||||
416,
|
||||
400,
|
||||
383,
|
||||
366,
|
||||
350,
|
||||
333,
|
||||
316,
|
||||
299,
|
||||
282,
|
||||
265,
|
||||
247,
|
||||
230,
|
||||
212,
|
||||
195,
|
||||
177,
|
||||
160,
|
||||
142,
|
||||
124,
|
||||
107,
|
||||
89,
|
||||
71,
|
||||
53,
|
||||
35,
|
||||
17,
|
||||
0,
|
||||
-17,
|
||||
-35,
|
||||
-53,
|
||||
-71,
|
||||
-89,
|
||||
-107,
|
||||
-124,
|
||||
-142,
|
||||
-160,
|
||||
-177,
|
||||
-195,
|
||||
-212,
|
||||
-230,
|
||||
-247,
|
||||
-265,
|
||||
-282,
|
||||
-299,
|
||||
-316,
|
||||
-333,
|
||||
-350,
|
||||
-366,
|
||||
-383,
|
||||
-400,
|
||||
-416,
|
||||
-432,
|
||||
-448,
|
||||
-464,
|
||||
-480,
|
||||
-496,
|
||||
-512,
|
||||
-527,
|
||||
-542,
|
||||
-557,
|
||||
-572,
|
||||
-587,
|
||||
-601,
|
||||
-616,
|
||||
-630,
|
||||
-644,
|
||||
-658,
|
||||
-671,
|
||||
-685,
|
||||
-698,
|
||||
-711,
|
||||
-724,
|
||||
-736,
|
||||
-748,
|
||||
-760,
|
||||
-772,
|
||||
-784,
|
||||
-795,
|
||||
-806,
|
||||
-817,
|
||||
-828,
|
||||
-838,
|
||||
-848,
|
||||
-858,
|
||||
-868,
|
||||
-877,
|
||||
-886,
|
||||
-895,
|
||||
-904,
|
||||
-912,
|
||||
-920,
|
||||
-928,
|
||||
-935,
|
||||
-942,
|
||||
-949,
|
||||
-955,
|
||||
-962,
|
||||
-968,
|
||||
-973,
|
||||
-979,
|
||||
-984,
|
||||
-989,
|
||||
-993,
|
||||
-997,
|
||||
-1001,
|
||||
-1005,
|
||||
-1008,
|
||||
-1011,
|
||||
-1014,
|
||||
-1016,
|
||||
-1018,
|
||||
-1020,
|
||||
-1021,
|
||||
-1022,
|
||||
-1023,
|
||||
-1023,
|
||||
-1024,
|
||||
-1023,
|
||||
-1023,
|
||||
-1022,
|
||||
-1021,
|
||||
-1020,
|
||||
-1018,
|
||||
-1016,
|
||||
-1014,
|
||||
-1011,
|
||||
-1008,
|
||||
-1005,
|
||||
-1001,
|
||||
-997,
|
||||
-993,
|
||||
-989,
|
||||
-984,
|
||||
-979,
|
||||
-973,
|
||||
-968,
|
||||
-962,
|
||||
-955,
|
||||
-949,
|
||||
-942,
|
||||
-935,
|
||||
-928,
|
||||
-920,
|
||||
-912,
|
||||
-904,
|
||||
-895,
|
||||
-886,
|
||||
-877,
|
||||
-868,
|
||||
-858,
|
||||
-848,
|
||||
-838,
|
||||
-828,
|
||||
-817,
|
||||
-806,
|
||||
-795,
|
||||
-784,
|
||||
-772,
|
||||
-760,
|
||||
-748,
|
||||
-736,
|
||||
-724,
|
||||
-711,
|
||||
-698,
|
||||
-685,
|
||||
-671,
|
||||
-658,
|
||||
-644,
|
||||
-630,
|
||||
-616,
|
||||
-601,
|
||||
-587,
|
||||
-572,
|
||||
-557,
|
||||
-542,
|
||||
-527,
|
||||
-512,
|
||||
-496,
|
||||
-480,
|
||||
-464,
|
||||
-448,
|
||||
-432,
|
||||
-416,
|
||||
-400,
|
||||
-383,
|
||||
-366,
|
||||
-350,
|
||||
-333,
|
||||
-316,
|
||||
-299,
|
||||
-282,
|
||||
-265,
|
||||
-247,
|
||||
-230,
|
||||
-212,
|
||||
-195,
|
||||
-177,
|
||||
-160,
|
||||
-142,
|
||||
-124,
|
||||
-107,
|
||||
-89,
|
||||
-71,
|
||||
-53,
|
||||
-35,
|
||||
-17,
|
||||
0,
|
||||
17,
|
||||
35,
|
||||
53,
|
||||
71,
|
||||
89,
|
||||
107,
|
||||
124,
|
||||
142,
|
||||
160,
|
||||
177,
|
||||
195,
|
||||
212,
|
||||
230,
|
||||
247,
|
||||
265,
|
||||
282,
|
||||
299,
|
||||
316,
|
||||
333,
|
||||
350,
|
||||
366,
|
||||
383,
|
||||
400,
|
||||
416,
|
||||
432,
|
||||
448,
|
||||
464,
|
||||
480,
|
||||
496,
|
||||
512,
|
||||
527,
|
||||
542,
|
||||
557,
|
||||
572,
|
||||
587,
|
||||
601,
|
||||
616,
|
||||
630,
|
||||
644,
|
||||
658,
|
||||
671,
|
||||
685,
|
||||
698,
|
||||
711,
|
||||
724,
|
||||
736,
|
||||
748,
|
||||
760,
|
||||
772,
|
||||
784,
|
||||
795,
|
||||
806,
|
||||
817,
|
||||
828,
|
||||
838,
|
||||
848,
|
||||
858,
|
||||
868,
|
||||
877,
|
||||
886,
|
||||
895,
|
||||
904,
|
||||
912,
|
||||
920,
|
||||
928,
|
||||
935,
|
||||
942,
|
||||
949,
|
||||
955,
|
||||
962,
|
||||
968,
|
||||
973,
|
||||
979,
|
||||
984,
|
||||
989,
|
||||
993,
|
||||
997,
|
||||
1001,
|
||||
1005,
|
||||
1008,
|
||||
1011,
|
||||
1014,
|
||||
1016,
|
||||
1018,
|
||||
1020,
|
||||
1021,
|
||||
1022,
|
||||
1023,
|
||||
1023
|
||||
};
|
||||
|
||||
int gdSinT[] = {
|
||||
0,
|
||||
17,
|
||||
35,
|
||||
53,
|
||||
71,
|
||||
89,
|
||||
107,
|
||||
124,
|
||||
142,
|
||||
160,
|
||||
177,
|
||||
195,
|
||||
212,
|
||||
230,
|
||||
247,
|
||||
265,
|
||||
282,
|
||||
299,
|
||||
316,
|
||||
333,
|
||||
350,
|
||||
366,
|
||||
383,
|
||||
400,
|
||||
416,
|
||||
432,
|
||||
448,
|
||||
464,
|
||||
480,
|
||||
496,
|
||||
512,
|
||||
527,
|
||||
542,
|
||||
557,
|
||||
572,
|
||||
587,
|
||||
601,
|
||||
616,
|
||||
630,
|
||||
644,
|
||||
658,
|
||||
671,
|
||||
685,
|
||||
698,
|
||||
711,
|
||||
724,
|
||||
736,
|
||||
748,
|
||||
760,
|
||||
772,
|
||||
784,
|
||||
795,
|
||||
806,
|
||||
817,
|
||||
828,
|
||||
838,
|
||||
848,
|
||||
858,
|
||||
868,
|
||||
877,
|
||||
886,
|
||||
895,
|
||||
904,
|
||||
912,
|
||||
920,
|
||||
928,
|
||||
935,
|
||||
942,
|
||||
949,
|
||||
955,
|
||||
962,
|
||||
968,
|
||||
973,
|
||||
979,
|
||||
984,
|
||||
989,
|
||||
993,
|
||||
997,
|
||||
1001,
|
||||
1005,
|
||||
1008,
|
||||
1011,
|
||||
1014,
|
||||
1016,
|
||||
1018,
|
||||
1020,
|
||||
1021,
|
||||
1022,
|
||||
1023,
|
||||
1023,
|
||||
1024,
|
||||
1023,
|
||||
1023,
|
||||
1022,
|
||||
1021,
|
||||
1020,
|
||||
1018,
|
||||
1016,
|
||||
1014,
|
||||
1011,
|
||||
1008,
|
||||
1005,
|
||||
1001,
|
||||
997,
|
||||
993,
|
||||
989,
|
||||
984,
|
||||
979,
|
||||
973,
|
||||
968,
|
||||
962,
|
||||
955,
|
||||
949,
|
||||
942,
|
||||
935,
|
||||
928,
|
||||
920,
|
||||
912,
|
||||
904,
|
||||
895,
|
||||
886,
|
||||
877,
|
||||
868,
|
||||
858,
|
||||
848,
|
||||
838,
|
||||
828,
|
||||
817,
|
||||
806,
|
||||
795,
|
||||
784,
|
||||
772,
|
||||
760,
|
||||
748,
|
||||
736,
|
||||
724,
|
||||
711,
|
||||
698,
|
||||
685,
|
||||
671,
|
||||
658,
|
||||
644,
|
||||
630,
|
||||
616,
|
||||
601,
|
||||
587,
|
||||
572,
|
||||
557,
|
||||
542,
|
||||
527,
|
||||
512,
|
||||
496,
|
||||
480,
|
||||
464,
|
||||
448,
|
||||
432,
|
||||
416,
|
||||
400,
|
||||
383,
|
||||
366,
|
||||
350,
|
||||
333,
|
||||
316,
|
||||
299,
|
||||
282,
|
||||
265,
|
||||
247,
|
||||
230,
|
||||
212,
|
||||
195,
|
||||
177,
|
||||
160,
|
||||
142,
|
||||
124,
|
||||
107,
|
||||
89,
|
||||
71,
|
||||
53,
|
||||
35,
|
||||
17,
|
||||
0,
|
||||
-17,
|
||||
-35,
|
||||
-53,
|
||||
-71,
|
||||
-89,
|
||||
-107,
|
||||
-124,
|
||||
-142,
|
||||
-160,
|
||||
-177,
|
||||
-195,
|
||||
-212,
|
||||
-230,
|
||||
-247,
|
||||
-265,
|
||||
-282,
|
||||
-299,
|
||||
-316,
|
||||
-333,
|
||||
-350,
|
||||
-366,
|
||||
-383,
|
||||
-400,
|
||||
-416,
|
||||
-432,
|
||||
-448,
|
||||
-464,
|
||||
-480,
|
||||
-496,
|
||||
-512,
|
||||
-527,
|
||||
-542,
|
||||
-557,
|
||||
-572,
|
||||
-587,
|
||||
-601,
|
||||
-616,
|
||||
-630,
|
||||
-644,
|
||||
-658,
|
||||
-671,
|
||||
-685,
|
||||
-698,
|
||||
-711,
|
||||
-724,
|
||||
-736,
|
||||
-748,
|
||||
-760,
|
||||
-772,
|
||||
-784,
|
||||
-795,
|
||||
-806,
|
||||
-817,
|
||||
-828,
|
||||
-838,
|
||||
-848,
|
||||
-858,
|
||||
-868,
|
||||
-877,
|
||||
-886,
|
||||
-895,
|
||||
-904,
|
||||
-912,
|
||||
-920,
|
||||
-928,
|
||||
-935,
|
||||
-942,
|
||||
-949,
|
||||
-955,
|
||||
-962,
|
||||
-968,
|
||||
-973,
|
||||
-979,
|
||||
-984,
|
||||
-989,
|
||||
-993,
|
||||
-997,
|
||||
-1001,
|
||||
-1005,
|
||||
-1008,
|
||||
-1011,
|
||||
-1014,
|
||||
-1016,
|
||||
-1018,
|
||||
-1020,
|
||||
-1021,
|
||||
-1022,
|
||||
-1023,
|
||||
-1023,
|
||||
-1024,
|
||||
-1023,
|
||||
-1023,
|
||||
-1022,
|
||||
-1021,
|
||||
-1020,
|
||||
-1018,
|
||||
-1016,
|
||||
-1014,
|
||||
-1011,
|
||||
-1008,
|
||||
-1005,
|
||||
-1001,
|
||||
-997,
|
||||
-993,
|
||||
-989,
|
||||
-984,
|
||||
-979,
|
||||
-973,
|
||||
-968,
|
||||
-962,
|
||||
-955,
|
||||
-949,
|
||||
-942,
|
||||
-935,
|
||||
-928,
|
||||
-920,
|
||||
-912,
|
||||
-904,
|
||||
-895,
|
||||
-886,
|
||||
-877,
|
||||
-868,
|
||||
-858,
|
||||
-848,
|
||||
-838,
|
||||
-828,
|
||||
-817,
|
||||
-806,
|
||||
-795,
|
||||
-784,
|
||||
-772,
|
||||
-760,
|
||||
-748,
|
||||
-736,
|
||||
-724,
|
||||
-711,
|
||||
-698,
|
||||
-685,
|
||||
-671,
|
||||
-658,
|
||||
-644,
|
||||
-630,
|
||||
-616,
|
||||
-601,
|
||||
-587,
|
||||
-572,
|
||||
-557,
|
||||
-542,
|
||||
-527,
|
||||
-512,
|
||||
-496,
|
||||
-480,
|
||||
-464,
|
||||
-448,
|
||||
-432,
|
||||
-416,
|
||||
-400,
|
||||
-383,
|
||||
-366,
|
||||
-350,
|
||||
-333,
|
||||
-316,
|
||||
-299,
|
||||
-282,
|
||||
-265,
|
||||
-247,
|
||||
-230,
|
||||
-212,
|
||||
-195,
|
||||
-177,
|
||||
-160,
|
||||
-142,
|
||||
-124,
|
||||
-107,
|
||||
-89,
|
||||
-71,
|
||||
-53,
|
||||
-35,
|
||||
-17
|
||||
};
|
|
@ -1,154 +0,0 @@
|
|||
|
||||
/*
|
||||
add ability to load xpm files to gd, requires the xpm
|
||||
library.
|
||||
Caolan.McNamara@ul.ie
|
||||
http://www.csn.ul.ie/~caolan
|
||||
*/
|
||||
|
||||
#ifdef HAVE_CONFIG_H
|
||||
#include "config.h"
|
||||
#endif
|
||||
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
#include "gd.h"
|
||||
#include "gdhelpers.h"
|
||||
|
||||
#ifndef HAVE_LIBXPM
|
||||
gdImagePtr
|
||||
gdImageCreateFromXpm (char *filename)
|
||||
{
|
||||
fprintf (stderr, "libgd was not built with xpm support\n");
|
||||
return (NULL);
|
||||
}
|
||||
|
||||
#else
|
||||
|
||||
#include <X11/xpm.h>
|
||||
|
||||
gdImagePtr
|
||||
gdImageCreateFromXpm (char *filename)
|
||||
{
|
||||
XpmInfo info;
|
||||
XpmImage image;
|
||||
int i, j, k, number;
|
||||
char buf[5];
|
||||
gdImagePtr im = 0;
|
||||
char *apixel;
|
||||
int *pointer;
|
||||
int red = 0, green = 0, blue = 0;
|
||||
int *colors;
|
||||
int ret;
|
||||
|
||||
ret = XpmReadFileToXpmImage (filename, &image, &info);
|
||||
if (ret != XpmSuccess)
|
||||
return 0;
|
||||
|
||||
if (!(im = gdImageCreate (image.width, image.height)))
|
||||
return 0;
|
||||
|
||||
number = image.ncolors;
|
||||
colors = (int *) gdMalloc (sizeof (int) * number);
|
||||
if (colors == NULL)
|
||||
return (0);
|
||||
for (i = 0; i < number; i++)
|
||||
{
|
||||
switch (strlen (image.colorTable[i].c_color))
|
||||
{
|
||||
case 4:
|
||||
buf[1] = '\0';
|
||||
buf[0] = image.colorTable[i].c_color[1];
|
||||
red = strtol (buf, NULL, 16);
|
||||
|
||||
buf[0] = image.colorTable[i].c_color[3];
|
||||
green = strtol (buf, NULL, 16);
|
||||
|
||||
buf[0] = image.colorTable[i].c_color[5];
|
||||
blue = strtol (buf, NULL, 16);
|
||||
break;
|
||||
case 7:
|
||||
buf[2] = '\0';
|
||||
buf[0] = image.colorTable[i].c_color[1];
|
||||
buf[1] = image.colorTable[i].c_color[2];
|
||||
red = strtol (buf, NULL, 16);
|
||||
|
||||
buf[0] = image.colorTable[i].c_color[3];
|
||||
buf[1] = image.colorTable[i].c_color[4];
|
||||
green = strtol (buf, NULL, 16);
|
||||
|
||||
buf[0] = image.colorTable[i].c_color[5];
|
||||
buf[1] = image.colorTable[i].c_color[6];
|
||||
blue = strtol (buf, NULL, 16);
|
||||
break;
|
||||
case 10:
|
||||
buf[3] = '\0';
|
||||
buf[0] = image.colorTable[i].c_color[1];
|
||||
buf[1] = image.colorTable[i].c_color[2];
|
||||
buf[2] = image.colorTable[i].c_color[3];
|
||||
red = strtol (buf, NULL, 16);
|
||||
red /= 64;
|
||||
|
||||
buf[0] = image.colorTable[i].c_color[4];
|
||||
buf[1] = image.colorTable[i].c_color[5];
|
||||
buf[2] = image.colorTable[i].c_color[6];
|
||||
green = strtol (buf, NULL, 16);
|
||||
green /= 64;
|
||||
|
||||
buf[0] = image.colorTable[i].c_color[7];
|
||||
buf[1] = image.colorTable[i].c_color[8];
|
||||
buf[2] = image.colorTable[i].c_color[9];
|
||||
blue = strtol (buf, NULL, 16);
|
||||
blue /= 64;
|
||||
break;
|
||||
case 13:
|
||||
buf[4] = '\0';
|
||||
buf[0] = image.colorTable[i].c_color[1];
|
||||
buf[1] = image.colorTable[i].c_color[2];
|
||||
buf[2] = image.colorTable[i].c_color[3];
|
||||
buf[3] = image.colorTable[i].c_color[4];
|
||||
red = strtol (buf, NULL, 16);
|
||||
red /= 256;
|
||||
|
||||
buf[0] = image.colorTable[i].c_color[5];
|
||||
buf[1] = image.colorTable[i].c_color[6];
|
||||
buf[2] = image.colorTable[i].c_color[7];
|
||||
buf[3] = image.colorTable[i].c_color[8];
|
||||
green = strtol (buf, NULL, 16);
|
||||
green /= 256;
|
||||
|
||||
buf[0] = image.colorTable[i].c_color[9];
|
||||
buf[1] = image.colorTable[i].c_color[10];
|
||||
buf[2] = image.colorTable[i].c_color[11];
|
||||
buf[3] = image.colorTable[i].c_color[12];
|
||||
blue = strtol (buf, NULL, 16);
|
||||
blue /= 256;
|
||||
break;
|
||||
}
|
||||
|
||||
|
||||
colors[i] = gdImageColorResolve (im, red, green, blue);
|
||||
if (colors[i] == -1)
|
||||
fprintf (stderr, "ARRRGH\n");
|
||||
}
|
||||
|
||||
apixel = (char *) gdMalloc (image.cpp + 1);
|
||||
if (apixel == NULL)
|
||||
return (0);
|
||||
apixel[image.cpp] = '\0';
|
||||
|
||||
pointer = (int *) image.data;
|
||||
for (i = 0; i < image.height; i++)
|
||||
{
|
||||
for (j = 0; j < image.width; j++)
|
||||
{
|
||||
k = *pointer++;
|
||||
gdImageSetPixel (im, j, i, colors[k]);
|
||||
}
|
||||
}
|
||||
gdFree (apixel);
|
||||
gdFree (colors);
|
||||
return (im);
|
||||
}
|
||||
#endif /* HAVE_LIBXPM */
|
|
@ -1,875 +0,0 @@
|
|||
/* gzio.c -- IO on .gz files
|
||||
* Copyright (C) 1995-2002 Jean-loup Gailly.
|
||||
* For conditions of distribution and use, see copyright notice in zlib.h
|
||||
*
|
||||
* Compile this file with -DNO_DEFLATE to avoid the compression code.
|
||||
*/
|
||||
|
||||
/* @(#) $Id: gzio.c,v 1.1 2004/03/01 20:54:49 cozmic Exp $ */
|
||||
|
||||
#include <stdio.h>
|
||||
|
||||
#include "zutil.h"
|
||||
|
||||
struct internal_state {int dummy;}; /* for buggy compilers */
|
||||
|
||||
#ifndef Z_BUFSIZE
|
||||
# ifdef MAXSEG_64K
|
||||
# define Z_BUFSIZE 4096 /* minimize memory usage for 16-bit DOS */
|
||||
# else
|
||||
# define Z_BUFSIZE 16384
|
||||
# endif
|
||||
#endif
|
||||
#ifndef Z_PRINTF_BUFSIZE
|
||||
# define Z_PRINTF_BUFSIZE 4096
|
||||
#endif
|
||||
|
||||
#define ALLOC(size) malloc(size)
|
||||
#define TRYFREE(p) {if (p) free(p);}
|
||||
|
||||
static int gz_magic[2] = {0x1f, 0x8b}; /* gzip magic header */
|
||||
|
||||
/* gzip flag byte */
|
||||
#define ASCII_FLAG 0x01 /* bit 0 set: file probably ascii text */
|
||||
#define HEAD_CRC 0x02 /* bit 1 set: header CRC present */
|
||||
#define EXTRA_FIELD 0x04 /* bit 2 set: extra field present */
|
||||
#define ORIG_NAME 0x08 /* bit 3 set: original file name present */
|
||||
#define COMMENT 0x10 /* bit 4 set: file comment present */
|
||||
#define RESERVED 0xE0 /* bits 5..7: reserved */
|
||||
|
||||
typedef struct gz_stream {
|
||||
z_stream stream;
|
||||
int z_err; /* error code for last stream operation */
|
||||
int z_eof; /* set if end of input file */
|
||||
FILE *file; /* .gz file */
|
||||
Byte *inbuf; /* input buffer */
|
||||
Byte *outbuf; /* output buffer */
|
||||
uLong crc; /* crc32 of uncompressed data */
|
||||
char *msg; /* error message */
|
||||
char *path; /* path name for debugging only */
|
||||
int transparent; /* 1 if input file is not a .gz file */
|
||||
char mode; /* 'w' or 'r' */
|
||||
long startpos; /* start of compressed data in file (header skipped) */
|
||||
} gz_stream;
|
||||
|
||||
|
||||
local gzFile gz_open OF((const char *path, const char *mode, int fd));
|
||||
local int do_flush OF((gzFile file, int flush));
|
||||
local int get_byte OF((gz_stream *s));
|
||||
local void check_header OF((gz_stream *s));
|
||||
local int destroy OF((gz_stream *s));
|
||||
local void putLong OF((FILE *file, uLong x));
|
||||
local uLong getLong OF((gz_stream *s));
|
||||
|
||||
/* ===========================================================================
|
||||
Opens a gzip (.gz) file for reading or writing. The mode parameter
|
||||
is as in fopen ("rb" or "wb"). The file is given either by file descriptor
|
||||
or path name (if fd == -1).
|
||||
gz_open return NULL if the file could not be opened or if there was
|
||||
insufficient memory to allocate the (de)compression state; errno
|
||||
can be checked to distinguish the two cases (if errno is zero, the
|
||||
zlib error is Z_MEM_ERROR).
|
||||
*/
|
||||
local gzFile gz_open (path, mode, fd)
|
||||
const char *path;
|
||||
const char *mode;
|
||||
int fd;
|
||||
{
|
||||
int err;
|
||||
int level = Z_DEFAULT_COMPRESSION; /* compression level */
|
||||
int strategy = Z_DEFAULT_STRATEGY; /* compression strategy */
|
||||
char *p = (char*)mode;
|
||||
gz_stream *s;
|
||||
char fmode[80]; /* copy of mode, without the compression level */
|
||||
char *m = fmode;
|
||||
|
||||
if (!path || !mode) return Z_NULL;
|
||||
|
||||
s = (gz_stream *)ALLOC(sizeof(gz_stream));
|
||||
if (!s) return Z_NULL;
|
||||
|
||||
s->stream.zalloc = (alloc_func)0;
|
||||
s->stream.zfree = (free_func)0;
|
||||
s->stream.opaque = (voidpf)0;
|
||||
s->stream.next_in = s->inbuf = Z_NULL;
|
||||
s->stream.next_out = s->outbuf = Z_NULL;
|
||||
s->stream.avail_in = s->stream.avail_out = 0;
|
||||
s->file = NULL;
|
||||
s->z_err = Z_OK;
|
||||
s->z_eof = 0;
|
||||
s->crc = crc32(0L, Z_NULL, 0);
|
||||
s->msg = NULL;
|
||||
s->transparent = 0;
|
||||
|
||||
s->path = (char*)ALLOC(strlen(path)+1);
|
||||
if (s->path == NULL) {
|
||||
return destroy(s), (gzFile)Z_NULL;
|
||||
}
|
||||
strcpy(s->path, path); /* do this early for debugging */
|
||||
|
||||
s->mode = '\0';
|
||||
do {
|
||||
if (*p == 'r') s->mode = 'r';
|
||||
if (*p == 'w' || *p == 'a') s->mode = 'w';
|
||||
if (*p >= '0' && *p <= '9') {
|
||||
level = *p - '0';
|
||||
} else if (*p == 'f') {
|
||||
strategy = Z_FILTERED;
|
||||
} else if (*p == 'h') {
|
||||
strategy = Z_HUFFMAN_ONLY;
|
||||
} else {
|
||||
*m++ = *p; /* copy the mode */
|
||||
}
|
||||
} while (*p++ && m != fmode + sizeof(fmode));
|
||||
if (s->mode == '\0') return destroy(s), (gzFile)Z_NULL;
|
||||
|
||||
if (s->mode == 'w') {
|
||||
#ifdef NO_DEFLATE
|
||||
err = Z_STREAM_ERROR;
|
||||
#else
|
||||
err = deflateInit2(&(s->stream), level,
|
||||
Z_DEFLATED, -MAX_WBITS, DEF_MEM_LEVEL, strategy);
|
||||
/* windowBits is passed < 0 to suppress zlib header */
|
||||
|
||||
s->stream.next_out = s->outbuf = (Byte*)ALLOC(Z_BUFSIZE);
|
||||
#endif
|
||||
if (err != Z_OK || s->outbuf == Z_NULL) {
|
||||
return destroy(s), (gzFile)Z_NULL;
|
||||
}
|
||||
} else {
|
||||
s->stream.next_in = s->inbuf = (Byte*)ALLOC(Z_BUFSIZE);
|
||||
|
||||
err = inflateInit2(&(s->stream), -MAX_WBITS);
|
||||
/* windowBits is passed < 0 to tell that there is no zlib header.
|
||||
* Note that in this case inflate *requires* an extra "dummy" byte
|
||||
* after the compressed stream in order to complete decompression and
|
||||
* return Z_STREAM_END. Here the gzip CRC32 ensures that 4 bytes are
|
||||
* present after the compressed stream.
|
||||
*/
|
||||
if (err != Z_OK || s->inbuf == Z_NULL) {
|
||||
return destroy(s), (gzFile)Z_NULL;
|
||||
}
|
||||
}
|
||||
s->stream.avail_out = Z_BUFSIZE;
|
||||
|
||||
errno = 0;
|
||||
s->file = fd < 0 ? F_OPEN(path, fmode) : (FILE*)fdopen(fd, fmode);
|
||||
|
||||
if (s->file == NULL) {
|
||||
return destroy(s), (gzFile)Z_NULL;
|
||||
}
|
||||
if (s->mode == 'w') {
|
||||
/* Write a very simple .gz header:
|
||||
*/
|
||||
fprintf(s->file, "%c%c%c%c%c%c%c%c%c%c", gz_magic[0], gz_magic[1],
|
||||
Z_DEFLATED, 0 /*flags*/, 0,0,0,0 /*time*/, 0 /*xflags*/, OS_CODE);
|
||||
s->startpos = 10L;
|
||||
/* We use 10L instead of ftell(s->file) to because ftell causes an
|
||||
* fflush on some systems. This version of the library doesn't use
|
||||
* startpos anyway in write mode, so this initialization is not
|
||||
* necessary.
|
||||
*/
|
||||
} else {
|
||||
check_header(s); /* skip the .gz header */
|
||||
s->startpos = (ftell(s->file) - s->stream.avail_in);
|
||||
}
|
||||
|
||||
return (gzFile)s;
|
||||
}
|
||||
|
||||
/* ===========================================================================
|
||||
Opens a gzip (.gz) file for reading or writing.
|
||||
*/
|
||||
gzFile ZEXPORT gzopen (path, mode)
|
||||
const char *path;
|
||||
const char *mode;
|
||||
{
|
||||
return gz_open (path, mode, -1);
|
||||
}
|
||||
|
||||
/* ===========================================================================
|
||||
Associate a gzFile with the file descriptor fd. fd is not dup'ed here
|
||||
to mimic the behavio(u)r of fdopen.
|
||||
*/
|
||||
gzFile ZEXPORT gzdopen (fd, mode)
|
||||
int fd;
|
||||
const char *mode;
|
||||
{
|
||||
char name[20];
|
||||
|
||||
if (fd < 0) return (gzFile)Z_NULL;
|
||||
sprintf(name, "<fd:%d>", fd); /* for debugging */
|
||||
|
||||
return gz_open (name, mode, fd);
|
||||
}
|
||||
|
||||
/* ===========================================================================
|
||||
* Update the compression level and strategy
|
||||
*/
|
||||
int ZEXPORT gzsetparams (file, level, strategy)
|
||||
gzFile file;
|
||||
int level;
|
||||
int strategy;
|
||||
{
|
||||
gz_stream *s = (gz_stream*)file;
|
||||
|
||||
if (s == NULL || s->mode != 'w') return Z_STREAM_ERROR;
|
||||
|
||||
/* Make room to allow flushing */
|
||||
if (s->stream.avail_out == 0) {
|
||||
|
||||
s->stream.next_out = s->outbuf;
|
||||
if (fwrite(s->outbuf, 1, Z_BUFSIZE, s->file) != Z_BUFSIZE) {
|
||||
s->z_err = Z_ERRNO;
|
||||
}
|
||||
s->stream.avail_out = Z_BUFSIZE;
|
||||
}
|
||||
|
||||
return deflateParams (&(s->stream), level, strategy);
|
||||
}
|
||||
|
||||
/* ===========================================================================
|
||||
Read a byte from a gz_stream; update next_in and avail_in. Return EOF
|
||||
for end of file.
|
||||
IN assertion: the stream s has been sucessfully opened for reading.
|
||||
*/
|
||||
local int get_byte(s)
|
||||
gz_stream *s;
|
||||
{
|
||||
if (s->z_eof) return EOF;
|
||||
if (s->stream.avail_in == 0) {
|
||||
errno = 0;
|
||||
s->stream.avail_in = fread(s->inbuf, 1, Z_BUFSIZE, s->file);
|
||||
if (s->stream.avail_in == 0) {
|
||||
s->z_eof = 1;
|
||||
if (ferror(s->file)) s->z_err = Z_ERRNO;
|
||||
return EOF;
|
||||
}
|
||||
s->stream.next_in = s->inbuf;
|
||||
}
|
||||
s->stream.avail_in--;
|
||||
return *(s->stream.next_in)++;
|
||||
}
|
||||
|
||||
/* ===========================================================================
|
||||
Check the gzip header of a gz_stream opened for reading. Set the stream
|
||||
mode to transparent if the gzip magic header is not present; set s->err
|
||||
to Z_DATA_ERROR if the magic header is present but the rest of the header
|
||||
is incorrect.
|
||||
IN assertion: the stream s has already been created sucessfully;
|
||||
s->stream.avail_in is zero for the first time, but may be non-zero
|
||||
for concatenated .gz files.
|
||||
*/
|
||||
local void check_header(s)
|
||||
gz_stream *s;
|
||||
{
|
||||
int method; /* method byte */
|
||||
int flags; /* flags byte */
|
||||
uInt len;
|
||||
int c;
|
||||
|
||||
/* Check the gzip magic header */
|
||||
for (len = 0; len < 2; len++) {
|
||||
c = get_byte(s);
|
||||
if (c != gz_magic[len]) {
|
||||
if (len != 0) s->stream.avail_in++, s->stream.next_in--;
|
||||
if (c != EOF) {
|
||||
s->stream.avail_in++, s->stream.next_in--;
|
||||
s->transparent = 1;
|
||||
}
|
||||
s->z_err = s->stream.avail_in != 0 ? Z_OK : Z_STREAM_END;
|
||||
return;
|
||||
}
|
||||
}
|
||||
method = get_byte(s);
|
||||
flags = get_byte(s);
|
||||
if (method != Z_DEFLATED || (flags & RESERVED) != 0) {
|
||||
s->z_err = Z_DATA_ERROR;
|
||||
return;
|
||||
}
|
||||
|
||||
/* Discard time, xflags and OS code: */
|
||||
for (len = 0; len < 6; len++) (void)get_byte(s);
|
||||
|
||||
if ((flags & EXTRA_FIELD) != 0) { /* skip the extra field */
|
||||
len = (uInt)get_byte(s);
|
||||
len += ((uInt)get_byte(s))<<8;
|
||||
/* len is garbage if EOF but the loop below will quit anyway */
|
||||
while (len-- != 0 && get_byte(s) != EOF) ;
|
||||
}
|
||||
if ((flags & ORIG_NAME) != 0) { /* skip the original file name */
|
||||
while ((c = get_byte(s)) != 0 && c != EOF) ;
|
||||
}
|
||||
if ((flags & COMMENT) != 0) { /* skip the .gz file comment */
|
||||
while ((c = get_byte(s)) != 0 && c != EOF) ;
|
||||
}
|
||||
if ((flags & HEAD_CRC) != 0) { /* skip the header crc */
|
||||
for (len = 0; len < 2; len++) (void)get_byte(s);
|
||||
}
|
||||
s->z_err = s->z_eof ? Z_DATA_ERROR : Z_OK;
|
||||
}
|
||||
|
||||
/* ===========================================================================
|
||||
* Cleanup then free the given gz_stream. Return a zlib error code.
|
||||
Try freeing in the reverse order of allocations.
|
||||
*/
|
||||
local int destroy (s)
|
||||
gz_stream *s;
|
||||
{
|
||||
int err = Z_OK;
|
||||
|
||||
if (!s) return Z_STREAM_ERROR;
|
||||
|
||||
TRYFREE(s->msg);
|
||||
|
||||
if (s->stream.state != NULL) {
|
||||
if (s->mode == 'w') {
|
||||
#ifdef NO_DEFLATE
|
||||
err = Z_STREAM_ERROR;
|
||||
#else
|
||||
err = deflateEnd(&(s->stream));
|
||||
#endif
|
||||
} else if (s->mode == 'r') {
|
||||
err = inflateEnd(&(s->stream));
|
||||
}
|
||||
}
|
||||
if (s->file != NULL && fclose(s->file)) {
|
||||
#ifdef ESPIPE
|
||||
if (errno != ESPIPE) /* fclose is broken for pipes in HP/UX */
|
||||
#endif
|
||||
err = Z_ERRNO;
|
||||
}
|
||||
if (s->z_err < 0) err = s->z_err;
|
||||
|
||||
TRYFREE(s->inbuf);
|
||||
TRYFREE(s->outbuf);
|
||||
TRYFREE(s->path);
|
||||
TRYFREE(s);
|
||||
return err;
|
||||
}
|
||||
|
||||
/* ===========================================================================
|
||||
Reads the given number of uncompressed bytes from the compressed file.
|
||||
gzread returns the number of bytes actually read (0 for end of file).
|
||||
*/
|
||||
int ZEXPORT gzread (file, buf, len)
|
||||
gzFile file;
|
||||
voidp buf;
|
||||
unsigned len;
|
||||
{
|
||||
gz_stream *s = (gz_stream*)file;
|
||||
Bytef *start = (Bytef*)buf; /* starting point for crc computation */
|
||||
Byte *next_out; /* == stream.next_out but not forced far (for MSDOS) */
|
||||
|
||||
if (s == NULL || s->mode != 'r') return Z_STREAM_ERROR;
|
||||
|
||||
if (s->z_err == Z_DATA_ERROR || s->z_err == Z_ERRNO) return -1;
|
||||
if (s->z_err == Z_STREAM_END) return 0; /* EOF */
|
||||
|
||||
next_out = (Byte*)buf;
|
||||
s->stream.next_out = (Bytef*)buf;
|
||||
s->stream.avail_out = len;
|
||||
|
||||
while (s->stream.avail_out != 0) {
|
||||
|
||||
if (s->transparent) {
|
||||
/* Copy first the lookahead bytes: */
|
||||
uInt n = s->stream.avail_in;
|
||||
if (n > s->stream.avail_out) n = s->stream.avail_out;
|
||||
if (n > 0) {
|
||||
zmemcpy(s->stream.next_out, s->stream.next_in, n);
|
||||
next_out += n;
|
||||
s->stream.next_out = next_out;
|
||||
s->stream.next_in += n;
|
||||
s->stream.avail_out -= n;
|
||||
s->stream.avail_in -= n;
|
||||
}
|
||||
if (s->stream.avail_out > 0) {
|
||||
s->stream.avail_out -= fread(next_out, 1, s->stream.avail_out,
|
||||
s->file);
|
||||
}
|
||||
len -= s->stream.avail_out;
|
||||
s->stream.total_in += (uLong)len;
|
||||
s->stream.total_out += (uLong)len;
|
||||
if (len == 0) s->z_eof = 1;
|
||||
return (int)len;
|
||||
}
|
||||
if (s->stream.avail_in == 0 && !s->z_eof) {
|
||||
|
||||
errno = 0;
|
||||
s->stream.avail_in = fread(s->inbuf, 1, Z_BUFSIZE, s->file);
|
||||
if (s->stream.avail_in == 0) {
|
||||
s->z_eof = 1;
|
||||
if (ferror(s->file)) {
|
||||
s->z_err = Z_ERRNO;
|
||||
break;
|
||||
}
|
||||
}
|
||||
s->stream.next_in = s->inbuf;
|
||||
}
|
||||
s->z_err = inflate(&(s->stream), Z_NO_FLUSH);
|
||||
|
||||
if (s->z_err == Z_STREAM_END) {
|
||||
/* Check CRC and original size */
|
||||
s->crc = crc32(s->crc, start, (uInt)(s->stream.next_out - start));
|
||||
start = s->stream.next_out;
|
||||
|
||||
if (getLong(s) != s->crc) {
|
||||
s->z_err = Z_DATA_ERROR;
|
||||
} else {
|
||||
(void)getLong(s);
|
||||
/* The uncompressed length returned by above getlong() may
|
||||
* be different from s->stream.total_out) in case of
|
||||
* concatenated .gz files. Check for such files:
|
||||
*/
|
||||
check_header(s);
|
||||
if (s->z_err == Z_OK) {
|
||||
uLong total_in = s->stream.total_in;
|
||||
uLong total_out = s->stream.total_out;
|
||||
|
||||
inflateReset(&(s->stream));
|
||||
s->stream.total_in = total_in;
|
||||
s->stream.total_out = total_out;
|
||||
s->crc = crc32(0L, Z_NULL, 0);
|
||||
}
|
||||
}
|
||||
}
|
||||
if (s->z_err != Z_OK || s->z_eof) break;
|
||||
}
|
||||
s->crc = crc32(s->crc, start, (uInt)(s->stream.next_out - start));
|
||||
|
||||
return (int)(len - s->stream.avail_out);
|
||||
}
|
||||
|
||||
|
||||
/* ===========================================================================
|
||||
Reads one byte from the compressed file. gzgetc returns this byte
|
||||
or -1 in case of end of file or error.
|
||||
*/
|
||||
int ZEXPORT gzgetc(file)
|
||||
gzFile file;
|
||||
{
|
||||
unsigned char c;
|
||||
|
||||
return gzread(file, &c, 1) == 1 ? c : -1;
|
||||
}
|
||||
|
||||
|
||||
/* ===========================================================================
|
||||
Reads bytes from the compressed file until len-1 characters are
|
||||
read, or a newline character is read and transferred to buf, or an
|
||||
end-of-file condition is encountered. The string is then terminated
|
||||
with a null character.
|
||||
gzgets returns buf, or Z_NULL in case of error.
|
||||
|
||||
The current implementation is not optimized at all.
|
||||
*/
|
||||
char * ZEXPORT gzgets(file, buf, len)
|
||||
gzFile file;
|
||||
char *buf;
|
||||
int len;
|
||||
{
|
||||
char *b = buf;
|
||||
if (buf == Z_NULL || len <= 0) return Z_NULL;
|
||||
|
||||
while (--len > 0 && gzread(file, buf, 1) == 1 && *buf++ != '\n') ;
|
||||
*buf = '\0';
|
||||
return b == buf && len > 0 ? Z_NULL : b;
|
||||
}
|
||||
|
||||
|
||||
#ifndef NO_DEFLATE
|
||||
/* ===========================================================================
|
||||
Writes the given number of uncompressed bytes into the compressed file.
|
||||
gzwrite returns the number of bytes actually written (0 in case of error).
|
||||
*/
|
||||
int ZEXPORT gzwrite (file, buf, len)
|
||||
gzFile file;
|
||||
const voidp buf;
|
||||
unsigned len;
|
||||
{
|
||||
gz_stream *s = (gz_stream*)file;
|
||||
|
||||
if (s == NULL || s->mode != 'w') return Z_STREAM_ERROR;
|
||||
|
||||
s->stream.next_in = (Bytef*)buf;
|
||||
s->stream.avail_in = len;
|
||||
|
||||
while (s->stream.avail_in != 0) {
|
||||
|
||||
if (s->stream.avail_out == 0) {
|
||||
|
||||
s->stream.next_out = s->outbuf;
|
||||
if (fwrite(s->outbuf, 1, Z_BUFSIZE, s->file) != Z_BUFSIZE) {
|
||||
s->z_err = Z_ERRNO;
|
||||
break;
|
||||
}
|
||||
s->stream.avail_out = Z_BUFSIZE;
|
||||
}
|
||||
s->z_err = deflate(&(s->stream), Z_NO_FLUSH);
|
||||
if (s->z_err != Z_OK) break;
|
||||
}
|
||||
s->crc = crc32(s->crc, (const Bytef *)buf, len);
|
||||
|
||||
return (int)(len - s->stream.avail_in);
|
||||
}
|
||||
|
||||
/* ===========================================================================
|
||||
Converts, formats, and writes the args to the compressed file under
|
||||
control of the format string, as in fprintf. gzprintf returns the number of
|
||||
uncompressed bytes actually written (0 in case of error).
|
||||
*/
|
||||
#ifdef STDC
|
||||
#include <stdarg.h>
|
||||
|
||||
int ZEXPORTVA gzprintf (gzFile file, const char *format, /* args */ ...)
|
||||
{
|
||||
char buf[Z_PRINTF_BUFSIZE];
|
||||
va_list va;
|
||||
int len;
|
||||
|
||||
va_start(va, format);
|
||||
#ifdef HAS_vsnprintf
|
||||
(void)vsnprintf(buf, sizeof(buf), format, va);
|
||||
#else
|
||||
(void)vsprintf(buf, format, va);
|
||||
#endif
|
||||
va_end(va);
|
||||
len = strlen(buf); /* some *sprintf don't return the nb of bytes written */
|
||||
if (len <= 0) return 0;
|
||||
|
||||
return gzwrite(file, buf, (unsigned)len);
|
||||
}
|
||||
#else /* not ANSI C */
|
||||
|
||||
int ZEXPORTVA gzprintf (file, format, a1, a2, a3, a4, a5, a6, a7, a8, a9, a10,
|
||||
a11, a12, a13, a14, a15, a16, a17, a18, a19, a20)
|
||||
gzFile file;
|
||||
const char *format;
|
||||
int a1, a2, a3, a4, a5, a6, a7, a8, a9, a10,
|
||||
a11, a12, a13, a14, a15, a16, a17, a18, a19, a20;
|
||||
{
|
||||
char buf[Z_PRINTF_BUFSIZE];
|
||||
int len;
|
||||
|
||||
#ifdef HAS_snprintf
|
||||
snprintf(buf, sizeof(buf), format, a1, a2, a3, a4, a5, a6, a7, a8,
|
||||
a9, a10, a11, a12, a13, a14, a15, a16, a17, a18, a19, a20);
|
||||
#else
|
||||
sprintf(buf, format, a1, a2, a3, a4, a5, a6, a7, a8,
|
||||
a9, a10, a11, a12, a13, a14, a15, a16, a17, a18, a19, a20);
|
||||
#endif
|
||||
len = strlen(buf); /* old sprintf doesn't return the nb of bytes written */
|
||||
if (len <= 0) return 0;
|
||||
|
||||
return gzwrite(file, buf, len);
|
||||
}
|
||||
#endif
|
||||
|
||||
/* ===========================================================================
|
||||
Writes c, converted to an unsigned char, into the compressed file.
|
||||
gzputc returns the value that was written, or -1 in case of error.
|
||||
*/
|
||||
int ZEXPORT gzputc(file, c)
|
||||
gzFile file;
|
||||
int c;
|
||||
{
|
||||
unsigned char cc = (unsigned char) c; /* required for big endian systems */
|
||||
|
||||
return gzwrite(file, &cc, 1) == 1 ? (int)cc : -1;
|
||||
}
|
||||
|
||||
|
||||
/* ===========================================================================
|
||||
Writes the given null-terminated string to the compressed file, excluding
|
||||
the terminating null character.
|
||||
gzputs returns the number of characters written, or -1 in case of error.
|
||||
*/
|
||||
int ZEXPORT gzputs(file, s)
|
||||
gzFile file;
|
||||
const char *s;
|
||||
{
|
||||
return gzwrite(file, (char*)s, (unsigned)strlen(s));
|
||||
}
|
||||
|
||||
|
||||
/* ===========================================================================
|
||||
Flushes all pending output into the compressed file. The parameter
|
||||
flush is as in the deflate() function.
|
||||
*/
|
||||
local int do_flush (file, flush)
|
||||
gzFile file;
|
||||
int flush;
|
||||
{
|
||||
uInt len;
|
||||
int done = 0;
|
||||
gz_stream *s = (gz_stream*)file;
|
||||
|
||||
if (s == NULL || s->mode != 'w') return Z_STREAM_ERROR;
|
||||
|
||||
s->stream.avail_in = 0; /* should be zero already anyway */
|
||||
|
||||
for (;;) {
|
||||
len = Z_BUFSIZE - s->stream.avail_out;
|
||||
|
||||
if (len != 0) {
|
||||
if ((uInt)fwrite(s->outbuf, 1, len, s->file) != len) {
|
||||
s->z_err = Z_ERRNO;
|
||||
return Z_ERRNO;
|
||||
}
|
||||
s->stream.next_out = s->outbuf;
|
||||
s->stream.avail_out = Z_BUFSIZE;
|
||||
}
|
||||
if (done) break;
|
||||
s->z_err = deflate(&(s->stream), flush);
|
||||
|
||||
/* Ignore the second of two consecutive flushes: */
|
||||
if (len == 0 && s->z_err == Z_BUF_ERROR) s->z_err = Z_OK;
|
||||
|
||||
/* deflate has finished flushing only when it hasn't used up
|
||||
* all the available space in the output buffer:
|
||||
*/
|
||||
done = (s->stream.avail_out != 0 || s->z_err == Z_STREAM_END);
|
||||
|
||||
if (s->z_err != Z_OK && s->z_err != Z_STREAM_END) break;
|
||||
}
|
||||
return s->z_err == Z_STREAM_END ? Z_OK : s->z_err;
|
||||
}
|
||||
|
||||
int ZEXPORT gzflush (file, flush)
|
||||
gzFile file;
|
||||
int flush;
|
||||
{
|
||||
gz_stream *s = (gz_stream*)file;
|
||||
int err = do_flush (file, flush);
|
||||
|
||||
if (err) return err;
|
||||
fflush(s->file);
|
||||
return s->z_err == Z_STREAM_END ? Z_OK : s->z_err;
|
||||
}
|
||||
#endif /* NO_DEFLATE */
|
||||
|
||||
/* ===========================================================================
|
||||
Sets the starting position for the next gzread or gzwrite on the given
|
||||
compressed file. The offset represents a number of bytes in the
|
||||
gzseek returns the resulting offset location as measured in bytes from
|
||||
the beginning of the uncompressed stream, or -1 in case of error.
|
||||
SEEK_END is not implemented, returns error.
|
||||
In this version of the library, gzseek can be extremely slow.
|
||||
*/
|
||||
z_off_t ZEXPORT gzseek (file, offset, whence)
|
||||
gzFile file;
|
||||
z_off_t offset;
|
||||
int whence;
|
||||
{
|
||||
gz_stream *s = (gz_stream*)file;
|
||||
|
||||
if (s == NULL || whence == SEEK_END ||
|
||||
s->z_err == Z_ERRNO || s->z_err == Z_DATA_ERROR) {
|
||||
return -1L;
|
||||
}
|
||||
|
||||
if (s->mode == 'w') {
|
||||
#ifdef NO_DEFLATE
|
||||
return -1L;
|
||||
#else
|
||||
if (whence == SEEK_SET) {
|
||||
offset -= s->stream.total_in;
|
||||
}
|
||||
if (offset < 0) return -1L;
|
||||
|
||||
/* At this point, offset is the number of zero bytes to write. */
|
||||
if (s->inbuf == Z_NULL) {
|
||||
s->inbuf = (Byte*)ALLOC(Z_BUFSIZE); /* for seeking */
|
||||
zmemzero(s->inbuf, Z_BUFSIZE);
|
||||
}
|
||||
while (offset > 0) {
|
||||
uInt size = Z_BUFSIZE;
|
||||
if (offset < Z_BUFSIZE) size = (uInt)offset;
|
||||
|
||||
size = gzwrite(file, s->inbuf, size);
|
||||
if (size == 0) return -1L;
|
||||
|
||||
offset -= size;
|
||||
}
|
||||
return (z_off_t)s->stream.total_in;
|
||||
#endif
|
||||
}
|
||||
/* Rest of function is for reading only */
|
||||
|
||||
/* compute absolute position */
|
||||
if (whence == SEEK_CUR) {
|
||||
offset += s->stream.total_out;
|
||||
}
|
||||
if (offset < 0) return -1L;
|
||||
|
||||
if (s->transparent) {
|
||||
/* map to fseek */
|
||||
s->stream.avail_in = 0;
|
||||
s->stream.next_in = s->inbuf;
|
||||
if (fseek(s->file, offset, SEEK_SET) < 0) return -1L;
|
||||
|
||||
s->stream.total_in = s->stream.total_out = (uLong)offset;
|
||||
return offset;
|
||||
}
|
||||
|
||||
/* For a negative seek, rewind and use positive seek */
|
||||
if ((uLong)offset >= s->stream.total_out) {
|
||||
offset -= s->stream.total_out;
|
||||
} else if (gzrewind(file) < 0) {
|
||||
return -1L;
|
||||
}
|
||||
/* offset is now the number of bytes to skip. */
|
||||
|
||||
if (offset != 0 && s->outbuf == Z_NULL) {
|
||||
s->outbuf = (Byte*)ALLOC(Z_BUFSIZE);
|
||||
}
|
||||
while (offset > 0) {
|
||||
int size = Z_BUFSIZE;
|
||||
if (offset < Z_BUFSIZE) size = (int)offset;
|
||||
|
||||
size = gzread(file, s->outbuf, (uInt)size);
|
||||
if (size <= 0) return -1L;
|
||||
offset -= size;
|
||||
}
|
||||
return (z_off_t)s->stream.total_out;
|
||||
}
|
||||
|
||||
/* ===========================================================================
|
||||
Rewinds input file.
|
||||
*/
|
||||
int ZEXPORT gzrewind (file)
|
||||
gzFile file;
|
||||
{
|
||||
gz_stream *s = (gz_stream*)file;
|
||||
|
||||
if (s == NULL || s->mode != 'r') return -1;
|
||||
|
||||
s->z_err = Z_OK;
|
||||
s->z_eof = 0;
|
||||
s->stream.avail_in = 0;
|
||||
s->stream.next_in = s->inbuf;
|
||||
s->crc = crc32(0L, Z_NULL, 0);
|
||||
|
||||
if (s->startpos == 0) { /* not a compressed file */
|
||||
rewind(s->file);
|
||||
return 0;
|
||||
}
|
||||
|
||||
(void) inflateReset(&s->stream);
|
||||
return fseek(s->file, s->startpos, SEEK_SET);
|
||||
}
|
||||
|
||||
/* ===========================================================================
|
||||
Returns the starting position for the next gzread or gzwrite on the
|
||||
given compressed file. This position represents a number of bytes in the
|
||||
uncompressed data stream.
|
||||
*/
|
||||
z_off_t ZEXPORT gztell (file)
|
||||
gzFile file;
|
||||
{
|
||||
return gzseek(file, 0L, SEEK_CUR);
|
||||
}
|
||||
|
||||
/* ===========================================================================
|
||||
Returns 1 when EOF has previously been detected reading the given
|
||||
input stream, otherwise zero.
|
||||
*/
|
||||
int ZEXPORT gzeof (file)
|
||||
gzFile file;
|
||||
{
|
||||
gz_stream *s = (gz_stream*)file;
|
||||
|
||||
return (s == NULL || s->mode != 'r') ? 0 : s->z_eof;
|
||||
}
|
||||
|
||||
/* ===========================================================================
|
||||
Outputs a long in LSB order to the given file
|
||||
*/
|
||||
local void putLong (file, x)
|
||||
FILE *file;
|
||||
uLong x;
|
||||
{
|
||||
int n;
|
||||
for (n = 0; n < 4; n++) {
|
||||
fputc((int)(x & 0xff), file);
|
||||
x >>= 8;
|
||||
}
|
||||
}
|
||||
|
||||
/* ===========================================================================
|
||||
Reads a long in LSB order from the given gz_stream. Sets z_err in case
|
||||
of error.
|
||||
*/
|
||||
local uLong getLong (s)
|
||||
gz_stream *s;
|
||||
{
|
||||
uLong x = (uLong)get_byte(s);
|
||||
int c;
|
||||
|
||||
x += ((uLong)get_byte(s))<<8;
|
||||
x += ((uLong)get_byte(s))<<16;
|
||||
c = get_byte(s);
|
||||
if (c == EOF) s->z_err = Z_DATA_ERROR;
|
||||
x += ((uLong)c)<<24;
|
||||
return x;
|
||||
}
|
||||
|
||||
/* ===========================================================================
|
||||
Flushes all pending output if necessary, closes the compressed file
|
||||
and deallocates all the (de)compression state.
|
||||
*/
|
||||
int ZEXPORT gzclose (file)
|
||||
gzFile file;
|
||||
{
|
||||
int err;
|
||||
gz_stream *s = (gz_stream*)file;
|
||||
|
||||
if (s == NULL) return Z_STREAM_ERROR;
|
||||
|
||||
if (s->mode == 'w') {
|
||||
#ifdef NO_DEFLATE
|
||||
return Z_STREAM_ERROR;
|
||||
#else
|
||||
err = do_flush (file, Z_FINISH);
|
||||
if (err != Z_OK) return destroy((gz_stream*)file);
|
||||
|
||||
putLong (s->file, s->crc);
|
||||
putLong (s->file, s->stream.total_in);
|
||||
#endif
|
||||
}
|
||||
return destroy((gz_stream*)file);
|
||||
}
|
||||
|
||||
/* ===========================================================================
|
||||
Returns the error message for the last error which occured on the
|
||||
given compressed file. errnum is set to zlib error number. If an
|
||||
error occured in the file system and not in the compression library,
|
||||
errnum is set to Z_ERRNO and the application may consult errno
|
||||
to get the exact error code.
|
||||
*/
|
||||
const char* ZEXPORT gzerror (file, errnum)
|
||||
gzFile file;
|
||||
int *errnum;
|
||||
{
|
||||
char *m;
|
||||
gz_stream *s = (gz_stream*)file;
|
||||
|
||||
if (s == NULL) {
|
||||
*errnum = Z_STREAM_ERROR;
|
||||
return (const char*)ERR_MSG(Z_STREAM_ERROR);
|
||||
}
|
||||
*errnum = s->z_err;
|
||||
if (*errnum == Z_OK) return (const char*)"";
|
||||
|
||||
m = (char*)(*errnum == Z_ERRNO ? zstrerror(errno) : s->stream.msg);
|
||||
|
||||
if (m == NULL || *m == '\0') m = (char*)ERR_MSG(s->z_err);
|
||||
|
||||
TRYFREE(s->msg);
|
||||
s->msg = (char*)ALLOC(strlen(s->path) + strlen(m) + 3);
|
||||
strcpy(s->msg, s->path);
|
||||
strcat(s->msg, ": ");
|
||||
strcat(s->msg, m);
|
||||
return (const char*)s->msg;
|
||||
}
|
|
@ -1,403 +0,0 @@
|
|||
/* infblock.c -- interpret and process block types to last block
|
||||
* Copyright (C) 1995-2002 Mark Adler
|
||||
* For conditions of distribution and use, see copyright notice in zlib.h
|
||||
*/
|
||||
|
||||
#include "zutil.h"
|
||||
#include "infblock.h"
|
||||
#include "inftrees.h"
|
||||
#include "infcodes.h"
|
||||
#include "infutil.h"
|
||||
|
||||
struct inflate_codes_state {int dummy;}; /* for buggy compilers */
|
||||
|
||||
/* simplify the use of the inflate_huft type with some defines */
|
||||
#define exop word.what.Exop
|
||||
#define bits word.what.Bits
|
||||
|
||||
/* Table for deflate from PKZIP's appnote.txt. */
|
||||
local const uInt border[] = { /* Order of the bit length code lengths */
|
||||
16, 17, 18, 0, 8, 7, 9, 6, 10, 5, 11, 4, 12, 3, 13, 2, 14, 1, 15};
|
||||
|
||||
/*
|
||||
Notes beyond the 1.93a appnote.txt:
|
||||
|
||||
1. Distance pointers never point before the beginning of the output
|
||||
stream.
|
||||
2. Distance pointers can point back across blocks, up to 32k away.
|
||||
3. There is an implied maximum of 7 bits for the bit length table and
|
||||
15 bits for the actual data.
|
||||
4. If only one code exists, then it is encoded using one bit. (Zero
|
||||
would be more efficient, but perhaps a little confusing.) If two
|
||||
codes exist, they are coded using one bit each (0 and 1).
|
||||
5. There is no way of sending zero distance codes--a dummy must be
|
||||
sent if there are none. (History: a pre 2.0 version of PKZIP would
|
||||
store blocks with no distance codes, but this was discovered to be
|
||||
too harsh a criterion.) Valid only for 1.93a. 2.04c does allow
|
||||
zero distance codes, which is sent as one code of zero bits in
|
||||
length.
|
||||
6. There are up to 286 literal/length codes. Code 256 represents the
|
||||
end-of-block. Note however that the static length tree defines
|
||||
288 codes just to fill out the Huffman codes. Codes 286 and 287
|
||||
cannot be used though, since there is no length base or extra bits
|
||||
defined for them. Similarily, there are up to 30 distance codes.
|
||||
However, static trees define 32 codes (all 5 bits) to fill out the
|
||||
Huffman codes, but the last two had better not show up in the data.
|
||||
7. Unzip can check dynamic Huffman blocks for complete code sets.
|
||||
The exception is that a single code would not be complete (see #4).
|
||||
8. The five bits following the block type is really the number of
|
||||
literal codes sent minus 257.
|
||||
9. Length codes 8,16,16 are interpreted as 13 length codes of 8 bits
|
||||
(1+6+6). Therefore, to output three times the length, you output
|
||||
three codes (1+1+1), whereas to output four times the same length,
|
||||
you only need two codes (1+3). Hmm.
|
||||
10. In the tree reconstruction algorithm, Code = Code + Increment
|
||||
only if BitLength(i) is not zero. (Pretty obvious.)
|
||||
11. Correction: 4 Bits: # of Bit Length codes - 4 (4 - 19)
|
||||
12. Note: length code 284 can represent 227-258, but length code 285
|
||||
really is 258. The last length deserves its own, short code
|
||||
since it gets used a lot in very redundant files. The length
|
||||
258 is special since 258 - 3 (the min match length) is 255.
|
||||
13. The literal/length and distance code bit lengths are read as a
|
||||
single stream of lengths. It is possible (and advantageous) for
|
||||
a repeat code (16, 17, or 18) to go across the boundary between
|
||||
the two sets of lengths.
|
||||
*/
|
||||
|
||||
|
||||
void inflate_blocks_reset(s, z, c)
|
||||
inflate_blocks_statef *s;
|
||||
z_streamp z;
|
||||
uLongf *c;
|
||||
{
|
||||
if (c != Z_NULL)
|
||||
*c = s->check;
|
||||
if (s->mode == BTREE || s->mode == DTREE)
|
||||
ZFREE(z, s->sub.trees.blens);
|
||||
if (s->mode == CODES)
|
||||
inflate_codes_free(s->sub.decode.codes, z);
|
||||
s->mode = TYPE;
|
||||
s->bitk = 0;
|
||||
s->bitb = 0;
|
||||
s->read = s->write = s->window;
|
||||
if (s->checkfn != Z_NULL)
|
||||
z->adler = s->check = (*s->checkfn)(0L, (const Bytef *)Z_NULL, 0);
|
||||
Tracev((stderr, "inflate: blocks reset\n"));
|
||||
}
|
||||
|
||||
|
||||
inflate_blocks_statef *inflate_blocks_new(z, c, w)
|
||||
z_streamp z;
|
||||
check_func c;
|
||||
uInt w;
|
||||
{
|
||||
inflate_blocks_statef *s;
|
||||
|
||||
if ((s = (inflate_blocks_statef *)ZALLOC
|
||||
(z,1,sizeof(struct inflate_blocks_state))) == Z_NULL)
|
||||
return s;
|
||||
if ((s->hufts =
|
||||
(inflate_huft *)ZALLOC(z, sizeof(inflate_huft), MANY)) == Z_NULL)
|
||||
{
|
||||
ZFREE(z, s);
|
||||
return Z_NULL;
|
||||
}
|
||||
if ((s->window = (Bytef *)ZALLOC(z, 1, w)) == Z_NULL)
|
||||
{
|
||||
ZFREE(z, s->hufts);
|
||||
ZFREE(z, s);
|
||||
return Z_NULL;
|
||||
}
|
||||
s->end = s->window + w;
|
||||
s->checkfn = c;
|
||||
s->mode = TYPE;
|
||||
Tracev((stderr, "inflate: blocks allocated\n"));
|
||||
inflate_blocks_reset(s, z, Z_NULL);
|
||||
return s;
|
||||
}
|
||||
|
||||
|
||||
int inflate_blocks(s, z, r)
|
||||
inflate_blocks_statef *s;
|
||||
z_streamp z;
|
||||
int r;
|
||||
{
|
||||
uInt t; /* temporary storage */
|
||||
uLong b; /* bit buffer */
|
||||
uInt k; /* bits in bit buffer */
|
||||
Bytef *p; /* input data pointer */
|
||||
uInt n; /* bytes available there */
|
||||
Bytef *q; /* output window write pointer */
|
||||
uInt m; /* bytes to end of window or read pointer */
|
||||
|
||||
/* copy input/output information to locals (UPDATE macro restores) */
|
||||
LOAD
|
||||
|
||||
/* process input based on current state */
|
||||
while (1) switch (s->mode)
|
||||
{
|
||||
case TYPE:
|
||||
NEEDBITS(3)
|
||||
t = (uInt)b & 7;
|
||||
s->last = t & 1;
|
||||
switch (t >> 1)
|
||||
{
|
||||
case 0: /* stored */
|
||||
Tracev((stderr, "inflate: stored block%s\n",
|
||||
s->last ? " (last)" : ""));
|
||||
DUMPBITS(3)
|
||||
t = k & 7; /* go to byte boundary */
|
||||
DUMPBITS(t)
|
||||
s->mode = LENS; /* get length of stored block */
|
||||
break;
|
||||
case 1: /* fixed */
|
||||
Tracev((stderr, "inflate: fixed codes block%s\n",
|
||||
s->last ? " (last)" : ""));
|
||||
{
|
||||
uInt bl, bd;
|
||||
inflate_huft *tl, *td;
|
||||
|
||||
inflate_trees_fixed(&bl, &bd, &tl, &td, z);
|
||||
s->sub.decode.codes = inflate_codes_new(bl, bd, tl, td, z);
|
||||
if (s->sub.decode.codes == Z_NULL)
|
||||
{
|
||||
r = Z_MEM_ERROR;
|
||||
LEAVE
|
||||
}
|
||||
}
|
||||
DUMPBITS(3)
|
||||
s->mode = CODES;
|
||||
break;
|
||||
case 2: /* dynamic */
|
||||
Tracev((stderr, "inflate: dynamic codes block%s\n",
|
||||
s->last ? " (last)" : ""));
|
||||
DUMPBITS(3)
|
||||
s->mode = TABLE;
|
||||
break;
|
||||
case 3: /* illegal */
|
||||
DUMPBITS(3)
|
||||
s->mode = BAD;
|
||||
z->msg = (char*)"invalid block type";
|
||||
r = Z_DATA_ERROR;
|
||||
LEAVE
|
||||
}
|
||||
break;
|
||||
case LENS:
|
||||
NEEDBITS(32)
|
||||
if ((((~b) >> 16) & 0xffff) != (b & 0xffff))
|
||||
{
|
||||
s->mode = BAD;
|
||||
z->msg = (char*)"invalid stored block lengths";
|
||||
r = Z_DATA_ERROR;
|
||||
LEAVE
|
||||
}
|
||||
s->sub.left = (uInt)b & 0xffff;
|
||||
b = k = 0; /* dump bits */
|
||||
Tracev((stderr, "inflate: stored length %u\n", s->sub.left));
|
||||
s->mode = s->sub.left ? STORED : (s->last ? DRY : TYPE);
|
||||
break;
|
||||
case STORED:
|
||||
if (n == 0)
|
||||
LEAVE
|
||||
NEEDOUT
|
||||
t = s->sub.left;
|
||||
if (t > n) t = n;
|
||||
if (t > m) t = m;
|
||||
zmemcpy(q, p, t);
|
||||
p += t; n -= t;
|
||||
q += t; m -= t;
|
||||
if ((s->sub.left -= t) != 0)
|
||||
break;
|
||||
Tracev((stderr, "inflate: stored end, %lu total out\n",
|
||||
z->total_out + (q >= s->read ? q - s->read :
|
||||
(s->end - s->read) + (q - s->window))));
|
||||
s->mode = s->last ? DRY : TYPE;
|
||||
break;
|
||||
case TABLE:
|
||||
NEEDBITS(14)
|
||||
s->sub.trees.table = t = (uInt)b & 0x3fff;
|
||||
#ifndef PKZIP_BUG_WORKAROUND
|
||||
if ((t & 0x1f) > 29 || ((t >> 5) & 0x1f) > 29)
|
||||
{
|
||||
s->mode = BAD;
|
||||
z->msg = (char*)"too many length or distance symbols";
|
||||
r = Z_DATA_ERROR;
|
||||
LEAVE
|
||||
}
|
||||
#endif
|
||||
t = 258 + (t & 0x1f) + ((t >> 5) & 0x1f);
|
||||
if ((s->sub.trees.blens = (uIntf*)ZALLOC(z, t, sizeof(uInt))) == Z_NULL)
|
||||
{
|
||||
r = Z_MEM_ERROR;
|
||||
LEAVE
|
||||
}
|
||||
DUMPBITS(14)
|
||||
s->sub.trees.index = 0;
|
||||
Tracev((stderr, "inflate: table sizes ok\n"));
|
||||
s->mode = BTREE;
|
||||
case BTREE:
|
||||
while (s->sub.trees.index < 4 + (s->sub.trees.table >> 10))
|
||||
{
|
||||
NEEDBITS(3)
|
||||
s->sub.trees.blens[border[s->sub.trees.index++]] = (uInt)b & 7;
|
||||
DUMPBITS(3)
|
||||
}
|
||||
while (s->sub.trees.index < 19)
|
||||
s->sub.trees.blens[border[s->sub.trees.index++]] = 0;
|
||||
s->sub.trees.bb = 7;
|
||||
t = inflate_trees_bits(s->sub.trees.blens, &s->sub.trees.bb,
|
||||
&s->sub.trees.tb, s->hufts, z);
|
||||
if (t != Z_OK)
|
||||
{
|
||||
r = t;
|
||||
if (r == Z_DATA_ERROR)
|
||||
{
|
||||
ZFREE(z, s->sub.trees.blens);
|
||||
s->mode = BAD;
|
||||
}
|
||||
LEAVE
|
||||
}
|
||||
s->sub.trees.index = 0;
|
||||
Tracev((stderr, "inflate: bits tree ok\n"));
|
||||
s->mode = DTREE;
|
||||
case DTREE:
|
||||
while (t = s->sub.trees.table,
|
||||
s->sub.trees.index < 258 + (t & 0x1f) + ((t >> 5) & 0x1f))
|
||||
{
|
||||
inflate_huft *h;
|
||||
uInt i, j, c;
|
||||
|
||||
t = s->sub.trees.bb;
|
||||
NEEDBITS(t)
|
||||
h = s->sub.trees.tb + ((uInt)b & inflate_mask[t]);
|
||||
t = h->bits;
|
||||
c = h->base;
|
||||
if (c < 16)
|
||||
{
|
||||
DUMPBITS(t)
|
||||
s->sub.trees.blens[s->sub.trees.index++] = c;
|
||||
}
|
||||
else /* c == 16..18 */
|
||||
{
|
||||
i = c == 18 ? 7 : c - 14;
|
||||
j = c == 18 ? 11 : 3;
|
||||
NEEDBITS(t + i)
|
||||
DUMPBITS(t)
|
||||
j += (uInt)b & inflate_mask[i];
|
||||
DUMPBITS(i)
|
||||
i = s->sub.trees.index;
|
||||
t = s->sub.trees.table;
|
||||
if (i + j > 258 + (t & 0x1f) + ((t >> 5) & 0x1f) ||
|
||||
(c == 16 && i < 1))
|
||||
{
|
||||
ZFREE(z, s->sub.trees.blens);
|
||||
s->mode = BAD;
|
||||
z->msg = (char*)"invalid bit length repeat";
|
||||
r = Z_DATA_ERROR;
|
||||
LEAVE
|
||||
}
|
||||
c = c == 16 ? s->sub.trees.blens[i - 1] : 0;
|
||||
do {
|
||||
s->sub.trees.blens[i++] = c;
|
||||
} while (--j);
|
||||
s->sub.trees.index = i;
|
||||
}
|
||||
}
|
||||
s->sub.trees.tb = Z_NULL;
|
||||
{
|
||||
uInt bl, bd;
|
||||
inflate_huft *tl, *td;
|
||||
inflate_codes_statef *c;
|
||||
|
||||
bl = 9; /* must be <= 9 for lookahead assumptions */
|
||||
bd = 6; /* must be <= 9 for lookahead assumptions */
|
||||
t = s->sub.trees.table;
|
||||
t = inflate_trees_dynamic(257 + (t & 0x1f), 1 + ((t >> 5) & 0x1f),
|
||||
s->sub.trees.blens, &bl, &bd, &tl, &td,
|
||||
s->hufts, z);
|
||||
if (t != Z_OK)
|
||||
{
|
||||
if (t == (uInt)Z_DATA_ERROR)
|
||||
{
|
||||
ZFREE(z, s->sub.trees.blens);
|
||||
s->mode = BAD;
|
||||
}
|
||||
r = t;
|
||||
LEAVE
|
||||
}
|
||||
Tracev((stderr, "inflate: trees ok\n"));
|
||||
if ((c = inflate_codes_new(bl, bd, tl, td, z)) == Z_NULL)
|
||||
{
|
||||
r = Z_MEM_ERROR;
|
||||
LEAVE
|
||||
}
|
||||
s->sub.decode.codes = c;
|
||||
}
|
||||
ZFREE(z, s->sub.trees.blens);
|
||||
s->mode = CODES;
|
||||
case CODES:
|
||||
UPDATE
|
||||
if ((r = inflate_codes(s, z, r)) != Z_STREAM_END)
|
||||
return inflate_flush(s, z, r);
|
||||
r = Z_OK;
|
||||
inflate_codes_free(s->sub.decode.codes, z);
|
||||
LOAD
|
||||
Tracev((stderr, "inflate: codes end, %lu total out\n",
|
||||
z->total_out + (q >= s->read ? q - s->read :
|
||||
(s->end - s->read) + (q - s->window))));
|
||||
if (!s->last)
|
||||
{
|
||||
s->mode = TYPE;
|
||||
break;
|
||||
}
|
||||
s->mode = DRY;
|
||||
case DRY:
|
||||
FLUSH
|
||||
if (s->read != s->write)
|
||||
LEAVE
|
||||
s->mode = DONE;
|
||||
case DONE:
|
||||
r = Z_STREAM_END;
|
||||
LEAVE
|
||||
case BAD:
|
||||
r = Z_DATA_ERROR;
|
||||
LEAVE
|
||||
default:
|
||||
r = Z_STREAM_ERROR;
|
||||
LEAVE
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
int inflate_blocks_free(s, z)
|
||||
inflate_blocks_statef *s;
|
||||
z_streamp z;
|
||||
{
|
||||
inflate_blocks_reset(s, z, Z_NULL);
|
||||
ZFREE(z, s->window);
|
||||
ZFREE(z, s->hufts);
|
||||
ZFREE(z, s);
|
||||
Tracev((stderr, "inflate: blocks freed\n"));
|
||||
return Z_OK;
|
||||
}
|
||||
|
||||
|
||||
void inflate_set_dictionary(s, d, n)
|
||||
inflate_blocks_statef *s;
|
||||
const Bytef *d;
|
||||
uInt n;
|
||||
{
|
||||
zmemcpy(s->window, d, n);
|
||||
s->read = s->write = s->window + n;
|
||||
}
|
||||
|
||||
|
||||
/* Returns true if inflate is currently at the end of a block generated
|
||||
* by Z_SYNC_FLUSH or Z_FULL_FLUSH.
|
||||
* IN assertion: s != Z_NULL
|
||||
*/
|
||||
int inflate_blocks_sync_point(s)
|
||||
inflate_blocks_statef *s;
|
||||
{
|
||||
return s->mode == LENS;
|
||||
}
|
|
@ -1,39 +0,0 @@
|
|||
/* infblock.h -- header to use infblock.c
|
||||
* Copyright (C) 1995-2002 Mark Adler
|
||||
* For conditions of distribution and use, see copyright notice in zlib.h
|
||||
*/
|
||||
|
||||
/* WARNING: this file should *not* be used by applications. It is
|
||||
part of the implementation of the compression library and is
|
||||
subject to change. Applications should only use zlib.h.
|
||||
*/
|
||||
|
||||
struct inflate_blocks_state;
|
||||
typedef struct inflate_blocks_state FAR inflate_blocks_statef;
|
||||
|
||||
extern inflate_blocks_statef * inflate_blocks_new OF((
|
||||
z_streamp z,
|
||||
check_func c, /* check function */
|
||||
uInt w)); /* window size */
|
||||
|
||||
extern int inflate_blocks OF((
|
||||
inflate_blocks_statef *,
|
||||
z_streamp ,
|
||||
int)); /* initial return code */
|
||||
|
||||
extern void inflate_blocks_reset OF((
|
||||
inflate_blocks_statef *,
|
||||
z_streamp ,
|
||||
uLongf *)); /* check value on output */
|
||||
|
||||
extern int inflate_blocks_free OF((
|
||||
inflate_blocks_statef *,
|
||||
z_streamp));
|
||||
|
||||
extern void inflate_set_dictionary OF((
|
||||
inflate_blocks_statef *s,
|
||||
const Bytef *d, /* dictionary */
|
||||
uInt n)); /* dictionary length */
|
||||
|
||||
extern int inflate_blocks_sync_point OF((
|
||||
inflate_blocks_statef *s));
|
|
@ -1,251 +0,0 @@
|
|||
/* infcodes.c -- process literals and length/distance pairs
|
||||
* Copyright (C) 1995-2002 Mark Adler
|
||||
* For conditions of distribution and use, see copyright notice in zlib.h
|
||||
*/
|
||||
|
||||
#include "zutil.h"
|
||||
#include "inftrees.h"
|
||||
#include "infblock.h"
|
||||
#include "infcodes.h"
|
||||
#include "infutil.h"
|
||||
#include "inffast.h"
|
||||
|
||||
/* simplify the use of the inflate_huft type with some defines */
|
||||
#define exop word.what.Exop
|
||||
#define bits word.what.Bits
|
||||
|
||||
typedef enum { /* waiting for "i:"=input, "o:"=output, "x:"=nothing */
|
||||
START, /* x: set up for LEN */
|
||||
LEN, /* i: get length/literal/eob next */
|
||||
LENEXT, /* i: getting length extra (have base) */
|
||||
DIST, /* i: get distance next */
|
||||
DISTEXT, /* i: getting distance extra */
|
||||
COPY, /* o: copying bytes in window, waiting for space */
|
||||
LIT, /* o: got literal, waiting for output space */
|
||||
WASH, /* o: got eob, possibly still output waiting */
|
||||
END, /* x: got eob and all data flushed */
|
||||
BADCODE} /* x: got error */
|
||||
inflate_codes_mode;
|
||||
|
||||
/* inflate codes private state */
|
||||
struct inflate_codes_state {
|
||||
|
||||
/* mode */
|
||||
inflate_codes_mode mode; /* current inflate_codes mode */
|
||||
|
||||
/* mode dependent information */
|
||||
uInt len;
|
||||
union {
|
||||
struct {
|
||||
inflate_huft *tree; /* pointer into tree */
|
||||
uInt need; /* bits needed */
|
||||
} code; /* if LEN or DIST, where in tree */
|
||||
uInt lit; /* if LIT, literal */
|
||||
struct {
|
||||
uInt get; /* bits to get for extra */
|
||||
uInt dist; /* distance back to copy from */
|
||||
} copy; /* if EXT or COPY, where and how much */
|
||||
} sub; /* submode */
|
||||
|
||||
/* mode independent information */
|
||||
Byte lbits; /* ltree bits decoded per branch */
|
||||
Byte dbits; /* dtree bits decoder per branch */
|
||||
inflate_huft *ltree; /* literal/length/eob tree */
|
||||
inflate_huft *dtree; /* distance tree */
|
||||
|
||||
};
|
||||
|
||||
|
||||
inflate_codes_statef *inflate_codes_new(bl, bd, tl, td, z)
|
||||
uInt bl, bd;
|
||||
inflate_huft *tl;
|
||||
inflate_huft *td; /* need separate declaration for Borland C++ */
|
||||
z_streamp z;
|
||||
{
|
||||
inflate_codes_statef *c;
|
||||
|
||||
if ((c = (inflate_codes_statef *)
|
||||
ZALLOC(z,1,sizeof(struct inflate_codes_state))) != Z_NULL)
|
||||
{
|
||||
c->mode = START;
|
||||
c->lbits = (Byte)bl;
|
||||
c->dbits = (Byte)bd;
|
||||
c->ltree = tl;
|
||||
c->dtree = td;
|
||||
Tracev((stderr, "inflate: codes new\n"));
|
||||
}
|
||||
return c;
|
||||
}
|
||||
|
||||
|
||||
int inflate_codes(s, z, r)
|
||||
inflate_blocks_statef *s;
|
||||
z_streamp z;
|
||||
int r;
|
||||
{
|
||||
uInt j; /* temporary storage */
|
||||
inflate_huft *t; /* temporary pointer */
|
||||
uInt e; /* extra bits or operation */
|
||||
uLong b; /* bit buffer */
|
||||
uInt k; /* bits in bit buffer */
|
||||
Bytef *p; /* input data pointer */
|
||||
uInt n; /* bytes available there */
|
||||
Bytef *q; /* output window write pointer */
|
||||
uInt m; /* bytes to end of window or read pointer */
|
||||
Bytef *f; /* pointer to copy strings from */
|
||||
inflate_codes_statef *c = s->sub.decode.codes; /* codes state */
|
||||
|
||||
/* copy input/output information to locals (UPDATE macro restores) */
|
||||
LOAD
|
||||
|
||||
/* process input and output based on current state */
|
||||
while (1) switch (c->mode)
|
||||
{ /* waiting for "i:"=input, "o:"=output, "x:"=nothing */
|
||||
case START: /* x: set up for LEN */
|
||||
#ifndef SLOW
|
||||
if (m >= 258 && n >= 10)
|
||||
{
|
||||
UPDATE
|
||||
r = inflate_fast(c->lbits, c->dbits, c->ltree, c->dtree, s, z);
|
||||
LOAD
|
||||
if (r != Z_OK)
|
||||
{
|
||||
c->mode = r == Z_STREAM_END ? WASH : BADCODE;
|
||||
break;
|
||||
}
|
||||
}
|
||||
#endif /* !SLOW */
|
||||
c->sub.code.need = c->lbits;
|
||||
c->sub.code.tree = c->ltree;
|
||||
c->mode = LEN;
|
||||
case LEN: /* i: get length/literal/eob next */
|
||||
j = c->sub.code.need;
|
||||
NEEDBITS(j)
|
||||
t = c->sub.code.tree + ((uInt)b & inflate_mask[j]);
|
||||
DUMPBITS(t->bits)
|
||||
e = (uInt)(t->exop);
|
||||
if (e == 0) /* literal */
|
||||
{
|
||||
c->sub.lit = t->base;
|
||||
Tracevv((stderr, t->base >= 0x20 && t->base < 0x7f ?
|
||||
"inflate: literal '%c'\n" :
|
||||
"inflate: literal 0x%02x\n", t->base));
|
||||
c->mode = LIT;
|
||||
break;
|
||||
}
|
||||
if (e & 16) /* length */
|
||||
{
|
||||
c->sub.copy.get = e & 15;
|
||||
c->len = t->base;
|
||||
c->mode = LENEXT;
|
||||
break;
|
||||
}
|
||||
if ((e & 64) == 0) /* next table */
|
||||
{
|
||||
c->sub.code.need = e;
|
||||
c->sub.code.tree = t + t->base;
|
||||
break;
|
||||
}
|
||||
if (e & 32) /* end of block */
|
||||
{
|
||||
Tracevv((stderr, "inflate: end of block\n"));
|
||||
c->mode = WASH;
|
||||
break;
|
||||
}
|
||||
c->mode = BADCODE; /* invalid code */
|
||||
z->msg = (char*)"invalid literal/length code";
|
||||
r = Z_DATA_ERROR;
|
||||
LEAVE
|
||||
case LENEXT: /* i: getting length extra (have base) */
|
||||
j = c->sub.copy.get;
|
||||
NEEDBITS(j)
|
||||
c->len += (uInt)b & inflate_mask[j];
|
||||
DUMPBITS(j)
|
||||
c->sub.code.need = c->dbits;
|
||||
c->sub.code.tree = c->dtree;
|
||||
Tracevv((stderr, "inflate: length %u\n", c->len));
|
||||
c->mode = DIST;
|
||||
case DIST: /* i: get distance next */
|
||||
j = c->sub.code.need;
|
||||
NEEDBITS(j)
|
||||
t = c->sub.code.tree + ((uInt)b & inflate_mask[j]);
|
||||
DUMPBITS(t->bits)
|
||||
e = (uInt)(t->exop);
|
||||
if (e & 16) /* distance */
|
||||
{
|
||||
c->sub.copy.get = e & 15;
|
||||
c->sub.copy.dist = t->base;
|
||||
c->mode = DISTEXT;
|
||||
break;
|
||||
}
|
||||
if ((e & 64) == 0) /* next table */
|
||||
{
|
||||
c->sub.code.need = e;
|
||||
c->sub.code.tree = t + t->base;
|
||||
break;
|
||||
}
|
||||
c->mode = BADCODE; /* invalid code */
|
||||
z->msg = (char*)"invalid distance code";
|
||||
r = Z_DATA_ERROR;
|
||||
LEAVE
|
||||
case DISTEXT: /* i: getting distance extra */
|
||||
j = c->sub.copy.get;
|
||||
NEEDBITS(j)
|
||||
c->sub.copy.dist += (uInt)b & inflate_mask[j];
|
||||
DUMPBITS(j)
|
||||
Tracevv((stderr, "inflate: distance %u\n", c->sub.copy.dist));
|
||||
c->mode = COPY;
|
||||
case COPY: /* o: copying bytes in window, waiting for space */
|
||||
f = q - c->sub.copy.dist;
|
||||
while (f < s->window) /* modulo window size-"while" instead */
|
||||
f += s->end - s->window; /* of "if" handles invalid distances */
|
||||
while (c->len)
|
||||
{
|
||||
NEEDOUT
|
||||
OUTBYTE(*f++)
|
||||
if (f == s->end)
|
||||
f = s->window;
|
||||
c->len--;
|
||||
}
|
||||
c->mode = START;
|
||||
break;
|
||||
case LIT: /* o: got literal, waiting for output space */
|
||||
NEEDOUT
|
||||
OUTBYTE(c->sub.lit)
|
||||
c->mode = START;
|
||||
break;
|
||||
case WASH: /* o: got eob, possibly more output */
|
||||
if (k > 7) /* return unused byte, if any */
|
||||
{
|
||||
Assert(k < 16, "inflate_codes grabbed too many bytes")
|
||||
k -= 8;
|
||||
n++;
|
||||
p--; /* can always return one */
|
||||
}
|
||||
FLUSH
|
||||
if (s->read != s->write)
|
||||
LEAVE
|
||||
c->mode = END;
|
||||
case END:
|
||||
r = Z_STREAM_END;
|
||||
LEAVE
|
||||
case BADCODE: /* x: got error */
|
||||
r = Z_DATA_ERROR;
|
||||
LEAVE
|
||||
default:
|
||||
r = Z_STREAM_ERROR;
|
||||
LEAVE
|
||||
}
|
||||
#ifdef NEED_DUMMY_RETURN
|
||||
return Z_STREAM_ERROR; /* Some dumb compilers complain without this */
|
||||
#endif
|
||||
}
|
||||
|
||||
|
||||
void inflate_codes_free(c, z)
|
||||
inflate_codes_statef *c;
|
||||
z_streamp z;
|
||||
{
|
||||
ZFREE(z, c);
|
||||
Tracev((stderr, "inflate: codes free\n"));
|
||||
}
|
|
@ -1,27 +0,0 @@
|
|||
/* infcodes.h -- header to use infcodes.c
|
||||
* Copyright (C) 1995-2002 Mark Adler
|
||||
* For conditions of distribution and use, see copyright notice in zlib.h
|
||||
*/
|
||||
|
||||
/* WARNING: this file should *not* be used by applications. It is
|
||||
part of the implementation of the compression library and is
|
||||
subject to change. Applications should only use zlib.h.
|
||||
*/
|
||||
|
||||
struct inflate_codes_state;
|
||||
typedef struct inflate_codes_state FAR inflate_codes_statef;
|
||||
|
||||
extern inflate_codes_statef *inflate_codes_new OF((
|
||||
uInt, uInt,
|
||||
inflate_huft *, inflate_huft *,
|
||||
z_streamp ));
|
||||
|
||||
extern int inflate_codes OF((
|
||||
inflate_blocks_statef *,
|
||||
z_streamp ,
|
||||
int));
|
||||
|
||||
extern void inflate_codes_free OF((
|
||||
inflate_codes_statef *,
|
||||
z_streamp ));
|
||||
|
|
@ -1,183 +0,0 @@
|
|||
/* inffast.c -- process literals and length/distance pairs fast
|
||||
* Copyright (C) 1995-2002 Mark Adler
|
||||
* For conditions of distribution and use, see copyright notice in zlib.h
|
||||
*/
|
||||
|
||||
#include "zutil.h"
|
||||
#include "inftrees.h"
|
||||
#include "infblock.h"
|
||||
#include "infcodes.h"
|
||||
#include "infutil.h"
|
||||
#include "inffast.h"
|
||||
|
||||
struct inflate_codes_state {int dummy;}; /* for buggy compilers */
|
||||
|
||||
/* simplify the use of the inflate_huft type with some defines */
|
||||
#define exop word.what.Exop
|
||||
#define bits word.what.Bits
|
||||
|
||||
/* macros for bit input with no checking and for returning unused bytes */
|
||||
#define GRABBITS(j) {while(k<(j)){b|=((uLong)NEXTBYTE)<<k;k+=8;}}
|
||||
#define UNGRAB {c=z->avail_in-n;c=(k>>3)<c?k>>3:c;n+=c;p-=c;k-=c<<3;}
|
||||
|
||||
/* Called with number of bytes left to write in window at least 258
|
||||
(the maximum string length) and number of input bytes available
|
||||
at least ten. The ten bytes are six bytes for the longest length/
|
||||
distance pair plus four bytes for overloading the bit buffer. */
|
||||
|
||||
int inflate_fast(bl, bd, tl, td, s, z)
|
||||
uInt bl, bd;
|
||||
inflate_huft *tl;
|
||||
inflate_huft *td; /* need separate declaration for Borland C++ */
|
||||
inflate_blocks_statef *s;
|
||||
z_streamp z;
|
||||
{
|
||||
inflate_huft *t; /* temporary pointer */
|
||||
uInt e; /* extra bits or operation */
|
||||
uLong b; /* bit buffer */
|
||||
uInt k; /* bits in bit buffer */
|
||||
Bytef *p; /* input data pointer */
|
||||
uInt n; /* bytes available there */
|
||||
Bytef *q; /* output window write pointer */
|
||||
uInt m; /* bytes to end of window or read pointer */
|
||||
uInt ml; /* mask for literal/length tree */
|
||||
uInt md; /* mask for distance tree */
|
||||
uInt c; /* bytes to copy */
|
||||
uInt d; /* distance back to copy from */
|
||||
Bytef *r; /* copy source pointer */
|
||||
|
||||
/* load input, output, bit values */
|
||||
LOAD
|
||||
|
||||
/* initialize masks */
|
||||
ml = inflate_mask[bl];
|
||||
md = inflate_mask[bd];
|
||||
|
||||
/* do until not enough input or output space for fast loop */
|
||||
do { /* assume called with m >= 258 && n >= 10 */
|
||||
/* get literal/length code */
|
||||
GRABBITS(20) /* max bits for literal/length code */
|
||||
if ((e = (t = tl + ((uInt)b & ml))->exop) == 0)
|
||||
{
|
||||
DUMPBITS(t->bits)
|
||||
Tracevv((stderr, t->base >= 0x20 && t->base < 0x7f ?
|
||||
"inflate: * literal '%c'\n" :
|
||||
"inflate: * literal 0x%02x\n", t->base));
|
||||
*q++ = (Byte)t->base;
|
||||
m--;
|
||||
continue;
|
||||
}
|
||||
do {
|
||||
DUMPBITS(t->bits)
|
||||
if (e & 16)
|
||||
{
|
||||
/* get extra bits for length */
|
||||
e &= 15;
|
||||
c = t->base + ((uInt)b & inflate_mask[e]);
|
||||
DUMPBITS(e)
|
||||
Tracevv((stderr, "inflate: * length %u\n", c));
|
||||
|
||||
/* decode distance base of block to copy */
|
||||
GRABBITS(15); /* max bits for distance code */
|
||||
e = (t = td + ((uInt)b & md))->exop;
|
||||
do {
|
||||
DUMPBITS(t->bits)
|
||||
if (e & 16)
|
||||
{
|
||||
/* get extra bits to add to distance base */
|
||||
e &= 15;
|
||||
GRABBITS(e) /* get extra bits (up to 13) */
|
||||
d = t->base + ((uInt)b & inflate_mask[e]);
|
||||
DUMPBITS(e)
|
||||
Tracevv((stderr, "inflate: * distance %u\n", d));
|
||||
|
||||
/* do the copy */
|
||||
m -= c;
|
||||
r = q - d;
|
||||
if (r < s->window) /* wrap if needed */
|
||||
{
|
||||
do {
|
||||
r += s->end - s->window; /* force pointer in window */
|
||||
} while (r < s->window); /* covers invalid distances */
|
||||
e = s->end - r;
|
||||
if (c > e)
|
||||
{
|
||||
c -= e; /* wrapped copy */
|
||||
do {
|
||||
*q++ = *r++;
|
||||
} while (--e);
|
||||
r = s->window;
|
||||
do {
|
||||
*q++ = *r++;
|
||||
} while (--c);
|
||||
}
|
||||
else /* normal copy */
|
||||
{
|
||||
*q++ = *r++; c--;
|
||||
*q++ = *r++; c--;
|
||||
do {
|
||||
*q++ = *r++;
|
||||
} while (--c);
|
||||
}
|
||||
}
|
||||
else /* normal copy */
|
||||
{
|
||||
*q++ = *r++; c--;
|
||||
*q++ = *r++; c--;
|
||||
do {
|
||||
*q++ = *r++;
|
||||
} while (--c);
|
||||
}
|
||||
break;
|
||||
}
|
||||
else if ((e & 64) == 0)
|
||||
{
|
||||
t += t->base;
|
||||
e = (t += ((uInt)b & inflate_mask[e]))->exop;
|
||||
}
|
||||
else
|
||||
{
|
||||
z->msg = (char*)"invalid distance code";
|
||||
UNGRAB
|
||||
UPDATE
|
||||
return Z_DATA_ERROR;
|
||||
}
|
||||
} while (1);
|
||||
break;
|
||||
}
|
||||
if ((e & 64) == 0)
|
||||
{
|
||||
t += t->base;
|
||||
if ((e = (t += ((uInt)b & inflate_mask[e]))->exop) == 0)
|
||||
{
|
||||
DUMPBITS(t->bits)
|
||||
Tracevv((stderr, t->base >= 0x20 && t->base < 0x7f ?
|
||||
"inflate: * literal '%c'\n" :
|
||||
"inflate: * literal 0x%02x\n", t->base));
|
||||
*q++ = (Byte)t->base;
|
||||
m--;
|
||||
break;
|
||||
}
|
||||
}
|
||||
else if (e & 32)
|
||||
{
|
||||
Tracevv((stderr, "inflate: * end of block\n"));
|
||||
UNGRAB
|
||||
UPDATE
|
||||
return Z_STREAM_END;
|
||||
}
|
||||
else
|
||||
{
|
||||
z->msg = (char*)"invalid literal/length code";
|
||||
UNGRAB
|
||||
UPDATE
|
||||
return Z_DATA_ERROR;
|
||||
}
|
||||
} while (1);
|
||||
} while (m >= 258 && n >= 10);
|
||||
|
||||
/* not enough input or output--restore pointers and return */
|
||||
UNGRAB
|
||||
UPDATE
|
||||
return Z_OK;
|
||||
}
|
|
@ -1,17 +0,0 @@
|
|||
/* inffast.h -- header to use inffast.c
|
||||
* Copyright (C) 1995-2002 Mark Adler
|
||||
* For conditions of distribution and use, see copyright notice in zlib.h
|
||||
*/
|
||||
|
||||
/* WARNING: this file should *not* be used by applications. It is
|
||||
part of the implementation of the compression library and is
|
||||
subject to change. Applications should only use zlib.h.
|
||||
*/
|
||||
|
||||
extern int inflate_fast OF((
|
||||
uInt,
|
||||
uInt,
|
||||
inflate_huft *,
|
||||
inflate_huft *,
|
||||
inflate_blocks_statef *,
|
||||
z_streamp ));
|
|
@ -1,151 +0,0 @@
|
|||
/* inffixed.h -- table for decoding fixed codes
|
||||
* Generated automatically by the maketree.c program
|
||||
*/
|
||||
|
||||
/* WARNING: this file should *not* be used by applications. It is
|
||||
part of the implementation of the compression library and is
|
||||
subject to change. Applications should only use zlib.h.
|
||||
*/
|
||||
|
||||
local uInt fixed_bl = 9;
|
||||
local uInt fixed_bd = 5;
|
||||
local inflate_huft fixed_tl[] = {
|
||||
{{{96,7}},256}, {{{0,8}},80}, {{{0,8}},16}, {{{84,8}},115},
|
||||
{{{82,7}},31}, {{{0,8}},112}, {{{0,8}},48}, {{{0,9}},192},
|
||||
{{{80,7}},10}, {{{0,8}},96}, {{{0,8}},32}, {{{0,9}},160},
|
||||
{{{0,8}},0}, {{{0,8}},128}, {{{0,8}},64}, {{{0,9}},224},
|
||||
{{{80,7}},6}, {{{0,8}},88}, {{{0,8}},24}, {{{0,9}},144},
|
||||
{{{83,7}},59}, {{{0,8}},120}, {{{0,8}},56}, {{{0,9}},208},
|
||||
{{{81,7}},17}, {{{0,8}},104}, {{{0,8}},40}, {{{0,9}},176},
|
||||
{{{0,8}},8}, {{{0,8}},136}, {{{0,8}},72}, {{{0,9}},240},
|
||||
{{{80,7}},4}, {{{0,8}},84}, {{{0,8}},20}, {{{85,8}},227},
|
||||
{{{83,7}},43}, {{{0,8}},116}, {{{0,8}},52}, {{{0,9}},200},
|
||||
{{{81,7}},13}, {{{0,8}},100}, {{{0,8}},36}, {{{0,9}},168},
|
||||
{{{0,8}},4}, {{{0,8}},132}, {{{0,8}},68}, {{{0,9}},232},
|
||||
{{{80,7}},8}, {{{0,8}},92}, {{{0,8}},28}, {{{0,9}},152},
|
||||
{{{84,7}},83}, {{{0,8}},124}, {{{0,8}},60}, {{{0,9}},216},
|
||||
{{{82,7}},23}, {{{0,8}},108}, {{{0,8}},44}, {{{0,9}},184},
|
||||
{{{0,8}},12}, {{{0,8}},140}, {{{0,8}},76}, {{{0,9}},248},
|
||||
{{{80,7}},3}, {{{0,8}},82}, {{{0,8}},18}, {{{85,8}},163},
|
||||
{{{83,7}},35}, {{{0,8}},114}, {{{0,8}},50}, {{{0,9}},196},
|
||||
{{{81,7}},11}, {{{0,8}},98}, {{{0,8}},34}, {{{0,9}},164},
|
||||
{{{0,8}},2}, {{{0,8}},130}, {{{0,8}},66}, {{{0,9}},228},
|
||||
{{{80,7}},7}, {{{0,8}},90}, {{{0,8}},26}, {{{0,9}},148},
|
||||
{{{84,7}},67}, {{{0,8}},122}, {{{0,8}},58}, {{{0,9}},212},
|
||||
{{{82,7}},19}, {{{0,8}},106}, {{{0,8}},42}, {{{0,9}},180},
|
||||
{{{0,8}},10}, {{{0,8}},138}, {{{0,8}},74}, {{{0,9}},244},
|
||||
{{{80,7}},5}, {{{0,8}},86}, {{{0,8}},22}, {{{192,8}},0},
|
||||
{{{83,7}},51}, {{{0,8}},118}, {{{0,8}},54}, {{{0,9}},204},
|
||||
{{{81,7}},15}, {{{0,8}},102}, {{{0,8}},38}, {{{0,9}},172},
|
||||
{{{0,8}},6}, {{{0,8}},134}, {{{0,8}},70}, {{{0,9}},236},
|
||||
{{{80,7}},9}, {{{0,8}},94}, {{{0,8}},30}, {{{0,9}},156},
|
||||
{{{84,7}},99}, {{{0,8}},126}, {{{0,8}},62}, {{{0,9}},220},
|
||||
{{{82,7}},27}, {{{0,8}},110}, {{{0,8}},46}, {{{0,9}},188},
|
||||
{{{0,8}},14}, {{{0,8}},142}, {{{0,8}},78}, {{{0,9}},252},
|
||||
{{{96,7}},256}, {{{0,8}},81}, {{{0,8}},17}, {{{85,8}},131},
|
||||
{{{82,7}},31}, {{{0,8}},113}, {{{0,8}},49}, {{{0,9}},194},
|
||||
{{{80,7}},10}, {{{0,8}},97}, {{{0,8}},33}, {{{0,9}},162},
|
||||
{{{0,8}},1}, {{{0,8}},129}, {{{0,8}},65}, {{{0,9}},226},
|
||||
{{{80,7}},6}, {{{0,8}},89}, {{{0,8}},25}, {{{0,9}},146},
|
||||
{{{83,7}},59}, {{{0,8}},121}, {{{0,8}},57}, {{{0,9}},210},
|
||||
{{{81,7}},17}, {{{0,8}},105}, {{{0,8}},41}, {{{0,9}},178},
|
||||
{{{0,8}},9}, {{{0,8}},137}, {{{0,8}},73}, {{{0,9}},242},
|
||||
{{{80,7}},4}, {{{0,8}},85}, {{{0,8}},21}, {{{80,8}},258},
|
||||
{{{83,7}},43}, {{{0,8}},117}, {{{0,8}},53}, {{{0,9}},202},
|
||||
{{{81,7}},13}, {{{0,8}},101}, {{{0,8}},37}, {{{0,9}},170},
|
||||
{{{0,8}},5}, {{{0,8}},133}, {{{0,8}},69}, {{{0,9}},234},
|
||||
{{{80,7}},8}, {{{0,8}},93}, {{{0,8}},29}, {{{0,9}},154},
|
||||
{{{84,7}},83}, {{{0,8}},125}, {{{0,8}},61}, {{{0,9}},218},
|
||||
{{{82,7}},23}, {{{0,8}},109}, {{{0,8}},45}, {{{0,9}},186},
|
||||
{{{0,8}},13}, {{{0,8}},141}, {{{0,8}},77}, {{{0,9}},250},
|
||||
{{{80,7}},3}, {{{0,8}},83}, {{{0,8}},19}, {{{85,8}},195},
|
||||
{{{83,7}},35}, {{{0,8}},115}, {{{0,8}},51}, {{{0,9}},198},
|
||||
{{{81,7}},11}, {{{0,8}},99}, {{{0,8}},35}, {{{0,9}},166},
|
||||
{{{0,8}},3}, {{{0,8}},131}, {{{0,8}},67}, {{{0,9}},230},
|
||||
{{{80,7}},7}, {{{0,8}},91}, {{{0,8}},27}, {{{0,9}},150},
|
||||
{{{84,7}},67}, {{{0,8}},123}, {{{0,8}},59}, {{{0,9}},214},
|
||||
{{{82,7}},19}, {{{0,8}},107}, {{{0,8}},43}, {{{0,9}},182},
|
||||
{{{0,8}},11}, {{{0,8}},139}, {{{0,8}},75}, {{{0,9}},246},
|
||||
{{{80,7}},5}, {{{0,8}},87}, {{{0,8}},23}, {{{192,8}},0},
|
||||
{{{83,7}},51}, {{{0,8}},119}, {{{0,8}},55}, {{{0,9}},206},
|
||||
{{{81,7}},15}, {{{0,8}},103}, {{{0,8}},39}, {{{0,9}},174},
|
||||
{{{0,8}},7}, {{{0,8}},135}, {{{0,8}},71}, {{{0,9}},238},
|
||||
{{{80,7}},9}, {{{0,8}},95}, {{{0,8}},31}, {{{0,9}},158},
|
||||
{{{84,7}},99}, {{{0,8}},127}, {{{0,8}},63}, {{{0,9}},222},
|
||||
{{{82,7}},27}, {{{0,8}},111}, {{{0,8}},47}, {{{0,9}},190},
|
||||
{{{0,8}},15}, {{{0,8}},143}, {{{0,8}},79}, {{{0,9}},254},
|
||||
{{{96,7}},256}, {{{0,8}},80}, {{{0,8}},16}, {{{84,8}},115},
|
||||
{{{82,7}},31}, {{{0,8}},112}, {{{0,8}},48}, {{{0,9}},193},
|
||||
{{{80,7}},10}, {{{0,8}},96}, {{{0,8}},32}, {{{0,9}},161},
|
||||
{{{0,8}},0}, {{{0,8}},128}, {{{0,8}},64}, {{{0,9}},225},
|
||||
{{{80,7}},6}, {{{0,8}},88}, {{{0,8}},24}, {{{0,9}},145},
|
||||
{{{83,7}},59}, {{{0,8}},120}, {{{0,8}},56}, {{{0,9}},209},
|
||||
{{{81,7}},17}, {{{0,8}},104}, {{{0,8}},40}, {{{0,9}},177},
|
||||
{{{0,8}},8}, {{{0,8}},136}, {{{0,8}},72}, {{{0,9}},241},
|
||||
{{{80,7}},4}, {{{0,8}},84}, {{{0,8}},20}, {{{85,8}},227},
|
||||
{{{83,7}},43}, {{{0,8}},116}, {{{0,8}},52}, {{{0,9}},201},
|
||||
{{{81,7}},13}, {{{0,8}},100}, {{{0,8}},36}, {{{0,9}},169},
|
||||
{{{0,8}},4}, {{{0,8}},132}, {{{0,8}},68}, {{{0,9}},233},
|
||||
{{{80,7}},8}, {{{0,8}},92}, {{{0,8}},28}, {{{0,9}},153},
|
||||
{{{84,7}},83}, {{{0,8}},124}, {{{0,8}},60}, {{{0,9}},217},
|
||||
{{{82,7}},23}, {{{0,8}},108}, {{{0,8}},44}, {{{0,9}},185},
|
||||
{{{0,8}},12}, {{{0,8}},140}, {{{0,8}},76}, {{{0,9}},249},
|
||||
{{{80,7}},3}, {{{0,8}},82}, {{{0,8}},18}, {{{85,8}},163},
|
||||
{{{83,7}},35}, {{{0,8}},114}, {{{0,8}},50}, {{{0,9}},197},
|
||||
{{{81,7}},11}, {{{0,8}},98}, {{{0,8}},34}, {{{0,9}},165},
|
||||
{{{0,8}},2}, {{{0,8}},130}, {{{0,8}},66}, {{{0,9}},229},
|
||||
{{{80,7}},7}, {{{0,8}},90}, {{{0,8}},26}, {{{0,9}},149},
|
||||
{{{84,7}},67}, {{{0,8}},122}, {{{0,8}},58}, {{{0,9}},213},
|
||||
{{{82,7}},19}, {{{0,8}},106}, {{{0,8}},42}, {{{0,9}},181},
|
||||
{{{0,8}},10}, {{{0,8}},138}, {{{0,8}},74}, {{{0,9}},245},
|
||||
{{{80,7}},5}, {{{0,8}},86}, {{{0,8}},22}, {{{192,8}},0},
|
||||
{{{83,7}},51}, {{{0,8}},118}, {{{0,8}},54}, {{{0,9}},205},
|
||||
{{{81,7}},15}, {{{0,8}},102}, {{{0,8}},38}, {{{0,9}},173},
|
||||
{{{0,8}},6}, {{{0,8}},134}, {{{0,8}},70}, {{{0,9}},237},
|
||||
{{{80,7}},9}, {{{0,8}},94}, {{{0,8}},30}, {{{0,9}},157},
|
||||
{{{84,7}},99}, {{{0,8}},126}, {{{0,8}},62}, {{{0,9}},221},
|
||||
{{{82,7}},27}, {{{0,8}},110}, {{{0,8}},46}, {{{0,9}},189},
|
||||
{{{0,8}},14}, {{{0,8}},142}, {{{0,8}},78}, {{{0,9}},253},
|
||||
{{{96,7}},256}, {{{0,8}},81}, {{{0,8}},17}, {{{85,8}},131},
|
||||
{{{82,7}},31}, {{{0,8}},113}, {{{0,8}},49}, {{{0,9}},195},
|
||||
{{{80,7}},10}, {{{0,8}},97}, {{{0,8}},33}, {{{0,9}},163},
|
||||
{{{0,8}},1}, {{{0,8}},129}, {{{0,8}},65}, {{{0,9}},227},
|
||||
{{{80,7}},6}, {{{0,8}},89}, {{{0,8}},25}, {{{0,9}},147},
|
||||
{{{83,7}},59}, {{{0,8}},121}, {{{0,8}},57}, {{{0,9}},211},
|
||||
{{{81,7}},17}, {{{0,8}},105}, {{{0,8}},41}, {{{0,9}},179},
|
||||
{{{0,8}},9}, {{{0,8}},137}, {{{0,8}},73}, {{{0,9}},243},
|
||||
{{{80,7}},4}, {{{0,8}},85}, {{{0,8}},21}, {{{80,8}},258},
|
||||
{{{83,7}},43}, {{{0,8}},117}, {{{0,8}},53}, {{{0,9}},203},
|
||||
{{{81,7}},13}, {{{0,8}},101}, {{{0,8}},37}, {{{0,9}},171},
|
||||
{{{0,8}},5}, {{{0,8}},133}, {{{0,8}},69}, {{{0,9}},235},
|
||||
{{{80,7}},8}, {{{0,8}},93}, {{{0,8}},29}, {{{0,9}},155},
|
||||
{{{84,7}},83}, {{{0,8}},125}, {{{0,8}},61}, {{{0,9}},219},
|
||||
{{{82,7}},23}, {{{0,8}},109}, {{{0,8}},45}, {{{0,9}},187},
|
||||
{{{0,8}},13}, {{{0,8}},141}, {{{0,8}},77}, {{{0,9}},251},
|
||||
{{{80,7}},3}, {{{0,8}},83}, {{{0,8}},19}, {{{85,8}},195},
|
||||
{{{83,7}},35}, {{{0,8}},115}, {{{0,8}},51}, {{{0,9}},199},
|
||||
{{{81,7}},11}, {{{0,8}},99}, {{{0,8}},35}, {{{0,9}},167},
|
||||
{{{0,8}},3}, {{{0,8}},131}, {{{0,8}},67}, {{{0,9}},231},
|
||||
{{{80,7}},7}, {{{0,8}},91}, {{{0,8}},27}, {{{0,9}},151},
|
||||
{{{84,7}},67}, {{{0,8}},123}, {{{0,8}},59}, {{{0,9}},215},
|
||||
{{{82,7}},19}, {{{0,8}},107}, {{{0,8}},43}, {{{0,9}},183},
|
||||
{{{0,8}},11}, {{{0,8}},139}, {{{0,8}},75}, {{{0,9}},247},
|
||||
{{{80,7}},5}, {{{0,8}},87}, {{{0,8}},23}, {{{192,8}},0},
|
||||
{{{83,7}},51}, {{{0,8}},119}, {{{0,8}},55}, {{{0,9}},207},
|
||||
{{{81,7}},15}, {{{0,8}},103}, {{{0,8}},39}, {{{0,9}},175},
|
||||
{{{0,8}},7}, {{{0,8}},135}, {{{0,8}},71}, {{{0,9}},239},
|
||||
{{{80,7}},9}, {{{0,8}},95}, {{{0,8}},31}, {{{0,9}},159},
|
||||
{{{84,7}},99}, {{{0,8}},127}, {{{0,8}},63}, {{{0,9}},223},
|
||||
{{{82,7}},27}, {{{0,8}},111}, {{{0,8}},47}, {{{0,9}},191},
|
||||
{{{0,8}},15}, {{{0,8}},143}, {{{0,8}},79}, {{{0,9}},255}
|
||||
};
|
||||
local inflate_huft fixed_td[] = {
|
||||
{{{80,5}},1}, {{{87,5}},257}, {{{83,5}},17}, {{{91,5}},4097},
|
||||
{{{81,5}},5}, {{{89,5}},1025}, {{{85,5}},65}, {{{93,5}},16385},
|
||||
{{{80,5}},3}, {{{88,5}},513}, {{{84,5}},33}, {{{92,5}},8193},
|
||||
{{{82,5}},9}, {{{90,5}},2049}, {{{86,5}},129}, {{{192,5}},24577},
|
||||
{{{80,5}},2}, {{{87,5}},385}, {{{83,5}},25}, {{{91,5}},6145},
|
||||
{{{81,5}},7}, {{{89,5}},1537}, {{{85,5}},97}, {{{93,5}},24577},
|
||||
{{{80,5}},4}, {{{88,5}},769}, {{{84,5}},49}, {{{92,5}},12289},
|
||||
{{{82,5}},13}, {{{90,5}},3073}, {{{86,5}},193}, {{{192,5}},24577}
|
||||
};
|
|
@ -1,366 +0,0 @@
|
|||
/* inflate.c -- zlib interface to inflate modules
|
||||
* Copyright (C) 1995-2002 Mark Adler
|
||||
* For conditions of distribution and use, see copyright notice in zlib.h
|
||||
*/
|
||||
|
||||
#include "zutil.h"
|
||||
#include "infblock.h"
|
||||
|
||||
struct inflate_blocks_state {int dummy;}; /* for buggy compilers */
|
||||
|
||||
typedef enum {
|
||||
METHOD, /* waiting for method byte */
|
||||
FLAG, /* waiting for flag byte */
|
||||
DICT4, /* four dictionary check bytes to go */
|
||||
DICT3, /* three dictionary check bytes to go */
|
||||
DICT2, /* two dictionary check bytes to go */
|
||||
DICT1, /* one dictionary check byte to go */
|
||||
DICT0, /* waiting for inflateSetDictionary */
|
||||
BLOCKS, /* decompressing blocks */
|
||||
CHECK4, /* four check bytes to go */
|
||||
CHECK3, /* three check bytes to go */
|
||||
CHECK2, /* two check bytes to go */
|
||||
CHECK1, /* one check byte to go */
|
||||
DONE, /* finished check, done */
|
||||
BAD} /* got an error--stay here */
|
||||
inflate_mode;
|
||||
|
||||
/* inflate private state */
|
||||
struct internal_state {
|
||||
|
||||
/* mode */
|
||||
inflate_mode mode; /* current inflate mode */
|
||||
|
||||
/* mode dependent information */
|
||||
union {
|
||||
uInt method; /* if FLAGS, method byte */
|
||||
struct {
|
||||
uLong was; /* computed check value */
|
||||
uLong need; /* stream check value */
|
||||
} check; /* if CHECK, check values to compare */
|
||||
uInt marker; /* if BAD, inflateSync's marker bytes count */
|
||||
} sub; /* submode */
|
||||
|
||||
/* mode independent information */
|
||||
int nowrap; /* flag for no wrapper */
|
||||
uInt wbits; /* log2(window size) (8..15, defaults to 15) */
|
||||
inflate_blocks_statef
|
||||
*blocks; /* current inflate_blocks state */
|
||||
|
||||
};
|
||||
|
||||
|
||||
int ZEXPORT inflateReset(z)
|
||||
z_streamp z;
|
||||
{
|
||||
if (z == Z_NULL || z->state == Z_NULL)
|
||||
return Z_STREAM_ERROR;
|
||||
z->total_in = z->total_out = 0;
|
||||
z->msg = Z_NULL;
|
||||
z->state->mode = z->state->nowrap ? BLOCKS : METHOD;
|
||||
inflate_blocks_reset(z->state->blocks, z, Z_NULL);
|
||||
Tracev((stderr, "inflate: reset\n"));
|
||||
return Z_OK;
|
||||
}
|
||||
|
||||
|
||||
int ZEXPORT inflateEnd(z)
|
||||
z_streamp z;
|
||||
{
|
||||
if (z == Z_NULL || z->state == Z_NULL || z->zfree == Z_NULL)
|
||||
return Z_STREAM_ERROR;
|
||||
if (z->state->blocks != Z_NULL)
|
||||
inflate_blocks_free(z->state->blocks, z);
|
||||
ZFREE(z, z->state);
|
||||
z->state = Z_NULL;
|
||||
Tracev((stderr, "inflate: end\n"));
|
||||
return Z_OK;
|
||||
}
|
||||
|
||||
|
||||
int ZEXPORT inflateInit2_(z, w, version, stream_size)
|
||||
z_streamp z;
|
||||
int w;
|
||||
const char *version;
|
||||
int stream_size;
|
||||
{
|
||||
if (version == Z_NULL || version[0] != ZLIB_VERSION[0] ||
|
||||
stream_size != sizeof(z_stream))
|
||||
return Z_VERSION_ERROR;
|
||||
|
||||
/* initialize state */
|
||||
if (z == Z_NULL)
|
||||
return Z_STREAM_ERROR;
|
||||
z->msg = Z_NULL;
|
||||
if (z->zalloc == Z_NULL)
|
||||
{
|
||||
z->zalloc = zcalloc;
|
||||
z->opaque = (voidpf)0;
|
||||
}
|
||||
if (z->zfree == Z_NULL) z->zfree = zcfree;
|
||||
if ((z->state = (struct internal_state FAR *)
|
||||
ZALLOC(z,1,sizeof(struct internal_state))) == Z_NULL)
|
||||
return Z_MEM_ERROR;
|
||||
z->state->blocks = Z_NULL;
|
||||
|
||||
/* handle undocumented nowrap option (no zlib header or check) */
|
||||
z->state->nowrap = 0;
|
||||
if (w < 0)
|
||||
{
|
||||
w = - w;
|
||||
z->state->nowrap = 1;
|
||||
}
|
||||
|
||||
/* set window size */
|
||||
if (w < 8 || w > 15)
|
||||
{
|
||||
inflateEnd(z);
|
||||
return Z_STREAM_ERROR;
|
||||
}
|
||||
z->state->wbits = (uInt)w;
|
||||
|
||||
/* create inflate_blocks state */
|
||||
if ((z->state->blocks =
|
||||
inflate_blocks_new(z, z->state->nowrap ? Z_NULL : adler32, (uInt)1 << w))
|
||||
== Z_NULL)
|
||||
{
|
||||
inflateEnd(z);
|
||||
return Z_MEM_ERROR;
|
||||
}
|
||||
Tracev((stderr, "inflate: allocated\n"));
|
||||
|
||||
/* reset state */
|
||||
inflateReset(z);
|
||||
return Z_OK;
|
||||
}
|
||||
|
||||
|
||||
int ZEXPORT inflateInit_(z, version, stream_size)
|
||||
z_streamp z;
|
||||
const char *version;
|
||||
int stream_size;
|
||||
{
|
||||
return inflateInit2_(z, DEF_WBITS, version, stream_size);
|
||||
}
|
||||
|
||||
|
||||
#define NEEDBYTE {if(z->avail_in==0)return r;r=f;}
|
||||
#define NEXTBYTE (z->avail_in--,z->total_in++,*z->next_in++)
|
||||
|
||||
int ZEXPORT inflate(z, f)
|
||||
z_streamp z;
|
||||
int f;
|
||||
{
|
||||
int r;
|
||||
uInt b;
|
||||
|
||||
if (z == Z_NULL || z->state == Z_NULL || z->next_in == Z_NULL)
|
||||
return Z_STREAM_ERROR;
|
||||
f = f == Z_FINISH ? Z_BUF_ERROR : Z_OK;
|
||||
r = Z_BUF_ERROR;
|
||||
while (1) switch (z->state->mode)
|
||||
{
|
||||
case METHOD:
|
||||
NEEDBYTE
|
||||
if (((z->state->sub.method = NEXTBYTE) & 0xf) != Z_DEFLATED)
|
||||
{
|
||||
z->state->mode = BAD;
|
||||
z->msg = (char*)"unknown compression method";
|
||||
z->state->sub.marker = 5; /* can't try inflateSync */
|
||||
break;
|
||||
}
|
||||
if ((z->state->sub.method >> 4) + 8 > z->state->wbits)
|
||||
{
|
||||
z->state->mode = BAD;
|
||||
z->msg = (char*)"invalid window size";
|
||||
z->state->sub.marker = 5; /* can't try inflateSync */
|
||||
break;
|
||||
}
|
||||
z->state->mode = FLAG;
|
||||
case FLAG:
|
||||
NEEDBYTE
|
||||
b = NEXTBYTE;
|
||||
if (((z->state->sub.method << 8) + b) % 31)
|
||||
{
|
||||
z->state->mode = BAD;
|
||||
z->msg = (char*)"incorrect header check";
|
||||
z->state->sub.marker = 5; /* can't try inflateSync */
|
||||
break;
|
||||
}
|
||||
Tracev((stderr, "inflate: zlib header ok\n"));
|
||||
if (!(b & PRESET_DICT))
|
||||
{
|
||||
z->state->mode = BLOCKS;
|
||||
break;
|
||||
}
|
||||
z->state->mode = DICT4;
|
||||
case DICT4:
|
||||
NEEDBYTE
|
||||
z->state->sub.check.need = (uLong)NEXTBYTE << 24;
|
||||
z->state->mode = DICT3;
|
||||
case DICT3:
|
||||
NEEDBYTE
|
||||
z->state->sub.check.need += (uLong)NEXTBYTE << 16;
|
||||
z->state->mode = DICT2;
|
||||
case DICT2:
|
||||
NEEDBYTE
|
||||
z->state->sub.check.need += (uLong)NEXTBYTE << 8;
|
||||
z->state->mode = DICT1;
|
||||
case DICT1:
|
||||
NEEDBYTE
|
||||
z->state->sub.check.need += (uLong)NEXTBYTE;
|
||||
z->adler = z->state->sub.check.need;
|
||||
z->state->mode = DICT0;
|
||||
return Z_NEED_DICT;
|
||||
case DICT0:
|
||||
z->state->mode = BAD;
|
||||
z->msg = (char*)"need dictionary";
|
||||
z->state->sub.marker = 0; /* can try inflateSync */
|
||||
return Z_STREAM_ERROR;
|
||||
case BLOCKS:
|
||||
r = inflate_blocks(z->state->blocks, z, r);
|
||||
if (r == Z_DATA_ERROR)
|
||||
{
|
||||
z->state->mode = BAD;
|
||||
z->state->sub.marker = 0; /* can try inflateSync */
|
||||
break;
|
||||
}
|
||||
if (r == Z_OK)
|
||||
r = f;
|
||||
if (r != Z_STREAM_END)
|
||||
return r;
|
||||
r = f;
|
||||
inflate_blocks_reset(z->state->blocks, z, &z->state->sub.check.was);
|
||||
if (z->state->nowrap)
|
||||
{
|
||||
z->state->mode = DONE;
|
||||
break;
|
||||
}
|
||||
z->state->mode = CHECK4;
|
||||
case CHECK4:
|
||||
NEEDBYTE
|
||||
z->state->sub.check.need = (uLong)NEXTBYTE << 24;
|
||||
z->state->mode = CHECK3;
|
||||
case CHECK3:
|
||||
NEEDBYTE
|
||||
z->state->sub.check.need += (uLong)NEXTBYTE << 16;
|
||||
z->state->mode = CHECK2;
|
||||
case CHECK2:
|
||||
NEEDBYTE
|
||||
z->state->sub.check.need += (uLong)NEXTBYTE << 8;
|
||||
z->state->mode = CHECK1;
|
||||
case CHECK1:
|
||||
NEEDBYTE
|
||||
z->state->sub.check.need += (uLong)NEXTBYTE;
|
||||
|
||||
if (z->state->sub.check.was != z->state->sub.check.need)
|
||||
{
|
||||
z->state->mode = BAD;
|
||||
z->msg = (char*)"incorrect data check";
|
||||
z->state->sub.marker = 5; /* can't try inflateSync */
|
||||
break;
|
||||
}
|
||||
Tracev((stderr, "inflate: zlib check ok\n"));
|
||||
z->state->mode = DONE;
|
||||
case DONE:
|
||||
return Z_STREAM_END;
|
||||
case BAD:
|
||||
return Z_DATA_ERROR;
|
||||
default:
|
||||
return Z_STREAM_ERROR;
|
||||
}
|
||||
#ifdef NEED_DUMMY_RETURN
|
||||
return Z_STREAM_ERROR; /* Some dumb compilers complain without this */
|
||||
#endif
|
||||
}
|
||||
|
||||
|
||||
int ZEXPORT inflateSetDictionary(z, dictionary, dictLength)
|
||||
z_streamp z;
|
||||
const Bytef *dictionary;
|
||||
uInt dictLength;
|
||||
{
|
||||
uInt length = dictLength;
|
||||
|
||||
if (z == Z_NULL || z->state == Z_NULL || z->state->mode != DICT0)
|
||||
return Z_STREAM_ERROR;
|
||||
|
||||
if (adler32(1L, dictionary, dictLength) != z->adler) return Z_DATA_ERROR;
|
||||
z->adler = 1L;
|
||||
|
||||
if (length >= ((uInt)1<<z->state->wbits))
|
||||
{
|
||||
length = (1<<z->state->wbits)-1;
|
||||
dictionary += dictLength - length;
|
||||
}
|
||||
inflate_set_dictionary(z->state->blocks, dictionary, length);
|
||||
z->state->mode = BLOCKS;
|
||||
return Z_OK;
|
||||
}
|
||||
|
||||
|
||||
int ZEXPORT inflateSync(z)
|
||||
z_streamp z;
|
||||
{
|
||||
uInt n; /* number of bytes to look at */
|
||||
Bytef *p; /* pointer to bytes */
|
||||
uInt m; /* number of marker bytes found in a row */
|
||||
uLong r, w; /* temporaries to save total_in and total_out */
|
||||
|
||||
/* set up */
|
||||
if (z == Z_NULL || z->state == Z_NULL)
|
||||
return Z_STREAM_ERROR;
|
||||
if (z->state->mode != BAD)
|
||||
{
|
||||
z->state->mode = BAD;
|
||||
z->state->sub.marker = 0;
|
||||
}
|
||||
if ((n = z->avail_in) == 0)
|
||||
return Z_BUF_ERROR;
|
||||
p = z->next_in;
|
||||
m = z->state->sub.marker;
|
||||
|
||||
/* search */
|
||||
while (n && m < 4)
|
||||
{
|
||||
static const Byte mark[4] = {0, 0, 0xff, 0xff};
|
||||
if (*p == mark[m])
|
||||
m++;
|
||||
else if (*p)
|
||||
m = 0;
|
||||
else
|
||||
m = 4 - m;
|
||||
p++, n--;
|
||||
}
|
||||
|
||||
/* restore */
|
||||
z->total_in += p - z->next_in;
|
||||
z->next_in = p;
|
||||
z->avail_in = n;
|
||||
z->state->sub.marker = m;
|
||||
|
||||
/* return no joy or set up to restart on a new block */
|
||||
if (m != 4)
|
||||
return Z_DATA_ERROR;
|
||||
r = z->total_in; w = z->total_out;
|
||||
inflateReset(z);
|
||||
z->total_in = r; z->total_out = w;
|
||||
z->state->mode = BLOCKS;
|
||||
return Z_OK;
|
||||
}
|
||||
|
||||
|
||||
/* Returns true if inflate is currently at the end of a block generated
|
||||
* by Z_SYNC_FLUSH or Z_FULL_FLUSH. This function is used by one PPP
|
||||
* implementation to provide an additional safety check. PPP uses Z_SYNC_FLUSH
|
||||
* but removes the length bytes of the resulting empty stored block. When
|
||||
* decompressing, PPP checks that at the end of input packet, inflate is
|
||||
* waiting for these length bytes.
|
||||
*/
|
||||
int ZEXPORT inflateSyncPoint(z)
|
||||
z_streamp z;
|
||||
{
|
||||
if (z == Z_NULL || z->state == Z_NULL || z->state->blocks == Z_NULL)
|
||||
return Z_STREAM_ERROR;
|
||||
return inflate_blocks_sync_point(z->state->blocks);
|
||||
}
|
|
@ -1,454 +0,0 @@
|
|||
/* inftrees.c -- generate Huffman trees for efficient decoding
|
||||
* Copyright (C) 1995-2002 Mark Adler
|
||||
* For conditions of distribution and use, see copyright notice in zlib.h
|
||||
*/
|
||||
|
||||
#include "zutil.h"
|
||||
#include "inftrees.h"
|
||||
|
||||
#if !defined(BUILDFIXED) && !defined(STDC)
|
||||
# define BUILDFIXED /* non ANSI compilers may not accept inffixed.h */
|
||||
#endif
|
||||
|
||||
const char inflate_copyright[] =
|
||||
" inflate 1.1.4 Copyright 1995-2002 Mark Adler ";
|
||||
/*
|
||||
If you use the zlib library in a product, an acknowledgment is welcome
|
||||
in the documentation of your product. If for some reason you cannot
|
||||
include such an acknowledgment, I would appreciate that you keep this
|
||||
copyright string in the executable of your product.
|
||||
*/
|
||||
struct internal_state {int dummy;}; /* for buggy compilers */
|
||||
|
||||
/* simplify the use of the inflate_huft type with some defines */
|
||||
#define exop word.what.Exop
|
||||
#define bits word.what.Bits
|
||||
|
||||
|
||||
local int huft_build OF((
|
||||
uIntf *, /* code lengths in bits */
|
||||
uInt, /* number of codes */
|
||||
uInt, /* number of "simple" codes */
|
||||
const uIntf *, /* list of base values for non-simple codes */
|
||||
const uIntf *, /* list of extra bits for non-simple codes */
|
||||
inflate_huft * FAR*,/* result: starting table */
|
||||
uIntf *, /* maximum lookup bits (returns actual) */
|
||||
inflate_huft *, /* space for trees */
|
||||
uInt *, /* hufts used in space */
|
||||
uIntf * )); /* space for values */
|
||||
|
||||
/* Tables for deflate from PKZIP's appnote.txt. */
|
||||
local const uInt cplens[31] = { /* Copy lengths for literal codes 257..285 */
|
||||
3, 4, 5, 6, 7, 8, 9, 10, 11, 13, 15, 17, 19, 23, 27, 31,
|
||||
35, 43, 51, 59, 67, 83, 99, 115, 131, 163, 195, 227, 258, 0, 0};
|
||||
/* see note #13 above about 258 */
|
||||
local const uInt cplext[31] = { /* Extra bits for literal codes 257..285 */
|
||||
0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 1, 1, 2, 2, 2, 2,
|
||||
3, 3, 3, 3, 4, 4, 4, 4, 5, 5, 5, 5, 0, 112, 112}; /* 112==invalid */
|
||||
local const uInt cpdist[30] = { /* Copy offsets for distance codes 0..29 */
|
||||
1, 2, 3, 4, 5, 7, 9, 13, 17, 25, 33, 49, 65, 97, 129, 193,
|
||||
257, 385, 513, 769, 1025, 1537, 2049, 3073, 4097, 6145,
|
||||
8193, 12289, 16385, 24577};
|
||||
local const uInt cpdext[30] = { /* Extra bits for distance codes */
|
||||
0, 0, 0, 0, 1, 1, 2, 2, 3, 3, 4, 4, 5, 5, 6, 6,
|
||||
7, 7, 8, 8, 9, 9, 10, 10, 11, 11,
|
||||
12, 12, 13, 13};
|
||||
|
||||
/*
|
||||
Huffman code decoding is performed using a multi-level table lookup.
|
||||
The fastest way to decode is to simply build a lookup table whose
|
||||
size is determined by the longest code. However, the time it takes
|
||||
to build this table can also be a factor if the data being decoded
|
||||
is not very long. The most common codes are necessarily the
|
||||
shortest codes, so those codes dominate the decoding time, and hence
|
||||
the speed. The idea is you can have a shorter table that decodes the
|
||||
shorter, more probable codes, and then point to subsidiary tables for
|
||||
the longer codes. The time it costs to decode the longer codes is
|
||||
then traded against the time it takes to make longer tables.
|
||||
|
||||
This results of this trade are in the variables lbits and dbits
|
||||
below. lbits is the number of bits the first level table for literal/
|
||||
length codes can decode in one step, and dbits is the same thing for
|
||||
the distance codes. Subsequent tables are also less than or equal to
|
||||
those sizes. These values may be adjusted either when all of the
|
||||
codes are shorter than that, in which case the longest code length in
|
||||
bits is used, or when the shortest code is *longer* than the requested
|
||||
table size, in which case the length of the shortest code in bits is
|
||||
used.
|
||||
|
||||
There are two different values for the two tables, since they code a
|
||||
different number of possibilities each. The literal/length table
|
||||
codes 286 possible values, or in a flat code, a little over eight
|
||||
bits. The distance table codes 30 possible values, or a little less
|
||||
than five bits, flat. The optimum values for speed end up being
|
||||
about one bit more than those, so lbits is 8+1 and dbits is 5+1.
|
||||
The optimum values may differ though from machine to machine, and
|
||||
possibly even between compilers. Your mileage may vary.
|
||||
*/
|
||||
|
||||
|
||||
/* If BMAX needs to be larger than 16, then h and x[] should be uLong. */
|
||||
#define BMAX 15 /* maximum bit length of any code */
|
||||
|
||||
local int huft_build(b, n, s, d, e, t, m, hp, hn, v)
|
||||
uIntf *b; /* code lengths in bits (all assumed <= BMAX) */
|
||||
uInt n; /* number of codes (assumed <= 288) */
|
||||
uInt s; /* number of simple-valued codes (0..s-1) */
|
||||
const uIntf *d; /* list of base values for non-simple codes */
|
||||
const uIntf *e; /* list of extra bits for non-simple codes */
|
||||
inflate_huft * FAR *t; /* result: starting table */
|
||||
uIntf *m; /* maximum lookup bits, returns actual */
|
||||
inflate_huft *hp; /* space for trees */
|
||||
uInt *hn; /* hufts used in space */
|
||||
uIntf *v; /* working area: values in order of bit length */
|
||||
/* Given a list of code lengths and a maximum table size, make a set of
|
||||
tables to decode that set of codes. Return Z_OK on success, Z_BUF_ERROR
|
||||
if the given code set is incomplete (the tables are still built in this
|
||||
case), or Z_DATA_ERROR if the input is invalid. */
|
||||
{
|
||||
|
||||
uInt a; /* counter for codes of length k */
|
||||
uInt c[BMAX+1]; /* bit length count table */
|
||||
uInt f; /* i repeats in table every f entries */
|
||||
int g; /* maximum code length */
|
||||
int h; /* table level */
|
||||
register uInt i; /* counter, current code */
|
||||
register uInt j; /* counter */
|
||||
register int k; /* number of bits in current code */
|
||||
int l; /* bits per table (returned in m) */
|
||||
uInt mask; /* (1 << w) - 1, to avoid cc -O bug on HP */
|
||||
register uIntf *p; /* pointer into c[], b[], or v[] */
|
||||
inflate_huft *q; /* points to current table */
|
||||
struct inflate_huft_s r; /* table entry for structure assignment */
|
||||
inflate_huft *u[BMAX]; /* table stack */
|
||||
register int w; /* bits before this table == (l * h) */
|
||||
uInt x[BMAX+1]; /* bit offsets, then code stack */
|
||||
uIntf *xp; /* pointer into x */
|
||||
int y; /* number of dummy codes added */
|
||||
uInt z; /* number of entries in current table */
|
||||
|
||||
|
||||
/* Generate counts for each bit length */
|
||||
p = c;
|
||||
#define C0 *p++ = 0;
|
||||
#define C2 C0 C0 C0 C0
|
||||
#define C4 C2 C2 C2 C2
|
||||
C4 /* clear c[]--assume BMAX+1 is 16 */
|
||||
p = b; i = n;
|
||||
do {
|
||||
c[*p++]++; /* assume all entries <= BMAX */
|
||||
} while (--i);
|
||||
if (c[0] == n) /* null input--all zero length codes */
|
||||
{
|
||||
*t = (inflate_huft *)Z_NULL;
|
||||
*m = 0;
|
||||
return Z_OK;
|
||||
}
|
||||
|
||||
|
||||
/* Find minimum and maximum length, bound *m by those */
|
||||
l = *m;
|
||||
for (j = 1; j <= BMAX; j++)
|
||||
if (c[j])
|
||||
break;
|
||||
k = j; /* minimum code length */
|
||||
if ((uInt)l < j)
|
||||
l = j;
|
||||
for (i = BMAX; i; i--)
|
||||
if (c[i])
|
||||
break;
|
||||
g = i; /* maximum code length */
|
||||
if ((uInt)l > i)
|
||||
l = i;
|
||||
*m = l;
|
||||
|
||||
|
||||
/* Adjust last length count to fill out codes, if needed */
|
||||
for (y = 1 << j; j < i; j++, y <<= 1)
|
||||
if ((y -= c[j]) < 0)
|
||||
return Z_DATA_ERROR;
|
||||
if ((y -= c[i]) < 0)
|
||||
return Z_DATA_ERROR;
|
||||
c[i] += y;
|
||||
|
||||
|
||||
/* Generate starting offsets into the value table for each length */
|
||||
x[1] = j = 0;
|
||||
p = c + 1; xp = x + 2;
|
||||
while (--i) { /* note that i == g from above */
|
||||
*xp++ = (j += *p++);
|
||||
}
|
||||
|
||||
|
||||
/* Make a table of values in order of bit lengths */
|
||||
p = b; i = 0;
|
||||
do {
|
||||
if ((j = *p++) != 0)
|
||||
v[x[j]++] = i;
|
||||
} while (++i < n);
|
||||
n = x[g]; /* set n to length of v */
|
||||
|
||||
|
||||
/* Generate the Huffman codes and for each, make the table entries */
|
||||
x[0] = i = 0; /* first Huffman code is zero */
|
||||
p = v; /* grab values in bit order */
|
||||
h = -1; /* no tables yet--level -1 */
|
||||
w = -l; /* bits decoded == (l * h) */
|
||||
u[0] = (inflate_huft *)Z_NULL; /* just to keep compilers happy */
|
||||
q = (inflate_huft *)Z_NULL; /* ditto */
|
||||
z = 0; /* ditto */
|
||||
|
||||
/* go through the bit lengths (k already is bits in shortest code) */
|
||||
for (; k <= g; k++)
|
||||
{
|
||||
a = c[k];
|
||||
while (a--)
|
||||
{
|
||||
/* here i is the Huffman code of length k bits for value *p */
|
||||
/* make tables up to required level */
|
||||
while (k > w + l)
|
||||
{
|
||||
h++;
|
||||
w += l; /* previous table always l bits */
|
||||
|
||||
/* compute minimum size table less than or equal to l bits */
|
||||
z = g - w;
|
||||
z = z > (uInt)l ? l : z; /* table size upper limit */
|
||||
if ((f = 1 << (j = k - w)) > a + 1) /* try a k-w bit table */
|
||||
{ /* too few codes for k-w bit table */
|
||||
f -= a + 1; /* deduct codes from patterns left */
|
||||
xp = c + k;
|
||||
if (j < z)
|
||||
while (++j < z) /* try smaller tables up to z bits */
|
||||
{
|
||||
if ((f <<= 1) <= *++xp)
|
||||
break; /* enough codes to use up j bits */
|
||||
f -= *xp; /* else deduct codes from patterns */
|
||||
}
|
||||
}
|
||||
z = 1 << j; /* table entries for j-bit table */
|
||||
|
||||
/* allocate new table */
|
||||
if (*hn + z > MANY) /* (note: doesn't matter for fixed) */
|
||||
return Z_DATA_ERROR; /* overflow of MANY */
|
||||
u[h] = q = hp + *hn;
|
||||
*hn += z;
|
||||
|
||||
/* connect to last table, if there is one */
|
||||
if (h)
|
||||
{
|
||||
x[h] = i; /* save pattern for backing up */
|
||||
r.bits = (Byte)l; /* bits to dump before this table */
|
||||
r.exop = (Byte)j; /* bits in this table */
|
||||
j = i >> (w - l);
|
||||
r.base = (uInt)(q - u[h-1] - j); /* offset to this table */
|
||||
u[h-1][j] = r; /* connect to last table */
|
||||
}
|
||||
else
|
||||
*t = q; /* first table is returned result */
|
||||
}
|
||||
|
||||
/* set up table entry in r */
|
||||
r.bits = (Byte)(k - w);
|
||||
if (p >= v + n)
|
||||
r.exop = 128 + 64; /* out of values--invalid code */
|
||||
else if (*p < s)
|
||||
{
|
||||
r.exop = (Byte)(*p < 256 ? 0 : 32 + 64); /* 256 is end-of-block */
|
||||
r.base = *p++; /* simple code is just the value */
|
||||
}
|
||||
else
|
||||
{
|
||||
r.exop = (Byte)(e[*p - s] + 16 + 64);/* non-simple--look up in lists */
|
||||
r.base = d[*p++ - s];
|
||||
}
|
||||
|
||||
/* fill code-like entries with r */
|
||||
f = 1 << (k - w);
|
||||
for (j = i >> w; j < z; j += f)
|
||||
q[j] = r;
|
||||
|
||||
/* backwards increment the k-bit code i */
|
||||
for (j = 1 << (k - 1); i & j; j >>= 1)
|
||||
i ^= j;
|
||||
i ^= j;
|
||||
|
||||
/* backup over finished tables */
|
||||
mask = (1 << w) - 1; /* needed on HP, cc -O bug */
|
||||
while ((i & mask) != x[h])
|
||||
{
|
||||
h--; /* don't need to update q */
|
||||
w -= l;
|
||||
mask = (1 << w) - 1;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/* Return Z_BUF_ERROR if we were given an incomplete table */
|
||||
return y != 0 && g != 1 ? Z_BUF_ERROR : Z_OK;
|
||||
}
|
||||
|
||||
|
||||
int inflate_trees_bits(c, bb, tb, hp, z)
|
||||
uIntf *c; /* 19 code lengths */
|
||||
uIntf *bb; /* bits tree desired/actual depth */
|
||||
inflate_huft * FAR *tb; /* bits tree result */
|
||||
inflate_huft *hp; /* space for trees */
|
||||
z_streamp z; /* for messages */
|
||||
{
|
||||
int r;
|
||||
uInt hn = 0; /* hufts used in space */
|
||||
uIntf *v; /* work area for huft_build */
|
||||
|
||||
if ((v = (uIntf*)ZALLOC(z, 19, sizeof(uInt))) == Z_NULL)
|
||||
return Z_MEM_ERROR;
|
||||
r = huft_build(c, 19, 19, (uIntf*)Z_NULL, (uIntf*)Z_NULL,
|
||||
tb, bb, hp, &hn, v);
|
||||
if (r == Z_DATA_ERROR)
|
||||
z->msg = (char*)"oversubscribed dynamic bit lengths tree";
|
||||
else if (r == Z_BUF_ERROR || *bb == 0)
|
||||
{
|
||||
z->msg = (char*)"incomplete dynamic bit lengths tree";
|
||||
r = Z_DATA_ERROR;
|
||||
}
|
||||
ZFREE(z, v);
|
||||
return r;
|
||||
}
|
||||
|
||||
|
||||
int inflate_trees_dynamic(nl, nd, c, bl, bd, tl, td, hp, z)
|
||||
uInt nl; /* number of literal/length codes */
|
||||
uInt nd; /* number of distance codes */
|
||||
uIntf *c; /* that many (total) code lengths */
|
||||
uIntf *bl; /* literal desired/actual bit depth */
|
||||
uIntf *bd; /* distance desired/actual bit depth */
|
||||
inflate_huft * FAR *tl; /* literal/length tree result */
|
||||
inflate_huft * FAR *td; /* distance tree result */
|
||||
inflate_huft *hp; /* space for trees */
|
||||
z_streamp z; /* for messages */
|
||||
{
|
||||
int r;
|
||||
uInt hn = 0; /* hufts used in space */
|
||||
uIntf *v; /* work area for huft_build */
|
||||
|
||||
/* allocate work area */
|
||||
if ((v = (uIntf*)ZALLOC(z, 288, sizeof(uInt))) == Z_NULL)
|
||||
return Z_MEM_ERROR;
|
||||
|
||||
/* build literal/length tree */
|
||||
r = huft_build(c, nl, 257, cplens, cplext, tl, bl, hp, &hn, v);
|
||||
if (r != Z_OK || *bl == 0)
|
||||
{
|
||||
if (r == Z_DATA_ERROR)
|
||||
z->msg = (char*)"oversubscribed literal/length tree";
|
||||
else if (r != Z_MEM_ERROR)
|
||||
{
|
||||
z->msg = (char*)"incomplete literal/length tree";
|
||||
r = Z_DATA_ERROR;
|
||||
}
|
||||
ZFREE(z, v);
|
||||
return r;
|
||||
}
|
||||
|
||||
/* build distance tree */
|
||||
r = huft_build(c + nl, nd, 0, cpdist, cpdext, td, bd, hp, &hn, v);
|
||||
if (r != Z_OK || (*bd == 0 && nl > 257))
|
||||
{
|
||||
if (r == Z_DATA_ERROR)
|
||||
z->msg = (char*)"oversubscribed distance tree";
|
||||
else if (r == Z_BUF_ERROR) {
|
||||
#ifdef PKZIP_BUG_WORKAROUND
|
||||
r = Z_OK;
|
||||
}
|
||||
#else
|
||||
z->msg = (char*)"incomplete distance tree";
|
||||
r = Z_DATA_ERROR;
|
||||
}
|
||||
else if (r != Z_MEM_ERROR)
|
||||
{
|
||||
z->msg = (char*)"empty distance tree with lengths";
|
||||
r = Z_DATA_ERROR;
|
||||
}
|
||||
ZFREE(z, v);
|
||||
return r;
|
||||
#endif
|
||||
}
|
||||
|
||||
/* done */
|
||||
ZFREE(z, v);
|
||||
return Z_OK;
|
||||
}
|
||||
|
||||
|
||||
/* build fixed tables only once--keep them here */
|
||||
#ifdef BUILDFIXED
|
||||
local int fixed_built = 0;
|
||||
#define FIXEDH 544 /* number of hufts used by fixed tables */
|
||||
local inflate_huft fixed_mem[FIXEDH];
|
||||
local uInt fixed_bl;
|
||||
local uInt fixed_bd;
|
||||
local inflate_huft *fixed_tl;
|
||||
local inflate_huft *fixed_td;
|
||||
#else
|
||||
#include "inffixed.h"
|
||||
#endif
|
||||
|
||||
|
||||
int inflate_trees_fixed(bl, bd, tl, td, z)
|
||||
uIntf *bl; /* literal desired/actual bit depth */
|
||||
uIntf *bd; /* distance desired/actual bit depth */
|
||||
inflate_huft * FAR *tl; /* literal/length tree result */
|
||||
inflate_huft * FAR *td; /* distance tree result */
|
||||
z_streamp z; /* for memory allocation */
|
||||
{
|
||||
#ifdef BUILDFIXED
|
||||
/* build fixed tables if not already */
|
||||
if (!fixed_built)
|
||||
{
|
||||
int k; /* temporary variable */
|
||||
uInt f = 0; /* number of hufts used in fixed_mem */
|
||||
uIntf *c; /* length list for huft_build */
|
||||
uIntf *v; /* work area for huft_build */
|
||||
|
||||
/* allocate memory */
|
||||
if ((c = (uIntf*)ZALLOC(z, 288, sizeof(uInt))) == Z_NULL)
|
||||
return Z_MEM_ERROR;
|
||||
if ((v = (uIntf*)ZALLOC(z, 288, sizeof(uInt))) == Z_NULL)
|
||||
{
|
||||
ZFREE(z, c);
|
||||
return Z_MEM_ERROR;
|
||||
}
|
||||
|
||||
/* literal table */
|
||||
for (k = 0; k < 144; k++)
|
||||
c[k] = 8;
|
||||
for (; k < 256; k++)
|
||||
c[k] = 9;
|
||||
for (; k < 280; k++)
|
||||
c[k] = 7;
|
||||
for (; k < 288; k++)
|
||||
c[k] = 8;
|
||||
fixed_bl = 9;
|
||||
huft_build(c, 288, 257, cplens, cplext, &fixed_tl, &fixed_bl,
|
||||
fixed_mem, &f, v);
|
||||
|
||||
/* distance table */
|
||||
for (k = 0; k < 30; k++)
|
||||
c[k] = 5;
|
||||
fixed_bd = 5;
|
||||
huft_build(c, 30, 0, cpdist, cpdext, &fixed_td, &fixed_bd,
|
||||
fixed_mem, &f, v);
|
||||
|
||||
/* done */
|
||||
ZFREE(z, v);
|
||||
ZFREE(z, c);
|
||||
fixed_built = 1;
|
||||
}
|
||||
#endif
|
||||
*bl = fixed_bl;
|
||||
*bd = fixed_bd;
|
||||
*tl = fixed_tl;
|
||||
*td = fixed_td;
|
||||
return Z_OK;
|
||||
}
|
|
@ -1,58 +0,0 @@
|
|||
/* inftrees.h -- header to use inftrees.c
|
||||
* Copyright (C) 1995-2002 Mark Adler
|
||||
* For conditions of distribution and use, see copyright notice in zlib.h
|
||||
*/
|
||||
|
||||
/* WARNING: this file should *not* be used by applications. It is
|
||||
part of the implementation of the compression library and is
|
||||
subject to change. Applications should only use zlib.h.
|
||||
*/
|
||||
|
||||
/* Huffman code lookup table entry--this entry is four bytes for machines
|
||||
that have 16-bit pointers (e.g. PC's in the small or medium model). */
|
||||
|
||||
typedef struct inflate_huft_s FAR inflate_huft;
|
||||
|
||||
struct inflate_huft_s {
|
||||
union {
|
||||
struct {
|
||||
Byte Exop; /* number of extra bits or operation */
|
||||
Byte Bits; /* number of bits in this code or subcode */
|
||||
} what;
|
||||
uInt pad; /* pad structure to a power of 2 (4 bytes for */
|
||||
} word; /* 16-bit, 8 bytes for 32-bit int's) */
|
||||
uInt base; /* literal, length base, distance base,
|
||||
or table offset */
|
||||
};
|
||||
|
||||
/* Maximum size of dynamic tree. The maximum found in a long but non-
|
||||
exhaustive search was 1004 huft structures (850 for length/literals
|
||||
and 154 for distances, the latter actually the result of an
|
||||
exhaustive search). The actual maximum is not known, but the
|
||||
value below is more than safe. */
|
||||
#define MANY 1440
|
||||
|
||||
extern int inflate_trees_bits OF((
|
||||
uIntf *, /* 19 code lengths */
|
||||
uIntf *, /* bits tree desired/actual depth */
|
||||
inflate_huft * FAR *, /* bits tree result */
|
||||
inflate_huft *, /* space for trees */
|
||||
z_streamp)); /* for messages */
|
||||
|
||||
extern int inflate_trees_dynamic OF((
|
||||
uInt, /* number of literal/length codes */
|
||||
uInt, /* number of distance codes */
|
||||
uIntf *, /* that many (total) code lengths */
|
||||
uIntf *, /* literal desired/actual bit depth */
|
||||
uIntf *, /* distance desired/actual bit depth */
|
||||
inflate_huft * FAR *, /* literal/length tree result */
|
||||
inflate_huft * FAR *, /* distance tree result */
|
||||
inflate_huft *, /* space for trees */
|
||||
z_streamp)); /* for messages */
|
||||
|
||||
extern int inflate_trees_fixed OF((
|
||||
uIntf *, /* literal desired/actual bit depth */
|
||||
uIntf *, /* distance desired/actual bit depth */
|
||||
inflate_huft * FAR *, /* literal/length tree result */
|
||||
inflate_huft * FAR *, /* distance tree result */
|
||||
z_streamp)); /* for memory allocation */
|
|
@ -1,87 +0,0 @@
|
|||
/* inflate_util.c -- data and routines common to blocks and codes
|
||||
* Copyright (C) 1995-2002 Mark Adler
|
||||
* For conditions of distribution and use, see copyright notice in zlib.h
|
||||
*/
|
||||
|
||||
#include "zutil.h"
|
||||
#include "infblock.h"
|
||||
#include "inftrees.h"
|
||||
#include "infcodes.h"
|
||||
#include "infutil.h"
|
||||
|
||||
struct inflate_codes_state {int dummy;}; /* for buggy compilers */
|
||||
|
||||
/* And'ing with mask[n] masks the lower n bits */
|
||||
uInt inflate_mask[17] = {
|
||||
0x0000,
|
||||
0x0001, 0x0003, 0x0007, 0x000f, 0x001f, 0x003f, 0x007f, 0x00ff,
|
||||
0x01ff, 0x03ff, 0x07ff, 0x0fff, 0x1fff, 0x3fff, 0x7fff, 0xffff
|
||||
};
|
||||
|
||||
|
||||
/* copy as much as possible from the sliding window to the output area */
|
||||
int inflate_flush(s, z, r)
|
||||
inflate_blocks_statef *s;
|
||||
z_streamp z;
|
||||
int r;
|
||||
{
|
||||
uInt n;
|
||||
Bytef *p;
|
||||
Bytef *q;
|
||||
|
||||
/* local copies of source and destination pointers */
|
||||
p = z->next_out;
|
||||
q = s->read;
|
||||
|
||||
/* compute number of bytes to copy as far as end of window */
|
||||
n = (uInt)((q <= s->write ? s->write : s->end) - q);
|
||||
if (n > z->avail_out) n = z->avail_out;
|
||||
if (n && r == Z_BUF_ERROR) r = Z_OK;
|
||||
|
||||
/* update counters */
|
||||
z->avail_out -= n;
|
||||
z->total_out += n;
|
||||
|
||||
/* update check information */
|
||||
if (s->checkfn != Z_NULL)
|
||||
z->adler = s->check = (*s->checkfn)(s->check, q, n);
|
||||
|
||||
/* copy as far as end of window */
|
||||
zmemcpy(p, q, n);
|
||||
p += n;
|
||||
q += n;
|
||||
|
||||
/* see if more to copy at beginning of window */
|
||||
if (q == s->end)
|
||||
{
|
||||
/* wrap pointers */
|
||||
q = s->window;
|
||||
if (s->write == s->end)
|
||||
s->write = s->window;
|
||||
|
||||
/* compute bytes to copy */
|
||||
n = (uInt)(s->write - q);
|
||||
if (n > z->avail_out) n = z->avail_out;
|
||||
if (n && r == Z_BUF_ERROR) r = Z_OK;
|
||||
|
||||
/* update counters */
|
||||
z->avail_out -= n;
|
||||
z->total_out += n;
|
||||
|
||||
/* update check information */
|
||||
if (s->checkfn != Z_NULL)
|
||||
z->adler = s->check = (*s->checkfn)(s->check, q, n);
|
||||
|
||||
/* copy */
|
||||
zmemcpy(p, q, n);
|
||||
p += n;
|
||||
q += n;
|
||||
}
|
||||
|
||||
/* update pointers */
|
||||
z->next_out = p;
|
||||
s->read = q;
|
||||
|
||||
/* done */
|
||||
return r;
|
||||
}
|
|
@ -1,98 +0,0 @@
|
|||
/* infutil.h -- types and macros common to blocks and codes
|
||||
* Copyright (C) 1995-2002 Mark Adler
|
||||
* For conditions of distribution and use, see copyright notice in zlib.h
|
||||
*/
|
||||
|
||||
/* WARNING: this file should *not* be used by applications. It is
|
||||
part of the implementation of the compression library and is
|
||||
subject to change. Applications should only use zlib.h.
|
||||
*/
|
||||
|
||||
#ifndef _INFUTIL_H
|
||||
#define _INFUTIL_H
|
||||
|
||||
typedef enum {
|
||||
TYPE, /* get type bits (3, including end bit) */
|
||||
LENS, /* get lengths for stored */
|
||||
STORED, /* processing stored block */
|
||||
TABLE, /* get table lengths */
|
||||
BTREE, /* get bit lengths tree for a dynamic block */
|
||||
DTREE, /* get length, distance trees for a dynamic block */
|
||||
CODES, /* processing fixed or dynamic block */
|
||||
DRY, /* output remaining window bytes */
|
||||
DONE, /* finished last block, done */
|
||||
BAD} /* got a data error--stuck here */
|
||||
inflate_block_mode;
|
||||
|
||||
/* inflate blocks semi-private state */
|
||||
struct inflate_blocks_state {
|
||||
|
||||
/* mode */
|
||||
inflate_block_mode mode; /* current inflate_block mode */
|
||||
|
||||
/* mode dependent information */
|
||||
union {
|
||||
uInt left; /* if STORED, bytes left to copy */
|
||||
struct {
|
||||
uInt table; /* table lengths (14 bits) */
|
||||
uInt index; /* index into blens (or border) */
|
||||
uIntf *blens; /* bit lengths of codes */
|
||||
uInt bb; /* bit length tree depth */
|
||||
inflate_huft *tb; /* bit length decoding tree */
|
||||
} trees; /* if DTREE, decoding info for trees */
|
||||
struct {
|
||||
inflate_codes_statef
|
||||
*codes;
|
||||
} decode; /* if CODES, current state */
|
||||
} sub; /* submode */
|
||||
uInt last; /* true if this block is the last block */
|
||||
|
||||
/* mode independent information */
|
||||
uInt bitk; /* bits in bit buffer */
|
||||
uLong bitb; /* bit buffer */
|
||||
inflate_huft *hufts; /* single malloc for tree space */
|
||||
Bytef *window; /* sliding window */
|
||||
Bytef *end; /* one byte after sliding window */
|
||||
Bytef *read; /* window read pointer */
|
||||
Bytef *write; /* window write pointer */
|
||||
check_func checkfn; /* check function */
|
||||
uLong check; /* check on output */
|
||||
|
||||
};
|
||||
|
||||
|
||||
/* defines for inflate input/output */
|
||||
/* update pointers and return */
|
||||
#define UPDBITS {s->bitb=b;s->bitk=k;}
|
||||
#define UPDIN {z->avail_in=n;z->total_in+=p-z->next_in;z->next_in=p;}
|
||||
#define UPDOUT {s->write=q;}
|
||||
#define UPDATE {UPDBITS UPDIN UPDOUT}
|
||||
#define LEAVE {UPDATE return inflate_flush(s,z,r);}
|
||||
/* get bytes and bits */
|
||||
#define LOADIN {p=z->next_in;n=z->avail_in;b=s->bitb;k=s->bitk;}
|
||||
#define NEEDBYTE {if(n)r=Z_OK;else LEAVE}
|
||||
#define NEXTBYTE (n--,*p++)
|
||||
#define NEEDBITS(j) {while(k<(j)){NEEDBYTE;b|=((uLong)NEXTBYTE)<<k;k+=8;}}
|
||||
#define DUMPBITS(j) {b>>=(j);k-=(j);}
|
||||
/* output bytes */
|
||||
#define WAVAIL (uInt)(q<s->read?s->read-q-1:s->end-q)
|
||||
#define LOADOUT {q=s->write;m=(uInt)WAVAIL;}
|
||||
#define WRAP {if(q==s->end&&s->read!=s->window){q=s->window;m=(uInt)WAVAIL;}}
|
||||
#define FLUSH {UPDOUT r=inflate_flush(s,z,r); LOADOUT}
|
||||
#define NEEDOUT {if(m==0){WRAP if(m==0){FLUSH WRAP if(m==0) LEAVE}}r=Z_OK;}
|
||||
#define OUTBYTE(a) {*q++=(Byte)(a);m--;}
|
||||
/* load local pointers */
|
||||
#define LOAD {LOADIN LOADOUT}
|
||||
|
||||
/* masks for lower bits (size given to avoid silly warnings with Visual C++) */
|
||||
extern uInt inflate_mask[17];
|
||||
|
||||
/* copy as much as possible from the sliding window to the output area */
|
||||
extern int inflate_flush OF((
|
||||
inflate_blocks_statef *,
|
||||
z_streamp ,
|
||||
int));
|
||||
|
||||
struct internal_state {int dummy;}; /* for buggy compilers */
|
||||
|
||||
#endif
|
File diff suppressed because it is too large
Load Diff
|
@ -1,805 +0,0 @@
|
|||
|
||||
/* png.c - location for general purpose libpng functions
|
||||
*
|
||||
* libpng version 1.2.5 - October 3, 2002
|
||||
* Copyright (c) 1998-2002 Glenn Randers-Pehrson
|
||||
* (Version 0.96 Copyright (c) 1996, 1997 Andreas Dilger)
|
||||
* (Version 0.88 Copyright (c) 1995, 1996 Guy Eric Schalnat, Group 42, Inc.)
|
||||
*
|
||||
*/
|
||||
|
||||
#define PNG_INTERNAL
|
||||
#define PNG_NO_EXTERN
|
||||
#include "png.h"
|
||||
|
||||
/* Generate a compiler error if there is an old png.h in the search path. */
|
||||
typedef version_1_2_5 Your_png_h_is_not_version_1_2_5;
|
||||
|
||||
/* Version information for C files. This had better match the version
|
||||
* string defined in png.h. */
|
||||
|
||||
#ifdef PNG_USE_GLOBAL_ARRAYS
|
||||
/* png_libpng_ver was changed to a function in version 1.0.5c */
|
||||
const char png_libpng_ver[18] = "1.2.5";
|
||||
|
||||
/* png_sig was changed to a function in version 1.0.5c */
|
||||
/* Place to hold the signature string for a PNG file. */
|
||||
const png_byte FARDATA png_sig[8] = {137, 80, 78, 71, 13, 10, 26, 10};
|
||||
|
||||
/* Invoke global declarations for constant strings for known chunk types */
|
||||
PNG_IHDR;
|
||||
PNG_IDAT;
|
||||
PNG_IEND;
|
||||
PNG_PLTE;
|
||||
PNG_bKGD;
|
||||
PNG_cHRM;
|
||||
PNG_gAMA;
|
||||
PNG_hIST;
|
||||
PNG_iCCP;
|
||||
PNG_iTXt;
|
||||
PNG_oFFs;
|
||||
PNG_pCAL;
|
||||
PNG_sCAL;
|
||||
PNG_pHYs;
|
||||
PNG_sBIT;
|
||||
PNG_sPLT;
|
||||
PNG_sRGB;
|
||||
PNG_tEXt;
|
||||
PNG_tIME;
|
||||
PNG_tRNS;
|
||||
PNG_zTXt;
|
||||
|
||||
/* arrays to facilitate easy interlacing - use pass (0 - 6) as index */
|
||||
|
||||
/* start of interlace block */
|
||||
const int FARDATA png_pass_start[] = {0, 4, 0, 2, 0, 1, 0};
|
||||
|
||||
/* offset to next interlace block */
|
||||
const int FARDATA png_pass_inc[] = {8, 8, 4, 4, 2, 2, 1};
|
||||
|
||||
/* start of interlace block in the y direction */
|
||||
const int FARDATA png_pass_ystart[] = {0, 0, 4, 0, 2, 0, 1};
|
||||
|
||||
/* offset to next interlace block in the y direction */
|
||||
const int FARDATA png_pass_yinc[] = {8, 8, 8, 4, 4, 2, 2};
|
||||
|
||||
/* width of interlace block (used in assembler routines only) */
|
||||
#ifdef PNG_HAVE_ASSEMBLER_COMBINE_ROW
|
||||
const int FARDATA png_pass_width[] = {8, 4, 4, 2, 2, 1, 1};
|
||||
#endif
|
||||
|
||||
/* Height of interlace block. This is not currently used - if you need
|
||||
* it, uncomment it here and in png.h
|
||||
const int FARDATA png_pass_height[] = {8, 8, 4, 4, 2, 2, 1};
|
||||
*/
|
||||
|
||||
/* Mask to determine which pixels are valid in a pass */
|
||||
const int FARDATA png_pass_mask[] = {0x80, 0x08, 0x88, 0x22, 0xaa, 0x55, 0xff};
|
||||
|
||||
/* Mask to determine which pixels to overwrite while displaying */
|
||||
const int FARDATA png_pass_dsp_mask[]
|
||||
= {0xff, 0x0f, 0xff, 0x33, 0xff, 0x55, 0xff};
|
||||
|
||||
#endif
|
||||
|
||||
/* Tells libpng that we have already handled the first "num_bytes" bytes
|
||||
* of the PNG file signature. If the PNG data is embedded into another
|
||||
* stream we can set num_bytes = 8 so that libpng will not attempt to read
|
||||
* or write any of the magic bytes before it starts on the IHDR.
|
||||
*/
|
||||
|
||||
void PNGAPI
|
||||
png_set_sig_bytes(png_structp png_ptr, int num_bytes)
|
||||
{
|
||||
png_debug(1, "in png_set_sig_bytes\n");
|
||||
if (num_bytes > 8)
|
||||
png_error(png_ptr, "Too many bytes for PNG signature.");
|
||||
|
||||
png_ptr->sig_bytes = (png_byte)(num_bytes < 0 ? 0 : num_bytes);
|
||||
}
|
||||
|
||||
/* Checks whether the supplied bytes match the PNG signature. We allow
|
||||
* checking less than the full 8-byte signature so that those apps that
|
||||
* already read the first few bytes of a file to determine the file type
|
||||
* can simply check the remaining bytes for extra assurance. Returns
|
||||
* an integer less than, equal to, or greater than zero if sig is found,
|
||||
* respectively, to be less than, to match, or be greater than the correct
|
||||
* PNG signature (this is the same behaviour as strcmp, memcmp, etc).
|
||||
*/
|
||||
int PNGAPI
|
||||
png_sig_cmp(png_bytep sig, png_size_t start, png_size_t num_to_check)
|
||||
{
|
||||
png_byte png_signature[8] = {137, 80, 78, 71, 13, 10, 26, 10};
|
||||
if (num_to_check > 8)
|
||||
num_to_check = 8;
|
||||
else if (num_to_check < 1)
|
||||
return (0);
|
||||
|
||||
if (start > 7)
|
||||
return (0);
|
||||
|
||||
if (start + num_to_check > 8)
|
||||
num_to_check = 8 - start;
|
||||
|
||||
return ((int)(png_memcmp(&sig[start], &png_signature[start], num_to_check)));
|
||||
}
|
||||
|
||||
/* (Obsolete) function to check signature bytes. It does not allow one
|
||||
* to check a partial signature. This function might be removed in the
|
||||
* future - use png_sig_cmp(). Returns true (nonzero) if the file is a PNG.
|
||||
*/
|
||||
int PNGAPI
|
||||
png_check_sig(png_bytep sig, int num)
|
||||
{
|
||||
return ((int)!png_sig_cmp(sig, (png_size_t)0, (png_size_t)num));
|
||||
}
|
||||
|
||||
/* Function to allocate memory for zlib and clear it to 0. */
|
||||
#ifdef PNG_1_0_X
|
||||
voidpf PNGAPI
|
||||
#else
|
||||
voidpf /* private */
|
||||
#endif
|
||||
png_zalloc(voidpf png_ptr, uInt items, uInt size)
|
||||
{
|
||||
png_uint_32 num_bytes = (png_uint_32)items * size;
|
||||
png_voidp ptr;
|
||||
png_structp p=png_ptr;
|
||||
png_uint_32 save_flags=p->flags;
|
||||
|
||||
p->flags|=PNG_FLAG_MALLOC_NULL_MEM_OK;
|
||||
ptr = (png_voidp)png_malloc((png_structp)png_ptr, num_bytes);
|
||||
p->flags=save_flags;
|
||||
|
||||
#ifndef PNG_NO_ZALLOC_ZERO
|
||||
if (ptr == NULL)
|
||||
return ((voidpf)ptr);
|
||||
|
||||
if (num_bytes > (png_uint_32)0x8000L)
|
||||
{
|
||||
png_memset(ptr, 0, (png_size_t)0x8000L);
|
||||
png_memset((png_bytep)ptr + (png_size_t)0x8000L, 0,
|
||||
(png_size_t)(num_bytes - (png_uint_32)0x8000L));
|
||||
}
|
||||
else
|
||||
{
|
||||
png_memset(ptr, 0, (png_size_t)num_bytes);
|
||||
}
|
||||
#endif
|
||||
return ((voidpf)ptr);
|
||||
}
|
||||
|
||||
/* function to free memory for zlib */
|
||||
#ifdef PNG_1_0_X
|
||||
void PNGAPI
|
||||
#else
|
||||
void /* private */
|
||||
#endif
|
||||
png_zfree(voidpf png_ptr, voidpf ptr)
|
||||
{
|
||||
png_free((png_structp)png_ptr, (png_voidp)ptr);
|
||||
}
|
||||
|
||||
/* Reset the CRC variable to 32 bits of 1's. Care must be taken
|
||||
* in case CRC is > 32 bits to leave the top bits 0.
|
||||
*/
|
||||
void /* PRIVATE */
|
||||
png_reset_crc(png_structp png_ptr)
|
||||
{
|
||||
png_ptr->crc = crc32(0, Z_NULL, 0);
|
||||
}
|
||||
|
||||
/* Calculate the CRC over a section of data. We can only pass as
|
||||
* much data to this routine as the largest single buffer size. We
|
||||
* also check that this data will actually be used before going to the
|
||||
* trouble of calculating it.
|
||||
*/
|
||||
void /* PRIVATE */
|
||||
png_calculate_crc(png_structp png_ptr, png_bytep ptr, png_size_t length)
|
||||
{
|
||||
int need_crc = 1;
|
||||
|
||||
if (png_ptr->chunk_name[0] & 0x20) /* ancillary */
|
||||
{
|
||||
if ((png_ptr->flags & PNG_FLAG_CRC_ANCILLARY_MASK) ==
|
||||
(PNG_FLAG_CRC_ANCILLARY_USE | PNG_FLAG_CRC_ANCILLARY_NOWARN))
|
||||
need_crc = 0;
|
||||
}
|
||||
else /* critical */
|
||||
{
|
||||
if (png_ptr->flags & PNG_FLAG_CRC_CRITICAL_IGNORE)
|
||||
need_crc = 0;
|
||||
}
|
||||
|
||||
if (need_crc)
|
||||
png_ptr->crc = crc32(png_ptr->crc, ptr, (uInt)length);
|
||||
}
|
||||
|
||||
/* Allocate the memory for an info_struct for the application. We don't
|
||||
* really need the png_ptr, but it could potentially be useful in the
|
||||
* future. This should be used in favour of malloc(sizeof(png_info))
|
||||
* and png_info_init() so that applications that want to use a shared
|
||||
* libpng don't have to be recompiled if png_info changes size.
|
||||
*/
|
||||
png_infop PNGAPI
|
||||
png_create_info_struct(png_structp png_ptr)
|
||||
{
|
||||
png_infop info_ptr;
|
||||
|
||||
png_debug(1, "in png_create_info_struct\n");
|
||||
if(png_ptr == NULL) return (NULL);
|
||||
#ifdef PNG_USER_MEM_SUPPORTED
|
||||
info_ptr = (png_infop)png_create_struct_2(PNG_STRUCT_INFO,
|
||||
png_ptr->malloc_fn, png_ptr->mem_ptr);
|
||||
#else
|
||||
info_ptr = (png_infop)png_create_struct(PNG_STRUCT_INFO);
|
||||
#endif
|
||||
if (info_ptr != NULL)
|
||||
png_info_init_3(&info_ptr, sizeof(png_info));
|
||||
|
||||
return (info_ptr);
|
||||
}
|
||||
|
||||
/* This function frees the memory associated with a single info struct.
|
||||
* Normally, one would use either png_destroy_read_struct() or
|
||||
* png_destroy_write_struct() to free an info struct, but this may be
|
||||
* useful for some applications.
|
||||
*/
|
||||
void PNGAPI
|
||||
png_destroy_info_struct(png_structp png_ptr, png_infopp info_ptr_ptr)
|
||||
{
|
||||
png_infop info_ptr = NULL;
|
||||
|
||||
png_debug(1, "in png_destroy_info_struct\n");
|
||||
if (info_ptr_ptr != NULL)
|
||||
info_ptr = *info_ptr_ptr;
|
||||
|
||||
if (info_ptr != NULL)
|
||||
{
|
||||
png_info_destroy(png_ptr, info_ptr);
|
||||
|
||||
#ifdef PNG_USER_MEM_SUPPORTED
|
||||
png_destroy_struct_2((png_voidp)info_ptr, png_ptr->free_fn,
|
||||
png_ptr->mem_ptr);
|
||||
#else
|
||||
png_destroy_struct((png_voidp)info_ptr);
|
||||
#endif
|
||||
*info_ptr_ptr = NULL;
|
||||
}
|
||||
}
|
||||
|
||||
/* Initialize the info structure. This is now an internal function (0.89)
|
||||
* and applications using it are urged to use png_create_info_struct()
|
||||
* instead.
|
||||
*/
|
||||
#undef png_info_init
|
||||
void PNGAPI
|
||||
png_info_init(png_infop info_ptr)
|
||||
{
|
||||
/* We only come here via pre-1.0.12-compiled applications */
|
||||
png_info_init_3(&info_ptr, 0);
|
||||
}
|
||||
|
||||
void PNGAPI
|
||||
png_info_init_3(png_infopp ptr_ptr, png_size_t png_info_struct_size)
|
||||
{
|
||||
png_infop info_ptr = *ptr_ptr;
|
||||
|
||||
png_debug(1, "in png_info_init_3\n");
|
||||
|
||||
if(sizeof(png_info) > png_info_struct_size)
|
||||
{
|
||||
png_destroy_struct(info_ptr);
|
||||
info_ptr = (png_infop)png_create_struct(PNG_STRUCT_INFO);
|
||||
*ptr_ptr = info_ptr;
|
||||
}
|
||||
|
||||
/* set everything to 0 */
|
||||
png_memset(info_ptr, 0, sizeof (png_info));
|
||||
}
|
||||
|
||||
#ifdef PNG_FREE_ME_SUPPORTED
|
||||
void PNGAPI
|
||||
png_data_freer(png_structp png_ptr, png_infop info_ptr,
|
||||
int freer, png_uint_32 mask)
|
||||
{
|
||||
png_debug(1, "in png_data_freer\n");
|
||||
if (png_ptr == NULL || info_ptr == NULL)
|
||||
return;
|
||||
if(freer == PNG_DESTROY_WILL_FREE_DATA)
|
||||
info_ptr->free_me |= mask;
|
||||
else if(freer == PNG_USER_WILL_FREE_DATA)
|
||||
info_ptr->free_me &= ~mask;
|
||||
else
|
||||
png_warning(png_ptr,
|
||||
"Unknown freer parameter in png_data_freer.");
|
||||
}
|
||||
#endif
|
||||
|
||||
void PNGAPI
|
||||
png_free_data(png_structp png_ptr, png_infop info_ptr, png_uint_32 mask,
|
||||
int num)
|
||||
{
|
||||
png_debug(1, "in png_free_data\n");
|
||||
if (png_ptr == NULL || info_ptr == NULL)
|
||||
return;
|
||||
|
||||
#if defined(PNG_TEXT_SUPPORTED)
|
||||
/* free text item num or (if num == -1) all text items */
|
||||
#ifdef PNG_FREE_ME_SUPPORTED
|
||||
if ((mask & PNG_FREE_TEXT) & info_ptr->free_me)
|
||||
#else
|
||||
if (mask & PNG_FREE_TEXT)
|
||||
#endif
|
||||
{
|
||||
if (num != -1)
|
||||
{
|
||||
if (info_ptr->text && info_ptr->text[num].key)
|
||||
{
|
||||
png_free(png_ptr, info_ptr->text[num].key);
|
||||
info_ptr->text[num].key = NULL;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
int i;
|
||||
for (i = 0; i < info_ptr->num_text; i++)
|
||||
png_free_data(png_ptr, info_ptr, PNG_FREE_TEXT, i);
|
||||
png_free(png_ptr, info_ptr->text);
|
||||
info_ptr->text = NULL;
|
||||
info_ptr->num_text=0;
|
||||
}
|
||||
}
|
||||
#endif
|
||||
|
||||
#if defined(PNG_tRNS_SUPPORTED)
|
||||
/* free any tRNS entry */
|
||||
#ifdef PNG_FREE_ME_SUPPORTED
|
||||
if ((mask & PNG_FREE_TRNS) & info_ptr->free_me)
|
||||
#else
|
||||
if ((mask & PNG_FREE_TRNS) && (png_ptr->flags & PNG_FLAG_FREE_TRNS))
|
||||
#endif
|
||||
{
|
||||
png_free(png_ptr, info_ptr->trans);
|
||||
info_ptr->valid &= ~PNG_INFO_tRNS;
|
||||
#ifndef PNG_FREE_ME_SUPPORTED
|
||||
png_ptr->flags &= ~PNG_FLAG_FREE_TRNS;
|
||||
#endif
|
||||
info_ptr->trans = NULL;
|
||||
}
|
||||
#endif
|
||||
|
||||
#if defined(PNG_sCAL_SUPPORTED)
|
||||
/* free any sCAL entry */
|
||||
#ifdef PNG_FREE_ME_SUPPORTED
|
||||
if ((mask & PNG_FREE_SCAL) & info_ptr->free_me)
|
||||
#else
|
||||
if (mask & PNG_FREE_SCAL)
|
||||
#endif
|
||||
{
|
||||
#if defined(PNG_FIXED_POINT_SUPPORTED) && !defined(PNG_FLOATING_POINT_SUPPORTED)
|
||||
png_free(png_ptr, info_ptr->scal_s_width);
|
||||
png_free(png_ptr, info_ptr->scal_s_height);
|
||||
info_ptr->scal_s_width = NULL;
|
||||
info_ptr->scal_s_height = NULL;
|
||||
#endif
|
||||
info_ptr->valid &= ~PNG_INFO_sCAL;
|
||||
}
|
||||
#endif
|
||||
|
||||
#if defined(PNG_pCAL_SUPPORTED)
|
||||
/* free any pCAL entry */
|
||||
#ifdef PNG_FREE_ME_SUPPORTED
|
||||
if ((mask & PNG_FREE_PCAL) & info_ptr->free_me)
|
||||
#else
|
||||
if (mask & PNG_FREE_PCAL)
|
||||
#endif
|
||||
{
|
||||
png_free(png_ptr, info_ptr->pcal_purpose);
|
||||
png_free(png_ptr, info_ptr->pcal_units);
|
||||
info_ptr->pcal_purpose = NULL;
|
||||
info_ptr->pcal_units = NULL;
|
||||
if (info_ptr->pcal_params != NULL)
|
||||
{
|
||||
int i;
|
||||
for (i = 0; i < (int)info_ptr->pcal_nparams; i++)
|
||||
{
|
||||
png_free(png_ptr, info_ptr->pcal_params[i]);
|
||||
info_ptr->pcal_params[i]=NULL;
|
||||
}
|
||||
png_free(png_ptr, info_ptr->pcal_params);
|
||||
info_ptr->pcal_params = NULL;
|
||||
}
|
||||
info_ptr->valid &= ~PNG_INFO_pCAL;
|
||||
}
|
||||
#endif
|
||||
|
||||
#if defined(PNG_iCCP_SUPPORTED)
|
||||
/* free any iCCP entry */
|
||||
#ifdef PNG_FREE_ME_SUPPORTED
|
||||
if ((mask & PNG_FREE_ICCP) & info_ptr->free_me)
|
||||
#else
|
||||
if (mask & PNG_FREE_ICCP)
|
||||
#endif
|
||||
{
|
||||
png_free(png_ptr, info_ptr->iccp_name);
|
||||
png_free(png_ptr, info_ptr->iccp_profile);
|
||||
info_ptr->iccp_name = NULL;
|
||||
info_ptr->iccp_profile = NULL;
|
||||
info_ptr->valid &= ~PNG_INFO_iCCP;
|
||||
}
|
||||
#endif
|
||||
|
||||
#if defined(PNG_sPLT_SUPPORTED)
|
||||
/* free a given sPLT entry, or (if num == -1) all sPLT entries */
|
||||
#ifdef PNG_FREE_ME_SUPPORTED
|
||||
if ((mask & PNG_FREE_SPLT) & info_ptr->free_me)
|
||||
#else
|
||||
if (mask & PNG_FREE_SPLT)
|
||||
#endif
|
||||
{
|
||||
if (num != -1)
|
||||
{
|
||||
if(info_ptr->splt_palettes)
|
||||
{
|
||||
png_free(png_ptr, info_ptr->splt_palettes[num].name);
|
||||
png_free(png_ptr, info_ptr->splt_palettes[num].entries);
|
||||
info_ptr->splt_palettes[num].name = NULL;
|
||||
info_ptr->splt_palettes[num].entries = NULL;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
if(info_ptr->splt_palettes_num)
|
||||
{
|
||||
int i;
|
||||
for (i = 0; i < (int)info_ptr->splt_palettes_num; i++)
|
||||
png_free_data(png_ptr, info_ptr, PNG_FREE_SPLT, i);
|
||||
|
||||
png_free(png_ptr, info_ptr->splt_palettes);
|
||||
info_ptr->splt_palettes = NULL;
|
||||
info_ptr->splt_palettes_num = 0;
|
||||
}
|
||||
info_ptr->valid &= ~PNG_INFO_sPLT;
|
||||
}
|
||||
}
|
||||
#endif
|
||||
|
||||
#if defined(PNG_UNKNOWN_CHUNKS_SUPPORTED)
|
||||
#ifdef PNG_FREE_ME_SUPPORTED
|
||||
if ((mask & PNG_FREE_UNKN) & info_ptr->free_me)
|
||||
#else
|
||||
if (mask & PNG_FREE_UNKN)
|
||||
#endif
|
||||
{
|
||||
if (num != -1)
|
||||
{
|
||||
if(info_ptr->unknown_chunks)
|
||||
{
|
||||
png_free(png_ptr, info_ptr->unknown_chunks[num].data);
|
||||
info_ptr->unknown_chunks[num].data = NULL;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
int i;
|
||||
|
||||
if(info_ptr->unknown_chunks_num)
|
||||
{
|
||||
for (i = 0; i < (int)info_ptr->unknown_chunks_num; i++)
|
||||
png_free_data(png_ptr, info_ptr, PNG_FREE_UNKN, i);
|
||||
|
||||
png_free(png_ptr, info_ptr->unknown_chunks);
|
||||
info_ptr->unknown_chunks = NULL;
|
||||
info_ptr->unknown_chunks_num = 0;
|
||||
}
|
||||
}
|
||||
}
|
||||
#endif
|
||||
|
||||
#if defined(PNG_hIST_SUPPORTED)
|
||||
/* free any hIST entry */
|
||||
#ifdef PNG_FREE_ME_SUPPORTED
|
||||
if ((mask & PNG_FREE_HIST) & info_ptr->free_me)
|
||||
#else
|
||||
if ((mask & PNG_FREE_HIST) && (png_ptr->flags & PNG_FLAG_FREE_HIST))
|
||||
#endif
|
||||
{
|
||||
png_free(png_ptr, info_ptr->hist);
|
||||
info_ptr->hist = NULL;
|
||||
info_ptr->valid &= ~PNG_INFO_hIST;
|
||||
#ifndef PNG_FREE_ME_SUPPORTED
|
||||
png_ptr->flags &= ~PNG_FLAG_FREE_HIST;
|
||||
#endif
|
||||
}
|
||||
#endif
|
||||
|
||||
/* free any PLTE entry that was internally allocated */
|
||||
#ifdef PNG_FREE_ME_SUPPORTED
|
||||
if ((mask & PNG_FREE_PLTE) & info_ptr->free_me)
|
||||
#else
|
||||
if ((mask & PNG_FREE_PLTE) && (png_ptr->flags & PNG_FLAG_FREE_PLTE))
|
||||
#endif
|
||||
{
|
||||
png_zfree(png_ptr, info_ptr->palette);
|
||||
info_ptr->palette = NULL;
|
||||
info_ptr->valid &= ~PNG_INFO_PLTE;
|
||||
#ifndef PNG_FREE_ME_SUPPORTED
|
||||
png_ptr->flags &= ~PNG_FLAG_FREE_PLTE;
|
||||
#endif
|
||||
info_ptr->num_palette = 0;
|
||||
}
|
||||
|
||||
#if defined(PNG_INFO_IMAGE_SUPPORTED)
|
||||
/* free any image bits attached to the info structure */
|
||||
#ifdef PNG_FREE_ME_SUPPORTED
|
||||
if ((mask & PNG_FREE_ROWS) & info_ptr->free_me)
|
||||
#else
|
||||
if (mask & PNG_FREE_ROWS)
|
||||
#endif
|
||||
{
|
||||
if(info_ptr->row_pointers)
|
||||
{
|
||||
int row;
|
||||
for (row = 0; row < (int)info_ptr->height; row++)
|
||||
{
|
||||
png_free(png_ptr, info_ptr->row_pointers[row]);
|
||||
info_ptr->row_pointers[row]=NULL;
|
||||
}
|
||||
png_free(png_ptr, info_ptr->row_pointers);
|
||||
info_ptr->row_pointers=NULL;
|
||||
}
|
||||
info_ptr->valid &= ~PNG_INFO_IDAT;
|
||||
}
|
||||
#endif
|
||||
|
||||
#ifdef PNG_FREE_ME_SUPPORTED
|
||||
if(num == -1)
|
||||
info_ptr->free_me &= ~mask;
|
||||
else
|
||||
info_ptr->free_me &= ~(mask & ~PNG_FREE_MUL);
|
||||
#endif
|
||||
}
|
||||
|
||||
/* This is an internal routine to free any memory that the info struct is
|
||||
* pointing to before re-using it or freeing the struct itself. Recall
|
||||
* that png_free() checks for NULL pointers for us.
|
||||
*/
|
||||
void /* PRIVATE */
|
||||
png_info_destroy(png_structp png_ptr, png_infop info_ptr)
|
||||
{
|
||||
png_debug(1, "in png_info_destroy\n");
|
||||
|
||||
png_free_data(png_ptr, info_ptr, PNG_FREE_ALL, -1);
|
||||
|
||||
#if defined(PNG_UNKNOWN_CHUNKS_SUPPORTED)
|
||||
if (png_ptr->num_chunk_list)
|
||||
{
|
||||
png_free(png_ptr, png_ptr->chunk_list);
|
||||
png_ptr->chunk_list=NULL;
|
||||
png_ptr->num_chunk_list=0;
|
||||
}
|
||||
#endif
|
||||
|
||||
png_info_init_3(&info_ptr, sizeof(png_info));
|
||||
}
|
||||
|
||||
/* This function returns a pointer to the io_ptr associated with the user
|
||||
* functions. The application should free any memory associated with this
|
||||
* pointer before png_write_destroy() or png_read_destroy() are called.
|
||||
*/
|
||||
png_voidp PNGAPI
|
||||
png_get_io_ptr(png_structp png_ptr)
|
||||
{
|
||||
return (png_ptr->io_ptr);
|
||||
}
|
||||
|
||||
#if !defined(PNG_NO_STDIO)
|
||||
/* Initialize the default input/output functions for the PNG file. If you
|
||||
* use your own read or write routines, you can call either png_set_read_fn()
|
||||
* or png_set_write_fn() instead of png_init_io(). If you have defined
|
||||
* PNG_NO_STDIO, you must use a function of your own because "FILE *" isn't
|
||||
* necessarily available.
|
||||
*/
|
||||
void PNGAPI
|
||||
png_init_io(png_structp png_ptr, png_FILE_p fp)
|
||||
{
|
||||
png_debug(1, "in png_init_io\n");
|
||||
png_ptr->io_ptr = (png_voidp)fp;
|
||||
}
|
||||
#endif
|
||||
|
||||
#if defined(PNG_TIME_RFC1123_SUPPORTED)
|
||||
/* Convert the supplied time into an RFC 1123 string suitable for use in
|
||||
* a "Creation Time" or other text-based time string.
|
||||
*/
|
||||
png_charp PNGAPI
|
||||
png_convert_to_rfc1123(png_structp png_ptr, png_timep ptime)
|
||||
{
|
||||
static PNG_CONST char short_months[12][4] =
|
||||
{"Jan", "Feb", "Mar", "Apr", "May", "Jun",
|
||||
"Jul", "Aug", "Sep", "Oct", "Nov", "Dec"};
|
||||
|
||||
if (png_ptr->time_buffer == NULL)
|
||||
{
|
||||
png_ptr->time_buffer = (png_charp)png_malloc(png_ptr, (png_uint_32)(29*
|
||||
sizeof(char)));
|
||||
}
|
||||
|
||||
#if defined(_WIN32_WCE)
|
||||
{
|
||||
wchar_t time_buf[29];
|
||||
wsprintf(time_buf, TEXT("%d %S %d %02d:%02d:%02d +0000"),
|
||||
ptime->day % 32, short_months[(ptime->month - 1) % 12],
|
||||
ptime->year, ptime->hour % 24, ptime->minute % 60,
|
||||
ptime->second % 61);
|
||||
WideCharToMultiByte(CP_ACP, 0, time_buf, -1, png_ptr->time_buffer, 29,
|
||||
NULL, NULL);
|
||||
}
|
||||
#else
|
||||
#ifdef USE_FAR_KEYWORD
|
||||
{
|
||||
char near_time_buf[29];
|
||||
sprintf(near_time_buf, "%d %s %d %02d:%02d:%02d +0000",
|
||||
ptime->day % 32, short_months[(ptime->month - 1) % 12],
|
||||
ptime->year, ptime->hour % 24, ptime->minute % 60,
|
||||
ptime->second % 61);
|
||||
png_memcpy(png_ptr->time_buffer, near_time_buf,
|
||||
29*sizeof(char));
|
||||
}
|
||||
#else
|
||||
sprintf(png_ptr->time_buffer, "%d %s %d %02d:%02d:%02d +0000",
|
||||
ptime->day % 32, short_months[(ptime->month - 1) % 12],
|
||||
ptime->year, ptime->hour % 24, ptime->minute % 60,
|
||||
ptime->second % 61);
|
||||
#endif
|
||||
#endif /* _WIN32_WCE */
|
||||
return ((png_charp)png_ptr->time_buffer);
|
||||
}
|
||||
#endif /* PNG_TIME_RFC1123_SUPPORTED */
|
||||
|
||||
#if 0
|
||||
/* Signature string for a PNG file. */
|
||||
png_bytep PNGAPI
|
||||
png_sig_bytes(void)
|
||||
{
|
||||
return ((png_bytep)"\211\120\116\107\015\012\032\012");
|
||||
}
|
||||
#endif
|
||||
|
||||
png_charp PNGAPI
|
||||
png_get_copyright(png_structp png_ptr)
|
||||
{
|
||||
if (png_ptr != NULL || png_ptr == NULL) /* silence compiler warning */
|
||||
return ((png_charp) "\n libpng version 1.2.5 - October 3, 2002\n\
|
||||
Copyright (c) 1998-2002 Glenn Randers-Pehrson\n\
|
||||
Copyright (c) 1996-1997 Andreas Dilger\n\
|
||||
Copyright (c) 1995-1996 Guy Eric Schalnat, Group 42, Inc.\n");
|
||||
return ((png_charp) "");
|
||||
}
|
||||
|
||||
/* The following return the library version as a short string in the
|
||||
* format 1.0.0 through 99.99.99zz. To get the version of *.h files used
|
||||
* with your application, print out PNG_LIBPNG_VER_STRING, which is defined
|
||||
* in png.h.
|
||||
*/
|
||||
|
||||
png_charp PNGAPI
|
||||
png_get_libpng_ver(png_structp png_ptr)
|
||||
{
|
||||
/* Version of *.c files used when building libpng */
|
||||
if(png_ptr != NULL) /* silence compiler warning about unused png_ptr */
|
||||
return((png_charp) "1.2.5");
|
||||
return((png_charp) "1.2.5");
|
||||
}
|
||||
|
||||
png_charp PNGAPI
|
||||
png_get_header_ver(png_structp png_ptr)
|
||||
{
|
||||
/* Version of *.h files used when building libpng */
|
||||
if(png_ptr != NULL) /* silence compiler warning about unused png_ptr */
|
||||
return((png_charp) PNG_LIBPNG_VER_STRING);
|
||||
return((png_charp) PNG_LIBPNG_VER_STRING);
|
||||
}
|
||||
|
||||
png_charp PNGAPI
|
||||
png_get_header_version(png_structp png_ptr)
|
||||
{
|
||||
/* Returns longer string containing both version and date */
|
||||
if(png_ptr != NULL) /* silence compiler warning about unused png_ptr */
|
||||
return((png_charp) PNG_HEADER_VERSION_STRING);
|
||||
return((png_charp) PNG_HEADER_VERSION_STRING);
|
||||
}
|
||||
|
||||
#ifdef PNG_HANDLE_AS_UNKNOWN_SUPPORTED
|
||||
int PNGAPI
|
||||
png_handle_as_unknown(png_structp png_ptr, png_bytep chunk_name)
|
||||
{
|
||||
/* check chunk_name and return "keep" value if it's on the list, else 0 */
|
||||
int i;
|
||||
png_bytep p;
|
||||
if((png_ptr == NULL && chunk_name == NULL) || png_ptr->num_chunk_list<=0)
|
||||
return 0;
|
||||
p=png_ptr->chunk_list+png_ptr->num_chunk_list*5-5;
|
||||
for (i = png_ptr->num_chunk_list; i; i--, p-=5)
|
||||
if (!png_memcmp(chunk_name, p, 4))
|
||||
return ((int)*(p+4));
|
||||
return 0;
|
||||
}
|
||||
#endif
|
||||
|
||||
/* This function, added to libpng-1.0.6g, is untested. */
|
||||
int PNGAPI
|
||||
png_reset_zstream(png_structp png_ptr)
|
||||
{
|
||||
return (inflateReset(&png_ptr->zstream));
|
||||
}
|
||||
|
||||
/* This function was added to libpng-1.0.7 */
|
||||
png_uint_32 PNGAPI
|
||||
png_access_version_number(void)
|
||||
{
|
||||
/* Version of *.c files used when building libpng */
|
||||
return((png_uint_32) 10205L);
|
||||
}
|
||||
|
||||
|
||||
#if !defined(PNG_1_0_X)
|
||||
#if defined(PNG_ASSEMBLER_CODE_SUPPORTED)
|
||||
/* GRR: could add this: && defined(PNG_MMX_CODE_SUPPORTED) */
|
||||
/* this INTERNAL function was added to libpng 1.2.0 */
|
||||
void /* PRIVATE */
|
||||
png_init_mmx_flags (png_structp png_ptr)
|
||||
{
|
||||
png_ptr->mmx_rowbytes_threshold = 0;
|
||||
png_ptr->mmx_bitdepth_threshold = 0;
|
||||
|
||||
# if (defined(PNG_USE_PNGVCRD) || defined(PNG_USE_PNGGCCRD))
|
||||
|
||||
png_ptr->asm_flags |= PNG_ASM_FLAG_MMX_SUPPORT_COMPILED;
|
||||
|
||||
if (png_mmx_support() > 0) {
|
||||
png_ptr->asm_flags |= PNG_ASM_FLAG_MMX_SUPPORT_IN_CPU
|
||||
# ifdef PNG_HAVE_ASSEMBLER_COMBINE_ROW
|
||||
| PNG_ASM_FLAG_MMX_READ_COMBINE_ROW
|
||||
# endif
|
||||
# ifdef PNG_HAVE_ASSEMBLER_READ_INTERLACE
|
||||
| PNG_ASM_FLAG_MMX_READ_INTERLACE
|
||||
# endif
|
||||
# ifndef PNG_HAVE_ASSEMBLER_READ_FILTER_ROW
|
||||
;
|
||||
# else
|
||||
| PNG_ASM_FLAG_MMX_READ_FILTER_SUB
|
||||
| PNG_ASM_FLAG_MMX_READ_FILTER_UP
|
||||
| PNG_ASM_FLAG_MMX_READ_FILTER_AVG
|
||||
| PNG_ASM_FLAG_MMX_READ_FILTER_PAETH ;
|
||||
|
||||
png_ptr->mmx_rowbytes_threshold = PNG_MMX_ROWBYTES_THRESHOLD_DEFAULT;
|
||||
png_ptr->mmx_bitdepth_threshold = PNG_MMX_BITDEPTH_THRESHOLD_DEFAULT;
|
||||
# endif
|
||||
} else {
|
||||
png_ptr->asm_flags &= ~( PNG_ASM_FLAG_MMX_SUPPORT_IN_CPU
|
||||
| PNG_MMX_READ_FLAGS
|
||||
| PNG_MMX_WRITE_FLAGS );
|
||||
}
|
||||
|
||||
# else /* !((PNGVCRD || PNGGCCRD) && PNG_ASSEMBLER_CODE_SUPPORTED)) */
|
||||
|
||||
/* clear all MMX flags; no support is compiled in */
|
||||
png_ptr->asm_flags &= ~( PNG_MMX_FLAGS );
|
||||
|
||||
# endif /* ?(PNGVCRD || PNGGCCRD) */
|
||||
}
|
||||
|
||||
#endif /* !(PNG_ASSEMBLER_CODE_SUPPORTED) */
|
||||
|
||||
/* this function was added to libpng 1.2.0 */
|
||||
#if !defined(PNG_USE_PNGGCCRD) && \
|
||||
!(defined(PNG_ASSEMBLER_CODE_SUPPORTED) && defined(PNG_USE_PNGVCRD))
|
||||
int PNGAPI
|
||||
png_mmx_support(void)
|
||||
{
|
||||
return -1;
|
||||
}
|
||||
#endif
|
||||
#endif /* PNG_1_0_X */
|
File diff suppressed because it is too large
Load Diff
|
@ -1,11 +0,0 @@
|
|||
/* pngasmrd.h - assembler version of utilities to read a PNG file
|
||||
*
|
||||
* libpng 1.2.5 - October 3, 2002
|
||||
* For conditions of distribution and use, see copyright notice in png.h
|
||||
* Copyright (c) 2002 Glenn Randers-Pehrson
|
||||
*
|
||||
*/
|
||||
|
||||
/* This file is obsolete in libpng-1.0.9 and later; its contents now appear
|
||||
* at the end of pngconf.h.
|
||||
*/
|
File diff suppressed because it is too large
Load Diff
|
@ -1,291 +0,0 @@
|
|||
|
||||
/* pngerror.c - stub functions for i/o and memory allocation
|
||||
*
|
||||
* libpng 1.2.5 - October 3, 2002
|
||||
* For conditions of distribution and use, see copyright notice in png.h
|
||||
* Copyright (c) 1998-2002 Glenn Randers-Pehrson
|
||||
* (Version 0.96 Copyright (c) 1996, 1997 Andreas Dilger)
|
||||
* (Version 0.88 Copyright (c) 1995, 1996 Guy Eric Schalnat, Group 42, Inc.)
|
||||
*
|
||||
* This file provides a location for all error handling. Users who
|
||||
* need special error handling are expected to write replacement functions
|
||||
* and use png_set_error_fn() to use those functions. See the instructions
|
||||
* at each function.
|
||||
*/
|
||||
|
||||
#define PNG_INTERNAL
|
||||
#include "png.h"
|
||||
|
||||
static void /* PRIVATE */
|
||||
png_default_error PNGARG((png_structp png_ptr,
|
||||
png_const_charp error_message));
|
||||
static void /* PRIVATE */
|
||||
png_default_warning PNGARG((png_structp png_ptr,
|
||||
png_const_charp warning_message));
|
||||
|
||||
/* This function is called whenever there is a fatal error. This function
|
||||
* should not be changed. If there is a need to handle errors differently,
|
||||
* you should supply a replacement error function and use png_set_error_fn()
|
||||
* to replace the error function at run-time.
|
||||
*/
|
||||
void PNGAPI
|
||||
png_error(png_structp png_ptr, png_const_charp error_message)
|
||||
{
|
||||
#ifdef PNG_ERROR_NUMBERS_SUPPORTED
|
||||
char msg[16];
|
||||
if (png_ptr->flags&(PNG_FLAG_STRIP_ERROR_NUMBERS|PNG_FLAG_STRIP_ERROR_TEXT))
|
||||
{
|
||||
int offset = 0;
|
||||
if (*error_message == '#')
|
||||
{
|
||||
for (offset=1; offset<15; offset++)
|
||||
if (*(error_message+offset) == ' ')
|
||||
break;
|
||||
if (png_ptr->flags&PNG_FLAG_STRIP_ERROR_TEXT)
|
||||
{
|
||||
int i;
|
||||
for (i=0; i<offset-1; i++)
|
||||
msg[i]=error_message[i+1];
|
||||
msg[i]='\0';
|
||||
error_message=msg;
|
||||
}
|
||||
else
|
||||
error_message+=offset;
|
||||
}
|
||||
else
|
||||
{
|
||||
if (png_ptr->flags&PNG_FLAG_STRIP_ERROR_TEXT)
|
||||
{
|
||||
msg[0]='0';
|
||||
msg[1]='\0';
|
||||
error_message=msg;
|
||||
}
|
||||
}
|
||||
}
|
||||
#endif
|
||||
if (png_ptr->error_fn != NULL)
|
||||
(*(png_ptr->error_fn))(png_ptr, error_message);
|
||||
|
||||
/* if the following returns or doesn't exist, use the default function,
|
||||
which will not return */
|
||||
png_default_error(png_ptr, error_message);
|
||||
}
|
||||
|
||||
/* This function is called whenever there is a non-fatal error. This function
|
||||
* should not be changed. If there is a need to handle warnings differently,
|
||||
* you should supply a replacement warning function and use
|
||||
* png_set_error_fn() to replace the warning function at run-time.
|
||||
*/
|
||||
void PNGAPI
|
||||
png_warning(png_structp png_ptr, png_const_charp warning_message)
|
||||
{
|
||||
int offset = 0;
|
||||
#ifdef PNG_ERROR_NUMBERS_SUPPORTED
|
||||
if (png_ptr->flags&(PNG_FLAG_STRIP_ERROR_NUMBERS|PNG_FLAG_STRIP_ERROR_TEXT))
|
||||
#endif
|
||||
{
|
||||
if (*warning_message == '#')
|
||||
{
|
||||
for (offset=1; offset<15; offset++)
|
||||
if (*(warning_message+offset) == ' ')
|
||||
break;
|
||||
}
|
||||
}
|
||||
if (png_ptr->warning_fn != NULL)
|
||||
(*(png_ptr->warning_fn))(png_ptr,
|
||||
(png_const_charp)(warning_message+offset));
|
||||
else
|
||||
png_default_warning(png_ptr, (png_const_charp)(warning_message+offset));
|
||||
}
|
||||
|
||||
/* These utilities are used internally to build an error message that relates
|
||||
* to the current chunk. The chunk name comes from png_ptr->chunk_name,
|
||||
* this is used to prefix the message. The message is limited in length
|
||||
* to 63 bytes, the name characters are output as hex digits wrapped in []
|
||||
* if the character is invalid.
|
||||
*/
|
||||
#define isnonalpha(c) ((c) < 41 || (c) > 122 || ((c) > 90 && (c) < 97))
|
||||
static PNG_CONST char png_digit[16] = {
|
||||
'0', '1', '2', '3', '4', '5', '6', '7', '8', '9', 'A', 'B', 'C', 'D', 'E',
|
||||
'F' };
|
||||
|
||||
static void /* PRIVATE */
|
||||
png_format_buffer(png_structp png_ptr, png_charp buffer, png_const_charp
|
||||
error_message)
|
||||
{
|
||||
int iout = 0, iin = 0;
|
||||
|
||||
while (iin < 4)
|
||||
{
|
||||
int c = png_ptr->chunk_name[iin++];
|
||||
if (isnonalpha(c))
|
||||
{
|
||||
buffer[iout++] = '[';
|
||||
buffer[iout++] = png_digit[(c & 0xf0) >> 4];
|
||||
buffer[iout++] = png_digit[c & 0x0f];
|
||||
buffer[iout++] = ']';
|
||||
}
|
||||
else
|
||||
{
|
||||
buffer[iout++] = (png_byte)c;
|
||||
}
|
||||
}
|
||||
|
||||
if (error_message == NULL)
|
||||
buffer[iout] = 0;
|
||||
else
|
||||
{
|
||||
buffer[iout++] = ':';
|
||||
buffer[iout++] = ' ';
|
||||
png_memcpy(buffer+iout, error_message, 64);
|
||||
buffer[iout+63] = 0;
|
||||
}
|
||||
}
|
||||
|
||||
void PNGAPI
|
||||
png_chunk_error(png_structp png_ptr, png_const_charp error_message)
|
||||
{
|
||||
char msg[18+64];
|
||||
png_format_buffer(png_ptr, msg, error_message);
|
||||
png_error(png_ptr, msg);
|
||||
}
|
||||
|
||||
void PNGAPI
|
||||
png_chunk_warning(png_structp png_ptr, png_const_charp warning_message)
|
||||
{
|
||||
char msg[18+64];
|
||||
png_format_buffer(png_ptr, msg, warning_message);
|
||||
png_warning(png_ptr, msg);
|
||||
}
|
||||
|
||||
/* This is the default error handling function. Note that replacements for
|
||||
* this function MUST NOT RETURN, or the program will likely crash. This
|
||||
* function is used by default, or if the program supplies NULL for the
|
||||
* error function pointer in png_set_error_fn().
|
||||
*/
|
||||
static void /* PRIVATE */
|
||||
png_default_error(png_structp png_ptr, png_const_charp error_message)
|
||||
{
|
||||
#ifndef PNG_NO_CONSOLE_IO
|
||||
#ifdef PNG_ERROR_NUMBERS_SUPPORTED
|
||||
if (*error_message == '#')
|
||||
{
|
||||
int offset;
|
||||
char error_number[16];
|
||||
for (offset=0; offset<15; offset++)
|
||||
{
|
||||
error_number[offset] = *(error_message+offset+1);
|
||||
if (*(error_message+offset) == ' ')
|
||||
break;
|
||||
}
|
||||
if((offset > 1) && (offset < 15))
|
||||
{
|
||||
error_number[offset-1]='\0';
|
||||
fprintf(stderr, "libpng error no. %s: %s\n", error_number,
|
||||
error_message+offset);
|
||||
}
|
||||
else
|
||||
fprintf(stderr, "libpng error: %s, offset=%d\n", error_message,offset);
|
||||
}
|
||||
else
|
||||
#endif
|
||||
fprintf(stderr, "libpng error: %s\n", error_message);
|
||||
#else
|
||||
if (error_message)
|
||||
/* make compiler happy */ ;
|
||||
#endif
|
||||
|
||||
#ifdef PNG_SETJMP_SUPPORTED
|
||||
# ifdef USE_FAR_KEYWORD
|
||||
{
|
||||
jmp_buf jmpbuf;
|
||||
png_memcpy(jmpbuf,png_ptr->jmpbuf,sizeof(jmp_buf));
|
||||
longjmp(jmpbuf, 1);
|
||||
}
|
||||
# else
|
||||
longjmp(png_ptr->jmpbuf, 1);
|
||||
# endif
|
||||
#else
|
||||
if (png_ptr)
|
||||
/* make compiler happy */ ;
|
||||
PNG_ABORT();
|
||||
#endif
|
||||
}
|
||||
|
||||
/* This function is called when there is a warning, but the library thinks
|
||||
* it can continue anyway. Replacement functions don't have to do anything
|
||||
* here if you don't want them to. In the default configuration, png_ptr is
|
||||
* not used, but it is passed in case it may be useful.
|
||||
*/
|
||||
static void /* PRIVATE */
|
||||
png_default_warning(png_structp png_ptr, png_const_charp warning_message)
|
||||
{
|
||||
#ifndef PNG_NO_CONSOLE_IO
|
||||
# ifdef PNG_ERROR_NUMBERS_SUPPORTED
|
||||
if (*warning_message == '#')
|
||||
{
|
||||
int offset;
|
||||
char warning_number[16];
|
||||
for (offset=0; offset<15; offset++)
|
||||
{
|
||||
warning_number[offset]=*(warning_message+offset+1);
|
||||
if (*(warning_message+offset) == ' ')
|
||||
break;
|
||||
}
|
||||
if((offset > 1) && (offset < 15))
|
||||
{
|
||||
warning_number[offset-1]='\0';
|
||||
fprintf(stderr, "libpng warning no. %s: %s\n", warning_number,
|
||||
warning_message+offset);
|
||||
}
|
||||
else
|
||||
fprintf(stderr, "libpng warning: %s\n", warning_message);
|
||||
}
|
||||
else
|
||||
# endif
|
||||
fprintf(stderr, "libpng warning: %s\n", warning_message);
|
||||
#else
|
||||
if (warning_message)
|
||||
/* appease compiler */ ;
|
||||
#endif
|
||||
if (png_ptr)
|
||||
return;
|
||||
}
|
||||
|
||||
/* This function is called when the application wants to use another method
|
||||
* of handling errors and warnings. Note that the error function MUST NOT
|
||||
* return to the calling routine or serious problems will occur. The return
|
||||
* method used in the default routine calls longjmp(png_ptr->jmpbuf, 1)
|
||||
*/
|
||||
void PNGAPI
|
||||
png_set_error_fn(png_structp png_ptr, png_voidp error_ptr,
|
||||
png_error_ptr error_fn, png_error_ptr warning_fn)
|
||||
{
|
||||
png_ptr->error_ptr = error_ptr;
|
||||
png_ptr->error_fn = error_fn;
|
||||
png_ptr->warning_fn = warning_fn;
|
||||
}
|
||||
|
||||
|
||||
/* This function returns a pointer to the error_ptr associated with the user
|
||||
* functions. The application should free any memory associated with this
|
||||
* pointer before png_write_destroy and png_read_destroy are called.
|
||||
*/
|
||||
png_voidp PNGAPI
|
||||
png_get_error_ptr(png_structp png_ptr)
|
||||
{
|
||||
return ((png_voidp)png_ptr->error_ptr);
|
||||
}
|
||||
|
||||
|
||||
#ifdef PNG_ERROR_NUMBERS_SUPPORTED
|
||||
void PNGAPI
|
||||
png_set_strip_error_numbers(png_structp png_ptr, png_uint_32 strip_mode)
|
||||
{
|
||||
if(png_ptr != NULL)
|
||||
{
|
||||
png_ptr->flags &=
|
||||
((~(PNG_FLAG_STRIP_ERROR_NUMBERS|PNG_FLAG_STRIP_ERROR_TEXT))&strip_mode);
|
||||
}
|
||||
}
|
||||
#endif
|
File diff suppressed because it is too large
Load Diff
|
@ -1,927 +0,0 @@
|
|||
|
||||
/* pngget.c - retrieval of values from info struct
|
||||
*
|
||||
* libpng 1.2.5 - October 3, 2002
|
||||
* For conditions of distribution and use, see copyright notice in png.h
|
||||
* Copyright (c) 1998-2002 Glenn Randers-Pehrson
|
||||
* (Version 0.96 Copyright (c) 1996, 1997 Andreas Dilger)
|
||||
* (Version 0.88 Copyright (c) 1995, 1996 Guy Eric Schalnat, Group 42, Inc.)
|
||||
*/
|
||||
|
||||
#define PNG_INTERNAL
|
||||
#include "png.h"
|
||||
|
||||
png_uint_32 PNGAPI
|
||||
png_get_valid(png_structp png_ptr, png_infop info_ptr, png_uint_32 flag)
|
||||
{
|
||||
if (png_ptr != NULL && info_ptr != NULL)
|
||||
return(info_ptr->valid & flag);
|
||||
else
|
||||
return(0);
|
||||
}
|
||||
|
||||
png_uint_32 PNGAPI
|
||||
png_get_rowbytes(png_structp png_ptr, png_infop info_ptr)
|
||||
{
|
||||
if (png_ptr != NULL && info_ptr != NULL)
|
||||
return(info_ptr->rowbytes);
|
||||
else
|
||||
return(0);
|
||||
}
|
||||
|
||||
#if defined(PNG_INFO_IMAGE_SUPPORTED)
|
||||
png_bytepp PNGAPI
|
||||
png_get_rows(png_structp png_ptr, png_infop info_ptr)
|
||||
{
|
||||
if (png_ptr != NULL && info_ptr != NULL)
|
||||
return(info_ptr->row_pointers);
|
||||
else
|
||||
return(0);
|
||||
}
|
||||
#endif
|
||||
|
||||
#ifdef PNG_EASY_ACCESS_SUPPORTED
|
||||
/* easy access to info, added in libpng-0.99 */
|
||||
png_uint_32 PNGAPI
|
||||
png_get_image_width(png_structp png_ptr, png_infop info_ptr)
|
||||
{
|
||||
if (png_ptr != NULL && info_ptr != NULL)
|
||||
{
|
||||
return info_ptr->width;
|
||||
}
|
||||
return (0);
|
||||
}
|
||||
|
||||
png_uint_32 PNGAPI
|
||||
png_get_image_height(png_structp png_ptr, png_infop info_ptr)
|
||||
{
|
||||
if (png_ptr != NULL && info_ptr != NULL)
|
||||
{
|
||||
return info_ptr->height;
|
||||
}
|
||||
return (0);
|
||||
}
|
||||
|
||||
png_byte PNGAPI
|
||||
png_get_bit_depth(png_structp png_ptr, png_infop info_ptr)
|
||||
{
|
||||
if (png_ptr != NULL && info_ptr != NULL)
|
||||
{
|
||||
return info_ptr->bit_depth;
|
||||
}
|
||||
return (0);
|
||||
}
|
||||
|
||||
png_byte PNGAPI
|
||||
png_get_color_type(png_structp png_ptr, png_infop info_ptr)
|
||||
{
|
||||
if (png_ptr != NULL && info_ptr != NULL)
|
||||
{
|
||||
return info_ptr->color_type;
|
||||
}
|
||||
return (0);
|
||||
}
|
||||
|
||||
png_byte PNGAPI
|
||||
png_get_filter_type(png_structp png_ptr, png_infop info_ptr)
|
||||
{
|
||||
if (png_ptr != NULL && info_ptr != NULL)
|
||||
{
|
||||
return info_ptr->filter_type;
|
||||
}
|
||||
return (0);
|
||||
}
|
||||
|
||||
png_byte PNGAPI
|
||||
png_get_interlace_type(png_structp png_ptr, png_infop info_ptr)
|
||||
{
|
||||
if (png_ptr != NULL && info_ptr != NULL)
|
||||
{
|
||||
return info_ptr->interlace_type;
|
||||
}
|
||||
return (0);
|
||||
}
|
||||
|
||||
png_byte PNGAPI
|
||||
png_get_compression_type(png_structp png_ptr, png_infop info_ptr)
|
||||
{
|
||||
if (png_ptr != NULL && info_ptr != NULL)
|
||||
{
|
||||
return info_ptr->compression_type;
|
||||
}
|
||||
return (0);
|
||||
}
|
||||
|
||||
png_uint_32 PNGAPI
|
||||
png_get_x_pixels_per_meter(png_structp png_ptr, png_infop info_ptr)
|
||||
{
|
||||
if (png_ptr != NULL && info_ptr != NULL)
|
||||
#if defined(PNG_pHYs_SUPPORTED)
|
||||
if (info_ptr->valid & PNG_INFO_pHYs)
|
||||
{
|
||||
png_debug1(1, "in %s retrieval function\n", "png_get_x_pixels_per_meter");
|
||||
if(info_ptr->phys_unit_type != PNG_RESOLUTION_METER)
|
||||
return (0);
|
||||
else return (info_ptr->x_pixels_per_unit);
|
||||
}
|
||||
#else
|
||||
return (0);
|
||||
#endif
|
||||
return (0);
|
||||
}
|
||||
|
||||
png_uint_32 PNGAPI
|
||||
png_get_y_pixels_per_meter(png_structp png_ptr, png_infop info_ptr)
|
||||
{
|
||||
if (png_ptr != NULL && info_ptr != NULL)
|
||||
#if defined(PNG_pHYs_SUPPORTED)
|
||||
if (info_ptr->valid & PNG_INFO_pHYs)
|
||||
{
|
||||
png_debug1(1, "in %s retrieval function\n", "png_get_y_pixels_per_meter");
|
||||
if(info_ptr->phys_unit_type != PNG_RESOLUTION_METER)
|
||||
return (0);
|
||||
else return (info_ptr->y_pixels_per_unit);
|
||||
}
|
||||
#else
|
||||
return (0);
|
||||
#endif
|
||||
return (0);
|
||||
}
|
||||
|
||||
png_uint_32 PNGAPI
|
||||
png_get_pixels_per_meter(png_structp png_ptr, png_infop info_ptr)
|
||||
{
|
||||
if (png_ptr != NULL && info_ptr != NULL)
|
||||
#if defined(PNG_pHYs_SUPPORTED)
|
||||
if (info_ptr->valid & PNG_INFO_pHYs)
|
||||
{
|
||||
png_debug1(1, "in %s retrieval function\n", "png_get_pixels_per_meter");
|
||||
if(info_ptr->phys_unit_type != PNG_RESOLUTION_METER ||
|
||||
info_ptr->x_pixels_per_unit != info_ptr->y_pixels_per_unit)
|
||||
return (0);
|
||||
else return (info_ptr->x_pixels_per_unit);
|
||||
}
|
||||
#else
|
||||
return (0);
|
||||
#endif
|
||||
return (0);
|
||||
}
|
||||
|
||||
#ifdef PNG_FLOATING_POINT_SUPPORTED
|
||||
float PNGAPI
|
||||
png_get_pixel_aspect_ratio(png_structp png_ptr, png_infop info_ptr)
|
||||
{
|
||||
if (png_ptr != NULL && info_ptr != NULL)
|
||||
#if defined(PNG_pHYs_SUPPORTED)
|
||||
if (info_ptr->valid & PNG_INFO_pHYs)
|
||||
{
|
||||
png_debug1(1, "in %s retrieval function\n", "png_get_aspect_ratio");
|
||||
if (info_ptr->x_pixels_per_unit == 0)
|
||||
return ((float)0.0);
|
||||
else
|
||||
return ((float)((float)info_ptr->y_pixels_per_unit
|
||||
/(float)info_ptr->x_pixels_per_unit));
|
||||
}
|
||||
#else
|
||||
return (0.0);
|
||||
#endif
|
||||
return ((float)0.0);
|
||||
}
|
||||
#endif
|
||||
|
||||
png_int_32 PNGAPI
|
||||
png_get_x_offset_microns(png_structp png_ptr, png_infop info_ptr)
|
||||
{
|
||||
if (png_ptr != NULL && info_ptr != NULL)
|
||||
#if defined(PNG_oFFs_SUPPORTED)
|
||||
if (info_ptr->valid & PNG_INFO_oFFs)
|
||||
{
|
||||
png_debug1(1, "in %s retrieval function\n", "png_get_x_offset_microns");
|
||||
if(info_ptr->offset_unit_type != PNG_OFFSET_MICROMETER)
|
||||
return (0);
|
||||
else return (info_ptr->x_offset);
|
||||
}
|
||||
#else
|
||||
return (0);
|
||||
#endif
|
||||
return (0);
|
||||
}
|
||||
|
||||
png_int_32 PNGAPI
|
||||
png_get_y_offset_microns(png_structp png_ptr, png_infop info_ptr)
|
||||
{
|
||||
if (png_ptr != NULL && info_ptr != NULL)
|
||||
#if defined(PNG_oFFs_SUPPORTED)
|
||||
if (info_ptr->valid & PNG_INFO_oFFs)
|
||||
{
|
||||
png_debug1(1, "in %s retrieval function\n", "png_get_y_offset_microns");
|
||||
if(info_ptr->offset_unit_type != PNG_OFFSET_MICROMETER)
|
||||
return (0);
|
||||
else return (info_ptr->y_offset);
|
||||
}
|
||||
#else
|
||||
return (0);
|
||||
#endif
|
||||
return (0);
|
||||
}
|
||||
|
||||
png_int_32 PNGAPI
|
||||
png_get_x_offset_pixels(png_structp png_ptr, png_infop info_ptr)
|
||||
{
|
||||
if (png_ptr != NULL && info_ptr != NULL)
|
||||
#if defined(PNG_oFFs_SUPPORTED)
|
||||
if (info_ptr->valid & PNG_INFO_oFFs)
|
||||
{
|
||||
png_debug1(1, "in %s retrieval function\n", "png_get_x_offset_microns");
|
||||
if(info_ptr->offset_unit_type != PNG_OFFSET_PIXEL)
|
||||
return (0);
|
||||
else return (info_ptr->x_offset);
|
||||
}
|
||||
#else
|
||||
return (0);
|
||||
#endif
|
||||
return (0);
|
||||
}
|
||||
|
||||
png_int_32 PNGAPI
|
||||
png_get_y_offset_pixels(png_structp png_ptr, png_infop info_ptr)
|
||||
{
|
||||
if (png_ptr != NULL && info_ptr != NULL)
|
||||
#if defined(PNG_oFFs_SUPPORTED)
|
||||
if (info_ptr->valid & PNG_INFO_oFFs)
|
||||
{
|
||||
png_debug1(1, "in %s retrieval function\n", "png_get_y_offset_microns");
|
||||
if(info_ptr->offset_unit_type != PNG_OFFSET_PIXEL)
|
||||
return (0);
|
||||
else return (info_ptr->y_offset);
|
||||
}
|
||||
#else
|
||||
return (0);
|
||||
#endif
|
||||
return (0);
|
||||
}
|
||||
|
||||
#if defined(PNG_INCH_CONVERSIONS) && defined(PNG_FLOATING_POINT_SUPPORTED)
|
||||
png_uint_32 PNGAPI
|
||||
png_get_pixels_per_inch(png_structp png_ptr, png_infop info_ptr)
|
||||
{
|
||||
return ((png_uint_32)((float)png_get_pixels_per_meter(png_ptr, info_ptr)
|
||||
*.0254 +.5));
|
||||
}
|
||||
|
||||
png_uint_32 PNGAPI
|
||||
png_get_x_pixels_per_inch(png_structp png_ptr, png_infop info_ptr)
|
||||
{
|
||||
return ((png_uint_32)((float)png_get_x_pixels_per_meter(png_ptr, info_ptr)
|
||||
*.0254 +.5));
|
||||
}
|
||||
|
||||
png_uint_32 PNGAPI
|
||||
png_get_y_pixels_per_inch(png_structp png_ptr, png_infop info_ptr)
|
||||
{
|
||||
return ((png_uint_32)((float)png_get_y_pixels_per_meter(png_ptr, info_ptr)
|
||||
*.0254 +.5));
|
||||
}
|
||||
|
||||
float PNGAPI
|
||||
png_get_x_offset_inches(png_structp png_ptr, png_infop info_ptr)
|
||||
{
|
||||
return ((float)png_get_x_offset_microns(png_ptr, info_ptr)
|
||||
*.00003937);
|
||||
}
|
||||
|
||||
float PNGAPI
|
||||
png_get_y_offset_inches(png_structp png_ptr, png_infop info_ptr)
|
||||
{
|
||||
return ((float)png_get_y_offset_microns(png_ptr, info_ptr)
|
||||
*.00003937);
|
||||
}
|
||||
|
||||
#if defined(PNG_pHYs_SUPPORTED)
|
||||
png_uint_32 PNGAPI
|
||||
png_get_pHYs_dpi(png_structp png_ptr, png_infop info_ptr,
|
||||
png_uint_32 *res_x, png_uint_32 *res_y, int *unit_type)
|
||||
{
|
||||
png_uint_32 retval = 0;
|
||||
|
||||
if (png_ptr != NULL && info_ptr != NULL && (info_ptr->valid & PNG_INFO_pHYs))
|
||||
{
|
||||
png_debug1(1, "in %s retrieval function\n", "pHYs");
|
||||
if (res_x != NULL)
|
||||
{
|
||||
*res_x = info_ptr->x_pixels_per_unit;
|
||||
retval |= PNG_INFO_pHYs;
|
||||
}
|
||||
if (res_y != NULL)
|
||||
{
|
||||
*res_y = info_ptr->y_pixels_per_unit;
|
||||
retval |= PNG_INFO_pHYs;
|
||||
}
|
||||
if (unit_type != NULL)
|
||||
{
|
||||
*unit_type = (int)info_ptr->phys_unit_type;
|
||||
retval |= PNG_INFO_pHYs;
|
||||
if(*unit_type == 1)
|
||||
{
|
||||
if (res_x != NULL) *res_x = (png_uint_32)(*res_x * .0254 + .50);
|
||||
if (res_y != NULL) *res_y = (png_uint_32)(*res_y * .0254 + .50);
|
||||
}
|
||||
}
|
||||
}
|
||||
return (retval);
|
||||
}
|
||||
#endif /* PNG_pHYs_SUPPORTED */
|
||||
#endif /* PNG_INCH_CONVERSIONS && PNG_FLOATING_POINT_SUPPORTED */
|
||||
|
||||
/* png_get_channels really belongs in here, too, but it's been around longer */
|
||||
|
||||
#endif /* PNG_EASY_ACCESS_SUPPORTED */
|
||||
|
||||
png_byte PNGAPI
|
||||
png_get_channels(png_structp png_ptr, png_infop info_ptr)
|
||||
{
|
||||
if (png_ptr != NULL && info_ptr != NULL)
|
||||
return(info_ptr->channels);
|
||||
else
|
||||
return (0);
|
||||
}
|
||||
|
||||
png_bytep PNGAPI
|
||||
png_get_signature(png_structp png_ptr, png_infop info_ptr)
|
||||
{
|
||||
if (png_ptr != NULL && info_ptr != NULL)
|
||||
return(info_ptr->signature);
|
||||
else
|
||||
return (NULL);
|
||||
}
|
||||
|
||||
#if defined(PNG_bKGD_SUPPORTED)
|
||||
png_uint_32 PNGAPI
|
||||
png_get_bKGD(png_structp png_ptr, png_infop info_ptr,
|
||||
png_color_16p *background)
|
||||
{
|
||||
if (png_ptr != NULL && info_ptr != NULL && (info_ptr->valid & PNG_INFO_bKGD)
|
||||
&& background != NULL)
|
||||
{
|
||||
png_debug1(1, "in %s retrieval function\n", "bKGD");
|
||||
*background = &(info_ptr->background);
|
||||
return (PNG_INFO_bKGD);
|
||||
}
|
||||
return (0);
|
||||
}
|
||||
#endif
|
||||
|
||||
#if defined(PNG_cHRM_SUPPORTED)
|
||||
#ifdef PNG_FLOATING_POINT_SUPPORTED
|
||||
png_uint_32 PNGAPI
|
||||
png_get_cHRM(png_structp png_ptr, png_infop info_ptr,
|
||||
double *white_x, double *white_y, double *red_x, double *red_y,
|
||||
double *green_x, double *green_y, double *blue_x, double *blue_y)
|
||||
{
|
||||
if (png_ptr != NULL && info_ptr != NULL && (info_ptr->valid & PNG_INFO_cHRM))
|
||||
{
|
||||
png_debug1(1, "in %s retrieval function\n", "cHRM");
|
||||
if (white_x != NULL)
|
||||
*white_x = (double)info_ptr->x_white;
|
||||
if (white_y != NULL)
|
||||
*white_y = (double)info_ptr->y_white;
|
||||
if (red_x != NULL)
|
||||
*red_x = (double)info_ptr->x_red;
|
||||
if (red_y != NULL)
|
||||
*red_y = (double)info_ptr->y_red;
|
||||
if (green_x != NULL)
|
||||
*green_x = (double)info_ptr->x_green;
|
||||
if (green_y != NULL)
|
||||
*green_y = (double)info_ptr->y_green;
|
||||
if (blue_x != NULL)
|
||||
*blue_x = (double)info_ptr->x_blue;
|
||||
if (blue_y != NULL)
|
||||
*blue_y = (double)info_ptr->y_blue;
|
||||
return (PNG_INFO_cHRM);
|
||||
}
|
||||
return (0);
|
||||
}
|
||||
#endif
|
||||
#ifdef PNG_FIXED_POINT_SUPPORTED
|
||||
png_uint_32 PNGAPI
|
||||
png_get_cHRM_fixed(png_structp png_ptr, png_infop info_ptr,
|
||||
png_fixed_point *white_x, png_fixed_point *white_y, png_fixed_point *red_x,
|
||||
png_fixed_point *red_y, png_fixed_point *green_x, png_fixed_point *green_y,
|
||||
png_fixed_point *blue_x, png_fixed_point *blue_y)
|
||||
{
|
||||
if (png_ptr != NULL && info_ptr != NULL && (info_ptr->valid & PNG_INFO_cHRM))
|
||||
{
|
||||
png_debug1(1, "in %s retrieval function\n", "cHRM");
|
||||
if (white_x != NULL)
|
||||
*white_x = info_ptr->int_x_white;
|
||||
if (white_y != NULL)
|
||||
*white_y = info_ptr->int_y_white;
|
||||
if (red_x != NULL)
|
||||
*red_x = info_ptr->int_x_red;
|
||||
if (red_y != NULL)
|
||||
*red_y = info_ptr->int_y_red;
|
||||
if (green_x != NULL)
|
||||
*green_x = info_ptr->int_x_green;
|
||||
if (green_y != NULL)
|
||||
*green_y = info_ptr->int_y_green;
|
||||
if (blue_x != NULL)
|
||||
*blue_x = info_ptr->int_x_blue;
|
||||
if (blue_y != NULL)
|
||||
*blue_y = info_ptr->int_y_blue;
|
||||
return (PNG_INFO_cHRM);
|
||||
}
|
||||
return (0);
|
||||
}
|
||||
#endif
|
||||
#endif
|
||||
|
||||
#if defined(PNG_gAMA_SUPPORTED)
|
||||
#ifdef PNG_FLOATING_POINT_SUPPORTED
|
||||
png_uint_32 PNGAPI
|
||||
png_get_gAMA(png_structp png_ptr, png_infop info_ptr, double *file_gamma)
|
||||
{
|
||||
if (png_ptr != NULL && info_ptr != NULL && (info_ptr->valid & PNG_INFO_gAMA)
|
||||
&& file_gamma != NULL)
|
||||
{
|
||||
png_debug1(1, "in %s retrieval function\n", "gAMA");
|
||||
*file_gamma = (double)info_ptr->gamma;
|
||||
return (PNG_INFO_gAMA);
|
||||
}
|
||||
return (0);
|
||||
}
|
||||
#endif
|
||||
#ifdef PNG_FIXED_POINT_SUPPORTED
|
||||
png_uint_32 PNGAPI
|
||||
png_get_gAMA_fixed(png_structp png_ptr, png_infop info_ptr,
|
||||
png_fixed_point *int_file_gamma)
|
||||
{
|
||||
if (png_ptr != NULL && info_ptr != NULL && (info_ptr->valid & PNG_INFO_gAMA)
|
||||
&& int_file_gamma != NULL)
|
||||
{
|
||||
png_debug1(1, "in %s retrieval function\n", "gAMA");
|
||||
*int_file_gamma = info_ptr->int_gamma;
|
||||
return (PNG_INFO_gAMA);
|
||||
}
|
||||
return (0);
|
||||
}
|
||||
#endif
|
||||
#endif
|
||||
|
||||
#if defined(PNG_sRGB_SUPPORTED)
|
||||
png_uint_32 PNGAPI
|
||||
png_get_sRGB(png_structp png_ptr, png_infop info_ptr, int *file_srgb_intent)
|
||||
{
|
||||
if (png_ptr != NULL && info_ptr != NULL && (info_ptr->valid & PNG_INFO_sRGB)
|
||||
&& file_srgb_intent != NULL)
|
||||
{
|
||||
png_debug1(1, "in %s retrieval function\n", "sRGB");
|
||||
*file_srgb_intent = (int)info_ptr->srgb_intent;
|
||||
return (PNG_INFO_sRGB);
|
||||
}
|
||||
return (0);
|
||||
}
|
||||
#endif
|
||||
|
||||
#if defined(PNG_iCCP_SUPPORTED)
|
||||
png_uint_32 PNGAPI
|
||||
png_get_iCCP(png_structp png_ptr, png_infop info_ptr,
|
||||
png_charpp name, int *compression_type,
|
||||
png_charpp profile, png_uint_32 *proflen)
|
||||
{
|
||||
if (png_ptr != NULL && info_ptr != NULL && (info_ptr->valid & PNG_INFO_iCCP)
|
||||
&& name != NULL && profile != NULL && proflen != NULL)
|
||||
{
|
||||
png_debug1(1, "in %s retrieval function\n", "iCCP");
|
||||
*name = info_ptr->iccp_name;
|
||||
*profile = info_ptr->iccp_profile;
|
||||
/* compression_type is a dummy so the API won't have to change
|
||||
if we introduce multiple compression types later. */
|
||||
*proflen = (int)info_ptr->iccp_proflen;
|
||||
*compression_type = (int)info_ptr->iccp_compression;
|
||||
return (PNG_INFO_iCCP);
|
||||
}
|
||||
return (0);
|
||||
}
|
||||
#endif
|
||||
|
||||
#if defined(PNG_sPLT_SUPPORTED)
|
||||
png_uint_32 PNGAPI
|
||||
png_get_sPLT(png_structp png_ptr, png_infop info_ptr,
|
||||
png_sPLT_tpp spalettes)
|
||||
{
|
||||
if (png_ptr != NULL && info_ptr != NULL && spalettes != NULL)
|
||||
*spalettes = info_ptr->splt_palettes;
|
||||
return ((png_uint_32)info_ptr->splt_palettes_num);
|
||||
}
|
||||
#endif
|
||||
|
||||
#if defined(PNG_hIST_SUPPORTED)
|
||||
png_uint_32 PNGAPI
|
||||
png_get_hIST(png_structp png_ptr, png_infop info_ptr, png_uint_16p *hist)
|
||||
{
|
||||
if (png_ptr != NULL && info_ptr != NULL && (info_ptr->valid & PNG_INFO_hIST)
|
||||
&& hist != NULL)
|
||||
{
|
||||
png_debug1(1, "in %s retrieval function\n", "hIST");
|
||||
*hist = info_ptr->hist;
|
||||
return (PNG_INFO_hIST);
|
||||
}
|
||||
return (0);
|
||||
}
|
||||
#endif
|
||||
|
||||
png_uint_32 PNGAPI
|
||||
png_get_IHDR(png_structp png_ptr, png_infop info_ptr,
|
||||
png_uint_32 *width, png_uint_32 *height, int *bit_depth,
|
||||
int *color_type, int *interlace_type, int *compression_type,
|
||||
int *filter_type)
|
||||
|
||||
{
|
||||
if (png_ptr != NULL && info_ptr != NULL && width != NULL && height != NULL &&
|
||||
bit_depth != NULL && color_type != NULL)
|
||||
{
|
||||
int pixel_depth, channels;
|
||||
png_uint_32 rowbytes_per_pixel;
|
||||
|
||||
png_debug1(1, "in %s retrieval function\n", "IHDR");
|
||||
*width = info_ptr->width;
|
||||
*height = info_ptr->height;
|
||||
*bit_depth = info_ptr->bit_depth;
|
||||
if (info_ptr->bit_depth < 1 || info_ptr->bit_depth > 16)
|
||||
png_error(png_ptr, "Invalid bit depth");
|
||||
*color_type = info_ptr->color_type;
|
||||
if (info_ptr->color_type > 6)
|
||||
png_error(png_ptr, "Invalid color type");
|
||||
if (compression_type != NULL)
|
||||
*compression_type = info_ptr->compression_type;
|
||||
if (filter_type != NULL)
|
||||
*filter_type = info_ptr->filter_type;
|
||||
if (interlace_type != NULL)
|
||||
*interlace_type = info_ptr->interlace_type;
|
||||
|
||||
/* check for potential overflow of rowbytes */
|
||||
if (*color_type == PNG_COLOR_TYPE_PALETTE)
|
||||
channels = 1;
|
||||
else if (*color_type & PNG_COLOR_MASK_COLOR)
|
||||
channels = 3;
|
||||
else
|
||||
channels = 1;
|
||||
if (*color_type & PNG_COLOR_MASK_ALPHA)
|
||||
channels++;
|
||||
pixel_depth = *bit_depth * channels;
|
||||
rowbytes_per_pixel = (pixel_depth + 7) >> 3;
|
||||
if (width == 0 || *width > PNG_MAX_UINT)
|
||||
png_error(png_ptr, "Invalid image width");
|
||||
if (height == 0 || *height > PNG_MAX_UINT)
|
||||
png_error(png_ptr, "Invalid image height");
|
||||
if (*width > PNG_MAX_UINT/rowbytes_per_pixel - 64)
|
||||
{
|
||||
png_error(png_ptr,
|
||||
"Width too large for libpng to process image data.");
|
||||
}
|
||||
return (1);
|
||||
}
|
||||
return (0);
|
||||
}
|
||||
|
||||
#if defined(PNG_oFFs_SUPPORTED)
|
||||
png_uint_32 PNGAPI
|
||||
png_get_oFFs(png_structp png_ptr, png_infop info_ptr,
|
||||
png_int_32 *offset_x, png_int_32 *offset_y, int *unit_type)
|
||||
{
|
||||
if (png_ptr != NULL && info_ptr != NULL && (info_ptr->valid & PNG_INFO_oFFs)
|
||||
&& offset_x != NULL && offset_y != NULL && unit_type != NULL)
|
||||
{
|
||||
png_debug1(1, "in %s retrieval function\n", "oFFs");
|
||||
*offset_x = info_ptr->x_offset;
|
||||
*offset_y = info_ptr->y_offset;
|
||||
*unit_type = (int)info_ptr->offset_unit_type;
|
||||
return (PNG_INFO_oFFs);
|
||||
}
|
||||
return (0);
|
||||
}
|
||||
#endif
|
||||
|
||||
#if defined(PNG_pCAL_SUPPORTED)
|
||||
png_uint_32 PNGAPI
|
||||
png_get_pCAL(png_structp png_ptr, png_infop info_ptr,
|
||||
png_charp *purpose, png_int_32 *X0, png_int_32 *X1, int *type, int *nparams,
|
||||
png_charp *units, png_charpp *params)
|
||||
{
|
||||
if (png_ptr != NULL && info_ptr != NULL && (info_ptr->valid & PNG_INFO_pCAL)
|
||||
&& purpose != NULL && X0 != NULL && X1 != NULL && type != NULL &&
|
||||
nparams != NULL && units != NULL && params != NULL)
|
||||
{
|
||||
png_debug1(1, "in %s retrieval function\n", "pCAL");
|
||||
*purpose = info_ptr->pcal_purpose;
|
||||
*X0 = info_ptr->pcal_X0;
|
||||
*X1 = info_ptr->pcal_X1;
|
||||
*type = (int)info_ptr->pcal_type;
|
||||
*nparams = (int)info_ptr->pcal_nparams;
|
||||
*units = info_ptr->pcal_units;
|
||||
*params = info_ptr->pcal_params;
|
||||
return (PNG_INFO_pCAL);
|
||||
}
|
||||
return (0);
|
||||
}
|
||||
#endif
|
||||
|
||||
#if defined(PNG_sCAL_SUPPORTED)
|
||||
#ifdef PNG_FLOATING_POINT_SUPPORTED
|
||||
png_uint_32 PNGAPI
|
||||
png_get_sCAL(png_structp png_ptr, png_infop info_ptr,
|
||||
int *unit, double *width, double *height)
|
||||
{
|
||||
if (png_ptr != NULL && info_ptr != NULL &&
|
||||
(info_ptr->valid & PNG_INFO_sCAL))
|
||||
{
|
||||
*unit = info_ptr->scal_unit;
|
||||
*width = info_ptr->scal_pixel_width;
|
||||
*height = info_ptr->scal_pixel_height;
|
||||
return (PNG_INFO_sCAL);
|
||||
}
|
||||
return(0);
|
||||
}
|
||||
#else
|
||||
#ifdef PNG_FIXED_POINT_SUPPORTED
|
||||
png_uint_32 PNGAPI
|
||||
png_get_sCAL_s(png_structp png_ptr, png_infop info_ptr,
|
||||
int *unit, png_charpp width, png_charpp height)
|
||||
{
|
||||
if (png_ptr != NULL && info_ptr != NULL &&
|
||||
(info_ptr->valid & PNG_INFO_sCAL))
|
||||
{
|
||||
*unit = info_ptr->scal_unit;
|
||||
*width = info_ptr->scal_s_width;
|
||||
*height = info_ptr->scal_s_height;
|
||||
return (PNG_INFO_sCAL);
|
||||
}
|
||||
return(0);
|
||||
}
|
||||
#endif
|
||||
#endif
|
||||
#endif
|
||||
|
||||
#if defined(PNG_pHYs_SUPPORTED)
|
||||
png_uint_32 PNGAPI
|
||||
png_get_pHYs(png_structp png_ptr, png_infop info_ptr,
|
||||
png_uint_32 *res_x, png_uint_32 *res_y, int *unit_type)
|
||||
{
|
||||
png_uint_32 retval = 0;
|
||||
|
||||
if (png_ptr != NULL && info_ptr != NULL &&
|
||||
(info_ptr->valid & PNG_INFO_pHYs))
|
||||
{
|
||||
png_debug1(1, "in %s retrieval function\n", "pHYs");
|
||||
if (res_x != NULL)
|
||||
{
|
||||
*res_x = info_ptr->x_pixels_per_unit;
|
||||
retval |= PNG_INFO_pHYs;
|
||||
}
|
||||
if (res_y != NULL)
|
||||
{
|
||||
*res_y = info_ptr->y_pixels_per_unit;
|
||||
retval |= PNG_INFO_pHYs;
|
||||
}
|
||||
if (unit_type != NULL)
|
||||
{
|
||||
*unit_type = (int)info_ptr->phys_unit_type;
|
||||
retval |= PNG_INFO_pHYs;
|
||||
}
|
||||
}
|
||||
return (retval);
|
||||
}
|
||||
#endif
|
||||
|
||||
png_uint_32 PNGAPI
|
||||
png_get_PLTE(png_structp png_ptr, png_infop info_ptr, png_colorp *palette,
|
||||
int *num_palette)
|
||||
{
|
||||
if (png_ptr != NULL && info_ptr != NULL && (info_ptr->valid & PNG_INFO_PLTE)
|
||||
&& palette != NULL)
|
||||
{
|
||||
png_debug1(1, "in %s retrieval function\n", "PLTE");
|
||||
*palette = info_ptr->palette;
|
||||
*num_palette = info_ptr->num_palette;
|
||||
png_debug1(3, "num_palette = %d\n", *num_palette);
|
||||
return (PNG_INFO_PLTE);
|
||||
}
|
||||
return (0);
|
||||
}
|
||||
|
||||
#if defined(PNG_sBIT_SUPPORTED)
|
||||
png_uint_32 PNGAPI
|
||||
png_get_sBIT(png_structp png_ptr, png_infop info_ptr, png_color_8p *sig_bit)
|
||||
{
|
||||
if (png_ptr != NULL && info_ptr != NULL && (info_ptr->valid & PNG_INFO_sBIT)
|
||||
&& sig_bit != NULL)
|
||||
{
|
||||
png_debug1(1, "in %s retrieval function\n", "sBIT");
|
||||
*sig_bit = &(info_ptr->sig_bit);
|
||||
return (PNG_INFO_sBIT);
|
||||
}
|
||||
return (0);
|
||||
}
|
||||
#endif
|
||||
|
||||
#if defined(PNG_TEXT_SUPPORTED)
|
||||
png_uint_32 PNGAPI
|
||||
png_get_text(png_structp png_ptr, png_infop info_ptr, png_textp *text_ptr,
|
||||
int *num_text)
|
||||
{
|
||||
if (png_ptr != NULL && info_ptr != NULL && info_ptr->num_text > 0)
|
||||
{
|
||||
png_debug1(1, "in %s retrieval function\n",
|
||||
(png_ptr->chunk_name[0] == '\0' ? "text"
|
||||
: (png_const_charp)png_ptr->chunk_name));
|
||||
if (text_ptr != NULL)
|
||||
*text_ptr = info_ptr->text;
|
||||
if (num_text != NULL)
|
||||
*num_text = info_ptr->num_text;
|
||||
return ((png_uint_32)info_ptr->num_text);
|
||||
}
|
||||
if (num_text != NULL)
|
||||
*num_text = 0;
|
||||
return(0);
|
||||
}
|
||||
#endif
|
||||
|
||||
#if defined(PNG_tIME_SUPPORTED)
|
||||
png_uint_32 PNGAPI
|
||||
png_get_tIME(png_structp png_ptr, png_infop info_ptr, png_timep *mod_time)
|
||||
{
|
||||
if (png_ptr != NULL && info_ptr != NULL && (info_ptr->valid & PNG_INFO_tIME)
|
||||
&& mod_time != NULL)
|
||||
{
|
||||
png_debug1(1, "in %s retrieval function\n", "tIME");
|
||||
*mod_time = &(info_ptr->mod_time);
|
||||
return (PNG_INFO_tIME);
|
||||
}
|
||||
return (0);
|
||||
}
|
||||
#endif
|
||||
|
||||
#if defined(PNG_tRNS_SUPPORTED)
|
||||
png_uint_32 PNGAPI
|
||||
png_get_tRNS(png_structp png_ptr, png_infop info_ptr,
|
||||
png_bytep *trans, int *num_trans, png_color_16p *trans_values)
|
||||
{
|
||||
png_uint_32 retval = 0;
|
||||
if (png_ptr != NULL && info_ptr != NULL && (info_ptr->valid & PNG_INFO_tRNS))
|
||||
{
|
||||
png_debug1(1, "in %s retrieval function\n", "tRNS");
|
||||
if (info_ptr->color_type == PNG_COLOR_TYPE_PALETTE)
|
||||
{
|
||||
if (trans != NULL)
|
||||
{
|
||||
*trans = info_ptr->trans;
|
||||
retval |= PNG_INFO_tRNS;
|
||||
}
|
||||
if (trans_values != NULL)
|
||||
*trans_values = &(info_ptr->trans_values);
|
||||
}
|
||||
else /* if (info_ptr->color_type != PNG_COLOR_TYPE_PALETTE) */
|
||||
{
|
||||
if (trans_values != NULL)
|
||||
{
|
||||
*trans_values = &(info_ptr->trans_values);
|
||||
retval |= PNG_INFO_tRNS;
|
||||
}
|
||||
if(trans != NULL)
|
||||
*trans = NULL;
|
||||
}
|
||||
if(num_trans != NULL)
|
||||
{
|
||||
*num_trans = info_ptr->num_trans;
|
||||
retval |= PNG_INFO_tRNS;
|
||||
}
|
||||
}
|
||||
return (retval);
|
||||
}
|
||||
#endif
|
||||
|
||||
#if defined(PNG_UNKNOWN_CHUNKS_SUPPORTED)
|
||||
png_uint_32 PNGAPI
|
||||
png_get_unknown_chunks(png_structp png_ptr, png_infop info_ptr,
|
||||
png_unknown_chunkpp unknowns)
|
||||
{
|
||||
if (png_ptr != NULL && info_ptr != NULL && unknowns != NULL)
|
||||
*unknowns = info_ptr->unknown_chunks;
|
||||
return ((png_uint_32)info_ptr->unknown_chunks_num);
|
||||
}
|
||||
#endif
|
||||
|
||||
#if defined(PNG_READ_RGB_TO_GRAY_SUPPORTED)
|
||||
png_byte PNGAPI
|
||||
png_get_rgb_to_gray_status (png_structp png_ptr)
|
||||
{
|
||||
return (png_byte)(png_ptr? png_ptr->rgb_to_gray_status : 0);
|
||||
}
|
||||
#endif
|
||||
|
||||
#if defined(PNG_USER_CHUNKS_SUPPORTED)
|
||||
png_voidp PNGAPI
|
||||
png_get_user_chunk_ptr(png_structp png_ptr)
|
||||
{
|
||||
return (png_ptr? png_ptr->user_chunk_ptr : NULL);
|
||||
}
|
||||
#endif
|
||||
|
||||
|
||||
png_uint_32 PNGAPI
|
||||
png_get_compression_buffer_size(png_structp png_ptr)
|
||||
{
|
||||
return (png_uint_32)(png_ptr? png_ptr->zbuf_size : 0L);
|
||||
}
|
||||
|
||||
|
||||
#ifndef PNG_1_0_X
|
||||
#ifdef PNG_ASSEMBLER_CODE_SUPPORTED
|
||||
/* this function was added to libpng 1.2.0 and should exist by default */
|
||||
png_uint_32 PNGAPI
|
||||
png_get_asm_flags (png_structp png_ptr)
|
||||
{
|
||||
return (png_uint_32)(png_ptr? png_ptr->asm_flags : 0L);
|
||||
}
|
||||
|
||||
/* this function was added to libpng 1.2.0 and should exist by default */
|
||||
png_uint_32 PNGAPI
|
||||
png_get_asm_flagmask (int flag_select)
|
||||
{
|
||||
png_uint_32 settable_asm_flags = 0;
|
||||
|
||||
if (flag_select & PNG_SELECT_READ)
|
||||
settable_asm_flags |=
|
||||
PNG_ASM_FLAG_MMX_READ_COMBINE_ROW |
|
||||
PNG_ASM_FLAG_MMX_READ_INTERLACE |
|
||||
PNG_ASM_FLAG_MMX_READ_FILTER_SUB |
|
||||
PNG_ASM_FLAG_MMX_READ_FILTER_UP |
|
||||
PNG_ASM_FLAG_MMX_READ_FILTER_AVG |
|
||||
PNG_ASM_FLAG_MMX_READ_FILTER_PAETH ;
|
||||
/* no non-MMX flags yet */
|
||||
|
||||
#if 0
|
||||
/* GRR: no write-flags yet, either, but someday... */
|
||||
if (flag_select & PNG_SELECT_WRITE)
|
||||
settable_asm_flags |=
|
||||
PNG_ASM_FLAG_MMX_WRITE_ [whatever] ;
|
||||
#endif /* 0 */
|
||||
|
||||
return settable_asm_flags; /* _theoretically_ settable capabilities only */
|
||||
}
|
||||
#endif /* PNG_ASSEMBLER_CODE_SUPPORTED */
|
||||
|
||||
|
||||
#if defined(PNG_ASSEMBLER_CODE_SUPPORTED)
|
||||
/* GRR: could add this: && defined(PNG_MMX_CODE_SUPPORTED) */
|
||||
/* this function was added to libpng 1.2.0 */
|
||||
png_uint_32 PNGAPI
|
||||
png_get_mmx_flagmask (int flag_select, int *compilerID)
|
||||
{
|
||||
png_uint_32 settable_mmx_flags = 0;
|
||||
|
||||
if (flag_select & PNG_SELECT_READ)
|
||||
settable_mmx_flags |=
|
||||
PNG_ASM_FLAG_MMX_READ_COMBINE_ROW |
|
||||
PNG_ASM_FLAG_MMX_READ_INTERLACE |
|
||||
PNG_ASM_FLAG_MMX_READ_FILTER_SUB |
|
||||
PNG_ASM_FLAG_MMX_READ_FILTER_UP |
|
||||
PNG_ASM_FLAG_MMX_READ_FILTER_AVG |
|
||||
PNG_ASM_FLAG_MMX_READ_FILTER_PAETH ;
|
||||
#if 0
|
||||
/* GRR: no MMX write support yet, but someday... */
|
||||
if (flag_select & PNG_SELECT_WRITE)
|
||||
settable_mmx_flags |=
|
||||
PNG_ASM_FLAG_MMX_WRITE_ [whatever] ;
|
||||
#endif /* 0 */
|
||||
|
||||
if (compilerID != NULL) {
|
||||
#ifdef PNG_USE_PNGVCRD
|
||||
*compilerID = 1; /* MSVC */
|
||||
#else
|
||||
#ifdef PNG_USE_PNGGCCRD
|
||||
*compilerID = 2; /* gcc/gas */
|
||||
#else
|
||||
*compilerID = -1; /* unknown (i.e., no asm/MMX code compiled) */
|
||||
#endif
|
||||
#endif
|
||||
}
|
||||
|
||||
return settable_mmx_flags; /* _theoretically_ settable capabilities only */
|
||||
}
|
||||
|
||||
/* this function was added to libpng 1.2.0 */
|
||||
png_byte PNGAPI
|
||||
png_get_mmx_bitdepth_threshold (png_structp png_ptr)
|
||||
{
|
||||
return (png_byte)(png_ptr? png_ptr->mmx_bitdepth_threshold : 0);
|
||||
}
|
||||
|
||||
/* this function was added to libpng 1.2.0 */
|
||||
png_uint_32 PNGAPI
|
||||
png_get_mmx_rowbytes_threshold (png_structp png_ptr)
|
||||
{
|
||||
return (png_uint_32)(png_ptr? png_ptr->mmx_rowbytes_threshold : 0L);
|
||||
}
|
||||
#endif /* PNG_ASSEMBLER_CODE_SUPPORTED */
|
||||
#endif /* PNG_1_0_X */
|
|
@ -1,566 +0,0 @@
|
|||
|
||||
/* pngmem.c - stub functions for memory allocation
|
||||
*
|
||||
* libpng 1.2.5 - October 3, 2002
|
||||
* For conditions of distribution and use, see copyright notice in png.h
|
||||
* Copyright (c) 1998-2002 Glenn Randers-Pehrson
|
||||
* (Version 0.96 Copyright (c) 1996, 1997 Andreas Dilger)
|
||||
* (Version 0.88 Copyright (c) 1995, 1996 Guy Eric Schalnat, Group 42, Inc.)
|
||||
*
|
||||
* This file provides a location for all memory allocation. Users who
|
||||
* need special memory handling are expected to supply replacement
|
||||
* functions for png_malloc() and png_free(), and to use
|
||||
* png_create_read_struct_2() and png_create_write_struct_2() to
|
||||
* identify the replacement functions.
|
||||
*/
|
||||
|
||||
#define PNG_INTERNAL
|
||||
#include "png.h"
|
||||
|
||||
/* Borland DOS special memory handler */
|
||||
#if defined(__TURBOC__) && !defined(_Windows) && !defined(__FLAT__)
|
||||
/* if you change this, be sure to change the one in png.h also */
|
||||
|
||||
/* Allocate memory for a png_struct. The malloc and memset can be replaced
|
||||
by a single call to calloc() if this is thought to improve performance. */
|
||||
png_voidp /* PRIVATE */
|
||||
png_create_struct(int type)
|
||||
{
|
||||
#ifdef PNG_USER_MEM_SUPPORTED
|
||||
return (png_create_struct_2(type, png_malloc_ptr_NULL, png_voidp_NULL));
|
||||
}
|
||||
|
||||
/* Alternate version of png_create_struct, for use with user-defined malloc. */
|
||||
png_voidp /* PRIVATE */
|
||||
png_create_struct_2(int type, png_malloc_ptr malloc_fn, png_voidp mem_ptr)
|
||||
{
|
||||
#endif /* PNG_USER_MEM_SUPPORTED */
|
||||
png_size_t size;
|
||||
png_voidp struct_ptr;
|
||||
|
||||
if (type == PNG_STRUCT_INFO)
|
||||
size = sizeof(png_info);
|
||||
else if (type == PNG_STRUCT_PNG)
|
||||
size = sizeof(png_struct);
|
||||
else
|
||||
return (png_get_copyright());
|
||||
|
||||
#ifdef PNG_USER_MEM_SUPPORTED
|
||||
if(malloc_fn != NULL)
|
||||
{
|
||||
png_struct dummy_struct;
|
||||
png_structp png_ptr = &dummy_struct;
|
||||
png_ptr->mem_ptr=mem_ptr;
|
||||
struct_ptr = (*(malloc_fn))(png_ptr, (png_uint_32)size);
|
||||
}
|
||||
else
|
||||
#endif /* PNG_USER_MEM_SUPPORTED */
|
||||
struct_ptr = (png_voidp)farmalloc(size));
|
||||
if (struct_ptr != NULL)
|
||||
png_memset(struct_ptr, 0, size);
|
||||
return (struct_ptr);
|
||||
}
|
||||
|
||||
/* Free memory allocated by a png_create_struct() call */
|
||||
void /* PRIVATE */
|
||||
png_destroy_struct(png_voidp struct_ptr)
|
||||
{
|
||||
#ifdef PNG_USER_MEM_SUPPORTED
|
||||
png_destroy_struct_2(struct_ptr, png_free_ptr_NULL, png_voidp_NULL);
|
||||
}
|
||||
|
||||
/* Free memory allocated by a png_create_struct() call */
|
||||
void /* PRIVATE */
|
||||
png_destroy_struct_2(png_voidp struct_ptr, png_free_ptr free_fn,
|
||||
png_voidp mem_ptr)
|
||||
{
|
||||
#endif
|
||||
if (struct_ptr != NULL)
|
||||
{
|
||||
#ifdef PNG_USER_MEM_SUPPORTED
|
||||
if(free_fn != NULL)
|
||||
{
|
||||
png_struct dummy_struct;
|
||||
png_structp png_ptr = &dummy_struct;
|
||||
png_ptr->mem_ptr=mem_ptr;
|
||||
(*(free_fn))(png_ptr, struct_ptr);
|
||||
return;
|
||||
}
|
||||
#endif /* PNG_USER_MEM_SUPPORTED */
|
||||
farfree (struct_ptr);
|
||||
}
|
||||
}
|
||||
|
||||
/* Allocate memory. For reasonable files, size should never exceed
|
||||
* 64K. However, zlib may allocate more then 64K if you don't tell
|
||||
* it not to. See zconf.h and png.h for more information. zlib does
|
||||
* need to allocate exactly 64K, so whatever you call here must
|
||||
* have the ability to do that.
|
||||
*
|
||||
* Borland seems to have a problem in DOS mode for exactly 64K.
|
||||
* It gives you a segment with an offset of 8 (perhaps to store its
|
||||
* memory stuff). zlib doesn't like this at all, so we have to
|
||||
* detect and deal with it. This code should not be needed in
|
||||
* Windows or OS/2 modes, and only in 16 bit mode. This code has
|
||||
* been updated by Alexander Lehmann for version 0.89 to waste less
|
||||
* memory.
|
||||
*
|
||||
* Note that we can't use png_size_t for the "size" declaration,
|
||||
* since on some systems a png_size_t is a 16-bit quantity, and as a
|
||||
* result, we would be truncating potentially larger memory requests
|
||||
* (which should cause a fatal error) and introducing major problems.
|
||||
*/
|
||||
|
||||
png_voidp PNGAPI
|
||||
png_malloc(png_structp png_ptr, png_uint_32 size)
|
||||
{
|
||||
png_voidp ret;
|
||||
|
||||
if (png_ptr == NULL || size == 0)
|
||||
return (NULL);
|
||||
|
||||
#ifdef PNG_USER_MEM_SUPPORTED
|
||||
if(png_ptr->malloc_fn != NULL)
|
||||
{
|
||||
ret = ((png_voidp)(*(png_ptr->malloc_fn))(png_ptr, (png_size_t)size));
|
||||
if (ret == NULL && (png_ptr->flags&PNG_FLAG_MALLOC_NULL_MEM_OK) == 0)
|
||||
png_error(png_ptr, "Out of memory!");
|
||||
return (ret);
|
||||
}
|
||||
else
|
||||
return png_malloc_default(png_ptr, size);
|
||||
}
|
||||
|
||||
png_voidp PNGAPI
|
||||
png_malloc_default(png_structp png_ptr, png_uint_32 size)
|
||||
{
|
||||
png_voidp ret;
|
||||
#endif /* PNG_USER_MEM_SUPPORTED */
|
||||
|
||||
#ifdef PNG_MAX_MALLOC_64K
|
||||
if (size > (png_uint_32)65536L)
|
||||
png_error(png_ptr, "Cannot Allocate > 64K");
|
||||
#endif
|
||||
|
||||
if (size == (png_uint_32)65536L)
|
||||
{
|
||||
if (png_ptr->offset_table == NULL)
|
||||
{
|
||||
/* try to see if we need to do any of this fancy stuff */
|
||||
ret = farmalloc(size);
|
||||
if (ret == NULL || ((png_size_t)ret & 0xffff))
|
||||
{
|
||||
int num_blocks;
|
||||
png_uint_32 total_size;
|
||||
png_bytep table;
|
||||
int i;
|
||||
png_byte huge * hptr;
|
||||
|
||||
if (ret != NULL)
|
||||
{
|
||||
farfree(ret);
|
||||
ret = NULL;
|
||||
}
|
||||
|
||||
if(png_ptr->zlib_window_bits > 14)
|
||||
num_blocks = (int)(1 << (png_ptr->zlib_window_bits - 14));
|
||||
else
|
||||
num_blocks = 1;
|
||||
if (png_ptr->zlib_mem_level >= 7)
|
||||
num_blocks += (int)(1 << (png_ptr->zlib_mem_level - 7));
|
||||
else
|
||||
num_blocks++;
|
||||
|
||||
total_size = ((png_uint_32)65536L) * (png_uint_32)num_blocks+16;
|
||||
|
||||
table = farmalloc(total_size);
|
||||
|
||||
if (table == NULL)
|
||||
{
|
||||
if (png_ptr->flags&PNG_FLAG_MALLOC_NULL_MEM_OK) == 0)
|
||||
png_error(png_ptr, "Out Of Memory."); /* Note "O" and "M" */
|
||||
else
|
||||
png_warning(png_ptr, "Out Of Memory.");
|
||||
return (NULL);
|
||||
}
|
||||
|
||||
if ((png_size_t)table & 0xfff0)
|
||||
{
|
||||
if (png_ptr->flags&PNG_FLAG_MALLOC_NULL_MEM_OK) == 0)
|
||||
png_error(png_ptr,
|
||||
"Farmalloc didn't return normalized pointer");
|
||||
else
|
||||
png_warning(png_ptr,
|
||||
"Farmalloc didn't return normalized pointer");
|
||||
return (NULL);
|
||||
}
|
||||
|
||||
png_ptr->offset_table = table;
|
||||
png_ptr->offset_table_ptr = farmalloc(num_blocks *
|
||||
sizeof (png_bytep));
|
||||
|
||||
if (png_ptr->offset_table_ptr == NULL)
|
||||
{
|
||||
if (png_ptr->flags&PNG_FLAG_MALLOC_NULL_MEM_OK) == 0)
|
||||
png_error(png_ptr, "Out Of memory."); /* Note "O" and "M" */
|
||||
else
|
||||
png_warning(png_ptr, "Out Of memory.");
|
||||
return (NULL);
|
||||
}
|
||||
|
||||
hptr = (png_byte huge *)table;
|
||||
if ((png_size_t)hptr & 0xf)
|
||||
{
|
||||
hptr = (png_byte huge *)((long)(hptr) & 0xfffffff0L);
|
||||
hptr = hptr + 16L; /* "hptr += 16L" fails on Turbo C++ 3.0 */
|
||||
}
|
||||
for (i = 0; i < num_blocks; i++)
|
||||
{
|
||||
png_ptr->offset_table_ptr[i] = (png_bytep)hptr;
|
||||
hptr = hptr + (png_uint_32)65536L; /* "+=" fails on TC++3.0 */
|
||||
}
|
||||
|
||||
png_ptr->offset_table_number = num_blocks;
|
||||
png_ptr->offset_table_count = 0;
|
||||
png_ptr->offset_table_count_free = 0;
|
||||
}
|
||||
}
|
||||
|
||||
if (png_ptr->offset_table_count >= png_ptr->offset_table_number)
|
||||
{
|
||||
if (png_ptr->flags&PNG_FLAG_MALLOC_NULL_MEM_OK) == 0)
|
||||
png_error(png_ptr, "Out of Memory."); /* Note "o" and "M" */
|
||||
else
|
||||
png_warning(png_ptr, "Out of Memory.");
|
||||
return (NULL);
|
||||
}
|
||||
|
||||
ret = png_ptr->offset_table_ptr[png_ptr->offset_table_count++];
|
||||
}
|
||||
else
|
||||
ret = farmalloc(size);
|
||||
|
||||
if (ret == NULL)
|
||||
{
|
||||
if (png_ptr->flags&PNG_FLAG_MALLOC_NULL_MEM_OK) == 0)
|
||||
png_error(png_ptr, "Out of memory."); /* Note "o" and "m" */
|
||||
else
|
||||
png_warning(png_ptr, "Out of memory."); /* Note "o" and "m" */
|
||||
}
|
||||
|
||||
return (ret);
|
||||
}
|
||||
|
||||
/* free a pointer allocated by png_malloc(). In the default
|
||||
configuration, png_ptr is not used, but is passed in case it
|
||||
is needed. If ptr is NULL, return without taking any action. */
|
||||
void PNGAPI
|
||||
png_free(png_structp png_ptr, png_voidp ptr)
|
||||
{
|
||||
if (png_ptr == NULL || ptr == NULL)
|
||||
return;
|
||||
|
||||
#ifdef PNG_USER_MEM_SUPPORTED
|
||||
if (png_ptr->free_fn != NULL)
|
||||
{
|
||||
(*(png_ptr->free_fn))(png_ptr, ptr);
|
||||
return;
|
||||
}
|
||||
else png_free_default(png_ptr, ptr);
|
||||
}
|
||||
|
||||
void PNGAPI
|
||||
png_free_default(png_structp png_ptr, png_voidp ptr)
|
||||
{
|
||||
#endif /* PNG_USER_MEM_SUPPORTED */
|
||||
|
||||
if (png_ptr->offset_table != NULL)
|
||||
{
|
||||
int i;
|
||||
|
||||
for (i = 0; i < png_ptr->offset_table_count; i++)
|
||||
{
|
||||
if (ptr == png_ptr->offset_table_ptr[i])
|
||||
{
|
||||
ptr = NULL;
|
||||
png_ptr->offset_table_count_free++;
|
||||
break;
|
||||
}
|
||||
}
|
||||
if (png_ptr->offset_table_count_free == png_ptr->offset_table_count)
|
||||
{
|
||||
farfree(png_ptr->offset_table);
|
||||
farfree(png_ptr->offset_table_ptr);
|
||||
png_ptr->offset_table = NULL;
|
||||
png_ptr->offset_table_ptr = NULL;
|
||||
}
|
||||
}
|
||||
|
||||
if (ptr != NULL)
|
||||
{
|
||||
farfree(ptr);
|
||||
}
|
||||
}
|
||||
|
||||
#else /* Not the Borland DOS special memory handler */
|
||||
|
||||
/* Allocate memory for a png_struct or a png_info. The malloc and
|
||||
memset can be replaced by a single call to calloc() if this is thought
|
||||
to improve performance noticably. */
|
||||
png_voidp /* PRIVATE */
|
||||
png_create_struct(int type)
|
||||
{
|
||||
#ifdef PNG_USER_MEM_SUPPORTED
|
||||
return (png_create_struct_2(type, png_malloc_ptr_NULL, png_voidp_NULL));
|
||||
}
|
||||
|
||||
/* Allocate memory for a png_struct or a png_info. The malloc and
|
||||
memset can be replaced by a single call to calloc() if this is thought
|
||||
to improve performance noticably. */
|
||||
png_voidp /* PRIVATE */
|
||||
png_create_struct_2(int type, png_malloc_ptr malloc_fn, png_voidp mem_ptr)
|
||||
{
|
||||
#endif /* PNG_USER_MEM_SUPPORTED */
|
||||
png_size_t size;
|
||||
png_voidp struct_ptr;
|
||||
|
||||
if (type == PNG_STRUCT_INFO)
|
||||
size = sizeof(png_info);
|
||||
else if (type == PNG_STRUCT_PNG)
|
||||
size = sizeof(png_struct);
|
||||
else
|
||||
return (NULL);
|
||||
|
||||
#ifdef PNG_USER_MEM_SUPPORTED
|
||||
if(malloc_fn != NULL)
|
||||
{
|
||||
png_struct dummy_struct;
|
||||
png_structp png_ptr = &dummy_struct;
|
||||
png_ptr->mem_ptr=mem_ptr;
|
||||
struct_ptr = (*(malloc_fn))(png_ptr, size);
|
||||
if (struct_ptr != NULL)
|
||||
png_memset(struct_ptr, 0, size);
|
||||
return (struct_ptr);
|
||||
}
|
||||
#endif /* PNG_USER_MEM_SUPPORTED */
|
||||
|
||||
#if defined(__TURBOC__) && !defined(__FLAT__)
|
||||
if ((struct_ptr = (png_voidp)farmalloc(size)) != NULL)
|
||||
#else
|
||||
# if defined(_MSC_VER) && defined(MAXSEG_64K)
|
||||
if ((struct_ptr = (png_voidp)halloc(size,1)) != NULL)
|
||||
# else
|
||||
if ((struct_ptr = (png_voidp)malloc(size)) != NULL)
|
||||
# endif
|
||||
#endif
|
||||
{
|
||||
png_memset(struct_ptr, 0, size);
|
||||
}
|
||||
|
||||
return (struct_ptr);
|
||||
}
|
||||
|
||||
|
||||
/* Free memory allocated by a png_create_struct() call */
|
||||
void /* PRIVATE */
|
||||
png_destroy_struct(png_voidp struct_ptr)
|
||||
{
|
||||
#ifdef PNG_USER_MEM_SUPPORTED
|
||||
png_destroy_struct_2(struct_ptr, png_free_ptr_NULL, png_voidp_NULL);
|
||||
}
|
||||
|
||||
/* Free memory allocated by a png_create_struct() call */
|
||||
void /* PRIVATE */
|
||||
png_destroy_struct_2(png_voidp struct_ptr, png_free_ptr free_fn,
|
||||
png_voidp mem_ptr)
|
||||
{
|
||||
#endif /* PNG_USER_MEM_SUPPORTED */
|
||||
if (struct_ptr != NULL)
|
||||
{
|
||||
#ifdef PNG_USER_MEM_SUPPORTED
|
||||
if(free_fn != NULL)
|
||||
{
|
||||
png_struct dummy_struct;
|
||||
png_structp png_ptr = &dummy_struct;
|
||||
png_ptr->mem_ptr=mem_ptr;
|
||||
(*(free_fn))(png_ptr, struct_ptr);
|
||||
return;
|
||||
}
|
||||
#endif /* PNG_USER_MEM_SUPPORTED */
|
||||
#if defined(__TURBOC__) && !defined(__FLAT__)
|
||||
farfree(struct_ptr);
|
||||
#else
|
||||
# if defined(_MSC_VER) && defined(MAXSEG_64K)
|
||||
hfree(struct_ptr);
|
||||
# else
|
||||
free(struct_ptr);
|
||||
# endif
|
||||
#endif
|
||||
}
|
||||
}
|
||||
|
||||
/* Allocate memory. For reasonable files, size should never exceed
|
||||
64K. However, zlib may allocate more then 64K if you don't tell
|
||||
it not to. See zconf.h and png.h for more information. zlib does
|
||||
need to allocate exactly 64K, so whatever you call here must
|
||||
have the ability to do that. */
|
||||
|
||||
png_voidp PNGAPI
|
||||
png_malloc(png_structp png_ptr, png_uint_32 size)
|
||||
{
|
||||
png_voidp ret;
|
||||
|
||||
if (png_ptr == NULL || size == 0)
|
||||
return (NULL);
|
||||
|
||||
#ifdef PNG_USER_MEM_SUPPORTED
|
||||
if(png_ptr->malloc_fn != NULL)
|
||||
{
|
||||
ret = ((png_voidp)(*(png_ptr->malloc_fn))(png_ptr, (png_size_t)size));
|
||||
if (ret == NULL && (png_ptr->flags&PNG_FLAG_MALLOC_NULL_MEM_OK) == 0)
|
||||
png_error(png_ptr, "Out of Memory!");
|
||||
return (ret);
|
||||
}
|
||||
else
|
||||
return (png_malloc_default(png_ptr, size));
|
||||
}
|
||||
|
||||
png_voidp PNGAPI
|
||||
png_malloc_default(png_structp png_ptr, png_uint_32 size)
|
||||
{
|
||||
png_voidp ret;
|
||||
#endif /* PNG_USER_MEM_SUPPORTED */
|
||||
|
||||
#ifdef PNG_MAX_MALLOC_64K
|
||||
if (size > (png_uint_32)65536L)
|
||||
{
|
||||
if(png_ptr->flags&PNG_FLAG_MALLOC_NULL_MEM_OK) == 0)
|
||||
png_error(png_ptr, "Cannot Allocate > 64K");
|
||||
else
|
||||
return NULL;
|
||||
}
|
||||
#endif
|
||||
|
||||
#if defined(__TURBOC__) && !defined(__FLAT__)
|
||||
ret = farmalloc(size);
|
||||
#else
|
||||
# if defined(_MSC_VER) && defined(MAXSEG_64K)
|
||||
ret = halloc(size, 1);
|
||||
# else
|
||||
ret = malloc((size_t)size);
|
||||
# endif
|
||||
#endif
|
||||
|
||||
if (ret == NULL && (png_ptr->flags&PNG_FLAG_MALLOC_NULL_MEM_OK) == 0)
|
||||
png_error(png_ptr, "Out of Memory");
|
||||
|
||||
return (ret);
|
||||
}
|
||||
|
||||
/* Free a pointer allocated by png_malloc(). If ptr is NULL, return
|
||||
without taking any action. */
|
||||
void PNGAPI
|
||||
png_free(png_structp png_ptr, png_voidp ptr)
|
||||
{
|
||||
if (png_ptr == NULL || ptr == NULL)
|
||||
return;
|
||||
|
||||
#ifdef PNG_USER_MEM_SUPPORTED
|
||||
if (png_ptr->free_fn != NULL)
|
||||
{
|
||||
(*(png_ptr->free_fn))(png_ptr, ptr);
|
||||
return;
|
||||
}
|
||||
else png_free_default(png_ptr, ptr);
|
||||
}
|
||||
void PNGAPI
|
||||
png_free_default(png_structp png_ptr, png_voidp ptr)
|
||||
{
|
||||
if (png_ptr == NULL || ptr == NULL)
|
||||
return;
|
||||
|
||||
#endif /* PNG_USER_MEM_SUPPORTED */
|
||||
|
||||
#if defined(__TURBOC__) && !defined(__FLAT__)
|
||||
farfree(ptr);
|
||||
#else
|
||||
# if defined(_MSC_VER) && defined(MAXSEG_64K)
|
||||
hfree(ptr);
|
||||
# else
|
||||
free(ptr);
|
||||
# endif
|
||||
#endif
|
||||
}
|
||||
|
||||
#endif /* Not Borland DOS special memory handler */
|
||||
|
||||
#if defined(PNG_1_0_X)
|
||||
# define png_malloc_warn png_malloc
|
||||
#else
|
||||
/* This function was added at libpng version 1.2.3. The png_malloc_warn()
|
||||
* function will issue a png_warning and return NULL instead of issuing a
|
||||
* png_error, if it fails to allocate the requested memory.
|
||||
*/
|
||||
png_voidp PNGAPI
|
||||
png_malloc_warn(png_structp png_ptr, png_uint_32 size)
|
||||
{
|
||||
png_voidp ptr;
|
||||
png_uint_32 save_flags=png_ptr->flags;
|
||||
|
||||
png_ptr->flags|=PNG_FLAG_MALLOC_NULL_MEM_OK;
|
||||
ptr = (png_voidp)png_malloc((png_structp)png_ptr, size);
|
||||
png_ptr->flags=save_flags;
|
||||
return(ptr);
|
||||
}
|
||||
#endif
|
||||
|
||||
png_voidp PNGAPI
|
||||
png_memcpy_check (png_structp png_ptr, png_voidp s1, png_voidp s2,
|
||||
png_uint_32 length)
|
||||
{
|
||||
png_size_t size;
|
||||
|
||||
size = (png_size_t)length;
|
||||
if ((png_uint_32)size != length)
|
||||
png_error(png_ptr,"Overflow in png_memcpy_check.");
|
||||
|
||||
return(png_memcpy (s1, s2, size));
|
||||
}
|
||||
|
||||
png_voidp PNGAPI
|
||||
png_memset_check (png_structp png_ptr, png_voidp s1, int value,
|
||||
png_uint_32 length)
|
||||
{
|
||||
png_size_t size;
|
||||
|
||||
size = (png_size_t)length;
|
||||
if ((png_uint_32)size != length)
|
||||
png_error(png_ptr,"Overflow in png_memset_check.");
|
||||
|
||||
return (png_memset (s1, value, size));
|
||||
|
||||
}
|
||||
|
||||
#ifdef PNG_USER_MEM_SUPPORTED
|
||||
/* This function is called when the application wants to use another method
|
||||
* of allocating and freeing memory.
|
||||
*/
|
||||
void PNGAPI
|
||||
png_set_mem_fn(png_structp png_ptr, png_voidp mem_ptr, png_malloc_ptr
|
||||
malloc_fn, png_free_ptr free_fn)
|
||||
{
|
||||
png_ptr->mem_ptr = mem_ptr;
|
||||
png_ptr->malloc_fn = malloc_fn;
|
||||
png_ptr->free_fn = free_fn;
|
||||
}
|
||||
|
||||
/* This function returns a pointer to the mem_ptr associated with the user
|
||||
* functions. The application should free any memory associated with this
|
||||
* pointer before png_write_destroy and png_read_destroy are called.
|
||||
*/
|
||||
png_voidp PNGAPI
|
||||
png_get_mem_ptr(png_structp png_ptr)
|
||||
{
|
||||
return ((png_voidp)png_ptr->mem_ptr);
|
||||
}
|
||||
#endif /* PNG_USER_MEM_SUPPORTED */
|
File diff suppressed because it is too large
Load Diff
File diff suppressed because it is too large
Load Diff
|
@ -1,161 +0,0 @@
|
|||
|
||||
/* pngrio.c - functions for data input
|
||||
*
|
||||
* libpng 1.2.5 - October 3, 2002
|
||||
* For conditions of distribution and use, see copyright notice in png.h
|
||||
* Copyright (c) 1998-2002 Glenn Randers-Pehrson
|
||||
* (Version 0.96 Copyright (c) 1996, 1997 Andreas Dilger)
|
||||
* (Version 0.88 Copyright (c) 1995, 1996 Guy Eric Schalnat, Group 42, Inc.)
|
||||
*
|
||||
* This file provides a location for all input. Users who need
|
||||
* special handling are expected to write a function that has the same
|
||||
* arguments as this and performs a similar function, but that possibly
|
||||
* has a different input method. Note that you shouldn't change this
|
||||
* function, but rather write a replacement function and then make
|
||||
* libpng use it at run time with png_set_read_fn(...).
|
||||
*/
|
||||
|
||||
#define PNG_INTERNAL
|
||||
#include "png.h"
|
||||
|
||||
/* Read the data from whatever input you are using. The default routine
|
||||
reads from a file pointer. Note that this routine sometimes gets called
|
||||
with very small lengths, so you should implement some kind of simple
|
||||
buffering if you are using unbuffered reads. This should never be asked
|
||||
to read more then 64K on a 16 bit machine. */
|
||||
void /* PRIVATE */
|
||||
png_read_data(png_structp png_ptr, png_bytep data, png_size_t length)
|
||||
{
|
||||
png_debug1(4,"reading %d bytes\n", (int)length);
|
||||
if (png_ptr->read_data_fn != NULL)
|
||||
(*(png_ptr->read_data_fn))(png_ptr, data, length);
|
||||
else
|
||||
png_error(png_ptr, "Call to NULL read function");
|
||||
}
|
||||
|
||||
#if !defined(PNG_NO_STDIO)
|
||||
/* This is the function that does the actual reading of data. If you are
|
||||
not reading from a standard C stream, you should create a replacement
|
||||
read_data function and use it at run time with png_set_read_fn(), rather
|
||||
than changing the library. */
|
||||
#ifndef USE_FAR_KEYWORD
|
||||
void PNGAPI
|
||||
png_default_read_data(png_structp png_ptr, png_bytep data, png_size_t length)
|
||||
{
|
||||
png_size_t check;
|
||||
|
||||
/* fread() returns 0 on error, so it is OK to store this in a png_size_t
|
||||
* instead of an int, which is what fread() actually returns.
|
||||
*/
|
||||
#if defined(_WIN32_WCE)
|
||||
if ( !ReadFile((HANDLE)(png_ptr->io_ptr), data, length, &check, NULL) )
|
||||
check = 0;
|
||||
#else
|
||||
check = (png_size_t)fread(data, (png_size_t)1, length,
|
||||
(png_FILE_p)png_ptr->io_ptr);
|
||||
#endif
|
||||
|
||||
if (check != length)
|
||||
png_error(png_ptr, "Read Error");
|
||||
}
|
||||
#else
|
||||
/* this is the model-independent version. Since the standard I/O library
|
||||
can't handle far buffers in the medium and small models, we have to copy
|
||||
the data.
|
||||
*/
|
||||
|
||||
#define NEAR_BUF_SIZE 1024
|
||||
#define MIN(a,b) (a <= b ? a : b)
|
||||
|
||||
static void /* PRIVATE */
|
||||
png_default_read_data(png_structp png_ptr, png_bytep data, png_size_t length)
|
||||
{
|
||||
int check;
|
||||
png_byte *n_data;
|
||||
png_FILE_p io_ptr;
|
||||
|
||||
/* Check if data really is near. If so, use usual code. */
|
||||
n_data = (png_byte *)CVT_PTR_NOCHECK(data);
|
||||
io_ptr = (png_FILE_p)CVT_PTR(png_ptr->io_ptr);
|
||||
if ((png_bytep)n_data == data)
|
||||
{
|
||||
#if defined(_WIN32_WCE)
|
||||
if ( !ReadFile((HANDLE)(png_ptr->io_ptr), data, length, &check, NULL) )
|
||||
check = 0;
|
||||
#else
|
||||
check = fread(n_data, 1, length, io_ptr);
|
||||
#endif
|
||||
}
|
||||
else
|
||||
{
|
||||
png_byte buf[NEAR_BUF_SIZE];
|
||||
png_size_t read, remaining, err;
|
||||
check = 0;
|
||||
remaining = length;
|
||||
do
|
||||
{
|
||||
read = MIN(NEAR_BUF_SIZE, remaining);
|
||||
#if defined(_WIN32_WCE)
|
||||
if ( !ReadFile((HANDLE)(io_ptr), buf, read, &err, NULL) )
|
||||
err = 0;
|
||||
#else
|
||||
err = fread(buf, (png_size_t)1, read, io_ptr);
|
||||
#endif
|
||||
png_memcpy(data, buf, read); /* copy far buffer to near buffer */
|
||||
if(err != read)
|
||||
break;
|
||||
else
|
||||
check += err;
|
||||
data += read;
|
||||
remaining -= read;
|
||||
}
|
||||
while (remaining != 0);
|
||||
}
|
||||
if ((png_uint_32)check != (png_uint_32)length)
|
||||
png_error(png_ptr, "read Error");
|
||||
}
|
||||
#endif
|
||||
#endif
|
||||
|
||||
/* This function allows the application to supply a new input function
|
||||
for libpng if standard C streams aren't being used.
|
||||
|
||||
This function takes as its arguments:
|
||||
png_ptr - pointer to a png input data structure
|
||||
io_ptr - pointer to user supplied structure containing info about
|
||||
the input functions. May be NULL.
|
||||
read_data_fn - pointer to a new input function that takes as its
|
||||
arguments a pointer to a png_struct, a pointer to
|
||||
a location where input data can be stored, and a 32-bit
|
||||
unsigned int that is the number of bytes to be read.
|
||||
To exit and output any fatal error messages the new write
|
||||
function should call png_error(png_ptr, "Error msg"). */
|
||||
void PNGAPI
|
||||
png_set_read_fn(png_structp png_ptr, png_voidp io_ptr,
|
||||
png_rw_ptr read_data_fn)
|
||||
{
|
||||
png_ptr->io_ptr = io_ptr;
|
||||
|
||||
#if !defined(PNG_NO_STDIO)
|
||||
if (read_data_fn != NULL)
|
||||
png_ptr->read_data_fn = read_data_fn;
|
||||
else
|
||||
png_ptr->read_data_fn = png_default_read_data;
|
||||
#else
|
||||
png_ptr->read_data_fn = read_data_fn;
|
||||
#endif
|
||||
|
||||
/* It is an error to write to a read device */
|
||||
if (png_ptr->write_data_fn != NULL)
|
||||
{
|
||||
png_ptr->write_data_fn = NULL;
|
||||
png_warning(png_ptr,
|
||||
"It's an error to set both read_data_fn and write_data_fn in the ");
|
||||
png_warning(png_ptr,
|
||||
"same structure. Resetting write_data_fn to NULL.");
|
||||
}
|
||||
|
||||
#if defined(PNG_WRITE_FLUSH_SUPPORTED)
|
||||
png_ptr->output_flush_fn = NULL;
|
||||
#endif
|
||||
}
|
File diff suppressed because it is too large
Load Diff
File diff suppressed because it is too large
Load Diff
File diff suppressed because it is too large
Load Diff
|
@ -1,640 +0,0 @@
|
|||
|
||||
/* pngtrans.c - transforms the data in a row (used by both readers and writers)
|
||||
*
|
||||
* libpng 1.2.5 - October 3, 2002
|
||||
* For conditions of distribution and use, see copyright notice in png.h
|
||||
* Copyright (c) 1998-2002 Glenn Randers-Pehrson
|
||||
* (Version 0.96 Copyright (c) 1996, 1997 Andreas Dilger)
|
||||
* (Version 0.88 Copyright (c) 1995, 1996 Guy Eric Schalnat, Group 42, Inc.)
|
||||
*/
|
||||
|
||||
#define PNG_INTERNAL
|
||||
#include "png.h"
|
||||
|
||||
#if defined(PNG_READ_BGR_SUPPORTED) || defined(PNG_WRITE_BGR_SUPPORTED)
|
||||
/* turn on BGR-to-RGB mapping */
|
||||
void PNGAPI
|
||||
png_set_bgr(png_structp png_ptr)
|
||||
{
|
||||
png_debug(1, "in png_set_bgr\n");
|
||||
png_ptr->transformations |= PNG_BGR;
|
||||
}
|
||||
#endif
|
||||
|
||||
#if defined(PNG_READ_SWAP_SUPPORTED) || defined(PNG_WRITE_SWAP_SUPPORTED)
|
||||
/* turn on 16 bit byte swapping */
|
||||
void PNGAPI
|
||||
png_set_swap(png_structp png_ptr)
|
||||
{
|
||||
png_debug(1, "in png_set_swap\n");
|
||||
if (png_ptr->bit_depth == 16)
|
||||
png_ptr->transformations |= PNG_SWAP_BYTES;
|
||||
}
|
||||
#endif
|
||||
|
||||
#if defined(PNG_READ_PACK_SUPPORTED) || defined(PNG_WRITE_PACK_SUPPORTED)
|
||||
/* turn on pixel packing */
|
||||
void PNGAPI
|
||||
png_set_packing(png_structp png_ptr)
|
||||
{
|
||||
png_debug(1, "in png_set_packing\n");
|
||||
if (png_ptr->bit_depth < 8)
|
||||
{
|
||||
png_ptr->transformations |= PNG_PACK;
|
||||
png_ptr->usr_bit_depth = 8;
|
||||
}
|
||||
}
|
||||
#endif
|
||||
|
||||
#if defined(PNG_READ_PACKSWAP_SUPPORTED)||defined(PNG_WRITE_PACKSWAP_SUPPORTED)
|
||||
/* turn on packed pixel swapping */
|
||||
void PNGAPI
|
||||
png_set_packswap(png_structp png_ptr)
|
||||
{
|
||||
png_debug(1, "in png_set_packswap\n");
|
||||
if (png_ptr->bit_depth < 8)
|
||||
png_ptr->transformations |= PNG_PACKSWAP;
|
||||
}
|
||||
#endif
|
||||
|
||||
#if defined(PNG_READ_SHIFT_SUPPORTED) || defined(PNG_WRITE_SHIFT_SUPPORTED)
|
||||
void PNGAPI
|
||||
png_set_shift(png_structp png_ptr, png_color_8p true_bits)
|
||||
{
|
||||
png_debug(1, "in png_set_shift\n");
|
||||
png_ptr->transformations |= PNG_SHIFT;
|
||||
png_ptr->shift = *true_bits;
|
||||
}
|
||||
#endif
|
||||
|
||||
#if defined(PNG_READ_INTERLACING_SUPPORTED) || \
|
||||
defined(PNG_WRITE_INTERLACING_SUPPORTED)
|
||||
int PNGAPI
|
||||
png_set_interlace_handling(png_structp png_ptr)
|
||||
{
|
||||
png_debug(1, "in png_set_interlace handling\n");
|
||||
if (png_ptr->interlaced)
|
||||
{
|
||||
png_ptr->transformations |= PNG_INTERLACE;
|
||||
return (7);
|
||||
}
|
||||
|
||||
return (1);
|
||||
}
|
||||
#endif
|
||||
|
||||
#if defined(PNG_READ_FILLER_SUPPORTED) || defined(PNG_WRITE_FILLER_SUPPORTED)
|
||||
/* Add a filler byte on read, or remove a filler or alpha byte on write.
|
||||
* The filler type has changed in v0.95 to allow future 2-byte fillers
|
||||
* for 48-bit input data, as well as to avoid problems with some compilers
|
||||
* that don't like bytes as parameters.
|
||||
*/
|
||||
void PNGAPI
|
||||
png_set_filler(png_structp png_ptr, png_uint_32 filler, int filler_loc)
|
||||
{
|
||||
png_debug(1, "in png_set_filler\n");
|
||||
png_ptr->transformations |= PNG_FILLER;
|
||||
png_ptr->filler = (png_byte)filler;
|
||||
if (filler_loc == PNG_FILLER_AFTER)
|
||||
png_ptr->flags |= PNG_FLAG_FILLER_AFTER;
|
||||
else
|
||||
png_ptr->flags &= ~PNG_FLAG_FILLER_AFTER;
|
||||
|
||||
/* This should probably go in the "do_filler" routine.
|
||||
* I attempted to do that in libpng-1.0.1a but that caused problems
|
||||
* so I restored it in libpng-1.0.2a
|
||||
*/
|
||||
|
||||
if (png_ptr->color_type == PNG_COLOR_TYPE_RGB)
|
||||
{
|
||||
png_ptr->usr_channels = 4;
|
||||
}
|
||||
|
||||
/* Also I added this in libpng-1.0.2a (what happens when we expand
|
||||
* a less-than-8-bit grayscale to GA? */
|
||||
|
||||
if (png_ptr->color_type == PNG_COLOR_TYPE_GRAY && png_ptr->bit_depth >= 8)
|
||||
{
|
||||
png_ptr->usr_channels = 2;
|
||||
}
|
||||
}
|
||||
#endif
|
||||
|
||||
#if defined(PNG_READ_SWAP_ALPHA_SUPPORTED) || \
|
||||
defined(PNG_WRITE_SWAP_ALPHA_SUPPORTED)
|
||||
void PNGAPI
|
||||
png_set_swap_alpha(png_structp png_ptr)
|
||||
{
|
||||
png_debug(1, "in png_set_swap_alpha\n");
|
||||
png_ptr->transformations |= PNG_SWAP_ALPHA;
|
||||
}
|
||||
#endif
|
||||
|
||||
#if defined(PNG_READ_INVERT_ALPHA_SUPPORTED) || \
|
||||
defined(PNG_WRITE_INVERT_ALPHA_SUPPORTED)
|
||||
void PNGAPI
|
||||
png_set_invert_alpha(png_structp png_ptr)
|
||||
{
|
||||
png_debug(1, "in png_set_invert_alpha\n");
|
||||
png_ptr->transformations |= PNG_INVERT_ALPHA;
|
||||
}
|
||||
#endif
|
||||
|
||||
#if defined(PNG_READ_INVERT_SUPPORTED) || defined(PNG_WRITE_INVERT_SUPPORTED)
|
||||
void PNGAPI
|
||||
png_set_invert_mono(png_structp png_ptr)
|
||||
{
|
||||
png_debug(1, "in png_set_invert_mono\n");
|
||||
png_ptr->transformations |= PNG_INVERT_MONO;
|
||||
}
|
||||
|
||||
/* invert monochrome grayscale data */
|
||||
void /* PRIVATE */
|
||||
png_do_invert(png_row_infop row_info, png_bytep row)
|
||||
{
|
||||
png_debug(1, "in png_do_invert\n");
|
||||
/* This test removed from libpng version 1.0.13 and 1.2.0:
|
||||
* if (row_info->bit_depth == 1 &&
|
||||
*/
|
||||
#if defined(PNG_USELESS_TESTS_SUPPORTED)
|
||||
if (row == NULL || row_info == NULL)
|
||||
return;
|
||||
#endif
|
||||
if (row_info->color_type == PNG_COLOR_TYPE_GRAY)
|
||||
{
|
||||
png_bytep rp = row;
|
||||
png_uint_32 i;
|
||||
png_uint_32 istop = row_info->rowbytes;
|
||||
|
||||
for (i = 0; i < istop; i++)
|
||||
{
|
||||
*rp = (png_byte)(~(*rp));
|
||||
rp++;
|
||||
}
|
||||
}
|
||||
else if (row_info->color_type == PNG_COLOR_TYPE_GRAY_ALPHA &&
|
||||
row_info->bit_depth == 8)
|
||||
{
|
||||
png_bytep rp = row;
|
||||
png_uint_32 i;
|
||||
png_uint_32 istop = row_info->rowbytes;
|
||||
|
||||
for (i = 0; i < istop; i+=2)
|
||||
{
|
||||
*rp = (png_byte)(~(*rp));
|
||||
rp+=2;
|
||||
}
|
||||
}
|
||||
else if (row_info->color_type == PNG_COLOR_TYPE_GRAY_ALPHA &&
|
||||
row_info->bit_depth == 16)
|
||||
{
|
||||
png_bytep rp = row;
|
||||
png_uint_32 i;
|
||||
png_uint_32 istop = row_info->rowbytes;
|
||||
|
||||
for (i = 0; i < istop; i+=4)
|
||||
{
|
||||
*rp = (png_byte)(~(*rp));
|
||||
*(rp+1) = (png_byte)(~(*(rp+1)));
|
||||
rp+=4;
|
||||
}
|
||||
}
|
||||
}
|
||||
#endif
|
||||
|
||||
#if defined(PNG_READ_SWAP_SUPPORTED) || defined(PNG_WRITE_SWAP_SUPPORTED)
|
||||
/* swaps byte order on 16 bit depth images */
|
||||
void /* PRIVATE */
|
||||
png_do_swap(png_row_infop row_info, png_bytep row)
|
||||
{
|
||||
png_debug(1, "in png_do_swap\n");
|
||||
if (
|
||||
#if defined(PNG_USELESS_TESTS_SUPPORTED)
|
||||
row != NULL && row_info != NULL &&
|
||||
#endif
|
||||
row_info->bit_depth == 16)
|
||||
{
|
||||
png_bytep rp = row;
|
||||
png_uint_32 i;
|
||||
png_uint_32 istop= row_info->width * row_info->channels;
|
||||
|
||||
for (i = 0; i < istop; i++, rp += 2)
|
||||
{
|
||||
png_byte t = *rp;
|
||||
*rp = *(rp + 1);
|
||||
*(rp + 1) = t;
|
||||
}
|
||||
}
|
||||
}
|
||||
#endif
|
||||
|
||||
#if defined(PNG_READ_PACKSWAP_SUPPORTED)||defined(PNG_WRITE_PACKSWAP_SUPPORTED)
|
||||
static png_byte onebppswaptable[256] = {
|
||||
0x00, 0x80, 0x40, 0xC0, 0x20, 0xA0, 0x60, 0xE0,
|
||||
0x10, 0x90, 0x50, 0xD0, 0x30, 0xB0, 0x70, 0xF0,
|
||||
0x08, 0x88, 0x48, 0xC8, 0x28, 0xA8, 0x68, 0xE8,
|
||||
0x18, 0x98, 0x58, 0xD8, 0x38, 0xB8, 0x78, 0xF8,
|
||||
0x04, 0x84, 0x44, 0xC4, 0x24, 0xA4, 0x64, 0xE4,
|
||||
0x14, 0x94, 0x54, 0xD4, 0x34, 0xB4, 0x74, 0xF4,
|
||||
0x0C, 0x8C, 0x4C, 0xCC, 0x2C, 0xAC, 0x6C, 0xEC,
|
||||
0x1C, 0x9C, 0x5C, 0xDC, 0x3C, 0xBC, 0x7C, 0xFC,
|
||||
0x02, 0x82, 0x42, 0xC2, 0x22, 0xA2, 0x62, 0xE2,
|
||||
0x12, 0x92, 0x52, 0xD2, 0x32, 0xB2, 0x72, 0xF2,
|
||||
0x0A, 0x8A, 0x4A, 0xCA, 0x2A, 0xAA, 0x6A, 0xEA,
|
||||
0x1A, 0x9A, 0x5A, 0xDA, 0x3A, 0xBA, 0x7A, 0xFA,
|
||||
0x06, 0x86, 0x46, 0xC6, 0x26, 0xA6, 0x66, 0xE6,
|
||||
0x16, 0x96, 0x56, 0xD6, 0x36, 0xB6, 0x76, 0xF6,
|
||||
0x0E, 0x8E, 0x4E, 0xCE, 0x2E, 0xAE, 0x6E, 0xEE,
|
||||
0x1E, 0x9E, 0x5E, 0xDE, 0x3E, 0xBE, 0x7E, 0xFE,
|
||||
0x01, 0x81, 0x41, 0xC1, 0x21, 0xA1, 0x61, 0xE1,
|
||||
0x11, 0x91, 0x51, 0xD1, 0x31, 0xB1, 0x71, 0xF1,
|
||||
0x09, 0x89, 0x49, 0xC9, 0x29, 0xA9, 0x69, 0xE9,
|
||||
0x19, 0x99, 0x59, 0xD9, 0x39, 0xB9, 0x79, 0xF9,
|
||||
0x05, 0x85, 0x45, 0xC5, 0x25, 0xA5, 0x65, 0xE5,
|
||||
0x15, 0x95, 0x55, 0xD5, 0x35, 0xB5, 0x75, 0xF5,
|
||||
0x0D, 0x8D, 0x4D, 0xCD, 0x2D, 0xAD, 0x6D, 0xED,
|
||||
0x1D, 0x9D, 0x5D, 0xDD, 0x3D, 0xBD, 0x7D, 0xFD,
|
||||
0x03, 0x83, 0x43, 0xC3, 0x23, 0xA3, 0x63, 0xE3,
|
||||
0x13, 0x93, 0x53, 0xD3, 0x33, 0xB3, 0x73, 0xF3,
|
||||
0x0B, 0x8B, 0x4B, 0xCB, 0x2B, 0xAB, 0x6B, 0xEB,
|
||||
0x1B, 0x9B, 0x5B, 0xDB, 0x3B, 0xBB, 0x7B, 0xFB,
|
||||
0x07, 0x87, 0x47, 0xC7, 0x27, 0xA7, 0x67, 0xE7,
|
||||
0x17, 0x97, 0x57, 0xD7, 0x37, 0xB7, 0x77, 0xF7,
|
||||
0x0F, 0x8F, 0x4F, 0xCF, 0x2F, 0xAF, 0x6F, 0xEF,
|
||||
0x1F, 0x9F, 0x5F, 0xDF, 0x3F, 0xBF, 0x7F, 0xFF
|
||||
};
|
||||
|
||||
static png_byte twobppswaptable[256] = {
|
||||
0x00, 0x40, 0x80, 0xC0, 0x10, 0x50, 0x90, 0xD0,
|
||||
0x20, 0x60, 0xA0, 0xE0, 0x30, 0x70, 0xB0, 0xF0,
|
||||
0x04, 0x44, 0x84, 0xC4, 0x14, 0x54, 0x94, 0xD4,
|
||||
0x24, 0x64, 0xA4, 0xE4, 0x34, 0x74, 0xB4, 0xF4,
|
||||
0x08, 0x48, 0x88, 0xC8, 0x18, 0x58, 0x98, 0xD8,
|
||||
0x28, 0x68, 0xA8, 0xE8, 0x38, 0x78, 0xB8, 0xF8,
|
||||
0x0C, 0x4C, 0x8C, 0xCC, 0x1C, 0x5C, 0x9C, 0xDC,
|
||||
0x2C, 0x6C, 0xAC, 0xEC, 0x3C, 0x7C, 0xBC, 0xFC,
|
||||
0x01, 0x41, 0x81, 0xC1, 0x11, 0x51, 0x91, 0xD1,
|
||||
0x21, 0x61, 0xA1, 0xE1, 0x31, 0x71, 0xB1, 0xF1,
|
||||
0x05, 0x45, 0x85, 0xC5, 0x15, 0x55, 0x95, 0xD5,
|
||||
0x25, 0x65, 0xA5, 0xE5, 0x35, 0x75, 0xB5, 0xF5,
|
||||
0x09, 0x49, 0x89, 0xC9, 0x19, 0x59, 0x99, 0xD9,
|
||||
0x29, 0x69, 0xA9, 0xE9, 0x39, 0x79, 0xB9, 0xF9,
|
||||
0x0D, 0x4D, 0x8D, 0xCD, 0x1D, 0x5D, 0x9D, 0xDD,
|
||||
0x2D, 0x6D, 0xAD, 0xED, 0x3D, 0x7D, 0xBD, 0xFD,
|
||||
0x02, 0x42, 0x82, 0xC2, 0x12, 0x52, 0x92, 0xD2,
|
||||
0x22, 0x62, 0xA2, 0xE2, 0x32, 0x72, 0xB2, 0xF2,
|
||||
0x06, 0x46, 0x86, 0xC6, 0x16, 0x56, 0x96, 0xD6,
|
||||
0x26, 0x66, 0xA6, 0xE6, 0x36, 0x76, 0xB6, 0xF6,
|
||||
0x0A, 0x4A, 0x8A, 0xCA, 0x1A, 0x5A, 0x9A, 0xDA,
|
||||
0x2A, 0x6A, 0xAA, 0xEA, 0x3A, 0x7A, 0xBA, 0xFA,
|
||||
0x0E, 0x4E, 0x8E, 0xCE, 0x1E, 0x5E, 0x9E, 0xDE,
|
||||
0x2E, 0x6E, 0xAE, 0xEE, 0x3E, 0x7E, 0xBE, 0xFE,
|
||||
0x03, 0x43, 0x83, 0xC3, 0x13, 0x53, 0x93, 0xD3,
|
||||
0x23, 0x63, 0xA3, 0xE3, 0x33, 0x73, 0xB3, 0xF3,
|
||||
0x07, 0x47, 0x87, 0xC7, 0x17, 0x57, 0x97, 0xD7,
|
||||
0x27, 0x67, 0xA7, 0xE7, 0x37, 0x77, 0xB7, 0xF7,
|
||||
0x0B, 0x4B, 0x8B, 0xCB, 0x1B, 0x5B, 0x9B, 0xDB,
|
||||
0x2B, 0x6B, 0xAB, 0xEB, 0x3B, 0x7B, 0xBB, 0xFB,
|
||||
0x0F, 0x4F, 0x8F, 0xCF, 0x1F, 0x5F, 0x9F, 0xDF,
|
||||
0x2F, 0x6F, 0xAF, 0xEF, 0x3F, 0x7F, 0xBF, 0xFF
|
||||
};
|
||||
|
||||
static png_byte fourbppswaptable[256] = {
|
||||
0x00, 0x10, 0x20, 0x30, 0x40, 0x50, 0x60, 0x70,
|
||||
0x80, 0x90, 0xA0, 0xB0, 0xC0, 0xD0, 0xE0, 0xF0,
|
||||
0x01, 0x11, 0x21, 0x31, 0x41, 0x51, 0x61, 0x71,
|
||||
0x81, 0x91, 0xA1, 0xB1, 0xC1, 0xD1, 0xE1, 0xF1,
|
||||
0x02, 0x12, 0x22, 0x32, 0x42, 0x52, 0x62, 0x72,
|
||||
0x82, 0x92, 0xA2, 0xB2, 0xC2, 0xD2, 0xE2, 0xF2,
|
||||
0x03, 0x13, 0x23, 0x33, 0x43, 0x53, 0x63, 0x73,
|
||||
0x83, 0x93, 0xA3, 0xB3, 0xC3, 0xD3, 0xE3, 0xF3,
|
||||
0x04, 0x14, 0x24, 0x34, 0x44, 0x54, 0x64, 0x74,
|
||||
0x84, 0x94, 0xA4, 0xB4, 0xC4, 0xD4, 0xE4, 0xF4,
|
||||
0x05, 0x15, 0x25, 0x35, 0x45, 0x55, 0x65, 0x75,
|
||||
0x85, 0x95, 0xA5, 0xB5, 0xC5, 0xD5, 0xE5, 0xF5,
|
||||
0x06, 0x16, 0x26, 0x36, 0x46, 0x56, 0x66, 0x76,
|
||||
0x86, 0x96, 0xA6, 0xB6, 0xC6, 0xD6, 0xE6, 0xF6,
|
||||
0x07, 0x17, 0x27, 0x37, 0x47, 0x57, 0x67, 0x77,
|
||||
0x87, 0x97, 0xA7, 0xB7, 0xC7, 0xD7, 0xE7, 0xF7,
|
||||
0x08, 0x18, 0x28, 0x38, 0x48, 0x58, 0x68, 0x78,
|
||||
0x88, 0x98, 0xA8, 0xB8, 0xC8, 0xD8, 0xE8, 0xF8,
|
||||
0x09, 0x19, 0x29, 0x39, 0x49, 0x59, 0x69, 0x79,
|
||||
0x89, 0x99, 0xA9, 0xB9, 0xC9, 0xD9, 0xE9, 0xF9,
|
||||
0x0A, 0x1A, 0x2A, 0x3A, 0x4A, 0x5A, 0x6A, 0x7A,
|
||||
0x8A, 0x9A, 0xAA, 0xBA, 0xCA, 0xDA, 0xEA, 0xFA,
|
||||
0x0B, 0x1B, 0x2B, 0x3B, 0x4B, 0x5B, 0x6B, 0x7B,
|
||||
0x8B, 0x9B, 0xAB, 0xBB, 0xCB, 0xDB, 0xEB, 0xFB,
|
||||
0x0C, 0x1C, 0x2C, 0x3C, 0x4C, 0x5C, 0x6C, 0x7C,
|
||||
0x8C, 0x9C, 0xAC, 0xBC, 0xCC, 0xDC, 0xEC, 0xFC,
|
||||
0x0D, 0x1D, 0x2D, 0x3D, 0x4D, 0x5D, 0x6D, 0x7D,
|
||||
0x8D, 0x9D, 0xAD, 0xBD, 0xCD, 0xDD, 0xED, 0xFD,
|
||||
0x0E, 0x1E, 0x2E, 0x3E, 0x4E, 0x5E, 0x6E, 0x7E,
|
||||
0x8E, 0x9E, 0xAE, 0xBE, 0xCE, 0xDE, 0xEE, 0xFE,
|
||||
0x0F, 0x1F, 0x2F, 0x3F, 0x4F, 0x5F, 0x6F, 0x7F,
|
||||
0x8F, 0x9F, 0xAF, 0xBF, 0xCF, 0xDF, 0xEF, 0xFF
|
||||
};
|
||||
|
||||
/* swaps pixel packing order within bytes */
|
||||
void /* PRIVATE */
|
||||
png_do_packswap(png_row_infop row_info, png_bytep row)
|
||||
{
|
||||
png_debug(1, "in png_do_packswap\n");
|
||||
if (
|
||||
#if defined(PNG_USELESS_TESTS_SUPPORTED)
|
||||
row != NULL && row_info != NULL &&
|
||||
#endif
|
||||
row_info->bit_depth < 8)
|
||||
{
|
||||
png_bytep rp, end, table;
|
||||
|
||||
end = row + row_info->rowbytes;
|
||||
|
||||
if (row_info->bit_depth == 1)
|
||||
table = onebppswaptable;
|
||||
else if (row_info->bit_depth == 2)
|
||||
table = twobppswaptable;
|
||||
else if (row_info->bit_depth == 4)
|
||||
table = fourbppswaptable;
|
||||
else
|
||||
return;
|
||||
|
||||
for (rp = row; rp < end; rp++)
|
||||
*rp = table[*rp];
|
||||
}
|
||||
}
|
||||
#endif /* PNG_READ_PACKSWAP_SUPPORTED or PNG_WRITE_PACKSWAP_SUPPORTED */
|
||||
|
||||
#if defined(PNG_WRITE_FILLER_SUPPORTED) || \
|
||||
defined(PNG_READ_STRIP_ALPHA_SUPPORTED)
|
||||
/* remove filler or alpha byte(s) */
|
||||
void /* PRIVATE */
|
||||
png_do_strip_filler(png_row_infop row_info, png_bytep row, png_uint_32 flags)
|
||||
{
|
||||
png_debug(1, "in png_do_strip_filler\n");
|
||||
#if defined(PNG_USELESS_TESTS_SUPPORTED)
|
||||
if (row != NULL && row_info != NULL)
|
||||
#endif
|
||||
{
|
||||
/*
|
||||
if (row_info->color_type == PNG_COLOR_TYPE_RGB ||
|
||||
row_info->color_type == PNG_COLOR_TYPE_RGB_ALPHA)
|
||||
*/
|
||||
png_bytep sp=row;
|
||||
png_bytep dp=row;
|
||||
png_uint_32 row_width=row_info->width;
|
||||
png_uint_32 i;
|
||||
|
||||
if (row_info->channels == 4)
|
||||
{
|
||||
if (row_info->bit_depth == 8)
|
||||
{
|
||||
/* This converts from RGBX or RGBA to RGB */
|
||||
if (flags & PNG_FLAG_FILLER_AFTER)
|
||||
{
|
||||
dp+=3; sp+=4;
|
||||
for (i = 1; i < row_width; i++)
|
||||
{
|
||||
*dp++ = *sp++;
|
||||
*dp++ = *sp++;
|
||||
*dp++ = *sp++;
|
||||
sp++;
|
||||
}
|
||||
}
|
||||
/* This converts from XRGB or ARGB to RGB */
|
||||
else
|
||||
{
|
||||
for (i = 0; i < row_width; i++)
|
||||
{
|
||||
sp++;
|
||||
*dp++ = *sp++;
|
||||
*dp++ = *sp++;
|
||||
*dp++ = *sp++;
|
||||
}
|
||||
}
|
||||
row_info->pixel_depth = 24;
|
||||
row_info->rowbytes = row_width * 3;
|
||||
}
|
||||
else /* if (row_info->bit_depth == 16) */
|
||||
{
|
||||
if (flags & PNG_FLAG_FILLER_AFTER)
|
||||
{
|
||||
/* This converts from RRGGBBXX or RRGGBBAA to RRGGBB */
|
||||
sp += 8; dp += 6;
|
||||
for (i = 1; i < row_width; i++)
|
||||
{
|
||||
/* This could be (although png_memcpy is probably slower):
|
||||
png_memcpy(dp, sp, 6);
|
||||
sp += 8;
|
||||
dp += 6;
|
||||
*/
|
||||
|
||||
*dp++ = *sp++;
|
||||
*dp++ = *sp++;
|
||||
*dp++ = *sp++;
|
||||
*dp++ = *sp++;
|
||||
*dp++ = *sp++;
|
||||
*dp++ = *sp++;
|
||||
sp += 2;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
/* This converts from XXRRGGBB or AARRGGBB to RRGGBB */
|
||||
for (i = 0; i < row_width; i++)
|
||||
{
|
||||
/* This could be (although png_memcpy is probably slower):
|
||||
png_memcpy(dp, sp, 6);
|
||||
sp += 8;
|
||||
dp += 6;
|
||||
*/
|
||||
|
||||
sp+=2;
|
||||
*dp++ = *sp++;
|
||||
*dp++ = *sp++;
|
||||
*dp++ = *sp++;
|
||||
*dp++ = *sp++;
|
||||
*dp++ = *sp++;
|
||||
*dp++ = *sp++;
|
||||
}
|
||||
}
|
||||
row_info->pixel_depth = 48;
|
||||
row_info->rowbytes = row_width * 6;
|
||||
}
|
||||
row_info->channels = 3;
|
||||
row_info->color_type &= ~PNG_COLOR_MASK_ALPHA;
|
||||
}
|
||||
/*
|
||||
else if (row_info->color_type == PNG_COLOR_TYPE_GRAY ||
|
||||
row_info->color_type == PNG_COLOR_TYPE_GRAY_ALPHA)
|
||||
*/
|
||||
else if (row_info->channels == 2)
|
||||
{
|
||||
if (row_info->bit_depth == 8)
|
||||
{
|
||||
/* This converts from GX or GA to G */
|
||||
if (flags & PNG_FLAG_FILLER_AFTER)
|
||||
{
|
||||
for (i = 0; i < row_width; i++)
|
||||
{
|
||||
*dp++ = *sp++;
|
||||
sp++;
|
||||
}
|
||||
}
|
||||
/* This converts from XG or AG to G */
|
||||
else
|
||||
{
|
||||
for (i = 0; i < row_width; i++)
|
||||
{
|
||||
sp++;
|
||||
*dp++ = *sp++;
|
||||
}
|
||||
}
|
||||
row_info->pixel_depth = 8;
|
||||
row_info->rowbytes = row_width;
|
||||
}
|
||||
else /* if (row_info->bit_depth == 16) */
|
||||
{
|
||||
if (flags & PNG_FLAG_FILLER_AFTER)
|
||||
{
|
||||
/* This converts from GGXX or GGAA to GG */
|
||||
sp += 4; dp += 2;
|
||||
for (i = 1; i < row_width; i++)
|
||||
{
|
||||
*dp++ = *sp++;
|
||||
*dp++ = *sp++;
|
||||
sp += 2;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
/* This converts from XXGG or AAGG to GG */
|
||||
for (i = 0; i < row_width; i++)
|
||||
{
|
||||
sp += 2;
|
||||
*dp++ = *sp++;
|
||||
*dp++ = *sp++;
|
||||
}
|
||||
}
|
||||
row_info->pixel_depth = 16;
|
||||
row_info->rowbytes = row_width * 2;
|
||||
}
|
||||
row_info->channels = 1;
|
||||
row_info->color_type &= ~PNG_COLOR_MASK_ALPHA;
|
||||
}
|
||||
}
|
||||
}
|
||||
#endif
|
||||
|
||||
#if defined(PNG_READ_BGR_SUPPORTED) || defined(PNG_WRITE_BGR_SUPPORTED)
|
||||
/* swaps red and blue bytes within a pixel */
|
||||
void /* PRIVATE */
|
||||
png_do_bgr(png_row_infop row_info, png_bytep row)
|
||||
{
|
||||
png_debug(1, "in png_do_bgr\n");
|
||||
if (
|
||||
#if defined(PNG_USELESS_TESTS_SUPPORTED)
|
||||
row != NULL && row_info != NULL &&
|
||||
#endif
|
||||
(row_info->color_type & PNG_COLOR_MASK_COLOR))
|
||||
{
|
||||
png_uint_32 row_width = row_info->width;
|
||||
if (row_info->bit_depth == 8)
|
||||
{
|
||||
if (row_info->color_type == PNG_COLOR_TYPE_RGB)
|
||||
{
|
||||
png_bytep rp;
|
||||
png_uint_32 i;
|
||||
|
||||
for (i = 0, rp = row; i < row_width; i++, rp += 3)
|
||||
{
|
||||
png_byte save = *rp;
|
||||
*rp = *(rp + 2);
|
||||
*(rp + 2) = save;
|
||||
}
|
||||
}
|
||||
else if (row_info->color_type == PNG_COLOR_TYPE_RGB_ALPHA)
|
||||
{
|
||||
png_bytep rp;
|
||||
png_uint_32 i;
|
||||
|
||||
for (i = 0, rp = row; i < row_width; i++, rp += 4)
|
||||
{
|
||||
png_byte save = *rp;
|
||||
*rp = *(rp + 2);
|
||||
*(rp + 2) = save;
|
||||
}
|
||||
}
|
||||
}
|
||||
else if (row_info->bit_depth == 16)
|
||||
{
|
||||
if (row_info->color_type == PNG_COLOR_TYPE_RGB)
|
||||
{
|
||||
png_bytep rp;
|
||||
png_uint_32 i;
|
||||
|
||||
for (i = 0, rp = row; i < row_width; i++, rp += 6)
|
||||
{
|
||||
png_byte save = *rp;
|
||||
*rp = *(rp + 4);
|
||||
*(rp + 4) = save;
|
||||
save = *(rp + 1);
|
||||
*(rp + 1) = *(rp + 5);
|
||||
*(rp + 5) = save;
|
||||
}
|
||||
}
|
||||
else if (row_info->color_type == PNG_COLOR_TYPE_RGB_ALPHA)
|
||||
{
|
||||
png_bytep rp;
|
||||
png_uint_32 i;
|
||||
|
||||
for (i = 0, rp = row; i < row_width; i++, rp += 8)
|
||||
{
|
||||
png_byte save = *rp;
|
||||
*rp = *(rp + 4);
|
||||
*(rp + 4) = save;
|
||||
save = *(rp + 1);
|
||||
*(rp + 1) = *(rp + 5);
|
||||
*(rp + 5) = save;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
#endif /* PNG_READ_BGR_SUPPORTED or PNG_WRITE_BGR_SUPPORTED */
|
||||
|
||||
#if defined(PNG_READ_USER_TRANSFORM_SUPPORTED) || \
|
||||
defined(PNG_WRITE_USER_TRANSFORM_SUPPORTED) || \
|
||||
defined(PNG_LEGACY_SUPPORTED)
|
||||
void PNGAPI
|
||||
png_set_user_transform_info(png_structp png_ptr, png_voidp
|
||||
user_transform_ptr, int user_transform_depth, int user_transform_channels)
|
||||
{
|
||||
png_debug(1, "in png_set_user_transform_info\n");
|
||||
#if defined(PNG_USER_TRANSFORM_PTR_SUPPORTED)
|
||||
png_ptr->user_transform_ptr = user_transform_ptr;
|
||||
png_ptr->user_transform_depth = (png_byte)user_transform_depth;
|
||||
png_ptr->user_transform_channels = (png_byte)user_transform_channels;
|
||||
#else
|
||||
if(user_transform_ptr || user_transform_depth || user_transform_channels)
|
||||
png_warning(png_ptr,
|
||||
"This version of libpng does not support user transform info");
|
||||
#endif
|
||||
}
|
||||
#endif
|
||||
|
||||
/* This function returns a pointer to the user_transform_ptr associated with
|
||||
* the user transform functions. The application should free any memory
|
||||
* associated with this pointer before png_write_destroy and png_read_destroy
|
||||
* are called.
|
||||
*/
|
||||
png_voidp PNGAPI
|
||||
png_get_user_transform_ptr(png_structp png_ptr)
|
||||
{
|
||||
#if defined(PNG_USER_TRANSFORM_PTR_SUPPORTED)
|
||||
return ((png_voidp)png_ptr->user_transform_ptr);
|
||||
#else
|
||||
if(png_ptr)
|
||||
return (NULL);
|
||||
return (NULL);
|
||||
#endif
|
||||
}
|
File diff suppressed because it is too large
Load Diff
|
@ -1,228 +0,0 @@
|
|||
|
||||
/* pngwio.c - functions for data output
|
||||
*
|
||||
* libpng 1.2.5 - October 3, 2002
|
||||
* For conditions of distribution and use, see copyright notice in png.h
|
||||
* Copyright (c) 1998-2002 Glenn Randers-Pehrson
|
||||
* (Version 0.96 Copyright (c) 1996, 1997 Andreas Dilger)
|
||||
* (Version 0.88 Copyright (c) 1995, 1996 Guy Eric Schalnat, Group 42, Inc.)
|
||||
*
|
||||
* This file provides a location for all output. Users who need
|
||||
* special handling are expected to write functions that have the same
|
||||
* arguments as these and perform similar functions, but that possibly
|
||||
* use different output methods. Note that you shouldn't change these
|
||||
* functions, but rather write replacement functions and then change
|
||||
* them at run time with png_set_write_fn(...).
|
||||
*/
|
||||
|
||||
#define PNG_INTERNAL
|
||||
#include "png.h"
|
||||
#ifdef PNG_WRITE_SUPPORTED
|
||||
|
||||
/* Write the data to whatever output you are using. The default routine
|
||||
writes to a file pointer. Note that this routine sometimes gets called
|
||||
with very small lengths, so you should implement some kind of simple
|
||||
buffering if you are using unbuffered writes. This should never be asked
|
||||
to write more than 64K on a 16 bit machine. */
|
||||
|
||||
void /* PRIVATE */
|
||||
png_write_data(png_structp png_ptr, png_bytep data, png_size_t length)
|
||||
{
|
||||
if (png_ptr->write_data_fn != NULL )
|
||||
(*(png_ptr->write_data_fn))(png_ptr, data, length);
|
||||
else
|
||||
png_error(png_ptr, "Call to NULL write function");
|
||||
}
|
||||
|
||||
#if !defined(PNG_NO_STDIO)
|
||||
/* This is the function that does the actual writing of data. If you are
|
||||
not writing to a standard C stream, you should create a replacement
|
||||
write_data function and use it at run time with png_set_write_fn(), rather
|
||||
than changing the library. */
|
||||
#ifndef USE_FAR_KEYWORD
|
||||
void PNGAPI
|
||||
png_default_write_data(png_structp png_ptr, png_bytep data, png_size_t length)
|
||||
{
|
||||
png_uint_32 check;
|
||||
|
||||
#if defined(_WIN32_WCE)
|
||||
if ( !WriteFile((HANDLE)(png_ptr->io_ptr), data, length, &check, NULL) )
|
||||
check = 0;
|
||||
#else
|
||||
check = fwrite(data, 1, length, (png_FILE_p)(png_ptr->io_ptr));
|
||||
#endif
|
||||
if (check != length)
|
||||
png_error(png_ptr, "Write Error");
|
||||
}
|
||||
#else
|
||||
/* this is the model-independent version. Since the standard I/O library
|
||||
can't handle far buffers in the medium and small models, we have to copy
|
||||
the data.
|
||||
*/
|
||||
|
||||
#define NEAR_BUF_SIZE 1024
|
||||
#define MIN(a,b) (a <= b ? a : b)
|
||||
|
||||
void PNGAPI
|
||||
png_default_write_data(png_structp png_ptr, png_bytep data, png_size_t length)
|
||||
{
|
||||
png_uint_32 check;
|
||||
png_byte *near_data; /* Needs to be "png_byte *" instead of "png_bytep" */
|
||||
png_FILE_p io_ptr;
|
||||
|
||||
/* Check if data really is near. If so, use usual code. */
|
||||
near_data = (png_byte *)CVT_PTR_NOCHECK(data);
|
||||
io_ptr = (png_FILE_p)CVT_PTR(png_ptr->io_ptr);
|
||||
if ((png_bytep)near_data == data)
|
||||
{
|
||||
#if defined(_WIN32_WCE)
|
||||
if ( !WriteFile(io_ptr, near_data, length, &check, NULL) )
|
||||
check = 0;
|
||||
#else
|
||||
check = fwrite(near_data, 1, length, io_ptr);
|
||||
#endif
|
||||
}
|
||||
else
|
||||
{
|
||||
png_byte buf[NEAR_BUF_SIZE];
|
||||
png_size_t written, remaining, err;
|
||||
check = 0;
|
||||
remaining = length;
|
||||
do
|
||||
{
|
||||
written = MIN(NEAR_BUF_SIZE, remaining);
|
||||
png_memcpy(buf, data, written); /* copy far buffer to near buffer */
|
||||
#if defined(_WIN32_WCE)
|
||||
if ( !WriteFile(io_ptr, buf, written, &err, NULL) )
|
||||
err = 0;
|
||||
#else
|
||||
err = fwrite(buf, 1, written, io_ptr);
|
||||
#endif
|
||||
if (err != written)
|
||||
break;
|
||||
else
|
||||
check += err;
|
||||
data += written;
|
||||
remaining -= written;
|
||||
}
|
||||
while (remaining != 0);
|
||||
}
|
||||
if (check != length)
|
||||
png_error(png_ptr, "Write Error");
|
||||
}
|
||||
|
||||
#endif
|
||||
#endif
|
||||
|
||||
/* This function is called to output any data pending writing (normally
|
||||
to disk). After png_flush is called, there should be no data pending
|
||||
writing in any buffers. */
|
||||
#if defined(PNG_WRITE_FLUSH_SUPPORTED)
|
||||
void /* PRIVATE */
|
||||
png_flush(png_structp png_ptr)
|
||||
{
|
||||
if (png_ptr->output_flush_fn != NULL)
|
||||
(*(png_ptr->output_flush_fn))(png_ptr);
|
||||
}
|
||||
|
||||
#if !defined(PNG_NO_STDIO)
|
||||
void PNGAPI
|
||||
png_default_flush(png_structp png_ptr)
|
||||
{
|
||||
#if !defined(_WIN32_WCE)
|
||||
png_FILE_p io_ptr;
|
||||
io_ptr = (png_FILE_p)CVT_PTR((png_ptr->io_ptr));
|
||||
if (io_ptr != NULL)
|
||||
fflush(io_ptr);
|
||||
#endif
|
||||
}
|
||||
#endif
|
||||
#endif
|
||||
|
||||
/* This function allows the application to supply new output functions for
|
||||
libpng if standard C streams aren't being used.
|
||||
|
||||
This function takes as its arguments:
|
||||
png_ptr - pointer to a png output data structure
|
||||
io_ptr - pointer to user supplied structure containing info about
|
||||
the output functions. May be NULL.
|
||||
write_data_fn - pointer to a new output function that takes as its
|
||||
arguments a pointer to a png_struct, a pointer to
|
||||
data to be written, and a 32-bit unsigned int that is
|
||||
the number of bytes to be written. The new write
|
||||
function should call png_error(png_ptr, "Error msg")
|
||||
to exit and output any fatal error messages.
|
||||
flush_data_fn - pointer to a new flush function that takes as its
|
||||
arguments a pointer to a png_struct. After a call to
|
||||
the flush function, there should be no data in any buffers
|
||||
or pending transmission. If the output method doesn't do
|
||||
any buffering of ouput, a function prototype must still be
|
||||
supplied although it doesn't have to do anything. If
|
||||
PNG_WRITE_FLUSH_SUPPORTED is not defined at libpng compile
|
||||
time, output_flush_fn will be ignored, although it must be
|
||||
supplied for compatibility. */
|
||||
void PNGAPI
|
||||
png_set_write_fn(png_structp png_ptr, png_voidp io_ptr,
|
||||
png_rw_ptr write_data_fn, png_flush_ptr output_flush_fn)
|
||||
{
|
||||
png_ptr->io_ptr = io_ptr;
|
||||
|
||||
#if !defined(PNG_NO_STDIO)
|
||||
if (write_data_fn != NULL)
|
||||
png_ptr->write_data_fn = write_data_fn;
|
||||
else
|
||||
png_ptr->write_data_fn = png_default_write_data;
|
||||
#else
|
||||
png_ptr->write_data_fn = write_data_fn;
|
||||
#endif
|
||||
|
||||
#if defined(PNG_WRITE_FLUSH_SUPPORTED)
|
||||
#if !defined(PNG_NO_STDIO)
|
||||
if (output_flush_fn != NULL)
|
||||
png_ptr->output_flush_fn = output_flush_fn;
|
||||
else
|
||||
png_ptr->output_flush_fn = png_default_flush;
|
||||
#else
|
||||
png_ptr->output_flush_fn = output_flush_fn;
|
||||
#endif
|
||||
#endif /* PNG_WRITE_FLUSH_SUPPORTED */
|
||||
|
||||
/* It is an error to read while writing a png file */
|
||||
if (png_ptr->read_data_fn != NULL)
|
||||
{
|
||||
png_ptr->read_data_fn = NULL;
|
||||
png_warning(png_ptr,
|
||||
"Attempted to set both read_data_fn and write_data_fn in");
|
||||
png_warning(png_ptr,
|
||||
"the same structure. Resetting read_data_fn to NULL.");
|
||||
}
|
||||
}
|
||||
|
||||
#if defined(USE_FAR_KEYWORD)
|
||||
#if defined(_MSC_VER)
|
||||
void *png_far_to_near(png_structp png_ptr,png_voidp ptr, int check)
|
||||
{
|
||||
void *near_ptr;
|
||||
void FAR *far_ptr;
|
||||
FP_OFF(near_ptr) = FP_OFF(ptr);
|
||||
far_ptr = (void FAR *)near_ptr;
|
||||
if(check != 0)
|
||||
if(FP_SEG(ptr) != FP_SEG(far_ptr))
|
||||
png_error(png_ptr,"segment lost in conversion");
|
||||
return(near_ptr);
|
||||
}
|
||||
# else
|
||||
void *png_far_to_near(png_structp png_ptr,png_voidp ptr, int check)
|
||||
{
|
||||
void *near_ptr;
|
||||
void FAR *far_ptr;
|
||||
near_ptr = (void FAR *)ptr;
|
||||
far_ptr = (void FAR *)near_ptr;
|
||||
if(check != 0)
|
||||
if(far_ptr != ptr)
|
||||
png_error(png_ptr,"segment lost in conversion");
|
||||
return(near_ptr);
|
||||
}
|
||||
# endif
|
||||
# endif
|
||||
#endif /* PNG_WRITE_SUPPORTED */
|
File diff suppressed because it is too large
Load Diff
|
@ -1,563 +0,0 @@
|
|||
|
||||
/* pngwtran.c - transforms the data in a row for PNG writers
|
||||
*
|
||||
* libpng 1.2.5 - October 3, 2002
|
||||
* For conditions of distribution and use, see copyright notice in png.h
|
||||
* Copyright (c) 1998-2002 Glenn Randers-Pehrson
|
||||
* (Version 0.96 Copyright (c) 1996, 1997 Andreas Dilger)
|
||||
* (Version 0.88 Copyright (c) 1995, 1996 Guy Eric Schalnat, Group 42, Inc.)
|
||||
*/
|
||||
|
||||
#define PNG_INTERNAL
|
||||
#include "png.h"
|
||||
#ifdef PNG_WRITE_SUPPORTED
|
||||
|
||||
/* Transform the data according to the user's wishes. The order of
|
||||
* transformations is significant.
|
||||
*/
|
||||
void /* PRIVATE */
|
||||
png_do_write_transformations(png_structp png_ptr)
|
||||
{
|
||||
png_debug(1, "in png_do_write_transformations\n");
|
||||
|
||||
if (png_ptr == NULL)
|
||||
return;
|
||||
|
||||
#if defined(PNG_WRITE_USER_TRANSFORM_SUPPORTED)
|
||||
if (png_ptr->transformations & PNG_USER_TRANSFORM)
|
||||
if(png_ptr->write_user_transform_fn != NULL)
|
||||
(*(png_ptr->write_user_transform_fn)) /* user write transform function */
|
||||
(png_ptr, /* png_ptr */
|
||||
&(png_ptr->row_info), /* row_info: */
|
||||
/* png_uint_32 width; width of row */
|
||||
/* png_uint_32 rowbytes; number of bytes in row */
|
||||
/* png_byte color_type; color type of pixels */
|
||||
/* png_byte bit_depth; bit depth of samples */
|
||||
/* png_byte channels; number of channels (1-4) */
|
||||
/* png_byte pixel_depth; bits per pixel (depth*channels) */
|
||||
png_ptr->row_buf + 1); /* start of pixel data for row */
|
||||
#endif
|
||||
#if defined(PNG_WRITE_FILLER_SUPPORTED)
|
||||
if (png_ptr->transformations & PNG_FILLER)
|
||||
png_do_strip_filler(&(png_ptr->row_info), png_ptr->row_buf + 1,
|
||||
png_ptr->flags);
|
||||
#endif
|
||||
#if defined(PNG_WRITE_PACKSWAP_SUPPORTED)
|
||||
if (png_ptr->transformations & PNG_PACKSWAP)
|
||||
png_do_packswap(&(png_ptr->row_info), png_ptr->row_buf + 1);
|
||||
#endif
|
||||
#if defined(PNG_WRITE_PACK_SUPPORTED)
|
||||
if (png_ptr->transformations & PNG_PACK)
|
||||
png_do_pack(&(png_ptr->row_info), png_ptr->row_buf + 1,
|
||||
(png_uint_32)png_ptr->bit_depth);
|
||||
#endif
|
||||
#if defined(PNG_WRITE_SWAP_SUPPORTED)
|
||||
if (png_ptr->transformations & PNG_SWAP_BYTES)
|
||||
png_do_swap(&(png_ptr->row_info), png_ptr->row_buf + 1);
|
||||
#endif
|
||||
#if defined(PNG_WRITE_SHIFT_SUPPORTED)
|
||||
if (png_ptr->transformations & PNG_SHIFT)
|
||||
png_do_shift(&(png_ptr->row_info), png_ptr->row_buf + 1,
|
||||
&(png_ptr->shift));
|
||||
#endif
|
||||
#if defined(PNG_WRITE_INVERT_ALPHA_SUPPORTED)
|
||||
if (png_ptr->transformations & PNG_INVERT_ALPHA)
|
||||
png_do_write_invert_alpha(&(png_ptr->row_info), png_ptr->row_buf + 1);
|
||||
#endif
|
||||
#if defined(PNG_WRITE_SWAP_ALPHA_SUPPORTED)
|
||||
if (png_ptr->transformations & PNG_SWAP_ALPHA)
|
||||
png_do_write_swap_alpha(&(png_ptr->row_info), png_ptr->row_buf + 1);
|
||||
#endif
|
||||
#if defined(PNG_WRITE_BGR_SUPPORTED)
|
||||
if (png_ptr->transformations & PNG_BGR)
|
||||
png_do_bgr(&(png_ptr->row_info), png_ptr->row_buf + 1);
|
||||
#endif
|
||||
#if defined(PNG_WRITE_INVERT_SUPPORTED)
|
||||
if (png_ptr->transformations & PNG_INVERT_MONO)
|
||||
png_do_invert(&(png_ptr->row_info), png_ptr->row_buf + 1);
|
||||
#endif
|
||||
}
|
||||
|
||||
#if defined(PNG_WRITE_PACK_SUPPORTED)
|
||||
/* Pack pixels into bytes. Pass the true bit depth in bit_depth. The
|
||||
* row_info bit depth should be 8 (one pixel per byte). The channels
|
||||
* should be 1 (this only happens on grayscale and paletted images).
|
||||
*/
|
||||
void /* PRIVATE */
|
||||
png_do_pack(png_row_infop row_info, png_bytep row, png_uint_32 bit_depth)
|
||||
{
|
||||
png_debug(1, "in png_do_pack\n");
|
||||
if (row_info->bit_depth == 8 &&
|
||||
#if defined(PNG_USELESS_TESTS_SUPPORTED)
|
||||
row != NULL && row_info != NULL &&
|
||||
#endif
|
||||
row_info->channels == 1)
|
||||
{
|
||||
switch ((int)bit_depth)
|
||||
{
|
||||
case 1:
|
||||
{
|
||||
png_bytep sp, dp;
|
||||
int mask, v;
|
||||
png_uint_32 i;
|
||||
png_uint_32 row_width = row_info->width;
|
||||
|
||||
sp = row;
|
||||
dp = row;
|
||||
mask = 0x80;
|
||||
v = 0;
|
||||
|
||||
for (i = 0; i < row_width; i++)
|
||||
{
|
||||
if (*sp != 0)
|
||||
v |= mask;
|
||||
sp++;
|
||||
if (mask > 1)
|
||||
mask >>= 1;
|
||||
else
|
||||
{
|
||||
mask = 0x80;
|
||||
*dp = (png_byte)v;
|
||||
dp++;
|
||||
v = 0;
|
||||
}
|
||||
}
|
||||
if (mask != 0x80)
|
||||
*dp = (png_byte)v;
|
||||
break;
|
||||
}
|
||||
case 2:
|
||||
{
|
||||
png_bytep sp, dp;
|
||||
int shift, v;
|
||||
png_uint_32 i;
|
||||
png_uint_32 row_width = row_info->width;
|
||||
|
||||
sp = row;
|
||||
dp = row;
|
||||
shift = 6;
|
||||
v = 0;
|
||||
for (i = 0; i < row_width; i++)
|
||||
{
|
||||
png_byte value;
|
||||
|
||||
value = (png_byte)(*sp & 0x03);
|
||||
v |= (value << shift);
|
||||
if (shift == 0)
|
||||
{
|
||||
shift = 6;
|
||||
*dp = (png_byte)v;
|
||||
dp++;
|
||||
v = 0;
|
||||
}
|
||||
else
|
||||
shift -= 2;
|
||||
sp++;
|
||||
}
|
||||
if (shift != 6)
|
||||
*dp = (png_byte)v;
|
||||
break;
|
||||
}
|
||||
case 4:
|
||||
{
|
||||
png_bytep sp, dp;
|
||||
int shift, v;
|
||||
png_uint_32 i;
|
||||
png_uint_32 row_width = row_info->width;
|
||||
|
||||
sp = row;
|
||||
dp = row;
|
||||
shift = 4;
|
||||
v = 0;
|
||||
for (i = 0; i < row_width; i++)
|
||||
{
|
||||
png_byte value;
|
||||
|
||||
value = (png_byte)(*sp & 0x0f);
|
||||
v |= (value << shift);
|
||||
|
||||
if (shift == 0)
|
||||
{
|
||||
shift = 4;
|
||||
*dp = (png_byte)v;
|
||||
dp++;
|
||||
v = 0;
|
||||
}
|
||||
else
|
||||
shift -= 4;
|
||||
|
||||
sp++;
|
||||
}
|
||||
if (shift != 4)
|
||||
*dp = (png_byte)v;
|
||||
break;
|
||||
}
|
||||
}
|
||||
row_info->bit_depth = (png_byte)bit_depth;
|
||||
row_info->pixel_depth = (png_byte)(bit_depth * row_info->channels);
|
||||
row_info->rowbytes =
|
||||
((row_info->width * row_info->pixel_depth + 7) >> 3);
|
||||
}
|
||||
}
|
||||
#endif
|
||||
|
||||
#if defined(PNG_WRITE_SHIFT_SUPPORTED)
|
||||
/* Shift pixel values to take advantage of whole range. Pass the
|
||||
* true number of bits in bit_depth. The row should be packed
|
||||
* according to row_info->bit_depth. Thus, if you had a row of
|
||||
* bit depth 4, but the pixels only had values from 0 to 7, you
|
||||
* would pass 3 as bit_depth, and this routine would translate the
|
||||
* data to 0 to 15.
|
||||
*/
|
||||
void /* PRIVATE */
|
||||
png_do_shift(png_row_infop row_info, png_bytep row, png_color_8p bit_depth)
|
||||
{
|
||||
png_debug(1, "in png_do_shift\n");
|
||||
#if defined(PNG_USELESS_TESTS_SUPPORTED)
|
||||
if (row != NULL && row_info != NULL &&
|
||||
#else
|
||||
if (
|
||||
#endif
|
||||
row_info->color_type != PNG_COLOR_TYPE_PALETTE)
|
||||
{
|
||||
int shift_start[4], shift_dec[4];
|
||||
int channels = 0;
|
||||
|
||||
if (row_info->color_type & PNG_COLOR_MASK_COLOR)
|
||||
{
|
||||
shift_start[channels] = row_info->bit_depth - bit_depth->red;
|
||||
shift_dec[channels] = bit_depth->red;
|
||||
channels++;
|
||||
shift_start[channels] = row_info->bit_depth - bit_depth->green;
|
||||
shift_dec[channels] = bit_depth->green;
|
||||
channels++;
|
||||
shift_start[channels] = row_info->bit_depth - bit_depth->blue;
|
||||
shift_dec[channels] = bit_depth->blue;
|
||||
channels++;
|
||||
}
|
||||
else
|
||||
{
|
||||
shift_start[channels] = row_info->bit_depth - bit_depth->gray;
|
||||
shift_dec[channels] = bit_depth->gray;
|
||||
channels++;
|
||||
}
|
||||
if (row_info->color_type & PNG_COLOR_MASK_ALPHA)
|
||||
{
|
||||
shift_start[channels] = row_info->bit_depth - bit_depth->alpha;
|
||||
shift_dec[channels] = bit_depth->alpha;
|
||||
channels++;
|
||||
}
|
||||
|
||||
/* with low row depths, could only be grayscale, so one channel */
|
||||
if (row_info->bit_depth < 8)
|
||||
{
|
||||
png_bytep bp = row;
|
||||
png_uint_32 i;
|
||||
png_byte mask;
|
||||
png_uint_32 row_bytes = row_info->rowbytes;
|
||||
|
||||
if (bit_depth->gray == 1 && row_info->bit_depth == 2)
|
||||
mask = 0x55;
|
||||
else if (row_info->bit_depth == 4 && bit_depth->gray == 3)
|
||||
mask = 0x11;
|
||||
else
|
||||
mask = 0xff;
|
||||
|
||||
for (i = 0; i < row_bytes; i++, bp++)
|
||||
{
|
||||
png_uint_16 v;
|
||||
int j;
|
||||
|
||||
v = *bp;
|
||||
*bp = 0;
|
||||
for (j = shift_start[0]; j > -shift_dec[0]; j -= shift_dec[0])
|
||||
{
|
||||
if (j > 0)
|
||||
*bp |= (png_byte)((v << j) & 0xff);
|
||||
else
|
||||
*bp |= (png_byte)((v >> (-j)) & mask);
|
||||
}
|
||||
}
|
||||
}
|
||||
else if (row_info->bit_depth == 8)
|
||||
{
|
||||
png_bytep bp = row;
|
||||
png_uint_32 i;
|
||||
png_uint_32 istop = channels * row_info->width;
|
||||
|
||||
for (i = 0; i < istop; i++, bp++)
|
||||
{
|
||||
|
||||
png_uint_16 v;
|
||||
int j;
|
||||
int c = (int)(i%channels);
|
||||
|
||||
v = *bp;
|
||||
*bp = 0;
|
||||
for (j = shift_start[c]; j > -shift_dec[c]; j -= shift_dec[c])
|
||||
{
|
||||
if (j > 0)
|
||||
*bp |= (png_byte)((v << j) & 0xff);
|
||||
else
|
||||
*bp |= (png_byte)((v >> (-j)) & 0xff);
|
||||
}
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
png_bytep bp;
|
||||
png_uint_32 i;
|
||||
png_uint_32 istop = channels * row_info->width;
|
||||
|
||||
for (bp = row, i = 0; i < istop; i++)
|
||||
{
|
||||
int c = (int)(i%channels);
|
||||
png_uint_16 value, v;
|
||||
int j;
|
||||
|
||||
v = (png_uint_16)(((png_uint_16)(*bp) << 8) + *(bp + 1));
|
||||
value = 0;
|
||||
for (j = shift_start[c]; j > -shift_dec[c]; j -= shift_dec[c])
|
||||
{
|
||||
if (j > 0)
|
||||
value |= (png_uint_16)((v << j) & (png_uint_16)0xffff);
|
||||
else
|
||||
value |= (png_uint_16)((v >> (-j)) & (png_uint_16)0xffff);
|
||||
}
|
||||
*bp++ = (png_byte)(value >> 8);
|
||||
*bp++ = (png_byte)(value & 0xff);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
#endif
|
||||
|
||||
#if defined(PNG_WRITE_SWAP_ALPHA_SUPPORTED)
|
||||
void /* PRIVATE */
|
||||
png_do_write_swap_alpha(png_row_infop row_info, png_bytep row)
|
||||
{
|
||||
png_debug(1, "in png_do_write_swap_alpha\n");
|
||||
#if defined(PNG_USELESS_TESTS_SUPPORTED)
|
||||
if (row != NULL && row_info != NULL)
|
||||
#endif
|
||||
{
|
||||
if (row_info->color_type == PNG_COLOR_TYPE_RGB_ALPHA)
|
||||
{
|
||||
/* This converts from ARGB to RGBA */
|
||||
if (row_info->bit_depth == 8)
|
||||
{
|
||||
png_bytep sp, dp;
|
||||
png_uint_32 i;
|
||||
png_uint_32 row_width = row_info->width;
|
||||
for (i = 0, sp = dp = row; i < row_width; i++)
|
||||
{
|
||||
png_byte save = *(sp++);
|
||||
*(dp++) = *(sp++);
|
||||
*(dp++) = *(sp++);
|
||||
*(dp++) = *(sp++);
|
||||
*(dp++) = save;
|
||||
}
|
||||
}
|
||||
/* This converts from AARRGGBB to RRGGBBAA */
|
||||
else
|
||||
{
|
||||
png_bytep sp, dp;
|
||||
png_uint_32 i;
|
||||
png_uint_32 row_width = row_info->width;
|
||||
|
||||
for (i = 0, sp = dp = row; i < row_width; i++)
|
||||
{
|
||||
png_byte save[2];
|
||||
save[0] = *(sp++);
|
||||
save[1] = *(sp++);
|
||||
*(dp++) = *(sp++);
|
||||
*(dp++) = *(sp++);
|
||||
*(dp++) = *(sp++);
|
||||
*(dp++) = *(sp++);
|
||||
*(dp++) = *(sp++);
|
||||
*(dp++) = *(sp++);
|
||||
*(dp++) = save[0];
|
||||
*(dp++) = save[1];
|
||||
}
|
||||
}
|
||||
}
|
||||
else if (row_info->color_type == PNG_COLOR_TYPE_GRAY_ALPHA)
|
||||
{
|
||||
/* This converts from AG to GA */
|
||||
if (row_info->bit_depth == 8)
|
||||
{
|
||||
png_bytep sp, dp;
|
||||
png_uint_32 i;
|
||||
png_uint_32 row_width = row_info->width;
|
||||
|
||||
for (i = 0, sp = dp = row; i < row_width; i++)
|
||||
{
|
||||
png_byte save = *(sp++);
|
||||
*(dp++) = *(sp++);
|
||||
*(dp++) = save;
|
||||
}
|
||||
}
|
||||
/* This converts from AAGG to GGAA */
|
||||
else
|
||||
{
|
||||
png_bytep sp, dp;
|
||||
png_uint_32 i;
|
||||
png_uint_32 row_width = row_info->width;
|
||||
|
||||
for (i = 0, sp = dp = row; i < row_width; i++)
|
||||
{
|
||||
png_byte save[2];
|
||||
save[0] = *(sp++);
|
||||
save[1] = *(sp++);
|
||||
*(dp++) = *(sp++);
|
||||
*(dp++) = *(sp++);
|
||||
*(dp++) = save[0];
|
||||
*(dp++) = save[1];
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
#endif
|
||||
|
||||
#if defined(PNG_WRITE_INVERT_ALPHA_SUPPORTED)
|
||||
void /* PRIVATE */
|
||||
png_do_write_invert_alpha(png_row_infop row_info, png_bytep row)
|
||||
{
|
||||
png_debug(1, "in png_do_write_invert_alpha\n");
|
||||
#if defined(PNG_USELESS_TESTS_SUPPORTED)
|
||||
if (row != NULL && row_info != NULL)
|
||||
#endif
|
||||
{
|
||||
if (row_info->color_type == PNG_COLOR_TYPE_RGB_ALPHA)
|
||||
{
|
||||
/* This inverts the alpha channel in RGBA */
|
||||
if (row_info->bit_depth == 8)
|
||||
{
|
||||
png_bytep sp, dp;
|
||||
png_uint_32 i;
|
||||
png_uint_32 row_width = row_info->width;
|
||||
for (i = 0, sp = dp = row; i < row_width; i++)
|
||||
{
|
||||
*(dp++) = *(sp++);
|
||||
*(dp++) = *(sp++);
|
||||
*(dp++) = *(sp++);
|
||||
*(dp++) = (png_byte)(255 - *(sp++));
|
||||
}
|
||||
}
|
||||
/* This inverts the alpha channel in RRGGBBAA */
|
||||
else
|
||||
{
|
||||
png_bytep sp, dp;
|
||||
png_uint_32 i;
|
||||
png_uint_32 row_width = row_info->width;
|
||||
|
||||
for (i = 0, sp = dp = row; i < row_width; i++)
|
||||
{
|
||||
*(dp++) = *(sp++);
|
||||
*(dp++) = *(sp++);
|
||||
*(dp++) = *(sp++);
|
||||
*(dp++) = *(sp++);
|
||||
*(dp++) = *(sp++);
|
||||
*(dp++) = *(sp++);
|
||||
*(dp++) = (png_byte)(255 - *(sp++));
|
||||
*(dp++) = (png_byte)(255 - *(sp++));
|
||||
}
|
||||
}
|
||||
}
|
||||
else if (row_info->color_type == PNG_COLOR_TYPE_GRAY_ALPHA)
|
||||
{
|
||||
/* This inverts the alpha channel in GA */
|
||||
if (row_info->bit_depth == 8)
|
||||
{
|
||||
png_bytep sp, dp;
|
||||
png_uint_32 i;
|
||||
png_uint_32 row_width = row_info->width;
|
||||
|
||||
for (i = 0, sp = dp = row; i < row_width; i++)
|
||||
{
|
||||
*(dp++) = *(sp++);
|
||||
*(dp++) = (png_byte)(255 - *(sp++));
|
||||
}
|
||||
}
|
||||
/* This inverts the alpha channel in GGAA */
|
||||
else
|
||||
{
|
||||
png_bytep sp, dp;
|
||||
png_uint_32 i;
|
||||
png_uint_32 row_width = row_info->width;
|
||||
|
||||
for (i = 0, sp = dp = row; i < row_width; i++)
|
||||
{
|
||||
*(dp++) = *(sp++);
|
||||
*(dp++) = *(sp++);
|
||||
*(dp++) = (png_byte)(255 - *(sp++));
|
||||
*(dp++) = (png_byte)(255 - *(sp++));
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
#endif
|
||||
|
||||
#if defined(PNG_MNG_FEATURES_SUPPORTED)
|
||||
/* undoes intrapixel differencing */
|
||||
void /* PRIVATE */
|
||||
png_do_write_intrapixel(png_row_infop row_info, png_bytep row)
|
||||
{
|
||||
png_debug(1, "in png_do_write_intrapixel\n");
|
||||
if (
|
||||
#if defined(PNG_USELESS_TESTS_SUPPORTED)
|
||||
row != NULL && row_info != NULL &&
|
||||
#endif
|
||||
(row_info->color_type & PNG_COLOR_MASK_COLOR))
|
||||
{
|
||||
int bytes_per_pixel;
|
||||
png_uint_32 row_width = row_info->width;
|
||||
if (row_info->bit_depth == 8)
|
||||
{
|
||||
png_bytep rp;
|
||||
png_uint_32 i;
|
||||
|
||||
if (row_info->color_type == PNG_COLOR_TYPE_RGB)
|
||||
bytes_per_pixel = 3;
|
||||
else if (row_info->color_type == PNG_COLOR_TYPE_RGB_ALPHA)
|
||||
bytes_per_pixel = 4;
|
||||
else
|
||||
return;
|
||||
|
||||
for (i = 0, rp = row; i < row_width; i++, rp += bytes_per_pixel)
|
||||
{
|
||||
*(rp) = (png_byte)((*rp - *(rp+1))&0xff);
|
||||
*(rp+2) = (png_byte)((*(rp+2) - *(rp+1))&0xff);
|
||||
}
|
||||
}
|
||||
else if (row_info->bit_depth == 16)
|
||||
{
|
||||
png_bytep rp;
|
||||
png_uint_32 i;
|
||||
|
||||
if (row_info->color_type == PNG_COLOR_TYPE_RGB)
|
||||
bytes_per_pixel = 6;
|
||||
else if (row_info->color_type == PNG_COLOR_TYPE_RGB_ALPHA)
|
||||
bytes_per_pixel = 8;
|
||||
else
|
||||
return;
|
||||
|
||||
for (i = 0, rp = row; i < row_width; i++, rp += bytes_per_pixel)
|
||||
{
|
||||
png_uint_32 s0=*(rp )<<8 | *(rp+1);
|
||||
png_uint_32 s1=*(rp+2)<<8 | *(rp+3);
|
||||
png_uint_32 s2=*(rp+4)<<8 | *(rp+5);
|
||||
png_uint_32 red=(s0-s1)&0xffff;
|
||||
png_uint_32 blue=(s2-s1)&0xffff;
|
||||
*(rp ) = (png_byte)((red>>8)&0xff);
|
||||
*(rp+1) = (png_byte)(red&0xff);
|
||||
*(rp+4) = (png_byte)((blue>>8)&0xff);
|
||||
*(rp+5) = (png_byte)(blue&0xff);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
#endif /* PNG_MNG_FEATURES_SUPPORTED */
|
||||
#endif /* PNG_WRITE_SUPPORTED */
|
File diff suppressed because it is too large
Load Diff
|
@ -1,70 +0,0 @@
|
|||
/*
|
||||
* These definitions are for the Postscript (ps.c) and
|
||||
* Postscript/LaTeX (pstex.c) drivers
|
||||
*/
|
||||
|
||||
#ifndef __PS_H__
|
||||
#define __PS_H__
|
||||
|
||||
/* top level declarations */
|
||||
|
||||
#define LINELENGTH 78
|
||||
#define COPIES 1
|
||||
#define XSIZE 540 /* 7.5 x 10 [inches] */
|
||||
#define YSIZE 720 /* (72 points = 1 inch) */
|
||||
#define ENLARGE 5
|
||||
#define XPSSIZE ENLARGE*XSIZE
|
||||
#define YPSSIZE ENLARGE*YSIZE
|
||||
#define XOFFSET 32 /* Margins -- */
|
||||
#define YOFFSET 32 /* .5 inches each */
|
||||
#define PSX XPSSIZE-1
|
||||
#define PSY YPSSIZE-1
|
||||
#define OF pls->OutFile
|
||||
#define MIN_WIDTH 1 /* Minimum pen width */
|
||||
#define MAX_WIDTH 30 /* Maximum pen width */
|
||||
#define DEF_WIDTH 3 /* Default pen width */
|
||||
|
||||
/* These are for covering the page with the background color */
|
||||
|
||||
#define XMIN -XOFFSET*ENLARGE
|
||||
#define XMAX PSX+XOFFSET*ENLARGE
|
||||
#define YMIN -XOFFSET*ENLARGE
|
||||
#define YMAX PSY+XOFFSET*ENLARGE
|
||||
|
||||
/* Struct to hold device-specific info. */
|
||||
|
||||
typedef struct {
|
||||
PLFLT pxlx, pxly;
|
||||
PLINT xold, yold;
|
||||
|
||||
PLINT xmin, xmax, xlen;
|
||||
PLINT ymin, ymax, ylen;
|
||||
|
||||
PLINT xmin_dev, xmax_dev, xlen_dev;
|
||||
PLINT ymin_dev, ymax_dev, ylen_dev;
|
||||
|
||||
PLFLT xscale_dev, yscale_dev;
|
||||
|
||||
int llx, lly, urx, ury, ptcnt;
|
||||
} PSDev;
|
||||
|
||||
void plD_init_pstex (PLStream *);
|
||||
void plD_line_pstex (PLStream *, short, short, short, short);
|
||||
void plD_polyline_pstex (PLStream *, short *, short *, PLINT);
|
||||
void plD_eop_pstex (PLStream *);
|
||||
void plD_bop_pstex (PLStream *);
|
||||
void plD_tidy_pstex (PLStream *);
|
||||
void plD_state_pstex (PLStream *, PLINT);
|
||||
void plD_esc_pstex (PLStream *, PLINT, void *);
|
||||
|
||||
void plD_init_psm (PLStream *);
|
||||
void plD_init_psc (PLStream *);
|
||||
void plD_line_ps (PLStream *, short, short, short, short);
|
||||
void plD_polyline_ps (PLStream *, short *, short *, PLINT);
|
||||
void plD_eop_ps (PLStream *);
|
||||
void plD_bop_ps (PLStream *);
|
||||
void plD_tidy_ps (PLStream *);
|
||||
void plD_state_ps (PLStream *, PLINT);
|
||||
void plD_esc_ps (PLStream *, PLINT, void *);
|
||||
|
||||
#endif /* __PS_H__ */
|
|
@ -1,24 +0,0 @@
|
|||
//{{NO_DEPENDENCIES}}
|
||||
// Microsoft Developer Studio generated include file.
|
||||
// Used by plplot.rc
|
||||
//
|
||||
#define IDR_MENU1 101
|
||||
#define IDI_ICON1 102
|
||||
#define PLCOMMANDS 106
|
||||
#define PLICON 107
|
||||
#define CM_NEXTPLOT 40002
|
||||
#define CM_PRINTPLOT 40003
|
||||
#define CM_EDITCOPY 40004
|
||||
#define CM_ABOUT 40005
|
||||
|
||||
// Next default values for new objects
|
||||
//
|
||||
#ifdef APSTUDIO_INVOKED
|
||||
#ifndef APSTUDIO_READONLY_SYMBOLS
|
||||
#define _APS_NO_MFC 1
|
||||
#define _APS_NEXT_RESOURCE_VALUE 108
|
||||
#define _APS_NEXT_COMMAND_VALUE 40006
|
||||
#define _APS_NEXT_CONTROL_VALUE 1000
|
||||
#define _APS_NEXT_SYMED_VALUE 101
|
||||
#endif
|
||||
#endif
|
File diff suppressed because it is too large
Load Diff
|
@ -1,128 +0,0 @@
|
|||
/* header created automatically with -DGEN_TREES_H */
|
||||
|
||||
local const ct_data static_ltree[L_CODES+2] = {
|
||||
{{ 12},{ 8}}, {{140},{ 8}}, {{ 76},{ 8}}, {{204},{ 8}}, {{ 44},{ 8}},
|
||||
{{172},{ 8}}, {{108},{ 8}}, {{236},{ 8}}, {{ 28},{ 8}}, {{156},{ 8}},
|
||||
{{ 92},{ 8}}, {{220},{ 8}}, {{ 60},{ 8}}, {{188},{ 8}}, {{124},{ 8}},
|
||||
{{252},{ 8}}, {{ 2},{ 8}}, {{130},{ 8}}, {{ 66},{ 8}}, {{194},{ 8}},
|
||||
{{ 34},{ 8}}, {{162},{ 8}}, {{ 98},{ 8}}, {{226},{ 8}}, {{ 18},{ 8}},
|
||||
{{146},{ 8}}, {{ 82},{ 8}}, {{210},{ 8}}, {{ 50},{ 8}}, {{178},{ 8}},
|
||||
{{114},{ 8}}, {{242},{ 8}}, {{ 10},{ 8}}, {{138},{ 8}}, {{ 74},{ 8}},
|
||||
{{202},{ 8}}, {{ 42},{ 8}}, {{170},{ 8}}, {{106},{ 8}}, {{234},{ 8}},
|
||||
{{ 26},{ 8}}, {{154},{ 8}}, {{ 90},{ 8}}, {{218},{ 8}}, {{ 58},{ 8}},
|
||||
{{186},{ 8}}, {{122},{ 8}}, {{250},{ 8}}, {{ 6},{ 8}}, {{134},{ 8}},
|
||||
{{ 70},{ 8}}, {{198},{ 8}}, {{ 38},{ 8}}, {{166},{ 8}}, {{102},{ 8}},
|
||||
{{230},{ 8}}, {{ 22},{ 8}}, {{150},{ 8}}, {{ 86},{ 8}}, {{214},{ 8}},
|
||||
{{ 54},{ 8}}, {{182},{ 8}}, {{118},{ 8}}, {{246},{ 8}}, {{ 14},{ 8}},
|
||||
{{142},{ 8}}, {{ 78},{ 8}}, {{206},{ 8}}, {{ 46},{ 8}}, {{174},{ 8}},
|
||||
{{110},{ 8}}, {{238},{ 8}}, {{ 30},{ 8}}, {{158},{ 8}}, {{ 94},{ 8}},
|
||||
{{222},{ 8}}, {{ 62},{ 8}}, {{190},{ 8}}, {{126},{ 8}}, {{254},{ 8}},
|
||||
{{ 1},{ 8}}, {{129},{ 8}}, {{ 65},{ 8}}, {{193},{ 8}}, {{ 33},{ 8}},
|
||||
{{161},{ 8}}, {{ 97},{ 8}}, {{225},{ 8}}, {{ 17},{ 8}}, {{145},{ 8}},
|
||||
{{ 81},{ 8}}, {{209},{ 8}}, {{ 49},{ 8}}, {{177},{ 8}}, {{113},{ 8}},
|
||||
{{241},{ 8}}, {{ 9},{ 8}}, {{137},{ 8}}, {{ 73},{ 8}}, {{201},{ 8}},
|
||||
{{ 41},{ 8}}, {{169},{ 8}}, {{105},{ 8}}, {{233},{ 8}}, {{ 25},{ 8}},
|
||||
{{153},{ 8}}, {{ 89},{ 8}}, {{217},{ 8}}, {{ 57},{ 8}}, {{185},{ 8}},
|
||||
{{121},{ 8}}, {{249},{ 8}}, {{ 5},{ 8}}, {{133},{ 8}}, {{ 69},{ 8}},
|
||||
{{197},{ 8}}, {{ 37},{ 8}}, {{165},{ 8}}, {{101},{ 8}}, {{229},{ 8}},
|
||||
{{ 21},{ 8}}, {{149},{ 8}}, {{ 85},{ 8}}, {{213},{ 8}}, {{ 53},{ 8}},
|
||||
{{181},{ 8}}, {{117},{ 8}}, {{245},{ 8}}, {{ 13},{ 8}}, {{141},{ 8}},
|
||||
{{ 77},{ 8}}, {{205},{ 8}}, {{ 45},{ 8}}, {{173},{ 8}}, {{109},{ 8}},
|
||||
{{237},{ 8}}, {{ 29},{ 8}}, {{157},{ 8}}, {{ 93},{ 8}}, {{221},{ 8}},
|
||||
{{ 61},{ 8}}, {{189},{ 8}}, {{125},{ 8}}, {{253},{ 8}}, {{ 19},{ 9}},
|
||||
{{275},{ 9}}, {{147},{ 9}}, {{403},{ 9}}, {{ 83},{ 9}}, {{339},{ 9}},
|
||||
{{211},{ 9}}, {{467},{ 9}}, {{ 51},{ 9}}, {{307},{ 9}}, {{179},{ 9}},
|
||||
{{435},{ 9}}, {{115},{ 9}}, {{371},{ 9}}, {{243},{ 9}}, {{499},{ 9}},
|
||||
{{ 11},{ 9}}, {{267},{ 9}}, {{139},{ 9}}, {{395},{ 9}}, {{ 75},{ 9}},
|
||||
{{331},{ 9}}, {{203},{ 9}}, {{459},{ 9}}, {{ 43},{ 9}}, {{299},{ 9}},
|
||||
{{171},{ 9}}, {{427},{ 9}}, {{107},{ 9}}, {{363},{ 9}}, {{235},{ 9}},
|
||||
{{491},{ 9}}, {{ 27},{ 9}}, {{283},{ 9}}, {{155},{ 9}}, {{411},{ 9}},
|
||||
{{ 91},{ 9}}, {{347},{ 9}}, {{219},{ 9}}, {{475},{ 9}}, {{ 59},{ 9}},
|
||||
{{315},{ 9}}, {{187},{ 9}}, {{443},{ 9}}, {{123},{ 9}}, {{379},{ 9}},
|
||||
{{251},{ 9}}, {{507},{ 9}}, {{ 7},{ 9}}, {{263},{ 9}}, {{135},{ 9}},
|
||||
{{391},{ 9}}, {{ 71},{ 9}}, {{327},{ 9}}, {{199},{ 9}}, {{455},{ 9}},
|
||||
{{ 39},{ 9}}, {{295},{ 9}}, {{167},{ 9}}, {{423},{ 9}}, {{103},{ 9}},
|
||||
{{359},{ 9}}, {{231},{ 9}}, {{487},{ 9}}, {{ 23},{ 9}}, {{279},{ 9}},
|
||||
{{151},{ 9}}, {{407},{ 9}}, {{ 87},{ 9}}, {{343},{ 9}}, {{215},{ 9}},
|
||||
{{471},{ 9}}, {{ 55},{ 9}}, {{311},{ 9}}, {{183},{ 9}}, {{439},{ 9}},
|
||||
{{119},{ 9}}, {{375},{ 9}}, {{247},{ 9}}, {{503},{ 9}}, {{ 15},{ 9}},
|
||||
{{271},{ 9}}, {{143},{ 9}}, {{399},{ 9}}, {{ 79},{ 9}}, {{335},{ 9}},
|
||||
{{207},{ 9}}, {{463},{ 9}}, {{ 47},{ 9}}, {{303},{ 9}}, {{175},{ 9}},
|
||||
{{431},{ 9}}, {{111},{ 9}}, {{367},{ 9}}, {{239},{ 9}}, {{495},{ 9}},
|
||||
{{ 31},{ 9}}, {{287},{ 9}}, {{159},{ 9}}, {{415},{ 9}}, {{ 95},{ 9}},
|
||||
{{351},{ 9}}, {{223},{ 9}}, {{479},{ 9}}, {{ 63},{ 9}}, {{319},{ 9}},
|
||||
{{191},{ 9}}, {{447},{ 9}}, {{127},{ 9}}, {{383},{ 9}}, {{255},{ 9}},
|
||||
{{511},{ 9}}, {{ 0},{ 7}}, {{ 64},{ 7}}, {{ 32},{ 7}}, {{ 96},{ 7}},
|
||||
{{ 16},{ 7}}, {{ 80},{ 7}}, {{ 48},{ 7}}, {{112},{ 7}}, {{ 8},{ 7}},
|
||||
{{ 72},{ 7}}, {{ 40},{ 7}}, {{104},{ 7}}, {{ 24},{ 7}}, {{ 88},{ 7}},
|
||||
{{ 56},{ 7}}, {{120},{ 7}}, {{ 4},{ 7}}, {{ 68},{ 7}}, {{ 36},{ 7}},
|
||||
{{100},{ 7}}, {{ 20},{ 7}}, {{ 84},{ 7}}, {{ 52},{ 7}}, {{116},{ 7}},
|
||||
{{ 3},{ 8}}, {{131},{ 8}}, {{ 67},{ 8}}, {{195},{ 8}}, {{ 35},{ 8}},
|
||||
{{163},{ 8}}, {{ 99},{ 8}}, {{227},{ 8}}
|
||||
};
|
||||
|
||||
local const ct_data static_dtree[D_CODES] = {
|
||||
{{ 0},{ 5}}, {{16},{ 5}}, {{ 8},{ 5}}, {{24},{ 5}}, {{ 4},{ 5}},
|
||||
{{20},{ 5}}, {{12},{ 5}}, {{28},{ 5}}, {{ 2},{ 5}}, {{18},{ 5}},
|
||||
{{10},{ 5}}, {{26},{ 5}}, {{ 6},{ 5}}, {{22},{ 5}}, {{14},{ 5}},
|
||||
{{30},{ 5}}, {{ 1},{ 5}}, {{17},{ 5}}, {{ 9},{ 5}}, {{25},{ 5}},
|
||||
{{ 5},{ 5}}, {{21},{ 5}}, {{13},{ 5}}, {{29},{ 5}}, {{ 3},{ 5}},
|
||||
{{19},{ 5}}, {{11},{ 5}}, {{27},{ 5}}, {{ 7},{ 5}}, {{23},{ 5}}
|
||||
};
|
||||
|
||||
const uch _dist_code[DIST_CODE_LEN] = {
|
||||
0, 1, 2, 3, 4, 4, 5, 5, 6, 6, 6, 6, 7, 7, 7, 7, 8, 8, 8, 8,
|
||||
8, 8, 8, 8, 9, 9, 9, 9, 9, 9, 9, 9, 10, 10, 10, 10, 10, 10, 10, 10,
|
||||
10, 10, 10, 10, 10, 10, 10, 10, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11,
|
||||
11, 11, 11, 11, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12,
|
||||
12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 13, 13, 13, 13,
|
||||
13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13,
|
||||
13, 13, 13, 13, 13, 13, 13, 13, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14,
|
||||
14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14,
|
||||
14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14,
|
||||
14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 15, 15, 15, 15, 15, 15, 15, 15,
|
||||
15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15,
|
||||
15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15,
|
||||
15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 0, 0, 16, 17,
|
||||
18, 18, 19, 19, 20, 20, 20, 20, 21, 21, 21, 21, 22, 22, 22, 22, 22, 22, 22, 22,
|
||||
23, 23, 23, 23, 23, 23, 23, 23, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24,
|
||||
24, 24, 24, 24, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25,
|
||||
26, 26, 26, 26, 26, 26, 26, 26, 26, 26, 26, 26, 26, 26, 26, 26, 26, 26, 26, 26,
|
||||
26, 26, 26, 26, 26, 26, 26, 26, 26, 26, 26, 26, 27, 27, 27, 27, 27, 27, 27, 27,
|
||||
27, 27, 27, 27, 27, 27, 27, 27, 27, 27, 27, 27, 27, 27, 27, 27, 27, 27, 27, 27,
|
||||
27, 27, 27, 27, 28, 28, 28, 28, 28, 28, 28, 28, 28, 28, 28, 28, 28, 28, 28, 28,
|
||||
28, 28, 28, 28, 28, 28, 28, 28, 28, 28, 28, 28, 28, 28, 28, 28, 28, 28, 28, 28,
|
||||
28, 28, 28, 28, 28, 28, 28, 28, 28, 28, 28, 28, 28, 28, 28, 28, 28, 28, 28, 28,
|
||||
28, 28, 28, 28, 28, 28, 28, 28, 29, 29, 29, 29, 29, 29, 29, 29, 29, 29, 29, 29,
|
||||
29, 29, 29, 29, 29, 29, 29, 29, 29, 29, 29, 29, 29, 29, 29, 29, 29, 29, 29, 29,
|
||||
29, 29, 29, 29, 29, 29, 29, 29, 29, 29, 29, 29, 29, 29, 29, 29, 29, 29, 29, 29,
|
||||
29, 29, 29, 29, 29, 29, 29, 29, 29, 29, 29, 29
|
||||
};
|
||||
|
||||
const uch _length_code[MAX_MATCH-MIN_MATCH+1]= {
|
||||
0, 1, 2, 3, 4, 5, 6, 7, 8, 8, 9, 9, 10, 10, 11, 11, 12, 12, 12, 12,
|
||||
13, 13, 13, 13, 14, 14, 14, 14, 15, 15, 15, 15, 16, 16, 16, 16, 16, 16, 16, 16,
|
||||
17, 17, 17, 17, 17, 17, 17, 17, 18, 18, 18, 18, 18, 18, 18, 18, 19, 19, 19, 19,
|
||||
19, 19, 19, 19, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20,
|
||||
21, 21, 21, 21, 21, 21, 21, 21, 21, 21, 21, 21, 21, 21, 21, 21, 22, 22, 22, 22,
|
||||
22, 22, 22, 22, 22, 22, 22, 22, 22, 22, 22, 22, 23, 23, 23, 23, 23, 23, 23, 23,
|
||||
23, 23, 23, 23, 23, 23, 23, 23, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24,
|
||||
24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24,
|
||||
25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25,
|
||||
25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 26, 26, 26, 26, 26, 26, 26, 26,
|
||||
26, 26, 26, 26, 26, 26, 26, 26, 26, 26, 26, 26, 26, 26, 26, 26, 26, 26, 26, 26,
|
||||
26, 26, 26, 26, 27, 27, 27, 27, 27, 27, 27, 27, 27, 27, 27, 27, 27, 27, 27, 27,
|
||||
27, 27, 27, 27, 27, 27, 27, 27, 27, 27, 27, 27, 27, 27, 27, 28
|
||||
};
|
||||
|
||||
local const int base_length[LENGTH_CODES] = {
|
||||
0, 1, 2, 3, 4, 5, 6, 7, 8, 10, 12, 14, 16, 20, 24, 28, 32, 40, 48, 56,
|
||||
64, 80, 96, 112, 128, 160, 192, 224, 0
|
||||
};
|
||||
|
||||
local const int base_dist[D_CODES] = {
|
||||
0, 1, 2, 3, 4, 6, 8, 12, 16, 24,
|
||||
32, 48, 64, 96, 128, 192, 256, 384, 512, 768,
|
||||
1024, 1536, 2048, 3072, 4096, 6144, 8192, 12288, 16384, 24576
|
||||
};
|
||||
|
|
@ -1,58 +0,0 @@
|
|||
/* uncompr.c -- decompress a memory buffer
|
||||
* Copyright (C) 1995-2002 Jean-loup Gailly.
|
||||
* For conditions of distribution and use, see copyright notice in zlib.h
|
||||
*/
|
||||
|
||||
/* @(#) $Id: uncompr.c,v 1.1 2004/03/01 20:54:55 cozmic Exp $ */
|
||||
|
||||
#include "zlib.h"
|
||||
|
||||
/* ===========================================================================
|
||||
Decompresses the source buffer into the destination buffer. sourceLen is
|
||||
the byte length of the source buffer. Upon entry, destLen is the total
|
||||
size of the destination buffer, which must be large enough to hold the
|
||||
entire uncompressed data. (The size of the uncompressed data must have
|
||||
been saved previously by the compressor and transmitted to the decompressor
|
||||
by some mechanism outside the scope of this compression library.)
|
||||
Upon exit, destLen is the actual size of the compressed buffer.
|
||||
This function can be used to decompress a whole file at once if the
|
||||
input file is mmap'ed.
|
||||
|
||||
uncompress returns Z_OK if success, Z_MEM_ERROR if there was not
|
||||
enough memory, Z_BUF_ERROR if there was not enough room in the output
|
||||
buffer, or Z_DATA_ERROR if the input data was corrupted.
|
||||
*/
|
||||
int ZEXPORT uncompress (dest, destLen, source, sourceLen)
|
||||
Bytef *dest;
|
||||
uLongf *destLen;
|
||||
const Bytef *source;
|
||||
uLong sourceLen;
|
||||
{
|
||||
z_stream stream;
|
||||
int err;
|
||||
|
||||
stream.next_in = (Bytef*)source;
|
||||
stream.avail_in = (uInt)sourceLen;
|
||||
/* Check for source > 64K on 16-bit machine: */
|
||||
if ((uLong)stream.avail_in != sourceLen) return Z_BUF_ERROR;
|
||||
|
||||
stream.next_out = dest;
|
||||
stream.avail_out = (uInt)*destLen;
|
||||
if ((uLong)stream.avail_out != *destLen) return Z_BUF_ERROR;
|
||||
|
||||
stream.zalloc = (alloc_func)0;
|
||||
stream.zfree = (free_func)0;
|
||||
|
||||
err = inflateInit(&stream);
|
||||
if (err != Z_OK) return err;
|
||||
|
||||
err = inflate(&stream, Z_FINISH);
|
||||
if (err != Z_STREAM_END) {
|
||||
inflateEnd(&stream);
|
||||
return err == Z_OK ? Z_BUF_ERROR : err;
|
||||
}
|
||||
*destLen = stream.total_out;
|
||||
|
||||
err = inflateEnd(&stream);
|
||||
return err;
|
||||
}
|
|
@ -1,19 +0,0 @@
|
|||
/******************************************************************************
|
||||
*
|
||||
* File: version.h
|
||||
*
|
||||
* Created: 16/10/2002
|
||||
*
|
||||
* Author: Pavel Sakov
|
||||
* CSIRO Marine Research
|
||||
*
|
||||
* Purpose: Version string for csa library
|
||||
*
|
||||
*****************************************************************************/
|
||||
|
||||
#if !defined(_VERSION_H)
|
||||
#define _VERSION_H
|
||||
|
||||
char* csa_version = "0.05";
|
||||
|
||||
#endif
|
|
@ -1,376 +0,0 @@
|
|||
|
||||
/* WBMP
|
||||
** ----
|
||||
** WBMP Level 0: B/W, Uncompressed
|
||||
** This implements the WBMP format as specified in WAPSpec 1.1 and 1.2.
|
||||
** It does not support ExtHeaders as defined in the spec. The spec states
|
||||
** that a WAP client does not need to implement ExtHeaders.
|
||||
**
|
||||
** (c) 2000 Johan Van den Brande <johan@vandenbrande.com>
|
||||
*/
|
||||
|
||||
#ifdef HAVE_CONFIG_H
|
||||
#include "config.h"
|
||||
#endif
|
||||
|
||||
#include <stdio.h>
|
||||
#include <stddef.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
|
||||
#include "wbmp.h"
|
||||
#include "gd.h"
|
||||
#include "gdhelpers.h"
|
||||
|
||||
#ifdef NOTDEF
|
||||
#define __TEST /* Compile with main function */
|
||||
#define __DEBUG /* Extra verbose when with __TEST */
|
||||
#define __WRITE /* readwbmp and writewbmp(stdout) */
|
||||
#define __VIEW /* view the wbmp on stdout */
|
||||
#endif
|
||||
|
||||
/* getmbi
|
||||
** ------
|
||||
** Get a multibyte integer from a generic getin function
|
||||
** 'getin' can be getc, with in = NULL
|
||||
** you can find getin as a function just above the main function
|
||||
** This way you gain a lot of flexibilty about how this package
|
||||
** reads a wbmp file.
|
||||
*/
|
||||
int
|
||||
getmbi (int (*getin) (void *in), void *in)
|
||||
{
|
||||
int i, mbi = 0;
|
||||
|
||||
do
|
||||
{
|
||||
i = getin (in);
|
||||
if (i < 0)
|
||||
return (-1);
|
||||
mbi = (mbi << 7) | (i & 0x7f);
|
||||
}
|
||||
while (i & 0x80);
|
||||
|
||||
return (mbi);
|
||||
}
|
||||
|
||||
|
||||
/* putmbi
|
||||
** ------
|
||||
** Put a multibyte intgerer in some kind of output stream
|
||||
** I work here with a function pointer, to make it as generic
|
||||
** as possible. Look at this function as an iterator on the
|
||||
** mbi integers it spits out.
|
||||
**
|
||||
*/
|
||||
void
|
||||
putmbi (int i, void (*putout) (int c, void *out), void *out)
|
||||
{
|
||||
int cnt, l, accu;
|
||||
|
||||
/* Get number of septets */
|
||||
cnt = 0;
|
||||
accu = 0;
|
||||
while (accu != i)
|
||||
accu += i & 0x7f << 7 * cnt++;
|
||||
|
||||
/* Produce the multibyte output */
|
||||
for (l = cnt - 1; l > 0; l--)
|
||||
putout (0x80 | (i & 0x7f << 7 * l) >> 7 * l, out);
|
||||
|
||||
putout (i & 0x7f, out);
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
/* skipheader
|
||||
** ----------
|
||||
** Skips the ExtHeader. Not needed for the moment
|
||||
**
|
||||
*/
|
||||
int
|
||||
skipheader (int (*getin) (void *in), void *in)
|
||||
{
|
||||
int i;
|
||||
|
||||
do
|
||||
{
|
||||
i = getin (in);
|
||||
if (i < 0)
|
||||
return (-1);
|
||||
}
|
||||
while (i & 0x80);
|
||||
|
||||
return (0);
|
||||
}
|
||||
|
||||
/* create wbmp
|
||||
** -----------
|
||||
** create an empty wbmp
|
||||
**
|
||||
*/
|
||||
Wbmp *
|
||||
createwbmp (int width, int height, int color)
|
||||
{
|
||||
int i;
|
||||
|
||||
Wbmp *wbmp;
|
||||
if ((wbmp = (Wbmp *) gdMalloc (sizeof (Wbmp))) == NULL)
|
||||
return (NULL);
|
||||
|
||||
if ((wbmp->bitmap =
|
||||
(int *) gdMalloc (sizeof (int) * width * height)) == NULL)
|
||||
{
|
||||
gdFree (wbmp);
|
||||
return (NULL);
|
||||
}
|
||||
|
||||
wbmp->width = width;
|
||||
wbmp->height = height;
|
||||
|
||||
for (i = 0; i < width * height; wbmp->bitmap[i++] = color);
|
||||
|
||||
return (wbmp);
|
||||
}
|
||||
|
||||
|
||||
|
||||
/* readwbmp
|
||||
** -------
|
||||
** Actually reads the WBMP format from an open file descriptor
|
||||
** It goes along by returning a pointer to a WBMP struct.
|
||||
**
|
||||
*/
|
||||
int
|
||||
readwbmp (int (*getin) (void *in), void *in, Wbmp ** return_wbmp)
|
||||
{
|
||||
int row, col, byte, pel, pos;
|
||||
Wbmp *wbmp;
|
||||
|
||||
if ((wbmp = (Wbmp *) gdMalloc (sizeof (Wbmp))) == NULL)
|
||||
return (-1);
|
||||
|
||||
wbmp->type = getin (in);
|
||||
if (wbmp->type != 0)
|
||||
{
|
||||
gdFree (wbmp);
|
||||
return (-1);
|
||||
}
|
||||
|
||||
if (skipheader (getin, in))
|
||||
return (-1);
|
||||
|
||||
|
||||
wbmp->width = getmbi (getin, in);
|
||||
if (wbmp->width == -1)
|
||||
{
|
||||
gdFree (wbmp);
|
||||
return (-1);
|
||||
}
|
||||
|
||||
wbmp->height = getmbi (getin, in);
|
||||
if (wbmp->height == -1)
|
||||
{
|
||||
gdFree (wbmp);
|
||||
return (-1);
|
||||
}
|
||||
|
||||
#ifdef __DEBUG
|
||||
printf ("W: %d, H: %d\n", wbmp->width, wbmp->height);
|
||||
#endif
|
||||
|
||||
if ((wbmp->bitmap =
|
||||
(int *) gdMalloc (sizeof (int) * wbmp->width * wbmp->height)) == NULL)
|
||||
{
|
||||
gdFree (wbmp);
|
||||
return (-1);
|
||||
}
|
||||
|
||||
#ifdef __DEBUG
|
||||
printf ("DATA CONSTRUCTED\n");
|
||||
#endif
|
||||
|
||||
pos = 0;
|
||||
for (row = 0; row < wbmp->height; row++)
|
||||
{
|
||||
for (col = 0; col < wbmp->width;)
|
||||
{
|
||||
byte = getin (in);
|
||||
|
||||
for (pel = 7; pel >= 0; pel--)
|
||||
{
|
||||
if (col++ < wbmp->width)
|
||||
{
|
||||
if (byte & 1 << pel)
|
||||
{
|
||||
wbmp->bitmap[pos] = WBMP_WHITE;
|
||||
}
|
||||
else
|
||||
{
|
||||
wbmp->bitmap[pos] = WBMP_BLACK;
|
||||
}
|
||||
pos++;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
*return_wbmp = wbmp;
|
||||
|
||||
return (0);
|
||||
}
|
||||
|
||||
|
||||
/* writewbmp
|
||||
** ---------
|
||||
** Write a wbmp to a file descriptor
|
||||
**
|
||||
** Why not just giving a filedescriptor to this function?
|
||||
** Well, the incentive to write this function was the complete
|
||||
** integration in gd library from www.boutell.com. They use
|
||||
** their own io functions, so the passing of a function seemed to be
|
||||
** a logic(?) decision ...
|
||||
**
|
||||
*/
|
||||
int
|
||||
writewbmp (Wbmp * wbmp, void (*putout) (int c, void *out), void *out)
|
||||
{
|
||||
int row, col;
|
||||
int bitpos, octet;
|
||||
|
||||
/* Generate the header */
|
||||
putout (0, out); /* WBMP Type 0: B/W, Uncompressed bitmap */
|
||||
putout (0, out); /* FixHeaderField */
|
||||
|
||||
|
||||
|
||||
/* Size of the image */
|
||||
putmbi (wbmp->width, putout, out); /* width */
|
||||
putmbi (wbmp->height, putout, out); /* height */
|
||||
|
||||
|
||||
/* Image data */
|
||||
for (row = 0; row < wbmp->height; row++)
|
||||
{
|
||||
bitpos = 8;
|
||||
octet = 0;
|
||||
for (col = 0; col < wbmp->width; col++)
|
||||
{
|
||||
octet |=
|
||||
((wbmp->bitmap[row * wbmp->width + col] ==
|
||||
1) ? WBMP_WHITE : WBMP_BLACK) << --bitpos;
|
||||
if (bitpos == 0)
|
||||
{
|
||||
bitpos = 8;
|
||||
putout (octet, out);
|
||||
octet = 0;
|
||||
}
|
||||
}
|
||||
if (bitpos != 8)
|
||||
putout (octet, out);
|
||||
|
||||
}
|
||||
return (0);
|
||||
|
||||
}
|
||||
|
||||
|
||||
/* freewbmp
|
||||
** --------
|
||||
** gdFrees up memory occupied by a WBMP structure
|
||||
**
|
||||
*/
|
||||
void
|
||||
freewbmp (Wbmp * wbmp)
|
||||
{
|
||||
gdFree (wbmp->bitmap);
|
||||
gdFree (wbmp);
|
||||
}
|
||||
|
||||
|
||||
/* printwbmp
|
||||
** ---------
|
||||
** print a WBMP to stdout for visualisation
|
||||
**
|
||||
*/
|
||||
void
|
||||
printwbmp (Wbmp * wbmp)
|
||||
{
|
||||
int row, col;
|
||||
for (row = 0; row < wbmp->height; row++)
|
||||
{
|
||||
for (col = 0; col < wbmp->width; col++)
|
||||
{
|
||||
if (wbmp->bitmap[wbmp->width * row + col] == WBMP_BLACK)
|
||||
{
|
||||
putchar ('#');
|
||||
}
|
||||
else
|
||||
{
|
||||
putchar (' ');
|
||||
}
|
||||
}
|
||||
putchar ('\n');
|
||||
}
|
||||
}
|
||||
|
||||
#ifdef __TEST
|
||||
|
||||
/* putout to file descriptor
|
||||
** -------------------------
|
||||
*/
|
||||
int
|
||||
putout (int c, void *out)
|
||||
{
|
||||
return (putc (c, (FILE *) out));
|
||||
}
|
||||
|
||||
/* getin from file descriptor
|
||||
** --------------------------
|
||||
*/
|
||||
int
|
||||
getin (void *in)
|
||||
{
|
||||
return (getc ((FILE *) in));
|
||||
}
|
||||
|
||||
|
||||
/* Main function
|
||||
** -------------
|
||||
**
|
||||
*/
|
||||
int
|
||||
main (int argc, char *argv[])
|
||||
{
|
||||
FILE *wbmp_file;
|
||||
Wbmp *wbmp;
|
||||
|
||||
wbmp_file = fopen (argv[1], "rb");
|
||||
if (wbmp_file)
|
||||
{
|
||||
readwbmp (&getin, wbmp_file, &wbmp);
|
||||
|
||||
#ifdef __VIEW
|
||||
|
||||
#ifdef __DEBUG
|
||||
printf ("\nVIEWING IMAGE\n");
|
||||
#endif
|
||||
|
||||
printwbmp (wbmp);
|
||||
#endif
|
||||
|
||||
#ifdef __WRITE
|
||||
|
||||
#ifdef __DEBUG
|
||||
printf ("\nDUMPING WBMP to STDOUT\n");
|
||||
#endif
|
||||
|
||||
writewbmp (wbmp, &putout, stdout);
|
||||
#endif
|
||||
|
||||
freewbmp (wbmp);
|
||||
fclose (wbmp_file);
|
||||
}
|
||||
}
|
||||
#endif
|
|
@ -1,48 +0,0 @@
|
|||
/* WBMP
|
||||
** ----
|
||||
** WBMP Level 0: B/W, Uncompressed
|
||||
** This implements the WBMP format as specified in WAPSpec 1.1 and 1.2.
|
||||
** It does not support ExtHeaders as defined in the spec. The spec states
|
||||
** that a WAP client does not need to implement ExtHeaders.
|
||||
**
|
||||
** (c) 2000 Johan Van den Brande <johan@vandenbrande.com>
|
||||
**
|
||||
** Header file
|
||||
*/
|
||||
#ifndef __WBMP_H
|
||||
#define __WBMP_H 1
|
||||
|
||||
|
||||
/* WBMP struct
|
||||
** -----------
|
||||
** A Wireless bitmap structure
|
||||
**
|
||||
*/
|
||||
|
||||
typedef struct Wbmp_
|
||||
{
|
||||
int type; /* type of the wbmp */
|
||||
int width; /* width of the image */
|
||||
int height; /* height of the image */
|
||||
int *bitmap; /* pointer to data: 0 = WHITE , 1 = BLACK */
|
||||
}
|
||||
Wbmp;
|
||||
|
||||
#define WBMP_WHITE 1
|
||||
#define WBMP_BLACK 0
|
||||
|
||||
|
||||
/* Proto's
|
||||
** -------
|
||||
**
|
||||
*/
|
||||
void putmbi (int i, void (*putout) (int c, void *out), void *out);
|
||||
int getmbi (int (*getin) (void *in), void *in);
|
||||
int skipheader (int (*getin) (void *in), void *in);
|
||||
Wbmp *createwbmp (int width, int height, int color);
|
||||
int readwbmp (int (*getin) (void *in), void *in, Wbmp ** wbmp);
|
||||
int writewbmp (Wbmp * wbmp, void (*putout) (int c, void *out), void *out);
|
||||
void freewbmp (Wbmp * wbmp);
|
||||
void printwbmp (Wbmp * wbmp);
|
||||
|
||||
#endif
|
|
@ -1,279 +0,0 @@
|
|||
/* zconf.h -- configuration of the zlib compression library
|
||||
* Copyright (C) 1995-2002 Jean-loup Gailly.
|
||||
* For conditions of distribution and use, see copyright notice in zlib.h
|
||||
*/
|
||||
|
||||
/* @(#) $Id: zconf.h,v 1.1 2004/03/01 20:54:56 cozmic Exp $ */
|
||||
|
||||
#ifndef _ZCONF_H
|
||||
#define _ZCONF_H
|
||||
|
||||
/*
|
||||
* If you *really* need a unique prefix for all types and library functions,
|
||||
* compile with -DZ_PREFIX. The "standard" zlib should be compiled without it.
|
||||
*/
|
||||
#ifdef Z_PREFIX
|
||||
# define deflateInit_ z_deflateInit_
|
||||
# define deflate z_deflate
|
||||
# define deflateEnd z_deflateEnd
|
||||
# define inflateInit_ z_inflateInit_
|
||||
# define inflate z_inflate
|
||||
# define inflateEnd z_inflateEnd
|
||||
# define deflateInit2_ z_deflateInit2_
|
||||
# define deflateSetDictionary z_deflateSetDictionary
|
||||
# define deflateCopy z_deflateCopy
|
||||
# define deflateReset z_deflateReset
|
||||
# define deflateParams z_deflateParams
|
||||
# define inflateInit2_ z_inflateInit2_
|
||||
# define inflateSetDictionary z_inflateSetDictionary
|
||||
# define inflateSync z_inflateSync
|
||||
# define inflateSyncPoint z_inflateSyncPoint
|
||||
# define inflateReset z_inflateReset
|
||||
# define compress z_compress
|
||||
# define compress2 z_compress2
|
||||
# define uncompress z_uncompress
|
||||
# define adler32 z_adler32
|
||||
# define crc32 z_crc32
|
||||
# define get_crc_table z_get_crc_table
|
||||
|
||||
# define Byte z_Byte
|
||||
# define uInt z_uInt
|
||||
# define uLong z_uLong
|
||||
# define Bytef z_Bytef
|
||||
# define charf z_charf
|
||||
# define intf z_intf
|
||||
# define uIntf z_uIntf
|
||||
# define uLongf z_uLongf
|
||||
# define voidpf z_voidpf
|
||||
# define voidp z_voidp
|
||||
#endif
|
||||
|
||||
#if (defined(_WIN32) || defined(__WIN32__)) && !defined(WIN32)
|
||||
# define WIN32
|
||||
#endif
|
||||
#if defined(__GNUC__) || defined(WIN32) || defined(__386__) || defined(i386)
|
||||
# ifndef __32BIT__
|
||||
# define __32BIT__
|
||||
# endif
|
||||
#endif
|
||||
#if defined(__MSDOS__) && !defined(MSDOS)
|
||||
# define MSDOS
|
||||
#endif
|
||||
|
||||
/*
|
||||
* Compile with -DMAXSEG_64K if the alloc function cannot allocate more
|
||||
* than 64k bytes at a time (needed on systems with 16-bit int).
|
||||
*/
|
||||
#if defined(MSDOS) && !defined(__32BIT__)
|
||||
# define MAXSEG_64K
|
||||
#endif
|
||||
#ifdef MSDOS
|
||||
# define UNALIGNED_OK
|
||||
#endif
|
||||
|
||||
#if (defined(MSDOS) || defined(_WINDOWS) || defined(WIN32)) && !defined(STDC)
|
||||
# define STDC
|
||||
#endif
|
||||
#if defined(__STDC__) || defined(__cplusplus) || defined(__OS2__)
|
||||
# ifndef STDC
|
||||
# define STDC
|
||||
# endif
|
||||
#endif
|
||||
|
||||
#ifndef STDC
|
||||
# ifndef const /* cannot use !defined(STDC) && !defined(const) on Mac */
|
||||
# define const
|
||||
# endif
|
||||
#endif
|
||||
|
||||
/* Some Mac compilers merge all .h files incorrectly: */
|
||||
#if defined(__MWERKS__) || defined(applec) ||defined(THINK_C) ||defined(__SC__)
|
||||
# define NO_DUMMY_DECL
|
||||
#endif
|
||||
|
||||
/* Old Borland C incorrectly complains about missing returns: */
|
||||
#if defined(__BORLANDC__) && (__BORLANDC__ < 0x500)
|
||||
# define NEED_DUMMY_RETURN
|
||||
#endif
|
||||
|
||||
|
||||
/* Maximum value for memLevel in deflateInit2 */
|
||||
#ifndef MAX_MEM_LEVEL
|
||||
# ifdef MAXSEG_64K
|
||||
# define MAX_MEM_LEVEL 8
|
||||
# else
|
||||
# define MAX_MEM_LEVEL 9
|
||||
# endif
|
||||
#endif
|
||||
|
||||
/* Maximum value for windowBits in deflateInit2 and inflateInit2.
|
||||
* WARNING: reducing MAX_WBITS makes minigzip unable to extract .gz files
|
||||
* created by gzip. (Files created by minigzip can still be extracted by
|
||||
* gzip.)
|
||||
*/
|
||||
#ifndef MAX_WBITS
|
||||
# define MAX_WBITS 15 /* 32K LZ77 window */
|
||||
#endif
|
||||
|
||||
/* The memory requirements for deflate are (in bytes):
|
||||
(1 << (windowBits+2)) + (1 << (memLevel+9))
|
||||
that is: 128K for windowBits=15 + 128K for memLevel = 8 (default values)
|
||||
plus a few kilobytes for small objects. For example, if you want to reduce
|
||||
the default memory requirements from 256K to 128K, compile with
|
||||
make CFLAGS="-O -DMAX_WBITS=14 -DMAX_MEM_LEVEL=7"
|
||||
Of course this will generally degrade compression (there's no free lunch).
|
||||
|
||||
The memory requirements for inflate are (in bytes) 1 << windowBits
|
||||
that is, 32K for windowBits=15 (default value) plus a few kilobytes
|
||||
for small objects.
|
||||
*/
|
||||
|
||||
/* Type declarations */
|
||||
|
||||
#ifndef OF /* function prototypes */
|
||||
# ifdef STDC
|
||||
# define OF(args) args
|
||||
# else
|
||||
# define OF(args) ()
|
||||
# endif
|
||||
#endif
|
||||
|
||||
/* The following definitions for FAR are needed only for MSDOS mixed
|
||||
* model programming (small or medium model with some far allocations).
|
||||
* This was tested only with MSC; for other MSDOS compilers you may have
|
||||
* to define NO_MEMCPY in zutil.h. If you don't need the mixed model,
|
||||
* just define FAR to be empty.
|
||||
*/
|
||||
#if (defined(M_I86SM) || defined(M_I86MM)) && !defined(__32BIT__)
|
||||
/* MSC small or medium model */
|
||||
# define SMALL_MEDIUM
|
||||
# ifdef _MSC_VER
|
||||
# define FAR _far
|
||||
# else
|
||||
# define FAR far
|
||||
# endif
|
||||
#endif
|
||||
#if defined(__BORLANDC__) && (defined(__SMALL__) || defined(__MEDIUM__))
|
||||
# ifndef __32BIT__
|
||||
# define SMALL_MEDIUM
|
||||
# define FAR _far
|
||||
# endif
|
||||
#endif
|
||||
|
||||
/* Compile with -DZLIB_DLL for Windows DLL support */
|
||||
#if defined(ZLIB_DLL)
|
||||
# if defined(_WINDOWS) || defined(WINDOWS)
|
||||
# ifdef FAR
|
||||
# undef FAR
|
||||
# endif
|
||||
# include <windows.h>
|
||||
# define ZEXPORT WINAPI
|
||||
# ifdef WIN32
|
||||
# define ZEXPORTVA WINAPIV
|
||||
# else
|
||||
# define ZEXPORTVA FAR _cdecl _export
|
||||
# endif
|
||||
# endif
|
||||
# if defined (__BORLANDC__)
|
||||
# if (__BORLANDC__ >= 0x0500) && defined (WIN32)
|
||||
# include <windows.h>
|
||||
# define ZEXPORT __declspec(dllexport) WINAPI
|
||||
# define ZEXPORTRVA __declspec(dllexport) WINAPIV
|
||||
# else
|
||||
# if defined (_Windows) && defined (__DLL__)
|
||||
# define ZEXPORT _export
|
||||
# define ZEXPORTVA _export
|
||||
# endif
|
||||
# endif
|
||||
# endif
|
||||
#endif
|
||||
|
||||
#if defined (__BEOS__)
|
||||
# if defined (ZLIB_DLL)
|
||||
# define ZEXTERN extern __declspec(dllexport)
|
||||
# else
|
||||
# define ZEXTERN extern __declspec(dllimport)
|
||||
# endif
|
||||
#endif
|
||||
|
||||
#ifndef ZEXPORT
|
||||
# define ZEXPORT
|
||||
#endif
|
||||
#ifndef ZEXPORTVA
|
||||
# define ZEXPORTVA
|
||||
#endif
|
||||
#ifndef ZEXTERN
|
||||
# define ZEXTERN extern
|
||||
#endif
|
||||
|
||||
#ifndef FAR
|
||||
# define FAR
|
||||
#endif
|
||||
|
||||
#if !defined(MACOS) && !defined(TARGET_OS_MAC)
|
||||
typedef unsigned char Byte; /* 8 bits */
|
||||
#endif
|
||||
typedef unsigned int uInt; /* 16 bits or more */
|
||||
typedef unsigned long uLong; /* 32 bits or more */
|
||||
|
||||
#ifdef SMALL_MEDIUM
|
||||
/* Borland C/C++ and some old MSC versions ignore FAR inside typedef */
|
||||
# define Bytef Byte FAR
|
||||
#else
|
||||
typedef Byte FAR Bytef;
|
||||
#endif
|
||||
typedef char FAR charf;
|
||||
typedef int FAR intf;
|
||||
typedef uInt FAR uIntf;
|
||||
typedef uLong FAR uLongf;
|
||||
|
||||
#ifdef STDC
|
||||
typedef void FAR *voidpf;
|
||||
typedef void *voidp;
|
||||
#else
|
||||
typedef Byte FAR *voidpf;
|
||||
typedef Byte *voidp;
|
||||
#endif
|
||||
|
||||
#ifdef HAVE_UNISTD_H
|
||||
# include <sys/types.h> /* for off_t */
|
||||
# include <unistd.h> /* for SEEK_* and off_t */
|
||||
# define z_off_t off_t
|
||||
#endif
|
||||
#ifndef SEEK_SET
|
||||
# define SEEK_SET 0 /* Seek from beginning of file. */
|
||||
# define SEEK_CUR 1 /* Seek from current position. */
|
||||
# define SEEK_END 2 /* Set file pointer to EOF plus "offset" */
|
||||
#endif
|
||||
#ifndef z_off_t
|
||||
# define z_off_t long
|
||||
#endif
|
||||
|
||||
/* MVS linker does not support external names larger than 8 bytes */
|
||||
#if defined(__MVS__)
|
||||
# pragma map(deflateInit_,"DEIN")
|
||||
# pragma map(deflateInit2_,"DEIN2")
|
||||
# pragma map(deflateEnd,"DEEND")
|
||||
# pragma map(inflateInit_,"ININ")
|
||||
# pragma map(inflateInit2_,"ININ2")
|
||||
# pragma map(inflateEnd,"INEND")
|
||||
# pragma map(inflateSync,"INSY")
|
||||
# pragma map(inflateSetDictionary,"INSEDI")
|
||||
# pragma map(inflate_blocks,"INBL")
|
||||
# pragma map(inflate_blocks_new,"INBLNE")
|
||||
# pragma map(inflate_blocks_free,"INBLFR")
|
||||
# pragma map(inflate_blocks_reset,"INBLRE")
|
||||
# pragma map(inflate_codes_free,"INCOFR")
|
||||
# pragma map(inflate_codes,"INCO")
|
||||
# pragma map(inflate_fast,"INFA")
|
||||
# pragma map(inflate_flush,"INFLU")
|
||||
# pragma map(inflate_mask,"INMA")
|
||||
# pragma map(inflate_set_dictionary,"INSEDI2")
|
||||
# pragma map(inflate_copyright,"INCOPY")
|
||||
# pragma map(inflate_trees_bits,"INTRBI")
|
||||
# pragma map(inflate_trees_dynamic,"INTRDY")
|
||||
# pragma map(inflate_trees_fixed,"INTRFI")
|
||||
# pragma map(inflate_trees_free,"INTRFR")
|
||||
#endif
|
||||
|
||||
#endif /* _ZCONF_H */
|
|
@ -1,893 +0,0 @@
|
|||
/* zlib.h -- interface of the 'zlib' general purpose compression library
|
||||
version 1.1.4, March 11th, 2002
|
||||
|
||||
Copyright (C) 1995-2002 Jean-loup Gailly and Mark Adler
|
||||
|
||||
This software is provided 'as-is', without any express or implied
|
||||
warranty. In no event will the authors be held liable for any damages
|
||||
arising from the use of this software.
|
||||
|
||||
Permission is granted to anyone to use this software for any purpose,
|
||||
including commercial applications, and to alter it and redistribute it
|
||||
freely, subject to the following restrictions:
|
||||
|
||||
1. The origin of this software must not be misrepresented; you must not
|
||||
claim that you wrote the original software. If you use this software
|
||||
in a product, an acknowledgment in the product documentation would be
|
||||
appreciated but is not required.
|
||||
2. Altered source versions must be plainly marked as such, and must not be
|
||||
misrepresented as being the original software.
|
||||
3. This notice may not be removed or altered from any source distribution.
|
||||
|
||||
Jean-loup Gailly Mark Adler
|
||||
jloup@gzip.org madler@alumni.caltech.edu
|
||||
|
||||
|
||||
The data format used by the zlib library is described by RFCs (Request for
|
||||
Comments) 1950 to 1952 in the files ftp://ds.internic.net/rfc/rfc1950.txt
|
||||
(zlib format), rfc1951.txt (deflate format) and rfc1952.txt (gzip format).
|
||||
*/
|
||||
|
||||
#ifndef _ZLIB_H
|
||||
#define _ZLIB_H
|
||||
|
||||
#include "zconf.h"
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
#define ZLIB_VERSION "1.1.4"
|
||||
|
||||
/*
|
||||
The 'zlib' compression library provides in-memory compression and
|
||||
decompression functions, including integrity checks of the uncompressed
|
||||
data. This version of the library supports only one compression method
|
||||
(deflation) but other algorithms will be added later and will have the same
|
||||
stream interface.
|
||||
|
||||
Compression can be done in a single step if the buffers are large
|
||||
enough (for example if an input file is mmap'ed), or can be done by
|
||||
repeated calls of the compression function. In the latter case, the
|
||||
application must provide more input and/or consume the output
|
||||
(providing more output space) before each call.
|
||||
|
||||
The library also supports reading and writing files in gzip (.gz) format
|
||||
with an interface similar to that of stdio.
|
||||
|
||||
The library does not install any signal handler. The decoder checks
|
||||
the consistency of the compressed data, so the library should never
|
||||
crash even in case of corrupted input.
|
||||
*/
|
||||
|
||||
typedef voidpf (*alloc_func) OF((voidpf opaque, uInt items, uInt size));
|
||||
typedef void (*free_func) OF((voidpf opaque, voidpf address));
|
||||
|
||||
struct internal_state;
|
||||
|
||||
typedef struct z_stream_s {
|
||||
Bytef *next_in; /* next input byte */
|
||||
uInt avail_in; /* number of bytes available at next_in */
|
||||
uLong total_in; /* total nb of input bytes read so far */
|
||||
|
||||
Bytef *next_out; /* next output byte should be put there */
|
||||
uInt avail_out; /* remaining free space at next_out */
|
||||
uLong total_out; /* total nb of bytes output so far */
|
||||
|
||||
char *msg; /* last error message, NULL if no error */
|
||||
struct internal_state FAR *state; /* not visible by applications */
|
||||
|
||||
alloc_func zalloc; /* used to allocate the internal state */
|
||||
free_func zfree; /* used to free the internal state */
|
||||
voidpf opaque; /* private data object passed to zalloc and zfree */
|
||||
|
||||
int data_type; /* best guess about the data type: ascii or binary */
|
||||
uLong adler; /* adler32 value of the uncompressed data */
|
||||
uLong reserved; /* reserved for future use */
|
||||
} z_stream;
|
||||
|
||||
typedef z_stream FAR *z_streamp;
|
||||
|
||||
/*
|
||||
The application must update next_in and avail_in when avail_in has
|
||||
dropped to zero. It must update next_out and avail_out when avail_out
|
||||
has dropped to zero. The application must initialize zalloc, zfree and
|
||||
opaque before calling the init function. All other fields are set by the
|
||||
compression library and must not be updated by the application.
|
||||
|
||||
The opaque value provided by the application will be passed as the first
|
||||
parameter for calls of zalloc and zfree. This can be useful for custom
|
||||
memory management. The compression library attaches no meaning to the
|
||||
opaque value.
|
||||
|
||||
zalloc must return Z_NULL if there is not enough memory for the object.
|
||||
If zlib is used in a multi-threaded application, zalloc and zfree must be
|
||||
thread safe.
|
||||
|
||||
On 16-bit systems, the functions zalloc and zfree must be able to allocate
|
||||
exactly 65536 bytes, but will not be required to allocate more than this
|
||||
if the symbol MAXSEG_64K is defined (see zconf.h). WARNING: On MSDOS,
|
||||
pointers returned by zalloc for objects of exactly 65536 bytes *must*
|
||||
have their offset normalized to zero. The default allocation function
|
||||
provided by this library ensures this (see zutil.c). To reduce memory
|
||||
requirements and avoid any allocation of 64K objects, at the expense of
|
||||
compression ratio, compile the library with -DMAX_WBITS=14 (see zconf.h).
|
||||
|
||||
The fields total_in and total_out can be used for statistics or
|
||||
progress reports. After compression, total_in holds the total size of
|
||||
the uncompressed data and may be saved for use in the decompressor
|
||||
(particularly if the decompressor wants to decompress everything in
|
||||
a single step).
|
||||
*/
|
||||
|
||||
/* constants */
|
||||
|
||||
#define Z_NO_FLUSH 0
|
||||
#define Z_PARTIAL_FLUSH 1 /* will be removed, use Z_SYNC_FLUSH instead */
|
||||
#define Z_SYNC_FLUSH 2
|
||||
#define Z_FULL_FLUSH 3
|
||||
#define Z_FINISH 4
|
||||
/* Allowed flush values; see deflate() below for details */
|
||||
|
||||
#define Z_OK 0
|
||||
#define Z_STREAM_END 1
|
||||
#define Z_NEED_DICT 2
|
||||
#define Z_ERRNO (-1)
|
||||
#define Z_STREAM_ERROR (-2)
|
||||
#define Z_DATA_ERROR (-3)
|
||||
#define Z_MEM_ERROR (-4)
|
||||
#define Z_BUF_ERROR (-5)
|
||||
#define Z_VERSION_ERROR (-6)
|
||||
/* Return codes for the compression/decompression functions. Negative
|
||||
* values are errors, positive values are used for special but normal events.
|
||||
*/
|
||||
|
||||
#define Z_NO_COMPRESSION 0
|
||||
#define Z_BEST_SPEED 1
|
||||
#define Z_BEST_COMPRESSION 9
|
||||
#define Z_DEFAULT_COMPRESSION (-1)
|
||||
/* compression levels */
|
||||
|
||||
#define Z_FILTERED 1
|
||||
#define Z_HUFFMAN_ONLY 2
|
||||
#define Z_DEFAULT_STRATEGY 0
|
||||
/* compression strategy; see deflateInit2() below for details */
|
||||
|
||||
#define Z_BINARY 0
|
||||
#define Z_ASCII 1
|
||||
#define Z_UNKNOWN 2
|
||||
/* Possible values of the data_type field */
|
||||
|
||||
#define Z_DEFLATED 8
|
||||
/* The deflate compression method (the only one supported in this version) */
|
||||
|
||||
#define Z_NULL 0 /* for initializing zalloc, zfree, opaque */
|
||||
|
||||
#define zlib_version zlibVersion()
|
||||
/* for compatibility with versions < 1.0.2 */
|
||||
|
||||
/* basic functions */
|
||||
|
||||
ZEXTERN const char * ZEXPORT zlibVersion OF((void));
|
||||
/* The application can compare zlibVersion and ZLIB_VERSION for consistency.
|
||||
If the first character differs, the library code actually used is
|
||||
not compatible with the zlib.h header file used by the application.
|
||||
This check is automatically made by deflateInit and inflateInit.
|
||||
*/
|
||||
|
||||
/*
|
||||
ZEXTERN int ZEXPORT deflateInit OF((z_streamp strm, int level));
|
||||
|
||||
Initializes the internal stream state for compression. The fields
|
||||
zalloc, zfree and opaque must be initialized before by the caller.
|
||||
If zalloc and zfree are set to Z_NULL, deflateInit updates them to
|
||||
use default allocation functions.
|
||||
|
||||
The compression level must be Z_DEFAULT_COMPRESSION, or between 0 and 9:
|
||||
1 gives best speed, 9 gives best compression, 0 gives no compression at
|
||||
all (the input data is simply copied a block at a time).
|
||||
Z_DEFAULT_COMPRESSION requests a default compromise between speed and
|
||||
compression (currently equivalent to level 6).
|
||||
|
||||
deflateInit returns Z_OK if success, Z_MEM_ERROR if there was not
|
||||
enough memory, Z_STREAM_ERROR if level is not a valid compression level,
|
||||
Z_VERSION_ERROR if the zlib library version (zlib_version) is incompatible
|
||||
with the version assumed by the caller (ZLIB_VERSION).
|
||||
msg is set to null if there is no error message. deflateInit does not
|
||||
perform any compression: this will be done by deflate().
|
||||
*/
|
||||
|
||||
|
||||
ZEXTERN int ZEXPORT deflate OF((z_streamp strm, int flush));
|
||||
/*
|
||||
deflate compresses as much data as possible, and stops when the input
|
||||
buffer becomes empty or the output buffer becomes full. It may introduce some
|
||||
output latency (reading input without producing any output) except when
|
||||
forced to flush.
|
||||
|
||||
The detailed semantics are as follows. deflate performs one or both of the
|
||||
following actions:
|
||||
|
||||
- Compress more input starting at next_in and update next_in and avail_in
|
||||
accordingly. If not all input can be processed (because there is not
|
||||
enough room in the output buffer), next_in and avail_in are updated and
|
||||
processing will resume at this point for the next call of deflate().
|
||||
|
||||
- Provide more output starting at next_out and update next_out and avail_out
|
||||
accordingly. This action is forced if the parameter flush is non zero.
|
||||
Forcing flush frequently degrades the compression ratio, so this parameter
|
||||
should be set only when necessary (in interactive applications).
|
||||
Some output may be provided even if flush is not set.
|
||||
|
||||
Before the call of deflate(), the application should ensure that at least
|
||||
one of the actions is possible, by providing more input and/or consuming
|
||||
more output, and updating avail_in or avail_out accordingly; avail_out
|
||||
should never be zero before the call. The application can consume the
|
||||
compressed output when it wants, for example when the output buffer is full
|
||||
(avail_out == 0), or after each call of deflate(). If deflate returns Z_OK
|
||||
and with zero avail_out, it must be called again after making room in the
|
||||
output buffer because there might be more output pending.
|
||||
|
||||
If the parameter flush is set to Z_SYNC_FLUSH, all pending output is
|
||||
flushed to the output buffer and the output is aligned on a byte boundary, so
|
||||
that the decompressor can get all input data available so far. (In particular
|
||||
avail_in is zero after the call if enough output space has been provided
|
||||
before the call.) Flushing may degrade compression for some compression
|
||||
algorithms and so it should be used only when necessary.
|
||||
|
||||
If flush is set to Z_FULL_FLUSH, all output is flushed as with
|
||||
Z_SYNC_FLUSH, and the compression state is reset so that decompression can
|
||||
restart from this point if previous compressed data has been damaged or if
|
||||
random access is desired. Using Z_FULL_FLUSH too often can seriously degrade
|
||||
the compression.
|
||||
|
||||
If deflate returns with avail_out == 0, this function must be called again
|
||||
with the same value of the flush parameter and more output space (updated
|
||||
avail_out), until the flush is complete (deflate returns with non-zero
|
||||
avail_out).
|
||||
|
||||
If the parameter flush is set to Z_FINISH, pending input is processed,
|
||||
pending output is flushed and deflate returns with Z_STREAM_END if there
|
||||
was enough output space; if deflate returns with Z_OK, this function must be
|
||||
called again with Z_FINISH and more output space (updated avail_out) but no
|
||||
more input data, until it returns with Z_STREAM_END or an error. After
|
||||
deflate has returned Z_STREAM_END, the only possible operations on the
|
||||
stream are deflateReset or deflateEnd.
|
||||
|
||||
Z_FINISH can be used immediately after deflateInit if all the compression
|
||||
is to be done in a single step. In this case, avail_out must be at least
|
||||
0.1% larger than avail_in plus 12 bytes. If deflate does not return
|
||||
Z_STREAM_END, then it must be called again as described above.
|
||||
|
||||
deflate() sets strm->adler to the adler32 checksum of all input read
|
||||
so far (that is, total_in bytes).
|
||||
|
||||
deflate() may update data_type if it can make a good guess about
|
||||
the input data type (Z_ASCII or Z_BINARY). In doubt, the data is considered
|
||||
binary. This field is only for information purposes and does not affect
|
||||
the compression algorithm in any manner.
|
||||
|
||||
deflate() returns Z_OK if some progress has been made (more input
|
||||
processed or more output produced), Z_STREAM_END if all input has been
|
||||
consumed and all output has been produced (only when flush is set to
|
||||
Z_FINISH), Z_STREAM_ERROR if the stream state was inconsistent (for example
|
||||
if next_in or next_out was NULL), Z_BUF_ERROR if no progress is possible
|
||||
(for example avail_in or avail_out was zero).
|
||||
*/
|
||||
|
||||
|
||||
ZEXTERN int ZEXPORT deflateEnd OF((z_streamp strm));
|
||||
/*
|
||||
All dynamically allocated data structures for this stream are freed.
|
||||
This function discards any unprocessed input and does not flush any
|
||||
pending output.
|
||||
|
||||
deflateEnd returns Z_OK if success, Z_STREAM_ERROR if the
|
||||
stream state was inconsistent, Z_DATA_ERROR if the stream was freed
|
||||
prematurely (some input or output was discarded). In the error case,
|
||||
msg may be set but then points to a static string (which must not be
|
||||
deallocated).
|
||||
*/
|
||||
|
||||
|
||||
/*
|
||||
ZEXTERN int ZEXPORT inflateInit OF((z_streamp strm));
|
||||
|
||||
Initializes the internal stream state for decompression. The fields
|
||||
next_in, avail_in, zalloc, zfree and opaque must be initialized before by
|
||||
the caller. If next_in is not Z_NULL and avail_in is large enough (the exact
|
||||
value depends on the compression method), inflateInit determines the
|
||||
compression method from the zlib header and allocates all data structures
|
||||
accordingly; otherwise the allocation will be deferred to the first call of
|
||||
inflate. If zalloc and zfree are set to Z_NULL, inflateInit updates them to
|
||||
use default allocation functions.
|
||||
|
||||
inflateInit returns Z_OK if success, Z_MEM_ERROR if there was not enough
|
||||
memory, Z_VERSION_ERROR if the zlib library version is incompatible with the
|
||||
version assumed by the caller. msg is set to null if there is no error
|
||||
message. inflateInit does not perform any decompression apart from reading
|
||||
the zlib header if present: this will be done by inflate(). (So next_in and
|
||||
avail_in may be modified, but next_out and avail_out are unchanged.)
|
||||
*/
|
||||
|
||||
|
||||
ZEXTERN int ZEXPORT inflate OF((z_streamp strm, int flush));
|
||||
/*
|
||||
inflate decompresses as much data as possible, and stops when the input
|
||||
buffer becomes empty or the output buffer becomes full. It may some
|
||||
introduce some output latency (reading input without producing any output)
|
||||
except when forced to flush.
|
||||
|
||||
The detailed semantics are as follows. inflate performs one or both of the
|
||||
following actions:
|
||||
|
||||
- Decompress more input starting at next_in and update next_in and avail_in
|
||||
accordingly. If not all input can be processed (because there is not
|
||||
enough room in the output buffer), next_in is updated and processing
|
||||
will resume at this point for the next call of inflate().
|
||||
|
||||
- Provide more output starting at next_out and update next_out and avail_out
|
||||
accordingly. inflate() provides as much output as possible, until there
|
||||
is no more input data or no more space in the output buffer (see below
|
||||
about the flush parameter).
|
||||
|
||||
Before the call of inflate(), the application should ensure that at least
|
||||
one of the actions is possible, by providing more input and/or consuming
|
||||
more output, and updating the next_* and avail_* values accordingly.
|
||||
The application can consume the uncompressed output when it wants, for
|
||||
example when the output buffer is full (avail_out == 0), or after each
|
||||
call of inflate(). If inflate returns Z_OK and with zero avail_out, it
|
||||
must be called again after making room in the output buffer because there
|
||||
might be more output pending.
|
||||
|
||||
If the parameter flush is set to Z_SYNC_FLUSH, inflate flushes as much
|
||||
output as possible to the output buffer. The flushing behavior of inflate is
|
||||
not specified for values of the flush parameter other than Z_SYNC_FLUSH
|
||||
and Z_FINISH, but the current implementation actually flushes as much output
|
||||
as possible anyway.
|
||||
|
||||
inflate() should normally be called until it returns Z_STREAM_END or an
|
||||
error. However if all decompression is to be performed in a single step
|
||||
(a single call of inflate), the parameter flush should be set to
|
||||
Z_FINISH. In this case all pending input is processed and all pending
|
||||
output is flushed; avail_out must be large enough to hold all the
|
||||
uncompressed data. (The size of the uncompressed data may have been saved
|
||||
by the compressor for this purpose.) The next operation on this stream must
|
||||
be inflateEnd to deallocate the decompression state. The use of Z_FINISH
|
||||
is never required, but can be used to inform inflate that a faster routine
|
||||
may be used for the single inflate() call.
|
||||
|
||||
If a preset dictionary is needed at this point (see inflateSetDictionary
|
||||
below), inflate sets strm-adler to the adler32 checksum of the
|
||||
dictionary chosen by the compressor and returns Z_NEED_DICT; otherwise
|
||||
it sets strm->adler to the adler32 checksum of all output produced
|
||||
so far (that is, total_out bytes) and returns Z_OK, Z_STREAM_END or
|
||||
an error code as described below. At the end of the stream, inflate()
|
||||
checks that its computed adler32 checksum is equal to that saved by the
|
||||
compressor and returns Z_STREAM_END only if the checksum is correct.
|
||||
|
||||
inflate() returns Z_OK if some progress has been made (more input processed
|
||||
or more output produced), Z_STREAM_END if the end of the compressed data has
|
||||
been reached and all uncompressed output has been produced, Z_NEED_DICT if a
|
||||
preset dictionary is needed at this point, Z_DATA_ERROR if the input data was
|
||||
corrupted (input stream not conforming to the zlib format or incorrect
|
||||
adler32 checksum), Z_STREAM_ERROR if the stream structure was inconsistent
|
||||
(for example if next_in or next_out was NULL), Z_MEM_ERROR if there was not
|
||||
enough memory, Z_BUF_ERROR if no progress is possible or if there was not
|
||||
enough room in the output buffer when Z_FINISH is used. In the Z_DATA_ERROR
|
||||
case, the application may then call inflateSync to look for a good
|
||||
compression block.
|
||||
*/
|
||||
|
||||
|
||||
ZEXTERN int ZEXPORT inflateEnd OF((z_streamp strm));
|
||||
/*
|
||||
All dynamically allocated data structures for this stream are freed.
|
||||
This function discards any unprocessed input and does not flush any
|
||||
pending output.
|
||||
|
||||
inflateEnd returns Z_OK if success, Z_STREAM_ERROR if the stream state
|
||||
was inconsistent. In the error case, msg may be set but then points to a
|
||||
static string (which must not be deallocated).
|
||||
*/
|
||||
|
||||
/* Advanced functions */
|
||||
|
||||
/*
|
||||
The following functions are needed only in some special applications.
|
||||
*/
|
||||
|
||||
/*
|
||||
ZEXTERN int ZEXPORT deflateInit2 OF((z_streamp strm,
|
||||
int level,
|
||||
int method,
|
||||
int windowBits,
|
||||
int memLevel,
|
||||
int strategy));
|
||||
|
||||
This is another version of deflateInit with more compression options. The
|
||||
fields next_in, zalloc, zfree and opaque must be initialized before by
|
||||
the caller.
|
||||
|
||||
The method parameter is the compression method. It must be Z_DEFLATED in
|
||||
this version of the library.
|
||||
|
||||
The windowBits parameter is the base two logarithm of the window size
|
||||
(the size of the history buffer). It should be in the range 8..15 for this
|
||||
version of the library. Larger values of this parameter result in better
|
||||
compression at the expense of memory usage. The default value is 15 if
|
||||
deflateInit is used instead.
|
||||
|
||||
The memLevel parameter specifies how much memory should be allocated
|
||||
for the internal compression state. memLevel=1 uses minimum memory but
|
||||
is slow and reduces compression ratio; memLevel=9 uses maximum memory
|
||||
for optimal speed. The default value is 8. See zconf.h for total memory
|
||||
usage as a function of windowBits and memLevel.
|
||||
|
||||
The strategy parameter is used to tune the compression algorithm. Use the
|
||||
value Z_DEFAULT_STRATEGY for normal data, Z_FILTERED for data produced by a
|
||||
filter (or predictor), or Z_HUFFMAN_ONLY to force Huffman encoding only (no
|
||||
string match). Filtered data consists mostly of small values with a
|
||||
somewhat random distribution. In this case, the compression algorithm is
|
||||
tuned to compress them better. The effect of Z_FILTERED is to force more
|
||||
Huffman coding and less string matching; it is somewhat intermediate
|
||||
between Z_DEFAULT and Z_HUFFMAN_ONLY. The strategy parameter only affects
|
||||
the compression ratio but not the correctness of the compressed output even
|
||||
if it is not set appropriately.
|
||||
|
||||
deflateInit2 returns Z_OK if success, Z_MEM_ERROR if there was not enough
|
||||
memory, Z_STREAM_ERROR if a parameter is invalid (such as an invalid
|
||||
method). msg is set to null if there is no error message. deflateInit2 does
|
||||
not perform any compression: this will be done by deflate().
|
||||
*/
|
||||
|
||||
ZEXTERN int ZEXPORT deflateSetDictionary OF((z_streamp strm,
|
||||
const Bytef *dictionary,
|
||||
uInt dictLength));
|
||||
/*
|
||||
Initializes the compression dictionary from the given byte sequence
|
||||
without producing any compressed output. This function must be called
|
||||
immediately after deflateInit, deflateInit2 or deflateReset, before any
|
||||
call of deflate. The compressor and decompressor must use exactly the same
|
||||
dictionary (see inflateSetDictionary).
|
||||
|
||||
The dictionary should consist of strings (byte sequences) that are likely
|
||||
to be encountered later in the data to be compressed, with the most commonly
|
||||
used strings preferably put towards the end of the dictionary. Using a
|
||||
dictionary is most useful when the data to be compressed is short and can be
|
||||
predicted with good accuracy; the data can then be compressed better than
|
||||
with the default empty dictionary.
|
||||
|
||||
Depending on the size of the compression data structures selected by
|
||||
deflateInit or deflateInit2, a part of the dictionary may in effect be
|
||||
discarded, for example if the dictionary is larger than the window size in
|
||||
deflate or deflate2. Thus the strings most likely to be useful should be
|
||||
put at the end of the dictionary, not at the front.
|
||||
|
||||
Upon return of this function, strm->adler is set to the Adler32 value
|
||||
of the dictionary; the decompressor may later use this value to determine
|
||||
which dictionary has been used by the compressor. (The Adler32 value
|
||||
applies to the whole dictionary even if only a subset of the dictionary is
|
||||
actually used by the compressor.)
|
||||
|
||||
deflateSetDictionary returns Z_OK if success, or Z_STREAM_ERROR if a
|
||||
parameter is invalid (such as NULL dictionary) or the stream state is
|
||||
inconsistent (for example if deflate has already been called for this stream
|
||||
or if the compression method is bsort). deflateSetDictionary does not
|
||||
perform any compression: this will be done by deflate().
|
||||
*/
|
||||
|
||||
ZEXTERN int ZEXPORT deflateCopy OF((z_streamp dest,
|
||||
z_streamp source));
|
||||
/*
|
||||
Sets the destination stream as a complete copy of the source stream.
|
||||
|
||||
This function can be useful when several compression strategies will be
|
||||
tried, for example when there are several ways of pre-processing the input
|
||||
data with a filter. The streams that will be discarded should then be freed
|
||||
by calling deflateEnd. Note that deflateCopy duplicates the internal
|
||||
compression state which can be quite large, so this strategy is slow and
|
||||
can consume lots of memory.
|
||||
|
||||
deflateCopy returns Z_OK if success, Z_MEM_ERROR if there was not
|
||||
enough memory, Z_STREAM_ERROR if the source stream state was inconsistent
|
||||
(such as zalloc being NULL). msg is left unchanged in both source and
|
||||
destination.
|
||||
*/
|
||||
|
||||
ZEXTERN int ZEXPORT deflateReset OF((z_streamp strm));
|
||||
/*
|
||||
This function is equivalent to deflateEnd followed by deflateInit,
|
||||
but does not free and reallocate all the internal compression state.
|
||||
The stream will keep the same compression level and any other attributes
|
||||
that may have been set by deflateInit2.
|
||||
|
||||
deflateReset returns Z_OK if success, or Z_STREAM_ERROR if the source
|
||||
stream state was inconsistent (such as zalloc or state being NULL).
|
||||
*/
|
||||
|
||||
ZEXTERN int ZEXPORT deflateParams OF((z_streamp strm,
|
||||
int level,
|
||||
int strategy));
|
||||
/*
|
||||
Dynamically update the compression level and compression strategy. The
|
||||
interpretation of level and strategy is as in deflateInit2. This can be
|
||||
used to switch between compression and straight copy of the input data, or
|
||||
to switch to a different kind of input data requiring a different
|
||||
strategy. If the compression level is changed, the input available so far
|
||||
is compressed with the old level (and may be flushed); the new level will
|
||||
take effect only at the next call of deflate().
|
||||
|
||||
Before the call of deflateParams, the stream state must be set as for
|
||||
a call of deflate(), since the currently available input may have to
|
||||
be compressed and flushed. In particular, strm->avail_out must be non-zero.
|
||||
|
||||
deflateParams returns Z_OK if success, Z_STREAM_ERROR if the source
|
||||
stream state was inconsistent or if a parameter was invalid, Z_BUF_ERROR
|
||||
if strm->avail_out was zero.
|
||||
*/
|
||||
|
||||
/*
|
||||
ZEXTERN int ZEXPORT inflateInit2 OF((z_streamp strm,
|
||||
int windowBits));
|
||||
|
||||
This is another version of inflateInit with an extra parameter. The
|
||||
fields next_in, avail_in, zalloc, zfree and opaque must be initialized
|
||||
before by the caller.
|
||||
|
||||
The windowBits parameter is the base two logarithm of the maximum window
|
||||
size (the size of the history buffer). It should be in the range 8..15 for
|
||||
this version of the library. The default value is 15 if inflateInit is used
|
||||
instead. If a compressed stream with a larger window size is given as
|
||||
input, inflate() will return with the error code Z_DATA_ERROR instead of
|
||||
trying to allocate a larger window.
|
||||
|
||||
inflateInit2 returns Z_OK if success, Z_MEM_ERROR if there was not enough
|
||||
memory, Z_STREAM_ERROR if a parameter is invalid (such as a negative
|
||||
memLevel). msg is set to null if there is no error message. inflateInit2
|
||||
does not perform any decompression apart from reading the zlib header if
|
||||
present: this will be done by inflate(). (So next_in and avail_in may be
|
||||
modified, but next_out and avail_out are unchanged.)
|
||||
*/
|
||||
|
||||
ZEXTERN int ZEXPORT inflateSetDictionary OF((z_streamp strm,
|
||||
const Bytef *dictionary,
|
||||
uInt dictLength));
|
||||
/*
|
||||
Initializes the decompression dictionary from the given uncompressed byte
|
||||
sequence. This function must be called immediately after a call of inflate
|
||||
if this call returned Z_NEED_DICT. The dictionary chosen by the compressor
|
||||
can be determined from the Adler32 value returned by this call of
|
||||
inflate. The compressor and decompressor must use exactly the same
|
||||
dictionary (see deflateSetDictionary).
|
||||
|
||||
inflateSetDictionary returns Z_OK if success, Z_STREAM_ERROR if a
|
||||
parameter is invalid (such as NULL dictionary) or the stream state is
|
||||
inconsistent, Z_DATA_ERROR if the given dictionary doesn't match the
|
||||
expected one (incorrect Adler32 value). inflateSetDictionary does not
|
||||
perform any decompression: this will be done by subsequent calls of
|
||||
inflate().
|
||||
*/
|
||||
|
||||
ZEXTERN int ZEXPORT inflateSync OF((z_streamp strm));
|
||||
/*
|
||||
Skips invalid compressed data until a full flush point (see above the
|
||||
description of deflate with Z_FULL_FLUSH) can be found, or until all
|
||||
available input is skipped. No output is provided.
|
||||
|
||||
inflateSync returns Z_OK if a full flush point has been found, Z_BUF_ERROR
|
||||
if no more input was provided, Z_DATA_ERROR if no flush point has been found,
|
||||
or Z_STREAM_ERROR if the stream structure was inconsistent. In the success
|
||||
case, the application may save the current current value of total_in which
|
||||
indicates where valid compressed data was found. In the error case, the
|
||||
application may repeatedly call inflateSync, providing more input each time,
|
||||
until success or end of the input data.
|
||||
*/
|
||||
|
||||
ZEXTERN int ZEXPORT inflateReset OF((z_streamp strm));
|
||||
/*
|
||||
This function is equivalent to inflateEnd followed by inflateInit,
|
||||
but does not free and reallocate all the internal decompression state.
|
||||
The stream will keep attributes that may have been set by inflateInit2.
|
||||
|
||||
inflateReset returns Z_OK if success, or Z_STREAM_ERROR if the source
|
||||
stream state was inconsistent (such as zalloc or state being NULL).
|
||||
*/
|
||||
|
||||
|
||||
/* utility functions */
|
||||
|
||||
/*
|
||||
The following utility functions are implemented on top of the
|
||||
basic stream-oriented functions. To simplify the interface, some
|
||||
default options are assumed (compression level and memory usage,
|
||||
standard memory allocation functions). The source code of these
|
||||
utility functions can easily be modified if you need special options.
|
||||
*/
|
||||
|
||||
ZEXTERN int ZEXPORT compress OF((Bytef *dest, uLongf *destLen,
|
||||
const Bytef *source, uLong sourceLen));
|
||||
/*
|
||||
Compresses the source buffer into the destination buffer. sourceLen is
|
||||
the byte length of the source buffer. Upon entry, destLen is the total
|
||||
size of the destination buffer, which must be at least 0.1% larger than
|
||||
sourceLen plus 12 bytes. Upon exit, destLen is the actual size of the
|
||||
compressed buffer.
|
||||
This function can be used to compress a whole file at once if the
|
||||
input file is mmap'ed.
|
||||
compress returns Z_OK if success, Z_MEM_ERROR if there was not
|
||||
enough memory, Z_BUF_ERROR if there was not enough room in the output
|
||||
buffer.
|
||||
*/
|
||||
|
||||
ZEXTERN int ZEXPORT compress2 OF((Bytef *dest, uLongf *destLen,
|
||||
const Bytef *source, uLong sourceLen,
|
||||
int level));
|
||||
/*
|
||||
Compresses the source buffer into the destination buffer. The level
|
||||
parameter has the same meaning as in deflateInit. sourceLen is the byte
|
||||
length of the source buffer. Upon entry, destLen is the total size of the
|
||||
destination buffer, which must be at least 0.1% larger than sourceLen plus
|
||||
12 bytes. Upon exit, destLen is the actual size of the compressed buffer.
|
||||
|
||||
compress2 returns Z_OK if success, Z_MEM_ERROR if there was not enough
|
||||
memory, Z_BUF_ERROR if there was not enough room in the output buffer,
|
||||
Z_STREAM_ERROR if the level parameter is invalid.
|
||||
*/
|
||||
|
||||
ZEXTERN int ZEXPORT uncompress OF((Bytef *dest, uLongf *destLen,
|
||||
const Bytef *source, uLong sourceLen));
|
||||
/*
|
||||
Decompresses the source buffer into the destination buffer. sourceLen is
|
||||
the byte length of the source buffer. Upon entry, destLen is the total
|
||||
size of the destination buffer, which must be large enough to hold the
|
||||
entire uncompressed data. (The size of the uncompressed data must have
|
||||
been saved previously by the compressor and transmitted to the decompressor
|
||||
by some mechanism outside the scope of this compression library.)
|
||||
Upon exit, destLen is the actual size of the compressed buffer.
|
||||
This function can be used to decompress a whole file at once if the
|
||||
input file is mmap'ed.
|
||||
|
||||
uncompress returns Z_OK if success, Z_MEM_ERROR if there was not
|
||||
enough memory, Z_BUF_ERROR if there was not enough room in the output
|
||||
buffer, or Z_DATA_ERROR if the input data was corrupted.
|
||||
*/
|
||||
|
||||
|
||||
typedef voidp gzFile;
|
||||
|
||||
ZEXTERN gzFile ZEXPORT gzopen OF((const char *path, const char *mode));
|
||||
/*
|
||||
Opens a gzip (.gz) file for reading or writing. The mode parameter
|
||||
is as in fopen ("rb" or "wb") but can also include a compression level
|
||||
("wb9") or a strategy: 'f' for filtered data as in "wb6f", 'h' for
|
||||
Huffman only compression as in "wb1h". (See the description
|
||||
of deflateInit2 for more information about the strategy parameter.)
|
||||
|
||||
gzopen can be used to read a file which is not in gzip format; in this
|
||||
case gzread will directly read from the file without decompression.
|
||||
|
||||
gzopen returns NULL if the file could not be opened or if there was
|
||||
insufficient memory to allocate the (de)compression state; errno
|
||||
can be checked to distinguish the two cases (if errno is zero, the
|
||||
zlib error is Z_MEM_ERROR). */
|
||||
|
||||
ZEXTERN gzFile ZEXPORT gzdopen OF((int fd, const char *mode));
|
||||
/*
|
||||
gzdopen() associates a gzFile with the file descriptor fd. File
|
||||
descriptors are obtained from calls like open, dup, creat, pipe or
|
||||
fileno (in the file has been previously opened with fopen).
|
||||
The mode parameter is as in gzopen.
|
||||
The next call of gzclose on the returned gzFile will also close the
|
||||
file descriptor fd, just like fclose(fdopen(fd), mode) closes the file
|
||||
descriptor fd. If you want to keep fd open, use gzdopen(dup(fd), mode).
|
||||
gzdopen returns NULL if there was insufficient memory to allocate
|
||||
the (de)compression state.
|
||||
*/
|
||||
|
||||
ZEXTERN int ZEXPORT gzsetparams OF((gzFile file, int level, int strategy));
|
||||
/*
|
||||
Dynamically update the compression level or strategy. See the description
|
||||
of deflateInit2 for the meaning of these parameters.
|
||||
gzsetparams returns Z_OK if success, or Z_STREAM_ERROR if the file was not
|
||||
opened for writing.
|
||||
*/
|
||||
|
||||
ZEXTERN int ZEXPORT gzread OF((gzFile file, voidp buf, unsigned len));
|
||||
/*
|
||||
Reads the given number of uncompressed bytes from the compressed file.
|
||||
If the input file was not in gzip format, gzread copies the given number
|
||||
of bytes into the buffer.
|
||||
gzread returns the number of uncompressed bytes actually read (0 for
|
||||
end of file, -1 for error). */
|
||||
|
||||
ZEXTERN int ZEXPORT gzwrite OF((gzFile file,
|
||||
const voidp buf, unsigned len));
|
||||
/*
|
||||
Writes the given number of uncompressed bytes into the compressed file.
|
||||
gzwrite returns the number of uncompressed bytes actually written
|
||||
(0 in case of error).
|
||||
*/
|
||||
|
||||
ZEXTERN int ZEXPORTVA gzprintf OF((gzFile file, const char *format, ...));
|
||||
/*
|
||||
Converts, formats, and writes the args to the compressed file under
|
||||
control of the format string, as in fprintf. gzprintf returns the number of
|
||||
uncompressed bytes actually written (0 in case of error).
|
||||
*/
|
||||
|
||||
ZEXTERN int ZEXPORT gzputs OF((gzFile file, const char *s));
|
||||
/*
|
||||
Writes the given null-terminated string to the compressed file, excluding
|
||||
the terminating null character.
|
||||
gzputs returns the number of characters written, or -1 in case of error.
|
||||
*/
|
||||
|
||||
ZEXTERN char * ZEXPORT gzgets OF((gzFile file, char *buf, int len));
|
||||
/*
|
||||
Reads bytes from the compressed file until len-1 characters are read, or
|
||||
a newline character is read and transferred to buf, or an end-of-file
|
||||
condition is encountered. The string is then terminated with a null
|
||||
character.
|
||||
gzgets returns buf, or Z_NULL in case of error.
|
||||
*/
|
||||
|
||||
ZEXTERN int ZEXPORT gzputc OF((gzFile file, int c));
|
||||
/*
|
||||
Writes c, converted to an unsigned char, into the compressed file.
|
||||
gzputc returns the value that was written, or -1 in case of error.
|
||||
*/
|
||||
|
||||
ZEXTERN int ZEXPORT gzgetc OF((gzFile file));
|
||||
/*
|
||||
Reads one byte from the compressed file. gzgetc returns this byte
|
||||
or -1 in case of end of file or error.
|
||||
*/
|
||||
|
||||
ZEXTERN int ZEXPORT gzflush OF((gzFile file, int flush));
|
||||
/*
|
||||
Flushes all pending output into the compressed file. The parameter
|
||||
flush is as in the deflate() function. The return value is the zlib
|
||||
error number (see function gzerror below). gzflush returns Z_OK if
|
||||
the flush parameter is Z_FINISH and all output could be flushed.
|
||||
gzflush should be called only when strictly necessary because it can
|
||||
degrade compression.
|
||||
*/
|
||||
|
||||
ZEXTERN z_off_t ZEXPORT gzseek OF((gzFile file,
|
||||
z_off_t offset, int whence));
|
||||
/*
|
||||
Sets the starting position for the next gzread or gzwrite on the
|
||||
given compressed file. The offset represents a number of bytes in the
|
||||
uncompressed data stream. The whence parameter is defined as in lseek(2);
|
||||
the value SEEK_END is not supported.
|
||||
If the file is opened for reading, this function is emulated but can be
|
||||
extremely slow. If the file is opened for writing, only forward seeks are
|
||||
supported; gzseek then compresses a sequence of zeroes up to the new
|
||||
starting position.
|
||||
|
||||
gzseek returns the resulting offset location as measured in bytes from
|
||||
the beginning of the uncompressed stream, or -1 in case of error, in
|
||||
particular if the file is opened for writing and the new starting position
|
||||
would be before the current position.
|
||||
*/
|
||||
|
||||
ZEXTERN int ZEXPORT gzrewind OF((gzFile file));
|
||||
/*
|
||||
Rewinds the given file. This function is supported only for reading.
|
||||
|
||||
gzrewind(file) is equivalent to (int)gzseek(file, 0L, SEEK_SET)
|
||||
*/
|
||||
|
||||
ZEXTERN z_off_t ZEXPORT gztell OF((gzFile file));
|
||||
/*
|
||||
Returns the starting position for the next gzread or gzwrite on the
|
||||
given compressed file. This position represents a number of bytes in the
|
||||
uncompressed data stream.
|
||||
|
||||
gztell(file) is equivalent to gzseek(file, 0L, SEEK_CUR)
|
||||
*/
|
||||
|
||||
ZEXTERN int ZEXPORT gzeof OF((gzFile file));
|
||||
/*
|
||||
Returns 1 when EOF has previously been detected reading the given
|
||||
input stream, otherwise zero.
|
||||
*/
|
||||
|
||||
ZEXTERN int ZEXPORT gzclose OF((gzFile file));
|
||||
/*
|
||||
Flushes all pending output if necessary, closes the compressed file
|
||||
and deallocates all the (de)compression state. The return value is the zlib
|
||||
error number (see function gzerror below).
|
||||
*/
|
||||
|
||||
ZEXTERN const char * ZEXPORT gzerror OF((gzFile file, int *errnum));
|
||||
/*
|
||||
Returns the error message for the last error which occurred on the
|
||||
given compressed file. errnum is set to zlib error number. If an
|
||||
error occurred in the file system and not in the compression library,
|
||||
errnum is set to Z_ERRNO and the application may consult errno
|
||||
to get the exact error code.
|
||||
*/
|
||||
|
||||
/* checksum functions */
|
||||
|
||||
/*
|
||||
These functions are not related to compression but are exported
|
||||
anyway because they might be useful in applications using the
|
||||
compression library.
|
||||
*/
|
||||
|
||||
ZEXTERN uLong ZEXPORT adler32 OF((uLong adler, const Bytef *buf, uInt len));
|
||||
|
||||
/*
|
||||
Update a running Adler-32 checksum with the bytes buf[0..len-1] and
|
||||
return the updated checksum. If buf is NULL, this function returns
|
||||
the required initial value for the checksum.
|
||||
An Adler-32 checksum is almost as reliable as a CRC32 but can be computed
|
||||
much faster. Usage example:
|
||||
|
||||
uLong adler = adler32(0L, Z_NULL, 0);
|
||||
|
||||
while (read_buffer(buffer, length) != EOF) {
|
||||
adler = adler32(adler, buffer, length);
|
||||
}
|
||||
if (adler != original_adler) error();
|
||||
*/
|
||||
|
||||
ZEXTERN uLong ZEXPORT crc32 OF((uLong crc, const Bytef *buf, uInt len));
|
||||
/*
|
||||
Update a running crc with the bytes buf[0..len-1] and return the updated
|
||||
crc. If buf is NULL, this function returns the required initial value
|
||||
for the crc. Pre- and post-conditioning (one's complement) is performed
|
||||
within this function so it shouldn't be done by the application.
|
||||
Usage example:
|
||||
|
||||
uLong crc = crc32(0L, Z_NULL, 0);
|
||||
|
||||
while (read_buffer(buffer, length) != EOF) {
|
||||
crc = crc32(crc, buffer, length);
|
||||
}
|
||||
if (crc != original_crc) error();
|
||||
*/
|
||||
|
||||
|
||||
/* various hacks, don't look :) */
|
||||
|
||||
/* deflateInit and inflateInit are macros to allow checking the zlib version
|
||||
* and the compiler's view of z_stream:
|
||||
*/
|
||||
ZEXTERN int ZEXPORT deflateInit_ OF((z_streamp strm, int level,
|
||||
const char *version, int stream_size));
|
||||
ZEXTERN int ZEXPORT inflateInit_ OF((z_streamp strm,
|
||||
const char *version, int stream_size));
|
||||
ZEXTERN int ZEXPORT deflateInit2_ OF((z_streamp strm, int level, int method,
|
||||
int windowBits, int memLevel,
|
||||
int strategy, const char *version,
|
||||
int stream_size));
|
||||
ZEXTERN int ZEXPORT inflateInit2_ OF((z_streamp strm, int windowBits,
|
||||
const char *version, int stream_size));
|
||||
#define deflateInit(strm, level) \
|
||||
deflateInit_((strm), (level), ZLIB_VERSION, sizeof(z_stream))
|
||||
#define inflateInit(strm) \
|
||||
inflateInit_((strm), ZLIB_VERSION, sizeof(z_stream))
|
||||
#define deflateInit2(strm, level, method, windowBits, memLevel, strategy) \
|
||||
deflateInit2_((strm),(level),(method),(windowBits),(memLevel),\
|
||||
(strategy), ZLIB_VERSION, sizeof(z_stream))
|
||||
#define inflateInit2(strm, windowBits) \
|
||||
inflateInit2_((strm), (windowBits), ZLIB_VERSION, sizeof(z_stream))
|
||||
|
||||
|
||||
#if !defined(_Z_UTIL_H) && !defined(NO_DUMMY_DECL)
|
||||
struct internal_state {int dummy;}; /* hack for buggy compilers */
|
||||
#endif
|
||||
|
||||
ZEXTERN const char * ZEXPORT zError OF((int err));
|
||||
ZEXTERN int ZEXPORT inflateSyncPoint OF((z_streamp z));
|
||||
ZEXTERN const uLongf * ZEXPORT get_crc_table OF((void));
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif /* _ZLIB_H */
|
|
@ -1,225 +0,0 @@
|
|||
/* zutil.c -- target dependent utility functions for the compression library
|
||||
* Copyright (C) 1995-2002 Jean-loup Gailly.
|
||||
* For conditions of distribution and use, see copyright notice in zlib.h
|
||||
*/
|
||||
|
||||
/* @(#) $Id: zutil.c,v 1.1 2004/03/01 20:54:56 cozmic Exp $ */
|
||||
|
||||
#include "zutil.h"
|
||||
|
||||
struct internal_state {int dummy;}; /* for buggy compilers */
|
||||
|
||||
#ifndef STDC
|
||||
extern void exit OF((int));
|
||||
#endif
|
||||
|
||||
const char *z_errmsg[10] = {
|
||||
"need dictionary", /* Z_NEED_DICT 2 */
|
||||
"stream end", /* Z_STREAM_END 1 */
|
||||
"", /* Z_OK 0 */
|
||||
"file error", /* Z_ERRNO (-1) */
|
||||
"stream error", /* Z_STREAM_ERROR (-2) */
|
||||
"data error", /* Z_DATA_ERROR (-3) */
|
||||
"insufficient memory", /* Z_MEM_ERROR (-4) */
|
||||
"buffer error", /* Z_BUF_ERROR (-5) */
|
||||
"incompatible version",/* Z_VERSION_ERROR (-6) */
|
||||
""};
|
||||
|
||||
|
||||
const char * ZEXPORT zlibVersion()
|
||||
{
|
||||
return ZLIB_VERSION;
|
||||
}
|
||||
|
||||
#ifdef DEBUG
|
||||
|
||||
# ifndef verbose
|
||||
# define verbose 0
|
||||
# endif
|
||||
int z_verbose = verbose;
|
||||
|
||||
void z_error (m)
|
||||
char *m;
|
||||
{
|
||||
fprintf(stderr, "%s\n", m);
|
||||
exit(1);
|
||||
}
|
||||
#endif
|
||||
|
||||
/* exported to allow conversion of error code to string for compress() and
|
||||
* uncompress()
|
||||
*/
|
||||
const char * ZEXPORT zError(err)
|
||||
int err;
|
||||
{
|
||||
return ERR_MSG(err);
|
||||
}
|
||||
|
||||
|
||||
#ifndef HAVE_MEMCPY
|
||||
|
||||
void zmemcpy(dest, source, len)
|
||||
Bytef* dest;
|
||||
const Bytef* source;
|
||||
uInt len;
|
||||
{
|
||||
if (len == 0) return;
|
||||
do {
|
||||
*dest++ = *source++; /* ??? to be unrolled */
|
||||
} while (--len != 0);
|
||||
}
|
||||
|
||||
int zmemcmp(s1, s2, len)
|
||||
const Bytef* s1;
|
||||
const Bytef* s2;
|
||||
uInt len;
|
||||
{
|
||||
uInt j;
|
||||
|
||||
for (j = 0; j < len; j++) {
|
||||
if (s1[j] != s2[j]) return 2*(s1[j] > s2[j])-1;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
void zmemzero(dest, len)
|
||||
Bytef* dest;
|
||||
uInt len;
|
||||
{
|
||||
if (len == 0) return;
|
||||
do {
|
||||
*dest++ = 0; /* ??? to be unrolled */
|
||||
} while (--len != 0);
|
||||
}
|
||||
#endif
|
||||
|
||||
#ifdef __TURBOC__
|
||||
#if (defined( __BORLANDC__) || !defined(SMALL_MEDIUM)) && !defined(__32BIT__)
|
||||
/* Small and medium model in Turbo C are for now limited to near allocation
|
||||
* with reduced MAX_WBITS and MAX_MEM_LEVEL
|
||||
*/
|
||||
# define MY_ZCALLOC
|
||||
|
||||
/* Turbo C malloc() does not allow dynamic allocation of 64K bytes
|
||||
* and farmalloc(64K) returns a pointer with an offset of 8, so we
|
||||
* must fix the pointer. Warning: the pointer must be put back to its
|
||||
* original form in order to free it, use zcfree().
|
||||
*/
|
||||
|
||||
#define MAX_PTR 10
|
||||
/* 10*64K = 640K */
|
||||
|
||||
local int next_ptr = 0;
|
||||
|
||||
typedef struct ptr_table_s {
|
||||
voidpf org_ptr;
|
||||
voidpf new_ptr;
|
||||
} ptr_table;
|
||||
|
||||
local ptr_table table[MAX_PTR];
|
||||
/* This table is used to remember the original form of pointers
|
||||
* to large buffers (64K). Such pointers are normalized with a zero offset.
|
||||
* Since MSDOS is not a preemptive multitasking OS, this table is not
|
||||
* protected from concurrent access. This hack doesn't work anyway on
|
||||
* a protected system like OS/2. Use Microsoft C instead.
|
||||
*/
|
||||
|
||||
voidpf zcalloc (voidpf opaque, unsigned items, unsigned size)
|
||||
{
|
||||
voidpf buf = opaque; /* just to make some compilers happy */
|
||||
ulg bsize = (ulg)items*size;
|
||||
|
||||
/* If we allocate less than 65520 bytes, we assume that farmalloc
|
||||
* will return a usable pointer which doesn't have to be normalized.
|
||||
*/
|
||||
if (bsize < 65520L) {
|
||||
buf = farmalloc(bsize);
|
||||
if (*(ush*)&buf != 0) return buf;
|
||||
} else {
|
||||
buf = farmalloc(bsize + 16L);
|
||||
}
|
||||
if (buf == NULL || next_ptr >= MAX_PTR) return NULL;
|
||||
table[next_ptr].org_ptr = buf;
|
||||
|
||||
/* Normalize the pointer to seg:0 */
|
||||
*((ush*)&buf+1) += ((ush)((uch*)buf-0) + 15) >> 4;
|
||||
*(ush*)&buf = 0;
|
||||
table[next_ptr++].new_ptr = buf;
|
||||
return buf;
|
||||
}
|
||||
|
||||
void zcfree (voidpf opaque, voidpf ptr)
|
||||
{
|
||||
int n;
|
||||
if (*(ush*)&ptr != 0) { /* object < 64K */
|
||||
farfree(ptr);
|
||||
return;
|
||||
}
|
||||
/* Find the original pointer */
|
||||
for (n = 0; n < next_ptr; n++) {
|
||||
if (ptr != table[n].new_ptr) continue;
|
||||
|
||||
farfree(table[n].org_ptr);
|
||||
while (++n < next_ptr) {
|
||||
table[n-1] = table[n];
|
||||
}
|
||||
next_ptr--;
|
||||
return;
|
||||
}
|
||||
ptr = opaque; /* just to make some compilers happy */
|
||||
Assert(0, "zcfree: ptr not found");
|
||||
}
|
||||
#endif
|
||||
#endif /* __TURBOC__ */
|
||||
|
||||
|
||||
#if defined(M_I86) && !defined(__32BIT__)
|
||||
/* Microsoft C in 16-bit mode */
|
||||
|
||||
# define MY_ZCALLOC
|
||||
|
||||
#if (!defined(_MSC_VER) || (_MSC_VER <= 600))
|
||||
# define _halloc halloc
|
||||
# define _hfree hfree
|
||||
#endif
|
||||
|
||||
voidpf zcalloc (voidpf opaque, unsigned items, unsigned size)
|
||||
{
|
||||
if (opaque) opaque = 0; /* to make compiler happy */
|
||||
return _halloc((long)items, size);
|
||||
}
|
||||
|
||||
void zcfree (voidpf opaque, voidpf ptr)
|
||||
{
|
||||
if (opaque) opaque = 0; /* to make compiler happy */
|
||||
_hfree(ptr);
|
||||
}
|
||||
|
||||
#endif /* MSC */
|
||||
|
||||
|
||||
#ifndef MY_ZCALLOC /* Any system without a special alloc function */
|
||||
|
||||
#ifndef STDC
|
||||
extern voidp calloc OF((uInt items, uInt size));
|
||||
extern void free OF((voidpf ptr));
|
||||
#endif
|
||||
|
||||
voidpf zcalloc (opaque, items, size)
|
||||
voidpf opaque;
|
||||
unsigned items;
|
||||
unsigned size;
|
||||
{
|
||||
if (opaque) items += size - size; /* make compiler happy */
|
||||
return (voidpf)calloc(items, size);
|
||||
}
|
||||
|
||||
void zcfree (opaque, ptr)
|
||||
voidpf opaque;
|
||||
voidpf ptr;
|
||||
{
|
||||
free(ptr);
|
||||
if (opaque) return; /* make compiler happy */
|
||||
}
|
||||
|
||||
#endif /* MY_ZCALLOC */
|
|
@ -1,220 +0,0 @@
|
|||
/* zutil.h -- internal interface and configuration of the compression library
|
||||
* Copyright (C) 1995-2002 Jean-loup Gailly.
|
||||
* For conditions of distribution and use, see copyright notice in zlib.h
|
||||
*/
|
||||
|
||||
/* WARNING: this file should *not* be used by applications. It is
|
||||
part of the implementation of the compression library and is
|
||||
subject to change. Applications should only use zlib.h.
|
||||
*/
|
||||
|
||||
/* @(#) $Id: zutil.h,v 1.1 2004/03/01 20:54:56 cozmic Exp $ */
|
||||
|
||||
#ifndef _Z_UTIL_H
|
||||
#define _Z_UTIL_H
|
||||
|
||||
#include "zlib.h"
|
||||
|
||||
#ifdef STDC
|
||||
# include <stddef.h>
|
||||
# include <string.h>
|
||||
# include <stdlib.h>
|
||||
#endif
|
||||
#ifdef NO_ERRNO_H
|
||||
extern int errno;
|
||||
#else
|
||||
# include <errno.h>
|
||||
#endif
|
||||
|
||||
#ifndef local
|
||||
# define local static
|
||||
#endif
|
||||
/* compile with -Dlocal if your debugger can't find static symbols */
|
||||
|
||||
typedef unsigned char uch;
|
||||
typedef uch FAR uchf;
|
||||
typedef unsigned short ush;
|
||||
typedef ush FAR ushf;
|
||||
typedef unsigned long ulg;
|
||||
|
||||
extern const char *z_errmsg[10]; /* indexed by 2-zlib_error */
|
||||
/* (size given to avoid silly warnings with Visual C++) */
|
||||
|
||||
#define ERR_MSG(err) z_errmsg[Z_NEED_DICT-(err)]
|
||||
|
||||
#define ERR_RETURN(strm,err) \
|
||||
return (strm->msg = (char*)ERR_MSG(err), (err))
|
||||
/* To be used only when the state is known to be valid */
|
||||
|
||||
/* common constants */
|
||||
|
||||
#ifndef DEF_WBITS
|
||||
# define DEF_WBITS MAX_WBITS
|
||||
#endif
|
||||
/* default windowBits for decompression. MAX_WBITS is for compression only */
|
||||
|
||||
#if MAX_MEM_LEVEL >= 8
|
||||
# define DEF_MEM_LEVEL 8
|
||||
#else
|
||||
# define DEF_MEM_LEVEL MAX_MEM_LEVEL
|
||||
#endif
|
||||
/* default memLevel */
|
||||
|
||||
#define STORED_BLOCK 0
|
||||
#define STATIC_TREES 1
|
||||
#define DYN_TREES 2
|
||||
/* The three kinds of block type */
|
||||
|
||||
#define MIN_MATCH 3
|
||||
#define MAX_MATCH 258
|
||||
/* The minimum and maximum match lengths */
|
||||
|
||||
#define PRESET_DICT 0x20 /* preset dictionary flag in zlib header */
|
||||
|
||||
/* target dependencies */
|
||||
|
||||
#ifdef MSDOS
|
||||
# define OS_CODE 0x00
|
||||
# if defined(__TURBOC__) || defined(__BORLANDC__)
|
||||
# if(__STDC__ == 1) && (defined(__LARGE__) || defined(__COMPACT__))
|
||||
/* Allow compilation with ANSI keywords only enabled */
|
||||
void _Cdecl farfree( void *block );
|
||||
void *_Cdecl farmalloc( unsigned long nbytes );
|
||||
# else
|
||||
# include <alloc.h>
|
||||
# endif
|
||||
# else /* MSC or DJGPP */
|
||||
# include <malloc.h>
|
||||
# endif
|
||||
#endif
|
||||
|
||||
#ifdef OS2
|
||||
# define OS_CODE 0x06
|
||||
#endif
|
||||
|
||||
#ifdef WIN32 /* Window 95 & Windows NT */
|
||||
# define OS_CODE 0x0b
|
||||
#endif
|
||||
|
||||
#if defined(VAXC) || defined(VMS)
|
||||
# define OS_CODE 0x02
|
||||
# define F_OPEN(name, mode) \
|
||||
fopen((name), (mode), "mbc=60", "ctx=stm", "rfm=fix", "mrs=512")
|
||||
#endif
|
||||
|
||||
#ifdef AMIGA
|
||||
# define OS_CODE 0x01
|
||||
#endif
|
||||
|
||||
#if defined(ATARI) || defined(atarist)
|
||||
# define OS_CODE 0x05
|
||||
#endif
|
||||
|
||||
#if defined(MACOS) || defined(TARGET_OS_MAC)
|
||||
# define OS_CODE 0x07
|
||||
# if defined(__MWERKS__) && __dest_os != __be_os && __dest_os != __win32_os
|
||||
# include <unix.h> /* for fdopen */
|
||||
# else
|
||||
# ifndef fdopen
|
||||
# define fdopen(fd,mode) NULL /* No fdopen() */
|
||||
# endif
|
||||
# endif
|
||||
#endif
|
||||
|
||||
#ifdef __50SERIES /* Prime/PRIMOS */
|
||||
# define OS_CODE 0x0F
|
||||
#endif
|
||||
|
||||
#ifdef TOPS20
|
||||
# define OS_CODE 0x0a
|
||||
#endif
|
||||
|
||||
#if defined(_BEOS_) || defined(RISCOS)
|
||||
# define fdopen(fd,mode) NULL /* No fdopen() */
|
||||
#endif
|
||||
|
||||
#if (defined(_MSC_VER) && (_MSC_VER > 600))
|
||||
# define fdopen(fd,type) _fdopen(fd,type)
|
||||
#endif
|
||||
|
||||
|
||||
/* Common defaults */
|
||||
|
||||
#ifndef OS_CODE
|
||||
# define OS_CODE 0x03 /* assume Unix */
|
||||
#endif
|
||||
|
||||
#ifndef F_OPEN
|
||||
# define F_OPEN(name, mode) fopen((name), (mode))
|
||||
#endif
|
||||
|
||||
/* functions */
|
||||
|
||||
#ifdef HAVE_STRERROR
|
||||
extern char *strerror OF((int));
|
||||
# define zstrerror(errnum) strerror(errnum)
|
||||
#else
|
||||
# define zstrerror(errnum) ""
|
||||
#endif
|
||||
|
||||
#if defined(pyr)
|
||||
# define NO_MEMCPY
|
||||
#endif
|
||||
#if defined(SMALL_MEDIUM) && !defined(_MSC_VER) && !defined(__SC__)
|
||||
/* Use our own functions for small and medium model with MSC <= 5.0.
|
||||
* You may have to use the same strategy for Borland C (untested).
|
||||
* The __SC__ check is for Symantec.
|
||||
*/
|
||||
# define NO_MEMCPY
|
||||
#endif
|
||||
#if defined(STDC) && !defined(HAVE_MEMCPY) && !defined(NO_MEMCPY)
|
||||
# define HAVE_MEMCPY
|
||||
#endif
|
||||
#ifdef HAVE_MEMCPY
|
||||
# ifdef SMALL_MEDIUM /* MSDOS small or medium model */
|
||||
# define zmemcpy _fmemcpy
|
||||
# define zmemcmp _fmemcmp
|
||||
# define zmemzero(dest, len) _fmemset(dest, 0, len)
|
||||
# else
|
||||
# define zmemcpy memcpy
|
||||
# define zmemcmp memcmp
|
||||
# define zmemzero(dest, len) memset(dest, 0, len)
|
||||
# endif
|
||||
#else
|
||||
extern void zmemcpy OF((Bytef* dest, const Bytef* source, uInt len));
|
||||
extern int zmemcmp OF((const Bytef* s1, const Bytef* s2, uInt len));
|
||||
extern void zmemzero OF((Bytef* dest, uInt len));
|
||||
#endif
|
||||
|
||||
/* Diagnostic functions */
|
||||
#ifdef DEBUG
|
||||
# include <stdio.h>
|
||||
extern int z_verbose;
|
||||
extern void z_error OF((char *m));
|
||||
# define Assert(cond,msg) {if(!(cond)) z_error(msg);}
|
||||
# define Trace(x) {if (z_verbose>=0) fprintf x ;}
|
||||
# define Tracev(x) {if (z_verbose>0) fprintf x ;}
|
||||
# define Tracevv(x) {if (z_verbose>1) fprintf x ;}
|
||||
# define Tracec(c,x) {if (z_verbose>0 && (c)) fprintf x ;}
|
||||
# define Tracecv(c,x) {if (z_verbose>1 && (c)) fprintf x ;}
|
||||
#else
|
||||
# define Assert(cond,msg)
|
||||
# define Trace(x)
|
||||
# define Tracev(x)
|
||||
# define Tracevv(x)
|
||||
# define Tracec(c,x)
|
||||
# define Tracecv(c,x)
|
||||
#endif
|
||||
|
||||
|
||||
typedef uLong (ZEXPORT *check_func) OF((uLong check, const Bytef *buf,
|
||||
uInt len));
|
||||
voidpf zcalloc OF((voidpf opaque, unsigned items, unsigned size));
|
||||
void zcfree OF((voidpf opaque, voidpf ptr));
|
||||
|
||||
#define ZALLOC(strm, items, size) \
|
||||
(*((strm)->zalloc))((strm)->opaque, (items), (size))
|
||||
#define ZFREE(strm, addr) (*((strm)->zfree))((strm)->opaque, (voidpf)(addr))
|
||||
#define TRY_FREE(s, p) {if (p) ZFREE(s, p);}
|
||||
|
||||
#endif /* _Z_UTIL_H */
|
|
@ -66,14 +66,14 @@
|
|||
(x-label "X axis")
|
||||
(y-label "Y axis")
|
||||
(title "")
|
||||
(device 'png)
|
||||
(device 'dc)
|
||||
(fgcolor '( 0 0 0))
|
||||
(bgcolor '(255 255 255))
|
||||
(lncolor '(255 0 0 )))
|
||||
|
||||
(define bitmap #f)
|
||||
(define x-size 400)
|
||||
(define y-size 300)
|
||||
(define bitmap (make-bitmap width height))
|
||||
|
||||
(inherit
|
||||
set-bitmap
|
||||
|
@ -118,44 +118,48 @@
|
|||
; does housekeeping/setup for plplot
|
||||
(define (start-plot)
|
||||
(cond
|
||||
[(eq? device 'png)
|
||||
(set! bitmap (if out-file
|
||||
(build-path out-file)
|
||||
(make-temporary-file)))
|
||||
[(eq? device 'dc)
|
||||
(init-colors)
|
||||
(pl-setup-page width height)
|
||||
(pl-set-device "png")
|
||||
(pl-set-output-file (path->string bitmap))
|
||||
(pl-init-plot)]
|
||||
; [(eq? device 'mem)
|
||||
; (init-colors)
|
||||
; (set! bitmap (make-u8vector (* x-size y-size 4) 255))
|
||||
; (pl-setup-memory x-size y-size bitmap)
|
||||
; (pl-set-device "mem")
|
||||
; (pl-init-plot)]
|
||||
(pl-set-device "dc")
|
||||
(let ([dev (pl-init-plot)])
|
||||
(init-dev! dev (let ([dc (make-object bitmap-dc% bitmap)])
|
||||
(send dc set-origin 0 height)
|
||||
(send dc set-scale 1 -1)
|
||||
(send dc set-smoothing 'aligned)
|
||||
(new (class object%
|
||||
(define/public (draw-line x1 y1 x2 y2)
|
||||
(send dc draw-line x1 y1 x2 y2))
|
||||
(define/public (draw-lines points)
|
||||
(send dc draw-lines points))
|
||||
(define/public (draw-polygon points)
|
||||
(send dc draw-polygon points))
|
||||
(define/public (set-width n)
|
||||
(send dc set-pen (send (send dc get-pen) get-color) n 'solid))
|
||||
(define/public (set-index-color i)
|
||||
(let ([color (make-object color% (symbol->string (car (list-ref colors i))))])
|
||||
(send dc set-pen color (send (send dc get-pen) get-width) 'solid)
|
||||
(send dc set-brush color 'solid)))
|
||||
(define/public (set-rgb-color r g b)
|
||||
(let ([color (make-object color% r g b)])
|
||||
(send dc set-pen color (send (send dc get-pen) get-width) 'solid)
|
||||
(send dc set-brush color 'solid)))
|
||||
(define/public (start-page) (void))
|
||||
(define/public (end-page) (void))
|
||||
(define/public (end-doc)
|
||||
(send dc set-bitmap #f))
|
||||
(super-new))))))]
|
||||
[else
|
||||
(error "Incorrect device specified")]))
|
||||
|
||||
; finish the plot.. loads the file
|
||||
(define (finish-plot)
|
||||
(cond
|
||||
[(eq? device 'png)
|
||||
[(eq? device 'dc)
|
||||
(pl-finish-plot)
|
||||
(load-file bitmap)
|
||||
(or out-file (delete-file bitmap))]
|
||||
; [(eq? device 'mem)
|
||||
; (pl-finish-plot)
|
||||
; (set-bitmap (bits->bitmap-dc% bitmap))]
|
||||
(set-bitmap bitmap)]
|
||||
[else
|
||||
(error "Incorrect device specified")]))
|
||||
|
||||
;(define (bits->bitmap-dc% bitmap)
|
||||
; (let ((bmdc (instantiate bitmap-dc% () (bitmap (make-object bitmap% x-size y-size #f))))
|
||||
; (result-string (u8vec->scheme-string bitmap)))
|
||||
; (send bmdc set-argb-pixels 0 0 x-size y-size result-string)
|
||||
; (begin0
|
||||
; (send bmdc get-bitmap)
|
||||
; (send bmdc set-bitmap #f))))
|
||||
|
||||
(super-instantiate ())))
|
||||
|
||||
|
|
|
@ -31,20 +31,28 @@ all:
|
|||
3m:
|
||||
cd racket; $(MAKE) 3m
|
||||
$(MAKE) @MAKE_GRACKET@-3m
|
||||
$(MAKE) @MAKE_PLOT@-3m
|
||||
|
||||
gracket-3m:
|
||||
cd gracket; $(MAKE) 3m
|
||||
|
||||
plot-3m:
|
||||
cd plot; $(MAKE) 3m
|
||||
|
||||
no-3m:
|
||||
$(NOOP)
|
||||
|
||||
cgc:
|
||||
cd racket; $(MAKE) cgc
|
||||
$(MAKE) @MAKE_GRACKET@-cgc
|
||||
$(MAKE) @MAKE_PLOT@-cgc
|
||||
|
||||
gracket-cgc:
|
||||
cd gracket; $(MAKE) cgc
|
||||
|
||||
plot-cgc:
|
||||
cd plot; $(MAKE) cgc
|
||||
|
||||
no-cgc:
|
||||
$(NOOP)
|
||||
|
||||
|
@ -76,6 +84,7 @@ install-common-first:
|
|||
mkdir -p $(ALLDIRINFO)
|
||||
|
||||
install-common-middle:
|
||||
$(MAKE) install-@MAKE_PLOT@
|
||||
$(MAKE) @MAKE_COPYTREE@-run
|
||||
$(MAKE) install-@MAKE_GRACKET@-post-collects
|
||||
$(MAKE) lib-finish
|
||||
|
@ -83,6 +92,12 @@ install-common-middle:
|
|||
install-common-last:
|
||||
$(MAKE) fix-paths
|
||||
|
||||
install-plot:
|
||||
cd plot; $(MAKE) install
|
||||
|
||||
install-no:
|
||||
$(NOOP)
|
||||
|
||||
lib-finish:
|
||||
@LIBFINISH@ "$(libdir)"
|
||||
|
||||
|
@ -161,6 +176,7 @@ install-both-common:
|
|||
$(MAKE) install-common-first
|
||||
cd racket; $(MAKE) install-both
|
||||
$(MAKE) install-@MAKE_GRACKET@-both
|
||||
$(MAKE) install-@MAKE_PLOT@-both
|
||||
$(MAKE) install-common-middle
|
||||
|
||||
install-both:
|
||||
|
|
32
src/configure
vendored
32
src/configure
vendored
|
@ -703,6 +703,7 @@ FRAMEWORK_REL_INSTALL
|
|||
FRAMEWORK_PREFIX
|
||||
INSTALL_ORIG_TREE
|
||||
EXE_SUFFIX
|
||||
SO_SUFFIX
|
||||
MZRT_CGC_FLAGS
|
||||
LIBATOM
|
||||
LIBSFX
|
||||
|
@ -712,6 +713,7 @@ ICP
|
|||
MRLIBINSTALL
|
||||
LIBFINISH
|
||||
MAKE_GRACKET
|
||||
MAKE_PLOT
|
||||
MAKE_WBUILD
|
||||
MAKE_COPYTREE
|
||||
MAKE_FINISH
|
||||
|
@ -1322,6 +1324,7 @@ Optional Features:
|
|||
--disable-FEATURE do not include FEATURE (same as --enable-FEATURE=no)
|
||||
--enable-FEATURE[=ARG] include FEATURE [ARG=yes]
|
||||
--enable-gracket compile GRacket as well as Racket (enabled by default)
|
||||
--enable-plot compile plot libraries (enabled by default)
|
||||
--enable-docs build docs on install (enabled by default)
|
||||
--enable-shared create shared libraries
|
||||
--enable-dynlib same as --enable-shared
|
||||
|
@ -1806,6 +1809,13 @@ else
|
|||
enable_gracket=yes
|
||||
fi
|
||||
|
||||
# Check whether --enable-plot was given.
|
||||
if test "${enable_plot+set}" = set; then
|
||||
enableval=$enable_plot;
|
||||
else
|
||||
enable_plot=yes
|
||||
fi
|
||||
|
||||
# Check whether --enable-docs was given.
|
||||
if test "${enable_docs+set}" = set; then
|
||||
enableval=$enable_docs;
|
||||
|
@ -2195,6 +2205,7 @@ show_explicitly_enabled "${enable_xonx}" "X-on-X"
|
|||
show_explicitly_enabled "${enable_shared}" "Shared libraries"
|
||||
|
||||
show_explicitly_disabled "${enable_gracket}" GRacket
|
||||
show_explicitly_disabled "${enable_plot}" Plot
|
||||
|
||||
if test "$LIBTOOLPROG" != "" ; then
|
||||
echo "=== Libtool program: $LIBTOOLPROG"
|
||||
|
@ -2266,6 +2277,7 @@ ar_libtool_no_undefined=""
|
|||
LIBRACKET_DEP=""
|
||||
|
||||
EXE_SUFFIX=
|
||||
SO_SUFFIX=.so
|
||||
|
||||
MMM=3m
|
||||
MMM_INSTALLED=
|
||||
|
@ -5297,9 +5309,7 @@ case $OS in
|
|||
|
||||
STRIP_DEBUG="/usr/bin/strip -S"
|
||||
|
||||
# zlib comes with the OS
|
||||
ZLIB_A=""
|
||||
ZLIB_INC=""
|
||||
SO_SUFFIX=.dylib
|
||||
|
||||
GC_THREADS_FLAG="-DGC_DARWIN_THREADS"
|
||||
|
||||
|
@ -9185,6 +9195,8 @@ LIBS="$LIBS $EXTRALIBS"
|
|||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
@ -9256,6 +9268,14 @@ fi
|
|||
makefiles="$makefiles foreign/Makefile"
|
||||
ac_configure_args="$ac_configure_args$SUB_CONFIGURE_EXTRAS"
|
||||
|
||||
if test "${enable_plot}" = "yes" ; then
|
||||
makefiles="$makefiles
|
||||
plot/Makefile"
|
||||
MAKE_PLOT=plot
|
||||
else
|
||||
MAKE_PLOT=no
|
||||
fi
|
||||
|
||||
if test "${enable_gracket}" = "yes" ; then
|
||||
makefiles="$makefiles
|
||||
gracket/Makefile
|
||||
|
@ -9968,6 +9988,7 @@ FRAMEWORK_REL_INSTALL!$FRAMEWORK_REL_INSTALL$ac_delim
|
|||
FRAMEWORK_PREFIX!$FRAMEWORK_PREFIX$ac_delim
|
||||
INSTALL_ORIG_TREE!$INSTALL_ORIG_TREE$ac_delim
|
||||
EXE_SUFFIX!$EXE_SUFFIX$ac_delim
|
||||
SO_SUFFIX!$SO_SUFFIX$ac_delim
|
||||
MZRT_CGC_FLAGS!$MZRT_CGC_FLAGS$ac_delim
|
||||
LIBATOM!$LIBATOM$ac_delim
|
||||
LIBSFX!$LIBSFX$ac_delim
|
||||
|
@ -9975,7 +9996,6 @@ WXLIBS!$WXLIBS$ac_delim
|
|||
WXVARIANT!$WXVARIANT$ac_delim
|
||||
ICP!$ICP$ac_delim
|
||||
MRLIBINSTALL!$MRLIBINSTALL$ac_delim
|
||||
LIBFINISH!$LIBFINISH$ac_delim
|
||||
_ACEOF
|
||||
|
||||
if test `sed -n "s/.*$ac_delim\$/X/p" conf$$subs.sed | grep -c X` = 97; then
|
||||
|
@ -10017,7 +10037,9 @@ _ACEOF
|
|||
ac_delim='%!_!# '
|
||||
for ac_last_try in false false false false false :; do
|
||||
cat >conf$$subs.sed <<_ACEOF
|
||||
LIBFINISH!$LIBFINISH$ac_delim
|
||||
MAKE_GRACKET!$MAKE_GRACKET$ac_delim
|
||||
MAKE_PLOT!$MAKE_PLOT$ac_delim
|
||||
MAKE_WBUILD!$MAKE_WBUILD$ac_delim
|
||||
MAKE_COPYTREE!$MAKE_COPYTREE$ac_delim
|
||||
MAKE_FINISH!$MAKE_FINISH$ac_delim
|
||||
|
@ -10052,7 +10074,7 @@ LIBOBJS!$LIBOBJS$ac_delim
|
|||
LTLIBOBJS!$LTLIBOBJS$ac_delim
|
||||
_ACEOF
|
||||
|
||||
if test `sed -n "s/.*$ac_delim\$/X/p" conf$$subs.sed | grep -c X` = 33; then
|
||||
if test `sed -n "s/.*$ac_delim\$/X/p" conf$$subs.sed | grep -c X` = 35; then
|
||||
break
|
||||
elif $ac_last_try; then
|
||||
{ { echo "$as_me:$LINENO: error: could not make $CONFIG_STATUS" >&5
|
||||
|
|
58
src/plot/Makefile.in
Normal file
58
src/plot/Makefile.in
Normal file
|
@ -0,0 +1,58 @@
|
|||
|
||||
srcdir = @srcdir@
|
||||
prefix = @prefix@
|
||||
exec_prefix = @exec_prefix@
|
||||
bindir = @bindir@
|
||||
libdir = @libdir@
|
||||
libpltdir = @libpltdir@
|
||||
collectsdir = @collectsdir@
|
||||
builddir = @builddir@
|
||||
|
||||
ICP=@ICP@
|
||||
|
||||
PLPLOT_SRCS = $(srcdir)/plplot/dc_drv.c \
|
||||
$(srcdir)/plplot/plcont.c \
|
||||
$(srcdir)/plplot/plfill.c \
|
||||
$(srcdir)/plplot/plmap.c \
|
||||
$(srcdir)/plplot/plshade.c \
|
||||
$(srcdir)/plplot/plwind.c \
|
||||
$(srcdir)/plplot/pdfutils.c \
|
||||
$(srcdir)/plplot/plcore.c \
|
||||
$(srcdir)/plplot/plgridd.c \
|
||||
$(srcdir)/plplot/plmeta.c \
|
||||
$(srcdir)/plplot/plstripc.c \
|
||||
$(srcdir)/plplot/plargs.c \
|
||||
$(srcdir)/plplot/plctrl.c \
|
||||
$(srcdir)/plplot/plhist.c \
|
||||
$(srcdir)/plplot/plot3d.c \
|
||||
$(srcdir)/plplot/plsym.c \
|
||||
$(srcdir)/plplot/plbox.c \
|
||||
$(srcdir)/plplot/plcvt.c \
|
||||
$(srcdir)/plplot/plimage.c \
|
||||
$(srcdir)/plplot/plpage.c \
|
||||
$(srcdir)/plplot/pltick.c \
|
||||
$(srcdir)/plplot/plbuf.c \
|
||||
$(srcdir)/plplot/pldtik.c \
|
||||
$(srcdir)/plplot/plline.c \
|
||||
$(srcdir)/plplot/plsdef.c \
|
||||
$(srcdir)/plplot/plvpor.c
|
||||
|
||||
FIT_SRCS = $(srcdir)/fit/fit.c $(srcdir)/fit/matrix.c
|
||||
|
||||
XCOLLECTS = -X ../racket/gc2/xform-collects
|
||||
|
||||
CC = @CC@
|
||||
|
||||
# In 3m mode, we can reply on an xform-collects setup
|
||||
3m:
|
||||
env CC="$(CC)" LD="@MZLINKER@" ../racket/racket3m $(XCOLLECTS) $(srcdir)/build.rkt "libplplot" $(PLPLOT_SRCS)
|
||||
env CC="$(CC)" LD="@MZLINKER@" ../racket/racket3m $(XCOLLECTS) $(srcdir)/build.rkt "libfit" $(FIT_SRCS)
|
||||
|
||||
# In just-cgc mode, it's slow to load build.rkt:
|
||||
cgc:
|
||||
env CC="$(CC)" LD="@MZLINKER@" ../racket/racketcgc -c $(srcdir)/build.rkt "libplplot" $(PLPLOT_SRCS)
|
||||
env CC="$(CC)" LD="@MZLINKER@" ../racket/racketcgc -c $(srcdir)/build.rkt "libfit" $(FIT_SRCS)
|
||||
|
||||
install:
|
||||
cd ..; $(ICP) plot/libplplot@SO_SUFFIX@ "$(DESTDIR)$(libpltdir)/libplplot@SO_SUFFIX@"
|
||||
cd ..; $(ICP) plot/libfit@SO_SUFFIX@ "$(DESTDIR)$(libpltdir)/libfit@SO_SUFFIX@"
|
Some files were not shown because too many files have changed in this diff Show More
Loading…
Reference in New Issue
Block a user