<?xml version="1.0" encoding="UTF-8"?>
<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema"
    xmlns:wam="http://www.thewalters.org/ns/mss-manifest/1.0/"
    xmlns:jhove="http://hul.harvard.edu/ois/xml/ns/jhove"
    targetNamespace="http://www.thewalters.org/ns/mss-manifest/1.0/" elementFormDefault="qualified"
    attributeFormDefault="unqualified" xmlns:dc="http://purl.org/dc/elements/1.1/"
    xmlns:mix="http://www.loc.gov/mix/v20 file:mix20.xsd">

    <!--<xs:import namespace="http://purl.org/dc/elements/1.1/" schemaLocation="http://purl.org/dc/elements/1.1/"/>-->
    <xs:import namespace="http://purl.org/dc/elements/1.1/" schemaLocation="dc.xsd"/>
    <xs:element name="manuscript" type="wam:manuscriptType"/>

    <xs:complexType name="manuscriptType">
        <xs:annotation>
            <xs:documentation>
                A manuscript consists of an imaged object and the 
                images of that object.  The imaged_object describes the 
                manuscript, whether a book or single sheet.
                
                The images collection has one image element for each distinct 
                image of the object: outside/inside cover, folio, and so forth.  
                Each image element contains data on one master image and several 
                derivatives.
            </xs:documentation>
        </xs:annotation>
        <xs:sequence>
            <xs:element name="imaged_object" type="wam:imagedObjectType"/>
            <xs:element name="images">
                <xs:complexType>
                    <xs:sequence>
                        <xs:element name="image" type="wam:imageType" minOccurs="1"
                            maxOccurs="unbounded"/>
                    </xs:sequence>
                </xs:complexType>
            </xs:element>
        </xs:sequence>
    </xs:complexType>

    <xs:complexType name="imagedObjectType">
        <xs:sequence>
            <xs:group ref="dc:elementsGroup">
                <xs:annotation>
                    <xs:documentation>
                        The list of Dublin Core elements to describe this
                        manuscript.
                    </xs:documentation>
                </xs:annotation>
            </xs:group>
            <xs:element name="imageCount" type="xs:integer">
                <xs:annotation>
                    <xs:documentation>
                        The number of images taken of this manuscript.
                    </xs:documentation>
                </xs:annotation>
            </xs:element>
        </xs:sequence>
    </xs:complexType>

    <xs:complexType name="masterDerivationType">
        <xs:annotation>
            <xs:documentation>
                Metadata describing how the master TIFF file was 
                derived from the raw image described in the
                capture section.
            </xs:documentation>
        </xs:annotation>
        <xs:sequence>
            <xs:element name="corrected_date" type="xs:dateTime">
                <xs:annotation>
                    <xs:documentation>
                        The date of manual image cropping and color
                        correction made by the operator to the evaluation 
                        copy of the raw image.
                    </xs:documentation>
                </xs:annotation>
            </xs:element>
            <xs:element name="verified_date" type="xs:dateTime">
                <xs:annotation>
                    <xs:documentation>
                        The date of quality assurance verification
                        after correction before modification.
                    </xs:documentation>
                </xs:annotation>
            </xs:element>
            <xs:element name="automation_date" type="xs:dateTime">
                <xs:annotation>
                    <xs:documentation>
                        The date of the automated application of color
                        manual correction made by the user to the
                        evaluation copy of the raw images and the 
                        creation of master and other derivative images.
                    </xs:documentation>
                </xs:annotation>
            </xs:element>
            <xs:element name="inspected_date" type="xs:dateTime">
                <xs:annotation>
                    <xs:documentation>
                        The date of visual inspection by the operator
                        of the outputs of the IWS software's automation
                        output.
                    </xs:documentation>
                </xs:annotation>
            </xs:element>
            <xs:element name="red_gamma" type="xs:float"/>
            <xs:element name="green_gamma" type="xs:float"/>
            <xs:element name="blue_gamma" type="xs:float"/>
            <xs:element name="crop" type="wam:cropType">
                <xs:annotation>
                    <xs:documentation>
                        Crop information describing how the master
                        was derived from the raw image.  
                        
                        The raw image is 
                        rotated before cropping.  For example, if the raw 
                        image is rotated 90 degrees clockwise,
                        the "top" of the image is the post-rotation top of 
                        the image (which had been the left edge of the image 
                        before the rotation).
                        
                        The cropping for the master TIFF image is expressed 
                        in the IWS database in percentage values multiplied 
                        by 1000.  Here, these values are given as real 
                        numbers to three places of percision.
                    </xs:documentation>
                </xs:annotation>
            </xs:element>
            <xs:element name="degrees_rotation" type="xs:float">
                <xs:annotation>
                    <xs:documentation>
                        Degrees of deskew rotation applied by the operator
                        during correction.
                    </xs:documentation>
                </xs:annotation>
            </xs:element>
            <xs:element name="scale" type="wam:scaleType">
                <xs:annotation>
                    <xs:documentation>
                        Scale applied to this derivative: pixelsPerInch, 
                        maxPixelsPerSide, or none.  Should be none for
                        the master TIFF.
                    </xs:documentation>
                </xs:annotation>
            </xs:element>
            <xs:element name="derivative_bit_depth" type="xs:integer">
                <xs:annotation>
                    <xs:documentation>
                        Derivative bit depth: usually 24-bit for color
                        images.
                    </xs:documentation>
                </xs:annotation>
            </xs:element>
            <xs:element name="derivative_rotate" type="wam:yesNoType">
                <xs:annotation>
                    <xs:documentation>
                        Whether the derivative is rotated.
                    </xs:documentation>
                </xs:annotation>
            </xs:element>
            <xs:element name="derivative_color_correct" type="wam:yesNoType">
                <xs:annotation>
                    <xs:documentation>
                        Whether the derivative is color corrected.
                    </xs:documentation>
                </xs:annotation>
            </xs:element>
            <xs:element name="derivative_sharpening_level" type="xs:integer"/>
            <xs:element name="derivative_medium_moire_blur_level" type="xs:integer"/>
            <xs:element name="derivative_medium_moire_sharpening_level" type="xs:integer"/>
            <xs:element name="derivative_high_moire_blur_level" type="xs:integer"/>
            <xs:element name="derivative_high_moire_sharpening_level" type="xs:integer"/>
            <xs:element name="derivative_color_jpg_compression" type="xs:integer"/>
            <xs:element name="derivative_grayscale_jpg_compression" type="xs:integer"/>
            <xs:element name="derivative_bits_per_channel" type="xs:integer"/>
            <xs:element name="derivative_filesize" type="xs:integer"/>
            <xs:element name="derivative_ppi" type="xs:integer"/>
            <xs:element name="derivative_width" type="xs:integer"/>
            <xs:element name="derivative_height" type="xs:integer"/>
            <!--<xs:element name="derivative_checksum" type="xs:string"/>-->
        </xs:sequence>
    </xs:complexType>

    <xs:simpleType name="yesNoType">
        <xs:restriction base="xs:NMTOKEN">
            <xs:enumeration value="y"/>
            <xs:enumeration value="n"/>
        </xs:restriction>
    </xs:simpleType>

    <xs:complexType name="captureType">
        <xs:sequence>
            <xs:element name="image_id" type="xs:integer"/>
            <xs:element name="project_id" type="xs:string"/>
            <xs:element name="original_size" type="xs:integer" minOccurs="0"/>
            <xs:element name="scan_width_pixels" type="xs:integer"/>
            <xs:element name="scan_height_pixels" type="xs:integer"/>
            <xs:element name="scan_width_inches" type="xs:double"/>
            <xs:element name="scan_height_inches" type="xs:double"/>
            <xs:element name="captured_image_path" type="xs:string"/>
            <xs:element name="raw_filename" type="xs:string"/>
            <xs:element name="walters_image_ppi" type="xs:string">
                <xs:annotation>
                    <xs:documentation>
                        Either the camera-calculated pixels per inch value
                        of the image (the default) or an operator-entered 
                        value that overrides the camera value (stored in
                        the IWS database as raw_image_ppi).  
                        
                        Each imaged cover and page of a manuscript or book
                        rests flat on a vacuum wedge that is parallel to
                        the camera sensor.
                        The camera calculates the image's PPI value based on 
                        its distance from the wedge.  While this gives an
                        accurate PPI value for the flat components of a 
                        manuscript or printed book, it is not correct for 
                        edge components, which are photographed by placing 
                        the book's flat surface perpendicular to the 
                        wedge.
                        Images of a manuscript's spine, head, tail, or 
                        fore-edge have a focal plane closer to the camera 
                        from the wedge by the height or width of the book.  
                        For these images, the operator calculates the actual 
                        PPI, using a ruler placed in the same focal plane as 
                        the imaged object.
                    </xs:documentation>
                </xs:annotation>
            </xs:element>
            <xs:element name="red_raw_min" type="xs:integer"/>
            <xs:element name="red_raw_max" type="xs:integer"/>
            <xs:element name="green_raw_min" type="xs:integer"/>
            <xs:element name="green_raw_max" type="xs:integer"/>
            <xs:element name="blue_raw_min" type="xs:integer"/>
            <xs:element name="blue_raw_max" type="xs:integer"/>
            <xs:element name="raw_image_size" type="xs:integer"/>
            <xs:element name="rotate_at_scan" type="xs:double">
                <xs:annotation>
                    <xs:documentation>
                        How the image should be rotated after capture
                        to be for the object to upright in the view frame.
                        Folios are usually imaged at a right angle to the 
                        top of the sensor and so the captured images are
                        rotated -90.0º or 90.0º.
                        
                        At capture images are rotated.  Cropping, color 
                        correction and other values are based on and 
                        applied to the rotated raw image.
                    </xs:documentation>
                </xs:annotation>
            </xs:element>
            <xs:element name="exposure_time_ms" type="xs:integer"/>
            <xs:element name="aperture_setting" type="xs:float"/>
            <xs:element name="light_source" type="xs:string"/>
            <xs:element name="captured_date" type="xs:dateTime"/>
            <xs:element name="scan_width_mm" type="xs:double"/>
            <xs:element name="scan_height_mm" type="xs:double"/>
            <xs:element name="scan_mode" type="xs:string">
                <xs:annotation>
                    <xs:documentation>
                        Current values:
                            1x1x16&gt;0 PPI
                            1x1x16&gt;600 PPI
                            1x1x4&gt;0 PPI
                        Waiting for complete explanation from John T. 
                        Stokes.  The values 4 and 16 are the number of 
                        shots in the scan.
                    </xs:documentation>
                </xs:annotation>
            </xs:element>
        </xs:sequence>
    </xs:complexType>

    <xs:complexType name="imageType">
        <xs:sequence>
            <xs:element name="index" type="xs:integer"/>
            <xs:element name="image_subject" type="xs:string"/>
            <xs:element name="capture" type="wam:captureType"/>
            <xs:element name="masterDerivation" type="wam:masterDerivationType"/>
            <xs:element name="jhoveData">
                <xs:annotation>
                    <xs:documentation>
                        The JHOVE xml output for this image.
                    </xs:documentation>
                </xs:annotation>
                <xs:complexType>
                    <xs:sequence>
                        <xs:any namespace="http://hul.harvard.edu/ois/xml/ns/jhove"/>
                    </xs:sequence>
                </xs:complexType>
            </xs:element>
            <xs:element name="derivative" type="wam:derivativeType" minOccurs="1"
                maxOccurs="unbounded">
                <xs:annotation>
                    <xs:documentation>
                        Data describing the derivatives that may be created 
                        from this master TIFF.
                    </xs:documentation>
                </xs:annotation>
            </xs:element>
        </xs:sequence>
    </xs:complexType>

    <xs:complexType name="cropType">
        <xs:annotation>
            <xs:documentation>
                Description of the crop of this
            </xs:documentation>
        </xs:annotation>
        <xs:sequence>
            <xs:element name="left" type="xs:float"/>
            <xs:element name="top" type="xs:float"/>
            <xs:element name="right" type="xs:float"/>
            <xs:element name="bottom" type="xs:float"/>
        </xs:sequence>
        <xs:attribute name="unit" use="required">
            <xs:simpleType>
                <xs:restriction base="xs:string">
                    <xs:enumeration value="percent"/>
                    <xs:enumeration value="pixel"/>
                </xs:restriction>
            </xs:simpleType>
        </xs:attribute>
    </xs:complexType>

    <xs:complexType name="derivativeType">
        <xs:sequence>
            <xs:element name="derivative_filename" type="xs:string"/>
            <xs:element name="file_format">
                <xs:simpleType>
                    <xs:restriction base="xs:NMTOKEN">
                        <xs:enumeration value="TIFF"/>
                        <xs:enumeration value="JPEG"/>
                    </xs:restriction>
                </xs:simpleType>
            </xs:element>
            <xs:element name="derivative_class">
                <xs:annotation>
                    <xs:documentation>
                        The class value indicates the class of the derivative:
                        
                        sap      Standard All-Purpose JPEG image.  1800
                                 pixels on its longest side
                        
                        thumb    Thumbnail JPEG. 190 pixels on its 
                                 longest side
                        
                        300      300 PPI TIFF image.
                        
                        Each derivative file has a flag in its name in 
                        the last position in the name before the file 
                        extension.
                        
                        
                    </xs:documentation>
                </xs:annotation>
                <xs:simpleType>
                    <xs:restriction base="xs:token">
                        <xs:enumeration value="sap"/>
                        <xs:enumeration value="thumb"/>
                        <xs:enumeration value="300"/>
                        <xs:enumeration value="master"/>
                    </xs:restriction>
                </xs:simpleType>
            </xs:element>
            <xs:element name="crop" type="wam:cropType"/>
            <xs:element name="scale" type="wam:scaleType"/>
            <xs:element name="derivative_bit_depth" type="xs:integer"/>
            <xs:element name="derivative_bits_per_channel" type="xs:integer"/>
            <xs:element name="derivative_color_jpg_compression" type="xs:integer" minOccurs="0" maxOccurs="1"/>
            <xs:element name="derivative_grayscale_jpg_compression" type="xs:integer" minOccurs="0" maxOccurs="1"/>
        </xs:sequence>
    </xs:complexType>

    <xs:complexType name="scaleType">
        <xs:annotation>
            <xs:documentation> The values for derivative_scale in the IWS db are: 1800xMIN 190xMIN
                300 300PPI &lt;NONE&gt; These values will be mapped to scale, for example:
                &lt;scale&gt; &lt;pixelsPerInch&gt;300&lt;/pixelsPerInch&gt;
                &lt;/scale&gt; &lt;scale&gt;
                &lt;maxPixelsPerSide&gt;1800&lt;/maxPixelsPerSide&gt;
                &lt;/scale&gt; &lt;scale&gt; &lt;none/&gt;
                &lt;/scale&gt; </xs:documentation>
        </xs:annotation>
        <xs:choice>
            <xs:element name="pixelsPerInch" type="xs:integer"/>
            <xs:element name="maxPixelsPerSide" type="xs:integer"/>
            <xs:element name="none">
                <xs:simpleType>
                    <xs:restriction base="xs:NMTOKEN">
                        <xs:enumeration value="none"/>
                    </xs:restriction>
                </xs:simpleType>
            </xs:element>
        </xs:choice>
    </xs:complexType>
</xs:schema>
