1 /*M* 2 // 3 // 4 // INTEL CORPORATION PROPRIETARY INFORMATION 5 // This software is supplied under the terms of a license agreement or 6 // nondisclosure agreement with Intel Corporation and may not be copied 7 // or disclosed except in accordance with the terms of that agreement. 8 // Copyright (c) 1998 Intel Corporation. All Rights Reserved. 9 // 10 // 11 // File: 12 // ijl.h 13 // 14 // Purpose: 15 // IJL Common Header File 16 // This file contains: definitions for data types, data 17 // structures, error codes, and function prototypes used 18 // in the Intel(R) JPEG Library (IJL). 19 // 20 // Version: 21 // 1.0 beta 1 22 // 23 *M*/ 24 25 #ifndef __IJL_H__ 26 #define __IJL_H__ 27 28 29 #if defined( __cplusplus ) 30 extern "C" { 31 #endif 32 33 34 #ifndef IJL_ALL_WARNINGS 35 36 #if _MSC_VER >= 1000 37 38 /* nonstandard extension used : nameless struct/union */ 39 #pragma warning(disable : 4201) 40 /* nonstandard extension used : bit field types other than int */ 41 #pragma warning(disable : 4214) 42 /* unreferenced inline function has been removed */ 43 #pragma warning(disable : 4514) 44 /* named type definition in parentheses */ 45 #pragma warning(disable : 4115) 46 47 #endif /* _MSC_VER >= 1000 */ 48 49 #endif /* IJL_ALL_WARNINGS */ 50 51 52 53 54 #define _X86_ 55 #define WIN32_LEAN_AND_MEAN 56 #include <windows.h> 57 58 59 #ifdef _MSC_VER 60 # pragma pack (8) 61 #endif 62 63 64 /* ///////////////////////////////////////////////////////////////////////// 65 // Macros/Constants */ 66 67 #define IJL_NONE 0 68 #define IJL_OTHER 255 69 #define JBUFSIZE 4096 // Size of file I/O buffer (4K). 70 71 72 #ifndef INT64 73 #define INT64 __int64 74 #endif 75 #ifndef UINT64 76 #define UINT64 unsigned INT64 77 #endif 78 79 80 #if defined( _IJL_STDIMP_ ) 81 82 # define IJLAPI(type,name,arg) \ 83 extern type WINAPI name arg 84 85 #else 86 87 # if !defined( _IJL_API_ ) 88 89 # define IJLAPI(type,name,arg) \ 90 extern __declspec(dllimport) type WINAPI name arg 91 92 # else 93 94 # define IJLAPI(type,name,arg) \ 95 extern __declspec(dllexport) type WINAPI name arg 96 97 # endif // _IJL_API_ 98 99 #endif //_IJL_STDIMP_ 100 101 102 103 104 /*D* 105 //////////////////////////////////////////////////////////////////////////// 106 // Name: IJLibVersion 107 // 108 // Purpose: Stores library version info. 109 // 110 // Context: 111 // 112 // Example: 113 // major - 1 114 // minor - 0 115 // build - 1 116 // Name - "ijl10.dll" 117 // Version - "1.0.1 Beta1" 118 // InternalVersion - "1.0.1.1" 119 // BuildDate - "Sep 22 1998" 120 // CallConv - "DLL" 121 // 122 //////////////////////////////////////////////////////////////////////////// 123 *D*/ 124 125 typedef struct _IJLibVersion 126 { 127 int major; 128 int minor; 129 int build; 130 LPCTSTR Name; 131 LPCTSTR Version; 132 LPCTSTR InternalVersion; 133 LPCTSTR BuildDate; 134 LPCTSTR CallConv; 135 136 } IJLibVersion; 137 138 139 /*D* 140 //////////////////////////////////////////////////////////////////////////// 141 // Name: IJLIOTYPE 142 // 143 // Purpose: Possible types of data read/write/other operations to be 144 // performed by the functions IJL_Read and IJL_Write. 145 // 146 // See the Developer's Guide for details on appropriate usage. 147 // 148 // Fields: 149 // 150 // IJL_JFILE_XXXXXXX Indicates JPEG data in a stdio file. 151 // 152 // IJL_JBUFF_XXXXXXX Indicates JPEG data in an addressable buffer. 153 // 154 //////////////////////////////////////////////////////////////////////////// 155 *D*/ 156 157 typedef enum 158 { 159 IJL_SETUP = -1, 160 161 162 // Read JPEG parameters (i.e., height, width, channels, 163 // sampling, etc.) from a JPEG bit stream. 164 IJL_JFILE_READPARAMS = 0, 165 IJL_JBUFF_READPARAMS = 1, 166 167 // Read a JPEG Interchange Format image. 168 IJL_JFILE_READWHOLEIMAGE = 2, 169 IJL_JBUFF_READWHOLEIMAGE = 3, 170 171 // Read JPEG tables from a JPEG Abbreviated Format bit stream. 172 IJL_JFILE_READHEADER = 4, 173 IJL_JBUFF_READHEADER = 5, 174 175 // Read image info from a JPEG Abbreviated Format bit stream. 176 IJL_JFILE_READENTROPY = 6, 177 IJL_JBUFF_READENTROPY = 7, 178 179 // Write an entire JFIF bit stream. 180 IJL_JFILE_WRITEWHOLEIMAGE = 8, 181 IJL_JBUFF_WRITEWHOLEIMAGE = 9, 182 183 // Write a JPEG Abbreviated Format bit stream. 184 IJL_JFILE_WRITEHEADER = 10, 185 IJL_JBUFF_WRITEHEADER = 11, 186 187 // Write image info to a JPEG Abbreviated Format bit stream. 188 IJL_JFILE_WRITEENTROPY = 12, 189 IJL_JBUFF_WRITEENTROPY = 13, 190 191 192 // Scaled Decoding Options: 193 194 // Reads a JPEG image scaled to 1/2 size. 195 IJL_JFILE_READONEHALF = 14, 196 IJL_JBUFF_READONEHALF = 15, 197 198 // Reads a JPEG image scaled to 1/4 size. 199 IJL_JFILE_READONEQUARTER = 16, 200 IJL_JBUFF_READONEQUARTER = 17, 201 202 // Reads a JPEG image scaled to 1/8 size. 203 IJL_JFILE_READONEEIGHTH = 18, 204 IJL_JBUFF_READONEEIGHTH = 19, 205 206 // Reads an embedded thumbnail from a JFIF bit stream. 207 IJL_JFILE_READTHUMBNAIL = 20, 208 IJL_JBUFF_READTHUMBNAIL = 21 209 210 } IJLIOTYPE; 211 212 213 /*D* 214 //////////////////////////////////////////////////////////////////////////// 215 // Name: IJL_COLOR 216 // 217 // Purpose: Possible color space formats. 218 // 219 // Note these formats do *not* necessarily denote 220 // the number of channels in the color space. 221 // There exists separate "channel" fields in the 222 // JPEG_CORE_PROPERTIES data structure specifically 223 // for indicating the number of channels in the 224 // JPEG and/or DIB color spaces. 225 // 226 // See the Developer's Guide for details on appropriate usage. 227 // 228 //////////////////////////////////////////////////////////////////////////// 229 *D*/ 230 231 typedef enum 232 { 233 IJL_RGB = 1, // Red-Green-Blue color space. 234 IJL_BGR = 2, // Reversed channel ordering from IJL_RGB. 235 IJL_YCBCR = 3, // Luminance-Chrominance color space as defined 236 // by CCIR Recommendation 601. 237 IJL_G = 4, // Grayscale color space. 238 IJL_RGBA_FPX = 5, // FlashPix RGB 4 channel color space that 239 // has pre-multiplied opacity. 240 IJL_YCBCRA_FPX = 6 // FlashPix YCbCr 4 channel color space that 241 // has pre-multiplied opacity. 242 243 // IJL_OTHER // Some other color space not defined by the IJL. 244 // (This means no color space conversion will 245 // be done by the IJL.) 246 247 } IJL_COLOR; 248 249 250 /*D* 251 //////////////////////////////////////////////////////////////////////////// 252 // Name: IJL_JPGSUBSAMPLING 253 // 254 // Purpose: Possible subsampling formats used in the JPEG. 255 // 256 // See the Developer's Guide for details on appropriate usage. 257 // 258 //////////////////////////////////////////////////////////////////////////// 259 *D*/ 260 261 typedef enum 262 { 263 IJL_411 = 1, // Valid on a JPEG w/ 3 channels. 264 IJL_422 = 2, // Valid on a JPEG w/ 3 channels. 265 266 IJL_4114 = 3, // Valid on a JPEG w/ 4 channels. 267 IJL_4224 = 4, // Valid on a JPEG w/ 4 channels. 268 269 // IJL_NONE = Corresponds to "No Subsampling". 270 // Valid on a JPEG w/ any number of channels. 271 272 // IJL_OTHER = Valid entry, but only used internally to the IJL. 273 274 } IJL_JPGSUBSAMPLING; 275 276 277 /*D* 278 //////////////////////////////////////////////////////////////////////////// 279 // Name: IJL_DIBSUBSAMPLING 280 // 281 // Purpose: Possible subsampling formats used in the DIB. 282 // 283 // See the Developer's Guide for details on appropriate usage. 284 // 285 //////////////////////////////////////////////////////////////////////////// 286 *D*/ 287 288 typedef enum 289 { 290 // IJL_NONE = Corresponds to "No Subsampling". 291 292 } IJL_DIBSUBSAMPLING; 293 294 295 /*D* 296 //////////////////////////////////////////////////////////////////////////// 297 // Name: HUFFMAN_TABLE 298 // 299 // Purpose: Stores Huffman table information in a fast-to-use format. 300 // 301 // Context: Used by Huffman encoder/decoder to access Huffman table 302 // data. Raw Huffman tables are formatted to fit this 303 // structure prior to use. 304 // 305 // Fields: 306 // huff_class 0 == DC Huffman or lossless table, 1 == AC table. 307 // ident Huffman table identifier, 0-3 valid (Extended Baseline). 308 // huffelem Huffman elements for codes <= 8 bits long; 309 // contains both zero run-length and symbol length in bits. 310 // huffval Huffman values for codes 9-16 bits in length. 311 // mincode Smallest Huffman code of length n. 312 // maxcode Largest Huffman code of length n. 313 // valptr Starting index into huffval[] for symbols of length k. 314 // 315 //////////////////////////////////////////////////////////////////////////// 316 *D*/ 317 318 typedef struct _HUFFMAN_TABLE 319 { 320 int huff_class; 321 int ident; 322 unsigned int huffelem[256]; 323 unsigned short huffval[256]; 324 unsigned short mincode[17]; 325 unsigned short maxcode[18]; 326 unsigned short valptr[17]; 327 328 } HUFFMAN_TABLE; 329 330 331 /*D* 332 //////////////////////////////////////////////////////////////////////////// 333 // Name: JPEGHuffTable 334 // 335 // Purpose: Stores pointers to JPEG-binary spec compliant 336 // Huffman table information. 337 // 338 // Context: Used by interface and table methods to specify encoder 339 // tables to generate and store JPEG images. 340 // 341 // Fields: 342 // bits Points to number of codes of length i (<=16 supported). 343 // vals Value associated with each Huffman code. 344 // hclass 0 == DC table, 1 == AC table. 345 // ident Specifies the identifier for this table. 346 // 0-3 for extended JPEG compliance. 347 // 348 //////////////////////////////////////////////////////////////////////////// 349 *D*/ 350 351 typedef struct 352 { 353 unsigned char* bits; 354 unsigned char* vals; 355 unsigned char hclass; 356 unsigned char ident; 357 358 } JPEGHuffTable; 359 360 361 /*D* 362 //////////////////////////////////////////////////////////////////////////// 363 // Name: QUANT_TABLE 364 // 365 // Purpose: Stores quantization table information in a 366 // fast-to-use format. 367 // 368 // Context: Used by quantizer/dequantizer to store formatted 369 // quantization tables. 370 // 371 // Fields: 372 // precision 0 => elements contains 8-bit elements, 373 // 1 => elements contains 16-bit elements. 374 // ident Table identifier (0-3). 375 // elements Pointer to 64 table elements + 16 extra elements to catch 376 // input data errors that may cause malfunction of the 377 // Huffman decoder. 378 // elarray Space for elements (see above) plus 8 bytes to align 379 // to a quadword boundary. 380 // 381 //////////////////////////////////////////////////////////////////////////// 382 *D*/ 383 384 typedef struct _QUANT_TABLE 385 { 386 int precision; 387 int ident; 388 short* elements; 389 short elarray [84]; 390 391 } QUANT_TABLE; 392 393 394 /*D* 395 //////////////////////////////////////////////////////////////////////////// 396 // Name: JPEGQuantTable 397 // 398 // Purpose: Stores pointers to JPEG binary spec compliant 399 // quantization table information. 400 // 401 // Context: Used by interface and table methods to specify encoder 402 // tables to generate and store JPEG images. 403 // 404 // Fields: 405 // quantizer Zig-zag order elements specifying quantization factors. 406 // ident Specifies identifier for this table. 407 // 0-3 valid for Extended Baseline JPEG compliance. 408 // 409 //////////////////////////////////////////////////////////////////////////// 410 *D*/ 411 412 typedef struct 413 { 414 unsigned char* quantizer; 415 unsigned char ident; 416 417 } JPEGQuantTable; 418 419 420 /*D* 421 //////////////////////////////////////////////////////////////////////////// 422 // Name: FRAME_COMPONENT 423 // 424 // Purpose: One frame-component structure is allocated per component 425 // in a frame. 426 // 427 // Context: Used by Huffman decoder to manage components. 428 // 429 // Fields: 430 // ident Component identifier. The tables use this ident to 431 // determine the correct table for each component. 432 // hsampling Horizontal subsampling factor for this component, 433 // 1-4 are legal. 434 // vsampling Vertical subsampling factor for this component, 435 // 1-4 are legal. 436 // quant_sel Quantization table selector. The quantization table 437 // used by this component is determined via this selector. 438 // 439 //////////////////////////////////////////////////////////////////////////// 440 *D*/ 441 442 typedef struct _FRAME_COMPONENT 443 { 444 int ident; 445 int hsampling; 446 int vsampling; 447 int quant_sel; 448 449 } FRAME_COMPONENT; 450 451 452 /*D* 453 //////////////////////////////////////////////////////////////////////////// 454 // Name: FRAME 455 // 456 // Purpose: Stores frame-specific data. 457 // 458 // Context: One Frame structure per image. 459 // 460 // Fields: 461 // precision Sample precision in bits. 462 // width Width of the source image in pixels. 463 // height Height of the source image in pixels. 464 // MCUheight Height of a frame MCU. 465 // MCUwidth Width of a frame MCU. 466 // max_hsampling Max horiz sampling ratio of any component in the frame. 467 // max_vsampling Max vert sampling ratio of any component in the frame. 468 // ncomps Number of components/channels in the frame. 469 // horMCU Number of horizontal MCUs in the frame. 470 // totalMCU Total number of MCUs in the frame. 471 // comps Array of 'ncomps' component descriptors. 472 // restart_interv Indicates number of MCUs after which to restart the 473 // entropy parameters. 474 // SeenAllDCScans Used when decoding Multiscan images to determine if 475 // all channels of an image have been decoded. 476 // SeenAllACScans (See SeenAllDCScans) 477 // 478 //////////////////////////////////////////////////////////////////////////// 479 *D*/ 480 481 typedef struct _FRAME 482 { 483 int precision; 484 int width; 485 int height; 486 int MCUheight; 487 int MCUwidth; 488 int max_hsampling; 489 int max_vsampling; 490 int ncomps; 491 int horMCU; 492 long totalMCU; 493 FRAME_COMPONENT* comps; 494 int restart_interv; 495 int SeenAllDCScans; 496 int SeenAllACScans; 497 498 } FRAME; 499 500 501 /*D* 502 //////////////////////////////////////////////////////////////////////////// 503 // Name: SCAN_COMPONENT 504 // 505 // Purpose: One scan-component structure is allocated per component 506 // of each scan in a frame. 507 // 508 // Context: Used by Huffman decoder to manage components within scans. 509 // 510 // Fields: 511 // comp Component number, index to the comps member of FRAME. 512 // hsampling Horizontal sampling factor. 513 // vsampling Vertical sampling factor. 514 // dc_table DC Huffman table pointer for this scan. 515 // ac_table AC Huffman table pointer for this scan. 516 // quant_table Quantization table pointer for this scan. 517 // 518 //////////////////////////////////////////////////////////////////////////// 519 *D*/ 520 521 typedef struct 522 { 523 int comp; 524 int hsampling; 525 int vsampling; 526 HUFFMAN_TABLE* dc_table; 527 HUFFMAN_TABLE* ac_table; 528 QUANT_TABLE* quant_table; 529 530 } SCAN_COMPONENT; 531 532 533 /*D* 534 //////////////////////////////////////////////////////////////////////////// 535 // Name: SCAN 536 // 537 // Purpose: One SCAN structure is allocated per scan in a frame. 538 // 539 // Context: Used by Huffman decoder to manage scans. 540 // 541 // Fields: 542 // ncomps Number of image components in a scan, 1-4 legal. 543 // gray_scale If TRUE, decode only the Y channel. 544 // start_spec Start coefficient of spectral or predictor selector. 545 // end_spec End coefficient of spectral selector. 546 // approx_high High bit position in successive approximation 547 // Progressive coding. 548 // approx_low Low bit position in successive approximation 549 // Progressive coding. 550 // restart_interv Restart interval, 0 if disabled. 551 // curxMCU Next horizontal MCU index to be processed after 552 // an interrupted SCAN. 553 // curyMCU Next vertical MCU index to be processed after 554 // an interrupted SCAN. 555 // dc_diff Array of DC predictor values for DPCM modes. 556 // comps Array of ncomps SCAN_COMPONENT component identifiers. 557 // 558 //////////////////////////////////////////////////////////////////////////// 559 *D*/ 560 561 typedef struct _SCAN 562 { 563 int ncomps; 564 int gray_scale; 565 int start_spec; 566 int end_spec; 567 int approx_high; 568 int approx_low; 569 UINT restart_interv; 570 DWORD curxMCU; 571 DWORD curyMCU; 572 int dc_diff[4]; 573 SCAN_COMPONENT* comps; 574 575 } SCAN; 576 577 578 /*D* 579 //////////////////////////////////////////////////////////////////////////// 580 // Name: DCTTYPE 581 // 582 // Purpose: Possible algorithms to be used to perform the discrete 583 // cosine transform (DCT). 584 // 585 // Fields: 586 // IJL_AAN The AAN (Arai, Agui, and Nakajima) algorithm from 587 // Trans. IEICE, vol. E 71(11), 1095-1097, Nov. 1988. 588 // 589 //////////////////////////////////////////////////////////////////////////// 590 *D*/ 591 592 typedef enum 593 { 594 IJL_AAN = 0 595 596 } DCTTYPE; 597 598 599 /*D* 600 //////////////////////////////////////////////////////////////////////////// 601 // Name: PROCESSOR_TYPE 602 // 603 // Purpose: Possible types of processors. 604 // Note that the enums are defined in ascending order 605 // depending upon their various IA32 instruction support. 606 // 607 // Fields: 608 // 609 // IJL_OTHER_PROC 610 // Does not support the CPUID instruction and 611 // assumes no Pentium(R) processor instructions. 612 // 613 // IJL_PENTIUM_PROC 614 // Corresponds to an Intel(R) Pentium(R) processor 615 // (or a 100% compatible) that supports the 616 // Pentium(R) processor instructions. 617 // 618 // IJL_PENTIUM_PRO_PROC 619 // Corresponds to an Intel(R) Pentium(R) Pro processor 620 // (or a 100% compatible) that supports the 621 // Pentium(R) Pro processor instructions. 622 // 623 // IJL_PENTIUM_PROC_MMX_TECH 624 // Corresponds to an Intel(R) Pentium(R) processor 625 // with MMX(TM) technology (or a 100% compatible) 626 // that supports the MMX(TM) instructions. 627 // 628 // IJL_PENTIUM_II_PROC 629 // Corresponds to an Intel(R) Pentium(R) II processor 630 // (or a 100% compatible) that supports both the 631 // Pentium(R) Pro processor instructions and the 632 // MMX(TM) instructions. 633 // 634 // Any additional processor types that support a superset 635 // of both the Pentium(R) Pro processor instructions and the 636 // MMX(TM) instructions should be given an enum value greater 637 // than IJL_PENTIUM_II_PROC. 638 // 639 //////////////////////////////////////////////////////////////////////////// 640 *D*/ 641 642 typedef enum 643 { 644 IJL_OTHER_PROC = 0, 645 IJL_PENTIUM_PROC = 1, 646 IJL_PENTIUM_PRO_PROC = 2, 647 IJL_PENTIUM_PROC_MMX_TECH = 3, 648 IJL_PENTIUM_II_PROC = 4 649 650 } PROCESSOR_TYPE; 651 652 653 /*D* 654 //////////////////////////////////////////////////////////////////////////// 655 // Name: ENTROPYSTRUCT 656 // 657 // Purpose: Stores the decoder state information necessary to "jump" 658 // to a particular MCU row in a compressed entropy stream. 659 // 660 // Context: Used to persist the decoder state within Decode_Scan when 661 // decoding using ROIs. 662 // 663 // Fields: 664 // offset Offset (in bytes) into the entropy stream 665 // from the beginning. 666 // dcval1 DC val at the beginning of the MCU row 667 // for component 1. 668 // dcval2 DC val at the beginning of the MCU row 669 // for component 2. 670 // dcval3 DC val at the beginning of the MCU row 671 // for component 3. 672 // dcval4 DC val at the beginning of the MCU row 673 // for component 4. 674 // bit_buffer_64 64-bit Huffman bit buffer. Stores current 675 // bit buffer at the start of a MCU row. 676 // Also used as a 32-bit buffer on 32-bit 677 // architectures. 678 // bitbuf_bits_valid Number of valid bits in the above bit buffer. 679 // unread_marker Have any markers been decoded but not 680 // processed at the beginning of a MCU row? 681 // This entry holds the unprocessed marker, or 682 // 0 if none. 683 // 684 //////////////////////////////////////////////////////////////////////////// 685 *D*/ 686 687 typedef struct 688 { 689 DWORD offset; 690 int dcval1; 691 int dcval2; 692 int dcval3; 693 int dcval4; 694 UINT64 bit_buffer_64; 695 int bitbuf_bits_valid; 696 BYTE unread_marker; 697 698 } ENTROPYSTRUCT; 699 700 701 /*D* 702 //////////////////////////////////////////////////////////////////////////// 703 // Name: STATE 704 // 705 // Purpose: Stores the active state of the IJL. 706 // 707 // Context: Used by all low-level routines to store pseudo-global or 708 // state variables. 709 // 710 // Fields: 711 // bit_buffer_64 64-bit bitbuffer utilized by Huffman 712 // encoder/decoder algorithms utilizing routines 713 // designed for MMX(TM) technology. 714 // bit_buffer_32 32-bit bitbuffer for all other Huffman 715 // encoder/decoder algorithms. 716 // bitbuf_bits_valid Number of bits in the above two fields that 717 // are valid. 718 // 719 // cur_entropy_ptr Current position (absolute address) in 720 // the entropy buffer. 721 // start_entropy_ptr Starting position (absolute address) of 722 // the entropy buffer. 723 // end_entropy_ptr Ending position (absolute address) of 724 // the entropy buffer. 725 // entropy_bytes_processed Number of bytes actually processed 726 // (passed over) in the entropy buffer. 727 // entropy_buf_maxsize Max size of the entropy buffer. 728 // entropy_bytes_left Number of bytes left in the entropy buffer. 729 // Prog_EndOfBlock_Run Progressive block run counter. 730 // 731 // DIB_ptr Temporary offset into the input/output DIB. 732 // 733 // unread_marker If a marker has been read but not processed, 734 // stick it in this field. 735 // processor_type (0, 1, or 2) == current processor does not 736 // support MMX(TM) instructions. 737 // (3 or 4) == current processor does 738 // support MMX(TM) instructions. 739 // cur_scan_comp On which component of the scan are we working? 740 // file Process file handle, or 741 // 0x00000000 if no file is defined. 742 // JPGBuffer Entropy buffer (~4K). 743 // 744 // 745 //////////////////////////////////////////////////////////////////////////// 746 *D*/ 747 748 typedef struct _STATE 749 { 750 // Bit buffer. 751 UINT64 bit_buffer_64; 752 DWORD bit_buffer_32; 753 int bitbuf_bits_valid; 754 755 // Entropy. 756 BYTE* cur_entropy_ptr; 757 BYTE* start_entropy_ptr; 758 BYTE* end_entropy_ptr; 759 long entropy_bytes_processed; 760 long entropy_buf_maxsize; 761 int entropy_bytes_left; 762 int Prog_EndOfBlock_Run; 763 764 // Input or output DIB. 765 BYTE* DIB_ptr; 766 767 // Control. 768 BYTE unread_marker; 769 PROCESSOR_TYPE processor_type; 770 int cur_scan_comp; 771 HANDLE file; 772 BYTE JPGBuffer [JBUFSIZE]; 773 774 } STATE; 775 776 777 /*D* 778 //////////////////////////////////////////////////////////////////////////// 779 // Name: FAST_MCU_PROCESSING_TYPE 780 // 781 // Purpose: Advanced Control Option. Do NOT modify. 782 // WARNING: Used for internal reference only. 783 // 784 // Fields: 785 // 786 // IJL_(sampling)_(JPEG color space)_(sampling)_(DIB color space) 787 // Decode is read left to right w/ upsampling. 788 // Encode is read right to left w/ subsampling. 789 // 790 //////////////////////////////////////////////////////////////////////////// 791 *D*/ 792 793 typedef enum 794 { 795 IJL_NO_CC_OR_US = 0, 796 797 IJL_111_YCBCR_111_RGB = 1, 798 IJL_111_YCBCR_111_BGR = 2, 799 800 IJL_411_YCBCR_111_RGB = 3, 801 IJL_411_YCBCR_111_BGR = 4, 802 803 IJL_422_YCBCR_111_RGB = 5, 804 IJL_422_YCBCR_111_BGR = 6, 805 806 IJL_111_YCBCR_1111_RGBA_FPX = 7, 807 IJL_411_YCBCR_1111_RGBA_FPX = 8, 808 IJL_422_YCBCR_1111_RGBA_FPX = 9, 809 810 IJL_1111_YCBCRA_FPX_1111_RGBA_FPX = 10, 811 IJL_4114_YCBCRA_FPX_1111_RGBA_FPX = 11, 812 IJL_4224_YCBCRA_FPX_1111_RGBA_FPX = 12, 813 814 IJL_111_RGB_1111_RGBA_FPX = 13, 815 816 IJL_1111_RGBA_FPX_1111_RGBA_FPX = 14 817 818 } FAST_MCU_PROCESSING_TYPE; 819 820 821 /*D* 822 //////////////////////////////////////////////////////////////////////////// 823 // Name: JPEG_PROPERTIES 824 // 825 // Purpose: Stores low-level and control information. It is used by 826 // both the encoder and decoder. An advanced external user 827 // may access this structure to expand the interface 828 // capability. 829 // 830 // See the Developer's Guide for an expanded description 831 // of this structure and its use. 832 // 833 // Context: Used by all interface methods and most IJL routines. 834 // 835 // Fields: 836 // 837 // iotype IN: Specifies type of data operation 838 // (read/write/other) to be 839 // performed by IJL_Read or IJL_Write. 840 // roi IN: Rectangle-Of-Interest to read from, or 841 // write to, in pixels. 842 // dcttype IN: DCT alogrithm to be used. 843 // fast_processing OUT: Supported fast pre/post-processing path. 844 // This is set by the IJL. 845 // interrupt IN: Signals an interrupt has been requested. 846 // 847 // DIBBytes IN: Pointer to buffer of uncompressed data. 848 // DIBWidth IN: Width of uncompressed data. 849 // DIBHeight IN: Height of uncompressed data. 850 // DIBPadBytes IN: Padding (in bytes) at end of each 851 // row in the uncompressed data. 852 // DIBChannels IN: Number of components in the 853 // uncompressed data. 854 // DIBColor IN: Color space of uncompressed data. 855 // DIBSubsampling IN: Required to be IJL_NONE. 856 // DIBLineBytes OUT: Number of bytes in an output DIB line 857 // including padding. 858 // 859 // JPGFile IN: Pointer to file based JPEG. 860 // JPGBytes IN: Pointer to buffer based JPEG. 861 // JPGSizeBytes IN: Max buffer size. Used with JPGBytes. 862 // OUT: Number of compressed bytes written. 863 // JPGWidth IN: Width of JPEG image. 864 // OUT: After reading (except READHEADER). 865 // JPGHeight IN: Height of JPEG image. 866 // OUT: After reading (except READHEADER). 867 // JPGChannels IN: Number of components in JPEG image. 868 // OUT: After reading (except READHEADER). 869 // JPGColor IN: Color space of JPEG image. 870 // JPGSubsampling IN: Subsampling of JPEG image. 871 // OUT: After reading (except READHEADER). 872 // JPGThumbWidth OUT: JFIF embedded thumbnail width [0-255]. 873 // JPGThumbHeight OUT: JFIF embedded thumbnail height [0-255]. 874 // 875 // cconversion_reqd OUT: If color conversion done on decode, TRUE. 876 // upsampling_reqd OUT: If upsampling done on decode, TRUE. 877 // jquality IN: [0-100] where highest quality is 100. 878 // jinterleaveType IN/OUT: 0 => MCU interleaved file, and 879 // 1 => 1 scan per component. 880 // numxMCUs OUT: Number of MCUs in the x direction. 881 // numyMCUs OUT: Number of MCUs in the y direction. 882 // 883 // nqtables IN/OUT: Number of quantization tables. 884 // maxquantindex IN/OUT: Maximum index of quantization tables. 885 // nhuffActables IN/OUT: Number of AC Huffman tables. 886 // nhuffDctables IN/OUT: Number of DC Huffman tables. 887 // maxhuffindex IN/OUT: Maximum index of Huffman tables. 888 // jFmtQuant IN/OUT: Formatted quantization table info. 889 // jFmtAcHuffman IN/OUT: Formatted AC Huffman table info. 890 // jFmtDcHuffman IN/OUT: Formatted DC Huffman table info. 891 // 892 // jEncFmtQuant IN/OUT: Pointer to one of the above, or 893 // to externally persisted table. 894 // jEncFmtAcHuffman IN/OUT: Pointer to one of the above, or 895 // to externally persisted table. 896 // jEncFmtDcHuffman IN/OUT: Pointer to one of the above, or 897 // to externally persisted table. 898 // 899 // use_default_qtables IN: Set to default quantization tables. 900 // Clear to supply your own. 901 // use_default_htables IN: Set to default Huffman tables. 902 // Clear to supply your own. 903 // rawquanttables IN: Up to 4 sets of quantization tables. 904 // rawhufftables IN: Alternating pairs (DC/AC) of up to 4 905 // sets of raw Huffman tables. 906 // HuffIdentifierAC IN: Indicates what channel the user- 907 // supplied Huffman AC tables apply to. 908 // HuffIdentifierDC IN: Indicates what channel the user- 909 // supplied Huffman DC tables apply to. 910 // 911 // jframe OUT: Structure with frame-specific info. 912 // needframe OUT: TRUE when a frame has been detected. 913 // 914 // jscan Persistence for current scan pointer when 915 // interrupted. 916 // 917 // state OUT: Contains info on the state of the IJL. 918 // SawAdobeMarker OUT: Decoder saw an APP14 marker somewhere. 919 // AdobeXform OUT: If SawAdobeMarker TRUE, this indicates 920 // the JPEG color space given by that marker. 921 // 922 // rowoffsets Persistence for the decoder MCU row origins 923 // when decoding by ROI. Offsets (in bytes 924 // from the beginning of the entropy data) 925 // to the start of each of the decoded rows. 926 // Fill the offsets with -1 if they have not 927 // been initalized and NULL could be the 928 // offset to the first row. 929 // 930 // MCUBuf OUT: Quadword aligned internal buffer. 931 // Big enough for the largest MCU 932 // (10 blocks) with extra room for 933 // additional operations. 934 // tMCUBuf OUT: Version of above, without alignment. 935 // 936 // processor_type OUT: Determines type of processor found 937 // during initialization. 938 // 939 // ignoreDCTs IN: Assert to bypass DCTs when processing 940 // data. Required for conformance 941 // testing. 942 // 943 // progressive_found OUT: 1 when progressive image detected. 944 // coef_buffer IN: Pointer to a larger buffer containing 945 // frequency coefficients when they 946 // cannot be decoded dynamically 947 // (i.e., as in progressive decoding). 948 // 949 //////////////////////////////////////////////////////////////////////////// 950 *D*/ 951 952 typedef struct 953 { 954 // Compression/Decompression control. 955 IJLIOTYPE iotype; // default = IJL_SETUP 956 RECT roi; // default = 0 957 DCTTYPE dcttype; // default = IJL_AAN 958 FAST_MCU_PROCESSING_TYPE fast_processing; // default = IJL_NO_CC_OR_US 959 DWORD interrupt; // default = FALSE 960 961 // DIB specific I/O data specifiers. 962 BYTE* DIBBytes; // default = NULL 963 DWORD DIBWidth; // default = 0 964 int DIBHeight; // default = 0 965 DWORD DIBPadBytes; // default = 0 966 DWORD DIBChannels; // default = 3 967 IJL_COLOR DIBColor; // default = IJL_BGR 968 IJL_DIBSUBSAMPLING DIBSubsampling; // default = IJL_NONE 969 int DIBLineBytes; // default = 0 970 971 // JPEG specific I/O data specifiers. 972 LPTSTR JPGFile; // default = NULL 973 BYTE* JPGBytes; // default = NULL 974 DWORD JPGSizeBytes; // default = 0 975 DWORD JPGWidth; // default = 0 976 DWORD JPGHeight; // default = 0 977 DWORD JPGChannels; // default = 3 978 IJL_COLOR JPGColor; // default = IJL_YCBCR 979 IJL_JPGSUBSAMPLING JPGSubsampling; // default = IJL_411 980 DWORD JPGThumbWidth; // default = 0 981 DWORD JPGThumbHeight; // default = 0 982 983 // JPEG conversion properties. 984 DWORD cconversion_reqd; // default = TRUE 985 DWORD upsampling_reqd; // default = TRUE 986 DWORD jquality; // default = 75 987 DWORD jinterleaveType; // default = 0 988 DWORD numxMCUs; // default = 0 989 DWORD numyMCUs; // default = 0 990 991 // Tables. 992 DWORD nqtables; 993 DWORD maxquantindex; 994 DWORD nhuffActables; 995 DWORD nhuffDctables; 996 DWORD maxhuffindex; 997 998 QUANT_TABLE jFmtQuant[4]; 999 HUFFMAN_TABLE jFmtAcHuffman[4]; 1000 HUFFMAN_TABLE jFmtDcHuffman[4]; 1001 1002 short* jEncFmtQuant[4]; 1003 HUFFMAN_TABLE* jEncFmtAcHuffman[4]; 1004 HUFFMAN_TABLE* jEncFmtDcHuffman[4]; 1005 1006 // Allow user-defined tables. 1007 DWORD use_default_qtables; 1008 DWORD use_default_htables; 1009 1010 JPEGQuantTable rawquanttables[4]; 1011 JPEGHuffTable rawhufftables[8]; 1012 BYTE HuffIdentifierAC[4]; 1013 BYTE HuffIdentifierDC[4]; 1014 1015 // Frame specific members. 1016 FRAME jframe; 1017 int needframe; 1018 1019 // SCAN persistent members. 1020 SCAN* jscan; 1021 1022 // State members. 1023 STATE state; 1024 DWORD SawAdobeMarker; 1025 DWORD AdobeXform; 1026 1027 // ROI decoder members. 1028 ENTROPYSTRUCT* rowoffsets; 1029 1030 // Intermediate buffers. 1031 BYTE* MCUBuf; 1032 BYTE tMCUBuf[720*2]; // ??? 1033 1034 // Processor detected. 1035 PROCESSOR_TYPE processor_type; 1036 1037 // Test specific members. 1038 DWORD ignoreDCTs; 1039 1040 // Progressive mode members. 1041 int progressive_found; 1042 short* coef_buffer; 1043 1044 } JPEG_PROPERTIES; 1045 1046 1047 /*D* 1048 //////////////////////////////////////////////////////////////////////////// 1049 // Name: JPEG_CORE_PROPERTIES 1050 // 1051 // Purpose: This is the primary data structure between the IJL and 1052 // the external user. It stores JPEG state information 1053 // and controls the IJL. It is user-modifiable. 1054 // 1055 // See the Developer's Guide for details on appropriate usage. 1056 // 1057 // Context: Used by all low-level IJL routines to store 1058 // pseudo-global information. 1059 // 1060 // Fields: 1061 // 1062 // UseJPEGPROPERTIES Set this flag != 0 if you wish to override 1063 // the JPEG_CORE_PROPERTIES "IN" parameters with 1064 // the JPEG_PROPERTIES parameters. 1065 // 1066 // DIBBytes IN: Pointer to buffer of uncompressed data. 1067 // DIBWidth IN: Width of uncompressed data. 1068 // DIBHeight IN: Height of uncompressed data. 1069 // DIBPadBytes IN: Padding (in bytes) at end of each 1070 // row in the uncompressed data. 1071 // DIBChannels IN: Number of components in the 1072 // uncompressed data. 1073 // DIBColor IN: Color space of uncompressed data. 1074 // DIBSubsampling IN: Required to be IJL_NONE. 1075 // 1076 // JPGFile IN: Pointer to file based JPEG. 1077 // JPGBytes IN: Pointer to buffer based JPEG. 1078 // JPGSizeBytes IN: Max buffer size. Used with JPGBytes. 1079 // OUT: Number of compressed bytes written. 1080 // JPGWidth IN: Width of JPEG image. 1081 // OUT: After reading (except READHEADER). 1082 // JPGHeight IN: Height of JPEG image. 1083 // OUT: After reading (except READHEADER). 1084 // JPGChannels IN: Number of components in JPEG image. 1085 // OUT: After reading (except READHEADER). 1086 // JPGColor IN: Color space of JPEG image. 1087 // JPGSubsampling IN: Subsampling of JPEG image. 1088 // OUT: After reading (except READHEADER). 1089 // JPGThumbWidth OUT: JFIF embedded thumbnail width [0-255]. 1090 // JPGThumbHeight OUT: JFIF embedded thumbnail height [0-255]. 1091 // 1092 // cconversion_reqd OUT: If color conversion done on decode, TRUE. 1093 // upsampling_reqd OUT: If upsampling done on decode, TRUE. 1094 // jquality IN: [0-100] where highest quality is 100. 1095 // 1096 // jprops "Low-Level" IJL data structure. 1097 // 1098 //////////////////////////////////////////////////////////////////////////// 1099 *D*/ 1100 1101 typedef struct _JPEG_CORE_PROPERTIES 1102 { 1103 DWORD UseJPEGPROPERTIES; // default = 0 1104 1105 // DIB specific I/O data specifiers. 1106 BYTE* DIBBytes; // default = NULL 1107 DWORD DIBWidth; // default = 0 1108 int DIBHeight; // default = 0 1109 DWORD DIBPadBytes; // default = 0 1110 DWORD DIBChannels; // default = 3 1111 IJL_COLOR DIBColor; // default = IJL_BGR 1112 IJL_DIBSUBSAMPLING DIBSubsampling; // default = IJL_NONE 1113 1114 // JPEG specific I/O data specifiers. 1115 LPTSTR JPGFile; // default = NULL 1116 BYTE* JPGBytes; // default = NULL 1117 DWORD JPGSizeBytes; // default = 0 1118 DWORD JPGWidth; // default = 0 1119 DWORD JPGHeight; // default = 0 1120 DWORD JPGChannels; // default = 3 1121 IJL_COLOR JPGColor; // default = IJL_YCBCR 1122 IJL_JPGSUBSAMPLING JPGSubsampling; // default = IJL_411 1123 DWORD JPGThumbWidth; // default = 0 1124 DWORD JPGThumbHeight; // default = 0 1125 1126 // JPEG conversion properties. 1127 DWORD cconversion_reqd; // default = TRUE 1128 DWORD upsampling_reqd; // default = TRUE 1129 DWORD jquality; // default = 75 1130 1131 // Low-level properties. 1132 JPEG_PROPERTIES jprops; 1133 1134 } JPEG_CORE_PROPERTIES; 1135 1136 1137 /*D* 1138 //////////////////////////////////////////////////////////////////////////// 1139 // Name: IJLERR 1140 // 1141 // Purpose: Listing of possible "error" codes returned by the IJL. 1142 // 1143 // See the Developer's Guide for details on appropriate usage. 1144 // 1145 // Context: Used for error checking. 1146 // 1147 //////////////////////////////////////////////////////////////////////////// 1148 *D*/ 1149 1150 typedef enum 1151 { 1152 // The following "error" values indicate an "OK" condition. 1153 IJL_OK = 0, 1154 IJL_INTERRUPT_OK = 1, 1155 IJL_ROI_OK = 2, 1156 1157 // The following "error" values indicate an error has occurred. 1158 IJL_EXCEPTION_DETECTED = -1, 1159 IJL_INVALID_ENCODER = -2, 1160 IJL_UNSUPPORTED_SUBSAMPLING = -3, 1161 IJL_UNSUPPORTED_BYTES_PER_PIXEL = -4, 1162 IJL_MEMORY_ERROR = -5, 1163 IJL_BAD_HUFFMAN_TABLE = -6, 1164 IJL_BAD_QUANT_TABLE = -7, 1165 IJL_INVALID_JPEG_PROPERTIES = -8, 1166 IJL_ERR_FILECLOSE = -9, 1167 IJL_INVALID_FILENAME = -10, 1168 IJL_ERROR_EOF = -11, 1169 IJL_PROG_NOT_SUPPORTED = -12, 1170 IJL_ERR_NOT_JPEG = -13, 1171 IJL_ERR_COMP = -14, 1172 IJL_ERR_SOF = -15, 1173 IJL_ERR_DNL = -16, 1174 IJL_ERR_NO_HUF = -17, 1175 IJL_ERR_NO_QUAN = -18, 1176 IJL_ERR_NO_FRAME = -19, 1177 IJL_ERR_MULT_FRAME = -20, 1178 IJL_ERR_DATA = -21, 1179 IJL_ERR_NO_IMAGE = -22, 1180 IJL_FILE_ERROR = -23, 1181 IJL_INTERNAL_ERROR = -24, 1182 IJL_BAD_RST_MARKER = -25, 1183 IJL_THUMBNAIL_DIB_TOO_SMALL = -26, 1184 IJL_THUMBNAIL_DIB_WRONG_COLOR = -27, 1185 IJL_RESERVED = -99 1186 1187 } IJLERR; 1188 1189 1190 1191 1192 /* ///////////////////////////////////////////////////////////////////////// 1193 // Function Prototypes (API Calls) // 1194 ///////////////////////////////////////////////////////////////////////// */ 1195 1196 1197 /*F* 1198 //////////////////////////////////////////////////////////////////////////// 1199 // Name: ijlInit 1200 // 1201 // Purpose: Used to initalize the IJL. 1202 // 1203 // See the Developer's Guide for details on appropriate usage. 1204 // 1205 // Context: Always call this before anything else. 1206 // Also, only call this with a new jcprops structure, or 1207 // after calling IJL_Free. Otherwise, dynamically 1208 // allocated memory may be leaked. 1209 // 1210 // Returns: Any IJLERR value. IJL_OK indicates success. 1211 // 1212 // Parameters: 1213 // jcprops Pointer to an externally allocated 1214 // JPEG_CORE_PROPERTIES structure. 1215 // 1216 //////////////////////////////////////////////////////////////////////////// 1217 *F*/ 1218 1219 IJLAPI(IJLERR, ijlInit, ( JPEG_CORE_PROPERTIES* jcprops )); 1220 1221 1222 /*F* 1223 //////////////////////////////////////////////////////////////////////////// 1224 // Name: ijlFree 1225 // 1226 // Purpose: Used to properly close down the IJL. 1227 // 1228 // See the Developer's Guide for details on appropriate usage. 1229 // 1230 // Context: Always call this when done using the IJL to perform 1231 // clean-up of dynamically allocated memory. 1232 // Note, IJL_Init will have to be called to use the 1233 // IJL again. 1234 // 1235 // Returns: Any IJLERR value. IJL_OK indicates success. 1236 // 1237 // Parameters: 1238 // jcprops Pointer to an externally allocated 1239 // JPEG_CORE_PROPERTIES structure. 1240 // 1241 //////////////////////////////////////////////////////////////////////////// 1242 *F*/ 1243 1244 IJLAPI(IJLERR, ijlFree, ( JPEG_CORE_PROPERTIES* jcprops )); 1245 1246 1247 /*F* 1248 //////////////////////////////////////////////////////////////////////////// 1249 // Name: IJL_Read 1250 // 1251 // Purpose: Used to read JPEG data (entropy, or header, or both) into 1252 // a user-supplied buffer (to hold the image data) and/or 1253 // into the JPEG_CORE_PROPERTIES structure (to hold the 1254 // header info). 1255 // 1256 // Context: See the Developer's Guide for a detailed description 1257 // on the use of this function. The jcprops main data 1258 // members are checked for consistency. 1259 // 1260 // Returns: Any IJLERR value. IJL_OK indicates success. 1261 // 1262 // Parameters: 1263 // jcprops Pointer to an externally allocated 1264 // JPEG_CORE_PROPERTIES structure. 1265 // iotype Specifies what type of read operation to perform. 1266 // 1267 //////////////////////////////////////////////////////////////////////////// 1268 *F*/ 1269 1270 IJLAPI(IJLERR, ijlRead, ( JPEG_CORE_PROPERTIES* jcprops, IJLIOTYPE iotype )); 1271 1272 1273 /*F* 1274 //////////////////////////////////////////////////////////////////////////// 1275 // Name: ijlWrite 1276 // 1277 // Purpose: Used to write JPEG data (entropy, or header, or both) into 1278 // a user-supplied buffer (to hold the image data) and/or 1279 // into the JPEG_CORE_PROPERTIES structure (to hold the 1280 // header info). 1281 // 1282 // Context: See the Developer's Guide for a detailed description 1283 // on the use of this function. The jcprops main data 1284 // members are checked for consistency. 1285 // 1286 // Returns: Any IJLERR value. IJL_OK indicates success. 1287 // 1288 // Parameters: 1289 // jcprops Pointer to an externally allocated 1290 // JPEG_CORE_PROPERTIES structure. 1291 // iotype Specifies what type of write operation to perform. 1292 // 1293 //////////////////////////////////////////////////////////////////////////// 1294 *F*/ 1295 1296 IJLAPI(IJLERR, ijlWrite, ( JPEG_CORE_PROPERTIES* jcprops, IJLIOTYPE iotype )); 1297 1298 1299 /*F* 1300 //////////////////////////////////////////////////////////////////////////// 1301 // Name: ijlGetLibVersion 1302 // 1303 // Purpose: To identify the version number of the IJL. 1304 // 1305 // Context: Call to get the IJL version number. 1306 // 1307 // Returns: pointer to IJLibVersion struct 1308 // 1309 // Parameters: none 1310 // 1311 //////////////////////////////////////////////////////////////////////////// 1312 *F*/ 1313 1314 IJLAPI(const IJLibVersion*, ijlGetLibVersion, (void)); 1315 1316 1317 /*F* 1318 //////////////////////////////////////////////////////////////////////////// 1319 // Name: ijlErrorStr 1320 // 1321 // Purpose: Gets the string to describe error code. 1322 // 1323 // Context: Is called to get descriptive string on arbitrary IJLERR code. 1324 // 1325 // Returns: pointer to string 1326 // 1327 // Parameters: IJLERR - IJL error code 1328 // 1329 //////////////////////////////////////////////////////////////////////////// 1330 *F*/ 1331 1332 IJLAPI(const LPCTSTR, ijlErrorStr, (IJLERR code)); 1333 1334 1335 1336 1337 #if defined( __cplusplus ) 1338 } 1339 #endif 1340 1341 #endif // __IJL_H__ 1342