예제 #1
0
void _cmsFree(void *ptr)
{
    if (ptr != NULL) {
        gs_warn1("lcms free at 0x%x",ptr);
#if defined(SHARE_LCMS) && SHARE_LCMS==1
        free(ptr);
#else
        gs_free_object(gs_lib_ctx_get_non_gc_memory_t(), ptr, "lcms");
#endif
    }
}
예제 #2
0
파일: gp_mspol.c 프로젝트: 99years/plan9
int
gp_check_interrupts(const gs_memory_t *mem)
{
    if(mem == NULL) {
	/* MAJOR HACK will NOT work in multithreaded environment */
	mem = gs_lib_ctx_get_non_gc_memory_t();
    }
    if (mem && mem->gs_lib_ctx && mem->gs_lib_ctx->poll_fn)
	return (*mem->gs_lib_ctx->poll_fn)(mem->gs_lib_ctx->caller_handle);
    return 0;
}
예제 #3
0
static void eprn_forget_defaultmatrix(void)
{
#if EPRN_USE_GSTATE
  /* Old ghostscript versions */
  gs_setdefaultmatrix(igs, NULL);
#else
  gs_setdefaultmatrix(get_minst_from_memory(gs_lib_ctx_get_non_gc_memory_t())->i_ctx_p->pgs, NULL);
#endif

  return;
}
예제 #4
0
void* _cmsMalloc(unsigned int size)
{
    void *ptr;

#if defined(SHARE_LCMS) && SHARE_LCMS==1
    ptr = malloc(size);
#else
    ptr = gs_alloc_bytes(gs_lib_ctx_get_non_gc_memory_t(), size, "lcms");
#endif
    gs_warn2("lcms malloc (%d) at 0x%x",size,ptr);
    return ptr;
}
예제 #5
0
int eprn_close_device(gx_device *device)
{
  eprn_Eprn *eprn = &((eprn_Device *)device)->eprn;

#ifdef EPRN_TRACE
  if_debug0(EPRN_TRACE_CHAR, "! eprn_close_device()...\n");
#endif

  if (eprn->scan_line.str != NULL) {
    gs_free(gs_lib_ctx_get_non_gc_memory_t(), eprn->scan_line.str, eprn->octets_per_line, sizeof(eprn_Octet),
      "eprn_close_device");
    eprn->scan_line.str = NULL;
  }
  if (eprn->next_scan_line.str != NULL) {
    gs_free(gs_lib_ctx_get_non_gc_memory_t(), eprn->next_scan_line.str, eprn->octets_per_line, sizeof(eprn_Octet),
      "eprn_close_device");
    eprn->next_scan_line.str = NULL;
  }

  return gdev_prn_close(device);
}
예제 #6
0
void* _cmsCalloc(unsigned int nelts, unsigned int size)
{
    void *ptr;

#if defined(SHARE_LCMS) && SHARE_LCMS==1
    ptr = malloc(nelts * size);
#else
    ptr = gs_alloc_byte_array(gs_lib_ctx_get_non_gc_memory_t(), nelts, size, "lcms");
#endif

    if (ptr != NULL)
        memset(ptr, 0, nelts * size);
    return ptr;
}
예제 #7
0
/* Set the defaults for the DCT filters. */
void
s_DCT_set_defaults(stream_state * st)
{
    stream_DCT_state *const ss = (stream_DCT_state *) st;

    ss->jpeg_memory = (gs_memory_t *)gs_lib_ctx_get_non_gc_memory_t(); /* cast away const */
    ss->data.common = 0;
    /****************
      ss->data.common->Picky = 0;
      ss->data.common->Relax = 0;
     ****************/
    ss->ColorTransform = -1;
    ss->QFactor = 1.0;
    /* Clear pointers */
    ss->Markers.data = 0;
    ss->Markers.size = 0;
}
예제 #8
0
/*
 * Open a stream using a filename that can include a PS style IODevice prefix
 * If iodev_default is the '%os' device, then the file will be on the host
 * file system transparently to the caller. The "%os%" prefix can be used
 * to explicilty access the host file system.
 */
