package main

import (
	"image"
	_ "image/png"
	_ "image/jpeg"
	"image/color"
	"image/png"
	"os"
)

type Merge struct {
	first, second image.Image
}

func (m Merge) ColorModel() color.Model { return m.first.ColorModel() }
func (m Merge) Bounds() image.Rectangle { return m.first.Bounds() }

func (m Merge) At(x, y int) color.Color {
	if (x%2 != 0) && (y%2 != 0) {
		return m.second.At(x, y)
	}
	return m.first.At(x, y)
}

func main() {
	f1, err := os.Open(os.Args[1])
	if err != nil {
		panic(err)
	}
	f2, err := os.Open(os.Args[2])
	if err != nil {
		panic(err)
	}
	img1, _, err := image.Decode(f1)
	if err != nil {
		panic(err)
	}
	img2, _, err := image.Decode(f2)
	if err != nil {
		panic(err)
	}
	png.Encode(os.Stdout, Merge{img1, img2})
}
