id
int32 0
167k
| repo
stringlengths 5
54
| path
stringlengths 4
155
| func_name
stringlengths 1
118
| original_string
stringlengths 52
85.5k
| language
stringclasses 1
value | code
stringlengths 52
85.5k
| code_tokens
sequencelengths 21
1.41k
| docstring
stringlengths 6
2.61k
| docstring_tokens
sequencelengths 3
215
| sha
stringlengths 40
40
| url
stringlengths 85
252
|
---|---|---|---|---|---|---|---|---|---|---|---|
153,300 | thoas/stats | options.go | StatusCode | func (o Options) StatusCode() int {
if o.recorder != nil {
return o.recorder.Status()
}
return *o.statusCode
} | go | func (o Options) StatusCode() int {
if o.recorder != nil {
return o.recorder.Status()
}
return *o.statusCode
} | [
"func",
"(",
"o",
"Options",
")",
"StatusCode",
"(",
")",
"int",
"{",
"if",
"o",
".",
"recorder",
"!=",
"nil",
"{",
"return",
"o",
".",
"recorder",
".",
"Status",
"(",
")",
"\n",
"}",
"\n\n",
"return",
"*",
"o",
".",
"statusCode",
"\n",
"}"
] | // StatusCode returns the response status code. | [
"StatusCode",
"returns",
"the",
"response",
"status",
"code",
"."
] | 965cb2de1678b040aefd01c448e2f10de3aec2ae | https://github.com/thoas/stats/blob/965cb2de1678b040aefd01c448e2f10de3aec2ae/options.go#L11-L17 |
153,301 | thoas/stats | options.go | Size | func (o Options) Size() int {
if o.recorder != nil {
return o.recorder.Size()
}
return o.size
} | go | func (o Options) Size() int {
if o.recorder != nil {
return o.recorder.Size()
}
return o.size
} | [
"func",
"(",
"o",
"Options",
")",
"Size",
"(",
")",
"int",
"{",
"if",
"o",
".",
"recorder",
"!=",
"nil",
"{",
"return",
"o",
".",
"recorder",
".",
"Size",
"(",
")",
"\n",
"}",
"\n\n",
"return",
"o",
".",
"size",
"\n",
"}"
] | // Size returns the response size. | [
"Size",
"returns",
"the",
"response",
"size",
"."
] | 965cb2de1678b040aefd01c448e2f10de3aec2ae | https://github.com/thoas/stats/blob/965cb2de1678b040aefd01c448e2f10de3aec2ae/options.go#L20-L26 |
153,302 | thoas/stats | options.go | newOptions | func newOptions(options ...Option) *Options {
opts := &Options{}
for _, o := range options {
o(opts)
}
return opts
} | go | func newOptions(options ...Option) *Options {
opts := &Options{}
for _, o := range options {
o(opts)
}
return opts
} | [
"func",
"newOptions",
"(",
"options",
"...",
"Option",
")",
"*",
"Options",
"{",
"opts",
":=",
"&",
"Options",
"{",
"}",
"\n",
"for",
"_",
",",
"o",
":=",
"range",
"options",
"{",
"o",
"(",
"opts",
")",
"\n",
"}",
"\n",
"return",
"opts",
"\n",
"}"
] | // newOptions takes functional options and returns options. | [
"newOptions",
"takes",
"functional",
"options",
"and",
"returns",
"options",
"."
] | 965cb2de1678b040aefd01c448e2f10de3aec2ae | https://github.com/thoas/stats/blob/965cb2de1678b040aefd01c448e2f10de3aec2ae/options.go#L53-L59 |
153,303 | thoas/stats | stats.go | New | func New() *Stats {
name, _ := os.Hostname()
stats := &Stats{
closed: make(chan struct{}, 1),
Uptime: time.Now(),
Pid: os.Getpid(),
ResponseCounts: map[string]int{},
TotalResponseCounts: map[string]int{},
TotalResponseTime: time.Time{},
Hostname: name,
}
go func() {
for {
select {
case <-stats.closed:
return
default:
stats.ResetResponseCounts()
time.Sleep(time.Second * 1)
}
}
}()
return stats
} | go | func New() *Stats {
name, _ := os.Hostname()
stats := &Stats{
closed: make(chan struct{}, 1),
Uptime: time.Now(),
Pid: os.Getpid(),
ResponseCounts: map[string]int{},
TotalResponseCounts: map[string]int{},
TotalResponseTime: time.Time{},
Hostname: name,
}
go func() {
for {
select {
case <-stats.closed:
return
default:
stats.ResetResponseCounts()
time.Sleep(time.Second * 1)
}
}
}()
return stats
} | [
"func",
"New",
"(",
")",
"*",
"Stats",
"{",
"name",
",",
"_",
":=",
"os",
".",
"Hostname",
"(",
")",
"\n\n",
"stats",
":=",
"&",
"Stats",
"{",
"closed",
":",
"make",
"(",
"chan",
"struct",
"{",
"}",
",",
"1",
")",
",",
"Uptime",
":",
"time",
".",
"Now",
"(",
")",
",",
"Pid",
":",
"os",
".",
"Getpid",
"(",
")",
",",
"ResponseCounts",
":",
"map",
"[",
"string",
"]",
"int",
"{",
"}",
",",
"TotalResponseCounts",
":",
"map",
"[",
"string",
"]",
"int",
"{",
"}",
",",
"TotalResponseTime",
":",
"time",
".",
"Time",
"{",
"}",
",",
"Hostname",
":",
"name",
",",
"}",
"\n\n",
"go",
"func",
"(",
")",
"{",
"for",
"{",
"select",
"{",
"case",
"<-",
"stats",
".",
"closed",
":",
"return",
"\n",
"default",
":",
"stats",
".",
"ResetResponseCounts",
"(",
")",
"\n\n",
"time",
".",
"Sleep",
"(",
"time",
".",
"Second",
"*",
"1",
")",
"\n",
"}",
"\n",
"}",
"\n",
"}",
"(",
")",
"\n\n",
"return",
"stats",
"\n",
"}"
] | // New constructs a new Stats structure | [
"New",
"constructs",
"a",
"new",
"Stats",
"structure"
] | 965cb2de1678b040aefd01c448e2f10de3aec2ae | https://github.com/thoas/stats/blob/965cb2de1678b040aefd01c448e2f10de3aec2ae/stats.go#L33-L60 |
153,304 | thoas/stats | stats.go | ResetResponseCounts | func (mw *Stats) ResetResponseCounts() {
mw.mu.Lock()
defer mw.mu.Unlock()
mw.ResponseCounts = map[string]int{}
} | go | func (mw *Stats) ResetResponseCounts() {
mw.mu.Lock()
defer mw.mu.Unlock()
mw.ResponseCounts = map[string]int{}
} | [
"func",
"(",
"mw",
"*",
"Stats",
")",
"ResetResponseCounts",
"(",
")",
"{",
"mw",
".",
"mu",
".",
"Lock",
"(",
")",
"\n",
"defer",
"mw",
".",
"mu",
".",
"Unlock",
"(",
")",
"\n",
"mw",
".",
"ResponseCounts",
"=",
"map",
"[",
"string",
"]",
"int",
"{",
"}",
"\n",
"}"
] | // ResetResponseCounts reset the response counts | [
"ResetResponseCounts",
"reset",
"the",
"response",
"counts"
] | 965cb2de1678b040aefd01c448e2f10de3aec2ae | https://github.com/thoas/stats/blob/965cb2de1678b040aefd01c448e2f10de3aec2ae/stats.go#L67-L71 |
153,305 | thoas/stats | stats.go | Handler | func (mw *Stats) Handler(h http.Handler) http.Handler {
return http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
beginning, recorder := mw.Begin(w)
h.ServeHTTP(recorder, r)
mw.End(beginning, WithRecorder(recorder))
})
} | go | func (mw *Stats) Handler(h http.Handler) http.Handler {
return http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
beginning, recorder := mw.Begin(w)
h.ServeHTTP(recorder, r)
mw.End(beginning, WithRecorder(recorder))
})
} | [
"func",
"(",
"mw",
"*",
"Stats",
")",
"Handler",
"(",
"h",
"http",
".",
"Handler",
")",
"http",
".",
"Handler",
"{",
"return",
"http",
".",
"HandlerFunc",
"(",
"func",
"(",
"w",
"http",
".",
"ResponseWriter",
",",
"r",
"*",
"http",
".",
"Request",
")",
"{",
"beginning",
",",
"recorder",
":=",
"mw",
".",
"Begin",
"(",
"w",
")",
"\n\n",
"h",
".",
"ServeHTTP",
"(",
"recorder",
",",
"r",
")",
"\n\n",
"mw",
".",
"End",
"(",
"beginning",
",",
"WithRecorder",
"(",
"recorder",
")",
")",
"\n",
"}",
")",
"\n",
"}"
] | // Handler is a MiddlewareFunc makes Stats implement the Middleware interface. | [
"Handler",
"is",
"a",
"MiddlewareFunc",
"makes",
"Stats",
"implement",
"the",
"Middleware",
"interface",
"."
] | 965cb2de1678b040aefd01c448e2f10de3aec2ae | https://github.com/thoas/stats/blob/965cb2de1678b040aefd01c448e2f10de3aec2ae/stats.go#L74-L82 |
153,306 | thoas/stats | stats.go | Begin | func (mw *Stats) Begin(w http.ResponseWriter) (time.Time, ResponseWriter) {
start := time.Now()
writer := NewRecorderResponseWriter(w, 200)
return start, writer
} | go | func (mw *Stats) Begin(w http.ResponseWriter) (time.Time, ResponseWriter) {
start := time.Now()
writer := NewRecorderResponseWriter(w, 200)
return start, writer
} | [
"func",
"(",
"mw",
"*",
"Stats",
")",
"Begin",
"(",
"w",
"http",
".",
"ResponseWriter",
")",
"(",
"time",
".",
"Time",
",",
"ResponseWriter",
")",
"{",
"start",
":=",
"time",
".",
"Now",
"(",
")",
"\n\n",
"writer",
":=",
"NewRecorderResponseWriter",
"(",
"w",
",",
"200",
")",
"\n\n",
"return",
"start",
",",
"writer",
"\n",
"}"
] | // Begin starts a recorder | [
"Begin",
"starts",
"a",
"recorder"
] | 965cb2de1678b040aefd01c448e2f10de3aec2ae | https://github.com/thoas/stats/blob/965cb2de1678b040aefd01c448e2f10de3aec2ae/stats.go#L94-L100 |
153,307 | thoas/stats | stats.go | End | func (mw *Stats) End(start time.Time, opts ...Option) {
options := newOptions(opts...)
responseTime := time.Since(start)
mw.mu.Lock()
defer mw.mu.Unlock()
// If Hijacked connection do not count in response time
if options.StatusCode() != 0 {
statusCode := fmt.Sprintf("%d", options.StatusCode())
mw.ResponseCounts[statusCode]++
mw.TotalResponseCounts[statusCode]++
mw.TotalResponseTime = mw.TotalResponseTime.Add(responseTime)
mw.TotalResponseSize += int64(options.Size())
}
} | go | func (mw *Stats) End(start time.Time, opts ...Option) {
options := newOptions(opts...)
responseTime := time.Since(start)
mw.mu.Lock()
defer mw.mu.Unlock()
// If Hijacked connection do not count in response time
if options.StatusCode() != 0 {
statusCode := fmt.Sprintf("%d", options.StatusCode())
mw.ResponseCounts[statusCode]++
mw.TotalResponseCounts[statusCode]++
mw.TotalResponseTime = mw.TotalResponseTime.Add(responseTime)
mw.TotalResponseSize += int64(options.Size())
}
} | [
"func",
"(",
"mw",
"*",
"Stats",
")",
"End",
"(",
"start",
"time",
".",
"Time",
",",
"opts",
"...",
"Option",
")",
"{",
"options",
":=",
"newOptions",
"(",
"opts",
"...",
")",
"\n\n",
"responseTime",
":=",
"time",
".",
"Since",
"(",
"start",
")",
"\n\n",
"mw",
".",
"mu",
".",
"Lock",
"(",
")",
"\n\n",
"defer",
"mw",
".",
"mu",
".",
"Unlock",
"(",
")",
"\n\n",
"// If Hijacked connection do not count in response time",
"if",
"options",
".",
"StatusCode",
"(",
")",
"!=",
"0",
"{",
"statusCode",
":=",
"fmt",
".",
"Sprintf",
"(",
"\"",
"\"",
",",
"options",
".",
"StatusCode",
"(",
")",
")",
"\n",
"mw",
".",
"ResponseCounts",
"[",
"statusCode",
"]",
"++",
"\n",
"mw",
".",
"TotalResponseCounts",
"[",
"statusCode",
"]",
"++",
"\n",
"mw",
".",
"TotalResponseTime",
"=",
"mw",
".",
"TotalResponseTime",
".",
"Add",
"(",
"responseTime",
")",
"\n",
"mw",
".",
"TotalResponseSize",
"+=",
"int64",
"(",
"options",
".",
"Size",
"(",
")",
")",
"\n",
"}",
"\n",
"}"
] | // End closes the recorder with a specific status | [
"End",
"closes",
"the",
"recorder",
"with",
"a",
"specific",
"status"
] | 965cb2de1678b040aefd01c448e2f10de3aec2ae | https://github.com/thoas/stats/blob/965cb2de1678b040aefd01c448e2f10de3aec2ae/stats.go#L103-L120 |
153,308 | thoas/stats | stats.go | MeasureSince | func (mw *Stats) MeasureSince(key string, start time.Time) {
mw.MeasureSinceWithLabels(key, start, nil)
} | go | func (mw *Stats) MeasureSince(key string, start time.Time) {
mw.MeasureSinceWithLabels(key, start, nil)
} | [
"func",
"(",
"mw",
"*",
"Stats",
")",
"MeasureSince",
"(",
"key",
"string",
",",
"start",
"time",
".",
"Time",
")",
"{",
"mw",
".",
"MeasureSinceWithLabels",
"(",
"key",
",",
"start",
",",
"nil",
")",
"\n",
"}"
] | // MeasureSince method for execution time recording | [
"MeasureSince",
"method",
"for",
"execution",
"time",
"recording"
] | 965cb2de1678b040aefd01c448e2f10de3aec2ae | https://github.com/thoas/stats/blob/965cb2de1678b040aefd01c448e2f10de3aec2ae/stats.go#L123-L125 |
153,309 | thoas/stats | stats.go | MeasureSinceWithLabels | func (mw *Stats) MeasureSinceWithLabels(key string, start time.Time, labels []Label) {
labels = append(labels, Label{"host", mw.Hostname})
elapsed := time.Since(start)
mw.mu.Lock()
defer mw.mu.Unlock()
mw.MetricsCounts[key]++
mw.MetricsTimers[key] = mw.MetricsTimers[key].Add(elapsed)
} | go | func (mw *Stats) MeasureSinceWithLabels(key string, start time.Time, labels []Label) {
labels = append(labels, Label{"host", mw.Hostname})
elapsed := time.Since(start)
mw.mu.Lock()
defer mw.mu.Unlock()
mw.MetricsCounts[key]++
mw.MetricsTimers[key] = mw.MetricsTimers[key].Add(elapsed)
} | [
"func",
"(",
"mw",
"*",
"Stats",
")",
"MeasureSinceWithLabels",
"(",
"key",
"string",
",",
"start",
"time",
".",
"Time",
",",
"labels",
"[",
"]",
"Label",
")",
"{",
"labels",
"=",
"append",
"(",
"labels",
",",
"Label",
"{",
"\"",
"\"",
",",
"mw",
".",
"Hostname",
"}",
")",
"\n",
"elapsed",
":=",
"time",
".",
"Since",
"(",
"start",
")",
"\n\n",
"mw",
".",
"mu",
".",
"Lock",
"(",
")",
"\n",
"defer",
"mw",
".",
"mu",
".",
"Unlock",
"(",
")",
"\n\n",
"mw",
".",
"MetricsCounts",
"[",
"key",
"]",
"++",
"\n",
"mw",
".",
"MetricsTimers",
"[",
"key",
"]",
"=",
"mw",
".",
"MetricsTimers",
"[",
"key",
"]",
".",
"Add",
"(",
"elapsed",
")",
"\n",
"}"
] | // MeasureSinceWithLabels method for execution time recording with custom labels | [
"MeasureSinceWithLabels",
"method",
"for",
"execution",
"time",
"recording",
"with",
"custom",
"labels"
] | 965cb2de1678b040aefd01c448e2f10de3aec2ae | https://github.com/thoas/stats/blob/965cb2de1678b040aefd01c448e2f10de3aec2ae/stats.go#L128-L137 |
153,310 | thoas/stats | stats.go | Data | func (mw *Stats) Data() *Data {
mw.mu.RLock()
responseCounts := make(map[string]int, len(mw.ResponseCounts))
totalResponseCounts := make(map[string]int, len(mw.TotalResponseCounts))
totalMetricsCounts := make(map[string]int, len(mw.MetricsCounts))
metricsCounts := make(map[string]float64, len(mw.MetricsCounts))
now := time.Now()
uptime := now.Sub(mw.Uptime)
count := 0
for code, current := range mw.ResponseCounts {
responseCounts[code] = current
count += current
}
totalCount := 0
for code, count := range mw.TotalResponseCounts {
totalResponseCounts[code] = count
totalCount += count
}
totalResponseTime := mw.TotalResponseTime.Sub(time.Time{})
totalResponseSize := mw.TotalResponseSize
averageResponseTime := time.Duration(0)
averageResponseSize := int64(0)
if totalCount > 0 {
avgNs := int64(totalResponseTime) / int64(totalCount)
averageResponseTime = time.Duration(avgNs)
averageResponseSize = int64(totalResponseSize) / int64(totalCount)
}
for key, count := range mw.MetricsCounts {
totalMetric := mw.MetricsTimers[key].Sub(time.Time{})
avgNs := int64(totalMetric) / int64(count)
metricsCounts[key] = time.Duration(avgNs).Seconds()
totalMetricsCounts[key] = count
}
mw.mu.RUnlock()
r := &Data{
Pid: mw.Pid,
UpTime: uptime.String(),
UpTimeSec: uptime.Seconds(),
Time: now.String(),
TimeUnix: now.Unix(),
StatusCodeCount: responseCounts,
TotalStatusCodeCount: totalResponseCounts,
Count: count,
TotalCount: totalCount,
TotalResponseTime: totalResponseTime.String(),
TotalResponseSize: totalResponseSize,
TotalResponseTimeSec: totalResponseTime.Seconds(),
TotalMetricsCounts: totalMetricsCounts,
AverageResponseSize: averageResponseSize,
AverageResponseTime: averageResponseTime.String(),
AverageResponseTimeSec: averageResponseTime.Seconds(),
AverageMetricsTimers: metricsCounts,
}
return r
} | go | func (mw *Stats) Data() *Data {
mw.mu.RLock()
responseCounts := make(map[string]int, len(mw.ResponseCounts))
totalResponseCounts := make(map[string]int, len(mw.TotalResponseCounts))
totalMetricsCounts := make(map[string]int, len(mw.MetricsCounts))
metricsCounts := make(map[string]float64, len(mw.MetricsCounts))
now := time.Now()
uptime := now.Sub(mw.Uptime)
count := 0
for code, current := range mw.ResponseCounts {
responseCounts[code] = current
count += current
}
totalCount := 0
for code, count := range mw.TotalResponseCounts {
totalResponseCounts[code] = count
totalCount += count
}
totalResponseTime := mw.TotalResponseTime.Sub(time.Time{})
totalResponseSize := mw.TotalResponseSize
averageResponseTime := time.Duration(0)
averageResponseSize := int64(0)
if totalCount > 0 {
avgNs := int64(totalResponseTime) / int64(totalCount)
averageResponseTime = time.Duration(avgNs)
averageResponseSize = int64(totalResponseSize) / int64(totalCount)
}
for key, count := range mw.MetricsCounts {
totalMetric := mw.MetricsTimers[key].Sub(time.Time{})
avgNs := int64(totalMetric) / int64(count)
metricsCounts[key] = time.Duration(avgNs).Seconds()
totalMetricsCounts[key] = count
}
mw.mu.RUnlock()
r := &Data{
Pid: mw.Pid,
UpTime: uptime.String(),
UpTimeSec: uptime.Seconds(),
Time: now.String(),
TimeUnix: now.Unix(),
StatusCodeCount: responseCounts,
TotalStatusCodeCount: totalResponseCounts,
Count: count,
TotalCount: totalCount,
TotalResponseTime: totalResponseTime.String(),
TotalResponseSize: totalResponseSize,
TotalResponseTimeSec: totalResponseTime.Seconds(),
TotalMetricsCounts: totalMetricsCounts,
AverageResponseSize: averageResponseSize,
AverageResponseTime: averageResponseTime.String(),
AverageResponseTimeSec: averageResponseTime.Seconds(),
AverageMetricsTimers: metricsCounts,
}
return r
} | [
"func",
"(",
"mw",
"*",
"Stats",
")",
"Data",
"(",
")",
"*",
"Data",
"{",
"mw",
".",
"mu",
".",
"RLock",
"(",
")",
"\n\n",
"responseCounts",
":=",
"make",
"(",
"map",
"[",
"string",
"]",
"int",
",",
"len",
"(",
"mw",
".",
"ResponseCounts",
")",
")",
"\n",
"totalResponseCounts",
":=",
"make",
"(",
"map",
"[",
"string",
"]",
"int",
",",
"len",
"(",
"mw",
".",
"TotalResponseCounts",
")",
")",
"\n",
"totalMetricsCounts",
":=",
"make",
"(",
"map",
"[",
"string",
"]",
"int",
",",
"len",
"(",
"mw",
".",
"MetricsCounts",
")",
")",
"\n",
"metricsCounts",
":=",
"make",
"(",
"map",
"[",
"string",
"]",
"float64",
",",
"len",
"(",
"mw",
".",
"MetricsCounts",
")",
")",
"\n\n",
"now",
":=",
"time",
".",
"Now",
"(",
")",
"\n\n",
"uptime",
":=",
"now",
".",
"Sub",
"(",
"mw",
".",
"Uptime",
")",
"\n\n",
"count",
":=",
"0",
"\n",
"for",
"code",
",",
"current",
":=",
"range",
"mw",
".",
"ResponseCounts",
"{",
"responseCounts",
"[",
"code",
"]",
"=",
"current",
"\n",
"count",
"+=",
"current",
"\n",
"}",
"\n\n",
"totalCount",
":=",
"0",
"\n",
"for",
"code",
",",
"count",
":=",
"range",
"mw",
".",
"TotalResponseCounts",
"{",
"totalResponseCounts",
"[",
"code",
"]",
"=",
"count",
"\n",
"totalCount",
"+=",
"count",
"\n",
"}",
"\n\n",
"totalResponseTime",
":=",
"mw",
".",
"TotalResponseTime",
".",
"Sub",
"(",
"time",
".",
"Time",
"{",
"}",
")",
"\n",
"totalResponseSize",
":=",
"mw",
".",
"TotalResponseSize",
"\n\n",
"averageResponseTime",
":=",
"time",
".",
"Duration",
"(",
"0",
")",
"\n",
"averageResponseSize",
":=",
"int64",
"(",
"0",
")",
"\n",
"if",
"totalCount",
">",
"0",
"{",
"avgNs",
":=",
"int64",
"(",
"totalResponseTime",
")",
"/",
"int64",
"(",
"totalCount",
")",
"\n",
"averageResponseTime",
"=",
"time",
".",
"Duration",
"(",
"avgNs",
")",
"\n",
"averageResponseSize",
"=",
"int64",
"(",
"totalResponseSize",
")",
"/",
"int64",
"(",
"totalCount",
")",
"\n",
"}",
"\n\n",
"for",
"key",
",",
"count",
":=",
"range",
"mw",
".",
"MetricsCounts",
"{",
"totalMetric",
":=",
"mw",
".",
"MetricsTimers",
"[",
"key",
"]",
".",
"Sub",
"(",
"time",
".",
"Time",
"{",
"}",
")",
"\n",
"avgNs",
":=",
"int64",
"(",
"totalMetric",
")",
"/",
"int64",
"(",
"count",
")",
"\n",
"metricsCounts",
"[",
"key",
"]",
"=",
"time",
".",
"Duration",
"(",
"avgNs",
")",
".",
"Seconds",
"(",
")",
"\n",
"totalMetricsCounts",
"[",
"key",
"]",
"=",
"count",
"\n",
"}",
"\n\n",
"mw",
".",
"mu",
".",
"RUnlock",
"(",
")",
"\n\n",
"r",
":=",
"&",
"Data",
"{",
"Pid",
":",
"mw",
".",
"Pid",
",",
"UpTime",
":",
"uptime",
".",
"String",
"(",
")",
",",
"UpTimeSec",
":",
"uptime",
".",
"Seconds",
"(",
")",
",",
"Time",
":",
"now",
".",
"String",
"(",
")",
",",
"TimeUnix",
":",
"now",
".",
"Unix",
"(",
")",
",",
"StatusCodeCount",
":",
"responseCounts",
",",
"TotalStatusCodeCount",
":",
"totalResponseCounts",
",",
"Count",
":",
"count",
",",
"TotalCount",
":",
"totalCount",
",",
"TotalResponseTime",
":",
"totalResponseTime",
".",
"String",
"(",
")",
",",
"TotalResponseSize",
":",
"totalResponseSize",
",",
"TotalResponseTimeSec",
":",
"totalResponseTime",
".",
"Seconds",
"(",
")",
",",
"TotalMetricsCounts",
":",
"totalMetricsCounts",
",",
"AverageResponseSize",
":",
"averageResponseSize",
",",
"AverageResponseTime",
":",
"averageResponseTime",
".",
"String",
"(",
")",
",",
"AverageResponseTimeSec",
":",
"averageResponseTime",
".",
"Seconds",
"(",
")",
",",
"AverageMetricsTimers",
":",
"metricsCounts",
",",
"}",
"\n\n",
"return",
"r",
"\n",
"}"
] | // Data returns the data serializable structure | [
"Data",
"returns",
"the",
"data",
"serializable",
"structure"
] | 965cb2de1678b040aefd01c448e2f10de3aec2ae | https://github.com/thoas/stats/blob/965cb2de1678b040aefd01c448e2f10de3aec2ae/stats.go#L162-L227 |
153,311 | anthonynsimon/bild | segment/thresholding.go | Threshold | func Threshold(img image.Image, level uint8) *image.Gray {
src := clone.AsRGBA(img)
bounds := src.Bounds()
dst := image.NewGray(bounds)
for y := 0; y < bounds.Dy(); y++ {
for x := 0; x < bounds.Dx(); x++ {
srcPos := y*src.Stride + x*4
dstPos := y*dst.Stride + x
c := src.Pix[srcPos : srcPos+4]
r := util.Rank(color.RGBA{c[0], c[1], c[2], c[3]})
// transparent pixel is always white
if c[0] == 0 && c[1] == 0 && c[2] == 0 && c[3] == 0 {
dst.Pix[dstPos] = 0xFF
continue
}
if uint8(r) >= level {
dst.Pix[dstPos] = 0xFF
} else {
dst.Pix[dstPos] = 0x00
}
}
}
return dst
} | go | func Threshold(img image.Image, level uint8) *image.Gray {
src := clone.AsRGBA(img)
bounds := src.Bounds()
dst := image.NewGray(bounds)
for y := 0; y < bounds.Dy(); y++ {
for x := 0; x < bounds.Dx(); x++ {
srcPos := y*src.Stride + x*4
dstPos := y*dst.Stride + x
c := src.Pix[srcPos : srcPos+4]
r := util.Rank(color.RGBA{c[0], c[1], c[2], c[3]})
// transparent pixel is always white
if c[0] == 0 && c[1] == 0 && c[2] == 0 && c[3] == 0 {
dst.Pix[dstPos] = 0xFF
continue
}
if uint8(r) >= level {
dst.Pix[dstPos] = 0xFF
} else {
dst.Pix[dstPos] = 0x00
}
}
}
return dst
} | [
"func",
"Threshold",
"(",
"img",
"image",
".",
"Image",
",",
"level",
"uint8",
")",
"*",
"image",
".",
"Gray",
"{",
"src",
":=",
"clone",
".",
"AsRGBA",
"(",
"img",
")",
"\n",
"bounds",
":=",
"src",
".",
"Bounds",
"(",
")",
"\n\n",
"dst",
":=",
"image",
".",
"NewGray",
"(",
"bounds",
")",
"\n\n",
"for",
"y",
":=",
"0",
";",
"y",
"<",
"bounds",
".",
"Dy",
"(",
")",
";",
"y",
"++",
"{",
"for",
"x",
":=",
"0",
";",
"x",
"<",
"bounds",
".",
"Dx",
"(",
")",
";",
"x",
"++",
"{",
"srcPos",
":=",
"y",
"*",
"src",
".",
"Stride",
"+",
"x",
"*",
"4",
"\n",
"dstPos",
":=",
"y",
"*",
"dst",
".",
"Stride",
"+",
"x",
"\n\n",
"c",
":=",
"src",
".",
"Pix",
"[",
"srcPos",
":",
"srcPos",
"+",
"4",
"]",
"\n",
"r",
":=",
"util",
".",
"Rank",
"(",
"color",
".",
"RGBA",
"{",
"c",
"[",
"0",
"]",
",",
"c",
"[",
"1",
"]",
",",
"c",
"[",
"2",
"]",
",",
"c",
"[",
"3",
"]",
"}",
")",
"\n\n",
"// transparent pixel is always white",
"if",
"c",
"[",
"0",
"]",
"==",
"0",
"&&",
"c",
"[",
"1",
"]",
"==",
"0",
"&&",
"c",
"[",
"2",
"]",
"==",
"0",
"&&",
"c",
"[",
"3",
"]",
"==",
"0",
"{",
"dst",
".",
"Pix",
"[",
"dstPos",
"]",
"=",
"0xFF",
"\n",
"continue",
"\n",
"}",
"\n\n",
"if",
"uint8",
"(",
"r",
")",
">=",
"level",
"{",
"dst",
".",
"Pix",
"[",
"dstPos",
"]",
"=",
"0xFF",
"\n",
"}",
"else",
"{",
"dst",
".",
"Pix",
"[",
"dstPos",
"]",
"=",
"0x00",
"\n",
"}",
"\n",
"}",
"\n",
"}",
"\n\n",
"return",
"dst",
"\n",
"}"
] | // Threshold returns a grayscale image in which values from the param img that are
// smaller than the param level are set to black and values larger than or equal to
// it are set to white.
// Level must be of the range 0 to 255. | [
"Threshold",
"returns",
"a",
"grayscale",
"image",
"in",
"which",
"values",
"from",
"the",
"param",
"img",
"that",
"are",
"smaller",
"than",
"the",
"param",
"level",
"are",
"set",
"to",
"black",
"and",
"values",
"larger",
"than",
"or",
"equal",
"to",
"it",
"are",
"set",
"to",
"white",
".",
"Level",
"must",
"be",
"of",
"the",
"range",
"0",
"to",
"255",
"."
] | 3a6867030b45db250c7619233c6056b46a980667 | https://github.com/anthonynsimon/bild/blob/3a6867030b45db250c7619233c6056b46a980667/segment/thresholding.go#L16-L45 |
153,312 | anthonynsimon/bild | transform/shear.go | ShearH | func ShearH(img image.Image, angle float64) *image.RGBA {
src := clone.AsRGBA(img)
srcW, srcH := src.Bounds().Dx(), src.Bounds().Dy()
// Supersample, currently hard set to 2x
srcW, srcH = srcW*2, srcH*2
src = Resize(src, srcW, srcH, NearestNeighbor)
// Calculate shear factor
kx := math.Tan(angle * (math.Pi / 180))
dstW, dstH := srcW+int(float64(srcH)*math.Abs(kx)), srcH
dst := image.NewRGBA(image.Rect(0, 0, dstW, dstH))
pivotX := float64(dstW) / 2
pivotY := float64(dstH) / 2
// Calculate offset since we are resizing the bounds to
// fit the sheared image.
dx := (dstW - srcW) / 2
dy := (dstH - srcH) / 2
parallel.Line(dstH, func(start, end int) {
for y := start; y < end; y++ {
for x := 0; x < dstW; x++ {
// Move positions to revolve around pivot
ix := x - int(pivotX) - dx
iy := y - int(pivotY) - dy
// Apply linear transformation
ix = ix + int(float64(iy)*kx)
// Move positions back to image coordinates
ix += int(pivotX)
iy += int(pivotY)
if ix < 0 || ix >= srcW || iy < 0 || iy >= srcH {
continue
}
srcPos := iy*src.Stride + ix*4
dstPos := y*dst.Stride + x*4
dst.Pix[dstPos+0] = src.Pix[srcPos+0]
dst.Pix[dstPos+1] = src.Pix[srcPos+1]
dst.Pix[dstPos+2] = src.Pix[srcPos+2]
dst.Pix[dstPos+3] = src.Pix[srcPos+3]
}
}
})
// Downsample to original bounds as part of the Supersampling
dst = Resize(dst, dstW/2, dstH/2, Linear)
return dst
} | go | func ShearH(img image.Image, angle float64) *image.RGBA {
src := clone.AsRGBA(img)
srcW, srcH := src.Bounds().Dx(), src.Bounds().Dy()
// Supersample, currently hard set to 2x
srcW, srcH = srcW*2, srcH*2
src = Resize(src, srcW, srcH, NearestNeighbor)
// Calculate shear factor
kx := math.Tan(angle * (math.Pi / 180))
dstW, dstH := srcW+int(float64(srcH)*math.Abs(kx)), srcH
dst := image.NewRGBA(image.Rect(0, 0, dstW, dstH))
pivotX := float64(dstW) / 2
pivotY := float64(dstH) / 2
// Calculate offset since we are resizing the bounds to
// fit the sheared image.
dx := (dstW - srcW) / 2
dy := (dstH - srcH) / 2
parallel.Line(dstH, func(start, end int) {
for y := start; y < end; y++ {
for x := 0; x < dstW; x++ {
// Move positions to revolve around pivot
ix := x - int(pivotX) - dx
iy := y - int(pivotY) - dy
// Apply linear transformation
ix = ix + int(float64(iy)*kx)
// Move positions back to image coordinates
ix += int(pivotX)
iy += int(pivotY)
if ix < 0 || ix >= srcW || iy < 0 || iy >= srcH {
continue
}
srcPos := iy*src.Stride + ix*4
dstPos := y*dst.Stride + x*4
dst.Pix[dstPos+0] = src.Pix[srcPos+0]
dst.Pix[dstPos+1] = src.Pix[srcPos+1]
dst.Pix[dstPos+2] = src.Pix[srcPos+2]
dst.Pix[dstPos+3] = src.Pix[srcPos+3]
}
}
})
// Downsample to original bounds as part of the Supersampling
dst = Resize(dst, dstW/2, dstH/2, Linear)
return dst
} | [
"func",
"ShearH",
"(",
"img",
"image",
".",
"Image",
",",
"angle",
"float64",
")",
"*",
"image",
".",
"RGBA",
"{",
"src",
":=",
"clone",
".",
"AsRGBA",
"(",
"img",
")",
"\n",
"srcW",
",",
"srcH",
":=",
"src",
".",
"Bounds",
"(",
")",
".",
"Dx",
"(",
")",
",",
"src",
".",
"Bounds",
"(",
")",
".",
"Dy",
"(",
")",
"\n\n",
"// Supersample, currently hard set to 2x",
"srcW",
",",
"srcH",
"=",
"srcW",
"*",
"2",
",",
"srcH",
"*",
"2",
"\n",
"src",
"=",
"Resize",
"(",
"src",
",",
"srcW",
",",
"srcH",
",",
"NearestNeighbor",
")",
"\n\n",
"// Calculate shear factor",
"kx",
":=",
"math",
".",
"Tan",
"(",
"angle",
"*",
"(",
"math",
".",
"Pi",
"/",
"180",
")",
")",
"\n\n",
"dstW",
",",
"dstH",
":=",
"srcW",
"+",
"int",
"(",
"float64",
"(",
"srcH",
")",
"*",
"math",
".",
"Abs",
"(",
"kx",
")",
")",
",",
"srcH",
"\n",
"dst",
":=",
"image",
".",
"NewRGBA",
"(",
"image",
".",
"Rect",
"(",
"0",
",",
"0",
",",
"dstW",
",",
"dstH",
")",
")",
"\n\n",
"pivotX",
":=",
"float64",
"(",
"dstW",
")",
"/",
"2",
"\n",
"pivotY",
":=",
"float64",
"(",
"dstH",
")",
"/",
"2",
"\n\n",
"// Calculate offset since we are resizing the bounds to",
"// fit the sheared image.",
"dx",
":=",
"(",
"dstW",
"-",
"srcW",
")",
"/",
"2",
"\n",
"dy",
":=",
"(",
"dstH",
"-",
"srcH",
")",
"/",
"2",
"\n\n",
"parallel",
".",
"Line",
"(",
"dstH",
",",
"func",
"(",
"start",
",",
"end",
"int",
")",
"{",
"for",
"y",
":=",
"start",
";",
"y",
"<",
"end",
";",
"y",
"++",
"{",
"for",
"x",
":=",
"0",
";",
"x",
"<",
"dstW",
";",
"x",
"++",
"{",
"// Move positions to revolve around pivot",
"ix",
":=",
"x",
"-",
"int",
"(",
"pivotX",
")",
"-",
"dx",
"\n",
"iy",
":=",
"y",
"-",
"int",
"(",
"pivotY",
")",
"-",
"dy",
"\n\n",
"// Apply linear transformation",
"ix",
"=",
"ix",
"+",
"int",
"(",
"float64",
"(",
"iy",
")",
"*",
"kx",
")",
"\n\n",
"// Move positions back to image coordinates",
"ix",
"+=",
"int",
"(",
"pivotX",
")",
"\n",
"iy",
"+=",
"int",
"(",
"pivotY",
")",
"\n\n",
"if",
"ix",
"<",
"0",
"||",
"ix",
">=",
"srcW",
"||",
"iy",
"<",
"0",
"||",
"iy",
">=",
"srcH",
"{",
"continue",
"\n",
"}",
"\n\n",
"srcPos",
":=",
"iy",
"*",
"src",
".",
"Stride",
"+",
"ix",
"*",
"4",
"\n",
"dstPos",
":=",
"y",
"*",
"dst",
".",
"Stride",
"+",
"x",
"*",
"4",
"\n\n",
"dst",
".",
"Pix",
"[",
"dstPos",
"+",
"0",
"]",
"=",
"src",
".",
"Pix",
"[",
"srcPos",
"+",
"0",
"]",
"\n",
"dst",
".",
"Pix",
"[",
"dstPos",
"+",
"1",
"]",
"=",
"src",
".",
"Pix",
"[",
"srcPos",
"+",
"1",
"]",
"\n",
"dst",
".",
"Pix",
"[",
"dstPos",
"+",
"2",
"]",
"=",
"src",
".",
"Pix",
"[",
"srcPos",
"+",
"2",
"]",
"\n",
"dst",
".",
"Pix",
"[",
"dstPos",
"+",
"3",
"]",
"=",
"src",
".",
"Pix",
"[",
"srcPos",
"+",
"3",
"]",
"\n",
"}",
"\n",
"}",
"\n",
"}",
")",
"\n\n",
"// Downsample to original bounds as part of the Supersampling",
"dst",
"=",
"Resize",
"(",
"dst",
",",
"dstW",
"/",
"2",
",",
"dstH",
"/",
"2",
",",
"Linear",
")",
"\n\n",
"return",
"dst",
"\n",
"}"
] | // ShearH applies a shear linear transformation along the horizontal axis,
// the parameter angle is the shear angle to be applied.
// The transformation will be applied with the center of the image as the pivot. | [
"ShearH",
"applies",
"a",
"shear",
"linear",
"transformation",
"along",
"the",
"horizontal",
"axis",
"the",
"parameter",
"angle",
"is",
"the",
"shear",
"angle",
"to",
"be",
"applied",
".",
"The",
"transformation",
"will",
"be",
"applied",
"with",
"the",
"center",
"of",
"the",
"image",
"as",
"the",
"pivot",
"."
] | 3a6867030b45db250c7619233c6056b46a980667 | https://github.com/anthonynsimon/bild/blob/3a6867030b45db250c7619233c6056b46a980667/transform/shear.go#L14-L69 |
153,313 | anthonynsimon/bild | transform/translate.go | Translate | func Translate(img image.Image, dx, dy int) *image.RGBA {
src := clone.AsRGBA(img)
if dx == 0 && dy == 0 {
return src
}
w, h := src.Bounds().Dx(), src.Bounds().Dy()
dst := image.NewRGBA(src.Bounds())
parallel.Line(h, func(start, end int) {
for y := start; y < end; y++ {
for x := 0; x < w; x++ {
ix, iy := x-dx, y+dy
if ix < 0 || ix >= w || iy < 0 || iy >= h {
continue
}
srcPos := iy*src.Stride + ix*4
dstPos := y*src.Stride + x*4
copy(dst.Pix[dstPos:dstPos+4], src.Pix[srcPos:srcPos+4])
}
}
})
return dst
} | go | func Translate(img image.Image, dx, dy int) *image.RGBA {
src := clone.AsRGBA(img)
if dx == 0 && dy == 0 {
return src
}
w, h := src.Bounds().Dx(), src.Bounds().Dy()
dst := image.NewRGBA(src.Bounds())
parallel.Line(h, func(start, end int) {
for y := start; y < end; y++ {
for x := 0; x < w; x++ {
ix, iy := x-dx, y+dy
if ix < 0 || ix >= w || iy < 0 || iy >= h {
continue
}
srcPos := iy*src.Stride + ix*4
dstPos := y*src.Stride + x*4
copy(dst.Pix[dstPos:dstPos+4], src.Pix[srcPos:srcPos+4])
}
}
})
return dst
} | [
"func",
"Translate",
"(",
"img",
"image",
".",
"Image",
",",
"dx",
",",
"dy",
"int",
")",
"*",
"image",
".",
"RGBA",
"{",
"src",
":=",
"clone",
".",
"AsRGBA",
"(",
"img",
")",
"\n\n",
"if",
"dx",
"==",
"0",
"&&",
"dy",
"==",
"0",
"{",
"return",
"src",
"\n",
"}",
"\n\n",
"w",
",",
"h",
":=",
"src",
".",
"Bounds",
"(",
")",
".",
"Dx",
"(",
")",
",",
"src",
".",
"Bounds",
"(",
")",
".",
"Dy",
"(",
")",
"\n",
"dst",
":=",
"image",
".",
"NewRGBA",
"(",
"src",
".",
"Bounds",
"(",
")",
")",
"\n\n",
"parallel",
".",
"Line",
"(",
"h",
",",
"func",
"(",
"start",
",",
"end",
"int",
")",
"{",
"for",
"y",
":=",
"start",
";",
"y",
"<",
"end",
";",
"y",
"++",
"{",
"for",
"x",
":=",
"0",
";",
"x",
"<",
"w",
";",
"x",
"++",
"{",
"ix",
",",
"iy",
":=",
"x",
"-",
"dx",
",",
"y",
"+",
"dy",
"\n\n",
"if",
"ix",
"<",
"0",
"||",
"ix",
">=",
"w",
"||",
"iy",
"<",
"0",
"||",
"iy",
">=",
"h",
"{",
"continue",
"\n",
"}",
"\n\n",
"srcPos",
":=",
"iy",
"*",
"src",
".",
"Stride",
"+",
"ix",
"*",
"4",
"\n",
"dstPos",
":=",
"y",
"*",
"src",
".",
"Stride",
"+",
"x",
"*",
"4",
"\n\n",
"copy",
"(",
"dst",
".",
"Pix",
"[",
"dstPos",
":",
"dstPos",
"+",
"4",
"]",
",",
"src",
".",
"Pix",
"[",
"srcPos",
":",
"srcPos",
"+",
"4",
"]",
")",
"\n",
"}",
"\n",
"}",
"\n",
"}",
")",
"\n\n",
"return",
"dst",
"\n",
"}"
] | // Translate repositions a copy of the provided image by dx on the x-axis and
// by dy on the y-axis and returns the result. The bounds from the provided image
// will be kept.
// A positive dx value moves the image towards the right and a positive dy value
// moves the image upwards. | [
"Translate",
"repositions",
"a",
"copy",
"of",
"the",
"provided",
"image",
"by",
"dx",
"on",
"the",
"x",
"-",
"axis",
"and",
"by",
"dy",
"on",
"the",
"y",
"-",
"axis",
"and",
"returns",
"the",
"result",
".",
"The",
"bounds",
"from",
"the",
"provided",
"image",
"will",
"be",
"kept",
".",
"A",
"positive",
"dx",
"value",
"moves",
"the",
"image",
"towards",
"the",
"right",
"and",
"a",
"positive",
"dy",
"value",
"moves",
"the",
"image",
"upwards",
"."
] | 3a6867030b45db250c7619233c6056b46a980667 | https://github.com/anthonynsimon/bild/blob/3a6867030b45db250c7619233c6056b46a980667/transform/translate.go#L15-L43 |
153,314 | anthonynsimon/bild | noise/noise.go | Generate | func Generate(width, height int, o *Options) *image.RGBA {
dst := image.NewRGBA(image.Rect(0, 0, width, height))
// Get options or defaults
noiseFn := Uniform
monochrome := false
if o != nil {
if o.NoiseFn != nil {
noiseFn = o.NoiseFn
}
monochrome = o.Monochrome
}
rand.Seed(time.Now().UTC().UnixNano())
if monochrome {
fillMonochrome(dst, noiseFn)
} else {
fillColored(dst, noiseFn)
}
return dst
} | go | func Generate(width, height int, o *Options) *image.RGBA {
dst := image.NewRGBA(image.Rect(0, 0, width, height))
// Get options or defaults
noiseFn := Uniform
monochrome := false
if o != nil {
if o.NoiseFn != nil {
noiseFn = o.NoiseFn
}
monochrome = o.Monochrome
}
rand.Seed(time.Now().UTC().UnixNano())
if monochrome {
fillMonochrome(dst, noiseFn)
} else {
fillColored(dst, noiseFn)
}
return dst
} | [
"func",
"Generate",
"(",
"width",
",",
"height",
"int",
",",
"o",
"*",
"Options",
")",
"*",
"image",
".",
"RGBA",
"{",
"dst",
":=",
"image",
".",
"NewRGBA",
"(",
"image",
".",
"Rect",
"(",
"0",
",",
"0",
",",
"width",
",",
"height",
")",
")",
"\n\n",
"// Get options or defaults",
"noiseFn",
":=",
"Uniform",
"\n",
"monochrome",
":=",
"false",
"\n",
"if",
"o",
"!=",
"nil",
"{",
"if",
"o",
".",
"NoiseFn",
"!=",
"nil",
"{",
"noiseFn",
"=",
"o",
".",
"NoiseFn",
"\n",
"}",
"\n",
"monochrome",
"=",
"o",
".",
"Monochrome",
"\n",
"}",
"\n\n",
"rand",
".",
"Seed",
"(",
"time",
".",
"Now",
"(",
")",
".",
"UTC",
"(",
")",
".",
"UnixNano",
"(",
")",
")",
"\n\n",
"if",
"monochrome",
"{",
"fillMonochrome",
"(",
"dst",
",",
"noiseFn",
")",
"\n",
"}",
"else",
"{",
"fillColored",
"(",
"dst",
",",
"noiseFn",
")",
"\n",
"}",
"\n\n",
"return",
"dst",
"\n",
"}"
] | // Generate returns an image of the parameter width and height filled
// with the values from a noise function.
// If no options are provided, defaults will be used. | [
"Generate",
"returns",
"an",
"image",
"of",
"the",
"parameter",
"width",
"and",
"height",
"filled",
"with",
"the",
"values",
"from",
"a",
"noise",
"function",
".",
"If",
"no",
"options",
"are",
"provided",
"defaults",
"will",
"be",
"used",
"."
] | 3a6867030b45db250c7619233c6056b46a980667 | https://github.com/anthonynsimon/bild/blob/3a6867030b45db250c7619233c6056b46a980667/noise/noise.go#L49-L71 |
153,315 | anthonynsimon/bild | histogram/histogram.go | Max | func (h *Histogram) Max() int {
var max int
if len(h.Bins) > 0 {
max = h.Bins[0]
for i := 1; i < len(h.Bins); i++ {
if h.Bins[i] > max {
max = h.Bins[i]
}
}
}
return max
} | go | func (h *Histogram) Max() int {
var max int
if len(h.Bins) > 0 {
max = h.Bins[0]
for i := 1; i < len(h.Bins); i++ {
if h.Bins[i] > max {
max = h.Bins[i]
}
}
}
return max
} | [
"func",
"(",
"h",
"*",
"Histogram",
")",
"Max",
"(",
")",
"int",
"{",
"var",
"max",
"int",
"\n",
"if",
"len",
"(",
"h",
".",
"Bins",
")",
">",
"0",
"{",
"max",
"=",
"h",
".",
"Bins",
"[",
"0",
"]",
"\n",
"for",
"i",
":=",
"1",
";",
"i",
"<",
"len",
"(",
"h",
".",
"Bins",
")",
";",
"i",
"++",
"{",
"if",
"h",
".",
"Bins",
"[",
"i",
"]",
">",
"max",
"{",
"max",
"=",
"h",
".",
"Bins",
"[",
"i",
"]",
"\n",
"}",
"\n",
"}",
"\n",
"}",
"\n",
"return",
"max",
"\n",
"}"
] | // Max returns the highest count found in the histogram bins. | [
"Max",
"returns",
"the",
"highest",
"count",
"found",
"in",
"the",
"histogram",
"bins",
"."
] | 3a6867030b45db250c7619233c6056b46a980667 | https://github.com/anthonynsimon/bild/blob/3a6867030b45db250c7619233c6056b46a980667/histogram/histogram.go#L25-L36 |
153,316 | anthonynsimon/bild | histogram/histogram.go | Min | func (h *Histogram) Min() int {
var min int
if len(h.Bins) > 0 {
min = h.Bins[0]
for i := 1; i < len(h.Bins); i++ {
if h.Bins[i] < min {
min = h.Bins[i]
}
}
}
return min
} | go | func (h *Histogram) Min() int {
var min int
if len(h.Bins) > 0 {
min = h.Bins[0]
for i := 1; i < len(h.Bins); i++ {
if h.Bins[i] < min {
min = h.Bins[i]
}
}
}
return min
} | [
"func",
"(",
"h",
"*",
"Histogram",
")",
"Min",
"(",
")",
"int",
"{",
"var",
"min",
"int",
"\n",
"if",
"len",
"(",
"h",
".",
"Bins",
")",
">",
"0",
"{",
"min",
"=",
"h",
".",
"Bins",
"[",
"0",
"]",
"\n",
"for",
"i",
":=",
"1",
";",
"i",
"<",
"len",
"(",
"h",
".",
"Bins",
")",
";",
"i",
"++",
"{",
"if",
"h",
".",
"Bins",
"[",
"i",
"]",
"<",
"min",
"{",
"min",
"=",
"h",
".",
"Bins",
"[",
"i",
"]",
"\n",
"}",
"\n",
"}",
"\n",
"}",
"\n",
"return",
"min",
"\n",
"}"
] | // Min returns the lowest count found in the histogram bins. | [
"Min",
"returns",
"the",
"lowest",
"count",
"found",
"in",
"the",
"histogram",
"bins",
"."
] | 3a6867030b45db250c7619233c6056b46a980667 | https://github.com/anthonynsimon/bild/blob/3a6867030b45db250c7619233c6056b46a980667/histogram/histogram.go#L39-L50 |
153,317 | anthonynsimon/bild | histogram/histogram.go | Cumulative | func (h *Histogram) Cumulative() *Histogram {
binCount := len(h.Bins)
out := Histogram{make([]int, binCount)}
if binCount > 0 {
out.Bins[0] = h.Bins[0]
}
for i := 1; i < binCount; i++ {
out.Bins[i] = out.Bins[i-1] + h.Bins[i]
}
return &out
} | go | func (h *Histogram) Cumulative() *Histogram {
binCount := len(h.Bins)
out := Histogram{make([]int, binCount)}
if binCount > 0 {
out.Bins[0] = h.Bins[0]
}
for i := 1; i < binCount; i++ {
out.Bins[i] = out.Bins[i-1] + h.Bins[i]
}
return &out
} | [
"func",
"(",
"h",
"*",
"Histogram",
")",
"Cumulative",
"(",
")",
"*",
"Histogram",
"{",
"binCount",
":=",
"len",
"(",
"h",
".",
"Bins",
")",
"\n",
"out",
":=",
"Histogram",
"{",
"make",
"(",
"[",
"]",
"int",
",",
"binCount",
")",
"}",
"\n\n",
"if",
"binCount",
">",
"0",
"{",
"out",
".",
"Bins",
"[",
"0",
"]",
"=",
"h",
".",
"Bins",
"[",
"0",
"]",
"\n",
"}",
"\n\n",
"for",
"i",
":=",
"1",
";",
"i",
"<",
"binCount",
";",
"i",
"++",
"{",
"out",
".",
"Bins",
"[",
"i",
"]",
"=",
"out",
".",
"Bins",
"[",
"i",
"-",
"1",
"]",
"+",
"h",
".",
"Bins",
"[",
"i",
"]",
"\n",
"}",
"\n\n",
"return",
"&",
"out",
"\n",
"}"
] | // Cumulative returns a new Histogram in which each bin is the cumulative
// value of its previous bins | [
"Cumulative",
"returns",
"a",
"new",
"Histogram",
"in",
"which",
"each",
"bin",
"is",
"the",
"cumulative",
"value",
"of",
"its",
"previous",
"bins"
] | 3a6867030b45db250c7619233c6056b46a980667 | https://github.com/anthonynsimon/bild/blob/3a6867030b45db250c7619233c6056b46a980667/histogram/histogram.go#L54-L67 |
153,318 | anthonynsimon/bild | histogram/histogram.go | Image | func (h *Histogram) Image() *image.Gray {
dstW, dstH := len(h.Bins), len(h.Bins)
dst := image.NewGray(image.Rect(0, 0, dstW, dstH))
max := h.Max()
if max == 0 {
max = 1
}
for x := 0; x < dstW; x++ {
value := ((h.Bins[x] << 16 / max) * dstH) >> 16
// Fill from the bottom up
for y := dstH - 1; y > dstH-value-1; y-- {
dst.Pix[y*dst.Stride+x] = 0xFF
}
}
return dst
} | go | func (h *Histogram) Image() *image.Gray {
dstW, dstH := len(h.Bins), len(h.Bins)
dst := image.NewGray(image.Rect(0, 0, dstW, dstH))
max := h.Max()
if max == 0 {
max = 1
}
for x := 0; x < dstW; x++ {
value := ((h.Bins[x] << 16 / max) * dstH) >> 16
// Fill from the bottom up
for y := dstH - 1; y > dstH-value-1; y-- {
dst.Pix[y*dst.Stride+x] = 0xFF
}
}
return dst
} | [
"func",
"(",
"h",
"*",
"Histogram",
")",
"Image",
"(",
")",
"*",
"image",
".",
"Gray",
"{",
"dstW",
",",
"dstH",
":=",
"len",
"(",
"h",
".",
"Bins",
")",
",",
"len",
"(",
"h",
".",
"Bins",
")",
"\n",
"dst",
":=",
"image",
".",
"NewGray",
"(",
"image",
".",
"Rect",
"(",
"0",
",",
"0",
",",
"dstW",
",",
"dstH",
")",
")",
"\n\n",
"max",
":=",
"h",
".",
"Max",
"(",
")",
"\n",
"if",
"max",
"==",
"0",
"{",
"max",
"=",
"1",
"\n",
"}",
"\n\n",
"for",
"x",
":=",
"0",
";",
"x",
"<",
"dstW",
";",
"x",
"++",
"{",
"value",
":=",
"(",
"(",
"h",
".",
"Bins",
"[",
"x",
"]",
"<<",
"16",
"/",
"max",
")",
"*",
"dstH",
")",
">>",
"16",
"\n",
"// Fill from the bottom up",
"for",
"y",
":=",
"dstH",
"-",
"1",
";",
"y",
">",
"dstH",
"-",
"value",
"-",
"1",
";",
"y",
"--",
"{",
"dst",
".",
"Pix",
"[",
"y",
"*",
"dst",
".",
"Stride",
"+",
"x",
"]",
"=",
"0xFF",
"\n",
"}",
"\n",
"}",
"\n",
"return",
"dst",
"\n",
"}"
] | // Image returns a grayscale image representation of the Histogram.
// The width and height of the image will be equivalent to the number of Bins in the Histogram. | [
"Image",
"returns",
"a",
"grayscale",
"image",
"representation",
"of",
"the",
"Histogram",
".",
"The",
"width",
"and",
"height",
"of",
"the",
"image",
"will",
"be",
"equivalent",
"to",
"the",
"number",
"of",
"Bins",
"in",
"the",
"Histogram",
"."
] | 3a6867030b45db250c7619233c6056b46a980667 | https://github.com/anthonynsimon/bild/blob/3a6867030b45db250c7619233c6056b46a980667/histogram/histogram.go#L71-L88 |
153,319 | anthonynsimon/bild | histogram/histogram.go | NewRGBAHistogram | func NewRGBAHistogram(img image.Image) *RGBAHistogram {
src := clone.AsRGBA(img)
binCount := 256
r := Histogram{make([]int, binCount)}
g := Histogram{make([]int, binCount)}
b := Histogram{make([]int, binCount)}
a := Histogram{make([]int, binCount)}
for y := 0; y < src.Bounds().Dy(); y++ {
for x := 0; x < src.Bounds().Dx(); x++ {
pos := y*src.Stride + x*4
r.Bins[src.Pix[pos+0]]++
g.Bins[src.Pix[pos+1]]++
b.Bins[src.Pix[pos+2]]++
a.Bins[src.Pix[pos+3]]++
}
}
return &RGBAHistogram{R: r, G: g, B: b, A: a}
} | go | func NewRGBAHistogram(img image.Image) *RGBAHistogram {
src := clone.AsRGBA(img)
binCount := 256
r := Histogram{make([]int, binCount)}
g := Histogram{make([]int, binCount)}
b := Histogram{make([]int, binCount)}
a := Histogram{make([]int, binCount)}
for y := 0; y < src.Bounds().Dy(); y++ {
for x := 0; x < src.Bounds().Dx(); x++ {
pos := y*src.Stride + x*4
r.Bins[src.Pix[pos+0]]++
g.Bins[src.Pix[pos+1]]++
b.Bins[src.Pix[pos+2]]++
a.Bins[src.Pix[pos+3]]++
}
}
return &RGBAHistogram{R: r, G: g, B: b, A: a}
} | [
"func",
"NewRGBAHistogram",
"(",
"img",
"image",
".",
"Image",
")",
"*",
"RGBAHistogram",
"{",
"src",
":=",
"clone",
".",
"AsRGBA",
"(",
"img",
")",
"\n\n",
"binCount",
":=",
"256",
"\n",
"r",
":=",
"Histogram",
"{",
"make",
"(",
"[",
"]",
"int",
",",
"binCount",
")",
"}",
"\n",
"g",
":=",
"Histogram",
"{",
"make",
"(",
"[",
"]",
"int",
",",
"binCount",
")",
"}",
"\n",
"b",
":=",
"Histogram",
"{",
"make",
"(",
"[",
"]",
"int",
",",
"binCount",
")",
"}",
"\n",
"a",
":=",
"Histogram",
"{",
"make",
"(",
"[",
"]",
"int",
",",
"binCount",
")",
"}",
"\n\n",
"for",
"y",
":=",
"0",
";",
"y",
"<",
"src",
".",
"Bounds",
"(",
")",
".",
"Dy",
"(",
")",
";",
"y",
"++",
"{",
"for",
"x",
":=",
"0",
";",
"x",
"<",
"src",
".",
"Bounds",
"(",
")",
".",
"Dx",
"(",
")",
";",
"x",
"++",
"{",
"pos",
":=",
"y",
"*",
"src",
".",
"Stride",
"+",
"x",
"*",
"4",
"\n",
"r",
".",
"Bins",
"[",
"src",
".",
"Pix",
"[",
"pos",
"+",
"0",
"]",
"]",
"++",
"\n",
"g",
".",
"Bins",
"[",
"src",
".",
"Pix",
"[",
"pos",
"+",
"1",
"]",
"]",
"++",
"\n",
"b",
".",
"Bins",
"[",
"src",
".",
"Pix",
"[",
"pos",
"+",
"2",
"]",
"]",
"++",
"\n",
"a",
".",
"Bins",
"[",
"src",
".",
"Pix",
"[",
"pos",
"+",
"3",
"]",
"]",
"++",
"\n",
"}",
"\n",
"}",
"\n\n",
"return",
"&",
"RGBAHistogram",
"{",
"R",
":",
"r",
",",
"G",
":",
"g",
",",
"B",
":",
"b",
",",
"A",
":",
"a",
"}",
"\n",
"}"
] | // NewRGBAHistogram constructs a RGBAHistogram out of the provided image.
// A sub-histogram is created per RGBA channel with 256 bins each. | [
"NewRGBAHistogram",
"constructs",
"a",
"RGBAHistogram",
"out",
"of",
"the",
"provided",
"image",
".",
"A",
"sub",
"-",
"histogram",
"is",
"created",
"per",
"RGBA",
"channel",
"with",
"256",
"bins",
"each",
"."
] | 3a6867030b45db250c7619233c6056b46a980667 | https://github.com/anthonynsimon/bild/blob/3a6867030b45db250c7619233c6056b46a980667/histogram/histogram.go#L92-L112 |
153,320 | anthonynsimon/bild | histogram/histogram.go | Cumulative | func (h *RGBAHistogram) Cumulative() *RGBAHistogram {
binCount := len(h.R.Bins)
r := Histogram{make([]int, binCount)}
g := Histogram{make([]int, binCount)}
b := Histogram{make([]int, binCount)}
a := Histogram{make([]int, binCount)}
out := RGBAHistogram{R: r, G: g, B: b, A: a}
if binCount > 0 {
out.R.Bins[0] = h.R.Bins[0]
out.G.Bins[0] = h.G.Bins[0]
out.B.Bins[0] = h.B.Bins[0]
out.A.Bins[0] = h.A.Bins[0]
}
for i := 1; i < binCount; i++ {
out.R.Bins[i] = out.R.Bins[i-1] + h.R.Bins[i]
out.G.Bins[i] = out.G.Bins[i-1] + h.G.Bins[i]
out.B.Bins[i] = out.B.Bins[i-1] + h.B.Bins[i]
out.A.Bins[i] = out.A.Bins[i-1] + h.A.Bins[i]
}
return &out
} | go | func (h *RGBAHistogram) Cumulative() *RGBAHistogram {
binCount := len(h.R.Bins)
r := Histogram{make([]int, binCount)}
g := Histogram{make([]int, binCount)}
b := Histogram{make([]int, binCount)}
a := Histogram{make([]int, binCount)}
out := RGBAHistogram{R: r, G: g, B: b, A: a}
if binCount > 0 {
out.R.Bins[0] = h.R.Bins[0]
out.G.Bins[0] = h.G.Bins[0]
out.B.Bins[0] = h.B.Bins[0]
out.A.Bins[0] = h.A.Bins[0]
}
for i := 1; i < binCount; i++ {
out.R.Bins[i] = out.R.Bins[i-1] + h.R.Bins[i]
out.G.Bins[i] = out.G.Bins[i-1] + h.G.Bins[i]
out.B.Bins[i] = out.B.Bins[i-1] + h.B.Bins[i]
out.A.Bins[i] = out.A.Bins[i-1] + h.A.Bins[i]
}
return &out
} | [
"func",
"(",
"h",
"*",
"RGBAHistogram",
")",
"Cumulative",
"(",
")",
"*",
"RGBAHistogram",
"{",
"binCount",
":=",
"len",
"(",
"h",
".",
"R",
".",
"Bins",
")",
"\n\n",
"r",
":=",
"Histogram",
"{",
"make",
"(",
"[",
"]",
"int",
",",
"binCount",
")",
"}",
"\n",
"g",
":=",
"Histogram",
"{",
"make",
"(",
"[",
"]",
"int",
",",
"binCount",
")",
"}",
"\n",
"b",
":=",
"Histogram",
"{",
"make",
"(",
"[",
"]",
"int",
",",
"binCount",
")",
"}",
"\n",
"a",
":=",
"Histogram",
"{",
"make",
"(",
"[",
"]",
"int",
",",
"binCount",
")",
"}",
"\n\n",
"out",
":=",
"RGBAHistogram",
"{",
"R",
":",
"r",
",",
"G",
":",
"g",
",",
"B",
":",
"b",
",",
"A",
":",
"a",
"}",
"\n\n",
"if",
"binCount",
">",
"0",
"{",
"out",
".",
"R",
".",
"Bins",
"[",
"0",
"]",
"=",
"h",
".",
"R",
".",
"Bins",
"[",
"0",
"]",
"\n",
"out",
".",
"G",
".",
"Bins",
"[",
"0",
"]",
"=",
"h",
".",
"G",
".",
"Bins",
"[",
"0",
"]",
"\n",
"out",
".",
"B",
".",
"Bins",
"[",
"0",
"]",
"=",
"h",
".",
"B",
".",
"Bins",
"[",
"0",
"]",
"\n",
"out",
".",
"A",
".",
"Bins",
"[",
"0",
"]",
"=",
"h",
".",
"A",
".",
"Bins",
"[",
"0",
"]",
"\n",
"}",
"\n\n",
"for",
"i",
":=",
"1",
";",
"i",
"<",
"binCount",
";",
"i",
"++",
"{",
"out",
".",
"R",
".",
"Bins",
"[",
"i",
"]",
"=",
"out",
".",
"R",
".",
"Bins",
"[",
"i",
"-",
"1",
"]",
"+",
"h",
".",
"R",
".",
"Bins",
"[",
"i",
"]",
"\n",
"out",
".",
"G",
".",
"Bins",
"[",
"i",
"]",
"=",
"out",
".",
"G",
".",
"Bins",
"[",
"i",
"-",
"1",
"]",
"+",
"h",
".",
"G",
".",
"Bins",
"[",
"i",
"]",
"\n",
"out",
".",
"B",
".",
"Bins",
"[",
"i",
"]",
"=",
"out",
".",
"B",
".",
"Bins",
"[",
"i",
"-",
"1",
"]",
"+",
"h",
".",
"B",
".",
"Bins",
"[",
"i",
"]",
"\n",
"out",
".",
"A",
".",
"Bins",
"[",
"i",
"]",
"=",
"out",
".",
"A",
".",
"Bins",
"[",
"i",
"-",
"1",
"]",
"+",
"h",
".",
"A",
".",
"Bins",
"[",
"i",
"]",
"\n",
"}",
"\n\n",
"return",
"&",
"out",
"\n",
"}"
] | // Cumulative returns a new RGBAHistogram in which each bin is the cumulative
// value of its previous bins per channel. | [
"Cumulative",
"returns",
"a",
"new",
"RGBAHistogram",
"in",
"which",
"each",
"bin",
"is",
"the",
"cumulative",
"value",
"of",
"its",
"previous",
"bins",
"per",
"channel",
"."
] | 3a6867030b45db250c7619233c6056b46a980667 | https://github.com/anthonynsimon/bild/blob/3a6867030b45db250c7619233c6056b46a980667/histogram/histogram.go#L116-L141 |
153,321 | anthonynsimon/bild | histogram/histogram.go | Image | func (h *RGBAHistogram) Image() *image.RGBA {
if len(h.R.Bins) != 256 || len(h.G.Bins) != 256 ||
len(h.B.Bins) != 256 || len(h.A.Bins) != 256 {
panic("RGBAHistogram bins length not equal to 256")
}
dstW, dstH := 256, 256
dst := image.NewRGBA(image.Rect(0, 0, dstW, dstH))
maxR := h.R.Max()
if maxR == 0 {
maxR = 1
}
maxG := h.G.Max()
if maxG == 0 {
maxG = 1
}
maxB := h.B.Max()
if maxB == 0 {
maxB = 1
}
for x := 0; x < dstW; x++ {
binHeightR := ((h.R.Bins[x] << 16 / maxR) * dstH) >> 16
binHeightG := ((h.G.Bins[x] << 16 / maxG) * dstH) >> 16
binHeightB := ((h.B.Bins[x] << 16 / maxB) * dstH) >> 16
// Fill from the bottom up
for y := dstH - 1; y >= 0; y-- {
pos := y*dst.Stride + x*4
iy := dstH - 1 - y
if iy < binHeightR {
dst.Pix[pos+0] = 0xFF
}
if iy < binHeightG {
dst.Pix[pos+1] = 0xFF
}
if iy < binHeightB {
dst.Pix[pos+2] = 0xFF
}
dst.Pix[pos+3] = 0xFF
}
}
return dst
} | go | func (h *RGBAHistogram) Image() *image.RGBA {
if len(h.R.Bins) != 256 || len(h.G.Bins) != 256 ||
len(h.B.Bins) != 256 || len(h.A.Bins) != 256 {
panic("RGBAHistogram bins length not equal to 256")
}
dstW, dstH := 256, 256
dst := image.NewRGBA(image.Rect(0, 0, dstW, dstH))
maxR := h.R.Max()
if maxR == 0 {
maxR = 1
}
maxG := h.G.Max()
if maxG == 0 {
maxG = 1
}
maxB := h.B.Max()
if maxB == 0 {
maxB = 1
}
for x := 0; x < dstW; x++ {
binHeightR := ((h.R.Bins[x] << 16 / maxR) * dstH) >> 16
binHeightG := ((h.G.Bins[x] << 16 / maxG) * dstH) >> 16
binHeightB := ((h.B.Bins[x] << 16 / maxB) * dstH) >> 16
// Fill from the bottom up
for y := dstH - 1; y >= 0; y-- {
pos := y*dst.Stride + x*4
iy := dstH - 1 - y
if iy < binHeightR {
dst.Pix[pos+0] = 0xFF
}
if iy < binHeightG {
dst.Pix[pos+1] = 0xFF
}
if iy < binHeightB {
dst.Pix[pos+2] = 0xFF
}
dst.Pix[pos+3] = 0xFF
}
}
return dst
} | [
"func",
"(",
"h",
"*",
"RGBAHistogram",
")",
"Image",
"(",
")",
"*",
"image",
".",
"RGBA",
"{",
"if",
"len",
"(",
"h",
".",
"R",
".",
"Bins",
")",
"!=",
"256",
"||",
"len",
"(",
"h",
".",
"G",
".",
"Bins",
")",
"!=",
"256",
"||",
"len",
"(",
"h",
".",
"B",
".",
"Bins",
")",
"!=",
"256",
"||",
"len",
"(",
"h",
".",
"A",
".",
"Bins",
")",
"!=",
"256",
"{",
"panic",
"(",
"\"",
"\"",
")",
"\n",
"}",
"\n\n",
"dstW",
",",
"dstH",
":=",
"256",
",",
"256",
"\n",
"dst",
":=",
"image",
".",
"NewRGBA",
"(",
"image",
".",
"Rect",
"(",
"0",
",",
"0",
",",
"dstW",
",",
"dstH",
")",
")",
"\n\n",
"maxR",
":=",
"h",
".",
"R",
".",
"Max",
"(",
")",
"\n",
"if",
"maxR",
"==",
"0",
"{",
"maxR",
"=",
"1",
"\n",
"}",
"\n",
"maxG",
":=",
"h",
".",
"G",
".",
"Max",
"(",
")",
"\n",
"if",
"maxG",
"==",
"0",
"{",
"maxG",
"=",
"1",
"\n",
"}",
"\n",
"maxB",
":=",
"h",
".",
"B",
".",
"Max",
"(",
")",
"\n",
"if",
"maxB",
"==",
"0",
"{",
"maxB",
"=",
"1",
"\n",
"}",
"\n\n",
"for",
"x",
":=",
"0",
";",
"x",
"<",
"dstW",
";",
"x",
"++",
"{",
"binHeightR",
":=",
"(",
"(",
"h",
".",
"R",
".",
"Bins",
"[",
"x",
"]",
"<<",
"16",
"/",
"maxR",
")",
"*",
"dstH",
")",
">>",
"16",
"\n",
"binHeightG",
":=",
"(",
"(",
"h",
".",
"G",
".",
"Bins",
"[",
"x",
"]",
"<<",
"16",
"/",
"maxG",
")",
"*",
"dstH",
")",
">>",
"16",
"\n",
"binHeightB",
":=",
"(",
"(",
"h",
".",
"B",
".",
"Bins",
"[",
"x",
"]",
"<<",
"16",
"/",
"maxB",
")",
"*",
"dstH",
")",
">>",
"16",
"\n",
"// Fill from the bottom up",
"for",
"y",
":=",
"dstH",
"-",
"1",
";",
"y",
">=",
"0",
";",
"y",
"--",
"{",
"pos",
":=",
"y",
"*",
"dst",
".",
"Stride",
"+",
"x",
"*",
"4",
"\n",
"iy",
":=",
"dstH",
"-",
"1",
"-",
"y",
"\n\n",
"if",
"iy",
"<",
"binHeightR",
"{",
"dst",
".",
"Pix",
"[",
"pos",
"+",
"0",
"]",
"=",
"0xFF",
"\n",
"}",
"\n",
"if",
"iy",
"<",
"binHeightG",
"{",
"dst",
".",
"Pix",
"[",
"pos",
"+",
"1",
"]",
"=",
"0xFF",
"\n",
"}",
"\n",
"if",
"iy",
"<",
"binHeightB",
"{",
"dst",
".",
"Pix",
"[",
"pos",
"+",
"2",
"]",
"=",
"0xFF",
"\n",
"}",
"\n",
"dst",
".",
"Pix",
"[",
"pos",
"+",
"3",
"]",
"=",
"0xFF",
"\n",
"}",
"\n",
"}",
"\n\n",
"return",
"dst",
"\n",
"}"
] | // Image returns an RGBA image representation of the RGBAHistogram.
// An image width of 256 represents the 256 Bins per channel and the
// image height of 256 represents the max normalized histogram value per channel.
// Each RGB channel from the histogram is mapped to its corresponding channel in the image,
// so that for example if the red channel is extracted from the image, it corresponds to the
// red channel histogram. | [
"Image",
"returns",
"an",
"RGBA",
"image",
"representation",
"of",
"the",
"RGBAHistogram",
".",
"An",
"image",
"width",
"of",
"256",
"represents",
"the",
"256",
"Bins",
"per",
"channel",
"and",
"the",
"image",
"height",
"of",
"256",
"represents",
"the",
"max",
"normalized",
"histogram",
"value",
"per",
"channel",
".",
"Each",
"RGB",
"channel",
"from",
"the",
"histogram",
"is",
"mapped",
"to",
"its",
"corresponding",
"channel",
"in",
"the",
"image",
"so",
"that",
"for",
"example",
"if",
"the",
"red",
"channel",
"is",
"extracted",
"from",
"the",
"image",
"it",
"corresponds",
"to",
"the",
"red",
"channel",
"histogram",
"."
] | 3a6867030b45db250c7619233c6056b46a980667 | https://github.com/anthonynsimon/bild/blob/3a6867030b45db250c7619233c6056b46a980667/histogram/histogram.go#L149-L194 |
153,322 | anthonynsimon/bild | convolution/kernel.go | NewKernel | func NewKernel(width, height int) *Kernel {
return &Kernel{make([]float64, width*height), width, height}
} | go | func NewKernel(width, height int) *Kernel {
return &Kernel{make([]float64, width*height), width, height}
} | [
"func",
"NewKernel",
"(",
"width",
",",
"height",
"int",
")",
"*",
"Kernel",
"{",
"return",
"&",
"Kernel",
"{",
"make",
"(",
"[",
"]",
"float64",
",",
"width",
"*",
"height",
")",
",",
"width",
",",
"height",
"}",
"\n",
"}"
] | // NewKernel returns a kernel of the provided length. | [
"NewKernel",
"returns",
"a",
"kernel",
"of",
"the",
"provided",
"length",
"."
] | 3a6867030b45db250c7619233c6056b46a980667 | https://github.com/anthonynsimon/bild/blob/3a6867030b45db250c7619233c6056b46a980667/convolution/kernel.go#L21-L23 |
153,323 | anthonynsimon/bild | convolution/kernel.go | Normalized | func (k *Kernel) Normalized() Matrix {
sum := k.Absum()
w := k.Width
h := k.Height
nk := NewKernel(w, h)
// avoid division by 0
if sum == 0 {
sum = 1
}
for i := 0; i < w*h; i++ {
nk.Matrix[i] = k.Matrix[i] / sum
}
return nk
} | go | func (k *Kernel) Normalized() Matrix {
sum := k.Absum()
w := k.Width
h := k.Height
nk := NewKernel(w, h)
// avoid division by 0
if sum == 0 {
sum = 1
}
for i := 0; i < w*h; i++ {
nk.Matrix[i] = k.Matrix[i] / sum
}
return nk
} | [
"func",
"(",
"k",
"*",
"Kernel",
")",
"Normalized",
"(",
")",
"Matrix",
"{",
"sum",
":=",
"k",
".",
"Absum",
"(",
")",
"\n",
"w",
":=",
"k",
".",
"Width",
"\n",
"h",
":=",
"k",
".",
"Height",
"\n",
"nk",
":=",
"NewKernel",
"(",
"w",
",",
"h",
")",
"\n\n",
"// avoid division by 0",
"if",
"sum",
"==",
"0",
"{",
"sum",
"=",
"1",
"\n",
"}",
"\n\n",
"for",
"i",
":=",
"0",
";",
"i",
"<",
"w",
"*",
"h",
";",
"i",
"++",
"{",
"nk",
".",
"Matrix",
"[",
"i",
"]",
"=",
"k",
".",
"Matrix",
"[",
"i",
"]",
"/",
"sum",
"\n",
"}",
"\n\n",
"return",
"nk",
"\n",
"}"
] | // Normalized returns a new Kernel with normalized values. | [
"Normalized",
"returns",
"a",
"new",
"Kernel",
"with",
"normalized",
"values",
"."
] | 3a6867030b45db250c7619233c6056b46a980667 | https://github.com/anthonynsimon/bild/blob/3a6867030b45db250c7619233c6056b46a980667/convolution/kernel.go#L33-L49 |
153,324 | anthonynsimon/bild | convolution/kernel.go | At | func (k *Kernel) At(x, y int) float64 {
return k.Matrix[y*k.Width+x]
} | go | func (k *Kernel) At(x, y int) float64 {
return k.Matrix[y*k.Width+x]
} | [
"func",
"(",
"k",
"*",
"Kernel",
")",
"At",
"(",
"x",
",",
"y",
"int",
")",
"float64",
"{",
"return",
"k",
".",
"Matrix",
"[",
"y",
"*",
"k",
".",
"Width",
"+",
"x",
"]",
"\n",
"}"
] | // At returns the matrix value at position x, y. | [
"At",
"returns",
"the",
"matrix",
"value",
"at",
"position",
"x",
"y",
"."
] | 3a6867030b45db250c7619233c6056b46a980667 | https://github.com/anthonynsimon/bild/blob/3a6867030b45db250c7619233c6056b46a980667/convolution/kernel.go#L62-L64 |
153,325 | anthonynsimon/bild | convolution/kernel.go | String | func (k *Kernel) String() string {
result := ""
stride := k.MaxX()
height := k.MaxY()
for y := 0; y < height; y++ {
result += fmt.Sprintf("\n")
for x := 0; x < stride; x++ {
result += fmt.Sprintf("%-8.4f", k.At(x, y))
}
}
return result
} | go | func (k *Kernel) String() string {
result := ""
stride := k.MaxX()
height := k.MaxY()
for y := 0; y < height; y++ {
result += fmt.Sprintf("\n")
for x := 0; x < stride; x++ {
result += fmt.Sprintf("%-8.4f", k.At(x, y))
}
}
return result
} | [
"func",
"(",
"k",
"*",
"Kernel",
")",
"String",
"(",
")",
"string",
"{",
"result",
":=",
"\"",
"\"",
"\n",
"stride",
":=",
"k",
".",
"MaxX",
"(",
")",
"\n",
"height",
":=",
"k",
".",
"MaxY",
"(",
")",
"\n",
"for",
"y",
":=",
"0",
";",
"y",
"<",
"height",
";",
"y",
"++",
"{",
"result",
"+=",
"fmt",
".",
"Sprintf",
"(",
"\"",
"\\n",
"\"",
")",
"\n",
"for",
"x",
":=",
"0",
";",
"x",
"<",
"stride",
";",
"x",
"++",
"{",
"result",
"+=",
"fmt",
".",
"Sprintf",
"(",
"\"",
"\"",
",",
"k",
".",
"At",
"(",
"x",
",",
"y",
")",
")",
"\n",
"}",
"\n",
"}",
"\n",
"return",
"result",
"\n",
"}"
] | // String returns the string representation of the matrix. | [
"String",
"returns",
"the",
"string",
"representation",
"of",
"the",
"matrix",
"."
] | 3a6867030b45db250c7619233c6056b46a980667 | https://github.com/anthonynsimon/bild/blob/3a6867030b45db250c7619233c6056b46a980667/convolution/kernel.go#L67-L78 |
153,326 | anthonynsimon/bild | convolution/kernel.go | Absum | func (k *Kernel) Absum() float64 {
var sum float64
for _, v := range k.Matrix {
sum += math.Abs(v)
}
return sum
} | go | func (k *Kernel) Absum() float64 {
var sum float64
for _, v := range k.Matrix {
sum += math.Abs(v)
}
return sum
} | [
"func",
"(",
"k",
"*",
"Kernel",
")",
"Absum",
"(",
")",
"float64",
"{",
"var",
"sum",
"float64",
"\n",
"for",
"_",
",",
"v",
":=",
"range",
"k",
".",
"Matrix",
"{",
"sum",
"+=",
"math",
".",
"Abs",
"(",
"v",
")",
"\n",
"}",
"\n",
"return",
"sum",
"\n",
"}"
] | // Absum returns the absolute cumulative value of the kernel. | [
"Absum",
"returns",
"the",
"absolute",
"cumulative",
"value",
"of",
"the",
"kernel",
"."
] | 3a6867030b45db250c7619233c6056b46a980667 | https://github.com/anthonynsimon/bild/blob/3a6867030b45db250c7619233c6056b46a980667/convolution/kernel.go#L81-L87 |
153,327 | anthonynsimon/bild | effect/effect.go | Invert | func Invert(src image.Image) *image.RGBA {
fn := func(c color.RGBA) color.RGBA {
return color.RGBA{255 - c.R, 255 - c.G, 255 - c.B, c.A}
}
img := adjust.Apply(src, fn)
return img
} | go | func Invert(src image.Image) *image.RGBA {
fn := func(c color.RGBA) color.RGBA {
return color.RGBA{255 - c.R, 255 - c.G, 255 - c.B, c.A}
}
img := adjust.Apply(src, fn)
return img
} | [
"func",
"Invert",
"(",
"src",
"image",
".",
"Image",
")",
"*",
"image",
".",
"RGBA",
"{",
"fn",
":=",
"func",
"(",
"c",
"color",
".",
"RGBA",
")",
"color",
".",
"RGBA",
"{",
"return",
"color",
".",
"RGBA",
"{",
"255",
"-",
"c",
".",
"R",
",",
"255",
"-",
"c",
".",
"G",
",",
"255",
"-",
"c",
".",
"B",
",",
"c",
".",
"A",
"}",
"\n",
"}",
"\n\n",
"img",
":=",
"adjust",
".",
"Apply",
"(",
"src",
",",
"fn",
")",
"\n\n",
"return",
"img",
"\n",
"}"
] | // Invert returns a negated version of the image. | [
"Invert",
"returns",
"a",
"negated",
"version",
"of",
"the",
"image",
"."
] | 3a6867030b45db250c7619233c6056b46a980667 | https://github.com/anthonynsimon/bild/blob/3a6867030b45db250c7619233c6056b46a980667/effect/effect.go#L20-L28 |
153,328 | anthonynsimon/bild | effect/effect.go | Grayscale | func Grayscale(img image.Image) *image.Gray {
src := clone.AsRGBA(img)
bounds := src.Bounds()
srcW, srcH := bounds.Dx(), bounds.Dy()
if bounds.Empty() {
return &image.Gray{}
}
dst := image.NewGray(bounds)
parallel.Line(srcH, func(start, end int) {
for y := start; y < end; y++ {
for x := 0; x < srcW; x++ {
srcPos := y*src.Stride + x*4
dstPos := y*dst.Stride + x
c := 0.3*float64(src.Pix[srcPos+0]) + 0.6*float64(src.Pix[srcPos+1]) + 0.1*float64(src.Pix[srcPos+2])
dst.Pix[dstPos] = uint8(c + 0.5)
}
}
})
return dst
} | go | func Grayscale(img image.Image) *image.Gray {
src := clone.AsRGBA(img)
bounds := src.Bounds()
srcW, srcH := bounds.Dx(), bounds.Dy()
if bounds.Empty() {
return &image.Gray{}
}
dst := image.NewGray(bounds)
parallel.Line(srcH, func(start, end int) {
for y := start; y < end; y++ {
for x := 0; x < srcW; x++ {
srcPos := y*src.Stride + x*4
dstPos := y*dst.Stride + x
c := 0.3*float64(src.Pix[srcPos+0]) + 0.6*float64(src.Pix[srcPos+1]) + 0.1*float64(src.Pix[srcPos+2])
dst.Pix[dstPos] = uint8(c + 0.5)
}
}
})
return dst
} | [
"func",
"Grayscale",
"(",
"img",
"image",
".",
"Image",
")",
"*",
"image",
".",
"Gray",
"{",
"src",
":=",
"clone",
".",
"AsRGBA",
"(",
"img",
")",
"\n",
"bounds",
":=",
"src",
".",
"Bounds",
"(",
")",
"\n",
"srcW",
",",
"srcH",
":=",
"bounds",
".",
"Dx",
"(",
")",
",",
"bounds",
".",
"Dy",
"(",
")",
"\n\n",
"if",
"bounds",
".",
"Empty",
"(",
")",
"{",
"return",
"&",
"image",
".",
"Gray",
"{",
"}",
"\n",
"}",
"\n\n",
"dst",
":=",
"image",
".",
"NewGray",
"(",
"bounds",
")",
"\n\n",
"parallel",
".",
"Line",
"(",
"srcH",
",",
"func",
"(",
"start",
",",
"end",
"int",
")",
"{",
"for",
"y",
":=",
"start",
";",
"y",
"<",
"end",
";",
"y",
"++",
"{",
"for",
"x",
":=",
"0",
";",
"x",
"<",
"srcW",
";",
"x",
"++",
"{",
"srcPos",
":=",
"y",
"*",
"src",
".",
"Stride",
"+",
"x",
"*",
"4",
"\n",
"dstPos",
":=",
"y",
"*",
"dst",
".",
"Stride",
"+",
"x",
"\n\n",
"c",
":=",
"0.3",
"*",
"float64",
"(",
"src",
".",
"Pix",
"[",
"srcPos",
"+",
"0",
"]",
")",
"+",
"0.6",
"*",
"float64",
"(",
"src",
".",
"Pix",
"[",
"srcPos",
"+",
"1",
"]",
")",
"+",
"0.1",
"*",
"float64",
"(",
"src",
".",
"Pix",
"[",
"srcPos",
"+",
"2",
"]",
")",
"\n",
"dst",
".",
"Pix",
"[",
"dstPos",
"]",
"=",
"uint8",
"(",
"c",
"+",
"0.5",
")",
"\n",
"}",
"\n",
"}",
"\n",
"}",
")",
"\n\n",
"return",
"dst",
"\n",
"}"
] | // Grayscale returns a copy of the image in Grayscale using the weights
// 0.3R + 0.6G + 0.1B as a heuristic. | [
"Grayscale",
"returns",
"a",
"copy",
"of",
"the",
"image",
"in",
"Grayscale",
"using",
"the",
"weights",
"0",
".",
"3R",
"+",
"0",
".",
"6G",
"+",
"0",
".",
"1B",
"as",
"a",
"heuristic",
"."
] | 3a6867030b45db250c7619233c6056b46a980667 | https://github.com/anthonynsimon/bild/blob/3a6867030b45db250c7619233c6056b46a980667/effect/effect.go#L32-L56 |
153,329 | anthonynsimon/bild | effect/effect.go | Sepia | func Sepia(img image.Image) *image.RGBA {
fn := func(c color.RGBA) color.RGBA {
// Cache values as float64
var fc [3]float64
fc[0] = float64(c.R)
fc[1] = float64(c.G)
fc[2] = float64(c.B)
// Calculate out color based on heuristic
outRed := fc[0]*0.393 + fc[1]*0.769 + fc[2]*0.189
outGreen := fc[0]*0.349 + fc[1]*0.686 + fc[2]*0.168
outBlue := fc[0]*0.272 + fc[1]*0.534 + fc[2]*0.131
// Clamp ceiled values before returning
return color.RGBA{
R: uint8(f64.Clamp(outRed+0.5, 0, 255)),
G: uint8(f64.Clamp(outGreen+0.5, 0, 255)),
B: uint8(f64.Clamp(outBlue+0.5, 0, 255)),
A: c.A,
}
}
dst := adjust.Apply(img, fn)
return dst
} | go | func Sepia(img image.Image) *image.RGBA {
fn := func(c color.RGBA) color.RGBA {
// Cache values as float64
var fc [3]float64
fc[0] = float64(c.R)
fc[1] = float64(c.G)
fc[2] = float64(c.B)
// Calculate out color based on heuristic
outRed := fc[0]*0.393 + fc[1]*0.769 + fc[2]*0.189
outGreen := fc[0]*0.349 + fc[1]*0.686 + fc[2]*0.168
outBlue := fc[0]*0.272 + fc[1]*0.534 + fc[2]*0.131
// Clamp ceiled values before returning
return color.RGBA{
R: uint8(f64.Clamp(outRed+0.5, 0, 255)),
G: uint8(f64.Clamp(outGreen+0.5, 0, 255)),
B: uint8(f64.Clamp(outBlue+0.5, 0, 255)),
A: c.A,
}
}
dst := adjust.Apply(img, fn)
return dst
} | [
"func",
"Sepia",
"(",
"img",
"image",
".",
"Image",
")",
"*",
"image",
".",
"RGBA",
"{",
"fn",
":=",
"func",
"(",
"c",
"color",
".",
"RGBA",
")",
"color",
".",
"RGBA",
"{",
"// Cache values as float64",
"var",
"fc",
"[",
"3",
"]",
"float64",
"\n",
"fc",
"[",
"0",
"]",
"=",
"float64",
"(",
"c",
".",
"R",
")",
"\n",
"fc",
"[",
"1",
"]",
"=",
"float64",
"(",
"c",
".",
"G",
")",
"\n",
"fc",
"[",
"2",
"]",
"=",
"float64",
"(",
"c",
".",
"B",
")",
"\n\n",
"// Calculate out color based on heuristic",
"outRed",
":=",
"fc",
"[",
"0",
"]",
"*",
"0.393",
"+",
"fc",
"[",
"1",
"]",
"*",
"0.769",
"+",
"fc",
"[",
"2",
"]",
"*",
"0.189",
"\n",
"outGreen",
":=",
"fc",
"[",
"0",
"]",
"*",
"0.349",
"+",
"fc",
"[",
"1",
"]",
"*",
"0.686",
"+",
"fc",
"[",
"2",
"]",
"*",
"0.168",
"\n",
"outBlue",
":=",
"fc",
"[",
"0",
"]",
"*",
"0.272",
"+",
"fc",
"[",
"1",
"]",
"*",
"0.534",
"+",
"fc",
"[",
"2",
"]",
"*",
"0.131",
"\n\n",
"// Clamp ceiled values before returning",
"return",
"color",
".",
"RGBA",
"{",
"R",
":",
"uint8",
"(",
"f64",
".",
"Clamp",
"(",
"outRed",
"+",
"0.5",
",",
"0",
",",
"255",
")",
")",
",",
"G",
":",
"uint8",
"(",
"f64",
".",
"Clamp",
"(",
"outGreen",
"+",
"0.5",
",",
"0",
",",
"255",
")",
")",
",",
"B",
":",
"uint8",
"(",
"f64",
".",
"Clamp",
"(",
"outBlue",
"+",
"0.5",
",",
"0",
",",
"255",
")",
")",
",",
"A",
":",
"c",
".",
"A",
",",
"}",
"\n",
"}",
"\n\n",
"dst",
":=",
"adjust",
".",
"Apply",
"(",
"img",
",",
"fn",
")",
"\n\n",
"return",
"dst",
"\n",
"}"
] | // Sepia returns a copy of the image in Sepia tone. | [
"Sepia",
"returns",
"a",
"copy",
"of",
"the",
"image",
"in",
"Sepia",
"tone",
"."
] | 3a6867030b45db250c7619233c6056b46a980667 | https://github.com/anthonynsimon/bild/blob/3a6867030b45db250c7619233c6056b46a980667/effect/effect.go#L59-L84 |
153,330 | anthonynsimon/bild | effect/effect.go | EdgeDetection | func EdgeDetection(src image.Image, radius float64) *image.RGBA {
if radius <= 0 {
return image.NewRGBA(src.Bounds())
}
length := int(math.Ceil(2*radius + 1))
k := convolution.NewKernel(length, length)
for x := 0; x < length; x++ {
for y := 0; y < length; y++ {
v := -1.0
if x == length/2 && y == length/2 {
v = float64(length*length) - 1
}
k.Matrix[y*length+x] = v
}
}
return convolution.Convolve(src, k, &convolution.Options{Bias: 0, Wrap: false, KeepAlpha: false})
} | go | func EdgeDetection(src image.Image, radius float64) *image.RGBA {
if radius <= 0 {
return image.NewRGBA(src.Bounds())
}
length := int(math.Ceil(2*radius + 1))
k := convolution.NewKernel(length, length)
for x := 0; x < length; x++ {
for y := 0; y < length; y++ {
v := -1.0
if x == length/2 && y == length/2 {
v = float64(length*length) - 1
}
k.Matrix[y*length+x] = v
}
}
return convolution.Convolve(src, k, &convolution.Options{Bias: 0, Wrap: false, KeepAlpha: false})
} | [
"func",
"EdgeDetection",
"(",
"src",
"image",
".",
"Image",
",",
"radius",
"float64",
")",
"*",
"image",
".",
"RGBA",
"{",
"if",
"radius",
"<=",
"0",
"{",
"return",
"image",
".",
"NewRGBA",
"(",
"src",
".",
"Bounds",
"(",
")",
")",
"\n",
"}",
"\n\n",
"length",
":=",
"int",
"(",
"math",
".",
"Ceil",
"(",
"2",
"*",
"radius",
"+",
"1",
")",
")",
"\n",
"k",
":=",
"convolution",
".",
"NewKernel",
"(",
"length",
",",
"length",
")",
"\n\n",
"for",
"x",
":=",
"0",
";",
"x",
"<",
"length",
";",
"x",
"++",
"{",
"for",
"y",
":=",
"0",
";",
"y",
"<",
"length",
";",
"y",
"++",
"{",
"v",
":=",
"-",
"1.0",
"\n",
"if",
"x",
"==",
"length",
"/",
"2",
"&&",
"y",
"==",
"length",
"/",
"2",
"{",
"v",
"=",
"float64",
"(",
"length",
"*",
"length",
")",
"-",
"1",
"\n",
"}",
"\n",
"k",
".",
"Matrix",
"[",
"y",
"*",
"length",
"+",
"x",
"]",
"=",
"v",
"\n\n",
"}",
"\n",
"}",
"\n",
"return",
"convolution",
".",
"Convolve",
"(",
"src",
",",
"k",
",",
"&",
"convolution",
".",
"Options",
"{",
"Bias",
":",
"0",
",",
"Wrap",
":",
"false",
",",
"KeepAlpha",
":",
"false",
"}",
")",
"\n",
"}"
] | // EdgeDetection returns a copy of the image with its edges highlighted. | [
"EdgeDetection",
"returns",
"a",
"copy",
"of",
"the",
"image",
"with",
"its",
"edges",
"highlighted",
"."
] | 3a6867030b45db250c7619233c6056b46a980667 | https://github.com/anthonynsimon/bild/blob/3a6867030b45db250c7619233c6056b46a980667/effect/effect.go#L87-L106 |
153,331 | anthonynsimon/bild | effect/effect.go | Sharpen | func Sharpen(src image.Image) *image.RGBA {
k := convolution.Kernel{
Matrix: []float64{
0, -1, 0,
-1, 5, -1,
0, -1, 0,
},
Width: 3,
Height: 3,
}
return convolution.Convolve(src, &k, &convolution.Options{Bias: 0, Wrap: false})
} | go | func Sharpen(src image.Image) *image.RGBA {
k := convolution.Kernel{
Matrix: []float64{
0, -1, 0,
-1, 5, -1,
0, -1, 0,
},
Width: 3,
Height: 3,
}
return convolution.Convolve(src, &k, &convolution.Options{Bias: 0, Wrap: false})
} | [
"func",
"Sharpen",
"(",
"src",
"image",
".",
"Image",
")",
"*",
"image",
".",
"RGBA",
"{",
"k",
":=",
"convolution",
".",
"Kernel",
"{",
"Matrix",
":",
"[",
"]",
"float64",
"{",
"0",
",",
"-",
"1",
",",
"0",
",",
"-",
"1",
",",
"5",
",",
"-",
"1",
",",
"0",
",",
"-",
"1",
",",
"0",
",",
"}",
",",
"Width",
":",
"3",
",",
"Height",
":",
"3",
",",
"}",
"\n\n",
"return",
"convolution",
".",
"Convolve",
"(",
"src",
",",
"&",
"k",
",",
"&",
"convolution",
".",
"Options",
"{",
"Bias",
":",
"0",
",",
"Wrap",
":",
"false",
"}",
")",
"\n",
"}"
] | // Sharpen returns a sharpened copy of the image by detecting its edges and adding it to the original. | [
"Sharpen",
"returns",
"a",
"sharpened",
"copy",
"of",
"the",
"image",
"by",
"detecting",
"its",
"edges",
"and",
"adding",
"it",
"to",
"the",
"original",
"."
] | 3a6867030b45db250c7619233c6056b46a980667 | https://github.com/anthonynsimon/bild/blob/3a6867030b45db250c7619233c6056b46a980667/effect/effect.go#L125-L137 |
153,332 | anthonynsimon/bild | effect/effect.go | UnsharpMask | func UnsharpMask(img image.Image, radius, amount float64) *image.RGBA {
amount = f64.Clamp(amount, 0, 10)
blurred := blur.Gaussian(img, 5*radius) // scale radius by matching factor
bounds := img.Bounds()
src := clone.AsRGBA(img)
dst := image.NewRGBA(bounds)
w, h := bounds.Dx(), bounds.Dy()
parallel.Line(h, func(start, end int) {
for y := start; y < end; y++ {
for x := 0; x < w; x++ {
pos := y*dst.Stride + x*4
r := float64(src.Pix[pos+0])
g := float64(src.Pix[pos+1])
b := float64(src.Pix[pos+2])
a := float64(src.Pix[pos+3])
rBlur := float64(blurred.Pix[pos+0])
gBlur := float64(blurred.Pix[pos+1])
bBlur := float64(blurred.Pix[pos+2])
aBlur := float64(blurred.Pix[pos+3])
r = r + (r-rBlur)*amount
g = g + (g-gBlur)*amount
b = b + (b-bBlur)*amount
a = a + (a-aBlur)*amount
dst.Pix[pos+0] = uint8(f64.Clamp(r, 0, 255))
dst.Pix[pos+1] = uint8(f64.Clamp(g, 0, 255))
dst.Pix[pos+2] = uint8(f64.Clamp(b, 0, 255))
dst.Pix[pos+3] = uint8(f64.Clamp(a, 0, 255))
}
}
})
return dst
} | go | func UnsharpMask(img image.Image, radius, amount float64) *image.RGBA {
amount = f64.Clamp(amount, 0, 10)
blurred := blur.Gaussian(img, 5*radius) // scale radius by matching factor
bounds := img.Bounds()
src := clone.AsRGBA(img)
dst := image.NewRGBA(bounds)
w, h := bounds.Dx(), bounds.Dy()
parallel.Line(h, func(start, end int) {
for y := start; y < end; y++ {
for x := 0; x < w; x++ {
pos := y*dst.Stride + x*4
r := float64(src.Pix[pos+0])
g := float64(src.Pix[pos+1])
b := float64(src.Pix[pos+2])
a := float64(src.Pix[pos+3])
rBlur := float64(blurred.Pix[pos+0])
gBlur := float64(blurred.Pix[pos+1])
bBlur := float64(blurred.Pix[pos+2])
aBlur := float64(blurred.Pix[pos+3])
r = r + (r-rBlur)*amount
g = g + (g-gBlur)*amount
b = b + (b-bBlur)*amount
a = a + (a-aBlur)*amount
dst.Pix[pos+0] = uint8(f64.Clamp(r, 0, 255))
dst.Pix[pos+1] = uint8(f64.Clamp(g, 0, 255))
dst.Pix[pos+2] = uint8(f64.Clamp(b, 0, 255))
dst.Pix[pos+3] = uint8(f64.Clamp(a, 0, 255))
}
}
})
return dst
} | [
"func",
"UnsharpMask",
"(",
"img",
"image",
".",
"Image",
",",
"radius",
",",
"amount",
"float64",
")",
"*",
"image",
".",
"RGBA",
"{",
"amount",
"=",
"f64",
".",
"Clamp",
"(",
"amount",
",",
"0",
",",
"10",
")",
"\n\n",
"blurred",
":=",
"blur",
".",
"Gaussian",
"(",
"img",
",",
"5",
"*",
"radius",
")",
"// scale radius by matching factor",
"\n\n",
"bounds",
":=",
"img",
".",
"Bounds",
"(",
")",
"\n",
"src",
":=",
"clone",
".",
"AsRGBA",
"(",
"img",
")",
"\n",
"dst",
":=",
"image",
".",
"NewRGBA",
"(",
"bounds",
")",
"\n",
"w",
",",
"h",
":=",
"bounds",
".",
"Dx",
"(",
")",
",",
"bounds",
".",
"Dy",
"(",
")",
"\n\n",
"parallel",
".",
"Line",
"(",
"h",
",",
"func",
"(",
"start",
",",
"end",
"int",
")",
"{",
"for",
"y",
":=",
"start",
";",
"y",
"<",
"end",
";",
"y",
"++",
"{",
"for",
"x",
":=",
"0",
";",
"x",
"<",
"w",
";",
"x",
"++",
"{",
"pos",
":=",
"y",
"*",
"dst",
".",
"Stride",
"+",
"x",
"*",
"4",
"\n\n",
"r",
":=",
"float64",
"(",
"src",
".",
"Pix",
"[",
"pos",
"+",
"0",
"]",
")",
"\n",
"g",
":=",
"float64",
"(",
"src",
".",
"Pix",
"[",
"pos",
"+",
"1",
"]",
")",
"\n",
"b",
":=",
"float64",
"(",
"src",
".",
"Pix",
"[",
"pos",
"+",
"2",
"]",
")",
"\n",
"a",
":=",
"float64",
"(",
"src",
".",
"Pix",
"[",
"pos",
"+",
"3",
"]",
")",
"\n\n",
"rBlur",
":=",
"float64",
"(",
"blurred",
".",
"Pix",
"[",
"pos",
"+",
"0",
"]",
")",
"\n",
"gBlur",
":=",
"float64",
"(",
"blurred",
".",
"Pix",
"[",
"pos",
"+",
"1",
"]",
")",
"\n",
"bBlur",
":=",
"float64",
"(",
"blurred",
".",
"Pix",
"[",
"pos",
"+",
"2",
"]",
")",
"\n",
"aBlur",
":=",
"float64",
"(",
"blurred",
".",
"Pix",
"[",
"pos",
"+",
"3",
"]",
")",
"\n\n",
"r",
"=",
"r",
"+",
"(",
"r",
"-",
"rBlur",
")",
"*",
"amount",
"\n",
"g",
"=",
"g",
"+",
"(",
"g",
"-",
"gBlur",
")",
"*",
"amount",
"\n",
"b",
"=",
"b",
"+",
"(",
"b",
"-",
"bBlur",
")",
"*",
"amount",
"\n",
"a",
"=",
"a",
"+",
"(",
"a",
"-",
"aBlur",
")",
"*",
"amount",
"\n\n",
"dst",
".",
"Pix",
"[",
"pos",
"+",
"0",
"]",
"=",
"uint8",
"(",
"f64",
".",
"Clamp",
"(",
"r",
",",
"0",
",",
"255",
")",
")",
"\n",
"dst",
".",
"Pix",
"[",
"pos",
"+",
"1",
"]",
"=",
"uint8",
"(",
"f64",
".",
"Clamp",
"(",
"g",
",",
"0",
",",
"255",
")",
")",
"\n",
"dst",
".",
"Pix",
"[",
"pos",
"+",
"2",
"]",
"=",
"uint8",
"(",
"f64",
".",
"Clamp",
"(",
"b",
",",
"0",
",",
"255",
")",
")",
"\n",
"dst",
".",
"Pix",
"[",
"pos",
"+",
"3",
"]",
"=",
"uint8",
"(",
"f64",
".",
"Clamp",
"(",
"a",
",",
"0",
",",
"255",
")",
")",
"\n",
"}",
"\n",
"}",
"\n",
"}",
")",
"\n\n",
"return",
"dst",
"\n",
"}"
] | // UnsharpMask returns a copy of the image with its high-frecuency components amplified.
// Parameter radius corresponds to the radius to be samples per pixel.
// Parameter amount is the normalized strength of the effect. A value of 0.0 will leave
// the image untouched and a value of 1.0 will fully apply the unsharp mask. | [
"UnsharpMask",
"returns",
"a",
"copy",
"of",
"the",
"image",
"with",
"its",
"high",
"-",
"frecuency",
"components",
"amplified",
".",
"Parameter",
"radius",
"corresponds",
"to",
"the",
"radius",
"to",
"be",
"samples",
"per",
"pixel",
".",
"Parameter",
"amount",
"is",
"the",
"normalized",
"strength",
"of",
"the",
"effect",
".",
"A",
"value",
"of",
"0",
".",
"0",
"will",
"leave",
"the",
"image",
"untouched",
"and",
"a",
"value",
"of",
"1",
".",
"0",
"will",
"fully",
"apply",
"the",
"unsharp",
"mask",
"."
] | 3a6867030b45db250c7619233c6056b46a980667 | https://github.com/anthonynsimon/bild/blob/3a6867030b45db250c7619233c6056b46a980667/effect/effect.go#L143-L182 |
153,333 | anthonynsimon/bild | effect/effect.go | Median | func Median(img image.Image, radius float64) *image.RGBA {
fn := func(neighbors []color.RGBA) color.RGBA {
util.SortRGBA(neighbors, 0, len(neighbors)-1)
return neighbors[len(neighbors)/2]
}
result := spatialFilter(img, radius, fn)
return result
} | go | func Median(img image.Image, radius float64) *image.RGBA {
fn := func(neighbors []color.RGBA) color.RGBA {
util.SortRGBA(neighbors, 0, len(neighbors)-1)
return neighbors[len(neighbors)/2]
}
result := spatialFilter(img, radius, fn)
return result
} | [
"func",
"Median",
"(",
"img",
"image",
".",
"Image",
",",
"radius",
"float64",
")",
"*",
"image",
".",
"RGBA",
"{",
"fn",
":=",
"func",
"(",
"neighbors",
"[",
"]",
"color",
".",
"RGBA",
")",
"color",
".",
"RGBA",
"{",
"util",
".",
"SortRGBA",
"(",
"neighbors",
",",
"0",
",",
"len",
"(",
"neighbors",
")",
"-",
"1",
")",
"\n",
"return",
"neighbors",
"[",
"len",
"(",
"neighbors",
")",
"/",
"2",
"]",
"\n",
"}",
"\n\n",
"result",
":=",
"spatialFilter",
"(",
"img",
",",
"radius",
",",
"fn",
")",
"\n\n",
"return",
"result",
"\n",
"}"
] | // Median returns a new image in which each pixel is the median of its neighbors.
// The parameter radius corresponds to the radius of the neighbor area to be searched,
// for example a radius of R will result in a search window length of 2R+1 for each dimension. | [
"Median",
"returns",
"a",
"new",
"image",
"in",
"which",
"each",
"pixel",
"is",
"the",
"median",
"of",
"its",
"neighbors",
".",
"The",
"parameter",
"radius",
"corresponds",
"to",
"the",
"radius",
"of",
"the",
"neighbor",
"area",
"to",
"be",
"searched",
"for",
"example",
"a",
"radius",
"of",
"R",
"will",
"result",
"in",
"a",
"search",
"window",
"length",
"of",
"2R",
"+",
"1",
"for",
"each",
"dimension",
"."
] | 3a6867030b45db250c7619233c6056b46a980667 | https://github.com/anthonynsimon/bild/blob/3a6867030b45db250c7619233c6056b46a980667/effect/effect.go#L216-L225 |
153,334 | anthonynsimon/bild | effect/effect.go | spatialFilter | func spatialFilter(img image.Image, radius float64, pickerFn func(neighbors []color.RGBA) color.RGBA) *image.RGBA {
if radius <= 0 {
return clone.AsRGBA(img)
}
padding := int(radius + 0.5)
src := clone.Pad(img, padding, padding, clone.EdgeExtend)
kernelSize := int(2*radius + 1 + 0.5)
bounds := img.Bounds()
dst := image.NewRGBA(bounds)
w, h := bounds.Dx(), bounds.Dy()
neighborsCount := kernelSize * kernelSize
parallel.Line(h, func(start, end int) {
for y := start + padding; y < end+padding; y++ {
for x := padding; x < w+padding; x++ {
neighbors := make([]color.RGBA, neighborsCount)
i := 0
for ky := 0; ky < kernelSize; ky++ {
for kx := 0; kx < kernelSize; kx++ {
ix := x - kernelSize>>1 + kx
iy := y - kernelSize>>1 + ky
ipos := iy*src.Stride + ix*4
neighbors[i] = color.RGBA{
R: src.Pix[ipos+0],
G: src.Pix[ipos+1],
B: src.Pix[ipos+2],
A: src.Pix[ipos+3],
}
i++
}
}
c := pickerFn(neighbors)
pos := (y-padding)*dst.Stride + (x-padding)*4
dst.Pix[pos+0] = c.R
dst.Pix[pos+1] = c.G
dst.Pix[pos+2] = c.B
dst.Pix[pos+3] = c.A
}
}
})
return dst
} | go | func spatialFilter(img image.Image, radius float64, pickerFn func(neighbors []color.RGBA) color.RGBA) *image.RGBA {
if radius <= 0 {
return clone.AsRGBA(img)
}
padding := int(radius + 0.5)
src := clone.Pad(img, padding, padding, clone.EdgeExtend)
kernelSize := int(2*radius + 1 + 0.5)
bounds := img.Bounds()
dst := image.NewRGBA(bounds)
w, h := bounds.Dx(), bounds.Dy()
neighborsCount := kernelSize * kernelSize
parallel.Line(h, func(start, end int) {
for y := start + padding; y < end+padding; y++ {
for x := padding; x < w+padding; x++ {
neighbors := make([]color.RGBA, neighborsCount)
i := 0
for ky := 0; ky < kernelSize; ky++ {
for kx := 0; kx < kernelSize; kx++ {
ix := x - kernelSize>>1 + kx
iy := y - kernelSize>>1 + ky
ipos := iy*src.Stride + ix*4
neighbors[i] = color.RGBA{
R: src.Pix[ipos+0],
G: src.Pix[ipos+1],
B: src.Pix[ipos+2],
A: src.Pix[ipos+3],
}
i++
}
}
c := pickerFn(neighbors)
pos := (y-padding)*dst.Stride + (x-padding)*4
dst.Pix[pos+0] = c.R
dst.Pix[pos+1] = c.G
dst.Pix[pos+2] = c.B
dst.Pix[pos+3] = c.A
}
}
})
return dst
} | [
"func",
"spatialFilter",
"(",
"img",
"image",
".",
"Image",
",",
"radius",
"float64",
",",
"pickerFn",
"func",
"(",
"neighbors",
"[",
"]",
"color",
".",
"RGBA",
")",
"color",
".",
"RGBA",
")",
"*",
"image",
".",
"RGBA",
"{",
"if",
"radius",
"<=",
"0",
"{",
"return",
"clone",
".",
"AsRGBA",
"(",
"img",
")",
"\n",
"}",
"\n\n",
"padding",
":=",
"int",
"(",
"radius",
"+",
"0.5",
")",
"\n",
"src",
":=",
"clone",
".",
"Pad",
"(",
"img",
",",
"padding",
",",
"padding",
",",
"clone",
".",
"EdgeExtend",
")",
"\n\n",
"kernelSize",
":=",
"int",
"(",
"2",
"*",
"radius",
"+",
"1",
"+",
"0.5",
")",
"\n\n",
"bounds",
":=",
"img",
".",
"Bounds",
"(",
")",
"\n",
"dst",
":=",
"image",
".",
"NewRGBA",
"(",
"bounds",
")",
"\n\n",
"w",
",",
"h",
":=",
"bounds",
".",
"Dx",
"(",
")",
",",
"bounds",
".",
"Dy",
"(",
")",
"\n",
"neighborsCount",
":=",
"kernelSize",
"*",
"kernelSize",
"\n\n",
"parallel",
".",
"Line",
"(",
"h",
",",
"func",
"(",
"start",
",",
"end",
"int",
")",
"{",
"for",
"y",
":=",
"start",
"+",
"padding",
";",
"y",
"<",
"end",
"+",
"padding",
";",
"y",
"++",
"{",
"for",
"x",
":=",
"padding",
";",
"x",
"<",
"w",
"+",
"padding",
";",
"x",
"++",
"{",
"neighbors",
":=",
"make",
"(",
"[",
"]",
"color",
".",
"RGBA",
",",
"neighborsCount",
")",
"\n",
"i",
":=",
"0",
"\n",
"for",
"ky",
":=",
"0",
";",
"ky",
"<",
"kernelSize",
";",
"ky",
"++",
"{",
"for",
"kx",
":=",
"0",
";",
"kx",
"<",
"kernelSize",
";",
"kx",
"++",
"{",
"ix",
":=",
"x",
"-",
"kernelSize",
">>",
"1",
"+",
"kx",
"\n",
"iy",
":=",
"y",
"-",
"kernelSize",
">>",
"1",
"+",
"ky",
"\n\n",
"ipos",
":=",
"iy",
"*",
"src",
".",
"Stride",
"+",
"ix",
"*",
"4",
"\n",
"neighbors",
"[",
"i",
"]",
"=",
"color",
".",
"RGBA",
"{",
"R",
":",
"src",
".",
"Pix",
"[",
"ipos",
"+",
"0",
"]",
",",
"G",
":",
"src",
".",
"Pix",
"[",
"ipos",
"+",
"1",
"]",
",",
"B",
":",
"src",
".",
"Pix",
"[",
"ipos",
"+",
"2",
"]",
",",
"A",
":",
"src",
".",
"Pix",
"[",
"ipos",
"+",
"3",
"]",
",",
"}",
"\n",
"i",
"++",
"\n",
"}",
"\n",
"}",
"\n\n",
"c",
":=",
"pickerFn",
"(",
"neighbors",
")",
"\n\n",
"pos",
":=",
"(",
"y",
"-",
"padding",
")",
"*",
"dst",
".",
"Stride",
"+",
"(",
"x",
"-",
"padding",
")",
"*",
"4",
"\n",
"dst",
".",
"Pix",
"[",
"pos",
"+",
"0",
"]",
"=",
"c",
".",
"R",
"\n",
"dst",
".",
"Pix",
"[",
"pos",
"+",
"1",
"]",
"=",
"c",
".",
"G",
"\n",
"dst",
".",
"Pix",
"[",
"pos",
"+",
"2",
"]",
"=",
"c",
".",
"B",
"\n",
"dst",
".",
"Pix",
"[",
"pos",
"+",
"3",
"]",
"=",
"c",
".",
"A",
"\n",
"}",
"\n",
"}",
"\n",
"}",
")",
"\n\n",
"return",
"dst",
"\n",
"}"
] | // spatialFilter goes through each pixel on an image collecting its neighbors and picking one
// based on the function provided. The resulting image is then returned.
// The parameter radius corresponds to the radius of the neighbor area to be searched,
// for example a radius of R will result in a search window length of 2R+1 for each dimension.
// The parameter pickerFn is the function that receives the list of neighbors and returns the selected
// neighbor to be used for the resulting image. | [
"spatialFilter",
"goes",
"through",
"each",
"pixel",
"on",
"an",
"image",
"collecting",
"its",
"neighbors",
"and",
"picking",
"one",
"based",
"on",
"the",
"function",
"provided",
".",
"The",
"resulting",
"image",
"is",
"then",
"returned",
".",
"The",
"parameter",
"radius",
"corresponds",
"to",
"the",
"radius",
"of",
"the",
"neighbor",
"area",
"to",
"be",
"searched",
"for",
"example",
"a",
"radius",
"of",
"R",
"will",
"result",
"in",
"a",
"search",
"window",
"length",
"of",
"2R",
"+",
"1",
"for",
"each",
"dimension",
".",
"The",
"parameter",
"pickerFn",
"is",
"the",
"function",
"that",
"receives",
"the",
"list",
"of",
"neighbors",
"and",
"returns",
"the",
"selected",
"neighbor",
"to",
"be",
"used",
"for",
"the",
"resulting",
"image",
"."
] | 3a6867030b45db250c7619233c6056b46a980667 | https://github.com/anthonynsimon/bild/blob/3a6867030b45db250c7619233c6056b46a980667/effect/effect.go#L261-L311 |
153,335 | anthonynsimon/bild | util/util.go | SortRGBA | func SortRGBA(data []color.RGBA, min, max int) {
if min > max {
return
}
p := partitionRGBASlice(data, min, max)
SortRGBA(data, min, p-1)
SortRGBA(data, p+1, max)
} | go | func SortRGBA(data []color.RGBA, min, max int) {
if min > max {
return
}
p := partitionRGBASlice(data, min, max)
SortRGBA(data, min, p-1)
SortRGBA(data, p+1, max)
} | [
"func",
"SortRGBA",
"(",
"data",
"[",
"]",
"color",
".",
"RGBA",
",",
"min",
",",
"max",
"int",
")",
"{",
"if",
"min",
">",
"max",
"{",
"return",
"\n",
"}",
"\n",
"p",
":=",
"partitionRGBASlice",
"(",
"data",
",",
"min",
",",
"max",
")",
"\n",
"SortRGBA",
"(",
"data",
",",
"min",
",",
"p",
"-",
"1",
")",
"\n",
"SortRGBA",
"(",
"data",
",",
"p",
"+",
"1",
",",
"max",
")",
"\n",
"}"
] | // SortRGBA sorts a slice of RGBA values.
// Parameter min and max correspond to the start and end slice indices
// that determine the range to be sorted. | [
"SortRGBA",
"sorts",
"a",
"slice",
"of",
"RGBA",
"values",
".",
"Parameter",
"min",
"and",
"max",
"correspond",
"to",
"the",
"start",
"and",
"end",
"slice",
"indices",
"that",
"determine",
"the",
"range",
"to",
"be",
"sorted",
"."
] | 3a6867030b45db250c7619233c6056b46a980667 | https://github.com/anthonynsimon/bild/blob/3a6867030b45db250c7619233c6056b46a980667/util/util.go#L13-L20 |
153,336 | anthonynsimon/bild | util/util.go | Rank | func Rank(c color.RGBA) float64 {
return float64(c.R)*0.3 + float64(c.G)*0.6 + float64(c.B)*0.1
} | go | func Rank(c color.RGBA) float64 {
return float64(c.R)*0.3 + float64(c.G)*0.6 + float64(c.B)*0.1
} | [
"func",
"Rank",
"(",
"c",
"color",
".",
"RGBA",
")",
"float64",
"{",
"return",
"float64",
"(",
"c",
".",
"R",
")",
"*",
"0.3",
"+",
"float64",
"(",
"c",
".",
"G",
")",
"*",
"0.6",
"+",
"float64",
"(",
"c",
".",
"B",
")",
"*",
"0.1",
"\n",
"}"
] | // Rank a color based on a color perception heuristic. | [
"Rank",
"a",
"color",
"based",
"on",
"a",
"color",
"perception",
"heuristic",
"."
] | 3a6867030b45db250c7619233c6056b46a980667 | https://github.com/anthonynsimon/bild/blob/3a6867030b45db250c7619233c6056b46a980667/util/util.go#L41-L43 |
153,337 | anthonynsimon/bild | util/util.go | RGBAToString | func RGBAToString(img *image.RGBA) string {
var result string
result += fmt.Sprintf("\nBounds: %v", img.Bounds())
result += fmt.Sprintf("\nStride: %v", img.Stride)
for y := 0; y < img.Bounds().Dy(); y++ {
result += "\n"
for x := 0; x < img.Bounds().Dx(); x++ {
pos := y*img.Stride + x*4
result += fmt.Sprintf("%#X, ", img.Pix[pos+0])
result += fmt.Sprintf("%#X, ", img.Pix[pos+1])
result += fmt.Sprintf("%#X, ", img.Pix[pos+2])
result += fmt.Sprintf("%#X, ", img.Pix[pos+3])
}
}
result += "\n"
return result
} | go | func RGBAToString(img *image.RGBA) string {
var result string
result += fmt.Sprintf("\nBounds: %v", img.Bounds())
result += fmt.Sprintf("\nStride: %v", img.Stride)
for y := 0; y < img.Bounds().Dy(); y++ {
result += "\n"
for x := 0; x < img.Bounds().Dx(); x++ {
pos := y*img.Stride + x*4
result += fmt.Sprintf("%#X, ", img.Pix[pos+0])
result += fmt.Sprintf("%#X, ", img.Pix[pos+1])
result += fmt.Sprintf("%#X, ", img.Pix[pos+2])
result += fmt.Sprintf("%#X, ", img.Pix[pos+3])
}
}
result += "\n"
return result
} | [
"func",
"RGBAToString",
"(",
"img",
"*",
"image",
".",
"RGBA",
")",
"string",
"{",
"var",
"result",
"string",
"\n",
"result",
"+=",
"fmt",
".",
"Sprintf",
"(",
"\"",
"\\n",
"\"",
",",
"img",
".",
"Bounds",
"(",
")",
")",
"\n",
"result",
"+=",
"fmt",
".",
"Sprintf",
"(",
"\"",
"\\n",
"\"",
",",
"img",
".",
"Stride",
")",
"\n",
"for",
"y",
":=",
"0",
";",
"y",
"<",
"img",
".",
"Bounds",
"(",
")",
".",
"Dy",
"(",
")",
";",
"y",
"++",
"{",
"result",
"+=",
"\"",
"\\n",
"\"",
"\n",
"for",
"x",
":=",
"0",
";",
"x",
"<",
"img",
".",
"Bounds",
"(",
")",
".",
"Dx",
"(",
")",
";",
"x",
"++",
"{",
"pos",
":=",
"y",
"*",
"img",
".",
"Stride",
"+",
"x",
"*",
"4",
"\n",
"result",
"+=",
"fmt",
".",
"Sprintf",
"(",
"\"",
"\"",
",",
"img",
".",
"Pix",
"[",
"pos",
"+",
"0",
"]",
")",
"\n",
"result",
"+=",
"fmt",
".",
"Sprintf",
"(",
"\"",
"\"",
",",
"img",
".",
"Pix",
"[",
"pos",
"+",
"1",
"]",
")",
"\n",
"result",
"+=",
"fmt",
".",
"Sprintf",
"(",
"\"",
"\"",
",",
"img",
".",
"Pix",
"[",
"pos",
"+",
"2",
"]",
")",
"\n",
"result",
"+=",
"fmt",
".",
"Sprintf",
"(",
"\"",
"\"",
",",
"img",
".",
"Pix",
"[",
"pos",
"+",
"3",
"]",
")",
"\n",
"}",
"\n",
"}",
"\n",
"result",
"+=",
"\"",
"\\n",
"\"",
"\n",
"return",
"result",
"\n",
"}"
] | // RGBAToString returns a string representation of the Hex values contained in an image.RGBA. | [
"RGBAToString",
"returns",
"a",
"string",
"representation",
"of",
"the",
"Hex",
"values",
"contained",
"in",
"an",
"image",
".",
"RGBA",
"."
] | 3a6867030b45db250c7619233c6056b46a980667 | https://github.com/anthonynsimon/bild/blob/3a6867030b45db250c7619233c6056b46a980667/util/util.go#L46-L62 |
153,338 | anthonynsimon/bild | util/util.go | RGBASlicesEqual | func RGBASlicesEqual(a, b []color.RGBA) bool {
if a == nil && b == nil {
return true
}
if len(a) != len(b) {
return false
}
for i := range a {
if a[i] != b[i] {
return false
}
}
return true
} | go | func RGBASlicesEqual(a, b []color.RGBA) bool {
if a == nil && b == nil {
return true
}
if len(a) != len(b) {
return false
}
for i := range a {
if a[i] != b[i] {
return false
}
}
return true
} | [
"func",
"RGBASlicesEqual",
"(",
"a",
",",
"b",
"[",
"]",
"color",
".",
"RGBA",
")",
"bool",
"{",
"if",
"a",
"==",
"nil",
"&&",
"b",
"==",
"nil",
"{",
"return",
"true",
"\n",
"}",
"\n\n",
"if",
"len",
"(",
"a",
")",
"!=",
"len",
"(",
"b",
")",
"{",
"return",
"false",
"\n",
"}",
"\n\n",
"for",
"i",
":=",
"range",
"a",
"{",
"if",
"a",
"[",
"i",
"]",
"!=",
"b",
"[",
"i",
"]",
"{",
"return",
"false",
"\n",
"}",
"\n",
"}",
"\n\n",
"return",
"true",
"\n",
"}"
] | // RGBASlicesEqual returns true if the parameter RGBA color slices a and b match
// or false if otherwise. | [
"RGBASlicesEqual",
"returns",
"true",
"if",
"the",
"parameter",
"RGBA",
"color",
"slices",
"a",
"and",
"b",
"match",
"or",
"false",
"if",
"otherwise",
"."
] | 3a6867030b45db250c7619233c6056b46a980667 | https://github.com/anthonynsimon/bild/blob/3a6867030b45db250c7619233c6056b46a980667/util/util.go#L66-L82 |
153,339 | anthonynsimon/bild | util/util.go | GrayImageEqual | func GrayImageEqual(a, b *image.Gray) bool {
if !a.Rect.Eq(b.Rect) {
return false
}
for i := 0; i < len(a.Pix); i++ {
if a.Pix[i] != b.Pix[i] {
return false
}
}
return true
} | go | func GrayImageEqual(a, b *image.Gray) bool {
if !a.Rect.Eq(b.Rect) {
return false
}
for i := 0; i < len(a.Pix); i++ {
if a.Pix[i] != b.Pix[i] {
return false
}
}
return true
} | [
"func",
"GrayImageEqual",
"(",
"a",
",",
"b",
"*",
"image",
".",
"Gray",
")",
"bool",
"{",
"if",
"!",
"a",
".",
"Rect",
".",
"Eq",
"(",
"b",
".",
"Rect",
")",
"{",
"return",
"false",
"\n",
"}",
"\n\n",
"for",
"i",
":=",
"0",
";",
"i",
"<",
"len",
"(",
"a",
".",
"Pix",
")",
";",
"i",
"++",
"{",
"if",
"a",
".",
"Pix",
"[",
"i",
"]",
"!=",
"b",
".",
"Pix",
"[",
"i",
"]",
"{",
"return",
"false",
"\n",
"}",
"\n",
"}",
"\n",
"return",
"true",
"\n",
"}"
] | // GrayImageEqual returns true if the parameter images a and b match
// or false if otherwise. | [
"GrayImageEqual",
"returns",
"true",
"if",
"the",
"parameter",
"images",
"a",
"and",
"b",
"match",
"or",
"false",
"if",
"otherwise",
"."
] | 3a6867030b45db250c7619233c6056b46a980667 | https://github.com/anthonynsimon/bild/blob/3a6867030b45db250c7619233c6056b46a980667/util/util.go#L86-L97 |
153,340 | anthonynsimon/bild | util/util.go | RGBAImageEqual | func RGBAImageEqual(a, b *image.RGBA) bool {
if !a.Rect.Eq(b.Rect) {
return false
}
for y := 0; y < a.Bounds().Dy(); y++ {
for x := 0; x < a.Bounds().Dx(); x++ {
pos := y*a.Stride + x*4
if a.Pix[pos+0] != b.Pix[pos+0] {
return false
}
if a.Pix[pos+1] != b.Pix[pos+1] {
return false
}
if a.Pix[pos+2] != b.Pix[pos+2] {
return false
}
if a.Pix[pos+3] != b.Pix[pos+3] {
return false
}
}
}
return true
} | go | func RGBAImageEqual(a, b *image.RGBA) bool {
if !a.Rect.Eq(b.Rect) {
return false
}
for y := 0; y < a.Bounds().Dy(); y++ {
for x := 0; x < a.Bounds().Dx(); x++ {
pos := y*a.Stride + x*4
if a.Pix[pos+0] != b.Pix[pos+0] {
return false
}
if a.Pix[pos+1] != b.Pix[pos+1] {
return false
}
if a.Pix[pos+2] != b.Pix[pos+2] {
return false
}
if a.Pix[pos+3] != b.Pix[pos+3] {
return false
}
}
}
return true
} | [
"func",
"RGBAImageEqual",
"(",
"a",
",",
"b",
"*",
"image",
".",
"RGBA",
")",
"bool",
"{",
"if",
"!",
"a",
".",
"Rect",
".",
"Eq",
"(",
"b",
".",
"Rect",
")",
"{",
"return",
"false",
"\n",
"}",
"\n\n",
"for",
"y",
":=",
"0",
";",
"y",
"<",
"a",
".",
"Bounds",
"(",
")",
".",
"Dy",
"(",
")",
";",
"y",
"++",
"{",
"for",
"x",
":=",
"0",
";",
"x",
"<",
"a",
".",
"Bounds",
"(",
")",
".",
"Dx",
"(",
")",
";",
"x",
"++",
"{",
"pos",
":=",
"y",
"*",
"a",
".",
"Stride",
"+",
"x",
"*",
"4",
"\n",
"if",
"a",
".",
"Pix",
"[",
"pos",
"+",
"0",
"]",
"!=",
"b",
".",
"Pix",
"[",
"pos",
"+",
"0",
"]",
"{",
"return",
"false",
"\n",
"}",
"\n",
"if",
"a",
".",
"Pix",
"[",
"pos",
"+",
"1",
"]",
"!=",
"b",
".",
"Pix",
"[",
"pos",
"+",
"1",
"]",
"{",
"return",
"false",
"\n",
"}",
"\n",
"if",
"a",
".",
"Pix",
"[",
"pos",
"+",
"2",
"]",
"!=",
"b",
".",
"Pix",
"[",
"pos",
"+",
"2",
"]",
"{",
"return",
"false",
"\n",
"}",
"\n",
"if",
"a",
".",
"Pix",
"[",
"pos",
"+",
"3",
"]",
"!=",
"b",
".",
"Pix",
"[",
"pos",
"+",
"3",
"]",
"{",
"return",
"false",
"\n",
"}",
"\n",
"}",
"\n",
"}",
"\n",
"return",
"true",
"\n",
"}"
] | // RGBAImageEqual returns true if the parameter images a and b match
// or false if otherwise. | [
"RGBAImageEqual",
"returns",
"true",
"if",
"the",
"parameter",
"images",
"a",
"and",
"b",
"match",
"or",
"false",
"if",
"otherwise",
"."
] | 3a6867030b45db250c7619233c6056b46a980667 | https://github.com/anthonynsimon/bild/blob/3a6867030b45db250c7619233c6056b46a980667/util/util.go#L101-L124 |
153,341 | anthonynsimon/bild | util/stack.go | Push | func (s *Stack) Push(value interface{}) {
s.top = &stackElement{value, s.top}
s.size++
} | go | func (s *Stack) Push(value interface{}) {
s.top = &stackElement{value, s.top}
s.size++
} | [
"func",
"(",
"s",
"*",
"Stack",
")",
"Push",
"(",
"value",
"interface",
"{",
"}",
")",
"{",
"s",
".",
"top",
"=",
"&",
"stackElement",
"{",
"value",
",",
"s",
".",
"top",
"}",
"\n",
"s",
".",
"size",
"++",
"\n",
"}"
] | // Push a new value onto the stack | [
"Push",
"a",
"new",
"value",
"onto",
"the",
"stack"
] | 3a6867030b45db250c7619233c6056b46a980667 | https://github.com/anthonynsimon/bild/blob/3a6867030b45db250c7619233c6056b46a980667/util/stack.go#L20-L23 |
153,342 | anthonynsimon/bild | util/stack.go | Pop | func (s *Stack) Pop() interface{} {
if s.size > 0 {
value := s.top.value
s.top = s.top.next
s.size--
return value
}
return nil
} | go | func (s *Stack) Pop() interface{} {
if s.size > 0 {
value := s.top.value
s.top = s.top.next
s.size--
return value
}
return nil
} | [
"func",
"(",
"s",
"*",
"Stack",
")",
"Pop",
"(",
")",
"interface",
"{",
"}",
"{",
"if",
"s",
".",
"size",
">",
"0",
"{",
"value",
":=",
"s",
".",
"top",
".",
"value",
"\n",
"s",
".",
"top",
"=",
"s",
".",
"top",
".",
"next",
"\n",
"s",
".",
"size",
"--",
"\n",
"return",
"value",
"\n",
"}",
"\n",
"return",
"nil",
"\n",
"}"
] | // Pop the most recently pushed value from the stack | [
"Pop",
"the",
"most",
"recently",
"pushed",
"value",
"from",
"the",
"stack"
] | 3a6867030b45db250c7619233c6056b46a980667 | https://github.com/anthonynsimon/bild/blob/3a6867030b45db250c7619233c6056b46a980667/util/stack.go#L26-L34 |
153,343 | anthonynsimon/bild | fcolor/rgbaf64.go | NewRGBAF64 | func NewRGBAF64(r, g, b, a uint8) RGBAF64 {
return RGBAF64{float64(r) / 255, float64(g) / 255, float64(b) / 255, float64(a) / 255}
} | go | func NewRGBAF64(r, g, b, a uint8) RGBAF64 {
return RGBAF64{float64(r) / 255, float64(g) / 255, float64(b) / 255, float64(a) / 255}
} | [
"func",
"NewRGBAF64",
"(",
"r",
",",
"g",
",",
"b",
",",
"a",
"uint8",
")",
"RGBAF64",
"{",
"return",
"RGBAF64",
"{",
"float64",
"(",
"r",
")",
"/",
"255",
",",
"float64",
"(",
"g",
")",
"/",
"255",
",",
"float64",
"(",
"b",
")",
"/",
"255",
",",
"float64",
"(",
"a",
")",
"/",
"255",
"}",
"\n",
"}"
] | // NewRGBAF64 returns a new RGBAF64 color based on the provided uint8 values.
// uint8 value 0 maps to 0, 128 to 0.5 and 255 to 1.0. | [
"NewRGBAF64",
"returns",
"a",
"new",
"RGBAF64",
"color",
"based",
"on",
"the",
"provided",
"uint8",
"values",
".",
"uint8",
"value",
"0",
"maps",
"to",
"0",
"128",
"to",
"0",
".",
"5",
"and",
"255",
"to",
"1",
".",
"0",
"."
] | 3a6867030b45db250c7619233c6056b46a980667 | https://github.com/anthonynsimon/bild/blob/3a6867030b45db250c7619233c6056b46a980667/fcolor/rgbaf64.go#L13-L15 |
153,344 | anthonynsimon/bild | fcolor/rgbaf64.go | Clamp | func (c *RGBAF64) Clamp() {
c.R = f64.Clamp(c.R, 0, 1)
c.G = f64.Clamp(c.G, 0, 1)
c.B = f64.Clamp(c.B, 0, 1)
c.A = f64.Clamp(c.A, 0, 1)
} | go | func (c *RGBAF64) Clamp() {
c.R = f64.Clamp(c.R, 0, 1)
c.G = f64.Clamp(c.G, 0, 1)
c.B = f64.Clamp(c.B, 0, 1)
c.A = f64.Clamp(c.A, 0, 1)
} | [
"func",
"(",
"c",
"*",
"RGBAF64",
")",
"Clamp",
"(",
")",
"{",
"c",
".",
"R",
"=",
"f64",
".",
"Clamp",
"(",
"c",
".",
"R",
",",
"0",
",",
"1",
")",
"\n",
"c",
".",
"G",
"=",
"f64",
".",
"Clamp",
"(",
"c",
".",
"G",
",",
"0",
",",
"1",
")",
"\n",
"c",
".",
"B",
"=",
"f64",
".",
"Clamp",
"(",
"c",
".",
"B",
",",
"0",
",",
"1",
")",
"\n",
"c",
".",
"A",
"=",
"f64",
".",
"Clamp",
"(",
"c",
".",
"A",
",",
"0",
",",
"1",
")",
"\n",
"}"
] | // Clamp limits the channel values of the RGBAF64 color to the range 0.0 to 1.0. | [
"Clamp",
"limits",
"the",
"channel",
"values",
"of",
"the",
"RGBAF64",
"color",
"to",
"the",
"range",
"0",
".",
"0",
"to",
"1",
".",
"0",
"."
] | 3a6867030b45db250c7619233c6056b46a980667 | https://github.com/anthonynsimon/bild/blob/3a6867030b45db250c7619233c6056b46a980667/fcolor/rgbaf64.go#L18-L23 |
153,345 | anthonynsimon/bild | imgio/io.go | JPEGEncoder | func JPEGEncoder(quality int) Encoder {
return func(w io.Writer, img image.Image) error {
return jpeg.Encode(w, img, &jpeg.Options{Quality: quality})
}
} | go | func JPEGEncoder(quality int) Encoder {
return func(w io.Writer, img image.Image) error {
return jpeg.Encode(w, img, &jpeg.Options{Quality: quality})
}
} | [
"func",
"JPEGEncoder",
"(",
"quality",
"int",
")",
"Encoder",
"{",
"return",
"func",
"(",
"w",
"io",
".",
"Writer",
",",
"img",
"image",
".",
"Image",
")",
"error",
"{",
"return",
"jpeg",
".",
"Encode",
"(",
"w",
",",
"img",
",",
"&",
"jpeg",
".",
"Options",
"{",
"Quality",
":",
"quality",
"}",
")",
"\n",
"}",
"\n",
"}"
] | // JPEGEncoder returns an encoder to JPEG given the argument 'quality' | [
"JPEGEncoder",
"returns",
"an",
"encoder",
"to",
"JPEG",
"given",
"the",
"argument",
"quality"
] | 3a6867030b45db250c7619233c6056b46a980667 | https://github.com/anthonynsimon/bild/blob/3a6867030b45db250c7619233c6056b46a980667/imgio/io.go#L40-L44 |
153,346 | anthonynsimon/bild | imgio/io.go | PNGEncoder | func PNGEncoder() Encoder {
return func(w io.Writer, img image.Image) error {
return png.Encode(w, img)
}
} | go | func PNGEncoder() Encoder {
return func(w io.Writer, img image.Image) error {
return png.Encode(w, img)
}
} | [
"func",
"PNGEncoder",
"(",
")",
"Encoder",
"{",
"return",
"func",
"(",
"w",
"io",
".",
"Writer",
",",
"img",
"image",
".",
"Image",
")",
"error",
"{",
"return",
"png",
".",
"Encode",
"(",
"w",
",",
"img",
")",
"\n",
"}",
"\n",
"}"
] | // PNGEncoder returns an encoder to PNG | [
"PNGEncoder",
"returns",
"an",
"encoder",
"to",
"PNG"
] | 3a6867030b45db250c7619233c6056b46a980667 | https://github.com/anthonynsimon/bild/blob/3a6867030b45db250c7619233c6056b46a980667/imgio/io.go#L47-L51 |
153,347 | anthonynsimon/bild | imgio/io.go | BMPEncoder | func BMPEncoder() Encoder {
return func(w io.Writer, img image.Image) error {
return bmp.Encode(w, img)
}
} | go | func BMPEncoder() Encoder {
return func(w io.Writer, img image.Image) error {
return bmp.Encode(w, img)
}
} | [
"func",
"BMPEncoder",
"(",
")",
"Encoder",
"{",
"return",
"func",
"(",
"w",
"io",
".",
"Writer",
",",
"img",
"image",
".",
"Image",
")",
"error",
"{",
"return",
"bmp",
".",
"Encode",
"(",
"w",
",",
"img",
")",
"\n",
"}",
"\n",
"}"
] | // BMPEncoder returns an encoder to BMP | [
"BMPEncoder",
"returns",
"an",
"encoder",
"to",
"BMP"
] | 3a6867030b45db250c7619233c6056b46a980667 | https://github.com/anthonynsimon/bild/blob/3a6867030b45db250c7619233c6056b46a980667/imgio/io.go#L54-L58 |
153,348 | anthonynsimon/bild | parallel/parallel.go | Line | func Line(length int, fn func(start, end int)) {
procs := runtime.GOMAXPROCS(0)
counter := length
partSize := length / procs
if procs <= 1 || partSize <= procs {
fn(0, length)
} else {
var wg sync.WaitGroup
for counter > 0 {
start := counter - partSize
end := counter
if start < 0 {
start = 0
}
counter -= partSize
wg.Add(1)
go func() {
defer wg.Done()
fn(start, end)
}()
}
wg.Wait()
}
} | go | func Line(length int, fn func(start, end int)) {
procs := runtime.GOMAXPROCS(0)
counter := length
partSize := length / procs
if procs <= 1 || partSize <= procs {
fn(0, length)
} else {
var wg sync.WaitGroup
for counter > 0 {
start := counter - partSize
end := counter
if start < 0 {
start = 0
}
counter -= partSize
wg.Add(1)
go func() {
defer wg.Done()
fn(start, end)
}()
}
wg.Wait()
}
} | [
"func",
"Line",
"(",
"length",
"int",
",",
"fn",
"func",
"(",
"start",
",",
"end",
"int",
")",
")",
"{",
"procs",
":=",
"runtime",
".",
"GOMAXPROCS",
"(",
"0",
")",
"\n",
"counter",
":=",
"length",
"\n",
"partSize",
":=",
"length",
"/",
"procs",
"\n",
"if",
"procs",
"<=",
"1",
"||",
"partSize",
"<=",
"procs",
"{",
"fn",
"(",
"0",
",",
"length",
")",
"\n",
"}",
"else",
"{",
"var",
"wg",
"sync",
".",
"WaitGroup",
"\n",
"for",
"counter",
">",
"0",
"{",
"start",
":=",
"counter",
"-",
"partSize",
"\n",
"end",
":=",
"counter",
"\n",
"if",
"start",
"<",
"0",
"{",
"start",
"=",
"0",
"\n",
"}",
"\n",
"counter",
"-=",
"partSize",
"\n",
"wg",
".",
"Add",
"(",
"1",
")",
"\n",
"go",
"func",
"(",
")",
"{",
"defer",
"wg",
".",
"Done",
"(",
")",
"\n",
"fn",
"(",
"start",
",",
"end",
")",
"\n",
"}",
"(",
")",
"\n",
"}",
"\n\n",
"wg",
".",
"Wait",
"(",
")",
"\n",
"}",
"\n",
"}"
] | // Line dispatches a parameter fn into multiple goroutines by splitting the parameter length
// by the number of available CPUs and assigning the length parts into each fn. | [
"Line",
"dispatches",
"a",
"parameter",
"fn",
"into",
"multiple",
"goroutines",
"by",
"splitting",
"the",
"parameter",
"length",
"by",
"the",
"number",
"of",
"available",
"CPUs",
"and",
"assigning",
"the",
"length",
"parts",
"into",
"each",
"fn",
"."
] | 3a6867030b45db250c7619233c6056b46a980667 | https://github.com/anthonynsimon/bild/blob/3a6867030b45db250c7619233c6056b46a980667/parallel/parallel.go#L15-L39 |
153,349 | anthonynsimon/bild | transform/rotate.go | FlipH | func FlipH(img image.Image) *image.RGBA {
bounds := img.Bounds()
src := clone.AsRGBA(img)
dst := image.NewRGBA(bounds)
w, h := dst.Bounds().Dx(), dst.Bounds().Dy()
parallel.Line(h, func(start, end int) {
for y := start; y < end; y++ {
for x := 0; x < w; x++ {
iy := y * dst.Stride
pos := iy + (x * 4)
flippedX := w - x - 1
flippedPos := iy + (flippedX * 4)
dst.Pix[pos+0] = src.Pix[flippedPos+0]
dst.Pix[pos+1] = src.Pix[flippedPos+1]
dst.Pix[pos+2] = src.Pix[flippedPos+2]
dst.Pix[pos+3] = src.Pix[flippedPos+3]
}
}
})
return dst
} | go | func FlipH(img image.Image) *image.RGBA {
bounds := img.Bounds()
src := clone.AsRGBA(img)
dst := image.NewRGBA(bounds)
w, h := dst.Bounds().Dx(), dst.Bounds().Dy()
parallel.Line(h, func(start, end int) {
for y := start; y < end; y++ {
for x := 0; x < w; x++ {
iy := y * dst.Stride
pos := iy + (x * 4)
flippedX := w - x - 1
flippedPos := iy + (flippedX * 4)
dst.Pix[pos+0] = src.Pix[flippedPos+0]
dst.Pix[pos+1] = src.Pix[flippedPos+1]
dst.Pix[pos+2] = src.Pix[flippedPos+2]
dst.Pix[pos+3] = src.Pix[flippedPos+3]
}
}
})
return dst
} | [
"func",
"FlipH",
"(",
"img",
"image",
".",
"Image",
")",
"*",
"image",
".",
"RGBA",
"{",
"bounds",
":=",
"img",
".",
"Bounds",
"(",
")",
"\n",
"src",
":=",
"clone",
".",
"AsRGBA",
"(",
"img",
")",
"\n",
"dst",
":=",
"image",
".",
"NewRGBA",
"(",
"bounds",
")",
"\n",
"w",
",",
"h",
":=",
"dst",
".",
"Bounds",
"(",
")",
".",
"Dx",
"(",
")",
",",
"dst",
".",
"Bounds",
"(",
")",
".",
"Dy",
"(",
")",
"\n\n",
"parallel",
".",
"Line",
"(",
"h",
",",
"func",
"(",
"start",
",",
"end",
"int",
")",
"{",
"for",
"y",
":=",
"start",
";",
"y",
"<",
"end",
";",
"y",
"++",
"{",
"for",
"x",
":=",
"0",
";",
"x",
"<",
"w",
";",
"x",
"++",
"{",
"iy",
":=",
"y",
"*",
"dst",
".",
"Stride",
"\n",
"pos",
":=",
"iy",
"+",
"(",
"x",
"*",
"4",
")",
"\n",
"flippedX",
":=",
"w",
"-",
"x",
"-",
"1",
"\n",
"flippedPos",
":=",
"iy",
"+",
"(",
"flippedX",
"*",
"4",
")",
"\n\n",
"dst",
".",
"Pix",
"[",
"pos",
"+",
"0",
"]",
"=",
"src",
".",
"Pix",
"[",
"flippedPos",
"+",
"0",
"]",
"\n",
"dst",
".",
"Pix",
"[",
"pos",
"+",
"1",
"]",
"=",
"src",
".",
"Pix",
"[",
"flippedPos",
"+",
"1",
"]",
"\n",
"dst",
".",
"Pix",
"[",
"pos",
"+",
"2",
"]",
"=",
"src",
".",
"Pix",
"[",
"flippedPos",
"+",
"2",
"]",
"\n",
"dst",
".",
"Pix",
"[",
"pos",
"+",
"3",
"]",
"=",
"src",
".",
"Pix",
"[",
"flippedPos",
"+",
"3",
"]",
"\n",
"}",
"\n",
"}",
"\n",
"}",
")",
"\n\n",
"return",
"dst",
"\n",
"}"
] | // FlipH returns a horizontally flipped version of the image. | [
"FlipH",
"returns",
"a",
"horizontally",
"flipped",
"version",
"of",
"the",
"image",
"."
] | 3a6867030b45db250c7619233c6056b46a980667 | https://github.com/anthonynsimon/bild/blob/3a6867030b45db250c7619233c6056b46a980667/transform/rotate.go#L125-L148 |
153,350 | anthonynsimon/bild | math/f64/clamp.go | Clamp | func Clamp(value, min, max float64) float64 {
if value > max {
return max
}
if value < min {
return min
}
return value
} | go | func Clamp(value, min, max float64) float64 {
if value > max {
return max
}
if value < min {
return min
}
return value
} | [
"func",
"Clamp",
"(",
"value",
",",
"min",
",",
"max",
"float64",
")",
"float64",
"{",
"if",
"value",
">",
"max",
"{",
"return",
"max",
"\n",
"}",
"\n",
"if",
"value",
"<",
"min",
"{",
"return",
"min",
"\n",
"}",
"\n",
"return",
"value",
"\n",
"}"
] | // Clamp returns the value if it fits within the parameters min and max.
// Otherwise returns the closest boundary parameter value. | [
"Clamp",
"returns",
"the",
"value",
"if",
"it",
"fits",
"within",
"the",
"parameters",
"min",
"and",
"max",
".",
"Otherwise",
"returns",
"the",
"closest",
"boundary",
"parameter",
"value",
"."
] | 3a6867030b45db250c7619233c6056b46a980667 | https://github.com/anthonynsimon/bild/blob/3a6867030b45db250c7619233c6056b46a980667/math/f64/clamp.go#L6-L14 |
153,351 | anthonynsimon/bild | blend/blend.go | Normal | func Normal(bg image.Image, fg image.Image) *image.RGBA {
dst := blend(bg, fg, func(c0, c1 fcolor.RGBAF64) fcolor.RGBAF64 {
return alphaComp(c0, c1)
})
return dst
} | go | func Normal(bg image.Image, fg image.Image) *image.RGBA {
dst := blend(bg, fg, func(c0, c1 fcolor.RGBAF64) fcolor.RGBAF64 {
return alphaComp(c0, c1)
})
return dst
} | [
"func",
"Normal",
"(",
"bg",
"image",
".",
"Image",
",",
"fg",
"image",
".",
"Image",
")",
"*",
"image",
".",
"RGBA",
"{",
"dst",
":=",
"blend",
"(",
"bg",
",",
"fg",
",",
"func",
"(",
"c0",
",",
"c1",
"fcolor",
".",
"RGBAF64",
")",
"fcolor",
".",
"RGBAF64",
"{",
"return",
"alphaComp",
"(",
"c0",
",",
"c1",
")",
"\n",
"}",
")",
"\n\n",
"return",
"dst",
"\n",
"}"
] | // Normal combines the foreground and background images by placing the foreground over the
// background using alpha compositing. The resulting image is then returned. | [
"Normal",
"combines",
"the",
"foreground",
"and",
"background",
"images",
"by",
"placing",
"the",
"foreground",
"over",
"the",
"background",
"using",
"alpha",
"compositing",
".",
"The",
"resulting",
"image",
"is",
"then",
"returned",
"."
] | 3a6867030b45db250c7619233c6056b46a980667 | https://github.com/anthonynsimon/bild/blob/3a6867030b45db250c7619233c6056b46a980667/blend/blend.go#L16-L22 |
153,352 | anthonynsimon/bild | blend/blend.go | Add | func Add(bg image.Image, fg image.Image) *image.RGBA {
dst := blend(bg, fg, func(c0, c1 fcolor.RGBAF64) fcolor.RGBAF64 {
r := c0.R + c1.R
g := c0.G + c1.G
b := c0.B + c1.B
c2 := fcolor.RGBAF64{R: r, G: g, B: b, A: c1.A}
return alphaComp(c0, c2)
})
return dst
} | go | func Add(bg image.Image, fg image.Image) *image.RGBA {
dst := blend(bg, fg, func(c0, c1 fcolor.RGBAF64) fcolor.RGBAF64 {
r := c0.R + c1.R
g := c0.G + c1.G
b := c0.B + c1.B
c2 := fcolor.RGBAF64{R: r, G: g, B: b, A: c1.A}
return alphaComp(c0, c2)
})
return dst
} | [
"func",
"Add",
"(",
"bg",
"image",
".",
"Image",
",",
"fg",
"image",
".",
"Image",
")",
"*",
"image",
".",
"RGBA",
"{",
"dst",
":=",
"blend",
"(",
"bg",
",",
"fg",
",",
"func",
"(",
"c0",
",",
"c1",
"fcolor",
".",
"RGBAF64",
")",
"fcolor",
".",
"RGBAF64",
"{",
"r",
":=",
"c0",
".",
"R",
"+",
"c1",
".",
"R",
"\n",
"g",
":=",
"c0",
".",
"G",
"+",
"c1",
".",
"G",
"\n",
"b",
":=",
"c0",
".",
"B",
"+",
"c1",
".",
"B",
"\n\n",
"c2",
":=",
"fcolor",
".",
"RGBAF64",
"{",
"R",
":",
"r",
",",
"G",
":",
"g",
",",
"B",
":",
"b",
",",
"A",
":",
"c1",
".",
"A",
"}",
"\n",
"return",
"alphaComp",
"(",
"c0",
",",
"c2",
")",
"\n",
"}",
")",
"\n\n",
"return",
"dst",
"\n",
"}"
] | // Add combines the foreground and background images by adding their values and
// returns the resulting image. | [
"Add",
"combines",
"the",
"foreground",
"and",
"background",
"images",
"by",
"adding",
"their",
"values",
"and",
"returns",
"the",
"resulting",
"image",
"."
] | 3a6867030b45db250c7619233c6056b46a980667 | https://github.com/anthonynsimon/bild/blob/3a6867030b45db250c7619233c6056b46a980667/blend/blend.go#L26-L37 |
153,353 | anthonynsimon/bild | blend/blend.go | Opacity | func Opacity(bg image.Image, fg image.Image, percent float64) *image.RGBA {
percent = f64.Clamp(percent, 0, 1.0)
dst := blend(bg, fg, func(c0, c1 fcolor.RGBAF64) fcolor.RGBAF64 {
r := c1.R*percent + (1-percent)*c0.R
g := c1.G*percent + (1-percent)*c0.G
b := c1.B*percent + (1-percent)*c0.B
c2 := fcolor.RGBAF64{R: r, G: g, B: b, A: c1.A}
return alphaComp(c0, c2)
})
return dst
} | go | func Opacity(bg image.Image, fg image.Image, percent float64) *image.RGBA {
percent = f64.Clamp(percent, 0, 1.0)
dst := blend(bg, fg, func(c0, c1 fcolor.RGBAF64) fcolor.RGBAF64 {
r := c1.R*percent + (1-percent)*c0.R
g := c1.G*percent + (1-percent)*c0.G
b := c1.B*percent + (1-percent)*c0.B
c2 := fcolor.RGBAF64{R: r, G: g, B: b, A: c1.A}
return alphaComp(c0, c2)
})
return dst
} | [
"func",
"Opacity",
"(",
"bg",
"image",
".",
"Image",
",",
"fg",
"image",
".",
"Image",
",",
"percent",
"float64",
")",
"*",
"image",
".",
"RGBA",
"{",
"percent",
"=",
"f64",
".",
"Clamp",
"(",
"percent",
",",
"0",
",",
"1.0",
")",
"\n\n",
"dst",
":=",
"blend",
"(",
"bg",
",",
"fg",
",",
"func",
"(",
"c0",
",",
"c1",
"fcolor",
".",
"RGBAF64",
")",
"fcolor",
".",
"RGBAF64",
"{",
"r",
":=",
"c1",
".",
"R",
"*",
"percent",
"+",
"(",
"1",
"-",
"percent",
")",
"*",
"c0",
".",
"R",
"\n",
"g",
":=",
"c1",
".",
"G",
"*",
"percent",
"+",
"(",
"1",
"-",
"percent",
")",
"*",
"c0",
".",
"G",
"\n",
"b",
":=",
"c1",
".",
"B",
"*",
"percent",
"+",
"(",
"1",
"-",
"percent",
")",
"*",
"c0",
".",
"B",
"\n\n",
"c2",
":=",
"fcolor",
".",
"RGBAF64",
"{",
"R",
":",
"r",
",",
"G",
":",
"g",
",",
"B",
":",
"b",
",",
"A",
":",
"c1",
".",
"A",
"}",
"\n",
"return",
"alphaComp",
"(",
"c0",
",",
"c2",
")",
"\n",
"}",
")",
"\n\n",
"return",
"dst",
"\n",
"}"
] | // Opacity returns an image which blends the two input images by the percentage provided.
// Percent must be of range 0 <= percent <= 1.0 | [
"Opacity",
"returns",
"an",
"image",
"which",
"blends",
"the",
"two",
"input",
"images",
"by",
"the",
"percentage",
"provided",
".",
"Percent",
"must",
"be",
"of",
"range",
"0",
"<",
"=",
"percent",
"<",
"=",
"1",
".",
"0"
] | 3a6867030b45db250c7619233c6056b46a980667 | https://github.com/anthonynsimon/bild/blob/3a6867030b45db250c7619233c6056b46a980667/blend/blend.go#L286-L299 |
153,354 | anthonynsimon/bild | blend/blend.go | blend | func blend(bg image.Image, fg image.Image, fn func(fcolor.RGBAF64, fcolor.RGBAF64) fcolor.RGBAF64) *image.RGBA {
bgBounds := bg.Bounds()
fgBounds := fg.Bounds()
var w, h int
if bgBounds.Dx() < fgBounds.Dx() {
w = bgBounds.Dx()
} else {
w = fgBounds.Dx()
}
if bgBounds.Dy() < fgBounds.Dy() {
h = bgBounds.Dy()
} else {
h = fgBounds.Dy()
}
bgSrc := clone.AsRGBA(bg)
fgSrc := clone.AsRGBA(fg)
dst := image.NewRGBA(image.Rect(0, 0, w, h))
parallel.Line(h, func(start, end int) {
for y := start; y < end; y++ {
for x := 0; x < w; x++ {
bgPos := y*bgSrc.Stride + x*4
fgPos := y*fgSrc.Stride + x*4
result := fn(
fcolor.NewRGBAF64(bgSrc.Pix[bgPos+0], bgSrc.Pix[bgPos+1], bgSrc.Pix[bgPos+2], bgSrc.Pix[bgPos+3]),
fcolor.NewRGBAF64(fgSrc.Pix[fgPos+0], fgSrc.Pix[fgPos+1], fgSrc.Pix[fgPos+2], fgSrc.Pix[fgPos+3]))
result.Clamp()
dstPos := y*dst.Stride + x*4
dst.Pix[dstPos+0] = uint8(result.R * 255)
dst.Pix[dstPos+1] = uint8(result.G * 255)
dst.Pix[dstPos+2] = uint8(result.B * 255)
dst.Pix[dstPos+3] = uint8(result.A * 255)
}
}
})
return dst
} | go | func blend(bg image.Image, fg image.Image, fn func(fcolor.RGBAF64, fcolor.RGBAF64) fcolor.RGBAF64) *image.RGBA {
bgBounds := bg.Bounds()
fgBounds := fg.Bounds()
var w, h int
if bgBounds.Dx() < fgBounds.Dx() {
w = bgBounds.Dx()
} else {
w = fgBounds.Dx()
}
if bgBounds.Dy() < fgBounds.Dy() {
h = bgBounds.Dy()
} else {
h = fgBounds.Dy()
}
bgSrc := clone.AsRGBA(bg)
fgSrc := clone.AsRGBA(fg)
dst := image.NewRGBA(image.Rect(0, 0, w, h))
parallel.Line(h, func(start, end int) {
for y := start; y < end; y++ {
for x := 0; x < w; x++ {
bgPos := y*bgSrc.Stride + x*4
fgPos := y*fgSrc.Stride + x*4
result := fn(
fcolor.NewRGBAF64(bgSrc.Pix[bgPos+0], bgSrc.Pix[bgPos+1], bgSrc.Pix[bgPos+2], bgSrc.Pix[bgPos+3]),
fcolor.NewRGBAF64(fgSrc.Pix[fgPos+0], fgSrc.Pix[fgPos+1], fgSrc.Pix[fgPos+2], fgSrc.Pix[fgPos+3]))
result.Clamp()
dstPos := y*dst.Stride + x*4
dst.Pix[dstPos+0] = uint8(result.R * 255)
dst.Pix[dstPos+1] = uint8(result.G * 255)
dst.Pix[dstPos+2] = uint8(result.B * 255)
dst.Pix[dstPos+3] = uint8(result.A * 255)
}
}
})
return dst
} | [
"func",
"blend",
"(",
"bg",
"image",
".",
"Image",
",",
"fg",
"image",
".",
"Image",
",",
"fn",
"func",
"(",
"fcolor",
".",
"RGBAF64",
",",
"fcolor",
".",
"RGBAF64",
")",
"fcolor",
".",
"RGBAF64",
")",
"*",
"image",
".",
"RGBA",
"{",
"bgBounds",
":=",
"bg",
".",
"Bounds",
"(",
")",
"\n",
"fgBounds",
":=",
"fg",
".",
"Bounds",
"(",
")",
"\n\n",
"var",
"w",
",",
"h",
"int",
"\n",
"if",
"bgBounds",
".",
"Dx",
"(",
")",
"<",
"fgBounds",
".",
"Dx",
"(",
")",
"{",
"w",
"=",
"bgBounds",
".",
"Dx",
"(",
")",
"\n",
"}",
"else",
"{",
"w",
"=",
"fgBounds",
".",
"Dx",
"(",
")",
"\n",
"}",
"\n",
"if",
"bgBounds",
".",
"Dy",
"(",
")",
"<",
"fgBounds",
".",
"Dy",
"(",
")",
"{",
"h",
"=",
"bgBounds",
".",
"Dy",
"(",
")",
"\n",
"}",
"else",
"{",
"h",
"=",
"fgBounds",
".",
"Dy",
"(",
")",
"\n",
"}",
"\n\n",
"bgSrc",
":=",
"clone",
".",
"AsRGBA",
"(",
"bg",
")",
"\n",
"fgSrc",
":=",
"clone",
".",
"AsRGBA",
"(",
"fg",
")",
"\n",
"dst",
":=",
"image",
".",
"NewRGBA",
"(",
"image",
".",
"Rect",
"(",
"0",
",",
"0",
",",
"w",
",",
"h",
")",
")",
"\n\n",
"parallel",
".",
"Line",
"(",
"h",
",",
"func",
"(",
"start",
",",
"end",
"int",
")",
"{",
"for",
"y",
":=",
"start",
";",
"y",
"<",
"end",
";",
"y",
"++",
"{",
"for",
"x",
":=",
"0",
";",
"x",
"<",
"w",
";",
"x",
"++",
"{",
"bgPos",
":=",
"y",
"*",
"bgSrc",
".",
"Stride",
"+",
"x",
"*",
"4",
"\n",
"fgPos",
":=",
"y",
"*",
"fgSrc",
".",
"Stride",
"+",
"x",
"*",
"4",
"\n",
"result",
":=",
"fn",
"(",
"fcolor",
".",
"NewRGBAF64",
"(",
"bgSrc",
".",
"Pix",
"[",
"bgPos",
"+",
"0",
"]",
",",
"bgSrc",
".",
"Pix",
"[",
"bgPos",
"+",
"1",
"]",
",",
"bgSrc",
".",
"Pix",
"[",
"bgPos",
"+",
"2",
"]",
",",
"bgSrc",
".",
"Pix",
"[",
"bgPos",
"+",
"3",
"]",
")",
",",
"fcolor",
".",
"NewRGBAF64",
"(",
"fgSrc",
".",
"Pix",
"[",
"fgPos",
"+",
"0",
"]",
",",
"fgSrc",
".",
"Pix",
"[",
"fgPos",
"+",
"1",
"]",
",",
"fgSrc",
".",
"Pix",
"[",
"fgPos",
"+",
"2",
"]",
",",
"fgSrc",
".",
"Pix",
"[",
"fgPos",
"+",
"3",
"]",
")",
")",
"\n\n",
"result",
".",
"Clamp",
"(",
")",
"\n",
"dstPos",
":=",
"y",
"*",
"dst",
".",
"Stride",
"+",
"x",
"*",
"4",
"\n",
"dst",
".",
"Pix",
"[",
"dstPos",
"+",
"0",
"]",
"=",
"uint8",
"(",
"result",
".",
"R",
"*",
"255",
")",
"\n",
"dst",
".",
"Pix",
"[",
"dstPos",
"+",
"1",
"]",
"=",
"uint8",
"(",
"result",
".",
"G",
"*",
"255",
")",
"\n",
"dst",
".",
"Pix",
"[",
"dstPos",
"+",
"2",
"]",
"=",
"uint8",
"(",
"result",
".",
"B",
"*",
"255",
")",
"\n",
"dst",
".",
"Pix",
"[",
"dstPos",
"+",
"3",
"]",
"=",
"uint8",
"(",
"result",
".",
"A",
"*",
"255",
")",
"\n",
"}",
"\n\n",
"}",
"\n",
"}",
")",
"\n\n",
"return",
"dst",
"\n",
"}"
] | // Blend two images together by applying the provided function for each pixel.
// If images differ in size, the minimum width and height will be picked from each one
// when creating the resulting image. | [
"Blend",
"two",
"images",
"together",
"by",
"applying",
"the",
"provided",
"function",
"for",
"each",
"pixel",
".",
"If",
"images",
"differ",
"in",
"size",
"the",
"minimum",
"width",
"and",
"height",
"will",
"be",
"picked",
"from",
"each",
"one",
"when",
"creating",
"the",
"resulting",
"image",
"."
] | 3a6867030b45db250c7619233c6056b46a980667 | https://github.com/anthonynsimon/bild/blob/3a6867030b45db250c7619233c6056b46a980667/blend/blend.go#L334-L375 |
153,355 | anthonynsimon/bild | blend/blend.go | alphaComp | func alphaComp(bg, fg fcolor.RGBAF64) fcolor.RGBAF64 {
fg.Clamp()
fga := fg.A
r := (fg.R * fga / 1) + ((1 - fga) * bg.R / 1)
g := (fg.G * fga / 1) + ((1 - fga) * bg.G / 1)
b := (fg.B * fga / 1) + ((1 - fga) * bg.B / 1)
a := bg.A + fga
return fcolor.RGBAF64{R: r, G: g, B: b, A: a}
} | go | func alphaComp(bg, fg fcolor.RGBAF64) fcolor.RGBAF64 {
fg.Clamp()
fga := fg.A
r := (fg.R * fga / 1) + ((1 - fga) * bg.R / 1)
g := (fg.G * fga / 1) + ((1 - fga) * bg.G / 1)
b := (fg.B * fga / 1) + ((1 - fga) * bg.B / 1)
a := bg.A + fga
return fcolor.RGBAF64{R: r, G: g, B: b, A: a}
} | [
"func",
"alphaComp",
"(",
"bg",
",",
"fg",
"fcolor",
".",
"RGBAF64",
")",
"fcolor",
".",
"RGBAF64",
"{",
"fg",
".",
"Clamp",
"(",
")",
"\n",
"fga",
":=",
"fg",
".",
"A",
"\n\n",
"r",
":=",
"(",
"fg",
".",
"R",
"*",
"fga",
"/",
"1",
")",
"+",
"(",
"(",
"1",
"-",
"fga",
")",
"*",
"bg",
".",
"R",
"/",
"1",
")",
"\n",
"g",
":=",
"(",
"fg",
".",
"G",
"*",
"fga",
"/",
"1",
")",
"+",
"(",
"(",
"1",
"-",
"fga",
")",
"*",
"bg",
".",
"G",
"/",
"1",
")",
"\n",
"b",
":=",
"(",
"fg",
".",
"B",
"*",
"fga",
"/",
"1",
")",
"+",
"(",
"(",
"1",
"-",
"fga",
")",
"*",
"bg",
".",
"B",
"/",
"1",
")",
"\n",
"a",
":=",
"bg",
".",
"A",
"+",
"fga",
"\n\n",
"return",
"fcolor",
".",
"RGBAF64",
"{",
"R",
":",
"r",
",",
"G",
":",
"g",
",",
"B",
":",
"b",
",",
"A",
":",
"a",
"}",
"\n",
"}"
] | // alphaComp returns a new color after compositing the two colors
// based on the foreground's alpha channel. | [
"alphaComp",
"returns",
"a",
"new",
"color",
"after",
"compositing",
"the",
"two",
"colors",
"based",
"on",
"the",
"foreground",
"s",
"alpha",
"channel",
"."
] | 3a6867030b45db250c7619233c6056b46a980667 | https://github.com/anthonynsimon/bild/blob/3a6867030b45db250c7619233c6056b46a980667/blend/blend.go#L379-L389 |
153,356 | anthonynsimon/bild | adjust/adjustment.go | Gamma | func Gamma(src image.Image, gamma float64) *image.RGBA {
gamma = math.Max(0.00001, gamma)
lookup := make([]uint8, 256)
for i := 0; i < 256; i++ {
lookup[i] = uint8(f64.Clamp(math.Pow(float64(i)/255, 1.0/gamma)*255, 0, 255))
}
fn := func(c color.RGBA) color.RGBA {
return color.RGBA{lookup[c.R], lookup[c.G], lookup[c.B], c.A}
}
img := Apply(src, fn)
return img
} | go | func Gamma(src image.Image, gamma float64) *image.RGBA {
gamma = math.Max(0.00001, gamma)
lookup := make([]uint8, 256)
for i := 0; i < 256; i++ {
lookup[i] = uint8(f64.Clamp(math.Pow(float64(i)/255, 1.0/gamma)*255, 0, 255))
}
fn := func(c color.RGBA) color.RGBA {
return color.RGBA{lookup[c.R], lookup[c.G], lookup[c.B], c.A}
}
img := Apply(src, fn)
return img
} | [
"func",
"Gamma",
"(",
"src",
"image",
".",
"Image",
",",
"gamma",
"float64",
")",
"*",
"image",
".",
"RGBA",
"{",
"gamma",
"=",
"math",
".",
"Max",
"(",
"0.00001",
",",
"gamma",
")",
"\n\n",
"lookup",
":=",
"make",
"(",
"[",
"]",
"uint8",
",",
"256",
")",
"\n\n",
"for",
"i",
":=",
"0",
";",
"i",
"<",
"256",
";",
"i",
"++",
"{",
"lookup",
"[",
"i",
"]",
"=",
"uint8",
"(",
"f64",
".",
"Clamp",
"(",
"math",
".",
"Pow",
"(",
"float64",
"(",
"i",
")",
"/",
"255",
",",
"1.0",
"/",
"gamma",
")",
"*",
"255",
",",
"0",
",",
"255",
")",
")",
"\n",
"}",
"\n\n",
"fn",
":=",
"func",
"(",
"c",
"color",
".",
"RGBA",
")",
"color",
".",
"RGBA",
"{",
"return",
"color",
".",
"RGBA",
"{",
"lookup",
"[",
"c",
".",
"R",
"]",
",",
"lookup",
"[",
"c",
".",
"G",
"]",
",",
"lookup",
"[",
"c",
".",
"B",
"]",
",",
"c",
".",
"A",
"}",
"\n",
"}",
"\n\n",
"img",
":=",
"Apply",
"(",
"src",
",",
"fn",
")",
"\n\n",
"return",
"img",
"\n",
"}"
] | // Gamma returns a gamma corrected copy of the image. Provided gamma param must be larger than 0. | [
"Gamma",
"returns",
"a",
"gamma",
"corrected",
"copy",
"of",
"the",
"image",
".",
"Provided",
"gamma",
"param",
"must",
"be",
"larger",
"than",
"0",
"."
] | 3a6867030b45db250c7619233c6056b46a980667 | https://github.com/anthonynsimon/bild/blob/3a6867030b45db250c7619233c6056b46a980667/adjust/adjustment.go#L32-L48 |
153,357 | anthonynsimon/bild | adjust/adjustment.go | Hue | func Hue(img image.Image, change int) *image.RGBA {
fn := func(c color.RGBA) color.RGBA {
h, s, l := util.RGBToHSL(c)
h = float64((int(h) + change) % 360)
outColor := util.HSLToRGB(h, s, l)
outColor.A = c.A
return outColor
}
return Apply(img, fn)
} | go | func Hue(img image.Image, change int) *image.RGBA {
fn := func(c color.RGBA) color.RGBA {
h, s, l := util.RGBToHSL(c)
h = float64((int(h) + change) % 360)
outColor := util.HSLToRGB(h, s, l)
outColor.A = c.A
return outColor
}
return Apply(img, fn)
} | [
"func",
"Hue",
"(",
"img",
"image",
".",
"Image",
",",
"change",
"int",
")",
"*",
"image",
".",
"RGBA",
"{",
"fn",
":=",
"func",
"(",
"c",
"color",
".",
"RGBA",
")",
"color",
".",
"RGBA",
"{",
"h",
",",
"s",
",",
"l",
":=",
"util",
".",
"RGBToHSL",
"(",
"c",
")",
"\n",
"h",
"=",
"float64",
"(",
"(",
"int",
"(",
"h",
")",
"+",
"change",
")",
"%",
"360",
")",
"\n",
"outColor",
":=",
"util",
".",
"HSLToRGB",
"(",
"h",
",",
"s",
",",
"l",
")",
"\n",
"outColor",
".",
"A",
"=",
"c",
".",
"A",
"\n",
"return",
"outColor",
"\n",
"}",
"\n\n",
"return",
"Apply",
"(",
"img",
",",
"fn",
")",
"\n",
"}"
] | // Hue adjusts the overall hue of the provided image and returns the result.
// Parameter change is the amount of change to be applied and is of the range
// -360 to 360. It corresponds to the hue angle in the HSL color model. | [
"Hue",
"adjusts",
"the",
"overall",
"hue",
"of",
"the",
"provided",
"image",
"and",
"returns",
"the",
"result",
".",
"Parameter",
"change",
"is",
"the",
"amount",
"of",
"change",
"to",
"be",
"applied",
"and",
"is",
"of",
"the",
"range",
"-",
"360",
"to",
"360",
".",
"It",
"corresponds",
"to",
"the",
"hue",
"angle",
"in",
"the",
"HSL",
"color",
"model",
"."
] | 3a6867030b45db250c7619233c6056b46a980667 | https://github.com/anthonynsimon/bild/blob/3a6867030b45db250c7619233c6056b46a980667/adjust/adjustment.go#L72-L82 |
153,358 | anthonynsimon/bild | clone/clone.go | AsRGBA | func AsRGBA(src image.Image) *image.RGBA {
bounds := src.Bounds()
img := image.NewRGBA(bounds)
draw.Draw(img, bounds, src, bounds.Min, draw.Src)
return img
} | go | func AsRGBA(src image.Image) *image.RGBA {
bounds := src.Bounds()
img := image.NewRGBA(bounds)
draw.Draw(img, bounds, src, bounds.Min, draw.Src)
return img
} | [
"func",
"AsRGBA",
"(",
"src",
"image",
".",
"Image",
")",
"*",
"image",
".",
"RGBA",
"{",
"bounds",
":=",
"src",
".",
"Bounds",
"(",
")",
"\n",
"img",
":=",
"image",
".",
"NewRGBA",
"(",
"bounds",
")",
"\n",
"draw",
".",
"Draw",
"(",
"img",
",",
"bounds",
",",
"src",
",",
"bounds",
".",
"Min",
",",
"draw",
".",
"Src",
")",
"\n",
"return",
"img",
"\n",
"}"
] | // AsRGBA returns an RGBA copy of the supplied image. | [
"AsRGBA",
"returns",
"an",
"RGBA",
"copy",
"of",
"the",
"supplied",
"image",
"."
] | 3a6867030b45db250c7619233c6056b46a980667 | https://github.com/anthonynsimon/bild/blob/3a6867030b45db250c7619233c6056b46a980667/clone/clone.go#L24-L29 |
153,359 | anthonynsimon/bild | adjust/apply.go | Apply | func Apply(img image.Image, fn func(color.RGBA) color.RGBA) *image.RGBA {
bounds := img.Bounds()
dst := clone.AsRGBA(img)
w, h := bounds.Dx(), bounds.Dy()
parallel.Line(h, func(start, end int) {
for y := start; y < end; y++ {
for x := 0; x < w; x++ {
dstPos := y*dst.Stride + x*4
c := color.RGBA{}
c.R = dst.Pix[dstPos+0]
c.G = dst.Pix[dstPos+1]
c.B = dst.Pix[dstPos+2]
c.A = dst.Pix[dstPos+3]
c = fn(c)
dst.Pix[dstPos+0] = c.R
dst.Pix[dstPos+1] = c.G
dst.Pix[dstPos+2] = c.B
dst.Pix[dstPos+3] = c.A
}
}
})
return dst
} | go | func Apply(img image.Image, fn func(color.RGBA) color.RGBA) *image.RGBA {
bounds := img.Bounds()
dst := clone.AsRGBA(img)
w, h := bounds.Dx(), bounds.Dy()
parallel.Line(h, func(start, end int) {
for y := start; y < end; y++ {
for x := 0; x < w; x++ {
dstPos := y*dst.Stride + x*4
c := color.RGBA{}
c.R = dst.Pix[dstPos+0]
c.G = dst.Pix[dstPos+1]
c.B = dst.Pix[dstPos+2]
c.A = dst.Pix[dstPos+3]
c = fn(c)
dst.Pix[dstPos+0] = c.R
dst.Pix[dstPos+1] = c.G
dst.Pix[dstPos+2] = c.B
dst.Pix[dstPos+3] = c.A
}
}
})
return dst
} | [
"func",
"Apply",
"(",
"img",
"image",
".",
"Image",
",",
"fn",
"func",
"(",
"color",
".",
"RGBA",
")",
"color",
".",
"RGBA",
")",
"*",
"image",
".",
"RGBA",
"{",
"bounds",
":=",
"img",
".",
"Bounds",
"(",
")",
"\n",
"dst",
":=",
"clone",
".",
"AsRGBA",
"(",
"img",
")",
"\n",
"w",
",",
"h",
":=",
"bounds",
".",
"Dx",
"(",
")",
",",
"bounds",
".",
"Dy",
"(",
")",
"\n\n",
"parallel",
".",
"Line",
"(",
"h",
",",
"func",
"(",
"start",
",",
"end",
"int",
")",
"{",
"for",
"y",
":=",
"start",
";",
"y",
"<",
"end",
";",
"y",
"++",
"{",
"for",
"x",
":=",
"0",
";",
"x",
"<",
"w",
";",
"x",
"++",
"{",
"dstPos",
":=",
"y",
"*",
"dst",
".",
"Stride",
"+",
"x",
"*",
"4",
"\n\n",
"c",
":=",
"color",
".",
"RGBA",
"{",
"}",
"\n\n",
"c",
".",
"R",
"=",
"dst",
".",
"Pix",
"[",
"dstPos",
"+",
"0",
"]",
"\n",
"c",
".",
"G",
"=",
"dst",
".",
"Pix",
"[",
"dstPos",
"+",
"1",
"]",
"\n",
"c",
".",
"B",
"=",
"dst",
".",
"Pix",
"[",
"dstPos",
"+",
"2",
"]",
"\n",
"c",
".",
"A",
"=",
"dst",
".",
"Pix",
"[",
"dstPos",
"+",
"3",
"]",
"\n\n",
"c",
"=",
"fn",
"(",
"c",
")",
"\n\n",
"dst",
".",
"Pix",
"[",
"dstPos",
"+",
"0",
"]",
"=",
"c",
".",
"R",
"\n",
"dst",
".",
"Pix",
"[",
"dstPos",
"+",
"1",
"]",
"=",
"c",
".",
"G",
"\n",
"dst",
".",
"Pix",
"[",
"dstPos",
"+",
"2",
"]",
"=",
"c",
".",
"B",
"\n",
"dst",
".",
"Pix",
"[",
"dstPos",
"+",
"3",
"]",
"=",
"c",
".",
"A",
"\n",
"}",
"\n",
"}",
"\n",
"}",
")",
"\n\n",
"return",
"dst",
"\n",
"}"
] | // Apply returns a copy of the provided image after applying the provided color function to each pixel. | [
"Apply",
"returns",
"a",
"copy",
"of",
"the",
"provided",
"image",
"after",
"applying",
"the",
"provided",
"color",
"function",
"to",
"each",
"pixel",
"."
] | 3a6867030b45db250c7619233c6056b46a980667 | https://github.com/anthonynsimon/bild/blob/3a6867030b45db250c7619233c6056b46a980667/adjust/apply.go#L12-L40 |
153,360 | anthonynsimon/bild | util/colormodel.go | RGBToHSL | func RGBToHSL(c color.RGBA) (float64, float64, float64) {
r, g, b := float64(c.R)/255, float64(c.G)/255, float64(c.B)/255
max := math.Max(r, math.Max(g, b))
min := math.Min(r, math.Min(g, b))
delta := max - min
var h, s, l float64
l = (max + min) / 2
// Achromatic
if delta <= 0 {
return h, s, l
}
// Should it be smaller than or equals instead?
if l < 0.5 {
s = delta / (max + min)
} else {
s = delta / (2 - max - min)
}
if r >= max {
h = (g - b) / delta
} else if g >= max {
h = (b-r)/delta + 2
} else {
h = (r-g)/delta + 4
}
h *= 60
if h < 0 {
h += 360
}
return h, s, l
} | go | func RGBToHSL(c color.RGBA) (float64, float64, float64) {
r, g, b := float64(c.R)/255, float64(c.G)/255, float64(c.B)/255
max := math.Max(r, math.Max(g, b))
min := math.Min(r, math.Min(g, b))
delta := max - min
var h, s, l float64
l = (max + min) / 2
// Achromatic
if delta <= 0 {
return h, s, l
}
// Should it be smaller than or equals instead?
if l < 0.5 {
s = delta / (max + min)
} else {
s = delta / (2 - max - min)
}
if r >= max {
h = (g - b) / delta
} else if g >= max {
h = (b-r)/delta + 2
} else {
h = (r-g)/delta + 4
}
h *= 60
if h < 0 {
h += 360
}
return h, s, l
} | [
"func",
"RGBToHSL",
"(",
"c",
"color",
".",
"RGBA",
")",
"(",
"float64",
",",
"float64",
",",
"float64",
")",
"{",
"r",
",",
"g",
",",
"b",
":=",
"float64",
"(",
"c",
".",
"R",
")",
"/",
"255",
",",
"float64",
"(",
"c",
".",
"G",
")",
"/",
"255",
",",
"float64",
"(",
"c",
".",
"B",
")",
"/",
"255",
"\n",
"max",
":=",
"math",
".",
"Max",
"(",
"r",
",",
"math",
".",
"Max",
"(",
"g",
",",
"b",
")",
")",
"\n",
"min",
":=",
"math",
".",
"Min",
"(",
"r",
",",
"math",
".",
"Min",
"(",
"g",
",",
"b",
")",
")",
"\n",
"delta",
":=",
"max",
"-",
"min",
"\n\n",
"var",
"h",
",",
"s",
",",
"l",
"float64",
"\n",
"l",
"=",
"(",
"max",
"+",
"min",
")",
"/",
"2",
"\n\n",
"// Achromatic",
"if",
"delta",
"<=",
"0",
"{",
"return",
"h",
",",
"s",
",",
"l",
"\n",
"}",
"\n\n",
"// Should it be smaller than or equals instead?",
"if",
"l",
"<",
"0.5",
"{",
"s",
"=",
"delta",
"/",
"(",
"max",
"+",
"min",
")",
"\n",
"}",
"else",
"{",
"s",
"=",
"delta",
"/",
"(",
"2",
"-",
"max",
"-",
"min",
")",
"\n",
"}",
"\n\n",
"if",
"r",
">=",
"max",
"{",
"h",
"=",
"(",
"g",
"-",
"b",
")",
"/",
"delta",
"\n",
"}",
"else",
"if",
"g",
">=",
"max",
"{",
"h",
"=",
"(",
"b",
"-",
"r",
")",
"/",
"delta",
"+",
"2",
"\n",
"}",
"else",
"{",
"h",
"=",
"(",
"r",
"-",
"g",
")",
"/",
"delta",
"+",
"4",
"\n",
"}",
"\n\n",
"h",
"*=",
"60",
"\n",
"if",
"h",
"<",
"0",
"{",
"h",
"+=",
"360",
"\n",
"}",
"\n\n",
"return",
"h",
",",
"s",
",",
"l",
"\n",
"}"
] | // RGBToHSL converts from RGB to HSL color model.
// Parameter c is the RGBA color and must implement the color.RGBA interface.
// Returned values h, s and l correspond to the hue, saturation and lightness.
// The hue is of range 0 to 360 and the saturation and lightness are of range 0.0 to 1.0. | [
"RGBToHSL",
"converts",
"from",
"RGB",
"to",
"HSL",
"color",
"model",
".",
"Parameter",
"c",
"is",
"the",
"RGBA",
"color",
"and",
"must",
"implement",
"the",
"color",
".",
"RGBA",
"interface",
".",
"Returned",
"values",
"h",
"s",
"and",
"l",
"correspond",
"to",
"the",
"hue",
"saturation",
"and",
"lightness",
".",
"The",
"hue",
"is",
"of",
"range",
"0",
"to",
"360",
"and",
"the",
"saturation",
"and",
"lightness",
"are",
"of",
"range",
"0",
".",
"0",
"to",
"1",
".",
"0",
"."
] | 3a6867030b45db250c7619233c6056b46a980667 | https://github.com/anthonynsimon/bild/blob/3a6867030b45db250c7619233c6056b46a980667/util/colormodel.go#L14-L49 |
153,361 | anthonynsimon/bild | util/colormodel.go | HSLToRGB | func HSLToRGB(h, s, l float64) color.RGBA {
var r, g, b float64
if s == 0 {
r = l
g = l
b = l
} else {
var temp0, temp1 float64
if l < 0.5 {
temp0 = l * (1 + s)
} else {
temp0 = (l + s) - (s * l)
}
temp1 = 2*l - temp0
h /= 360
hueFn := func(v float64) float64 {
if v < 0 {
v++
} else if v > 1 {
v--
}
if v < 1.0/6.0 {
return temp1 + (temp0-temp1)*6*v
}
if v < 1.0/2.0 {
return temp0
}
if v < 2.0/3.0 {
return temp1 + (temp0-temp1)*(2.0/3.0-v)*6
}
return temp1
}
r = hueFn(h + 1.0/3.0)
g = hueFn(h)
b = hueFn(h - 1.0/3.0)
}
outR := uint8(f64.Clamp(r*255+0.5, 0, 255))
outG := uint8(f64.Clamp(g*255+0.5, 0, 255))
outB := uint8(f64.Clamp(b*255+0.5, 0, 255))
return color.RGBA{outR, outG, outB, 0xFF}
} | go | func HSLToRGB(h, s, l float64) color.RGBA {
var r, g, b float64
if s == 0 {
r = l
g = l
b = l
} else {
var temp0, temp1 float64
if l < 0.5 {
temp0 = l * (1 + s)
} else {
temp0 = (l + s) - (s * l)
}
temp1 = 2*l - temp0
h /= 360
hueFn := func(v float64) float64 {
if v < 0 {
v++
} else if v > 1 {
v--
}
if v < 1.0/6.0 {
return temp1 + (temp0-temp1)*6*v
}
if v < 1.0/2.0 {
return temp0
}
if v < 2.0/3.0 {
return temp1 + (temp0-temp1)*(2.0/3.0-v)*6
}
return temp1
}
r = hueFn(h + 1.0/3.0)
g = hueFn(h)
b = hueFn(h - 1.0/3.0)
}
outR := uint8(f64.Clamp(r*255+0.5, 0, 255))
outG := uint8(f64.Clamp(g*255+0.5, 0, 255))
outB := uint8(f64.Clamp(b*255+0.5, 0, 255))
return color.RGBA{outR, outG, outB, 0xFF}
} | [
"func",
"HSLToRGB",
"(",
"h",
",",
"s",
",",
"l",
"float64",
")",
"color",
".",
"RGBA",
"{",
"var",
"r",
",",
"g",
",",
"b",
"float64",
"\n",
"if",
"s",
"==",
"0",
"{",
"r",
"=",
"l",
"\n",
"g",
"=",
"l",
"\n",
"b",
"=",
"l",
"\n",
"}",
"else",
"{",
"var",
"temp0",
",",
"temp1",
"float64",
"\n",
"if",
"l",
"<",
"0.5",
"{",
"temp0",
"=",
"l",
"*",
"(",
"1",
"+",
"s",
")",
"\n",
"}",
"else",
"{",
"temp0",
"=",
"(",
"l",
"+",
"s",
")",
"-",
"(",
"s",
"*",
"l",
")",
"\n",
"}",
"\n",
"temp1",
"=",
"2",
"*",
"l",
"-",
"temp0",
"\n\n",
"h",
"/=",
"360",
"\n\n",
"hueFn",
":=",
"func",
"(",
"v",
"float64",
")",
"float64",
"{",
"if",
"v",
"<",
"0",
"{",
"v",
"++",
"\n",
"}",
"else",
"if",
"v",
">",
"1",
"{",
"v",
"--",
"\n",
"}",
"\n\n",
"if",
"v",
"<",
"1.0",
"/",
"6.0",
"{",
"return",
"temp1",
"+",
"(",
"temp0",
"-",
"temp1",
")",
"*",
"6",
"*",
"v",
"\n",
"}",
"\n",
"if",
"v",
"<",
"1.0",
"/",
"2.0",
"{",
"return",
"temp0",
"\n",
"}",
"\n",
"if",
"v",
"<",
"2.0",
"/",
"3.0",
"{",
"return",
"temp1",
"+",
"(",
"temp0",
"-",
"temp1",
")",
"*",
"(",
"2.0",
"/",
"3.0",
"-",
"v",
")",
"*",
"6",
"\n",
"}",
"\n",
"return",
"temp1",
"\n",
"}",
"\n\n",
"r",
"=",
"hueFn",
"(",
"h",
"+",
"1.0",
"/",
"3.0",
")",
"\n",
"g",
"=",
"hueFn",
"(",
"h",
")",
"\n",
"b",
"=",
"hueFn",
"(",
"h",
"-",
"1.0",
"/",
"3.0",
")",
"\n\n",
"}",
"\n\n",
"outR",
":=",
"uint8",
"(",
"f64",
".",
"Clamp",
"(",
"r",
"*",
"255",
"+",
"0.5",
",",
"0",
",",
"255",
")",
")",
"\n",
"outG",
":=",
"uint8",
"(",
"f64",
".",
"Clamp",
"(",
"g",
"*",
"255",
"+",
"0.5",
",",
"0",
",",
"255",
")",
")",
"\n",
"outB",
":=",
"uint8",
"(",
"f64",
".",
"Clamp",
"(",
"b",
"*",
"255",
"+",
"0.5",
",",
"0",
",",
"255",
")",
")",
"\n\n",
"return",
"color",
".",
"RGBA",
"{",
"outR",
",",
"outG",
",",
"outB",
",",
"0xFF",
"}",
"\n",
"}"
] | // HSLToRGB converts from HSL to RGB color model.
// Parameter h is the hue and its range is from 0 to 360 degrees.
// Parameter s is the saturation and its range is from 0.0 to 1.0.
// Parameter l is the lightness and its range is from 0.0 to 1.0. | [
"HSLToRGB",
"converts",
"from",
"HSL",
"to",
"RGB",
"color",
"model",
".",
"Parameter",
"h",
"is",
"the",
"hue",
"and",
"its",
"range",
"is",
"from",
"0",
"to",
"360",
"degrees",
".",
"Parameter",
"s",
"is",
"the",
"saturation",
"and",
"its",
"range",
"is",
"from",
"0",
".",
"0",
"to",
"1",
".",
"0",
".",
"Parameter",
"l",
"is",
"the",
"lightness",
"and",
"its",
"range",
"is",
"from",
"0",
".",
"0",
"to",
"1",
".",
"0",
"."
] | 3a6867030b45db250c7619233c6056b46a980667 | https://github.com/anthonynsimon/bild/blob/3a6867030b45db250c7619233c6056b46a980667/util/colormodel.go#L55-L103 |
153,362 | anthonynsimon/bild | util/colormodel.go | HSVToRGB | func HSVToRGB(h, s, v float64) color.RGBA {
var i, f, p, q, t float64
// Achromatic
if s == 0 {
outV := uint8(f64.Clamp(v*255+0.5, 0, 255))
return color.RGBA{outV, outV, outV, 0xFF}
}
h /= 60
i = math.Floor(h)
f = h - i
p = v * (1 - s)
q = v * (1 - s*f)
t = v * (1 - s*(1-f))
var r, g, b float64
switch i {
case 0:
r = v
g = t
b = p
case 1:
r = q
g = v
b = p
case 2:
r = p
g = v
b = t
case 3:
r = p
g = q
b = v
case 4:
r = t
g = p
b = v
default:
r = v
g = p
b = q
}
outR := uint8(f64.Clamp(r*255+0.5, 0, 255))
outG := uint8(f64.Clamp(g*255+0.5, 0, 255))
outB := uint8(f64.Clamp(b*255+0.5, 0, 255))
return color.RGBA{outR, outG, outB, 0xFF}
} | go | func HSVToRGB(h, s, v float64) color.RGBA {
var i, f, p, q, t float64
// Achromatic
if s == 0 {
outV := uint8(f64.Clamp(v*255+0.5, 0, 255))
return color.RGBA{outV, outV, outV, 0xFF}
}
h /= 60
i = math.Floor(h)
f = h - i
p = v * (1 - s)
q = v * (1 - s*f)
t = v * (1 - s*(1-f))
var r, g, b float64
switch i {
case 0:
r = v
g = t
b = p
case 1:
r = q
g = v
b = p
case 2:
r = p
g = v
b = t
case 3:
r = p
g = q
b = v
case 4:
r = t
g = p
b = v
default:
r = v
g = p
b = q
}
outR := uint8(f64.Clamp(r*255+0.5, 0, 255))
outG := uint8(f64.Clamp(g*255+0.5, 0, 255))
outB := uint8(f64.Clamp(b*255+0.5, 0, 255))
return color.RGBA{outR, outG, outB, 0xFF}
} | [
"func",
"HSVToRGB",
"(",
"h",
",",
"s",
",",
"v",
"float64",
")",
"color",
".",
"RGBA",
"{",
"var",
"i",
",",
"f",
",",
"p",
",",
"q",
",",
"t",
"float64",
"\n\n",
"// Achromatic",
"if",
"s",
"==",
"0",
"{",
"outV",
":=",
"uint8",
"(",
"f64",
".",
"Clamp",
"(",
"v",
"*",
"255",
"+",
"0.5",
",",
"0",
",",
"255",
")",
")",
"\n",
"return",
"color",
".",
"RGBA",
"{",
"outV",
",",
"outV",
",",
"outV",
",",
"0xFF",
"}",
"\n",
"}",
"\n\n",
"h",
"/=",
"60",
"\n",
"i",
"=",
"math",
".",
"Floor",
"(",
"h",
")",
"\n",
"f",
"=",
"h",
"-",
"i",
"\n",
"p",
"=",
"v",
"*",
"(",
"1",
"-",
"s",
")",
"\n",
"q",
"=",
"v",
"*",
"(",
"1",
"-",
"s",
"*",
"f",
")",
"\n",
"t",
"=",
"v",
"*",
"(",
"1",
"-",
"s",
"*",
"(",
"1",
"-",
"f",
")",
")",
"\n\n",
"var",
"r",
",",
"g",
",",
"b",
"float64",
"\n",
"switch",
"i",
"{",
"case",
"0",
":",
"r",
"=",
"v",
"\n",
"g",
"=",
"t",
"\n",
"b",
"=",
"p",
"\n",
"case",
"1",
":",
"r",
"=",
"q",
"\n",
"g",
"=",
"v",
"\n",
"b",
"=",
"p",
"\n",
"case",
"2",
":",
"r",
"=",
"p",
"\n",
"g",
"=",
"v",
"\n",
"b",
"=",
"t",
"\n",
"case",
"3",
":",
"r",
"=",
"p",
"\n",
"g",
"=",
"q",
"\n",
"b",
"=",
"v",
"\n",
"case",
"4",
":",
"r",
"=",
"t",
"\n",
"g",
"=",
"p",
"\n",
"b",
"=",
"v",
"\n",
"default",
":",
"r",
"=",
"v",
"\n",
"g",
"=",
"p",
"\n",
"b",
"=",
"q",
"\n",
"}",
"\n\n",
"outR",
":=",
"uint8",
"(",
"f64",
".",
"Clamp",
"(",
"r",
"*",
"255",
"+",
"0.5",
",",
"0",
",",
"255",
")",
")",
"\n",
"outG",
":=",
"uint8",
"(",
"f64",
".",
"Clamp",
"(",
"g",
"*",
"255",
"+",
"0.5",
",",
"0",
",",
"255",
")",
")",
"\n",
"outB",
":=",
"uint8",
"(",
"f64",
".",
"Clamp",
"(",
"b",
"*",
"255",
"+",
"0.5",
",",
"0",
",",
"255",
")",
")",
"\n",
"return",
"color",
".",
"RGBA",
"{",
"outR",
",",
"outG",
",",
"outB",
",",
"0xFF",
"}",
"\n",
"}"
] | // HSVToRGB converts from HSV to RGB color model.
// Parameter h is the hue and its range is from 0 to 360 degrees.
// Parameter s is the saturation and its range is from 0.0 to 1.0.
// Parameter v is the value and its range is from 0.0 to 1.0. | [
"HSVToRGB",
"converts",
"from",
"HSV",
"to",
"RGB",
"color",
"model",
".",
"Parameter",
"h",
"is",
"the",
"hue",
"and",
"its",
"range",
"is",
"from",
"0",
"to",
"360",
"degrees",
".",
"Parameter",
"s",
"is",
"the",
"saturation",
"and",
"its",
"range",
"is",
"from",
"0",
".",
"0",
"to",
"1",
".",
"0",
".",
"Parameter",
"v",
"is",
"the",
"value",
"and",
"its",
"range",
"is",
"from",
"0",
".",
"0",
"to",
"1",
".",
"0",
"."
] | 3a6867030b45db250c7619233c6056b46a980667 | https://github.com/anthonynsimon/bild/blob/3a6867030b45db250c7619233c6056b46a980667/util/colormodel.go#L152-L200 |
153,363 | anthonynsimon/bild | blur/blur.go | Gaussian | func Gaussian(src image.Image, radius float64) *image.RGBA {
if radius <= 0 {
return clone.AsRGBA(src)
}
length := int(math.Ceil(2*radius + 1))
k := convolution.NewKernel(length, length)
gaussianFn := func(x, y, sigma float64) float64 {
return math.Exp(-(x*x/sigma + y*y/sigma))
}
for x := 0; x < length; x++ {
for y := 0; y < length; y++ {
k.Matrix[y*length+x] = gaussianFn(float64(x)-radius, float64(y)-radius, 4*radius)
}
}
return convolution.Convolve(src, k.Normalized(), &convolution.Options{Bias: 0, Wrap: false, KeepAlpha: false})
} | go | func Gaussian(src image.Image, radius float64) *image.RGBA {
if radius <= 0 {
return clone.AsRGBA(src)
}
length := int(math.Ceil(2*radius + 1))
k := convolution.NewKernel(length, length)
gaussianFn := func(x, y, sigma float64) float64 {
return math.Exp(-(x*x/sigma + y*y/sigma))
}
for x := 0; x < length; x++ {
for y := 0; y < length; y++ {
k.Matrix[y*length+x] = gaussianFn(float64(x)-radius, float64(y)-radius, 4*radius)
}
}
return convolution.Convolve(src, k.Normalized(), &convolution.Options{Bias: 0, Wrap: false, KeepAlpha: false})
} | [
"func",
"Gaussian",
"(",
"src",
"image",
".",
"Image",
",",
"radius",
"float64",
")",
"*",
"image",
".",
"RGBA",
"{",
"if",
"radius",
"<=",
"0",
"{",
"return",
"clone",
".",
"AsRGBA",
"(",
"src",
")",
"\n",
"}",
"\n\n",
"length",
":=",
"int",
"(",
"math",
".",
"Ceil",
"(",
"2",
"*",
"radius",
"+",
"1",
")",
")",
"\n",
"k",
":=",
"convolution",
".",
"NewKernel",
"(",
"length",
",",
"length",
")",
"\n\n",
"gaussianFn",
":=",
"func",
"(",
"x",
",",
"y",
",",
"sigma",
"float64",
")",
"float64",
"{",
"return",
"math",
".",
"Exp",
"(",
"-",
"(",
"x",
"*",
"x",
"/",
"sigma",
"+",
"y",
"*",
"y",
"/",
"sigma",
")",
")",
"\n",
"}",
"\n\n",
"for",
"x",
":=",
"0",
";",
"x",
"<",
"length",
";",
"x",
"++",
"{",
"for",
"y",
":=",
"0",
";",
"y",
"<",
"length",
";",
"y",
"++",
"{",
"k",
".",
"Matrix",
"[",
"y",
"*",
"length",
"+",
"x",
"]",
"=",
"gaussianFn",
"(",
"float64",
"(",
"x",
")",
"-",
"radius",
",",
"float64",
"(",
"y",
")",
"-",
"radius",
",",
"4",
"*",
"radius",
")",
"\n\n",
"}",
"\n",
"}",
"\n\n",
"return",
"convolution",
".",
"Convolve",
"(",
"src",
",",
"k",
".",
"Normalized",
"(",
")",
",",
"&",
"convolution",
".",
"Options",
"{",
"Bias",
":",
"0",
",",
"Wrap",
":",
"false",
",",
"KeepAlpha",
":",
"false",
"}",
")",
"\n",
"}"
] | // Gaussian returns a smoothly blurred version of the image using
// a Gaussian function. Radius must be larger than 0. | [
"Gaussian",
"returns",
"a",
"smoothly",
"blurred",
"version",
"of",
"the",
"image",
"using",
"a",
"Gaussian",
"function",
".",
"Radius",
"must",
"be",
"larger",
"than",
"0",
"."
] | 3a6867030b45db250c7619233c6056b46a980667 | https://github.com/anthonynsimon/bild/blob/3a6867030b45db250c7619233c6056b46a980667/blur/blur.go#L33-L53 |
153,364 | graphql-go/handler | graphcoolPlayground.go | renderPlayground | func renderPlayground(w http.ResponseWriter, r *http.Request) {
t := template.New("Playground")
t, err := t.Parse(graphcoolPlaygroundTemplate)
if err != nil {
http.Error(w, err.Error(), http.StatusInternalServerError)
return
}
d := playgroundData{
PlaygroundVersion: graphcoolPlaygroundVersion,
Endpoint: r.URL.Path,
SubscriptionEndpoint: fmt.Sprintf("ws://%v/subscriptions", r.Host),
SetTitle: true,
}
err = t.ExecuteTemplate(w, "index", d)
if err != nil {
http.Error(w, err.Error(), http.StatusInternalServerError)
}
return
} | go | func renderPlayground(w http.ResponseWriter, r *http.Request) {
t := template.New("Playground")
t, err := t.Parse(graphcoolPlaygroundTemplate)
if err != nil {
http.Error(w, err.Error(), http.StatusInternalServerError)
return
}
d := playgroundData{
PlaygroundVersion: graphcoolPlaygroundVersion,
Endpoint: r.URL.Path,
SubscriptionEndpoint: fmt.Sprintf("ws://%v/subscriptions", r.Host),
SetTitle: true,
}
err = t.ExecuteTemplate(w, "index", d)
if err != nil {
http.Error(w, err.Error(), http.StatusInternalServerError)
}
return
} | [
"func",
"renderPlayground",
"(",
"w",
"http",
".",
"ResponseWriter",
",",
"r",
"*",
"http",
".",
"Request",
")",
"{",
"t",
":=",
"template",
".",
"New",
"(",
"\"",
"\"",
")",
"\n",
"t",
",",
"err",
":=",
"t",
".",
"Parse",
"(",
"graphcoolPlaygroundTemplate",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"http",
".",
"Error",
"(",
"w",
",",
"err",
".",
"Error",
"(",
")",
",",
"http",
".",
"StatusInternalServerError",
")",
"\n",
"return",
"\n",
"}",
"\n\n",
"d",
":=",
"playgroundData",
"{",
"PlaygroundVersion",
":",
"graphcoolPlaygroundVersion",
",",
"Endpoint",
":",
"r",
".",
"URL",
".",
"Path",
",",
"SubscriptionEndpoint",
":",
"fmt",
".",
"Sprintf",
"(",
"\"",
"\"",
",",
"r",
".",
"Host",
")",
",",
"SetTitle",
":",
"true",
",",
"}",
"\n",
"err",
"=",
"t",
".",
"ExecuteTemplate",
"(",
"w",
",",
"\"",
"\"",
",",
"d",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"http",
".",
"Error",
"(",
"w",
",",
"err",
".",
"Error",
"(",
")",
",",
"http",
".",
"StatusInternalServerError",
")",
"\n",
"}",
"\n\n",
"return",
"\n",
"}"
] | // renderPlayground renders the Playground GUI | [
"renderPlayground",
"renders",
"the",
"Playground",
"GUI"
] | c1267356e6539d975e83bbea383c2bbb861dce5b | https://github.com/graphql-go/handler/blob/c1267356e6539d975e83bbea383c2bbb861dce5b/graphcoolPlayground.go#L17-L37 |
153,365 | graphql-go/handler | handler.go | NewRequestOptions | func NewRequestOptions(r *http.Request) *RequestOptions {
if reqOpt := getFromForm(r.URL.Query()); reqOpt != nil {
return reqOpt
}
if r.Method != http.MethodPost {
return &RequestOptions{}
}
if r.Body == nil {
return &RequestOptions{}
}
// TODO: improve Content-Type handling
contentTypeStr := r.Header.Get("Content-Type")
contentTypeTokens := strings.Split(contentTypeStr, ";")
contentType := contentTypeTokens[0]
switch contentType {
case ContentTypeGraphQL:
body, err := ioutil.ReadAll(r.Body)
if err != nil {
return &RequestOptions{}
}
return &RequestOptions{
Query: string(body),
}
case ContentTypeFormURLEncoded:
if err := r.ParseForm(); err != nil {
return &RequestOptions{}
}
if reqOpt := getFromForm(r.PostForm); reqOpt != nil {
return reqOpt
}
return &RequestOptions{}
case ContentTypeJSON:
fallthrough
default:
var opts RequestOptions
body, err := ioutil.ReadAll(r.Body)
if err != nil {
return &opts
}
err = json.Unmarshal(body, &opts)
if err != nil {
// Probably `variables` was sent as a string instead of an object.
// So, we try to be polite and try to parse that as a JSON string
var optsCompatible requestOptionsCompatibility
json.Unmarshal(body, &optsCompatible)
json.Unmarshal([]byte(optsCompatible.Variables), &opts.Variables)
}
return &opts
}
} | go | func NewRequestOptions(r *http.Request) *RequestOptions {
if reqOpt := getFromForm(r.URL.Query()); reqOpt != nil {
return reqOpt
}
if r.Method != http.MethodPost {
return &RequestOptions{}
}
if r.Body == nil {
return &RequestOptions{}
}
// TODO: improve Content-Type handling
contentTypeStr := r.Header.Get("Content-Type")
contentTypeTokens := strings.Split(contentTypeStr, ";")
contentType := contentTypeTokens[0]
switch contentType {
case ContentTypeGraphQL:
body, err := ioutil.ReadAll(r.Body)
if err != nil {
return &RequestOptions{}
}
return &RequestOptions{
Query: string(body),
}
case ContentTypeFormURLEncoded:
if err := r.ParseForm(); err != nil {
return &RequestOptions{}
}
if reqOpt := getFromForm(r.PostForm); reqOpt != nil {
return reqOpt
}
return &RequestOptions{}
case ContentTypeJSON:
fallthrough
default:
var opts RequestOptions
body, err := ioutil.ReadAll(r.Body)
if err != nil {
return &opts
}
err = json.Unmarshal(body, &opts)
if err != nil {
// Probably `variables` was sent as a string instead of an object.
// So, we try to be polite and try to parse that as a JSON string
var optsCompatible requestOptionsCompatibility
json.Unmarshal(body, &optsCompatible)
json.Unmarshal([]byte(optsCompatible.Variables), &opts.Variables)
}
return &opts
}
} | [
"func",
"NewRequestOptions",
"(",
"r",
"*",
"http",
".",
"Request",
")",
"*",
"RequestOptions",
"{",
"if",
"reqOpt",
":=",
"getFromForm",
"(",
"r",
".",
"URL",
".",
"Query",
"(",
")",
")",
";",
"reqOpt",
"!=",
"nil",
"{",
"return",
"reqOpt",
"\n",
"}",
"\n\n",
"if",
"r",
".",
"Method",
"!=",
"http",
".",
"MethodPost",
"{",
"return",
"&",
"RequestOptions",
"{",
"}",
"\n",
"}",
"\n\n",
"if",
"r",
".",
"Body",
"==",
"nil",
"{",
"return",
"&",
"RequestOptions",
"{",
"}",
"\n",
"}",
"\n\n",
"// TODO: improve Content-Type handling",
"contentTypeStr",
":=",
"r",
".",
"Header",
".",
"Get",
"(",
"\"",
"\"",
")",
"\n",
"contentTypeTokens",
":=",
"strings",
".",
"Split",
"(",
"contentTypeStr",
",",
"\"",
"\"",
")",
"\n",
"contentType",
":=",
"contentTypeTokens",
"[",
"0",
"]",
"\n\n",
"switch",
"contentType",
"{",
"case",
"ContentTypeGraphQL",
":",
"body",
",",
"err",
":=",
"ioutil",
".",
"ReadAll",
"(",
"r",
".",
"Body",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"&",
"RequestOptions",
"{",
"}",
"\n",
"}",
"\n",
"return",
"&",
"RequestOptions",
"{",
"Query",
":",
"string",
"(",
"body",
")",
",",
"}",
"\n",
"case",
"ContentTypeFormURLEncoded",
":",
"if",
"err",
":=",
"r",
".",
"ParseForm",
"(",
")",
";",
"err",
"!=",
"nil",
"{",
"return",
"&",
"RequestOptions",
"{",
"}",
"\n",
"}",
"\n\n",
"if",
"reqOpt",
":=",
"getFromForm",
"(",
"r",
".",
"PostForm",
")",
";",
"reqOpt",
"!=",
"nil",
"{",
"return",
"reqOpt",
"\n",
"}",
"\n\n",
"return",
"&",
"RequestOptions",
"{",
"}",
"\n\n",
"case",
"ContentTypeJSON",
":",
"fallthrough",
"\n",
"default",
":",
"var",
"opts",
"RequestOptions",
"\n",
"body",
",",
"err",
":=",
"ioutil",
".",
"ReadAll",
"(",
"r",
".",
"Body",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"&",
"opts",
"\n",
"}",
"\n",
"err",
"=",
"json",
".",
"Unmarshal",
"(",
"body",
",",
"&",
"opts",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"// Probably `variables` was sent as a string instead of an object.",
"// So, we try to be polite and try to parse that as a JSON string",
"var",
"optsCompatible",
"requestOptionsCompatibility",
"\n",
"json",
".",
"Unmarshal",
"(",
"body",
",",
"&",
"optsCompatible",
")",
"\n",
"json",
".",
"Unmarshal",
"(",
"[",
"]",
"byte",
"(",
"optsCompatible",
".",
"Variables",
")",
",",
"&",
"opts",
".",
"Variables",
")",
"\n",
"}",
"\n",
"return",
"&",
"opts",
"\n",
"}",
"\n",
"}"
] | // RequestOptions Parses a http.Request into GraphQL request options struct | [
"RequestOptions",
"Parses",
"a",
"http",
".",
"Request",
"into",
"GraphQL",
"request",
"options",
"struct"
] | c1267356e6539d975e83bbea383c2bbb861dce5b | https://github.com/graphql-go/handler/blob/c1267356e6539d975e83bbea383c2bbb861dce5b/handler.go#L67-L123 |
153,366 | graphql-go/handler | handler.go | ContextHandler | func (h *Handler) ContextHandler(ctx context.Context, w http.ResponseWriter, r *http.Request) {
// get query
opts := NewRequestOptions(r)
// execute graphql query
params := graphql.Params{
Schema: *h.Schema,
RequestString: opts.Query,
VariableValues: opts.Variables,
OperationName: opts.OperationName,
Context: ctx,
}
if h.rootObjectFn != nil {
params.RootObject = h.rootObjectFn(ctx, r)
}
result := graphql.Do(params)
if formatErrorFn := h.formatErrorFn; formatErrorFn != nil && len(result.Errors) > 0 {
formatted := make([]gqlerrors.FormattedError, len(result.Errors))
for i, formattedError := range result.Errors {
formatted[i] = formatErrorFn(formattedError.OriginalError())
}
result.Errors = formatted
}
if h.graphiql {
acceptHeader := r.Header.Get("Accept")
_, raw := r.URL.Query()["raw"]
if !raw && !strings.Contains(acceptHeader, "application/json") && strings.Contains(acceptHeader, "text/html") {
renderGraphiQL(w, params)
return
}
}
if h.playground {
acceptHeader := r.Header.Get("Accept")
_, raw := r.URL.Query()["raw"]
if !raw && !strings.Contains(acceptHeader, "application/json") && strings.Contains(acceptHeader, "text/html") {
renderPlayground(w, r)
return
}
}
// use proper JSON Header
w.Header().Add("Content-Type", "application/json; charset=utf-8")
var buff []byte
if h.pretty {
w.WriteHeader(http.StatusOK)
buff, _ = json.MarshalIndent(result, "", "\t")
w.Write(buff)
} else {
w.WriteHeader(http.StatusOK)
buff, _ = json.Marshal(result)
w.Write(buff)
}
if h.resultCallbackFn != nil {
h.resultCallbackFn(ctx, ¶ms, result, buff)
}
} | go | func (h *Handler) ContextHandler(ctx context.Context, w http.ResponseWriter, r *http.Request) {
// get query
opts := NewRequestOptions(r)
// execute graphql query
params := graphql.Params{
Schema: *h.Schema,
RequestString: opts.Query,
VariableValues: opts.Variables,
OperationName: opts.OperationName,
Context: ctx,
}
if h.rootObjectFn != nil {
params.RootObject = h.rootObjectFn(ctx, r)
}
result := graphql.Do(params)
if formatErrorFn := h.formatErrorFn; formatErrorFn != nil && len(result.Errors) > 0 {
formatted := make([]gqlerrors.FormattedError, len(result.Errors))
for i, formattedError := range result.Errors {
formatted[i] = formatErrorFn(formattedError.OriginalError())
}
result.Errors = formatted
}
if h.graphiql {
acceptHeader := r.Header.Get("Accept")
_, raw := r.URL.Query()["raw"]
if !raw && !strings.Contains(acceptHeader, "application/json") && strings.Contains(acceptHeader, "text/html") {
renderGraphiQL(w, params)
return
}
}
if h.playground {
acceptHeader := r.Header.Get("Accept")
_, raw := r.URL.Query()["raw"]
if !raw && !strings.Contains(acceptHeader, "application/json") && strings.Contains(acceptHeader, "text/html") {
renderPlayground(w, r)
return
}
}
// use proper JSON Header
w.Header().Add("Content-Type", "application/json; charset=utf-8")
var buff []byte
if h.pretty {
w.WriteHeader(http.StatusOK)
buff, _ = json.MarshalIndent(result, "", "\t")
w.Write(buff)
} else {
w.WriteHeader(http.StatusOK)
buff, _ = json.Marshal(result)
w.Write(buff)
}
if h.resultCallbackFn != nil {
h.resultCallbackFn(ctx, ¶ms, result, buff)
}
} | [
"func",
"(",
"h",
"*",
"Handler",
")",
"ContextHandler",
"(",
"ctx",
"context",
".",
"Context",
",",
"w",
"http",
".",
"ResponseWriter",
",",
"r",
"*",
"http",
".",
"Request",
")",
"{",
"// get query",
"opts",
":=",
"NewRequestOptions",
"(",
"r",
")",
"\n\n",
"// execute graphql query",
"params",
":=",
"graphql",
".",
"Params",
"{",
"Schema",
":",
"*",
"h",
".",
"Schema",
",",
"RequestString",
":",
"opts",
".",
"Query",
",",
"VariableValues",
":",
"opts",
".",
"Variables",
",",
"OperationName",
":",
"opts",
".",
"OperationName",
",",
"Context",
":",
"ctx",
",",
"}",
"\n",
"if",
"h",
".",
"rootObjectFn",
"!=",
"nil",
"{",
"params",
".",
"RootObject",
"=",
"h",
".",
"rootObjectFn",
"(",
"ctx",
",",
"r",
")",
"\n",
"}",
"\n",
"result",
":=",
"graphql",
".",
"Do",
"(",
"params",
")",
"\n\n",
"if",
"formatErrorFn",
":=",
"h",
".",
"formatErrorFn",
";",
"formatErrorFn",
"!=",
"nil",
"&&",
"len",
"(",
"result",
".",
"Errors",
")",
">",
"0",
"{",
"formatted",
":=",
"make",
"(",
"[",
"]",
"gqlerrors",
".",
"FormattedError",
",",
"len",
"(",
"result",
".",
"Errors",
")",
")",
"\n",
"for",
"i",
",",
"formattedError",
":=",
"range",
"result",
".",
"Errors",
"{",
"formatted",
"[",
"i",
"]",
"=",
"formatErrorFn",
"(",
"formattedError",
".",
"OriginalError",
"(",
")",
")",
"\n",
"}",
"\n",
"result",
".",
"Errors",
"=",
"formatted",
"\n",
"}",
"\n\n",
"if",
"h",
".",
"graphiql",
"{",
"acceptHeader",
":=",
"r",
".",
"Header",
".",
"Get",
"(",
"\"",
"\"",
")",
"\n",
"_",
",",
"raw",
":=",
"r",
".",
"URL",
".",
"Query",
"(",
")",
"[",
"\"",
"\"",
"]",
"\n",
"if",
"!",
"raw",
"&&",
"!",
"strings",
".",
"Contains",
"(",
"acceptHeader",
",",
"\"",
"\"",
")",
"&&",
"strings",
".",
"Contains",
"(",
"acceptHeader",
",",
"\"",
"\"",
")",
"{",
"renderGraphiQL",
"(",
"w",
",",
"params",
")",
"\n",
"return",
"\n",
"}",
"\n",
"}",
"\n\n",
"if",
"h",
".",
"playground",
"{",
"acceptHeader",
":=",
"r",
".",
"Header",
".",
"Get",
"(",
"\"",
"\"",
")",
"\n",
"_",
",",
"raw",
":=",
"r",
".",
"URL",
".",
"Query",
"(",
")",
"[",
"\"",
"\"",
"]",
"\n",
"if",
"!",
"raw",
"&&",
"!",
"strings",
".",
"Contains",
"(",
"acceptHeader",
",",
"\"",
"\"",
")",
"&&",
"strings",
".",
"Contains",
"(",
"acceptHeader",
",",
"\"",
"\"",
")",
"{",
"renderPlayground",
"(",
"w",
",",
"r",
")",
"\n",
"return",
"\n",
"}",
"\n",
"}",
"\n\n",
"// use proper JSON Header",
"w",
".",
"Header",
"(",
")",
".",
"Add",
"(",
"\"",
"\"",
",",
"\"",
"\"",
")",
"\n\n",
"var",
"buff",
"[",
"]",
"byte",
"\n",
"if",
"h",
".",
"pretty",
"{",
"w",
".",
"WriteHeader",
"(",
"http",
".",
"StatusOK",
")",
"\n",
"buff",
",",
"_",
"=",
"json",
".",
"MarshalIndent",
"(",
"result",
",",
"\"",
"\"",
",",
"\"",
"\\t",
"\"",
")",
"\n\n",
"w",
".",
"Write",
"(",
"buff",
")",
"\n",
"}",
"else",
"{",
"w",
".",
"WriteHeader",
"(",
"http",
".",
"StatusOK",
")",
"\n",
"buff",
",",
"_",
"=",
"json",
".",
"Marshal",
"(",
"result",
")",
"\n\n",
"w",
".",
"Write",
"(",
"buff",
")",
"\n",
"}",
"\n\n",
"if",
"h",
".",
"resultCallbackFn",
"!=",
"nil",
"{",
"h",
".",
"resultCallbackFn",
"(",
"ctx",
",",
"&",
"params",
",",
"result",
",",
"buff",
")",
"\n",
"}",
"\n",
"}"
] | // ContextHandler provides an entrypoint into executing graphQL queries with a
// user-provided context. | [
"ContextHandler",
"provides",
"an",
"entrypoint",
"into",
"executing",
"graphQL",
"queries",
"with",
"a",
"user",
"-",
"provided",
"context",
"."
] | c1267356e6539d975e83bbea383c2bbb861dce5b | https://github.com/graphql-go/handler/blob/c1267356e6539d975e83bbea383c2bbb861dce5b/handler.go#L127-L189 |
153,367 | graphql-go/handler | handler.go | ServeHTTP | func (h *Handler) ServeHTTP(w http.ResponseWriter, r *http.Request) {
h.ContextHandler(r.Context(), w, r)
} | go | func (h *Handler) ServeHTTP(w http.ResponseWriter, r *http.Request) {
h.ContextHandler(r.Context(), w, r)
} | [
"func",
"(",
"h",
"*",
"Handler",
")",
"ServeHTTP",
"(",
"w",
"http",
".",
"ResponseWriter",
",",
"r",
"*",
"http",
".",
"Request",
")",
"{",
"h",
".",
"ContextHandler",
"(",
"r",
".",
"Context",
"(",
")",
",",
"w",
",",
"r",
")",
"\n",
"}"
] | // ServeHTTP provides an entrypoint into executing graphQL queries. | [
"ServeHTTP",
"provides",
"an",
"entrypoint",
"into",
"executing",
"graphQL",
"queries",
"."
] | c1267356e6539d975e83bbea383c2bbb861dce5b | https://github.com/graphql-go/handler/blob/c1267356e6539d975e83bbea383c2bbb861dce5b/handler.go#L192-L194 |
153,368 | graphql-go/handler | graphiql.go | renderGraphiQL | func renderGraphiQL(w http.ResponseWriter, params graphql.Params) {
t := template.New("GraphiQL")
t, err := t.Parse(graphiqlTemplate)
if err != nil {
http.Error(w, err.Error(), http.StatusInternalServerError)
return
}
// Create variables string
vars, err := json.MarshalIndent(params.VariableValues, "", " ")
if err != nil {
http.Error(w, err.Error(), http.StatusInternalServerError)
return
}
varsString := string(vars)
if varsString == "null" {
varsString = ""
}
// Create result string
var resString string
if params.RequestString == "" {
resString = ""
} else {
result, err := json.MarshalIndent(graphql.Do(params), "", " ")
if err != nil {
http.Error(w, err.Error(), http.StatusInternalServerError)
return
}
resString = string(result)
}
d := graphiqlData{
GraphiqlVersion: graphiqlVersion,
QueryString: params.RequestString,
ResultString: resString,
VariablesString: varsString,
OperationName: params.OperationName,
}
err = t.ExecuteTemplate(w, "index", d)
if err != nil {
http.Error(w, err.Error(), http.StatusInternalServerError)
}
return
} | go | func renderGraphiQL(w http.ResponseWriter, params graphql.Params) {
t := template.New("GraphiQL")
t, err := t.Parse(graphiqlTemplate)
if err != nil {
http.Error(w, err.Error(), http.StatusInternalServerError)
return
}
// Create variables string
vars, err := json.MarshalIndent(params.VariableValues, "", " ")
if err != nil {
http.Error(w, err.Error(), http.StatusInternalServerError)
return
}
varsString := string(vars)
if varsString == "null" {
varsString = ""
}
// Create result string
var resString string
if params.RequestString == "" {
resString = ""
} else {
result, err := json.MarshalIndent(graphql.Do(params), "", " ")
if err != nil {
http.Error(w, err.Error(), http.StatusInternalServerError)
return
}
resString = string(result)
}
d := graphiqlData{
GraphiqlVersion: graphiqlVersion,
QueryString: params.RequestString,
ResultString: resString,
VariablesString: varsString,
OperationName: params.OperationName,
}
err = t.ExecuteTemplate(w, "index", d)
if err != nil {
http.Error(w, err.Error(), http.StatusInternalServerError)
}
return
} | [
"func",
"renderGraphiQL",
"(",
"w",
"http",
".",
"ResponseWriter",
",",
"params",
"graphql",
".",
"Params",
")",
"{",
"t",
":=",
"template",
".",
"New",
"(",
"\"",
"\"",
")",
"\n",
"t",
",",
"err",
":=",
"t",
".",
"Parse",
"(",
"graphiqlTemplate",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"http",
".",
"Error",
"(",
"w",
",",
"err",
".",
"Error",
"(",
")",
",",
"http",
".",
"StatusInternalServerError",
")",
"\n",
"return",
"\n",
"}",
"\n\n",
"// Create variables string",
"vars",
",",
"err",
":=",
"json",
".",
"MarshalIndent",
"(",
"params",
".",
"VariableValues",
",",
"\"",
"\"",
",",
"\"",
"\"",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"http",
".",
"Error",
"(",
"w",
",",
"err",
".",
"Error",
"(",
")",
",",
"http",
".",
"StatusInternalServerError",
")",
"\n",
"return",
"\n",
"}",
"\n",
"varsString",
":=",
"string",
"(",
"vars",
")",
"\n",
"if",
"varsString",
"==",
"\"",
"\"",
"{",
"varsString",
"=",
"\"",
"\"",
"\n",
"}",
"\n\n",
"// Create result string",
"var",
"resString",
"string",
"\n",
"if",
"params",
".",
"RequestString",
"==",
"\"",
"\"",
"{",
"resString",
"=",
"\"",
"\"",
"\n",
"}",
"else",
"{",
"result",
",",
"err",
":=",
"json",
".",
"MarshalIndent",
"(",
"graphql",
".",
"Do",
"(",
"params",
")",
",",
"\"",
"\"",
",",
"\"",
"\"",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"http",
".",
"Error",
"(",
"w",
",",
"err",
".",
"Error",
"(",
")",
",",
"http",
".",
"StatusInternalServerError",
")",
"\n",
"return",
"\n",
"}",
"\n",
"resString",
"=",
"string",
"(",
"result",
")",
"\n",
"}",
"\n\n",
"d",
":=",
"graphiqlData",
"{",
"GraphiqlVersion",
":",
"graphiqlVersion",
",",
"QueryString",
":",
"params",
".",
"RequestString",
",",
"ResultString",
":",
"resString",
",",
"VariablesString",
":",
"varsString",
",",
"OperationName",
":",
"params",
".",
"OperationName",
",",
"}",
"\n",
"err",
"=",
"t",
".",
"ExecuteTemplate",
"(",
"w",
",",
"\"",
"\"",
",",
"d",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"http",
".",
"Error",
"(",
"w",
",",
"err",
".",
"Error",
"(",
")",
",",
"http",
".",
"StatusInternalServerError",
")",
"\n",
"}",
"\n\n",
"return",
"\n",
"}"
] | // renderGraphiQL renders the GraphiQL GUI | [
"renderGraphiQL",
"renders",
"the",
"GraphiQL",
"GUI"
] | c1267356e6539d975e83bbea383c2bbb861dce5b | https://github.com/graphql-go/handler/blob/c1267356e6539d975e83bbea383c2bbb861dce5b/graphiql.go#L21-L66 |
153,369 | josharian/impl | impl.go | gofmt | func (p Pkg) gofmt(e ast.Expr) string {
var buf bytes.Buffer
printer.Fprint(&buf, p.FileSet, e)
return buf.String()
} | go | func (p Pkg) gofmt(e ast.Expr) string {
var buf bytes.Buffer
printer.Fprint(&buf, p.FileSet, e)
return buf.String()
} | [
"func",
"(",
"p",
"Pkg",
")",
"gofmt",
"(",
"e",
"ast",
".",
"Expr",
")",
"string",
"{",
"var",
"buf",
"bytes",
".",
"Buffer",
"\n",
"printer",
".",
"Fprint",
"(",
"&",
"buf",
",",
"p",
".",
"FileSet",
",",
"e",
")",
"\n",
"return",
"buf",
".",
"String",
"(",
")",
"\n",
"}"
] | // gofmt pretty-prints e. | [
"gofmt",
"pretty",
"-",
"prints",
"e",
"."
] | 3d0f908298c49598b6aa84f101c69670e15d1d03 | https://github.com/josharian/impl/blob/3d0f908298c49598b6aa84f101c69670e15d1d03/impl.go#L139-L143 |
153,370 | josharian/impl | impl.go | funcs | func funcs(iface string, srcDir string) ([]Func, error) {
// Special case for the built-in error interface.
if iface == "error" {
return errorInterface, nil
}
// Locate the interface.
path, id, err := findInterface(iface, srcDir)
if err != nil {
return nil, err
}
// Parse the package and find the interface declaration.
p, spec, err := typeSpec(path, id, srcDir)
if err != nil {
return nil, fmt.Errorf("interface %s not found: %s", iface, err)
}
idecl, ok := spec.Type.(*ast.InterfaceType)
if !ok {
return nil, fmt.Errorf("not an interface: %s", iface)
}
if idecl.Methods == nil {
return nil, fmt.Errorf("empty interface: %s", iface)
}
var fns []Func
for _, fndecl := range idecl.Methods.List {
if len(fndecl.Names) == 0 {
// Embedded interface: recurse
embedded, err := funcs(p.fullType(fndecl.Type), srcDir)
if err != nil {
return nil, err
}
fns = append(fns, embedded...)
continue
}
fn := p.funcsig(fndecl)
fns = append(fns, fn)
}
return fns, nil
} | go | func funcs(iface string, srcDir string) ([]Func, error) {
// Special case for the built-in error interface.
if iface == "error" {
return errorInterface, nil
}
// Locate the interface.
path, id, err := findInterface(iface, srcDir)
if err != nil {
return nil, err
}
// Parse the package and find the interface declaration.
p, spec, err := typeSpec(path, id, srcDir)
if err != nil {
return nil, fmt.Errorf("interface %s not found: %s", iface, err)
}
idecl, ok := spec.Type.(*ast.InterfaceType)
if !ok {
return nil, fmt.Errorf("not an interface: %s", iface)
}
if idecl.Methods == nil {
return nil, fmt.Errorf("empty interface: %s", iface)
}
var fns []Func
for _, fndecl := range idecl.Methods.List {
if len(fndecl.Names) == 0 {
// Embedded interface: recurse
embedded, err := funcs(p.fullType(fndecl.Type), srcDir)
if err != nil {
return nil, err
}
fns = append(fns, embedded...)
continue
}
fn := p.funcsig(fndecl)
fns = append(fns, fn)
}
return fns, nil
} | [
"func",
"funcs",
"(",
"iface",
"string",
",",
"srcDir",
"string",
")",
"(",
"[",
"]",
"Func",
",",
"error",
")",
"{",
"// Special case for the built-in error interface.",
"if",
"iface",
"==",
"\"",
"\"",
"{",
"return",
"errorInterface",
",",
"nil",
"\n",
"}",
"\n\n",
"// Locate the interface.",
"path",
",",
"id",
",",
"err",
":=",
"findInterface",
"(",
"iface",
",",
"srcDir",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"nil",
",",
"err",
"\n",
"}",
"\n\n",
"// Parse the package and find the interface declaration.",
"p",
",",
"spec",
",",
"err",
":=",
"typeSpec",
"(",
"path",
",",
"id",
",",
"srcDir",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"nil",
",",
"fmt",
".",
"Errorf",
"(",
"\"",
"\"",
",",
"iface",
",",
"err",
")",
"\n",
"}",
"\n",
"idecl",
",",
"ok",
":=",
"spec",
".",
"Type",
".",
"(",
"*",
"ast",
".",
"InterfaceType",
")",
"\n",
"if",
"!",
"ok",
"{",
"return",
"nil",
",",
"fmt",
".",
"Errorf",
"(",
"\"",
"\"",
",",
"iface",
")",
"\n",
"}",
"\n\n",
"if",
"idecl",
".",
"Methods",
"==",
"nil",
"{",
"return",
"nil",
",",
"fmt",
".",
"Errorf",
"(",
"\"",
"\"",
",",
"iface",
")",
"\n",
"}",
"\n\n",
"var",
"fns",
"[",
"]",
"Func",
"\n",
"for",
"_",
",",
"fndecl",
":=",
"range",
"idecl",
".",
"Methods",
".",
"List",
"{",
"if",
"len",
"(",
"fndecl",
".",
"Names",
")",
"==",
"0",
"{",
"// Embedded interface: recurse",
"embedded",
",",
"err",
":=",
"funcs",
"(",
"p",
".",
"fullType",
"(",
"fndecl",
".",
"Type",
")",
",",
"srcDir",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"nil",
",",
"err",
"\n",
"}",
"\n",
"fns",
"=",
"append",
"(",
"fns",
",",
"embedded",
"...",
")",
"\n",
"continue",
"\n",
"}",
"\n\n",
"fn",
":=",
"p",
".",
"funcsig",
"(",
"fndecl",
")",
"\n",
"fns",
"=",
"append",
"(",
"fns",
",",
"fn",
")",
"\n",
"}",
"\n",
"return",
"fns",
",",
"nil",
"\n",
"}"
] | // funcs returns the set of methods required to implement iface.
// It is called funcs rather than methods because the
// function descriptions are functions; there is no receiver. | [
"funcs",
"returns",
"the",
"set",
"of",
"methods",
"required",
"to",
"implement",
"iface",
".",
"It",
"is",
"called",
"funcs",
"rather",
"than",
"methods",
"because",
"the",
"function",
"descriptions",
"are",
"functions",
";",
"there",
"is",
"no",
"receiver",
"."
] | 3d0f908298c49598b6aa84f101c69670e15d1d03 | https://github.com/josharian/impl/blob/3d0f908298c49598b6aa84f101c69670e15d1d03/impl.go#L227-L269 |
153,371 | josharian/impl | impl.go | genStubs | func genStubs(recv string, fns []Func) []byte {
var buf bytes.Buffer
for _, fn := range fns {
meth := Method{Recv: recv, Func: fn}
tmpl.Execute(&buf, meth)
}
pretty, err := format.Source(buf.Bytes())
if err != nil {
panic(err)
}
return pretty
} | go | func genStubs(recv string, fns []Func) []byte {
var buf bytes.Buffer
for _, fn := range fns {
meth := Method{Recv: recv, Func: fn}
tmpl.Execute(&buf, meth)
}
pretty, err := format.Source(buf.Bytes())
if err != nil {
panic(err)
}
return pretty
} | [
"func",
"genStubs",
"(",
"recv",
"string",
",",
"fns",
"[",
"]",
"Func",
")",
"[",
"]",
"byte",
"{",
"var",
"buf",
"bytes",
".",
"Buffer",
"\n",
"for",
"_",
",",
"fn",
":=",
"range",
"fns",
"{",
"meth",
":=",
"Method",
"{",
"Recv",
":",
"recv",
",",
"Func",
":",
"fn",
"}",
"\n",
"tmpl",
".",
"Execute",
"(",
"&",
"buf",
",",
"meth",
")",
"\n",
"}",
"\n\n",
"pretty",
",",
"err",
":=",
"format",
".",
"Source",
"(",
"buf",
".",
"Bytes",
"(",
")",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"panic",
"(",
"err",
")",
"\n",
"}",
"\n",
"return",
"pretty",
"\n",
"}"
] | // genStubs prints nicely formatted method stubs
// for fns using receiver expression recv.
// If recv is not a valid receiver expression,
// genStubs will panic. | [
"genStubs",
"prints",
"nicely",
"formatted",
"method",
"stubs",
"for",
"fns",
"using",
"receiver",
"expression",
"recv",
".",
"If",
"recv",
"is",
"not",
"a",
"valid",
"receiver",
"expression",
"genStubs",
"will",
"panic",
"."
] | 3d0f908298c49598b6aa84f101c69670e15d1d03 | https://github.com/josharian/impl/blob/3d0f908298c49598b6aa84f101c69670e15d1d03/impl.go#L282-L294 |
153,372 | josharian/impl | impl.go | validReceiver | func validReceiver(recv string) bool {
if recv == "" {
// The parse will parse empty receivers, but we don't want to accept them,
// since it won't generate a usable code snippet.
return false
}
fset := token.NewFileSet()
_, err := parser.ParseFile(fset, "", "package hack\nfunc ("+recv+") Foo()", 0)
return err == nil
} | go | func validReceiver(recv string) bool {
if recv == "" {
// The parse will parse empty receivers, but we don't want to accept them,
// since it won't generate a usable code snippet.
return false
}
fset := token.NewFileSet()
_, err := parser.ParseFile(fset, "", "package hack\nfunc ("+recv+") Foo()", 0)
return err == nil
} | [
"func",
"validReceiver",
"(",
"recv",
"string",
")",
"bool",
"{",
"if",
"recv",
"==",
"\"",
"\"",
"{",
"// The parse will parse empty receivers, but we don't want to accept them,",
"// since it won't generate a usable code snippet.",
"return",
"false",
"\n",
"}",
"\n",
"fset",
":=",
"token",
".",
"NewFileSet",
"(",
")",
"\n",
"_",
",",
"err",
":=",
"parser",
".",
"ParseFile",
"(",
"fset",
",",
"\"",
"\"",
",",
"\"",
"\\n",
"\"",
"+",
"recv",
"+",
"\"",
"\"",
",",
"0",
")",
"\n",
"return",
"err",
"==",
"nil",
"\n",
"}"
] | // validReceiver reports whether recv is a valid receiver expression. | [
"validReceiver",
"reports",
"whether",
"recv",
"is",
"a",
"valid",
"receiver",
"expression",
"."
] | 3d0f908298c49598b6aa84f101c69670e15d1d03 | https://github.com/josharian/impl/blob/3d0f908298c49598b6aa84f101c69670e15d1d03/impl.go#L297-L306 |
153,373 | k0kubun/pp | pp.go | Print | func Print(a ...interface{}) (n int, err error) {
return fmt.Fprint(out, formatAll(a)...)
} | go | func Print(a ...interface{}) (n int, err error) {
return fmt.Fprint(out, formatAll(a)...)
} | [
"func",
"Print",
"(",
"a",
"...",
"interface",
"{",
"}",
")",
"(",
"n",
"int",
",",
"err",
"error",
")",
"{",
"return",
"fmt",
".",
"Fprint",
"(",
"out",
",",
"formatAll",
"(",
"a",
")",
"...",
")",
"\n",
"}"
] | // Print prints given arguments. | [
"Print",
"prints",
"given",
"arguments",
"."
] | ea9763a91366a414dccd02c8019a6dafe54829db | https://github.com/k0kubun/pp/blob/ea9763a91366a414dccd02c8019a6dafe54829db/pp.go#L32-L34 |
153,374 | k0kubun/pp | pp.go | Printf | func Printf(format string, a ...interface{}) (n int, err error) {
return fmt.Fprintf(out, format, formatAll(a)...)
} | go | func Printf(format string, a ...interface{}) (n int, err error) {
return fmt.Fprintf(out, format, formatAll(a)...)
} | [
"func",
"Printf",
"(",
"format",
"string",
",",
"a",
"...",
"interface",
"{",
"}",
")",
"(",
"n",
"int",
",",
"err",
"error",
")",
"{",
"return",
"fmt",
".",
"Fprintf",
"(",
"out",
",",
"format",
",",
"formatAll",
"(",
"a",
")",
"...",
")",
"\n",
"}"
] | // Printf prints a given format. | [
"Printf",
"prints",
"a",
"given",
"format",
"."
] | ea9763a91366a414dccd02c8019a6dafe54829db | https://github.com/k0kubun/pp/blob/ea9763a91366a414dccd02c8019a6dafe54829db/pp.go#L37-L39 |
153,375 | k0kubun/pp | pp.go | Println | func Println(a ...interface{}) (n int, err error) {
return fmt.Fprintln(out, formatAll(a)...)
} | go | func Println(a ...interface{}) (n int, err error) {
return fmt.Fprintln(out, formatAll(a)...)
} | [
"func",
"Println",
"(",
"a",
"...",
"interface",
"{",
"}",
")",
"(",
"n",
"int",
",",
"err",
"error",
")",
"{",
"return",
"fmt",
".",
"Fprintln",
"(",
"out",
",",
"formatAll",
"(",
"a",
")",
"...",
")",
"\n",
"}"
] | // Println prints given arguments with newline. | [
"Println",
"prints",
"given",
"arguments",
"with",
"newline",
"."
] | ea9763a91366a414dccd02c8019a6dafe54829db | https://github.com/k0kubun/pp/blob/ea9763a91366a414dccd02c8019a6dafe54829db/pp.go#L42-L44 |
153,376 | k0kubun/pp | pp.go | Sprintf | func Sprintf(format string, a ...interface{}) string {
return fmt.Sprintf(format, formatAll(a)...)
} | go | func Sprintf(format string, a ...interface{}) string {
return fmt.Sprintf(format, formatAll(a)...)
} | [
"func",
"Sprintf",
"(",
"format",
"string",
",",
"a",
"...",
"interface",
"{",
"}",
")",
"string",
"{",
"return",
"fmt",
".",
"Sprintf",
"(",
"format",
",",
"formatAll",
"(",
"a",
")",
"...",
")",
"\n",
"}"
] | // Sprintf formats with pretty print and returns the result as string. | [
"Sprintf",
"formats",
"with",
"pretty",
"print",
"and",
"returns",
"the",
"result",
"as",
"string",
"."
] | ea9763a91366a414dccd02c8019a6dafe54829db | https://github.com/k0kubun/pp/blob/ea9763a91366a414dccd02c8019a6dafe54829db/pp.go#L52-L54 |
153,377 | k0kubun/pp | pp.go | Fprint | func Fprint(w io.Writer, a ...interface{}) (n int, err error) {
return fmt.Fprint(w, formatAll(a)...)
} | go | func Fprint(w io.Writer, a ...interface{}) (n int, err error) {
return fmt.Fprint(w, formatAll(a)...)
} | [
"func",
"Fprint",
"(",
"w",
"io",
".",
"Writer",
",",
"a",
"...",
"interface",
"{",
"}",
")",
"(",
"n",
"int",
",",
"err",
"error",
")",
"{",
"return",
"fmt",
".",
"Fprint",
"(",
"w",
",",
"formatAll",
"(",
"a",
")",
"...",
")",
"\n",
"}"
] | // Fprint prints given arguments to a given writer. | [
"Fprint",
"prints",
"given",
"arguments",
"to",
"a",
"given",
"writer",
"."
] | ea9763a91366a414dccd02c8019a6dafe54829db | https://github.com/k0kubun/pp/blob/ea9763a91366a414dccd02c8019a6dafe54829db/pp.go#L62-L64 |
153,378 | k0kubun/pp | pp.go | Fatalf | func Fatalf(format string, a ...interface{}) {
fmt.Fprintf(out, format, formatAll(a)...)
os.Exit(1)
} | go | func Fatalf(format string, a ...interface{}) {
fmt.Fprintf(out, format, formatAll(a)...)
os.Exit(1)
} | [
"func",
"Fatalf",
"(",
"format",
"string",
",",
"a",
"...",
"interface",
"{",
"}",
")",
"{",
"fmt",
".",
"Fprintf",
"(",
"out",
",",
"format",
",",
"formatAll",
"(",
"a",
")",
"...",
")",
"\n",
"os",
".",
"Exit",
"(",
"1",
")",
"\n",
"}"
] | // Fatalf prints a given format and finishes execution with exit status 1. | [
"Fatalf",
"prints",
"a",
"given",
"format",
"and",
"finishes",
"execution",
"with",
"exit",
"status",
"1",
"."
] | ea9763a91366a414dccd02c8019a6dafe54829db | https://github.com/k0kubun/pp/blob/ea9763a91366a414dccd02c8019a6dafe54829db/pp.go#L88-L91 |
153,379 | alecthomas/log4go | wrapper.go | Crashf | func Crashf(format string, args ...interface{}) {
Global.intLogf(CRITICAL, format, args...)
Global.Close() // so that hopefully the messages get logged
panic(fmt.Sprintf(format, args...))
} | go | func Crashf(format string, args ...interface{}) {
Global.intLogf(CRITICAL, format, args...)
Global.Close() // so that hopefully the messages get logged
panic(fmt.Sprintf(format, args...))
} | [
"func",
"Crashf",
"(",
"format",
"string",
",",
"args",
"...",
"interface",
"{",
"}",
")",
"{",
"Global",
".",
"intLogf",
"(",
"CRITICAL",
",",
"format",
",",
"args",
"...",
")",
"\n",
"Global",
".",
"Close",
"(",
")",
"// so that hopefully the messages get logged",
"\n",
"panic",
"(",
"fmt",
".",
"Sprintf",
"(",
"format",
",",
"args",
"...",
")",
")",
"\n",
"}"
] | // Logs the given message and crashes the program | [
"Logs",
"the",
"given",
"message",
"and",
"crashes",
"the",
"program"
] | d146e6b86faab5f7e4d135cc63b749d74bf0d4a6 | https://github.com/alecthomas/log4go/blob/d146e6b86faab5f7e4d135cc63b749d74bf0d4a6/wrapper.go#L43-L47 |
153,380 | alecthomas/log4go | log4go.go | Warn | func (log Logger) Warn(arg0 interface{}, args ...interface{}) error {
const (
lvl = WARNING
)
var msg string
switch first := arg0.(type) {
case string:
// Use the string as a format string
msg = fmt.Sprintf(first, args...)
case func() string:
// Log the closure (no other arguments used)
msg = first()
default:
// Build a format string so that it will be similar to Sprint
msg = fmt.Sprintf(fmt.Sprint(first)+strings.Repeat(" %v", len(args)), args...)
}
log.intLogf(lvl, msg)
return errors.New(msg)
} | go | func (log Logger) Warn(arg0 interface{}, args ...interface{}) error {
const (
lvl = WARNING
)
var msg string
switch first := arg0.(type) {
case string:
// Use the string as a format string
msg = fmt.Sprintf(first, args...)
case func() string:
// Log the closure (no other arguments used)
msg = first()
default:
// Build a format string so that it will be similar to Sprint
msg = fmt.Sprintf(fmt.Sprint(first)+strings.Repeat(" %v", len(args)), args...)
}
log.intLogf(lvl, msg)
return errors.New(msg)
} | [
"func",
"(",
"log",
"Logger",
")",
"Warn",
"(",
"arg0",
"interface",
"{",
"}",
",",
"args",
"...",
"interface",
"{",
"}",
")",
"error",
"{",
"const",
"(",
"lvl",
"=",
"WARNING",
"\n",
")",
"\n",
"var",
"msg",
"string",
"\n",
"switch",
"first",
":=",
"arg0",
".",
"(",
"type",
")",
"{",
"case",
"string",
":",
"// Use the string as a format string",
"msg",
"=",
"fmt",
".",
"Sprintf",
"(",
"first",
",",
"args",
"...",
")",
"\n",
"case",
"func",
"(",
")",
"string",
":",
"// Log the closure (no other arguments used)",
"msg",
"=",
"first",
"(",
")",
"\n",
"default",
":",
"// Build a format string so that it will be similar to Sprint",
"msg",
"=",
"fmt",
".",
"Sprintf",
"(",
"fmt",
".",
"Sprint",
"(",
"first",
")",
"+",
"strings",
".",
"Repeat",
"(",
"\"",
"\"",
",",
"len",
"(",
"args",
")",
")",
",",
"args",
"...",
")",
"\n",
"}",
"\n",
"log",
".",
"intLogf",
"(",
"lvl",
",",
"msg",
")",
"\n",
"return",
"errors",
".",
"New",
"(",
"msg",
")",
"\n",
"}"
] | // Warn logs a message at the warning log level and returns the formatted error.
// At the warning level and higher, there is no performance benefit if the
// message is not actually logged, because all formats are processed and all
// closures are executed to format the error message.
// See Debug for further explanation of the arguments. | [
"Warn",
"logs",
"a",
"message",
"at",
"the",
"warning",
"log",
"level",
"and",
"returns",
"the",
"formatted",
"error",
".",
"At",
"the",
"warning",
"level",
"and",
"higher",
"there",
"is",
"no",
"performance",
"benefit",
"if",
"the",
"message",
"is",
"not",
"actually",
"logged",
"because",
"all",
"formats",
"are",
"processed",
"and",
"all",
"closures",
"are",
"executed",
"to",
"format",
"the",
"error",
"message",
".",
"See",
"Debug",
"for",
"further",
"explanation",
"of",
"the",
"arguments",
"."
] | d146e6b86faab5f7e4d135cc63b749d74bf0d4a6 | https://github.com/alecthomas/log4go/blob/d146e6b86faab5f7e4d135cc63b749d74bf0d4a6/log4go.go#L420-L438 |
153,381 | alecthomas/log4go | filelog.go | SetRotateMaxBackup | func (w *FileLogWriter) SetRotateMaxBackup(maxbackup int) *FileLogWriter {
w.maxbackup = maxbackup
return w
} | go | func (w *FileLogWriter) SetRotateMaxBackup(maxbackup int) *FileLogWriter {
w.maxbackup = maxbackup
return w
} | [
"func",
"(",
"w",
"*",
"FileLogWriter",
")",
"SetRotateMaxBackup",
"(",
"maxbackup",
"int",
")",
"*",
"FileLogWriter",
"{",
"w",
".",
"maxbackup",
"=",
"maxbackup",
"\n",
"return",
"w",
"\n",
"}"
] | // Set max backup files. Must be called before the first log message
// is written. | [
"Set",
"max",
"backup",
"files",
".",
"Must",
"be",
"called",
"before",
"the",
"first",
"log",
"message",
"is",
"written",
"."
] | d146e6b86faab5f7e4d135cc63b749d74bf0d4a6 | https://github.com/alecthomas/log4go/blob/d146e6b86faab5f7e4d135cc63b749d74bf0d4a6/filelog.go#L240-L243 |
153,382 | alecthomas/log4go | pattlog.go | NewFormatLogWriter | func NewFormatLogWriter(out io.Writer, format string) FormatLogWriter {
records := make(FormatLogWriter, LogBufferLength)
go records.run(out, format)
return records
} | go | func NewFormatLogWriter(out io.Writer, format string) FormatLogWriter {
records := make(FormatLogWriter, LogBufferLength)
go records.run(out, format)
return records
} | [
"func",
"NewFormatLogWriter",
"(",
"out",
"io",
".",
"Writer",
",",
"format",
"string",
")",
"FormatLogWriter",
"{",
"records",
":=",
"make",
"(",
"FormatLogWriter",
",",
"LogBufferLength",
")",
"\n",
"go",
"records",
".",
"run",
"(",
"out",
",",
"format",
")",
"\n",
"return",
"records",
"\n",
"}"
] | // This creates a new FormatLogWriter | [
"This",
"creates",
"a",
"new",
"FormatLogWriter"
] | d146e6b86faab5f7e4d135cc63b749d74bf0d4a6 | https://github.com/alecthomas/log4go/blob/d146e6b86faab5f7e4d135cc63b749d74bf0d4a6/pattlog.go#L116-L120 |
153,383 | alecthomas/log4go | termlog.go | Close | func (c *ConsoleLogWriter) Close() {
close(c.w)
time.Sleep(50 * time.Millisecond) // Try to give console I/O time to complete
} | go | func (c *ConsoleLogWriter) Close() {
close(c.w)
time.Sleep(50 * time.Millisecond) // Try to give console I/O time to complete
} | [
"func",
"(",
"c",
"*",
"ConsoleLogWriter",
")",
"Close",
"(",
")",
"{",
"close",
"(",
"c",
".",
"w",
")",
"\n",
"time",
".",
"Sleep",
"(",
"50",
"*",
"time",
".",
"Millisecond",
")",
"// Try to give console I/O time to complete",
"\n",
"}"
] | // Close stops the logger from sending messages to standard output. Attempts to
// send log messages to this logger after a Close have undefined behavior. | [
"Close",
"stops",
"the",
"logger",
"from",
"sending",
"messages",
"to",
"standard",
"output",
".",
"Attempts",
"to",
"send",
"log",
"messages",
"to",
"this",
"logger",
"after",
"a",
"Close",
"have",
"undefined",
"behavior",
"."
] | d146e6b86faab5f7e4d135cc63b749d74bf0d4a6 | https://github.com/alecthomas/log4go/blob/d146e6b86faab5f7e4d135cc63b749d74bf0d4a6/termlog.go#L46-L49 |
153,384 | rook/operator-kit | sample-operator/pkg/client/clientset/versioned/typed/myproject/v1alpha1/fake/fake_sample.go | Get | func (c *FakeSamples) Get(name string, options v1.GetOptions) (result *v1alpha1.Sample, err error) {
obj, err := c.Fake.
Invokes(testing.NewGetAction(samplesResource, c.ns, name), &v1alpha1.Sample{})
if obj == nil {
return nil, err
}
return obj.(*v1alpha1.Sample), err
} | go | func (c *FakeSamples) Get(name string, options v1.GetOptions) (result *v1alpha1.Sample, err error) {
obj, err := c.Fake.
Invokes(testing.NewGetAction(samplesResource, c.ns, name), &v1alpha1.Sample{})
if obj == nil {
return nil, err
}
return obj.(*v1alpha1.Sample), err
} | [
"func",
"(",
"c",
"*",
"FakeSamples",
")",
"Get",
"(",
"name",
"string",
",",
"options",
"v1",
".",
"GetOptions",
")",
"(",
"result",
"*",
"v1alpha1",
".",
"Sample",
",",
"err",
"error",
")",
"{",
"obj",
",",
"err",
":=",
"c",
".",
"Fake",
".",
"Invokes",
"(",
"testing",
".",
"NewGetAction",
"(",
"samplesResource",
",",
"c",
".",
"ns",
",",
"name",
")",
",",
"&",
"v1alpha1",
".",
"Sample",
"{",
"}",
")",
"\n\n",
"if",
"obj",
"==",
"nil",
"{",
"return",
"nil",
",",
"err",
"\n",
"}",
"\n",
"return",
"obj",
".",
"(",
"*",
"v1alpha1",
".",
"Sample",
")",
",",
"err",
"\n",
"}"
] | // Get takes name of the sample, and returns the corresponding sample object, and an error if there is any. | [
"Get",
"takes",
"name",
"of",
"the",
"sample",
"and",
"returns",
"the",
"corresponding",
"sample",
"object",
"and",
"an",
"error",
"if",
"there",
"is",
"any",
"."
] | e7b2e1264fff5f1dc9d506089af2399621b5a0c1 | https://github.com/rook/operator-kit/blob/e7b2e1264fff5f1dc9d506089af2399621b5a0c1/sample-operator/pkg/client/clientset/versioned/typed/myproject/v1alpha1/fake/fake_sample.go#L42-L50 |
153,385 | rook/operator-kit | sample-operator/pkg/client/clientset/versioned/typed/myproject/v1alpha1/fake/fake_sample.go | List | func (c *FakeSamples) List(opts v1.ListOptions) (result *v1alpha1.SampleList, err error) {
obj, err := c.Fake.
Invokes(testing.NewListAction(samplesResource, samplesKind, c.ns, opts), &v1alpha1.SampleList{})
if obj == nil {
return nil, err
}
label, _, _ := testing.ExtractFromListOptions(opts)
if label == nil {
label = labels.Everything()
}
list := &v1alpha1.SampleList{ListMeta: obj.(*v1alpha1.SampleList).ListMeta}
for _, item := range obj.(*v1alpha1.SampleList).Items {
if label.Matches(labels.Set(item.Labels)) {
list.Items = append(list.Items, item)
}
}
return list, err
} | go | func (c *FakeSamples) List(opts v1.ListOptions) (result *v1alpha1.SampleList, err error) {
obj, err := c.Fake.
Invokes(testing.NewListAction(samplesResource, samplesKind, c.ns, opts), &v1alpha1.SampleList{})
if obj == nil {
return nil, err
}
label, _, _ := testing.ExtractFromListOptions(opts)
if label == nil {
label = labels.Everything()
}
list := &v1alpha1.SampleList{ListMeta: obj.(*v1alpha1.SampleList).ListMeta}
for _, item := range obj.(*v1alpha1.SampleList).Items {
if label.Matches(labels.Set(item.Labels)) {
list.Items = append(list.Items, item)
}
}
return list, err
} | [
"func",
"(",
"c",
"*",
"FakeSamples",
")",
"List",
"(",
"opts",
"v1",
".",
"ListOptions",
")",
"(",
"result",
"*",
"v1alpha1",
".",
"SampleList",
",",
"err",
"error",
")",
"{",
"obj",
",",
"err",
":=",
"c",
".",
"Fake",
".",
"Invokes",
"(",
"testing",
".",
"NewListAction",
"(",
"samplesResource",
",",
"samplesKind",
",",
"c",
".",
"ns",
",",
"opts",
")",
",",
"&",
"v1alpha1",
".",
"SampleList",
"{",
"}",
")",
"\n\n",
"if",
"obj",
"==",
"nil",
"{",
"return",
"nil",
",",
"err",
"\n",
"}",
"\n\n",
"label",
",",
"_",
",",
"_",
":=",
"testing",
".",
"ExtractFromListOptions",
"(",
"opts",
")",
"\n",
"if",
"label",
"==",
"nil",
"{",
"label",
"=",
"labels",
".",
"Everything",
"(",
")",
"\n",
"}",
"\n",
"list",
":=",
"&",
"v1alpha1",
".",
"SampleList",
"{",
"ListMeta",
":",
"obj",
".",
"(",
"*",
"v1alpha1",
".",
"SampleList",
")",
".",
"ListMeta",
"}",
"\n",
"for",
"_",
",",
"item",
":=",
"range",
"obj",
".",
"(",
"*",
"v1alpha1",
".",
"SampleList",
")",
".",
"Items",
"{",
"if",
"label",
".",
"Matches",
"(",
"labels",
".",
"Set",
"(",
"item",
".",
"Labels",
")",
")",
"{",
"list",
".",
"Items",
"=",
"append",
"(",
"list",
".",
"Items",
",",
"item",
")",
"\n",
"}",
"\n",
"}",
"\n",
"return",
"list",
",",
"err",
"\n",
"}"
] | // List takes label and field selectors, and returns the list of Samples that match those selectors. | [
"List",
"takes",
"label",
"and",
"field",
"selectors",
"and",
"returns",
"the",
"list",
"of",
"Samples",
"that",
"match",
"those",
"selectors",
"."
] | e7b2e1264fff5f1dc9d506089af2399621b5a0c1 | https://github.com/rook/operator-kit/blob/e7b2e1264fff5f1dc9d506089af2399621b5a0c1/sample-operator/pkg/client/clientset/versioned/typed/myproject/v1alpha1/fake/fake_sample.go#L53-L72 |
153,386 | rook/operator-kit | sample-operator/pkg/client/clientset/versioned/typed/myproject/v1alpha1/fake/fake_sample.go | Watch | func (c *FakeSamples) Watch(opts v1.ListOptions) (watch.Interface, error) {
return c.Fake.
InvokesWatch(testing.NewWatchAction(samplesResource, c.ns, opts))
} | go | func (c *FakeSamples) Watch(opts v1.ListOptions) (watch.Interface, error) {
return c.Fake.
InvokesWatch(testing.NewWatchAction(samplesResource, c.ns, opts))
} | [
"func",
"(",
"c",
"*",
"FakeSamples",
")",
"Watch",
"(",
"opts",
"v1",
".",
"ListOptions",
")",
"(",
"watch",
".",
"Interface",
",",
"error",
")",
"{",
"return",
"c",
".",
"Fake",
".",
"InvokesWatch",
"(",
"testing",
".",
"NewWatchAction",
"(",
"samplesResource",
",",
"c",
".",
"ns",
",",
"opts",
")",
")",
"\n\n",
"}"
] | // Watch returns a watch.Interface that watches the requested samples. | [
"Watch",
"returns",
"a",
"watch",
".",
"Interface",
"that",
"watches",
"the",
"requested",
"samples",
"."
] | e7b2e1264fff5f1dc9d506089af2399621b5a0c1 | https://github.com/rook/operator-kit/blob/e7b2e1264fff5f1dc9d506089af2399621b5a0c1/sample-operator/pkg/client/clientset/versioned/typed/myproject/v1alpha1/fake/fake_sample.go#L75-L79 |
153,387 | rook/operator-kit | sample-operator/pkg/client/clientset/versioned/typed/myproject/v1alpha1/fake/fake_sample.go | Delete | func (c *FakeSamples) Delete(name string, options *v1.DeleteOptions) error {
_, err := c.Fake.
Invokes(testing.NewDeleteAction(samplesResource, c.ns, name), &v1alpha1.Sample{})
return err
} | go | func (c *FakeSamples) Delete(name string, options *v1.DeleteOptions) error {
_, err := c.Fake.
Invokes(testing.NewDeleteAction(samplesResource, c.ns, name), &v1alpha1.Sample{})
return err
} | [
"func",
"(",
"c",
"*",
"FakeSamples",
")",
"Delete",
"(",
"name",
"string",
",",
"options",
"*",
"v1",
".",
"DeleteOptions",
")",
"error",
"{",
"_",
",",
"err",
":=",
"c",
".",
"Fake",
".",
"Invokes",
"(",
"testing",
".",
"NewDeleteAction",
"(",
"samplesResource",
",",
"c",
".",
"ns",
",",
"name",
")",
",",
"&",
"v1alpha1",
".",
"Sample",
"{",
"}",
")",
"\n\n",
"return",
"err",
"\n",
"}"
] | // Delete takes name of the sample and deletes it. Returns an error if one occurs. | [
"Delete",
"takes",
"name",
"of",
"the",
"sample",
"and",
"deletes",
"it",
".",
"Returns",
"an",
"error",
"if",
"one",
"occurs",
"."
] | e7b2e1264fff5f1dc9d506089af2399621b5a0c1 | https://github.com/rook/operator-kit/blob/e7b2e1264fff5f1dc9d506089af2399621b5a0c1/sample-operator/pkg/client/clientset/versioned/typed/myproject/v1alpha1/fake/fake_sample.go#L104-L109 |
153,388 | rook/operator-kit | sample-operator/pkg/client/clientset/versioned/typed/myproject/v1alpha1/fake/fake_sample.go | Patch | func (c *FakeSamples) Patch(name string, pt types.PatchType, data []byte, subresources ...string) (result *v1alpha1.Sample, err error) {
obj, err := c.Fake.
Invokes(testing.NewPatchSubresourceAction(samplesResource, c.ns, name, data, subresources...), &v1alpha1.Sample{})
if obj == nil {
return nil, err
}
return obj.(*v1alpha1.Sample), err
} | go | func (c *FakeSamples) Patch(name string, pt types.PatchType, data []byte, subresources ...string) (result *v1alpha1.Sample, err error) {
obj, err := c.Fake.
Invokes(testing.NewPatchSubresourceAction(samplesResource, c.ns, name, data, subresources...), &v1alpha1.Sample{})
if obj == nil {
return nil, err
}
return obj.(*v1alpha1.Sample), err
} | [
"func",
"(",
"c",
"*",
"FakeSamples",
")",
"Patch",
"(",
"name",
"string",
",",
"pt",
"types",
".",
"PatchType",
",",
"data",
"[",
"]",
"byte",
",",
"subresources",
"...",
"string",
")",
"(",
"result",
"*",
"v1alpha1",
".",
"Sample",
",",
"err",
"error",
")",
"{",
"obj",
",",
"err",
":=",
"c",
".",
"Fake",
".",
"Invokes",
"(",
"testing",
".",
"NewPatchSubresourceAction",
"(",
"samplesResource",
",",
"c",
".",
"ns",
",",
"name",
",",
"data",
",",
"subresources",
"...",
")",
",",
"&",
"v1alpha1",
".",
"Sample",
"{",
"}",
")",
"\n\n",
"if",
"obj",
"==",
"nil",
"{",
"return",
"nil",
",",
"err",
"\n",
"}",
"\n",
"return",
"obj",
".",
"(",
"*",
"v1alpha1",
".",
"Sample",
")",
",",
"err",
"\n",
"}"
] | // Patch applies the patch and returns the patched sample. | [
"Patch",
"applies",
"the",
"patch",
"and",
"returns",
"the",
"patched",
"sample",
"."
] | e7b2e1264fff5f1dc9d506089af2399621b5a0c1 | https://github.com/rook/operator-kit/blob/e7b2e1264fff5f1dc9d506089af2399621b5a0c1/sample-operator/pkg/client/clientset/versioned/typed/myproject/v1alpha1/fake/fake_sample.go#L120-L128 |
153,389 | rook/operator-kit | sample-operator/pkg/client/clientset/versioned/typed/myproject/v1alpha1/sample.go | newSamples | func newSamples(c *MyprojectV1alpha1Client, namespace string) *samples {
return &samples{
client: c.RESTClient(),
ns: namespace,
}
} | go | func newSamples(c *MyprojectV1alpha1Client, namespace string) *samples {
return &samples{
client: c.RESTClient(),
ns: namespace,
}
} | [
"func",
"newSamples",
"(",
"c",
"*",
"MyprojectV1alpha1Client",
",",
"namespace",
"string",
")",
"*",
"samples",
"{",
"return",
"&",
"samples",
"{",
"client",
":",
"c",
".",
"RESTClient",
"(",
")",
",",
"ns",
":",
"namespace",
",",
"}",
"\n",
"}"
] | // newSamples returns a Samples | [
"newSamples",
"returns",
"a",
"Samples"
] | e7b2e1264fff5f1dc9d506089af2399621b5a0c1 | https://github.com/rook/operator-kit/blob/e7b2e1264fff5f1dc9d506089af2399621b5a0c1/sample-operator/pkg/client/clientset/versioned/typed/myproject/v1alpha1/sample.go#L56-L61 |
153,390 | rook/operator-kit | sample-operator/pkg/apis/myproject/v1alpha1/zz_generated.deepcopy.go | DeepCopy | func (in *Sample) DeepCopy() *Sample {
if in == nil {
return nil
}
out := new(Sample)
in.DeepCopyInto(out)
return out
} | go | func (in *Sample) DeepCopy() *Sample {
if in == nil {
return nil
}
out := new(Sample)
in.DeepCopyInto(out)
return out
} | [
"func",
"(",
"in",
"*",
"Sample",
")",
"DeepCopy",
"(",
")",
"*",
"Sample",
"{",
"if",
"in",
"==",
"nil",
"{",
"return",
"nil",
"\n",
"}",
"\n",
"out",
":=",
"new",
"(",
"Sample",
")",
"\n",
"in",
".",
"DeepCopyInto",
"(",
"out",
")",
"\n",
"return",
"out",
"\n",
"}"
] | // DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new Sample. | [
"DeepCopy",
"is",
"an",
"autogenerated",
"deepcopy",
"function",
"copying",
"the",
"receiver",
"creating",
"a",
"new",
"Sample",
"."
] | e7b2e1264fff5f1dc9d506089af2399621b5a0c1 | https://github.com/rook/operator-kit/blob/e7b2e1264fff5f1dc9d506089af2399621b5a0c1/sample-operator/pkg/apis/myproject/v1alpha1/zz_generated.deepcopy.go#L37-L44 |
153,391 | rook/operator-kit | sample-operator/pkg/apis/myproject/v1alpha1/zz_generated.deepcopy.go | DeepCopy | func (in *SampleList) DeepCopy() *SampleList {
if in == nil {
return nil
}
out := new(SampleList)
in.DeepCopyInto(out)
return out
} | go | func (in *SampleList) DeepCopy() *SampleList {
if in == nil {
return nil
}
out := new(SampleList)
in.DeepCopyInto(out)
return out
} | [
"func",
"(",
"in",
"*",
"SampleList",
")",
"DeepCopy",
"(",
")",
"*",
"SampleList",
"{",
"if",
"in",
"==",
"nil",
"{",
"return",
"nil",
"\n",
"}",
"\n",
"out",
":=",
"new",
"(",
"SampleList",
")",
"\n",
"in",
".",
"DeepCopyInto",
"(",
"out",
")",
"\n",
"return",
"out",
"\n",
"}"
] | // DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new SampleList. | [
"DeepCopy",
"is",
"an",
"autogenerated",
"deepcopy",
"function",
"copying",
"the",
"receiver",
"creating",
"a",
"new",
"SampleList",
"."
] | e7b2e1264fff5f1dc9d506089af2399621b5a0c1 | https://github.com/rook/operator-kit/blob/e7b2e1264fff5f1dc9d506089af2399621b5a0c1/sample-operator/pkg/apis/myproject/v1alpha1/zz_generated.deepcopy.go#L70-L77 |
153,392 | rook/operator-kit | sample-operator/pkg/apis/myproject/v1alpha1/zz_generated.deepcopy.go | DeepCopy | func (in *SampleSpec) DeepCopy() *SampleSpec {
if in == nil {
return nil
}
out := new(SampleSpec)
in.DeepCopyInto(out)
return out
} | go | func (in *SampleSpec) DeepCopy() *SampleSpec {
if in == nil {
return nil
}
out := new(SampleSpec)
in.DeepCopyInto(out)
return out
} | [
"func",
"(",
"in",
"*",
"SampleSpec",
")",
"DeepCopy",
"(",
")",
"*",
"SampleSpec",
"{",
"if",
"in",
"==",
"nil",
"{",
"return",
"nil",
"\n",
"}",
"\n",
"out",
":=",
"new",
"(",
"SampleSpec",
")",
"\n",
"in",
".",
"DeepCopyInto",
"(",
"out",
")",
"\n",
"return",
"out",
"\n",
"}"
] | // DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new SampleSpec. | [
"DeepCopy",
"is",
"an",
"autogenerated",
"deepcopy",
"function",
"copying",
"the",
"receiver",
"creating",
"a",
"new",
"SampleSpec",
"."
] | e7b2e1264fff5f1dc9d506089af2399621b5a0c1 | https://github.com/rook/operator-kit/blob/e7b2e1264fff5f1dc9d506089af2399621b5a0c1/sample-operator/pkg/apis/myproject/v1alpha1/zz_generated.deepcopy.go#L94-L101 |
153,393 | rook/operator-kit | sample-operator/pkg/client/clientset/versioned/fake/clientset_generated.go | MyprojectV1alpha1 | func (c *Clientset) MyprojectV1alpha1() myprojectv1alpha1.MyprojectV1alpha1Interface {
return &fakemyprojectv1alpha1.FakeMyprojectV1alpha1{Fake: &c.Fake}
} | go | func (c *Clientset) MyprojectV1alpha1() myprojectv1alpha1.MyprojectV1alpha1Interface {
return &fakemyprojectv1alpha1.FakeMyprojectV1alpha1{Fake: &c.Fake}
} | [
"func",
"(",
"c",
"*",
"Clientset",
")",
"MyprojectV1alpha1",
"(",
")",
"myprojectv1alpha1",
".",
"MyprojectV1alpha1Interface",
"{",
"return",
"&",
"fakemyprojectv1alpha1",
".",
"FakeMyprojectV1alpha1",
"{",
"Fake",
":",
"&",
"c",
".",
"Fake",
"}",
"\n",
"}"
] | // MyprojectV1alpha1 retrieves the MyprojectV1alpha1Client | [
"MyprojectV1alpha1",
"retrieves",
"the",
"MyprojectV1alpha1Client"
] | e7b2e1264fff5f1dc9d506089af2399621b5a0c1 | https://github.com/rook/operator-kit/blob/e7b2e1264fff5f1dc9d506089af2399621b5a0c1/sample-operator/pkg/client/clientset/versioned/fake/clientset_generated.go#L75-L77 |
153,394 | rook/operator-kit | sample-operator/pkg/client/clientset/versioned/fake/clientset_generated.go | Myproject | func (c *Clientset) Myproject() myprojectv1alpha1.MyprojectV1alpha1Interface {
return &fakemyprojectv1alpha1.FakeMyprojectV1alpha1{Fake: &c.Fake}
} | go | func (c *Clientset) Myproject() myprojectv1alpha1.MyprojectV1alpha1Interface {
return &fakemyprojectv1alpha1.FakeMyprojectV1alpha1{Fake: &c.Fake}
} | [
"func",
"(",
"c",
"*",
"Clientset",
")",
"Myproject",
"(",
")",
"myprojectv1alpha1",
".",
"MyprojectV1alpha1Interface",
"{",
"return",
"&",
"fakemyprojectv1alpha1",
".",
"FakeMyprojectV1alpha1",
"{",
"Fake",
":",
"&",
"c",
".",
"Fake",
"}",
"\n",
"}"
] | // Myproject retrieves the MyprojectV1alpha1Client | [
"Myproject",
"retrieves",
"the",
"MyprojectV1alpha1Client"
] | e7b2e1264fff5f1dc9d506089af2399621b5a0c1 | https://github.com/rook/operator-kit/blob/e7b2e1264fff5f1dc9d506089af2399621b5a0c1/sample-operator/pkg/client/clientset/versioned/fake/clientset_generated.go#L80-L82 |
153,395 | rook/operator-kit | sample-operator/pkg/client/listers/myproject/v1alpha1/sample.go | List | func (s *sampleLister) List(selector labels.Selector) (ret []*v1alpha1.Sample, err error) {
err = cache.ListAll(s.indexer, selector, func(m interface{}) {
ret = append(ret, m.(*v1alpha1.Sample))
})
return ret, err
} | go | func (s *sampleLister) List(selector labels.Selector) (ret []*v1alpha1.Sample, err error) {
err = cache.ListAll(s.indexer, selector, func(m interface{}) {
ret = append(ret, m.(*v1alpha1.Sample))
})
return ret, err
} | [
"func",
"(",
"s",
"*",
"sampleLister",
")",
"List",
"(",
"selector",
"labels",
".",
"Selector",
")",
"(",
"ret",
"[",
"]",
"*",
"v1alpha1",
".",
"Sample",
",",
"err",
"error",
")",
"{",
"err",
"=",
"cache",
".",
"ListAll",
"(",
"s",
".",
"indexer",
",",
"selector",
",",
"func",
"(",
"m",
"interface",
"{",
"}",
")",
"{",
"ret",
"=",
"append",
"(",
"ret",
",",
"m",
".",
"(",
"*",
"v1alpha1",
".",
"Sample",
")",
")",
"\n",
"}",
")",
"\n",
"return",
"ret",
",",
"err",
"\n",
"}"
] | // List lists all Samples in the indexer. | [
"List",
"lists",
"all",
"Samples",
"in",
"the",
"indexer",
"."
] | e7b2e1264fff5f1dc9d506089af2399621b5a0c1 | https://github.com/rook/operator-kit/blob/e7b2e1264fff5f1dc9d506089af2399621b5a0c1/sample-operator/pkg/client/listers/myproject/v1alpha1/sample.go#L48-L53 |
153,396 | rook/operator-kit | sample-operator/pkg/client/listers/myproject/v1alpha1/sample.go | Samples | func (s *sampleLister) Samples(namespace string) SampleNamespaceLister {
return sampleNamespaceLister{indexer: s.indexer, namespace: namespace}
} | go | func (s *sampleLister) Samples(namespace string) SampleNamespaceLister {
return sampleNamespaceLister{indexer: s.indexer, namespace: namespace}
} | [
"func",
"(",
"s",
"*",
"sampleLister",
")",
"Samples",
"(",
"namespace",
"string",
")",
"SampleNamespaceLister",
"{",
"return",
"sampleNamespaceLister",
"{",
"indexer",
":",
"s",
".",
"indexer",
",",
"namespace",
":",
"namespace",
"}",
"\n",
"}"
] | // Samples returns an object that can list and get Samples. | [
"Samples",
"returns",
"an",
"object",
"that",
"can",
"list",
"and",
"get",
"Samples",
"."
] | e7b2e1264fff5f1dc9d506089af2399621b5a0c1 | https://github.com/rook/operator-kit/blob/e7b2e1264fff5f1dc9d506089af2399621b5a0c1/sample-operator/pkg/client/listers/myproject/v1alpha1/sample.go#L56-L58 |
153,397 | rook/operator-kit | sample-operator/pkg/client/listers/myproject/v1alpha1/sample.go | List | func (s sampleNamespaceLister) List(selector labels.Selector) (ret []*v1alpha1.Sample, err error) {
err = cache.ListAllByNamespace(s.indexer, s.namespace, selector, func(m interface{}) {
ret = append(ret, m.(*v1alpha1.Sample))
})
return ret, err
} | go | func (s sampleNamespaceLister) List(selector labels.Selector) (ret []*v1alpha1.Sample, err error) {
err = cache.ListAllByNamespace(s.indexer, s.namespace, selector, func(m interface{}) {
ret = append(ret, m.(*v1alpha1.Sample))
})
return ret, err
} | [
"func",
"(",
"s",
"sampleNamespaceLister",
")",
"List",
"(",
"selector",
"labels",
".",
"Selector",
")",
"(",
"ret",
"[",
"]",
"*",
"v1alpha1",
".",
"Sample",
",",
"err",
"error",
")",
"{",
"err",
"=",
"cache",
".",
"ListAllByNamespace",
"(",
"s",
".",
"indexer",
",",
"s",
".",
"namespace",
",",
"selector",
",",
"func",
"(",
"m",
"interface",
"{",
"}",
")",
"{",
"ret",
"=",
"append",
"(",
"ret",
",",
"m",
".",
"(",
"*",
"v1alpha1",
".",
"Sample",
")",
")",
"\n",
"}",
")",
"\n",
"return",
"ret",
",",
"err",
"\n",
"}"
] | // List lists all Samples in the indexer for a given namespace. | [
"List",
"lists",
"all",
"Samples",
"in",
"the",
"indexer",
"for",
"a",
"given",
"namespace",
"."
] | e7b2e1264fff5f1dc9d506089af2399621b5a0c1 | https://github.com/rook/operator-kit/blob/e7b2e1264fff5f1dc9d506089af2399621b5a0c1/sample-operator/pkg/client/listers/myproject/v1alpha1/sample.go#L77-L82 |
153,398 | rook/operator-kit | sample-operator/controller.go | newSampleController | func newSampleController(context *opkit.Context, sampleClientset sampleclient.MyprojectV1alpha1Interface) *SampleController {
return &SampleController{
context: context,
sampleClientset: sampleClientset,
}
} | go | func newSampleController(context *opkit.Context, sampleClientset sampleclient.MyprojectV1alpha1Interface) *SampleController {
return &SampleController{
context: context,
sampleClientset: sampleClientset,
}
} | [
"func",
"newSampleController",
"(",
"context",
"*",
"opkit",
".",
"Context",
",",
"sampleClientset",
"sampleclient",
".",
"MyprojectV1alpha1Interface",
")",
"*",
"SampleController",
"{",
"return",
"&",
"SampleController",
"{",
"context",
":",
"context",
",",
"sampleClientset",
":",
"sampleClientset",
",",
"}",
"\n",
"}"
] | // newSampleController create controller for watching sample custom resources created | [
"newSampleController",
"create",
"controller",
"for",
"watching",
"sample",
"custom",
"resources",
"created"
] | e7b2e1264fff5f1dc9d506089af2399621b5a0c1 | https://github.com/rook/operator-kit/blob/e7b2e1264fff5f1dc9d506089af2399621b5a0c1/sample-operator/controller.go#L36-L41 |
153,399 | rook/operator-kit | sample-operator/controller.go | StartWatch | func (c *SampleController) StartWatch(namespace string, stopCh chan struct{}) error {
resourceHandlers := cache.ResourceEventHandlerFuncs{
AddFunc: c.onAdd,
UpdateFunc: c.onUpdate,
DeleteFunc: c.onDelete,
}
restClient := c.sampleClientset.RESTClient()
watcher := opkit.NewWatcher(sample.SampleResource, namespace, resourceHandlers, restClient)
go watcher.Watch(&sample.Sample{}, stopCh)
return nil
} | go | func (c *SampleController) StartWatch(namespace string, stopCh chan struct{}) error {
resourceHandlers := cache.ResourceEventHandlerFuncs{
AddFunc: c.onAdd,
UpdateFunc: c.onUpdate,
DeleteFunc: c.onDelete,
}
restClient := c.sampleClientset.RESTClient()
watcher := opkit.NewWatcher(sample.SampleResource, namespace, resourceHandlers, restClient)
go watcher.Watch(&sample.Sample{}, stopCh)
return nil
} | [
"func",
"(",
"c",
"*",
"SampleController",
")",
"StartWatch",
"(",
"namespace",
"string",
",",
"stopCh",
"chan",
"struct",
"{",
"}",
")",
"error",
"{",
"resourceHandlers",
":=",
"cache",
".",
"ResourceEventHandlerFuncs",
"{",
"AddFunc",
":",
"c",
".",
"onAdd",
",",
"UpdateFunc",
":",
"c",
".",
"onUpdate",
",",
"DeleteFunc",
":",
"c",
".",
"onDelete",
",",
"}",
"\n",
"restClient",
":=",
"c",
".",
"sampleClientset",
".",
"RESTClient",
"(",
")",
"\n",
"watcher",
":=",
"opkit",
".",
"NewWatcher",
"(",
"sample",
".",
"SampleResource",
",",
"namespace",
",",
"resourceHandlers",
",",
"restClient",
")",
"\n",
"go",
"watcher",
".",
"Watch",
"(",
"&",
"sample",
".",
"Sample",
"{",
"}",
",",
"stopCh",
")",
"\n",
"return",
"nil",
"\n",
"}"
] | // Watch watches for instances of Sample custom resources and acts on them | [
"Watch",
"watches",
"for",
"instances",
"of",
"Sample",
"custom",
"resources",
"and",
"acts",
"on",
"them"
] | e7b2e1264fff5f1dc9d506089af2399621b5a0c1 | https://github.com/rook/operator-kit/blob/e7b2e1264fff5f1dc9d506089af2399621b5a0c1/sample-operator/controller.go#L44-L55 |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.