stream *
sfopen(const char *path, const char *mode, gs_memory_t *memory)
{
    gs_parsed_file_name_t pfn;
    stream *s;
    iodev_proc_open_file((*open_file));
    gs_memory_t *mem = (memory == NULL) ? gs_lib_ctx_get_non_gc_memory_t() : memory;

    int code = gs_parse_file_name(&pfn, path, strlen(path));
    if (code < 0) {
#	define EMSG	"sfopen: gs_parse_file_name failed.\n"
	errwrite(EMSG, strlen(EMSG));
#	undef EMSG
	return NULL;
    }
    if (pfn.fname == NULL) {	/* just a device */
#	define EMSG	"sfopen: not allowed with %device only.\n"
	errwrite(EMSG, strlen(EMSG));
#	undef EMSG
	return NULL;
    }
    if (pfn.iodev == NULL)
	pfn.iodev = iodev_default;
    open_file = pfn.iodev->procs.open_file;
    if (open_file == 0)
	code = file_open_stream(pfn.fname, pfn.len, mode, 2048, &s,
				pfn.iodev, pfn.iodev->procs.fopen, mem);
    else
	code = open_file(pfn.iodev, pfn.fname, pfn.len, mode, &s, mem);
    if (code < 0)
	return NULL;
    s->position = 0;
    code = ssetfilename(s, (const byte *)path, strlen(path));
    if (code < 0) {
	/* Only error is e_VMerror */
	sclose(s);
	gs_free_object(s->memory, s, "sfopen: allocation error");
#	define EMSG	"sfopen: allocation error setting path name into stream.\n"
	errwrite(EMSG, strlen(EMSG));
#	undef EMSG
	return NULL;
    }
    return s;
}
예제 #9
0
void eprn_init_device(eprn_Device *dev, const eprn_PrinterDescription *desc)
{
  eprn_Eprn *eprn = &dev->eprn;
  int j;
  float hres, vres;

  if (dev->is_open) gs_closedevice((gx_device *)dev);

  assert(desc != NULL);
  eprn->cap = desc;
  eprn_set_media_data(dev, NULL, 0);

  /* The media flags are retained because they have not been prescribed by the
     user directly in contact with eprn but are completely under the control
     of the derived device. */

  eprn->code = ms_none;
  eprn->leading_edge_set = false;
  eprn->right_shift = 0;
  eprn->down_shift = 0;
  eprn->keep_margins = false;
  eprn->soft_tumble = false;
  for (j = 0; j < 4; j++) dev->HWMargins[j] = 0;

  /* Set to default colour state, ignoring request failures */
  eprn->colour_model = eprn_DeviceGray;
  eprn->black_levels = 2;
  eprn->non_black_levels = 0;
  eprn->intensity_rendering = eprn_IR_halftones;
  hres = dev->HWResolution[0];
  vres = dev->HWResolution[1];
  eprn_check_colour_info(desc->colour_info, &eprn->colour_model,
      &hres, &vres, &eprn->black_levels, &eprn->non_black_levels);

  if (eprn->pagecount_file != NULL) {
    gs_free(gs_lib_ctx_get_non_gc_memory_t(), eprn->pagecount_file, strlen(eprn->pagecount_file) + 1,
      sizeof(char), "eprn_init_device");
    eprn->pagecount_file = NULL;
  }

  eprn->media_position_set = false;

  return;
}
예제 #10
0
void* _cmsCalloc(unsigned int nelts, unsigned int size)
{
    return gs_alloc_byte_array(gs_lib_ctx_get_non_gc_memory_t(), nelts, size, "lcms");
}
예제 #11
0
void* _cmsMalloc(unsigned int size)
{
    return gs_alloc_bytes(gs_lib_ctx_get_non_gc_memory_t(), size, "lcms");
}
예제 #12
0
/* Send the page to the printer. */
static int
bj10v_print_page(gx_device_printer *pdev, FILE *prn_stream)
{	int line_size = gdev_prn_raster((gx_device *)pdev);
	int xres = pdev->x_pixels_per_inch;
	int yres = pdev->y_pixels_per_inch;
	char *mode = (yres == 180 ?
		      (xres == 180 ? "\052\047" : "\052\050") :
		      "|*");
	int bits_per_column = 24 * (yres / 180);
	int bytes_per_column = bits_per_column / 8;
	int x_skip_unit = bytes_per_column * (xres / 180);
	int y_skip_unit = (yres / 180);
	byte *in = (byte *)gs_malloc(gs_lib_ctx_get_non_gc_memory_t(), 8, line_size, "bj10v_print_page(in)");
	byte *out = (byte *)gs_malloc(gs_lib_ctx_get_non_gc_memory_t(), bits_per_column, line_size, "bj10v_print_page(out)");
	int lnum = 0;
	int y_skip = 0;
	int code = 0;
	int blank_lines = 0;
	int bytes_per_data = ((xres == 360) && (yres == 360)) ? 1 : 3;

	if ( in == 0 || out == 0 )
		return -1;

	/* Initialize the printer. */
	prn_puts(pdev, "\033@");
	/* Transfer pixels to printer */
	while ( lnum < pdev->height )
	   {	byte *out_beg;
		byte *out_end;
		byte *outl, *outp;
		byte *zp;
		int count, bnum;

		/* Copy 1 scan line and test for all zero. */
		code = gdev_prn_get_bits(pdev, lnum + blank_lines, in, NULL);
		if ( code < 0 ) goto xit;
		/* The mem... or str... functions should be faster than */
		/* the following code, but all systems seem to implement */
		/* them so badly that this code is faster. */
		{	register long *zip = (long *)in;
			register int zcnt = line_size;
			static const long zeroes[4] = { 0, 0, 0, 0 };
			for ( ; zcnt >= 4 * sizeof(long); zip += 4, zcnt -= 4 * sizeof(long) )
			    {	if ( zip[0] | zip[1] | zip[2] | zip[3] )
				    goto notz;
			    }
			if ( !memcmp(in, (const char *)zeroes, zcnt) )
			    {	/* Line is all zero, skip */
				if (++blank_lines >= y_skip_unit) {
				    lnum += y_skip_unit;
				    y_skip++;
				    blank_lines = 0;
				}
				continue;
			    }
		}
notz:
		blank_lines = 0;
		out_end = out + bytes_per_column * pdev->width;
		/* Vertical tab to the appropriate position. */
		while ( y_skip > 255 )
		   {	prn_puts(pdev, "\033J\377");
			y_skip -= 255;
		   }
		if ( y_skip ) {
			prn_puts(pdev, "\033J");
			prn_putc(pdev, y_skip);
		}

		/* Transpose in blocks of 8 scan lines. */
		for ( bnum = 0, outl = out; bnum < bits_per_column; bnum += 8, lnum += 8 )
		   {	int lcnt = gdev_prn_copy_scan_lines(pdev,
				lnum, in, 8 * line_size);
			byte *inp = in;
			if ( lcnt < 0 )
			   {	code = lcnt;
				goto xit;
			   }
			if ( lcnt < 8 )
				memset(in + lcnt * line_size, 0,
				       (8 - lcnt) * line_size);
			for (outp = outl ; inp < in + line_size; inp++, outp += bits_per_column )
			   {	memflip8x8(inp, line_size,
					outp, bytes_per_column);
			   }
			outl++;
		   }

		/* Remove trailing 0s. */
		/* Note that non zero byte always exists. */
		outl = out_end;
		while ( *--outl == 0 )
		    ;
		count = ((out_end - (outl + 1)) / bytes_per_column) * bytes_per_column;
		out_end -= count;
		*out_end = 1;		/* sentinel */

		for ( out_beg = outp = out; outp < out_end; )
		    { /* Skip a run of leading 0s. */
			/* At least 10 bytes are needed to make tabbing worth it. */
			byte *zp = outp;
			int x_skip;
			while ( *outp == 0 )
				outp++;
			x_skip = ((outp - zp) / x_skip_unit) * x_skip_unit;
			outp = zp + x_skip;
			if (x_skip >= 10) {
			    /* Output preceding bit data. */
			    int bytes = zp - out_beg;
			    if (bytes > 0)
					/* Only false at beginning of line. */
					bj10v_output_run(out_beg, bytes / bytes_per_data, bytes,
									 mode, pdev);
			    /* Tab over to the appropriate position. */
			    {	int skip = x_skip / x_skip_unit;
					prn_puts(pdev, "\033\\");
					prn_putc(pdev, skip & 0xff);
					prn_putc(pdev, skip >> 8);
			    }
			    out_beg = outp;
			} else
			    outp += x_skip_unit;
		    }
예제 #13
0
int eprn_open_device(gx_device *device)
{
  eprn_Eprn *eprn = &((eprn_Device *)device)->eprn;
  const char *epref = eprn->CUPS_messages? CUPS_ERRPREF: "";
  int rc;

#ifdef EPRN_TRACE
  if_debug0(EPRN_TRACE_CHAR, "! eprn_open_device()...\n");
#endif

  /* Checks on page size and determination of derived values */
  if (eprn_set_page_layout((eprn_Device *)device) != 0)
    return_error(gs_error_rangecheck);

  /* Check the rendering parameters */
  if (eprn_check_colour_info(eprn->cap->colour_info, &eprn->colour_model,
      &device->HWResolution[0], &device->HWResolution[1], 
      &eprn->black_levels, &eprn->non_black_levels) != 0) {
    gs_param_string str;

    eprintf1("%s" ERRPREF "The requested combination of colour model (",
      epref);
    str.size = 0;
    if (eprn_get_string(eprn->colour_model, eprn_colour_model_list, &str) != 0)
      assert(0); /* Bug. No harm on NDEBUG because I've just set the size. */
    errwrite((const char *)str.data, str.size * sizeof(str.data[0]));
    eprintf7("),\n"
      "%s  resolution (%gx%g ppi) and intensity levels (%d, %d) is\n"
      "%s  not supported by the %s.\n",
      epref, device->HWResolution[0], device->HWResolution[1],
      eprn->black_levels, eprn->non_black_levels, epref, eprn->cap->name);
    return_error(gs_error_rangecheck);
  }

  /* Initialization for colour rendering */
  if (device->color_info.num_components == 4) {
    /* Native colour space is 'DeviceCMYK' */
    set_dev_proc(device, map_rgb_color, NULL);

    if (eprn->intensity_rendering == eprn_IR_FloydSteinberg)
      set_dev_proc(device, map_cmyk_color, &eprn_map_cmyk_color_max);
    else if (device->color_info.max_gray > 1 || device->color_info.max_color > 1)
      set_dev_proc(device, map_cmyk_color, &eprn_map_cmyk_color_flex);
    else
      set_dev_proc(device, map_cmyk_color, &eprn_map_cmyk_color);

    if (eprn->intensity_rendering == eprn_IR_FloydSteinberg)
      set_dev_proc(device, map_rgb_color, &eprn_map_rgb_color_for_CMY_or_K_max);
    else if (device->color_info.max_gray > 1 || device->color_info.max_color > 1)
      set_dev_proc(device, map_rgb_color, &eprn_map_rgb_color_for_CMY_or_K_flex);
    else
      set_dev_proc(device, map_rgb_color, &eprn_map_rgb_color_for_CMY_or_K);

  }
  else {
    set_dev_proc(device, map_cmyk_color, NULL);

    if (eprn->colour_model == eprn_DeviceRGB) {
      if (eprn->intensity_rendering == eprn_IR_FloydSteinberg)
	set_dev_proc(device, map_rgb_color, &eprn_map_rgb_color_for_RGB_max);
      else if (device->color_info.max_color > 1)
	set_dev_proc(device, map_rgb_color, &eprn_map_rgb_color_for_RGB_flex);
      else
	set_dev_proc(device, map_rgb_color, &eprn_map_rgb_color_for_RGB);
    } else {
      if (eprn->intensity_rendering == eprn_IR_FloydSteinberg)
	set_dev_proc(device, map_rgb_color, &eprn_map_rgb_color_for_CMY_or_K_max);
      else if (device->color_info.max_gray > 1 || device->color_info.max_color > 1)
	set_dev_proc(device, map_rgb_color, &eprn_map_rgb_color_for_CMY_or_K_flex);
      else
	set_dev_proc(device, map_rgb_color, &eprn_map_rgb_color_for_CMY_or_K);
    }
  }
  eprn->output_planes = eprn_bits_for_levels(eprn->black_levels) +
    3 * eprn_bits_for_levels(eprn->non_black_levels);

#if !defined(GS_REVISION) || GS_REVISION >= 600
  /*  According to my understanding, the following call should be superfluous
      (because the colour mapping functions may not be called while the device
      is closed) and I am also not aware of any situation where it does make a
      difference. It shouldn't do any harm, though, and I feel safer with it :-)
  */
  gx_device_decache_colors(device);
#endif

#ifndef EPRN_NO_PAGECOUNTFILE
  /* Read the page count value */
  if (eprn->pagecount_file != NULL) {
    unsigned long count;
    if (pcf_getcount(eprn->pagecount_file, &count) == 0)
      device->PageCount = count;
       /* unsigned to signed. The C standard permits
	  an implementation to generate an overflow indication if the value is
	  too large. I consider this to mean that the type of 'PageCount' is
	  inappropriate :-). Note that eprn does not use 'PageCount' for
	  updating the file. */
    else {
      /* pcf_getcount() has issued an error message. */
      eprintf(
        "  No further attempts will be made to access the page count file.\n");
      gs_free(gs_lib_ctx_get_non_gc_memory_t(), eprn->pagecount_file, strlen(eprn->pagecount_file) + 1,
	sizeof(char), "eprn_open_device");
      eprn->pagecount_file = NULL;
    }
  }
#endif	/* !EPRN_NO_PAGECOUNTFILE */

  /* Open the "prn" device part */
  if ((rc = gdev_prn_open(device)) != 0) return rc;

  /* Just in case a previous open call failed in a derived device (note that
     'octets_per_line' is still the same as then): */
  if (eprn->scan_line.str != NULL)
    gs_free(gs_lib_ctx_get_non_gc_memory_t(), eprn->scan_line.str, eprn->octets_per_line, sizeof(eprn_Octet),
      "eprn_open_device");
  if (eprn->next_scan_line.str != NULL) {
    gs_free(gs_lib_ctx_get_non_gc_memory_t(), eprn->next_scan_line.str, eprn->octets_per_line, sizeof(eprn_Octet),
      "eprn_open_device");
    eprn->next_scan_line.str = NULL;
  }

  /* Calls which might depend on prn having been initialized */
  eprn->octets_per_line = gdev_prn_raster((gx_device_printer *)device);
  eprn->scan_line.str = (eprn_Octet *) gs_malloc(gs_lib_ctx_get_non_gc_memory_t(), eprn->octets_per_line,
    sizeof(eprn_Octet), "eprn_open_device");
  if (eprn->intensity_rendering == eprn_IR_FloydSteinberg) {
    eprn->next_scan_line.str = (eprn_Octet *) gs_malloc(gs_lib_ctx_get_non_gc_memory_t(), eprn->octets_per_line,
      sizeof(eprn_Octet), "eprn_open_device");
    if (eprn->next_scan_line.str == NULL && eprn->scan_line.str != NULL) {
      gs_free(gs_lib_ctx_get_non_gc_memory_t(), eprn->scan_line.str, eprn->octets_per_line, sizeof(eprn_Octet),
	"eprn_open_device");
      eprn->scan_line.str = NULL;
    }
  }
  if (eprn->scan_line.str == NULL) {
    eprintf1("%s" ERRPREF
      "Memory allocation failure from gs_malloc() in eprn_open_device().\n",
      epref);
    return_error(gs_error_VMerror);
  }

  return rc;
}
예제 #14
0
static long
CompressImage(gx_device_printer *pDev, struct bounding *pBox, FILE *fp, const char *format)
{
	int	x, y, i, count = 255;
	int	Xres = (int)pDev->x_pixels_per_inch;
	int	LineSize = gdev_mem_bytes_per_scan_line((gx_device *)pDev);
	byte	*Buf, oBuf[128], c_prev, c_cur, c_tmp;
	long	DataSize = 0;

	/* ----==== Printer initialize ====---- */
	/* ----==== start TEXT mode ====---- */
	fprintf(fp, "\x1b%%@");
	/* ----==== job start ====---- */
	fprintf(fp, "\x1bP35;%d;1J;GhostScript\x1b\\", Xres);
	/* ----==== soft reset ====---- */
	fprintf(fp, "\x1b<");
	/* ----==== select size as dot ====---- */
	fprintf(fp, "\x1b[7 I");
	/* ----==== ??? ====---- */
	fprintf(fp, "\x1b[;1;'v");
	/* ----==== set paper size ====---- */
	fprintf(fp, "\x1b[%d;;p", PaperInfo[pBox->paper].id);
	/* ----==== select sheet feeder ====---- */
	fprintf(fp, "\x1b[1q");
	/* ----==== disable automatic FF ====---- */
	fprintf(fp, "\x1b[?2h");
	/* ----==== set number of copies ====---- */
	fprintf(fp, "\x1b[%dv", 1);
	/* ----==== move CAP location ====---- */
	fprintf(fp, "\x1b[%d;%df", pBox->Top, pBox->Left*16);
	/* ----==== draw raster image ====---- */
	fprintf(fp, format, pBox->Right-pBox->Left+1,
		Xres, pBox->Bottom-pBox->Top+1);

	/* ----==== Allocate momory ====---- */
	Buf = (byte *)gs_malloc(gs_lib_ctx_get_non_gc_memory_t(), 1, LineSize, "LineBuffer");
	/* ----==== transfer raster image ====---- */
	for (y=pBox->Top ; y<=pBox->Bottom ; y++) {
		gdev_prn_copy_scan_lines(pDev, y, Buf, LineSize);
		for (x=pBox->Left*2 ; x<=pBox->Right*2+1 ; x++) {
		/* ----==== check pointer & Reverse bit order ====---- */
			c_cur = 0;
			if (x<LineSize) {
				c_tmp = *(Buf+x);
				for (i=0 ; i<8 ; i++) {
					c_cur = (c_cur << 1) | (c_tmp & 1);
					c_tmp = c_tmp >> 1;
				}
			}
			/* ----==== Compress data ====---- */
			if (count < 0) {
				if (c_prev == c_cur && count > -127) {
					count--;
					continue;
				} else {
					fprintf(fp, "%c%c", count, c_prev);
					DataSize += 2;
				}
			} else if (count == 0) {
				if (c_prev == c_cur) {
					count--;
				} else {
					count++;
					c_prev = *(oBuf+count) = c_cur;
				}
			continue;
			} else if (count < 127) {
				if (c_prev == c_cur) {
					fprintf(fp, "%c", count-1);
					fwrite(oBuf, 1, count, fp);
					DataSize += (count+1);
					count = -1;
				} else {
					count++;
					c_prev = *(oBuf+count) = c_cur;
				}
			continue;
			} else if (count == 127) {
				fprintf(fp, "%c", count);
				fwrite(oBuf, 1, count+1, fp);
				DataSize += (count+2);
			}
			c_prev = *oBuf = c_cur;
			count = 0;
		}
	}
예제 #15
0
/* Send the page to the printer. */
static int
jj100_print_page(gx_device_printer *pdev, FILE *prn_stream)
{	int line_size = gdev_prn_raster(pdev);
	int height = pdev->height;
	int bits_per_column = 48;
	int bytes_per_column = bits_per_column / 8;
	int chunk_size = bits_per_column * line_size;
	byte *in, *out;
	int lnum, skip;
	char prn_buf[16];

	in = (byte *)
		gs_malloc(gs_lib_ctx_get_non_gc_memory_t(), bits_per_column, line_size, "jj100_print_page(in)");
	out = (byte *)
		gs_malloc(gs_lib_ctx_get_non_gc_memory_t(), bits_per_column, line_size, "jj100_print_page(out)");
	if(in == 0 || out == 0)
		return -1;

	/* Initialize printer */
	fputs("\033P", pdev->file);	/* Proportional Mode */
        fputs("\033G", pdev->file);        /* 1/180 inch per line */
	fputs("\033T16", pdev->file);	/* 16/180 inch per line */

	/* Send Data to printer */
	lnum = 0;
	skip = 0;
	while(lnum < height) {
		byte *inp, *outp, *out_beg, *out_end;
		int x, y, num_lines, size, mod;

		/* Copy scan lines */
		if(gdev_prn_copy_scan_lines(pdev, lnum, in, chunk_size) < 0)
			break;

		/* The number of lines to process */
		if((num_lines = height - lnum) > bits_per_column)
			num_lines = bits_per_column;

		/* Test for all zero */
		size = line_size * num_lines;
		if(in[0] == 0 && 
		   !memcmp((char *)in, (char *)in + 1, size - 1)) {
			lnum += bits_per_column;
			skip ++;
			continue;
		}

		/* Fill zero */
		if(num_lines < bits_per_column) {
			size = line_size * (bits_per_column - num_lines);
			memset(in + line_size * num_lines, 0, size);
		}
		lnum += bits_per_column;

		/* Vertical tab to the appropriate position. */
		while(skip > 15) {
			sprintf(prn_buf, "\037%c", 16 + 15);
			fputs(prn_buf, pdev->file);
			skip -= 15;
		}
		if(skip > 0) {
			sprintf(prn_buf, "\037%c", 16 + skip);
			fputs(prn_buf, pdev->file);
		}

		/* Transpose in blocks of 8 scan lines. */
		for(y = 0; y < bytes_per_column; y ++) {
			inp = in + line_size * 8 * y;
			outp = out + y;
			for(x = 0; x < line_size; x ++) {
				jj100_transpose_8x8(inp, line_size,
						    outp, bytes_per_column);
				inp ++;
				outp += bits_per_column;
			}
		}

		/* Remove trailing 0s. */
		out_end = out + chunk_size - 1;
		while(out_end >= out) {
			if(*out_end)
				break;
			out_end --;
		}
		size = (out_end - out) + 1;
		if((mod = size % bytes_per_column) != 0)
			out_end += bytes_per_column - mod;

		/* Remove leading 0s. */
		out_beg = out;
		while(out_beg <= out_end) {
			if(*out_beg)
				break;
			out_beg ++;
		}
		out_beg -= (out_beg - out) % (bytes_per_column * 2);

		/* Dot addressing */
		sprintf(prn_buf, "\033F%04d", 
			(out_beg - out) / bytes_per_column / 2);
		fputs(prn_buf, pdev->file);

		/* Dot graphics */
		size = out_end - out_beg + 1;
		sprintf(prn_buf, "\034bP,48,%04d.", size / bytes_per_column);
		fputs(prn_buf, pdev->file);
		fwrite(out_beg, 1, size, pdev->file);

		/* Carriage Return */
		fputc('\r', pdev->file);
		skip = 1;
	}

	/* Form Feed */
	fputc('\f', pdev->file);
	fflush(pdev->file);

	gs_free(gs_lib_ctx_get_non_gc_memory_t(), (char *)out, 
		bits_per_column, line_size, "jj100_print_page(out)");
	gs_free(gs_lib_ctx_get_non_gc_memory_t(), (char *)in,
		bits_per_column, line_size, "jj100_print_page(in)");

	return 0;
}
예제 #16
0
void _cmsFree(void *ptr)
{
    if (ptr != NULL)
        gs_free_object(gs_lib_ctx_get_non_gc_memory_t(), ptr, "lcms");
}
예제 #17
0
/* since computer-to-printer communication time is often a bottleneck. */
static int
oki4w_print_page(gx_device_printer *pdev, FILE *prn_stream)
{
	int line_size = gdev_mem_bytes_per_scan_line((gx_device *)pdev);
	int line_size_words = (line_size + W - 1) / W;
	uint storage_size_words = line_size_words * 8; /* data, out_row, out_row_alt, prev_row */
	word *storage = (ulong *)gs_malloc(gs_lib_ctx_get_non_gc_memory_t(), storage_size_words, W,
					   "oki4w_print_page");
	word
	  *data_words,
	  *out_row_words,
	  *out_row_alt_words,
	  *prev_row_words;
#define data ((byte *)data_words)
#define out_row ((byte *)out_row_words)
#define out_row_alt ((byte *)out_row_alt_words)
#define prev_row ((byte *)prev_row_words)
	byte *out_data;
	int x_dpi = pdev->x_pixels_per_inch;
	int y_dpi = pdev->y_pixels_per_inch;
	int y_dots_per_pixel = x_dpi / y_dpi;
	int dpi_code, compress_code;
	int num_rows = dev_print_scan_lines(pdev);

	int out_count;
	int paper_size = oki_paper_size((gx_device *)pdev);
	int code = 0;
	/* bool dup = pdev->Duplex;
	bool dupset = pdev->Duplex_set >= 0; */

	if ( storage == 0 )	/* can't allocate working area */
		return_error(gs_error_VMerror);
	data_words = storage;
	out_row_words = data_words + (line_size_words * 2);
	out_row_alt_words = out_row_words + (line_size_words * 2);
	prev_row_words = out_row_alt_words + (line_size_words * 2);
	/* Clear temp storage */
	memset(data, 0, storage_size_words * W);

	out_data = out_row;

	if (y_dpi == 150) {
		dpi_code = 3;
		compress_code = 2;
	} else if (y_dpi == 300) {
		dpi_code = 5;
		compress_code = 2;
	} else {
		dpi_code = 7;
		compress_code = 2;
	}

	/* Initialize printer. */
/*	if ( pdev->PageCount == 0 ) { */
		/* Put out init string before page. */
		fprintf(prn_stream, "\x1B%%-98765X\x1C\x14\x03\x41i\x10\x1C"
			"\x14\x05\x41\x65%cf%c\x1C\x14\x09\x42\x61%cb\x02\x63"
			"\x01\x65%c\x1C\x7F\x39\x1B&B\x1B&A\x07%c\x01%c"
			"\x01%c%c%c%c\x1B$A",
			dpi_code, dpi_code, 0, 0, 0, paper_size,
			0, dpi_code, dpi_code, 0);
/*	} */

	/* Send each scan line in turn */
	   {	int lnum;
		int num_blank_lines = 0;
		word rmask = ~(word)0 << (-pdev->width & (W * 8 - 1));

		/* Transfer raster graphics. */
		for ( lnum = 0; lnum < num_rows; lnum++ )
		   {	register word *end_data =
				data_words + line_size_words;
			int i;
			code = gdev_prn_copy_scan_lines(pdev, lnum,
						 (byte *)data, line_size);
			if ( code < 0 )
				break;
		   	/* Mask off 1-bits beyond the line width. */
			end_data[-1] &= rmask;
			/* Remove trailing 0s. */
			while ( end_data > data_words && end_data[-1] == 0 )
			  end_data--;
			if ( end_data == data_words )
			   {	/* Blank line */
				num_blank_lines++;
				continue;
			   }

			/* We've reached a non-blank line. */
			/* Put out a spacing command if necessary. */
			if ( num_blank_lines == lnum )
			{	/* We're at the top of a page. */
				/* TODO: skip top_margin lines... */
				/* num_blank_lines += xxx */
				/* Skip blank lines if any */
				if (num_blank_lines > 0) {
					fprintf(prn_stream, "\x1b*B%c%c",
						num_blank_lines & 0xff,
						num_blank_lines >> 8);
				}
			}
			else if ( num_blank_lines != 0 )
			{
				/* Skip blank lines if any */
				fprintf(prn_stream, "\x1b*B%c%c",
					num_blank_lines & 0xff,
					num_blank_lines >> 8);
			}
예제 #18
0
/* all? MD series monochrome mode print with data compression. */
static int
md1xm_print_page(gx_device_printer *pdev, FILE *prn_stream)
{
  int lnum;
  int line_size = gdev_mem_bytes_per_scan_line((gx_device *)pdev);
  byte *data = (byte *)gs_malloc(gs_lib_ctx_get_non_gc_memory_t(), 8, line_size, "md1xm_print_page(data)");
  byte *out_start = (byte *)gs_malloc(gs_lib_ctx_get_non_gc_memory_t(), 8, line_size, "md1xm_print_page(data)");
  int skipping = 0;
  int nbyte;

  /* Load Paper & Select Inc Cartridge */
  fwrite(&init_md13[0], sizeof(char), sizeof(init_md13), prn_stream);
  fflush(prn_stream);

  for ( lnum = 0; lnum <= pdev->height; lnum++ ) {
    byte *end_data = data + line_size;
    byte *data_p = data;
    byte *out_data = out_start;
    byte *p, *q;
    int count;

    gdev_prn_copy_scan_lines(pdev, lnum, data, line_size);
    /* Remove trailing 0s. */
    while ( end_data > data && end_data[-1] == 0 ) 
      end_data--; 

     nbyte = end_data - data_p;

    if(nbyte == 0)
      {
	skipping++;
	continue;
      }
    else
      {
	if(skipping)
	  {
	    fprintf(prn_stream, "%c%c%c%c%c%c", 0x1b, 0x2a, 0x62,
		    skipping & 0xff, (skipping & 0xff00) / 0x100, 0x59);
	    skipping = 0;
	  }

	/* Following codes are borrowed from gdevescp.c */

	for ( p = data_p, q = data_p + 1; q < end_data; ){

	  if( *p != *q ) {

	    p += 2;
	    q += 2;

	  } else {
	    /*
	    ** Check behind us, just in case:
	    */

	    if( p > data_p && *p == *(p-1) )
	      p--;

	    /*
	    ** walk forward, looking for matches:
	    */

	    for( q++ ; *q == *p && q < end_data ; q++ ) {
	      if( (q-p) >= 128 ) {
		if( p > data_p ) {
		  count = p - data_p;
		  while( count > 128 ) {
   		    *out_data++ = '\177';
		    memcpy(out_data, data_p, 128);	/* data */
		    data_p += 128;
		    out_data += 128;
		    count -= 128;
		  }
		  *out_data++ = (char) (count - 1); /* count */
		  memcpy(out_data, data_p, count);	/* data */
		  out_data += count;
		}
 		*out_data++ = '\201';	/* Repeat 128 times */ 
		*out_data++ = *p;
		p += 128;
		data_p = p;
	      }
	    }

	    if( (q - p) > 2 ) {	/* output this sequence */
	      if( p > data_p ) {
		count = p - data_p;
		while( count > 128 ) {
  		  *out_data++ = '\177'; 
		  memcpy(out_data, data_p, 128);	/* data */
		  data_p += 128;
		  out_data += 128;
		  count -= 128;
		}
		*out_data++ = (char) (count - 1);	/* byte count */
		memcpy(out_data, data_p, count);	/* data */
		out_data += count;
	      }
	      count = q - p;
	      *out_data++ = (char) (256 - count + 1);
	      *out_data++ = *p;
	      p += count;
	      data_p = p;
	    } else	/* add to non-repeating data list */
	      p = q;
	    if( q < end_data )
	      q++;
	  }
	}
	/*
	** copy remaining part of line:
	*/
	
	if( data_p < end_data ) {

	  count = end_data - data_p;

	  /*
	  ** If we've had a long run of varying data followed by a
	  ** sequence of repeated data and then hit the end of line,
	  ** it's possible to get data counts > 128.
	  */

	  while( count > 128 ) {
  	    *out_data++ = '\177';  
	    memcpy(out_data, data_p, 128);	/* data */
	    data_p += 128;
	    out_data += 128;
	    count -= 128;
	  }

	  *out_data++ = (char) (count - 1);	/* byte count */
	  memcpy(out_data, data_p, count);	/* data */
	  out_data += count;
	}

	nbyte = out_data - out_start;

        fprintf(prn_stream, "%c%c%c%c%c%c", 0x1b, 0x2a, 0x62,
		nbyte & 0xff, (nbyte & 0xff00) / 0x100, 0x57);
	fwrite(out_start, sizeof(char), nbyte, prn_stream);
      }
  }
  
  /* Eject Page */
  fwrite(end_md, sizeof(char), sizeof(end_md), prn_stream);
  fflush(prn_stream);
  
  return 0;
}
예제 #19
0
/* Send the page to the printer.  */
static int
fmlbp_print_page(gx_device_printer *pdev, FILE *prn_stream)
{
  int line_size = gdev_mem_bytes_per_scan_line((gx_device *)pdev);
#ifdef	FMLBP_NOPAPERSIZE
  char data[LINE_SIZE*2];
#else
  byte *data = (byte *)gs_malloc(gs_lib_ctx_get_non_gc_memory_t(), 1, line_size, "fmlpr_print_page(data)");
  if(data == NULL) return_error(gs_error_VMerror);
#endif/*FMLBP_NOPAPERSIZE*/

  /* initialize */
  fwrite(can_inits, sizeof(can_inits), 1, prn_stream);
  fprintf(prn_stream, "%c%c%d!I", PU1, 0);	/* 100% */
#ifndef	OLD_FMLBP_400DPI
  fprintf(prn_stream, "%c%c%d!A", PU1,
	  (int)(pdev->x_pixels_per_inch));	/* 240dpi or 400dpi */
#endif/*!OLD_FMLBP_400DPI*/
#ifndef	FMLBP_NOPAPERSIZE
  fprintf(prn_stream, "%c%c%s!F", PU1,
	  gdev_fmlbp_paper_size(pdev));		/* Paper size */
#endif/*!FMLBP_NOPAPERSIZE*/

  /* Send each scan line in turn */
  {	int lnum;
	byte rmask = (byte)(0xff << (-pdev->width & 7));

	for ( lnum = 0; lnum < pdev->height; lnum++ )
	  {	byte *end_data = data + line_size;
		int s = gdev_prn_copy_scan_lines(pdev, lnum,
						(byte *)data, line_size);
		if(s < 0) return_error(s);
		/* Mask off 1-bits beyond the line width. */
		end_data[-1] &= rmask;
		/* Remove trailing 0s. */
		while ( end_data > data && end_data[-1] == 0 )
		  end_data--;
		if ( end_data != data ) {	
		  int num_cols = 0;
		  int out_count = 0;
		  byte *out_data = data;
		  
		  while(out_data < end_data && *out_data == 0) {
		    num_cols += 8;
		    out_data++;
		  }
		  out_count = end_data - out_data;

		  /* move down */ /* move across */
		  goto_xy(prn_stream, num_cols, lnum);

		  /* transfer raster graphics */
		  fprintf(prn_stream, "%c%c%d;%d;0!a",
			  PU1, out_count, out_count*8 );

		  /* send the row */
		  fwrite(out_data, sizeof(byte), out_count, prn_stream);
		}
	      }
      }
  /* eject page */
  fputc(0x0c,prn_stream);
  fflush(prn_stream);
#ifndef	FMLBP_NOPAPERSIZE
  gs_free(gs_lib_ctx_get_non_gc_memory_t(), (char *)data, line_size, sizeof(byte), "fmlbp_print_page(data)");
#endif/*!FMLBP_NOPAPERSIZE*/

  return 0;
}
예제 #20
0
/* Send the page to the printer. */
static int
pr201_print_page(gx_device_printer *pdev, FILE *prn_stream)
{	int line_size;
	int height;
	int bits_per_column;
	int bytes_per_column;
	int chunk_size;
	byte *in, *out;
	int lnum, skip;
	int head_pins, lr_pitch, x_dpi;
	
	switch (check_mode(pdev->dname)){
		case PR201:
			head_pins=24; lr_pitch=18; x_dpi=160; break;
		case PR1000:
			head_pins=40; lr_pitch=20; x_dpi=240; break;
		case PR150:
			head_pins=48; lr_pitch=18; x_dpi=320; break;
		case PR1K4:
			head_pins=60; lr_pitch=18; x_dpi=400; break;
	}

	line_size = gdev_mem_bytes_per_scan_line((gx_device *)pdev);
	height = pdev->height;
	bits_per_column	 = head_pins;
	bytes_per_column = bits_per_column / 8;
	chunk_size = bits_per_column * line_size;

	in = (byte *)
		gs_malloc(gs_lib_ctx_get_non_gc_memory_t(), bits_per_column, line_size, "pr201_print_page(in)");
	out = (byte *)
		gs_malloc(gs_lib_ctx_get_non_gc_memory_t(), bits_per_column, line_size, "pr201_print_page(out)");
	if(in == 0 || out == 0)
		return -1;

	/* Initialize printer */
	fputs("\033cl", pdev->file);	/* Software Reset */
	fputs("\033P", pdev->file);	/* Proportional Mode */
	if (check_mode(pdev->dname)==PR150){
		fprintf(pdev->file, "\034d%d.", x_dpi); /* 320 dpi mode. */
	}
	fprintf(pdev->file, "\033T%d" , lr_pitch);
				/* 18/120 inch per line */

	/* Send Data to printer */
	lnum = 0;
	skip = 0;
	while(lnum < height) {
		byte *inp, *outp, *out_beg, *out_end;
		int x, y, num_lines, size, mod;

		/* Copy scan lines */
		if(gdev_prn_copy_scan_lines(pdev, lnum, in, chunk_size) < 0)
			break;

		/* The number of lines to process */
		if((num_lines = height - lnum) > bits_per_column)
			num_lines = bits_per_column;

		/* Test for all zero */
		size = line_size * num_lines;
		if(in[0] == 0 && 
		   !memcmp((char *)in, (char *)in + 1, size - 1)) {
			lnum += bits_per_column;
			skip ++;
			continue;
		}

		/* Fill zero */
		if(num_lines < bits_per_column) {
			size = line_size * (bits_per_column - num_lines);
			memset(in + line_size * num_lines, 0, size);
		}
		lnum += bits_per_column;

		/* Vertical tab to the appropriate position. */
		while(skip > 72) {
			fprintf(pdev->file, "\037%c", 16 + 72);
			skip -= 72;
		}
		if(skip > 0) {
			fprintf(pdev->file, "\037%c", 16 + skip);
		}

		/* Transpose in blocks of 8 scan lines. */
		for(y = 0; y < bytes_per_column; y ++) {
			inp = in + line_size * 8 * y;
			outp = out + y;
			for(x = 0; x < line_size; x ++) {
				pr201_transpose_8x8(inp, line_size,
						    outp, bytes_per_column);
				inp ++;
				outp += bits_per_column;
			}
		}

		/* Remove trailing 0s. */
		out_end = out + chunk_size - 1;
		while(out_end >= out) {
			if(*out_end)
				break;
			out_end --;
		}
		size = (out_end - out) + 1;
		if((mod = size % bytes_per_column) != 0)
			out_end += bytes_per_column - mod;

		/* Remove leading 0s. */
		out_beg = out;
		while(out_beg <= out_end) {
			if(*out_beg)
				break;
			out_beg ++;
		}
		out_beg -= (out_beg - out) % bytes_per_column;

		/* Dot addressing */
		fprintf(pdev->file, "\033F%04d", 
			(out_beg - out) / bytes_per_column);

		/* Dot graphics */
		size = out_end - out_beg + 1;
		if (check_mode(pdev->dname)==PR201){
			fprintf(pdev->file,"\033J%04d", size / bytes_per_column);
		}else{
			fprintf(pdev->file,"\034bP,48,%04d.",
			  size / bytes_per_column);
		}
		fwrite(out_beg, size, 1, pdev->file);

		/* Carriage Return */
		fputc('\r', pdev->file);
		skip = 1;
	}

	/* Form Feed */
	fputc('\f',pdev->file);
	fflush(pdev->file);

	gs_free(gs_lib_ctx_get_non_gc_memory_t(), (char *)out, 
		bits_per_column, line_size, "pr201_print_page(out)");
	gs_free(gs_lib_ctx_get_non_gc_memory_t(), (char *)in,
		bits_per_column, line_size, "pr201_print_page(in)");

	return 0;
}