FAQ
Hi,

I was just trying to write a small go program to stitch all the tiles of
todays xkcd comic together (http://xkcd.org/1110/).
The big picture is put together from 81x32 tiles with 2048x2048 pixels each
resulting in an output image of the dimensions 165888x65536.

My small programm takes the naive approach of just pasting the tiles in a
new NRGBA image and saving that to disk.

Unfortunately the png.Encode step fails:

panic: runtime error: index out of range

goroutine 1 [running]:
image.(*NRGBA).Set(0xf840031cc0, 0x32a00000000, 0xf840031bd0, 0xf8ff0000ff,
0xf840031cc0, ...)
/home/schlinse/go/src/pkg/image/image.go:297 +0x160
image/draw.DrawMask(0xf84002f5c0, 0xf840031cc0, 0x0, 0x7ff000007ff,
0xf84002f4c0, ...)
/home/schlinse/go/src/pkg/image/draw/draw.go:145 +0xcd7
image/draw.Draw(0xf84002f5c0, 0xf840031cc0, 0x0, 0x7ff000007ff,
0xf84002f4c0, ...)
/home/schlinse/go/src/pkg/image/draw/draw.go:37 +0x95
main.main()
/home/me/code/xkcd_image_stitch/src/stitch/stitch.go:65 +0x829

goroutine 2 [syscall]:
created by runtime.main
/home/me/go/src/pkg/runtime/proc.c:221

Guess I am running out of memory there. The same happens if I just try to
fill an in-memory image of the same dimensions with one color.
So I tried to reduce the number of tiles to stitch together.
Interestingly at a size of 34x14 tiles (69632x28672 pixels) the initial
call to image.NewNRGBA fails:

panic: runtime error: makeslice: len out of range

goroutine 1 [running]:
image.NewNRGBA(0x0, 0x700000018800, 0x0, 0x700000018800, 0x7, ...)
/home/me/go/src/pkg/image/image.go:353 +0x91
main.main()
/home/me/code/xkcd_image_stitch/src/stitch/stitch.go:26 +0xb3

goroutine 2 [syscall]:
created by runtime.main
/home/me/go/src/pkg/runtime/proc.c:221

Why doesn't the NewNRGBA complain when I create the much larger image?

I am running 64 bit Go on Linux with 8 GB of RAM if it matters.

--

Search Discussions

  • Volker Dobler at Sep 19, 2012 at 11:13 am
    Hi,

    I think the image gets too big in the following sense:
    165888 x 65536 = 10871635968 pixels in total.
    At 4 byte per pixel (8 bit for each of RGBA) your
    image is backed by a []uint8 with 43486543872
    elements. Unfortunately this cannot be index with
    a 32bit int.

    I am unsure why make didn't fail in the first place
    like in your second example.

    Try a image.Gray, it will fit.

    Volker

    On 19 Sep., 11:35, Sebastian Schlingmann
    wrote:
    Hi,

    I was just trying to write a small go program to stitch all the tiles of
    todays xkcd comic together (http://xkcd.org/1110/).
    The big picture is put together from 81x32 tiles with 2048x2048 pixels each
    resulting in an output image of the dimensions 165888x65536.

    My small programm takes the naive approach of just pasting the tiles in a
    new NRGBA image and saving that to disk.

    Unfortunately the png.Encode step fails:

    panic: runtime error: index out of range

    goroutine 1 [running]:
    image.(*NRGBA).Set(0xf840031cc0, 0x32a00000000, 0xf840031bd0, 0xf8ff0000ff,
    0xf840031cc0, ...)
    /home/schlinse/go/src/pkg/image/image.go:297 +0x160
    image/draw.DrawMask(0xf84002f5c0, 0xf840031cc0, 0x0, 0x7ff000007ff,
    0xf84002f4c0, ...)
    /home/schlinse/go/src/pkg/image/draw/draw.go:145 +0xcd7
    image/draw.Draw(0xf84002f5c0, 0xf840031cc0, 0x0, 0x7ff000007ff,
    0xf84002f4c0, ...)
    /home/schlinse/go/src/pkg/image/draw/draw.go:37 +0x95
    main.main()
    /home/me/code/xkcd_image_stitch/src/stitch/stitch.go:65 +0x829

    goroutine 2 [syscall]:
    created by runtime.main
    /home/me/go/src/pkg/runtime/proc.c:221

    Guess I am running out of memory there. The same happens if I just try to
    fill an in-memory image of the same dimensions with one color.
    So I tried to reduce the number of tiles to stitch together.
    Interestingly at a size of 34x14 tiles (69632x28672 pixels) the initial
    call to image.NewNRGBA fails:

    panic: runtime error: makeslice: len out of range

    goroutine 1 [running]:
    image.NewNRGBA(0x0, 0x700000018800, 0x0, 0x700000018800, 0x7, ...)
    /home/me/go/src/pkg/image/image.go:353 +0x91
    main.main()
    /home/me/code/xkcd_image_stitch/src/stitch/stitch.go:26 +0xb3

    goroutine 2 [syscall]:
    created by runtime.main
    /home/me/go/src/pkg/runtime/proc.c:221

    Why doesn't the NewNRGBA complain when I create the much larger image?

    I am running 64 bit Go on Linux with 8 GB of RAM if it matters.
    --
  • Sebastian Schlingmann at Sep 19, 2012 at 11:19 am
    Unfortunately image.Gray also fails. This time I also got the "makeslice:
    len out of range" runtime error with the original size (81x32 tiles).
    On Wednesday, September 19, 2012 1:05:17 PM UTC+2, Volker Dobler wrote:


    Try a image.Gray, it will fit.
    --

Related Discussions

Discussion Navigation
viewthread | post
Discussion Overview
groupgolang-nuts @
categoriesgo
postedSep 19, '12 at 10:29a
activeSep 19, '12 at 11:19a
posts3
users2
websitegolang.org

People

Translate

site design / logo © 2021 Grokbase