github.com/boki/go-xmp@v1.0.1/models/crs/types.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 16 17 import ( 18 "bytes" 19 "fmt" 20 "strconv" 21 "trimmer.io/go-xmp/xmp" 22 ) 23 24 // Point "x, y" 25 // 26 type Point struct { 27 X int64 28 Y int64 29 } 30 31 func (x Point) IsZero() bool { 32 return x.X == 0 && x.Y == 0 33 } 34 35 func (x Point) String() string { 36 buf := bytes.Buffer{} 37 buf.WriteString(strconv.FormatInt(x.X, 10)) 38 buf.WriteString(", ") 39 buf.WriteString(strconv.FormatInt(x.Y, 10)) 40 return buf.String() 41 } 42 43 func (x Point) MarshalText() ([]byte, error) { 44 return []byte(x.String()), nil 45 } 46 47 func (x *Point) UnmarshalText(data []byte) error { 48 v := string(data) 49 r := Point{} 50 if _, err := fmt.Sscanf(v, "%d, %d", &r.X, &r.Y); err != nil { 51 return fmt.Errorf("xmp: invalid point '%s': %v", v, err) 52 } 53 *x = r 54 return nil 55 } 56 57 type PointList []Point 58 59 func (x PointList) Typ() xmp.ArrayType { 60 return xmp.ArrayTypeOrdered 61 } 62 63 func (x PointList) MarshalXMP(e *xmp.Encoder, node *xmp.Node, m xmp.Model) error { 64 return xmp.MarshalArray(e, node, x.Typ(), x) 65 } 66 67 func (x *PointList) UnmarshalXMP(d *xmp.Decoder, node *xmp.Node, m xmp.Model) error { 68 return xmp.UnmarshalArray(d, node, x.Typ(), x) 69 } 70 71 type Correction struct { 72 What string `xmp:"crs:What,attr"` 73 CorrectionAmount float32 `xmp:"crs:CorrectionAmount,attr"` 74 CorrectionActive xmp.Bool `xmp:"crs:CorrectionActive,attr"` 75 LocalExposure float32 `xmp:"crs:LocalExposure,attr"` 76 LocalSaturation float32 `xmp:"crs:LocalSaturation,attr"` 77 LocalContrast float32 `xmp:"crs:LocalContrast,attr"` 78 LocalBrightness float32 `xmp:"crs:LocalBrightness,attr"` 79 LocalClarity float32 `xmp:"crs:LocalClarity,attr"` 80 LocalSharpness float32 `xmp:"crs:LocalSharpness,attr"` 81 LocalToningHue float32 `xmp:"crs:LocalToningHue,attr"` 82 LocalToningSaturation float32 `xmp:"crs:LocalToningSaturation,attr"` 83 LocalExposure2012 float32 `xmp:"crs:LocalExposure2012,attr"` 84 LocalContrast2012 float32 `xmp:"crs:LocalContrast2012,attr"` 85 LocalHighlights2012 float32 `xmp:"crs:LocalHighlights2012,attr"` 86 LocalShadows2012 float32 `xmp:"crs:LocalShadows2012,attr"` 87 LocalClarity2012 float32 `xmp:"crs:LocalClarity2012,attr"` 88 LocalLuminanceNoise float32 `xmp:"crs:LocalLuminanceNoise,attr"` 89 LocalMoire float32 `xmp:"crs:LocalMoire,attr"` 90 LocalDefringe float32 `xmp:"crs:LocalDefringe,attr"` 91 LocalTemperature float32 `xmp:"crs:LocalTemperature,attr"` 92 LocalTint float32 `xmp:"crs:LocalTint,attr"` 93 CorrectionMasks CorrectionMaskList `xmp:"crs:CorrectionMasks"` 94 } 95 96 type CorrectionList []Correction 97 98 func (x CorrectionList) Typ() xmp.ArrayType { 99 return xmp.ArrayTypeOrdered 100 } 101 102 func (x CorrectionList) MarshalXMP(e *xmp.Encoder, node *xmp.Node, m xmp.Model) error { 103 return xmp.MarshalArray(e, node, x.Typ(), x) 104 } 105 106 func (x *CorrectionList) UnmarshalXMP(d *xmp.Decoder, node *xmp.Node, m xmp.Model) error { 107 return xmp.UnmarshalArray(d, node, x.Typ(), x) 108 } 109 110 type CorrectionMask struct { 111 What string `xmp:"crs:What,attr"` 112 MaskValue float32 `xmp:"crs:MaskValue,attr"` 113 Radius float32 `xmp:"crs:Radius,attr"` 114 Flow float32 `xmp:"crs:Flow,attr"` 115 CenterWeight float32 `xmp:"crs:CenterWeight,attr"` 116 Dabs xmp.StringList `xmp:"crs:Dabs"` 117 ZeroX float32 `xmp:"crs:ZeroX,attr"` 118 ZeroY float32 `xmp:"crs:ZeroY,attr"` 119 FullX float32 `xmp:"crs:FullX,attr"` 120 FullY float32 `xmp:"crs:FullY,attr"` 121 Top float32 `xmp:"crs:Top,attr"` 122 Left float32 `xmp:"crs:Left,attr"` 123 Bottom float32 `xmp:"crs:Bottom,attr"` 124 Right float32 `xmp:"crs:Right,attr"` 125 Angle float32 `xmp:"crs:Angle,attr"` 126 Midpoint float32 `xmp:"crs:Midpoint,attr"` 127 Roundness float32 `xmp:"crs:Roundness,attr"` 128 Feather float32 `xmp:"crs:Feather,attr"` 129 Flipped xmp.Bool `xmp:"crs:Flipped,attr"` 130 Version int64 `xmp:"crs:Version,attr"` 131 SizeX float32 `xmp:"crs:SizeX,attr"` 132 SizeY float32 `xmp:"crs:SizeY,attr"` 133 X float32 `xmp:"crs:X,attr"` 134 Y float32 `xmp:"crs:Y,attr"` 135 Alpha float32 `xmp:"crs:Alpha,attr"` 136 CenterValue float32 `xmp:"crs:CenterValue,attr"` 137 PerimeterValue float32 `xmp:"crs:PerimeterValue,attr"` 138 } 139 140 type CorrectionMaskList []CorrectionMask 141 142 func (x CorrectionMaskList) Typ() xmp.ArrayType { 143 return xmp.ArrayTypeOrdered 144 } 145 146 func (x CorrectionMaskList) MarshalXMP(e *xmp.Encoder, node *xmp.Node, m xmp.Model) error { 147 return xmp.MarshalArray(e, node, x.Typ(), x) 148 } 149 150 func (x *CorrectionMaskList) UnmarshalXMP(d *xmp.Decoder, node *xmp.Node, m xmp.Model) error { 151 return xmp.UnmarshalArray(d, node, x.Typ(), x) 152 } 153 154 type RetouchArea struct { 155 SpotType string `xmp:"crs:SpotType,attr"` // heal 156 SourceState string `xmp:"crs:SourceState,attr"` // sourceSetExplicitly 157 Method string `xmp:"crs:Method,attr"` // gaussian 158 SourceX float32 `xmp:"crs:SourceX,attr"` 159 OffsetY float32 `xmp:"crs:OffsetY,attr"` 160 Opacity float32 `xmp:"crs:Opacity,attr"` 161 Feather float32 `xmp:"crs:Feather,attr"` 162 Seed int64 `xmp:"crs:Seed,attr"` 163 Masks CorrectionMaskList `xmp:"crs:Masks"` 164 } 165 166 type RetouchAreaList []RetouchArea 167 168 func (x RetouchAreaList) Typ() xmp.ArrayType { 169 return xmp.ArrayTypeOrdered 170 } 171 172 func (x RetouchAreaList) MarshalXMP(e *xmp.Encoder, node *xmp.Node, m xmp.Model) error { 173 return xmp.MarshalArray(e, node, x.Typ(), x) 174 } 175 176 func (x *RetouchAreaList) UnmarshalXMP(d *xmp.Decoder, node *xmp.Node, m xmp.Model) error { 177 return xmp.UnmarshalArray(d, node, x.Typ(), x) 178 } 179 180 // TODO: (Un)MarshalText 181 // <rdf:li>centerX = 0.290216, centerY = 0.190122, radius = 0.005845, sourceState = sourceSetExplicitly, sourceX = 0.260958, sourceY = 0.189526, spotType = heal</rdf:li> 182 type RetouchInfo struct { 183 SpotType string 184 SourceState string 185 CenterX float32 186 CenterY float32 187 Radius float32 188 SourceX float32 189 SourceY float32 190 }