From e405b1b548b39bd8d3d4b8e5816f00b9a9544321 Mon Sep 17 00:00:00 2001 From: sigismondm Date: Tue, 11 Aug 2015 11:16:06 -0500 Subject: [PATCH 01/13] init commit --- .idea/.name | 1 + .idea/compiler.xml | 22 ++ .idea/copyright/profiles_settings.xml | 3 + .idea/libraries/GOPATH__ase_.xml | 18 ++ .idea/misc.xml | 104 ++++++++++ .idea/modules.xml | 8 + .idea/vcs.xml | 6 + .idea/workspace.xml | 287 ++++++++++++++++++++++++++ ase.go | 158 ++++++++++++-- ase.iml | 10 + 10 files changed, 603 insertions(+), 14 deletions(-) create mode 100644 .idea/.name create mode 100644 .idea/compiler.xml create mode 100644 .idea/copyright/profiles_settings.xml create mode 100644 .idea/libraries/GOPATH__ase_.xml create mode 100644 .idea/misc.xml create mode 100644 .idea/modules.xml create mode 100644 .idea/vcs.xml create mode 100644 .idea/workspace.xml create mode 100644 ase.iml diff --git a/.idea/.name b/.idea/.name new file mode 100644 index 0000000..a7f0591 --- /dev/null +++ b/.idea/.name @@ -0,0 +1 @@ +ase \ No newline at end of file diff --git a/.idea/compiler.xml b/.idea/compiler.xml new file mode 100644 index 0000000..96cc43e --- /dev/null +++ b/.idea/compiler.xml @@ -0,0 +1,22 @@ + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/.idea/copyright/profiles_settings.xml b/.idea/copyright/profiles_settings.xml new file mode 100644 index 0000000..e7bedf3 --- /dev/null +++ b/.idea/copyright/profiles_settings.xml @@ -0,0 +1,3 @@ + + + \ No newline at end of file diff --git a/.idea/libraries/GOPATH__ase_.xml b/.idea/libraries/GOPATH__ase_.xml new file mode 100644 index 0000000..631af52 --- /dev/null +++ b/.idea/libraries/GOPATH__ase_.xml @@ -0,0 +1,18 @@ + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/.idea/misc.xml b/.idea/misc.xml new file mode 100644 index 0000000..b024d05 --- /dev/null +++ b/.idea/misc.xml @@ -0,0 +1,104 @@ + + + + + + + + + + + + + + Android Lint + + + General + + + Maven + + + Plugin DevKit + + + XPath + + + + + Android + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + Go 1.4.2 + + + + + + + + Go 1.4.2 + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/.idea/modules.xml b/.idea/modules.xml new file mode 100644 index 0000000..91cbcfa --- /dev/null +++ b/.idea/modules.xml @@ -0,0 +1,8 @@ + + + + + + + + \ No newline at end of file diff --git a/.idea/vcs.xml b/.idea/vcs.xml new file mode 100644 index 0000000..35eb1dd --- /dev/null +++ b/.idea/vcs.xml @@ -0,0 +1,6 @@ + + + + + + \ No newline at end of file diff --git a/.idea/workspace.xml b/.idea/workspace.xml new file mode 100644 index 0000000..2a938ab --- /dev/null +++ b/.idea/workspace.xml @@ -0,0 +1,287 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + 1438994921671 + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/ase.go b/ase.go index 7fb78ee..6155a4a 100755 --- a/ase.go +++ b/ase.go @@ -5,6 +5,8 @@ import ( "errors" "io" "os" + "log" + "unicode/utf16" ) var ( @@ -42,6 +44,8 @@ func Decode(r io.Reader) (ase ASE, err error) { // decode the block container b.Read(r) + ase.Blocks = append(ase.Blocks, b) + // switch on block type switch b.Type { case color: @@ -95,26 +99,13 @@ func DecodeFile(file string) (ase ASE, err error) { return Decode(f) } -// TODO: complete encode method -func Encode(ase ASE, w io.Writer) (err error) { - - // write signature - - // write version - - // write number of blocks - - // write details of each block - - return -} - type ASE struct { signature [4]uint8 version [2]int16 numBlocks int32 Colors []Color Groups []Group + Blocks []block } // ASE Files start are signed with ASEF at the beginning of the file @@ -133,6 +124,79 @@ func (ase *ASE) readSignature(r io.Reader) (err error) { return } +func Encode(ase ASE, w io.Writer) (err error) { + + if err = ase.writeSignature(w); err != nil { + return + } + + if err = ase.writeVersion(w); err != nil { + return + } + + if err = ase.writeNumBlock(w); err != nil { + return + } + + + + // itereate based on our block count + for i := 0; i < int(ase.numBlocks); i++ { + b := ase.Blocks[i] + if err = ase.writeBlockType(w, ase.Blocks[i]); err != nil { + return + } + + if err = ase.writeBlockLength (w, ase.Blocks[i]); err != nil { + return + } + + + + + switch b.Type { + case color: + if err = ase.writeColorName(w, ase.Colors[i]); err != nil { + return + } + + if err = ase.writeColorModel(w, ase.Colors[i]); err != nil { + return + } + + if err = ase.writeColorValues(w, ase.Colors[i]); err != nil { + return + } + + if err = ase.writeColorType(w, ase.Colors[i]); err != nil { + return + } + + + break + case groupStart: + + + break + case groupEnd: + + break + default: + err = ErrInvalidBlockType + return + } + + } + + + + var numOfColors = len(ase.Colors) + var numOfGroups = len(ase.Groups) + log.Print("Number of colors ", numOfColors) + log.Print("Number of groups ", numOfGroups) + return +} + // ASE version. Should be 1.0 func (ase *ASE) readVersion(r io.Reader) error { return binary.Read(r, binary.BigEndian, &ase.version) @@ -147,3 +211,69 @@ func (ase *ASE) readNumBlock(r io.Reader) error { func (ase *ASE) Signature() string { return string(ase.signature[0:]) } + +func (ase *ASE) writeSignature(w io.Writer) error { + return binary.Write(w, binary.BigEndian, ase.signature) +} + +func (ase *ASE) writeVersion(w io.Writer) error { + return binary.Write(w, binary.BigEndian, ase.version) +} + +func (ase *ASE) writeNumBlock(w io.Writer) error { + return binary.Write(w, binary.BigEndian, ase.numBlocks) +} + +func (ase *ASE) writeBlockType(w io.Writer, b block) error { + return binary.Write(w, binary.BigEndian, b.Type) +} + +func (ase *ASE) writeBlockLength(w io.Writer, b block) error { + return binary.Write(w, binary.BigEndian, b.Length) +} + +func (ase *ASE) writeColorName(w io.Writer, c Color) error { + colorNameSlice := []rune(c.Name) + colorNameSlice = append(colorNameSlice, 0) + colorName := utf16.Encode(colorNameSlice) + return binary.Write(w, binary.BigEndian, colorName) +} + +func (ase *ASE) writeColorModel(w io.Writer, c Color) error { + colorModelSlice := []rune(c.Model) + colorModel := utf16.Encode(colorModelSlice) + return binary.Write(w,binary.BigEndian, colorModel) +} + +func (ase *ASE) writeColorValues(w io.Writer, c Color) error { + var err error + for _, cv := range c.Values { + err = binary.Write(w,binary.BigEndian, cv) + + if(err != nil){ + return err + } + } + return err +} + +func (ase *ASE) writeColorType(w io.Writer, c Color) error { + var cType int16 + switch { + case c.Type == "Global": + cType = 0 + break + case c.Type == "Spot": + cType = 1 + break + case c.Type == "Normal": + cType = 2 + break + default: + return ErrInvalidColorType + + } + return binary.Write(w, binary.BigEndian, cType) +} + + diff --git a/ase.iml b/ase.iml new file mode 100644 index 0000000..2324e1e --- /dev/null +++ b/ase.iml @@ -0,0 +1,10 @@ + + + + + + + + + + \ No newline at end of file From 95c228c7c5dcb2d34a11ccffebfa8ee548c98444 Mon Sep 17 00:00:00 2001 From: sigismondm Date: Tue, 11 Aug 2015 12:52:56 -0500 Subject: [PATCH 02/13] Fix writing color model , write name length --- ase.go | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/ase.go b/ase.go index 6155a4a..f381b8f 100755 --- a/ase.go +++ b/ase.go @@ -156,6 +156,10 @@ func Encode(ase ASE, w io.Writer) (err error) { switch b.Type { case color: + if err = ase.writeNameLength(w, ase.Colors[i]); err != nil { + return + } + if err = ase.writeColorName(w, ase.Colors[i]); err != nil { return } @@ -240,9 +244,7 @@ func (ase *ASE) writeColorName(w io.Writer, c Color) error { } func (ase *ASE) writeColorModel(w io.Writer, c Color) error { - colorModelSlice := []rune(c.Model) - colorModel := utf16.Encode(colorModelSlice) - return binary.Write(w,binary.BigEndian, colorModel) + return binary.Write(w,binary.BigEndian, []byte(c.Model)) } func (ase *ASE) writeColorValues(w io.Writer, c Color) error { @@ -276,4 +278,7 @@ func (ase *ASE) writeColorType(w io.Writer, c Color) error { return binary.Write(w, binary.BigEndian, cType) } +func (ase *ASE) writeNameLength(w io.Writer, c Color) error { + return binary.Write(w, binary.BigEndian, c.nameLen) +} From 9c8af26078bdeeef50fe0733356165ad218f2260 Mon Sep 17 00:00:00 2001 From: sigismondm Date: Wed, 12 Aug 2015 05:46:42 -0500 Subject: [PATCH 03/13] Rename writeColorNameLength method add methods for writing groups --- ase.go | 23 +++++++++++++++++++++-- 1 file changed, 21 insertions(+), 2 deletions(-) diff --git a/ase.go b/ase.go index f381b8f..39c0c10 100755 --- a/ase.go +++ b/ase.go @@ -156,7 +156,7 @@ func Encode(ase ASE, w io.Writer) (err error) { switch b.Type { case color: - if err = ase.writeNameLength(w, ase.Colors[i]); err != nil { + if err = ase.writeColorNameLength(w, ase.Colors[i]); err != nil { return } @@ -181,9 +181,18 @@ func Encode(ase ASE, w io.Writer) (err error) { case groupStart: + if err = ase.writeGroupNameLength(w, ase.Groups[i]); err != nil { + return + } + + + + + break case groupEnd: + //Write group end break default: err = ErrInvalidBlockType @@ -278,7 +287,17 @@ func (ase *ASE) writeColorType(w io.Writer, c Color) error { return binary.Write(w, binary.BigEndian, cType) } -func (ase *ASE) writeNameLength(w io.Writer, c Color) error { +func (ase *ASE) writeColorNameLength(w io.Writer, c Color) error { return binary.Write(w, binary.BigEndian, c.nameLen) } +func (ase *ASE) writeGroupNameLength(w io.Writer, g Group) error { + return binary.Write(w, binary.BigEndian, g.nameLen) +} + +func (ase *ASE) writeGroupName(w io.Writer, g Group) error { + groupNameSlice := []rune(g.Name) + groupNameSlice = append(groupNameSlice, 0) + groupName := utf16.Encode(groupNameSlice) + return binary.Write(w, binary.BigEndian, groupName) +} From 3f19d654226d5615f9fc555fadd14ff7c0124773 Mon Sep 17 00:00:00 2001 From: sigismondm Date: Wed, 12 Aug 2015 06:38:33 -0500 Subject: [PATCH 04/13] Move methods out of main file --- ase.go | 89 ++------------------------------------------------------ block.go | 20 +++++++++++++ color.go | 66 +++++++++++++++++++++++++++++++++++++++++ 3 files changed, 89 insertions(+), 86 deletions(-) diff --git a/ase.go b/ase.go index 39c0c10..1d2e59c 100755 --- a/ase.go +++ b/ase.go @@ -143,52 +143,23 @@ func Encode(ase ASE, w io.Writer) (err error) { // itereate based on our block count for i := 0; i < int(ase.numBlocks); i++ { b := ase.Blocks[i] - if err = ase.writeBlockType(w, ase.Blocks[i]); err != nil { - return - } - if err = ase.writeBlockLength (w, ase.Blocks[i]); err != nil { + if err = b.Write(w); err != nil { return } - + c := ase.Colors[i] switch b.Type { case color: - if err = ase.writeColorNameLength(w, ase.Colors[i]); err != nil { - return - } - - if err = ase.writeColorName(w, ase.Colors[i]); err != nil { - return - } - - if err = ase.writeColorModel(w, ase.Colors[i]); err != nil { - return - } - - if err = ase.writeColorValues(w, ase.Colors[i]); err != nil { - return - } - - if err = ase.writeColorType(w, ase.Colors[i]); err != nil { - return - } - - + c.write(w) break case groupStart: - - if err = ase.writeGroupNameLength(w, ase.Groups[i]); err != nil { return } - - - - break case groupEnd: @@ -237,60 +208,6 @@ func (ase *ASE) writeNumBlock(w io.Writer) error { return binary.Write(w, binary.BigEndian, ase.numBlocks) } -func (ase *ASE) writeBlockType(w io.Writer, b block) error { - return binary.Write(w, binary.BigEndian, b.Type) -} - -func (ase *ASE) writeBlockLength(w io.Writer, b block) error { - return binary.Write(w, binary.BigEndian, b.Length) -} - -func (ase *ASE) writeColorName(w io.Writer, c Color) error { - colorNameSlice := []rune(c.Name) - colorNameSlice = append(colorNameSlice, 0) - colorName := utf16.Encode(colorNameSlice) - return binary.Write(w, binary.BigEndian, colorName) -} - -func (ase *ASE) writeColorModel(w io.Writer, c Color) error { - return binary.Write(w,binary.BigEndian, []byte(c.Model)) -} - -func (ase *ASE) writeColorValues(w io.Writer, c Color) error { - var err error - for _, cv := range c.Values { - err = binary.Write(w,binary.BigEndian, cv) - - if(err != nil){ - return err - } - } - return err -} - -func (ase *ASE) writeColorType(w io.Writer, c Color) error { - var cType int16 - switch { - case c.Type == "Global": - cType = 0 - break - case c.Type == "Spot": - cType = 1 - break - case c.Type == "Normal": - cType = 2 - break - default: - return ErrInvalidColorType - - } - return binary.Write(w, binary.BigEndian, cType) -} - -func (ase *ASE) writeColorNameLength(w io.Writer, c Color) error { - return binary.Write(w, binary.BigEndian, c.nameLen) -} - func (ase *ASE) writeGroupNameLength(w io.Writer, g Group) error { return binary.Write(w, binary.BigEndian, g.nameLen) } diff --git a/block.go b/block.go index 55bb2eb..b5e9016 100755 --- a/block.go +++ b/block.go @@ -46,3 +46,23 @@ func (block *block) readType(r io.Reader) error { func (block *block) readLength(r io.Reader) error { return binary.Read(r, binary.BigEndian, &block.Length) } + +func (b *block) Write(w io.Writer) (err error) { + if err = b.writeType(w); err != nil { + return + } + + if err= b.writeLength(w); err != nil { + return + } + + return +} + +func (block *block) writeType(w io.Writer) error { + return binary.Write(w, binary.BigEndian, block.Type) +} + +func (block *block) writeLength(w io.Writer) error { + return binary.Write(w, binary.BigEndian, block.Length) +} \ No newline at end of file diff --git a/color.go b/color.go index 1615a60..afc1a31 100755 --- a/color.go +++ b/color.go @@ -140,3 +140,69 @@ func (color *Color) readColorType(r io.Reader) (err error) { return } + +func (color *Color) write(w io.Writer) (err error) { + if err = color.writeColorNameLength(w); err != nil { + return + } + + if err = color.writeColorName(w); err != nil { + return + } + + if err = color.writeColorModel(w); err != nil { + return + } + + if err = color.writeColorValues(w); err != nil { + return + } + + return color.writeColorType(w) +} + +func (color *Color) writeColorName(w io.Writer) error { + colorNameSlice := []rune(color.Name) + colorNameSlice = append(colorNameSlice, 0) + colorName := utf16.Encode(colorNameSlice) + return binary.Write(w, binary.BigEndian, colorName) +} + +func (color *Color) writeColorModel(w io.Writer) error { + return binary.Write(w,binary.BigEndian, []byte(color.Model)) +} + +func (color *Color) writeColorValues(w io.Writer) error { + var err error + for _, cv := range color.Values { + err = binary.Write(w,binary.BigEndian, cv) + + if(err != nil){ + return err + } + } + return err +} + +func (color *Color) writeColorType(w io.Writer) error { + var cType int16 + switch { + case color.Type == "Global": + cType = 0 + break + case color.Type == "Spot": + cType = 1 + break + case color.Type == "Normal": + cType = 2 + break + default: + return ErrInvalidColorType + + } + return binary.Write(w, binary.BigEndian, cType) +} + +func (color *Color) writeColorNameLength(w io.Writer) error { + return binary.Write(w, binary.BigEndian, color.nameLen) +} \ No newline at end of file From 7954aad96ceea88c4e11d929012ee1f5d15d5cd8 Mon Sep 17 00:00:00 2001 From: sigismondm Date: Wed, 12 Aug 2015 19:16:25 -0500 Subject: [PATCH 05/13] Implement encoding for groups --- ase.go | 52 ++++++++++++++++++++++++++-------------------------- group.go | 23 +++++++++++++++++++++++ 2 files changed, 49 insertions(+), 26 deletions(-) diff --git a/ase.go b/ase.go index 1d2e59c..88b1246 100755 --- a/ase.go +++ b/ase.go @@ -5,8 +5,6 @@ import ( "errors" "io" "os" - "log" - "unicode/utf16" ) var ( @@ -138,32 +136,51 @@ func Encode(ase ASE, w io.Writer) (err error) { return } + var g Group + + //Group color index + j := 0 + //Group index + k := 0 // itereate based on our block count for i := 0; i < int(ase.numBlocks); i++ { + b := ase.Blocks[i] if err = b.Write(w); err != nil { return } - c := ase.Colors[i] - - switch b.Type { case color: - c.write(w) + c := Color{} + + if g.Name == "" { + c = ase.Colors[i] + } else { + c = g.Colors[j] + j++ + } + + + if err = c.write(w); err != nil { + return + } + break case groupStart: - if err = ase.writeGroupNameLength(w, ase.Groups[i]); err != nil { + g = ase.Groups[k] + if err = g.write(w); err != nil { return } + k++ break case groupEnd: - - //Write group end + g = Group{} + j = 0 break default: err = ErrInvalidBlockType @@ -172,12 +189,6 @@ func Encode(ase ASE, w io.Writer) (err error) { } - - - var numOfColors = len(ase.Colors) - var numOfGroups = len(ase.Groups) - log.Print("Number of colors ", numOfColors) - log.Print("Number of groups ", numOfGroups) return } @@ -207,14 +218,3 @@ func (ase *ASE) writeVersion(w io.Writer) error { func (ase *ASE) writeNumBlock(w io.Writer) error { return binary.Write(w, binary.BigEndian, ase.numBlocks) } - -func (ase *ASE) writeGroupNameLength(w io.Writer, g Group) error { - return binary.Write(w, binary.BigEndian, g.nameLen) -} - -func (ase *ASE) writeGroupName(w io.Writer, g Group) error { - groupNameSlice := []rune(g.Name) - groupNameSlice = append(groupNameSlice, 0) - groupName := utf16.Encode(groupNameSlice) - return binary.Write(w, binary.BigEndian, groupName) -} diff --git a/group.go b/group.go index 295a796..04a0921 100755 --- a/group.go +++ b/group.go @@ -36,3 +36,26 @@ func (group *Group) readName(r io.Reader) (err error) { return } + +func (group *Group) write(w io.Writer) (err error){ + if err = group.writeName(w); err != nil { + return + } + + if err = group.writeNameLen(w); err != nil { + return + } + + return +} + +func (group *Group) writeNameLen(w io.Writer) error { + return binary.Write(w, binary.BigEndian, group.nameLen) +} + +func (group *Group) writeName(w io.Writer) error { + groupNameSlice := []rune(group.Name) + groupNameSlice = append(groupNameSlice, 0) + groupName := utf16.Encode(groupNameSlice) + return binary.Write(w, binary.BigEndian, groupName) +} From abfa350db900444b4132ec6be99b4721724ef10c Mon Sep 17 00:00:00 2001 From: sigismondm Date: Wed, 12 Aug 2015 19:21:56 -0500 Subject: [PATCH 06/13] add gitignore --- .gitignore | 46 ++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 46 insertions(+) create mode 100644 .gitignore diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..573bcf4 --- /dev/null +++ b/.gitignore @@ -0,0 +1,46 @@ +# Covers JetBrains IDEs: IntelliJ, RubyMine, PhpStorm, AppCode, PyCharm, CLion, Android Studio + +*.iml + +## Directory-based project format: +.idea/ +# if you remove the above rule, at least ignore the following: + +# User-specific stuff: +# .idea/workspace.xml +# .idea/tasks.xml +# .idea/dictionaries + +# Sensitive or high-churn files: +# .idea/dataSources.ids +# .idea/dataSources.xml +# .idea/sqlDataSources.xml +# .idea/dynamic.xml +# .idea/uiDesigner.xml + +# Gradle: +# .idea/gradle.xml +# .idea/libraries + +# Mongo Explorer plugin: +# .idea/mongoSettings.xml + +## File-based project format: +*.ipr +*.iws + +## Plugin-specific files: + +# IntelliJ +/out/ + +# mpeltonen/sbt-idea plugin +.idea_modules/ + +# JIRA plugin +atlassian-ide-plugin.xml + +# Crashlytics plugin (for Android Studio and IntelliJ) +com_crashlytics_export_strings.xml +crashlytics.properties +crashlytics-build.properties From f56d2599118b2859c49e3668aa38b683c81d30fe Mon Sep 17 00:00:00 2001 From: sigismondm Date: Wed, 12 Aug 2015 19:26:00 -0500 Subject: [PATCH 07/13] Remove intellij files --- .idea/.name | 1 - .idea/compiler.xml | 22 -- .idea/copyright/profiles_settings.xml | 3 - .idea/libraries/GOPATH__ase_.xml | 18 -- .idea/misc.xml | 104 ---------- .idea/modules.xml | 8 - .idea/vcs.xml | 6 - .idea/workspace.xml | 287 -------------------------- ase.iml | 10 - 9 files changed, 459 deletions(-) delete mode 100644 .idea/.name delete mode 100644 .idea/compiler.xml delete mode 100644 .idea/copyright/profiles_settings.xml delete mode 100644 .idea/libraries/GOPATH__ase_.xml delete mode 100644 .idea/misc.xml delete mode 100644 .idea/modules.xml delete mode 100644 .idea/vcs.xml delete mode 100644 .idea/workspace.xml delete mode 100644 ase.iml diff --git a/.idea/.name b/.idea/.name deleted file mode 100644 index a7f0591..0000000 --- a/.idea/.name +++ /dev/null @@ -1 +0,0 @@ -ase \ No newline at end of file diff --git a/.idea/compiler.xml b/.idea/compiler.xml deleted file mode 100644 index 96cc43e..0000000 --- a/.idea/compiler.xml +++ /dev/null @@ -1,22 +0,0 @@ - - - - - - - - - - - - - - - - - - - - - - \ No newline at end of file diff --git a/.idea/copyright/profiles_settings.xml b/.idea/copyright/profiles_settings.xml deleted file mode 100644 index e7bedf3..0000000 --- a/.idea/copyright/profiles_settings.xml +++ /dev/null @@ -1,3 +0,0 @@ - - - \ No newline at end of file diff --git a/.idea/libraries/GOPATH__ase_.xml b/.idea/libraries/GOPATH__ase_.xml deleted file mode 100644 index 631af52..0000000 --- a/.idea/libraries/GOPATH__ase_.xml +++ /dev/null @@ -1,18 +0,0 @@ - - - - - - - - - - - - - - - - - - \ No newline at end of file diff --git a/.idea/misc.xml b/.idea/misc.xml deleted file mode 100644 index b024d05..0000000 --- a/.idea/misc.xml +++ /dev/null @@ -1,104 +0,0 @@ - - - - - - - - - - - - - - Android Lint - - - General - - - Maven - - - Plugin DevKit - - - XPath - - - - - Android - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - Go 1.4.2 - - - - - - - - Go 1.4.2 - - - - - - - - - - - - - - - \ No newline at end of file diff --git a/.idea/modules.xml b/.idea/modules.xml deleted file mode 100644 index 91cbcfa..0000000 --- a/.idea/modules.xml +++ /dev/null @@ -1,8 +0,0 @@ - - - - - - - - \ No newline at end of file diff --git a/.idea/vcs.xml b/.idea/vcs.xml deleted file mode 100644 index 35eb1dd..0000000 --- a/.idea/vcs.xml +++ /dev/null @@ -1,6 +0,0 @@ - - - - - - \ No newline at end of file diff --git a/.idea/workspace.xml b/.idea/workspace.xml deleted file mode 100644 index 2a938ab..0000000 --- a/.idea/workspace.xml +++ /dev/null @@ -1,287 +0,0 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - 1438994921671 - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - \ No newline at end of file diff --git a/ase.iml b/ase.iml deleted file mode 100644 index 2324e1e..0000000 --- a/ase.iml +++ /dev/null @@ -1,10 +0,0 @@ - - - - - - - - - - \ No newline at end of file From 93287b47fbd75cae62b57a4de3406d57852e8eb5 Mon Sep 17 00:00:00 2001 From: sigismondm Date: Thu, 13 Aug 2015 10:15:12 -0500 Subject: [PATCH 08/13] Fix issues --- .DS_Store | Bin 0 -> 6148 bytes color.go | 16 ++++++++++++++-- group.go | 5 +++-- 3 files changed, 17 insertions(+), 4 deletions(-) create mode 100644 .DS_Store diff --git a/.DS_Store b/.DS_Store new file mode 100644 index 0000000000000000000000000000000000000000..762eb38a6851431167486022edf76059fcb40217 GIT binary patch literal 6148 zcmeHKF>V4u473vpA{t7{{X%}QLgWSc07?J}35kNxU&Xufw9MEpf-dQxL1W3DU9V?P zH^upEX1+XcUd`raHiZ-I!Z0?T(?|AH83)2~$IkY4u&teTn^E=O336ZTiyXvX{L|;h z@p#~|ObSQ=DIf);fE2i)0@Ylnvm4&2tE7Mwcnk&jeQ0oEFB}r%(}55p0C0kI7}haM z02>p)UN|Ho1M{Q;lj=2Mc+!z?Ro4rL#H5?o@Zt4juL;HD>A1f|xp_}ilmb%VT7l=> z&e{Lp;Q!43*Cg$vfE0Kr1$?r4UoG)U)muj|$6njuYdCAZ;WVs+f)MQ(80{Dvw&O(< bWnJSM=e=-93_9{b2kK{ly2zx!y%qQYGu;)G literal 0 HcmV?d00001 diff --git a/color.go b/color.go index afc1a31..8c0699e 100755 --- a/color.go +++ b/color.go @@ -158,7 +158,11 @@ func (color *Color) write(w io.Writer) (err error) { return } - return color.writeColorType(w) + if err = color.writeColorType(w); err != nil { + return + } + + return } func (color *Color) writeColorName(w io.Writer) error { @@ -169,12 +173,20 @@ func (color *Color) writeColorName(w io.Writer) error { } func (color *Color) writeColorModel(w io.Writer) error { - return binary.Write(w,binary.BigEndian, []byte(color.Model)) + colorSlice := []byte(color.Model) + + //If color model is either RGB or LAB append space (0x20) + if color.Model == "RGB" || color.Model == "LAB" { + colorSlice = append(colorSlice, 0x20) + } + + return binary.Write(w,binary.BigEndian, colorSlice) } func (color *Color) writeColorValues(w io.Writer) error { var err error for _, cv := range color.Values { + err = binary.Write(w,binary.BigEndian, cv) if(err != nil){ diff --git a/group.go b/group.go index 04a0921..80ded38 100755 --- a/group.go +++ b/group.go @@ -13,6 +13,7 @@ type Group struct { } func (group *Group) read(r io.Reader) (err error) { + if err = group.readNameLen(r); err != nil { return } @@ -38,11 +39,11 @@ func (group *Group) readName(r io.Reader) (err error) { } func (group *Group) write(w io.Writer) (err error){ - if err = group.writeName(w); err != nil { + if err = group.writeNameLen(w); err != nil { return } - if err = group.writeNameLen(w); err != nil { + if err = group.writeName(w); err != nil { return } From 3ed6d4177721defe99426b59ed68e5ccb5ef75cf Mon Sep 17 00:00:00 2001 From: sigismondm Date: Thu, 13 Aug 2015 11:08:03 -0500 Subject: [PATCH 09/13] Add encode test --- ase_test.go | 54 +++++++++++++++++++++-- {testfiles => samples}/out.ase | 0 {testfiles => samples}/test-2.ase | Bin testfiles/test.ase => samples/test-4.ase | Bin samples/test.ase | Bin 0 -> 378 bytes 5 files changed, 51 insertions(+), 3 deletions(-) rename {testfiles => samples}/out.ase (100%) rename {testfiles => samples}/test-2.ase (100%) rename testfiles/test.ase => samples/test-4.ase (100%) create mode 100644 samples/test.ase diff --git a/ase_test.go b/ase_test.go index 364bbe3..2a71c58 100644 --- a/ase_test.go +++ b/ase_test.go @@ -4,10 +4,11 @@ import ( "log" "os" "testing" + "reflect" ) func TestDecode(t *testing.T) { - testFile := "testfiles/test.ase" + testFile := "samples/test.ase" // open our test file f, err := os.Open(testFile) @@ -26,7 +27,7 @@ func TestDecode(t *testing.T) { } func TestDecodeFile(t *testing.T) { - testFile := "testfiles/test.ase" + testFile := "samples/test.ase" ase, err := DecodeFile(testFile) if err != nil { @@ -38,7 +39,7 @@ func TestDecodeFile(t *testing.T) { } func TestSignature(t *testing.T) { - testFile := "testfiles/test.ase" + testFile := "samples/test.ase" ase, err := DecodeFile(testFile) if err != nil { @@ -49,3 +50,50 @@ func TestSignature(t *testing.T) { t.Error("file signature is invalid") } } + + +func TestEncode(t *testing.T) { + // open the file + f, err := os.Open("samples/test.ase") + if err != nil { + t.Error(err) + } + + output, err := Decode(f) + if err != nil { + t.Error(err) + } + + f.Close() + + fo, err := os.Create("samples/test-4.ase") + + err = Encode(output, fo) + + if err != nil { + t.Error(err) + } + + fo.Close() + + + //Decode previously created *.ase file + fTest4, err := os.Open("samples/test-4.ase") + + if err != nil { + t.Error(err) + } + + outputTest4, err := Decode(fTest4) + if err != nil { + t.Error(err) + } + + //Ensure they are equal + if isEqual := reflect.DeepEqual(output, outputTest4); isEqual == false { + t.Error("Did not produce identical structs") + } + + fTest4.Close() + +} diff --git a/testfiles/out.ase b/samples/out.ase similarity index 100% rename from testfiles/out.ase rename to samples/out.ase diff --git a/testfiles/test-2.ase b/samples/test-2.ase similarity index 100% rename from testfiles/test-2.ase rename to samples/test-2.ase diff --git a/testfiles/test.ase b/samples/test-4.ase similarity index 100% rename from testfiles/test.ase rename to samples/test-4.ase diff --git a/samples/test.ase b/samples/test.ase new file mode 100644 index 0000000000000000000000000000000000000000..dc5cc5c5ee08b629c883ea22db128490d778a0dd GIT binary patch literal 378 zcmYk2y-EW?6oo&7rmzruB@EVD2o_@DvK!(SMkCS2Qj#sipA|!jba@oPrw}amEqn&8 zd;uZn%(})4Gk0e0cYn^Lm%S5Ku&qbG%_>83G8pDrNaoNiT9Mclne)sIGbW7W?&AE42^Jeks}wHJ(++V$F)i9kDM e6;k|IQx5;rVyYv(nYv8 Date: Sat, 15 Aug 2015 06:42:45 -0500 Subject: [PATCH 10/13] Simplify switch statement --- color.go | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/color.go b/color.go index 8c0699e..38b9e42 100755 --- a/color.go +++ b/color.go @@ -198,14 +198,14 @@ func (color *Color) writeColorValues(w io.Writer) error { func (color *Color) writeColorType(w io.Writer) error { var cType int16 - switch { - case color.Type == "Global": + switch color.Type { + case "Global": cType = 0 break - case color.Type == "Spot": + case "Spot": cType = 1 break - case color.Type == "Normal": + case "Normal": cType = 2 break default: From 4f05bddbd57e74f8ca7247e3bc9193b514371558 Mon Sep 17 00:00:00 2001 From: sigismondm Date: Sat, 15 Aug 2015 06:43:34 -0500 Subject: [PATCH 11/13] Use a separate increment a separate index when write colors --- ase.go | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/ase.go b/ase.go index 88b1246..6440e3e 100755 --- a/ase.go +++ b/ase.go @@ -144,6 +144,10 @@ func Encode(ase ASE, w io.Writer) (err error) { //Group index k := 0 + //Color index + l := 0 + + // itereate based on our block count for i := 0; i < int(ase.numBlocks); i++ { @@ -158,7 +162,8 @@ func Encode(ase ASE, w io.Writer) (err error) { c := Color{} if g.Name == "" { - c = ase.Colors[i] + c = ase.Colors[l] + l++ } else { c = g.Colors[j] j++ From 2174aad5c4e409d03201bc033e8270dedc0aa1a2 Mon Sep 17 00:00:00 2001 From: sigismondm Date: Sat, 15 Aug 2015 06:45:11 -0500 Subject: [PATCH 12/13] remove .DS_Store --- .DS_Store | Bin 6148 -> 0 bytes 1 file changed, 0 insertions(+), 0 deletions(-) delete mode 100644 .DS_Store diff --git a/.DS_Store b/.DS_Store deleted file mode 100644 index 762eb38a6851431167486022edf76059fcb40217..0000000000000000000000000000000000000000 GIT binary patch literal 0 HcmV?d00001 literal 6148 zcmeHKF>V4u473vpA{t7{{X%}QLgWSc07?J}35kNxU&Xufw9MEpf-dQxL1W3DU9V?P zH^upEX1+XcUd`raHiZ-I!Z0?T(?|AH83)2~$IkY4u&teTn^E=O336ZTiyXvX{L|;h z@p#~|ObSQ=DIf);fE2i)0@Ylnvm4&2tE7Mwcnk&jeQ0oEFB}r%(}55p0C0kI7}haM z02>p)UN|Ho1M{Q;lj=2Mc+!z?Ro4rL#H5?o@Zt4juL;HD>A1f|xp_}ilmb%VT7l=> z&e{Lp;Q!43*Cg$vfE0Kr1$?r4UoG)U)muj|$6njuYdCAZ;WVs+f)MQ(80{Dvw&O(< bWnJSM=e=-93_9{b2kK{ly2zx!y%qQYGu;)G From 96f57e97a7b2815b40f17c351511c01a44ac8a0a Mon Sep 17 00:00:00 2001 From: sigismondm Date: Sat, 15 Aug 2015 06:46:09 -0500 Subject: [PATCH 13/13] Add .DS_store to .gitignore --- .gitignore | 1 + 1 file changed, 1 insertion(+) diff --git a/.gitignore b/.gitignore index 573bcf4..975d61a 100644 --- a/.gitignore +++ b/.gitignore @@ -44,3 +44,4 @@ atlassian-ide-plugin.xml com_crashlytics_export_strings.xml crashlytics.properties crashlytics-build.properties +.DS_Store