Решение на Картинки от Димитър Станев

Обратно към всички решения

Към профила на Димитър Станев

Резултати

  • 0 точки от тестове
  • 0 бонус точки
  • 0 точки общо
  • 0 успешни тест(а)
  • 10 неуспешни тест(а)

Код

package main
import (
"fmt";
"strings"
)
type Pixel struct {
red byte
green byte
blue byte
}
func NewPixel(red, green, blue byte) *Pixel {
p := new(Pixel)
p.red = red
p.green = green
p.blue = blue
return p
}
type Header struct {
Format string
LineWidth int
}
type ParsedImage struct {
parsedData [10][10][4]byte
}
func NewParsedImage(data[10][10][4]byte) *ParsedImage {
pd := new(ParsedImage)
pd.parsedData = data
return pd
}
func (parI *ParsedImage) InspectPixel(x int, y int) Pixel {
var pixl = NewPixel(parI.parsedData[x][y][0], parI.parsedData[x][y][1], parI.parsedData[x][y][2])
return *pixl
}
func ParseImage(data []byte, header Header) ParsedImage {
var dataToReturn [10][10][4]byte
var counter byte
counter = 0
for i := 0; i < ((len(data)/3)/header.LineWidth); i++ {
fmt.Println("FIRST")
for j := 0; j < header.LineWidth; j++ {
fmt.Println("SECOND")
for k := 0; k < len(header.Format); k++ {
fmt.Println("THIRD")
dataToReturn[i][j][k] = data[counter]
counter++
}
if header.Format == "RGBA" {
for z := 0; z < 3; z++ {
var result float32
result = float32(float32(dataToReturn[i][j][z]) * (float32(dataToReturn[i][j][3]) / float32(100)))
dataToReturn[i][j][z] = byte(result)
}
} else {
indexOfR := strings.Index(header.Format, "R")
indexOfG := strings.Index(header.Format, "G")
indexOfB := strings.Index(header.Format, "B")
if len(header.Format) == 3 {
var dataProcessed [3]byte
dataProcessed[0] = dataToReturn[i][j][indexOfR]
dataProcessed[1] = dataToReturn[i][j][indexOfG]
dataProcessed[2] = dataToReturn[i][j][indexOfB]
for q := 0; q < 3; q++ {
dataToReturn[i][j][q] = dataProcessed[q]
}
} else {
indexOfAlpha := strings.Index(header.Format, "A")
var dataProcessed [4]byte
dataProcessed[0] = byte(float32(float32(dataToReturn[i][j][indexOfR])*(float32(dataToReturn[i][j][indexOfAlpha])/float32(100))))
dataProcessed[1] = byte(float32(float32(dataToReturn[i][j][indexOfG])*(float32(dataToReturn[i][j][indexOfAlpha])/float32(100))))
dataProcessed[2] = byte(float32(float32(dataToReturn[i][j][indexOfB])*(float32(dataToReturn[i][j][indexOfAlpha])/float32(100))))
for w := 0; w < 3; w++ {
dataToReturn[i][j][w] = dataProcessed[w]
}
}
}
}
}
return *NewParsedImage(dataToReturn)
}
func main() {
data := []byte{0, 12, 244, 75, 13, 26, 52, 50, 31, 33, 41, 85}
header := Header{"GBAR", 3}
var PI ParsedImage = ParseImage(data, header)
fmt.Println(PI)
pix := PI.InspectPixel(0,0)
fmt.Println(pix)
}

Лог от изпълнението

