Fichiers Tiff
ldci19-Feb-2010/23:25:55+1:00
Salut à tous
J'ai besoin de votre aide.
Je suis en train de bricoler une librairie permettant de lire directement sous Rebol des fichiers tiff (non compressés pour le moment). Le code recupère bien la liste des tags et visualise certains fichiers.
Le problème réside dans le calcul de la taille des données qui si elles sont < à 4 bytes sont directement stockées dans le champ. Dans le cas contraire, la valeur "pointe" sur une adresse n dans le fichier. Mon pb réside dans le calcul de cette taille (fonction Get_Tag_Value dans le code). Si vous avez des idées je suis preneur.
Merci d'avance

Voici la lib

REBOL [
title: "Tiff Lib"
date: "January 2010"
file: "tifflib.r"
version: "2.0"
home: ""
author: "François Jouen"
rights: ""
needs: ""
comment: ""
history: ""
language: ""
updates: " Marc Le Marchand - 6 April 2004 - reference : mlm01"
updates: "François Jouen - Septembre 2009"
]



{*
* Tag Image File Format (TIFF)
*
* Based on Rev 6.0 from:
* Developer's Desk
* Aldus Corporation
* 411 First Ave. South
* Suite 200
* Seattle, WA 98104
* 206-622-5500
*/}





