github.com/boki/go-xmp@v1.0.1/models/crs/model.go (about)

     1  // Copyright (c) 2017-2018 Alexander Eichhorn
     2  //
     3  // Licensed under the Apache License, Version 2.0 (the "License"): you may
     4  // not use this file except in compliance with the License. You may obtain
     5  // a copy of the License at
     6  //
     7  //     http://www.apache.org/licenses/LICENSE-2.0
     8  //
     9  // Unless required by applicable law or agreed to in writing, software
    10  // distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
    11  // WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
    12  // License for the specific language governing permissions and limitations
    13  // under the License.
    14  
    15  // Package crs implements Adobe Camera Raw metadata as defined in chapter 3.3 of XMP Specification Part 2.
    16  package crs
    17  
    18  import (
    19  	"fmt"
    20  	"trimmer.io/go-xmp/xmp"
    21  )
    22  
    23  var (
    24  	NsCrs = xmp.NewNamespace("crs", "http://ns.adobe.com/camera-raw-settings/1.0/", NewModel)
    25  )
    26  
    27  func init() {
    28  	xmp.Register(NsCrs, xmp.ImageMetadata)
    29  }
    30  
    31  func NewModel(name string) xmp.Model {
    32  	return &CameraRawInfo{}
    33  }
    34  
    35  func MakeModel(d *xmp.Document) (*CameraRawInfo, error) {
    36  	m, err := d.MakeModel(NsCrs)
    37  	if err != nil {
    38  		return nil, err
    39  	}
    40  	x, _ := m.(*CameraRawInfo)
    41  	return x, nil
    42  }
    43  
    44  func FindModel(d *xmp.Document) *CameraRawInfo {
    45  	if m := d.FindModel(NsCrs); m != nil {
    46  		return m.(*CameraRawInfo)
    47  	}
    48  	return nil
    49  }
    50  
    51  // Part 2: 3.3 Camera Raw namespace
    52  type CameraRawInfo struct {
    53  	AutoBrightness       xmp.Bool        `xmp:"crs:AutoBrightness"`
    54  	AutoContrast         xmp.Bool        `xmp:"crs:AutoContrast"`
    55  	AutoExposure         xmp.Bool        `xmp:"crs:AutoExposure"`
    56  	AutoShadows          xmp.Bool        `xmp:"crs:AutoShadows"`
    57  	BlueHue              int64           `xmp:"crs:BlueHue"`
    58  	BlueSaturation       int64           `xmp:"crs:BlueSaturation"`
    59  	Brightness           int64           `xmp:"crs:Brightness"`
    60  	CameraProfile        string          `xmp:"crs:CameraProfile"`
    61  	ChromaticAberrationB int64           `xmp:"crs:ChromaticAberrationB"`
    62  	ChromaticAberrationR int64           `xmp:"crs:ChromaticAberrationR"`
    63  	ColorNoiseReduction  int64           `xmp:"crs:ColorNoiseReduction"`
    64  	Contrast             int64           `xmp:"crs:Contrast"`
    65  	CropTop              float32         `xmp:"crs:CropTop"`
    66  	CropLeft             float32         `xmp:"crs:CropLeft"`
    67  	CropBottom           float32         `xmp:"crs:CropBottom"`
    68  	CropRight            float32         `xmp:"crs:CropRight"`
    69  	CropAngle            float32         `xmp:"crs:CropAngle"`
    70  	CropWidth            float32         `xmp:"crs:CropWidth"`
    71  	CropHeight           float32         `xmp:"crs:CropHeight"`
    72  	CropUnits            CropUnits       `xmp:"crs:CropUnits"`
    73  	Exposure             float32         `xmp:"crs:Exposure"`
    74  	GreenHue             int64           `xmp:"crs:GreenHue"`
    75  	GreenSaturation      int64           `xmp:"crs:GreenSaturation"`
    76  	HasCrop              xmp.Bool        `xmp:"crs:HasCrop"`
    77  	HasSettings          xmp.Bool        `xmp:"crs:HasSettings"`
    78  	LuminanceSmoothing   int64           `xmp:"crs:LuminanceSmoothing"`
    79  	RawFileName          string          `xmp:"crs:RawFileName"`
    80  	RedHue               int64           `xmp:"crs:RedHue"`
    81  	RedSaturation        int64           `xmp:"crs:RedSaturation"`
    82  	Saturation           int64           `xmp:"crs:Saturation"`
    83  	Shadows              int64           `xmp:"crs:Shadows"`
    84  	ShadowTint           int64           `xmp:"crs:ShadowTint"`
    85  	Sharpness            int64           `xmp:"crs:Sharpness"`
    86  	Temperature          int64           `xmp:"crs:Temperature"`
    87  	Tint                 int64           `xmp:"crs:Tint"`
    88  	ToneCurve            xmp.StringArray `xmp:"crs:ToneCurve"`
    89  	ToneCurveName        ToneCurve       `xmp:"crs:ToneCurveName"`
    90  	Version              string          `xmp:"crs:Version"`
    91  	VignetteAmount       int64           `xmp:"crs:VignetteAmount"`
    92  	VignetteMidpoint     int64           `xmp:"crs:VignetteMidpoint"`
    93  	WhiteBalance         WhiteBalance    `xmp:"crs:WhiteBalance"`
    94  
    95  	// non-standard fields found in samples in the wild
    96  	AlreadyApplied                        xmp.Bool        `xmp:"crs:AlreadyApplied"`
    97  	Dehaze                                int             `xmp:"crs:Dehaze"`
    98  	Converter                             string          `xmp:"crs:Converter"`
    99  	MoireFilter                           string          `xmp:"crs:MoireFilter"`
   100  	Smoothness                            int64           `xmp:"crs:Smoothness"`
   101  	CameraProfileDigest                   string          `xmp:"crs:CameraProfileDigest"`
   102  	Clarity                               int64           `xmp:"crs:Clarity"`
   103  	ConvertToGrayscale                    xmp.Bool        `xmp:"crs:ConvertToGrayscale"`
   104  	Defringe                              int64           `xmp:"crs:Defringe"`
   105  	FillLight                             int64           `xmp:"crs:FillLight"`
   106  	HighlightRecovery                     int64           `xmp:"crs:HighlightRecovery"`
   107  	HueAdjustmentAqua                     int64           `xmp:"crs:HueAdjustmentAqua"`
   108  	HueAdjustmentBlue                     int64           `xmp:"crs:HueAdjustmentBlue"`
   109  	HueAdjustmentGreen                    int64           `xmp:"crs:HueAdjustmentGreen"`
   110  	HueAdjustmentMagenta                  int64           `xmp:"crs:HueAdjustmentMagenta"`
   111  	HueAdjustmentOrange                   int64           `xmp:"crs:HueAdjustmentOrange"`
   112  	HueAdjustmentPurple                   int64           `xmp:"crs:HueAdjustmentPurple"`
   113  	HueAdjustmentRed                      int64           `xmp:"crs:HueAdjustmentRed"`
   114  	HueAdjustmentYellow                   int64           `xmp:"crs:HueAdjustmentYellow"`
   115  	IncrementalTemperature                int64           `xmp:"crs:IncrementalTemperature"`
   116  	IncrementalTint                       int64           `xmp:"crs:IncrementalTint"`
   117  	LuminanceAdjustmentAqua               int64           `xmp:"crs:LuminanceAdjustmentAqua"`
   118  	LuminanceAdjustmentBlue               int64           `xmp:"crs:LuminanceAdjustmentBlue"`
   119  	LuminanceAdjustmentGreen              int64           `xmp:"crs:LuminanceAdjustmentGreen"`
   120  	LuminanceAdjustmentMagenta            int64           `xmp:"crs:LuminanceAdjustmentMagenta"`
   121  	LuminanceAdjustmentOrange             int64           `xmp:"crs:LuminanceAdjustmentOrange"`
   122  	LuminanceAdjustmentPurple             int64           `xmp:"crs:LuminanceAdjustmentPurple"`
   123  	LuminanceAdjustmentRed                int64           `xmp:"crs:LuminanceAdjustmentRed"`
   124  	LuminanceAdjustmentYellow             int64           `xmp:"crs:LuminanceAdjustmentYellow"`
   125  	ParametricDarks                       int64           `xmp:"crs:ParametricDarks"`
   126  	ParametricHighlights                  int64           `xmp:"crs:ParametricHighlights"`
   127  	ParametricHighlightSplit              int64           `xmp:"crs:ParametricHighlightSplit"`
   128  	ParametricLights                      int64           `xmp:"crs:ParametricLights"`
   129  	ParametricMidtoneSplit                int64           `xmp:"crs:ParametricMidtoneSplit"`
   130  	ParametricShadows                     int64           `xmp:"crs:ParametricShadows"`
   131  	ParametricShadowSplit                 int64           `xmp:"crs:ParametricShadowSplit"`
   132  	SaturationAdjustmentAqua              int64           `xmp:"crs:SaturationAdjustmentAqua"`
   133  	SaturationAdjustmentBlue              int64           `xmp:"crs:SaturationAdjustmentBlue"`
   134  	SaturationAdjustmentGreen             int64           `xmp:"crs:SaturationAdjustmentGreen"`
   135  	SaturationAdjustmentMagenta           int64           `xmp:"crs:SaturationAdjustmentMagenta"`
   136  	SaturationAdjustmentOrange            int64           `xmp:"crs:SaturationAdjustmentOrange"`
   137  	SaturationAdjustmentPurple            int64           `xmp:"crs:SaturationAdjustmentPurple"`
   138  	SaturationAdjustmentRed               int64           `xmp:"crs:SaturationAdjustmentRed"`
   139  	SaturationAdjustmentYellow            int64           `xmp:"crs:SaturationAdjustmentYellow"`
   140  	SharpenDetail                         int64           `xmp:"crs:SharpenDetail"`
   141  	SharpenEdgeMasking                    int64           `xmp:"crs:SharpenEdgeMasking"`
   142  	SharpenRadius                         float32         `xmp:"crs:SharpenRadius"`
   143  	SplitToningBalance                    int64           `xmp:"crs:SplitToningBalance"`
   144  	SplitToningHighlightHue               int64           `xmp:"crs:SplitToningHighlightHue"`
   145  	SplitToningHighlightSaturation        int64           `xmp:"crs:SplitToningHighlightSaturation"`
   146  	SplitToningShadowHue                  int64           `xmp:"crs:SplitToningShadowHue"`
   147  	SplitToningShadowSaturation           int64           `xmp:"crs:SplitToningShadowSaturation"`
   148  	Vibrance                              int64           `xmp:"crs:Vibrance"`
   149  	GrayMixerRed                          int64           `xmp:"crs:GrayMixerRed"`
   150  	GrayMixerOrange                       int64           `xmp:"crs:GrayMixerOrange"`
   151  	GrayMixerYellow                       int64           `xmp:"crs:GrayMixerYellow"`
   152  	GrayMixerGreen                        int64           `xmp:"crs:GrayMixerGreen"`
   153  	GrayMixerAqua                         int64           `xmp:"crs:GrayMixerAqua"`
   154  	GrayMixerBlue                         int64           `xmp:"crs:GrayMixerBlue"`
   155  	GrayMixerPurple                       int64           `xmp:"crs:GrayMixerPurple"`
   156  	GrayMixerMagenta                      int64           `xmp:"crs:GrayMixerMagenta"`
   157  	RetouchInfo                           xmp.StringArray `xmp:"crs:RetouchInfo"`
   158  	RedEyeInfo                            xmp.StringArray `xmp:"crs:RedEyeInfo"`
   159  	CropUnit                              int64           `xmp:"crs:CropUnit"`
   160  	PostCropVignetteAmount                int64           `xmp:"crs:PostCropVignetteAmount"`
   161  	PostCropVignetteMidpoint              int64           `xmp:"crs:PostCropVignetteMidpoint"`
   162  	PostCropVignetteFeather               int64           `xmp:"crs:PostCropVignetteFeather"`
   163  	PostCropVignetteRoundness             int64           `xmp:"crs:PostCropVignetteRoundness"`
   164  	PostCropVignetteStyle                 int64           `xmp:"crs:PostCropVignetteStyle"`
   165  	ProcessVersion                        string          `xmp:"crs:ProcessVersion"`
   166  	LensProfileEnable                     int64           `xmp:"crs:LensProfileEnable"`
   167  	LensProfileSetup                      string          `xmp:"crs:LensProfileSetup"`
   168  	LensProfileName                       string          `xmp:"crs:LensProfileName"`
   169  	LensProfileFilename                   string          `xmp:"crs:LensProfileFilename"`
   170  	LensProfileDigest                     string          `xmp:"crs:LensProfileDigest"`
   171  	LensProfileDistortionScale            int64           `xmp:"crs:LensProfileDistortionScale"`
   172  	LensProfileChromaticAberrationScale   int64           `xmp:"crs:LensProfileChromaticAberrationScale"`
   173  	LensProfileVignettingScale            int64           `xmp:"crs:LensProfileVignettingScale"`
   174  	LensManualDistortionAmount            int64           `xmp:"crs:LensManualDistortionAmount"`
   175  	PerspectiveVertical                   int64           `xmp:"crs:PerspectiveVertical"`
   176  	PerspectiveHorizontal                 int64           `xmp:"crs:PerspectiveHorizontal"`
   177  	PerspectiveRotate                     float32         `xmp:"crs:PerspectiveRotate"`
   178  	PerspectiveScale                      int64           `xmp:"crs:PerspectiveScale"`
   179  	CropConstrainToWarp                   int64           `xmp:"crs:CropConstrainToWarp"`
   180  	LuminanceNoiseReductionDetail         int64           `xmp:"crs:LuminanceNoiseReductionDetail"`
   181  	LuminanceNoiseReductionContrast       int64           `xmp:"crs:LuminanceNoiseReductionContrast"`
   182  	ColorNoiseReductionDetail             int64           `xmp:"crs:ColorNoiseReductionDetail"`
   183  	GrainAmount                           int64           `xmp:"crs:GrainAmount"`
   184  	GrainSize                             int64           `xmp:"crs:GrainSize"`
   185  	GrainFrequency                        int64           `xmp:"crs:GrainFrequency"`
   186  	AutoLateralCA                         int64           `xmp:"crs:AutoLateralCA"`
   187  	Exposure2012                          float32         `xmp:"crs:Exposure2012"`
   188  	Contrast2012                          int64           `xmp:"crs:Contrast2012"`
   189  	Highlights2012                        int64           `xmp:"crs:Highlights2012"`
   190  	Shadows2012                           int64           `xmp:"crs:Shadows2012"`
   191  	Whites2012                            int64           `xmp:"crs:Whites2012"`
   192  	Blacks2012                            int64           `xmp:"crs:Blacks2012"`
   193  	Clarity2012                           int64           `xmp:"crs:Clarity2012"`
   194  	PostCropVignetteHighlightContrast     int64           `xmp:"crs:PostCropVignetteHighlightContrast"`
   195  	ToneCurveName2012                     ToneCurve       `xmp:"crs:ToneCurveName2012"`
   196  	ToneCurveRed                          PointList       `xmp:"crs:ToneCurveRed"`
   197  	ToneCurveGreen                        PointList       `xmp:"crs:ToneCurveGreen"`
   198  	ToneCurveBlue                         PointList       `xmp:"crs:ToneCurveBlue"`
   199  	ToneCurvePV2012                       PointList       `xmp:"crs:ToneCurvePV2012"`
   200  	ToneCurvePV2012Red                    PointList       `xmp:"crs:ToneCurvePV2012Red"`
   201  	ToneCurvePV2012Green                  PointList       `xmp:"crs:ToneCurvePV2012Green"`
   202  	ToneCurvePV2012Blue                   PointList       `xmp:"crs:ToneCurvePV2012Blue"`
   203  	ToneMapStrength                       int             `xmp:"crs:ToneMapStrength"`
   204  	DefringePurpleAmount                  int64           `xmp:"crs:DefringePurpleAmount"`
   205  	DefringePurpleHueLo                   int64           `xmp:"crs:DefringePurpleHueLo"`
   206  	DefringePurpleHueHi                   int64           `xmp:"crs:DefringePurpleHueHi"`
   207  	DefringeGreenAmount                   int64           `xmp:"crs:DefringeGreenAmount"`
   208  	DefringeGreenHueLo                    int64           `xmp:"crs:DefringeGreenHueLo"`
   209  	DefringeGreenHueHi                    int64           `xmp:"crs:DefringeGreenHueHi"`
   210  	AutoWhiteVersion                      int64           `xmp:"crs:AutoWhiteVersion"`
   211  	ColorNoiseReductionSmoothness         int64           `xmp:"crs:ColorNoiseReductionSmoothness"`
   212  	PerspectiveAspect                     int64           `xmp:"crs:PerspectiveAspect"`
   213  	PerspectiveUpright                    int64           `xmp:"crs:PerspectiveUpright"`
   214  	UprightVersion                        int64           `xmp:"crs:UprightVersion"`
   215  	UprightCenterMode                     int64           `xmp:"crs:UprightCenterMode"`
   216  	UprightCenterNormX                    float32         `xmp:"crs:UprightCenterNormX"`
   217  	UprightCenterNormY                    float32         `xmp:"crs:UprightCenterNormY"`
   218  	UprightFocalMode                      int64           `xmp:"crs:UprightFocalMode"`
   219  	UprightFocalLength35mm                float32         `xmp:"crs:UprightFocalLength35mm"`
   220  	UprightPreview                        xmp.Bool        `xmp:"crs:UprightPreview"`
   221  	UprightTransformCount                 int64           `xmp:"crs:UprightTransformCount"`
   222  	UprightDependentDigest                string          `xmp:"crs:UprightDependentDigest"`
   223  	UprightTransform_0                    string          `xmp:"crs:UprightTransform_0"`
   224  	UprightTransform_1                    string          `xmp:"crs:UprightTransform_1"`
   225  	UprightTransform_2                    string          `xmp:"crs:UprightTransform_2"`
   226  	UprightTransform_3                    string          `xmp:"crs:UprightTransform_3"`
   227  	UprightTransform_4                    string          `xmp:"crs:UprightTransform_4"`
   228  	LensProfileMatchKeyExifMake           string          `xmp:"crs:LensProfileMatchKeyExifMake"`
   229  	LensProfileMatchKeyExifModel          string          `xmp:"crs:LensProfileMatchKeyExifModel"`
   230  	LensProfileMatchKeyCameraModelName    string          `xmp:"crs:LensProfileMatchKeyCameraModelName"`
   231  	LensProfileMatchKeyLensInfo           string          `xmp:"crs:LensProfileMatchKeyLensInfo"`
   232  	LensProfileMatchKeyLensID             string          `xmp:"crs:LensProfileMatchKeyLensID"`
   233  	LensProfileMatchKeyLensName           string          `xmp:"crs:LensProfileMatchKeyLensName"`
   234  	LensProfileMatchKeyIsRaw              xmp.Bool        `xmp:"crs:LensProfileMatchKeyIsRaw"`
   235  	LensProfileMatchKeySensorFormatFactor float32         `xmp:"crs:LensProfileMatchKeySensorFormatFactor"`
   236  	DefaultAutoTone                       xmp.Bool        `xmp:"crs:DefaultAutoTone"`
   237  	DefaultAutoGray                       xmp.Bool        `xmp:"crs:DefaultAutoGray"`
   238  	DefaultsSpecificToSerial              xmp.Bool        `xmp:"crs:DefaultsSpecificToSerial"`
   239  	DefaultsSpecificToISO                 xmp.Bool        `xmp:"crs:DefaultsSpecificToISO"`
   240  	DNGIgnoreSidecars                     xmp.Bool        `xmp:"crs:DNGIgnoreSidecars"`
   241  	NegativeCachePath                     string          `xmp:"crs:NegativeCachePath"`
   242  	NegativeCacheMaximumSize              float32         `xmp:"crs:NegativeCacheMaximumSize"`
   243  	NegativeCacheLargePreviewSize         int64           `xmp:"crs:NegativeCacheLargePreviewSize"`
   244  	JPEGHandling                          string          `xmp:"crs:JPEGHandling"`
   245  	TIFFHandling                          string          `xmp:"crs:TIFFHandling"`
   246  	GradientBasedCorrections              CorrectionList  `xmp:"crs:GradientBasedCorrections"`
   247  	CircularGradientBasedCorrections      CorrectionList  `xmp:"crs:CircularGradientBasedCorrections"`
   248  	PaintBasedCorrections                 CorrectionList  `xmp:"crs:PaintBasedCorrections"`
   249  	RetouchAreas                          RetouchAreaList `xmp:"crs:RetouchAreas"`
   250  }
   251  
   252  func (x CameraRawInfo) Can(nsName string) bool {
   253  	return NsCrs.GetName() == nsName
   254  }
   255  
   256  func (x CameraRawInfo) Namespaces() xmp.NamespaceList {
   257  	return xmp.NamespaceList{NsCrs}
   258  }
   259  
   260  func (x *CameraRawInfo) SyncModel(d *xmp.Document) error {
   261  	return nil
   262  }
   263  
   264  func (x *CameraRawInfo) SyncFromXMP(d *xmp.Document) error {
   265  	return nil
   266  }
   267  
   268  func (x CameraRawInfo) SyncToXMP(d *xmp.Document) error {
   269  	return nil
   270  }
   271  
   272  func (x *CameraRawInfo) CanTag(tag string) bool {
   273  	_, err := xmp.GetNativeField(x, tag)
   274  	return err == nil
   275  }
   276  
   277  func (x *CameraRawInfo) GetTag(tag string) (string, error) {
   278  	if v, err := xmp.GetNativeField(x, tag); err != nil {
   279  		return "", fmt.Errorf("%s: %v", NsCrs.GetName(), err)
   280  	} else {
   281  		return v, nil
   282  	}
   283  }
   284  
   285  func (x *CameraRawInfo) SetTag(tag, value string) error {
   286  	if err := xmp.SetNativeField(x, tag, value); err != nil {
   287  		return fmt.Errorf("%s: %v", NsCrs.GetName(), err)
   288  	}
   289  	return nil
   290  }