# _/tmp/d20131125-20161-1vtq8lb
./solution_test.go:9: pixel.Color undefined (type Pixel has no field or method Color)
./solution_test.go:10: pixel.Color undefined (type Pixel has no field or method Color)
./solution_test.go:13: pixel.Color undefined (type Pixel has no field or method Color)
./solution_test.go:14: pixel.Color undefined (type Pixel has no field or method Color)
./solution_test.go:17: pixel.Color undefined (type Pixel has no field or method Color)
./solution_test.go:18: pixel.Color undefined (type Pixel has no field or method Color)
FAIL	_/tmp/d20131125-20161-1vtq8lb [build failed]
# _/tmp/d20131125-20161-1vtq8lb
./solution_test.go:9: pixel.Color undefined (type Pixel has no field or method Color)
./solution_test.go:10: pixel.Color undefined (type Pixel has no field or method Color)
./solution_test.go:13: pixel.Color undefined (type Pixel has no field or method Color)
./solution_test.go:14: pixel.Color undefined (type Pixel has no field or method Color)
./solution_test.go:17: pixel.Color undefined (type Pixel has no field or method Color)
./solution_test.go:18: pixel.Color undefined (type Pixel has no field or method Color)
FAIL	_/tmp/d20131125-20161-1vtq8lb [build failed]
# _/tmp/d20131125-20161-1vtq8lb
./solution_test.go:9: pixel.Color undefined (type Pixel has no field or method Color)
./solution_test.go:10: pixel.Color undefined (type Pixel has no field or method Color)
./solution_test.go:13: pixel.Color undefined (type Pixel has no field or method Color)
./solution_test.go:14: pixel.Color undefined (type Pixel has no field or method Color)
./solution_test.go:17: pixel.Color undefined (type Pixel has no field or method Color)
./solution_test.go:18: pixel.Color undefined (type Pixel has no field or method Color)
FAIL	_/tmp/d20131125-20161-1vtq8lb [build failed]
# _/tmp/d20131125-20161-1vtq8lb
./solution_test.go:9: pixel.Color undefined (type Pixel has no field or method Color)
./solution_test.go:10: pixel.Color undefined (type Pixel has no field or method Color)
./solution_test.go:13: pixel.Color undefined (type Pixel has no field or method Color)
./solution_test.go:14: pixel.Color undefined (type Pixel has no field or method Color)
./solution_test.go:17: pixel.Color undefined (type Pixel has no field or method Color)
./solution_test.go:18: pixel.Color undefined (type Pixel has no field or method Color)
FAIL	_/tmp/d20131125-20161-1vtq8lb [build failed]
# _/tmp/d20131125-20161-1vtq8lb
./solution_test.go:9: pixel.Color undefined (type Pixel has no field or method Color)
./solution_test.go:10: pixel.Color undefined (type Pixel has no field or method Color)
./solution_test.go:13: pixel.Color undefined (type Pixel has no field or method Color)
./solution_test.go:14: pixel.Color undefined (type Pixel has no field or method Color)
./solution_test.go:17: pixel.Color undefined (type Pixel has no field or method Color)
./solution_test.go:18: pixel.Color undefined (type Pixel has no field or method Color)
FAIL	_/tmp/d20131125-20161-1vtq8lb [build failed]
# _/tmp/d20131125-20161-1vtq8lb
./solution_test.go:9: pixel.Color undefined (type Pixel has no field or method Color)
./solution_test.go:10: pixel.Color undefined (type Pixel has no field or method Color)
./solution_test.go:13: pixel.Color undefined (type Pixel has no field or method Color)
./solution_test.go:14: pixel.Color undefined (type Pixel has no field or method Color)
./solution_test.go:17: pixel.Color undefined (type Pixel has no field or method Color)
./solution_test.go:18: pixel.Color undefined (type Pixel has no field or method Color)
FAIL	_/tmp/d20131125-20161-1vtq8lb [build failed]
# _/tmp/d20131125-20161-1vtq8lb
./solution_test.go:9: pixel.Color undefined (type Pixel has no field or method Color)
./solution_test.go:10: pixel.Color undefined (type Pixel has no field or method Color)
./solution_test.go:13: pixel.Color undefined (type Pixel has no field or method Color)
./solution_test.go:14: pixel.Color undefined (type Pixel has no field or method Color)
./solution_test.go:17: pixel.Color undefined (type Pixel has no field or method Color)
./solution_test.go:18: pixel.Color undefined (type Pixel has no field or method Color)
FAIL	_/tmp/d20131125-20161-1vtq8lb [build failed]
# _/tmp/d20131125-20161-1vtq8lb
./solution_test.go:9: pixel.Color undefined (type Pixel has no field or method Color)
./solution_test.go:10: pixel.Color undefined (type Pixel has no field or method Color)
./solution_test.go:13: pixel.Color undefined (type Pixel has no field or method Color)
./solution_test.go:14: pixel.Color undefined (type Pixel has no field or method Color)
./solution_test.go:17: pixel.Color undefined (type Pixel has no field or method Color)
./solution_test.go:18: pixel.Color undefined (type Pixel has no field or method Color)
FAIL	_/tmp/d20131125-20161-1vtq8lb [build failed]
# _/tmp/d20131125-20161-1vtq8lb
./solution_test.go:9: pixel.Color undefined (type Pixel has no field or method Color)
./solution_test.go:10: pixel.Color undefined (type Pixel has no field or method Color)
./solution_test.go:13: pixel.Color undefined (type Pixel has no field or method Color)
./solution_test.go:14: pixel.Color undefined (type Pixel has no field or method Color)
./solution_test.go:17: pixel.Color undefined (type Pixel has no field or method Color)
./solution_test.go:18: pixel.Color undefined (type Pixel has no field or method Color)
FAIL	_/tmp/d20131125-20161-1vtq8lb [build failed]
# _/tmp/d20131125-20161-1vtq8lb
./solution_test.go:9: pixel.Color undefined (type Pixel has no field or method Color)
./solution_test.go:10: pixel.Color undefined (type Pixel has no field or method Color)
./solution_test.go:13: pixel.Color undefined (type Pixel has no field or method Color)
./solution_test.go:14: pixel.Color undefined (type Pixel has no field or method Color)
./solution_test.go:17: pixel.Color undefined (type Pixel has no field or method Color)
./solution_test.go:18: pixel.Color undefined (type Pixel has no field or method Color)
FAIL	_/tmp/d20131125-20161-1vtq8lb [build failed]