; list of tags
Tiff_Tags: [
   ; subfile data descriptor */ default 0
   254 [NewSubfileType [
      FILETYPE_REDUCEDIMAGE #00000001   ; reduced resolution version */
      FILETYPE_PAGE #00000002   ; one page of many */
      FILETYPE_MASK #00000004   ; transparency mask */
   ]]
   ; +kind of data in subfile */
   255 [OSUBFILETYPE [
    OFILETYPE_IMAGE 1   ; full resolution image data */
      OFILETYPE_REDUCEDIMAGE 2   ; reduced size image data */
      OFILETYPE_PAGE 3; one page of many */
   ]]
   256 [IMAGEWIDTH]   ; image width in pixels */
   257 [IMAGELENGTH] ; image height in pixels */      
   258 [BITSPERSAMPLE]      ; bits per channel (sample) */
   ; data compression technique */
   259 [COMPRESSION [         
      COMPRESSION_NONE   1; dump mode */
      COMPRESSION_CCITTRLE   2; CCITT modified Huffman RLE */
      COMPRESSION_CCITTFAX3   3; CCITT Group 3 fax encoding */
      COMPRESSION_CCITT_T4 3 ; CCITT T.4 (TIFF 6 name) */
      COMPRESSION_CCITTFAX4 4   ; CCITT Group 4 fax encoding */
      COMPRESSION_CCITT_T 4 ; CCITT T.6 (TIFF 6 name) */
      COMPRESSION_LZW 5 ; Lempel-Ziv & Welch */
      COMPRESSION_OJPEG   6; !6.0 JPEG */
      COMPRESSION_JPEG      7   ; %JPEG DCT compression */
      COMPRESSION_NEXT      32766   ; NeXT 2-bit RLE */
      COMPRESSION_CCITTRLEW   32771   ; #1 w/ word alignment */
      COMPRESSION_PACKBITS   32773   ; Macintosh RLE */
      COMPRESSION_THUNDERSCAN   32809   ; ThunderScan RLE */
      ;; codes 32895-32898 are reserved for ANSI IT8 TIFF/IT <dkelly@apago.com) */
      COMPRESSION_IT8CTPAD   32895 ; IT8 CT w/padding */
      COMPRESSION_IT8LW      32896 ; IT8 Linework RLE */
      COMPRESSION_IT8MP      32897 ; IT8 Monochrome picture */
      COMPRESSION_IT8BL      32898 ; IT8 Binary line art */
      ;; compression codes 32908-32911 are reserved for Pixar */
      COMPRESSION_PIXARFILM   32908 ; Pixar companded 10bit LZW */
      COMPRESSION_PIXARLOG   32909 ; Pixar companded 11bit ZIP */
      COMPRESSION_DEFLATE      32946   ; Deflate compression */
      COMPRESSION_ADOBE_DEFLATE 8 ; Deflate compression as recognized by Adobe */
      ;; compression code 32947 is reserved for Oceana Matrix <dev@oceana.com> */
      COMPRESSION_DCS 32947 ; Kodak DCS encoding */
      COMPRESSION_JBIG      34661   ; ISO JBIG */
      COMPRESSION_SGILOG      34676   ; SGI Log Luminance RLE */
      COMPRESSION_SGILOG24   34677   ; SGI Log 24-bit packed */
      COMPRESSION_JP2000 34712 ; Leadtools JPEG2000 */
   ]]
   ; photometric interpretation */
   262 [PHOTOMETRIC [         
      PHOTOMETRIC_MINISWHITE   0   ; min value is white */
      PHOTOMETRIC_MINISBLACK   1   ; min value is black */
      PHOTOMETRIC_RGB      2   ; RGB color model */
      PHOTOMETRIC_PALETTE      3   ; color map indexed */
      PHOTOMETRIC_MASK      4   ; $holdout mask */
      PHOTOMETRIC_SEPARATED   5   ; !color separations */
      PHOTOMETRIC_YCBCR      6   ; !CCIR 601 */
      PHOTOMETRIC_CIELAB      8   ; !1976 CIE L*a*b* */
      PHOTOMETRIC_ICCLAB      9   ; ICC L*a*b* [Adobe TIFF Technote 4] */
      PHOTOMETRIC_ITULAB      10   ; ITU L*a*b* */
      PHOTOMETRIC_LOGL      32844   ; CIE Log2(L) */
      PHOTOMETRIC_LOGLUV      32845   ; CIE Log2(L) (u',v') */
   ]]
   ; +thresholding used on data */
   263 [THRESHHOLDING [   
      THRESHHOLD_BILEVEL      1   ; b&w art scan */
      THRESHHOLD_HALFTONE      2   ; or dithered scan */
      THRESHHOLD_ERRORDIFFUSE   3   ; usually floyd-steinberg */
   ]]
   264 [CELLWIDTH]   ; +dithering matrix width */
   265 [CELLLENGTH]   ; +dithering matrix height */
   ; data order within a byte */
   266 [FILLORDER [
      FILLORDER_MSB2LSB      1   ; most significant -> least */
      FILLORDER_LSB2MSB      2   ; least significant -> most */
   ]]
   269 [DOCUMENTNAME]   ; name of doc. image is from */
   270 [IMAGEDESCRIPTION]; info about image */
   271 [MAKE]   ; scanner manufacturer name */
   272 [MODEL]   ; scanner model name/number */
   273 [STRIPOFFSETS]   ; offsets to data strips */
   ; +image orientation */
   274 [ORIENTATION [   
      ORIENTATION_TOPLEFT      1   ; row 0 top, col 0 lhs */
      ORIENTATION_TOPRIGHT   2   ; row 0 top, col 0 rhs */
      ORIENTATION_BOTRIGHT   3   ; row 0 bottom, col 0 rhs */
      ORIENTATION_BOTLEFT      4   ; row 0 bottom, col 0 lhs */
      ORIENTATION_LEFTTOP      5   ; row 0 lhs, col 0 top */
      ORIENTATION_RIGHTTOP   6   ; row 0 rhs, col 0 top */
      ORIENTATION_RIGHTBOT   7   ; row 0 rhs, col 0 bottom */
      ORIENTATION_LEFTBOT      8   ; row 0 lhs, col 0 bottom */
   ]]
   277 [SAMPLESPERPIXEL]   ; samples per pixel */
   278 [ROWSPERSTRIP]      ; rows per strip of data */
   279 [STRIPBYTECOUNTS]   ; bytes counts for strips */
   280 [MINSAMPLEVALUE]   ; +minimum sample value */
   281 [MAXSAMPLEVALUE]   ; +maximum sample value */
   282 [XRESOLUTION]       ; pixels/resolution in x */
   283 [YRESOLUTION]      ; pixels/resolution in y */
   ; storage organization */
   284 [PLANARCONFIG [   
      PLANARCONFIG_CONTIG      1   ; single image plane */
      PLANARCONFIG_SEPARATE   2   ; separate planes of data */
   ]]
   285 [PAGENAME]      ; page name image is from */
   286 [XPOSITION]      ; x page offset of image lhs */
   287 [YPOSITION]      ; y page offset of image lhs */
   288 [FREEOFFSETS]   ; +byte offset to free block */
   289 [FREEBYTECOUNTS]; +sizes of free blocks */
   ; $gray scale curve accuracy */
   290 [GRAYRESPONSEUNIT [
      GRAYRESPONSEUNIT_10S   1   ; tenths of a unit */
      GRAYRESPONSEUNIT_100S   2   ; hundredths of a unit */
      GRAYRESPONSEUNIT_1000S   3   ; thousandths of a unit */
      GRAYRESPONSEUNIT_10000S   4   ; ten-thousandths of a unit */
      GRAYRESPONSEUNIT_100000S 5   ; hundred-thousandths */
   ]]
   291 [GRAYRESPONSECURVE]   ; $gray scale response curve */
   292 [GROUP3OPTIONS]      ; 32 flag bits */
   ; TIFF 6.0 proper name alias */
   292 [T4OPTIONS [
      GROUP3OPT_2DENCODING   #00000001   ; 2-dimensional coding */
      GROUP3OPT_UNCOMPRESSED   #00000002   ; data not compressed */
      GROUP3OPT_FILLBITS      #00000004   ; fill to byte boundary */
   ]]
   293 [GROUP4OPTIONS]      ; 32 flag bits */
   ; TIFF 6.0 proper name */
   293 [T6OPTIONS [
      GROUP4OPT_UNCOMPRESSED   #00000002   ; data not compressed */
   ]]
   ; units of resolutions */
   296 [RESOLUTIONUNIT   [
      RESUNIT_NONE      1   ; no meaningful units */
      RESUNIT_INCH      2   ; english */
      RESUNIT_CENTIMETER      3   ; metric */
   ]]
   297 [PAGENUMBER]   ; page numbers of multi-page */
   ; $color curve accuracy */
   300 [COLORRESPONSEUNIT [
      COLORRESPONSEUNIT_10S   1   ; tenths of a unit */
      COLORRESPONSEUNIT_100S   2   ; hundredths of a unit */
      COLORRESPONSEUNIT_1000S   3   ; thousandths of a unit */
      COLORRESPONSEUNIT_10000S   4   ; ten-thousandths of a unit */
      COLORRESPONSEUNIT_100000S   5   ; hundred-thousandths */
   ]]
   301   [TRANSFERFUNCTION]   ; !colorimetry info */
   305 [SOFTWARE]         ; name & release */
   306 [DATETIME]         ; creation date and time */
   315 [ARTIST]         ; creator of image */
   316 [HOSTCOMPUTER]       ; machine where created */
   ; prediction scheme w/ LZW */
   317 [PREDICTOR [
      PREDICTOR_NONE      1   ; no prediction scheme used */
      PREDICTOR_HORIZONTAL   2   ; horizontal differencing */
      PREDICTOR_FLOATINGPOINT   3   ; floating point predictor */
   ]]
   318 [WHITEPOINT]         ; image white point */
   319 [PRIMARYCHROMATICITIES]      ; !primary chromaticities */
   320 [COLORMAP]    ; RGB map for pallette image */
   321 [HALFTONEHINTS]         ; !highlight+shadow info */
   322 [TILEWIDTH]         ; !tile width in pixels */
   323 [TILELENGTH]         ; !tile height in pixels */
   324 [TILEOFFSETS]      ; !offsets to data tiles */
   325 [TILEBYTECOUNTS]      ; !byte counts for tiles */
   326 [BADFAXLINES]         ; lines w/ wrong pixel count */
   ;regenerated line info */
   327 [CLEANFAXDATA [
      CLEANFAXDATA_CLEAN      0   ; no errors detected */
      CLEANFAXDATA_REGENERATED   1   ; receiver regenerated lines */
      CLEANFAXDATA_UNCLEAN   2   ; uncorrected errors exist */
   ]]
   328 [CONSECUTIVEBADFAXLINES]   ; max consecutive bad lines */
   330 [SUBIFD]               ; subimage descriptors */
   ; !inks in separated image */
   332 [INKSET   [   
      INKSET_CMYK         1   ; !cyan-magenta-yellow-black color */
      INKSET_MULTIINK      2   ; !multi-ink or hi-fi color */
   ]]
   333 [INKNAMES]         ; !ascii names of inks */
   334 [NUMBEROFINKS]      ; !number of inks */
   336 [DOTRANGE]         ; !0% and 100% dot codes */
   337 [TARGETPRINTER]      ; !separation target */
   ; !info about extra samples */
   338 [EXTRASAMPLES [
      EXTRASAMPLE_UNSPECIFIED   0   ; !unspecified data */
      EXTRASAMPLE_ASSOCALPHA   1   ; !associated alpha data */
      EXTRASAMPLE_UNASSALPHA   2   ; !unassociated alpha data */
   ]]
   ; !data sample format */
   339 [SAMPLEFORMAT [
      SAMPLEFORMAT_UINT      1   ; !unsigned integer data */
      SAMPLEFORMAT_INT      2   ; !signed integer data */
      SAMPLEFORMAT_IEEEFP      3   ; !IEEE floating point data */
      SAMPLEFORMAT_VOID      4   ; !untyped data */
      SAMPLEFORMAT_COMPLEXINT   5   ; !complex signed int */
      SAMPLEFORMAT_COMPLEXIEEEFP   6   ; !complex ieee floating */
   ]]
   340 [SMINSAMPLEVALUE]         ; !variable MinSampleValue */
   341 [SMAXSAMPLEVALUE]         ; !variable MaxSampleValue */
   343 [CLIPPATH]               ; %ClipPath [Adobe TIFF technote 2] */
   344 [XCLIPPATHUNITS]         ; %XClipPathUnits[Adobe TIFF technote 2] */
   345 [YCLIPPATHUNITS]         ; %YClipPathUnits[Adobe TIFF technote 2] */
   346 [INDEXED]               ; %Indexed[Adobe TIFF Technote 3] */
   347 [JPEGTABLES]            ; %JPEG table stream */
   351 [OPIPROXY]               ; %OPI Proxy [Adobe TIFF technote] */
   ;* Tags 512-521 are obsoleted by Technical Note #2 which specifies a revised JPEG-in-TIFF scheme.
   ; !JPEG processing algorithm */
   512 [JPEGPROC [
      JPEGPROC_BASELINE      1   ; !baseline sequential */
      JPEGPROC_LOSSLESS      14   ; !Huffman coded lossless */
   ]]
   513 [JPEGIFOFFSET]         ; !pointer to SOI marker */
   514 [JPEGIFBYTECOUNT]      ; !JFIF stream length */
   515 [JPEGRESTARTINTERVAL]      ; !restart interval length */
   517 [JPEGLOSSLESSPREDICTORS]      ; !lossless proc predictor */
   518 [JPEGPOINTTRANSFORM]      ; !lossless point transform */
   519 [JPEGQTABLES]         ; !Q matrice offsets */
   520 [JPEGDCTABLES]         ; !DCT table offsets */
   521 [JPEGACTABLES]         ; !AC coefficient offsets */
   529 [YCBCRCOEFFICIENTS]      ; !RGB -> YCbCr transform */
   530 [YCBCRSUBSAMPLING]   ; !YCbCr subsampling factors */
   ; !subsample positioning */
   531 [YCBCRPOSITIONING [
      YCBCRPOSITION_CENTERED   1   ; !as in PostScript Level 2 */
      YCBCRPOSITION_COSITED   2   ; !as in CCIR 601-1 */
   ]]
   532 [REFERENCEBLACKWHITE]      ; !colorimetry info */
   700 [XMLPACKET]         ; %XML packet[Adobe XMP Specification,January 2004 */
   32781 [OPIIMAGEID]      ; %OPI ImageID [Adobe TIFF technote] */
   ; tags 32952-32956 are private tags registered to Island Graphics */
   32953 [REFPTS]            ; image reference points */
   32954 [REGIONTACKPOINT]         ; region-xform tack point */
   32955 [REGIONWARPCORNERS]      ; warp quadrilateral */
   32956 [REGIONAFFINE]         ; affine transformation mat */
   ; tags 32995-32999 are private tags registered to SGI */
   32995 [MATTEING]         ; $use ExtraSamples */
   32996 [DATATYPE]         ; $use SampleFormat */
   32997 [IMAGEDEPTH]         ; z depth of image */
   32998 [TILEDEPTH]         ; z depth/data tile */
   ;; tags 33300-33309 are private tags registered to Pixar */
   {* PIXAR_IMAGEFULLWIDTH and PIXAR_IMAGEFULLLENGTH
   * are set when an image has been cropped out of a larger image.
   * They reflect the size of the original uncropped image.
   * The XPOSITION and YPOSITION can be used
   * to determine the position of the smaller image in the larger one.*}
   33300 [PIXAR_IMAGEFULLWIDTH] ; full image size in x */
   33301 [PIXAR_IMAGEFULLLENGTH] ; full image size in y */
   ;; Tags 33302-33306 are used to identify special image modes and data /used by Pixar's texture formats.
   33302 [PIXAR_TEXTUREFORMAT]      ; texture map format */
   33303 [PIXAR_WRAPMODES]         ; s & t wrap modes */
   33304 [PIXAR_FOVCOT]         ; cotan(fov) for env. maps */
   33305 [PIXAR_MATRIX_WORLDTOSCREEN]
   33306 [PIXAR_MATRIX_WORLDTOCAMERA]
   33405 [WRITERSERIALNUMBER] ; device serial number tag 33405 is a private tag registered to Eastman Kodak *
   33432 [COPYRIGHT]         ; copyright string */
   33723 [RICHTIFFIPTC]       ; IPTC TAG from RichTIFF specifications */
   ; 34016-34029 are reserved for ANSI IT8 TIFF/IT <dkelly@apago.com) */
   34016 [IT8SITE]            ; site name */
   34017 [IT8COLORSEQUENCE]      ; color seq. [RGB,CMYK,etc] */
   34018 [IT8HEADER]         ; DDES Header */
   34019 [IT8RASTERPADDING]      ; raster scanline padding */
   34020 [IT8BITSPERRUNLENGTH]      ; # of bits in short run */
   34021 [IT8BITSPEREXTENDEDRUNLENGTH] ; # of bits in long run */
   34022 [IT8COLORTABLE]         ; LW colortable */
   34023 [IT8IMAGECOLORINDICATOR]      ; BP/BL image color switch */
   34024 [IT8BKGCOLORINDICATOR]      ; BP/BL bg color switch */
   34025 [IT8IMAGECOLORVALUE]      ; BP/BL image color value */
   34026 [IT8BKGCOLORVALUE]      ; BP/BL bg color value */
   34027 [IT8PIXELINTENSITYRANGE]      ; MP pixel intensity value */
   34028 [IT8TRANSPARENCYINDICATOR]    ; HC transparency switch */
   34029 [IT8COLORCHARACTERIZATION]    ; color character. table */
   34030 [IT8HCUSAGE]         ; HC usage indicator */
   34031 [IT8TRAPINDICATOR]      ; Trapping indicator (untrapped=0, trapped=1) */
   34032 [IT8CMYKEQUIVALENT]      ; CMYK color equivalents */
   34232 [FRAMECOUNT] ; Sequence Frame Count private tags registered to Texas Instruments /
   34377 [PHOTOSHOP]         ; tag 34377 is private tag registered to Adobe for PhotoShop */
   34665 [EXIFIFD]            ; Pointer to EXIF private directory */
   34675 [ICCPROFILE]         ; ICC profile data */
   34750 [JBIGOPTIONS]         ; JBIG options private tag registered to Pixel Magic
   34853 [GPSIFD]            ; Pointer to GPS private directory */
   ; tags 34908-34914 are private tags registered to SGI */
   34908 [FAXRECVPARAMS]         ; encoded Class 2 ses. parms */
   34909 [FAXSUBADDRESS]         ; received SubAddr string */
   34910 [FAXRECVTIME]         ; receive time (secs) */
   34911 [FAXDCS]            ; encoded fax ses. params, Table 2/T.30 */
   37439 [STONITS]            ; Sample value to Nits */
   34929 [FEDEX_EDR]         ; a private tag registered to FedEx */ unknown use */
   40965 [INTEROPERABILITYIFD]      ; Pointer to Interoperability private directory */
   ; Adobe Digital Negative (DNG) format tags */
   50706 [DNGVERSION]            ; &DNG version number */
   50707 [DNGBACKWARDVERSION]      ; &DNG compatibility version */
   50708 [UNIQUECAMERAMODEL]      ; &name for the camera model */
   50709 [LOCALIZEDCAMERAMODEL]   ; &localized camera model name */
   50710 [CFAPLANECOLOR]         ; &CFAPattern->LinearRaw space mapping */
   50711 [CFALAYOUT]            ; &spatial layout of the CFA */
   50712 [LINEARIZATIONTABLE]      ; &lookup table description */
   50713 [BLACKLEVELREPEATDIM]      ; &repeat pattern size for the BlackLevel tag */
   50714 [BLACKLEVEL]            ; &zero light encoding level */
   50715 [BLACKLEVELDELTAH]      ; &zero light encoding level differences (columns) */
   50716 [BLACKLEVELDELTAV]      ; &zero light encoding level differences (rows) */
   50717 [WHITELEVEL]            ; &fully saturated encoding level */
   50718 [DEFAULTSCALE]         ; &default scale factors */
   50719 [DEFAULTCROPORIGIN]      ; &origin of the final image area */
   50720 [DEFAULTCROPSIZE]         ; &size of the final image area */
   50721 [COLORMATRIX1]         ; &XYZ->reference color space transformation matrix 1 */
   50722 [COLORMATRIX2]         ; &XYZ->reference color space transformation matrix 2 */
   50723 [CAMERACALIBRATION1]      ; &calibration matrix 1 */
   50724 [CAMERACALIBRATION2]      ; &calibration matrix 2 */
   50725 [REDUCTIONMATRIX1]      ; &dimensionality reduction matrix 1 */
   50726 [REDUCTIONMATRIX2]      ; &dimensionality reduction matrix 2 */
   50727 [ANALOGBALANCE]         ; &gain applied the stored raw values*/
   50728 [ASSHOTNEUTRAL]         ; &selected white balance in linear reference space */
   50729 [ASSHOTWHITEXY]         ; &selected white balance in x-y chromaticity coordinates */
   50730 [BASELINEEXPOSURE]      ; &how much to move the zero point */
   50731 [BASELINENOISE]         ; &relative noise level */
   50732 [BASELINESHARPNESS]      ; &relative amount of sharpening */
   50733 [BAYERGREENSPLIT]         ; &how closely the values of the green pixels in the blue/green rows track the values of the green pixel in the red/green rows */
   50734 [LINEARRESPONSELIMIT]      ; &non-linear encoding range */
   50735 [CAMERASERIALNUMBER]      ; &camera's serial number */
   50736 [LENSINFO]         ; info about the lens */
   50737 [CHROMABLURRADIUS]      ; &chroma blur radius */
   50738 [ANTIALIASSTRENGTH]      ; &relative strength of the camera's anti-alias filter */
   50739 [SHADOWSCALE]         ; &used by Adobe Camera Raw */
   50740 [DNGPRIVATEDATA]         ; &manufacturer's private data */
   50741 [MAKERNOTESAFETY]         ; &whether the EXIF MakerNote tag is safe to preserve along with the rest of the EXIF data */
   50778 [CALIBRATIONILLUMINANT1]      ; &illuminant 1 */
   50779 [CALIBRATIONILLUMINANT2]      ; &illuminant 2 */
   50780 [BESTQUALITYSCALE]   ; &best quality multiplier */
   50781 [RAWDATAUNIQUEID]         ; &unique identifier for the raw image data */
   50827 [ORIGINALRAWFILENAME]      ; &file name of the original raw file */
   50828 [ORIGINALRAWFILEDATA]      ; &contents of the original raw file */
   50829 [ACTIVEAREA]         ; &active (non-masked) pixels of the sensor */
   50830 [MASKEDAREAS]         ; &list of coordinates of fully masked pixels */
   50831 [ASSHOTICCPROFILE]      ; &these two tags used to */
   50832 [ASSHOTPREPROFILEMATRIX]      ; map cameras's color space into ICC profile space */
   50833 [CURRENTICCPROFILE]      ; & */
   50834 [CURRENTPREPROFILEMATRIX]      ; & */
   65535 [DCSHUESHIFTVALUES] ; hue shift correction data used by Eastman Kodak
   {* The following are ``pseudo tags'' that can be used to control
   * codec-specific functionality. These tags are not written to file.
    * Note that these values start at 0xffff+1 so that they'll never
   * collide with Aldus-assigned tags.
   *
   * If you want your private pseudo tags ``registered'' (i.e. added to
   * this file), please post a bug report via the tracking system at
   * http://www.remotesensing.org/libtiff/bugs.html with the appropriate
   * C definitions to add.}
   ; Group 3/4 format control */
   65536 [FAXMODE [         
         FAXMODE_CLASSIC   #00000000      ; default, include RTC */
         FAXMODE_NORTC   #00000001      ; no RTC at end of data */
         FAXMODE_NOEOL   #00000002      ; no EOL code at end of row */
         FAXMODE_BYTEALIGN   #00000004      ; byte align row */
         FAXMODE_WORDALIGN   #00000008      ; word align row */
         FAXMODE_CLASSF   #00000001   ; TIFF Class F */
   ]]
   65537 [JPEGQUALITY]         ; Compression quality level ; Note: quality level is on the IJG 0-100 scale. Default value is 75
   ; Auto RGB<=>YCbCr convert? */
   65538 [JPEGCOLORMODE [         
      JPEGCOLORMODE_RAW   #00000000      ; no conversion (default) */
      PEGCOLORMODE_RGB   #00000001      ; do auto conversion */
   ]]
   ; What to put in JPEGTables */
   65539 [JPEGTABLESMODE [         
         JPEGTABLESMODE_QUANT #00000001      ; include quantization tbls */
         JPEGTABLESMODE_HUFF   #00000002      ; include Huffman tbls */
         ; Note: default is JPEGTABLESMODE_QUANT | JPEGTABLESMODE_HUFF */
   ]]
   65540 [FAXFILLFUNC]         ; G3/G4 fill function */
   ; PixarLogCodec I/O data sz */   
   65549 [PIXARLOGDATAFMT [         
      PIXARLOGDATAFMT_8BIT   0   ; regular u_char samples */
      PIXARLOGDATAFMT_8BITABGR   1   ; ABGR-order u_chars */
      PIXARLOGDATAFMT_11BITLOG   2   ; 11-bit log-encoded (raw) */
      PIXARLOGDATAFMT_12BITPICIO   3   ; as per PICIO (1.0==2048) */
      PIXARLOGDATAFMT_16BIT   4   ; signed short samples */
      PIXARLOGDATAFMT_FLOAT   5   ; IEEE float samples */
   ]]
   ; 65550-65556 are allocated to Oceana Matrix <dev@oceana.com> */
   ; imager model & filter */
   65550 [DCSIMAGERTYPE [
         DCSIMAGERMODEL_M3 0 ; M3 chip (1280 x 1024) */
         DCSIMAGERMODEL_M5 1 ; M5 chip (1536 x 1024) */
         DCSIMAGERMODEL_M6 2 ; M6 chip (3072 x 2048) */
         DCSIMAGERFILTER_IR 0 ; infrared filter */
         DCSIMAGERFILTER_MONO 1 ; monochrome filter */
         DCSIMAGERFILTER_CFA 2 ; color filter array */
         DCSIMAGERFILTER_OTHER 3 ; other filter */
   ]]
   ; interpolation mode */
   65551 [DCSINTERPMODE[
         DCSINTERPMODE_NORMAL #00000000 ; whole image, default */
         DCSINTERPMODE_PREVIEW #00000001 ; preview of image (384x256) */
   ]]
   65552 [DCSBALANCEARRAY] ; color balance values */
   65553 [DCSCORRECTMATRIX] ; color correction values */
   65554 [DCSGAMMA] ; gamma value */
   65555 [DCSTOESHOULDERPTS] ; toe & shoulder points */
   65556 [DCSCALIBRATIONFD] ; calibration file desc */
   65557 [ZIPQUALITY]            ; compression quality level ; Note: quality level is on the ZLIB 1-9 scale. Default value is -1
   65558 [PIXARLOGQUALITY]         ; PixarLog uses same scale */
   65559 [DCSCLIPRECTANGLE]      ; area of image to acquire 65559 is allocated to Oceana Matrix <dev@oceana.com>
   ; SGILog user data format */
   65560 [SGILOGDATAFMT [         
         SGILOGDATAFMT_FLOAT      0   ; IEEE float samples */
         SGILOGDATAFMT_16BIT      1   ; 16-bit samples */
         SGILOGDATAFMT_RAW      2   ; uninterpreted data */
         SGILOGDATAFMT_8BIT      3   ; 8-bit RGB monitor values */
   ]]
   ; SGILog data encoding control*/   
   65561 [SGILOGENCODE   [   
         SGILOGENCODE_NODITHER   0 ; do not dither encoded values*/
         SGILOGENCODE_RANDITHER   1 ; randomly dither encd values */
   ]]
   ;EXIF tags
   33434 [EXIFTAG_EXPOSURETIME]         ; Exposure time */
   33437 [EXIFTAG_FNUMBER]            ; F number */
   34850 [EXIFTAG_EXPOSUREPROGRAM]         ; Exposure program */
   34852 [EXIFTAG_SPECTRALSENSITIVITY]      ; Spectral sensitivity */
   34855 [EXIFTAG_ISOSPEEDRATINGS]         ; ISO speed rating */
   34856 [EXIFTAG_OECF]            ; Optoelectric conversionbfactor */
   36864 [EXIFTAG_EXIFVERSION]         ; Exif version */
   36867 [EXIFTAG_DATETIMEORIGINAL]      ; Date and time of original data generation */
   36868 [EXIFTAG_DATETIMEDIGITIZED]      ; Date and time of digitaldata generation */
   37121 [EXIFTAG_COMPONENTSCONFIGURATION]      ; Meaning of each component */
   37122 [EXIFTAG_COMPRESSEDBITSPERPIXEL]      ; Image compression mode */
   37377 [EXIFTAG_SHUTTERSPEEDVALUE]      ; Shutter speed */
   37378 [EXIFTAG_APERTUREVALUE]         ; Aperture */
   37379 [EXIFTAG_BRIGHTNESSVALUE]         ; Brightness */
   37380 [EXIFTAG_EXPOSUREBIASVALUE]      ; [Exposure bias */
   37381 [EXIFTAG_MAXAPERTUREVALUE]      ; Maximum lens aperture */
   37382 [EXIFTAG_SUBJECTDISTANCE]         ; Subject distance */
   37383 [EXIFTAG_METERINGMODE]         ; Metering mode */
   37384 [EXIFTAG_LIGHTSOURCE]         ; Light source */
   37385 [EXIFTAG_FLASH]            ; Flash */
   37386 [EXIFTAG_FOCALLENGTH]         ; Lens focal length */
   37396 [EXIFTAG_SUBJECTAREA]         ; Subject area */
   37500 [EXIFTAG_MAKERNOTE]         ; Manufacturer notes */
   37510 [EXIFTAG_USERCOMMENT]         ; User comments */
   37520 [EXIFTAG_SUBSECTIME]         ; DateTime subseconds */
   37521 [EXIFTAG_SUBSECTIMEORIGINAL]      ; DateTimeOriginal subseconds */
   37522 [EXIFTAG_SUBSECTIMEDIGITIZED]      ; DateTimeDigitized subseconds */
   40960 [EXIFTAG_FLASHPIXVERSION]         ; Supported Flashpix version */
   40961 [EXIFTAG_COLORSPACE]         ; Color space information */
   40962 [EXIFTAG_PIXELXDIMENSION]         ; Valid image width */
   40963 [EXIFTAG_PIXELYDIMENSION]         ; Valid image height */
   40964 [EXIFTAG_RELATEDSOUNDFILE]      ; Related audio file */
   41483 [EXIFTAG_FLASHENERGY]         ; Flash [Energy */
   41484 [EXIFTAG_SPATIALFREQUENCYRESPONSE]    ; Spatial frequency response */
   41486 [EXIFTAG_FOCALPLANEXRESOLUTION]      ; Focal plane X resolution */
   41487 [EXIFTAG_FOCALPLANEYRESOLUTION]      ; Focal plane Y resolution */
   41488 [EXIFTAG_FOCALPLANERESOLUTIONUNIT]    ; Focal plane resolution unit */
   41492 [EXIFTAG_SUBJECTLOCATION]         ; Subject location */
   41493 [EXIFTAG_EXPOSUREINDEX]         ; [Exposure index */
   41495 [EXIFTAG_SENSINGMETHOD]         ; Sensing method */
   41728 [EXIFTAG_FILESOURCE]         ; File source */
   41729 [EXIFTAG_SCENETYPE]         ; Scene type */
   41730 [EXIFTAG_CFAPATTERN]         ; CFA pattern */
   41985 [EXIFTAG_CUSTOMRENDERED]         ; Custom image processing */
   41986 [EXIFTAG_EXPOSUREMODE]         ; [Exposure mode */
   41987 [EXIFTAG_WHITEBALANCE]         ; White balance */
   41988 [EXIFTAG_DIGITALZOOMRATIO]      ; Digital zoom ratio */
   41989 [EXIFTAG_FOCALLENGTHIN35MMFILM]      ; Focal length in 35 mm film */
   41990 [EXIFTAG_SCENECAPTURETYPE]   ; Scene capture type */
   41991 [EXIFTAG_GAINCONTROL]         ; Gain control */
   41992 [EXIFTAG_CONTRAST]         ; Contrast */
   41993 [EXIFTAG_SATURATION]         ; Saturation */
   41994 [EXIFTAG_SHARPNESS]         ; Sharpness */
   41995 [EXIFTAG_DEVICESETTINGDESCRIPTION]    ; Device settings description */
   41996 [EXIFTAG_SUBJECTDISTANCERANGE]      ; Subject distance range */
   41991 [EXIFTAG_GAINCONTROL]         ; Gain control */
   41991 [EXIFTAG_GAINCONTROL]         ; Gain control */
   42016 [EXIFTAG_IMAGEUNIQUEID]         ; Unique image ID */
]



byte_order: "Intel"
Big_Endian: false
Number_of_Pages: 1
Image_Type: "grayscale"
image_data: #{}
image_rgb: #{}
tiffBloc: []
Tag_Block: []
Tag_List: []

;initialisation des blocs pourla gestion des strips de données :
BStripOffsets: []
BStripByteCounts: []

;Tiff Header Structure
; header size: 8 bytes
TIFFHeader: make struct! [
   tiffBOrder [string!]; 2 bytes 0-1 byte order; could be also a binary or integer
   tiffVersion [integer!] ; 2b ytes 2-3 42 version number
   tiffFIFD [integer!] ; 4 bytes 4-7 offset of the first Image File Directory
] none

;Image File Directory
; Dir entry size: 12 bytes by entry

TImgFDEntry: make struct! [
   tiffTag [integer! ] ;byte 0-1 TIFF Field Tag 2 bytes 0-1 see TIFF Tag Definitions
   tiffDataType [integer!] ; byte 2-3 Field data type 2 bytes 2-3 see TIFFDataType
   tiffDataLength [integer!] ; byte 4-7 number of values of the indicated type; length in spec 4 bytes 4-7
   tiffOffset [integer!] ; byte 8-11 byte offset to field data 4 bytes 8-11 or value of the field if datalength < 4 bytes
   tiffValue [string!] ; supplementary rebol field to get the "real" value

] none


; kind of TIFF Images

{Baseline TIFF bilevel images were called TIFF Class B images in earlier versions of the TIFF specification.
A bilevel image contains two colors black and white. TIFF allows an application
to write out bilevel data in either a white-is-zero or black-is-zero format. The
field that records this information is called PhotometricInterpretation. i.e Tag 262
PhotometricInterpretation
Tag = 262 (106.H)
Type = SHORT
Values:
0 = WhiteIsZero. For bilevel and grayscale images: 0 is imaged as white. The maximum
value is imaged as black. This is the normal value for Compression=2.
1 = BlackIsZero. For bilevel and grayscale images: 0 is imaged as black. The maximum
value is imaged as white. If this value is specified for Compression=2, the
image should display and print reversed.
}


TBiLevel: make struct! [
;Here is a list of required fields for Baseline TIFF bilevel images
   ImageWidth [integer! ]; 256 SHORT or LONG
   ImageLength [integer! ]; 257 SHORT or LONG
   BitsPerSample [integer! ];258 SHORT 4 or 8
   Compression [integer! ]; 259 SHORT expected value: 1, 2 or 32773
   PhotometricInterpretation [integer! ]; 262 SHORT expected value 0 1
   StripOffsets [integer! ]; 273 SHORT or LONG
   RowsPerStrip [integer! ]; 278 SHORT or LONG
   StripByteCounts [integer! ]; 279 SHORT or LONG
   XResolution [decimal! ] ;282 RATIONAL
   YResolution [decimal! ] ;283 RATIONAL
   ResolutionUnit [integer! ]; 296 SHORT expected value: 1, 2 or 3   
   ; now some rebol field of interest
   NumberOfStripes [integer!];
] none   


{ Baseline TIFF grayscale images were called TIFF Class G images in earlier versions
of the TIFF specification.
Grayscale images are a generalization of bilevel images. Bilevel images can store
only black and white image data, but grayscale images can also store shades of gray.
Differences from Bilevel Images
Compression = 1 or 32773 (PackBits). In Baseline TIFF, grayscale images can
either be stored as uncompressed data or compressed with the PackBits algorithm.
Caution: PackBits is often ineffective on continuous tone images, including many
grayscale images. In such cases, it is better to leave the image uncompressed.
BitsPerSample
Tag = 258 (102.H)
Type = SHORT
The number of bits per component.
Allowable values for Baseline TIFF grayscale images are 4 and 8, allowing either 16 or 256 distinct shades of gray.
}

TGrayScale: make struct! [
;Here is a list of required fields for GrayScale TIFF images
   ImageWidth [integer! ];256 SHORT or LONG
   ImageLength [integer! ];257 SHORT or LONG
   BitsPerSample [integer! ];258 SHORT 4 or 8
   Compression [integer! ];259 SHORT 1 or 32773
   PhotometricInterpretation [integer! ] ;262 SHORT 0 or 1
   StripOffsets [integer! ];273 SHORT or LONG
   RowsPerStrip [integer! ];278 SHORT or LONG
   StripByteCounts [integer! ];279 LONG or SHORT
   XResolution [decimal! ];282 RATIONAL
   YResolution [decimal! ]; 283 RATIONAL
   ResolutionUnit [integer! ];296 SHORT 1 or 2 or 3
   ; now some rebol field of interest
   NumberOfStripes [integer!];
] none


{Baseline TIFF palette-color images were called TIFF Class P images in earlier
versions of the TIFF specification.

Palette-color images are similar to grayscale images. They still have one component
per pixel, but the component value is used as an index into a full RGB-lookup
table. To describe such images, you need to add or change the following fields.
The other required fields are the same as those for grayscale images.
Differences from Grayscale Images
PhotometricInterpretation = 3 (Palette Color).
ColorMap
Tag = 320 (140.H)
Type = SHORT
N = 3 * (2**BitsPerSample)
This field defines a Red-Green-Blue color map (often called a lookup table) for
palette color images. In a palette-color image, a pixel value is used to index into an
RGB-lookup table. For example, a palette-color pixel having a value of 0 would
be displayed according to the 0th Red, Green, Blue triplet.
In a TIFF ColorMap, all the Red values come first, followed by the Green values,
then the Blue values. In the ColorMap, black is represented by 0,0,0 and white is
represented by 65535, 65535, 65535.
}



TColorPalette: make struct! [
;Here is a list of required fields for Color Palette TIFF images
   ImageWidth [integer! ];256 SHORT or LONG
   ImageLength [integer! ];257 SHORT or LONG
   BitsPerSample [integer! ];258 SHORT 4 or 8
   Compression [integer! ]; 259 SHORT 1 or 32773
   PhotometricInterpretation [integer! ];262 SHORT 3
   StripOffsets [integer! ];273 SHORT or LONG
   RowsPerStrip [integer! ];278 SHORT or LONG
   StripByteCounts [integer! ];279 LONG or SHORT
   XResolution [decimal! ];282 RATIONAL
   YResolution [decimal! ];283 RATIONAL
   ResolutionUnit [integer! ];296 SHORT 1 or 2 or 3
   ColorMap [integer! ];320 SHORT
   ;mlm01 new variable for the colormap count
   ColorMapCount [integer!];320 length
   ; now some rebol field of interest
   NumberOfStripes [integer!];
] none


{ In an RGB image, each pixel is made up of three components: red, green, and
blue. There is no ColorMap.
To describe an RGB image, you need to add or change the following fields and
values. The other required fields are the same as those required for palette-color
images.
Differences from Palette Color Images
BitsPerSample = 8,8,8. Each component is 8 bits deep in a Baseline TIFF RGB image.
PhotometricInterpretation = 2 (RGB).
There is no ColorMap.
SamplesPerPixel
Tag = 277 (115.H)
Type = SHORT
The number of components per pixel. This number is 3 for RGB images, unless
extra samples are present. See the ExtraSamples field for further information.
}


TRGBImage: make struct! [
;Here is a list of required fields for RGB TIFF images
   ImageWidth [integer! ];256 SHORT or LONG
   ImageLength [integer! ];257 SHORT or LONG
   BitsPerSample [integer! ];258 SHORT 8,8,8
   Compression [integer! ];259 SHORT 1 or 32773
   PhotometricInterpretation [integer! ];262 SHORT 2
   StripOffsets [integer! ];273 SHORT or LONG
   SamplesPerPixel [integer! ];277 SHORT 3 or more
   RowsPerStrip [integer! ];278 SHORT or LONG
   StripByteCounts [integer! ];279 LONG or SHORT
   XResolution [decimal! ];282 RATIONAL
   YResolution [decimal! ];283 RATIONAL
   ResolutionUnit [integer! ];296 SHORT 1, 2 or 3
   ; now some rebol field of interest
   NumberOfStripes [integer!];
] none


;Read Tiff File header (8 bytes)
Read-Header: does [
      tiff: head tiff
    header: copy/part tiff 8
      tmp: to-string copy/part header 2
      ; file created by motorola (big endian) or intel (litte endian) processor?
      either (tmp = "MM") [Big_Endian: true byte_order: "Motorola"] [Big_Endian: false byte_order: "Intel"]
      TiffHeader/tiffBOrder: tmp
      header: skip header 2
      tmp: copy/part header 2
      if not Big_Endian [reverse tmp]
      TiffHeader/tiffVersion: to-integer tmp ; expected value: 42
      header: skip header 2
      tmp: copy/part header 4
      if not Big_Endian [reverse tmp]
      TiffHeader/tiffFIFD: to-integer tmp
      ;initialisation des blocs pourla gestion des strips de données :
      clear BStripOffsets
      clear BStripByteCounts
]



; make the list of Image File Directory (IFD) 12 bytes
Make_IFD_List: does [
   IFD_Offset_List: copy []
   ;now move to the First Image directory offset and get the number of entries
   tiff: head tiff
   stream: skip tiff TiffHeader/tiffFIFD
   start_offset: TiffHeader/tiffFIFD
   tmp: copy/part stream 2
if not Big_Endian [reverse tmp]
Number_of_Entries: to-integer tmp
bloc: copy []
append bloc start_offset
append bloc Number_of_Entries
append/only IFD_Offset_List bloc ; append data to the offset list
;move to the next IDF offset and get the value
next_offset: start_offset + 2 + (Number_of_Entries * 12)
stream: skip tiff next_offset
tmp: copy/part stream 4
if not Big_Endian [reverse tmp]
offset_value: to-integer tmp


;now move to the other IFD if exist and get the number of entries
; this is case for multi pages files
;repeat until ifd offset = 0

if offset_value > 0 [
until [
   start_offset: offset_value
   tiff: head tiff
   stream: skip tiff start_offset
       tmp: copy/part stream 2
   if not Big_Endian [reverse tmp]
   Number_of_Entries: to-integer tmp
   bloc: copy []
   append bloc start_offset
   append bloc Number_of_Entries
   append/only IFD_Offset_List bloc
   next_offset: start_offset + 2 + (Number_of_Entries * 12)
   stream: skip tiff next_offset
   tmp: copy/part stream 4
   if not Big_Endian [reverse tmp]
   offset_value: to-integer tmp
   (offset_value = 0 ) ]
]
Number_of_IFD: length? IFD_Offset_List
Number_of_Pages: Number_of_IFD
]



; what kind of images are included in the file ?
; parameter the number of the image
   Get_Image_Type: func [Page_Number] [
   clear Tag_Block
   bloc: pick IFD_Offset_List Page_Number
   start_offset: first bloc ; offset
   Number_of_Entries: second bloc ; number of entries
   for i 1 Number_of_Entries 1 [ tag_offset: (start_offset + 2) + ( 12 * (i - 1))
      ; get the entry values
      tiff: head tiff
      tiff2: skip tiff tag_offset
      stream: copy/part tiff2 12
      tmp: copy/part stream 2
   if not Big_Endian [reverse tmp]
   ; tag number
   TImgFDEntry/tiffTag: to-integer tmp
      stream: skip stream 2
      tmp: copy/part stream 2
   if not Big_Endian [reverse tmp]
   ; tag type
   TImgFDEntry/tiffDataType: to-integer tmp
      stream: skip stream 2
      tmp: copy/part stream 4
   if not Big_Endian [reverse tmp]
   ; tag count or length
   TImgFDEntry/tiffDataLength: to-integer tmp
   stream: skip stream 4
      tmp: copy/part stream 4
      ; value or offset of the value
   if not Big_Endian [reverse tmp]
   TImgFDEntry/tiffOffset: to-integer tmp
   append/only Tag_Block TImgFDEntry/tiffTag
]
   ; image type
   Image_Type: "grayscale"
   ; test image type
   if found? find Tag_Block 277 [Image_Type: "rgb" ]
   if found? find Tag_Block 320 [Image_Type: "palette" ]
   if not found? find Tag_Block 258 [Image_Type: "bilevel" ]
   ;make the structure
switch Image_Type [
   "bilevel" [Timage: make struct! TBiLevel none]
   "grayscale" [Timage: make struct! TGrayScale none]
   "palette" [Timage: make struct! TColorPalette none]
   "rgb" [Timage: make struct! TRGBImage none]
   ]   
   
]


; for each tag get the tag value
Get_Tag_Value: does [
   ; adapt to the real data length in reference to data type
   
      ; use a block rather a string for specific tags such as StripOffsets
      clear tiffBloc
      tiff: head tiff
   
      switch TImgFDEntry/tiffDataType [
       0 [cc: 1 data_type: "NoTYpe"] ;[] ;placeholder ; 1 byte
         1 [cc: 1 data_type: "Byte"] ;[];8-bit unsigned integer
         2 [cc: 1 data_type: "Ascii"] ;[TIFF_];8-bit bytes w/ last byte null
         3 [cc: 2 data_type: "Short"] ;[TIFF_];16-bit unsigned integer
         4 [cc: 4 data_type: "Long" ] ;[TIFF_LONG] ; 32-bit unsigned integer
         5 [cc: 8 data_type: "Rational"] ;[TIFF_RATIONAL]; 64-bit unsigned fraction (Two longs first represents the numerator and second the denominator)
         6 [cc: 1 data_type: "Sbyte"] ;[TIFF_SBYTE] ; !8-bit signed integer
         7 [cc: 1 data_type: "Undefined"] ;[TIFF_] ;!8-bit untyped data
         8 [cc: 2 data_type: "Sshort"] ;[TIFF_SSHORT]; !16-bit signed integer
         9 [cc: 4 data_type: "Slong"] ;[TIFF_SLONG]; !32-bit signed integer
         10 [cc: 8 data_type: "Srational"];[TIFF_SRATIONAL]; !64-bit signed fraction (Two longs first represents the numerator and second the denominator)
         11 [cc: 4 data_type: "Float"];[TIFF_FLOAT]; !32-bit IEEE floating point
         12 [cc: 8 data_type: "Double"];[TIFF_DOUBLE] ;!64-bit IEEE floating point
       ]
       
      ;ici est le le pb
      ;comment savoir si TImgFDEntry/tiffOffset est < 4 bytes
      ;normalement le calcul suivant devrait être correct
       tlong: (TImgFDEntry/tiffDataLength * cc)
       
      ; less than 4 bytes: value is here
      
   either tlong <= 4 [
   TImgFDEntry/tiffValue: to-string (TImgFDEntry/tiffOffset)
   append tiffBloc (to-string TImgFDEntry/tiffOffset)
   ]
   ; > 4 bytes: go to offset to find the tag value
   [tiff: skip tiff to-integer TImgFDEntry/tiffOffset
    str: copy/part tiff (tlong)
   
    switch TImgFDEntry/tiffDataType [
       0 [TImgFDEntry/tiffValue: "0"]
         1 [TImgFDEntry/tiffValue: str]
         2 [TImgFDEntry/tiffValue: str]
         3 [ n1: copy/part str 2
            if not Big_Endian [reverse n1]
            TImgFDEntry/tiffValue: to-string to-integer n1
            ]
         4 [for cpt 1 TImgFDEntry/tiffDataLength 1 [
               n1: copy/part str 4
               str: skip str 4
               if not Big_Endian [reverse n1]
               append tiffBloc (to-string to-integer n1)
               ;if cpt = 1 [TImgFDEntry/tiffValue: join to-string to-integer n1 " , ...."]
               
            ]
          ]
         5 [ ; 64-bit unsigned fraction -> get 2 values
            n1: copy/part str 4
            if not Big_Endian [reverse n1]
            str: skip str 4
            n2: copy/part str 4
            if not Big_Endian [reverse n2]
            TImgFDEntry/tiffValue: to-string ((to-integer n1) / (to-integer n2)) ]
         6 [TImgFDEntry/tiffValue: str]
         7 [TImgFDEntry/tiffValue: str]
         8 [n1: copy/part str 2
            if not Big_Endian [reverse n1]
            TImgFDEntry/tiffValue: to-string to-integer n1]
         9 [n1: copy/part str 4
            if not Big_Endian [reverse n1]
            TImgFDEntry/tiffValue: to-string to-integer n1]
         10 [; 64-bit unsigned fraction -> get 2 values
            n1: copy/part str 4
            if not Big_Endian [reverse n1]
            str: skip str 4
            n2: copy/part str 4
            if not Big_Endian [reverse n2]
            TImgFDEntry/tiffValue: to-string ((to-integer n1) / (to-integer n2))]
         11 [; 64-bit -> get 2 values
            n1: copy/part str 4
            if not Big_Endian [reverse n1]
            str: skip str 4
            n2: copy/part str 4
            if not Big_Endian [reverse n2]
            TImgFDEntry/tiffValue: to-string ((to-integer n1) / (to-integer n2))]
         12 [n1: copy/part str 8
            if not Big_Endian [reverse n1]
            TImgFDEntry/tiffValue: to-string to-integer n1]
          ]
   ]
]

Process_Tags: does [
   tbloc: copy []
   append tbloc TImgFDEntry/tiffTag
   either found? find Tiff_Tags TImgFDEntry/tiffTag [
      code: select Tiff_Tags TImgFDEntry/tiffTag
         
      ;append tbloc to-string second find Tiff_Tags TImgFDEntry/tiffTag
      append tbloc to-string first code
      ]
    [append tbloc to-string ": Unknown Tag"]
   
   ;append tbloc TImgFDEntry/tiffDataType
   append tbloc data_type
   append tbloc TImgFDEntry/tiffDataLength
   append tbloc ": " append tbloc TImgFDEntry/tiffValue
   append tbloc newline
   append/only Tag_List tbloc
   ; set value to image in ref basic common tags to different images
   switch TImgFDEntry/tiffTag [
      256 [TImage/ImageWidth: to-integer TImgFDEntry/tiffValue ]
      257 [TImage/ImageLength: to-integer TImgFDEntry/tiffValue ]
      258 [TImage/BitsPerSample: to-integer TImgFDEntry/tiffValue]
      259 [TImage/Compression: to-integer TImgFDEntry/tiffValue]
      262 [TImage/PhotometricInterpretation: to-integer TImgFDEntry/tiffValue]
      273 [BStripOffsets: copy tiffBloc ]
      278 [TImage/RowsPerStrip: to-integer TImgFDEntry/tiffValue]
      277 [Image_Type = "rgb" [TImage/SamplesPerPixel: to-integer TImgFDEntry/tiffValue]]
      279 [BStripByteCounts: copy tiffBloc TImage/NumberOfStripes: TImgFDEntry/tiffDataLength]
      282 [TImage/XResolution: to-decimal TImgFDEntry/tiffValue]
      283 [TImage/YResolution: to-decimal TImgFDEntry/tiffValue]
      296 [TImage/ResolutionUnit: to-integer TImgFDEntry/tiffValue]
      320 [if Image_Type = "palette" [TImage/Colormap: to-integer TImgFDEntry/tiffOffset
       TImage/ColorMapCount: to-integer (TImgFDEntry/tiffDataLength * cc ) ] ]
   ]
]


Get_Image_Tags: func [index] [
   ; get the image description for each image included in the file
   ;
   clear Tag_List
   bloc: pick IFD_Offset_List index
   start_offset: first bloc
   Number_of_Entries: second bloc
   
   for i 1 Number_of_Entries 1 [ tag_offset: (start_offset) + ( 12 * (i - 1) + 2)   
      tiff: head tiff
      tiff: skip tiff tag_offset
      ; read directory entry (12 bytes)
      stream: copy/part tiff 12
      
      tmp: copy/part stream 2
   if not Big_Endian [reverse tmp]
   TImgFDEntry/tiffTag: to-integer tmp ; tag number
   stream: skip stream 2
   
      tmp: copy/part stream 2
   if not Big_Endian [reverse tmp]
   TImgFDEntry/tiffDataType: to-integer tmp ; tag type
   stream: skip stream 2
   
   tmp: copy/part stream 4
   if not Big_Endian [reverse tmp]
   TImgFDEntry/tiffDataLength: to-integer tmp; number of values of previous tag type
   stream: skip stream 4
   
   tmp: copy/part stream 4
   if not Big_Endian [reverse tmp]
   
   TImgFDEntry/tiffOffset: to-integer tmp ; value offset or data
      
   
   Get_Tag_Value ; get the tag value
   Process_Tags ; and process tags
]

]


; procedure to read images from the tiff file
;parameter: the number of the page in case of multipage file
Get_Image_Data: func [page] [
   
   clear image_data
   clear image_rgb
   
   Get_Image_Type page
   Get_Image_Tags page
   ;now get the image data
   
   BStripOffsets: head BStripOffsets
   BStripByteCounts: head BStripByteCounts
   for i 1 TImage/NumberOfStripes 1 [
    startoff: pick BStripOffsets i
    tiff: head tiff
    tiff: skip tiff to-integer startoff
    donnee: copy/part tiff ( to-integer (pick BStripByteCounts i) )
    append image_data donnee
]
if (Image_Type = "palette") [
      tiff: head tiff
      skip tiff TImage/Colormap
      data: copy/part tiff TImage/ColorMapCount
      append image_rgb data
   ]

]



Read_Tiff_File: has [files] [
   files: request-file/filter ["*.tiff" "*.tif"]
   either all [
         (not none? files)
         (not empty? files)
   ] [
         tiff: read/binary first files Read-header
         Make_IFD_List
         Get_Image_Data 1
         return first files
      ]
      [return none]
]
ldci20-Feb-2010/0:15:37+1:00
Re
Voici le code pour tester la lib. Désolé pour l'oubli

#! /boot/home/rebol/rebol -qs
REBOL [
title: "Tiff Reader Demo"
]
;call Tiff Library
do %tifflib.r

Show_File_Information: does [
   t1/text: join "File: " fichier
   t2/text: join "Image Type: " Image_Type
   t3/text: join "Byte Order: " byte_order
   hsl/data: 0 nimage/text: "1"
   either (Number_of_Pages > 1) [show [hsl nimage]][hide [hsl nimage]]
   show [t1 t2 t3 ]
   
]


Show_Image_informations: does [
   clear test/text
   test/line-list: none
   
append test/text Tag_List


either (Image_Type = "palette") [
   tvisu: make image! reduce [ to-pair compose [ (TImage/ImageWidth) (TImage/ImageLength)] image_rgb image_data ]
   ] [
   tvisu: make image! reduce [ to-pair compose [ (TImage/ImageWidth) (TImage/ImageLength)] image_data ]
   ]   
   
   
visu/image: copy tvisu

show [test visu]    
]



MainWin: layout [
   origin 0X0
   space 0X0
   across
   at 5x3 btn 100 "Browse" [
         tiffnimage: 1
         fichier: Read_Tiff_File
         if not none? fichier [Show_File_Information Show_Image_informations]
]
pad 5 t1: info 405
pad 5 t2: info 155
pad 5 t3: info 155
   at 5x30 visu: image 512x512 frame blue
   at 520x30
   test: area wrap 300x512 sl: slider 16x512 [scroll-para test sl]
   
   at 5x555 hsl: scroller 445x12 [nimage/text: to-integer (hsl/data * (Number_of_IFD - 1)) + 1
       if (TImage/compression = 1 ) [
         tiffnimage: to-integer nimage/text
          show nimage
          if (Number_of_Pages > 1) [ Get_Image_Data tiffnimage Show_Image_informations ]
             
      ]
   ]
   at 460x550 nimage: info center 50 to-string Number_of_Pages
   
   
]

view/new center-face MainWin
hide [hsl nimage]
;visu/effect: 'aspect

insert-event-func [
   either all [event/type = 'close event/face = MainWin][
      quit
   ][event]
]

do-events
ldci20-Feb-2010/16:51:37+1:00
Dont't Act
J'ai trouvé le problème: tout c.. Rebol traite les short(16-bit) comme des integer c'est à dire en 32-bit...
Donc quand on récupère la valeur placée dans le champ offset/value on a toujours 4 bytes d'utilisés comme pour un entier. On doit donc corriger les calculs.
exemple pour le Ushort if valeur > 65535 [valeur: valeur / 65536].
Je mettrai le code sur Rebol.org quand il sera terminé.
Bon WE

Login required to Post.


Powered by RebelBB and REBOL 2.7.8.4.2