⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 jdapimin.pas

📁 用pascal寫的jpeg codec, 測試過的
💻 PAS
📖 第 1 页 / 共 2 页
字号:
Unit JdAPImin;

{$N+}

{ This file contains application interface code for the decompression half
  of the JPEG library.  These are the "minimum" API routines that may be
  needed in either the normal full-decompression case or the
  transcoding-only case.

  Most of the routines intended to be called directly by an application
  are in this file or in jdapistd.c.  But also see jcomapi.c for routines
  shared by compression and decompression, and jdtrans.c for the transcoding
  case. }

{ Original : jdapimin.c ;  Copyright (C) 1994-1996, Thomas G. Lane. }

interface

{$I jconfig.inc}

uses
  jmorecfg,
  jinclude,
  jdeferr,
  jerror,
  jpeglib,
  jmemmgr, jdmarker, jdinput, jcomapi;

{ Nomssi }
procedure jpeg_create_decompress(cinfo : j_decompress_ptr);

{ Initialization of a JPEG decompression object.
  The error manager must already be set up (in case memory manager fails). }

{GLOBAL}
procedure jpeg_CreateDecompress (cinfo : j_decompress_ptr;
                                 version : int;
                                 structsize : size_t);

{ Destruction of a JPEG decompression object }

{GLOBAL}
procedure jpeg_destroy_decompress (cinfo : j_decompress_ptr);

{ Install a special processing method for COM or APPn markers. }

{GLOBAL}
procedure jpeg_set_marker_processor (cinfo : j_decompress_ptr;
                                     marker_code : int;
			             routine : jpeg_marker_parser_method);

{ Decompression startup: read start of JPEG datastream to see what's there.
  Need only initialize JPEG object and supply a data source before calling.

  This routine will read as far as the first SOS marker (ie, actual start of
  compressed data), and will save all tables and parameters in the JPEG
  object.  It will also initialize the decompression parameters to default
  values, and finally return JPEG_HEADER_OK.  On return, the application may
  adjust the decompression parameters and then call jpeg_start_decompress.
  (Or, if the application only wanted to determine the image parameters,
  the data need not be decompressed.  In that case, call jpeg_abort or
  jpeg_destroy to release any temporary space.)
  If an abbreviated (tables only) datastream is presented, the routine will
  return JPEG_HEADER_TABLES_ONLY upon reaching EOI.  The application may then
  re-use the JPEG object to read the abbreviated image datastream(s).
  It is unnecessary (but OK) to call jpeg_abort in this case.
  The JPEG_SUSPENDED return code only occurs if the data source module
  requests suspension of the decompressor.  In this case the application
  should load more source data and then re-call jpeg_read_header to resume
  processing.
  If a non-suspending data source is used and require_image is TRUE, then the
  return code need not be inspected since only JPEG_HEADER_OK is possible.

  This routine is now just a front end to jpeg_consume_input, with some
  extra error checking. }

{GLOBAL}
function jpeg_read_header (cinfo : j_decompress_ptr;
                           require_image : boolean) : int;

{ Consume data in advance of what the decompressor requires.
  This can be called at any time once the decompressor object has
  been created and a data source has been set up.

  This routine is essentially a state machine that handles a couple
  of critical state-transition actions, namely initial setup and
  transition from header scanning to ready-for-start_decompress.
  All the actual input is done via the input controller's consume_input
  method. }

{GLOBAL}
function jpeg_consume_input (cinfo : j_decompress_ptr) : int;

{ Have we finished reading the input file? }

{GLOBAL}
function jpeg_input_complete (cinfo : j_decompress_ptr) : boolean;

{ Is there more than one scan? }

{GLOBAL}
function jpeg_has_multiple_scans (cinfo : j_decompress_ptr) : boolean;


{ Finish JPEG decompression.

  This will normally just verify the file trailer and release temp storage.

  Returns FALSE if suspended.  The return value need be inspected only if
  a suspending data source is used. }

{GLOBAL}
function jpeg_finish_decompress (cinfo : j_decompress_ptr) : boolean;

implementation

procedure jpeg_create_decompress(cinfo : j_decompress_ptr);
begin
  jpeg_CreateDecompress(cinfo, JPEG_LIB_VERSION,
    size_t(sizeof(jpeg_decompress_struct)));
end;

{ Initialization of a JPEG decompression object.
  The error manager must already be set up (in case memory manager fails). }

{GLOBAL}
procedure jpeg_CreateDecompress (cinfo : j_decompress_ptr;
                                 version : int;
                                 structsize : size_t);
var
  i : int;
var
  err : jpeg_error_mgr_ptr;