История (1 версия и 0 коментара)

Димитър обнови решението на 14.11.2013 16:41 (преди над 4 години)

+package main
+
+import (
+ "fmt";
+ "strings"
+)
+
+type Pixel struct {
+ red byte
+ green byte
+ blue byte
+}
+
+func NewPixel(red, green, blue byte) *Pixel {
+ p := new(Pixel)
+ p.red = red
+ p.green = green
+ p.blue = blue
+ return p
+}
+
+type Header struct {
+ Format string
+ LineWidth int
+}
+
+type ParsedImage struct {
+ parsedData [10][10][4]byte
+}
+
+func NewParsedImage(data[10][10][4]byte) *ParsedImage {
+ pd := new(ParsedImage)
+ pd.parsedData = data
+ return pd
+}
+
+func (parI *ParsedImage) InspectPixel(x int, y int) Pixel {
+ var pixl = NewPixel(parI.parsedData[x][y][0], parI.parsedData[x][y][1], parI.parsedData[x][y][2])
+ return *pixl
+}
+
+func ParseImage(data []byte, header Header) ParsedImage {
+
+ var dataToReturn [10][10][4]byte
+ var counter byte
+ counter = 0
+ for i := 0; i < ((len(data)/3)/header.LineWidth); i++ {
+ fmt.Println("FIRST")
+ for j := 0; j < header.LineWidth; j++ {
+ fmt.Println("SECOND")
+ for k := 0; k < len(header.Format); k++ {
+ fmt.Println("THIRD")
+ dataToReturn[i][j][k] = data[counter]
+ counter++
+ }
+
+ if header.Format == "RGBA" {
+ for z := 0; z < 3; z++ {
+ var result float32
+ result = float32(float32(dataToReturn[i][j][z]) * (float32(dataToReturn[i][j][3]) / float32(100)))
+ dataToReturn[i][j][z] = byte(result)
+ }
+ } else {
+ indexOfR := strings.Index(header.Format, "R")
+ indexOfG := strings.Index(header.Format, "G")
+ indexOfB := strings.Index(header.Format, "B")
+
+ if len(header.Format) == 3 {
+ var dataProcessed [3]byte
+ dataProcessed[0] = dataToReturn[i][j][indexOfR]
+ dataProcessed[1] = dataToReturn[i][j][indexOfG]
+ dataProcessed[2] = dataToReturn[i][j][indexOfB]
+ for q := 0; q < 3; q++ {
+ dataToReturn[i][j][q] = dataProcessed[q]
+ }
+ } else {
+ indexOfAlpha := strings.Index(header.Format, "A")
+ var dataProcessed [4]byte
+ dataProcessed[0] = byte(float32(float32(dataToReturn[i][j][indexOfR])*(float32(dataToReturn[i][j][indexOfAlpha])/float32(100))))
+ dataProcessed[1] = byte(float32(float32(dataToReturn[i][j][indexOfG])*(float32(dataToReturn[i][j][indexOfAlpha])/float32(100))))
+ dataProcessed[2] = byte(float32(float32(dataToReturn[i][j][indexOfB])*(float32(dataToReturn[i][j][indexOfAlpha])/float32(100))))
+ for w := 0; w < 3; w++ {
+ dataToReturn[i][j][w] = dataProcessed[w]
+ }
+ }
+ }
+ }
+ }
+ return *NewParsedImage(dataToReturn)
+}
+func main() {
+
+ data := []byte{0, 12, 244, 75, 13, 26, 52, 50, 31, 33, 41, 85}
+ header := Header{"GBAR", 3}
+ var PI ParsedImage = ParseImage(data, header)
+ fmt.Println(PI)
+ pix := PI.InspectPixel(0,0)
+ fmt.Println(pix)
+}