🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Article View: alt.graphics.pixutils
Article #589

TIFF 3 PLANARCONFIG_SEPARATE problem

#589
From: Craig Anderson
Date: Sat, 19 Dec 1992 02:52
131 lines
4338 bytes
The following code interleaves separate lines.
The comments document a segmentation fault in TIFFWriteScanLine()
Is there a problem with this code?

Craig H. Anderson
C4 Network, Inc.
518 17th Street, Suite 1400
Denver, CO 80202
    (303) 825-8183
FAX (303) 893-6510
c4craig@csn.org


/*
VERSION = 3.00
(gdb) run
Starting program: /home/mrt/craig/fsd/tiff_test 

Program received signal 11, Segmentation fault
0xf773072c in bcopy ()
(gdb) where
#0  0xf773072c in bcopy ()
#1  0xfc84 in DumpModeEncode (tif=0x3e6b0, pp=0x3da10 '\001' <repeats 200 times>..., cc=100, s=0) at tif_dumpmode.c:84
#2  0xc184 in TIFFWriteScanline (tif=0x3e6b0, buf=0x3da10 '\001' <repeats 200 times>..., row=8, sample=0) at tif_write.c:162
#3  0x253c in main () at tiff_test.c:42
 */
#include "tiffio.h"

int ww = 800;
int hh = 800;
TIFF * out_tif;
char *cbuf,*ybuf,*mbuf,*kbuf;

main ()
{
  int ii;

  cbuf = (char *)malloc (ww);
  mbuf = (char *)malloc (ww);
  ybuf = (char *)malloc (ww);
  kbuf = (char *)malloc (ww);

  memset (cbuf,1,ww);
  memset (mbuf,2,ww);
  memset (ybuf,3,ww);
  memset (kbuf,4,ww);

  out_tif = TIFFOpen("glop.tif", "w");
  if (out_tif == NULL) {
    perror ("can't open output file\n");
    return -1;
  }
  TIFFSetField(out_tif, TIFFTAG_IMAGEWIDTH, ww);
  TIFFSetField(out_tif, TIFFTAG_IMAGELENGTH, hh);
  TIFFSetField(out_tif, TIFFTAG_ROWSPERSTRIP, 100);
  TIFFSetField(out_tif, TIFFTAG_BITSPERSAMPLE, 1);
  TIFFSetField(out_tif, TIFFTAG_SAMPLESPERPIXEL, 4);
  TIFFSetField(out_tif, TIFFTAG_PLANARCONFIG, PLANARCONFIG_SEPARATE);
  TIFFSetField(out_tif, TIFFTAG_PHOTOMETRIC, PHOTOMETRIC_SEPARATED);
  TIFFSetField(out_tif, TIFFTAG_INKSET, INKSET_CMYK);
  TIFFSetField(out_tif, TIFFTAG_RESOLUTIONUNIT, RESUNIT_INCH);
  TIFFSetField(out_tif, TIFFTAG_XRESOLUTION, (float)200.0);
  TIFFSetField(out_tif, TIFFTAG_YRESOLUTION, (float)200.0);

  for (ii=0; ii<hh; ++ii)
    {
      TIFFWriteScanline (out_tif, cbuf, ii, 0);
      TIFFWriteScanline (out_tif, mbuf, ii, 1);
      TIFFWriteScanline (out_tif, ybuf, ii, 2);
      TIFFWriteScanline (out_tif, kbuf, ii, 3);
    }
  TIFFClose(out_tif);

  exit (0);
}
(gdb) where
#0  0xf773072c in bcopy ()
#1  0xfc84 in DumpModeEncode (tif=0x3e6b0, pp=0x3da10 '\001' <repeats 200 times>..., cc=100, s=0) at tif_dumpmode.c:84
#2  0xc184 in TIFFWriteScanline (tif=0x3e6b0, buf=0x3da10 '\001' <repeats 200 times>..., row=8, sample=0) at tif_write.c:162
#3  0x253c in main () at tiff_test.c:42
 */
#include "tiffio.h"

int ww = 800;
int hh = 800;
TIFF * out_tif;
char *cbuf,*ybuf,*mbuf,*kbuf;

main ()
{
  int ii;

  cbuf = (char *)malloc (ww);
  mbuf = (char *)malloc (ww);
  ybuf = (char *)malloc (ww);
  kbuf = (char *)malloc (ww);

  memset (cbuf,1,ww);
  memset (mbuf,2,ww);
  memset (ybuf,3,ww);
  memset (kbuf,4,ww);

  out_tif = TIFFOpen("glop.tif", "w");
  if (out_tif == NULL) {
    perror ("can't open output file\n");
    return -1;
  }
  TIFFSetField(out_tif, TIFFTAG_IMAGEWIDTH, ww);
  TIFFSetField(out_tif, TIFFTAG_IMAGELENGTH, hh);
  TIFFSetField(out_tif, TIFFTAG_ROWSPERSTRIP, 100);
  TIFFSetField(out_tif, TIFFTAG_BITSPERSAMPLE, 1);
  TIFFSetField(out_tif, TIFFTAG_SAMPLESPERPIXEL, 4);
  TIFFSetField(out_tif, TIFFTAG_PLANARCONFIG, PLANARCONFIG_SEPARATE);
  TIFFSetField(out_tif, TIFFTAG_PHOTOMETRIC, PHOTOMETRIC_SEPARATED);
  TIFFSetField(out_tif, TIFFTAG_INKSET, INKSET_CMYK);
  TIFFSetField(out_tif, TIFFTAG_RESOLUTIONUNIT, RESUNIT_INCH);
  TIFFSetField(out_tif, TIFFTAG_XRESOLUTION, (float)200.0);
  TIFFSetField(out_tif, TIFFTAG_YRESOLUTION, (float)200.0);

  for (ii=0; ii<hh; ++ii)
    {
      TIFFWriteScanline (out_tif, cbuf, ii, 0);
      TIFFWriteScanline (out_tif, mbuf, ii, 1);
      TIFFWriteScanline (out_tif, ybuf, ii, 2);
      TIFFWriteScanline (out_tif, kbuf, ii, 3);
    }
  TIFFClose(out_tif);

  exit (0);
}
Technical Details
Message-ID: <BzHJzv.MK5@csn.org>
Path: arc1-ca.pugleaf.net!sparky!uunet!spool.mu.edu!agate!usenet.ins.cwru.edu!ukma!cs.widener.edu!dsinc!ub!csn!teal.csn.org!c4craig

Show Full Headers
Complete Article Headers
Path: arc1-ca.pugleaf.net!sparky!uunet!spool.mu.edu!agate!usenet.ins.cwru.edu!ukma!cs.widener.edu!dsinc!ub!csn!teal.csn.org!c4craig
From: c4craig@teal.csn.org (Craig Anderson)
Newsgroups: alt.graphics.pixutils
Subject: TIFF 3 PLANARCONFIG_SEPARATE problem
Message-ID: <BzHJzv.MK5@csn.org>
Date: 19 Dec 92 02:52:41 GMT
Sender: news@csn.org (news)
Organization: Colorado SuperNet, Inc.
Lines: 131
Nntp-Posting-Host: teal.csn.org