begin
  { Guard against version mismatches between library and caller. }
  cinfo^.mem := NIL;		{ so jpeg_destroy knows mem mgr not called }
  if (version <> JPEG_LIB_VERSION) then
    ERREXIT2(j_common_ptr(cinfo), JERR_BAD_LIB_VERSION, JPEG_LIB_VERSION, version);
  if (structsize <> SIZEOF(jpeg_decompress_struct)) then
    ERREXIT2(j_common_ptr(cinfo), JERR_BAD_STRUCT_SIZE,
	     int(SIZEOF(jpeg_decompress_struct)), int(structsize));

  { For debugging purposes, zero the whole master structure.
    But error manager pointer is already there, so save and restore it. }
  begin
    err := cinfo^.err;
    MEMZERO(j_common_ptr(cinfo), SIZEOF(jpeg_decompress_struct));
    cinfo^.err := err;
  end;
  cinfo^.is_decompressor := TRUE;

  { Initialize a memory manager instance for this object }
  jinit_memory_mgr(j_common_ptr(cinfo));

  { Zero out pointers to permanent structures. }
  cinfo^.progress := NIL;
  cinfo^.src := NIL;

  for i := 0 to pred(NUM_QUANT_TBLS) do
    cinfo^.quant_tbl_ptrs[i] := NIL;

  for i := 0 to pred(NUM_HUFF_TBLS) do
  begin
    cinfo^.dc_huff_tbl_ptrs[i] := NIL;
    cinfo^.ac_huff_tbl_ptrs[i] := NIL;
  end;

  { Initialize marker processor so application can override methods
    for COM, APPn markers before calling jpeg_read_header.  }
  jinit_marker_reader(cinfo);

  { And initialize the overall input controller. }
  jinit_input_controller(cinfo);

  { OK, I'm ready }
  cinfo^.global_state := DSTATE_START;
end;


{ Destruction of a JPEG decompression object }

{GLOBAL}
procedure jpeg_destroy_decompress (cinfo : j_decompress_ptr);
begin
  jpeg_destroy(j_common_ptr(cinfo)); { use common routine }
end;


{ Abort processing of a JPEG decompression operation,
  but don't destroy the object itself. }

{GLOBAL}
procedure jpeg_abort_decompress (cinfo : j_decompress_ptr);
begin
  jpeg_abort(j_common_ptr(cinfo)); { use common routine }
end;


{ Install a special processing method for COM or APPn markers. }

{GLOBAL}
procedure jpeg_set_marker_processor (cinfo : j_decompress_ptr;
                                     marker_code : int;
			             routine : jpeg_marker_parser_method);
begin
  if (marker_code = JPEG_COM) then
    cinfo^.marker^.process_COM := routine
  else
    if (marker_code >= JPEG_APP0) and (marker_code <= JPEG_APP0+15) then
      cinfo^.marker^.process_APPn[marker_code-JPEG_APP0] := routine
    else
      ERREXIT1(j_common_ptr(cinfo), JERR_UNKNOWN_MARKER, marker_code);
end;


{ Set default decompression parameters. }

{LOCAL}
procedure default_decompress_parms (cinfo : j_decompress_ptr);
var
  cid0 : int;
  cid1 : int;
  cid2 : int;
begin
  { Guess the input colorspace, and set output colorspace accordingly. }
  { (Wish JPEG committee had provided a real way to specify this...) }
  { Note application may override our guesses. }
  case (cinfo^.num_components) of
  1: begin
       cinfo^.jpeg_color_space := JCS_GRAYSCALE;
       cinfo^.out_color_space := JCS_GRAYSCALE;
     end;

  3: begin
       if (cinfo^.saw_JFIF_marker) then
       begin
         cinfo^.jpeg_color_space := JCS_YCbCr; { JFIF implies YCbCr }
       end
       else
         if (cinfo^.saw_Adobe_marker) then
         begin
           case (cinfo^.Adobe_transform) of
           0: cinfo^.jpeg_color_space := JCS_RGB;
           1: cinfo^.jpeg_color_space := JCS_YCbCr;
           else
             begin
	       WARNMS1(j_common_ptr(cinfo), JWRN_ADOBE_XFORM, cinfo^.Adobe_transform);
               cinfo^.jpeg_color_space := JCS_YCbCr; { assume it's YCbCr }
             end;
           end;
         end
         else
         begin
           { Saw no special markers, try to guess from the component IDs }
           cid0 := jpeg_component_info_list_ptr(cinfo^.comp_info)^[0].component_id;
           cid1 := jpeg_component_info_list_ptr(cinfo^.comp_info)^[1].component_id;
           cid2 := jpeg_component_info_list_ptr(cinfo^.comp_info)^[2].component_id;

           if (cid0 = 1) and (cid1 = 2) and (cid2 = 3) then
	     cinfo^.jpeg_color_space := JCS_YCbCr { assume JFIF w/out marker }

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -