Thomas Oehrling - 2011-01-17

Hello,

I have two problems.
The first problem is that I have a matrix that have a negativ tx or ty value but the result image should get a part of the transformed image. for example:

gm convert \
        -size 692x1520 \
        -type TrueColorMatte \
        xc:none \
        -affine "0.3188258176,0.0000000000,0.0000000000,0.3188258176,-368,8" \
        -draw 'image over 0,0 0,0 image.jpg' \
        -crop 692x1520+2+2 \
        img_temp.png

I am wondering that I need a workaround to prevent memory allocation errors. My actual workaround use the negative tx value of the matrix to extend the x value of the size and the offset of the croping like the following and set the tx to zero:

gm convert \
        -size 1060x1520 \
        -type TrueColorMatte \
        xc:none \
        -affine "0.3188258176,0.0000000000,0.0000000000,0.3188258176,0,8" \
        -draw 'image over 0,0 0,0 image.jpg' \
        -crop 692x1520+370+2 \
        img_temp.png

This give me the correct result. I not really understand that this kind of workaround is needed because a negative tx or ty should work in my opinion.

The second problem follows by the first. If I have a matrix that is outside of the canvas like this:

gm convert \
        -size 767x1605 \
        xc:none \
        -type TrueColorMatte \
        -affine "-0.0057386350,1.2580197319,-2.1700619533,-0.0098990454,1251,105" \
        -draw 'image over 0,0 0,0 image.jpg' \
        -crop 767x1605+2+3 \
        img_temp.png

In this case the matrix forces the image left outside of the canvas and I get a "gm convert: Memory allocation failed (none)." error. The debug informations say "unable to resize image (Non-zero width and height required)".

gm identify give me "JPEG 1024x768+0+0 DirectClass 8-bit 69.5K 0.000u 0:01" for the jpg and the error ist reproduceble with gm version "GraphicsMagick 1.3.12".

At the end I put the wohle debug informations hopefully someone have a suggestion how I can solve this maybe mathematically or with another workaround.

Thank you

Thomas Oehrling

11:55:35 0:01 0.000u 5780 constitute.c/ReadImage/8235/Blob:
  Magick=XC, Filename=none
11:55:35 0:01 0.000u 5780 constitute.c/ReadImage/8347/Coder:
  Invoking "XC" decoder (Constant image uniform color) subimage=0 subrange=0
11:55:35 0:01 0.000u 5780 blob.c/GetConfigureBlob/1760/Configure:
  Searching for file "colors.mgk" in path "/usr/share/GraphicsMagick-1.3.12/config/:/usr/lib/GraphicsMagick-1.3.12/config/"
11:55:35 0:01 0.000u 5780 blob.c/GetConfigureBlob/1783/Configure:
  Found: /usr/share/GraphicsMagick-1.3.12/config/colors.mgk
11:55:35 0:01 0.000u 5780 resource.c/AcquireMagickResource/224/Resource:
  pixels +1.9MP/---/Unlimited
11:55:35 0:01 0.000u 5780 resource.c/AcquireMagickResource/224/Resource:
  memory +9.6MB/9.6MB/7.8GB
11:55:35 0:01 0.000u 5780 pixel_cache.c/OpenCache/3050/Cache:
  open none (9.6M)
11:55:35 0:01 0.010u 5780 constitute.c/ReadImage/8358/Coder:
  Returned from "XC" decoder: monochrome=True grayscale=True class=DirectClass colorspace=RGB
11:55:35 0:01 0.010u 5780 render.c/DrawImage/1655/Draw:
  begin draw-image
11:55:35 0:01 0.010u 5780 render.c/DrawImage/2934/Draw:
    image over 0,0 0,0 image.jpg
11:55:35 0:01 0.010u 5780 render.c/DrawPrimitive/3751/Draw:
    begin draw-primitive
11:55:35 0:01 0.010u 5780 render.c/DrawPrimitive/3752/Draw:
      affine: -0.00573863,1.25802,-2.17006,-0.00989905,1251,105
11:55:35 0:01 0.010u 5780 blob.c/OpenBlob/2361/Blob:
  Opening Blob for image 0x0x7f8094d30600 using ReadBinary mode …
11:55:36 0:01 0.100u 5780 blob.c/OpenBlob/2544/Blob:
    I/O buffer set to 16384 bytes
11:55:36 0:01 0.100u 5780 blob.c/OpenBlob/2564/Blob:
    opened file "image.jpg" as FileStream blob 0x0x7f8094d32098
11:55:36 0:01 0.100u 5780 blob.c/OpenBlob/2577/Blob:
    read 2053 magic header bytes
11:55:36 0:01 0.100u 5780 blob.c/CloseBlob/856/Blob:
  Closing FileStream blob 0x7f8094d32098
11:55:36 0:01 0.100u 5780 pixel_cache.c/DestroyCacheInfo/1733/Cache:
  destroy cache
11:55:36 0:01 0.100u 5780 blob.c/DestroyBlob/989/Blob:
  Destroy blob, image=0x7f8094d30600, filename="image.jpg"
11:55:36 0:01 0.100u 5780 constitute.c/ReadImage/8235/Blob:
  Magick=JPEG, Filename=image.jpg
11:55:36 0:01 0.100u 5780 constitute.c/ReadImage/8347/Coder:
  Invoking "JPEG" decoder (Joint Photographic Experts Group JFIF format) subimage=0 subrange=0
11:55:36 0:01 0.100u 5780 blob.c/OpenBlob/2361/Blob:
  Opening Blob for image 0x0x7f8094d30600 using ReadBinary mode …
11:55:36 0:01 0.170u 5780 blob.c/OpenBlob/2544/Blob:
    I/O buffer set to 16384 bytes
11:55:36 0:01 0.170u 5780 blob.c/OpenBlob/2564/Blob:
    opened file "image.jpg" as FileStream blob 0x0x7f8094d32098
11:55:36 0:01 0.170u 5780 blob.c/OpenBlob/2577/Blob:
    read 2053 magic header bytes
11:55:36 0:01 0.170u 5780 profile.c/SetImageProfile/1171/Transform:
  Adding EXIF profile with length 2991 bytes
11:55:36 0:01 0.170u 5780 jpeg.c/ReadGenericProfile/394/Coder:
  Profile: EXIF, 2991 bytes
11:55:36 0:01 0.170u 5780 jpeg.c/ReadIPTCProfile/562/Coder:
  Profile: IPTC, 4146 bytes
11:55:36 0:01 0.170u 5780 profile.c/SetImageProfile/1171/Transform:
  Adding IPTC profile with length 4146 bytes
11:55:36 0:01 0.170u 5780 profile.c/SetImageProfile/1171/Transform:
  Adding APP1 profile with length 4678 bytes
11:55:36 0:01 0.170u 5780 jpeg.c/ReadGenericProfile/394/Coder:
  Profile: APP1, 4678 bytes
11:55:36 0:01 0.200u 5780 jpeg.c/ReadJPEGImage/1139/Coder:
  Interlace: progressive
11:55:36 0:01 0.200u 5780 jpeg.c/ReadJPEGImage/1144/Coder:
  Data precision: 8
11:55:36 0:01 0.200u 5780 jpeg.c/ReadJPEGImage/1146/Coder:
  Components: 3
11:55:36 0:01 0.200u 5780 jpeg.c/ReadJPEGImage/1148/Coder:
  Geometry: 1024x768
11:55:36 0:01 0.200u 5780 jpeg.c/ReadJPEGImage/1151/Coder:
  DCT Method: 0
11:55:36 0:01 0.200u 5780 jpeg.c/ReadJPEGImage/1153/Coder:
  Fancy Upsampling: true
11:55:36 0:01 0.200u 5780 jpeg.c/ReadJPEGImage/1155/Coder:
  Block Smoothing: true
11:55:36 0:01 0.210u 5780 jpeg.c/EstimateJPEGQuality/711/Coder:
  Quality: 94 (approximate)
11:55:36 0:01 0.210u 5780 jpeg.c/ReadJPEGImage/1175/Coder:
  Colorspace: RGB (2)
11:55:36 0:01 0.210u 5780 jpeg.c/ReadJPEGImage/1182/Coder:
  Sampling Factors: 1x1,1x1,1x1
11:55:36 0:01 0.210u 5780 resource.c/AcquireMagickResource/224/Resource:
  pixels +768.0KP/---/Unlimited
11:55:36 0:01 0.210u 5780 resource.c/AcquireMagickResource/224/Resource:
  memory +3.8MB/13.3MB/7.8GB
11:55:36 0:01 0.210u 5780 pixel_cache.c/OpenCache/3050/Cache:
  open /var/www/resources/usermotives/motiveHeightResImages/2084291818.jpg (3.8M)
11:55:36 0:01 0.340u 5780 blob.c/CloseBlob/856/Blob:
  Closing FileStream blob 0x7f8094d32098
11:55:36 0:01 0.340u 5780 jpeg.c/ReadJPEGImage/1354/Coder:
  return
11:55:36 0:01 0.340u 5780 constitute.c/ReadImage/8358/Coder:
  Returned from "JPEG" decoder: monochrome=False grayscale=False class=DirectClass colorspace=RGB
11:55:36 0:01 0.340u 5780 resize.c/ResizeImage/1283/image:
  unable to resize image (Non-zero width and height required)
11:55:36 0:01 0.370u 5780 pixel_cache.c/SetNexus/4097/Cache:
  Failed to allocate 18446744073709550048 bytes for nexus staging (number pixels=18446744073709551224, region width=18446744073709551224, region height=1, cache columns=1252)!
11:55:36 0:01 0.370u 5780 pixel_cache.c/SetNexus/4097/Cache:
  Failed to allocate 18446744073709550924 bytes for nexus staging (number pixels=18446744073709551443, region width=18446744073709551443, region height=1, cache columns=1252)!
11:55:36 0:01 0.370u 5780 pixel_cache.c/SetNexus/4107/Resource:
   ()
11:55:36 0:01 0.370u 5780 pixel_cache.c/SetNexus/4107/Resource:
  Memory allocation failed (none)
11:55:36 0:01 0.370u 5780 resource.c/LiberateMagickResource/752/Resource:
  memory -3.8MB/9.6MB/7.8GB
11:55:36 0:01 0.370u 5780 pixel_cache.c/DestroyCacheInfo/1733/Cache:
  destroy cache /var/www/resources/usermotives/motiveHeightResImages/2084291818.jpg
11:55:36 0:01 0.370u 5780 blob.c/DestroyBlob/989/Blob:
  Destroy blob, image=0x7f8094d30600, filename="image.jpg"
11:55:36 0:01 0.370u 5780 render.c/DrawPrimitive/4060/Draw:
    end draw-primitive
11:55:36 0:01 0.370u 5780 render.c/DrawImage/2980/Draw:
  end draw-image
11:55:36 0:01 0.370u 5780 resource.c/AcquireMagickResource/224/Resource:
  pixels +1.2MP/---/Unlimited
11:55:36 0:01 0.370u 5780 resource.c/AcquireMagickResource/224/Resource:
  memory +5.9MB/15.4MB/7.8GB
11:55:36 0:01 0.370u 5780 pixel_cache.c/OpenCache/3050/Cache:
  open none (5.9M)
11:55:36 0:01 0.390u 5780 resource.c/LiberateMagickResource/752/Resource:
  memory -9.6MB/5.9MB/7.8GB
11:55:36 0:01 0.390u 5780 pixel_cache.c/DestroyCacheInfo/1733/Cache:
  destroy cache none
11:55:36 0:01 0.390u 5780 blob.c/DestroyBlob/989/Blob:
  Destroy blob, image=0x7f8094d0a750, filename="none"
11:55:36 0:01 0.400u 5780 constitute.c/WriteImage/8935/Coder:
  Invoking "PNG" encoder (Portable Network Graphics): adjoin=False type=TrueColorMatte monochrome=False grayscale=False class=DirectClass colorspace=RGB
11:55:36 0:01 0.400u 5780 png.c/WritePNGImage/7726/Coder:
  enter WritePNGImage()
11:55:36 0:01 0.400u 5780 blob.c/OpenBlob/2361/Blob:
  Opening Blob for image 0x0x7f80840008d0 using WriteBinary mode …
11:55:36 0:01 0.480u 5780 blob.c/OpenBlob/2544/Blob:
    I/O buffer set to 16384 bytes
11:55:36 0:01 0.480u 5780 blob.c/OpenBlob/2564/Blob:
    opened file "/var/www/resources/renderTemp/img_temp.png" as FileStream blob 0x0x7f8084002368
11:55:36 0:01 0.480u 5780 png.c/WriteOnePNGImage/6195/Coder:
    enter WriteOnePNGImage()
11:55:36 0:01 0.480u 5780 png.c/WriteOnePNGImage/6295/Coder:
      width=767
11:55:36 0:01 0.480u 5780 png.c/WriteOnePNGImage/6298/Coder:
      height=1602
11:55:36 0:01 0.480u 5780 png.c/WriteOnePNGImage/6301/Coder:
      image->depth=8
11:55:36 0:01 0.480u 5780 png.c/WriteOnePNGImage/6312/Coder:
      ping_info->bit_depth=8
11:55:36 0:01 0.480u 5780 png.c/WriteOnePNGImage/6357/Coder:
      Setting up oFFs chunk
11:55:36 0:01 0.480u 5780 png.c/WriteOnePNGImage/6391/Coder:
      Setting up bKGD chunk
11:55:36 0:01 0.480u 5780 png.c/WriteOnePNGImage/6595/Coder:
      Tentative PNG color type: RGB+Alpha (6)
11:55:36 0:01 0.480u 5780 png.c/WriteOnePNGImage/6599/Coder:
      image_info->type: 7
11:55:36 0:01 0.480u 5780 png.c/WriteOnePNGImage/6601/Coder:
      image->depth: 8
11:55:36 0:01 0.480u 5780 png.c/WriteOnePNGImage/6603/Coder:
      ping_info->bit_depth: 8
11:55:36 0:01 0.480u 5780 png.c/WriteOnePNGImage/6998/Coder:
      PNG color type: RGB+Alpha (6)
11:55:36 0:01 0.480u 5780 png.c/WriteOnePNGImage/7006/Coder:
    Setting up deflate compression
11:55:36 0:01 0.480u 5780 png.c/WriteOnePNGImage/7010/Coder:
      Compression buffer size: 32768
11:55:36 0:01 0.480u 5780 png.c/WriteOnePNGImage/7015/Coder:
      Compression mem level: 9
11:55:36 0:01 0.480u 5780 png.c/WriteOnePNGImage/7025/Coder:
      Compression level: 7
11:55:36 0:01 0.480u 5780 png.c/WriteOnePNGImage/7037/Coder:
    Setting up filtering
11:55:36 0:01 0.480u 5780 png.c/WriteOnePNGImage/7051/Coder:
      Filter_type: 0
11:55:36 0:01 0.480u 5780 png.c/WriteOnePNGImage/7073/Coder:
      Base filter method: ADAPTIVE
11:55:36 0:01 0.480u 5780 png.c/WriteOnePNGImage/7219/Coder:
    Writing PNG header chunks
11:55:36 0:01 0.480u 5780 png.c/WriteOnePNGImage/7261/Coder:
    Allocating 3068 bytes of memory for pixels
11:55:36 0:01 0.480u 5780 png.c/WriteOnePNGImage/7367/Coder:
    pass 0, Image Is RGB, PNG colortype is RGB+Alpha (6)
11:55:36 0:01 1.380u 5780 png.c/WriteOnePNGImage/7422/Coder:
    pass 0 done
11:55:36 0:01 1.380u 5780 png.c/WriteOnePNGImage/7470/Coder:
    Writing PNG image data
11:55:36 0:01 1.380u 5780 png.c/WriteOnePNGImage/7472/Coder:
      Width: 767
11:55:36 0:01 1.380u 5780 png.c/WriteOnePNGImage/7475/Coder:
      Height: 1602
11:55:36 0:01 1.380u 5780 png.c/WriteOnePNGImage/7478/Coder:
      PNG sample depth: 8
11:55:36 0:01 1.380u 5780 png.c/WriteOnePNGImage/7480/Coder:
      PNG color type: RGB+Alpha (6)
11:55:36 0:01 1.380u 5780 png.c/WriteOnePNGImage/7484/Coder:
      PNG Interlace method: 0
11:55:36 0:01 1.380u 5780 png.c/WriteOnePNGImage/7558/Coder:
    Writing PNG end info
11:55:36 0:01 1.380u 5780 png.c/WriteOnePNGImage/7637/Coder:
    exit WriteOnePNGImage()
11:55:36 0:01 1.380u 5780 blob.c/CloseBlob/856/Blob:
  Closing FileStream blob 0x7f8084002368
11:55:36 0:01 1.390u 5780 png.c/WritePNGImage/7754/Coder:
  exit WritePNGImage()
11:55:36 0:01 1.390u 5780 constitute.c/WriteImage/8948/Coder:
  Returned from "PNG" encoder
11:55:36 0:01 1.390u 5780 resource.c/LiberateMagickResource/752/Resource:
  memory -5.9MB/0B/7.8GB
11:55:36 0:01 1.390u 5780 pixel_cache.c/DestroyCacheInfo/1733/Cache:
  destroy cache none
11:55:36 0:01 1.390u 5780 blob.c/DestroyBlob/989/Blob:
  Destroy blob, image=0x7f80840008d0, filename="img_temp.png"
gm convert: Memory allocation failed (none).
11:55:36 0:01 1.390u 5780 magick.c/DestroyMagick/153/Configure:
  Destroy Magick