diff --git a/src/add-ons/translators/Jamfile b/src/add-ons/translators/Jamfile index 006ae5ccf8..b3a06632ca 100644 --- a/src/add-ons/translators/Jamfile +++ b/src/add-ons/translators/Jamfile @@ -2,6 +2,7 @@ SubDir HAIKU_TOP src add-ons translators ; SubInclude HAIKU_TOP src add-ons translators bmp ; SubInclude HAIKU_TOP src add-ons translators gif ; +SubInclude HAIKU_TOP src add-ons translators hpgs ; SubInclude HAIKU_TOP src add-ons translators ico ; SubInclude HAIKU_TOP src add-ons translators jpeg ; SubInclude HAIKU_TOP src add-ons translators jpeg2000 ; diff --git a/src/add-ons/translators/hpgs/ConfigView.cpp b/src/add-ons/translators/hpgs/ConfigView.cpp new file mode 100644 index 0000000000..c1b0f16df9 --- /dev/null +++ b/src/add-ons/translators/hpgs/ConfigView.cpp @@ -0,0 +1,67 @@ +/* + * Copyright 2007, Jérôme Duval. All rights reserved. + * Copyright 2005-2007, Axel Dörfler, axeld@pinc-software.de. All rights reserved. + * Distributed under the terms of the MIT License. + */ + + +#include "ConfigView.h" +#include "HPGSTranslator.h" + +#include +#include + +#include +#include + + +ConfigView::ConfigView(const BRect &frame, uint32 resize, uint32 flags) + : BView(frame, "HPGSTranslator Settings", resize, flags) +{ + SetViewColor(ui_color(B_PANEL_BACKGROUND_COLOR)); + + font_height fontHeight; + be_bold_font->GetHeight(&fontHeight); + float height = fontHeight.descent + fontHeight.ascent + fontHeight.leading; + + BRect rect(10, 10, 200, 10 + height); + BStringView *stringView = new BStringView(rect, "title", "HPGS Images"); + stringView->SetFont(be_bold_font); + stringView->ResizeToPreferred(); + AddChild(stringView); + + rect.OffsetBy(0, height + 10); + char version[256]; + sprintf(version, "Version %d.%d.%d, %s", + int(B_TRANSLATION_MAJOR_VERSION(HPGS_TRANSLATOR_VERSION)), + int(B_TRANSLATION_MINOR_VERSION(HPGS_TRANSLATOR_VERSION)), + int(B_TRANSLATION_REVISION_VERSION(HPGS_TRANSLATOR_VERSION)), + __DATE__); + stringView = new BStringView(rect, "version", version); + stringView->ResizeToPreferred(); + AddChild(stringView); + + GetFontHeight(&fontHeight); + height = fontHeight.descent + fontHeight.ascent + fontHeight.leading; + + rect.OffsetBy(0, height + 5); + stringView = new BStringView(rect, "copyright", B_UTF8_COPYRIGHT "2007 Haiku Inc."); + stringView->ResizeToPreferred(); + AddChild(stringView); + + rect.OffsetBy(0, height + 10); + stringView = new BStringView(rect, "copyright2", "Based on HPGS (http://hpgs.berlios.de)"); + stringView->ResizeToPreferred(); + AddChild(stringView); + + rect.OffsetBy(0, height + 5); + stringView = new BStringView(rect, "copyright3", B_UTF8_COPYRIGHT "2004-2006 ev-i Informationstechnologie GmbH"); + stringView->ResizeToPreferred(); + AddChild(stringView); +} + + +ConfigView::~ConfigView() +{ +} + diff --git a/src/add-ons/translators/hpgs/ConfigView.h b/src/add-ons/translators/hpgs/ConfigView.h new file mode 100644 index 0000000000..dfb0abf5fb --- /dev/null +++ b/src/add-ons/translators/hpgs/ConfigView.h @@ -0,0 +1,19 @@ +/* + * Copyright 2004-2007, Axel Dörfler, axeld@pinc-software.de. All rights reserved. + * Distributed under the terms of the MIT License. + */ +#ifndef CONFIG_VIEW_H +#define CONFIG_VIEW_H + + +#include + + +class ConfigView : public BView { + public: + ConfigView(const BRect &frame, uint32 resize = B_FOLLOW_ALL, + uint32 flags = B_WILL_DRAW); + virtual ~ConfigView(); +}; + +#endif /* CONFIG_VIEW_H */ diff --git a/src/add-ons/translators/hpgs/HPGSTranslator.cpp b/src/add-ons/translators/hpgs/HPGSTranslator.cpp new file mode 100644 index 0000000000..fb4a38fc17 --- /dev/null +++ b/src/add-ons/translators/hpgs/HPGSTranslator.cpp @@ -0,0 +1,277 @@ +/* + * Copyright 2007, Jérôme Duval. All rights reserved. + * Distributed under the terms of the MIT License. + */ + + +#include "HPGSTranslator.h" +#include "ConfigView.h" +#include "ReadHelper.h" + +#include "hpgsimage.h" + +#include +#include + +#include +#include +#include + +typedef struct my_hpgs_png_image_st { + hpgs_png_image image; + BPositionIO *target; +} my_hpgs_png_image; + + +int +my_pim_write(hpgs_image *_this, const char *filename) +{ + BPositionIO* target = ((my_hpgs_png_image *)_this)->target; + unsigned char *row; + int stride, depth; + _this->vtable->get_data(_this, &row, &stride, &depth); + for (int i = 0; i< _this->height; ++i) { + ssize_t bytesWritten = target->Write(row, stride); + if (bytesWritten < B_OK) + return bytesWritten; + row += stride; + } + + return 0; +} + + +// The input formats that this translator supports. +translation_format sInputFormats[] = { + { + HPGS_IMAGE_FORMAT, + B_TRANSLATOR_BITMAP, + HPGS_IN_QUALITY, + HPGS_IN_CAPABILITY, + "vector/x-hpgl2", + "HP-GL/2" + }, +}; + +// The output formats that this translator supports. +translation_format sOutputFormats[] = { + { + B_TRANSLATOR_BITMAP, + B_TRANSLATOR_BITMAP, + BITS_OUT_QUALITY, + BITS_OUT_CAPABILITY, + "x-be-bitmap", + "Be Bitmap image" + }, +}; + +// Default settings for the Translator +static TranSetting sDefaultSettings[] = { + {B_TRANSLATOR_EXT_HEADER_ONLY, TRAN_SETTING_BOOL, false}, + {B_TRANSLATOR_EXT_DATA_ONLY, TRAN_SETTING_BOOL, false} +}; + +const uint32 kNumInputFormats = sizeof(sInputFormats) / sizeof(translation_format); +const uint32 kNumOutputFormats = sizeof(sOutputFormats) / sizeof(translation_format); +const uint32 kNumDefaultSettings = sizeof(sDefaultSettings) / sizeof(TranSetting); + + +// #pragma mark - + + +HPGSTranslator::HPGSTranslator() + : BaseTranslator("HPGS Images", "HPGS Image Translator", + HPGS_TRANSLATOR_VERSION, + sInputFormats, kNumInputFormats, + sOutputFormats, kNumOutputFormats, + "HPGSTranslator_Settings", + sDefaultSettings, kNumDefaultSettings, + B_TRANSLATOR_BITMAP, HPGS_IMAGE_FORMAT) +{ + hpgs_init("/usr/local"); +} + + +HPGSTranslator::~HPGSTranslator() +{ + hpgs_cleanup(); +} + + +status_t +HPGSTranslator::DerivedIdentify(BPositionIO *stream, + const translation_format *format, BMessage *settings, + translator_info *info, uint32 outType) +{ + if (!outType) + outType = B_TRANSLATOR_BITMAP; + if (outType != B_TRANSLATOR_BITMAP) + return B_NO_TRANSLATOR; + + hpgs_istream *istream = hpgs_new_wrapper_istream(stream); + + status_t err = B_OK; + int verbosity = 1; + hpgs_bool multipage = HPGS_FALSE; + hpgs_bool ignore_ps = HPGS_FALSE; + hpgs_bool do_linewidth = HPGS_TRUE; + hpgs_device *size_dev = (hpgs_device *)hpgs_new_plotsize_device(ignore_ps, do_linewidth); + hpgs_reader *reader = hpgs_new_reader(istream, size_dev, multipage, verbosity); + if (hpgs_read(reader, HPGS_FALSE) == B_OK) { + info->type = HPGS_IMAGE_FORMAT; + info->group = B_TRANSLATOR_BITMAP; + info->quality = HPGS_IN_QUALITY; + info->capability = HPGS_IN_CAPABILITY; + snprintf(info->name, sizeof(info->name), "HPGS image"); + strcpy(info->MIME, "vector/x-hpgl2"); + } else + err = B_NO_TRANSLATOR; + + free(reader); + free(size_dev); + free(istream->stream); + free(istream); + + return err; +} + + +status_t +HPGSTranslator::DerivedTranslate(BPositionIO* source, + const translator_info* info, BMessage* settings, + uint32 outType, BPositionIO* target, int32 baseType) +{ + if (!outType) + outType = B_TRANSLATOR_BITMAP; + if (outType != B_TRANSLATOR_BITMAP || baseType != 0) + return B_NO_TRANSLATOR; + + status_t err = B_OK; + hpgs_istream *istream = hpgs_new_wrapper_istream(source); + + TranslatorBitmap header; + ssize_t bytesWritten; + uint32 dataSize; + + double paper_angle = 180.0; + double paper_border = 0.0; + double paper_width = 0.0; + double paper_height = 0.0; + int verbosity = 0; + int depth = 32; + int palette = 0; + hpgs_bool multipage = HPGS_FALSE; + hpgs_bool ignore_ps = HPGS_FALSE; + hpgs_bool do_linewidth = HPGS_TRUE; + hpgs_bool do_rop3 = HPGS_TRUE; + hpgs_bool antialias = HPGS_FALSE; + int image_interpolation = 0; + double thin_alpha = 0.25; + hpgs_device *size_dev = 0; + hpgs_bbox bbox = { 0.0, 0.0, 0.0, 0.0 }; + hpgs_image *image; + hpgs_paint_device *pdv; + hpgs_device *plot_dev; + + size_dev = (hpgs_device *)hpgs_new_plotsize_device(ignore_ps, do_linewidth); + hpgs_reader *reader = hpgs_new_reader(istream, size_dev, multipage, verbosity); + if (hpgs_read(reader, HPGS_FALSE)) { + fprintf(stderr, "no hpgs\n"); + err = B_NO_TRANSLATOR; + goto err1; + } + + if (hpgs_getplotsize(size_dev,1,&bbox)<0) { + fprintf(stderr, "no hpgs\n"); + err = B_NO_TRANSLATOR; + goto err1; + } + + // set the appropriate page placement. + if (paper_width > 0.0 && paper_height > 0.0) { + hpgs_reader_set_fixed_page(reader,&bbox, + paper_width, paper_height, paper_border, paper_angle); + } else { + paper_width = 200.0 * 72.0; + paper_height = 200.0 * 72.0; + hpgs_reader_set_dynamic_page(reader,&bbox, + paper_width, paper_height, paper_border, paper_angle); + } + + image = (hpgs_image*)hpgs_new_png_image((int)bbox.urx, (int)bbox.ury, depth, palette, do_rop3); + image->vtable->write = &my_pim_write; + image = (hpgs_image *)realloc(image, sizeof(my_hpgs_png_image)); + ((my_hpgs_png_image *)image)->target = target; + + pdv = hpgs_new_paint_device(image, NULL, &bbox, antialias); + hpgs_paint_device_set_image_interpolation(pdv, image_interpolation); + hpgs_paint_device_set_thin_alpha(pdv, thin_alpha); + + plot_dev = (hpgs_device *)pdv; + if (hpgs_reader_imbue(reader, plot_dev)) { + fprintf(stderr, hpgs_i18n("Error: Cannot imbue plot device to reader: %s\n"), + hpgs_get_error()); + err = B_NO_TRANSLATOR; + goto err2; + } + + dataSize = (int)bbox.urx * 4 * (int)bbox.ury; + + header.magic = B_TRANSLATOR_BITMAP; + header.bounds.Set(0, 0, (int)bbox.urx - 1, bbox.ury - 1); + header.rowBytes = (int)bbox.urx * 4; + header.colors = B_RGBA32; + header.dataSize = dataSize; + + // write out Be's Bitmap header + swap_data(B_UINT32_TYPE, &header, sizeof(TranslatorBitmap), + B_SWAP_HOST_TO_BENDIAN); + bytesWritten = target->Write(&header, sizeof(TranslatorBitmap)); + if (bytesWritten < B_OK) { + fprintf(stderr, "Write error %s\n", strerror(bytesWritten)); + err = bytesWritten; + goto err2; + } + + if ((size_t)bytesWritten != sizeof(TranslatorBitmap)) { + fprintf(stderr, "TranslatorBitmap\n"); + err = B_IO_ERROR; + } + + if (err == B_OK && hpgs_read(reader, HPGS_FALSE)) { + fprintf(stderr, hpgs_i18n("Error: Cannot process plot data %s\n"), hpgs_get_error()); + err = B_NO_TRANSLATOR; + } + +err2: + free(pdv); + free(image); + +err1: + free(reader); + free(size_dev); + free(istream->stream); + free(istream); + return err; +} + + +BView * +HPGSTranslator::NewConfigView(TranslatorSettings *settings) +{ + return new ConfigView(BRect(0, 0, 225, 175)); +} + + +// #pragma mark - + + +BTranslator * +make_nth_translator(int32 n, image_id you, uint32 flags, ...) +{ + if (n != 0) + return NULL; + + return new HPGSTranslator(); +} + diff --git a/src/add-ons/translators/hpgs/HPGSTranslator.h b/src/add-ons/translators/hpgs/HPGSTranslator.h new file mode 100644 index 0000000000..b95aee9c5d --- /dev/null +++ b/src/add-ons/translators/hpgs/HPGSTranslator.h @@ -0,0 +1,53 @@ +/* + * Copyright 2007, Jérôme Duval. All rights reserved. + * Distributed under the terms of the MIT License. + */ +#ifndef HPGS_TRANSLATOR_H +#define HPGS_TRANSLATOR_H + + +#include "BaseTranslator.h" + +#include +#include +#include +#include +#include +#include +#include +#include + + +#define HPGS_TRANSLATOR_VERSION B_TRANSLATION_MAKE_VERSION(0, 1, 0) +#define HPGS_IMAGE_FORMAT 'HPGI' + +#define HPGS_IN_QUALITY 0.90 +#define HPGS_IN_CAPABILITY 0.90 +#define BITS_IN_QUALITY 1 +#define BITS_IN_CAPABILITY 1 + +#define HPGS_OUT_QUALITY 0.8 +#define HPGS_OUT_CAPABILITY 0.8 +#define BITS_OUT_QUALITY 1 +#define BITS_OUT_CAPABILITY 0.9 + + +class HPGSTranslator : public BaseTranslator { + public: + HPGSTranslator(); + virtual ~HPGSTranslator(); + + virtual status_t DerivedIdentify(BPositionIO *inSource, + const translation_format *inFormat, BMessage *ioExtension, + translator_info *outInfo, uint32 outType); + + virtual status_t DerivedTranslate(BPositionIO *inSource, + const translator_info *inInfo, BMessage *ioExtension, + uint32 outType, BPositionIO *outDestination, int32 baseType); + + virtual BView *NewConfigView(TranslatorSettings *settings); + + private: +}; + +#endif // HPGS_TRANSLATOR_H diff --git a/src/add-ons/translators/hpgs/Jamfile b/src/add-ons/translators/hpgs/Jamfile new file mode 100644 index 0000000000..5ea67b8523 --- /dev/null +++ b/src/add-ons/translators/hpgs/Jamfile @@ -0,0 +1,59 @@ +SubDir HAIKU_TOP src add-ons translators hpgs ; + +SubDirSysHdrs [ FDirName $(SUBDIR) lib ] ; +SubDirCcFlags -DHPGS_SHARED -std=c99 ; +UseLibraryHeaders zlib png ; + +# Include code from shared translator directory +SEARCH_SOURCE += [ FDirName $(HAIKU_TOP) src add-ons translators shared ] ; + +local sources = +hpgsbase.c +hpgsbbox.c +hpgsbezier.c +hpgs.c +hpgscharacter.c +hpgsdevices.c +hpgsfont.c +hpgsglobal.c +hpgsgstate.c +hpgsi18n.c +hpgsimage.c +hpgsimagerop.c +hpgsistream.c +hpgslabel.c +hpgslexer.c +hpgsmatrix.c +hpgsostream.c +hpgspaint.c +hpgspaintimage.c +hpgspaintpath.c +hpgspath.c +hpgspcl.c +hpgspe.c +hpgspen.c +hpgspjl.c +hpgsreader.c +hpgsrop.c +hpgsscanline.c +hpgssetup.c +hpgstransform.c +hpgszostream.c +; + +Translator HPGSTranslator : + # HPGSTranslator classes + ConfigView.cpp + HPGSTranslator.cpp + $(sources) + + # shared classes + BaseTranslator.cpp + TranslatorSettings.cpp + TranslatorWindow.cpp + + : be translation libpng.so libtextencoding.so libz.so + : true +; + +SEARCH on [ FGristFiles $(sources) ] = [ FDirName $(SUBDIR) lib ] ; diff --git a/src/add-ons/translators/hpgs/ReadHelper.h b/src/add-ons/translators/hpgs/ReadHelper.h new file mode 100644 index 0000000000..bfe975394c --- /dev/null +++ b/src/add-ons/translators/hpgs/ReadHelper.h @@ -0,0 +1,127 @@ +/* + * Copyright 2007, Jérôme Duval. All rights reserved. + * Distributed under the terms of the MIT License. + */ +#ifndef READ_HELPER_H +#define READ_HELPER_H + +#include +#include +#include + +typedef struct my_hpgs_istream_st +{ + BPositionIO *stream; + status_t iseof; +} my_hpgs_istream; + + +static int +positionio_getc(my_hpgs_istream *stream) +{ + unsigned char value; + status_t error; + stream->iseof = 0; + error = stream->stream->Read((void *)&value, sizeof(unsigned char)); + if (error > B_OK) + return value; + stream->iseof = EOF; + return EOF; +} + + +static int +positionio_ungetc(int c, my_hpgs_istream *stream) +{ + return stream->stream->Seek(-1, SEEK_CUR); +} + + +static int +positionio_close(my_hpgs_istream *stream) +{ + return B_OK; +} + + +static int +positionio_eof(my_hpgs_istream *stream) +{ + return stream->iseof; +} + + +static int +positionio_error(my_hpgs_istream *stream) +{ + return errno; +} + + +static int +positionio_tell(my_hpgs_istream *stream, size_t *pos) +{ + *pos = stream->stream->Position(); + return 0; +} + + +static int +positionio_seek(my_hpgs_istream *stream, size_t pos) +{ + stream->stream->Seek(pos, SEEK_SET); + return 0; +} + + +static int +positionio_seekend(my_hpgs_istream *stream, size_t pos) +{ + stream->stream->Seek(pos, SEEK_END); + return 0; +} + + +static size_t +positionio_read(void *ptr, size_t size, size_t nmemb, my_hpgs_istream *stream) +{ + unsigned char *iptr = (unsigned char *)ptr; + size_t i = 0; + for (; i < nmemb; i++) { + if (size != stream->stream->Read(iptr, size)) + break; + iptr += size; + } + return i; +} + + +static hpgs_istream_vtable positionio_vtable = + { + (hpgs_istream_getc_func_t) positionio_getc, + (hpgs_istream_ungetc_func_t) positionio_ungetc, + (hpgs_istream_close_func_t) positionio_close, + (hpgs_istream_iseof_func_t) positionio_eof, + (hpgs_istream_iserror_func_t) positionio_error, + (hpgs_istream_seek_func_t) positionio_seek, + (hpgs_istream_tell_func_t) positionio_tell, + (hpgs_istream_read_func_t) positionio_read, + (hpgs_istream_seekend_func_t) positionio_seekend + }; + +hpgs_istream *hpgs_new_wrapper_istream(BPositionIO *stream) +{ + hpgs_istream *ret = (hpgs_istream *)malloc(sizeof(hpgs_istream)); + + if (!ret) + return NULL; + + ret->stream = (my_hpgs_istream *)malloc(sizeof(my_hpgs_istream)); + ret->vtable = &positionio_vtable; + ((my_hpgs_istream *)ret->stream)->iseof = 0; + ((my_hpgs_istream *)ret->stream)->stream = stream; + + return ret; +} + +#endif // READ_HELPER_H diff --git a/src/add-ons/translators/hpgs/lib/hpgs.c b/src/add-ons/translators/hpgs/lib/hpgs.c new file mode 100644 index 0000000000..561ee92c1c --- /dev/null +++ b/src/add-ons/translators/hpgs/lib/hpgs.c @@ -0,0 +1,1086 @@ +/*********************************************************************** + * * + * $Id: hpgs.c 390 2007-03-19 15:56:42Z softadm $ + * * + * hpgs - HPGl Script, a hpgl/2 interpreter, which uses a Postscript * + * API for rendering a scene and thus renders to a variety of * + * devices and fileformats. * + * * + * (C) 2004-2006 EV-i Informationstechnologie GmbH http://www.ev-i.at * + * * + * Author: Wolfgang Glas * + * * + * hpgs is free software; you can redistribute it and/or * + * modify it under the terms of the GNU Lesser General Public * + * License as published by the Free Software Foundation; either * + * version 2.1 of the License, or (at your option) any later version. * + * * + * hpgs is distributed in the hope that it will be useful, * + * but WITHOUT ANY WARRANTY; without even the implied warranty of * + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * + * Lesser General Public License for more details. * + * * + * You should have received a copy of the GNU Lesser General Public * + * License along with this library; if not, write to the * + * Free Software Foundation, Inc., 59 Temple Place, Suite 330, * + * Boston, MA 02111-1307 USA * + * * + *********************************************************************** + * * + * The main program. * + * * + ***********************************************************************/ + +#include +#include +#include +#include +#include + +#if defined ( __MINGW32__ ) || defined ( _MSC_VER ) +#include +#else +#include +#endif + +/*! \mainpage The HPGS documentation + + \section intro_sec Introduction + + + HPGS has been developed by + EV-i Informationstechnologie GmbH + and has been published under the + LGPL. + + For Details visit the project's homepage. + + \section install_sec Installation + + See the file INSTALL of the distribution. + + \section invoke_sec Invoking hpgs + + \verbinclude hpgs-args.txt + + \section api_sec The hpgs API. + + HPGS is designed to be highly modular and may be used inside + C or C++ programs for either displaying HPGL files or + drawing a vector graphics sceneery to an image. + + Refer to the \ref reader, \ref device, \ref paint_device and + \ref image modules in order to get an impression what the hpgs API + can do for you. + */ + + +#ifdef WIN32 + +#include + +static char *get_aux_path(void) +{ + const char *key = "SOFTWARE\\ev-i\\hpgs"; + DWORD len; + HKEY hkey; + char *ret; + const char *prg; + + if ((RegOpenKeyEx(HKEY_CURRENT_USER, + key, 0, KEY_READ, &hkey) == ERROR_SUCCESS || + RegOpenKeyEx(HKEY_LOCAL_MACHINE, + key, 0, KEY_READ, &hkey) == ERROR_SUCCESS )&& + RegQueryValueEx(hkey,"prefix",NULL,NULL,NULL,&len) == ERROR_SUCCESS) + { + ret = malloc(len+2); + + if (RegQueryValueEx(hkey,"prefix",NULL,NULL,ret,&len) != ERROR_SUCCESS) + { free (ret); ret = 0; } + + RegCloseKey(hkey); + + return ret; + } + + prg = getenv("PROGRAMFILES"); + + if (prg) + return hpgs_sprintf_malloc("%s\\EV-i",prg); + + return strdup("C:\\Programme\\EV-i"); +} +#else + +#ifndef HPGS_DEFAULT_PREFIX +#define HPGS_DEFAULT_PREFIX "/usr/local" +#endif + +static char *get_aux_path(void) +{ + char *p=getenv("EV_I_PREFIX"); + + if (!p) + return strdup(HPGS_DEFAULT_PREFIX); + + return strdup(p); +} +#endif + +static int usage (void) +{ + fprintf (stderr,hpgs_i18n( + "\n" + " hpgs v%s - HPGl Script, a hpgl/2 interpreter/renderer.\n" + "\n" + " (C) 2004-2006 ev-i Informationstechnologie GmbH (http://www.ev-i.at)\n" + " published under the LGPL (http://www.fsf.org/licenses/lgpl.html).\n" + "\n" + "Type `hpgs --help' for a detailed description of cmd line options.\n") + ,HPGS_VERSION ); + + hpgs_cleanup(); + + return 0; +} + +static int help (void) +{ + fprintf (stderr,hpgs_i18n( + "\n" + " hpgs v%s - HPGl Script, a hpgl/2 interpreter/renderer.\n" + "\n" + " (C) 2004-2006 ev-i Informationstechnologie GmbH (http://www.ev-i.at)\n" + " published under the LGPL (http://www.fsf.org/licenses/lgpl.html).\n" + "\n" + "usage: hpgs [-i] [-v] [-q] [-d ] [options...] [-o ] ...\n" + " -i ... Ignore plotsize from PS and determine\n" + " the plotsize from the file content.\n" + " --linewidth-size ... Account for linewidths in the plotsize\n" + " calculation for -i (default behaviour).\n" + " --no-linewidth-size ... Ignore linewidths in the plotsize\n" + " calculation for -i.\n" + " -v ... Increase verbosity.\n" + " -q ... Decrease verbosity, be quiet.\n" + " -o ... specifiy the output filename. If not specified, write\n" + " to stdout.\n" + " -m ... Switch to multipage mode, if a single file is given on the.\n" + " command line. If not specified, only the first page of the input\n" + " file is processed.\n" + " -w ... Correct linewidth by given factor (default: 1).\n" + " -d ... Specifiy the output device. The default is the\n" + " native 'eps' device, which writes a simple eps file.\n" + " See section `Supported devices' below.\n" + " -a ... Use antialiasing when rendering to a png image.\n" + " --thin-alpha=\n" + " Specifiy the minimal alpha value for thin lines.\n" + " allowed values lie in the interval [0.001,1.0] (default: 0.25).\n" + " -I ... Specifiy image interpolation.\n" + " --rop3 ... Use ROP3 raster operations for rendering on devices\n" + " with ROP3 capabilities (default).\n" + " --no-rop3 ... Suppress usage of ROP3 raster operations.\n" + " -c ... Specifiy the compression level for png writing.\n" + " -r ... Specifiy the device resolution in dpi.\n" + " If no y-resolution is given, the y-resolution\n" + " is set to the same value as the x-resolution.\n" + " -p ... Specifiy the maximum pixel size of the device.\n" + " This is in fact an alternate method to specify the\n" + " resolution of the device. If -p is given, the device\n" + " resolution is caclulated in a way, that the plot fits\n" + " into the given rectangle.\n" + " If no y-size is given, the size y-size\n" + " is set to the same value as the x-size.\n" + " -s ... Specifiy the plot size in pt (1/72 inch).\n" + " If -s is not given, the size is calculated from\n" + " the contents of the hpgl file.\n" + " The may be either one of the standard\n" + " paper sizes A0,A1,A2,A3 or A4, their landscape versions\n" + " A0l,A1l,A2l,A3l or A4l or a size in the format x\n" + " where and specify a physical length in one of the\n" + " formats ,mm,cm,inch or pt. is a floating point\n" + " number, the default unit is PostScript pt (1/72 inch).\n" + " --paper=\n" + " Specify a paper size of the output device. All plots\n" + " are scaled to this paper size respecting the given border.\n" + " If no fixed paper size is given, each page in the output\n" + " file has an individual size adapted to the size of the HPGL\n" + " content of the page.\n" + " The format of is decribed above for -s.\n" + " --border=\n" + " Specify a border for placing plots on output pages.\n" + " --rotation=\n" + " Specify an angle for placing plots on output pages.\n" + " --stamp=\n" + " Specify a string, which is printed in the background.\n" + " --stamp-encoding=\n" + " Specify an the name of the encoding of the string, which\n" + " is given in --stamp. Default is iso-8859-1.\n" + " --stamp-size=\n" + " Specify the size of the stamp specified with --stamp\n" + " in point. Default value: 500pt.\n" + " --dump-png=\n" + " Specify a filename for dumping inline PCL images in.\n" + " PNG format. The actual filenames written are:\n" + " 0001.png\n" + " 0002.png\n" + " .....\n" + " If contains an extension '.png' the counter\n" + " is put between the basename and the '.png' extension.\n" + " --help\n" + " Displays this usage information.\n" + " --version\n" + " Displays the version information.\n" + "\n" + "Supported devices (option -d):\n" + "\n" + " bbox ... writes a PostScript BoundingBox to stdout.\n" + " ps ... writes a multipage PostScript file.\n" + " eps ... writes an eps files.\n" + " png_256 ... writes an indexed 8bpp png image.\n" + " png_gray... writes a grayscale 8bpp png image.\n" + " png_rgb ... writes a rgb 24bpp png image.\n" + " png_gray_alpha ... writes a grayscale 16bpp png image\n" + " with an alpha channel.\n" + " png_rgb_alpha ... writes a rgb 32bpp png image\n" + " with an alpha channel.\n" + " cairo_png ... writes a rgb 32bpp png image using\n" + " the cairo library (experimental).\n") + ,HPGS_VERSION ); + + hpgs_cleanup(); + + return 0; +} + +static int get_double_arg(const char *arg, double *val) +{ + char * endptr = (char*)arg; + *val = strtod(arg,&endptr); + return (*endptr || endptr == arg) ? -1 : 0; +} + +static int get_double_pair(const char *arg, double *xval, double *yval) +{ + char * endptr = (char*)arg; + *xval = strtod(arg,&endptr); + + if (endptr == arg) return -1; + if (*endptr == '\0') { *yval = *xval; return 0; } + if (*endptr != 'x') return -1; + + const char *yarg=endptr+1; + + *yval = strtod(yarg,&endptr); + return (*endptr || endptr == yarg) ? -1 : 0; +} + +static int get_int_arg(const char *arg, int *val) +{ + char * endptr = (char*)arg; + *val = strtol(arg,&endptr,10); + return (*endptr) ? -1 : 0; +} + +static int get_int_pair(const char *arg, int *xval, int *yval) +{ + char * endptr = (char*)arg; + *xval = strtod(arg,&endptr); + + if (*endptr == '\0') { *yval = *xval; return 0; } + if (*endptr != 'x') return -1; + + const char *yarg=endptr+1; + + *yval = strtod(yarg,&endptr); + return (*endptr || endptr == yarg) ? -1 : 0; +} + +// helper function for supporting old device-specific options, which +// are now global ones. +static int get_dev_arg_value(const char *dev_name,int dev_name_len, + const char *opt, const char *argv[], + const char **value, int *narg) +{ + char *opt_name = alloca(4+dev_name_len+strlen(opt)); + + // contruct string -- + opt_name[1] = opt_name[0] = '-'; + memcpy(opt_name+2,dev_name,dev_name_len); + strcpy(&opt_name[2+dev_name_len],opt); + + return hpgs_get_arg_value(opt_name,argv,value,narg); +} + +/* + The main program analyses the cmd line argument and delegates the work. +*/ + +#define HPGS_MAX_PLUGIN_ARGS 32 + +int main(int argc, const char *argv[]) +{ + const char *dev_name="eps"; + int dev_name_len = 3; + const char *out_fn=0; + const char *stamp=0; + const char *stamp_enc=0; + const char *png_dump_fn=0; + int ifile; + char *aux_path; + double x_dpi=72.0; + double y_dpi=72.0; + hpgs_bbox bbox= { 0.0, 0.0, 0.0, 0.0 }; + double paper_angle = 0.0; + double paper_border = 0.0; + double paper_width = 0.0; + double paper_height = 0.0; + double lw_factor=-1.0; + double thin_alpha=0.25; + double stamp_size=500.0; + int x_px_size=0; + int y_px_size=0; + hpgs_bool multipage=HPGS_FALSE; + hpgs_bool ignore_ps=HPGS_FALSE; + hpgs_bool do_linewidth=HPGS_TRUE; + hpgs_bool do_rop3=HPGS_TRUE; + int verbosity=1; + int compression=6; + hpgs_bool antialias=HPGS_FALSE; + int image_interpolation=0; + hpgs_device *size_dev = 0; + hpgs_device *plot_dev = 0; + hpgs_istream *in = 0; + hpgs_reader *reader = 0; + hpgs_png_image *image = 0; + const char *plugin_argv[HPGS_MAX_PLUGIN_ARGS]; + int plugin_argc = 0; + int ret = 1; + +#ifdef LC_MESSAGES + setlocale(LC_MESSAGES,""); +#endif + setlocale(LC_CTYPE,""); + + aux_path = get_aux_path(); + + if (!aux_path) + { + fprintf(stderr,hpgs_i18n("Error getting installation path: %s.\n"), + strerror(errno)); + return 1; + } + + hpgs_init(aux_path); + free(aux_path); + + memset(plugin_argv,0,sizeof(plugin_argv)); + + ++argv; + --argc; + + while (argc>0) + { + int narg = 1; + const char *value; + + if (strcmp(argv[0],"--") == 0) + { + ++argv; + --argc; + break; + } + else if (strcmp(argv[0],"-v") == 0) + { + ++verbosity; + } + else if (strcmp(argv[0],"-q") == 0 || strcmp(argv[0],"-dQUIET") == 0) + { + --verbosity; + } + else if (strcmp(argv[0],"-i") == 0) + { + ignore_ps=HPGS_TRUE; + } + else if (strcmp(argv[0],"-m") == 0) + { + multipage=HPGS_TRUE; + } + else if (hpgs_get_arg_value("-d",argv,&value,&narg)) + { + dev_name = value; + dev_name_len = strlen(dev_name); + + if (plugin_argc) + { + fprintf(stderr,hpgs_i18n("Error: Device options specified before -d argument.\n")); + return usage(); + } + } + else if (hpgs_get_arg_value("--stamp=",argv,&value,&narg)) + { + stamp = value; + } + else if (hpgs_get_arg_value("--stamp-encoding=",argv,&value,&narg)) + { + stamp_enc = value; + } + else if (hpgs_get_arg_value("--stamp-size=",argv,&value,&narg)) + { + if (hpgs_parse_length(value,&stamp_size)) + { + fprintf(stderr,hpgs_i18n("Error: --stamp-size= must be followed by a valid length.\n")); + return usage(); + } + + if (stamp_size < 20.0 || stamp_size > 2000.0) + { + fprintf(stderr,hpgs_i18n("Error: stamp-size must lie in the interval [20,2000]pt.\n")); + return usage(); + } + } + else if (hpgs_get_arg_value("--dump-png=",argv,&value,&narg)) + { + png_dump_fn = value; + } + else if (hpgs_get_arg_value("-o",argv,&value,&narg)) + { + out_fn = value; + } + else if (strcmp(argv[0],"-a") == 0) + { + antialias = HPGS_TRUE; + } + else if (hpgs_get_arg_value("-I",argv,&value,&narg)) + { + if (get_int_arg(value,&image_interpolation)) + { + if (narg == 1) + { + fprintf(stderr,hpgs_i18n("Error: -I must be followed by an integer number.\n")); + return usage(); + } + else + { + image_interpolation= 1; + narg = 1; + } + } + + if (image_interpolation < 0 || image_interpolation > 1) + { + fprintf(stderr,hpgs_i18n("Error: The argument to -I must be 0 or 1.\n")); + return usage(); + } + } + else if (hpgs_get_arg_value("-c",argv,&value,&narg)) + { + if (get_int_arg(value,&compression)) + { + fprintf(stderr,hpgs_i18n("Error: -c must be followed by an integer number.\n")); + return usage(); + } + + if (compression < 1 || compression > 9) + { + fprintf(stderr,hpgs_i18n("Error: compression factor must lie in the interval [1,9].\n")); + return usage(); + } + } + else if (hpgs_get_arg_value("-w",argv,&value,&narg)) + { + if (get_double_arg(value,&lw_factor)) + { + fprintf(stderr,hpgs_i18n("Error: -w must be followed by a floating point number.\n")); + return usage(); + } + + if (lw_factor < 0.0 || lw_factor > 10.0) + { + fprintf(stderr,hpgs_i18n("Error: Linewidth factor must lie in the interval [0.0,10.0].\n")); + return usage(); + } + } + else if (hpgs_get_arg_value("--thin-alpha=",argv,&value,&narg)) + { + if (get_double_arg(value,&thin_alpha)) + { + fprintf(stderr,hpgs_i18n("Error: --thin-alpha= must be followed by a floating point number.\n")); + return usage(); + } + + if (thin_alpha < 0.01 || thin_alpha > 10.0) + { + fprintf(stderr,hpgs_i18n("Error: Thin alpha must lie in the interval [0.01,10.0].\n")); + return usage(); + } + } + else if (hpgs_get_arg_value("-r",argv,&value,&narg)) + { + if (get_double_pair(value,&x_dpi,&y_dpi)) + { + fprintf(stderr,hpgs_i18n("Error: -r must be followed by or x.\n")); + return usage(); + } + + if (x_dpi < 5.0 || y_dpi < 5.0) + { + fprintf(stderr,hpgs_i18n("Error: Resolutions must be at least 5 dpi.\n")); + return usage(); + } + } + else if (hpgs_get_arg_value("-p",argv,&value,&narg)) + { + if (get_int_pair(value,&x_px_size,&y_px_size)) + { + fprintf(stderr,hpgs_i18n("Error: -p must be followed by or x.\n")); + return usage(); + } + + if (y_px_size < 20 || x_px_size < 20) + { + fprintf(stderr,hpgs_i18n("Error: Pixel sizes must be at least 20px.\n")); + return usage(); + } + } + else if (hpgs_get_arg_value("-s",argv,&value,&narg)) + { + double x_size,y_size; + + if (hpgs_parse_papersize(value,&x_size, &y_size)<0) + { + fprintf(stderr,hpgs_i18n("Error: -s must be followed by a valid paper size.\n")); + return usage(); + } + + if (x_size < 72.0 || y_size < 72.0) + { + fprintf(stderr,hpgs_i18n("Error: The plot size must be at least 72 pt.\n")); + return usage(); + } + + bbox.urx = x_size; + bbox.ury = y_size; + } + else if (hpgs_get_arg_value("--paper=",argv,&value,&narg)) + { + if (hpgs_parse_papersize(value,&paper_width,&paper_height)<0) + { + fprintf(stderr,hpgs_i18n("Error: --paper= must be followed by a valid paper size.\n")); + return usage(); + } + + if (paper_width < 72.0 || paper_height < 72.0) + { + fprintf(stderr,hpgs_i18n("Error: The paper size must be at least 72 pt.\n")); + return usage(); + } + } + else if (hpgs_get_arg_value("--border=",argv,&value,&narg) || + // Allow old device-specific border parameters. + get_dev_arg_value(dev_name,dev_name_len,"-border=",argv,&value,&narg) ) + { + if (hpgs_parse_length(value,&paper_border)<0) + { + fprintf(stderr,hpgs_i18n("Error: --border= must be followed by a valid length.\n")); + return usage(); + } + + if (paper_border < 0.0 || paper_border > 144.0) + { + fprintf(stderr,hpgs_i18n("Error: The page border must lie in the interval [0,144] pt.\n")); + return usage(); + } + } + else if (hpgs_get_arg_value("--rotation=",argv,&value,&narg) || + // Allow old device-specific rotation parameters. + get_dev_arg_value(dev_name,dev_name_len,"-rotation=",argv,&value,&narg) ) + { + if (hpgs_parse_length(value,&paper_angle)<0) + { + fprintf(stderr,hpgs_i18n("Error: --angle= must be followed by a valid angle.\n")); + return usage(); + } + } + else if (strcmp(argv[0],"--linewidth-size") == 0) + { + do_linewidth = HPGS_TRUE; + } + else if (strcmp(argv[0],"--no-linewidth-size") == 0) + { + do_linewidth = HPGS_FALSE; + } + else if (strcmp(argv[0],"--rop3") == 0) + { + do_rop3 = HPGS_TRUE; + } + else if (strcmp(argv[0],"--no-rop3") == 0) + { + do_rop3 = HPGS_FALSE; + } + else if (strcmp(argv[0],"--help") == 0) + { + return help(); + } + else if (strcmp(argv[0],"--version") == 0) + { + usage(); + return 0; + } + else if (strncmp(argv[0],"--",2) == 0 && + strncmp(argv[0]+2,dev_name,dev_name_len) == 0 && + argv[0][dev_name_len+2] == '-') + { + int l=strlen(argv[0]); + + if (plugin_argc >= HPGS_MAX_PLUGIN_ARGS-1) + { + fprintf(stderr,hpgs_i18n("Error: Number of plugin-args exceeds maximum of %d.\n"), + HPGS_MAX_PLUGIN_ARGS-1); + return usage(); + } + + plugin_argv[plugin_argc] = argv[0]+dev_name_len+2; + ++plugin_argc; + + if (argv[0][l-1] == '=') + { + if (plugin_argc >= HPGS_MAX_PLUGIN_ARGS-1) + { + fprintf(stderr,hpgs_i18n("Error: Number of plugin-args exceed maximum of %d.\n"), + HPGS_MAX_PLUGIN_ARGS-1); + usage(); + } + + plugin_argv[plugin_argc] = argv[2]; + ++plugin_argc; + + narg=2; + } + } + else + { + if (argv[0][0] == '-') + { + fprintf(stderr,hpgs_i18n("Error: Unknown option %s given.\n"),argv[0]); + return usage(); + } + + break; + } + + argv+=narg; + argc-=narg; + } + + if (argc < 1) + { + fprintf(stderr,hpgs_i18n("Error: No input file given.\n")); + return usage(); + } + + if (argc > 1 && !multipage) + { + multipage = HPGS_TRUE; + } + + // adjust default linewidth factor. + if (lw_factor < 0.0) + { + // This is the best choice for our basic, non-antialiased renderer, + // which rounds up pixel line widths. + if (antialias == 0 && strncmp(dev_name,"png_",4) == 0) + lw_factor = 0.5; + else + lw_factor = 1.0; + } + + size_dev = (hpgs_device*)hpgs_new_plotsize_device(ignore_ps,do_linewidth); + + if (!size_dev) + { + fprintf(stderr,hpgs_i18n("Error: Cannot create plotsize device.\n")); + goto cleanup; + } + + in = hpgs_new_file_istream(argv[0]); + + if (!in) + { + fprintf(stderr,hpgs_i18n("Error: Cannot open input file %s: %s\n"), + argv[0],strerror(errno)); + hpgs_device_destroy((hpgs_device*)size_dev); + goto cleanup; + } + + reader = hpgs_new_reader(in,size_dev, + multipage,verbosity); + + if (!reader) + { + fprintf(stderr,hpgs_i18n("Error: Cannot create hpgl reader: %s\n"),strerror(errno)); + goto cleanup; + } + + hpgs_reader_set_lw_factor(reader,lw_factor); + + // determine plot size, if not specified on the cmd line + if (bbox.urx < 72.0 || bbox.ury < 72.0) + { + // read in multiple pages. + for (ifile = 1; ifile < argc; ++ifile) + { + if (hpgs_read(reader,HPGS_FALSE)) + { + fprintf(stderr,hpgs_i18n("Error: Cannot determine plot size of file %s: %s\n"), + argv[ifile-1],hpgs_get_error()); + goto cleanup; + } + + in = hpgs_new_file_istream(argv[ifile]); + + if (!in) + { + fprintf(stderr,hpgs_i18n("Error: Cannot open input file %s: %s\n"), + argv[ifile],strerror(errno)); + goto cleanup; + } + + hpgs_reader_attach(reader,in); + } + + if (hpgs_read(reader,HPGS_TRUE)) + { + fprintf(stderr,hpgs_i18n("Error: Cannot determine plot size of file %s: %s\n"), + argv[ifile-1],hpgs_get_error()); + goto cleanup; + } + + // get bounding box of first page. + // (will return overall boundingbox, if in singlepage mode.) + if (hpgs_getplotsize(size_dev,1,&bbox)<0) + { + fprintf(stderr,hpgs_i18n("Error: Cannot determine plotsize: %s\n"), + hpgs_get_error()); + goto cleanup; + } + + if (hpgs_bbox_isempty(&bbox)) + { + fprintf(stderr,hpgs_i18n("Error: Empty bounding: %g %g %g %g.\n"), + bbox.llx,bbox.lly,bbox.urx,bbox.ury); + goto cleanup; + } + + if (verbosity >= 1) + fprintf(stderr,"BoundingBox: %g %g %g %g.\n",bbox.llx,bbox.lly,bbox.urx,bbox.ury); + } + + // set the appropriate page placement. + if (paper_width > 0.0 && paper_height > 0.0) + { + hpgs_reader_set_fixed_page(reader,&bbox, + paper_width,paper_height, + paper_border,paper_angle ); + } + else + { + paper_width = 200.0 * 72.0; + paper_height = 200.0 * 72.0; + + hpgs_reader_set_dynamic_page(reader,&bbox, + paper_width,paper_height, + paper_border,paper_angle ); + } + + if (strcmp(dev_name,"bbox") == 0) + { + int i; + FILE *out = out_fn ? fopen(out_fn,"wb") : stdout; + + if (!out) + { + fprintf(stderr,hpgs_i18n("Error: Cannot open output file <%s>.\n"),out_fn); + goto cleanup; + } + + for (i=0;i<10000;++i) + { + int r = hpgs_getplotsize(size_dev,i,&bbox); + + if (r < 0) + { + fprintf(stderr,hpgs_i18n("Error: Cannot determine plotsize: %s\n"), + hpgs_get_error()); + fclose(out); + goto cleanup; + } + + if (r) break; + + if (i>0) + { + fprintf(out,"%%%%Page: %d %d.\n",i,i); + fprintf(out,"%%%%PageBoundingBox: %d %d %d %d.\n", + (int)floor(bbox.llx),(int)floor(bbox.lly), + (int)ceil(bbox.urx),(int)ceil(bbox.ury)); + fprintf(out,"%%%%PageHiResBoundingBox: %g %g %g %g.\n",bbox.llx,bbox.lly,bbox.urx,bbox.ury); + } + else + { + fprintf(out,"%%%%BoundingBox: %d %d %d %d.\n", + (int)floor(bbox.llx),(int)floor(bbox.lly), + (int)ceil(bbox.urx),(int)ceil(bbox.ury)); + fprintf(out,"%%%%HiResBoundingBox: %g %g %g %g.\n",bbox.llx,bbox.lly,bbox.urx,bbox.ury); + } + } + + if (out != stdout) fclose(out); + + ret=0; + goto cleanup; + } + else if (strcmp(dev_name,"eps") == 0) + { + plot_dev = + (hpgs_device*)hpgs_new_eps_device(out_fn,&bbox,do_rop3); + + if (!plot_dev) + { + fprintf(stderr,hpgs_i18n("Error: Cannot create eps device.\n")); + goto cleanup; + } + } + else if (strcmp(dev_name,"ps") == 0) + { + plot_dev = + (hpgs_device*)hpgs_new_ps_device(out_fn,&bbox,do_rop3); + + if (!plot_dev) + { + fprintf(stderr,hpgs_i18n("Error: Cannot create postscript device.\n")); + goto cleanup; + } + } + else if (strncmp(dev_name,"png_",4) == 0) + { + int depth = 8; + int palette = 0; + hpgs_paint_device *pdv; + + if (strcmp(dev_name+4,"gray") == 0) + depth = 8; + else if (strcmp(dev_name+4,"gray_alpha") == 0) + depth = 16; + else if (strcmp(dev_name+4,"rgb") == 0) + depth = 24; + else if (strcmp(dev_name+4,"rgb_alpha") == 0) + depth = 32; + else if (strcmp(dev_name+4,"256") == 0) + palette = 1; + else + { + fprintf(stderr,hpgs_i18n("Error: png device %s in not supported.\n"), + dev_name); + goto cleanup; + } + + if (x_px_size >= 20 && y_px_size >= 20) + { + // get overall bounding box, if pixel size is specified. + // This way no page image exceeds the given size and + // all images have the same resolution. + hpgs_bbox bb; + + if (hpgs_getplotsize(size_dev,0,&bb)<0) + { + fprintf(stderr,hpgs_i18n("Error: Cannot determine overall plotsize: %s\n"), + hpgs_get_error()); + goto cleanup; + } + + x_dpi = 72.0 * x_px_size / (bb.urx-bb.llx); + y_dpi = 72.0 * y_px_size / (bb.ury-bb.lly); + + if (x_dpi > y_dpi) + { + x_dpi = y_dpi; + x_px_size = x_dpi * (bb.urx-bb.llx) / 72.0; + } + else + { + y_dpi = x_dpi; + y_px_size = y_dpi * (bb.ury-bb.lly) / 72.0; + } + } + else + { + // initialize the pixel size from the first page. + x_px_size = x_dpi * (bbox.urx-bbox.llx) / 72.0; + y_px_size = y_dpi * (bbox.ury-bbox.lly) / 72.0; + } + + image = hpgs_new_png_image(x_px_size,y_px_size,depth,palette,do_rop3); + + if (!image) + { + fprintf(stderr,hpgs_i18n("Error creating %dx%dx%d sized png image: %s.\n"), + x_px_size,y_px_size,depth,strerror(errno)); + goto cleanup; + } + + hpgs_png_image_set_compression(image,compression); + + pdv = hpgs_new_paint_device((hpgs_image*)image, + out_fn,&bbox, + antialias); + if (!pdv) + { + fprintf(stderr,hpgs_i18n("Error: Cannot create paint device.\n")); + goto cleanup; + } + + hpgs_paint_device_set_image_interpolation(pdv,image_interpolation); + hpgs_paint_device_set_thin_alpha(pdv,thin_alpha); + // set the resolution of the image, although + // hpgs_new_paint_device has done this before. + // The reason is, that we know the resolution with more precision + // than hpgs_new_paint_device. + hpgs_image_set_resolution((hpgs_image*)image,x_dpi,y_dpi); + + plot_dev = (hpgs_device *)pdv; + } + else + { + if (x_px_size >= 20 && y_px_size >= 20) + { + // calculate resolution from overall bounding box, + // if pixel size is specified. + // This way no page image exceeds the given size and + // all images have the same resolution. + hpgs_bbox bb; + + if (hpgs_getplotsize(size_dev,0,&bb)<0) + { + fprintf(stderr,hpgs_i18n("Error: Cannot determine overall plotsize: %s\n"), + hpgs_get_error()); + goto cleanup; + } + + x_dpi = 72.0 * x_px_size / (bb.urx-bb.llx); + y_dpi = 72.0 * y_px_size / (bb.ury-bb.lly); + + if (x_dpi > y_dpi) + x_dpi = y_dpi; + else + y_dpi = x_dpi; + } + + void *page_asset_ctxt = 0; + hpgs_reader_asset_func_t page_asset_func = 0; + void *frame_asset_ctxt = 0; + hpgs_reader_asset_func_t frame_asset_func = 0; + + if (hpgs_new_plugin_device(&plot_dev, + &page_asset_ctxt, + &page_asset_func, + &frame_asset_ctxt, + &frame_asset_func, + dev_name,out_fn,&bbox, + x_dpi,y_dpi,do_rop3, + plugin_argc,plugin_argv)) + { + fprintf(stderr,hpgs_i18n("Error: Cannot create plugin device: %s\n"), + hpgs_get_error()); + goto cleanup; + } + + if (page_asset_func) + hpgs_reader_set_page_asset_func(reader,page_asset_ctxt,page_asset_func); + + if (frame_asset_func) + hpgs_reader_set_frame_asset_func(reader,frame_asset_ctxt,frame_asset_func); + } + + if (!plot_dev) + { + fprintf (stderr,hpgs_i18n("Error: invalid plot device name %s specified.\n"),dev_name); + goto cleanup; + } + + if (png_dump_fn && hpgs_reader_set_png_dump(reader,png_dump_fn)) + { + fprintf(stderr,hpgs_i18n("Error: Cannot set png_dump filename to reader: %s\n"), + hpgs_get_error()); + goto cleanup; + } + + if (stamp && hpgs_device_stamp(plot_dev,&bbox,stamp,stamp_enc,stamp_size)) + { + fprintf(stderr,hpgs_i18n("Error: Cannot stamp plot: %s\n"), + hpgs_get_error()); + goto cleanup; + } + + if (hpgs_reader_imbue(reader,plot_dev)) + { + fprintf(stderr,hpgs_i18n("Error: Cannot imbue plot device to reader: %s\n"), + hpgs_get_error()); + goto cleanup; + } + + // re-open first file, if we have more than one input file. + if (argc > 1) + { + in = hpgs_new_file_istream(argv[0]); + + if (!in) + { + fprintf(stderr,hpgs_i18n("Error: Cannot open input file %s: %s\n"), + argv[0],strerror(errno)); + goto cleanup; + } + hpgs_reader_attach(reader,in); + } + + // read in multiple pages. + for (ifile = 1; ifile < argc; ++ifile) + { + if (hpgs_read(reader,HPGS_FALSE)) + { + fprintf(stderr,hpgs_i18n("Error: Cannot process plot file %s: %s\n"), + argv[ifile-1],hpgs_get_error()); + goto cleanup; + } + + in = hpgs_new_file_istream(argv[ifile]); + + if (!in) + { + fprintf(stderr,hpgs_i18n("Error: Cannot open input file %s: %s\n"), + argv[ifile],strerror(errno)); + goto cleanup; + } + + hpgs_reader_attach(reader,in); + } + + if (hpgs_read(reader,HPGS_TRUE)) + { + fprintf(stderr,hpgs_i18n("Error: Cannot process plot file %s: %s\n"), + argv[ifile-1],hpgs_get_error()); + goto cleanup; + } + + if (verbosity >= 2) + fprintf(stderr,hpgs_i18n("Success.\n")); + + ret = 0; + + cleanup: + if (reader) + hpgs_destroy_reader(reader); + + hpgs_cleanup(); + + return ret; +} diff --git a/src/add-ons/translators/hpgs/lib/hpgs.h b/src/add-ons/translators/hpgs/lib/hpgs.h new file mode 100644 index 0000000000..bb82e7eb39 --- /dev/null +++ b/src/add-ons/translators/hpgs/lib/hpgs.h @@ -0,0 +1,1218 @@ +/*********************************************************************** + * * + * $Id: hpgs.h 381 2007-02-20 09:06:38Z softadm $ + * * + * hpgs - HPGl Script, a hpgl/2 interpreter, which uses a Postscript * + * API for rendering a scene and thus renders to a variety of * + * devices and fileformats. * + * * + * (C) 2004-2006 ev-i Informationstechnologie GmbH http://www.ev-i.at * + * * + * Author: Wolfgang Glas * + * * + * hpgs is free software; you can redistribute it and/or * + * modify it under the terms of the GNU Lesser General Public * + * License as published by the Free Software Foundation; either * + * version 2.1 of the License, or (at your option) any later version. * + * * + * hpgs is distributed in the hope that it will be useful, * + * but WITHOUT ANY WARRANTY; without even the implied warranty of * + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * + * Lesser General Public License for more details. * + * * + * You should have received a copy of the GNU Lesser General Public * + * License along with this library; if not, write to the * + * Free Software Foundation, Inc., 59 Temple Place, Suite 330, * + * Boston, MA 02111-1307 USA * + * * + *********************************************************************** + * * + * The public interfaces, which have to be known to all components. * + * * + ***********************************************************************/ + +#ifndef __HPGS_H +#define __HPGS_H + +#include +#include +#include + +#ifdef __cplusplus +extern "C" { +#endif + +#ifndef __GNUC__ +#ifdef _MSC_VER +#define __inline__ __inline +#else +#define __inline__ inline +#endif +#endif + +/* All this is needed in order to set the right attributes for functions. + This allows us to build fully compliant dlls under Windows and to + hide functions needed for the implementation of the API in + ELF modules. Additionally, we make use of the 'format' attribute of + gcc in order to get the most out of -Wall. + */ +#ifdef HPGS_SHARED +# ifdef WIN32 +# ifdef __GNUC__ +# ifdef HPGS_BUILD_SLIB +# define HPGS_API __attribute__((dllexport)) +# define HPGS_PRINTF_API(i) __attribute__((dllexport,format(printf,i,i+1))) +# define HPGS_I18N_API __attribute__((dllexport,format_arg (1))) +# define HPGS_I18N_N_API __attribute__((dllexport,format_arg (1),format_arg (2))) +# else +# define HPGS_API __attribute__((dllimport)) +# define HPGS_PRINTF_API(i) __attribute__((dllimport,format(printf,i,i+1))) +# define HPGS_I18N_API __attribute__((dllimport,format_arg (1))) +# define HPGS_I18N_N_API __attribute__((dllimport,format_arg (1),format_arg (2))) +# endif +# define HPGS_INTERNAL_PRINTF_API(i) __attribute__((format(printf,i,i+1))) +# else +# ifdef HPGS_BUILD_SLIB +# define HPGS_API __declspec(dllexport) +# else +# define HPGS_API __declspec(dllimport) +# endif +# endif +# else +# ifdef __GNUC__ +# define HPGS_PRINTF_API(i) __attribute__((format(printf,i,i+1))) +# define HPGS_I18N_API __attribute__((format_arg (1))) +# define HPGS_I18N_N_API __attribute__((format_arg (1),format_arg (2))) +# define HPGS_INTERNAL_API __attribute__((visibility("hidden"))) +# define HPGS_INTERNAL_PRINTF_API(i) __attribute__((visibility("hidden"),format(printf,i,i+1))) +# endif +# endif +#endif + +#ifndef HPGS_API +#define HPGS_API +#endif +#ifndef HPGS_PRINTF_API +#define HPGS_PRINTF_API(i) HPGS_API +#endif +#ifndef HPGS_I18N_API +#define HPGS_I18N_API HPGS_API +#endif +#ifndef HPGS_I18N_N_API +#define HPGS_I18N_N_API HPGS_API +#endif +#ifndef HPGS_INTERNAL_API +#define HPGS_INTERNAL_API +#endif +#ifndef HPGS_INTERNAL_PRINTF_API +#define HPGS_INTERNAL_PRINTF_API(i) HPGS_INTERNAL_API +#endif + +/* These defines are used in order to allow better doxygen integration + of the printf API functions. */ +#define HPGS_PRINTF1_API HPGS_PRINTF_API(1) +#define HPGS_PRINTF2_API HPGS_PRINTF_API(2) +#define HPGS_INTERNAL_PRINTF1_API HPGS_INTERNAL_PRINTF_API(1) +#define HPGS_INTERNAL_PRINTF2_API HPGS_INTERNAL_PRINTF_API(2) + +#ifdef WIN32 +#define HPGS_SIZE_T_FMT "%lu" +#else +#define HPGS_SIZE_T_FMT "%zu" +#endif + +/*! \file hpgs.h + + \brief The public interfaces. + + A header file, which declares the public structures and functions + provided by the hpgs library. The API declared in this header file + remains stable across the whole series of release with the same + major ans minor number. +*/ + +#define HPGS_STRINGIFYIFY(i) #i +#define HPGS_STRINGIFY(i) HPGS_STRINGIFYIFY(i) + +#define HPGS_MAJOR_VERSION 1 +#define HPGS_MINOR_VERSION 1 +#define HPGS_PATCH_VERSION 0 +#define HPGS_EXTRA_VERSION + +// a string for displaying the version. +#define HPGS_VERSION HPGS_STRINGIFY(HPGS_MAJOR_VERSION) "." HPGS_STRINGIFY(HPGS_MINOR_VERSION) "." HPGS_STRINGIFY(HPGS_PATCH_VERSION) HPGS_STRINGIFY(HPGS_EXTRA_VERSION) + +#define HPGS_ESC '\033' + +#define HPGS_MAX_LABEL_SIZE 256 + +#define hpgs_alloca(sz) alloca(sz) + +/*! @addtogroup base + * @{ + */ +typedef int hpgs_bool; + +#define HPGS_TRUE 1 +#define HPGS_FALSE 0 + +HPGS_API int hpgs_array_safe_resize (size_t itemsz, void **pptr, size_t *psz, size_t nsz); + +#define HPGS_MIN(a,b) ((a)<(b)?(a):(b)) +#define HPGS_MAX(a,b) ((a)>(b)?(a):(b)) + +#define HPGS_INIT_ARRAY(st,type,pmemb,nmemb,szmemb,insz) \ +(st->szmemb=insz,st->nmemb=0,(st->pmemb=(type*)malloc(sizeof(type)*insz))?0:-1) + +#define HPGS_GROW_ARRAY_FOR_PUSH(st,type,pmemb,nmemb,szmemb) \ +((st->nmemb >= st->szmemb)?hpgs_array_safe_resize(sizeof(type),(void **)(&st->pmemb),&st->szmemb,st->szmemb*2):(0)) + +#define HPGS_GROW_ARRAY_MIN_SIZE(st,type,pmemb,nmemb,szmemb,msz) \ +((st->nmemb>=st->szmemb||st->szmembpmemb),&st->szmemb,HPGS_MAX(st->szmemb*2,msz)):(0)) + +#ifdef WIN32 +#define HPGS_PATH_SEPARATOR '\\' +#else +#define HPGS_PATH_SEPARATOR '/' +#endif + +HPGS_API void hpgs_init (const char *prefix); +HPGS_API const char *hpgs_get_prefix(); +HPGS_API void hpgs_cleanup (void); +HPGS_API char *hpgs_share_filename(const char *rel_filename); + +HPGS_API char *hpgs_vsprintf_malloc(const char *fmt, va_list ap); +HPGS_PRINTF1_API char *hpgs_sprintf_malloc(const char *fmt, ...); + +HPGS_PRINTF1_API int hpgs_set_error(const char *fmt, ...); +HPGS_PRINTF1_API int hpgs_error_ctxt(const char *fmt, ...); +HPGS_API int hpgs_set_verror(const char *fmt, va_list ap); +HPGS_API int hpgs_verror_ctxt(const char *fmt, va_list ap); +HPGS_API const char *hpgs_get_error(); +HPGS_API hpgs_bool hpgs_have_error(); +HPGS_API void hpgs_clear_error(); + +HPGS_API int hpgs_next_utf8(const char **p); +HPGS_API int hpgs_utf8_strlen(const char *p, int n); + +HPGS_I18N_API const char *hpgs_i18n(const char *msg); +HPGS_I18N_N_API const char *hpgs_i18n_n(const char *msg, + const char *msg_plural, + unsigned long n); + +typedef void (*hpgs_logger_func_t) (const char *fmt, va_list ap); +HPGS_API void hpgs_set_logger(hpgs_logger_func_t func); +HPGS_PRINTF1_API void hpgs_log(const char *fmt, ...); +HPGS_API void hpgs_vlog(const char *fmt, va_list ap); + +HPGS_API hpgs_bool hpgs_get_arg_value(const char *opt, const char *argv[], + const char **value, int *narg); + +/*! \brief A 2D point. + + This structure has a public alias \c hpgs_point and + represents a point consisting of double precision + x and y coordinates. + */ +typedef struct hpgs_point_st { + double x, y; +} hpgs_point; + +/*! \brief An application level RGB color. + + This structure has a public alias \c hpgs_color and + represents an application level RGB color consisting + of double precision r,g and b color values in the range + from 0.0 to 1.0. + */ +typedef struct hpgs_color_st { + double r, g, b; +} hpgs_color; + +typedef struct hpgs_palette_color_st hpgs_palette_color; + +/*! \brief A screen RGB color as stored in a palette. + + This structure has a public alias \c hpgs_palette_color and + represents a screen RGB color consisting of single byte + r,g and b color values in the range 0 to 255. + */ +struct hpgs_palette_color_st +{ + unsigned char r; + unsigned char g; + unsigned char b; +}; + +typedef void (*hpgs_rop3_func_t) (unsigned char *, unsigned char, unsigned char); + +HPGS_API hpgs_rop3_func_t hpgs_rop3_func(int rop3, + hpgs_bool src_transparency, + hpgs_bool pattern_transparency); + +typedef unsigned (*hpgs_xrop3_func_t) (unsigned char, unsigned char); + +HPGS_API hpgs_xrop3_func_t hpgs_xrop3_func(int rop3, + hpgs_bool src_transparency, + hpgs_bool pattern_transparency); + +typedef struct hpgs_paint_color_st hpgs_paint_color; + +/*! \brief An image RGB color with an optional palette index. + + This structure has a public alias \c hpgs_paint_color and + represents an image RGB color with an optional palette index + consisting of single byte + r,g and b color values in the range 0 to 255 as well as of + a single byte palette index. + + For calculating a suitable palette index for a given + \c hpgs_image consider calling \c hpgs_image_define_color. + */ +struct hpgs_paint_color_st +{ + unsigned char r; + unsigned char g; + unsigned char b; + unsigned char index; +}; + +typedef struct hpgs_bbox_st hpgs_bbox; + +/*! \brief A bounding box. + + This structure hold a bounding box used in several contexts. + */ +struct hpgs_bbox_st +{ + double llx; + double lly; + double urx; + double ury; +}; + +HPGS_API hpgs_bool hpgs_bbox_isequal(const hpgs_bbox *bb1, const hpgs_bbox *bb2); +HPGS_API hpgs_bool hpgs_bbox_isnull (const hpgs_bbox *bb); +HPGS_API hpgs_bool hpgs_bbox_isempty (const hpgs_bbox *bb); +HPGS_API void hpgs_bbox_distance (hpgs_point *d, const hpgs_bbox *bb1, const hpgs_bbox *bb2); +HPGS_API void hpgs_bbox_null (hpgs_bbox *bb); +HPGS_API void hpgs_bbox_expand (hpgs_bbox *bb1, const hpgs_bbox *bb2); +HPGS_API void hpgs_bbox_intersect (hpgs_bbox *bb1, const hpgs_bbox *bb2); +/*! Expands the bounding box \c bb in all directions by the amount of \c border. */ +static void hpgs_bbox_addborder (hpgs_bbox *bb, double border); +/*! Expands the bounding box \c bb in order to comprise the smallest bounding box + containing both \c bb and \cp. */ +static void hpgs_bbox_add (hpgs_bbox *bb, const hpgs_point *p); + +__inline__ void hpgs_bbox_addborder (hpgs_bbox *bb, double border) +{ + bb->llx -= border; + bb->urx += border; + bb->lly -= border; + bb->ury += border; +} + +__inline__ void hpgs_bbox_add (hpgs_bbox *bb, const hpgs_point *p) +{ + if (p->x < bb->llx) bb->llx = p->x; + if (p->x > bb->urx) bb->urx = p->x; + if (p->y < bb->lly) bb->lly = p->y; + if (p->y > bb->ury) bb->ury = p->y; +} + +typedef struct hpgs_matrix_st hpgs_matrix; + +/*! \brief A transformation matrix for 2D points. + + This structure holds an affine transformation matrix consisting of a + translation vector and a 2x2 matrix for rotation and or scaling. + */ +struct hpgs_matrix_st +{ + double dx; + double dy; + double mxx; + double mxy; + double myx; + double myy; +}; + +HPGS_API void hpgs_matrix_set_identity(hpgs_matrix *m); + +HPGS_API void hpgs_matrix_xform(hpgs_point *res, + const hpgs_matrix *m, const hpgs_point *p); +HPGS_API void hpgs_matrix_ixform(hpgs_point *res, + const hpgs_point *p, const hpgs_matrix *m); +HPGS_API void hpgs_matrix_scale(hpgs_point *res, + const hpgs_matrix *m, const hpgs_point *p); +HPGS_API void hpgs_matrix_iscale(hpgs_point *res, + const hpgs_point *p, const hpgs_matrix *m); +HPGS_API void hpgs_matrix_concat(hpgs_matrix *res, + const hpgs_matrix *a, const hpgs_matrix *b); +HPGS_API void hpgs_matrix_invert(hpgs_matrix *res, const hpgs_matrix *m); + +HPGS_API void hpgs_matrix_xform_bbox(hpgs_bbox *res, + const hpgs_matrix *m, const hpgs_bbox *bb); +HPGS_API void hpgs_matrix_ixform_bbox(hpgs_bbox *res, + const hpgs_bbox *bb, const hpgs_matrix *m); + +/*! Defines the supported line cap styles. */ +typedef enum { + hpgs_cap_butt = 0, //!< Butt line cap. + hpgs_cap_round = 1, //!< Round line cap. + hpgs_cap_square = 2 //!< Square line cap. +} hpgs_line_cap; + +/*! Defines the supported line join styles. */ +typedef enum { + hpgs_join_miter = 0, //!< Miter line join. + hpgs_join_round = 1, //!< Round line join. + hpgs_join_bevel = 2 //!< Bevel line join. +} hpgs_line_join; + +// input stream +typedef struct hpgs_istream_st hpgs_istream; +typedef struct hpgs_istream_vtable_st hpgs_istream_vtable; + +typedef int (*hpgs_istream_getc_func_t)(void *); +typedef int (*hpgs_istream_ungetc_func_t)(int ,void *); +typedef int (*hpgs_istream_close_func_t)(void *); +typedef int (*hpgs_istream_iseof_func_t)(void *); +typedef int (*hpgs_istream_iserror_func_t)(void *); +typedef int (*hpgs_istream_seek_func_t)(void *, size_t); +typedef int (*hpgs_istream_tell_func_t)(void *, size_t*); +typedef size_t (*hpgs_istream_read_func_t)(void *, size_t, size_t, void *); +typedef int (*hpgs_istream_seekend_func_t)(void *, size_t); + +/*! \brief A table of virtual function implementing \c hpgs_istream. + + This structure has a public alias \c hpgs_istream_vtable and + represents a table of functions for a specific implementation + of \c hpgs_istream. + + The function names are deliberately similar to the corresponding + ANSI C functions. + */ +struct hpgs_istream_vtable_st +{ + hpgs_istream_getc_func_t getc_func; + hpgs_istream_ungetc_func_t ungetc_func; + hpgs_istream_close_func_t close_func; + hpgs_istream_iseof_func_t iseof_func; + hpgs_istream_iserror_func_t iserror_func; + hpgs_istream_seek_func_t seek_func; + hpgs_istream_tell_func_t tell_func; + hpgs_istream_read_func_t read_func; + hpgs_istream_seekend_func_t seekend_func; +}; + +/*! \brief A virtual input stream for the HPGL reader. + + This structure has a public alias \c hpgs_istream and + represents an abstract input stream consisting of + a stream pointer and a pointer to a table of virtual functions + implementing the stream. + */ +struct hpgs_istream_st +{ + hpgs_istream_vtable *vtable; + + void *stream; +}; + +HPGS_API hpgs_istream *hpgs_new_file_istream (const char *fn); +HPGS_API hpgs_istream *hpgs_new_mem_istream (const unsigned char *data, + size_t data_size, + hpgs_bool dup); + + +/*! The counterpart of ANSI getc for \c hpgs_istream. */ +static int hpgs_getc (hpgs_istream *_this); +/*! The counterpart of ANSI ungetc for \c hpgs_istream. */ +static int hpgs_ungetc (int c, hpgs_istream *_this); +/*! The counterpart of ANSI fclose for \c hpgs_istream. + After calling this function, all allocated resources of the stream are freed. */ +static int hpgs_istream_close (hpgs_istream *_this); +/*! The counterpart of ANSI feof for \c hpgs_istream. */ +static int hpgs_istream_iseof (hpgs_istream *_this); +/*! The counterpart of ANSI ferror for \c hpgs_istream. */ +static int hpgs_istream_iserror(hpgs_istream *_this); +/*! The counterpart of ANSI fseek for \c hpgs_istream. */ +static int hpgs_istream_seek (hpgs_istream *_this, size_t pos); +/*! The counterpart of ANSI fseek(SEEK_END) for \c hpgs_istream. */ +static int hpgs_istream_seekend (hpgs_istream *_this, size_t pos); +/*! The counterpart of ANSI ftell for \c hpgs_istream. */ +static int hpgs_istream_tell (hpgs_istream *_this, size_t *pos); +/*! The counterpart of ANSI fread for \c hpgs_istream. */ +static size_t hpgs_istream_read (void *ptr, size_t size, size_t nmemb, hpgs_istream *_this); + +__inline__ int hpgs_getc (hpgs_istream *_this) +{ return _this->vtable->getc_func(_this->stream); } + +__inline__ int hpgs_ungetc (int c, hpgs_istream *_this) +{ return _this->vtable->ungetc_func(c,_this->stream); } + +__inline__ int hpgs_istream_close (hpgs_istream *_this) +{ int ret = _this->vtable->close_func(_this->stream); free(_this); return ret; } + +__inline__ int hpgs_istream_iseof (hpgs_istream *_this) +{ return _this->vtable->iseof_func(_this->stream); } + +__inline__ int hpgs_istream_iserror (hpgs_istream *_this) +{ return _this->vtable->iserror_func(_this->stream); } + +__inline__ int hpgs_istream_seek (hpgs_istream *_this, size_t pos) +{ return _this->vtable->seek_func(_this->stream,pos); } + +__inline__ int hpgs_istream_seekend (hpgs_istream *_this, size_t pos) +{ return _this->vtable->seekend_func(_this->stream,pos); } + +__inline__ int hpgs_istream_tell (hpgs_istream *_this, size_t *pos) +{ return _this->vtable->tell_func(_this->stream,pos); } + +__inline__ size_t hpgs_istream_read (void *ptr, size_t size, size_t nmemb, hpgs_istream *_this) +{ return _this->vtable->read_func(ptr,size,nmemb,_this->stream); } + +// output stream +typedef struct hpgs_ostream_st hpgs_ostream; +typedef struct hpgs_ostream_vtable_st hpgs_ostream_vtable; + +typedef int (*hpgs_ostream_putc_func_t)(int, void *); +typedef size_t (*hpgs_ostream_write_func_t)(const void *, size_t, size_t, void *); +typedef int (*hpgs_ostream_vprintf_func_t)(void *, const char *, va_list); +typedef int (*hpgs_ostream_flush_func_t)(void *); +typedef int (*hpgs_ostream_close_func_t)(void *); +typedef int (*hpgs_ostream_iserror_func_t)(void *); +typedef hpgs_istream *(*hpgs_ostream_getbuf_func_t)(void *); +typedef int (*hpgs_ostream_tell_func_t)(void *, int layer, size_t *); +typedef int (*hpgs_ostream_seek_func_t)(void *, size_t); + +/*! \brief A table of virtual function implementing \c hpgs_istream. + + This structure has a public alias \c hpgs_istream_vtable and + represents a table of functions for a specific implementation + of \c hpgs_istream. + + The function names are deliberately similar to the corresponding + ANSI C functions. + */ +struct hpgs_ostream_vtable_st +{ + hpgs_ostream_putc_func_t putc_func; + hpgs_ostream_write_func_t write_func; + hpgs_ostream_vprintf_func_t vprintf_func; + hpgs_ostream_flush_func_t flush_func; + hpgs_ostream_close_func_t close_func; + hpgs_ostream_iserror_func_t iserror_func; + hpgs_ostream_getbuf_func_t getbuf_func; + hpgs_ostream_tell_func_t tell_func; + hpgs_ostream_seek_func_t seek_func; +}; + +/*! \brief A virtual output stream for the HPGL reader. + + This structure has a public alias \c hpgs_ostream and + represents an abstract onput stream consisting of + a stream pointer and a pointer to a table of virtual functions + implementing the stream. + */ +struct hpgs_ostream_st +{ + hpgs_ostream_vtable *vtable; + + void *stream; +}; + +HPGS_API hpgs_ostream *hpgs_new_file_ostream (const char *fn); +HPGS_API hpgs_ostream *hpgs_new_mem_ostream (size_t data_reserve); +HPGS_API hpgs_ostream *hpgs_new_z_ostream (hpgs_ostream *base, int compression, hpgs_bool take_base); + +HPGS_API int hpgs_copy_streams (hpgs_ostream *out, hpgs_istream *in); + +HPGS_PRINTF2_API int hpgs_ostream_printf (hpgs_ostream *_this, const char *msg, ...); +HPGS_API int hpgs_ostream_vprintf (hpgs_ostream *_this, const char *msg, va_list ap); + +/*! The counterpart of ANSI putc for \c hpgs_ostream. */ +static int hpgs_ostream_putc (int c, hpgs_ostream *_this); +/*! The counterpart of ANSI fwrite for \c hpgs_ostream. */ +static size_t hpgs_ostream_write (const void *ptr, size_t size, size_t nmemb, hpgs_ostream *_this); +/*! The counterpart of ANSI fflush for \c hpgs_ostream. */ +static int hpgs_ostream_flush (hpgs_ostream *_this); +/*! The counterpart of ANSI fclose for \c hpgs_ostream. + After calling this function, all allocated resources of the stream are freed. */ +static int hpgs_ostream_close (hpgs_ostream *_this); +/*! The counterpart of ANSI ferror for \c hpgs_ostream. */ +static int hpgs_ostream_iserror(hpgs_ostream *_this); +/*! Get the buffer of a \c hpgs_ostream. This function should only be called + after \c hpgs_ostream_flush. */ +static hpgs_istream *hpgs_ostream_getbuf(hpgs_ostream *_this); +/*! The counterpart of ANSI ftell for \c hpgs_ostream. */ +static int hpgs_ostream_tell(hpgs_ostream *_this, int layer, size_t *pos); +/*! The counterpart of ANSI fseek for \c hpgs_ostream. */ +static int hpgs_ostream_seek (hpgs_ostream *_this, size_t pos); + +__inline__ int hpgs_ostream_putc (int c, hpgs_ostream *_this) +{ return _this->vtable->putc_func(c,_this->stream); } + +__inline__ size_t hpgs_ostream_write (const void *ptr, size_t size, size_t nmemb, hpgs_ostream *_this) +{ return _this->vtable->write_func(ptr,size,nmemb,_this->stream); } + +__inline__ int hpgs_ostream_flush (hpgs_ostream *_this) +{ return _this->vtable->flush_func ? _this->vtable->flush_func(_this->stream) : 0; } + +__inline__ int hpgs_ostream_close (hpgs_ostream *_this) +{ int ret = _this->vtable->close_func(_this->stream); free(_this); return ret; } + +__inline__ int hpgs_ostream_iserror (hpgs_ostream *_this) +{ return _this->vtable->iserror_func(_this->stream); } + +__inline__ hpgs_istream *hpgs_ostream_getbuf (hpgs_ostream *_this) +{ return _this->vtable->getbuf_func ? _this->vtable->getbuf_func(_this->stream) : 0; } + +__inline__ int hpgs_ostream_tell(hpgs_ostream *_this, int layer, size_t *pos) +{ return _this->vtable->tell_func ? _this->vtable->tell_func(_this->stream,layer,pos) : -1; } + +__inline__ int hpgs_ostream_seek (hpgs_ostream *_this, size_t pos) +{ return _this->vtable->seek_func ? _this->vtable->seek_func(_this->stream,pos) : -1; } + +HPGS_API int hpgs_parse_papersize(const char *str, double *pt_width, double *pt_height); +HPGS_API int hpgs_parse_length(const char *str, double *pt_length); + +/*! @} */ /* end of group base */ + +/*! @addtogroup device + * @{ + */ +typedef struct hpgs_device_st hpgs_device; +typedef struct hpgs_plotsize_device_st hpgs_plotsize_device; +typedef struct hpgs_eps_device_st hpgs_eps_device; +typedef struct hpgs_gs_device_st hpgs_gs_device; +typedef struct hpgs_device_vtable_st hpgs_device_vtable; +typedef struct hpgs_image_st hpgs_image; +typedef struct hpgs_image_vtable_st hpgs_image_vtable; +typedef struct hpgs_png_image_st hpgs_png_image; +typedef struct hpgs_paint_device_st hpgs_paint_device; +typedef struct hpgs_gstate_st hpgs_gstate; +typedef struct hpgs_font_st hpgs_font; + +/*! \brief The vector graphics state. + + This structure has a public alias \c hpgs_gstate and holds + the line attributes of a graphics state. + */ +struct hpgs_gstate_st +{ + hpgs_line_cap line_cap; + hpgs_line_join line_join; + hpgs_color color; + double miterlimit; + double linewidth; + + int rop3; + hpgs_bool src_transparency; + hpgs_bool pattern_transparency; + + hpgs_color pattern_color; + + int n_dashes; + float *dash_lengths; + double dash_offset; +}; + +HPGS_API hpgs_gstate *hpgs_new_gstate(void); +HPGS_API void hpgs_gstate_destroy(hpgs_gstate *gstate); +HPGS_API int hpgs_gstate_setdash(hpgs_gstate *gstate, + const float *, unsigned, double); + + +#define HPGS_DEVICE_CAP_RASTER (1<<0) //!< This device is a raster device. +#define HPGS_DEVICE_CAP_ANTIALIAS (1<<1) //!< This device supports anitaliasing. +#define HPGS_DEVICE_CAP_VECTOR (1<<2) //!< This device is a true vector device. +#define HPGS_DEVICE_CAP_MULTIPAGE (1<<3) //!< This device supports multiple pages. +#define HPGS_DEVICE_CAP_PAGECOLLATION (1<<4) //!< This device is able to write multiple pages to a single file. +#define HPGS_DEVICE_CAP_MULTISIZE (1<<5) //!< This device is able to cope with distinct sizes per page. +#define HPGS_DEVICE_CAP_DRAWIMAGE (1<<6) //!< The device may draw an image. +#define HPGS_DEVICE_CAP_NULLIMAGE (1<<7) //!< The device accepts a null image in drawimage. +#define HPGS_DEVICE_CAP_PLOTSIZE (1<<8) //!< This device is a plotsize device. +#define HPGS_DEVICE_CAP_ROP3 (1<<9) //!< This device supports rop3 operations. + +/*! \brief A table of virtual function implementing \c hpgs_device. + + This structure has a public alias \c hpgs_device_vtable and + represents a table of functions for a specific implementation + of \c hpgs_device. + + The function names are deliberately similar to the corresponding + functions of the PostScript programming language. + */ +struct hpgs_device_vtable_st { + const char * rtti; + int (*moveto) (hpgs_device *_this, const hpgs_point *p); + int (*lineto) (hpgs_device *_this, const hpgs_point *p); + int (*curveto) (hpgs_device *_this, const hpgs_point *p1, + const hpgs_point *p2, const hpgs_point *p3 ); + int (*newpath) (hpgs_device *_this); + int (*closepath) (hpgs_device *_this); + int (*stroke) (hpgs_device *_this); + int (*fill) (hpgs_device *_this, hpgs_bool winding); + int (*clip) (hpgs_device *_this, hpgs_bool winding); + int (*clipsave) (hpgs_device *_this); + int (*cliprestore) (hpgs_device *_this); + int (*setrgbcolor) (hpgs_device *_this, const hpgs_color *rgb); + int (*setdash) (hpgs_device *_this, const float *, unsigned, double); + int (*setlinewidth)(hpgs_device *_this, double); + int (*setlinecap) (hpgs_device *_this, hpgs_line_cap); + int (*setlinejoin) (hpgs_device *_this, hpgs_line_join); + int (*setmiterlimit) (hpgs_device *_this, double l); + int (*setrop3) (hpgs_device *_this, int rop, + hpgs_bool src_transparency, hpgs_bool pattern_transparency); + int (*setpatcol) (hpgs_device *_this, const hpgs_color *rgb); + int (*drawimage) (hpgs_device *_this, const hpgs_image *img, + const hpgs_point *ll, const hpgs_point *lr, + const hpgs_point *ur); + int (*setplotsize) (hpgs_device *_this, const hpgs_bbox *bb); + int (*getplotsize) (hpgs_device *_this, int i, hpgs_bbox *bb); + int (*showpage) (hpgs_device *_this, int i); + int (*finish) (hpgs_device *_this); + int (*capabilities)(hpgs_device *_this); + void (*destroy) (hpgs_device *_this); +}; + +/*! \brief A virtual vector graphics device for the HPGL reader. + + This structure has a public alias \c hpgs_device and + represents an abstract vector drawing device consisting of + a pointer to a table of virtual functions + implementing the device. + + */ +struct hpgs_device_st { + hpgs_device_vtable *vtable; +}; + +#define HPGS_BASE_CLASS(d) (&(d->inherited)) + +HPGS_API hpgs_plotsize_device *hpgs_new_plotsize_device(hpgs_bool ignore_ps, + hpgs_bool do_linewidth); + +HPGS_API hpgs_eps_device *hpgs_new_eps_device(const char *filename, + const hpgs_bbox *bb, + hpgs_bool do_rop3 ); + +HPGS_API hpgs_eps_device *hpgs_new_ps_device(const char *filename, + const hpgs_bbox *bb, + hpgs_bool do_rop3); + +typedef int (*hpgs_reader_asset_func_t)(void *, hpgs_device *, + const hpgs_matrix *, + const hpgs_matrix *, + const hpgs_bbox *, int); + +HPGS_API int hpgs_new_plugin_device( hpgs_device **device, + void **page_asset_ctxt, + hpgs_reader_asset_func_t *page_asset_func, + void **frame_asset_ctxt, + hpgs_reader_asset_func_t *frame_asset_func, + const char *dev_name, + const char *filename, + const hpgs_bbox *bb, + double xres, double yres, + hpgs_bool do_rop3, + int argc, const char *argv[]); + +HPGS_API const char *hpgs_device_rtti(hpgs_device *_this); + +/*! PostScript moveto on the device. */ +static int hpgs_moveto (hpgs_device *_this, const hpgs_point *p); +/*! PostScript lineto on the device. */ +static int hpgs_lineto (hpgs_device *_this, const hpgs_point *p); +/*! PostScript curveto on the device. */ +static int hpgs_curveto (hpgs_device *_this, const hpgs_point *p1, + const hpgs_point *p2, const hpgs_point *p3 ); +/*! PostScript closepath on the device. */ +static int hpgs_closepath (hpgs_device *_this); +/*! PostScript newpath on the device. */ +static int hpgs_newpath (hpgs_device *_this); +/*! PostScript stroke on the device. */ +static int hpgs_stroke (hpgs_device *_this); +/*! PostScript fill/eofill on the device. + If \c winding is \c HPGS_TRUE we issue \c fill, otherwise \c eofill. */ +static int hpgs_fill (hpgs_device *_this, hpgs_bool winding); +/*! PostScript clip/eoclip on the device. + If \c winding is \c HPGS_TRUE we issue \c clip, otherwise \c eoclip. */ +static int hpgs_clip (hpgs_device *_this, hpgs_bool winding); +/*! Save the clip state onto the clip stack. Unlike PostScripts \c gsave + the line attributes and colors of the graphics state are not saved. */ +static int hpgs_clipsave (hpgs_device *_this); +/*! Restores the last clip state from the clip stack. */ +static int hpgs_cliprestore (hpgs_device *_this); +/*! PostScript setrgbcolor on the device. */ +static int hpgs_setrgbcolor (hpgs_device *_this, const hpgs_color *rgb); +/*! PostScript setdash on the device. */ +static int hpgs_setdash (hpgs_device *_this, const float *d, + unsigned nd, double s); +/*! PostScript setlinewidth on the device. */ +static int hpgs_setlinewidth(hpgs_device *_this, double w); +/*! PostScript setlinecap on the device. */ +static int hpgs_setlinecap (hpgs_device *_this, hpgs_line_cap c); +/*! PostScript setlinejoin on the device. */ +static int hpgs_setlinejoin (hpgs_device *_this, hpgs_line_join j); +/*! PostScript setmiterlimit on the device. */ +static int hpgs_setmiterlimit (hpgs_device *_this, double l); +/*! Get the device capabilities. */ +static int hpgs_device_capabilities (hpgs_device *_this); + +HPGS_API int hpgs_setrop3 (hpgs_device *_this, int rop, + hpgs_bool src_transparency, hpgs_bool pattern_transparency); +HPGS_API int hpgs_setpatcol (hpgs_device *_this, const hpgs_color *rgb); + +HPGS_API int hpgs_drawimage(hpgs_device *_this, const hpgs_image *img, + const hpgs_point *ll, const hpgs_point *lr, + const hpgs_point *ur); + +HPGS_API int hpgs_setplotsize (hpgs_device *_this, const hpgs_bbox *bb); +HPGS_API int hpgs_getplotsize (hpgs_device *_this, int i, hpgs_bbox *bb); +HPGS_API int hpgs_showpage (hpgs_device *_this, int i); +HPGS_API int hpgs_device_finish (hpgs_device *_this); +HPGS_API void hpgs_device_destroy (hpgs_device *_this); + +__inline__ int hpgs_moveto (hpgs_device *_this, const hpgs_point *p) +{ return _this->vtable->moveto(_this,p); } + +__inline__ int hpgs_lineto (hpgs_device *_this, const hpgs_point *p) +{ return _this->vtable->lineto(_this,p); } + +__inline__ int hpgs_curveto (hpgs_device *_this, const hpgs_point *p1, + const hpgs_point *p2, const hpgs_point *p3 ) +{ return _this->vtable->curveto(_this,p1,p2,p3); } + +__inline__ int hpgs_closepath (hpgs_device *_this) +{ return _this->vtable->closepath(_this); } + +__inline__ int hpgs_newpath (hpgs_device *_this) +{ return _this->vtable->newpath(_this); } + +__inline__ int hpgs_stroke (hpgs_device *_this) +{ return _this->vtable->stroke(_this); } + +__inline__ int hpgs_fill (hpgs_device *_this, hpgs_bool winding) +{ return _this->vtable->fill(_this,winding); } + +__inline__ int hpgs_clip (hpgs_device *_this, hpgs_bool winding) +{ return _this->vtable->clip(_this,winding); } + +__inline__ int hpgs_clipsave (hpgs_device *_this) +{ return _this->vtable->clipsave(_this); } + +__inline__ int hpgs_cliprestore (hpgs_device *_this) +{ return _this->vtable->cliprestore(_this); } + +__inline__ int hpgs_setrgbcolor (hpgs_device *_this, const hpgs_color *rgb) +{ return _this->vtable->setrgbcolor ? _this->vtable->setrgbcolor(_this,rgb) : 0; } + +__inline__ int hpgs_setdash (hpgs_device *_this, const float *d, + unsigned nd, double s) +{ return _this->vtable->setdash ? _this->vtable->setdash(_this,d,nd,s) : 0; } + +__inline__ int hpgs_setlinewidth(hpgs_device *_this, double w) +{ return _this->vtable->setlinewidth ? _this->vtable->setlinewidth(_this,w) : 0; } + +__inline__ int hpgs_setlinecap (hpgs_device *_this, hpgs_line_cap c) +{ return _this->vtable->setlinecap ? _this->vtable->setlinecap(_this,c) : 0; } + +__inline__ int hpgs_setlinejoin (hpgs_device *_this, hpgs_line_join j) +{ return _this->vtable->setlinejoin ? _this->vtable->setlinejoin(_this,j) : 0; } + +__inline__ int hpgs_setmiterlimit (hpgs_device *_this, double l) +{ return _this->vtable->setmiterlimit ? _this->vtable->setmiterlimit(_this,l) : 0; } + +__inline__ int hpgs_device_capabilities (hpgs_device *_this) +{ return _this->vtable->capabilities(_this); } + +/*! @} */ /* end of group device */ + +/*! @addtogroup reader + * @{ + */ +typedef struct hpgs_reader_st hpgs_reader; + +HPGS_API hpgs_reader *hpgs_new_reader(hpgs_istream *in, hpgs_device *dev, + hpgs_bool multipage, int v); + +HPGS_API void hpgs_reader_set_lw_factor(hpgs_reader *reader, double lw_factor); + +HPGS_API void hpgs_reader_set_fixed_page(hpgs_reader *reader, + hpgs_bbox *bbox, + double page_width, + double page_height, + double border, + double angle ); + +HPGS_API void hpgs_reader_set_dynamic_page(hpgs_reader *reader, + hpgs_bbox *bbox, + double max_page_width, + double max_page_height, + double border, + double angle ); + +HPGS_API void hpgs_reader_set_page_asset_func(hpgs_reader *reader, + void * ctxt, + hpgs_reader_asset_func_t func); + +HPGS_API void hpgs_reader_set_frame_asset_func(hpgs_reader *reader, + void * ctxt, + hpgs_reader_asset_func_t func); + +HPGS_API void hpgs_reader_interrupt(hpgs_reader *reader); +HPGS_API int hpgs_reader_get_current_pen(hpgs_reader *reader); + +HPGS_API int hpgs_reader_imbue(hpgs_reader *reader, hpgs_device *dev); +HPGS_API int hpgs_reader_attach(hpgs_reader *reader, hpgs_istream *in); +HPGS_API int hpgs_reader_stamp(hpgs_reader *reader, + const hpgs_bbox *bb, + const char *stamp, const char *encoding, + double stamp_size); + +HPGS_API int hpgs_device_stamp(hpgs_device *dev, + const hpgs_bbox *bb, + const char *stamp, const char *encoding, + double stamp_size); + +HPGS_API int hpgs_reader_set_png_dump(hpgs_reader *reader, const char *filename); +HPGS_API int hpgs_read(hpgs_reader *reader, hpgs_bool finish); +HPGS_API void hpgs_destroy_reader(hpgs_reader *reader); + +/*! @} */ /* end of group reader */ + +/*! @addtogroup font + * @{ + */ + +HPGS_API hpgs_font *hpgs_find_font(const char *name); +HPGS_API void hpgs_destroy_font(hpgs_font *font); +HPGS_API double hpgs_font_get_ascent(hpgs_font *font); +HPGS_API double hpgs_font_get_descent(hpgs_font *font); +HPGS_API double hpgs_font_get_line_gap(hpgs_font *font); +HPGS_API double hpgs_font_get_cap_height(hpgs_font *font); +HPGS_API unsigned hpgs_font_get_glyph_count(hpgs_font *font); +HPGS_API unsigned hpgs_font_get_glyph_id(hpgs_font *font, int uc); +HPGS_API const char *hpgs_font_get_glyph_name(hpgs_font *font, unsigned gid); +HPGS_API int hpgs_font_get_glyph_bbox(hpgs_font *font, hpgs_bbox *bb, unsigned gid); +HPGS_API int hpgs_font_get_glyph_metrics(hpgs_font *font, hpgs_point *m, unsigned gid); +HPGS_API int hpgs_font_get_kern_metrics(hpgs_font *font, hpgs_point *m, unsigned gid_l, unsigned gid_r); +HPGS_API int hpgs_font_get_utf8_metrics(hpgs_font *font, hpgs_point *m, const char *str, int strlen); + +typedef int (*hpgs_moveto_func_t) (void *ctxt, const hpgs_point *p); +typedef int (*hpgs_lineto_func_t) (void *ctxt, const hpgs_point *p); +typedef int (*hpgs_curveto_func_t) (void *ctxt, const hpgs_point *p1, const hpgs_point *p2, const hpgs_point *p3); +typedef int (*hpgs_fill_func_t) (void *ctxt, hpgs_bool winding); + +HPGS_API int hpgs_font_decompose_glyph(hpgs_font *font, + void *ctxt, + hpgs_moveto_func_t moveto_func, + hpgs_lineto_func_t lineto_func, + hpgs_curveto_func_t curveto_func, + const hpgs_matrix *m, + unsigned gid); + +HPGS_API int hpgs_font_draw_glyph(hpgs_font *font, + hpgs_device *device, + const hpgs_matrix *m, + unsigned gid); + +HPGS_API int hpgs_font_decompose_utf8(hpgs_font *font, + void *ctxt, + hpgs_moveto_func_t moveto_func, + hpgs_lineto_func_t lineto_func, + hpgs_curveto_func_t curveto_func, + hpgs_fill_func_t fill_func, + const hpgs_matrix *m, + const char *str, int strlen); + +HPGS_API int hpgs_font_draw_utf8(hpgs_font *font, + hpgs_device *device, + const hpgs_matrix *m, + const char *str, int strlen); + +/*! @} */ /* end of group font */ + +/*! @addtogroup image + * @{ + */ + +/*! \brief A table of virtual function implementing \c hpgs_image. + + This structure has a public alias \c hpgs_image_vtable and + represents a table of functions for a specific implementation + of \c hpgs_image. + */ +struct hpgs_image_vtable_st { + int (*get_pixel) (const hpgs_image *_this, + int x, int y, hpgs_paint_color *c, double *alpha); + int (*put_pixel) (hpgs_image *_this, + int x, int y, const hpgs_paint_color *c, double alpha); + int (*put_chunk) (hpgs_image *_this, + int x1, int x2, int y, const hpgs_paint_color *c); + int (*rop3_pixel) (hpgs_image *_this, + int x, int y, const hpgs_paint_color *c, double alpha); + int (*rop3_chunk) (hpgs_image *_this, + int x1, int x2, int y, const hpgs_paint_color *c); + int (*setrop3) (hpgs_image *_this, hpgs_rop3_func_t rop3); + int (*setpatcol) (hpgs_image *_this, const hpgs_palette_color *p); + int (*resize) (hpgs_image *_this, int w, int h); + int (*set_resolution)(hpgs_image *pim, double x_dpi, double y_dpi); + int (*clear) (hpgs_image *_this); + int (*write) (hpgs_image *_this, const char *filename); + int (*get_data) (hpgs_image *_this, unsigned char **data, int *stride, int *depth); + void (*destroy) (hpgs_image *_this); +}; + +/*! \brief An abstract pixel image. + + This structure has a public alias \c hpgs_image and + represents a rectangular pixel container, which tradiationally + is called an image. + + Nevertheless, implementations for drawing to a window system + may be provided in the future. + */ +struct hpgs_image_st { + hpgs_image_vtable *vtable; //!< The virtual table. + int width; //!< The number of pixel columns. + int height; //!< The number of pixel rows. + + hpgs_palette_color *palette; //!< The palette for indexed images. + unsigned *palette_idx; //!< a compacted rgb color index. + int palette_ncolors; //!< The number of colors in the palette. +}; + +HPGS_API int hpgs_image_define_color_func (hpgs_image *image, hpgs_paint_color *c); + +static int hpgs_image_define_color (hpgs_image *image, hpgs_paint_color *c); + +/*! Enter the supplied rgb value to the palette of an indexed image. + Set the index member of \c c to the palette index of the + RGB triplet. + + If the palette is exhausted, -1 is returned. + */ +__inline__ int hpgs_image_define_color (hpgs_image *image, hpgs_paint_color *c) +{ + if (image->palette) return hpgs_image_define_color_func (image,c); else return 0; +} + +HPGS_API int hpgs_image_set_palette (hpgs_image *image, + hpgs_palette_color *p, int np); + +HPGS_API hpgs_png_image *hpgs_new_png_image(int width, int height, + int depth, hpgs_bool palette, + hpgs_bool do_rop3); + +HPGS_API int hpgs_png_image_set_compression(hpgs_png_image *pim, int compression); + +HPGS_API int hpgs_image_set_resolution(hpgs_image *pim, double x_dpi, double y_dpi); + +HPGS_API int hpgs_image_get_data(hpgs_image *_this, + unsigned char **data, int *stride, + int *depth); + +/*! Retrieves the color and alpha value of the pixel + in column \c x and row \c y. */ +static int hpgs_image_get_pixel (const hpgs_image *_this, + int x, int y, + hpgs_paint_color *c, double *alpha); +/*! Sets the color and alpha value of the pixel + in column \c x and row \c y. */ +static int hpgs_image_put_pixel (hpgs_image *_this, + int x, int y, + const hpgs_paint_color *c, double alpha); +/*! Sets the color of all pixels + in the columns \c x1 up to \c x2 in row \c y. + The alpha value is set to 1. */ +static int hpgs_image_put_chunk (hpgs_image *_this, + int x1, int x2, int y, const hpgs_paint_color *c); + +/*! Sets the color and alpha value of the pixel + in column \c x and row \c y. This function applies a ROP3 + operation, if supported by the image. + */ +static int hpgs_image_rop3_pixel (hpgs_image *_this, + int x, int y, + const hpgs_paint_color *c, double alpha); +/*! Sets the color of all pixels + in the columns \c x1 up to \c x2 in row \c y. + The alpha value is set to 1. This function applies a ROP3 + operation, if supported by the image. + */ +static int hpgs_image_rop3_chunk (hpgs_image *_this, + int x1, int x2, int y, const hpgs_paint_color *c); + +HPGS_API int hpgs_image_resize (hpgs_image *_this, int w, int h); +HPGS_API int hpgs_image_clear (hpgs_image *_this); +HPGS_API int hpgs_image_write (hpgs_image *_this, const char *filename); +HPGS_API int hpgs_image_setrop3 (hpgs_image *_this, hpgs_rop3_func_t rop3); +HPGS_API int hpgs_image_setpatcol (hpgs_image *_this, const hpgs_palette_color *p); + +HPGS_API void hpgs_image_destroy (hpgs_image *_this); + +__inline__ int hpgs_image_get_pixel (const hpgs_image *_this, + int x, int y, + hpgs_paint_color *c, double *alpha) +{ return _this->vtable->get_pixel(_this,x,y,c,alpha); } + +__inline__ int hpgs_image_put_pixel (hpgs_image *_this, + int x, int y, + const hpgs_paint_color *c, double alpha) +{ return _this->vtable->put_pixel(_this,x,y,c,alpha); } + +__inline__ int hpgs_image_put_chunk (hpgs_image *_this, + int x1, int x2, int y, const hpgs_paint_color *c) +{ return _this->vtable->put_chunk(_this,x1,x2,y,c); } + +__inline__ int hpgs_image_rop3_pixel (hpgs_image *_this, + int x, int y, + const hpgs_paint_color *c, double alpha) +{ return _this->vtable->rop3_pixel(_this,x,y,c,alpha); } + +__inline__ int hpgs_image_rop3_chunk (hpgs_image *_this, + int x1, int x2, int y, const hpgs_paint_color *c) +{ return _this->vtable->rop3_chunk(_this,x1,x2,y,c); } + +HPGS_API int hpgs_image_rop3_clip(hpgs_device *device, + hpgs_palette_color *data, + const hpgs_image *img, + const hpgs_point *ll, const hpgs_point *lr, + const hpgs_point *ur, + const hpgs_palette_color *p, + hpgs_xrop3_func_t xrop3); + +/*! @} */ /* end of group image */ + +/*! @addtogroup path + * @{ + */ + +typedef struct hpgs_path_point_st hpgs_path_point; +typedef struct hpgs_paint_path_st hpgs_paint_path; + +#define HPGS_POINT_ROLE_MASK 0xF //!< A mask for retrieving the role of a point in the path +#define HPGS_POINT_UNDEFINED 0x0 //!< point is undefined +#define HPGS_POINT_LINE 0x1 //!< start of line +#define HPGS_POINT_BEZIER 0x2 //!< start of bezier curve +#define HPGS_POINT_CONTROL 0x3 //!< bezier control point +#define HPGS_POINT_FILL_LINE 0x4 //!< line fill only (implicit closepath) +#define HPGS_POINT_DOT 0x8 //!< indicates a moveto/lineto with the same coordinates at the start of a subpath. + +#define HPGS_POINT_SUBPATH_START 0x10 //!< a subpath starts at this point +#define HPGS_POINT_SUBPATH_END 0x20 //!< a subpath ends at this point +#define HPGS_POINT_SUBPATH_CLOSE 0x40 //!< indicates an explicit closepath at the end of a subpath + +/*! \brief A point in a stored path. + + This structure has a public alias \c hpgs_path_point and + represents a point of a polygonal path. + */ +struct hpgs_path_point_st +{ + hpgs_point p; /*!< Coordinates of this path point. */ + int flags; /*!< Flags for this path point. */ +}; + +/*! \brief A stored vector path. + + This structure has a public alias \c hpgs_paint_path and + represents a polygonal path, which is stores the path topology + together with cached informations about bezier splines. + */ +struct hpgs_paint_path_st +{ + /*@{ */ + /*! A stack of path points. + \c last_start indicates the index of the last start of a subpolygon. + This is information is needed during path construction. + */ + hpgs_path_point *points; + int n_points; + int last_start; + int points_malloc_size; + /*@} */ + + hpgs_bbox bb; /*! The bounding box of this path. */ +}; + +HPGS_API hpgs_paint_path *hpgs_new_paint_path(void); +HPGS_API void hpgs_paint_path_destroy(hpgs_paint_path *_this); +HPGS_API void hpgs_paint_path_truncate(hpgs_paint_path *_this); + +HPGS_API int hpgs_paint_path_moveto(hpgs_paint_path *_this, + const hpgs_point *p ); + +HPGS_API int hpgs_paint_path_lineto(hpgs_paint_path *_this, + const hpgs_point *p ); + +HPGS_API int hpgs_paint_path_curveto(hpgs_paint_path *_this, + const hpgs_point *p1, + const hpgs_point *p2, + const hpgs_point *p3 ); + +HPGS_API int hpgs_paint_path_closepath(hpgs_paint_path *_this); + +HPGS_API int hpgs_paint_path_buldgeto(hpgs_paint_path *_this, + const hpgs_point *p, + double buldge); + +HPGS_API hpgs_paint_path *hpgs_paint_path_stroke_path(const hpgs_paint_path *_this, + const hpgs_gstate *gstate); + +HPGS_API hpgs_paint_path *hpgs_paint_path_decompose_dashes(const hpgs_paint_path *_this, + const hpgs_gstate *gstate); + +HPGS_API double hpgs_bezier_path_x (const hpgs_paint_path *path, int i, double t); +HPGS_API double hpgs_bezier_path_y (const hpgs_paint_path *path, int i, double t); +HPGS_API double hpgs_bezier_path_delta_x (const hpgs_paint_path *path, int i, double t); +HPGS_API double hpgs_bezier_path_delta_y (const hpgs_paint_path *path, int i, double t); + +HPGS_API double hpgs_bezier_path_xmin (const hpgs_paint_path *path, int i); +HPGS_API double hpgs_bezier_path_xmax (const hpgs_paint_path *path, int i); +HPGS_API double hpgs_bezier_path_ymin (const hpgs_paint_path *path, int i); +HPGS_API double hpgs_bezier_path_ymax (const hpgs_paint_path *path, int i); + +HPGS_API void hpgs_bezier_path_point(const hpgs_paint_path *path, int i, + double t, hpgs_point *p); + +HPGS_API void hpgs_bezier_path_delta(const hpgs_paint_path *path, int i, + double t, hpgs_point *p); + +HPGS_API void hpgs_bezier_path_tangent(const hpgs_paint_path *path, int i, + double t, int orientation, + double ytol, + hpgs_point *p); + +HPGS_API void hpgs_bezier_path_singularities(const hpgs_paint_path *path, int i, + double t0, double t1, + int *nx, double *tx); + +HPGS_API void hpgs_bezier_path_to_quadratic(const hpgs_paint_path *path, int i, + double t0, double t1, + int *nx, hpgs_point *points); + +/*! @} */ /* end of group path */ + +/*! @addtogroup paint_device + * @{ + */ +HPGS_API hpgs_paint_device *hpgs_new_paint_device(hpgs_image *image, + const char *filename, + const hpgs_bbox *bb, + hpgs_bool antialias); + +HPGS_API void hpgs_paint_device_set_image_interpolation (hpgs_paint_device *pdv, int i); +HPGS_API void hpgs_paint_device_set_thin_alpha (hpgs_paint_device *pdv, double a); + +/*! @} */ /* end of group paint_device */ + +#ifdef __cplusplus +} // end of extern "C" +#endif + +#endif /* ! __HPGS_H */ diff --git a/src/add-ons/translators/hpgs/lib/hpgsbase.c b/src/add-ons/translators/hpgs/lib/hpgsbase.c new file mode 100644 index 0000000000..db740c1202 --- /dev/null +++ b/src/add-ons/translators/hpgs/lib/hpgsbase.c @@ -0,0 +1,176 @@ +/*********************************************************************** + * * + * $Id: hpgsbase.c 270 2006-01-29 21:12:23Z softadm $ + * * + * hpgs - HPGl Script, a hpgl/2 interpreter, which uses a Postscript * + * API for rendering a scene and thus renders to a variety of * + * devices and fileformats. * + * * + * (C) 2004-2006 ev-i Informationstechnologie GmbH http://www.ev-i.at * + * * + * Author: Wolfgang Glas * + * * + * hpgs is free software; you can redistribute it and/or * + * modify it under the terms of the GNU Lesser General Public * + * License as published by the Free Software Foundation; either * + * version 2.1 of the License, or (at your option) any later version. * + * * + * hpgs is distributed in the hope that it will be useful, * + * but WITHOUT ANY WARRANTY; without even the implied warranty of * + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * + * Lesser General Public License for more details. * + * * + * You should have received a copy of the GNU Lesser General Public * + * License along with this library; if not, write to the * + * Free Software Foundation, Inc., 59 Temple Place, Suite 330, * + * Boston, MA 02111-1307 USA * + * * + *********************************************************************** + * * + * The implementation of basic helper functions. * + * * + ***********************************************************************/ + +#include +#include + +/*! + Parses a physical paper size with a given unit and returns the + width and the height of the paper in PostScript pt (1/72 inch). + + The standard formats A4,A3,A2,A1 an A0 as well + as their landscape counterparts A4l,A3l,A2l,A1l and A0l are + accepted. + + If the string does not represent a standard paper size, + it must be of the format x, where + and must follow the convention of \c hpgs_parse_papersize. + + The function returns 0, if the string matches these conventions or + -1, if the string is in a wrong format. +*/ +int hpgs_parse_papersize(const char *str, double *pt_width, double *pt_height) +{ + if (strcmp(str,"A4")==0) + { + *pt_width = 595.91084545538825881889; + *pt_height = 842.74519960822752756850; + } + else if (strcmp(str,"A3")==0) + { + *pt_width = 842.74519960822752756850; + *pt_height = 1191.82169091077651766614; + } + else if (strcmp(str,"A2")==0) + { + *pt_width = 1191.82169091077651766614; + *pt_height = 1685.49039921645505516535; + } + else if (strcmp(str,"A1")==0) + { + *pt_width = 1685.49039921645505516535; + *pt_height = 2383.64338182155303536062; + } + else if (strcmp(str,"A0")==0) + { + *pt_width = 2383.64338182155303536062; + *pt_height = 3370.98079843291011035905; + } + else if (strcmp(str,"A4l")==0) + { + *pt_height = 595.91084545538825881889; + *pt_width = 842.74519960822752756850; + } + else if (strcmp(str,"A3l")==0) + { + *pt_height = 842.74519960822752756850; + *pt_width = 1191.82169091077651766614; + } + else if (strcmp(str,"A2l")==0) + { + *pt_height = 1191.82169091077651766614; + *pt_width = 1685.49039921645505516535; + } + else if (strcmp(str,"A1l")==0) + { + *pt_height = 1685.49039921645505516535; + *pt_width = 2383.64338182155303536062; + } + else if (strcmp(str,"A0l")==0) + { + *pt_height = 2383.64338182155303536062; + *pt_width = 3370.98079843291011035905; + } + else + { + // find the 'x' + const char *x=strchr(str,'x'); + char wstr[32]; + int l; + + if (!x) return -1; + l=x-str; + if (l > 31) return -1; + + strncpy(wstr,str,l); + wstr[l] = '\0'; + + if (hpgs_parse_length(wstr,pt_width)) return -1; + if (hpgs_parse_length(str+l+1,pt_height)) return -1; + } + return 0; +} + +/*! + Parses a physical length with a given unit and returns the length + in PostScript pt (1/72 inch). + + The following formats are accepted: + + \verbatim + 27 + 37pt + 4.5inch + 0.37m + 1.5cm + 11.34mm + \endverbatim + + If no unit is specified, PostScript points (1/72 inch) are assumed. + + The function returns 0, if the string matches these conventions or + -1, if the string is in a wrong format. + +*/ +int hpgs_parse_length(const char *str, double *pt_length) +{ + const char *unit="pt"; + + char * endptr = (char*)str; + + *pt_length = strtod(str,&endptr); + + if (endptr == str) return -1; + if (*endptr) unit = endptr; + + if (strcmp(unit,"cm")==0) + { + *pt_length *= 72.0 / 2.54; + } + else if (strcmp(unit,"mm")==0) + { + *pt_length *= 72.0 / 25.4; + } + else if (strcmp(unit,"m")==0) + { + *pt_length *= 72.0 / 0.0254; + } + else if (strcmp(unit,"inch")==0) + { + *pt_length *= 72.0; + } + else if (strcmp(unit,"pt")) + return -1; + + return 0; +} diff --git a/src/add-ons/translators/hpgs/lib/hpgsbbox.c b/src/add-ons/translators/hpgs/lib/hpgsbbox.c new file mode 100644 index 0000000000..c62f37a41b --- /dev/null +++ b/src/add-ons/translators/hpgs/lib/hpgsbbox.c @@ -0,0 +1,142 @@ +/*********************************************************************** + * * + * $Id: hpgsbbox.c 298 2006-03-05 18:18:03Z softadm $ + * * + * hpgs - HPGl Script, a hpgl/2 interpreter, which uses a Postscript * + * API for rendering a scene and thus renders to a variety of * + * devices and fileformats. * + * * + * (C) 2004-2006 ev-i Informationstechnologie GmbH http://www.ev-i.at * + * * + * Author: Wolfgang Glas * + * * + * hpgs is free software; you can redistribute it and/or * + * modify it under the terms of the GNU Lesser General Public * + * License as published by the Free Software Foundation; either * + * version 2.1 of the License, or (at your option) any later version. * + * * + * hpgs is distributed in the hope that it will be useful, * + * but WITHOUT ANY WARRANTY; without even the implied warranty of * + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * + * Lesser General Public License for more details. * + * * + * You should have received a copy of the GNU Lesser General Public * + * License along with this library; if not, write to the * + * Free Software Foundation, Inc., 59 Temple Place, Suite 330, * + * Boston, MA 02111-1307 USA * + * * + *********************************************************************** + * * + * The implementation of the public API for bounding boxes. * + * * + ***********************************************************************/ + +#include + +/*! + Returns, whether the two bounding boxes are equal. + */ +hpgs_bool hpgs_bbox_isequal (const hpgs_bbox *bb1, const hpgs_bbox *bb2) +{ + return + bb1->llx == bb2->llx && + bb1->lly == bb2->lly && + bb1->urx == bb2->urx && + bb1->ury == bb2->ury; +} + +/*! + Calculates the distance of the two bounding boxes. + */ +void hpgs_bbox_distance (hpgs_point *d, const hpgs_bbox *bb1, const hpgs_bbox *bb2) +{ + if (hpgs_bbox_isnull(bb1) || + hpgs_bbox_isnull(bb2) ) + { + d->x = 0.0; + d->y = 0.0; + return; + } + + if (bb2->llx >= bb1->urx) + { + d->x = bb2->llx - bb1->urx; + } + else if (bb1->llx >= bb2->urx) + { + d->x = bb1->llx - bb2->urx; + } + else + d->x = 0.0; + + if (bb2->lly >= bb1->ury) + { + d->y = bb2->lly - bb1->ury; + } + else if (bb1->lly >= bb2->ury) + { + d->y = bb1->lly - bb2->ury; + } + else + d->y = 0.0; +} + +/*! + Returns, whether the bounding box is null. + A null bounding box is als empty. + An empty bounding box may not be null, if + either of the x or y extend of the bounding box + is exactly zero. + */ +hpgs_bool hpgs_bbox_isnull (const hpgs_bbox *bb) +{ + return + bb->llx > bb->urx || + bb->lly > bb->ury; +} + +/*! + Returns, whether the bounding box is empty. + */ +hpgs_bool hpgs_bbox_isempty (const hpgs_bbox *bb) +{ + return + bb->llx >= bb->urx || + bb->lly >= bb->ury; +} + +/*! + Sets this bounding box to an empty bounding box. + */ +void hpgs_bbox_null (hpgs_bbox *bb) +{ + bb->llx = 1.0e20; + bb->lly = 1.0e20; + bb->urx = -1.0e20; + bb->ury = -1.0e20; +} + +/*! + Expands \c bb1 in order to comprise the smallest bounding box + containing both \c bb1 and \c bb2 + */ +void hpgs_bbox_expand (hpgs_bbox *bb1, const hpgs_bbox *bb2) +{ + if (bb2->llx < bb1->llx) bb1->llx = bb2->llx; + if (bb2->lly < bb1->lly) bb1->lly = bb2->lly; + if (bb2->urx > bb1->urx) bb1->urx = bb2->urx; + if (bb2->ury > bb1->ury) bb1->ury = bb2->ury; +} + +/*! + Shrinks \c bb1 in order to comprise the intersection + of \c bb1 and \c bb2. If the bounding boxes do not intersect, + \c bb1 is set to a null bounding box. + */ +void hpgs_bbox_intersect (hpgs_bbox *bb1, const hpgs_bbox *bb2) +{ + if (bb2->llx > bb1->llx) bb1->llx=bb2->llx; + if (bb2->lly > bb1->lly) bb1->lly=bb2->lly; + if (bb2->urx < bb1->urx) bb1->urx=bb2->urx; + if (bb2->ury < bb1->ury) bb1->ury=bb2->ury; +} diff --git a/src/add-ons/translators/hpgs/lib/hpgsbezier.c b/src/add-ons/translators/hpgs/lib/hpgsbezier.c new file mode 100644 index 0000000000..b9b89217b2 --- /dev/null +++ b/src/add-ons/translators/hpgs/lib/hpgsbezier.c @@ -0,0 +1,580 @@ +/*********************************************************************** + * * + * $Id: hpgsbezier.c 270 2006-01-29 21:12:23Z softadm $ + * * + * hpgs - HPGl Script, a hpgl/2 interpreter, which uses a Postscript * + * API for rendering a scene and thus renders to a variety of * + * devices and fileformats. * + * * + * (C) 2004-2006 ev-i Informationstechnologie GmbH http://www.ev-i.at * + * * + * Author: Wolfgang Glas * + * * + * hpgs is free software; you can redistribute it and/or * + * modify it under the terms of the GNU Lesser General Public * + * License as published by the Free Software Foundation; either * + * version 2.1 of the License, or (at your option) any later version. * + * * + * hpgs is distributed in the hope that it will be useful, * + * but WITHOUT ANY WARRANTY; without even the implied warranty of * + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * + * Lesser General Public License for more details. * + * * + * You should have received a copy of the GNU Lesser General Public * + * License along with this library; if not, write to the * + * Free Software Foundation, Inc., 59 Temple Place, Suite 330, * + * Boston, MA 02111-1307 USA * + * * + *********************************************************************** + * * + * Bezier spline length and scanline cut implementation. * + * * + ***********************************************************************/ + +#include +#include +#include + +// #define HPGS_BEZIER_DEBUG + +/*! Calculates the derivation of the bezier curve starting + at point \c i of \c path at curve parameter \c t. +*/ +void hpgs_bezier_path_delta(const hpgs_paint_path *path, int i, + double t, hpgs_point *p) +{ + double tp,tm; + + tp = t + 0.5; + tm = 0.5 - t; + + p->x = 3.0* ((path->points[i+1].p.x-path->points[i].p.x)*tm*tm+ + 2.0 * (path->points[i+2].p.x-path->points[i+1].p.x) * tm*tp+ + (path->points[i+3].p.x-path->points[i+2].p.x) * tp*tp); + + p->y = 3.0 * ((path->points[i+1].p.y-path->points[i].p.y)*tm*tm+ + 2.0 * (path->points[i+2].p.y-path->points[i+1].p.y) * tm*tp+ + (path->points[i+3].p.y-path->points[i+2].p.y) * tp*tp); +} + +/*! Calculates the derivation of the bezier curve starting + at point \c i of \c path at curve parameter \c t. +*/ +double hpgs_bezier_path_delta_x(const hpgs_paint_path *path, int i, double t) +{ + double tp,tm; + + tp = t + 0.5; + tm = 0.5 - t; + + return 3.0* ((path->points[i+1].p.x-path->points[i].p.x)*tm*tm+ + 2.0 * (path->points[i+2].p.x-path->points[i+1].p.x) * tm*tp+ + (path->points[i+3].p.x-path->points[i+2].p.x) * tp*tp); +} + +/*! Calculates the derivation of the bezier curve starting + at point \c i of \c path at curve parameter \c t. +*/ +double hpgs_bezier_path_delta_y(const hpgs_paint_path *path, int i, double t) +{ + double tp,tm; + + tp = t + 0.5; + tm = 0.5 - t; + + return 3.0* ((path->points[i+1].p.y-path->points[i].p.y)*tm*tm+ + 2.0 * (path->points[i+2].p.y-path->points[i+1].p.y) * tm*tp+ + (path->points[i+3].p.y-path->points[i+2].p.y) * tp*tp); +} + +/*! Calculates the tangent to the bezier curve starting + at point \c i of \c path at curve parameter \c t. + + If \c orientation is \c 1, the tangent is calculated with increasing + curve parameter, if we meet a singularity (right tangent). + + If \c orientation is \c -1, the tangent is calculated with decreasing + curve parameter, if we meet a singularity (left tangent). + + If \c orientation is \c 0, the tangent is calculated with decreased + and increased curve parameter, if we meet a singularity (mid tangent). +*/ + +void hpgs_bezier_path_tangent(const hpgs_paint_path *path, int i, + double t, int orientation, + double ytol, hpgs_point *p) +{ + hpgs_bezier_path_delta(path,i,t,p); + + double l = hypot(p->x,p->y); + + if (l < ytol) + { + hpgs_point p1; + + if (orientation <= 0) + hpgs_bezier_path_point(path,i,t-1.0e-4,&p1); + else + hpgs_bezier_path_point(path,i,t,&p1); + + if (orientation >= 0) + hpgs_bezier_path_point(path,i,t+1.0e-4,p); + else + hpgs_bezier_path_point(path,i,t,p); + + p->x -= p1.x; + p->y -= p1.y; + + l = hypot(p->x,p->y); + if (l < ytol*1.0e-4) return; + } + + p->x /= l; + p->y /= l; +} + +static int quad_roots (double a, double b, double c, + double t0, double t1, double *t) +{ + if (fabs(a) < (fabs(b)>fabs(c) ? fabs(b) : fabs(c)) * 1.0e-8 || fabs(a) < 1.0e-16) + { + if (fabs(b) < fabs(c) * 1.0e-8) + return 0; + + t[0] = -c/b; + return t[0] > t0 && t[0] < t1; + } + + double p = b/a; + double q = c/a; + + double det = 0.25*p-q; + + if (det < 0) return 0; + + det = sqrt(det); + + if (p > 0.0) + t[0] = -0.5*p - det; + else + t[0] = -0.5*p + det; + + if (fabs(t[0]) < 1.0e-8) + return t[0] > t0 && t[0] < t1; + + t[1] = q / t[0]; + + if (t[0] <= t0 || t[0] >= t1) + { + t[0] = t[1]; + return t[0] > t0 && t[0] < t1; + } + + if (t[1] <= t0 || t[1] >= t1) + return 1; + + if (t[0] > t[1]) + { + double tmp = t[1]; + t[1] = t[0]; + t[0] = tmp; + } + + return fabs(t[0]-t[1]) < 1.0e-8 ? 1 : 2; +} + + +/*! + Calculates the singularities of the bezier curve in the + parameter interval from \c t0 to \c t1. + + We calculate points, where the cross product of the first derivative + and the second derivative vanishes. These points include points, where + the first or second derivative vanishes. Additionally, turning points + of the curve are also included. + + \c tx is a pointer to an array of at least two double values, + in which the position of the singularities is returned. + */ +void hpgs_bezier_path_singularities(const hpgs_paint_path *path, int i, + double t0, double t1, + int *nx, double *tx) +{ + // The second order spline p'(t) cross p''(t) + double k0 = + (path->points[i+1].p.x-path->points[i].p.x)*(path->points[i+2].p.y-path->points[i+1].p.y) - + (path->points[i+1].p.y-path->points[i].p.y)*(path->points[i+2].p.x-path->points[i+1].p.x); + + double k1 = + (path->points[i+1].p.x-path->points[i].p.x)*(path->points[i+3].p.y-path->points[i+2].p.y) - + (path->points[i+1].p.y-path->points[i].p.y)*(path->points[i+3].p.x-path->points[i+2].p.x); + + double k2 = + (path->points[i+2].p.x-path->points[i+1].p.x)*(path->points[i+3].p.y-path->points[i+2].p.y) - + (path->points[i+2].p.y-path->points[i+1].p.y)*(path->points[i+3].p.x-path->points[i+2].p.x); + + + // coefficients for the quadratic equations. + double a = k0 - k1 + k2; + + double b = k2 - k0; + + double c = 0.25 * (k0 + k1 + k2); + + *nx = quad_roots (a,b,c,t0,t1,tx); +} + +static void add_quad (const hpgs_point *p1, + const hpgs_point *d1, + const hpgs_point *p2, + const hpgs_point *d2, + int *nx, hpgs_point *points) +{ + double det = d1->y * d2->x - d1->x * d2->y; + + if (fabs(det) < 1.0e-8) + { + points[*nx].x = 0.5 * (p1->x + p2->x); + points[*nx].y = 0.5 * (p1->y + p2->y); + ++*nx; + } + else + { + double s = (d2->x*(p2->y-p1->y)- + d2->y*(p2->x-p1->x) )/det; + + points[*nx].x = p1->x + s*d1->x; + points[*nx].y = p1->y + s*d1->y; + ++*nx; + } + + points[*nx].x = p2->x; + points[*nx].y = p2->y; + ++*nx; +} + +/*! + Approximates the bezier curve segment in the + parameter interval from \c t0 to \c t1 with quadratic bezier splines. + + The array \c points is used to return the quadratic bezier segments and + must have a dimension of at least 16 points. + + \c nx returns the number of generated points, which is always an even + number. The first point is the control point of the first quadratic + spline, the second point the endpoint of the first quadratic spline + and so on. + */ +void hpgs_bezier_path_to_quadratic(const hpgs_paint_path *path, int i, + double t0, double t1, + int *nx, hpgs_point *points) +{ + // The second order spline p'(t) cross p''(t) + double k0 = + (path->points[i+1].p.x-path->points[i].p.x)*(path->points[i+2].p.y-path->points[i+1].p.y) - + (path->points[i+1].p.y-path->points[i].p.y)*(path->points[i+2].p.x-path->points[i+1].p.x); + + double k1 = + (path->points[i+1].p.x-path->points[i].p.x)*(path->points[i+3].p.y-path->points[i+2].p.y) - + (path->points[i+1].p.y-path->points[i].p.y)*(path->points[i+3].p.x-path->points[i+2].p.x); + + double k2 = + (path->points[i+2].p.x-path->points[i+1].p.x)*(path->points[i+3].p.y-path->points[i+2].p.y) - + (path->points[i+2].p.y-path->points[i+1].p.y)*(path->points[i+3].p.x-path->points[i+2].p.x); + + + double xmax,xmin,ymin,ymax; + + // coefficients for the quadratic equations. + double a = k0 - k1 + k2; + + double b = k2 - k0; + + double c = 0.25 * (k0 + k1 + k2); + + // at most three partition points: + // extrem, roots of the curvature spline + double tpart[5]; + + // get the roots. + int ipart; + int npart = quad_roots (a,b,c,t0,t1,tpart+1) + 1; + + // add the extreme point. + if (fabs(a) > fabs(b)) + { + double text = -0.5 * b/a; + + if (npart == 3) + { + tpart[3] = tpart[2]; + tpart[2] = text; + npart = 3; + } + else if (text > t0 && text < t1) + { + if (npart == 2 && text < tpart[1]) + { + tpart[2] = tpart[1]; + tpart[1] = text; + } + else + tpart[npart] = text; + + ++npart; + } + } + + tpart[0] = t0; + tpart[npart] = t1; + + xmax = xmin = path->points[i].p.x; + if (path->points[i+1].p.x > xmax) xmax = path->points[i+1].p.x; + if (path->points[i+2].p.x > xmax) xmax = path->points[i+2].p.x; + if (path->points[i+3].p.x > xmax) xmax = path->points[i+3].p.x; + if (path->points[i+1].p.x < xmin) xmin = path->points[i+1].p.x; + if (path->points[i+2].p.x < xmin) xmin = path->points[i+2].p.x; + if (path->points[i+3].p.x < xmin) xmin = path->points[i+3].p.x; + + ymax = ymin = path->points[i].p.y; + if (path->points[i+1].p.y > ymax) ymax = path->points[i+1].p.y; + if (path->points[i+2].p.y > ymax) ymax = path->points[i+2].p.y; + if (path->points[i+3].p.y > ymax) ymax = path->points[i+3].p.y; + if (path->points[i+1].p.y < ymin) ymin = path->points[i+1].p.y; + if (path->points[i+2].p.y < ymin) ymin = path->points[i+2].p.y; + if (path->points[i+3].p.y < ymin) ymin = path->points[i+3].p.y; + + double curv0 = + k0*(0.5-tpart[0])*(0.5-tpart[0]) + + k1*(0.5-tpart[0])*(0.5+tpart[0]) + + k2*(0.5+tpart[0])*(0.5+tpart[0]); + + *nx = 0; + + for (ipart=0; ipart 8/npart) n_splines = 8/npart; + + hpgs_point d1; + hpgs_point p1; + + hpgs_bezier_path_point(path,i,tpart[ipart],&p1); + hpgs_bezier_path_tangent(path,i,tpart[ipart],1,1.0e-3,&d1); + + for (j=1;j<=n_splines;++j) + { + double t = tpart[ipart] + (tpart[ipart+1]-tpart[ipart]) * j / (double)n_splines; + + hpgs_point d2; + hpgs_point p2; + + hpgs_bezier_path_point(path,i,t,&p2); + hpgs_bezier_path_tangent(path,i,t,jpoints[i+1].p.x-path->points[i].p.x)*tm*tm+ + 2.0 * (path->points[i+2].p.x-path->points[i+1].p.x) * tm*tp+ + (path->points[i+3].p.x-path->points[i+2].p.x) * tp*tp, + + (path->points[i+1].p.y-path->points[i].p.y)*tm*tm+ + 2.0 * (path->points[i+2].p.y-path->points[i+1].p.y) * tm*tp+ + (path->points[i+3].p.y-path->points[i+2].p.y) * tp*tp + ); +} + +/*! Calculates the curve lengths at an equidistant grid + of curve parmeters by na numerical quadrature. + + You must call this subroutine before using + \c hpgs_bezier_length_param. +*/ +void hpgs_bezier_length_init(hpgs_bezier_length *b, + const hpgs_paint_path *path, int i) +{ + int ip; + + b->dl[0] = bezier_dl(path,i,-0.5); + + b->l[0] = 0.0; + + for (ip=1;ip<=16;++ip) + { + double dlm0,dlm1; + + // Lobatto quadrature with order 4. + b->dl[ip] = bezier_dl(path,i,(ip-8.0)*0.0625); + + dlm0 = bezier_dl(path,i,(ip-(8.5+0.22360679774997896964))*0.0625); + dlm1 = bezier_dl(path,i,(ip-(8.5-0.22360679774997896964))*0.0625); + + b->l[ip] = b->l[ip-1] + + (b->dl[ip-1] + 5.0 * (dlm0 + dlm1) + b->dl[ip])/(16.0*12.0); + } +} + +/*! Returns the curve parameter at the bezier curve \c b + corresponding to a curve length \c l. + + You must have called \c hpgs_bezier_length_init before using + this function. +*/ +double hpgs_bezier_length_param(const hpgs_bezier_length *b, double l) +{ + // binary search. + + int i = 0; + + if (l >= b->l[i+8]) i+=8; + if (l >= b->l[i+4]) i+=4; + if (l >= b->l[i+2]) i+=2; + if (l >= b->l[i+1]) ++i; + + double dl = b->l[i+1]-b->l[i]; + double ll = (l-b->l[i])/dl; + + return + (i - 8.0 + ll*ll*(3.0-2.0*ll)) * 0.0625 + + (ll*(ll*(ll-2.0)+1.0) / b->dl[i] + ll*ll*(ll-1.0) / b->dl[i+1] ) * dl; +} + +/*! Calculates the minimal x component of all four control points of + the bezier spline. */ +double hpgs_bezier_path_xmin (const hpgs_paint_path *path, int i) +{ + double x0 = + path->points[i].p.x < path->points[i+1].p.x ? + path->points[i].p.x : path->points[i+1].p.x; + + double x1 = + path->points[i+2].p.x < path->points[i+3].p.x ? + path->points[i+2].p.x : path->points[i+3].p.x; + + return x0 < x1 ? x0 : x1; +} + +/*! Calculates the maximal x component of all four control points of + the bezier spline. */ +double hpgs_bezier_path_xmax (const hpgs_paint_path *path, int i) +{ + double x0 = + path->points[i].p.x > path->points[i+1].p.x ? + path->points[i].p.x : path->points[i+1].p.x; + + double x1 = + path->points[i+2].p.x > path->points[i+3].p.x ? + path->points[i+2].p.x : path->points[i+3].p.x; + + return x0 > x1 ? x0 : x1; +} + +/*! Calculates the minimal y component of all four control points of + the bezier spline. */ +double hpgs_bezier_path_ymin (const hpgs_paint_path *path, int i) +{ + double y0 = + path->points[i].p.y < path->points[i+1].p.y ? + path->points[i].p.y : path->points[i+1].p.y; + + double y1 = + path->points[i+2].p.y < path->points[i+3].p.y ? + path->points[i+2].p.y : path->points[i+3].p.y; + + return y0 < y1 ? y0 : y1; +} + +/*! Calculates the maximal y component of all four control points of + the bezier spline. */ +double hpgs_bezier_path_ymax (const hpgs_paint_path *path, int i) +{ + double y0 = + path->points[i].p.y > path->points[i+1].p.y ? + path->points[i].p.y : path->points[i+1].p.y; + + double y1 = + path->points[i+2].p.y > path->points[i+3].p.y ? + path->points[i+2].p.y : path->points[i+3].p.y; + + return y0 > y1 ? y0 : y1; +} + +/*! Calculates the x component of a point on the bezier spline. */ +double hpgs_bezier_path_x (const hpgs_paint_path *path, int i, double t) +{ + double tp,tm; + + tp = t + 0.5; + tm = 0.5 - t; + + return + path->points[i].p.x *tm*tm*tm + + 3.0 * tm*tp * (path->points[i+1].p.x * tm + path->points[i+2].p.x * tp) + + path->points[i+3].p.x * tp*tp*tp; +} + +/*! Calculates the y component of a point on the bezier spline. */ +double hpgs_bezier_path_y (const hpgs_paint_path *path, int i, double t) +{ + double tp,tm; + + tp = t + 0.5; + tm = 0.5 - t; + + return + path->points[i].p.y *tm*tm*tm + + 3.0 * tm*tp * (path->points[i+1].p.y * tm + path->points[i+2].p.y * tp) + + path->points[i+3].p.y * tp*tp*tp; +} + +/*! Calculates the point on the bezier curve starting + at point \c i of \c path at curve parameter \c t. +*/ +void hpgs_bezier_path_point(const hpgs_paint_path *path, int i, + double t, hpgs_point *p) +{ + double tp,tm; + + tp = t + 0.5; + tm = 0.5 - t; + + p->x = + path->points[i].p.x *tm*tm*tm + + 3.0 * tm*tp * (path->points[i+1].p.x * tm + path->points[i+2].p.x * tp) + + path->points[i+3].p.x * tp*tp*tp; + + p->y = + path->points[i].p.y *tm*tm*tm + + 3.0 * tm*tp * (path->points[i+1].p.y * tm + path->points[i+2].p.y * tp) + + path->points[i+3].p.y * tp*tp*tp; +} diff --git a/src/add-ons/translators/hpgs/lib/hpgscharacter.c b/src/add-ons/translators/hpgs/lib/hpgscharacter.c new file mode 100644 index 0000000000..e608ab0893 --- /dev/null +++ b/src/add-ons/translators/hpgs/lib/hpgscharacter.c @@ -0,0 +1,686 @@ +/*********************************************************************** + * * + * $Id: hpgscharacter.c 383 2007-03-18 18:29:22Z softadm $ + * * + * hpgs - HPGl Script, a hpgl/2 interpreter, which uses a Postscript * + * API for rendering a scene and thus renders to a variety of * + * devices and fileformats. * + * * + * (C) 2004-2006 ev-i Informationstechnologie GmbH http://www.ev-i.at * + * * + * Author: Wolfgang Glas * + * * + * hpgs is free software; you can redistribute it and/or * + * modify it under the terms of the GNU Lesser General Public * + * License as published by the Free Software Foundation; either * + * version 2.1 of the License, or (at your option) any later version. * + * * + * hpgs is distributed in the hope that it will be useful, * + * but WITHOUT ANY WARRANTY; without even the implied warranty of * + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * + * Lesser General Public License for more details. * + * * + * You should have received a copy of the GNU Lesser General Public * + * License along with this library; if not, write to the * + * Free Software Foundation, Inc., 59 Temple Place, Suite 330, * + * Boston, MA 02111-1307 USA * + * * + *********************************************************************** + * * + * The implementation of the HPGL reader. * + * * + ***********************************************************************/ + +#include +#include +#include +#include + +// The size of a line feed measured in the cap height of a font. +#define HPGS_LF_FAC 1.75 +#define HPGS_VSPACE_FAC 1.5 + +/* + HPGL command AD (Alternate font Definition) +*/ +int hpgs_reader_do_AD (hpgs_reader *reader) +{ + while (!reader->eoc) + { + int kind; + if (hpgs_reader_read_int(reader,&kind)) return -1; + if (reader->eoc) return -1; + + switch (kind) + { + case 1: + if (hpgs_reader_read_int(reader,&reader->alternate_encoding)) + return -1; + break; + case 2: + if (hpgs_reader_read_int(reader,&reader->alternate_spacing)) + return -1; + break; + case 3: + if (hpgs_reader_read_double(reader,&reader->alternate_pitch)) + return -1; + break; + case 4: + if (hpgs_reader_read_double(reader,&reader->alternate_height)) + return -1; + break; + case 5: + if (hpgs_reader_read_int(reader,&reader->alternate_posture)) + return -1; + break; + case 6: + if (hpgs_reader_read_int(reader,&reader->alternate_weight)) + return -1; + break; + case 7: + if (hpgs_reader_read_int(reader,&reader->alternate_face)) + return -1; + break; + default: + return -1; + } + } + return 0; +} + +/* + HPGL command SD (Standard font Definition) +*/ +int hpgs_reader_do_SD (hpgs_reader *reader) +{ + while (!reader->eoc) + { + int kind; + if (hpgs_reader_read_int(reader,&kind)) return -1; + if (reader->eoc) return -1; + + switch (kind) + { + case 1: + if (hpgs_reader_read_int(reader,&reader->default_encoding)) + return -1; + break; + case 2: + if (hpgs_reader_read_int(reader,&reader->default_spacing)) + return -1; + break; + case 3: + if (hpgs_reader_read_double(reader,&reader->default_pitch)) + return -1; + break; + case 4: + if (hpgs_reader_read_double(reader,&reader->default_height)) + return -1; + break; + case 5: + if (hpgs_reader_read_int(reader,&reader->default_posture)) + return -1; + break; + case 6: + if (hpgs_reader_read_int(reader,&reader->default_weight)) + return -1; + break; + case 7: + if (hpgs_reader_read_int(reader,&reader->default_face)) + return -1; + break; + default: + return -1; + } + } + return 0; +} + +/* + HPGL command CP (Character Plot) +*/ +int hpgs_reader_do_CP (hpgs_reader *reader) +{ + double w,h,ca,sa,spaces=0.0; + double lines=reader->current_text_line ? 1.0 : -1.0; + hpgs_point space_vec; + hpgs_point lf_vec; + + + if (hpgs_reader_checkpath(reader)) return -1; + + if (reader->eoc) + reader->current_point = reader->cr_point; + else + { + if (hpgs_reader_read_double(reader,&spaces)) return -1; + if (hpgs_reader_read_double(reader,&lines)) return -1; + } + + w = + reader->current_char_size.x ? (1.5 * reader->current_char_size.x) : + (72.0 / (reader->alternate_font ? + reader->alternate_pitch : + reader->default_pitch )); + + h = + reader->current_char_size.y ? reader->current_char_size.y : + (reader->alternate_font ? + reader->alternate_height : + reader->default_height ); + + ca = cos(reader->current_label_angle); + sa = sin(reader->current_label_angle); + + switch (reader->current_text_path % 4) + { + case 0: + space_vec.x = ca * (1.0+reader->current_extra_space.x) * w; + space_vec.y = sa * (1.0+reader->current_extra_space.x) * w; + lf_vec.x = sa * (HPGS_LF_FAC+reader->current_extra_space.y) * h; + lf_vec.y = -ca * (HPGS_LF_FAC+reader->current_extra_space.y) * h; + break; + case 1: + space_vec.x = sa * (HPGS_VSPACE_FAC+reader->current_extra_space.y) * h; + space_vec.y = -ca * (HPGS_VSPACE_FAC+reader->current_extra_space.y) * h; + lf_vec.x = -ca * (HPGS_LF_FAC+reader->current_extra_space.x) * w; + lf_vec.y = -sa * (HPGS_LF_FAC+reader->current_extra_space.x) * w; + break; + case 2: + space_vec.x = -ca * (1.0+reader->current_extra_space.x) * w; + space_vec.y = -sa * (1.0+reader->current_extra_space.x) * w; + lf_vec.x = -sa * (HPGS_LF_FAC+reader->current_extra_space.y) * h; + lf_vec.y = ca * (HPGS_LF_FAC+reader->current_extra_space.y) * h; + break; + default: // 3 + space_vec.x = -sa * (HPGS_VSPACE_FAC+reader->current_extra_space.y) * h; + space_vec.y = ca * (HPGS_VSPACE_FAC+reader->current_extra_space.y) * h; + lf_vec.x = ca * (HPGS_LF_FAC+reader->current_extra_space.x) * w; + lf_vec.y = sa * (HPGS_LF_FAC+reader->current_extra_space.x) * w; + } + + if (reader->current_text_line) + lines = -lines; + + reader->current_point.x += space_vec.x * spaces; + reader->current_point.y += space_vec.y * spaces; + reader->current_point.x += lf_vec.x * lines; + reader->current_point.y += lf_vec.y * lines; + + return 0; +} + +/* + HPGL command DI (absolute DIrection) +*/ +int hpgs_reader_do_DI (hpgs_reader *reader) +{ + double run = 1.0; + double rise = 0.0; + + if (!reader->eoc) + { + if (hpgs_reader_read_double(reader,&run)) return -1; + if (hpgs_reader_read_double(reader,&rise)) return -1; + } + + reader->current_label_angle = atan2(rise,run); + + return 0; +} + +/* + HPGL command DR (Relative Direction) +*/ +int hpgs_reader_do_DR (hpgs_reader *reader) +{ + double run = 0.01; + double rise = 0.0; + + if (!reader->eoc) + { + if (hpgs_reader_read_double(reader,&run)) return -1; + if (hpgs_reader_read_double(reader,&rise)) return -1; + } + + run *= (reader->P2.x - reader->P1.x); + rise *= (reader->P2.y - reader->P1.y); + + reader->current_label_angle = atan2(rise,run); + + return 0; +} + +/* + HPGL command DV (Define Variable Text path) +*/ +int hpgs_reader_do_DV (hpgs_reader *reader) +{ + reader->current_text_path = 0; + reader->current_text_line = 0; + + if (!reader->eoc && + hpgs_reader_read_int(reader,&reader->current_text_path)) return -1; + + if (!reader->eoc && + hpgs_reader_read_int(reader,&reader->current_text_line)) return -1; + + return 0; +} + +/* + HPGL command ES (Extra Space) +*/ +int hpgs_reader_do_ES (hpgs_reader *reader) +{ + reader->current_extra_space.x = 0.0; + reader->current_extra_space.y = 0.0; + + if (!reader->eoc && + hpgs_reader_read_double(reader,&reader->current_extra_space.x)) return -1; + + if (!reader->eoc && + hpgs_reader_read_double(reader,&reader->current_extra_space.y)) return -1; + + return 0; +} + +/* + HPGL command LO (Label Origin) +*/ +int hpgs_reader_do_LO (hpgs_reader *reader) +{ + reader->current_label_origin = 1; + + if (!reader->eoc && + hpgs_reader_read_int(reader,&reader->current_label_origin)) return -1; + + return 0; +} + +/* + HPGL command SI (absolute character SIze) +*/ +int hpgs_reader_do_SI (hpgs_reader *reader) +{ + reader->current_char_size.x = 0.0; + reader->current_char_size.y = 0.0; + + if (reader->eoc) return 0; + + if (hpgs_reader_read_double(reader,&reader->current_char_size.x)) return -1; + if (hpgs_reader_read_double(reader,&reader->current_char_size.y)) return -1; + + reader->current_char_size.x *= 72.0 / 2.54; + reader->current_char_size.y *= 72.0 / 2.54; + + return 0; +} + +/* + HPGL command SR (Relative character Size) +*/ +int hpgs_reader_do_SR (hpgs_reader *reader) +{ + reader->current_char_size.x = 0.0; + reader->current_char_size.y = 0.0; + + if (reader->eoc) return 0; + + if (hpgs_reader_read_double(reader,&reader->current_char_size.x)) return -1; + if (hpgs_reader_read_double(reader,&reader->current_char_size.y)) return -1; + + reader->current_char_size.x *= (reader->P2.x-reader->P1.x) * 0.01 * HP_TO_PT; + reader->current_char_size.y *= (reader->P2.y-reader->P1.y) * 0.01 * HP_TO_PT; + + return 0; +} + +/* + HPGL command SL (character SLant) +*/ +int hpgs_reader_do_SL (hpgs_reader *reader) +{ + reader->current_slant = 0.0; + + if (!reader->eoc && + hpgs_reader_read_double(reader,&reader->current_slant)) return -1; + + return 0; +} + +/* + HPGL command SA (Select Alternate font) +*/ +int hpgs_reader_do_SA (hpgs_reader *reader) +{ + reader->alternate_font = 1; + return 0; +} + +/* + HPGL command SS (Select Standard font) +*/ +int hpgs_reader_do_SS(hpgs_reader *reader) +{ + reader->alternate_font = 0; + return 0; +} + +/* + HPGL command DT (Define label Terminator) +*/ +int hpgs_reader_do_DT (hpgs_reader *reader) +{ + reader->bytes_ignored = 0; + + reader->last_byte = hpgs_getc(reader->in); + if (reader->last_byte == EOF) + return -1; + + if (reader->last_byte == ';') + { + reader->label_term = '\003'; + reader->label_term_ignore = 1; + reader->eoc = 1; + return 0; + } + else + { + reader->label_term = reader->last_byte; + reader->last_byte = hpgs_getc(reader->in); + if (reader->last_byte == EOF) + return -1; + } + + if (reader->last_byte == ',') + { + reader->label_term_ignore = 0; + + while (isspace(reader->last_byte = hpgs_getc(reader->in))) ; + + while (isdigit(reader->last_byte = hpgs_getc(reader->in))) + if (reader->last_byte != '0') + reader->label_term_ignore = 1; + + if (reader->last_byte == EOF) + return -1; + } + else + reader->label_term_ignore = 1; + + while (isspace(reader->last_byte)) reader->last_byte = hpgs_getc(reader->in); + + if (isalpha(reader->last_byte) || reader->last_byte == HPGS_ESC) + reader->bytes_ignored = 1; + else + { + if (reader->last_byte != ';') + return -1; + + reader->bytes_ignored = 0; + } + + reader->eoc = 1; + return 0; +} + +/* + HPGL command SM (Symbol Mode) +*/ +int hpgs_reader_do_SM (hpgs_reader *reader) +{ + reader->bytes_ignored = 0; + + if (reader->eoc) + return 0; + + reader->last_byte = hpgs_getc(reader->in); + if (reader->last_byte == EOF) + return -1; + + return hpgs_reader_check_param_end(reader); +} + +/* + HPGL command LB (LaBel) +*/ +int hpgs_reader_do_LB (hpgs_reader *reader) +{ + char str[HPGS_MAX_LABEL_SIZE]; + double w,h,ca,sa; + hpgs_point left_vec; + hpgs_point up_vec; + hpgs_point space_vec; + hpgs_point lf_vec; + hpgs_point adj_vec; + int i0=0; + int ipos=0; + int i; + + if (hpgs_reader_read_label_string(reader,str)) return -1; + + if (hpgs_reader_checkpath(reader)) return -1; + + w = + reader->current_char_size.x ? (1.5 * reader->current_char_size.x) : + (72.0 / (reader->alternate_font ? + reader->alternate_pitch : + reader->default_pitch )); + + h = + reader->current_char_size.y ? reader->current_char_size.y : + (reader->alternate_font ? + reader->alternate_height : + reader->default_height ); + + ca = cos(reader->current_label_angle); + sa = sin(reader->current_label_angle); + + left_vec.x = ca * w; + left_vec.y = sa * w; + + up_vec.x = (reader->current_slant * ca - sa) * h; + up_vec.y = (reader->current_slant * sa + ca) * h; + + switch (reader->current_text_path % 4) + { + case 0: + space_vec.x = ca * (1.0+reader->current_extra_space.x) * w; + space_vec.y = sa * (1.0+reader->current_extra_space.x) * w; + lf_vec.x = sa * (HPGS_LF_FAC+reader->current_extra_space.y) * h; + lf_vec.y = -ca * (HPGS_LF_FAC+reader->current_extra_space.y) * h; + adj_vec.x = sa * h; + adj_vec.y = -ca * h; + break; + case 1: + space_vec.x = sa * (HPGS_VSPACE_FAC+reader->current_extra_space.y) * h; + space_vec.y = -ca * (HPGS_VSPACE_FAC+reader->current_extra_space.y) * h; + lf_vec.x = -ca * (HPGS_LF_FAC+reader->current_extra_space.x) * w; + lf_vec.y = -sa * (HPGS_LF_FAC+reader->current_extra_space.x) * w; + adj_vec.x = -ca * w; + adj_vec.y = -sa * w; + break; + case 2: + space_vec.x = -ca * (1.0+reader->current_extra_space.x) * w; + space_vec.y = -sa * (1.0+reader->current_extra_space.x) * w; + lf_vec.x = -sa * (HPGS_LF_FAC+reader->current_extra_space.y) * h; + lf_vec.y = ca * (HPGS_LF_FAC+reader->current_extra_space.y) * h; + adj_vec.x = -sa * h; + adj_vec.y = ca * h; + break; + default: // 3 + space_vec.x = -sa * (HPGS_VSPACE_FAC+reader->current_extra_space.y) * h; + space_vec.y = ca * (HPGS_VSPACE_FAC+reader->current_extra_space.y) * h; + lf_vec.x = ca * (HPGS_LF_FAC+reader->current_extra_space.x) * w; + lf_vec.y = sa * (HPGS_LF_FAC+reader->current_extra_space.x) * w; + adj_vec.x = ca * w; + adj_vec.y = sa * w; + } + + if (reader->current_text_line) + { + lf_vec.x = -lf_vec.x; + lf_vec.y = -lf_vec.y; + } + + hpgs_matrix_scale(&left_vec, &reader->page_matrix,&left_vec ); + hpgs_matrix_scale(&up_vec, &reader->page_matrix,&up_vec ); + hpgs_matrix_scale(&space_vec,&reader->page_matrix,&space_vec); + hpgs_matrix_scale(&lf_vec, &reader->page_matrix,&lf_vec ); + hpgs_matrix_scale(&adj_vec, &reader->page_matrix,&adj_vec ); + + hpgs_point adj = { 0.0, 0.0 }; + + // got through the string and search for control characters. + for (i=0;i<=HPGS_MAX_LABEL_SIZE;i++) + { + if (i < HPGS_MAX_LABEL_SIZE && (unsigned char)str[i] >= 32) + { + if (ipos == 0 && reader->current_label_origin % 10 > 1) + { + // Everytime we start a new portion of the label, + // adapt the current point in order to meet the given label origin. + + // lookahead for the new CR of EOS. + int j; + double x_adj,y_adj,nchars=0.0; + + for (j=i;j<=HPGS_MAX_LABEL_SIZE;j++) + { + if (j < HPGS_MAX_LABEL_SIZE && (unsigned char)str[j] >= 32) + nchars+=1.0; + else + if (j >= HPGS_MAX_LABEL_SIZE || str[j] == 0 || str[j] == 13) break; + } + + if (nchars && (reader->current_text_path % 2)) + nchars -= reader->current_extra_space.y / (1.0 + reader->current_extra_space.y); + else + nchars -= reader->current_extra_space.x / (1.0 + reader->current_extra_space.x); + + x_adj = -0.5 * nchars * ((reader->current_label_origin % 10 - 1) / 3); + y_adj = -0.5 * ((reader->current_label_origin % 10 - 1) % 3); + + if (reader->current_label_origin / 10) + { + x_adj -= 0.25 * ((reader->current_label_origin % 10 - 1) / 3 - 1); + y_adj -= 0.25 * ((reader->current_label_origin % 10 - 1) % 3 - 1); + } + + adj.x += x_adj * space_vec.x - y_adj * adj_vec.x; + adj.y += x_adj * space_vec.y - y_adj * adj_vec.y; + } + + if (ipos == 0) + switch (reader->current_text_path % 4) + { + case 1: + adj.x -= up_vec.x; + adj.y -= up_vec.y; + break; + case 2: + adj.x -= left_vec.x + up_vec.x; + adj.y -= left_vec.y + up_vec.y; + break; + case 3: + adj.x -= left_vec.x; + adj.y -= left_vec.y; + } + + ++ipos; + continue; + } + + reader->current_point.x += adj.x; + reader->current_point.y += adj.y; + + if (i>i0 && + hpgs_reader_label(reader,str+i0,i-i0, + reader->alternate_font ? + reader->alternate_face : + reader->default_face, + reader->alternate_font ? + reader->alternate_encoding : + reader->default_encoding, + reader->alternate_font ? + reader->alternate_posture : + reader->default_posture, + reader->alternate_font ? + reader->alternate_weight : + reader->default_weight, + &left_vec, + &up_vec, + &space_vec)) + return -1; + + reader->current_point.x -= adj.x; + reader->current_point.y -= adj.y; + + adj.x = 0.0; + adj.y = 0.0; + + if (i >= HPGS_MAX_LABEL_SIZE || str[i] == 0) break; + + i0 = i+1; + + switch (str[i]) + { + case 8: // backspace + reader->current_point.x -= space_vec.x; + reader->current_point.y -= space_vec.y; + break; + + case 9: // horizontal tab. + reader->current_point.x += space_vec.x * (8 - ipos % 8); + reader->current_point.y += space_vec.y * (8 - ipos % 8); + ipos += (8 - ipos % 8); + break; + + case 10: // linefeed. + reader->cr_point.x += lf_vec.x; + reader->cr_point.y += lf_vec.y; + reader->current_point.x += lf_vec.x; + reader->current_point.y += lf_vec.y; + break; + + case 13: // carriage return. + reader->current_point.x = reader->cr_point.x; + reader->current_point.y = reader->cr_point.y; + ipos=0; + break; + + case 14: // shift out. + reader->alternate_font = 1; + break; + + case 15: // shift in. + reader->alternate_font = 0; + break; + + default: + if (reader->verbosity >= 1) + hpgs_log(hpgs_i18n("LB: Ignoring unknown control character <%d>.\n"), + (int)str[i]); + } + } + + return 0; +} + +/* + HPGL command MG (MessaGe) +*/ +int hpgs_reader_do_MG (hpgs_reader *reader) +{ + char str[HPGS_MAX_LABEL_SIZE]; + + if (reader->eoc) return 0; + + if (hpgs_reader_read_new_string(reader,str)) return -1; + + if (reader->verbosity >= 1) + hpgs_log(hpgs_i18n("Message <%.*s>.\n"),HPGS_MAX_LABEL_SIZE,str); + + return 0; +} diff --git a/src/add-ons/translators/hpgs/lib/hpgsdevices.c b/src/add-ons/translators/hpgs/lib/hpgsdevices.c new file mode 100644 index 0000000000..55af32d5d4 --- /dev/null +++ b/src/add-ons/translators/hpgs/lib/hpgsdevices.c @@ -0,0 +1,1765 @@ +/*********************************************************************** + * * + * $Id: hpgsdevices.c 373 2007-01-24 13:43:04Z softadm $ + * * + * hpgs - HPGl Script, a hpgl/2 interpreter, which uses a Postscript * + * API for rendering a scene and thus renders to a variety of * + * devices and fileformats. * + * * + * (C) 2004-2006 ev-i Informationstechnologie GmbH http://www.ev-i.at * + * * + * Author: Wolfgang Glas * + * * + * hpgs is free software; you can redistribute it and/or * + * modify it under the terms of the GNU Lesser General Public * + * License as published by the Free Software Foundation; either * + * version 2.1 of the License, or (at your option) any later version. * + * * + * hpgs is distributed in the hope that it will be useful, * + * but WITHOUT ANY WARRANTY; without even the implied warranty of * + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * + * Lesser General Public License for more details. * + * * + * You should have received a copy of the GNU Lesser General Public * + * License along with this library; if not, write to the * + * Free Software Foundation, Inc., 59 Temple Place, Suite 330, * + * Boston, MA 02111-1307 USA * + * * + *********************************************************************** + * * + * The implementations of the simple plotsize and eps devices. * + * * + ***********************************************************************/ + +#include +#include +#include +#include +#ifdef WIN32 +#include +#else +#include +#endif +#if defined ( __MINGW32__ ) || defined ( _MSC_VER ) +#include +#include +#else +#include +#include +#endif + +//#define HPGS_EPS_DEBUG_ROP3 + +/*! \defgroup device Basic vector graphics devices. + + This group contains the definitions for the abstract vector graphics device + \c hpgs_device as well as the implementations of the two very basic + vector devices \c hpgs_plotsize_device ans \c hpgs_eps_device. + */ + +/*! + Returns the name of the device for use with RTTI, runtime type information. + */ +const char *hpgs_device_rtti(hpgs_device *_this) +{ + return _this->vtable->rtti; +} + +/*! Sets the raster operation for the given device. + Raster operations and source/pattern transparency are described in + + PCL 5 Comparison Guide, Edition 2, 6/2003, Hewlett Packard + (May be downloaded as bpl13206.pdf from http://www.hp.com) + + The function returns -1, if an invalid raster operation is specified. + If the device is not capable of raster operations, the function succeeds + anyways. +*/ +int hpgs_setrop3 (hpgs_device *_this, int rop, + hpgs_bool src_transparency, hpgs_bool pattern_transparency) +{ + if (!_this->vtable->setrop3) return 0; + + return _this->vtable->setrop3(_this,rop, + src_transparency,pattern_transparency); +} + +/*! Sets the patter ncolor applied using the raster operation specified + in \c hpgs_setrop3. +*/ +int hpgs_setpatcol (hpgs_device *_this, const hpgs_color *rgb) +{ + if (!_this->vtable->setpatcol) return 0; + + return _this->vtable->setpatcol(_this,rgb); +} + +/*! Draw an image to the device. + The arguments \c ll, \c lr and \c ur are the + lower left, lower right and upper right corner of the drawn image + in world coordinates. + + The function returns 0 on success. + -1 is returned upon failure. +*/ +int hpgs_drawimage(hpgs_device *_this, const hpgs_image *img, + const hpgs_point *ll, const hpgs_point *lr, + const hpgs_point *ur) +{ + if (!_this->vtable->drawimage) return 0; + + return _this->vtable->drawimage(_this,img,ll,lr,ur); +} + +/*! Report a HPGL PS command to the device. If the function returns 2, + the interpretation of the file is interrupted immediately without error. + + For devices with the \c HPGS_DEVICE_CAP_MULTISIZE capability, this function + may be called immediately after a showpage command. +*/ +int hpgs_setplotsize (hpgs_device *_this, const hpgs_bbox *bb) +{ + if (!_this->vtable->setplotsize) + return 0; + + return _this->vtable->setplotsize(_this,bb); +} + +/*! Gets the plotsize of the given page number \c i or the overall bounding box, + if \c i is zero. + + The function returns 0 on success. + + If the function returns 1, the overall bounding box is returned, + because the plotsize of page \c i is not known. + + -1 is returned, if the funtion is unimplemented for the given device. +*/ +int hpgs_getplotsize (hpgs_device *_this, int i, hpgs_bbox *bb) +{ + if (!_this->vtable->getplotsize) + return -1; + + return _this->vtable->getplotsize(_this,i,bb); +} + +/*! Finishes the output of a page to the device. If the function returns 2, + the interpretation of the file is interrupted immediately without error. + This is the case for device, which are not capable of displaying multiple + pages. + + The integer argument is the number of the page begin finished. + This argument is intended as a hint for devices, which write a file + for each page. + + If this argument is less than or equal to 0, this is the only page + written to the device. In this case, devices which write a file for + each page may omit a page counter from the filename of the written + file. +*/ +int hpgs_showpage (hpgs_device *_this, int i) +{ + if (!_this->vtable->showpage) + return 0; + + return _this->vtable->showpage(_this,i); +} + +/*! Finishes the output of a document to the device. + Implementations of device should discard all output, + which has been undertaken since the past showpage call. +*/ +int hpgs_device_finish (hpgs_device *_this) +{ + if (!_this->vtable->finish) + return 0; + + return _this->vtable->finish(_this); +} + + +/*! Destroys the given device and frees all allocated resources by this device. +*/ +void hpgs_device_destroy (hpgs_device *_this) +{ + _this->vtable->destroy(_this); + free(_this); +} + +static int eps_expand_media_sizes(hpgs_eps_device *eps) +{ + int n = eps->media_sizes_alloc_size*2; + hpgs_ps_media_size *nnms = realloc(eps->media_sizes,sizeof(hpgs_bbox)*n); + + if (!nnms) + return hpgs_set_error(hpgs_i18n("Out of memory expanding page size stack.")); + + eps->media_sizes=nnms; + eps->media_sizes_alloc_size=n; + return 0; +} + +#define HPGS_MEDIA_SIZE_HASH(w,h) (size_t)((419430343*((size_t)(w)))^((size_t)(h))) + +static int eps_get_papersize (hpgs_eps_device *eps, + char *name, size_t name_len, + double w, double h) +{ + int paper_width = (int)ceil(w); + int paper_height = (int)ceil(h); + size_t hash = HPGS_MEDIA_SIZE_HASH(paper_width,paper_height); + int i0 = 0; + int i1 = eps->n_media_sizes; + + // binary search for hash; + while (i1>i0) + { + int i = i0+(i1-i0)/2; + + if (eps->media_sizes[i].hash < hash) + i0 = i+1; + else + i1 = i; + } + + i1 = 0; + + // search all media sizes with equal hash + while (i0 < eps->n_media_sizes && + eps->media_sizes[i0].hash == hash) + { + if (eps->media_sizes[i0].width == paper_width && + eps->media_sizes[i0].height == paper_height ) + { i1 = 1; break; } + + ++i0; + } + + if (i1) + { + ++eps->media_sizes[i0].usage; + } + else + { + // no page size found -> make a new one + if (eps->n_media_sizes>=eps->media_sizes_alloc_size && + eps_expand_media_sizes(eps)) + return -1; + + if (i0 < eps->n_media_sizes) + memmove (eps->media_sizes+i0+1,eps->media_sizes+i0, + sizeof(hpgs_ps_media_size) * (eps->n_media_sizes-i0)); + + eps->media_sizes[i0].width = paper_width; + eps->media_sizes[i0].height = paper_height; + eps->media_sizes[i0].name = 0; + eps->media_sizes[i0].usage = 1; + eps->media_sizes[i0].hash = hash; + } + + // fill in media size. + if (eps->media_sizes[i0].name) + { + strcpy(name,eps->media_sizes[i0].name); + } + else + { +#ifdef WIN32 + _snprintf(name,name_len,"Custom%dx%d", + paper_width,paper_height); +#else + snprintf(name,name_len,"Custom%dx%d", + paper_width,paper_height); +#endif + } + return 0; +} + + +static int eps_startpage (hpgs_eps_device *eps) +{ + if (eps->n_pages < 0) + { + // EPS page file start + eps->out = hpgs_new_file_ostream (eps->filename); + + if (!eps->out) + return hpgs_set_error(hpgs_i18n("Error opening file %s: %s"), + eps->filename,strerror(errno)); + + if (hpgs_ostream_printf (eps->out, + "%%!PS-Adobe-3.0 EPSF-3.0\n" + "%%%%Creator: hpgs-%s\n" + "%%%%Title: %s\n" + "%%%%BoundingBox: %d %d %d %d\n" + "%%%%HiResBoundingBox: %g %g %g %g\n" + "/hpgsdict 20 dict def\n" + "hpgsdict begin\n" + "/B{bind def} bind def\n" + "/r{setrgbcolor}B/w{setlinewidth}B/j{setlinejoin}B/J{setlinecap}B/M{setmiterlimit}B\n" + "/d{setdash}B/n{newpath}B/h{closepath}B/m{moveto}B/l{lineto}B/c{curveto}B\n" + "/s{stroke}B/f{fill}B/g{eofill}B/x{clip}B/y{eoclip}B/cs{gsave}B\n" + "/cr{currentrgbcolor currentlinewidth currentlinecap currentlinejoin currentmiterlimit currentdash grestore setdash setmiterlimit setlinejoin setlinecap setlinewidth setrgbcolor}B\n" + "end\n" + "%%EndComments\n" + "%%EndProlog\n" + "hpgsdict begin\n" + "gsave\n", + HPGS_VERSION, + eps->filename ? eps->filename : "(stdout)", + (int)floor(eps->page_bb.llx),(int)floor(eps->page_bb.lly), + (int)ceil(eps->page_bb.urx),(int)ceil(eps->page_bb.ury), + eps->page_bb.llx,eps->page_bb.lly, + eps->page_bb.urx,eps->page_bb.ury ) < 0) + { + hpgs_ostream_close(eps->out); + eps->out = 0; + return hpgs_set_error(hpgs_i18n("Error writing header of file %s: %s"), + eps->filename?eps->filename:"(stdout)", + strerror(errno)); + } + eps->page_setup = HPGS_TRUE; + } + else + { + hpgs_bbox bb; + char paper_name[32]; + double paper_width = eps->page_bb.urx; + double paper_height = eps->page_bb.ury; + + hpgs_bool landscape = paper_width > paper_height; + + if (eps_get_papersize(eps,paper_name,sizeof(paper_name), + landscape ? paper_height : paper_width, + landscape ? paper_width : paper_height)) + return -1; + + if (landscape) + { + if (hpgs_ostream_printf (eps->out, + "%%%%Page: %d %d\n" + "%%%%PageMedia: %s\n" + "%%%%PageOrientation: Landscape\n" + "hpgsdict begin\n" + "gsave\n" + "%.8f %.8f translate\n" + "90 rotate\n", + eps->n_pages+1,eps->n_pages+1,paper_name, + paper_height,0.0 ) < 0) + return hpgs_set_error(hpgs_i18n("Error writing header of file %s: %s"), + eps->filename?eps->filename:"(stdout)", + strerror(errno)); + + + // caclulate the bounding box on the page. + bb.llx = 0.0; + bb.lly = 0.0; + bb.urx = paper_height; + bb.ury = paper_width; + } + else + { + if (hpgs_ostream_printf (eps->out, + "%%%%Page: %d %d\n" + "%%%%PageMedia: %s\n" + "%%%%PageOrientation: Portrait\n" + "gsave\n", + eps->n_pages+1,eps->n_pages+1,paper_name ) < 0) + return hpgs_set_error(hpgs_i18n("Error writing header of file %s: %s"), + eps->filename?eps->filename:"(stdout)", + strerror(errno)); + + // calculate the bounding box on the page. + bb = eps->page_bb; + } + + // expand document bounding box. + if (eps->n_pages) + hpgs_bbox_expand(&eps->doc_bb,&bb); + else + eps->doc_bb = bb; + + ++eps->n_pages; + eps->page_setup = HPGS_TRUE; + } + + return 0; +} + + +static int eps_moveto (hpgs_device *_this, const hpgs_point *p) +{ + hpgs_eps_device *eps = (hpgs_eps_device *)_this; + + if (!eps->page_setup && eps_startpage(eps)) return -1; + + if (hpgs_ostream_printf(eps->out,"%g %g m\n",p->x,p->y) < 0) + return hpgs_set_error("moveto: %s",strerror(errno)); + return 0; +} + +static int eps_lineto (hpgs_device *_this, const hpgs_point *p) +{ + hpgs_eps_device *eps = (hpgs_eps_device *)_this; + + if (!eps->page_setup && eps_startpage(eps)) return -1; + + if (hpgs_ostream_printf(eps->out,"%g %g l\n",p->x,p->y) < 0) + return hpgs_set_error("lineto: %s",strerror(errno)); + return 0; +} + +static int eps_curveto (hpgs_device *_this, const hpgs_point *p1, + const hpgs_point *p2, const hpgs_point *p3 ) +{ + hpgs_eps_device *eps = (hpgs_eps_device *)_this; + + if (!eps->page_setup && eps_startpage(eps)) return -1; + + if (hpgs_ostream_printf(eps->out,"%g %g %g %g %g %g c\n", + p1->x,p1->y,p2->x,p2->y,p3->x,p3->y) < 0) + return hpgs_set_error("curveto: %s",strerror(errno)); + return 0; +} + +static int eps_newpath (hpgs_device *_this) +{ + hpgs_eps_device *eps = (hpgs_eps_device *)_this; + + if (!eps->page_setup && eps_startpage(eps)) return -1; + + if (hpgs_ostream_printf(eps->out,"n\n") < 0) + return hpgs_set_error("newpath: %s",strerror(errno)); + return 0; +} + +static int eps_closepath (hpgs_device *_this) +{ + hpgs_eps_device *eps = (hpgs_eps_device *)_this; + + if (!eps->page_setup && eps_startpage(eps)) return -1; + + if (hpgs_ostream_printf(eps->out,"h\n") < 0) + return hpgs_set_error("closepath: %s",strerror(errno)); + return 0; +} + +static int eps_stroke (hpgs_device *_this) +{ + hpgs_eps_device *eps = (hpgs_eps_device *)_this; + + if (!eps->page_setup && eps_startpage(eps)) return -1; + + if (hpgs_ostream_printf(eps->out,"s\n") < 0) + return hpgs_set_error("stroke: %s",strerror(errno)); + return 0; +} + +static int eps_fill (hpgs_device *_this, hpgs_bool winding) +{ + hpgs_eps_device *eps = (hpgs_eps_device *)_this; + + if (!eps->page_setup && eps_startpage(eps)) return -1; + + if (hpgs_ostream_printf(eps->out,winding ? "f\n" : "g\n") < 0) + return hpgs_set_error("fill: %s",strerror(errno)); + return 0; +} + +static int eps_clip (hpgs_device *_this, hpgs_bool winding) +{ + hpgs_eps_device *eps = (hpgs_eps_device *)_this; + + if (!eps->page_setup && eps_startpage(eps)) return -1; + + if (hpgs_ostream_printf(eps->out,winding ? "x\n" : "y\n") < 0) + return hpgs_set_error("clip: %s",strerror(errno)); + return 0; +} + +static int eps_clipsave (hpgs_device *_this) +{ + hpgs_eps_device *eps = (hpgs_eps_device *)_this; + + if (!eps->page_setup && eps_startpage(eps)) return -1; + + if (hpgs_ostream_printf(eps->out,"cs\n") < 0) + return hpgs_set_error("clipsave: %s",strerror(errno)); + return 0; +} + +static int eps_cliprestore (hpgs_device *_this) +{ + hpgs_eps_device *eps = (hpgs_eps_device *)_this; + + if (!eps->page_setup && eps_startpage(eps)) return -1; + + if (hpgs_ostream_printf(eps->out,"cr\n") < 0) + return hpgs_set_error("cliprestore: %s",strerror(errno)); + return 0; +} + +static int eps_setrgbcolor (hpgs_device *_this, const hpgs_color *rgb) +{ + hpgs_eps_device *eps = (hpgs_eps_device *)_this; + + if (!eps->page_setup && eps_startpage(eps)) return -1; + + if (hpgs_ostream_printf(eps->out,"%g %g %g r\n",rgb->r,rgb->g,rgb->b) < 0) + return hpgs_set_error("setrgbcolor: %s",strerror(errno)); + + eps->color = *rgb; + return 0; +} + +static int eps_setdash (hpgs_device *_this, const float *segs, + unsigned n, double d) +{ + unsigned i; + hpgs_eps_device *eps = (hpgs_eps_device *)_this; + + if (!eps->page_setup && eps_startpage(eps)) return -1; + + if (hpgs_ostream_printf(eps->out,"[ ")<0) return 1; + + for (i=0;iout,"%f ",(double)segs[i])<0) + return hpgs_set_error("setdash: %s",strerror(errno)); + + if (hpgs_ostream_printf(eps->out,"] %g d\n",d)<0) + return hpgs_set_error("setdash: %s",strerror(errno)); + return 0; +} + +static int eps_setlinewidth(hpgs_device *_this, double lw) +{ + hpgs_eps_device *eps = (hpgs_eps_device *)_this; + + if (!eps->page_setup && eps_startpage(eps)) return -1; + + if (hpgs_ostream_printf(eps->out,"%g w\n",lw) < 0) + return hpgs_set_error("setlinewidth: %s",strerror(errno)); + return 0; +} + +static int eps_setlinecap (hpgs_device *_this, hpgs_line_cap lc) +{ + hpgs_eps_device *eps = (hpgs_eps_device *)_this; + + if (!eps->page_setup && eps_startpage(eps)) return -1; + + if (hpgs_ostream_printf(eps->out,"%d J\n",(int)lc) < 0) + return hpgs_set_error("setlinecap: %s",strerror(errno)); + return 0; +} + +static int eps_setlinejoin (hpgs_device *_this, hpgs_line_join lj) +{ + hpgs_eps_device *eps = (hpgs_eps_device *)_this; + + if (!eps->page_setup && eps_startpage(eps)) return -1; + + if (hpgs_ostream_printf(eps->out,"%d j\n",(int)lj) < 0) + return hpgs_set_error("setlinejoin: %s",strerror(errno)); + return 0; +} + +static int eps_setmiterlimit (hpgs_device *_this, double l) +{ + hpgs_eps_device *eps = (hpgs_eps_device *)_this; + + if (!eps->page_setup && eps_startpage(eps)) return -1; + + if (hpgs_ostream_printf(eps->out,"%g M\n",l) < 0) + return hpgs_set_error("setmiterlimit: %s",strerror(errno)); + return 0; +} + +static int eps_setrop3 (hpgs_device *_this, int rop, + hpgs_bool src_transparency, hpgs_bool pattern_transparency) +{ + hpgs_eps_device *eps = (hpgs_eps_device *)_this; + hpgs_xrop3_func_t rop3; + + if (!eps->rop3) return 0; + +#ifdef HPGS_EPS_DEBUG_ROP3 + hpgs_log("setrop3: rop,src_trans,pat_trans=%d,%d,%d.\n", + rop,src_transparency,pattern_transparency); +#endif + rop3 = hpgs_xrop3_func(rop,src_transparency,pattern_transparency); + + if (!rop3) + return hpgs_set_error("setrop3: Invalid ROP3 %d specified",rop); + + eps->rop3 = rop3; + return 0; +} + +static int eps_setpatcol(hpgs_device *_this, const hpgs_color *rgb) +{ + hpgs_eps_device *eps = (hpgs_eps_device *)_this; + + eps->pattern_color.r = (unsigned char)(rgb->r * 255.0); + eps->pattern_color.g = (unsigned char)(rgb->g * 255.0); + eps->pattern_color.b = (unsigned char)(rgb->b * 255.0); + +#ifdef HPGS_EPS_DEBUG_ROP3 + hpgs_log("setpatcol: patcol=%g,%g,%g.\n",rgb->r,rgb->g,rgb->b); +#endif + + return 0; +} + +static int eps_drawimage(hpgs_device *_this, const hpgs_image *img, + const hpgs_point *ll, const hpgs_point *lr, + const hpgs_point *ur) +{ + static const char *hex_4_bit = "0123456789abcdef"; + hpgs_eps_device *eps = (hpgs_eps_device *)_this; + int i,j; + hpgs_point ul; + int ret = -1; + + if (!img) + return hpgs_set_error("drawimage: Null image specified."); + + if (!eps->page_setup && eps_startpage(eps)) return -1; + + ul.x = ll->x + (ur->x - lr->x); + ul.y = ll->y + (ur->y - lr->y); + + hpgs_palette_color *data = (hpgs_palette_color *) + malloc(img->width*img->height*sizeof(hpgs_palette_color)); + + int have_clip = 0; + + // data aqusition. + if (eps->rop3) + { + hpgs_color rgb = eps->color; + + switch (hpgs_image_rop3_clip(_this,data,img, + ll,lr,ur, + &eps->pattern_color,eps->rop3)) + { + case 0: + // invisible. + ret = 0; + goto cleanup; + case 1: + // clipped. + have_clip = 1; + case 2: + // totally visible. + break; + case 3: + // optimized to a single color. + eps->color = rgb; + if (hpgs_ostream_printf(eps->out,"%g %g %g r\n", + eps->color.r,eps->color.g,eps->color.b) >= 0) + ret = 0; + goto cleanup; + default: + goto cleanup; + } + } + else + { + hpgs_palette_color *d = data; + + for (j=0; jheight;++j) + { + hpgs_paint_color c; + + for (i=0; iwidth;++i,++d) + { + hpgs_image_get_pixel(img,i,j,&c,(double *)0/*alpha*/); + d->r = c.r; + d->g = c.g; + d->b = c.b; + } + } + } + + if (!have_clip) + hpgs_ostream_printf(eps->out, + "gsave\n"); + + if (hpgs_ostream_printf(eps->out, + "[ %g %g %g %g %g %g ] concat\n" + "%d %d 8\n" + "[ %d 0 0 %d 0 0 ]\n" + "{ currentfile %d string readhexstring pop }\n" + "dup dup true 3 colorimage\n", + lr->x-ll->x,lr->y-ll->y,lr->x-ur->x,lr->y-ur->y,ul.x,ul.y, + img->width,img->height, + img->width,img->height,img->width) < 0) + { hpgs_set_error("drawimage: %s",strerror(errno)); goto cleanup; } + + // write data + for (j=0; jheight; ++j) + { + hpgs_palette_color *scanline = data + j * img->width; + + for (i=0; iwidth; i++) + { + hpgs_ostream_putc(hex_4_bit[scanline[i].r>>4],eps->out); + hpgs_ostream_putc(hex_4_bit[scanline[i].r&0xf],eps->out); + } + for (i=0; iwidth; i++) + { + hpgs_ostream_putc(hex_4_bit[scanline[i].g>>4],eps->out); + hpgs_ostream_putc(hex_4_bit[scanline[i].g&0xf],eps->out); + } + for (i=0; iwidth; i++) + { + hpgs_ostream_putc(hex_4_bit[scanline[i].b>>4],eps->out); + hpgs_ostream_putc(hex_4_bit[scanline[i].b&0xf],eps->out); + } + } + + if (hpgs_ostream_printf(eps->out,"\ngrestore\n")<0) + { hpgs_set_error("drawimage: %s",strerror(errno)); goto cleanup; } + + ret = 0; + + cleanup: + free(data); + + return ret; +} + +static int eps_showpage (hpgs_device *_this, int i) +{ + hpgs_eps_device *eps = (hpgs_eps_device *)_this; + + if (!eps->out) return 0; + + if (hpgs_ostream_printf(eps->out,"grestore\nshowpage\nend\n") < 0) + return hpgs_set_error("showpage: %s",strerror(errno)); + + // write an eps file, if we are not in multipage mode. + if (eps->n_pages<0) + { + if (hpgs_ostream_printf(eps->out,"%%%%EOF\n")<0 || + hpgs_ostream_close(eps->out) < 0) + return hpgs_set_error("showpage: %s",strerror(errno)); + + eps->out = 0; + + if (i > 0 && eps->filename) + { + int l = strlen(eps->filename); + char *fn = hpgs_alloca(l+20); + char *dot = strrchr(eps->filename,'.'); + int pos = dot ? dot-eps->filename : l; + +#ifdef WIN32 + _snprintf(fn,l+20,"%.*s%4.4d%s", + pos,eps->filename,i,eps->filename+pos); +#else + snprintf(fn,l+20,"%.*s%4.4d%s", + pos,eps->filename,i,eps->filename+pos); +#endif + l = rename(eps->filename,fn); + + if (l<0) + return hpgs_set_error(hpgs_i18n("Error moving file %s to %.*s%4.4d%s.eps: %s"), + eps->filename, + pos,eps->filename,i,eps->filename+pos, + strerror(errno)); + } + } + + eps->page_setup = HPGS_FALSE; + + return 0; +} + +static int eps_setplotsize (hpgs_device *_this, const hpgs_bbox *bb) +{ + hpgs_eps_device *eps = (hpgs_eps_device *)_this; + + eps->page_bb = *bb; + + return 0; +} + +static int eps_capabilities (hpgs_device *_this) +{ + hpgs_eps_device *eps = (hpgs_eps_device *)_this; + + int ret = + HPGS_DEVICE_CAP_VECTOR | + HPGS_DEVICE_CAP_MULTIPAGE | + HPGS_DEVICE_CAP_MULTISIZE | + HPGS_DEVICE_CAP_DRAWIMAGE; + + if (eps->n_pages >= 0) + ret |= HPGS_DEVICE_CAP_PAGECOLLATION; + + if (eps->rop3) + ret |= HPGS_DEVICE_CAP_ROP3; + + return ret; +} + +static int eps_finish (hpgs_device *_this) +{ + hpgs_eps_device *eps = (hpgs_eps_device *)_this; + + if (!eps->out) return 0; + + if (eps->n_pages < 0) + { + // discard trailing output in EPS mode. + if (hpgs_ostream_close(eps->out) < 0) + { + eps->out = 0; + return hpgs_set_error("finish: %s",strerror(errno)); + } + + eps->out = 0; + + if (eps->filename && unlink(eps->filename)<0) + return hpgs_set_error(hpgs_i18n("Error removing file %s: %s"), + eps->filename,strerror(errno)); + } + else + { + // now really write the postscript file + int i,i_media=0; + hpgs_istream *buffer; + + hpgs_ostream *out = hpgs_new_file_ostream (eps->filename); + + if (!out) + return hpgs_set_error(hpgs_i18n("Error opening file %s: %s"), + eps->filename,strerror(errno)); + + if (hpgs_ostream_flush(eps->out) <0 || + (buffer =hpgs_ostream_getbuf(eps->out)) == 0) + return hpgs_set_error(hpgs_i18n("Error getting page stream data")); + + hpgs_ostream_printf (out, + "%%!PS-Adobe-3.0\n" + "%%%%Creator: hpgs-%s\n" + "%%%%Title: %s\n" + "%%%%Pages: %d\n" + "%%%%BoundingBox: %d %d %d %d\n" + "%%%%HiResBoundingBox: %.3f %.3f %.3f %.3f\n" + "%%%%DocumentMedia:", + HPGS_VERSION, + eps->filename ? eps->filename : "(stdout)", + eps->n_pages, + (int)floor(eps->doc_bb.llx),(int)floor(eps->doc_bb.lly), + (int)ceil(eps->doc_bb.urx),(int)ceil(eps->doc_bb.ury), + eps->doc_bb.llx,eps->doc_bb.lly, + eps->doc_bb.urx,eps->doc_bb.ury); + + // write paper sizes. + for (i=0;in_media_sizes;++i) + if (eps->media_sizes[i].usage) + { + if (eps->media_sizes[i].name) + hpgs_ostream_printf (out,"%s %s %d %d 75 white()\n", + i_media ? "%%+" : "", + eps->media_sizes[i].name, + eps->media_sizes[i].width, + eps->media_sizes[i].height ); + else + hpgs_ostream_printf (out,"%s Custom%dx%d %d %d 75 white()\n", + i_media ? "%%+" : "", + eps->media_sizes[i].width, + eps->media_sizes[i].height, + eps->media_sizes[i].width, + eps->media_sizes[i].height ); + + ++i_media; + } + + hpgs_ostream_printf (out, + "%%%%EndComments\n" + "/hpgsdict 20 dict def\n" + "hpgsdict begin\n" + "/B{bind def} bind def\n" + "/r{setrgbcolor}B/w{setlinewidth}B/j{setlinejoin}B/J{setlinecap}B/M{setmiterlimit}B\n" + "/d{setdash}B/n{newpath}B/h{closepath}B/m{moveto}B/l{lineto}B/c{curveto}B\n" + "/s{stroke}B/f{fill}B/g{eofill}B/x{clip}B/y{eoclip}B/cs{gsave}B\n" + "/cr{currentrgbcolor currentlinewidth currentlinecap currentlinejoin currentmiterlimit currentdash grestore setdash setmiterlimit setlinejoin setlinecap setlinewidth setrgbcolor}B\n" + "end\n" + "%%%%EndProlog\n"); + + hpgs_copy_streams (out,buffer); + hpgs_istream_close(buffer); + + hpgs_ostream_printf (out,"%%%%EOF\n"); + + if (hpgs_ostream_iserror(out)) + { + if (eps->filename) + hpgs_ostream_close(out); + return hpgs_set_error(hpgs_i18n("Error writing file %s: %s"), + eps->filename?eps->filename:"(stdout)", + strerror(errno)); + } + + hpgs_ostream_close(out); + } + + return 0; +} + +static void eps_destroy (hpgs_device *_this) +{ + hpgs_eps_device *eps = (hpgs_eps_device *)_this; + if (eps->out) + hpgs_ostream_close(eps->out); + + if (eps->filename) + free(eps->filename); +} + +static hpgs_device_vtable eps_vtable = + { + "hpgs_eps_device", + eps_moveto, + eps_lineto, + eps_curveto, + eps_newpath, + eps_closepath, + eps_stroke, + eps_fill, + eps_clip, + eps_clipsave, + eps_cliprestore, + eps_setrgbcolor, + eps_setdash, + eps_setlinewidth, + eps_setlinecap, + eps_setlinejoin, + eps_setmiterlimit, + eps_setrop3, + eps_setpatcol, + eps_drawimage, + eps_setplotsize, + 0 /* eps_getplotsize */, + eps_showpage, + eps_finish, + eps_capabilities, + eps_destroy + }; + +/*! Retrieves the pointer to a new \c hpgs_eps_device on the heap, + which writes to the file with the gieven \c filename. + + The bounding box in the eps files is passed to this functions. + + If the file cannot be opened or the system is out of memory, + a null pointer is returned. +*/ +hpgs_eps_device *hpgs_new_eps_device(const char *filename, + const hpgs_bbox *bb, + hpgs_bool do_rop3) +{ + hpgs_eps_device *ret = (hpgs_eps_device *)malloc(sizeof(hpgs_eps_device)); + + if (!ret) + return 0; + + ret->out = 0; + ret->n_pages = -1; + ret->page_setup = HPGS_FALSE; + + if (filename) + { + ret->filename = strdup(filename); + + if (!ret->filename) + { + free(ret); + return 0; + } + } + else + ret->filename = 0; + + ret->pattern_color.r = 0; + ret->pattern_color.g = 0; + ret->pattern_color.b = 0; + + if (do_rop3) + ret->rop3 = hpgs_xrop3_func(252,HPGS_TRUE,HPGS_TRUE); + else + ret->rop3 = 0; + + ret->doc_bb = *bb; + ret->page_bb = *bb; + + ret->media_sizes_alloc_size = 0; + ret->n_media_sizes = 0; + ret->media_sizes = 0; + + ret->color.r = 0.0; + ret->color.g = 0.0; + ret->color.b = 0.0; + + ret->inherited.vtable=&eps_vtable; + + return ret; +} + +#define HPGS_STD_MEDIA_SIZE(w,h,n) {w,h,n,0,HPGS_MEDIA_SIZE_HASH(w,h)} + +static hpgs_ps_media_size ps_std_media_sizes[]= + { + HPGS_STD_MEDIA_SIZE(596 ,843 ,"A4"), + HPGS_STD_MEDIA_SIZE(843 ,1192,"A3"), + HPGS_STD_MEDIA_SIZE(1192,1686,"A2"), + HPGS_STD_MEDIA_SIZE(1686,2384,"A1"), + HPGS_STD_MEDIA_SIZE(2384,3371,"A0") + }; + +/* A helper for qsort */ +static int compare_media_hashes(const void *a, const void *b) +{ + const hpgs_ps_media_size *m1 = (const hpgs_ps_media_size *)a; + const hpgs_ps_media_size *m2 = (const hpgs_ps_media_size *)b; + + if (m1->hash < m2->hash) return -1; + if (m1->hash > m2->hash) return 1; + return 0; +} + + +/*! Retrieves the pointer to a new \c hpgs_eps_device on the heap, + which writes to a multipage PostScript file with the given \c filename. + + The overall document bounding box for the PostScript file is + passed as \c bb. + + If \c paper_width and \c paper_height are greater than zero, + the content of each page is scaled to this fixed paper format. + Otherwise, the paper size of each page adpats to the page + bounding box. + + The given \c border is used in order to place the contents on the + page. + + If the file cannot be opened or the system is out of memory, + a null pointer is returned. +*/ +hpgs_eps_device *hpgs_new_ps_device(const char *filename, + const hpgs_bbox *bb, + hpgs_bool do_rop3) +{ + hpgs_eps_device *ret = (hpgs_eps_device *)malloc(sizeof(hpgs_eps_device)); + + if (!ret) + return 0; + + ret->out = hpgs_new_mem_ostream(1024*1024); + + if (!ret->out) + { + free(ret); + return 0; + } + + ret->n_pages = 0; + ret->page_setup = HPGS_FALSE; + + if (filename) + { + ret->filename = strdup(filename); + + if (!ret->filename) + { + hpgs_ostream_close(ret->out); + free(ret); + return 0; + } + } + else + ret->filename = 0; + + ret->pattern_color.r = 0; + ret->pattern_color.g = 0; + ret->pattern_color.b = 0; + + if (do_rop3) + ret->rop3 = hpgs_xrop3_func(252,HPGS_TRUE,HPGS_TRUE); + else + ret->rop3 = 0; + + ret->doc_bb = *bb; + ret->page_bb = *bb; + + ret->media_sizes_alloc_size = 32; + ret->media_sizes = + (hpgs_ps_media_size*)malloc(sizeof(hpgs_ps_media_size)*ret->media_sizes_alloc_size); + + if (!ret->media_sizes) + { + hpgs_ostream_close(ret->out); + free(ret->filename); + free(ret); + return 0; + } + + // fill in std media sizes. + ret->n_media_sizes = sizeof(ps_std_media_sizes)/sizeof(hpgs_ps_media_size); + memcpy(ret->media_sizes,ps_std_media_sizes,sizeof(ps_std_media_sizes)); + + qsort(ret->media_sizes,ret->n_media_sizes, + sizeof(hpgs_ps_media_size),compare_media_hashes); + + ret->color.r = 0.0; + ret->color.g = 0.0; + ret->color.b = 0.0; + + ret->inherited.vtable=&eps_vtable; + + return ret; +} + +/*! + Plotsize device. +*/ +static int pls_expand_pages(hpgs_plotsize_device *pls) +{ + int i,n = pls->page_bbs_alloc_size*2; + hpgs_bbox *nbbs; + + if (pls->n_page_bbs > n) n=pls->n_page_bbs; + + nbbs = realloc(pls->page_bbs,sizeof(hpgs_bbox)*n); + + if (!nbbs) + return hpgs_set_error(hpgs_i18n("Out of memory expanding page size stack.")); + + pls->page_bbs=nbbs; + + for (i=pls->page_bbs_alloc_size;ipage_bbs+i); + + pls->page_bbs_alloc_size=n; + return 0; +} + +static int pls_moveto (hpgs_device *_this, const hpgs_point *p) +{ + hpgs_plotsize_device *pls = (hpgs_plotsize_device *)_this; + + pls->moveto = *p; + pls->deferred_moveto = 1; + + return 0; +} + +static int pls_lineto (hpgs_device *_this, const hpgs_point *p) +{ + hpgs_plotsize_device *pls = (hpgs_plotsize_device *)_this; + + if (pls->deferred_moveto) + { + hpgs_bbox_add(&pls->path_bb,&pls->moveto); + pls->deferred_moveto = 0; + } + + hpgs_bbox_add(&pls->path_bb,p); + pls->moveto = *p; + + return 0; +} + +static void add_bezier(hpgs_plotsize_device *pls, + const hpgs_point *p0, const hpgs_point *p1, + const hpgs_point *p2, const hpgs_point *p3, + int depth ) +{ + hpgs_point ll = { HPGS_MIN(p0->x,p3->x),HPGS_MIN(p0->y,p3->y) }; + hpgs_point ur = { HPGS_MAX(p0->x,p3->x),HPGS_MAX(p0->y,p3->y) }; + + // p1 and p2 inside bbox of p0 and p3. + if (depth > 2 || + p1->x < ll.x || p2->x < ll.x || + p1->y < ll.y || p2->y < ll.y || + p1->x > ur.x || p2->x > ur.x || + p1->y > ur.y || p2->y > ur.y ) + { + hpgs_bbox_add(&pls->path_bb,p3); + } + else + { + // split spline + hpgs_point p1l = { 0.5 * (p0->x + p1->x), 0.5 * (p0->y + p1->y) }; + hpgs_point p2l = { 0.25 * (p0->x + p2->x) + 0.5 * p1->x, 0.25 * (p0->y + p2->y) + 0.5 * p1->y }; + hpgs_point pm = { (p0->x + p3->x) * 0.125 + 0.375 * (p1->x + p2->x), (p0->y + p3->y) * 0.125 + 0.375 * (p1->y + p2->y) }; + hpgs_point p1u = { 0.25 * (p1->x + p3->x) + 0.5 * p2->x, 0.25 * (p1->y + p3->y) + 0.5 * p2->y }; + hpgs_point p2u = { 0.5 * (p2->x + p3->x), 0.5 * (p2->y + p3->y) }; + + add_bezier(pls,p0,&p1l,&p2l,&pm,depth+1); + add_bezier(pls,&pm,&p1u,&p2u,p3,depth+1); + } +} + +static int pls_curveto (hpgs_device *_this, const hpgs_point *p1, + const hpgs_point *p2, const hpgs_point *p3 ) +{ + hpgs_plotsize_device *pls = (hpgs_plotsize_device *)_this; + + if (pls->deferred_moveto) + { + hpgs_bbox_add(&pls->path_bb,&pls->moveto); + pls->deferred_moveto = 0; + } + + add_bezier(pls,&pls->moveto,p1,p2,p3,0); + + pls->moveto = *p3; + + return 0; +} + +static int pls_addpath (hpgs_device *_this, hpgs_bool do_linewidth) +{ + hpgs_plotsize_device *pls = (hpgs_plotsize_device *)_this; + + if (do_linewidth) + { + hpgs_bbox_addborder(&pls->path_bb,0.5 * pls->linewidth); + } + + if (pls->clip_depth >= 0) + { + hpgs_bbox_intersect(&pls->path_bb,pls->clip_bbs+pls->clip_depth); + + // check for null intersection + if (hpgs_bbox_isnull(&pls->path_bb)) + goto get_out; + } + + hpgs_bbox_expand(&pls->page_bb,&pls->path_bb); + hpgs_bbox_expand(&pls->global_bb,&pls->path_bb); + + get_out: + hpgs_bbox_null(&pls->path_bb); + + pls->moveto.x = 0.0; + pls->moveto.y = 0.0; + pls->deferred_moveto = 0; + + return 0; +} + +static int pls_stroke (hpgs_device *_this) +{ + hpgs_plotsize_device *pls = (hpgs_plotsize_device *)_this; + + return pls_addpath (_this,pls->do_linewidth); +} + +static int pls_fill (hpgs_device *_this, hpgs_bool winding) +{ + return pls_addpath (_this,HPGS_FALSE); +} + +static int pls_closepath (hpgs_device *_this) +{ + hpgs_plotsize_device *pls = (hpgs_plotsize_device *)_this; + + pls->deferred_moveto = 1; + + return 0; +} + +static int pls_newpath (hpgs_device *_this) +{ + hpgs_plotsize_device *pls = (hpgs_plotsize_device *)_this; + + hpgs_bbox_null(&pls->path_bb); + + pls->moveto.x = 0.0; + pls->moveto.y = 0.0; + pls->deferred_moveto = 0; + + return 0; +} + +static int pls_clip (hpgs_device *_this, hpgs_bool winding) +{ + hpgs_plotsize_device *pls = (hpgs_plotsize_device *)_this; + + hpgs_bbox_intersect(pls->clip_bbs+pls->clip_depth,&pls->path_bb); + + return 0; +} + +static int pls_clipsave (hpgs_device *_this) +{ + hpgs_plotsize_device *pls = (hpgs_plotsize_device *)_this; + + if (pls->clip_depth+1 >= HPGS_PLOTSIZE_MAX_CLIP_DEPTH) + return hpgs_set_error(hpgs_i18n("Maximum clip depth %d exceeded."), + HPGS_PLOTSIZE_MAX_CLIP_DEPTH); + + pls->clip_bbs[pls->clip_depth+1] = pls->clip_bbs[pls->clip_depth] ; + + ++pls->clip_depth; + + return 0; +} + +static int pls_cliprestore (hpgs_device *_this) +{ + hpgs_plotsize_device *pls = (hpgs_plotsize_device *)_this; + --pls->clip_depth; + + if (pls->clip_depth < 0) + return hpgs_set_error("cliprestore: clip stack underflow."); + + return 0; +} + +static int pls_setlinewidth(hpgs_device *_this, double lw) +{ + hpgs_plotsize_device *pls = (hpgs_plotsize_device *)_this; + + pls->linewidth = lw; + return 0; +} + +static int pls_drawimage(hpgs_device *_this, const hpgs_image *img, + const hpgs_point *ll, const hpgs_point *lr, + const hpgs_point *ur) +{ + hpgs_point ul; + + ul.x = ll->x + (ur->x - lr->x); + ul.y = ll->y + (ur->y - lr->y); + + pls_newpath(_this); + pls_moveto(_this,ll); + pls_lineto(_this,lr); + pls_lineto(_this,ur); + pls_lineto(_this,&ul); + pls_addpath(_this,HPGS_FALSE); + + return 0; +} + +static int pls_showpage (hpgs_device *_this, int i) +{ + hpgs_plotsize_device *pls = (hpgs_plotsize_device *)_this; + + if (i>0) + { + if (pls->page_bb.urx < pls->page_bb.llx) + pls->page_bb.urx = pls->page_bb.llx = 0.0; + + if (pls->page_bb.ury < pls->page_bb.lly) + pls->page_bb.ury = pls->page_bb.lly = 0.0; + + if (i > pls->n_page_bbs) pls->n_page_bbs=i; + + if (pls->n_page_bbs > pls->page_bbs_alloc_size && + pls_expand_pages(pls)) + return -1; + + pls->page_bbs[i-1] = pls->page_bb; + } + + hpgs_bbox_null(&pls->page_bb); + + return 0; +} + +static int pls_finish (hpgs_device *_this) +{ + hpgs_plotsize_device *pls = (hpgs_plotsize_device *)_this; + + if (pls->global_bb.urx < pls->global_bb.llx) + pls->global_bb.urx = pls->global_bb.llx = 0.0; + + if (pls->global_bb.ury < pls->global_bb.lly) + pls->global_bb.ury = pls->global_bb.lly = 0.0; + + return 0; +} + +static int pls_capabilities (hpgs_device *_this) +{ + return + HPGS_DEVICE_CAP_PLOTSIZE | + HPGS_DEVICE_CAP_MULTIPAGE | + HPGS_DEVICE_CAP_MULTISIZE | + HPGS_DEVICE_CAP_NULLIMAGE; +} + +static void pls_destroy (hpgs_device *_this) +{ + hpgs_plotsize_device *pls = (hpgs_plotsize_device *)_this; + + if (pls->page_bbs) + free (pls->page_bbs); +} + +static int pls_setplotsize (hpgs_device *_this, const hpgs_bbox *bb) +{ + hpgs_plotsize_device *pls = (hpgs_plotsize_device *)_this; + + if (pls->ignore_ps) + return 0; + + pls->global_bb = *bb; + pls->page_bb = *bb; + + return 2; +} + +static int pls_getplotsize (hpgs_device *_this, int i, hpgs_bbox *bb) +{ + hpgs_plotsize_device *pls = (hpgs_plotsize_device *)_this; + + int ret = 0; + + if (i<=0 || i > pls->n_page_bbs) + { + *bb = pls->global_bb; + if (i>0) ret = 1; + } + else + *bb = pls->page_bbs[i-1]; + + return ret; +} + +static hpgs_device_vtable pls_vtable = + { + "hpgs_plotsize_device", + pls_moveto, + pls_lineto, + pls_curveto, + pls_newpath, + pls_closepath, + pls_stroke, + pls_fill, + pls_clip, + pls_clipsave, + pls_cliprestore, + 0 /* pls_setrgbcolor */, + 0 /* pls_setdash */, + pls_setlinewidth, + 0 /* pls_setlinecap */, + 0 /* pls_setlinejoin */, + 0 /* pls_setmiterlimit */, + 0 /* pls_setrop3 */, + 0 /* pls_setpatcol */, + pls_drawimage, + pls_setplotsize, + pls_getplotsize, + pls_showpage, + pls_finish, + pls_capabilities, + pls_destroy + }; + +/*! Retrieves the pointer to a new \c hpgs_plotsize_device on the heap. + + If \c ignore_ps is \c HPGS_TRUE, a HPGL PS statement is ignored an the + plotsize is calculated from the vector graphics contents. + + If \c do_linewidth is \c HPGS_TRUE, the current linewidth is + taken into account in the plotsize calculation. + + If the system is out of memory, a null pointer is returned. +*/ +hpgs_plotsize_device *hpgs_new_plotsize_device(hpgs_bool ignore_ps, + hpgs_bool do_linewidth) +{ + hpgs_plotsize_device *ret = + (hpgs_plotsize_device *)malloc(sizeof(hpgs_plotsize_device)); + + if (ret) + { + ret->n_page_bbs = 0; + ret->page_bbs_alloc_size = 32; + ret->page_bbs = malloc(sizeof(hpgs_bbox)*ret->page_bbs_alloc_size); + + if (!ret->page_bbs) + { + free(ret); + return 0; + } + + hpgs_bbox_null(&ret->path_bb); + hpgs_bbox_null(&ret->page_bb); + hpgs_bbox_null(&ret->global_bb); + ret->moveto.x = 0.0; + ret->moveto.y = 0.0; + ret->deferred_moveto = 0; + ret->clip_bbs[0].llx = -1.0e20; + ret->clip_bbs[0].lly = -1.0e20; + ret->clip_bbs[0].urx = 1.0e20; + ret->clip_bbs[0].ury = 1.0e20; + ret->clip_depth = 0; + ret->linewidth = 1.0; + ret->ignore_ps = ignore_ps; + ret->do_linewidth = do_linewidth; + ret->inherited.vtable=&pls_vtable; + } + + return ret; +} + +/* + Custom device from plugin. +*/ +typedef int (*hpgs_new_device_func_t)(hpgs_device **device, + void **page_asset_ctxt, + hpgs_reader_asset_func_t *page_asset_func, + void **frame_asset_ctxt, + hpgs_reader_asset_func_t *frame_asset_func, + const char *dev_name, + const char *filename, + const hpgs_bbox *bb, + double xres, double yres, + hpgs_bool do_rop3, + int argc, const char *argv[]); + +typedef void (*hpgs_plugin_version_func_t)(int *major, int *minor); + +typedef void (*hpgs_plugin_init_func_t)(); +typedef void (*hpgs_plugin_cleanup_func_t)(); + +typedef struct hpgs_plugin_ref_st hpgs_plugin_ref; + +#define HPGS_PLUGIN_NAME_LEN 8 + +struct hpgs_plugin_ref_st +{ + char name[HPGS_PLUGIN_NAME_LEN]; +#ifdef WIN32 + HMODULE handle; +#else + void *handle; +#endif + hpgs_new_device_func_t new_dev_func; + hpgs_plugin_version_func_t version_func; + hpgs_plugin_init_func_t init_func; + hpgs_plugin_init_func_t cleanup_func; +}; + +static hpgs_plugin_ref plugins[4] = + { { "",0,0,0}, { "",0,0,0}, { "",0,0,0}, { "",0,0,0} }; + +static void hpgs_cleanup_plugin(hpgs_plugin_ref *plugin) +{ + if (strlen(plugin->name) == 0) + return; + + if (plugin->cleanup_func) plugin->cleanup_func(); + +#ifdef WIN32 + if (!FreeLibrary(plugin->handle)) + hpgs_log("hpgs_cleanup_plugin_devices: unable to close plugin %s.\n", + plugin->name); +#else + if (dlclose(plugin->handle)) + hpgs_log("hpgs_cleanup_plugin_devices: unable to close plugin %s: %s.\n", + plugin->name,dlerror()); +#endif + + plugin->name[0] = '\0'; + plugin->handle = 0; + plugin->new_dev_func = 0; + plugin->version_func = 0; + plugin->init_func = 0; + plugin->cleanup_func = 0; +} + +void hpgs_cleanup_plugin_devices() +{ + int i; + + for (i=0;i= HPGS_PLUGIN_NAME_LEN) l = HPGS_PLUGIN_NAME_LEN-1; + + for (i=0;i=sizeof(plugins)/sizeof(hpgs_plugin_ref)) + { + hpgs_set_error(hpgs_i18n("hpgs_new_plugin_device: too much plugins registered (max %u).\n"), + (unsigned)(sizeof(plugins)/sizeof(hpgs_plugin_ref))); + return 0; + } + + if (!plugin) + { + char plugin_name[1024]; + plugin = plugins+i; + +#ifdef WIN32 + _snprintf(plugin_name,sizeof(plugin_name),"%s\\lib\\hpgs\\hpgs%.*splugin.%d.%d.dll", + hpgs_get_prefix(), + l,dev_name, + HPGS_MAJOR_VERSION,HPGS_MINOR_VERSION); + plugin->handle =LoadLibraryA(plugin_name); + + if (!plugin->handle) + { + hpgs_set_error(hpgs_i18n("hpgs_new_plugin_device: unable to open plugin %s.\n"), + plugin_name); + return 0; + } +#else + +#ifndef HPGS_LIBSFX +#define HPGS_LIBSFX "lib" +#endif + snprintf(plugin_name,sizeof(plugin_name),"%s/" HPGS_LIBSFX "/hpgs/hpgs%.*splugin.so.%d.%d", + hpgs_get_prefix(), + l,dev_name, + HPGS_MAJOR_VERSION,HPGS_MINOR_VERSION); + + plugin->handle = dlopen(plugin_name,RTLD_LAZY); + + if (!plugin->handle) + { + hpgs_set_error(hpgs_i18n("hpgs_new_plugin_device: unable to open plugin %s: %s.\n"), + plugin_name,dlerror()); + return 0; + } +#endif + memcpy(plugin->name,dev_name,l); + plugin->name[l]='\0'; + + plugin->version_func=0; + plugin->init_func=0; + plugin->cleanup_func=0; + plugin->new_dev_func=0; + } + + + if (! plugin->version_func) + { + int minor = 0; + int major = 0; +#ifdef WIN32 + plugin->version_func = + (hpgs_plugin_version_func_t)GetProcAddress(plugin->handle, + "hpgs_plugin_version"); + if (!plugin->version_func) + { + hpgs_cleanup_plugin(plugin); + hpgs_set_error(hpgs_i18n("hpgs_new_plugin_device: unable to resolve function hpgs_plugin_version.\n")); + return 0; + } +#else + plugin->version_func = + (hpgs_plugin_version_func_t)dlsym(plugin->handle, + "hpgs_plugin_version"); + if (!plugin->version_func) + { + hpgs_cleanup_plugin(plugin); + hpgs_set_error(hpgs_i18n("hpgs_new_plugin_device: unable to resolve function hpgs_plugin_version: %s.\n"), + dlerror()); + return 0; + } +#endif + + plugin->version_func(&major,&minor); + + if (major != HPGS_MAJOR_VERSION || + minor != HPGS_MINOR_VERSION ) + { + hpgs_cleanup_plugin(plugin); + hpgs_set_error(hpgs_i18n("hpgs_new_plugin_device: Plugin version %d.%d does not match application version %d.%d.\n"), + major,minor,HPGS_MAJOR_VERSION,HPGS_MINOR_VERSION); + + return 0; + } + +#ifdef WIN32 + plugin->init_func = + (hpgs_plugin_init_func_t)GetProcAddress(plugin->handle, + "hpgs_plugin_init"); + plugin->cleanup_func = + (hpgs_plugin_cleanup_func_t)GetProcAddress(plugin->handle, + "hpgs_plugin_cleanup"); +#else + plugin->init_func = + (hpgs_plugin_init_func_t)dlsym(plugin->handle, + "hpgs_plugin_init"); + plugin->cleanup_func = + (hpgs_plugin_cleanup_func_t)dlsym(plugin->handle, + "hpgs_plugin_cleanup"); +#endif + + if (plugin->init_func) plugin->init_func(); + } + + + if (!plugin->new_dev_func) + { +#ifdef WIN32 + plugin->new_dev_func = + (hpgs_new_device_func_t)GetProcAddress(plugin->handle, + "hpgs_plugin_new_device"); + if (!plugin->new_dev_func) + { + hpgs_cleanup_plugin(plugin); + hpgs_set_error(hpgs_i18n("hpgs_new_plugin_device: unable to resolve function hpgs_plugin_new_device.\n")); + return 0; + } +#else + plugin->new_dev_func = + (hpgs_new_device_func_t)dlsym(plugin->handle, + "hpgs_plugin_new_device"); + + if (!plugin->new_dev_func) + { + hpgs_cleanup_plugin(plugin); + hpgs_set_error(hpgs_i18n("hpgs_new_plugin_device: unable to resolve function hpgs_plugin_new_device: %s.\n"), + dlerror()); + return 0; + } +#endif + } + + return plugin->new_dev_func(device, + page_asset_ctxt,page_asset_func, + frame_asset_ctxt,frame_asset_func, + dev_name,filename,bb,xres,yres,do_rop3,argc,argv); +} diff --git a/src/add-ons/translators/hpgs/lib/hpgsdevices.h b/src/add-ons/translators/hpgs/lib/hpgsdevices.h new file mode 100644 index 0000000000..9e08ce2342 --- /dev/null +++ b/src/add-ons/translators/hpgs/lib/hpgsdevices.h @@ -0,0 +1,151 @@ +/*********************************************************************** + * * + * $Id: hpgsdevices.h 298 2006-03-05 18:18:03Z softadm $ + * * + * hpgs - HPGl Script, a hpgl/2 interpreter, which uses a Postscript * + * API for rendering a scene and thus renders to a variety of * + * devices and fileformats. * + * * + * (C) 2004-2006 ev-i Informationstechnologie GmbH http://www.ev-i.at * + * * + * Author: Wolfgang Glas * + * * + * hpgs is free software; you can redistribute it and/or * + * modify it under the terms of the GNU Lesser General Public * + * License as published by the Free Software Foundation; either * + * version 2.1 of the License, or (at your option) any later version. * + * * + * hpgs is distributed in the hope that it will be useful, * + * but WITHOUT ANY WARRANTY; without even the implied warranty of * + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * + * Lesser General Public License for more details. * + * * + * You should have received a copy of the GNU Lesser General Public * + * License along with this library; if not, write to the * + * Free Software Foundation, Inc., 59 Temple Place, Suite 330, * + * Boston, MA 02111-1307 USA * + * * + *********************************************************************** + * * + * The private interfaces for the basic devices * + * * + ***********************************************************************/ + +#ifndef __HPGS_DEVICES_H +#define __HPGS_DEVICES_H + +#include + +#ifdef __cplusplus +extern "C" { +#endif + +/*! \file hpgsdevices.h + + \brief The private interfaces for basic vector devices. + + A header file, which declares the structures and functions internally + used for implementing the very basic implementations of \c hpgs_device. +*/ + +/*! @addtogroup device + * @{ + */ + +#define HPGS_PLOTSIZE_MAX_CLIP_DEPTH 16 + +/*! \brief A vector graphics device for plotsize calculating. + + This structure implements a \c hpgs_device and is used to calculate + the bounding box of a vector graphics scenery. + */ +struct hpgs_plotsize_device_st { + hpgs_device inherited; //!< The base device structure. + + hpgs_bool ignore_ps; //!< Do we ignore a PS command? + int clip_depth; //!< The depth of the current clip path stack. + + hpgs_point moveto; //!< The position of the last moveto. + int deferred_moveto; //!< Do we have an unregistered moveto pending? + + hpgs_bool do_linewidth; //!< Do we account for the current linewidth? + double linewidth; //!< Current linewidth. + + hpgs_bbox clip_bbs[HPGS_PLOTSIZE_MAX_CLIP_DEPTH]; /*! The bounding boxes of the clip paths. */ + + hpgs_bbox path_bb; /*! The bounding box of the current path. */ + hpgs_bbox page_bb; /*! The bounding box of the current page. */ + hpgs_bbox global_bb; /*! The currently calculated overall bounding box. */ + + /*@{ */ + /*! A stack of page bounding boxes. + */ + hpgs_bbox *page_bbs; /*! The currently calculated overall bounding box. */ + int n_page_bbs; + int page_bbs_alloc_size; + /*@} */ +}; + +typedef struct hpgs_ps_media_size_st hpgs_ps_media_size; + +/*! \brief A structure for storing a paper size. + + This structure stores a PostScipt paper size. + */ +struct hpgs_ps_media_size_st +{ + int width; //!< The width of the paper in pt. + int height; //!< The height of the paper in pt. + + const char *name; //!< The name of this paper size, if it is a std paper size. + size_t usage; //!< The usage count of this paper size. + + size_t hash; //!< A hash value for storing media sizes in a sorted vector. +}; + +/*! \brief A vector graphics device for drawing to an eps file. + + This structure implements a \c hpgs_device and is used to write + a scenery to an eps file. + */ +struct hpgs_eps_device_st { + hpgs_device inherited; //!< The base device structure. + + hpgs_bbox doc_bb; + /*! The document bounding box used for multipage postscript files. */ + + hpgs_bbox page_bb; + /*! The bounding box of the current page. */ + + int n_pages; + /*! The number of pages. -1...we are writing individual eps files. */ + + char *filename; //!< The output filename. + + hpgs_ostream *out; //!< The current page stream. + hpgs_bool page_setup; //!< Is the current page set up? + + /*@{ */ + /*! A stack of media sizes for multipage PostScript files. + The media sizes are sorted by their hash value. + */ + hpgs_ps_media_size *media_sizes; /*! The currently calculated overall bounding box. */ + int n_media_sizes; + int media_sizes_alloc_size; + /*@} */ + + hpgs_xrop3_func_t rop3; //!< The ROP3 transfer raster operation. + hpgs_palette_color pattern_color; //!< The color of the ROP3 pattern. + + hpgs_color color; //!< The current output color. +}; + +HPGS_INTERNAL_API void hpgs_cleanup_plugin_devices(); + +/*! @} */ /* end of group device */ + +#ifdef __cplusplus +} // end of extern "C" +#endif + +#endif /* ! __HPGS_DEVICES_H */ diff --git a/src/add-ons/translators/hpgs/lib/hpgsfont.c b/src/add-ons/translators/hpgs/lib/hpgsfont.c new file mode 100644 index 0000000000..4ceaee2844 --- /dev/null +++ b/src/add-ons/translators/hpgs/lib/hpgsfont.c @@ -0,0 +1,2205 @@ +/*********************************************************************** + * * + * $Id: hpgsfont.c 385 2007-03-18 18:32:07Z softadm $ + * * + * hpgs - HPGl Script, a hpgl/2 interpreter, which uses a Postscript * + * API for rendering a scene and thus renders to a variety of * + * devices and fileformats. * + * * + * (C) 2004-2006 ev-i Informationstechnologie GmbH http://www.ev-i.at * + * * + * Author: Wolfgang Glas * + * * + * hpgs is free software; you can redistribute it and/or * + * modify it under the terms of the GNU Lesser General Public * + * License as published by the Free Software Foundation; either * + * version 2.1 of the License, or (at your option) any later version. * + * * + * hpgs is distributed in the hope that it will be useful, * + * but WITHOUT ANY WARRANTY; without even the implied warranty of * + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * + * Lesser General Public License for more details. * + * * + * You should have received a copy of the GNU Lesser General Public * + * License along with this library; if not, write to the * + * Free Software Foundation, Inc., 59 Temple Place, Suite 330, * + * Boston, MA 02111-1307 USA * + * * + *********************************************************************** + * * + * The implementation of the public API for ttf font handling. * + * * + ***********************************************************************/ + +#include +#include + +#ifdef WIN32 +#include +#else +#include +#endif + +#if defined ( __MINGW32__ ) || defined ( _MSC_VER ) +#include +#else +#include +#endif + +static hpgs_mutex_t font_dir_mutex; +static hpgs_font_dentry *font_directory = 0; +static size_t font_directory_sz = 0; +static size_t font_directory_alloc_sz = 0; + +// Standard glyph names in mac encoding cf. +// to the OpenType spec. +static char *std_glyph_names[] = { + // 0 - 9 + ".notdef",".null","nonmarkingreturn","space","exclam","quotedbl","numbersign","dollar","percent","ampersand", + // 10 - 19 + "quotesingle","parenleft","parenright","asterisk","plus","comma","hyphen","period","slash","zero", + // 20 - 29 + "one","two","three","four","five","six","seven","eight","nine","colon", + // 30 - 39 + "semicolon","less","equal","greater","question","at","A","B","C","D", + // 40 - 49 + "E","F","G","H","I","J","K","L","M","N", + // 50 - 59 + "O","P","Q","R","S","T","U","V","W","X", + // 60 - 69 + "Y","Z","bracketleft","backslash","bracketright","asciicircum","underscore","grave","a","b", + // 70 - 79 + "c","d","e","f","g","h","i","j","k","l", + // 80 - 89 + "m","n","o","p","q","r","s","t","u","v", + // 90 - 99 + "w","x","y","z","braceleft","bar","braceright","asciitilde","Adieresis","Aring", + // 100 - 109 + "Ccedilla","Eacute","Ntilde","Odieresis","Udieresis","aacute","agrave","acircumflex","adieresis","atilde", + // 110 - 119 + "aring","ccedilla","eacute","egrave","ecircumflex","edieresis","iacute","igrave","icircumflex","idieresis", + // 120 - 129 + "ntilde","oacute","ograve","ocircumflex","odieresis","otilde","uacute","ugrave","ucircumflex","udieresis", + // 130 - 139 + "dagger","degree","cent","sterling","section","bullet","paragraph","germandbls","registered","copyright", + // 140 - 149 + "trademark","acute","dieresis","notequal","AE","Oslash","infinity","plusminus","lessequal","greaterequal", + // 150 - 159 + "yen","mu","partialdiff","summation","product","pi","integral","ordfeminine","ordmasculine","Omega", + // 160 - 169 + "ae","oslash","questiondown","exclamdown","logicalnot","radical","florin","approxequal","Delta","guillemotleft", + // 170 - 179 + "guillemotright","ellipsis","space","Agrave","Atilde","Otilde","OE","oe","endash","emdash", + // 180 - 189 + "quotedblleft","quotedblright","quoteleft","quoteright","divide","lozenge","ydieresis","Ydieresis","fraction","currency", + // 190 - 199 + "guilsinglleft","guilsinglright","fi","fl","daggerdbl","periodcentered","quotesinglbase","quotedblbase","perthousand","Acircumflex", + // 200 - 209 + "Ecircumflex","Aacute","Edieresis","Egrave","Iacute","Icircumflex","Idieresis","Igrave","Oacute","Ocircumflex", + // 210 - 219 + 0,"Ograve","Uacute","Ucircumflex","Ugrave","dotlessi","circumflex","tilde","macron","breve", + // 220 - 229 + "dotaccent","ring","cedilla","hungarumlaut","ogonek","caron","Lslash","lslash","Scaron","scaron", + // 230 - 239 + "Zcaron","zcaron","brokenbar","Eth","eth","Yacute","yacute","Thorn","thorn","minus", + // 240 - 249 + "multiply","onesuperior","twosuperior","threesuperior","onehalf","onequarter","threequarters","franc","Gbreve","gbreve", + // 250 - 257 + "Idotaccent","Scedilla","scedilla","Cacute","cacute","Ccaron","ccaron","dcroat" +}; + +void hpgs_font_init() +{ + hpgs_mutex_init(&font_dir_mutex); +} + +void hpgs_font_cleanup() +{ + hpgs_mutex_lock(&font_dir_mutex); + + size_t i; + + for (i=0;i=font_directory_alloc_sz) + { + hpgs_font_dentry *d = realloc(font_directory,sizeof(hpgs_font_dentry)*2*font_directory_alloc_sz); + + if (!d) { free(name); free(fn); return; } + + font_directory = d; + font_directory_alloc_sz *= 2; + } + + font_directory[font_directory_sz].font_name = name; + font_directory[font_directory_sz].filename = fn; + font_directory[font_directory_sz].font = 0; + + // hpgs_log("name,fn=%s,%s.\n",name,fn); + + ++font_directory_sz; +} + +// helpers for big-endian binary file treatment. +static int read_uint32(hpgs_istream *is, uint32_t *x) +{ + int c1,c2,c3,c4; + + c1=hpgs_getc(is); + if (c1<0) return -1; + c2=hpgs_getc(is); + if (c2<0) return -1; + c3=hpgs_getc(is); + if (c3<0) return -1; + c4=hpgs_getc(is); + if (c4<0) return -1; + + *x = + (((uint32_t)(c1))<<24)| + (((uint32_t)(c2))<<16)| + (((uint32_t)(c3))<<8)| + ((uint32_t)(c4)); + + return 0; +} + +static int read_int32(hpgs_istream *is, int32_t *x) { return read_uint32(is,(uint32_t *)x); } + +static int read_uint16(hpgs_istream *is, uint16_t *x) +{ + int c1,c2; + + c1=hpgs_getc(is); + if (c1<0) return -1; + c2=hpgs_getc(is); + if (c2<0) return -1; + + *x = + (((uint16_t)(c1))<<8)| + ((uint16_t)(c2)); + + return 0; +} + +static int read_int16(hpgs_istream *is, int16_t *x) { return read_uint16(is,(uint16_t *)x); } + +static int read_uint8(hpgs_istream *is, uint8_t *x) +{ + int c; + + c=hpgs_getc(is); + if (c<0) return -1; + + *x = (uint8_t)(c); + return 0; +} + +static int read_int8(hpgs_istream *is, int8_t *x) { return read_uint8(is,(uint8_t *)x); } + +// convert the next n bytes from the stream as ucs2 string +// to a utf-8 string. +// +static int ucs2_stream_string_to_utf8(hpgs_istream *is, size_t n, char *str) +{ + size_t i; + + for (i=0;i> 6) | 0xC0; + *str++ = (file_code & 0x3f) | 0x80; + } + else + { + *str++ = (file_code >> 12) | 0xE0; + *str++ = ((file_code >> 6) & 0x3f) | 0x80; + *str++ = (file_code & 0x3f) | 0x80; + } + } + + *str++ = 0; + return 0; +} + +static int ascii_stream_string_to_utf8(hpgs_istream *is, size_t n, char *str) +{ + size_t i; + + for (i=0;itag)) return -1; + if (read_uint32(is,&e->checksum)) return -1; + if (read_uint32(is,&e->offset)) return -1; + if (read_uint32(is,&e->length)) return -1; + return 0; +} + +static void init_font_cmap_data(hpgs_font_cmap_data *cmap_data) +{ + cmap_data->ranges_sz = 0; + cmap_data->ranges = 0; + cmap_data->glyphIndexArray_sz = 0; + cmap_data->glyphIndexArray = 0; +} + +static void cleanup_font_cmap_data(hpgs_font_cmap_data *cmap_data) +{ + if (cmap_data->ranges) free(cmap_data->ranges); + if (cmap_data->glyphIndexArray) free(cmap_data->glyphIndexArray); +} + +static void init_font_post_data(hpgs_font_post_data *post_data) +{ + memset(post_data,0,sizeof(hpgs_font_post_data)); +} + +static void cleanup_font_post_data(hpgs_font_post_data *post_data) +{ + if (post_data->names) free((void*)post_data->names); + if (post_data->name_data) free((void*)post_data->name_data); +} + +static void init_font_glyph_data(hpgs_font_glyph_data *glyph_data) +{ + hpgs_bbox_null(&glyph_data->bbox); + + glyph_data->points_sz = 0; + glyph_data->points = 0; + + glyph_data->refs_sz = 0; + glyph_data->refs_alloc_sz = 0; + glyph_data->refs = 0; +} + +static void cleanup_font_glyph_data(hpgs_font_glyph_data *glyph_data) +{ + if (glyph_data->points) free(glyph_data->points); + if (glyph_data->refs) free(glyph_data->refs); +} + +static int font_glyph_data_push_ref(hpgs_font_glyph_data *glyph_data,const hpgs_matrix *m, uint16_t gid) +{ + if (HPGS_GROW_ARRAY_MIN_SIZE(glyph_data,hpgs_font_glyph_ref,refs,refs_sz,refs_alloc_sz,8)) return -1; + + glyph_data->refs[glyph_data->refs_sz].matrix = *m; + glyph_data->refs[glyph_data->refs_sz].gid = gid; + ++glyph_data->refs_sz; + return 0; +} + +static unsigned cmap_find_unicode(const hpgs_font *font, int unicode) +{ + size_t i0 = 0; + size_t i1 = font->cmap_data.ranges_sz; + + if (unicode <= 0 || unicode > 65535) return 0; + + // binary search for the endCode. + while (i0 < i1) + { + size_t i = i0+(i1-i0)/2; + + if (font->cmap_data.ranges[i].endCode < unicode) + i0 = i+1; + else + i1 = i; + } + + // undefined glyph. + if (i0 >= font->cmap_data.ranges_sz || unicode < font->cmap_data.ranges[i0].startCode) + return 0; + + const hpgs_font_cmap_code_range *range = &font->cmap_data.ranges[i0]; + + uint16_t gid; + + if (range->idRangeOffset) + { + size_t idx = + (range->idRangeOffset/2 - (font->cmap_data.ranges_sz - i0)) + + unicode - range->startCode; + + if (idx < 0 || idx >= font->cmap_data.glyphIndexArray_sz) + return 0; + + gid = font->cmap_data.glyphIndexArray[idx]; + } + else + gid = unicode + range->idDelta; + + if (gid >= font->maxp_data.numGlyphs) gid = 0; + return gid; +} + + +static uint32_t make_ttf_tag(const char *c) +{ + return + (((uint32_t)(unsigned char)(c[0]))<<24)| + (((uint32_t)(unsigned char)(c[1]))<<16)| + (((uint32_t)(unsigned char)(c[2]))<<8)| + ((uint32_t)(unsigned char)(c[3])); +} + +static int read_header(hpgs_font_header *header, hpgs_istream *is) +{ + int i; + + header->name_table = -1; + header->head_table = -1; + header->hhea_table = -1; + header->maxp_table = -1; + header->hmtx_table = -1; + header->loca_table = -1; + header->cmap_table = -1; + header->post_table = -1; + header->glyf_table = -1; + header->kern_table = -1; + + if (read_int32(is,&header->version)) return -1; + + + // Chaeck the version tag. + if (header->version != 0x00010000 /* TrueType */) return -1; + + /* OpenType uses a header->version == 0x4f54544f, + but OpenType support is out of sight now, since this + involves interpretation of CFF compact PostScript font + programs. */ + + if (read_uint16(is,&header->numtab)) return -1; + if (read_uint16(is,&header->searchRange)) return -1; + if (read_uint16(is,&header->entrySel)) return -1; + if (read_uint16(is,&header->rangeShift)) return -1; + + if (header->numtab > HPGS_FONT_MAX_TTF_TABLES) return -1; + + for (i=0;inumtab;++i) + { + if (read_table_entry(is,&header->tables[i])) return -1; + + if (header->tables[i].tag == make_ttf_tag("name")) + header->name_table = i; + else if (header->tables[i].tag == make_ttf_tag("head")) + header->head_table = i; + else if (header->tables[i].tag == make_ttf_tag("hhea")) + header->hhea_table = i; + else if (header->tables[i].tag == make_ttf_tag("maxp")) + header->maxp_table = i; + else if (header->tables[i].tag == make_ttf_tag("hmtx")) + header->hmtx_table = i; + else if (header->tables[i].tag == make_ttf_tag("loca")) + header->loca_table = i; + else if (header->tables[i].tag == make_ttf_tag("cmap")) + header->cmap_table = i; + else if (header->tables[i].tag == make_ttf_tag("post")) + header->post_table = i; + else if (header->tables[i].tag == make_ttf_tag("glyf")) + header->glyf_table = i; + else if (header->tables[i].tag == make_ttf_tag("kern")) + header->kern_table = i; + } + + return 0; +} + +static int seek_table(hpgs_istream *is, + hpgs_font_header *header, int table) +{ + if (table < 0) return -1; + + return hpgs_istream_seek(is,header->tables[table].offset); +} + +static int seek_font_table(hpgs_font *font, int table) +{ + if (table < 0) return -1; + + return hpgs_istream_seek(font->is,font->header.tables[table].offset); +} + +static int seek_font_table_off(hpgs_font *font, int table, size_t off) +{ + if (table < 0) return -1; + + return hpgs_istream_seek(font->is,font->header.tables[table].offset+off); +} + +static char *scan_name_table(hpgs_font_header *header, + hpgs_istream *is) +{ + if (seek_table(is,header,header->name_table) < 0) return 0; + + uint16_t format; // Format selector (=0). + uint16_t count; // Number of name records. + uint16_t stringOffset; // Offset to start of string storage (from start of table). + + if (read_uint16(is,&format)) return 0; + if (read_uint16(is,&count)) return 0; + if (read_uint16(is,&stringOffset)) return 0; + + int i; + + for (i=0;i<(int)count;++i) + { + uint16_t platformID; // Platform ID. + uint16_t encodingID; // Platform-specific encoding ID. + uint16_t languageID; // Language ID. + uint16_t nameID; // Name ID. + uint16_t length; // String length (in bytes). + uint16_t offset; // String offset from start of storage area (in bytes). + + if (read_uint16(is,&platformID)) return 0; + if (read_uint16(is,&encodingID)) return 0; + if (read_uint16(is,&languageID)) return 0; + if (read_uint16(is,&nameID)) return 0; + if (read_uint16(is,&length)) return 0; + if (read_uint16(is,&offset)) return 0; + + // if (nameID == 4) + // hpgs_log("platformID,encodingID,languageID = %d,%d,%d.\n", + // (int)platformID,(int)encodingID,(int)languageID); + + // check for + // platformID 1 (Apple) + // encodingID 0 (Roman) + // languageID 0 (English) + // nameID 4 (full font name) + // + if (platformID == 1 && + encodingID == 0 && + languageID == 0 && + nameID == 4 ) + { + if (hpgs_istream_seek(is, + header->tables[header->name_table].offset+ + (size_t)stringOffset+ + (size_t)offset ) < 0) + return 0; + + char *name = alloca((size_t)length * 3 + 1); + + if (ascii_stream_string_to_utf8(is,(size_t)length,name)) + return 0; + + return strdup(name); + } + + // check for + // platformID 0 (Unicode) + // encodingID 3 (Unicode 2.0 BMP) + // languageID 0 (not used for platform ID 0) + // nameID 4 (full font name) + // + if (platformID == 0 && + encodingID == 3 && + languageID == 0 && + nameID == 4 ) + { + if (hpgs_istream_seek(is, + header->tables[header->name_table].offset+ + (size_t)stringOffset+ + (size_t)offset ) < 0) + return 0; + + + char *name = alloca((size_t)length * 3 + 1); + + if (ucs2_stream_string_to_utf8(is,(size_t)length,name)) + return 0; + + return strdup(name); + } + } + + return 0; +} + +static int hpgs_scan_font_dir(const char *path) +{ + hpgs_istream *is=0; + hpgs_font_header header; + +#ifdef WIN32 + // go through font directory. + char *pat = hpgs_sprintf_malloc("%s\\*.ttf",path); + + if (!pat) + return hpgs_set_error(hpgs_i18n("Out of memory reading font directory %s."),path); + + HANDLE d; + WIN32_FIND_DATAA data; + + if ((d=FindFirstFileA(pat,&data)) == INVALID_HANDLE_VALUE) + { + free(pat); + return hpgs_set_error(hpgs_i18n("Cannot open font directory %s."),path); + } + + free(pat); + + do + { + char * fn = hpgs_sprintf_malloc("%s\\%s",path,data.cFileName); + + if (!fn) + { + FindClose(d); + return hpgs_set_error(hpgs_i18n("Out of memory reading font directory %s."),path); + } + + is = hpgs_new_file_istream(fn); + if (!is) { free(fn); continue; } + + if (read_header(&header,is) == 0) + { + char *name = scan_name_table(&header,is); + + if (name) + push_font_to_directory(name,fn); + else + free(fn); + } + else + free(fn); + + hpgs_istream_close(is); + is = 0; + } + while (FindNextFileA(d,&data)); + + FindClose(d); + +#else + // go through font directory. + DIR *d; + struct dirent *data; + + if ((d=opendir(path))==0) + return hpgs_set_error(hpgs_i18n("Cannot open font directory %s."),path); + + while ((data=readdir(d)) != 0) + { + int l = strlen(data->d_name); + + if (strcmp(data->d_name+l-4,".ttf") && + strcmp(data->d_name+l-4,".TTF") ) continue; + + char * fn = hpgs_sprintf_malloc("%s/%s",path,data->d_name); + + if (!fn) + { + closedir (d); + return hpgs_set_error(hpgs_i18n("Out of memory reading font directory %s."),path); + } + + is = hpgs_new_file_istream(fn); + if (!is) { free(fn); continue; } + + if (read_header(&header,is) == 0) + { + char *name = scan_name_table(&header,is); + + if (name) + push_font_to_directory(name,fn); + else + free(fn); + } + else + free(fn); + + hpgs_istream_close(is); + is = 0; + } + + closedir (d); +#endif + return 0; +} + +static int font_dentry_compare(const void *a, const void *b) +{ + hpgs_font_dentry *fa = (hpgs_font_dentry *)a; + hpgs_font_dentry *fb = (hpgs_font_dentry *)b; + + return strcmp(fa->font_name,fb->font_name); +} + +static int hpgs_scan_font_dirs() +{ + // already scanned ? + hpgs_mutex_lock(&font_dir_mutex); + + if (font_directory) { hpgs_mutex_unlock(&font_dir_mutex); return 0; } + + font_directory = (hpgs_font_dentry *)malloc(sizeof(hpgs_font_dentry)*256); + if (!font_directory) + { + hpgs_mutex_unlock(&font_dir_mutex); + return hpgs_set_error(hpgs_i18n("Out of memory scanning font directories.")); + } + font_directory_alloc_sz = 256; + font_directory_sz = 0; + +#ifdef WIN32 + const char *root = getenv("SYSTEMROOT"); + char *path = hpgs_sprintf_malloc("%s\\fonts",root); + int ret = hpgs_scan_font_dir(path); + free(path); +#else + + const char *font_path = getenv("HPGS_FONT_PATH"); + + if (!font_path || strlen(font_path) <= 0) + font_path = "/usr/X11R6/lib/X11/fonts/truetype:/usr/X11R6/lib/X11/fonts/TTF:/usr/local/share/fonts:/usr/local/share/fonts/truetype:/usr/local/share/fonts/TTF"; + + char *font_path_dup = hpgs_alloca(strlen(font_path)); + + strcpy (font_path_dup,font_path); + + int npaths=0,ret=0; + int nerrors = 0; + + char *fp; + char *last_font = font_path_dup; + + for (fp = font_path_dup;;++fp) + { + if (*fp == ':' || *fp == 0) + { + hpgs_bool eos = (*fp == 0); + if (!eos) *fp = 0; + + if (fp - last_font > 0) + { + if (hpgs_scan_font_dir(last_font)) + { + ++nerrors; + hpgs_log("hpgs_scan_font_dirs: %s\n",hpgs_get_error()); + } + ++npaths; + } + + if (eos) break; + last_font = fp + 1; + } + } + + if (nerrors == npaths) + ret = -1; + +#endif + qsort(font_directory,font_directory_sz,sizeof(hpgs_font_dentry),font_dentry_compare); + + hpgs_mutex_unlock(&font_dir_mutex); + return ret; +} + +static int read_head_table(hpgs_font *font) +{ + if (seek_font_table(font,font->header.head_table) < 0) return -1; + + if (read_uint32(font->is,&font->head_data.version)) return -1; + if (read_uint32(font->is,&font->head_data.fontRevision)) return -1; + if (read_uint32(font->is,&font->head_data.checkSumAdjustment)) return -1; + if (read_uint32(font->is,&font->head_data.magicNumber)) return -1; + if (read_uint16(font->is,&font->head_data.flags)) return -1; + if (read_uint16(font->is,&font->head_data.unitsPerEm)) return -1; + if (read_int32(font->is,&font->head_data.created_low)) return -1; + if (read_int32(font->is,&font->head_data.created_high)) return -1; + if (read_int32(font->is,&font->head_data.modified_low)) return -1; + if (read_int32(font->is,&font->head_data.modified_high)) return -1; + if (read_int16(font->is,&font->head_data.xMin)) return -1; + if (read_int16(font->is,&font->head_data.yMin)) return -1; + if (read_int16(font->is,&font->head_data.xMax)) return -1; + if (read_int16(font->is,&font->head_data.yMax)) return -1; + if (read_uint16(font->is,&font->head_data.macStyle)) return -1; + if (read_int16(font->is,&font->head_data.lowestRecPPEM)) return -1; + if (read_int16(font->is,&font->head_data.fontDirectionHint)) return -1; + if (read_int16(font->is,&font->head_data.indexToLocFormat)) return -1; + if (read_int16(font->is,&font->head_data.glyphDataFormat)) return -1; + + return 0; +} + +static int read_hhea_table(hpgs_font *font) +{ + if (seek_font_table(font,font->header.hhea_table) < 0) return -1; + + if (read_uint32(font->is,&font->hhea_data.version)) return -1; + if (read_int16(font->is,&font->hhea_data.ascent)) return -1; + if (read_int16(font->is,&font->hhea_data.descent)) return -1; + if (read_int16(font->is,&font->hhea_data.lineGap)) return -1; + if (read_uint16(font->is,&font->hhea_data.advanceWidthMax)) return -1; + if (read_int16(font->is,&font->hhea_data.minLeftSideBearing)) return -1; + if (read_int16(font->is,&font->hhea_data.minRightSideBearing)) return -1; + if (read_int16(font->is,&font->hhea_data.xMaxExtent)) return -1; + if (read_int16(font->is,&font->hhea_data.caretSlopeRise)) return -1; + if (read_int16(font->is,&font->hhea_data.caretSlopeRun)) return -1; + if (read_int16(font->is,&font->hhea_data.caretOffset)) return -1; + if (read_int16(font->is,&font->hhea_data.reserved1)) return -1; + if (read_int16(font->is,&font->hhea_data.reserved2)) return -1; + if (read_int16(font->is,&font->hhea_data.reserved3)) return -1; + if (read_int16(font->is,&font->hhea_data.reserved4)) return -1; + if (read_int16(font->is,&font->hhea_data.metricDataFormat)) return -1; + if (read_uint16(font->is,&font->hhea_data.numOfLongHorMetrics)) return -1; + + return 0; +} + +static int read_maxp_table(hpgs_font *font) +{ + if (seek_font_table(font,font->header.maxp_table) < 0) return -1; + + if (read_uint32(font->is,&font->maxp_data.version)) return -1; + if (read_uint16(font->is,&font->maxp_data.numGlyphs)) return -1; + if (read_uint16(font->is,&font->maxp_data.maxPoints)) return -1; + if (read_uint16(font->is,&font->maxp_data.maxContours)) return -1; + if (read_uint16(font->is,&font->maxp_data.maxComponentPoints)) return -1; + if (read_uint16(font->is,&font->maxp_data.maxComponentContours)) return -1; + if (read_uint16(font->is,&font->maxp_data.maxZones)) return -1; + if (read_uint16(font->is,&font->maxp_data.maxTwilightPoints)) return -1; + if (read_uint16(font->is,&font->maxp_data.maxStorage)) return -1; + if (read_uint16(font->is,&font->maxp_data.maxFunctionDefs)) return -1; + if (read_uint16(font->is,&font->maxp_data.maxInstructionDefs)) return -1; + if (read_uint16(font->is,&font->maxp_data.maxStackElements)) return -1; + if (read_uint16(font->is,&font->maxp_data.maxSizeOfInstructions)) return -1; + if (read_uint16(font->is,&font->maxp_data.maxComponentElements)) return -1; + if (read_uint16(font->is,&font->maxp_data.maxComponentDepth)) return -1; + + return 0; +} + +static int read_hmtx_table(hpgs_font *font) +{ + if (font->hhea_data.numOfLongHorMetrics < 1) return -1; + + if (seek_font_table(font,font->header.hmtx_table) < 0) return -1; + + font->hmtx_data = (hpgs_font_longHorMetrics *) + malloc(sizeof(hpgs_font_longHorMetrics)*font->maxp_data.numGlyphs); + + if (!font->hmtx_data) return -1; + + int i = 0; + + while (ihhea_data.numOfLongHorMetrics) + { + if (read_uint16(font->is,&font->hmtx_data[i].advanceWidth)) return -1; + if (read_int16(font->is,&font->hmtx_data[i].leftSideBearing)) return -1; + ++i; + } + + while (imaxp_data.numGlyphs) + { + font->hmtx_data[i].advanceWidth = + font->hmtx_data[font->hhea_data.numOfLongHorMetrics-1].advanceWidth; + + if (read_int16(font->is,&font->hmtx_data[i].leftSideBearing)) return -1; + ++i; + } + + return 0; +} + +static int read_loca_table(hpgs_font *font) +{ + if (seek_font_table(font,font->header.loca_table) < 0) return -1; + + if (font->head_data.indexToLocFormat) + font->loca_data_sz = font->header.tables[font->header.loca_table].length/4; + else + font->loca_data_sz = font->header.tables[font->header.loca_table].length/2; + + font->loca_data = (uint32_t*)malloc(sizeof(uint32_t)*font->loca_data_sz); + + if (!font->loca_data) return -1; + + size_t i; + + if (font->head_data.indexToLocFormat) + { + for (i=0;iloca_data_sz;++i) + if (read_uint32(font->is,&font->loca_data[i])) return -1; + } + else + { + for (i=0;iloca_data_sz;++i) + { + uint16_t x; + + if (read_uint16(font->is,&x)) return -1; + + font->loca_data[i] = ((uint32_t)x) << 1; + } + } + + return 0; +} + +static int kern_pair_compare(const void *a, const void *b) +{ + hpgs_font_kern_pair *ka = (hpgs_font_kern_pair *)a; + hpgs_font_kern_pair *kb = (hpgs_font_kern_pair *)b; + + if (ka->left_gid < kb->left_gid) return -1; + if (ka->left_gid > kb->left_gid) return 1; + + if (ka->right_gid < kb->right_gid) return -1; + if (ka->right_gid > kb->right_gid) return 1; + + return 0; +} + +static int read_kern_table(hpgs_font *font) +{ + // kerning must not be available, so this is not an error. + if (font->header.kern_table < 0) return 0; + + if (seek_font_table(font,font->header.kern_table) < 0) return -1; + + uint16_t version; // Table version number (starts at 0) + uint16_t nTables; // Number of subtables in the kerning table. + + if (read_uint16(font->is,&version)) return -1; + if (read_uint16(font->is,&nTables)) return -1; + + // extra offset for seeking next subtable. + size_t extra_off = 4; + + uint16_t iTable; + + for (iTable = 0; iTable < nTables; ++iTable) + { + if (iTable && + seek_font_table_off(font,font->header.kern_table,extra_off) < 0) + return -1; + + uint16_t length; // Length of the subtable, in bytes (including this header). + uint16_t coverage; // What type of information is contained in this table. + + if (read_uint16(font->is,&version)) return -1; + if (read_uint16(font->is,&length)) return -1; + if (read_uint16(font->is,&coverage)) return -1; + + extra_off += length; + + // we seek a table with horzonal kern data in format 0. + if ((coverage & 0xfff3) == 0x0001) + { + uint16_t nPairs; // This gives the number of kerning pairs in the table. + uint16_t searchRange; // The largest power of two less than or equal to the value of nPairs, multiplied by the size in bytes of an entry in the table. + uint16_t entrySelector; // This is calculated as log2 of the largest power of two less than or equal to the value of nPairs. This value indicates how many iterations of the search loop will have to be made. (For example, in a list of eight items, there would have to be three iterations of the loop). + uint16_t rangeShift; // The value of nPairs minus the largest power of two less than or equal to nPairs, and then multiplied by the size in bytes of an entry in the table. + + if (read_uint16(font->is,&nPairs)) return -1; + if (read_uint16(font->is,&searchRange)) return -1; + if (read_uint16(font->is,&entrySelector)) return -1; + if (read_uint16(font->is,&rangeShift)) return -1; + + font->kern_data_sz = nPairs; + + font->kern_data = + (hpgs_font_kern_pair*)malloc(sizeof(hpgs_font_kern_pair)*font->kern_data_sz); + + if (!font->kern_data) return -1; + + size_t i; + + for (i=0;ikern_data_sz;++i) + { + int16_t value; + + if (read_uint16(font->is,&font->kern_data[i].left_gid)) return -1; + if (read_uint16(font->is,&font->kern_data[i].right_gid)) return -1; + if (read_int16(font->is,&value)) return -1; + + font->kern_data[i].value = (double)value/(double)font->head_data.unitsPerEm; + } + + // That's all we can interpret. + break; + } + } + + if (font->kern_data) + qsort(font->kern_data,font->kern_data_sz,sizeof(hpgs_font_kern_pair),kern_pair_compare); + + return 0; +} + +static int read_cmap_table(hpgs_font *font) +{ + if (seek_font_table(font,font->header.cmap_table) < 0) return -1; + + uint16_t dummy; + uint16_t numberSubtables; + + if (read_uint16(font->is,&dummy)) return -1; + if (read_uint16(font->is,&numberSubtables)) return -1; + + uint32_t offset = 0; + + // search type 4 subtable. + while (numberSubtables) + { + uint16_t platformID; + uint16_t platformSpecificID; + + if (read_uint16(font->is,&platformID)) return -1; + if (read_uint16(font->is,&platformSpecificID)) return -1; + if (read_uint32(font->is,&offset)) return -1; + + if (platformID == 3 && platformSpecificID == 1) + break; + + --numberSubtables; + } + + // no suitable subtable found. + if (!numberSubtables) return -1; + + if (seek_font_table_off(font,font->header.cmap_table,offset) < 0) + return -1; + + if (read_uint16(font->is,&dummy)) return -1; // version + + // character map is not of type 4. + if (dummy != 4) return -1; + + uint16_t length; + if (read_uint16(font->is,&length)) return -1; + + if (read_uint16(font->is,&dummy)) return -1; // language + if (read_uint16(font->is,&dummy)) return -1; // segCountX2 + + font->cmap_data.ranges_sz = dummy/2; + + font->cmap_data.ranges = (hpgs_font_cmap_code_range*) + malloc(sizeof(hpgs_font_cmap_code_range) * font->cmap_data.ranges_sz); + + font->cmap_data.glyphIndexArray_sz = + length - 8*2 - 4*2 * font->cmap_data.ranges_sz; + + font->cmap_data.glyphIndexArray = (uint16_t*) + malloc(sizeof(uint16_t)*font->cmap_data.glyphIndexArray_sz); + + if (read_uint16(font->is,&dummy)) return -1; // searchRange + if (read_uint16(font->is,&dummy)) return -1; // entrySelector + if (read_uint16(font->is,&dummy)) return -1; // rangeShift + + size_t i; + + for (i=0; icmap_data.ranges_sz; ++i) + if (read_uint16(font->is,&font->cmap_data.ranges[i].endCode)) return -1; + + if (read_uint16(font->is,&dummy)) return -1; // reservedPad + + for (i=0; icmap_data.ranges_sz; ++i) + if (read_uint16(font->is,&font->cmap_data.ranges[i].startCode)) return -1; + + for (i=0; icmap_data.ranges_sz; ++i) + if (read_uint16(font->is,&font->cmap_data.ranges[i].idDelta)) return -1; + + for (i=0; icmap_data.ranges_sz; ++i) + if (read_uint16(font->is,&font->cmap_data.ranges[i].idRangeOffset)) return -1; + + for (i=0; icmap_data.glyphIndexArray_sz; ++i) + if (read_uint16(font->is,&font->cmap_data.glyphIndexArray[i])) return -1; + + return 0; +} + +static int read_post_table(hpgs_font *font) +{ + if (seek_font_table(font,font->header.post_table) < 0) return -1; + + if (read_int32(font->is,&font->post_data.version)) return -1; + + if (font->post_data.version != 0x00020000) return -1; + + if (read_int32(font->is,&font->post_data.italicAngle)) return -1; + if (read_int16(font->is,&font->post_data.underlinePosition)) return -1; + if (read_int16(font->is,&font->post_data.underlineThickness)) return -1; + if (read_uint32(font->is,&font->post_data.isFixedPitch)) return -1; + if (read_uint32(font->is,&font->post_data.minMemType42)) return -1; + if (read_uint32(font->is,&font->post_data.maxMemType42)) return -1; + if (read_uint32(font->is,&font->post_data.minMemType1)) return -1; + if (read_uint32(font->is,&font->post_data.maxMemType1)) return -1; + if (read_uint16(font->is,&font->post_data.numberOfGlyphs)) return -1; + + font->post_data.names = (const char**)malloc((size_t)font->post_data.numberOfGlyphs*sizeof(const char**)); + + if (!font->post_data.names) return -1; + + size_t name_data_sz = + font->header.tables[font->header.post_table].length - 34 - 2*(size_t)font->post_data.numberOfGlyphs; + char *name_data = malloc(name_data_sz); + + size_t ig; + + uint16_t *glyphNameIndex = hpgs_alloca((size_t)font->post_data.numberOfGlyphs*sizeof(uint16_t)); + + size_t numberNewGlyphs = 0; + + for (ig=0; igpost_data.numberOfGlyphs; ++ig) + { + if (read_uint16(font->is,&glyphNameIndex[ig])) return -1; + + if (glyphNameIndex[ig] >= numberNewGlyphs) + numberNewGlyphs = (size_t)glyphNameIndex[ig] + 1; + } + + uint32_t *name_offsets = 0; + + if (numberNewGlyphs > 258) + { + numberNewGlyphs -= 258; + + name_offsets = hpgs_alloca(numberNewGlyphs*sizeof(uint32_t)); + + size_t id = 0; + + for (ig=0; igis,&name_l)) return -1; + + name_offsets[ig] = id; + + while (name_l) + { + if (id >= name_data_sz) return -1; + int c; + if ((c=hpgs_getc(font->is)) < 0) + return -1; + + name_data[id] = c; + ++id; + --name_l; + } + + if (id >= name_data_sz) return -1; + name_data[id] = '\0'; + ++id; + } + } + else + numberNewGlyphs = 0; + + for (ig=0; igpost_data.numberOfGlyphs; ++ig) + { + if (glyphNameIndex[ig] < 258) + font->post_data.names[ig] = std_glyph_names[glyphNameIndex[ig]]; + else if ((size_t)glyphNameIndex[ig] - 258 < numberNewGlyphs) + font->post_data.names[ig] = name_data + name_offsets[(size_t)glyphNameIndex[ig] - 258]; + else + font->post_data.names[ig] = 0; + } + + font->post_data.name_data = name_data; + + return 0; +} + +static int load_glyph_gid(hpgs_font *font, + hpgs_font_glyph_data *glyph_data, + uint16_t gid) +{ + // character out of range for loca data ? + if (gid+1 >= font->loca_data_sz) return -1; + + init_font_glyph_data(glyph_data); + + // check for an empty glyph description. + if (font->loca_data[gid+1] <= font->loca_data[gid]) + return 0; + + // seek character data in file. + if (seek_font_table_off(font,font->header.glyf_table, + (size_t)font->loca_data[gid]) < 0) + return -1; + + int16_t numberOfContours; + int16_t xMin,yMin,xMax,yMax; + + if (read_int16(font->is,&numberOfContours)) return -1; + if (read_int16(font->is,&xMin)) return -1; + if (read_int16(font->is,&yMin)) return -1; + if (read_int16(font->is,&xMax)) return -1; + if (read_int16(font->is,&yMax)) return -1; + + glyph_data->bbox.llx = (double)xMin/(double)font->head_data.unitsPerEm; + glyph_data->bbox.lly = (double)yMin/(double)font->head_data.unitsPerEm; + glyph_data->bbox.urx = (double)xMax/(double)font->head_data.unitsPerEm; + glyph_data->bbox.ury = (double)yMax/(double)font->head_data.unitsPerEm; + + // hpgs_log("bbox: %lg,%lg,%lg,%lg.\n", + // glyph_data->bbox.llx,glyph_data->bbox.lly,glyph_data->bbox.urx,glyph_data->bbox.ury); + + if (numberOfContours > 0) + { + // simple glyph description. + uint16_t *endPtsOfContours = (uint16_t *)hpgs_alloca(numberOfContours*sizeof(uint16_t)); + + unsigned ic; + for (ic = 0; icis,&endPtsOfContours[ic])) goto error; + // hpgs_log("endPtsOfContours[%u]: %d.\n", + // ic,(int)endPtsOfContours[ic]); + } + + glyph_data->points_sz = endPtsOfContours[numberOfContours-1]+1; + glyph_data->points = (hpgs_font_glyph_point*)malloc(sizeof(hpgs_font_glyph_point)*glyph_data->points_sz); + + if (!glyph_data->points) goto error; + + // read instructions. + uint16_t instructionLength; + + if (read_uint16(font->is,&instructionLength))goto error; + + uint8_t *instructions = (uint8_t *)hpgs_alloca(instructionLength); + + if (hpgs_istream_read(instructions,1,instructionLength,font->is) != instructionLength) + goto error; + + // read and unfold flags. + uint8_t *flags = (uint8_t *)hpgs_alloca(glyph_data->points_sz); + + size_t i = 0; + + while (ipoints_sz) + { + if (read_uint8(font->is,&flags[i])) goto error; + + // check for repat flag + if (flags[i] & (1<<3)) + { + uint8_t f = flags[i]; + uint8_t repeat; + if (read_uint8(font->is,&repeat)) goto error; + + while (repeat && ipoints_sz) + { + --repeat; + ++i; + flags[i] = f; + } + } + + ++i; + } + + // read the x coordinates. + int16_t *xCoordinates = (int16_t *)hpgs_alloca(glyph_data->points_sz*sizeof(int16_t)); + + for (i=0;ipoints_sz;++i) + { + if (flags[i] & (1<<1)) // x-Short vector + { + uint8_t x; + + if (read_uint8(font->is,&x)) goto error; + + if (flags[i] & (1<<4)) // sign of x + xCoordinates[i] = (int16_t)x; + else + xCoordinates[i] = -(int16_t)x; + } + else + { + if (flags[i] & (1<<4)) // This x is same + { + xCoordinates[i] = 0; + } + else + { + if (read_int16(font->is,&xCoordinates[i])) goto error; + } + } + + // hpgs_log("flags,x[%u]: %2.2x,%d.\n", + // (unsigned)i,(unsigned)flags[i],(int)xCoordinates[i]); + } + + // read the y coordinates. + int16_t *yCoordinates = (int16_t *)hpgs_alloca(glyph_data->points_sz*sizeof(int16_t)); + + for (i=0;ipoints_sz;++i) + { + if (flags[i] & (1<<2)) // y-Short vector + { + uint8_t y; + + if (read_uint8(font->is,&y)) goto error; + + if (flags[i] & (1<<5)) // sign of y + yCoordinates[i] = (int16_t)y; + else + yCoordinates[i] = -(int16_t)y; + } + else + { + if (flags[i] & (1<<5)) // This y is same + { + yCoordinates[i] = 0; + } + else + { + if (read_int16(font->is,&yCoordinates[i])) goto error; + } + } + // hpgs_log("flags,y[%u]: %2.2x,%d.\n", + // (unsigned)i,(unsigned)flags[i],(int)yCoordinates[i]); + } + + // now unfold the contour data. + i = 0; + + hpgs_point p = { 0.0, 0.0 }; + + for (ic = 0; ichead_data.unitsPerEm; + p.y += (double)yCoordinates[i]/(double)font->head_data.unitsPerEm; + + glyph_data->points[i].p = p; + + if (ii == 0) + glyph_data->points[i].flags = HPGS_FONT_GLYPH_POINT_START; + else if (flags[i] & (1<<0)) // on curve flags + glyph_data->points[i].flags = HPGS_FONT_GLYPH_POINT_ONCURVE; + else + glyph_data->points[i].flags = HPGS_FONT_GLYPH_POINT_CONTROL; + + // hpgs_log("p: %d,%lg,%lg.\n", + // glyph_data->points[i].flags, + // p.x*(double)font->head_data.unitsPerEm,p.y*(double)font->head_data.unitsPerEm); + + ++i; + ++ii; + } + } + + } + else if (numberOfContours < 0) + { + // composite glyph. + uint16_t flags; + uint16_t glyphIndex; + + hpgs_matrix m; + + do + { + if (read_uint16(font->is,&flags)) goto error; + if (read_uint16(font->is,&glyphIndex)) goto error; + + // read offsets. + if (flags & 1) // ARG_1_AND_2_ARE_WORDS + { + // offsets are 2 byte values + int16_t dx; + int16_t dy; + + if (read_int16(font->is,&dx)) goto error; + if (read_int16(font->is,&dy)) goto error; + + // if (flags & (1 << 1)) FIXME ARGS_ARE_XY_VALUES + m.dx = (double)dx/(double)font->head_data.unitsPerEm; + m.dy = (double)dy/(double)font->head_data.unitsPerEm; + } + else + { + // offsets are byte values + int8_t dx; + int8_t dy; + + if (read_int8(font->is,&dx)) goto error; + if (read_int8(font->is,&dy)) goto error; + + m.dx = (double)dx/(double)font->head_data.unitsPerEm; + m.dy = (double)dy/(double)font->head_data.unitsPerEm; + } + + // read transformation matrix. + if (flags & (1 << 3)) // WE_HAVE_A_SCALE + { + int16_t scale; + if (read_int16(font->is,&scale)) goto error; + + m.mxx = m.myy = (double)scale/16384.0; + m.mxy = m.myx = 0.0; + } + else if (flags & (1 << 6)) // WE_HAVE_AN_X_AND_Y_SCALE + { + int16_t xscale; + int16_t yscale; + if (read_int16(font->is,&xscale)) goto error; + if (read_int16(font->is,&yscale)) goto error; + + m.mxx = (double)xscale/16384.0; + m.myy = (double)yscale/16384.0; + m.mxy = m.myx = 0.0; + } + else if (flags & (1 << 7)) // WE_HAVE_A_TWO_BY_TWO + { + int16_t mxx; + int16_t mxy; + int16_t myx; + int16_t myy; + + if (read_int16(font->is,&mxx)) goto error; + if (read_int16(font->is,&mxy)) goto error; + if (read_int16(font->is,&myx)) goto error; + if (read_int16(font->is,&myy)) goto error; + + m.mxx = (double)mxx/16384.0; + m.mxy = (double)mxy/16384.0; + m.myx = (double)myx/16384.0; + m.myy = (double)myy/16384.0; + } + else + { + m.mxx = m.myy = 1.0; + m.mxy = m.myx = 0.0; + } + + if (font_glyph_data_push_ref(glyph_data,&m,glyphIndex)) + goto error; + + // hpgs_log("ref: %d,(%lg,%lg,%lg,%lg,%lg,%lg).\n", + // (int)glyphIndex, + // m.dx,m.dy,m.mxx,m.mxy,m.myx,m.myy); + } + while (flags & (1 << 5)); // MORE_COMPONENTS + } + + return 0; + + error: + cleanup_font_glyph_data(glyph_data); + return -1; +} + +static hpgs_font_glyph_data *find_glyph_gid(hpgs_font *font, + unsigned gid) +{ + if (gid > font->maxp_data.numGlyphs) gid = 0; + + // cache hit ? + if (font->glyph_cache_positions[gid] >= 0) + return &font->glyph_cache[font->glyph_cache_positions[gid]]; + + hpgs_mutex_lock(&font->mutex); + + if (font->glyph_cache_positions[gid] >= 0) + { + hpgs_mutex_unlock(&font->mutex); + return &font->glyph_cache[font->glyph_cache_positions[gid]]; + } + + // try to load new glyph. + hpgs_font_glyph_data *glyph_data = + &font->glyph_cache[font->n_cached_glyphs]; + + if (load_glyph_gid(font,glyph_data,gid) == 0) + { + // seek glyph in kern table. + size_t i0 = 0; + size_t i1 = font->kern_data_sz; + + while (i0kern_data[i].left_gid < gid) + i0 = i+1; + else + i1 = i; + } + + if (i0 < font->kern_data_sz && font->kern_data[i0].left_gid == gid) + { + glyph_data->begin_kern_pair = i0; + + // find end of equal range. + i1 = font->kern_data_sz; + + while (i0kern_data[i].left_gid <= gid) + i0 = i+1; + else + i1 = i; + } + + glyph_data->end_kern_pair = i0; + } + else + { + glyph_data->begin_kern_pair = 0; + glyph_data->end_kern_pair = 0; + } + + // enter successfully read glyph into cache. + font->glyph_cache_positions[gid] = font->n_cached_glyphs; + ++font->n_cached_glyphs; + } + else + glyph_data = 0; + + hpgs_mutex_unlock(&font->mutex); + + return glyph_data; +} + +static double find_kern_value(hpgs_font *font, + uint16_t gid, + uint16_t gid_n) +{ + if (!font->kern_data) return 0.0; + + hpgs_font_glyph_data *glyph_data = find_glyph_gid(font,gid); + + if (gid_n > font->maxp_data.numGlyphs) gid_n = 0; + + size_t i0 = glyph_data->begin_kern_pair; + size_t i1 = glyph_data->end_kern_pair; + + while (i0kern_data[i].right_gid < gid_n) + i0 = i+1; + else + i1 = i; + } + + if (i0 < glyph_data->end_kern_pair && + font->kern_data[i0].right_gid == gid_n) + return font->kern_data[i0].value; + + return 0.0; +} + +static hpgs_font *hpgs_open_font(const char *fn, const char *name) +{ + hpgs_font *ret = (hpgs_font *)malloc(sizeof(hpgs_font)); + + if (!ret) + { + hpgs_set_error(hpgs_i18n("Out of memory allocating font structure for font %s."),name); + return 0; + } + + ret->is = 0; + ret->hmtx_data = 0; + ret->loca_data = 0; + ret->loca_data_sz = 0; + + ret->kern_data = 0; + ret->kern_data_sz = 0; + + ret->glyph_cache_positions = 0; + ret->n_cached_glyphs = 0; + ret->glyph_cache = 0; + + init_font_cmap_data(&ret->cmap_data); + + init_font_post_data(&ret->post_data); + + ret->is = hpgs_new_file_istream(fn); + + if (!ret->is) + { + hpgs_set_error(hpgs_i18n("Cannot open font %s in file %s."),name,fn); + goto error; + } + + if (read_header(&ret->header,ret->is)) + { + hpgs_set_error(hpgs_i18n("Error reading header of font %s."),name); + goto error; + } + + if (read_head_table(ret)) + { + hpgs_set_error(hpgs_i18n("Error reading table %s of font %s."),"head",name); + goto error; + } + + if (read_hhea_table(ret)) + { + hpgs_set_error(hpgs_i18n("Error reading table %s of font %s."),"hhea",name); + goto error; + } + + if (read_maxp_table(ret)) + { + hpgs_set_error(hpgs_i18n("Error reading table %s of font %s."),"maxp",name); + goto error; + } + + if (read_hmtx_table(ret)) + { + hpgs_set_error(hpgs_i18n("Error reading table %s of font %s."),"hmtx",name); + goto error; + } + + if (read_loca_table(ret)) + { + hpgs_set_error(hpgs_i18n("Error reading table %s of font %s."),"loca",name); + goto error; + } + + if (read_cmap_table(ret)) + { + hpgs_set_error(hpgs_i18n("Error reading table %s of font %s."),"cmap",name); + goto error; + } + + if (read_post_table(ret)) + { + hpgs_set_error(hpgs_i18n("Error reading table %s of font %s."),"post",name); + goto error; + } + + if (read_kern_table(ret)) + { + hpgs_set_error(hpgs_i18n("Error reading table %s of font %s."),"kern",name); + goto error; + } + + ret->glyph_cache = + (hpgs_font_glyph_data *)malloc(sizeof(hpgs_font_glyph_data)*ret->maxp_data.numGlyphs); + + if (!ret->glyph_cache) goto error; + + ret->glyph_cache_positions = + (int *)malloc(sizeof(int)*ret->maxp_data.numGlyphs); + + if (!ret->glyph_cache_positions) goto error; + + int i; + + for (i=0;imaxp_data.numGlyphs;++i) + ret->glyph_cache_positions[i] = -1; + + hpgs_mutex_init(&ret->mutex); + ret->nref = 1; + return ret; + + error: + if (ret->glyph_cache_positions) free(ret->glyph_cache_positions); + if (ret->glyph_cache) free(ret->glyph_cache); + + if (ret->kern_data) free(ret->kern_data); + cleanup_font_cmap_data(&ret->cmap_data); + cleanup_font_post_data(&ret->post_data); + if (ret->loca_data) free(ret->loca_data); + if (ret->hmtx_data) free(ret->hmtx_data); + if (ret->is) hpgs_istream_close(ret->is); + free(ret); + return 0; +} + + +/*! + Loads the given font from disk. Depending on your operating system, + the appropriate font directories are scanned for a truetype file which + contains the font of the given name. + \c name is expected to be utf-8 encoded, which is almost no problem, + since all known font names are ASCII-encoded. + */ +hpgs_font *hpgs_find_font(const char *name) +{ + // read font directory if not done yet + if (hpgs_scan_font_dirs()) return 0; + + // binary search in font directory. + size_t i0 = 0; + size_t i1 = font_directory_sz; + + // binary search for the endCode. + while (i0 < i1) + { + size_t i = i0+(i1-i0)/2; + + if (strcmp(font_directory[i].font_name,name) < 0) + i0 = i+1; + else + i1 = i; + } + + if (i0 >= font_directory_sz || strcmp(font_directory[i0].font_name,name)) + { + hpgs_set_error(hpgs_i18n("Cannot find font %s."),name); + return 0; + } + + if (font_directory[i0].font == 0) + { + hpgs_mutex_lock(&font_dir_mutex); + if (font_directory[i0].font == 0) + font_directory[i0].font = hpgs_open_font(font_directory[i0].filename, + font_directory[i0].font_name); + hpgs_mutex_unlock(&font_dir_mutex); + } + + if (font_directory[i0].font == 0) return 0; + + hpgs_mutex_lock(&font_directory[i0].font->mutex); + ++font_directory[i0].font->nref; + hpgs_mutex_unlock(&font_directory[i0].font->mutex); + return font_directory[i0].font; +} + + +/*! + Frees all resources associated with this font object. + */ +void hpgs_destroy_font(hpgs_font *font) +{ + hpgs_mutex_lock(&font->mutex); + --font->nref; + hpgs_bool have_refs = (font->nref>0); + hpgs_mutex_unlock(&font->mutex); + + if (have_refs) return; + + if (font->glyph_cache_positions) free(font->glyph_cache_positions); + + unsigned gid; + + for (gid=0;gidn_cached_glyphs;++gid) + cleanup_font_glyph_data(&font->glyph_cache[gid]); + + if (font->glyph_cache) free(font->glyph_cache); + + if (font->kern_data) free(font->kern_data); + + cleanup_font_cmap_data(&font->cmap_data); + cleanup_font_post_data(&font->post_data); + if (font->loca_data) free(font->loca_data); + if (font->hmtx_data) free(font->hmtx_data); + if (font->is) hpgs_istream_close(font->is); + hpgs_mutex_destroy(&font->mutex); + free(font); +} + +/*! + Gets the maximal ascent of the font. + */ +double hpgs_font_get_ascent(hpgs_font *font) +{ + return (double)font->hhea_data.ascent / (double)font->head_data.unitsPerEm; +} + +/*! + Gets the maximal descent of the font. + */ +double hpgs_font_get_descent(hpgs_font *font) +{ + return (double)font->hhea_data.descent / (double)font->head_data.unitsPerEm; +} + +/*! + Gets the typographical line gap of the font. + */ +double hpgs_font_get_line_gap(hpgs_font *font) +{ + return (double)font->hhea_data.lineGap / (double)font->head_data.unitsPerEm; +} + +/*! + Gets the height of capital letters above the baseline, + computed from the size of the capital letter M. + */ +double hpgs_font_get_cap_height(hpgs_font *font) +{ + unsigned gid = cmap_find_unicode(font,'M'); + + hpgs_font_glyph_data *glyph_data = find_glyph_gid(font,gid); + + if (!glyph_data) + return hpgs_set_error(hpgs_i18n("Error reading glyph number %d from file."),(int)gid); + + return glyph_data->bbox.ury; +} + +/*! + Gets the number of glyphs in this font. This information might + be useful, if you keep a hash map with additional information for + the glyphs. + */ +unsigned hpgs_font_get_glyph_count(hpgs_font *font) +{ + return font->maxp_data.numGlyphs; +} + +/*! + Gets the glyph ID of the given unicode character. The + returned glpyh id is used by several other font functions. + */ +unsigned hpgs_font_get_glyph_id(hpgs_font *font, int uc) +{ + return cmap_find_unicode(font,uc); +} + +/*! + Gets the PostScript glyph name of the specified glpyh id. + This function retunrs a null pointer, if the glyph does not have + a PostScript name. In this situation you can use a glyph name + of the form \c uniXXXX, where XXXX is the upppercase 4-digit + hexadecimal unicode of the glpyh. + + You can get a glyph id for a given unicode character + using \c hpgs_font_get_glyph_id. + + Return -1, if an error occurrs. + */ +const char *hpgs_font_get_glyph_name(hpgs_font *font, unsigned gid) +{ + if (gid > font->post_data.numberOfGlyphs) return 0; + + return font->post_data.names[gid]; +} + +/*! + Gets the bounding box of the specified glpyh id. + + You can get a glyph id for a given unicode character + using \c hpgs_font_get_glyph_id. + + Return -1, if an error occurrs. + */ +int hpgs_font_get_glyph_bbox(hpgs_font *font, hpgs_bbox *bb, unsigned gid) +{ + hpgs_font_glyph_data *glyph_data = find_glyph_gid(font,gid); + + if (!glyph_data) + return hpgs_set_error(hpgs_i18n("Error reading glyph number %d from file."),(int)gid); + + *bb = glyph_data->bbox; + + return 0; +} + +/*! + Gets the horizontal and vertical advance of the given glyph + id. The unit of the returned vector is em, the nominal size + of the letter M of the font. For almost any font one em is actually + larger than the size of the capital letter M. + + You can get a glyph id for a given unicode character + using \c hpgs_font_get_glyph_id. + + Return -1, if an error occurrs. + */ +int hpgs_font_get_glyph_metrics(hpgs_font *font, hpgs_point *m, unsigned gid) +{ + if (gid > font->maxp_data.numGlyphs) gid = 0; + + m->x = (double)font->hmtx_data[gid].advanceWidth/(double)font->head_data.unitsPerEm; + m->y = 0.0; + + return 0; +} + +/*! + Gets the horizontal and vertical kerning correction for the given glyph + ids. The unit of the returned vector is em, the nominal size + of the letter M of the font. For almost any font one em is actually + larger than the size of the capital letter M. + + You can get a glyph id for a given unicode character + using \c hpgs_font_get_glyph_id. + + Return -1, if an error occurrs. + */ +int hpgs_font_get_kern_metrics(hpgs_font *font, hpgs_point *m, unsigned gid_l, unsigned gid_r) +{ + if (!font->kern_data) { m->y = m->x = 0.0; return 0; } + + m->x = find_kern_value(font,gid_l,gid_r); + m->y = 0.0; + + return 0; +} + +/*! + Gets the horizontal and vertical advance of the given unicode + string given in utf8 encoding. The unit of the returned vector is em, + the nominal size of the letter M of the font. For almost any font + one em is actually larger than the size of the capital letter M. + + Return -1, if an error occurrs. + */ +int hpgs_font_get_utf8_metrics(hpgs_font *font, hpgs_point *m, const char *str, int strlen) +{ + m->x = 0.0; + m->y = 0.0; + + if (strlen == 0) return 0; + + const char *s = str; + + int uc = hpgs_next_utf8(&s); + unsigned gid = cmap_find_unicode(font,uc); + + while (uc != 0) + { + m->x += (double)font->hmtx_data[gid].advanceWidth/(double)font->head_data.unitsPerEm; + + if (strlen >= 0 && (s - str) >= strlen) return 0; + + // next glyph + uc = hpgs_next_utf8(&s); + + // end of string. + if (uc == 0) return 0; + + unsigned gid_n = cmap_find_unicode(font,uc); + + m->x += find_kern_value(font,gid,gid_n); + + gid = gid_n; + } + + return 0; +} + +// dispatch a 2nd order spline +static int quad_to(void *ctxt, + hpgs_curveto_func_t curveto_func, + const hpgs_point *p0, + const hpgs_point *p1, + const hpgs_point *p2 ) +{ + hpgs_point pm0,pm1; + + pm0.x = (1.0/3.0) * p0->x + (2.0/3.0) * p1->x; + pm0.y = (1.0/3.0) * p0->y + (2.0/3.0) * p1->y; + + pm1.x = (1.0/3.0) * p2->x + (2.0/3.0) * p1->x; + pm1.y = (1.0/3.0) * p2->y + (2.0/3.0) * p1->y; + + return curveto_func(ctxt,&pm0,&pm1,p2); +} + +static int decompose_glyph_internal(hpgs_font *font, + void *ctxt, + hpgs_moveto_func_t moveto_func, + hpgs_lineto_func_t lineto_func, + hpgs_curveto_func_t curveto_func, + const hpgs_matrix *m, + unsigned gid) +{ + hpgs_font_glyph_data *glyph_data = find_glyph_gid(font,gid); + + if (!glyph_data) + return hpgs_set_error(hpgs_i18n("Error reading glyph number %d from file."),(int)gid); + + int ret = 0; + + // Output the glpyh outline. + if (glyph_data->points_sz) + { + size_t i; + hpgs_point last_out = {0.0,0.0}; + hpgs_point start_out = {0.0,0.0}; + hpgs_point ctrl_out = {0.0,0.0}; + hpgs_font_glyph_point *start_p = 0; + hpgs_font_glyph_point *last_p = 0; + + for (i=0;ipoints_sz;++i) + { + hpgs_font_glyph_point *point = &glyph_data->points[i]; + + switch(point->flags) + { + case HPGS_FONT_GLYPH_POINT_START: + // close subpath. + if (i>0 && start_p && last_p) + { + switch (last_p->flags) + { + case HPGS_FONT_GLYPH_POINT_ONCURVE: + if (lineto_func(ctxt,&start_out) < 0) + return -1; + ++ret; + break; + case HPGS_FONT_GLYPH_POINT_CONTROL: + if (quad_to(ctxt,curveto_func,&last_out,&ctrl_out,&start_out) < 0) + return -1; + ++ret; + } + } + + hpgs_matrix_xform(&start_out,m,&point->p); + if (moveto_func(ctxt,&start_out) < 0) + return -1; + start_p = point; + last_out = start_out; + break; + + case HPGS_FONT_GLYPH_POINT_CONTROL: + { + hpgs_point c_out; + hpgs_matrix_xform(&c_out,m,&point->p); + // generate intermediate on curve point from + // consecutive control points. + + if (start_p && last_p && last_p->flags == HPGS_FONT_GLYPH_POINT_CONTROL) + { + hpgs_point out; + out.x = (ctrl_out.x + c_out.x) * 0.5; + out.y = (ctrl_out.y + c_out.y) * 0.5; + + if (quad_to(ctxt,curveto_func,&last_out,&ctrl_out,&out) < 0) + return -1; + + last_out = out; + } + ctrl_out = c_out; + } + break; + + case HPGS_FONT_GLYPH_POINT_ONCURVE: + if (start_p && last_p) + { + hpgs_point out; + hpgs_matrix_xform(&out,m,&point->p); + + switch (last_p->flags) + { + default: + // HPGS_FONT_GLYPH_POINT_ONCURVE, HPGS_FONT_GLYPH_POINT_START + if (lineto_func(ctxt,&out) < 0) + return -1; + break; + case HPGS_FONT_GLYPH_POINT_CONTROL: + if (quad_to(ctxt,curveto_func,&last_out,&ctrl_out,&out) < 0) + return -1; + } + + last_out = out; + } + } + + last_p = point; + } + // close last subpath. + if (i>0 && start_p && last_p) + { + switch (last_p->flags) + { + case HPGS_FONT_GLYPH_POINT_ONCURVE: + if (lineto_func(ctxt,&start_out) < 0) + return -1; + ++ret; + break; + case HPGS_FONT_GLYPH_POINT_CONTROL: + if (quad_to(ctxt,curveto_func,&last_out,&ctrl_out,&start_out) < 0) + return -1; + ++ret; + } + } + } + + // output referenced glyphs. + if (glyph_data->refs_sz) + { + size_t i; + + for (i=0;irefs_sz;++i) + { + hpgs_matrix mm; + + hpgs_matrix_concat(&mm,m,&glyph_data->refs[i].matrix); + + int r = decompose_glyph_internal(font,ctxt, + moveto_func,lineto_func,curveto_func, + &mm,glyph_data->refs[i].gid); + + if (r < 0) return -1; + ret += r; + } + } + + return ret; +} + +/*! + Decomposes the outline of the given glyph id + using the given moveto/linto/curveto functions and + the specified transformation matrix. + + You can get a glyph id for a given unicode character + using \c hpgs_font_get_glyph_id. + + Returns the number of outlines drawn or -1, if an error occurrs. + */ +int hpgs_font_decompose_glyph(hpgs_font *font, + void *ctxt, + hpgs_moveto_func_t moveto_func, + hpgs_lineto_func_t lineto_func, + hpgs_curveto_func_t curveto_func, + const hpgs_matrix *m, + unsigned gid) +{ + return decompose_glyph_internal(font,ctxt, + moveto_func,lineto_func,curveto_func,m,gid); +} + +/*! + Draws the outline of the given glyph id + to the given device by issuing moveto/linto/curveto/fill operations. + + You can get a glyph id for a given unicode character + using \c hpgs_font_get_glyph_id. + + Returns -1, if an error occurrs. + */ +int hpgs_font_draw_glyph(hpgs_font *font, + hpgs_device *device, + const hpgs_matrix *m, + unsigned gid) +{ + int r=hpgs_font_decompose_glyph(font,device, + (hpgs_moveto_func_t)device->vtable->moveto, + (hpgs_lineto_func_t)device->vtable->lineto, + (hpgs_curveto_func_t)device->vtable->curveto, + m,gid); + if (r<0) return -1; + if (r==0) return 0; + + return hpgs_fill(device,HPGS_FALSE); +} + +/*! + Decomposes the outline of the given utf8-encoded unicode string + using the given moveto/linto/curveto/fill functions and + the specified transformation matrix. + + Returns -1, if an error occurrs. + */ +int hpgs_font_decompose_utf8(hpgs_font *font, + void *ctxt, + hpgs_moveto_func_t moveto_func, + hpgs_lineto_func_t lineto_func, + hpgs_curveto_func_t curveto_func, + hpgs_fill_func_t fill_func, + const hpgs_matrix *m, + const char *str, int strlen) +{ + if (strlen == 0) return 0; + + const char *s = str; + + int uc = hpgs_next_utf8(&s); + uint16_t gid = cmap_find_unicode(font,uc); + + hpgs_matrix mm = *m; + + while (uc != 0) + { + int r=decompose_glyph_internal(font,ctxt, + moveto_func,lineto_func,curveto_func,&mm,gid); + + if (r<0) return -1; + + if (r>0 && fill_func(ctxt,HPGS_FALSE)) + return -1; + + if (strlen >= 0 && (s - str) >= strlen) return 0; + + double d = (double)font->hmtx_data[gid].advanceWidth/(double)font->head_data.unitsPerEm; + + // next glyph + uc = hpgs_next_utf8(&s); + + // end of string. + if (uc == 0) return 0; + + uint16_t gid_n = cmap_find_unicode(font,uc); + + d += find_kern_value(font,gid,gid_n); + + mm.dx += d * mm.mxx; + mm.dy += d * mm.myx; + gid = gid_n; + } + + return 0; +} + +/*! + Draws the outline of the given utf8-encoded unicode string + to the given device by issuing moveto/linto/curveto/fill operations. + + Returns -1, if an error occurrs. + */ +int hpgs_font_draw_utf8(hpgs_font *font, + hpgs_device *device, + const hpgs_matrix *m, const char *str, int strlen) +{ + return hpgs_font_decompose_utf8(font,device, + (hpgs_moveto_func_t)device->vtable->moveto, + (hpgs_lineto_func_t)device->vtable->lineto, + (hpgs_curveto_func_t)device->vtable->curveto, + (hpgs_fill_func_t)device->vtable->fill, + m,str,strlen); +} diff --git a/src/add-ons/translators/hpgs/lib/hpgsfont.h b/src/add-ons/translators/hpgs/lib/hpgsfont.h new file mode 100644 index 0000000000..6182f82f0d --- /dev/null +++ b/src/add-ons/translators/hpgs/lib/hpgsfont.h @@ -0,0 +1,296 @@ +/*********************************************************************** + * * + * $Id: hpgsfont.h 307 2006-03-07 08:45:04Z softadm $ + * * + * hpgs - HPGl Script, a hpgl/2 interpreter, which uses a Postscript * + * API for rendering a scene and thus renders to a variety of * + * devices and fileformats. * + * * + * (C) 2004-2006 ev-i Informationstechnologie GmbH http://www.ev-i.at * + * * + * Author: Wolfgang Glas * + * * + * hpgs is free software; you can redistribute it and/or * + * modify it under the terms of the GNU Lesser General Public * + * License as published by the Free Software Foundation; either * + * version 2.1 of the License, or (at your option) any later version. * + * * + * hpgs is distributed in the hope that it will be useful, * + * but WITHOUT ANY WARRANTY; without even the implied warranty of * + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * + * Lesser General Public License for more details. * + * * + * You should have received a copy of the GNU Lesser General Public * + * License along with this library; if not, write to the * + * Free Software Foundation, Inc., 59 Temple Place, Suite 330, * + * Boston, MA 02111-1307 USA * + * * + *********************************************************************** + * * + * Private header file for ttf font support. * + * * + ***********************************************************************/ + +#ifndef __HPGS_FONT_H__ +#define __HPGS_FONT_H__ + +#include +#include + +HPGS_INTERNAL_API void hpgs_font_init(); +HPGS_INTERNAL_API void hpgs_font_cleanup(); + +// The max. number of ttf tables to store. +#define HPGS_FONT_MAX_TTF_TABLES 32 + +typedef struct hpgs_font_header_st hpgs_font_header; +typedef struct hpgs_font_dentry_st hpgs_font_dentry; +typedef struct hpgs_font_table_entry_st hpgs_font_table_entry; +typedef struct hpgs_font_head_data_st hpgs_font_head_data; +typedef struct hpgs_font_hhea_data_st hpgs_font_hhea_data; +typedef struct hpgs_font_maxp_data_st hpgs_font_maxp_data; +typedef struct hpgs_font_longHorMetrics_st hpgs_font_longHorMetrics; +typedef struct hpgs_font_cmap_data_st hpgs_font_cmap_data; +typedef struct hpgs_font_cmap_code_range_st hpgs_font_cmap_code_range; +typedef struct hpgs_font_post_data_st hpgs_font_post_data; +typedef struct hpgs_font_glyph_point_st hpgs_font_glyph_point; +typedef struct hpgs_font_glyph_ref_st hpgs_font_glyph_ref; +typedef struct hpgs_font_glyph_data_st hpgs_font_glyph_data; +typedef struct hpgs_font_kern_pair_st hpgs_font_kern_pair; + + +struct hpgs_font_table_entry_st +{ + uint32_t tag; /* Table name */ + uint32_t checksum; /* for table */ + uint32_t offset; /* to start of table in input file */ + uint32_t length; /* length of table */ +}; + +struct hpgs_font_head_data_st { + uint32_t version; + uint32_t fontRevision; + uint32_t checkSumAdjustment; + uint32_t magicNumber; + uint16_t flags; + uint16_t unitsPerEm; + //int64_t created; + //int64_t modified; + int32_t created_low; + int32_t created_high; + int32_t modified_low; + int32_t modified_high; + int16_t xMin; + int16_t yMin; + int16_t xMax; + int16_t yMax; + uint16_t macStyle; + int16_t lowestRecPPEM; + int16_t fontDirectionHint; + int16_t indexToLocFormat; + int16_t glyphDataFormat; +}; + +struct hpgs_font_hhea_data_st { + uint32_t version; + int16_t ascent; + int16_t descent; + int16_t lineGap; + uint16_t advanceWidthMax; + int16_t minLeftSideBearing; + int16_t minRightSideBearing; + int16_t xMaxExtent; + int16_t caretSlopeRise; + int16_t caretSlopeRun; + int16_t caretOffset; + int16_t reserved1; + int16_t reserved2; + int16_t reserved3; + int16_t reserved4; + int16_t metricDataFormat; + uint16_t numOfLongHorMetrics; +}; + +struct hpgs_font_maxp_data_st { + uint32_t version; + uint16_t numGlyphs; + uint16_t maxPoints; + uint16_t maxContours; + uint16_t maxComponentPoints; + uint16_t maxComponentContours; + uint16_t maxZones; + uint16_t maxTwilightPoints; + uint16_t maxStorage; + uint16_t maxFunctionDefs; + uint16_t maxInstructionDefs; + uint16_t maxStackElements; + uint16_t maxSizeOfInstructions; + uint16_t maxComponentElements; + uint16_t maxComponentDepth; +}; + +struct hpgs_font_longHorMetrics_st +{ + uint16_t advanceWidth; + int16_t leftSideBearing; +}; + +struct hpgs_font_cmap_code_range_st +{ + uint16_t startCode; + uint16_t endCode; + uint16_t idDelta; + uint16_t idRangeOffset; +}; + +struct hpgs_font_cmap_data_st +{ + size_t ranges_sz; + hpgs_font_cmap_code_range *ranges; + + size_t glyphIndexArray_sz; + uint16_t *glyphIndexArray; +}; + +struct hpgs_font_post_data_st +{ + int32_t version; // 0x00020000 for version 2.0 + int32_t italicAngle; // Italic angle in counter-clockwise degrees from the vertical. Zero for upright text, negative for text that leans to the right (forward). + int16_t underlinePosition; // This is the suggested distance of the top of the underline from the baseline (negative values indicate below baseline). + int16_t underlineThickness; // Suggested values for the underline thickness. + uint32_t isFixedPitch; // Set to 0 if the font is proportionally spaced, non-zero if the font is not proportionally spaced (i.e. monospaced). + uint32_t minMemType42; // Minimum memory usage when an OpenType font is downloaded. + uint32_t maxMemType42; // Maximum memory usage when an OpenType font is downloaded. + uint32_t minMemType1; // Minimum memory usage when an OpenType font is downloaded as a Type 1 font. + uint32_t maxMemType1; // Maximum memory usage when an OpenType font is downloaded as a Type 1 font. + uint16_t numberOfGlyphs; // Number of glyphs (this should be the same as numGlyphs in 'maxp' table). + + const char **names; // pointer to the glyph names. + const char *name_data; // the buffer holding the actual data. +}; + +#define HPGS_FONT_GLYPH_POINT_START 1 +#define HPGS_FONT_GLYPH_POINT_ONCURVE 2 +#define HPGS_FONT_GLYPH_POINT_CONTROL 3 + +struct hpgs_font_glyph_point_st +{ + hpgs_point p; + int flags; // HPGS_FONT_GLYPH_POINT_* +}; + +struct hpgs_font_glyph_ref_st +{ + hpgs_matrix matrix; // transformation matrix + uint16_t gid; // the references glyph id. +}; + +struct hpgs_font_glyph_data_st +{ + hpgs_bbox bbox; + + size_t points_sz; + hpgs_font_glyph_point *points; + + size_t refs_sz; + size_t refs_alloc_sz; + hpgs_font_glyph_ref *refs; + + size_t begin_kern_pair; /*!< The index of the first kern pair where this glyph id the left one. */ + size_t end_kern_pair;/*!< The index of the first kern pair after \c begin_kern_pair where this glyph id is not the left one. */ +}; + +/*! + \brief A ttf kerning pair +*/ +struct hpgs_font_kern_pair_st +{ + uint16_t left_gid; /*!< The left glyph ID. */ + uint16_t right_gid; /*!< The rightt glyph ID. */ + + double value; /*!< The correction of the advynce width in em. */ +}; + + +/*! \brief A truetype font header. + + This structure holds all the header information of a truetype font + and is used when scanning a fon directory as well as a part of an + open font file. +*/ +struct hpgs_font_header_st +{ + int32_t version; /*!< 0x00010000 */ + uint16_t numtab; /*!< The number truetype tables in this file. */ + uint16_t searchRange; /*!< (Max power of 2 <= numtab) *16 */ + uint16_t entrySel; /*!< Log2(Max power of 2 <= numtab ) */ + uint16_t rangeShift; /*!< numtab*16 - searchRange */ + + hpgs_font_table_entry tables[HPGS_FONT_MAX_TTF_TABLES]; /*!< The truetype table entries. */ + + int name_table; /*!< The position of the name table. */ + int head_table; /*!< The position of the head table. */ + int hhea_table; /*!< The position of the hhea table. */ + int maxp_table; /*!< The position of the maxp table. */ + int hmtx_table; /*!< The position of the hmtx table. */ + int loca_table; /*!< The position of the loca table. */ + int cmap_table; /*!< The position of the cmap table. */ + int post_table; /*!< The position of the post table. */ + int glyf_table; /*!< The position of the glyf table. */ + int kern_table; /*!< The position of the kern table. */ +}; + +/*! \brief A truetype font. + + This structure holds all details for operating on a truetype font + file. The font file is kept open by the font object during it's + lifetime, since we operate on the font file like on a database. +*/ +struct hpgs_font_st +{ + hpgs_istream *is; /*!< The input stream to operate on. */ + + // the file header. + hpgs_font_header header; + + hpgs_font_head_data head_data; /*!< The head table. */ + hpgs_font_hhea_data hhea_data; /*!< The hhea table. */ + hpgs_font_maxp_data maxp_data; /*!< The maxp table. */ + + hpgs_font_longHorMetrics *hmtx_data; + /*!< The hmtx table. This array has a dimension of maxp_data.numGlyphs. */ + + uint32_t *loca_data; /*!< The loca table. */ + size_t loca_data_sz; /*!< The size of the loca table. */ + + hpgs_font_cmap_data cmap_data; /*!< The cmap table. */ + hpgs_font_post_data post_data; /*!< The post table. */ + + hpgs_font_kern_pair *kern_data; + size_t kern_data_sz; /*!< The size of the kern table. */ + + int *glyph_cache_positions; + /*!< The position of an individual glyph in \c glyph_cache or -1, if the glyph has not been cached yet. + This array has a dimension of maxp_data.numGlyphs + */ + + size_t n_cached_glyphs; /*!< The number of actually cached glyphs. */ + hpgs_font_glyph_data *glyph_cache; /*!< The cached glyphs. This array has a dimension of maxp_data.numGlyphs. */ + + hpgs_mutex_t mutex; /*!< The mutex to protec glyph access and reference counting. */ + size_t nref; /*!< The reference count. */ +}; + +/*! \brief A truetype font directory entry. + + This structure holds an entry in the font directory. +*/ +struct hpgs_font_dentry_st { + + char *font_name; /*!< The utf8-encoded name of the font. */ + char *filename; /*!< The filename of the font. */ + + hpgs_font *font; /*!< The font object, if this font is cached. */ +}; + +#endif diff --git a/src/add-ons/translators/hpgs/lib/hpgsglobal.c b/src/add-ons/translators/hpgs/lib/hpgsglobal.c new file mode 100644 index 0000000000..3ab62104b2 --- /dev/null +++ b/src/add-ons/translators/hpgs/lib/hpgsglobal.c @@ -0,0 +1,629 @@ +/*********************************************************************** + * * + * $Id: hpgsglobal.c 338 2006-06-17 08:33:36Z softadm $ + * * + * hpgs - HPGl Script, a hpgl/2 interpreter, which uses a Postscript * + * API for rendering a scene and thus renders to a variety of * + * devices and fileformats. * + * * + * (C) 2004-2006 ev-i Informationstechnologie GmbH http://www.ev-i.at * + * * + * Author: Wolfgang Glas * + * * + * hpgs is free software; you can redistribute it and/or * + * modify it under the terms of the GNU Lesser General Public * + * License as published by the Free Software Foundation; either * + * version 2.1 of the License, or (at your option) any later version. * + * * + * hpgs is distributed in the hope that it will be useful, * + * but WITHOUT ANY WARRANTY; without even the implied warranty of * + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * + * Lesser General Public License for more details. * + * * + * You should have received a copy of the GNU Lesser General Public * + * License along with this library; if not, write to the * + * Free Software Foundation, Inc., 59 Temple Place, Suite 330, * + * Boston, MA 02111-1307 USA * + * * + *********************************************************************** + * * + * Global resources of HPGS. * + * * + ***********************************************************************/ + +#include +#include +#include +#include +#include +#include +#include +#include + +#ifdef WIN32 +#include + +static DWORD tls_handle = -1; +/* Use a separate heap for the error messages. This heap is + destroyed in hpgs_cleanup, so we risk no lost pointers. */ +static HANDLE hHeap = 0; + +/*! A counterpart of vsprintf, which allocates the result string + on the heap an is save against buffer overflows. + + Returns 0, if the system is out of memory. +*/ +static char* vsprintf_hHeap (const char *fmt, va_list ap) +{ + /* Guess we need no more than 1024 bytes. */ + int n, size = 1024; + char *p; + if ((p = HeapAlloc (hHeap,0,size)) == NULL) + return p; + + while (1) + { + /* Try to print in the allocated space. */ + n = _vsnprintf (p, size, fmt, ap); + /* If that worked, return the string. */ + if (n > -1 && n < size) + { return p; } + /* Else try again with more space. */ + if (n > -1) /* glibc 2.1 */ + size = n+1; /* precisely what is needed */ + else /* glibc 2.0 */ + size *= 2; /* twice the old size */ + + { + char *np = HeapReAlloc (hHeap,0,p,size); + + if (!np) { HeapFree(hHeap,0,p); return 0; } + p = np; + } + } +} + +static char* sprintf_hHeap (const char *fmt, ...) +{ + va_list ap; + char *ret; + + va_start(ap, fmt); + ret = vsprintf_hHeap(fmt,ap); + va_end(ap); + + return ret; +} + +#else +#include + +static pthread_key_t key; +#endif + +static char *hpgs_reader_prefix=0; + +/*! This function has to be called before using any other + function of hpgs. It defines the path, where additional + files such as the truetype files for HPGL files or plugins + are stored. + + Truetype fonts are searched in the path /share/hpgs + + The path is internally duplicated using \c strdup. +*/ +void hpgs_init(const char *path) +{ + int l; + + hpgs_reader_prefix = strdup(path); + + if (!hpgs_reader_prefix) return; + + // strip off trailing directory separators. + l = strlen(hpgs_reader_prefix); + + if (l && hpgs_reader_prefix[l-1] == HPGS_PATH_SEPARATOR) + hpgs_reader_prefix[l-1] = '\0'; + +#ifdef WIN32 + hHeap = HeapCreate(0,4096,128*1024); + tls_handle = TlsAlloc(); +#else + pthread_key_create (&key,free); +#endif +#ifdef HPGS_HAVE_GETTEXT + hpgs_i18n_init(); +#endif + hpgs_font_init(); +} + +/*! This function return a pointer to the installation prefix + set through \c hpgs_init. The returned string has any trailing + directory separator of the string passed to \c hpgs_init stripped + off. +*/ +HPGS_API const char *hpgs_get_prefix() +{ + if (hpgs_reader_prefix) + return hpgs_reader_prefix; + +#ifdef WIN32 + return "C:\\Programme\\EV-i"; +#else +#ifndef HPGS_DEFAULT_PREFIX + return "/usr/local"; +#else + return HPGS_DEFAULT_PREFIX; +#endif +#endif +} + +/*! This function has to be called atfer the last usage of hpgs. + It cleans up internally allocated resources. +*/ +void hpgs_cleanup() +{ + hpgs_font_cleanup(); + + hpgs_cleanup_plugin_devices(); + + if (hpgs_reader_prefix) + { + free(hpgs_reader_prefix); + hpgs_reader_prefix = 0; + } +#ifdef WIN32 + TlsFree(tls_handle); + HeapDestroy(hHeap); + hHeap=0; + tls_handle=-1; +#else + hpgs_clear_error(); + pthread_key_delete (key); +#endif +} + +/*! Get the value of the command line argument argv[0], + if the argument starts with \c opt. + + This subroutine is useful when parsing command lines + like in the following loop: + +\verbatim +int main(int argc, const char *argv[]) +{ + while (argc>1) + { + int narg = 1; + const char *value; + + if (hpgs_get_arg_value("-r",argv,&value,&narg)) + { + ...parse value of option -r... + } + else if (hpgs_get_arg_value("-p",argv,&value,&narg)) + { + ...parse value of option -p... + } + else + { + if (argv[0][0] == '-') + { + fprintf(stderr,"Error: Unknown option %s given.\n",argv[0]); + return usage(); + } + break; + } + + argv+=narg; + argc-=narg; + } + +\endverbatim + + Returns \c HPGS_TRUE, if argv[0] starts with opt. + If \c *narg == 2, argv[0] is exactly \c opt and + \c *value points to \c argv[1]. + If \c *narg == 1, argv[0] startwith \c opt and + \c *value points to \c argv[0]+strlen(opt). + + Returns \c HPGS_FALSE, if argv[0] does not start with \c opt. +*/ +hpgs_bool hpgs_get_arg_value(const char *opt, const char *argv[], + const char **value, int *narg) +{ + int l = strlen(opt); + if (strncmp(opt,argv[0],l)!=0) + return 0; + + if (l == strlen(argv[0])) + { + *value = argv[1]; + *narg = 2; + } + else + { + *value = argv[0] + l; + *narg = 1; + } + + return 1; +} + +/*! This subroutine encapsulates the standard C library function \c realloc. + This is needed in order to aviod hassels when \c realloc returns + a null pointer and the original pointer is still needed for subsequent + deallocations. + + \c itemsz is the size of the individual items in the array. + \c pptr is a pointer to the pointer holding te address of the array. + On success, \c *pptr points to the newly allocated array, otherwise + \c *pptr is untouched. + \c psz is a pointer to the allocated size of the array . + On success, *psz hold the new size \c nsz of the array, + otherwise \c *psz is untouched. + + Returns 0 upon success or -1 if the system is out of memory. +*/ +int hpgs_array_safe_resize (size_t itemsz, void **pptr, size_t *psz, size_t nsz) +{ + void *np = realloc(*pptr,nsz*itemsz); + if (!np) return -1; + *pptr=np; + *psz=nsz; + return 0; +} + +/*! A counterpart of vsprintf, which allocates the result string + on the heap an is save against buffer overflows. + + Returns 0, if the system is out of memory. +*/ +char* hpgs_vsprintf_malloc (const char *fmt, va_list ap) +{ + /* Guess we need no more than 1024 bytes. */ + int n, size = 1024; + char *p; + if ((p = malloc (size)) == NULL) + return p; + + while (1) + { + /* Try to print in the allocated space. */ + va_list aq; + va_copy(aq, ap); +#ifdef WIN32 + n = _vsnprintf (p, size, fmt, aq); +#else + n = vsnprintf (p, size, fmt, aq); +#endif + va_end(aq); + /* If that worked, return the string. */ + if (n > -1 && n < size) + { return p; } + /* Else try again with more space. */ + if (n > -1) /* glibc 2.1 */ + size = n+1; /* precisely what is needed */ + else /* glibc 2.0 */ + size *= 2; /* twice the old size */ + + { + char *np = realloc (p, size); + + if (!np) { free(p); return 0; } + p = np; + } + } +} + +/*! A counterpart of sprintf, which allocates the result string + on the heap an is save against buffer overflows. + + Returns 0, if the system is out of memory. +*/ +char* hpgs_sprintf_malloc (const char *fmt, ...) +{ + va_list ap; + char *ret; + + va_start(ap, fmt); + ret = hpgs_vsprintf_malloc(fmt,ap); + va_end(ap); + + return ret; +} + +/*! Constructs a filename on the heap for a file located in the + installation path passed to \c hpgs_init. + + Returns 0, if the system is out of memory. +*/ +char *hpgs_share_filename(const char *rel_filename) +{ + return hpgs_sprintf_malloc("%s%cshare%chpgs%c%s", + hpgs_get_prefix(), + HPGS_PATH_SEPARATOR, + HPGS_PATH_SEPARATOR, + HPGS_PATH_SEPARATOR, + rel_filename); +} + +/*! Set the error message of the current thread to the given string. + + Always returns -1. +*/ +int hpgs_set_error(const char *fmt, ...) +{ + va_list ap; + int ret; + + va_start(ap, fmt); + ret = hpgs_set_verror(fmt,ap); + va_end(ap); + + return ret; +} + +/*! Prepends the error message of the current thread with the given string. + this is useful, if you want to push context information + to the error message. + + Always returns -1. +*/ +int hpgs_error_ctxt(const char *fmt, ...) +{ + va_list ap; + int ret; + + va_start(ap, fmt); + ret = hpgs_verror_ctxt(fmt,ap); + va_end(ap); + + return ret; +} + +/*! Set the error message of the current thread to the given string. + + Always returns -1. +*/ +int hpgs_set_verror(const char *fmt, va_list ap) +{ + char *x; +#ifdef WIN32 + x = (char *)TlsGetValue(tls_handle); + if (x) HeapFree(hHeap,0,x); + x = vsprintf_hHeap(fmt,ap); + TlsSetValue(tls_handle,x); +#else + x = (char *)pthread_getspecific (key); + if (x) free(x); + + va_list aq; + va_copy(aq, ap); + x = hpgs_vsprintf_malloc(fmt,aq); + va_end(aq); + + pthread_setspecific (key,x); +#endif + return -1; +} + +/*! + Clears the error message of the current thread. +*/ +void hpgs_clear_error() +{ + char *x; +#ifdef WIN32 + x = (char *)TlsGetValue(tls_handle); + if (x) HeapFree(hHeap,0,x); + TlsSetValue(tls_handle,0); +#else + x = (char *)pthread_getspecific (key); + if (x) free(x); + pthread_setspecific (key,0); +#endif +} + +/*! + Checks, whther the error message of the current thread has been set. +*/ +HPGS_API hpgs_bool hpgs_have_error() +{ + char *x; +#ifdef WIN32 + x = (char *)TlsGetValue(tls_handle); +#else + x = (char *)pthread_getspecific (key); +#endif + return x != 0; +} + +/*! Prepends the error message of the current thread with the given string. + this is useful, if you want to push context information + to the error message. + + Always returns -1. +*/ +int hpgs_verror_ctxt(const char *fmt, va_list ap) +{ + char *x; +#ifdef WIN32 + x = (char *)TlsGetValue(tls_handle); + + if (!fmt) return -1; + + char * new_p = vsprintf_hHeap(fmt,ap); + + if (!new_p) return -1; + + if (x) + { + char *tmp = sprintf_hHeap("%s: %s",new_p,x); + HeapFree(hHeap,0,new_p); + + if (!tmp) return -1; + + HeapFree(hHeap,0,x); + new_p = tmp; + } + + TlsSetValue(tls_handle,new_p); + +#else + x = (char *)pthread_getspecific (key); + + char * new_p = hpgs_vsprintf_malloc(fmt,ap); + + if (!new_p) return -1; + + if (x) + { + char *tmp = hpgs_sprintf_malloc("%s: %s",new_p,x); + free(new_p); + + if (!tmp) return -1; + + free(x); + new_p = tmp; + } + + pthread_setspecific (key,new_p); +#endif + return -1; +} + +/*! + Get the error message of the current thread. +*/ +const char *hpgs_get_error() +{ + const char *ret; +#ifdef WIN32 + ret = (char *)TlsGetValue(tls_handle); +#else + ret = (char *)pthread_getspecific (key); +#endif + + if (!ret) ret = hpgs_i18n("(no error)"); + return ret; +} + +static void default_hpgs_logger(const char *fmt, va_list ap) +{ + va_list aq; + va_copy(aq, ap); + vfprintf(stderr,fmt,aq); + va_end(ap); +} + +static hpgs_logger_func_t static_logger = default_hpgs_logger; + +/*! + Set the logging function for logging informational messages. + If \c func is NULL, the default logging function, which log to + \c stderr is restored. + + Warning: This function is not thread-safe and should be called + just after \c hpgs_init() at the beginning of the program. +*/ +void hpgs_set_logger(hpgs_logger_func_t func) +{ + if (func) + static_logger = func; + else + static_logger = default_hpgs_logger; +} + +/*! + Logs an informational message using the function set with + \c hpgs_set_logger(). If no function is set with \c hpgs_set_logger(), + the message is printed to \c stderr. +*/ +void hpgs_log(const char *fmt, ...) +{ + va_list ap; + + va_start(ap, fmt); + static_logger(fmt,ap); + va_end(ap); +} + +/*! + Logs an informational message using the function set with + \c hpgs_set_logger(). If no function is set with \c hpgs_set_logger(), + the message is printed to \c stderr. +*/ +void hpgs_vlog(const char *fmt, va_list ap) +{ + va_list aq; + va_copy(aq, ap); + static_logger(fmt,aq); + va_end(aq); +} + +/*! + Returns the character code at the given position in an utf-8 string. + The pointer \c (*p) is advanced to the next character after the current + position. +*/ +int hpgs_next_utf8(const char **p) +{ + int ret; + + if (((unsigned char)**p & 0x80) == 0) + ret = **p; + else + { + // Hit in the middle of a multibyte sequence + // -> return EOS. + if (((unsigned char)**p & 0xC0) == 0x80) + ret = 0; + else + { + // true multibyte sequence + int mask = 0x20; + int need = 2; + ret = 0x1f; + + while (**p & mask) + { ret >>= 1; mask >>=1; ++need; } + + ret &= **p; + + while (--need) + { + ++(*p); + if (((**p) & 0xc0) != 0x80) { return 0; } + ret = (ret << 6) | ((**p) & 0x3f); + } + } + } + + ++(*p); + return ret; +} + +/*! + Returns the number of unicode characters contained in the first \c n bytes + of the given utf-8 string. If the null character is encountered, the + interpretation is stopped before the n'th byte. + + if \c n == -1, the string is ultimatively search up to the first occurrence + of the null character. + + The pointer \c (*p) is advanced to the next character after the current + position. +*/ +HPGS_API int hpgs_utf8_strlen(const char *p, int n) +{ + const char **pp = &p; + + int ret = 0; + + while ((n<0 || ((*pp) - p) < n) && hpgs_next_utf8(pp) != 0) + ++ret; + + return ret; +} diff --git a/src/add-ons/translators/hpgs/lib/hpgsgstate.c b/src/add-ons/translators/hpgs/lib/hpgsgstate.c new file mode 100644 index 0000000000..e29bee9db9 --- /dev/null +++ b/src/add-ons/translators/hpgs/lib/hpgsgstate.c @@ -0,0 +1,112 @@ +/*********************************************************************** + * * + * $Id: hpgsgstate.c 270 2006-01-29 21:12:23Z softadm $ + * * + * hpgs - HPGl Script, a hpgl/2 interpreter, which uses a Postscript * + * API for rendering a scene and thus renders to a variety of * + * devices and fileformats. * + * * + * (C) 2004-2006 ev-i Informationstechnologie GmbH http://www.ev-i.at * + * * + * Author: Wolfgang Glas * + * * + * hpgs is free software; you can redistribute it and/or * + * modify it under the terms of the GNU Lesser General Public * + * License as published by the Free Software Foundation; either * + * version 2.1 of the License, or (at your option) any later version. * + * * + * hpgs is distributed in the hope that it will be useful, * + * but WITHOUT ANY WARRANTY; without even the implied warranty of * + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * + * Lesser General Public License for more details. * + * * + * You should have received a copy of the GNU Lesser General Public * + * License along with this library; if not, write to the * + * Free Software Foundation, Inc., 59 Temple Place, Suite 330, * + * Boston, MA 02111-1307 USA * + * * + *********************************************************************** + * * + * The implementation of the public API for the gstate. * + * * + ***********************************************************************/ + +#include +#include +#include + +/*! Creates a new gstate on the heap. + Use \c hpgs_gstate_destroy in order to destroy the returned + gstate pointer. + + A null pointer is returned, if the system is out of memory. +*/ +hpgs_gstate *hpgs_new_gstate() +{ + hpgs_gstate *ret = (hpgs_gstate *)malloc(sizeof(hpgs_gstate)); + + if (ret) + { + ret->line_cap = hpgs_cap_butt; + ret->line_join = hpgs_join_miter; + ret->color.r = 0.0; + ret->color.g = 0.0; + ret->color.b = 0.0; + ret->miterlimit = 5.0; + ret->linewidth = 1.0; + ret->n_dashes = 0; + ret->dash_lengths = 0; + ret->dash_offset = 0.0; + // ROP3 function: destination = source or pattern. + ret->rop3 = 252; + ret->src_transparency = HPGS_TRUE; + ret->pattern_transparency = HPGS_TRUE; + + ret->pattern_color.r = 0.0; + ret->pattern_color.g = 0.0; + ret->pattern_color.b = 0.0; + } + return ret; +} + +/*! Destroys a gstate created using \c hpgs_new_gstate. +*/ +void hpgs_gstate_destroy(hpgs_gstate *gstate) +{ + if (!gstate) return; + if (gstate->dash_lengths) free(gstate->dash_lengths); + free (gstate); +} + +/*! Sets the dashes of \c gstate. The passed array and offset + folow th esemantics of PostScipt's \c setdash command. + + Return value: + \li 0 Success. + \li -1 The system is out of memory. +*/ +int hpgs_gstate_setdash(hpgs_gstate *gstate, + const float *dash_lengths, + unsigned n_dashes, double offset) +{ + if (gstate->dash_lengths) free(gstate->dash_lengths); + + gstate->n_dashes = n_dashes; + gstate->dash_offset = offset; + + if (gstate->n_dashes) + { + gstate->dash_lengths = (float *)malloc(sizeof(float)*gstate->n_dashes); + if (!gstate->dash_lengths) + { + gstate->n_dashes = 0; + return -1; + } + + memmove(gstate->dash_lengths,dash_lengths,sizeof(float)*gstate->n_dashes); + } + else + gstate->dash_lengths = 0; + + return 0; +} diff --git a/src/add-ons/translators/hpgs/lib/hpgsi18n.c b/src/add-ons/translators/hpgs/lib/hpgsi18n.c new file mode 100644 index 0000000000..cf0e63c95b --- /dev/null +++ b/src/add-ons/translators/hpgs/lib/hpgsi18n.c @@ -0,0 +1,75 @@ +/*********************************************************************** + * * + * $Id: hpgsi18n.c 270 2006-01-29 21:12:23Z softadm $ + * * + * hpgs - HPGl Script, a hpgl/2 interpreter, which uses a Postscript * + * API for rendering a scene and thus renders to a variety of * + * devices and fileformats. * + * * + * (C) 2004-2006 ev-i Informationstechnologie GmbH http://www.ev-i.at * + * * + * Author: Wolfgang Glas * + * * + * hpgs is free software; you can redistribute it and/or * + * modify it under the terms of the GNU Lesser General Public * + * License as published by the Free Software Foundation; either * + * version 2.1 of the License, or (at your option) any later version. * + * * + * hpgs is distributed in the hope that it will be useful, * + * but WITHOUT ANY WARRANTY; without even the implied warranty of * + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * + * Lesser General Public License for more details. * + * * + * You should have received a copy of the GNU Lesser General Public * + * License along with this library; if not, write to the * + * Free Software Foundation, Inc., 59 Temple Place, Suite 330, * + * Boston, MA 02111-1307 USA * + * * + *********************************************************************** + * * + * Private subroutines used by subroutines of the library. * + * * + ***********************************************************************/ + +#include + +#ifdef HPGS_HAVE_GETTEXT + +#define HPGS_I18N_DOMAIN "hpgs" + +void hpgs_i18n_init() +{ + char *sp = hpgs_sprintf_malloc("%s%cshare%clocale", + hpgs_get_prefix(), + HPGS_PATH_SEPARATOR, + HPGS_PATH_SEPARATOR); + + if (!sp) return; + + bindtextdomain(HPGS_I18N_DOMAIN,sp); + free(sp); +} + +const char *hpgs_i18n(const char *msg) +{ + return dgettext(HPGS_I18N_DOMAIN,msg); +} + +const char *hpgs_i18n_n(const char *msg, + const char *msg_plural, + unsigned long n) +{ + return dngettext(HPGS_I18N_DOMAIN,msg,msg_plural,n); +} + +#else + +const char *hpgs_i18n(const char *msg) +{ return msg; } + +const char *hpgs_i18n_n(const char *msg, + const char *msg_plural, + unsigned long n) +{ return n==1 ? msg : msg_plural; } + +#endif // HPGS_HAVE_GETTEXT diff --git a/src/add-ons/translators/hpgs/lib/hpgsi18n.h b/src/add-ons/translators/hpgs/lib/hpgsi18n.h new file mode 100644 index 0000000000..d689bcdbff --- /dev/null +++ b/src/add-ons/translators/hpgs/lib/hpgsi18n.h @@ -0,0 +1,46 @@ +/*********************************************************************** + * * + * $Id: hpgsi18n.h 270 2006-01-29 21:12:23Z softadm $ + * * + * hpgs - HPGl Script, a hpgl/2 interpreter, which uses a Postscript * + * API for rendering a scene and thus renders to a variety of * + * devices and fileformats. * + * * + * (C) 2004-2006 ev-i Informationstechnologie GmbH http://www.ev-i.at * + * * + * Author: Wolfgang Glas * + * * + * hpgs is free software; you can redistribute it and/or * + * modify it under the terms of the GNU Lesser General Public * + * License as published by the Free Software Foundation; either * + * version 2.1 of the License, or (at your option) any later version. * + * * + * hpgs is distributed in the hope that it will be useful, * + * but WITHOUT ANY WARRANTY; without even the implied warranty of * + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * + * Lesser General Public License for more details. * + * * + * You should have received a copy of the GNU Lesser General Public * + * License along with this library; if not, write to the * + * Free Software Foundation, Inc., 59 Temple Place, Suite 330, * + * Boston, MA 02111-1307 USA * + * * + *********************************************************************** + * * + * Private subroutines used by i18n facilities of the library. * + * * + ***********************************************************************/ + +#ifndef __HPGS_I18N_H__ +#define __HPGS_I18N_H__ + +#include + +#ifdef HPGS_HAVE_GETTEXT + +#include + +HPGS_INTERNAL_API void hpgs_i18n_init(); +#endif // HPGS_HAVE_GETTEXT + +#endif // ! __HPGS_I18N_H__ diff --git a/src/add-ons/translators/hpgs/lib/hpgsimage.c b/src/add-ons/translators/hpgs/lib/hpgsimage.c new file mode 100644 index 0000000000..d24510e9be --- /dev/null +++ b/src/add-ons/translators/hpgs/lib/hpgsimage.c @@ -0,0 +1,1303 @@ +/*********************************************************************** + * * + * $Id: hpgsimage.c 386 2007-03-18 18:33:10Z softadm $ + * * + * hpgs - HPGl Script, a hpgl/2 interpreter, which uses a Postscript * + * API for rendering a scene and thus renders to a variety of * + * devices and fileformats. * + * * + * (C) 2004-2006 ev-i Informationstechnologie GmbH http://www.ev-i.at * + * * + * Author: Wolfgang Glas * + * * + * hpgs is free software; you can redistribute it and/or * + * modify it under the terms of the GNU Lesser General Public * + * License as published by the Free Software Foundation; either * + * version 2.1 of the License, or (at your option) any later version. * + * * + * hpgs is distributed in the hope that it will be useful, * + * but WITHOUT ANY WARRANTY; without even the implied warranty of * + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * + * Lesser General Public License for more details. * + * * + * You should have received a copy of the GNU Lesser General Public * + * License along with this library; if not, write to the * + * Free Software Foundation, Inc., 59 Temple Place, Suite 330, * + * Boston, MA 02111-1307 USA * + * * + *********************************************************************** + * * + * The implementation of the public API for the pixel image. * + * * + ***********************************************************************/ + +#include +#include +#include +#ifdef __BEOS__ +#include +#else +#include +#endif + +/*! \defgroup image The public pixel image API. + + The structures and functions in this group handle the + creation and manipulation of rectangular pixel containers. +*/ + +/* image methods. */ +static int pim_get_pixel_8 (const hpgs_image *_this, + int x, int y, hpgs_paint_color *c, double *alpha) +{ + const hpgs_png_image *pim = (const hpgs_png_image *)_this; + + unsigned char *row = pim->data + pim->bytes_per_row * y; + + c->r = row[x]; + c->g = row[x]; + c->b = row[x]; + c->index = -1; + + if (alpha) + *alpha = 1.0; + + return 0; +} + +static int pim_put_pixel_8 (hpgs_image *_this, + int x, int y, const hpgs_paint_color *c, double alpha) +{ + hpgs_png_image *pim = (hpgs_png_image *)_this; + + unsigned char *row = pim->data + pim->bytes_per_row * y; + + int gray = + (11 * (int)c->r + 16 * (int)c->g + 5 * (int)c->b)/32; + + if (alpha >= 1.0) + row[x] = (unsigned char)(gray); + else if (alpha > 0.0) + row[x] = (unsigned char)(gray * alpha + row[x] * (1.0-alpha)); + + return 0; +} + +static int pim_put_chunk_8 (hpgs_image *_this, + int x1, int x2, int y, const hpgs_paint_color *c) +{ + hpgs_png_image *pim = (hpgs_png_image *)_this; + + unsigned char *row = pim->data + pim->bytes_per_row * y; + + int gray = + (11 * (int)c->r + 16 * (int)c->g + 5 * (int)c->b)/32; + + memset(row+x1,gray,x2-x1+1); + + return 0; +} + +static int pim_rop3_pixel_8 (hpgs_image *_this, + int x, int y, + const hpgs_paint_color *c, double alpha) +{ + hpgs_png_image *pim = (hpgs_png_image *)_this; + + unsigned char *row = pim->data + pim->bytes_per_row * y; + + int c_gray = (11 * (int)c->r + 16 * (int)c->g + 5 * (int)c->b)/32; + int p_gray = (11 * (int)pim->pattern_color.r + 16 * (int)pim->pattern_color.g + 5 * (int)pim->pattern_color.b)/32; + + if (alpha >= 1.0) + pim->rop3(&row[x],(unsigned char)(c_gray),(unsigned char)(p_gray)); + else if (alpha > 0.0) + { + unsigned char gray = row[x]; + pim->rop3(&gray,(unsigned char)(c_gray),(unsigned char)(p_gray)); + row[x] = (unsigned char)(gray * alpha + row[x] * (1.0-alpha)); + } + + return 0; +} + +static int pim_rop3_chunk_8 (hpgs_image *_this, + int x1, int x2, int y, const hpgs_paint_color *c) +{ + hpgs_png_image *pim = (hpgs_png_image *)_this; + + unsigned char *row = pim->data + pim->bytes_per_row * y; + + int c_gray = (11 * (int)c->r + 16 * (int)c->g + 5 * (int)c->b)/32; + int p_gray = (11 * (int)pim->pattern_color.r + 16 * (int)pim->pattern_color.g + 5 * (int)pim->pattern_color.b)/32; + + int x; + + for (x=x1;x<=x2;++x) + pim->rop3(&row[x],(unsigned char)(c_gray),(unsigned char)(p_gray)); + + return 0; +} + +static int pim_get_pixel_16 (const hpgs_image *_this, + int x, int y, hpgs_paint_color *c, double *alpha) +{ + const hpgs_png_image *pim = (const hpgs_png_image *)_this; + + unsigned char *row = pim->data + pim->bytes_per_row * y; + + c->r = row[2*x]; + c->g = row[2*x]; + c->b = row[2*x]; + + if (alpha) + *alpha = row[2*x+1] / 255.0; + + + return 0; +} + +static int pim_put_pixel_16 (hpgs_image *_this, + int x, int y, const hpgs_paint_color *c, double alpha) +{ + hpgs_png_image *pim = (hpgs_png_image *)_this; + + unsigned char *row = pim->data + pim->bytes_per_row * y; + + unsigned gray = + (11 * (unsigned)c->r + 16 * (unsigned)c->g + 5 * (unsigned)c->b)/32; + + if (alpha >= 1.0) + { + row[2*x] = (unsigned char)(gray); + row[2*x+1] = 0xff; + } + else if (alpha > 0.0) + { + double a0 = row[2*x+1] / 255.0; + row[2*x] = (unsigned char)(gray * alpha + row[2*x] * (1.0-alpha)); + row[2*x+1] = (unsigned char)(255.0 * (alpha + a0 * (1.0-alpha))); + } + + return 0; +} + +static int pim_put_chunk_16 (hpgs_image *_this, + int x1, int x2, int y, const hpgs_paint_color *c) +{ + hpgs_png_image *pim = (hpgs_png_image *)_this; + + unsigned char *row = pim->data + pim->bytes_per_row * y; + + unsigned gray = + (11 * (unsigned)c->r + 16 * (unsigned)c->g + 5 * (unsigned)c->b)/32; + + int i; + + for (i=2*x1;i<=2*x2;++i) + { + row[i] = (unsigned char)(gray); + ++i; + row[i] = 0xff; + } + return 0; +} + +static int pim_rop3_pixel_16 (hpgs_image *_this, + int x, int y, + const hpgs_paint_color *c, double alpha) +{ + hpgs_png_image *pim = (hpgs_png_image *)_this; + + unsigned char *row = pim->data + pim->bytes_per_row * y; + + int c_gray = (11 * (int)c->r + 16 * (int)c->g + 5 * (int)c->b)/32; + int p_gray = (11 * (int)pim->pattern_color.r + 16 * (int)pim->pattern_color.g + 5 * (int)pim->pattern_color.b)/32; + + if (alpha >= 1.0) + { + pim->rop3(&row[2*x],(unsigned char)(c_gray),(unsigned char)(p_gray)); + row[2*x+1] = 0xff; + } + else if (alpha > 0.0) + { + unsigned char gray = row[2*x]; + double a0 = row[2*x+1] / 255.0; + pim->rop3(&gray,(unsigned char)(c_gray),(unsigned char)(p_gray)); + row[2*x] = (unsigned char)(gray * alpha + row[2*x] * (1.0-alpha)); + row[2*x+1] = (unsigned char)(255.0 * (alpha + a0 * (1.0-alpha))); + } + + return 0; +} + +static int pim_rop3_chunk_16 (hpgs_image *_this, + int x1, int x2, int y, const hpgs_paint_color *c) +{ + hpgs_png_image *pim = (hpgs_png_image *)_this; + + unsigned char *row = pim->data + pim->bytes_per_row * y; + + int c_gray = (11 * (int)c->r + 16 * (int)c->g + 5 * (int)c->b)/32; + int p_gray = (11 * (int)pim->pattern_color.r + 16 * (int)pim->pattern_color.g + 5 * (int)pim->pattern_color.b)/32; + + int i; + + for (i=2*x1;i<=2*x2;++i) + { + pim->rop3(&row[i],(unsigned char)(c_gray),(unsigned char)(p_gray)); + ++i; + row[i] = 0xff; + } + + return 0; +} + +static int pim_get_pixel_24 (const hpgs_image *_this, + int x, int y, hpgs_paint_color *c, double *alpha) +{ + const hpgs_png_image *pim = (const hpgs_png_image *)_this; + + unsigned char *row = pim->data + pim->bytes_per_row * y; + + c->r = row[3*x ]; + c->g = row[3*x+1]; + c->b = row[3*x+2]; + + if (alpha) + *alpha = 1.0; + + return 0; +} + +static int pim_put_pixel_24 (hpgs_image *_this, + int x, int y, const hpgs_paint_color *c, double alpha) +{ + hpgs_png_image *pim = (hpgs_png_image *)_this; + + unsigned char *row = pim->data + pim->bytes_per_row * y; + + if (alpha >= 1.0) + { + row[3*x ] = c->r; + row[3*x+1] = c->g; + row[3*x+2] = c->b; + } + else if (alpha > 0.0) + { + row[3*x ] = (unsigned char)(c->r*alpha + row[3*x ]*(1.0-alpha)); + row[3*x+1] = (unsigned char)(c->g*alpha + row[3*x+1]*(1.0-alpha)); + row[3*x+2] = (unsigned char)(c->b*alpha + row[3*x+2]*(1.0-alpha)); + } + return 0; +} + +static int pim_put_chunk_24 (hpgs_image *_this, + int x1, int x2, int y, const hpgs_paint_color *c) +{ + hpgs_png_image *pim = (hpgs_png_image *)_this; + + unsigned char *row = pim->data + pim->bytes_per_row * y; + + int i; + + for (i=3*x1;i<=3*x2;++i) + { + row[i] = c->r; + ++i; + row[i] = c->g; + ++i; + row[i] = c->b; + } + return 0; +} + +static int pim_rop3_pixel_24 (hpgs_image *_this, + int x, int y, + const hpgs_paint_color *c, double alpha) +{ + hpgs_png_image *pim = (hpgs_png_image *)_this; + + unsigned char *row = pim->data + pim->bytes_per_row * y; + + if (alpha >= 1.0) + { + pim->rop3(&row[3*x ],c->r,pim->pattern_color.r); + pim->rop3(&row[3*x+1],c->g,pim->pattern_color.g); + pim->rop3(&row[3*x+2],c->b,pim->pattern_color.b); + } + else if (alpha > 0.0) + { + unsigned char v = row[3*x]; + pim->rop3(&v,c->r,pim->pattern_color.r); + row[3*x ] = (unsigned char)(v * alpha + row[3*x ] * (1.0-alpha)); + + v = row[3*x+1]; + pim->rop3(&v,c->g,pim->pattern_color.g); + row[3*x+1] = (unsigned char)(v * alpha + row[3*x+1] * (1.0-alpha)); + + v = row[3*x+2]; + pim->rop3(&v,c->b,pim->pattern_color.b); + row[3*x+2] = (unsigned char)(v * alpha + row[3*x+2] * (1.0-alpha)); + } + + return 0; +} + +static int pim_rop3_chunk_24 (hpgs_image *_this, + int x1, int x2, int y, const hpgs_paint_color *c) +{ + hpgs_png_image *pim = (hpgs_png_image *)_this; + + unsigned char *row = pim->data + pim->bytes_per_row * y; + + int i; + + for (i=3*x1;i<=3*x2;++i) + { + pim->rop3(&row[i],c->r,pim->pattern_color.r); + ++i; + pim->rop3(&row[i],c->g,pim->pattern_color.g); + ++i; + pim->rop3(&row[i],c->b,pim->pattern_color.b); + } + + return 0; +} + +static int pim_get_pixel_32 (const hpgs_image *_this, + int x, int y, hpgs_paint_color *c, double *alpha) +{ + const hpgs_png_image *pim = (const hpgs_png_image *)_this; + + unsigned char *row = pim->data + pim->bytes_per_row * y; + + c->r = row[4*x ]; + c->g = row[4*x+1]; + c->b = row[4*x+2]; + + if (alpha) + *alpha = row[4*x+3] / 255.0; + + return 0; +} + +static int pim_put_pixel_32 (hpgs_image *_this, + int x, int y, const hpgs_paint_color *c, double alpha) +{ + hpgs_png_image *pim = (hpgs_png_image *)_this; + + unsigned char *row = pim->data + pim->bytes_per_row * y; + + if (alpha >= 1.0) + { + row[4*x ] = c->r; + row[4*x+1] = c->g; + row[4*x+2] = c->b; + row[4*x+3] = 0xff; + } + else if (alpha > 0.0) + { + double a0 = row[4*x+3] / 255.0; + row[4*x ] = (unsigned char)(c->r*alpha+row[4*x ]*(1.0-alpha)); + row[4*x+1] = (unsigned char)(c->g*alpha+row[4*x+1]*(1.0-alpha)); + row[4*x+2] = (unsigned char)(c->b*alpha+row[4*x+2]*(1.0-alpha)); + row[4*x+3] = (unsigned char)(255.0*(alpha + a0 * (1.0-alpha))); + } + + return 0; +} + +static int pim_put_chunk_32 (hpgs_image *_this, + int x1, int x2, int y, const hpgs_paint_color *c) +{ + hpgs_png_image *pim = (hpgs_png_image *)_this; + + unsigned char *row = pim->data + pim->bytes_per_row * y; + + int i; + + for (i=4*x1;i<=4*x2;++i) + { + row[i] = c->r; + ++i; + row[i] = c->g; + ++i; + row[i] = c->b; + ++i; + row[i] = 0xff; + } + return 0; +} + +static int pim_rop3_pixel_32 (hpgs_image *_this, + int x, int y, + const hpgs_paint_color *c, double alpha) +{ + hpgs_png_image *pim = (hpgs_png_image *)_this; + + unsigned char *row = pim->data + pim->bytes_per_row * y; + + if (alpha >= 1.0) + { + pim->rop3(&row[4*x ],c->r,pim->pattern_color.r); + pim->rop3(&row[4*x+1],c->g,pim->pattern_color.g); + pim->rop3(&row[4*x+2],c->b,pim->pattern_color.b); + row[4*x+3] = 0xff; + } + else if (alpha > 0.0) + { + double a0 = row[4*x+3] / 255.0; + unsigned char v; + + v=row[4*x ]; + pim->rop3(&v,c->r,pim->pattern_color.r); + row[4*x ] = (unsigned char)(v*alpha+row[4*x ]*(1.0-alpha)); + + v=row[4*x+1]; + pim->rop3(&v,c->g,pim->pattern_color.g); + row[4*x+1] = (unsigned char)(v*alpha+row[4*x+1]*(1.0-alpha)); + + v=row[4*x+2]; + pim->rop3(&v,c->b,pim->pattern_color.b); + row[4*x+2] = (unsigned char)(v*alpha+row[4*x+2]*(1.0-alpha)); + + row[4*x+3] = (unsigned char)(255.0*(alpha + a0 * (1.0-alpha))); + } + + return 0; +} + +static int pim_rop3_chunk_32 (hpgs_image *_this, + int x1, int x2, int y, + const hpgs_paint_color *c) +{ + hpgs_png_image *pim = (hpgs_png_image *)_this; + + unsigned char *row = pim->data + pim->bytes_per_row * y; + + int i; + + for (i=4*x1;i<=4*x2;++i) + { + row[i] = c->r; + ++i; + row[i] = c->g; + ++i; + row[i] = c->b; + ++i; + row[i] = 0xff; + } + return 0; +} + +static int pim_put_pixel_256 (hpgs_image *_this, + int x, int y, + const hpgs_paint_color *c, double alpha) +{ + hpgs_png_image *pim = (hpgs_png_image *)_this; + + unsigned char *row = pim->data + pim->bytes_per_row * y; + + if (alpha >= 0.5) + row[x] = c->index; + + return 0; +} + +static int pim_get_pixel_256 (const hpgs_image *_this, + int x, int y, + hpgs_paint_color *c, double *alpha) +{ + const hpgs_png_image *pim = (const hpgs_png_image *)_this; + + unsigned char *row = pim->data + pim->bytes_per_row * y; + + c->index = row[x]; + + c->r = _this->palette[c->index].r; + c->g = _this->palette[c->index].g; + c->b = _this->palette[c->index].b; + + if (alpha) + *alpha=1.0; + + return 0; +} + +static int pim_put_chunk_256 (hpgs_image *_this, + int x1, int x2, int y, const hpgs_paint_color *c) +{ + hpgs_png_image *pim = (hpgs_png_image *)_this; + + unsigned char *row = pim->data + pim->bytes_per_row * y; + + memset(row+x1,c->index,x2-x1+1); + + return 0; +} + +static int pim_setrop3 (hpgs_image *_this, hpgs_rop3_func_t rop3) +{ + hpgs_png_image *pim = (hpgs_png_image *)_this; + + pim->rop3 = rop3; + return 0; +} + +static int pim_setpatcol (hpgs_image *_this, const hpgs_palette_color *p) +{ + hpgs_png_image *pim = (hpgs_png_image *)_this; + + pim->pattern_color = *p; + return 0; +} + +static int pim_resize(hpgs_image *_this, int w, int h) +{ + hpgs_png_image *pim = (hpgs_png_image *)_this; + int bytes_per_row,bpp,fill,i,j; + unsigned char *data; + + if (!pim->data) return -1; + + if (w == _this->width && h == _this->height) + return 0; + + bpp = (pim->depth / 8); + + bytes_per_row = ((w * bpp + 3) / 4) * 4; + + if (pim->color_type == PNG_COLOR_TYPE_PALETTE) + // fill indexed images with color 1 (white) + fill = 0x01; + else + // fill direct color with white. + fill = 0xff; + + if (w != _this->width) + { + data = (unsigned char *)malloc(bytes_per_row * h); + + if (!data) + return -1; + + for (i=0; i < h && i <_this->height; ++i) + { + unsigned char *orow = pim->data+pim->bytes_per_row * i; + unsigned char *row = data+bytes_per_row * i; + + if (w <= _this->width) + memcpy(row,orow,w * bpp); + else + { + memcpy(row,orow,_this->width * bpp); + memset(row+_this->width * bpp,fill,(w-_this->width) * bpp); + + // set alpha value to zero. + if (pim->depth == 16 || pim->depth == 32) + for (j=_this->width * bpp + bpp -1; j < bytes_per_row; j += bpp) + row[j] = 0x00; + } + } + + free(pim->data); + pim->data = data; + } + else + { + data = (unsigned char *)realloc(pim->data,bytes_per_row * h); + if (!data) return -1; + pim->data = data; + } + + for (i = _this->height; i < h; ++i) + { + unsigned char *row = data+bytes_per_row * i; + + memset(row,fill,w * bpp); + } + + pim->bytes_per_row = bytes_per_row; + _this->width = w; + _this->height = h; + return 0; +} + +static int pim_set_resolution(hpgs_image *_this, double x_dpi, double y_dpi) +{ + hpgs_png_image *pim = (hpgs_png_image *)_this; + + pim->res_x = (unsigned)floor(x_dpi/0.0254 + 0.5); + pim->res_y = (unsigned)floor(y_dpi/0.0254 + 0.5); + + return 0; +} + +static void pim_destroy (hpgs_image *_this) +{ + hpgs_png_image *pim = (hpgs_png_image *)_this; + + if (pim->data) free(pim->data); +} + +static int pim_clear (hpgs_image *_this) +{ + hpgs_png_image *pim = (hpgs_png_image *)_this; + + if (pim->color_type == PNG_COLOR_TYPE_PALETTE) + // fill indexed images with color 1 (white) + memset(pim->data,0x01,pim->bytes_per_row * _this->height); + else + { + // fill direct color with white. + memset(pim->data,0xff,pim->bytes_per_row * _this->height); + + // set alpha to zero. + if (pim->depth == 16 || pim->depth == 32) + { + int bpp = pim->depth/8; + int i,j; + + for (i=0; i < _this->height; ++i) + { + unsigned char *row = pim->data+pim->bytes_per_row * i; + + for (j=bpp-1; j < pim->bytes_per_row; j += bpp) + row[j] = 0x00; + } + } + } + + return 0; +} + +/* This is taken from ciro/test/write_png.c */ +static void +unpremultiply_data (png_structp png, png_row_infop row_info, png_bytep data) +{ + int i; + + for (i = 0; i < row_info->rowbytes; i += 4) { + unsigned char *b = &data[i]; + unsigned int pixel; + unsigned char alpha; + + memcpy (&pixel, b, sizeof (unsigned int)); + alpha = (pixel & 0xff000000) >> 24; + if (alpha == 0) { + b[0] = b[1] = b[2] = b[3] = 0; + } else { + b[0] = (((pixel & 0xff0000) >> 16) * 255 + alpha / 2) / alpha; + b[1] = (((pixel & 0x00ff00) >> 8) * 255 + alpha / 2) / alpha; + b[2] = (((pixel & 0x0000ff) >> 0) * 255 + alpha / 2) / alpha; + b[3] = alpha; + } + } +} + +static void png_error_function (png_structp png_ptr, png_const_charp str) +{ + hpgs_set_error("%s",str); + + longjmp(png_jmpbuf(png_ptr),1); +} + +static void png_warn_function (png_structp png_ptr, png_const_charp str) +{ + hpgs_log(hpgs_i18n("libpng warning: %s.\n"),str); +} + +static int pim_write(hpgs_image *_this, + const char *filename) +{ + hpgs_png_image *pim = (hpgs_png_image *)_this; + png_structp png_ptr=0; + png_infop info_ptr=0; + png_color_16 white; + png_text text; + FILE *fp=0; + int i; + unsigned char *row; + + fp = filename ? fopen(filename, "wb") : stdout; + + if (fp == NULL) + return hpgs_set_error(hpgs_i18n("Error opening file %s for writing: %s."), + filename?filename:"(stdout)",strerror(errno)); + + + png_ptr = png_create_write_struct(PNG_LIBPNG_VER_STRING, + NULL,png_error_function,png_warn_function); + + if (png_ptr == NULL) + return hpgs_set_error(hpgs_i18n("libpng error creating write structure for file %s."), + filename); + + info_ptr = png_create_info_struct(png_ptr); + + if (info_ptr == NULL) + { + png_destroy_write_struct(&png_ptr, png_infopp_NULL); + return hpgs_set_error(hpgs_i18n("libpng error creating info structure for file %s."), + filename); + } + + if (setjmp(png_jmpbuf(png_ptr))) + { + png_destroy_write_struct(&png_ptr, &info_ptr); + fclose(fp); + return hpgs_error_ctxt(hpgs_i18n("libpng error writing file %s"),filename); + } + + png_init_io(png_ptr, fp); + + png_set_IHDR(png_ptr, info_ptr, pim->inherited.width, pim->inherited.height, + 8,pim->color_type,PNG_INTERLACE_NONE, + PNG_COMPRESSION_TYPE_BASE, PNG_FILTER_TYPE_BASE); + + if (pim->inherited.palette) + png_set_PLTE(png_ptr,info_ptr, + (png_colorp)pim->inherited.palette, + pim->inherited.palette_ncolors); + + png_set_compression_level(png_ptr,pim->compression); + + + memset(&white,0,sizeof(white)); + + switch (pim->color_type) + { + case PNG_COLOR_TYPE_PALETTE: + white.index = 1; + break; + + case PNG_COLOR_TYPE_GRAY: + case PNG_COLOR_TYPE_GRAY_ALPHA: + white.gray = 0xff; + break; + + default: + white.red = 0xff; + white.blue = 0xff; + white.green = 0xff; + } + + png_set_bKGD (png_ptr, info_ptr, &white); + + if (pim->color_type == PNG_COLOR_TYPE_RGB_ALPHA) + png_set_write_user_transform_fn (png_ptr, unpremultiply_data); + +#ifdef PNG_TEXT_SUPPORTED + text.compression = PNG_TEXT_COMPRESSION_NONE; + text.key = "Software"; + text.text = "hpgs v" HPGS_VERSION; + text.text_length = strlen(text.text); + +#ifdef PNG_iTXt_SUPPORTED + text.itxt_length = 0; + text.lang = NULL; + text.lang_key = NULL; +#endif + png_set_text(png_ptr,info_ptr,&text,1); +#endif + +#ifdef PNG_pHYs_SUPPORTED + if (pim->res_x && pim->res_y) + png_set_pHYs (png_ptr,info_ptr,pim->res_x,pim->res_y,PNG_RESOLUTION_METER); +#endif + + png_write_info(png_ptr, info_ptr); + + row = pim->data; + + for (i = 0; i< pim->inherited.height; ++i) + { + png_write_row(png_ptr, row); + row += pim->bytes_per_row; + } + png_write_end(png_ptr, info_ptr); + + png_destroy_write_struct(&png_ptr, &info_ptr); + + if (filename) + fclose(fp); + + return 0; +} + +static int pim_get_data(hpgs_image *_this, + unsigned char **data, int *stride, int *depth) +{ + hpgs_png_image *pim = (hpgs_png_image *)_this; + + *data = pim->data; + *stride = pim->bytes_per_row; + *depth = pim->depth; + return 0; +} + +static hpgs_image_vtable pim_vtable_8 = + { + pim_get_pixel_8, + pim_put_pixel_8, + pim_put_chunk_8, + pim_put_pixel_8, + pim_put_chunk_8, + 0 /* pim_setrop3 */, + 0 /* pim_setpatcol */, + pim_resize, + pim_set_resolution, + pim_clear, + pim_write, + pim_get_data, + pim_destroy + }; + +static hpgs_image_vtable pim_vtable_8_rop = + { + pim_get_pixel_8, + pim_put_pixel_8, + pim_put_chunk_8, + pim_rop3_pixel_8, + pim_rop3_chunk_8, + pim_setrop3, + pim_setpatcol, + pim_resize, + pim_set_resolution, + pim_clear, + pim_write, + pim_get_data, + pim_destroy + }; + +static hpgs_image_vtable pim_vtable_16 = + { + pim_get_pixel_16, + pim_put_pixel_16, + pim_put_chunk_16, + pim_put_pixel_16, + pim_put_chunk_16, + 0 /* pim_setrop3 */, + 0 /* pim_setpatcol */, + pim_resize, + pim_set_resolution, + pim_clear, + pim_write, + pim_get_data, + pim_destroy + }; + +static hpgs_image_vtable pim_vtable_16_rop = + { + pim_get_pixel_16, + pim_put_pixel_16, + pim_put_chunk_16, + pim_rop3_pixel_16, + pim_rop3_chunk_16, + pim_setrop3, + pim_setpatcol, + pim_resize, + pim_set_resolution, + pim_clear, + pim_write, + pim_get_data, + pim_destroy + }; + +static hpgs_image_vtable pim_vtable_24 = + { + pim_get_pixel_24, + pim_put_pixel_24, + pim_put_chunk_24, + pim_put_pixel_24, + pim_put_chunk_24, + 0 /* pim_setrop3 */, + 0 /* pim_setpatcol */, + pim_resize, + pim_set_resolution, + pim_clear, + pim_write, + pim_get_data, + pim_destroy + }; + +static hpgs_image_vtable pim_vtable_24_rop = + { + pim_get_pixel_24, + pim_put_pixel_24, + pim_put_chunk_24, + pim_rop3_pixel_24, + pim_rop3_chunk_24, + pim_setrop3, + pim_setpatcol, + pim_resize, + pim_set_resolution, + pim_clear, + pim_write, + pim_get_data, + pim_destroy + }; + +static hpgs_image_vtable pim_vtable_32 = + { + pim_get_pixel_32, + pim_put_pixel_32, + pim_put_chunk_32, + pim_put_pixel_32, + pim_put_chunk_32, + 0 /* pim_setrop3 */, + 0 /* pim_setpatcol */, + pim_resize, + pim_set_resolution, + pim_clear, + pim_write, + pim_get_data, + pim_destroy + }; + +static hpgs_image_vtable pim_vtable_32_rop = + { + pim_get_pixel_32, + pim_put_pixel_32, + pim_put_chunk_32, + pim_rop3_pixel_32, + pim_rop3_chunk_32, + pim_setrop3, + pim_setpatcol, + pim_resize, + pim_set_resolution, + pim_clear, + pim_write, + pim_get_data, + pim_destroy + }; + +static hpgs_image_vtable pim_vtable_256 = + { + pim_get_pixel_256, + pim_put_pixel_256, + pim_put_chunk_256, + pim_put_pixel_256, + pim_put_chunk_256, + pim_setrop3, + pim_setpatcol, + pim_resize, + pim_set_resolution, + pim_clear, + pim_write, + pim_get_data, + pim_destroy + }; + +/*! Creates a new \c hpgs_png_image on the heap using the + given \c width and \c height. The bit depth \c depth of + the image is limited to 8,16, 24 or 32. + + If \c palette is \c HPGS_TRUE the image uses and indexed palette + and the bit depth is limited to 8. + + If \c palette is \c HPGS_FALSE the folowing depth are supported: + \li 8 contructs a greyscale image. + \li 16 contructs a greyscale image with alpha (transparency) plane. + \li 24 contructs an RGB image. + \li 16 contructs an RGB image with alpha (transparency) plane. + + If \c do_rop3 is \c HPGS_TRUE the image uses ROP3 raster operations. + \c do_rop3 is ignored for indexed images. Indexed images do never support + raster operations. +*/ +hpgs_png_image *hpgs_new_png_image(int width, int height, + int depth, hpgs_bool palette, + hpgs_bool do_rop3) +{ + hpgs_png_image *ret=(hpgs_png_image *)malloc(sizeof(hpgs_png_image)); + + if (ret) + { + if (palette) + depth = 8; + else + { + depth = ((depth + 7)/8) * 8; + if (depth < 8) depth = 8; + if (depth > 32) depth = 32; + } + + ret->depth = depth; + + ret->bytes_per_row = ((width * (depth / 8) + 3) / 4) * 4; + + ret->data = (unsigned char *)malloc(ret->bytes_per_row * height); + + ret->compression = 6; + + ret->inherited.width = width; + ret->inherited.height = height; + + ret->pattern_color.r = 0; + ret->pattern_color.g = 0; + ret->pattern_color.b = 0; + + if (do_rop3 && !palette) + ret->rop3 = hpgs_rop3_func(252,HPGS_TRUE,HPGS_TRUE); + else + ret->rop3 = 0; + + ret->res_x = 0; + ret->res_y = 0; + + if (palette) + { + hpgs_paint_color c; + + ret->color_type = PNG_COLOR_TYPE_PALETTE; + ret->inherited.vtable = &pim_vtable_256; + + ret->inherited.palette = + (hpgs_palette_color *)malloc(sizeof(hpgs_palette_color)*256); + ret->inherited.palette_idx = + (unsigned *)malloc(sizeof(unsigned)*256); + ret->inherited.palette_ncolors = 0; + + // define black and white a color 0 resp. 1 + c.r = c.g = c.b = 0; + hpgs_image_define_color (&ret->inherited,&c); + c.r = c.g = c.b = 255; + hpgs_image_define_color (&ret->inherited,&c); + } + else + { + switch (depth) + { + case 8: + ret->color_type = PNG_COLOR_TYPE_GRAY; + ret->inherited.vtable = do_rop3 ? &pim_vtable_8_rop : &pim_vtable_8; + break; + case 16: + ret->color_type = PNG_COLOR_TYPE_GRAY_ALPHA; + ret->inherited.vtable = do_rop3 ? &pim_vtable_16_rop : &pim_vtable_16; + break; + case 24: + ret->color_type = PNG_COLOR_TYPE_RGB; + ret->inherited.vtable = do_rop3 ? &pim_vtable_24_rop : &pim_vtable_24; + break; + default: + /* case 32: */ + ret->color_type = PNG_COLOR_TYPE_RGB_ALPHA; + ret->inherited.vtable = do_rop3 ? &pim_vtable_32_rop : &pim_vtable_32; + } + ret->inherited.palette = 0; + ret->inherited.palette_idx = 0; + ret->inherited.palette_ncolors = 0; + } + + if (!ret->data || + (palette && (!ret->inherited.palette || !ret->inherited.palette_idx))) + { + if (ret->data) + free(ret->data); + + if (ret->inherited.palette) + free(ret->inherited.palette); + + if (ret->inherited.palette_idx) + free(ret->inherited.palette_idx); + + free(ret); + ret = 0; + } + else + pim_clear(HPGS_BASE_CLASS(ret)); + } + + return ret; +} + +/*! Sets the compression ratio used for a png image. + Returns 0, if the compression is in the interval + from 1 to 9 inclusive. + + If the compression is invalid, -1 is returned. +*/ +int hpgs_png_image_set_compression(hpgs_png_image *pim, int compression) +{ + if (compression < 1 || compression >9) + return hpgs_set_error(hpgs_i18n("Invalid PNG compression %d specified."),compression); + + pim->compression = compression; + return 0; +} + +/*! Sets the resolution of this image in dpi. Note that for PNG images the + information in the pHYs chunk is given as an integral number of pixels + per meter. +*/ +int hpgs_image_set_resolution(hpgs_image *_this, double x_dpi, double y_dpi) +{ + if (!_this->vtable->set_resolution) + return 0; + + return _this->vtable->set_resolution(_this,x_dpi,y_dpi); +} + +/*! Gets the pixel buffer of the png image, which is needed + by some backends. If the image is not a png image -1 is retuned. + + If 0 is returned, *data point to the image data and *stride is + the number of bytes between two consecutive scanlines of the image. +*/ +HPGS_API int hpgs_image_get_data(hpgs_image *_this, + unsigned char **data, int *stride, int *depth) +{ + if (!_this->vtable->get_data) + return hpgs_set_error(hpgs_i18n("Exposure of image data is not implemented.")); + + return _this->vtable->get_data(_this,data,stride,depth); +} + +/*! Sets the ROP3 raster operation applied by + \c hpgs_image_put_pixel and \c hpgs_image_put_chunk. */ +int hpgs_image_setrop3 (hpgs_image *_this, hpgs_rop3_func_t rop3) +{ + if (!_this->vtable->setrop3) + return 0; + + return _this->vtable->setrop3(_this,rop3); +} + +/*! Sets the color of the pattern applied by the ROP3 operation. */ +int hpgs_image_setpatcol(hpgs_image *_this, const hpgs_palette_color *p) +{ + if (!_this->vtable->setpatcol) + return 0; + + return _this->vtable->setpatcol(_this,p); +} + + +/*! Resizes the given image \c _this to a new width \c w and new height \c h. + The pixel data preserved or initialized, if the image grows. */ +int hpgs_image_resize (hpgs_image *_this, int w, int h) +{ + if (!_this->vtable->resize) + return hpgs_set_error(hpgs_i18n("Image resize is not implemented.")); + + return _this->vtable->resize (_this,w,h); +} + +/*! Clears the given image \c _this. */ +int hpgs_image_clear (hpgs_image *_this) +{ + if (!_this->vtable->clear) + return hpgs_set_error(hpgs_i18n("Image clear is not implemented.")); + + return _this->vtable->clear (_this); +} + +/*! Writes the given image \c _this to a file with the given name \c filename. */ +int hpgs_image_write (hpgs_image *_this, const char *filename) +{ + if (!_this->vtable->write) + return hpgs_set_error(hpgs_i18n("Image write is not implemented.")); + + return _this->vtable->write (_this,filename); +} + +/*! Destroys the given image and frees all allocated resources by this image. +*/ +void hpgs_image_destroy (hpgs_image *_this) +{ + _this->vtable->destroy(_this); + if (_this->palette) free(_this->palette); + if (_this->palette_idx) free(_this->palette_idx); + free(_this); +} + +/*! The helper function for the inline function + \c hpgs_image_define_color, which is actually called for indexed images. +*/ +int hpgs_image_define_color_func (hpgs_image *image, hpgs_paint_color *c) +{ + if (!image->palette) return 0; + + // compactify color for index lookup. + unsigned rgb = + ((unsigned)c->r << 24) | ((unsigned)c->g << 16) | ((unsigned)c->b << 8); + + // binary search in the index. + int i0 = 0; + int i1 = image->palette_ncolors; + + while (i1>i0) + { + int i = i0+(i1-i0)/2; + + if ((image->palette_idx[i] & 0xffffff00) < rgb) + i0 = i+1; + else + i1 = i; + } + + if (i0 < image->palette_ncolors && + rgb == (image->palette_idx[i0] & 0xffffff00)) + { + c->index = image->palette_idx[i0] & 0xff; + return 0; + } + + // palette overflow. + if (image->palette_ncolors >= 256) + { + c->index = 0; + return hpgs_set_error(hpgs_i18n("Number of indexed colors exceeds 256.")); + } + + memmove(image->palette_idx+i0+1,image->palette_idx+i0, + (image->palette_ncolors-i0) * sizeof(unsigned)); + + image->palette_idx[i0] = rgb | image->palette_ncolors; + c->index = image->palette_ncolors; + image->palette[image->palette_ncolors].r = c->r; + image->palette[image->palette_ncolors].g = c->g; + image->palette[image->palette_ncolors].b = c->b; + ++image->palette_ncolors; + + return 0; +} + +static int compare_color_idx(const void *a, const void *b) +{ + unsigned ai = (*((const unsigned *)a)) & 0xffffff00; + unsigned bi = (*((const unsigned *)b)) & 0xffffff00; + + if (aibi) return 1; + return 0; +} + +/*! Sets the palette to an indexed image. +*/ +int hpgs_image_set_palette (hpgs_image *image, + hpgs_palette_color *p, int np) +{ + int i; + + if (!image->palette) + return hpgs_set_error(hpgs_i18n("Try to set a palette to a non-indexed image.")); + + if (np<1 || np >256) + return hpgs_set_error(hpgs_i18n("Invalid number %d of palette colors."),np); + + memmove(image->palette,p,sizeof(hpgs_palette_color)*np); + image->palette_ncolors = np; + + for (i=0;ipalette_idx[i] = + ((unsigned)p[i].r << 24) | ((unsigned)p[i].g << 16) | ((unsigned)p[i].b << 8) | i; + + // This is by no way time-critical, so we can use qsort here, + // which is far from being optimal in performance. + qsort(image->palette_idx,np,sizeof(unsigned),compare_color_idx); + return 0; +} diff --git a/src/add-ons/translators/hpgs/lib/hpgsimage.h b/src/add-ons/translators/hpgs/lib/hpgsimage.h new file mode 100644 index 0000000000..e3aae686e2 --- /dev/null +++ b/src/add-ons/translators/hpgs/lib/hpgsimage.h @@ -0,0 +1,77 @@ +/*********************************************************************** + * * + * $Id: hpgsimage.h 270 2006-01-29 21:12:23Z softadm $ + * * + * hpgs - HPGl Script, a hpgl/2 interpreter, which uses a Postscript * + * API for rendering a scene and thus renders to a variety of * + * devices and fileformats. * + * * + * (C) 2004-2006 ev-i Informationstechnologie GmbH http://www.ev-i.at * + * * + * Author: Wolfgang Glas * + * * + * hpgs is free software; you can redistribute it and/or * + * modify it under the terms of the GNU Lesser General Public * + * License as published by the Free Software Foundation; either * + * version 2.1 of the License, or (at your option) any later version. * + * * + * hpgs is distributed in the hope that it will be useful, * + * but WITHOUT ANY WARRANTY; without even the implied warranty of * + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * + * Lesser General Public License for more details. * + * * + * You should have received a copy of the GNU Lesser General Public * + * License along with this library; if not, write to the * + * Free Software Foundation, Inc., 59 Temple Place, Suite 330, * + * Boston, MA 02111-1307 USA * + * * + *********************************************************************** + * * + * Private declarations for images. * + * * + ***********************************************************************/ + +#ifndef __HPGS_IMAGE_H__ +#define __HPGS_IMAGE_H__ + +#include + +#ifdef __cplusplus +extern "C" { +#endif + +/*! \brief An concrete pixel image. + + This structure has a public alias \c hpgs_png_image and + implements \c hpgs_image. The storage format is similar + to the format used by \c libpng, so the image may be written + to png file using \c hpgs_png_image_write. +*/ + +/*! @addtogroup image + * @{ + */ +struct hpgs_png_image_st { + hpgs_image inherited; + + int depth; //!< The bit depth of the image. + int color_type; //!< The color type. + int bytes_per_row; //!< The number of bytes per row of the pixel data. + int compression; //!< The compression used for writing the image in the range from 0 to 9. + + unsigned char *data; //!< The pixel data. + + hpgs_rop3_func_t rop3; //!< The ROP3 raster operation. + hpgs_palette_color pattern_color; //!< The color of the ROP3 pattern. + + unsigned res_x; //!< The number of pixels per meter in x-direction, or 0 if unknown. + unsigned res_y; //!< The number of pixels per meter in y-direction, or 0 if unknown. +}; + +/*! @} */ /* end of group reader */ + +#ifdef __cplusplus +} // end of extern "C" +#endif + +#endif // ! __HPGS_IMAGE_H__ diff --git a/src/add-ons/translators/hpgs/lib/hpgsimagerop.c b/src/add-ons/translators/hpgs/lib/hpgsimagerop.c new file mode 100644 index 0000000000..97b8a58100 --- /dev/null +++ b/src/add-ons/translators/hpgs/lib/hpgsimagerop.c @@ -0,0 +1,551 @@ +/*********************************************************************** + * * + * $Id: hpgsimagerop.c 372 2007-01-14 18:16:03Z softadm $ + * * + * hpgs - HPGl Script, a hpgl/2 interpreter, which uses a Postscript * + * API for rendering a scene and thus renders to a variety of * + * devices and fileformats. * + * * + * (C) 2004-2006 ev-i Informationstechnologie GmbH http://www.ev-i.at * + * * + * Author: Wolfgang Glas * + * * + * hpgs is free software; you can redistribute it and/or * + * modify it under the terms of the GNU Lesser General Public * + * License as published by the Free Software Foundation; either * + * version 2.1 of the License, or (at your option) any later version. * + * * + * hpgs is distributed in the hope that it will be useful, * + * but WITHOUT ANY WARRANTY; without even the implied warranty of * + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * + * Lesser General Public License for more details. * + * * + * You should have received a copy of the GNU Lesser General Public * + * License along with this library; if not, write to the * + * Free Software Foundation, Inc., 59 Temple Place, Suite 330, * + * Boston, MA 02111-1307 USA * + * * + *********************************************************************** + * * + * The implementation of the ROP3 clip frame extraction from images. * + * * + ***********************************************************************/ + +#include +#include +#if defined ( __MINGW32__ ) || defined ( _MSC_VER ) +#include +#else +#include +#endif + +// #define HPGS_IMAGE_ROP_DEBUG + +typedef struct hpgs_img_clip_seg_st hpgs_img_clip_seg; + +struct hpgs_img_clip_seg_st +{ + int j; + int i_vert; +}; + +typedef struct hpgs_img_clip_line_st hpgs_img_clip_line; + +struct hpgs_img_clip_line_st +{ + int i0; + int j0; + + int i1; + int j1; + + int key; + int usage; +}; + +#define MK_LINE_KEY(i,j) ((j)+(img->width+1)*(i)) + +static int compare_clip_lines (const void *a, const void *b) +{ + const hpgs_img_clip_line *la = (const hpgs_img_clip_line *)a; + const hpgs_img_clip_line *lb = (const hpgs_img_clip_line *)b; + + if (la->key < lb->key) return -1; + if (la->key > lb->key) return 1; + return 0; +} + +static int grow_clip_lines (hpgs_device *device, + hpgs_img_clip_line **clip_lines, + size_t *clip_lines_sz) +{ + size_t nsz = *clip_lines_sz*2; + hpgs_img_clip_line *ncl=realloc(*clip_lines,nsz*sizeof(hpgs_img_clip_line)); + + if (!ncl) + return hpgs_set_error(hpgs_i18n("hpgs_image_rop3_clip: Out of memory growing temporary storage.")); + + *clip_lines = ncl; + *clip_lines_sz = nsz; + return 0; +} + +/*! + Sets a clip frame to the given device, which encloses all regions + of the device, which are cover by the image taking into account + the given ROP3 transfer function. + + The argument \c data must contain a pointer to a two-dimensional + array of raw pixels of the size of the image. This array is filled + with pixel values as if the image has been painted to a white + destination area using the given ROP3 function. + + Return values: + \li 0 The clip frame is empty, no operation has been performed on + the output device. + + \li 1 The clip frame is not empty, the clip path has been + set to the output device using clipsave/moveto/lineto/clip + operations. + + \li 2 The clip frame covers the whole image, no operation has been + performed on the output device. + + \li 3 The clip frame is not empty, the visible pixels have all the same color + and clip path has been set to the output device using + moveto/lineto/setrgbcolor/fill operations. The image does not have to be + transferred by subsequent functions, the rgb color of the device has been + altered. + + \li -1 An error occured on the output device. + +*/ +int hpgs_image_rop3_clip(hpgs_device *device, + hpgs_palette_color *data, + const hpgs_image *img, + const hpgs_point *ll, const hpgs_point *lr, + const hpgs_point *ur, + const hpgs_palette_color *p, + hpgs_xrop3_func_t xrop3) +{ + // The upper bound for clip_lines_sz is (w+1)*(h+1)*2. + // This formula is chosen so, that for w==1 and h==1, + // this result is achieved. For larger pictures, we + // use 1/8th of the upper bound, which is pretty conservative. + // If not doing so, the algorithm easily consumes up to 1GB or more, + // which is too much for alloca, too. So this estimation combined + // with the usage of malloc should make the code robust. + size_t clip_lines_sz = ((img->width+1)*(img->height+1)+31)/4; + + hpgs_img_clip_line *clip_lines = (hpgs_img_clip_line *) + malloc(sizeof(hpgs_img_clip_line)*clip_lines_sz); + + hpgs_img_clip_seg *segs0 = (hpgs_img_clip_seg *) + hpgs_alloca(sizeof(hpgs_img_clip_seg)*(img->width+1)); + + hpgs_img_clip_seg *segs1 = (hpgs_img_clip_seg *) + hpgs_alloca(sizeof(hpgs_img_clip_seg)*(img->width+1)); + + if (!clip_lines || !segs0 || !segs1) + return hpgs_set_error(hpgs_i18n("hpgs_image_rop3_clip: Out of memory allocating temporary storage.")); + + int n_clip_lines = 0; + int ret = -1; + int i_seg0,n_segs0 = 0; + int i_seg1,n_segs1 = 0; + + hpgs_point ul; + int i,j; + + hpgs_bool all_visible = HPGS_TRUE; + hpgs_palette_color *first_visible_pixel = 0; + hpgs_bool single_color = HPGS_FALSE; + + ul.x = ll->x + (ur->x - lr->x); + ul.y = ll->y + (ur->y - lr->y); + + // first, accumulate lines. + for (i=0;iheight+1;++i) + { + // cut the current raster line + int t_last = 1; + n_segs1 = 0; + + // this is here in order to construct all lines + // for the very last grid line + if (iheight) + { + for (j=0;jwidth;++j) + { + int t; + hpgs_paint_color s; + unsigned r,g,b; + + hpgs_image_get_pixel(img,j,i,&s,0); + + r = xrop3(s.r,p->r); + g = xrop3(s.g,p->g); + b = xrop3(s.b,p->b); + + // transparent ? + t = (r == 0x00ff && g == 0x00ff && b == 0x00ff); + + if (t != t_last) // last pixel different transparency ? + { + segs1[n_segs1].j = j; + segs1[n_segs1].i_vert = -1; + ++n_segs1; + } + + t_last = t; + + data->r = (unsigned char)r; + data->g = (unsigned char)g; + data->b = (unsigned char)b; + + if (!t) + { + if (!first_visible_pixel) + { + first_visible_pixel = data; + single_color = HPGS_TRUE; + } + else if (single_color && + (first_visible_pixel->r != data->r || + first_visible_pixel->g != data->g || + first_visible_pixel->b != data->b )) + single_color = HPGS_FALSE; + } + + ++data; + } + + if (n_segs1 != 1 || segs1[0].j > 0) + all_visible = HPGS_FALSE; + + // close trailing visible segment. + if (t_last == 0) + { + segs1[n_segs1].j = j; + segs1[n_segs1].i_vert = -1; + ++n_segs1; + } + } + + assert(n_segs1 <= (img->width+1)); + +#ifdef HPGS_IMAGE_ROP_DEBUG + hpgs_log("i=%d: segs1:",i); + + for (j=0;j= n_segs1 || (i_seg0 < n_segs0 && segs0[i_seg0].j < segs1[i_seg1].j)) + { + // horizontal line. + if (t_last >= 0) + { + clip_lines[n_clip_lines].i0 = i; + clip_lines[n_clip_lines].i1 = i; + // check for the orientation. + if (i_seg0 & 1) + { + clip_lines[n_clip_lines].j0 = t_last; + clip_lines[n_clip_lines].j1 = segs0[i_seg0].j; + } + else + { + clip_lines[n_clip_lines].j0 = segs0[i_seg0].j; + clip_lines[n_clip_lines].j1 = t_last; + } + + if (++n_clip_lines >= clip_lines_sz && + grow_clip_lines(device,&clip_lines,&clip_lines_sz)) + goto cleanup; + + t_last = -1; + } + else + t_last = segs0[i_seg0].j; + + + ++i_seg0; + } + else if (i_seg0 >= n_segs0 || segs1[i_seg1].j < segs0[i_seg0].j) + { + // horizontal line. + if (t_last >= 0) + { + clip_lines[n_clip_lines].i0 = i; + clip_lines[n_clip_lines].i1 = i; + // check for the orientation. + if (i_seg1 & 1) + { + clip_lines[n_clip_lines].j0 = segs1[i_seg1].j; + clip_lines[n_clip_lines].j1 = t_last; + } + else + { + clip_lines[n_clip_lines].j0 = t_last; + clip_lines[n_clip_lines].j1 = segs1[i_seg1].j; + } + if (++n_clip_lines >= clip_lines_sz && + grow_clip_lines(device,&clip_lines,&clip_lines_sz)) + goto cleanup; + t_last = -1; + } + else + t_last = segs1[i_seg1].j; + + // create vertical line. + clip_lines[n_clip_lines].j0 = segs1[i_seg1].j; + clip_lines[n_clip_lines].j1 = segs1[i_seg1].j; + + // check for the orientation. + if (i_seg1 & 1) + { + clip_lines[n_clip_lines].i0 = i+1; + clip_lines[n_clip_lines].i1 = i; + } + else + { + clip_lines[n_clip_lines].i0 = i; + clip_lines[n_clip_lines].i1 = i+1; + } + + segs1[i_seg1].i_vert = n_clip_lines; + if (++n_clip_lines >= clip_lines_sz && + grow_clip_lines(device,&clip_lines,&clip_lines_sz)) + goto cleanup; + + ++i_seg1; + } + else + { + assert(segs0[i_seg0].j == segs1[i_seg1].j); + + // horizontal line. + if (t_last >= 0) + { + clip_lines[n_clip_lines].i0 = i; + clip_lines[n_clip_lines].i1 = i; + // check for the orientation. + if (i_seg1 & 1) + { + clip_lines[n_clip_lines].j0 = segs1[i_seg1].j; + clip_lines[n_clip_lines].j1 = t_last; + } + else + { + clip_lines[n_clip_lines].j0 = t_last; + clip_lines[n_clip_lines].j1 = segs1[i_seg1].j; + } + + if (++n_clip_lines >= clip_lines_sz && + grow_clip_lines(device,&clip_lines,&clip_lines_sz)) + goto cleanup; + } + + if ((i_seg0 & 1) == (i_seg1 & 1)) + { + // extend segment + int il = segs0[i_seg0].i_vert; + if (i_seg1 & 1) + clip_lines[il].i0 = i+1; + else + clip_lines[il].i1= i+1; + + segs1[i_seg1].i_vert = il; + t_last = -1; + } + else + { + // create new segment. + clip_lines[n_clip_lines].j0 = segs1[i_seg1].j; + clip_lines[n_clip_lines].j1 = segs1[i_seg1].j; + + if (i_seg1 & 1) + { + clip_lines[n_clip_lines].i0 = i+1; + clip_lines[n_clip_lines].i1 = i; + } + else + { + clip_lines[n_clip_lines].i0 = i; + clip_lines[n_clip_lines].i1 = i+1; + } + + segs1[i_seg1].i_vert = n_clip_lines; + + if (++n_clip_lines >= clip_lines_sz && + grow_clip_lines(device,&clip_lines,&clip_lines_sz)) + goto cleanup; + + t_last = segs1[i_seg1].j; + } + + ++i_seg0; + ++i_seg1; + } + } + +#ifdef HPGS_IMAGE_ROP_DEBUG + hpgs_log("i=%d: lines: ",i); + + for (;jwidth+1)*(img->height+1)*2); + + // OK, now create the lookup key of the lines. + for (i=0;iusage) continue; + + do + { + hpgs_point p; + int key,i0,i1; + + p.x = ul.x + + line->j0 * (lr->x - ll->x) / img->width + + line->i0 * (lr->x - ur->x) / img->height ; + + p.y = ul.y + + line->j0 * (lr->y - ll->y) / img->width + + line->i0 * (lr->y - ur->y) / img->height ; + + key = MK_LINE_KEY(line->i1,line->j1); + + if (iline) + { + if (hpgs_lineto(device,&p)) goto cleanup; + } + else + { + if (hpgs_moveto(device,&p)) goto cleanup; + } + +#ifdef HPGS_IMAGE_ROP_DEBUG + hpgs_log("(%d,%d,%d,%d)", + line->i0,line->j0, + line->i1,line->j1); +#endif + ++iline; + line->usage=1; + + // binary search + i0 = 0; + i1 = n_clip_lines; + + while (i1>i0) + { + int ii = i0+(i1-i0)/2; + + if (clip_lines[ii].key < key) + i0 = ii+1; + else + i1 = ii; + } + + while (clip_lines[i0].usage && + i0 < n_clip_lines-1 && + clip_lines[i0+1].key == key) + ++i0; + + assert(i0 < n_clip_lines && key == clip_lines[i0].key); + + line = clip_lines+i0; + + assert (line); + + if (line->usage && line < clip_lines + n_clip_lines && + line[1].key == key) + ++line; + } + while (!line->usage); + + assert (line->i0 == clip_lines[i].i0 && + line->j0 == clip_lines[i].j0 ); + +#ifdef HPGS_IMAGE_ROP_DEBUG + hpgs_log("\n"); +#endif + if (hpgs_closepath(device)) goto cleanup; + } + + if (single_color) + { + hpgs_color c; + + c.r = first_visible_pixel->r / 255.0; + c.g = first_visible_pixel->g / 255.0; + c.b = first_visible_pixel->b / 255.0; + + if (hpgs_setrgbcolor(device,&c)) goto cleanup; + if (hpgs_fill(device,HPGS_FALSE)) goto cleanup; + if (hpgs_newpath(device)) goto cleanup; + + ret = 3; + } + + else + { + if (hpgs_clip(device,HPGS_FALSE)) goto cleanup; + if (hpgs_newpath(device)) goto cleanup; + + ret = 1; + } + + cleanup: + if (clip_lines) free(clip_lines); + return ret; +} diff --git a/src/add-ons/translators/hpgs/lib/hpgsistream.c b/src/add-ons/translators/hpgs/lib/hpgsistream.c new file mode 100644 index 0000000000..ce1c42ae6a --- /dev/null +++ b/src/add-ons/translators/hpgs/lib/hpgsistream.c @@ -0,0 +1,278 @@ +/*********************************************************************** + * * + * $Id: hpgsistream.c 343 2006-08-18 16:48:09Z softadm $ + * * + * hpgs - HPGl Script, a hpgl/2 interpreter, which uses a Postscript * + * API for rendering a scene and thus renders to a variety of * + * devices and fileformats. * + * * + * (C) 2004-2006 ev-i Informationstechnologie GmbH http://www.ev-i.at * + * * + * Author: Wolfgang Glas * + * * + * hpgs is free software; you can redistribute it and/or * + * modify it under the terms of the GNU Lesser General Public * + * License as published by the Free Software Foundation; either * + * version 2.1 of the License, or (at your option) any later version. * + * * + * hpgs is distributed in the hope that it will be useful, * + * but WITHOUT ANY WARRANTY; without even the implied warranty of * + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * + * Lesser General Public License for more details. * + * * + * You should have received a copy of the GNU Lesser General Public * + * License along with this library; if not, write to the * + * Free Software Foundation, Inc., 59 Temple Place, Suite 330, * + * Boston, MA 02111-1307 USA * + * * + *********************************************************************** + * * + * The implementations of input streams. * + * * + ***********************************************************************/ + +#include +#include +#include +#include + +static int file_seek (FILE *file, size_t pos) +{ + return fseek(file,pos,SEEK_SET); +} + +static int file_seekend (FILE *file, size_t pos) +{ + return fseek(file,-(long)pos,SEEK_END); +} + +static int file_tell (FILE *file, size_t *pos) +{ + long pp=ftell(file); + + if (pp<0) return -1; + + *pos = pp; + return 0; +} + +/*! \defgroup base Basic facilities. + + This module contains structures for operating on abstract input streams + as well as color structures and a 2D point. +*/ + +static hpgs_istream_vtable file_vtable = + { + (hpgs_istream_getc_func_t) getc, + (hpgs_istream_ungetc_func_t) ungetc, + (hpgs_istream_close_func_t) fclose, + (hpgs_istream_iseof_func_t) feof, + (hpgs_istream_iserror_func_t) ferror, + (hpgs_istream_seek_func_t) file_seek, + (hpgs_istream_tell_func_t) file_tell, + (hpgs_istream_read_func_t) fread, + (hpgs_istream_seekend_func_t) file_seekend + }; + +/*! Returns a new \c hpgs_istream created on the heap, + which operates on a file, which is opened by this call + in read-only mode. + + Returns a null pointer, when an I/O error occurrs. + In this case, details about the the error can be retrieved + using \c errno. + */ +hpgs_istream *hpgs_new_file_istream(const char *fn) +{ + FILE *in = fopen (fn,"rb"); + hpgs_istream *ret = 0; + + if (!in) return 0; + + ret = (hpgs_istream *)malloc(sizeof(hpgs_istream)); + + if (!ret) + { + fclose(in); + return 0; + } + + ret->stream = in; + ret->vtable = &file_vtable; + + return ret; +} + +/* memory stream implementation functions. */ +typedef struct hpgs_mem_istream_stream_st hpgs_mem_istream_stream; + +struct hpgs_mem_istream_stream_st +{ + const unsigned char *data; + const unsigned char *gptr; + const unsigned char *eptr; + int errflg; +}; + +static int mem_getc (hpgs_mem_istream_stream *stream) +{ + int ret; + + if (stream->errflg) + ret=EOF; + else + { + if (stream->gptr >= stream->eptr) + ret = EOF; + else + { + ret = *stream->gptr; + ++stream->gptr; + } + } + + return ret; +} + +static int mem_ungetc (int c, hpgs_mem_istream_stream *stream) +{ + if (stream->errflg) return -1; + if (stream->gptr <= stream->data) { stream->errflg = 1; return -1; } + --stream->gptr; + return 0; +} + +static int mem_close (hpgs_mem_istream_stream *stream) +{ + return 0; +} + +static int mem_iseof (hpgs_mem_istream_stream *stream) +{ + return stream->gptr >= stream->eptr; +} + +static int mem_iserror (hpgs_mem_istream_stream *stream) +{ + return stream->errflg; +} + +static int mem_tell (hpgs_mem_istream_stream *stream, size_t *pos) +{ + if (stream->errflg) return -1; + *pos = stream->gptr - stream->data; + return 0; +} + +static int mem_seek (hpgs_mem_istream_stream *stream, size_t pos) +{ + if (stream->data + pos > stream->eptr) + { + stream->errflg = 1; + return -1; + } + + stream->gptr = stream->data+pos; + stream->errflg = 0; + return 0; +} + +static int mem_seekend (hpgs_mem_istream_stream *stream, size_t pos) +{ + if (stream->data + pos > stream->eptr) + { + stream->errflg = 1; + return -1; + } + + stream->gptr = stream->eptr-pos; + stream->errflg = 0; + return 0; +} + +static size_t mem_read (void *ptr, size_t size, size_t nmemb, hpgs_mem_istream_stream *stream) +{ + size_t ret = 0; + + if (!stream->errflg) + { + if (stream->gptr < stream->eptr) + { + ret = (stream->eptr - stream->gptr)/size; + if (ret > nmemb) ret = nmemb; + + memcpy(ptr,stream->gptr,size * ret); + stream->gptr += size * ret; + } + } + + return ret; +} + +static hpgs_istream_vtable mem_vtable = + { + (hpgs_istream_getc_func_t) mem_getc, + (hpgs_istream_ungetc_func_t) mem_ungetc, + (hpgs_istream_close_func_t) mem_close, + (hpgs_istream_iseof_func_t) mem_iseof, + (hpgs_istream_iserror_func_t) mem_iserror, + (hpgs_istream_seek_func_t) mem_seek, + (hpgs_istream_tell_func_t) mem_tell, + (hpgs_istream_read_func_t) mem_read, + (hpgs_istream_seekend_func_t) mem_seekend + }; + +/*! Returns a new \c hpgs_istream created on the heap, + which operates on a chunk of memory in the given + location with the given size. + + Returns a null pointer, when the system is out of memory. + */ +hpgs_istream *hpgs_new_mem_istream(const unsigned char *data, + size_t data_size, + hpgs_bool dup) +{ +#define HPGS_ISTREAM_PAD_SZ (8*((sizeof(hpgs_istream)+7)/8)) +#define HPGS_ISTREAM_STREAM_PAD_SZ (8*((sizeof(hpgs_mem_istream_stream)+7)/8)) + + hpgs_mem_istream_stream *stream; + hpgs_istream *ret; + size_t sz = HPGS_ISTREAM_PAD_SZ + HPGS_ISTREAM_STREAM_PAD_SZ; + void *ptr; + + if (dup) sz += data_size; + + ptr = malloc(sz); + ret = (hpgs_istream *)ptr; + + if (!ret) + return 0; + + stream = (hpgs_mem_istream_stream *)(ptr+HPGS_ISTREAM_PAD_SZ); + + if (dup) + { + unsigned char *ddata = + (unsigned char *)ptr + HPGS_ISTREAM_PAD_SZ + HPGS_ISTREAM_STREAM_PAD_SZ; + + stream->data = ddata; + stream->gptr = ddata; + stream->eptr = ddata+data_size; + + memcpy(ddata,data,data_size); + } + else + { + stream->data = data; + stream->gptr = data; + stream->eptr = data+data_size; + } + + stream->errflg = 0; + + ret->stream = stream; + ret->vtable = &mem_vtable; + + return ret; +} diff --git a/src/add-ons/translators/hpgs/lib/hpgslabel.c b/src/add-ons/translators/hpgs/lib/hpgslabel.c new file mode 100644 index 0000000000..cf286e5154 --- /dev/null +++ b/src/add-ons/translators/hpgs/lib/hpgslabel.c @@ -0,0 +1,263 @@ +/*********************************************************************** + * * + * $Id: hpgslabel.c 381 2007-02-20 09:06:38Z softadm $ + * * + * hpgs - HPGl Script, a hpgl/2 interpreter, which uses a Postscript * + * API for rendering a scene and thus renders to a variety of * + * devices and fileformats. * + * * + * (C) 2004-2006 ev-i Informationstechnologie GmbH http://www.ev-i.at * + * * + * Author: Wolfgang Glas * + * * + * hpgs is free software; you can redistribute it and/or * + * modify it under the terms of the GNU Lesser General Public * + * License as published by the Free Software Foundation; either * + * version 2.1 of the License, or (at your option) any later version. * + * * + * hpgs is distributed in the hope that it will be useful, * + * but WITHOUT ANY WARRANTY; without even the implied warranty of * + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * + * Lesser General Public License for more details. * + * * + * You should have received a copy of the GNU Lesser General Public * + * License along with this library; if not, write to the * + * Free Software Foundation, Inc., 59 Temple Place, Suite 330, * + * Boston, MA 02111-1307 USA * + * * + *********************************************************************** + * * + * The implementation of old-style HPGL labels. * + * * + ***********************************************************************/ + +#include +#include +#include +#include +#if defined ( __MINGW32__ ) || defined ( _MSC_VER ) +#include +#else +#include +#endif + +#define HPGS_LABEL_NFACES 4 +#define HPGS_LABEL_NENC 27 + +typedef struct hpgs_ttf_face_info_st hpgs_ttf_face_info; + +struct hpgs_ttf_face_info_st +{ + const char *font_name; + double x_fac; + double y_fac; +}; + +#ifdef WIN32 +#define HPGS_LABEL_UCS_TYPE unsigned +#define HPGS_LABEL_UCS_ENC "UCS-4-INTERNAL" +#else +#define HPGS_LABEL_UCS_TYPE wchar_t +#define HPGS_LABEL_UCS_ENC "WCHAR_T" +#endif + +static hpgs_ttf_face_info face_infos[HPGS_LABEL_NFACES] = + { + { "LetterGothic", 1.48, 1.295 }, + { "LetterGothic Italic", 1.48, 1.295 }, + { "LetterGothic Bold", 1.48, 1.295 }, + { "LetterGothic Bold Italic", 1.48, 1.295 } + }; + +static const char *encoding_names[HPGS_LABEL_NENC] = + { + "HP-ROMAN8", + "LATIN1", // 14 + "LATIN2", // 78 + "LATIN5", // 174 + "GREEK8", // 263 + "CSISO25FRENCH", // 6 + "CSISO69FRENCH", // 38 + "CSISO14JISC6220RO", // 11 + "CSISO11SWEDISHFORNAMES", // 19 + "CSISO10SWEDISH", // 115 + "CSISO60NORWEGIAN1", // 4 + "CSISO61NORWEGIAN2", // 36 + "CSISO21GERMAN", // 39 + "CSISO15ITALIAN", // 9 + "CSISO17SPANISH", // 83 + "CSISO85SPANISH2", // 211 + "CSISO16PORTUGESE", // 147 + "CSISO84PORTUGESE2", // 179 + "HEBREW", // 8,264 + "CYRILLIC", // 18, 50 + "ECMA-CYRILLIC", // 334 + "MS-MAC-CYRILLIC", // 114 + "WINDOWS-1252", // 309 + "CP850", // 405 + "CP852", // 565 + "ARABIC7", // 22 + "ARABIC" // 278 + }; + +static int hpgs_device_label_internal(hpgs_device *dev, + hpgs_point *pos, + const char *str, int str_len, + int face, + iconv_t encoding, + const char* encoding_name, + int posture, + int weight, + const hpgs_point *left_vec, + const hpgs_point *up_vec, + const hpgs_point *space_vec) +{ + int iface = 0; + size_t i,len,inbytesleft; + HPGS_LABEL_UCS_TYPE ucs_str[HPGS_MAX_LABEL_SIZE]; + size_t outbytesleft; + char *inbuf; + char *outbuf; + + // get the face index. + if (posture) + iface += 1; + + if (weight >= 3) + iface += 2; + + // open the face. + hpgs_font *font = hpgs_find_font(face_infos[iface].font_name); + + if (!font) return -1; + + // convert to UNICODE + if (str_len > HPGS_MAX_LABEL_SIZE) str_len=HPGS_MAX_LABEL_SIZE; + inbytesleft = str_len; + outbytesleft = str_len*sizeof(HPGS_LABEL_UCS_TYPE); + inbuf = hpgs_alloca(str_len); + + if (!inbuf) + return hpgs_set_error(hpgs_i18n("unable to allocate %d bytes of temporary string data."), + str_len); + memcpy(inbuf,str,str_len); + + outbuf = (char*)ucs_str; + + len= + iconv(encoding,&inbuf,&inbytesleft,&outbuf,&outbytesleft); + + if (len == (size_t)(-1)) + return hpgs_set_error(hpgs_i18n("unable to convert string to encoding %s: %s."), + encoding_name,strerror(errno)); + + len = (str_len*sizeof(HPGS_LABEL_UCS_TYPE) - outbytesleft) / sizeof(HPGS_LABEL_UCS_TYPE); + + // OK, now let's go. + hpgs_matrix m; + + m.mxx = left_vec->x * face_infos[iface].x_fac; + m.mxy = up_vec->x * face_infos[iface].y_fac; + m.myx = left_vec->y * face_infos[iface].x_fac; + m.myy = up_vec->y * face_infos[iface].y_fac; + + for (i=0;ix; + m.dy = pos->y; + + unsigned gid = hpgs_font_get_glyph_id(font,(int)ucs_str[i]); + + if (hpgs_font_draw_glyph(font,dev,&m,gid)) + return -1; + + pos->x += space_vec->x; + pos->y += space_vec->y; + } + + return 0; +} + +int hpgs_reader_label(hpgs_reader *reader, + const char *str, int str_len, + int face, + int encoding, + int posture, + int weight, + const hpgs_point *left_vec, + const hpgs_point *up_vec, + const hpgs_point *space_vec) +{ + int ienc; + + // open the encoding. + switch (encoding) + { + case 14: ienc = 1; break; + case 78: ienc = 2; break; + case 174: ienc = 3; break; + case 263: ienc = 4; break; + case 6: ienc = 5; break; + case 38: ienc = 6; break; + case 11: ienc = 7; break; + case 19: ienc = 8; break; + case 115: ienc = 9; break; + case 4: ienc = 10; break; + case 36: ienc = 11; break; + case 39: ienc = 12; break; + case 9: ienc = 13; break; + case 83: ienc = 14; break; + case 211: ienc = 15; break; + case 147: ienc = 16; break; + case 179: ienc = 17; break; + case 8: case 264: ienc = 18; break; + case 18: case 50: ienc = 19; break; + case 334: ienc = 20; break; + case 114: ienc = 21; break; + case 309: ienc = 22; break; + case 405: ienc = 23; break; + case 565: ienc = 24; break; + case 22: ienc = 25; break; + case 278: ienc = 26; break; + default: ienc = 0; + } + + iconv_t ic = iconv_open(HPGS_LABEL_UCS_ENC,encoding_names[ienc]); + + if (ic == (iconv_t)(-1)) + return hpgs_set_error(hpgs_i18n("unable to open encoding %s."), + encoding_names[ienc]); + + int ret =hpgs_device_label_internal(reader->device,&reader->current_point, + str,str_len,face, + ic,encoding_names[ienc], + posture,weight,left_vec,up_vec,space_vec); + + iconv_close(ic); + return ret; +} + +int hpgs_device_label(hpgs_device *dev, + hpgs_point *pos, + const char *str, int str_len, + int face, + const char *encoding, + int posture, + int weight, + const hpgs_point *left_vec, + const hpgs_point *up_vec, + const hpgs_point *space_vec) +{ + // open the encoding. + iconv_t ic = iconv_open(HPGS_LABEL_UCS_ENC,encoding); + int ret; + + if (ic == (iconv_t)(-1)) + return hpgs_set_error(hpgs_i18n("unable to open encoding %s."),encoding); + + ret = hpgs_device_label_internal(dev,pos,str,str_len,face, + ic,encoding, + posture,weight,left_vec,up_vec,space_vec); + iconv_close(ic); + return ret; +} diff --git a/src/add-ons/translators/hpgs/lib/hpgslexer.c b/src/add-ons/translators/hpgs/lib/hpgslexer.c new file mode 100644 index 0000000000..e390f0505d --- /dev/null +++ b/src/add-ons/translators/hpgs/lib/hpgslexer.c @@ -0,0 +1,353 @@ +/*********************************************************************** + * * + * $Id: hpgslexer.c 298 2006-03-05 18:18:03Z softadm $ + * * + * hpgs - HPGl Script, a hpgl/2 interpreter, which uses a Postscript * + * API for rendering a scene and thus renders to a variety of * + * devices and fileformats. * + * * + * (C) 2004-2006 ev-i Informationstechnologie GmbH http://www.ev-i.at * + * * + * Author: Wolfgang Glas * + * * + * hpgs is free software; you can redistribute it and/or * + * modify it under the terms of the GNU Lesser General Public * + * License as published by the Free Software Foundation; either * + * version 2.1 of the License, or (at your option) any later version. * + * * + * hpgs is distributed in the hope that it will be useful, * + * but WITHOUT ANY WARRANTY; without even the implied warranty of * + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * + * Lesser General Public License for more details. * + * * + * You should have received a copy of the GNU Lesser General Public * + * License along with this library; if not, write to the * + * Free Software Foundation, Inc., 59 Temple Place, Suite 330, * + * Boston, MA 02111-1307 USA * + * * + *********************************************************************** + * * + * The implementation of the HPGL reader. * + * * + ***********************************************************************/ + +#include +#include +#include + +int hpgs_reader_check_param_end(hpgs_reader *reader) +{ + do + { + reader->last_byte = hpgs_getc(reader->in); + if (reader->last_byte == EOF) + return -1; + } + while (isspace(reader->last_byte)); + + reader->bytes_ignored = 0; + + if (reader->last_byte == ';') + { + reader->bytes_ignored = 0; + reader->eoc = 1; + return 0; + } + if (reader->last_byte == ',') + { + do + { + reader->last_byte = hpgs_getc(reader->in); + if (reader->last_byte == EOF) + return -1; + } + while (isspace(reader->last_byte)); + + if (isalpha(reader->last_byte) || reader->last_byte == HPGS_ESC) + { + reader->bytes_ignored = 1; + reader->eoc = 1; + return 0; + } + else + { + hpgs_ungetc(reader->last_byte,reader->in); + reader->bytes_ignored = 0; + reader->eoc = 0; + return 0; + } + } + if (reader->last_byte == '"' || reader->last_byte == '\'' || + isdigit(reader->last_byte) || + reader->last_byte == '+' || reader->last_byte == '-' || + reader->last_byte == '.') + { + hpgs_ungetc(reader->last_byte,reader->in); + reader->bytes_ignored = 0; + reader->eoc = 0; + return 0; + } + if (isalpha(reader->last_byte) || reader->last_byte == HPGS_ESC) + { + reader->bytes_ignored = 1; + reader->eoc = 1; + return 0; + } + return -1; +} + +/* read an integer argument from the stream - PCL version + return values: -1... read error/EOF + 0... no integer found. + 1... integer found. +*/ +int hpgs_reader_read_pcl_int(hpgs_reader *reader, int *x, int *sign) +{ + *sign = 0; + *x=0; + + reader->last_byte = hpgs_getc(reader->in); + if (reader->last_byte == EOF) + return -1; + + if (reader->last_byte == '-') + { *sign = -1; reader->last_byte=hpgs_getc(reader->in); } + else if (reader->last_byte == '+') + { *sign = 1; reader->last_byte=hpgs_getc(reader->in); } + + if (reader->last_byte == EOF) + return -1; + + if (!isdigit(reader->last_byte)) + { hpgs_ungetc(reader->last_byte,reader->in); return 0; } + + do + { + *x = 10 * (*x) + (reader->last_byte-'0'); + + reader->last_byte = hpgs_getc(reader->in); + if (reader->last_byte == EOF) + return -1; + } + while (isdigit(reader->last_byte)); + + hpgs_ungetc(reader->last_byte,reader->in); + if (*sign < 0) + *x = -*x; + + return 1; +} + +/* read an integer argument from the stream + return values: -1... read error/EOF + 0... success. + 1... End of command. +*/ +int hpgs_reader_read_int(hpgs_reader *reader, int *x) +{ + int sign = 0; + + if (reader->eoc) return -1; + + *x=0; + + do + { + reader->last_byte = hpgs_getc(reader->in); + if (reader->last_byte == EOF) + return -1; + } + while (isspace(reader->last_byte) || reader->last_byte==','); + + if (reader->last_byte == '-') + sign = 1; + else if (reader->last_byte == '+') + sign = 0; + else if (isdigit(reader->last_byte)) + hpgs_ungetc(reader->last_byte,reader->in); + else + return -1; + + while (1) + { + reader->last_byte = hpgs_getc(reader->in); + if (reader->last_byte == EOF) + return -1; + + if (isdigit(reader->last_byte)) + *x = 10 * (*x) + (reader->last_byte-'0'); + else + break; + } + + hpgs_ungetc(reader->last_byte,reader->in); + + return hpgs_reader_check_param_end(reader); +} + +/* read a double argument from the stream + return values: -1... read error/EOF + 0... success. + 1... End of command. +*/ +int hpgs_reader_read_double(hpgs_reader *reader, double *x) +{ + int sign = 0; + + if (reader->eoc) return -1; + + *x=0.0; + + do + { + reader->last_byte = hpgs_getc(reader->in); + if (reader->last_byte == EOF) + return -1; + } + while (isspace(reader->last_byte) || reader->last_byte==','); + + if (reader->last_byte == '-') + sign = 1; + else if (reader->last_byte == '+') + sign = 0; + else if (!isdigit(reader->last_byte) && reader->last_byte != '.') + return -1; + + if (isdigit(reader->last_byte)) + hpgs_ungetc(reader->last_byte,reader->in); + + if (reader->last_byte != '.') + while (1) + { + reader->last_byte = hpgs_getc(reader->in); + if (reader->last_byte == EOF) + return -1; + + if (isdigit(reader->last_byte)) + *x = 10.0 * (*x) + (reader->last_byte-'0'); + else + break; + } + + if (reader->last_byte == '.') + { + double xx=1.0; + + while (1) + { + reader->last_byte = hpgs_getc(reader->in); + if (reader->last_byte == EOF) + return -1; + + xx *= 0.1; + + if (isdigit(reader->last_byte)) + *x += xx * (reader->last_byte-'0'); + else + break; + } + } + + hpgs_ungetc(reader->last_byte,reader->in); + + if (sign) *x = -*x; + + return hpgs_reader_check_param_end(reader); +} + +int hpgs_reader_read_point(hpgs_reader *reader, hpgs_point *p, int xform) +{ + if (hpgs_reader_read_double(reader,&p->x)) return -1; + if (reader->eoc) return -1; + if (hpgs_reader_read_double(reader,&p->y)) return -1; + + switch (xform) + { + case 1: + hpgs_matrix_xform (p,&reader->total_matrix,p); + break; + case -1: + hpgs_matrix_scale (p,&reader->total_matrix,p); + break; + default: + break; + } + + return 0; +} + +/* read an integer argument from the stream + return values: -1... read error/EOF + 0... success. + 1... End of command. +*/ +int hpgs_reader_read_new_string(hpgs_reader *reader, char *str) +{ + int term=','; + int i=0; + + if (reader->eoc) return -1; + + do + { + reader->last_byte = hpgs_getc(reader->in); + if (reader->last_byte == EOF) + return -1; + } + while (isspace(reader->last_byte)); + + if (reader->last_byte == '\'' || reader->last_byte=='"') + term = reader->last_byte; + else + str[i++] = reader->last_byte; + + do + { + reader->last_byte = hpgs_getc(reader->in); + if (reader->last_byte == EOF) + return -1; + + if (ilast_byte; + + ++i; + + if (term == ',' && reader->last_byte == ';') break; + } + while (reader->last_byte != term); + + if (i) --i; + str[i] = '\0'; + + return hpgs_reader_check_param_end(reader); +} + +int hpgs_reader_read_label_string(hpgs_reader *reader, char *str) +{ + int i=0; + + if (reader->eoc) return -1; + + reader->bytes_ignored = 0; + + do + { + reader->last_byte = hpgs_getc(reader->in); + if (reader->last_byte == EOF) + return -1; + + if (ilast_byte; + + ++i; + } + while (reader->last_byte != reader->label_term); + + if (reader->label_term_ignore && i) + --i; + + str[i] = '\0'; + + return hpgs_reader_check_param_end(reader); +} + diff --git a/src/add-ons/translators/hpgs/lib/hpgsmatrix.c b/src/add-ons/translators/hpgs/lib/hpgsmatrix.c new file mode 100644 index 0000000000..ac5a372bc3 --- /dev/null +++ b/src/add-ons/translators/hpgs/lib/hpgsmatrix.c @@ -0,0 +1,223 @@ +/*********************************************************************** + * * + * $Id: hpgsmatrix.c 298 2006-03-05 18:18:03Z softadm $ + * * + * hpgs - HPGl Script, a hpgl/2 interpreter, which uses a Postscript * + * API for rendering a scene and thus renders to a variety of * + * devices and fileformats. * + * * + * (C) 2004-2006 ev-i Informationstechnologie GmbH http://www.ev-i.at * + * * + * Author: Wolfgang Glas * + * * + * hpgs is free software; you can redistribute it and/or * + * modify it under the terms of the GNU Lesser General Public * + * License as published by the Free Software Foundation; either * + * version 2.1 of the License, or (at your option) any later version. * + * * + * hpgs is distributed in the hope that it will be useful, * + * but WITHOUT ANY WARRANTY; without even the implied warranty of * + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * + * Lesser General Public License for more details. * + * * + * You should have received a copy of the GNU Lesser General Public * + * License along with this library; if not, write to the * + * Free Software Foundation, Inc., 59 Temple Place, Suite 330, * + * Boston, MA 02111-1307 USA * + * * + *********************************************************************** + * * + * The implementation of the public API for transformation matrices. * + * * + ***********************************************************************/ + +#include + +/*! + Sets the given matrix to the identity matrix. + */ +void hpgs_matrix_set_identity(hpgs_matrix *m) +{ + m->myx = m->mxy = m->dy = m->dx = 0.0; + m->myy = m->mxx = 1.0; +} + +/*! + Transforms the given point \c p with the matrix \c m. + The result is stored in \c res. + The pointers \c p and \c res may point to the same memory location. + */ +void hpgs_matrix_xform(hpgs_point *res, + const hpgs_matrix *m, const hpgs_point *p) +{ + double x = m->dx + m->mxx * p->x + m->mxy * p->y; + double y = m->dy + m->myx * p->x + m->myy * p->y; + res->x = x; + res->y = y; +} + +/*! + Transforms the given point \c p with the inverse of the matrix \c m. + The result is stored in \c res. + The pointers \c p and \c res may point to the same memory location. + */ +void hpgs_matrix_ixform(hpgs_point *res, + const hpgs_point *p, const hpgs_matrix *m) +{ + double x0 = (p->x - m->dx); + double y0 = (p->y - m->dy); + + double det = m->mxx * m->myy - m->mxy * m->myx; + + res->x = (m->myy * x0 - m->mxy * y0)/det; + res->y = (m->mxx * y0 - m->myx * x0)/det; +} + +/*! + Transforms the given bounding box \c bb with the matrix \c m. + The result is the enclosing bounding box of the transformed + rectangle of the bounding box and is stored in \c res. + The pointers \c bb and \c res may point to the same memory location. + */ +void hpgs_matrix_xform_bbox(hpgs_bbox *res, + const hpgs_matrix *m, const hpgs_bbox *bb) +{ + hpgs_point ll = { bb->llx, bb->lly }; + hpgs_point ur = { bb->urx, bb->ury }; + + hpgs_point lr = { bb->llx, bb->ury }; + hpgs_point ul = { bb->urx, bb->lly }; + + hpgs_matrix_xform(&ll,m,&ll); + hpgs_matrix_xform(&ur,m,&ur); + + hpgs_matrix_xform(&lr,m,&lr); + hpgs_matrix_xform(&ul,m,&ul); + + res->llx = HPGS_MIN(HPGS_MIN(ll.x,ur.x),HPGS_MIN(lr.x,ul.x)); + res->lly = HPGS_MIN(HPGS_MIN(ll.y,ur.y),HPGS_MIN(lr.y,ul.y)); + + res->urx = HPGS_MAX(HPGS_MAX(ll.x,ur.x),HPGS_MAX(lr.x,ul.x)); + res->ury = HPGS_MAX(HPGS_MAX(ll.y,ur.y),HPGS_MAX(lr.y,ul.y)); +} + +/*! + Transforms the given bounding box \c bb with the the inverse of + the matrix \c m. + The result is the enclosing bounding box of the transformed + rectangle of the bounding box and is stored in \c res. + The pointers \c bb and \c res may point to the same memory location. + */ +void hpgs_matrix_ixform_bbox(hpgs_bbox *res, + const hpgs_bbox *bb, const hpgs_matrix *m) +{ + hpgs_point ll = { bb->llx, bb->lly }; + hpgs_point ur = { bb->urx, bb->ury }; + + hpgs_point lr = { bb->llx, bb->ury }; + hpgs_point ul = { bb->urx, bb->lly }; + + hpgs_matrix_ixform(&ll,&ll,m); + hpgs_matrix_ixform(&ur,&ur,m); + + hpgs_matrix_ixform(&lr,&lr,m); + hpgs_matrix_ixform(&ul,&ul,m); + + res->llx = HPGS_MIN(HPGS_MIN(ll.x,ur.x),HPGS_MIN(lr.x,ul.x)); + res->lly = HPGS_MIN(HPGS_MIN(ll.y,ur.y),HPGS_MIN(lr.y,ul.y)); + + res->urx = HPGS_MAX(HPGS_MAX(ll.x,ur.x),HPGS_MAX(lr.x,ul.x)); + res->ury = HPGS_MAX(HPGS_MAX(ll.y,ur.y),HPGS_MAX(lr.y,ul.y)); +} + +/*! + Transforms the given point \c p with the matrix \c m without + applying the translation part of \c m. This is useful in order + to transform delta vectors. + + The result is stored in \c res. + The pointers \c p and \c res may point to the same memory location. + */ +void hpgs_matrix_scale(hpgs_point *res, + const hpgs_matrix *m, const hpgs_point *p) +{ + double x = m->mxx * p->x + m->mxy * p->y; + double y = m->myx * p->x + m->myy * p->y; + res->x = x; + res->y = y; +} + +/*! + Transforms the given point \c p with the inverse of the matrix \c m + without applying the translation part of \c m. This is useful in order + to transform delta vectors. + + The result is stored in \c res. + The pointers \c p and \c res may point to the same memory location. + */ +void hpgs_matrix_iscale(hpgs_point *res, + const hpgs_point *p, const hpgs_matrix *m) +{ + double x0 = p->x; + double y0 = p->y; + + double det = m->mxx * m->myy - m->mxy * m->myx; + + res->x = (m->myy * x0 - m->mxy * y0)/det; + res->y = (m->mxx * y0 - m->myx * x0)/det; +} + +/*! + Concatenates the given matrices \c a and \c b. + The result is stored in \c res. + Either of the pointer \c a or \b may point to the same memory location as + the pointer \c res. + */ +void hpgs_matrix_concat(hpgs_matrix *res, + const hpgs_matrix *a, const hpgs_matrix *b) +{ + // + // | 1 0 0 | | 1 0 0 | | 1 0 0 | + // | dx mxx mxy | x | Dx Mxx Mxy | = | dx+Dx*mxx+Dy*mxy mxx*Mxx+mxy*Myx mxx*Mxy+mxy*Myy | + // | dy myx myy | | Dy Myx Myy | | dy+Dx*myx+Dy*myy myx*Mxx+myy*Myx myx*Mxy+myy*Myy | + // + double r0,r1,r2,r3; + + r0 = a->dx+b->dx*a->mxx+b->dy*a->mxy; + r1 = a->dy+b->dx*a->myx+b->dy*a->myy; + + res->dx = r0; + res->dy = r1; + + r0 = a->mxx*b->mxx+a->mxy*b->myx; + r1 = a->mxx*b->mxy+a->mxy*b->myy; + r2 = a->myx*b->mxx+a->myy*b->myx; + r3 = a->myx*b->mxy+a->myy*b->myy; + + res->mxx = r0; + res->mxy = r1; + res->myx = r2; + res->myy = r3; +} + +/*! + Inverts the given matrix \c m. + The result is stored in \c res. + The pointers \c m and \c res may point to the same memory location. + */ +void hpgs_matrix_invert(hpgs_matrix *res, const hpgs_matrix *m) +{ + double det = m->mxx * m->myy - m->mxy * m->myx; + + double tmp = m->mxx/det; + res->mxx = m->myy/det; + res->myy = tmp; + + res->mxy = -m->mxy/det; + res->myx = -m->myx/det; + + double x0 = -m->dx; + double y0 = -m->dy; + res->dx = x0 * res->mxx + y0 * res->mxy; + res->dy = x0 * res->myx + y0 * res->myy; +} diff --git a/src/add-ons/translators/hpgs/lib/hpgsmkrop.c b/src/add-ons/translators/hpgs/lib/hpgsmkrop.c new file mode 100644 index 0000000000..6b44724ee9 --- /dev/null +++ b/src/add-ons/translators/hpgs/lib/hpgsmkrop.c @@ -0,0 +1,527 @@ +/*********************************************************************** + * * + * $Id: hpgsmkrop.c 270 2006-01-29 21:12:23Z softadm $ + * * + * hpgs - HPGl Script, a hpgl/2 interpreter, which uses a Postscript * + * API for rendering a scene and thus renders to a variety of * + * devices and fileformats. * + * * + * (C) 2004-2006 ev-i Informationstechnologie GmbH http://www.ev-i.at * + * * + * Author: Wolfgang Glas * + * * + * hpgs is free software; you can redistribute it and/or * + * modify it under the terms of the GNU Lesser General Public * + * License as published by the Free Software Foundation; either * + * version 2.1 of the License, or (at your option) any later version. * + * * + * hpgs is distributed in the hope that it will be useful, * + * but WITHOUT ANY WARRANTY; without even the implied warranty of * + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * + * Lesser General Public License for more details. * + * * + * You should have received a copy of the GNU Lesser General Public * + * License along with this library; if not, write to the * + * Free Software Foundation, Inc., 59 Temple Place, Suite 330, * + * Boston, MA 02111-1307 USA * + * * + *********************************************************************** + * * + * A small programm, which generates the raster operations hpgsrop.c * + * * + ***********************************************************************/ + +#include +#include +#include +#include +#include + +#ifdef __GNUC__ +__attribute__((format(printf,4,5))) +#endif +static int apprintf (char *str, size_t str_sz, size_t *str_len, + const char *fmt, ...) +{ + int n; + va_list ap; + + va_start(ap, fmt); + + n = vsnprintf(str+*str_len,str_sz-*str_len,fmt,ap); + + va_end(ap); + + if (n<0) { perror("snprintf"); return -1; } + *str_len+=n; + + return 0; +} + +static void mk_operand (char *operand, size_t operand_sz, const char *stack, int i) +{ + switch (stack[i]) + { + case 'D': + strcpy(operand,"*D"); + break; + case 'S': + case 'T': + operand[0] = stack[i]; + operand[1] = '\0'; + break; + default: + snprintf(operand,operand_sz,"stk%d",i+1); + } +} + +static void mk_xoperand (char *operand, size_t operand_sz, const char *stack, int i) +{ + switch (stack[i]) + { + case 'D': + strcpy(operand,"D"); + break; + case 'S': + case 'T': + operand[0] = stack[i]; + operand[1] = '\0'; + break; + default: + snprintf(operand,operand_sz,"stk%d",i+1); + } +} + +/* + This function converts a ROP3 description cf. to + + PCL 5 Comparison Guide, Edition 2, 6/2003, Hewlett Packard + (May be downloaded as bpl13206.pdf from http://www.hp.com) + + into 4 C-programs for all transparency modes supported by + HPGL/2 and PCL. + + Additional information may be found under + + http://msdn.microsoft.com/library/default.asp?url=/library/en-us/wceshellui5/html/wce50grfTernaryRasterOperations.asp + + (especially typos in HP's documentation are corrected from + this source of information). + +*/ +static int write_rop3_func(FILE *out, int irop, const char *ropstr) +{ + int stacksz = 0; + int max_stacksz = 0; + char stack[32]; + char operand[32]; + char operand2[32]; + const char *c; + + int D_used = 0; + int S_used = 0; + int T_used = 0; + + char defn[2048],op; + size_t defn_len=0; + char xdefn[2048]; + size_t xdefn_len=0; + int i; + + defn[0] = '\0'; + xdefn[0] = '\0'; + + for (c=ropstr;*c;++c) + switch (*c) + { + case '0': + case '1': + i = (*c == '0') ? 0 : 255; + max_stacksz = stacksz = 1; + + if (c!=ropstr || *(c+1)) + { + fprintf (stderr,"Misplaced %c in rop string %s.\n", + *c,ropstr); + return -1; + } + + if (apprintf(defn,sizeof(defn),&defn_len, + " stk1 = %d;\n",i )) + return -1; + + if (apprintf(xdefn,sizeof(xdefn),&xdefn_len, + " stk1 = %s;\n", (*c == '0') ? "0x0000" : "0xffff")) + return -1; + + break; + + case 'S': + case 'T': + case 'D': + if (stacksz >= sizeof(stack)-1) + { + fprintf (stderr,"Stack overflow in rop string %s.\n",ropstr); + return -1; + } + + stack[stacksz] = *c; + ++stacksz; + + if (*c == 'D') + D_used = 1; + + if (*c == 'T') + T_used = 1; + + if (*c == 'S') + S_used = 1; + break; + + case 'o': + case 'a': + case 'x': + if (stacksz<1) + { + fprintf (stderr,"Stack underflow in rop string %s.\n",ropstr); + return -1; + } + + mk_operand(operand,sizeof(operand),stack,stacksz-2); + mk_operand(operand2,sizeof(operand),stack,stacksz-1); + + op = (*c == 'o') ? '|' : ((*c == 'a') ? '&' : '^'); + + if (apprintf(defn,sizeof(defn),&defn_len, + " stk%d = %s %c %s;\n", + stacksz-1,operand,op,operand2 )) + return -1; + + mk_xoperand(operand,sizeof(operand),stack,stacksz-2); + mk_xoperand(operand2,sizeof(operand),stack,stacksz-1); + + if (apprintf(xdefn,sizeof(xdefn),&xdefn_len, + " stk%d = %s %c %s;\n", + stacksz-1,operand,op,operand2 )) + return -1; + + --stacksz; + // account for the max intermediate result on the stack. + if (stacksz > max_stacksz) max_stacksz = stacksz; + + stack[stacksz-1] = '\0'; + break; + + case 'n': + mk_operand(operand,sizeof(operand),stack,stacksz-1); + + if (apprintf(defn,sizeof(defn),&defn_len, + " stk%d = ~%s;\n", + stacksz,operand )) + return -1; + + mk_xoperand(operand,sizeof(operand),stack,stacksz-1); + + if (apprintf(xdefn,sizeof(xdefn),&xdefn_len, + " stk%d = ~%s;\n", + stacksz,operand )) + return -1; + + // account for the max intermediate result on the stack. + if (stacksz > max_stacksz) max_stacksz = stacksz; + + stack[stacksz-1] = '\0'; + break; + + default: + fprintf (stderr,"Illegal character %c in rop string %s.\n", + *c,ropstr); + return -1; + } + + if (stacksz!=1) + { + fprintf (stderr,"Unbalanced shift/reduce in rop string %s.\n",ropstr); + return -1; + } + + mk_operand(operand,sizeof(operand),stack,0); + + // ******** normal ROP functions + // case 1: source/pattern opaque. + fprintf (out, + "/* %s source/pattern opaque. */\n" + "static void rop3_%d_0_0 (unsigned char *D, unsigned char S, unsigned char T)\n{\n", + ropstr,irop); + + for (i=1;i<=max_stacksz;++i) + fprintf(out," unsigned char stk%d;\n",i); + + fputs(defn,out); + + // optimize for noop. + if (stack[0] != 'D') + fprintf(out," *D = %s;\n",operand); + + fprintf(out,"}\n\n"); + + // case 2: source opaque/pattern transparent. + fprintf (out, + "/* %s source opaque/pattern transparent. */\n" + "static void rop3_%d_0_1 (unsigned char *D, unsigned char S, unsigned char T)\n{\n", + ropstr,irop); + + for (i=1;i<=max_stacksz;++i) + fprintf(out," unsigned char stk%d;\n",i); + + fputs(defn,out); + + // Image_A = Temporary_ROP3, & Not Src. + // Image_B = Temporary_ROP3 & Pattern. + // Image_C = Not Pattern & Src & Dest. + // Return Image_A | Image_B | Image_C + fprintf(out," *D = (%s & S) | (%s & (~T)) | (T & (~S) & *D);\n",operand,operand); + + fprintf(out,"}\n\n"); + + // case 3: source transparent/pattern opaque. + fprintf (out, + "/* %s source transparent/pattern opaque. */\n" + "static void rop3_%d_1_0 (unsigned char *D, unsigned char S, unsigned char T)\n{\n", + ropstr,irop); + + for (i=1;i<=max_stacksz;++i) + fprintf(out," unsigned char stk%d;\n",i); + + fputs(defn,out); + + // Image_A = Temporary_ROP3 & Src. + // Image_B = Dest & Not Src. + // Return Image_A | Image_B + fprintf(out," *D = (%s & (~S)) | (*D & S);\n",operand); + + fprintf(out,"}\n\n"); + + // case 4: source/pattern transparent. + fprintf (out, + "/* %s source/pattern transparent. */\n" + "static void rop3_%d_1_1 (unsigned char *D, unsigned char S, unsigned char T)\n{\n", + ropstr,irop); + + for (i=1;i<=max_stacksz;++i) + fprintf(out," unsigned char stk%d;\n",i); + + fputs(defn,out); + // Image_A = Temporary_ROP3 & Src & Pattern. + // Image_B = Dest & Not Src. + // Image_C = Dest & Not Pattern. + // Return Image_A | Image_B | Image_C. + fprintf(out," *D = (%s & (~S) & (~T)) | (*D & S) | (*D & T);\n",operand); + + fprintf(out,"}\n\n"); + + // ******** ROP transfer functions + mk_xoperand(operand,sizeof(operand),stack,0); + // case 1: source/pattern opaque. + fprintf (out, + "/* %s source/pattern opaque. */\n" + "static unsigned xrop3_%d_0_0 (unsigned char s, unsigned char t)\n{\n", + ropstr,irop); + + if (D_used) + fprintf (out," unsigned D = 0x00ff;\n"); + if (S_used) + fprintf (out," unsigned S = ((unsigned)s << 8) | s;\n"); + if (T_used) + fprintf (out," unsigned T = ((unsigned)t << 8) | t;\n"); + + for (i=1;i<=max_stacksz;++i) + fprintf(out," unsigned stk%d;\n",i); + + fputs(xdefn,out); + + fprintf(out," return %s;\n",operand); + + fprintf(out,"}\n\n"); + + // case 2: source opaque/pattern transparent. + fprintf (out, + "/* %s source opaque/pattern transparent. */\n" + "static unsigned xrop3_%d_0_1 (unsigned char s, unsigned char t)\n{\n", + ropstr,irop); + + fprintf (out," unsigned D = 0x00ff;\n"); + fprintf (out," unsigned S = ((unsigned)s << 8) | s;\n"); + fprintf (out," unsigned T = ((unsigned)t << 8) | t;\n"); + + for (i=1;i<=max_stacksz;++i) + fprintf(out," unsigned stk%d;\n",i); + + fputs(xdefn,out); + + // Image_A = Temporary_ROP3, & Not Src. + // Image_B = Temporary_ROP3 & Pattern. + // Image_C = Not Pattern & Src & Dest. + // Return Image_A | Image_B | Image_C + fprintf(out," return (%s & S) | (%s & (~T)) | (T & (~S) & D);\n",operand,operand); + + fprintf(out,"}\n\n"); + + // case 3: source transparent/pattern opaque. + fprintf (out, + "/* %s source transparent/pattern opaque. */\n" + "static unsigned xrop3_%d_1_0 (unsigned char s, unsigned char t)\n{\n", + ropstr,irop); + + fprintf (out," unsigned D = 0x00ff;\n"); + fprintf (out," unsigned S = ((unsigned)s << 8) | s;\n"); + if (T_used) + fprintf (out," unsigned T = ((unsigned)t << 8) | t;\n"); + + for (i=1;i<=max_stacksz;++i) + fprintf(out," unsigned stk%d;\n",i); + + fputs(xdefn,out); + + // Image_A = Temporary_ROP3 & Src. + // Image_B = Dest & Not Src. + // Return Image_A | Image_B + fprintf(out," return (%s & (~S)) | (D & S);\n",operand); + + fprintf(out,"}\n\n"); + + // case 4: source/pattern transparent. + fprintf (out, + "/* %s source/pattern transparent. */\n" + "static unsigned xrop3_%d_1_1 (unsigned char s, unsigned char t)\n{\n", + ropstr,irop); + + fprintf (out," unsigned D = 0x00ff;\n"); + fprintf (out," unsigned S = ((unsigned)s << 8) | s;\n"); + fprintf (out," unsigned T = ((unsigned)t << 8) | t;\n"); + + for (i=1;i<=max_stacksz;++i) + fprintf(out," unsigned stk%d;\n",i); + + fputs(xdefn,out); + // Image_A = Temporary_ROP3 & Src & Pattern. + // Image_B = Dest & Not Src. + // Image_C = Dest & Not Pattern. + // Return Image_A | Image_B | Image_C. + fprintf(out," return (%s & (~S) & (~T)) | (D & S) | (D & T);\n",operand); + + fprintf(out,"}\n\n"); + + return 0; +} + +int main (int argc, const char *argv[]) +{ + FILE *in=0; + FILE *out=0; + int irop=0,i; + char ropstr[32]; + int ret = 0; + time_t now; + + if (argc != 3) + { + fprintf(stderr,"usage: %s .\n",argv[0]); + return 1; + } + + in = fopen(argv[1],"rb"); + + if (!in) + { + fprintf(stderr,"%s: Error opening file <%s>: %s.\n", + argv[0],argv[1],strerror(errno)); + ret = 1; + goto cleanup; + } + + out = fopen(argv[2],"wb"); + + if (!out) + { + fprintf(stderr,"%s: Error opening file <%s>: %s.\n", + argv[0],argv[2],strerror(errno)); + ret = 1; + goto cleanup; + } + + now = time(0); + fprintf(out,"/* Generated automatically by %s at %.24s.\n",argv[0],ctime(&now)); + fprintf(out," Do not edit!\n"); + fprintf(out," */\n"); + fprintf(out,"#include \n\n"); + + + // go through all ROP descritions in hpgsrop.dat + while (fscanf(in,"%d %31s",&i,ropstr) == 2) + { + if (i!=irop) + { + fprintf(stderr,"%s: Illegal count %d in stanza %d.\n", + argv[0],i,irop); + ret = 1; + goto cleanup; + } + + if (write_rop3_func(out,irop,ropstr)) + goto cleanup; + + ++irop; + } + + // Collect all rop function in one big lookup table... + fprintf(out, + "static hpgs_rop3_func_t rop3_table[][2][2] = {\n"); + + for (i=0;i= %d) return 0;\n" + " return rop3_table[rop3][src_transparency!=0][pattern_transparency!=0];\n" + "}\n", + irop); + + // Collect all rop xfer function in one big lookup table... + fprintf(out, + "static hpgs_xrop3_func_t xrop3_table[][2][2] = {\n"); + + for (i=0;i= %d) return 0;\n" + " return xrop3_table[rop3][src_transparency!=0][pattern_transparency!=0];\n" + "}\n", + irop); + + cleanup: + if (in) fclose(in); + if (out) fclose(out); + return ret; +} diff --git a/src/add-ons/translators/hpgs/lib/hpgsmutex.h b/src/add-ons/translators/hpgs/lib/hpgsmutex.h new file mode 100644 index 0000000000..90f73a2d99 --- /dev/null +++ b/src/add-ons/translators/hpgs/lib/hpgsmutex.h @@ -0,0 +1,84 @@ +/*********************************************************************** + * * + * $Id: hpgsmutex.h 286 2006-03-03 15:14:14Z softadm $ + * * + * hpgs - HPGl Script, a hpgl/2 interpreter, which uses a Postscript * + * API for rendering a scene and thus renders to a variety of * + * devices and fileformats. * + * * + * (C) 2004-2006 ev-i Informationstechnologie GmbH http://www.ev-i.at * + * * + * Author: Wolfgang Glas * + * * + * hpgs is free software; you can redistribute it and/or * + * modify it under the terms of the GNU Lesser General Public * + * License as published by the Free Software Foundation; either * + * version 2.1 of the License, or (at your option) any later version. * + * * + * hpgs is distributed in the hope that it will be useful, * + * but WITHOUT ANY WARRANTY; without even the implied warranty of * + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * + * Lesser General Public License for more details. * + * * + * You should have received a copy of the GNU Lesser General Public * + * License along with this library; if not, write to the * + * Free Software Foundation, Inc., 59 Temple Place, Suite 330, * + * Boston, MA 02111-1307 USA * + * * + *********************************************************************** + * * + * Private header file for thread mutex support. * + * * + ***********************************************************************/ + +#ifndef __HPGS_MUTEX_H__ +#define __HPGS_MUTEX_H__ + +#ifndef __HPGS_H +#include +#endif + +#ifdef WIN32 +#include +typedef CRITICAL_SECTION hpgs_mutex_t; +#else +#include +typedef pthread_mutex_t hpgs_mutex_t; +#endif + +static void hpgs_mutex_init(hpgs_mutex_t *m); +static void hpgs_mutex_destroy(hpgs_mutex_t *m); +static void hpgs_mutex_lock(hpgs_mutex_t *m); +static void hpgs_mutex_unlock(hpgs_mutex_t *m); + +#ifdef WIN32 + +__inline__ void hpgs_mutex_init(hpgs_mutex_t *m) +{ InitializeCriticalSection(m); } + +__inline__ void hpgs_mutex_destroy(hpgs_mutex_t *m) +{ DeleteCriticalSection(m); } + +__inline__ void hpgs_mutex_lock(hpgs_mutex_t *m) +{ EnterCriticalSection(m); } + +__inline__ void hpgs_mutex_unlock(hpgs_mutex_t *m) +{ LeaveCriticalSection(m); } + +#else + +__inline__ void hpgs_mutex_init(hpgs_mutex_t *m) +{ pthread_mutex_init(m,0); } + +__inline__ void hpgs_mutex_destroy(hpgs_mutex_t *m) +{ pthread_mutex_destroy(m); } + +__inline__ void hpgs_mutex_lock(hpgs_mutex_t *m) +{ pthread_mutex_lock(m); } + +__inline__ void hpgs_mutex_unlock(hpgs_mutex_t *m) +{ pthread_mutex_unlock(m); } + +#endif + +#endif diff --git a/src/add-ons/translators/hpgs/lib/hpgsostream.c b/src/add-ons/translators/hpgs/lib/hpgsostream.c new file mode 100644 index 0000000000..961d65233b --- /dev/null +++ b/src/add-ons/translators/hpgs/lib/hpgsostream.c @@ -0,0 +1,343 @@ +/*********************************************************************** + * * + * $Id: hpgsostream.c 368 2006-12-31 15:18:08Z softadm $ + * * + * hpgs - HPGl Script, a hpgl/2 interpreter, which uses a Postscript * + * API for rendering a scene and thus renders to a variety of * + * devices and fileformats. * + * * + * (C) 2004-2006 ev-i Informationstechnologie GmbH http://www.ev-i.at * + * * + * Author: Wolfgang Glas * + * * + * hpgs is free software; you can redistribute it and/or * + * modify it under the terms of the GNU Lesser General Public * + * License as published by the Free Software Foundation; either * + * version 2.1 of the License, or (at your option) any later version. * + * * + * hpgs is distributed in the hope that it will be useful, * + * but WITHOUT ANY WARRANTY; without even the implied warranty of * + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * + * Lesser General Public License for more details. * + * * + * You should have received a copy of the GNU Lesser General Public * + * License along with this library; if not, write to the * + * Free Software Foundation, Inc., 59 Temple Place, Suite 330, * + * Boston, MA 02111-1307 USA * + * * + *********************************************************************** + * * + * The implementation of basic output streams. * + * * + ***********************************************************************/ + +#include +#include +#include + +/*! The counterpart of ANSI fprintf for \c hpgs_ostream. */ +int hpgs_ostream_printf (hpgs_ostream *_this, const char *msg, ...) +{ + int ret; + va_list ap; + va_start(ap,msg); + ret=_this->vtable->vprintf_func(_this->stream,msg,ap); + va_end(ap); + return ret; +} + +/*! The counterpart of ANSI fvprintf for \c hpgs_ostream. */ +int hpgs_ostream_vprintf (hpgs_ostream *_this, const char *msg, va_list ap) +{ + int ret; + va_list aq; + va_copy(aq, ap); + ret = _this->vtable->vprintf_func(_this->stream,msg,aq); + va_end(aq); + return ret; +} + + +static int file_seek (FILE *file, size_t pos) +{ + return fseek(file,pos,SEEK_SET); +} + +static int file_tell (FILE *file, int layer, size_t *pos) +{ + if (layer) return -1; + + long pp=ftell(file); + + if (pp<0) return -1; + + *pos = pp; + return 0; +} + +static hpgs_ostream_vtable stdfile_vtable = + { + (hpgs_ostream_putc_func_t) putc, + (hpgs_ostream_write_func_t) fwrite, + (hpgs_ostream_vprintf_func_t) vfprintf, + (hpgs_ostream_flush_func_t) fflush, + (hpgs_ostream_close_func_t) fflush, + (hpgs_ostream_iserror_func_t) ferror, + (hpgs_ostream_getbuf_func_t) 0, + (hpgs_ostream_tell_func_t) file_tell, + (hpgs_ostream_seek_func_t) 0 + }; + +static hpgs_ostream_vtable file_vtable = + { + (hpgs_ostream_putc_func_t) putc, + (hpgs_ostream_write_func_t) fwrite, + (hpgs_ostream_vprintf_func_t) vfprintf, + (hpgs_ostream_flush_func_t) fflush, + (hpgs_ostream_close_func_t) fclose, + (hpgs_ostream_iserror_func_t) ferror, + (hpgs_ostream_getbuf_func_t) 0, + (hpgs_ostream_tell_func_t) file_tell, + (hpgs_ostream_seek_func_t) file_seek + }; + +/*! Returns a new \c hpgs_ostream created on the heap, + which operates on a file, which is opened by this call + in write-only mode. + + Returns a null pointer, when an I/O error occurrs. + In this case, details about the the error can be retrieved + using \c errno. + */ +hpgs_ostream *hpgs_new_file_ostream (const char *fn) +{ + FILE *out = fn ? fopen (fn,"wb") : stdout; + hpgs_ostream *ret = 0; + + if (!out) return 0; + + ret = (hpgs_ostream *)malloc(sizeof(hpgs_ostream)); + + if (!ret) + { + fclose(out); + return 0; + } + + ret->stream = out; + + if (fn) + ret->vtable = &file_vtable; + else + ret->vtable = &stdfile_vtable; + + return ret; +} + +typedef struct hpgs_mem_ostream_stream_st hpgs_mem_ostream_stream; + +struct hpgs_mem_ostream_stream_st +{ + unsigned char *data; + unsigned char *pptr; + unsigned char *eptr; + int errflg; +}; + +static int mem_grow (hpgs_mem_ostream_stream *stream, size_t hint) +{ + if (stream->errflg) + return EOF; + + size_t pos = stream->pptr-stream->data; + size_t sz = stream->eptr-stream->data; + size_t sz2 = (hint > sz) ? sz+hint : 2*sz; + + // check for overflow. + if (sz2 < sz) + { + stream->errflg = 1; + return EOF; + } + + unsigned char *ndata=(unsigned char *)realloc(stream->data,sz2); + + if (ndata) + { + stream->data=ndata; + stream->pptr=stream->data+pos; + stream->eptr=stream->data+sz2; + return 0; + } + else + { + stream->errflg = 1; + return EOF; + } +} + +static int mem_putc (int c, hpgs_mem_ostream_stream *stream) +{ + if (stream->pptr >= stream->eptr) + mem_grow(stream,0); + + if (stream->errflg) + return EOF; + + *stream->pptr = c; + ++stream->pptr; + + return c & 0xff; +} + +static size_t mem_write (void *ptr, size_t size, size_t nmemb, hpgs_mem_ostream_stream *stream) +{ + if (stream->pptr + size*nmemb > stream->eptr) + mem_grow(stream,size*nmemb); + + if (stream->errflg) + return 0; + + memcpy(stream->pptr,ptr,size*nmemb); + stream->pptr += size*nmemb; + + return nmemb; +} + +static int mem_vprintf (hpgs_mem_ostream_stream *stream, const char *fmt, va_list ap) +{ + int n; + size_t size; + + while (1) + { + if (stream->errflg) + return EOF; + + size = stream->eptr - stream->pptr; + /* Try to print in the allocated space. */ + va_list aq; + va_copy(aq, ap); +#ifdef WIN32 + n = _vsnprintf (stream->pptr, size, fmt, aq); +#else + n = vsnprintf ((char*)stream->pptr, size, fmt, aq); +#endif + va_end(aq); + /* If that worked, return the string. */ + if (n > -1 && n < size) + { + stream->pptr += n; + return n; + } + + /* Else try again with more space. */ + mem_grow(stream,0); + } + + return 0; +} + +static int mem_close (hpgs_mem_ostream_stream *stream) +{ + if (stream->data) free(stream->data); + free(stream); + return 0; +} + +static int mem_iserror (hpgs_mem_ostream_stream *stream) +{ + return stream->errflg; +} + +static hpgs_istream *mem_getbuf (hpgs_mem_ostream_stream *stream) +{ + if (stream->errflg || !stream->data) + return 0; + + return hpgs_new_mem_istream (stream->data,stream->pptr-stream->data,HPGS_FALSE); +} + +static int mem_tell (hpgs_mem_ostream_stream *stream, int layer, size_t *pos) +{ + if (layer || stream->errflg) return -1; + + *pos = stream->pptr-stream->data; + return 0; +} + +static int mem_seek (hpgs_mem_ostream_stream *stream, size_t pos) +{ + if (stream->errflg) return -1; + + if (stream->data + pos > stream->pptr) + { + stream->errflg = 1; + return -1; + } + + stream->pptr = stream->data + pos; + return 0; +} + +static hpgs_ostream_vtable mem_vtable = + { + (hpgs_ostream_putc_func_t) mem_putc, + (hpgs_ostream_write_func_t) mem_write, + (hpgs_ostream_vprintf_func_t) mem_vprintf, + (hpgs_ostream_flush_func_t) 0, + (hpgs_ostream_close_func_t) mem_close, + (hpgs_ostream_iserror_func_t) mem_iserror, + (hpgs_ostream_getbuf_func_t) mem_getbuf, + (hpgs_ostream_tell_func_t) mem_tell, + (hpgs_ostream_seek_func_t) mem_seek + }; + +/*! Returns a new \c hpgs_ostream created on the heap, + which operates on a malloced chunk of memory with + the preallocated given size. + + The memory buffer is realloced when the data grows over the + given preallocated size. + + Returns a null pointer, when the system is out of memory. + */ +hpgs_ostream *hpgs_new_mem_ostream (size_t data_reserve) +{ + hpgs_mem_ostream_stream *stream; + hpgs_ostream *ret = (hpgs_ostream *)malloc(sizeof(hpgs_ostream)); + + if (!ret) + return 0; + + stream = + (hpgs_mem_ostream_stream *)malloc(sizeof(hpgs_mem_ostream_stream)); + + if (!stream) + { + free (ret); + return 0; + } + + stream->data = (unsigned char *)malloc(data_reserve); + stream->pptr = stream->data; + stream->eptr = stream->data ? stream->data+data_reserve : 0; + stream->errflg = stream->data ? 0 : 1; + + ret->stream = stream; + ret->vtable = &mem_vtable; + + return ret; +} + +int hpgs_copy_streams (hpgs_ostream *out, hpgs_istream *in) +{ + unsigned char buf[16384]; + size_t sz; + + while ((sz = hpgs_istream_read(buf,1,sizeof(buf),in)) > 0) + if (hpgs_ostream_write(buf,1,sz,out) == 0) + return -1; + + return hpgs_istream_iserror(in); +} diff --git a/src/add-ons/translators/hpgs/lib/hpgspaint.c b/src/add-ons/translators/hpgs/lib/hpgspaint.c new file mode 100644 index 0000000000..16988f5420 --- /dev/null +++ b/src/add-ons/translators/hpgs/lib/hpgspaint.c @@ -0,0 +1,716 @@ +/*********************************************************************** + * * + * $Id: hpgspaint.c 375 2007-01-24 16:22:49Z softadm $ + * * + * hpgs - HPGl Script, a hpgl/2 interpreter, which uses a Postscript * + * API for rendering a scene and thus renders to a variety of * + * devices and fileformats. * + * * + * (C) 2004-2006 ev-i Informationstechnologie GmbH http://www.ev-i.at * + * * + * Author: Wolfgang Glas * + * * + * hpgs is free software; you can redistribute it and/or * + * modify it under the terms of the GNU Lesser General Public * + * License as published by the Free Software Foundation; either * + * version 2.1 of the License, or (at your option) any later version. * + * * + * hpgs is distributed in the hope that it will be useful, * + * but WITHOUT ANY WARRANTY; without even the implied warranty of * + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * + * Lesser General Public License for more details. * + * * + * You should have received a copy of the GNU Lesser General Public * + * License along with this library; if not, write to the * + * Free Software Foundation, Inc., 59 Temple Place, Suite 330, * + * Boston, MA 02111-1307 USA * + * * + *********************************************************************** + * * + * The implementation of the public API for the pixel painter. * + * * + ***********************************************************************/ + +#include +#include +#include +#include +#if defined ( __MINGW32__ ) || defined ( _MSC_VER ) +#include +#else +#include +#endif + +//#define HPGS_PAINT_DEBUG_ROP3 + +/*! \defgroup paint_device Paint device. + + This module contains the workhorse for rendering a scenery to pixel + graphics, \c hpgs_paint_device. + + Most notably, you can call \c hpgs_new_paint_device in order to + create a new paint device and perform the usual operations + \c hpgs_moveto, \c hpgs_lineto, ... on it. + + Details about the implementation are explained in the documentation + of \c hpgs_paint_device_st and \c hpgs_paint_clipper_st and the + hpyerlinks therein. +*/ + +/* static paint device methods for the hpgs_device vtable. */ +static int pdv_moveto (hpgs_device *_this, const hpgs_point *p) +{ + hpgs_paint_device *pdv = (hpgs_paint_device *)_this; + + if (hpgs_paint_path_moveto(pdv->path,p)) + return hpgs_set_error(hpgs_i18n("moveto error.")); + + return 0; +} + +static int pdv_lineto (hpgs_device *_this, const hpgs_point *p) +{ + hpgs_paint_device *pdv = (hpgs_paint_device *)_this; + + if (hpgs_paint_path_lineto(pdv->path,p)) + return hpgs_set_error(hpgs_i18n("lineto error.")); + + return 0; +} + +static int pdv_curveto (hpgs_device *_this, const hpgs_point *p1, + const hpgs_point *p2, const hpgs_point *p3 ) +{ + hpgs_paint_device *pdv = (hpgs_paint_device *)_this; + + if (hpgs_paint_path_curveto(pdv->path,p1,p2,p3)) + return hpgs_set_error(hpgs_i18n("curveto error.")); + + return 0; +} + +static int pdv_newpath (hpgs_device *_this) +{ + hpgs_paint_device *pdv = (hpgs_paint_device *)_this; + + hpgs_paint_path_truncate(pdv->path); + return 0; +} + +static int pdv_closepath (hpgs_device *_this) +{ + hpgs_paint_device *pdv = (hpgs_paint_device *)_this; + + if (hpgs_paint_path_closepath(pdv->path)) + return hpgs_set_error(hpgs_i18n("closepath error.")); + + return 0; +} + +static int pdv_stroke (hpgs_device *_this) +{ + hpgs_paint_device *pdv = (hpgs_paint_device *)_this; + int ret = 0; + + if (pdv->path->n_points > 1 || + (pdv->path->n_points == 1 && (pdv->path->points[0].flags&HPGS_POINT_DOT)) + ) + { + if (!pdv->overscan && + pdv->gstate->linewidth < 1.5 * pdv->path_clipper->yfac) + { + const hpgs_paint_clipper *clip = pdv->clippers[pdv->current_clipper]; + + if (hpgs_paint_clipper_thin_cut(pdv->path_clipper, + pdv->path,pdv->gstate)) + return hpgs_set_error(hpgs_i18n("Out of memory cutting thin line.")); + + if (hpgs_paint_clipper_emit(pdv->image, + pdv->path_clipper,clip, + &pdv->color,1,1)) + { + if (hpgs_have_error()) + return hpgs_error_ctxt(hpgs_i18n("stroke: Image error")); + + return hpgs_set_error(hpgs_i18n("stroke: Error emitting scanlines.")); + } + + hpgs_paint_clipper_clear(pdv->path_clipper); + } + else + { + hpgs_paint_path *p = hpgs_paint_path_stroke_path(pdv->path, + pdv->gstate); + + if (!p) + return hpgs_set_error(hpgs_i18n("Out of memory creating stroke path.")); + + ret = hpgs_paint_device_fill(pdv,p,HPGS_TRUE,HPGS_TRUE); + + hpgs_paint_path_destroy(p); + } + } + + hpgs_paint_path_truncate(pdv->path); + + if (ret) + return hpgs_set_error(hpgs_i18n("Error filling stroke path.")); + + return 0; +} + +static int pdv_fill (hpgs_device *_this, hpgs_bool winding) +{ + hpgs_paint_device *pdv = (hpgs_paint_device *)_this; + + int ret = hpgs_paint_device_fill(pdv,pdv->path,winding,HPGS_FALSE); + + hpgs_paint_path_truncate(pdv->path); + + return ret; +} + +static int pdv_clip (hpgs_device *_this, hpgs_bool winding) +{ + hpgs_paint_device *pdv = (hpgs_paint_device *)_this; + + int ret = hpgs_paint_device_clip(pdv,pdv->path,winding); + + hpgs_paint_path_truncate(pdv->path); + + return ret; +} + +static int pdv_clipsave (hpgs_device *_this) +{ + hpgs_paint_device *pdv = (hpgs_paint_device *)_this; + + if (pdv->clip_depth >= HPGS_PAINT_MAX_CLIP_DEPTH) + return hpgs_set_error(hpgs_i18n("Maximum clip depth of %d exceeded."), + HPGS_PAINT_MAX_CLIP_DEPTH); + + pdv->clippers[pdv->clip_depth] = 0; + + ++pdv->clip_depth; + + return 0; +} + +static int pdv_cliprestore (hpgs_device *_this) +{ + hpgs_paint_device *pdv = (hpgs_paint_device *)_this; + + --pdv->clip_depth; + + if (pdv->clippers[pdv->clip_depth]) + { + hpgs_paint_clipper_destroy(pdv->clippers[pdv->clip_depth]); + pdv->clippers[pdv->clip_depth] = 0; + } + + if (pdv->current_clipper < pdv->clip_depth) + return 0; + + while (pdv->current_clipper > 0) + { + --pdv->current_clipper; + if (pdv->clippers[pdv->current_clipper]) + return 0; + } + + return hpgs_set_error(hpgs_i18n("cliprestore: No valid clipper found.")); +} + +static int pdv_setrgbcolor (hpgs_device *_this, const hpgs_color *rgb) +{ + hpgs_paint_device *pdv = (hpgs_paint_device *)_this; + + pdv->gstate->color = *rgb; + + pdv->color.r = (unsigned char)(rgb->r*255.0); + pdv->color.g = (unsigned char)(rgb->g*255.0); + pdv->color.b = (unsigned char)(rgb->b*255.0); + + if (hpgs_image_define_color(pdv->image,&pdv->color)) + return hpgs_error_ctxt("setrgbcolor"); + + pdv->gstate->pattern_color = *rgb; + + hpgs_palette_color patcol; + + patcol.r = pdv->color.r & (~pdv->patcol.r); + patcol.g = pdv->color.g & (~pdv->patcol.g); + patcol.b = pdv->color.b & (~pdv->patcol.b); + +#ifdef HPGS_PAINT_DEBUG_ROP3 + hpgs_log("setrgbcol: patcol=%d,%d,%d.\n",patcol.r,patcol.g,patcol.b); +#endif + + return hpgs_image_setpatcol(pdv->image,&patcol); +} + +static int pdv_setdash (hpgs_device *_this, const float *segs, + unsigned n, double d) +{ + hpgs_paint_device *pdv = (hpgs_paint_device *)_this; + + if (hpgs_gstate_setdash(pdv->gstate,segs,n,d)) + return hpgs_set_error(hpgs_i18n("setdash: Out of memory.")); + + return 0; +} + +static int pdv_setlinewidth(hpgs_device *_this, double lw) +{ + hpgs_paint_device *pdv = (hpgs_paint_device *)_this; + + if (lw < pdv->thin_alpha * pdv->path_clipper->yfac) + pdv->gstate->linewidth = pdv->thin_alpha * pdv->path_clipper->yfac; + else + pdv->gstate->linewidth = lw; + return 0; +} + +static int pdv_setlinecap (hpgs_device *_this, hpgs_line_cap lc) +{ + hpgs_paint_device *pdv = (hpgs_paint_device *)_this; + + pdv->gstate->line_cap = lc; + return 0; +} + +static int pdv_setlinejoin (hpgs_device *_this, hpgs_line_join lj) +{ + hpgs_paint_device *pdv = (hpgs_paint_device *)_this; + + pdv->gstate->line_join = lj; + return 0; +} + +static int pdv_setmiterlimit (hpgs_device *_this, double l) +{ + hpgs_paint_device *pdv = (hpgs_paint_device *)_this; + + pdv->gstate->miterlimit = l; + return 0; +} + +static int pdv_setrop3 (hpgs_device *_this, int rop, + hpgs_bool src_transparency, hpgs_bool pattern_transparency) +{ + hpgs_paint_device *pdv = (hpgs_paint_device *)_this; + hpgs_rop3_func_t rop3; + +#ifdef HPGS_PAINT_DEBUG_ROP3 + hpgs_log("setrop3: rop,src_trans,pat_trans=%d,%d,%d.\n", + rop,src_transparency,pattern_transparency); +#endif + pdv->gstate->rop3 = rop; + pdv->gstate->src_transparency = src_transparency; + pdv->gstate->pattern_transparency = pattern_transparency; + + rop3 = hpgs_rop3_func(rop,src_transparency,pattern_transparency); + + if (!rop3) + return hpgs_set_error(hpgs_i18n("setrop3: Invalid ROP3 %d specified"),rop); + + return hpgs_image_setrop3(pdv->image,rop3); +} + +static int pdv_setpatcol(hpgs_device *_this, const hpgs_color *rgb) +{ + hpgs_paint_device *pdv = (hpgs_paint_device *)_this; + + pdv->gstate->pattern_color = *rgb; + + pdv->patcol.r = (unsigned char)(rgb->r * 255.0); + pdv->patcol.g = (unsigned char)(rgb->g * 255.0); + pdv->patcol.b = (unsigned char)(rgb->b * 255.0); + + hpgs_palette_color patcol; + + patcol.r = pdv->color.r & (~pdv->patcol.r); + patcol.g = pdv->color.g & (~pdv->patcol.g); + patcol.b = pdv->color.b & (~pdv->patcol.b); + +#ifdef HPGS_PAINT_DEBUG_ROP3 + hpgs_log("setpatcol: patcol=%d,%d,%d.\n",patcol.r,patcol.g,patcol.b); +#endif + + return hpgs_image_setpatcol(pdv->image,&patcol); +} + +static int pdv_drawimage(hpgs_device *_this, + const hpgs_image *img, + const hpgs_point *ll, const hpgs_point *lr, + const hpgs_point *ur) +{ + hpgs_paint_device *pdv = (hpgs_paint_device *)_this; + + if (!img) + return hpgs_set_error(hpgs_i18n("drawimage: Null image specified.")); + + hpgs_palette_color patcol; + patcol.r = 0; + patcol.g = 0; + patcol.b = 0; + + if (hpgs_image_setpatcol(pdv->image,&patcol)) + return -1; + + if (hpgs_paint_device_drawimage(pdv,img,ll,lr,ur)) + { + if (hpgs_have_error()) + return hpgs_error_ctxt(hpgs_i18n("drawimage error")); + + return hpgs_set_error(hpgs_i18n("drawimage error.")); + } + + patcol.r = pdv->color.r & (~pdv->patcol.r); + patcol.g = pdv->color.g & (~pdv->patcol.g); + patcol.b = pdv->color.b & (~pdv->patcol.b); + +#ifdef HPGS_PAINT_DEBUG_ROP3 + hpgs_log("setpatcol: patcol=%d,%d,%d.\n",patcol.r,patcol.g,patcol.b); +#endif + + return hpgs_image_setpatcol(pdv->image,&patcol); +} + +static int pdv_showpage (hpgs_device *_this, int i) +{ + hpgs_paint_device *pdv = (hpgs_paint_device *)_this; + + int ret = 0; + + if (i>0 && pdv->filename) + { + int l = strlen(pdv->filename); + char *fn = hpgs_alloca(l+20); + char * dot = strrchr(pdv->filename,'.'); + int pos = dot ? dot-pdv->filename : l; + +#ifdef WIN32 + _snprintf(fn,l+20,"%.*s%4.4d%s", + pos,pdv->filename,i,pdv->filename+pos); +#else + snprintf(fn,l+20,"%.*s%4.4d%s", + pos,pdv->filename,i,pdv->filename+pos); +#endif + ret = hpgs_image_write(pdv->image,fn); + + if (ret == 0) + ret = hpgs_image_clear(pdv->image); + } + else if (pdv->filename == 0 || strlen(pdv->filename) > 0) + ret = hpgs_image_write(pdv->image,pdv->filename); + + return ret; +} + +static int pdv_setplotsize (hpgs_device *_this, const hpgs_bbox *bb) +{ + hpgs_paint_device *pdv = (hpgs_paint_device *)_this; + int i; + + if (hpgs_bbox_isequal(&pdv->page_bb,bb)) + return 0; + + int w = (int)ceil((bb->urx-bb->llx)*pdv->xres); + int h = (int)ceil((bb->ury-bb->lly)*pdv->yres); + + if (w<2 || h<2) + return hpgs_set_error(hpgs_i18n("setplotsize: The given bounding box result in a null image.")); + + if (hpgs_image_resize(pdv->image,w,h)) + return hpgs_error_ctxt(hpgs_i18n("setplotsize: error resizing image")); + + + if (pdv->path_clipper) hpgs_paint_clipper_destroy(pdv->path_clipper); + + pdv->path_clipper = hpgs_new_paint_clipper(bb, + pdv->image->height, + 16,pdv->overscan); + if (!pdv->path_clipper) + return hpgs_set_error(hpgs_i18n("setplotsize: Out of memory allocating path clipper.")); + + for (i=0;iclip_depth;++i) + { + if (pdv->clippers[i]) hpgs_paint_clipper_destroy(pdv->clippers[i]); + pdv->clippers[i]=0; + } + + // Initial dimension of clip segments is 4. + pdv->clippers[0] = hpgs_new_paint_clipper(bb, + pdv->image->height,4,pdv->overscan); + + if (!pdv->clippers[0]) + return hpgs_set_error(hpgs_i18n("setplotsize: Out of memory allocating clip clipper.")); + + if (hpgs_paint_clipper_reset(pdv->clippers[0],bb->llx,bb->urx)) + return hpgs_set_error(hpgs_i18n("setplotsize: Out of memory initializing clip clipper.")); + + pdv->clip_depth = 1; + pdv->current_clipper = 0; + + return 0; +} + +static int pdv_capabilities (hpgs_device *_this) +{ + hpgs_paint_device *pdv = (hpgs_paint_device *)_this; + + int ret = + HPGS_DEVICE_CAP_RASTER | + HPGS_DEVICE_CAP_MULTIPAGE | + HPGS_DEVICE_CAP_MULTISIZE | + HPGS_DEVICE_CAP_DRAWIMAGE; + + if (pdv->overscan) + ret |= HPGS_DEVICE_CAP_ANTIALIAS; + + if (pdv->image->vtable->setrop3) + ret |= HPGS_DEVICE_CAP_ROP3; + + return ret; +} + +static void pdv_destroy (hpgs_device *_this) +{ + hpgs_paint_device *pdv = (hpgs_paint_device *)_this; + int i; + + if (pdv->filename) free(pdv->filename); + if (pdv->path) hpgs_paint_path_destroy(pdv->path); + if (pdv->path_clipper) hpgs_paint_clipper_destroy(pdv->path_clipper); + if (pdv->gstate) hpgs_gstate_destroy(pdv->gstate); + if (pdv->image) hpgs_image_destroy(pdv->image); + + for (i=0;iclip_depth;++i) + if (pdv->clippers[i]) hpgs_paint_clipper_destroy(pdv->clippers[i]); +} + +static hpgs_device_vtable pdv_vtable = + { + "hpgs_paint_device", + pdv_moveto, + pdv_lineto, + pdv_curveto, + pdv_newpath, + pdv_closepath, + pdv_stroke, + pdv_fill, + pdv_clip, + pdv_clipsave, + pdv_cliprestore, + pdv_setrgbcolor, + pdv_setdash, + pdv_setlinewidth, + pdv_setlinecap, + pdv_setlinejoin, + pdv_setmiterlimit, + pdv_setrop3, + pdv_setpatcol, + pdv_drawimage, + pdv_setplotsize, + 0 /* pdv_getplotsize */, + pdv_showpage, + 0 /* pdv_finish */, + pdv_capabilities, + pdv_destroy + }; + +/*! Creates a new paint device on the heap. + Use \c hpgs_destroy in order to destroy the returned + device pointer. + + The bounding box, which is mapped onto the given \c image is passed + in as well as the \c antialiasing switch. + + A null pointer is returned, if the system is out of memory. +*/ +hpgs_paint_device *hpgs_new_paint_device(hpgs_image *image, + const char *filename, + const hpgs_bbox *bb, + hpgs_bool antialias ) +{ + hpgs_paint_device *ret=(hpgs_paint_device *)malloc(sizeof(hpgs_paint_device)); + + if (ret) + { + ret->image = image; + + ret->path = 0; + ret->gstate = 0; + ret->overscan = antialias; + ret->thin_alpha = 0.25; + + if (filename) + { + ret->filename = strdup(filename); + + if (!ret->filename) goto fatal_error; + } + else + ret->filename = 0; + + memset(ret->clippers, + 0,HPGS_PAINT_MAX_CLIP_DEPTH * sizeof(hpgs_paint_clipper *)); + + ret->path = hpgs_new_paint_path(); + if (!ret->path) goto fatal_error; + + ret->path_clipper = hpgs_new_paint_clipper(bb, + image->height, + 16,ret->overscan); + if (!ret->path_clipper) goto fatal_error; + + ret->gstate = hpgs_new_gstate(); + if (!ret->gstate) goto fatal_error; + + // Initial dimesion of clip segments is 4. + ret->clippers[0] = hpgs_new_paint_clipper(bb, + image->height,4,ret->overscan); + if (!ret->clippers[0]) goto fatal_error; + if (hpgs_paint_clipper_reset(ret->clippers[0],bb->llx,bb->urx)) + goto fatal_error; + + ret->clip_depth = 1; + ret->current_clipper = 0; + + ret->page_bb = *bb; + ret->xres = image->width/(bb->urx-bb->llx); + ret->yres = image->height/(bb->ury-bb->lly); + + if (hpgs_image_set_resolution(image,72.0*ret->xres,72.0*ret->yres)) + goto fatal_error; + + ret->image_interpolation = 0; + + ret->color.r = 0; + ret->color.g = 0; + ret->color.b = 0; + ret->color.index = 0; + + ret->patcol.r = 0; + ret->patcol.g = 0; + ret->patcol.b = 0; + + ret->inherited.vtable = &pdv_vtable; + } + + return ret; + + fatal_error: + if (ret->filename) free(ret->filename); + if (ret->path) hpgs_paint_path_destroy(ret->path); + if (ret->clippers[0]) hpgs_paint_clipper_destroy(ret->clippers[0]); + if (ret->gstate) hpgs_gstate_destroy(ret->gstate); + if (ret->image) hpgs_image_destroy(ret->image); + free(ret); + return 0; +} + +/*! Sets the image interpolation value of the given paint device. + Currently, the following values are supported: + + \li 0 no image iterpolation + \li 1 linear image interpolation. + + Other values specifiying square or cubic interpolation may be + supported in the future. The default value is 0. +*/ +void hpgs_paint_device_set_image_interpolation (hpgs_paint_device *pdv, int i) +{ + pdv->image_interpolation = i; +} + +/*! Sets the minimal alpha value for thin lines, when antialiasing is + in effect. The supplied value must be grater than or equal to 0.01 and + lesser than or equal to 10.0. Other values are ignored. +*/ +void hpgs_paint_device_set_thin_alpha (hpgs_paint_device *pdv, double a) +{ + if (a > 0.01 && a <= 10.0) + pdv->thin_alpha = a; +} + +/*! Fills the intersection of the given path with the current clip + path of the paint device \c pdv using the current graphics state of \c pdv. + + if \c winding is \c HPGS_TRUE, the non-zero winding rule is used for filling, + otherwise the exclusive-or rule applies. + + Return values: + + \li 0 Sucess. + \li -1 An error ocurred. + Call \c hpgs_device_get_error in order to retrieve the error message. + +*/ +int hpgs_paint_device_fill(hpgs_paint_device *pdv, + hpgs_paint_path *path, + hpgs_bool winding, + hpgs_bool stroke ) +{ + const hpgs_paint_clipper *clip = pdv->clippers[pdv->current_clipper]; + + if (hpgs_paint_clipper_cut(pdv->path_clipper,path)) + return hpgs_set_error(hpgs_i18n("fill: Error cutting current path.")); + + if (hpgs_paint_clipper_emit(pdv->image, + pdv->path_clipper,clip, + &pdv->color,winding,stroke)) + { + if (hpgs_have_error()) + return hpgs_error_ctxt(hpgs_i18n("fill: Image error")); + + return hpgs_set_error(hpgs_i18n("fill: Error emitting scanlines.")); + } + + + hpgs_paint_clipper_clear(pdv->path_clipper); + + return 0; +} + +/*! Sets the intersection of the given path with the current clip + path of the paint device \c pdv as the current clip path of \c pdv. + + if \c winding is \c HPGS_TRUE, the non-zero winding rule is used for the + path intersection, otherwise the exclusive-or rule applies. + + Return values: + + \li 0 Sucess. + \li -1 An error ocurred. + Call \c hpgs_device_get_error in order to retrieve the error message. + +*/ +int hpgs_paint_device_clip(hpgs_paint_device *pdv, + hpgs_paint_path *path, + hpgs_bool winding) +{ + const hpgs_paint_clipper *clip = pdv->clippers[pdv->current_clipper]; + + if (hpgs_paint_clipper_cut(pdv->path_clipper,path)) + return hpgs_set_error(hpgs_i18n("clip: Error cutting current path.")); + + hpgs_paint_clipper *nclip = + hpgs_paint_clipper_clip(pdv->path_clipper,clip,winding); + + if (!nclip) + return hpgs_set_error(hpgs_i18n("clip: Out of memory creating new clipper.")); + + // push the new clipper onto the stack of clippers. + pdv->current_clipper = pdv->clip_depth-1; + + if (pdv->clippers[pdv->current_clipper]) + hpgs_paint_clipper_destroy(pdv->clippers[pdv->current_clipper]); + + pdv->clippers[pdv->current_clipper] = nclip; + + hpgs_paint_clipper_clear(pdv->path_clipper); + + return 0; +} diff --git a/src/add-ons/translators/hpgs/lib/hpgspaint.h b/src/add-ons/translators/hpgs/lib/hpgspaint.h new file mode 100644 index 0000000000..33bdc57e21 --- /dev/null +++ b/src/add-ons/translators/hpgs/lib/hpgspaint.h @@ -0,0 +1,287 @@ +/*********************************************************************** + * * + * $Id: hpgspaint.h 270 2006-01-29 21:12:23Z softadm $ + * * + * hpgs - HPGl Script, a hpgl/2 interpreter, which uses a Postscript * + * API for rendering a scene and thus renders to a variety of * + * devices and fileformats. * + * * + * (C) 2004-2006 ev-i Informationstechnologie GmbH http://www.ev-i.at * + * * + * Author: Wolfgang Glas * + * * + * hpgs is free software; you can redistribute it and/or * + * modify it under the terms of the GNU Lesser General Public * + * License as published by the Free Software Foundation; either * + * version 2.1 of the License, or (at your option) any later version. * + * * + * hpgs is distributed in the hope that it will be useful, * + * but WITHOUT ANY WARRANTY; without even the implied warranty of * + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * + * Lesser General Public License for more details. * + * * + * You should have received a copy of the GNU Lesser General Public * + * License along with this library; if not, write to the * + * Free Software Foundation, Inc., 59 Temple Place, Suite 330, * + * Boston, MA 02111-1307 USA * + * * + *********************************************************************** + * * + * The declarations for the pixel painter. * + * * + ***********************************************************************/ + +#ifndef __HPGS_PAINT_H +#define __HPGS_PAINT_H + +#include + +#ifdef __cplusplus +extern "C" { +#endif + +/*! \file hpgspaint.h + + \brief Internals of the pixel renderer. + + A header file, which declares the structures and functions internally + used by \c hpgs_paint_device. +*/ + +typedef struct hpgs_scanline_point_st hpgs_scanline_point; +typedef struct hpgs_paint_scanline_st hpgs_paint_scanline; +typedef struct hpgs_paint_clipper_st hpgs_paint_clipper; + +/*! @addtogroup paint_device + * @{ + */ + +#define HPGS_PAINT_MAX_CLIP_DEPTH 16 + +/*! \brief The pixel rendering vector graphics device. + + This structure has a public alias \c hpgs_paint_device and + represents a \c hpgs_device which draws to a given \c hpgs_image. + It is capable of drawing polgonal data with optional antialiasing. + Image may be drawn using a linear interpolation of the pixel values + or uninterpolated. + + The following figure outlines the coordinate setup of a paint device. + + \image html clipper.png + \image latex clipper.eps "Coordinate setup of hpgs_paint_device" + + Further details on antialiasing and scanline setup are described in the + documentation of \c hpgs_paint_clipper_st. + */ +struct hpgs_paint_device_st +{ + hpgs_device inherited; /*!< The base device structure. */ + + hpgs_image *image; /*!< The image to which we draw. */ + + char *filename; /*!< The image filename without an eventual extension. */ + + hpgs_bbox page_bb;/*! The bounding box in world coordinates, which is mapped onto + the image. */ + + double xres; /*!< The resolution of the image in x direction. */ + double yres; /*!< The resolution of the image in y direction. */ + + hpgs_bool overscan; + /*!< Specifies, whether we use antialiasing for rendering the image. */ + double thin_alpha; /*!< The minimal alpha value for antialiased thin lines. */ + + hpgs_paint_path *path; /*!< The current path, which is under contruction. */ + + hpgs_paint_clipper *path_clipper; /*!< The mapping of the current path onto the defined scanlines. */ + + + hpgs_paint_clipper *clippers[HPGS_PAINT_MAX_CLIP_DEPTH]; + /*!< A stack of mappings of the clip path' of onto the defined scanlines. */ + + + int current_clipper; /*!< The position of the current clip path in \c clippers. */ + int clip_depth; + /*!< The current depth of the clip stack, i.e. the number of time + \c hpgs_clip or \c hpgs_eoclip has been called. */ + + hpgs_gstate *gstate; /*!< The graphics state. */ + + hpgs_paint_color color; /*!< The current color transformed to a device color. */ + hpgs_palette_color patcol; /*!< The current pattern color transformed to a device color. */ + + int image_interpolation; /*!< A flag holding whether we do image interpolation. */ +}; + +HPGS_INTERNAL_API int hpgs_paint_device_fill(hpgs_paint_device *pdv, + hpgs_paint_path *path, + hpgs_bool winding, + hpgs_bool stroke); + +HPGS_INTERNAL_API int hpgs_paint_device_clip(hpgs_paint_device *pdv, + hpgs_paint_path *path, + hpgs_bool winding); + +HPGS_INTERNAL_API int hpgs_paint_device_drawimage(hpgs_paint_device *pdv, + const hpgs_image *img, + const hpgs_point *ll, const hpgs_point *lr, + const hpgs_point *ur); + +/*! @} */ /* end of group paint_device */ + +/*! @addtogroup path + * @{ + */ + +#define HPGS_BEZIER_NSEGS 16 + +typedef struct hpgs_bezier_length_st hpgs_bezier_length; + +/*! \brief A structure for holding intermediate values for length + calculations of a bezier spline. + + This structure has a public alias \c hpgs_bezier_length and holds + internals of a bezier spline used during length calculations. + */ + +struct hpgs_bezier_length_st +{ + double l[HPGS_BEZIER_NSEGS+1]; /*!< The length of the spline from the beginning to the parameter -0.5+i/HPGS_BEZIER_NSEGS. */ + double dl[HPGS_BEZIER_NSEGS+1]; /*!< The derivative of the length of the spline at the parameter -0.5+i/HPGS_BEZIER_NSEGS. */ +}; + +HPGS_INTERNAL_API void hpgs_bezier_length_init(hpgs_bezier_length *b, + const hpgs_paint_path *path, int i); +HPGS_INTERNAL_API double hpgs_bezier_length_param(const hpgs_bezier_length *b, double l); + +/*! @} */ /* end of group path */ + +/*! @addtogroup scanline + * @{ + */ + +/*! \brief An intersection point of a path with a scanline. + + This structure has a public alias \c hpgs_scanline_point and holds + the information of an intersection point of a path with a scanline. + */ +struct hpgs_scanline_point_st +{ + double x; + /*!< The x coordinate of the intersection point of the path with the scanline. */ + + int order; + /*!< The order of the intersection. + An \c order of 1 means an upward intersection, -1 means a downward intersection. + Horizontal intersection are stored as two distinct intersection points with the same + x coordinate. If antialiasing is used, the order represents a delta of a broken down + winding value. A order of 256 means that the scanline is intersected from the bottom + to the top of a physical image row between the previous and the actual intersection + point. if The order is smaller than 256, the physical row is not touched in its whole + extend an a corresponding alpha value less than 1 is generated. */ +}; + +/*! \brief A scanline of the pixel renderer. + + This structure has a public alias \c hpgs_paint_scanline and holds + the intersections points of a path with a scanline. + */ +struct hpgs_paint_scanline_st +{ + /*@{*/ + /*! A vector of intersection points. + */ + hpgs_scanline_point *points; + int points_malloc_size; + int n_points; + /*@}*/ +}; + +/*! \brief A collection of scanlines for mapping paths onto images. + + This structure has a public alias \c hpgs_paint_clipper and holds + intersection points of a path with a rectangular region represented + by a series of equidistantly distributed scanlines. + + The \c overscan member determines, whether we use antialiasing for + mappinng the path. The name of this structure member is historical, + because up to \c hpgs-0.8.x the antialiasing renderer effectively used + more than one scanline per physical image row in order to caclulate + alpha values. + + Nowadays a scanline always represents the middle of the + corresponding physical row of the image as sketch in the folowing figure, + which show the generated segment for non-antialiased rendering. + + \image html scanline_0.png + \image latex scanline_0.eps "scanline setup and pixel filling without antialiasing." + + If \c overscan is non-zero, the segment generator caclulates slopes of the + trapezoids, which are generated by the path segments cutting the boundaries + between two physical grid lines as sketched in the following figure. + + \image html scanline_n.png + \image latex scanline_n.eps "scanline setup and alpha generation with antialiasing." + + */ +struct hpgs_paint_clipper_st +{ + /*@{ */ + /*! The vector of scanlines in this clipper. + */ + hpgs_paint_scanline *scanlines; + int n_scanlines; + /*@} */ + + hpgs_bbox bb; /*! The bounding box of this clipper in world coordinates. */ + + /*@{ */ + /*! The mapping of scanline numbers to world coordinates. + \c iscan=(y0-y)/yfac and \c y=y0-iscan*yfac. + */ + double yfac; // height of a single scanline. + double y0; // y for scanline 0 + /*@} */ + + hpgs_bool overscan; /*!< Do we use antialiasing ?. */ + int height; /*!< Number of physical pixels of the underlying image. */ + + int iscan0; /*!< The first scanline with non-zero intersections. */ + int iscan1; /*!< The last scanline with non-zero intersections. */ +}; + +HPGS_INTERNAL_API hpgs_paint_clipper *hpgs_new_paint_clipper(const hpgs_bbox *bb, + int height, + int scanline_msize, + int overscan); + +HPGS_INTERNAL_API hpgs_paint_clipper *hpgs_paint_clipper_clip(const hpgs_paint_clipper *orig, + const hpgs_paint_clipper *clip, + hpgs_bool winding); + +HPGS_INTERNAL_API int hpgs_paint_clipper_cut(hpgs_paint_clipper *c, + hpgs_paint_path *path); + +HPGS_INTERNAL_API int hpgs_paint_clipper_thin_cut(hpgs_paint_clipper *c, + hpgs_paint_path *path, + const hpgs_gstate *gstate); + +HPGS_INTERNAL_API int hpgs_paint_clipper_emit (hpgs_image *image, + const hpgs_paint_clipper *img, + const hpgs_paint_clipper *clip, + const hpgs_paint_color *c, + hpgs_bool winding, + hpgs_bool stroke); + +HPGS_INTERNAL_API int hpgs_paint_clipper_reset(hpgs_paint_clipper *c, double llx, double urx); +HPGS_INTERNAL_API void hpgs_paint_clipper_clear(hpgs_paint_clipper *c); +HPGS_INTERNAL_API void hpgs_paint_clipper_destroy(hpgs_paint_clipper *c); + +/*! @} */ /* end of group scanline */ + +#ifdef __cplusplus +} // end of extern "C" +#endif + +#endif /* ! __HPGS_PAINT_H */ diff --git a/src/add-ons/translators/hpgs/lib/hpgspaintimage.c b/src/add-ons/translators/hpgs/lib/hpgspaintimage.c new file mode 100644 index 0000000000..b8b1163e71 --- /dev/null +++ b/src/add-ons/translators/hpgs/lib/hpgspaintimage.c @@ -0,0 +1,469 @@ +/*********************************************************************** + * * + * $Id: hpgspaintimage.c 281 2006-02-25 19:40:31Z softadm $ + * * + * hpgs - HPGl Script, a hpgl/2 interpreter, which uses a Postscript * + * API for rendering a scene and thus renders to a variety of * + * devices and fileformats. * + * * + * (C) 2004-2006 ev-i Informationstechnologie GmbH http://www.ev-i.at * + * * + * Author: Wolfgang Glas * + * * + * hpgs is free software; you can redistribute it and/or * + * modify it under the terms of the GNU Lesser General Public * + * License as published by the Free Software Foundation; either * + * version 2.1 of the License, or (at your option) any later version. * + * * + * hpgs is distributed in the hope that it will be useful, * + * but WITHOUT ANY WARRANTY; without even the implied warranty of * + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * + * Lesser General Public License for more details. * + * * + * You should have received a copy of the GNU Lesser General Public * + * License along with this library; if not, write to the * + * Free Software Foundation, Inc., 59 Temple Place, Suite 330, * + * Boston, MA 02111-1307 USA * + * * + *********************************************************************** + * * + * The implementation of the public API for the pixel painter. * + * * + ***********************************************************************/ + +#include +#include +#include +#include + +//#define HPGS_PAINT_IMAGE_DEBUG + +#ifdef HPGS_PAINT_IMAGE_DEBUG +static void log_mat_6(const char *lead, const double *mat) +{ + hpgs_log("%s%10lg,%10lg,%10lg\n%*s%10lg,%10lg,%10lg.\n", + lead,mat->dx,mat->mxx,mat->mxy, + strlen(lead)," ",mat->dy,mat->myx,mat->myy); + +} +#endif + +// multiplicates the given vector with the specified matrix. +// This is here in order to allow efficient inlining of the code. +// +static void mat_6_mul(hpgs_point *pout, const hpgs_matrix *mat, double xin, double yin) +{ + pout->x = mat->dx + mat->mxx * xin + mat->mxy * yin; + pout->y = mat->dy + mat->myx * xin + mat->myy * yin; +} + +// build matrix from destination to source pixel coordinates. +static void build_inv_matrix(hpgs_matrix *m, + const hpgs_paint_clipper *c, + const hpgs_image *dest, + const hpgs_image *src, + const hpgs_point *ll, + const hpgs_point *ul, + const hpgs_point *lr, + const hpgs_point *ur) +{ + // image to device coordinates. + hpgs_matrix a = { ul->x, ul->y, + (lr->x-ll->x)/src->width, (lr->x-ur->x)/src->height, + (lr->y-ll->y)/src->width, (lr->y-ur->y)/src->height }; + + // device to target raster coordinates. + hpgs_matrix b = {-0.5-c->bb.llx*dest->width/(c->bb.urx-c->bb.llx), c->y0/c->yfac, + dest->width/(c->bb.urx-c->bb.llx), 0.0, + 0.0, -1.0/c->yfac }; + + hpgs_matrix tmp; + + // take half a pixel into account. + a.dx += 0.5 * (a.mxx + a.mxy); + a.dy += 0.5 * (a.myx + a.myy); + + hpgs_matrix_concat(&tmp,&b,&a); +#ifdef HPGS_PAINT_IMAGE_DEBUG + log_mat_6("a = ",a); + log_mat_6("b = ",b); + log_mat_6("b*a = ",tmp); +#endif + hpgs_matrix_invert(m,&tmp); +} + +typedef int (*put_point_func_t)(hpgs_image *, const hpgs_image *, + int, int, const hpgs_point *, double); + +static int put_point_0(hpgs_image *dest, const hpgs_image *src, + int dest_i, int dest_j, const hpgs_point *src_point, + double alpha) +{ + hpgs_paint_color col; + + double a; + + int src_i = (int)rint(src_point->x); + int src_j = (int)rint(src_point->y); + + if (src_i < 0 || src_i >= src->width) return 0; + if (src_j < 0 || src_j >= src->height) return 0; + + hpgs_image_get_pixel(src,src_i,src_j,&col,&a); + + if (hpgs_image_define_color (dest,&col)) + return -1; + + return hpgs_image_rop3_pixel(dest,dest_i,dest_j,&col, + alpha*a); +} + +static int put_point_1(hpgs_image *dest, const hpgs_image *src, + int dest_i, int dest_j, const hpgs_point *src_point, + double alpha) +{ + hpgs_paint_color col; + + double aa,a=0.0; + double r=0.0,g=0.0,b=0.0; + + double w; + double sw = 0.0; + + int src_i = (int)ceil(src_point->x); + int src_j = (int)ceil(src_point->y); + + double wx = ceil(src_point->x) - src_point->x; + double wy = ceil(src_point->y) - src_point->y; + + if (src_i < 0 || src_i > src->width) return 0; + if (src_j < 0 || src_j > src->height) return 0; + + if (src_i > 0) + { + if (src_j > 0) + { + hpgs_image_get_pixel(src,src_i-1,src_j-1,&col,&aa); + w = wx+wy; + r+=w*col.r; + g+=w*col.g; + b+=w*col.b; + a += w*aa; + sw += w; + } + + if (src_j < src->height) + { + hpgs_image_get_pixel(src,src_i-1,src_j,&col,&aa); + w = 1.0-wy+wx; + r+=w*col.r; + g+=w*col.g; + b+=w*col.b; + a += w*aa; + sw += w; + } + } + + if (src_i < src->width) + { + if (src_j > 0) + { + hpgs_image_get_pixel(src,src_i,src_j-1,&col,&aa); + w = 1.0-wx+wy; + r+=w*col.r; + g+=w*col.g; + b+=w*col.b; + a += w*aa; + sw += w; + } + + if (src_j < src->height) + { + hpgs_image_get_pixel(src,src_i,src_j,&col,&aa); + w=2.0-wx-wy; + r+=w*col.r; + g+=w*col.g; + b+=w*col.b; + a += w*aa; + sw += w; + } + } + + if (!sw) return 0; + + col.r = r / sw; + col.g = g / sw; + col.b = b / sw; + + if (hpgs_image_define_color (dest,&col)) + return -1; + + return hpgs_image_rop3_pixel(dest,dest_i,dest_j,&col, + 0.25*alpha*a); +} + +/*! + + Draws the intersection of the given image with the current clip + path of the paint device \c pdv to the destination image of \c pdv. + + The arguments \c ll, \c lr and \c ur are the + lower left, lower right and upper right corner of the drawn image + in world coordinates. + + Return values: + + \li 0 Sucess. + \li -1 An error ocurred. + Call \c hpgs_device_get_error in order to retrieve the error message. + +*/ +int hpgs_paint_device_drawimage(hpgs_paint_device *pdv, + const hpgs_image *img, + const hpgs_point *ll, const hpgs_point *lr, + const hpgs_point *ur) +{ + const hpgs_paint_clipper *c = pdv->clippers[pdv->current_clipper]; + put_point_func_t put_point_func = put_point_0; + hpgs_point ul; + double ll_i,lr_i,ur_i,ul_i; + int iscan0; + int iscan1; + int iscan; + hpgs_matrix imat[6]; + + if (pdv->image_interpolation) + put_point_func = put_point_1; + + ul.x = ll->x + (ur->x - lr->x); + ul.y = ll->y + (ur->y - lr->y); + + build_inv_matrix(imat,c,pdv->image,img,ll,&ul,lr,ur); + + ll_i = (c->y0 - ll->y)/c->yfac; + lr_i = (c->y0 - lr->y)/c->yfac; + ur_i = (c->y0 - ur->y)/c->yfac; + ul_i = (c->y0 - ul.y)/c->yfac; + + iscan0 = (int)ceil(ll_i); + if (lr_i < iscan0) iscan0 = (int)ceil(lr_i); + if (ur_i < iscan0) iscan0 = (int)ceil(ur_i); + if (ul_i < iscan0) iscan0 = (int)ceil(ul_i); + + if (iscan0 < c->iscan0) iscan0 = c->iscan0; + + iscan1 = (int)floor(ll_i); + if (lr_i > iscan1) iscan1 = (int)floor(lr_i); + if (ur_i > iscan1) iscan1 = (int)floor(ur_i); + if (ul_i > iscan1) iscan1 = (int)floor(ul_i); + + if (iscan1 > c->iscan1) iscan1 = c->iscan1; + +#ifdef HPGS_PAINT_IMAGE_DEBUG + hpgs_log("ll_i,lr_i,ur_i,ul_i,iscan0,iscan1=%lg,%lg,%lg,%lg,%d,%d.\n", + ll_i,lr_i,ur_i,ul_i,iscan0,iscan1); + + print_mat_6(stderr,"imat = ",imat); +#endif + + for (iscan = iscan0; iscan <= iscan1; ++iscan) + { + double x[2]; + int ix = 0; + int io; + const hpgs_paint_scanline *scanline = c->scanlines+iscan; + + if ((iscan > ll_i && iscan < lr_i) || + (iscan < ll_i && iscan > lr_i) ) + { + x[ix] = ((ll_i - iscan)*lr->x + (iscan - lr_i)*ll->x) / (ll_i-lr_i); + ++ix; + } + + if ((iscan > lr_i && iscan < ur_i) || + (iscan < lr_i && iscan > ur_i) ) + { + x[ix] = ((lr_i - iscan)*ur->x + (iscan - ur_i)*lr->x) / (lr_i-ur_i); + ++ix; + } + if ((iscan > ur_i && iscan < ul_i) || + (iscan < ur_i && iscan > ul_i) ) + { + x[ix] = ((ur_i - iscan)*ul.x + (iscan - ul_i)*ur->x) / (ur_i-ul_i); + ++ix; + } + if ((iscan > ul_i && iscan < ll_i) || + (iscan < ul_i && iscan > ll_i) ) + { + x[ix] = ((ul_i - iscan)*ll->x + (iscan - ll_i)*ul.x) / (ul_i-ll_i); + ++ix; + } + + if (ix!=2) continue; + + if (x[0] > x[1]) + { + double tmp = x[0]; + x[0] = x[1]; + x[1] = tmp; + } + + if (pdv->overscan) + { + int out_state = 0; + io = 0; + + // go through clip segments antialiased + while (ion_points) + { + double xleft,xright,ixleft,ixright; + double ileft,iright,ii,alpha_left,alpha_right; + hpgs_point src_point; + + xleft= scanline->points[io].x; + + while (ion_points && scanline->points[io].x == xleft) + { + out_state += scanline->points[io].order; + ++io; + } + + if (io >= scanline->n_points) break; + + alpha_left = out_state/256.0; + + xright = scanline->points[io].x; + alpha_right = (out_state+scanline->points[io].order)/256.0; + + ixright = xright; + ixleft = xleft; + + if (ixleft < x[0]) ixleft = x[0]; + if (ixleft > x[1]) ixleft = x[1]; + + if (ixright < x[0]) ixright = x[0]; + if (ixright > x[1]) ixright = x[1]; + + if ((alpha_left == 0.0 && alpha_right == 0.0) || + ixleft >= ixright) continue; + + ixleft = pdv->image->width*(ixleft-c->bb.llx) / (c->bb.urx-c->bb.llx); + ixright = pdv->image->width*(ixright-c->bb.llx) / (c->bb.urx-c->bb.llx); + + ileft = ceil(ixleft); + iright = floor(ixright); + + // output left corner points with alpha + if (ileft >= 1.0) + { + double alpha = (ileft - ixleft) * + (alpha_left*(xright-0.5*(ileft+xleft))+alpha_right*(0.5*(ileft+xleft)-xleft))/(xright-xleft); + + mat_6_mul(&src_point,imat,ileft-1.0,iscan); + + if (put_point_func(pdv->image,img,ileft-1.0,iscan,&src_point,alpha)) + return -1; + +#ifdef HPGS_PAINT_IMAGE_DEBUG + hpgs_log("src: %lg,%lg, dest: %lg,%d.\n", + src_point->x,src_point->y,ileft-1.0,iscan); +#endif + } + + // output intermediate pixels. + for (ii = ileft; ii < iright; ++ii) + { + double alpha = (alpha_left*(xright-(ii+0.5))+alpha_right*((ii+0.5)-xleft))/(xright-xleft); + + mat_6_mul(&src_point,imat,ii,iscan); + if (put_point_func(pdv->image,img,ii,iscan,&src_point,alpha)) + return -1; + } + + // output right corner points with alpha + if (iright >= ileft && iright < pdv->image->width) + { + double alpha = (ixright - iright) * + (alpha_left*(xright-0.5*(iright+xright))+alpha_right*(0.5*(iright+xright)-xleft))/(xright-xleft); + + mat_6_mul(&src_point,imat,iright,iscan); + + if (put_point_func(pdv->image,img,iright,iscan,&src_point,alpha)) + return -1; + +#ifdef HPGS_PAINT_IMAGE_DEBUG + hpgs_log("src: %lg,%lg, dest: %lg,%d.\n", + src_point->x,src_point->y,iright,iscan); +#endif + } + } + } + else + { + // go through clip segments - non-antialiased + for (io = 0; io+1n_points; io+=2) + { + double xleft= scanline->points[io].x; + double xright= scanline->points[io+1].x; + double ileft,iright,ii; + hpgs_point src_point; + + if (xleft < x[0]) xleft = x[0]; + if (xleft > x[1]) xleft = x[1]; + + if (xright < x[0]) xright = x[0]; + if (xright > x[1]) xright = x[1]; + + if (xleft >= xright) continue; + + xleft = pdv->image->width*(xleft-c->bb.llx) / (c->bb.urx-c->bb.llx); + xright = pdv->image->width*(xright-c->bb.llx) / (c->bb.urx-c->bb.llx); + + ileft = ceil(xleft); + iright = floor(xright); + + // output left corner points with alpha + if (ileft >= 1.0) + { + double alpha = ileft - xleft; + + mat_6_mul(&src_point,imat,ileft-1.0,iscan); + + if (put_point_func(pdv->image,img,ileft-1.0,iscan,&src_point,alpha)) + return -1; + +#ifdef HPGS_PAINT_IMAGE_DEBUG + hpgs_log("src: %lg,%lg, dest: %lg,%d.\n", + src_point->x,src_point->y,ileft-1.0,iscan); +#endif + } + + // output intermediate pixels. + for (ii = ileft; ii < iright; ++ii) + { + mat_6_mul(&src_point,imat,ii,iscan); + if (put_point_func(pdv->image,img,ii,iscan,&src_point,1.0)) + return -1; + } + + // output right corner points with alpha + if (iright >= ileft && iright < pdv->image->width) + { + double alpha = xright - iright; + + mat_6_mul(&src_point,imat,iright,iscan); + + if (put_point_func(pdv->image,img,iright,iscan,&src_point,alpha)) + return -1; + +#ifdef HPGS_PAINT_IMAGE_DEBUG + hpgs_log("src: %lg,%lg, dest: %lg,%d.\n", + src_point->x,src_point->y,iright,iscan); +#endif + } + } + } + } + + return 0; +} diff --git a/src/add-ons/translators/hpgs/lib/hpgspaintpath.c b/src/add-ons/translators/hpgs/lib/hpgspaintpath.c new file mode 100644 index 0000000000..0cc1aefef9 --- /dev/null +++ b/src/add-ons/translators/hpgs/lib/hpgspaintpath.c @@ -0,0 +1,1310 @@ +/*********************************************************************** + * * + * $Id: hpgspaintpath.c 369 2007-01-13 22:44:32Z softadm $ + * * + * hpgs - HPGl Script, a hpgl/2 interpreter, which uses a Postscript * + * API for rendering a scene and thus renders to a variety of * + * devices and fileformats. * + * * + * (C) 2004-2006 ev-i Informationstechnologie GmbH http://www.ev-i.at * + * * + * Author: Wolfgang Glas * + * * + * hpgs is free software; you can redistribute it and/or * + * modify it under the terms of the GNU Lesser General Public * + * License as published by the Free Software Foundation; either * + * version 2.1 of the License, or (at your option) any later version. * + * * + * hpgs is distributed in the hope that it will be useful, * + * but WITHOUT ANY WARRANTY; without even the implied warranty of * + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * + * Lesser General Public License for more details. * + * * + * You should have received a copy of the GNU Lesser General Public * + * License along with this library; if not, write to the * + * Free Software Foundation, Inc., 59 Temple Place, Suite 330, * + * Boston, MA 02111-1307 USA * + * * + *********************************************************************** + * * + * The implementation of the API for paint path handling. * + * * + ***********************************************************************/ + +#include +#include +#include +#include + +// #define HPGS_STROKE_DEBUG + +/*! \defgroup path Path contruction functions. + + This module contains the documentation of the path contruction + layer of the vector renderer \c hpgs_paint_device. + + The dcomumentation of \c hpgs_paint_path_st explains the + most important parts of this module. +*/ + +/*! Returns a new, empty path created on the heap. + + Use \c hpgs_paint_path_destroy in order to destroy the returned + \c hpgs_paint_path from the heap. + + Returns a null pointer, if the system is out of memory. +*/ +hpgs_paint_path *hpgs_new_paint_path(void) +{ + hpgs_paint_path *ret = (hpgs_paint_path *)malloc(sizeof(hpgs_paint_path)); + + if (ret) + { + ret->points_malloc_size = 256; + ret->points = (hpgs_path_point *) + malloc(sizeof(hpgs_path_point)*ret->points_malloc_size); + + ret->n_points = 0; + ret->last_start = 0; + + hpgs_bbox_null(&ret->bb); + + if (!ret->points) + { + free(ret); + ret = 0; + } + } + + return ret; +} + +/*! Destroys a path from the heap. +*/ +void hpgs_paint_path_destroy(hpgs_paint_path *_this) +{ + if (_this->points) + free(_this->points); + + free(_this); +} + +/*! Resets the given path to be empty. +*/ +void hpgs_paint_path_truncate(hpgs_paint_path *_this) +{ + hpgs_bbox_null(&_this->bb); + + _this->n_points = 0; + _this->last_start = 0; +} + +/* Internal: + Pushes a point with given flags to the path \c _this. +*/ +static int push_path_point (hpgs_paint_path *_this, + const hpgs_point *p, + int flags) +{ + if (_this->n_points >= _this->points_malloc_size) + { + _this->points_malloc_size *= 2; + + _this->points = (hpgs_path_point *) + realloc(_this->points,sizeof(hpgs_path_point)*_this->points_malloc_size); + + if (!_this->points) return -1; + } + + hpgs_path_point *cp = _this->points + _this->n_points; + + cp->p = *p; + cp->flags = flags; + + hpgs_bbox_add(&_this->bb,p); + + ++_this->n_points; + + return 0; +} + +/*! Adds a new point to the path. If the path already has some points, + the current subpolygon is implicitly closed. +*/ +int hpgs_paint_path_moveto(hpgs_paint_path *_this, + const hpgs_point *p ) +{ +#ifdef HPGS_STROKE_DEBUG + hpgs_log("%lg %lg moveto\n",p->x,p->y); +#endif + + // check for current point and do an implicit path close. + if (_this->n_points > 0) + { + hpgs_path_point *cp = _this->points + (_this->n_points - 1); + + if ((cp->flags & HPGS_POINT_SUBPATH_END) == 0) + { + assert(_this->last_start < _this->n_points); + + hpgs_path_point *sp = _this->points + _this->last_start; + + if (cp->p.x == sp->p.x && cp->p.y == sp->p.y) + cp->flags |= HPGS_POINT_SUBPATH_END; + else + { + // do an implicit closepath. + cp->flags &= ~HPGS_POINT_ROLE_MASK; + cp->flags |= HPGS_POINT_FILL_LINE; + + if (push_path_point(_this,&sp->p,HPGS_POINT_SUBPATH_END)) + return -1; + } + } + else + // catch a double moveto. + if ((cp->flags & (HPGS_POINT_SUBPATH_START | HPGS_POINT_DOT)) == + HPGS_POINT_SUBPATH_START) + { + cp->p = *p; + hpgs_bbox_add(&_this->bb,p); + return 0; + } + } + + _this->last_start= _this->n_points; + + if (push_path_point(_this,p,HPGS_POINT_SUBPATH_START)) + return -1; + + return 0; +} + +/*! Adds a new point to the path and mark the last segment as line. +*/ +int hpgs_paint_path_lineto(hpgs_paint_path *_this, + const hpgs_point *p ) +{ +#ifdef HPGS_STROKE_DEBUG + hpgs_log("%lg %lg lineto\n",p->x,p->y); +#endif + + if (_this->n_points <= 0) + return -1; + + hpgs_path_point *cp = _this->points + (_this->n_points - 1); + + // zero line ignoration. + if (cp->p.x == p->x && cp->p.y == p->y) + { + if (cp->flags & HPGS_POINT_SUBPATH_START) + { + cp->flags &= ~HPGS_POINT_ROLE_MASK; + cp->flags |= HPGS_POINT_DOT; + } + return 0; + } + + cp->flags &= ~HPGS_POINT_ROLE_MASK; + cp->flags |= HPGS_POINT_LINE; + + // implicitly start a subpath. + if (cp->flags & HPGS_POINT_SUBPATH_END) + { + cp->flags |= HPGS_POINT_SUBPATH_START; + _this->last_start = _this->n_points - 1; + } + + return push_path_point(_this,p,0); +} + +/*! Adds three new points to the path and mark the last segment as bezier spline. +*/ +int hpgs_paint_path_curveto(hpgs_paint_path *_this, + const hpgs_point *p1, + const hpgs_point *p2, + const hpgs_point *p3 ) +{ +#ifdef HPGS_STROKE_DEBUG + hpgs_log("%lg %lg %lg %lg %lg %lg curveto\n", + p1->x,p1->y, + p2->x,p2->y, + p3->x,p3->y); +#endif + + if (_this->n_points <= 0) + return -1; + + hpgs_path_point *cp = _this->points + (_this->n_points - 1); + + cp->flags &= ~HPGS_POINT_ROLE_MASK; + cp->flags |= HPGS_POINT_BEZIER; + + // implicitly start a subpath. + if (cp->flags & HPGS_POINT_SUBPATH_END) + { + cp->flags |= HPGS_POINT_SUBPATH_START; + _this->last_start = _this->n_points - 1; + } + + if (push_path_point(_this,p1,HPGS_POINT_CONTROL)) return -1; + if (push_path_point(_this,p2,HPGS_POINT_CONTROL)) return -1; + + return push_path_point(_this,p3,0); +} + +/*! Closes the current subpolygon. If the current point is distinct from the + start point of the current subpolygon, a line is drawn from + the start point of the current subpolygon to the last point. +*/ +int hpgs_paint_path_closepath(hpgs_paint_path *_this) +{ + // check for current point and do an implicit path close. + if (_this->n_points <= 0) return 0; + + hpgs_path_point *cp = _this->points + (_this->n_points - 1); + + if (cp->flags & (HPGS_POINT_SUBPATH_END | HPGS_POINT_SUBPATH_START)) + return 0; + + assert(_this->last_start < _this->n_points); + + hpgs_path_point *sp = _this->points + _this->last_start; + + if (cp->p.x == sp->p.x && cp->p.y == sp->p.y) + cp->flags |= (HPGS_POINT_SUBPATH_END | HPGS_POINT_SUBPATH_CLOSE); + else + { + // do an explicit closepath. + cp->flags &= ~HPGS_POINT_ROLE_MASK; + cp->flags |= HPGS_POINT_LINE; + + if (push_path_point(_this,&sp->p, + HPGS_POINT_SUBPATH_END | HPGS_POINT_SUBPATH_CLOSE)) + return -1; + + _this->last_start=_this->n_points; + } + return 0; +} + +// caclulate tan(alpha/2) from tan(alpha) +static double half_tan (double x) +{ + return (sqrt(1.0+x*x)-1.0)/x; +} + +/*! Adds a buldged arc segment to the path. Buldge is defined to + be \c tan(alpha/4), where \c alpha is the turning angle of the arc. +*/ +int hpgs_paint_path_buldgeto(hpgs_paint_path *_this, + const hpgs_point *p, + double buldge) +{ + hpgs_point d,p1,p2; + hpgs_path_point *cp; + double x1,x2; + + if (_this->n_points <= 0) return -1; + + cp = _this->points + (_this->n_points - 1); + + // calculate sekant. + d.x = p->x - cp->p.x; + d.y = p->y - cp->p.y; + + // for large buldges (angle greater than 90 deg), + // split in to two bezier splines + if (fabs(buldge)+1.0 > M_SQRT2) + { + hpgs_point pm; + double b2 = half_tan(buldge); + + pm.x = 0.5 * (cp->p.x + p->x) + 0.5 * buldge * d.y; + pm.y = 0.5 * (cp->p.y + p->y) - 0.5 * buldge * d.x; + + if (hpgs_paint_path_buldgeto(_this,&pm,b2)) return -1; + return hpgs_paint_path_buldgeto(_this,p,b2); + } + + x1 = 1.0/3.0*(1.0-buldge*buldge); + x2 = 2.0/3.0*buldge; + + // first ctrl point. + p1.x = cp->p.x + x1 * d.x + x2 * d.y; + p1.y = cp->p.y + x1 * d.y - x2 * d.x; + + // second ctrl point. + p2.x = p->x - x1 * d.x + x2 * d.y; + p2.y = p->y - x1 * d.y - x2 * d.x; + + return hpgs_paint_path_curveto(_this,&p1,&p2,p); +} + +/* Internal: Adds a line join to the extruded path. + The next extruded point is \c e1, the tangent of + the previous and current path segment are passed. +*/ +static int join_lines(hpgs_paint_path *path, const hpgs_point *edge, + const hpgs_point *e1, + const hpgs_point *prev_tangent, + const hpgs_point *tangent, + hpgs_line_join join, + double ml) +{ + double sa = prev_tangent->x * tangent->y - prev_tangent->y * tangent->x; + double ca = prev_tangent->x * tangent->x + prev_tangent->y * tangent->y; + + // inner edge ? + if (sa < 0.0) + { + if (hpgs_paint_path_lineto(path,edge)) return -1; + return hpgs_paint_path_lineto(path,e1); + } + + switch (join) + { + case hpgs_join_round: + if (hpgs_paint_path_buldgeto(path,e1,tan(atan2(sa,ca)*0.25))) return -1; + break; + case hpgs_join_miter: + // + // This is the derivation of the miter condition used below. + // + // sin(a/2) = sqrt(0.5*(1.0+ca)) + // 1.0/sin(a/2) >= ml + // sin(a/2) <= 1.0/ml + // 0.5*(1.0+ca) <= 1.0/(ml*ml) + // (1.0+ca) <= 2.0/(ml*ml) + + // additionally, for very small angles the miter effect will not be visible + // for the kind user, so skip the miter calculation for these, too. + if ((1.0+ca) >= 2.0/(ml*ml) && sa > 0.01) + { + double det; + + // determine miter point. + // + // solve: + // + // e1->x - cp->x = t1 * prev_tangent->x - t2 * tangent->x + // e1->y - cp->y = t1 * prev_tangent->y - t2 * tangent->y + // + + det = prev_tangent->y * tangent->x - prev_tangent->x * tangent->y; + + if (det > 1.0e-8 || det < -1.0e-8) + { + hpgs_path_point *cp = path->points + (path->n_points - 1); + double t1; + double x = e1->x - cp->p.x; + double y = e1->y - cp->p.y; + hpgs_point mp; + + t1 = (tangent->x * y - tangent->y * x)/det; + // t2 = ( prev_tangent->y * x - prev_tangent->x * y)/det; + + mp.x = cp->p.x + t1 * prev_tangent->x; + mp.y = cp->p.y + t1 * prev_tangent->y; + + return hpgs_paint_path_lineto(path,&mp); + } + } + default: + /* hpgs_join_bevel */ + if (hpgs_paint_path_lineto(path,e1)) return -1; + } + return 0; +} + +/* Internal: Adds a line cap to the extruded path. + The next extruded point is \c e1. +*/ +static int cap_line(hpgs_paint_path *path, + const hpgs_point *e1, + hpgs_line_cap cap) +{ + switch (cap) + { + case hpgs_cap_round: + if (hpgs_paint_path_buldgeto(path,e1,1.0)) return -1; + break; + case hpgs_cap_square: + { + hpgs_path_point *cp = path->points + (path->n_points - 1); + hpgs_point d; + hpgs_point p; + + d.x = cp->p.x - e1->x; + d.y = cp->p.y - e1->y; + + p.x = cp->p.x + 0.5 * d.y; + p.y = cp->p.y - 0.5 * d.x; + + if (hpgs_paint_path_lineto(path,&p)) return -1; + + p.x += d.x; + p.y += d.y; + + if (hpgs_paint_path_lineto(path,&p)) return -1; + } + default: + /* hpgs_cap_butt */ + if (hpgs_paint_path_lineto(path,e1)) return -1; + } + return 0; +} + +static void normalize(hpgs_point *p) +{ + double l=hypot(p->x,p->y); + + if (l==0.0) return; + + p->x /= l; + p->y /= l; +} + +/* Internal: Extrudes a bezier segment starting at + point \c i of path \c _this by the half linewidth \c d. + + Start parameter is \c tt1, + end parameter is \c tt2. Returns the four defining points of the extruded + bezier spline and the starting/ending tangent. +*/ +static void extrude_bezier_internal (const hpgs_paint_path *_this, int i, + double tt1, double tt2, double d, + hpgs_path_point *ep, int *n_ep, + hpgs_point *tan1, + hpgs_point *tan2) +{ + double t_m = 0.5 * (tt1+tt2); + double alpha1,alpha2,det; + hpgs_point tan_m; + hpgs_point e_m; + + hpgs_bezier_path_point(_this,i,tt1,&ep[*n_ep+0].p); + + hpgs_bezier_path_tangent(_this,i,tt1,tt2 > tt1 ? 1 : -1,1.0e-8,tan1); + + if (tt2 < tt1) + { + tan1->x = -tan1->x; + tan1->y = -tan1->y; + } + + if (*n_ep && tan1->x == tan2->x && tan1->y == tan2->y) + -- *n_ep; + else + { + if (*n_ep) + ep[*n_ep-1].flags = HPGS_POINT_LINE; + ep[*n_ep+0].p.x += tan1->y * d; + ep[*n_ep+0].p.y -= tan1->x * d; + ep[*n_ep+0].flags = HPGS_POINT_BEZIER; + } + + hpgs_bezier_path_point(_this,i,tt2,&ep[*n_ep+3].p); + hpgs_bezier_path_point(_this,i,t_m,&e_m); + + hpgs_bezier_path_tangent(_this,i,tt2,tt2 > tt1 ? -1 : 1,1.0e-8,tan2); + hpgs_bezier_path_tangent(_this,i,t_m, 0,1.0e-8,&tan_m); + + if (tt2 < tt1) + { + tan2->x = -tan2->x; + tan2->y = -tan2->y; + tan_m.x = -tan_m.x; + tan_m.y = -tan_m.y; + } + + // extrude endpoints. + ep[*n_ep+3].p.x += tan2->y * d; + ep[*n_ep+3].p.y -= tan2->x * d; + ep[*n_ep+3].flags = HPGS_POINT_BEZIER; + + e_m.x += tan_m.y * d; + e_m.y -= tan_m.x * d; + + // + // solve: + // + // 8 * e_m.x = 4 * (e1->x + e2->x) + 3*(alpha1 * tan1->x + alpha2 * tan2->x) + // 8 * e_m.y = 4 * (e1->y + e2->y) + 3*(alpha1 * tan1->y + alpha2 * tan2->y) + // + + alpha1 = tt2 - tt1; + alpha2 = tt1 - tt2; + + det = tan1->x * tan2->y - tan1->y * tan2->x; + +#ifdef HPGS_STROKE_DEBUG + hpgs_log("extrude_bezier: tt1,tt2,det= %lg,%lg,%lg.\n", + tt1,tt2,det); +#endif + + if (det) + { + double x = 8.0/3.0 *e_m.x - 4.0/3.0 * (ep[*n_ep+0].p.x + ep[*n_ep+3].p.x); + double y = 8.0/3.0 *e_m.y - 4.0/3.0 * (ep[*n_ep+0].p.y + ep[*n_ep+3].p.y); + + alpha1 = (tan2->y * x - tan2->x * y)/det; + alpha2 = (tan1->x * y - tan1->y * x)/det; + } + + ep[*n_ep+1].p.x = ep[*n_ep+0].p.x + alpha1 * tan1->x; + ep[*n_ep+1].p.y = ep[*n_ep+0].p.y + alpha1 * tan1->y; + ep[*n_ep+1].flags = HPGS_POINT_CONTROL; + + ep[*n_ep+2].p.x = ep[*n_ep+3].p.x + alpha2 * tan2->x; + ep[*n_ep+2].p.y = ep[*n_ep+3].p.y + alpha2 * tan2->y; + ep[*n_ep+2].flags = HPGS_POINT_CONTROL; + + *n_ep += 4; +} + +static void extrude_bezier (const hpgs_paint_path *_this, int i, + double tt1, double tt2, double d, + hpgs_path_point *ep, int *n_ep, + hpgs_point *tan1, + hpgs_point *tan2) +{ + int nx; + double tx[2]; + + hpgs_bezier_path_singularities(_this,i, + tt1tt2 && nx > 1) + { + double tmp = tx[1]; + tx[1] = tx[0]; + tx[0] = tmp; + } + + if (nx == 0 && fabs(tt2 - tt1) > 0.4) + { + // break spline, if it runs by more than 90 degrees. + if ((_this->points[i+1].p.x - _this->points[i].p.x) * + (_this->points[i+2].p.x - _this->points[i+1].p.x) + + (_this->points[i+1].p.y- _this->points[i].p.y) * + (_this->points[i+2].p.y - _this->points[i+1].p.y) < 0.0) + ++nx; + if ((_this->points[i+2].p.x - _this->points[i+1].p.x) * + (_this->points[i+3].p.x - _this->points[i+2].p.x) + + (_this->points[i+2].p.y- _this->points[i+1].p.y) * + (_this->points[i+3].p.y - _this->points[i+2].p.y) < 0.0) + ++nx; + + switch (nx) + { + case 1: + tx[0] = 0.5 * (tt1 + tt2); + break; + case 2: + tx[0] = .61803398874989484820 * tt1 + .38196601125010515180 * tt2; + tx[1] = .38196601125010515180 * tt1 + .61803398874989484820 * tt2; + break; + default: + break; + } + } + + *n_ep = 0; + + if (nx == 0) + extrude_bezier_internal (_this,i,tt1,tt2,d,ep,n_ep,tan1,tan2); + else + { + hpgs_point tan_m; + + extrude_bezier_internal (_this,i,tt1,tx[0],d,ep,n_ep,tan1,tan2); + + if (nx > 1) + { + extrude_bezier_internal (_this,i,tx[0],tx[1],d,ep,n_ep,&tan_m,tan2); + extrude_bezier_internal (_this,i,tx[1],tt2,d,ep,n_ep,&tan_m,tan2); + } + else + extrude_bezier_internal (_this,i,tx[0],tt2,d,ep,n_ep,&tan_m,tan2); + } +} + + +/* Internal: Extrudes a line segment starting at + point \c i of path \c _this by the half linewidth \c d. + + Start parameter is \c tt1, + end parameter is \c tt2. Returns the two defining points of the extruded + line and the starting/ending tangent. +*/ +static void extrude_line (const hpgs_paint_path *_this, int i, + double tt1, double tt2, double d, + hpgs_path_point *ep, int *n_ep, + hpgs_point *tangent) +{ + if (tt2 >= tt1) + { + tangent->x = _this->points[i+1].p.x - _this->points[i].p.x; + tangent->y = _this->points[i+1].p.y - _this->points[i].p.y; + } + else + { + tangent->x = _this->points[i].p.x - _this->points[i+1].p.x; + tangent->y = _this->points[i].p.y - _this->points[i+1].p.y; + } + + normalize(tangent); + + ep[0].p.x = + (0.5-tt1) * _this->points[i].p.x + + (0.5+tt1) * _this->points[i+1].p.x + + tangent->y * d; + + ep[0].p.y = + (0.5-tt1) * _this->points[i].p.y + + (0.5+tt1) * _this->points[i+1].p.y - + tangent->x * d; + + ep[0].flags = HPGS_POINT_LINE; + + ep[1].p.x = + (0.5-tt2) * _this->points[i].p.x + + (0.5+tt2) * _this->points[i+1].p.x + + tangent->y * d; + + ep[1].p.y = + (0.5-tt2) * _this->points[i].p.y + + (0.5+tt2) * _this->points[i+1].p.y - + tangent->x * d; + + ep[1].flags = HPGS_POINT_SUBPATH_END; + + *n_ep = 2; +} + +/* Internal: + Extrude a subpath (dash segment) of \this path by the half linewidth + \c d and append the result to \c path. + + The subpath starts at the path segment starting at point \c i0 at the + curve parameter \c t0 (t=-0.5 start of segment, t=0.5 end of segment). + + The subpath ends at the path segment starting at point \c i1 at the + curve parameter \c t1. + + The extruded path is appended to \c path. The linecaps for the start + and end of the subpath are passed and the line join. + + if \c closed is non-zero, no line cap is applied and the extruded + path consists of two closed polygons, one interior and one exterior + border. +*/ +static int extrude_segment (const hpgs_paint_path *_this, + hpgs_paint_path *path, + int i0, double t0, hpgs_line_cap cap0, + int i1, double t1, hpgs_line_cap cap1, + double d, int closed, + hpgs_line_join join, double ml) +{ + int i; + + hpgs_point start_point; + hpgs_point start_tangent; + hpgs_point prev_tangent; + + // forward extrusion. + for (i=i0;i<=i1;++i) + { + double tt1 = i==i0 ? t0 : -0.5; + double tt2 = i==i1 ? t1 : 0.5; + hpgs_point tangent1; + hpgs_point tangent2; + hpgs_path_point ep[12]; + int j,n_ep; + + int role = _this->points[i].flags & HPGS_POINT_ROLE_MASK; + + switch (role) + { + case HPGS_POINT_LINE: + extrude_line(_this,i,tt1,tt2,d, + ep,&n_ep,&tangent1); + n_ep = 2; + tangent2 = tangent1; + break; + + case HPGS_POINT_BEZIER: + extrude_bezier(_this,i,tt1,tt2,d, + ep,&n_ep,&tangent1,&tangent2); + break; + + default: + continue; + } + + if (i > i0) + { + if (join_lines(path,&_this->points[i].p,&ep[0].p,&prev_tangent,&tangent1,join,ml)) + return -1; + } + else + { + start_point = ep[0].p; + start_tangent = tangent1; + if (hpgs_paint_path_moveto(path,&ep[0].p)) return -1; + } + + for (j=1;jpoints[i0].p,&start_point, + &prev_tangent,&start_tangent,join,ml)) + return -1; + + if (hpgs_paint_path_closepath(path)) + return -1; + } + + // backward extrusion. + for (i=i1;i>=i0;--i) + { + double tt1 = i==i1 ? t1 : 0.5; + double tt2 = i==i0 ? t0 : -0.5; + hpgs_point tangent1; + hpgs_point tangent2; + hpgs_path_point ep[12]; + int j,n_ep; + + int role = _this->points[i].flags & HPGS_POINT_ROLE_MASK; + + switch (role) + { + case HPGS_POINT_LINE: + extrude_line(_this,i,tt1,tt2,d, + ep,&n_ep,&tangent1); + tangent2 = tangent1; + n_ep=2; + break; + + case HPGS_POINT_BEZIER: + extrude_bezier(_this,i,tt1,tt2,d, + ep,&n_ep,&tangent1,&tangent2); + break; + + default: + continue; + } + + if (i < i1) + { + if (join_lines(path,&_this->points[i + ((role== HPGS_POINT_BEZIER) ? 3 : 1)].p,&ep[0].p,&prev_tangent,&tangent1,join,ml)) + return -1; + } + else + { + if (closed) + { + start_point = ep[0].p; + start_tangent = tangent1; + if (hpgs_paint_path_moveto(path,&ep[0].p)) return -1; + } + else + { + if (cap_line(path,&ep[0].p,cap1)) + return -1; + } + } + + for (j=1;jpoints[i0].p,&start_point, + &prev_tangent,&start_tangent,join,ml)) + return -1; + + if (hpgs_paint_path_closepath(path)) + return -1; + } + else + { + if (cap_line(path,&start_point,cap0)) + return -1; + } + + return hpgs_paint_path_closepath(path); +} + +/* Internal: + Extrude a dot of \this path by the half linewidth + \c d and append the result to \c path. + + The extruded path is appended to \c path and consists of a circle + or a square depending on the supplied line cap. +*/ +static int extrude_dot (hpgs_paint_path *path, + const hpgs_point *p, + hpgs_line_cap cap, double d) +{ + switch(cap) + { + case hpgs_cap_round: + { + hpgs_point ps = { p->x+d, p->y }; + hpgs_point p1 = { p->x, p->y+d }; + hpgs_point p2 = { p->x-d, p->y }; + hpgs_point p3 = { p->x, p->y-d }; + + if (hpgs_paint_path_moveto(path,&ps)) return -1; + + if (hpgs_paint_path_buldgeto(path,&p1,0.41421356237309504879)) return -1; + if (hpgs_paint_path_buldgeto(path,&p2,0.41421356237309504879)) return -1; + if (hpgs_paint_path_buldgeto(path,&p3,0.41421356237309504879)) return -1; + if (hpgs_paint_path_buldgeto(path,&ps,0.41421356237309504879)) return -1; + break; + } + case hpgs_cap_square: + { + hpgs_point ps = { p->x+d, p->y+d }; + hpgs_point p1 = { p->x+d, p->y-d }; + hpgs_point p2 = { p->x-d, p->y-d }; + hpgs_point p3 = { p->x-d, p->y+d }; + + if (hpgs_paint_path_moveto(path,&ps)) return -1; + if (hpgs_paint_path_lineto(path,&p1)) return -1; + if (hpgs_paint_path_lineto(path,&p2)) return -1; + if (hpgs_paint_path_lineto(path,&p3)) return -1; + if (hpgs_paint_path_closepath(path)) return -1; + break; + } + case hpgs_cap_butt: + break; + } + + return 0; +} + +/* Internal: + Extrude a path according to the passed gstate and append the + extruded parts to \c path. +*/ +static int decompose_solid (const hpgs_paint_path *_this, + hpgs_paint_path *path, + const hpgs_gstate *gstate, + + int (*segment_processor) (const hpgs_paint_path *_this, + hpgs_paint_path *path, + int i0, double t0, hpgs_line_cap cap0, + int i1, double t1, hpgs_line_cap cap1, + double d, int closed, + hpgs_line_join join, double ml), + int (*dot_processor) (hpgs_paint_path *path, + const hpgs_point *p, + hpgs_line_cap cap, double d) + ) +{ + int i0=0,i1=-1,i; + + for (i=0;i<_this->n_points;++i) + { + int role = _this->points[i].flags & HPGS_POINT_ROLE_MASK; + + if (role == HPGS_POINT_BEZIER || role == HPGS_POINT_LINE) + i1 = i; + + if (_this->points[i].flags & HPGS_POINT_SUBPATH_START) + { + if (role == HPGS_POINT_DOT) + { + if (dot_processor(path,&(_this->points[i].p),gstate->line_cap,0.5*gstate->linewidth)) + return -1; + + i1 =-1; + continue; + } + else + i0 = i1; + } + + if (i1>=0 && ((_this->points[i].flags & HPGS_POINT_SUBPATH_END) || + i == _this->n_points-1 ) ) + { + if (segment_processor(_this,path, + i0,-0.5,gstate->line_cap, + i1,0.5,gstate->line_cap, + 0.5*gstate->linewidth, + _this->points[i].flags & HPGS_POINT_SUBPATH_CLOSE, + gstate->line_join, + gstate->miterlimit)) + return -1; + i1 = -1; + } + } + return 0; +} + +/* Internal: + Extrude a dashed path according to the passed gstate and append the + extruded parts to \c path. +*/ +static int decompose_dashed (const hpgs_paint_path *_this, + hpgs_paint_path *path, + const hpgs_gstate *gstate, + + int (*segment_processor) (const hpgs_paint_path *_this, + hpgs_paint_path *path, + int i0, double t0, hpgs_line_cap cap0, + int i1, double t1, hpgs_line_cap cap1, + double d, int closed, + hpgs_line_join join, double ml), + int (*dot_processor) (hpgs_paint_path *path, + const hpgs_point *p, + hpgs_line_cap cap, double d) + ) +{ + int i0=0,i1=-1,i; + int idash = 0; + double t0=-0.5; + double t1=0.5; + + double l=gstate->dash_offset; + int out_state = 0; + double ltot = 0.0; + double next_l = 0.0; + double lseg; + + hpgs_bezier_length bl; + + for (idash=0;idashn_dashes;++idash) + ltot += gstate->dash_lengths[idash]; + + for (i=0;i<_this->n_points;++i) + { + int role = _this->points[i].flags & HPGS_POINT_ROLE_MASK; + hpgs_line_cap cap0 = hpgs_cap_butt; + int end_line = 0; + + if (role == HPGS_POINT_BEZIER || role == HPGS_POINT_LINE) + i1 = i; + + if (_this->points[i].flags & HPGS_POINT_SUBPATH_START) + { + if (role == HPGS_POINT_DOT) + { + if (dot_processor(path,&(_this->points[i].p),gstate->line_cap,0.5*gstate->linewidth)) + return -1; + + i1 = -1; + continue; + } + else + { + i0 = i1; + t0 = -0.5; + + l=fmod(gstate->dash_offset,ltot); + if (l<0.0) l+= ltot; + + next_l = 0.0; + for (idash=0;idashn_dashes;++idash) + { + next_l += gstate->dash_lengths[idash]; + if (next_l > l) + break; + } + + out_state = (idash+1) & 1; + cap0 = gstate->line_cap; + } + } + + switch (role) + { + case HPGS_POINT_LINE: + lseg = hypot(_this->points[i+1].p.x - _this->points[i].p.x, + _this->points[i+1].p.y - _this->points[i].p.y ); + + end_line = + (_this->points[i+1].flags & HPGS_POINT_SUBPATH_END) || + i >= _this->n_points-2; + + break; + case HPGS_POINT_BEZIER: + hpgs_bezier_length_init(&bl,_this,i); + + lseg = bl.l[HPGS_BEZIER_NSEGS]; + + end_line = + (_this->points[i+3].flags & HPGS_POINT_SUBPATH_END) || + i >= _this->n_points-4; + break; + + default: + lseg = 0.0; + } + + if (role == HPGS_POINT_BEZIER || role == HPGS_POINT_LINE) + { + while (l+lseg > next_l) + { + if (role == HPGS_POINT_BEZIER) + t1 = hpgs_bezier_length_param(&bl, + next_l - l); + else + t1 = (next_l - l) / lseg - 0.5; + + idash = (idash+1) % gstate->n_dashes; + next_l += gstate->dash_lengths[idash]; + + if (out_state) + { + hpgs_line_cap cap1 = hpgs_cap_butt; + + // does the current subpath end with an empty segment ? + // if yes, do a nice cap here. + if (end_line && l+lseg <= next_l) + cap1 = gstate->line_cap; + + if (segment_processor(_this,path, + i0,t0,cap0, + i1,t1,cap1, + 0.5*gstate->linewidth,0, + gstate->line_join, + gstate->miterlimit)) + return -1; + } + + i0 = i1; + t0 = t1; + cap0 = hpgs_cap_butt; + + out_state = (idash+1) & 1; + } + + l+=lseg; + } + + if (end_line && out_state && (i0line_cap, + 0.5*gstate->linewidth,0, + gstate->line_join, + gstate->miterlimit)) + return -1; + } + } + return 0; +} + +/*! + Returns a new path on the heap, which represents the extruded border + line of \c _this. The setting of \c gstate are applied accordingly. + + Use \c hpgs_paint_path_destroy in order to destroy the returned + \c hpgs_paint_path from the heap. + + Returns a null pointer, if the system is out of memory. +*/ +hpgs_paint_path *hpgs_paint_path_stroke_path(const hpgs_paint_path *_this, + const hpgs_gstate *gstate) +{ + hpgs_paint_path *path = hpgs_new_paint_path(); + + if (!path) return 0; + +#ifdef HPGS_STROKE_DEBUG + hpgs_log("************** strokepath start.\n"); +#endif + + if (gstate->n_dashes <= 0) + { + if (decompose_solid (_this,path,gstate,extrude_segment,extrude_dot)) + { hpgs_paint_path_destroy(path); path = 0; } + } + else + { + if (decompose_dashed (_this,path,gstate,extrude_segment,extrude_dot)) + { hpgs_paint_path_destroy(path); path = 0; } + } + +#ifdef HPGS_STROKE_DEBUG + hpgs_log("************** strokepath end.\n"); +#endif + + return path; +} + +/* Internal: + Append a subpath (dash segment) of _this to \c path. + + The subpath starts at the path segment starting at point \c i0 at the + curve parameter \c t0 (t=-0.5 start of segment, t=0.5 end of segment). + + The subpath ends at the path segment starting at point \c i1 at the + curve parameter \c t1. + + The extruded path is appended to \c path. The linecaps for the start + and end of the subpath are passed and the line join. + + if \c closed is non-zero, no line cap is applied and the extruded + path consists of two closed polygons, one interior and one exterior + border. +*/ +static int append_segment (const hpgs_paint_path *_this, + hpgs_paint_path *path, + int i0, double t0, hpgs_line_cap cap0, + int i1, double t1, hpgs_line_cap cap1, + double d, int closed, + hpgs_line_join join, double ml) +{ + int i; + + // get segment and push the result. + for (i=i0;i<=i1;++i) + { + double tt1 = i==i0 ? t0 : -0.5; + double tt2 = i==i1 ? t1 : 0.5; + hpgs_point ep[4]; + int n_ep; + + int role = _this->points[i].flags & HPGS_POINT_ROLE_MASK; + + switch (role) + { + case HPGS_POINT_LINE: + ep[0].x = + (0.5-tt1) * _this->points[i].p.x + + (0.5+tt1) * _this->points[i+1].p.x; + + ep[0].y = + (0.5-tt1) * _this->points[i].p.y + + (0.5+tt1) * _this->points[i+1].p.y; + + ep[1].x = + (0.5-tt2) * _this->points[i].p.x + + (0.5+tt2) * _this->points[i+1].p.x; + + ep[1].y = + (0.5-tt2) * _this->points[i].p.y + + (0.5+tt2) * _this->points[i+1].p.y; + + n_ep = 2; + break; + + case HPGS_POINT_BEZIER: + hpgs_bezier_path_point(_this,i,tt1,&ep[0]); + + hpgs_bezier_path_delta(_this,i,tt1,&ep[1]); + ep[1].x = ep[0].x + (tt2-tt1) * ep[1].x; + ep[1].y = ep[0].y + (tt2-tt1) * ep[1].y; + + hpgs_bezier_path_point(_this,i,tt2,&ep[3]); + + hpgs_bezier_path_delta(_this,i,tt2,&ep[2]); + ep[2].x = ep[3].x - (tt2-tt1) * ep[2].x; + ep[2].y = ep[3].y - (tt2-tt1) * ep[2].y; + + n_ep = 4; + break; + + default: + continue; + } + + if (i == i0) + { + if (hpgs_paint_path_moveto(path,&ep[0])) return -1; + } + + if (n_ep == 4) + { + if (hpgs_paint_path_curveto(path,&ep[1],&ep[2],&ep[3])) + return -1; + } + else + { + if (hpgs_paint_path_lineto(path,&ep[1])) return -1; + } + } + + if (closed) + return hpgs_paint_path_closepath(path); + else + return 0; +} + +static int append_dot (hpgs_paint_path *path, + const hpgs_point *p, + hpgs_line_cap cap, double d) +{ + if (hpgs_paint_path_moveto(path,p)) return -1; + if (hpgs_paint_path_lineto(path,p)) return -1; + return 0; +} + +/*! + Returns a new path on the heap, which represents a path which conists of + solid line segments which should be drawn instead of _this, if your output + device does not support dashed lines. + + Use \c hpgs_paint_path_destroy in order to destroy the returned + \c hpgs_paint_path from the heap. + + Returns a null pointer, if the system is out of memory. +*/ +hpgs_paint_path *hpgs_paint_path_decompose_dashes(const hpgs_paint_path *_this, + const hpgs_gstate *gstate) +{ + hpgs_paint_path *path = hpgs_new_paint_path(); + + if (!path) return 0; + + if (gstate->n_dashes <= 0) + { + if (decompose_solid (_this,path,gstate,append_segment,append_dot)) + { hpgs_paint_path_destroy(path); path = 0; } + } + else + { + if (decompose_dashed (_this,path,gstate,append_segment,append_dot)) + { hpgs_paint_path_destroy(path); path = 0; } + } + + return path; +} + diff --git a/src/add-ons/translators/hpgs/lib/hpgspath.c b/src/add-ons/translators/hpgs/lib/hpgspath.c new file mode 100644 index 0000000000..33ef457647 --- /dev/null +++ b/src/add-ons/translators/hpgs/lib/hpgspath.c @@ -0,0 +1,1393 @@ +/*********************************************************************** + * * + * $Id: hpgspath.c 352 2006-10-10 20:58:26Z softadm $ + * * + * hpgs - HPGl Script, a hpgl/2 interpreter, which uses a Postscript * + * API for rendering a scene and thus renders to a variety of * + * devices and fileformats. * + * * + * (C) 2004-2006 ev-i Informationstechnologie GmbH http://www.ev-i.at * + * * + * Author: Wolfgang Glas * + * * + * hpgs is free software; you can redistribute it and/or * + * modify it under the terms of the GNU Lesser General Public * + * License as published by the Free Software Foundation; either * + * version 2.1 of the License, or (at your option) any later version. * + * * + * hpgs is distributed in the hope that it will be useful, * + * but WITHOUT ANY WARRANTY; without even the implied warranty of * + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * + * Lesser General Public License for more details. * + * * + * You should have received a copy of the GNU Lesser General Public * + * License along with this library; if not, write to the * + * Free Software Foundation, Inc., 59 Temple Place, Suite 330, * + * Boston, MA 02111-1307 USA * + * * + *********************************************************************** + * * + * The implementation of the HPGL reader. * + * * + ***********************************************************************/ + +#include +#include +#include +#include + +#ifndef M_PI +#define M_PI 3.14159265358979323846264338327950288 +#endif + +/* + Do check for an open path. +*/ + +int hpgs_reader_checkpath(hpgs_reader *reader) +{ + if (!reader->polygon_mode && reader->polygon_open >= 2) + return hpgs_reader_stroke(reader); + + return 0; +} + +static int push_poly_point(hpgs_reader *reader, hpgs_point *p, int flag) +{ + if (flag == 0 && reader->poly_buffer_size>0 && + reader->poly_buffer[reader->poly_buffer_size-1].flag == 0 && + reader->poly_buffer[reader->poly_buffer_size-1].p.x == p->x && + reader->poly_buffer[reader->poly_buffer_size-1].p.y == p->y ) + return 0; + + if (reader->poly_buffer_size >= reader->poly_buffer_alloc_size) + { + reader->poly_buffer_alloc_size *= 2; + reader->poly_buffer = (hpgs_reader_poly_point *) + realloc(reader->poly_buffer, + sizeof(hpgs_reader_poly_point)*reader->poly_buffer_alloc_size); + + if (!reader->poly_buffer) + return hpgs_set_error(hpgs_i18n("out of memory in push_poly_point.")); + } + + reader->poly_buffer[reader->poly_buffer_size].p = *p; + reader->poly_buffer[reader->poly_buffer_size].flag = flag; + ++reader->poly_buffer_size; + + return 0; +} + +static void add_path_point(hpgs_reader *reader, hpgs_point *p) +{ + if (p->x < reader->min_path_point.x) reader->min_path_point.x = p->x; + if (p->y < reader->min_path_point.y) reader->min_path_point.y = p->y; + if (p->x > reader->max_path_point.x) reader->max_path_point.x = p->x; + if (p->y > reader->max_path_point.y) reader->max_path_point.y = p->y; +} + +static int do_polygon(hpgs_reader *reader, hpgs_bool fill) +{ + int ret = 0; + + int i0 = 0; + + while (i0 < reader->poly_buffer_size) + { + // find endpoint of current loop. + int i1 = i0; + + while (i1 < reader->poly_buffer_size && reader->poly_buffer[i1].flag != 3) + ++i1; + + if (i1 > i0+1) + { + int i=i0; + int open = 0; + hpgs_point *start=0; + + // Do optimize away a polygon like (PostScript notation): + // p1 moveto p2 moveto p3 lineto p4 lineto p2 lineto closepath fill + // Such polygons are easily created if the pushed currentpoint of PM 0 + // is followed by a closed polygon. + // This optimization avoids some strange graphical effects caused by the + // line of thickness zero produced by the final closepath. + if (fill && reader->poly_buffer[i+1].flag==0 && i1 > i+2 && + fabs(reader->poly_buffer[i+1].p.x - reader->poly_buffer[i1-1].p.x) < 1.0e-8 && + fabs(reader->poly_buffer[i+1].p.y - reader->poly_buffer[i1-1].p.y) < 1.0e-8 ) + ++i; + + while (ipoly_buffer[i].flag) + { + case 0: + // Well, there are HPGL files in the wild, which write polygons with + // the pen up all the time and do a fill afterwards. + if (open && fill) + { + if (open == 1) + { + if (hpgs_moveto(reader->device,start)) + return -1; + open = 2; + } + + if (hpgs_lineto(reader->device,&reader->poly_buffer[i].p)) + return -1; + } + else + { + start = &reader->poly_buffer[i].p; + open = 1; + } + + if (i) + add_path_point(reader,&reader->poly_buffer[i].p); + else + { + reader->min_path_point = reader->poly_buffer[0].p; + reader->max_path_point = reader->poly_buffer[0].p; + } + break; + + case 1: + if (open == 0) + return hpgs_set_error(hpgs_i18n("Missing moveto in do_polygon.")); + + if (open == 1 && hpgs_moveto(reader->device,start)) + return -1; + + if (hpgs_lineto(reader->device,&reader->poly_buffer[i].p)) + return -1; + + add_path_point(reader,&reader->poly_buffer[i].p); + open = 2; + break; + case 2: + if (open == 0) + return hpgs_set_error(hpgs_i18n("Missing moveto in do_polygon.")); + + if (open == 1 && hpgs_moveto(reader->device,start)) + return -1; + + if (i+2>=reader->poly_buffer_size) + return hpgs_set_error(hpgs_i18n("curveto error in do_polygon.")); + + if (hpgs_curveto(reader->device, + &reader->poly_buffer[i].p, + &reader->poly_buffer[i+1].p, + &reader->poly_buffer[i+2].p)) + return -1; + + add_path_point(reader,&reader->poly_buffer[i].p); + add_path_point(reader,&reader->poly_buffer[i+1].p); + add_path_point(reader,&reader->poly_buffer[i+2].p); + i+=2; + open = 2; + break; + default: + return hpgs_set_error(hpgs_i18n("internal error in do_polygon.")); + } + ++i; + } + + if (open >= 2) + { + if (i < reader->poly_buffer_size && + hpgs_closepath(reader->device)) + return -1; + ret = 1; + } + } + + i0=i1+1; + + } + + return ret; +} + +/* + Basic path operations. +*/ +int hpgs_reader_moveto(hpgs_reader *reader, hpgs_point *p) +{ + reader->current_point = *p; + reader->cr_point = *p; + + if (!reader->polygon_open) + { + reader->first_path_point = reader->current_point; + reader->min_path_point = reader->current_point; + reader->max_path_point = reader->current_point; + } + + if (reader->polygon_mode) + { + if (push_poly_point(reader,&reader->current_point,0)) + return -1; + + if (reader->polygon_open == 0) + reader->polygon_open = 1; + else if (reader->polygon_open == 1) + reader->polygon_open = 2; + } + + return 0; +} + +int hpgs_reader_lineto(hpgs_reader *reader, hpgs_point *p) +{ + if (!reader->polygon_open) + { + if (reader->polygon_mode) + { + if (push_poly_point(reader,&reader->current_point,0)) + return -1; + } + else + { + if (hpgs_moveto(reader->device,&reader->current_point)) + return -1; + } + + reader->first_path_point = reader->current_point; + + reader->min_path_point = reader->current_point; + reader->max_path_point = reader->current_point; + } + + if (reader->polygon_mode) + { + if (push_poly_point(reader,p,1)) + return -1; + } + else + { + if (hpgs_lineto(reader->device,p)) + return -1; + add_path_point(reader,p); + } + + reader->polygon_open = 2; + reader->current_point = *p; + reader->cr_point = *p; + + return 0; +} + +int hpgs_reader_curveto(hpgs_reader *reader, + hpgs_point *p1, hpgs_point *p2, hpgs_point *p3) +{ + if (!reader->polygon_open) + { + if (reader->polygon_mode) + { + if (push_poly_point(reader,&reader->current_point,0)) + return -1; + } + else + { + if (hpgs_moveto(reader->device,&reader->current_point)) + return -1; + } + + reader->first_path_point = reader->current_point; + reader->min_path_point = reader->current_point; + reader->max_path_point = reader->current_point; + } + + if (reader->polygon_mode) + { + if (push_poly_point(reader,p1,2) || + push_poly_point(reader,p2,2) || + push_poly_point(reader,p3,2) ) + return -1; + } + else + { + if (hpgs_curveto(reader->device,p1,p2,p3)) + return -1; + + add_path_point(reader,p1); + add_path_point(reader,p2); + add_path_point(reader,p3); + } + + reader->polygon_open = 2; + reader->current_point = *p3; + reader->cr_point = *p3; + + return 0; +} + +int hpgs_reader_closepath(hpgs_reader *reader) +{ + if (reader->polygon_open < 2) + { + reader->polygon_open = 0; + return 0; + } + + reader->current_point = reader->first_path_point; + reader->polygon_open = 0; + + if (reader->polygon_mode) + return push_poly_point(reader,&reader->first_path_point,3); + else + return hpgs_closepath(reader->device); +} + +int hpgs_reader_stroke(hpgs_reader *reader) +{ + reader->polygon_open = 0; + reader->have_current_point = 0; + return hpgs_stroke(reader->device); +} + +static int hatch(hpgs_reader *reader, double spacing, double angle, int cross, hpgs_bool winding) +{ + int i; + double ca = cos (angle*M_PI/180.0); + double sa = sin (angle*M_PI/180.0); + hpgs_point h_min,h_max; + hpgs_point p,ph; + + if (spacing <= 1.0) + spacing= hypot(reader->P2.x-reader->P1.x, + reader->P2.y-reader->P1.y ) * 0.01 * HP_TO_PT; + + // rotate corner points to hatch coordinates and calculate min/max hatches. + p.x = reader->min_path_point.x-reader->anchor_point.x; + p.y = reader->min_path_point.y-reader->anchor_point.y; + + h_max.x = h_min.x = (p.x * ca + p.y * sa)/spacing; + h_max.y = h_min.y = (p.y * ca - p.x * sa)/spacing; + + p.x = reader->min_path_point.x-reader->anchor_point.x; + p.y = reader->max_path_point.y-reader->anchor_point.y; + + ph.x = (p.x * ca + p.y * sa)/spacing; + ph.y = (p.y * ca - p.x * sa)/spacing; + + if (ph.x < h_min.x) h_min.x = ph.x; + if (ph.y < h_min.y) h_min.y = ph.y; + if (ph.x > h_max.x) h_max.x = ph.x; + if (ph.y > h_max.y) h_max.y = ph.y; + + p.x = reader->max_path_point.x-reader->anchor_point.x; + p.y = reader->max_path_point.y-reader->anchor_point.y; + + ph.x = (p.x * ca + p.y * sa)/spacing; + ph.y = (p.y * ca - p.x * sa)/spacing; + + if (ph.x < h_min.x) h_min.x = ph.x; + if (ph.y < h_min.y) h_min.y = ph.y; + if (ph.x > h_max.x) h_max.x = ph.x; + if (ph.y > h_max.y) h_max.y = ph.y; + + p.x = reader->max_path_point.x-reader->anchor_point.x; + p.y = reader->min_path_point.y-reader->anchor_point.y; + + ph.x = (p.x * ca + p.y * sa)/spacing; + ph.y = (p.y * ca - p.x * sa)/spacing; + + if (ph.x < h_min.x) h_min.x = ph.x; + if (ph.y < h_min.y) h_min.y = ph.y; + if (ph.x > h_max.x) h_max.x = ph.x; + if (ph.y > h_max.y) h_max.y = ph.y; + + if (hpgs_clipsave(reader->device)) return -1; + + if (hpgs_clip(reader->device,winding)) return -1; + + if (hpgs_newpath(reader->device)) return -1; + + // go through verticaltal hatches hatches. + for (i = (int)ceil(h_min.y); i <= (int)floor(h_max.y); ++i) + { + ph.y = i; + ph.x = h_min.x; + + p.x = (ph.x * ca - ph.y * sa) * spacing + reader->anchor_point.x; + p.y = (ph.y * ca + ph.x * sa) * spacing + reader->anchor_point.y; + + if (hpgs_moveto(reader->device,&p)) return -1; + + ph.x = h_max.x; + + p.x = (ph.x * ca - ph.y * sa) * spacing + reader->anchor_point.x; + p.y = (ph.y * ca + ph.x * sa) * spacing + reader->anchor_point.y; + + if (hpgs_lineto(reader->device,&p)) return -1; + if (hpgs_stroke(reader->device)) return -1; + } + + if (cross) + // go through horizontal hatches hatches. + for (i = (int)ceil(h_min.x); i <= (int)floor(h_max.x); ++i) + { + ph.x = i; + ph.y = h_min.y; + + p.x = (ph.x * ca - ph.y * sa) * spacing + reader->anchor_point.x; + p.y = (ph.y * ca + ph.x * sa) * spacing + reader->anchor_point.y; + + if (hpgs_moveto(reader->device,&p)) return -1; + + ph.y = h_max.y; + + p.x = (ph.x * ca - ph.y * sa) * spacing + reader->anchor_point.x; + p.y = (ph.y * ca + ph.x * sa) * spacing + reader->anchor_point.y; + + if (hpgs_lineto(reader->device,&p)) return -1; + if (hpgs_stroke(reader->device)) return -1; + } + + if (hpgs_cliprestore(reader->device)) + return -1; + + return hpgs_newpath(reader->device); +} + +// filltype 10. +static int shade(hpgs_reader *reader, double level, hpgs_bool winding) +{ + int pen = reader->current_pen; + double alpha = level * 0.01; + + if (alpha < 0.0) alpha = 0.0; + if (alpha > 1.0) alpha = 1.0; + + if (alpha != 1.0) + { + hpgs_color rgb; + + rgb.r = (1.0-alpha) + reader->pen_colors[pen].r*alpha; + rgb.g = (1.0-alpha) + reader->pen_colors[pen].g*alpha; + rgb.b = (1.0-alpha) + reader->pen_colors[pen].b*alpha; + + if (hpgs_setrgbcolor(reader->device,&rgb)) + return -1; + } + + + if (hpgs_fill(reader->device,winding)) return -1; + + if (alpha == 1.0) return 0; + + return hpgs_setrgbcolor(reader->device, + &reader->pen_colors[pen]); +} + +int hpgs_reader_fill(hpgs_reader *reader, hpgs_bool winding) +{ + reader->polygon_open = 0; + reader->have_current_point = 0; + + switch (reader->current_ft) + { + case 3: + return hatch(reader,reader->ft3_spacing,reader->ft3_angle,0,winding); + case 4: + return hatch(reader,reader->ft4_spacing,reader->ft4_angle,1,winding); + case 10: + return shade(reader,reader->ft10_level,winding); + default: + return hpgs_fill(reader->device,winding); + } + return 0; +} + +/* + HPGL Command AC (AnChor Point) +*/ +int hpgs_reader_do_AC (hpgs_reader *reader) +{ + if (reader->eoc) + { + reader->anchor_point.x = 0.0; + reader->anchor_point.y = 0.0; + return 0; + } + else + return hpgs_reader_read_point(reader,&reader->anchor_point,1); +} + +static double sqr(double x); +__inline__ double sqr(double x) { return x*x; } + +/* + Transform an arc from the current point through p2 to p3 to + center/sweep. + + Return value: 0 ... arc successfully constructed. + 1 ... points lie on a straight line. +*/ + +static int arc_by_points(hpgs_reader *reader, + hpgs_point *p2, + hpgs_point *p3, + hpgs_point *center, + double *r, + double *sweep ) +{ + hpgs_point * p1 = &reader->current_point; + + double dx12 = p1->x-p2->x; + double dy12 = p1->y-p2->y; + double dx23 = p2->x-p3->x; + double dy23 = p2->y-p3->y; + double dx13 = p1->x-p3->x; + double dy13 = p1->y-p3->y; + + double det=dy12*dx23-dy23*dx12; + double angle1,angle2; + + // don't ask for scaling, since graphical coordinates are + // reasonably scaled in most situations. + if (fabs(det)<1.0e-8) + { + // circle detection + // end points coincide + if (hypot(dx13,dy13)<1.0e-8) + { + center->x=0.5*(p1->x+p2->x); + center->y=0.5*(p1->y+p2->y); + *sweep=360.0; + *r=0.5*hypot(dx12,dy12); + return 0; + } + + // other points coincide or points lie on a straight line + center->x=0.5*(p1->x+p3->x); + center->y=0.5*(p1->y+p3->y); + *sweep=360.0; + *r=0.5*hypot(dx13,dy13); + return 1; + } + + center->x=dy13*dy12*dy23 + +(sqr(p1->x)-sqr(p2->x))*dy23 + -(sqr(p2->x)-sqr(p3->x))*dy12; + + center->y=dx13*dx12*dx23 + +(sqr(p1->y)-sqr(p2->y))*dx23 + -(sqr(p2->y)-sqr(p3->y))*dx12; + + center->x /= -2.0 * det; + center->y /= 2.0 * det; + + *r=hypot(p1->x-center->x,p1->y-center->y); + + angle1 = atan2(p1->y-center->y,p1->x-center->x)*180.0/M_PI; + angle2 = atan2(p2->y-center->y,p2->x-center->x)*180.0/M_PI; + + // det telsl us, whether the assertion + // angle10) + { + // This is necessary, because atan2 breaks at M_PI. + if (angle2 > angle1) angle2-=360.0; + } + else + { + // This is necessary, because atan2 breaks at M_PI. + if (angle2 < angle1) angle2+=360.0; + } + + *sweep = angle2-angle1; + + return 0; +} + + +// draw bezier spline parts for an elliptical arc. +static int arc_to_bezier (hpgs_reader *reader, + hpgs_point *center, + double sweep) +{ + int nseg = (int)ceil(fabs(sweep)/90.0); + double a,seg_alpha_2,beta; + int i; + hpgs_point *p0,axis; + + if (!nseg) return 0; + + axis.x = reader->current_point.x - center->x; + axis.y = reader->current_point.y - center->y; + + seg_alpha_2 = 0.5*M_PI/180.0*sweep/nseg; + beta = 4.0/3.0 * (1.0-cos(seg_alpha_2))/sin(seg_alpha_2); + + a=0.0; + + p0 = &reader->current_point; + + for (i=1;i<=nseg;i++) + { + hpgs_point p1=*p0; + hpgs_point p2; + hpgs_point p3=*center; + + p1.x -= sin(a)*beta*axis.x; + p1.y -= sin(a)*beta*axis.y; + + p1.x -= cos(a)*beta*axis.y; + p1.y += cos(a)*beta*axis.x; + + a=M_PI/180.0 * i*sweep/nseg; + + p3.x += cos(a)*axis.x; + p3.y += cos(a)*axis.y; + + p3.x -= sin(a)*axis.y; + p3.y += sin(a)*axis.x; + + p2=p3; + + p2.x += sin(a)*beta*axis.x; + p2.y += sin(a)*beta*axis.y; + + p2.x += cos(a)*beta*axis.y; + p2.y -= cos(a)*beta*axis.x; + + if (hpgs_reader_curveto(reader,&p1,&p2,&p3)) + return -1; + + *p0=p3; + } + + return 0; +} + +/* + HPGL Command AA (Arc Absolute) +*/ +int hpgs_reader_do_AA (hpgs_reader *reader) +{ + hpgs_point center; + double sweep; + double chord=0.0; + + if (hpgs_reader_read_point(reader,¢er,1)) return -1; + if (hpgs_reader_read_double(reader,&sweep)) return -1; + if (!reader->eoc && + hpgs_reader_read_double(reader,&chord)) return -1; + + // Be careful about the direction of the rotation for + // transformation matrices with neg. determinant. + if (reader->world_matrix.mxx * reader->world_matrix.myy - + reader->world_matrix.mxy * reader->world_matrix.myx < 0.0) + sweep=-sweep; + + return arc_to_bezier(reader,¢er,sweep); +} + +/* + HPGL Command AR (Arc Relative) +*/ +int hpgs_reader_do_AR (hpgs_reader *reader) +{ + hpgs_point center; + double sweep; + double chord=0.0; + + if (hpgs_reader_read_point(reader,¢er,-1)) return -1; + if (hpgs_reader_read_double(reader,&sweep)) return -1; + if (!reader->eoc && + hpgs_reader_read_double(reader,&chord)) return -1; + + center.x += reader->current_point.x; + center.y += reader->current_point.y; + + // Be careful about the direction of the rotation for + // transformation matrices with neg. determinant. + if (reader->world_matrix.mxx * reader->world_matrix.myy - + reader->world_matrix.mxy * reader->world_matrix.myx < 0.0) + sweep=-sweep; + + return arc_to_bezier(reader,¢er,sweep); +} + +/* + HPGL Command AT (Absolute Arc Three Points) +*/ +int hpgs_reader_do_AT (hpgs_reader *reader) +{ + hpgs_point p2,p3,center; + double r,sweep,chord=0.0; + + if (hpgs_reader_read_point(reader,&p2,1)) return -1; + if (hpgs_reader_read_point(reader,&p3,1)) return -1; + if (!reader->eoc && + hpgs_reader_read_double(reader,&chord)) return -1; + + reader->polygon_open = 1; + + if (arc_by_points(reader,&p2,&p3,¢er,&r,&sweep)) + return hpgs_reader_lineto(reader,&p3); + else + return arc_to_bezier(reader,¢er,sweep); +} + +/* + HPGL Command RT (Relative arc Three points) +*/ +int hpgs_reader_do_RT (hpgs_reader *reader) +{ + hpgs_point p2,p3,center; + double r,sweep,chord=0.0; + + if (hpgs_reader_read_point(reader,&p2,-1)) return -1; + if (hpgs_reader_read_point(reader,&p3,-1)) return -1; + + p2.x += reader->current_point.x; + p2.y += reader->current_point.y; + p3.x += reader->current_point.x; + p3.y += reader->current_point.y; + + if (!reader->eoc && + hpgs_reader_read_double(reader,&chord)) return -1; + + if (arc_by_points(reader,&p2,&p3,¢er,&r,&sweep)) + return hpgs_reader_lineto(reader,&p3); + else + return arc_to_bezier(reader,¢er,sweep); +} + +/* + HPGL Command CI (CIrcle) +*/ +int hpgs_reader_do_CI (hpgs_reader *reader) +{ + double r; + double chord=0.0; + hpgs_point p0,center = reader->current_point; + + // read input point + if (hpgs_reader_read_double(reader,&r)) return -1; + if (!reader->eoc && + hpgs_reader_read_double(reader,&chord)) return -1; + + if (reader->polygon_mode) + { + if (hpgs_reader_closepath(reader)) return -1; + } + + // scale r with the sqrt down to the paper space. + r *= reader->total_scale; + + p0.x = reader->current_point.x + r; + p0.y = reader->current_point.y; + reader->pen_down = 1; + + if (hpgs_reader_moveto(reader,&p0)) + return -1; + + if (arc_to_bezier(reader,¢er,360.0)) return -1; + + if (reader->polygon_mode) + { + if (hpgs_reader_closepath(reader)) return -1; + } + + return hpgs_reader_moveto(reader,¢er); +} + +/* + HPGL Command BZ (BeZier absolute) +*/ +int hpgs_reader_do_BZ (hpgs_reader *reader) +{ + hpgs_point p1; + hpgs_point p2; + hpgs_point p3; + + while (!reader->eoc) + { + if (hpgs_reader_read_point(reader,&p1,1)) return -1; + if (hpgs_reader_read_point(reader,&p2,1)) return -1; + if (hpgs_reader_read_point(reader,&p3,1)) return -1; + + if (hpgs_reader_curveto(reader,&p1,&p2,&p3)) return -1; + } + + return 0; +} + +/* + HPGL Command BR (Bezier Relative) +*/ +int hpgs_reader_do_BR (hpgs_reader *reader) +{ + hpgs_point p1; + hpgs_point p2; + hpgs_point p3; + + while (!reader->eoc) + { + if (hpgs_reader_read_point(reader,&p1,-1)) return -1; + if (hpgs_reader_read_point(reader,&p2,-1)) return -1; + if (hpgs_reader_read_point(reader,&p3,-1)) return -1; + + p1.x += reader->current_point.x; + p1.y += reader->current_point.y; + p2.x += reader->current_point.x; + p2.y += reader->current_point.y; + p3.x += reader->current_point.x; + p3.y += reader->current_point.y; + + if (hpgs_reader_curveto(reader,&p1,&p2,&p3)) return -1; + } + + return 0; +} + +/* + HPGL Command PA (Plot Absolute) +*/ +int hpgs_reader_do_PA (hpgs_reader *reader) +{ + hpgs_point p; + + if (!reader->pen_down && + hpgs_reader_checkpath(reader)) return -1; + + while (!reader->eoc) + { + if (hpgs_reader_read_point(reader,&p,1)) return -1; + + if (reader->pen_down) + { + if (hpgs_reader_lineto(reader,&p)) return -1; + } + else + { + if (hpgs_reader_moveto(reader,&p)) return -1; + } + } + + reader->absolute_plotting = 1; + + return 0; +} + +/* + HPGL Command PD (Pen Down) +*/ +int hpgs_reader_do_PD (hpgs_reader *reader) +{ + hpgs_point p; + + while (!reader->eoc) + { + if (hpgs_reader_read_point(reader,&p, + reader->absolute_plotting ? 1 : -1)) return -1; + + if (!reader->absolute_plotting) + { + p.x += reader->current_point.x; + p.y += reader->current_point.y; + } + + if (hpgs_reader_lineto(reader,&p)) return -1; + } + + reader->pen_down = 1; + + return 0; +} + +/* + HPGL Command PR (Plot Relative) +*/ +int hpgs_reader_do_PR (hpgs_reader *reader) +{ + hpgs_point p; + + if (!reader->pen_down && + hpgs_reader_checkpath(reader)) return -1; + + while (!reader->eoc) + { + if (hpgs_reader_read_point(reader,&p,-1)) return -1; + + p.x += reader->current_point.x; + p.y += reader->current_point.y; + + if (reader->pen_down) + { + if (hpgs_reader_lineto(reader,&p)) return -1; + } + else + { + if (hpgs_reader_moveto(reader,&p)) return -1; + } + } + + reader->absolute_plotting = 0; + + return 0; +} + +/* + HPGL Command PU (Pen Up) +*/ +int hpgs_reader_do_PU (hpgs_reader *reader) +{ + hpgs_point p; + + if (hpgs_reader_checkpath(reader)) return -1; + + while (!reader->eoc) + { + if (hpgs_reader_read_point(reader,&p, + reader->absolute_plotting ? 1 : -1)) return -1; + + if (!reader->absolute_plotting) + { + p.x += reader->current_point.x; + p.y += reader->current_point.y; + } + + if (hpgs_reader_moveto(reader,&p)) return -1; + } + + reader->pen_down = 0; + + return 0; +} + +/* + HPGL Command PM (Polygon Mode) +*/ +int hpgs_reader_do_PM (hpgs_reader *reader) +{ + int mode=0; + + if (!reader->eoc && + hpgs_reader_read_int(reader,&mode)) return -1; + + switch(mode) + { + case 0: + if (hpgs_reader_checkpath(reader)) return -1; + reader->poly_buffer_size=0; + reader->polygon_mode=1; + reader->polygon_open=0; + // push the current point to the polygon buffer. + if (hpgs_reader_moveto(reader,&reader->current_point)) return -1; + break; + case 1: + if (hpgs_reader_closepath(reader)) return -1; + break; + case 2: + if (hpgs_reader_closepath(reader)) return -1; + reader->polygon_mode=0; + if (reader->poly_buffer_size > 0) + reader->current_point = reader->poly_buffer[0].p; + break; + default: + return hpgs_set_error(hpgs_i18n("PM: Illegal mode %d."),mode); + }; + + return 0; +} + +/* + HPGL Command FP (Fill Polygon) +*/ +int hpgs_reader_do_FP (hpgs_reader *reader) +{ + hpgs_bool winding = HPGS_FALSE; + + if (!reader->eoc && + hpgs_reader_read_int(reader,&winding)) return -1; + + if (hpgs_reader_checkpath(reader)) return -1; + + if (reader->poly_buffer_size <= 0) return 0; + + switch (do_polygon(reader,HPGS_TRUE)) + { + case 0: + return 0; + case 1: + return hpgs_reader_fill(reader,winding); + default: + return -1; + } +} + +/* + HPGL Command PP (Pixel Placement) +*/ +int hpgs_reader_do_PP (hpgs_reader *reader) +{ + int dummy = 0; + + if (!reader->eoc && + hpgs_reader_read_int(reader,&dummy)) return -1; + + if (reader->verbosity > 1) + hpgs_log("PP %d: unimplemented.\n",dummy); + + return 0; +} + +/* + HPGL Command FT (Fill Type) +*/ +int hpgs_reader_do_FT (hpgs_reader *reader) +{ + double option; + + if (reader->eoc) + { + reader->current_ft = 1; + return 0; + } + + if (hpgs_reader_read_int(reader,&reader->current_ft)) return -1; + + if (!reader->eoc) + { + if (hpgs_reader_read_double(reader,&option)) return -1; + + switch (reader->current_ft) + { + case 3: + // spacing is measured in current units along the x axis. + reader->ft3_spacing = option * hypot(reader->total_matrix.mxx,reader->total_matrix.myx); + break; + case 4: + // spacing is measured in current units along the x axis. + reader->ft4_spacing = option * hypot(reader->total_matrix.mxx,reader->total_matrix.myx); + break; + case 10: + reader->ft10_level = option; + } + } + + if (!reader->eoc) + { + if (hpgs_reader_read_double(reader,&option)) return -1; + + switch (reader->current_ft) + { + case 3: + reader->ft3_angle = option; + break; + case 4: + reader->ft4_angle = option; + } + } + + return 0; +} + +/* + HPGL Command EA (Edge rectangle Absolute) +*/ +int hpgs_reader_do_EA (hpgs_reader *reader) +{ + hpgs_point p,pp,cp; + + if (hpgs_reader_read_point(reader,&p,1)) return -1; + + if (hpgs_reader_checkpath(reader)) return -1; + reader->poly_buffer_size = 0; + reader->polygon_mode = 1; + + cp = reader->current_point; + + if (hpgs_reader_moveto(reader,&cp)) return -1; + + pp.x = cp.x; + pp.y = p.y; + + if (hpgs_reader_lineto(reader,&pp)) return -1; + if (hpgs_reader_lineto(reader,&p)) return -1; + + pp.x = p.x; + pp.y = cp.y; + + if (hpgs_reader_lineto(reader,&pp)) return -1; + if (hpgs_reader_closepath(reader)) return -1; + + switch (do_polygon(reader,HPGS_FALSE)) + { + case 1: + if (hpgs_reader_fill(reader,HPGS_TRUE)) + return -1; + + if (hpgs_reader_stroke(reader)) + return -1; + + case 0: + reader->polygon_mode = 0; + return 0; + + default: + return -1; + } +} + +/* + HPGL Command RA (fill Rectangle Absolute) +*/ +int hpgs_reader_do_RA (hpgs_reader *reader) +{ + hpgs_point p,pp,cp; + + if (hpgs_reader_read_point(reader,&p,1)) return -1; + + if (hpgs_reader_checkpath(reader)) return -1; + reader->poly_buffer_size = 0; + reader->polygon_mode = 1; + + cp = reader->current_point; + + if (hpgs_reader_moveto(reader,&cp)) return -1; + + pp.x = cp.x; + pp.y = p.y; + + if (hpgs_reader_lineto(reader,&pp)) return -1; + if (hpgs_reader_lineto(reader,&p)) return -1; + + pp.x = p.x; + pp.y = cp.y; + + if (hpgs_reader_lineto(reader,&pp)) return -1; + if (hpgs_reader_closepath(reader)) return -1; + + switch (do_polygon(reader,HPGS_TRUE)) + { + case 1: + if (hpgs_reader_fill(reader,1)) + return -1; + + case 0: + reader->polygon_mode = 0; + return 0; + + default: + return -1; + } +} + +/* + HPGL Command ER (Edge rectangle Relative) +*/ +int hpgs_reader_do_ER (hpgs_reader *reader) +{ + hpgs_point p,pp,cp; + + if (hpgs_reader_read_point(reader,&p,-1)) return -1; + + p.x += reader->current_point.x; + p.y += reader->current_point.y; + + if (hpgs_reader_checkpath(reader)) return -1; + reader->poly_buffer_size = 0; + reader->polygon_mode = 1; + + cp = reader->current_point; + + if (hpgs_reader_moveto(reader,&cp)) return -1; + + pp.x = cp.x; + pp.y = p.y; + + if (hpgs_reader_lineto(reader,&pp)) return -1; + if (hpgs_reader_lineto(reader,&p)) return -1; + + pp.x = p.x; + pp.y = cp.y; + + if (hpgs_reader_lineto(reader,&pp)) return -1; + if (hpgs_reader_closepath(reader)) return -1; + + switch (do_polygon(reader,HPGS_FALSE)) + { + case 1: + if (hpgs_reader_stroke(reader)) + return -1; + + case 0: + reader->polygon_mode = 0; + return 0; + + default: + return -1; + } +} + +/* + HPGL Command RR (fill Rectangle Relative) +*/ +int hpgs_reader_do_RR (hpgs_reader *reader) +{ + hpgs_point p,pp,cp; + + if (hpgs_reader_read_point(reader,&p,-1)) return -1; + + p.x += reader->current_point.x; + p.y += reader->current_point.y; + + if (hpgs_reader_checkpath(reader)) return -1; + reader->poly_buffer_size = 0; + reader->polygon_mode = 1; + + cp = reader->current_point; + + if (hpgs_reader_moveto(reader,&cp)) return -1; + + pp.x = cp.x; + pp.y = p.y; + + if (hpgs_reader_lineto(reader,&pp)) return -1; + if (hpgs_reader_lineto(reader,&p)) return -1; + + pp.x = p.x; + pp.y = cp.y; + + if (hpgs_reader_lineto(reader,&pp)) return -1; + if (hpgs_reader_closepath(reader)) return -1; + + switch (do_polygon(reader,HPGS_TRUE)) + { + case 1: + if (hpgs_reader_fill(reader,1)) + return -1; + + case 0: + reader->polygon_mode = 0; + return 0; + + default: + return -1; + } +} + +/* + HPGL Command EP (Edge Polygon) +*/ +int hpgs_reader_do_EP (hpgs_reader *reader) +{ + if (hpgs_reader_checkpath(reader)) return -1; + + if (reader->poly_buffer_size <= 0) return 0; + + switch (do_polygon(reader,HPGS_FALSE)) + { + case 1: + if (hpgs_stroke(reader->device)) + return -1; + + case 0: + return 0; + + default: + return -1; + } +} + +/* + HPGL Command EW (Edge Wedge) +*/ +int hpgs_reader_do_EW (hpgs_reader *reader) +{ + double r,start,sweep,chord; + hpgs_point p,center; + + if (hpgs_reader_read_double(reader,&r)) return -1; + if (hpgs_reader_read_double(reader,&start)) return -1; + if (hpgs_reader_read_double(reader,&sweep)) return -1; + if (!reader->eoc && + hpgs_reader_read_double(reader,&chord)) return -1; + + if (hpgs_reader_checkpath(reader)) return -1; + reader->poly_buffer_size = 0; + reader->polygon_mode = 1; + + // scale r with the sqrt down to the paper space. + r *= reader->total_scale; + + center = reader->current_point; + p=reader->current_point; + p.x+=cos(start*M_PI/180.0)*r; + p.y+=sin(start*M_PI/180.0)*r; + + if (hpgs_reader_moveto(reader,&reader->current_point)) return -1; + if (hpgs_reader_lineto(reader,&p)) return -1; + + if (arc_to_bezier(reader,¢er,sweep)) + + if (hpgs_reader_closepath(reader)) return -1; + + switch (do_polygon(reader,HPGS_FALSE)) + { + case 1: + if (hpgs_reader_stroke(reader)) + return -1; + + case 0: + reader->polygon_mode = 0; + return 0; + + default: + return -1; + } +} + +/* + HPGL Command WG (fill WedGe) +*/ +int hpgs_reader_do_WG (hpgs_reader *reader) +{ + double r,start,sweep,chord; + hpgs_point p,center; + + if (hpgs_reader_read_double(reader,&r)) return -1; + if (hpgs_reader_read_double(reader,&start)) return -1; + if (hpgs_reader_read_double(reader,&sweep)) return -1; + if (!reader->eoc && + hpgs_reader_read_double(reader,&chord)) return -1; + + if (hpgs_reader_checkpath(reader)) return -1; + reader->poly_buffer_size = 0; + reader->polygon_mode = 1; + + // scale r with the sqrt down to the paper space. + r *= reader->total_scale; + + center = reader->current_point; + p=reader->current_point; + p.x+=cos(start*M_PI/180.0)*r; + p.y+=sin(start*M_PI/180.0)*r; + + if (hpgs_reader_moveto(reader,&reader->current_point)) return -1; + if (hpgs_reader_lineto(reader,&p)) return -1; + + if (arc_to_bezier(reader,¢er,sweep)) + + if (hpgs_reader_closepath(reader)) return -1; + + switch (do_polygon(reader,HPGS_TRUE)) + { + case 1: + if (hpgs_reader_fill(reader,1)) + return -1; + + case 0: + reader->polygon_mode = 0; + return 0; + + default: + return -1; + } +} diff --git a/src/add-ons/translators/hpgs/lib/hpgspcl.c b/src/add-ons/translators/hpgs/lib/hpgspcl.c new file mode 100644 index 0000000000..1e20838dfb --- /dev/null +++ b/src/add-ons/translators/hpgs/lib/hpgspcl.c @@ -0,0 +1,1461 @@ +/*********************************************************************** + * * + * $Id: hpgspcl.c 367 2006-10-25 06:45:31Z softadm $ + * * + * hpgs - HPGl Script, a hpgl/2 interpreter, which uses a Postscript * + * API for rendering a scene and thus renders to a variety of * + * devices and fileformats. * + * * + * (C) 2004-2006 ev-i Informationstechnologie GmbH http://www.ev-i.at * + * * + * Author: Wolfgang Glas * + * * + * hpgs is free software; you can redistribute it and/or * + * modify it under the terms of the GNU Lesser General Public * + * License as published by the Free Software Foundation; either * + * version 2.1 of the License, or (at your option) any later version. * + * * + * hpgs is distributed in the hope that it will be useful, * + * but WITHOUT ANY WARRANTY; without even the implied warranty of * + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * + * Lesser General Public License for more details. * + * * + * You should have received a copy of the GNU Lesser General Public * + * License along with this library; if not, write to the * + * Free Software Foundation, Inc., 59 Temple Place, Suite 330, * + * Boston, MA 02111-1307 USA * + * * + *********************************************************************** + * * + * The implementation of the PCL interpreter. * + * * + ***********************************************************************/ + +#include +#include +#include +#include +#include +#if defined ( __MINGW32__ ) || defined ( _MSC_VER ) +#include +#else +#include +#endif + +//#define HPGS_PCL_DEBUG + +#define MK_PCL_CMD(a,b,c) ((a)<<16 | (b)<<8 | (c)) + +#define PCL_RASTER_CLEAR_FORCE 2 +#define PCL_RASTER_CLEAR_IMAGE 1 +#define PCL_RASTER_CLEAR_PARTIAL 0 + +static void pcl_clear_raster_data(hpgs_reader *reader, int mode) +{ + int i; + + switch (mode) + { + case PCL_RASTER_CLEAR_FORCE: + reader->pcl_raster_presentation = 0; + reader->pcl_raster_src_width = 0; + reader->pcl_raster_src_height = 0; + reader->pcl_raster_dest_width = 0; + reader->pcl_raster_dest_height = 0; + reader->pcl_raster_planes = 1; + + case PCL_RASTER_CLEAR_IMAGE: + reader->pcl_raster_mode = -1; + reader->pcl_raster_compression = 0; + } + + reader->pcl_raster_y_offset = 0; + reader->pcl_raster_plane = 0; + reader->pcl_raster_line = 0; + + for (i=0;i<8;++i) + if (reader->pcl_raster_data[i]) + { + free(reader->pcl_raster_data[i]); + reader->pcl_raster_data[i]=0; + } + + reader->pcl_raster_data_size = 0; + + if (reader->pcl_image) + hpgs_image_destroy(reader->pcl_image); + + reader->pcl_image=0; +} + +static hpgs_bool is_pcl_compression_supported (int compression) +{ + return + compression == 0 || + compression == 1 || + compression == 2 || + compression == 3 || + compression == 9; +} + +// uncompressed raster line. +static int pcl_ignore_raster_data(hpgs_reader *reader,int data_len) +{ + int i; + + for (i=0;ilast_byte = hpgs_getc(reader->in); + if (reader->last_byte == EOF) + return -1; + } + + return 0; +} + +// uncompressed raster line. +static int pcl_read_raster_0(hpgs_reader *reader,int data_len) +{ + unsigned char *data = reader->pcl_raster_data[reader->pcl_raster_plane]; + int i; + + for (i=0;ilast_byte = hpgs_getc(reader->in); + if (reader->last_byte == EOF) + return -1; + + if (ipcl_raster_data_size) + data[i] = reader->last_byte; + } + + if (data_len < reader->pcl_raster_data_size) + memset(data+data_len,0,reader->pcl_raster_data_size-data_len); + + return 0; +} + +// run length encoding. +static int pcl_read_raster_1(hpgs_reader *reader,int data_len) +{ + unsigned char *data = reader->pcl_raster_data[reader->pcl_raster_plane]; + int i_in=0,i=0; + + while (i_in < data_len) + { + int count; + reader->last_byte = hpgs_getc(reader->in); + if (reader->last_byte == EOF) + return -1; + + if (++i_in >= data_len) break; + count = reader->last_byte + 1; + + reader->last_byte = hpgs_getc(reader->in); + if (reader->last_byte == EOF) + return -1; + + ++i_in; + + if (i+count > reader->pcl_raster_data_size) + count = reader->pcl_raster_data_size-i; + + if (count > 0) + { + memset(data+i,reader->last_byte,count); + i+=count; + } + } + + if (i < reader->pcl_raster_data_size) + memset(data+i,0,reader->pcl_raster_data_size-i); + + return 0; +} + +// tiff v4.0. +static int pcl_read_raster_2(hpgs_reader *reader,int data_len) +{ + unsigned char *data = reader->pcl_raster_data[reader->pcl_raster_plane]; + int i_in=0,i=0; + + while (i_in < data_len) + { + int control; + reader->last_byte = hpgs_getc(reader->in); + if (reader->last_byte == EOF) + return -1; + + if (++i_in >= data_len) break; + control = reader->last_byte; + + if (control < 128) + { + while (control >= 0 && i_in < data_len) + { + reader->last_byte = hpgs_getc(reader->in); + if (reader->last_byte == EOF) + return -1; + + --control; + if (i < reader->pcl_raster_data_size) + data[i] = reader->last_byte; + ++i; + ++i_in; + } + } + else if (control > 128) + { + int count = 257 - control; + + reader->last_byte = hpgs_getc(reader->in); + if (reader->last_byte == EOF) + return -1; + + ++i_in; + + if (i+count > reader->pcl_raster_data_size) + count = reader->pcl_raster_data_size-i; + + if (count > 0) + { + memset(data+i,reader->last_byte,count); + i+=count; + } + } + } + + if (i < reader->pcl_raster_data_size) + memset(data+i,0,reader->pcl_raster_data_size-i); + + return 0; +} + +// delta row +static int pcl_read_raster_3(hpgs_reader *reader,int data_len) +{ + unsigned char *data = reader->pcl_raster_data[reader->pcl_raster_plane]; + int i_in=0,i=0; + + while (i_in < data_len) + { + int count; + int offset; + + reader->last_byte = hpgs_getc(reader->in); + if (reader->last_byte == EOF) + return -1; + + if (++i_in >= data_len) break; + count = (reader->last_byte >> 5) + 1; + offset = reader->last_byte & 0x1f; + + if (offset == 0x1f) + { + do + { + reader->last_byte = hpgs_getc(reader->in); + if (reader->last_byte == EOF) + return -1; + + ++i_in; + offset += reader->last_byte; + } + while (reader->last_byte == 0xff && i_in < data_len); + + if (i_in >= data_len) break; + } + + i += offset; + + do + { + reader->last_byte = hpgs_getc(reader->in); + if (reader->last_byte == EOF) + return -1; + + ++i_in; + + if (i < reader->pcl_raster_data_size) + data[i] = reader->last_byte; + + ++i; + --count; + } + while (count && i_in < data_len); + } + + return 0; +} + +// modified delta row - compression mode 9 +static int pcl_read_raster_9(hpgs_reader *reader,int data_len) +{ + unsigned char *data = reader->pcl_raster_data[reader->pcl_raster_plane]; + int i_in=0,i=0; + + while (i_in < data_len) + { + int count; + hpgs_bool more_count; + int offset; + hpgs_bool more_offset; + hpgs_bool comp; + + reader->last_byte = hpgs_getc(reader->in); + if (reader->last_byte == EOF) + return -1; + + if (++i_in >= data_len) break; + + comp = (reader->last_byte & 0x80) != 0; + + if (comp) + { + offset = (reader->last_byte >> 5) & 0x03; + more_offset = (offset == 0x03); + count = (reader->last_byte & 0x1f) + 1; + more_count = (count == 0x20); + } + else + { + offset = (reader->last_byte >> 3) & 0x0f; + more_offset = (offset == 0x0f); + count = (reader->last_byte & 0x07) + 1; + more_count = (count == 0x08); + } + + while (more_offset && i_in < data_len) + { + reader->last_byte = hpgs_getc(reader->in); + if (reader->last_byte == EOF) + return -1; + + offset += reader->last_byte; + more_offset = (reader->last_byte == 0xff); + + if (++i_in >= data_len) return 0; + } + + while (more_count && i_in < data_len) + { + reader->last_byte = hpgs_getc(reader->in); + if (reader->last_byte == EOF) + return -1; + + count += reader->last_byte; + more_count = (reader->last_byte == 0xff); + + if (++i_in >= data_len) return 0; + } + + i += offset; + + if (i >= reader->pcl_raster_data_size) break; + + if (comp) + { + // run-length encoded replacement. + int i_rep = 0; + + while (i_rep < count) + { + reader->last_byte = hpgs_getc(reader->in); + if (reader->last_byte == EOF) + return -1; + + if (++i_in >= data_len) return 0; + + int rep_cnt = reader->last_byte+1; + + reader->last_byte = hpgs_getc(reader->in); + if (reader->last_byte == EOF) + return -1; + + ++i_in; + + int rep_val = reader->last_byte; + + while (rep_cnt-- > 0 && i_rep < count) + { + if (i < reader->pcl_raster_data_size) + data[i] = rep_val; + + ++i; + ++i_rep; + } + } + } + else + { + // uncompressed replacement. + while (count > 0 && i_in < data_len) + { + reader->last_byte = hpgs_getc(reader->in); + if (reader->last_byte == EOF) + return -1; + + if (i < reader->pcl_raster_data_size) + data[i] = reader->last_byte; + + ++i_in; + ++i; + --count; + } + } + } + + return 0; +} + +static int pcl_read_raster_row(hpgs_reader *reader,int data_len) +{ + if (!is_pcl_compression_supported(reader->pcl_raster_compression)) + // simply ignore unknown compression modes. + return pcl_ignore_raster_data(reader,data_len); + + if (!reader->pcl_raster_data[reader->pcl_raster_plane]) + { + if (reader->pcl_raster_src_width <= 0) + { + reader->pcl_raster_src_width = (int) + (reader->pcl_raster_presentation ? reader->x_size : reader->y_size) + * HP_TO_PT * reader->pcl_raster_res / 72.0; + + if (reader->verbosity) + hpgs_log(hpgs_i18n("Estimated PCL src width = %d.\n"), + reader->pcl_raster_src_width); + + reader->pcl_raster_mode = 1; + + if (reader->pcl_raster_src_height <= 0) + { + reader->pcl_raster_src_height = (int) + (reader->pcl_raster_presentation ? reader->y_size : reader->x_size) + * HP_TO_PT * reader->pcl_raster_res / 72.0; + + while (reader->pcl_raster_src_width * reader->pcl_raster_src_height + > 1024*16384) + reader->pcl_raster_src_height /= 2; + + if (reader->verbosity) + hpgs_log(hpgs_i18n("Estimated PCL src height = %d.\n"), + reader->pcl_raster_src_height); + } + } + + if (reader->pcl_raster_data_size <= 0) + { + reader->pcl_raster_data_size = reader->pcl_raster_src_width; + + if (reader->pcl_palettes[reader->pcl_i_palette]->cid_enc == 3) // direct by pixel + reader->pcl_raster_data_size *= 3; + } + + reader->pcl_raster_data[reader->pcl_raster_plane] = + (unsigned char *)malloc(reader->pcl_raster_data_size); + + if (!reader->pcl_raster_data[reader->pcl_raster_plane]) + return hpgs_set_error(hpgs_i18n("Out of memory allocating %d bytes of raster bata buffer."),reader->pcl_raster_data_size); + + memset(reader->pcl_raster_data[reader->pcl_raster_plane], + 0,reader->pcl_raster_data_size); + } + + switch (reader->pcl_raster_compression) + { + case 0: + if (pcl_read_raster_0(reader,data_len)) + return -1; + break; + + case 1: + if (pcl_read_raster_1(reader,data_len)) + return -1; + break; + + case 2: + if (pcl_read_raster_2(reader,data_len)) + return -1; + break; + + case 3: + if (pcl_read_raster_3(reader,data_len)) + return -1; + break; + + case 9: + if (pcl_read_raster_9(reader,data_len)) + return -1; + break; + + default: + return -1; + } + + return 0; +} + +static int pcl_fill_scanline(hpgs_reader *reader) +{ + int i; + hpgs_paint_color c; + + if (!reader->pcl_image) + { + if (reader->pcl_raster_src_width <= 0) + return hpgs_set_error(hpgs_i18n("No PCL source raster width specified.")); + + if (reader->pcl_raster_src_height <= 0) + return hpgs_set_error(hpgs_i18n("No PCL source raster height specified.")); + + if (reader->verbosity > 1) + hpgs_log(hpgs_i18n("Creating %dx%d PCL image.\n"), + reader->pcl_raster_src_width, + reader->pcl_raster_src_height); + + // set up image, if not done yet. + switch (reader->pcl_palettes[reader->pcl_i_palette]->cid_enc) + { + case 0: // indexed by plane. + case 1: // indexed by pixel. + reader->pcl_image = (hpgs_image *) + hpgs_new_png_image(reader->pcl_raster_src_width, + reader->pcl_raster_src_height, + 8,HPGS_TRUE,HPGS_FALSE); + + // pull in palette + if (reader->pcl_image && + hpgs_image_set_palette(reader->pcl_image, + reader->pcl_palettes[reader->pcl_i_palette]->colors,256)) + return -1; + + break; + + case 2: // direct by plane. + reader->pcl_image = (hpgs_image *) + hpgs_new_png_image(reader->pcl_raster_src_width, + reader->pcl_raster_src_height, + 8,HPGS_TRUE,HPGS_FALSE); + // set palette + if (reader->pcl_image) + { + hpgs_palette_color palette[8]; + + for (i=0; i<8; ++i) + { + palette[i].r = (i&1)*255; + palette[i].g = ((i>>1)&1)*255; + palette[i].b = ((i>>2)&1)*255; + } + + hpgs_image_set_palette(reader->pcl_image,palette,8); + } + break; + + case 3: + reader->pcl_image = (hpgs_image *) + hpgs_new_png_image(reader->pcl_raster_src_width, + reader->pcl_raster_src_height, + 24,HPGS_FALSE,HPGS_FALSE); + break; + + default: + return hpgs_set_error(hpgs_i18n("Invalid PCL Pixel Encoding Mode %d."), + reader->pcl_palettes[reader->pcl_i_palette]->cid_enc); + } + + if (!reader->pcl_image) + return hpgs_set_error(hpgs_i18n("Out of memory creating PCL image.")); + } + + if (reader->pcl_raster_line >= reader->pcl_raster_src_height) + { + if (reader->verbosity) + hpgs_log(hpgs_i18n("PCL raster line %d is out of range (%dx%d).\n"), + reader->pcl_raster_line, + reader->pcl_raster_src_width, + reader->pcl_raster_src_height); + + return 0; + } + + switch (reader->pcl_palettes[reader->pcl_i_palette]->cid_enc) + { + case 0: // indexed by plane. + { + int p; + + for (p=0;ppcl_raster_planes;++p) + if (!reader->pcl_raster_data[p]) + return hpgs_set_error("No raster data."); + + for (i=0; ipcl_raster_src_width;) + { + int mask = 0x80; + + int v[8]; + + for (p=0;ppcl_raster_planes;++p) + v[p] = reader->pcl_raster_data[p][i>>3]; + + for (; ipcl_raster_src_width && mask; ++i, mask>>=1) + { + int bit; + c.index = 0; + + for (p=0,bit=1;ppcl_raster_planes;++p,bit<<=1) + if (v[p] & mask) c.index |= bit; + + if (hpgs_image_put_pixel (reader->pcl_image,i, + reader->pcl_raster_line,&c,1.0)) + return -1; + } + } + } + break; + + case 1: // indexed by pixel. + if (!reader->pcl_raster_data[0]) + return hpgs_set_error(hpgs_i18n("No raster data.")); + + switch (reader->pcl_palettes[reader->pcl_i_palette]->cid_bpi) + { + case 1: + for (i=0; i<(reader->pcl_raster_src_width+7)/8;++i) + { + int bit = 0x80; + int j; + + for (j=0;j<8 && 8*i+j < reader->pcl_raster_src_width;++j,bit>>=1) + { + c.index = (reader->pcl_raster_data[0][i] & bit) ? 1 : 0; + + if (hpgs_image_put_pixel (reader->pcl_image,8*i+j, + reader->pcl_raster_line,&c,1.0)) + return -1; + } + } + break; + + case 2: + for (i=0; i<(reader->pcl_raster_src_width+3)/4;++i) + { + c.index = reader->pcl_raster_data[0][i] >> 6; + + if (hpgs_image_put_pixel (reader->pcl_image,4*i, + reader->pcl_raster_line,&c,1.0)) + return -1; + + c.index = (reader->pcl_raster_data[0][i] >> 4) & 0x03; + + if (4*i+1 >= reader->pcl_raster_src_width) break; + + if (hpgs_image_put_pixel (reader->pcl_image,4*i+1, + reader->pcl_raster_line,&c,1.0)) + return -1; + + c.index = (reader->pcl_raster_data[0][i] >> 2) & 0x03; + + if (4*i+2 >= reader->pcl_raster_src_width) break; + + if (hpgs_image_put_pixel (reader->pcl_image,4*i+2, + reader->pcl_raster_line,&c,1.0)) + return -1; + + c.index = reader->pcl_raster_data[0][i] & 0x03; + + if (4*i+3 >= reader->pcl_raster_src_width) break; + + if (hpgs_image_put_pixel (reader->pcl_image,4*i+3, + reader->pcl_raster_line,&c,1.0)) + return -1; + } + break; + + case 4: + for (i=0; i<(reader->pcl_raster_src_width+1)/2;++i) + { + c.index = reader->pcl_raster_data[0][i] >> 4; + + if (hpgs_image_put_pixel (reader->pcl_image,2*i, + reader->pcl_raster_line,&c,1.0)) + return -1; + + + c.index = reader->pcl_raster_data[0][i] & 0x0f; + + if (2*i+1 >= reader->pcl_raster_src_width) break; + + if (hpgs_image_put_pixel (reader->pcl_image,2*i+1, + reader->pcl_raster_line,&c,1.0)) + return -1; + } + break; + + case 8: + for (i=0; ipcl_raster_src_width;++i) + { + c.index = reader->pcl_raster_data[0][i]; + + if (hpgs_image_put_pixel (reader->pcl_image,i, + reader->pcl_raster_line,&c,1.0)) + return -1; + } + break; + + default: + return hpgs_set_error(hpgs_i18n("Invalid bpi %d."), + (int)reader->pcl_palettes[reader->pcl_i_palette]->cid_bpi); + } + break; + + case 2: // direct by plane. + if (!reader->pcl_raster_data[0] || + !reader->pcl_raster_data[1] || + !reader->pcl_raster_data[2] ) + return hpgs_set_error(hpgs_i18n("No raster data.")); + + for (i=0; ipcl_raster_src_width;) + { + int mask = 0x80; + + int v0 = reader->pcl_raster_data[0][i>>3]; + int v1 = reader->pcl_raster_data[1][i>>3]; + int v2 = reader->pcl_raster_data[2][i>>3]; + + for (; ipcl_raster_src_width && mask; ++i, mask>>=1) + { + c.r = (v0 & mask) ? 255 : 0; + c.g = (v1 & mask) ? 255 : 0; + c.b = (v2 & mask) ? 255 : 0; + + if (hpgs_image_define_color (reader->pcl_image,&c)) + return -1; + + if (hpgs_image_put_pixel (reader->pcl_image,i, + reader->pcl_raster_line,&c,1.0)) + return -1; + } + } + break; + + case 3: + if (!reader->pcl_raster_data[0]) + return hpgs_set_error(hpgs_i18n("No raster data.")); + + + for (i=0; ipcl_raster_src_width;++i) + { + c.r = reader->pcl_raster_data[0][3*i ]; + c.g = reader->pcl_raster_data[0][3*i+1]; + c.b = reader->pcl_raster_data[0][3*i+2]; + + if (hpgs_image_put_pixel (reader->pcl_image,i, + reader->pcl_raster_line,&c,1.0)) + return -1; + } + break; + + default: + return hpgs_set_error(hpgs_i18n("Invalid PCL Pixel Encoding Mode %d."),reader->pcl_palettes[reader->pcl_i_palette]->cid_bpi); + } + + return 0; +} + +static int pcl_put_image(hpgs_reader *reader) +{ + // setup image placement + double w,h; + hpgs_point ll,lr,ur; + + double x0; + double y0; + + int angle; + + if (reader->pcl_raster_line <= 0 || + reader->pcl_raster_src_width <= 0 || + reader->pcl_raster_src_height <= 0 ) + // don't process any further, if we don't have an image size. + // An image size is needed for correct cursor positioning. + return 0; + + if (reader->pcl_raster_line < reader->pcl_raster_src_height) + { + if (reader->pcl_image && + hpgs_image_resize(reader->pcl_image,reader->pcl_raster_src_width,reader->pcl_raster_line)) + return hpgs_set_error(hpgs_i18n("Error downsizing PCL image.")); + + reader->pcl_raster_src_height = reader->pcl_raster_line; + } + + angle = (reader->pcl_raster_presentation != 0) ? 0 : 90; + +#ifdef HPGS_PCL_DEBUG + hpgs_log("raster_pres,x_size,y_size,rot,angle=%d,%lg,%lg,%d,%d.\n", + reader->pcl_raster_presentation,reader->x_size,reader->y_size, + reader->rotation, angle); +#endif + + if (reader->pcl_raster_mode & 1) + { + x0 = reader->pcl_point.x; + y0 = reader->pcl_point.y; + } + else + if (reader->y_size >= reader->x_size) + { + x0 = 0.0; + y0 = reader->pcl_point.y; + } + else + { + x0 = reader->pcl_point.x; + y0 = 0.0; + } + + // PCL coordinates + // + // y (w,0)-------------(w,h) + // ^ | | + // | | | + // | | | + // | | | + // | (0,0)-------------(0,h) + // +-----------> x + +#ifdef HPGS_PCL_DEBUG + hpgs_log("src:w,h=%d,%d.\n",reader->pcl_raster_src_width,reader->pcl_raster_src_height); +#endif + if (reader->pcl_raster_mode & 2) + { + w = 0.1*reader->pcl_raster_dest_width; + h = 0.1*reader->pcl_raster_dest_height; + } + else + { +#ifdef HPGS_PCL_DEBUG + hpgs_log("raster_res=%d.\n",reader->pcl_raster_res); +#endif + w = reader->pcl_raster_src_width * 72.0 / reader->pcl_raster_res; + h = reader->pcl_raster_src_height * 72.0 / reader->pcl_raster_res; + } + +#ifdef HPGS_PCL_DEBUG + hpgs_log("w,h=%lg,%lg.\n",w,h); +#endif + + // 2005-06-13: + // Well, the code below is completely based on my experience + // with the testsuite, which is available to me. + // Up to now, I did not find a consistent description of + // the PCL coordinate setup in HP's docs. If you have any problems + // with PCL image placement, please send me an e-mail: + // + // wolfgang.glas@ev-i.at + // + switch (angle % 360) + { + case 90: + case 270: + ur.x = x0 + + h * reader->pcl_raster_y_offset/(double)reader->pcl_raster_src_height; + + ur.y = lr.y = y0 + w; + ll.y = y0; + ll.x = lr.x = ur.x + h; + break; + + default: /* case 0, 180: */ + ur.x = lr.x = x0 + w; + + ur.y = y0 - + h * reader->pcl_raster_y_offset/(double)reader->pcl_raster_src_height; + + ll.x = x0; + ll.y = lr.y = ur.y - h; + break; + } + +#ifdef HPGS_PCL_DEBUG + hpgs_log("raster_pres,x_s,y_s=%d,%lg,%lg.\n", + reader->pcl_raster_presentation,reader->x_size,reader->y_size); + + hpgs_log("ll,lr,ur=(%lg,%lg),(%lg,%lg),(%lg,%lg).\n", + ll.x,ll.y,lr.x,lr.y,ur.x,ur.y); +#endif + + // save inline images, if specified. + if (reader->pcl_image && reader->png_dump_filename) + { + int l = strlen(reader->png_dump_filename)+16; + char *fn = hpgs_alloca(l); + + ++reader->png_dump_count; + snprintf(fn,l,"%s%04d.png",reader->png_dump_filename,reader->png_dump_count); + + if (reader->verbosity) + hpgs_log(hpgs_i18n("Dumping inline PCL image to file <%s>.\n"),fn); + + int ret = hpgs_image_write(reader->pcl_image,fn); + + if (ret) return -1; + } + + // check for discarded image data of unknown compression modes, + // if the device is unable to process null images. + // (only plotsize devices normally can process null images...) + if ((hpgs_device_capabilities(reader->device) & HPGS_DEVICE_CAP_NULLIMAGE) || + reader->pcl_image) + { + hpgs_point ll_p; + hpgs_point lr_p; + hpgs_point ur_p; + + hpgs_matrix_xform(&ll_p,&reader->page_matrix,&ll); + hpgs_matrix_xform(&lr_p,&reader->page_matrix,&lr); + hpgs_matrix_xform(&ur_p,&reader->page_matrix,&ur); + + // draw image + if (hpgs_drawimage(reader->device,reader->pcl_image,&ll_p,&lr_p,&ur_p)) + return -1; + } + + // set the cursor position. + reader->pcl_point = ll; + + return 0; +} + +static int pcl_do_cmd(hpgs_reader *reader, int cmd, int arg, int arg_sign, + hpgs_bool have_arg) +{ + if (reader->verbosity>1) + hpgs_log(hpgs_i18n("PCL command %c%c%d%c found.\n"), + (char)(cmd >> 16),(char)(cmd >> 8),arg,(char)(cmd&0xff)); + + switch (cmd) + { + case MK_PCL_CMD('%',' ','B'): + if (!have_arg) return -1; +#ifdef HPGS_PCL_DEBUG + hpgs_log("leave PCL: arg,pcl_point,hpgl_point=%d,(%lg,%lg),(%lg,%lg).\n", + arg, + reader->pcl_point.x, + reader->pcl_point.y, + reader->current_point.x, + reader->current_point.y ); +#endif + if (arg & 1) + { + hpgs_point tmp; + hpgs_matrix_xform(&tmp,&reader->page_matrix,&reader->pcl_point); + if (hpgs_reader_moveto(reader,&tmp)) return -1; + } + + pcl_clear_raster_data(reader,PCL_RASTER_CLEAR_IMAGE); + return 1; + + case MK_PCL_CMD('%',' ','X'): + if (!have_arg) return -1; + pcl_clear_raster_data(reader,PCL_RASTER_CLEAR_IMAGE); + return 2; + + case MK_PCL_CMD('*','v','N'): // Source Transparency Mode. + if (!have_arg) return -1; + reader->src_transparency = (arg == 0); + +#ifdef HPGS_PCL_DEBUG + hpgs_log("src transp. %d,%d.\n",arg,reader->src_transparency); +#endif + if (hpgs_setrop3(reader->device,reader->rop3, + reader->src_transparency, + reader->pattern_transparency )) + return -1; + break; + + case MK_PCL_CMD('*','v','O'): // Pattern Transparency Mode. + if (!have_arg) return -1; + reader->pattern_transparency = (arg == 0); + +#ifdef HPGS_PCL_DEBUG + hpgs_log("pat transp. %d,%d.\n",arg,reader->pattern_transparency); +#endif + if (hpgs_setrop3(reader->device,reader->rop3, + reader->src_transparency, + reader->pattern_transparency )) + return -1; + break; + + case MK_PCL_CMD('*','v','T'): // Set Current Pattern. + if (!have_arg) return -1; + + { + hpgs_color patcol; + + patcol.r = patcol.g = patcol.b = arg ? (arg == 1 ? 1.0 : 0.5) : 0.0; + + if (reader->verbosity && (arg < 0 || arg > 1)) + hpgs_log(hpgs_i18n("Warning: Invalid pattern %d specified setting pattern to 50%% grey.\n"),arg); + + if (hpgs_setpatcol(reader->device,&patcol)) + return -1; + } + break; + + case MK_PCL_CMD('*','l','O'): // Logical operation. + if (!have_arg) return -1; + reader->rop3 = arg; + + if (hpgs_setrop3(reader->device,reader->rop3, + reader->src_transparency, + reader->pattern_transparency )) + return -1; + break; + + case MK_PCL_CMD('*','p','P'): // Push/Pop palette. + if (!have_arg) return -1; + if (arg < 0 || arg > 1) + return hpgs_set_error(hpgs_i18n("PCL push/pop palette arg %d invalid."),arg); + + if (arg) + { + if (hpgs_reader_pop_pcl_palette(reader)) return -1; + } + else + { + if (hpgs_reader_push_pcl_palette(reader)) return -1; + } + break; + + case MK_PCL_CMD('&','u','D'): // PCL unit + if (!have_arg) return -1; + reader->pcl_scale = 72.0/(double)arg; + break; + + case MK_PCL_CMD('&','k','H'): // horizontal motion index + if (!have_arg) return -1; + reader->pcl_hmi = (double)arg*72.0/120.0; + break; + + case MK_PCL_CMD('&','l','C'):// vertical motion index + if (!have_arg) return -1; + reader->pcl_vmi = (double)arg*72.0/48.0; + break; + + case MK_PCL_CMD('&','a','C'): // horiz. position in columns. + if (!have_arg) return -1; + if (arg_sign) + reader->pcl_point.y += arg * reader->pcl_hmi; + else + reader->pcl_point.y = reader->frame_y + arg * reader->pcl_hmi; + break; + + case MK_PCL_CMD('&','a','H'): // horiz. position in decipoints. + if (!have_arg) return -1; + if (arg_sign) + reader->pcl_point.y += arg * 0.1; + else + reader->pcl_point.y = reader->frame_y + arg * 0.1; + break; + + case MK_PCL_CMD('*','p','X'): // horiz. position in PCL units. + if (!have_arg) return -1; + if (arg_sign) + reader->pcl_point.y += arg * reader->pcl_scale; + else + reader->pcl_point.y = reader->frame_y + arg * reader->pcl_scale; + break; + + case MK_PCL_CMD('&','a','R'): // vert. position in columns. + if (!have_arg) return -1; + if (arg_sign) + reader->pcl_point.x += arg * reader->pcl_vmi; + else + reader->pcl_point.x = reader->frame_x + arg * reader->pcl_vmi; + break; + + case MK_PCL_CMD('&','a','V'): // vert. position in decipoints. + if (!have_arg) return -1; + if (arg_sign) + reader->pcl_point.x += arg * 0.1; + else + reader->pcl_point.x = reader->frame_x + arg * 0.1; + break; + + case MK_PCL_CMD('*','p','Y'): // vert. position in PCL units. + if (!have_arg) return -1; + if (arg_sign) + reader->pcl_point.x += arg * reader->pcl_scale; + else + reader->pcl_point.x = reader->frame_x + arg * reader->pcl_scale; + break; + + case MK_PCL_CMD('*','v','W'): // configure image data + if (!have_arg) return -1; + if (reader->pcl_raster_data[reader->pcl_raster_plane]) + return hpgs_set_error(hpgs_i18n("PCL CID command after image data.")); + + reader->pcl_palettes[reader->pcl_i_palette]->cid_space = hpgs_getc(reader->in); + if (reader->pcl_palettes[reader->pcl_i_palette]->cid_space == EOF) return -1; + reader->pcl_palettes[reader->pcl_i_palette]->cid_enc = hpgs_getc(reader->in); + if (reader->pcl_palettes[reader->pcl_i_palette]->cid_enc == EOF) return -1; + reader->pcl_palettes[reader->pcl_i_palette]->cid_bpi = hpgs_getc(reader->in); + if (reader->pcl_palettes[reader->pcl_i_palette]->cid_bpi == EOF) return -1; + reader->pcl_palettes[reader->pcl_i_palette]->cid_bpc[0] = hpgs_getc(reader->in); + if (reader->pcl_palettes[reader->pcl_i_palette]->cid_bpc[0] == EOF) return -1; + reader->pcl_palettes[reader->pcl_i_palette]->cid_bpc[1] = hpgs_getc(reader->in); + if (reader->pcl_palettes[reader->pcl_i_palette]->cid_bpc[1] == EOF) return -1; + reader->pcl_palettes[reader->pcl_i_palette]->cid_bpc[2] = hpgs_getc(reader->in); + if (reader->pcl_palettes[reader->pcl_i_palette]->cid_bpc[2] == EOF) return -1; + + if (arg == 18) + { + // basic interpretation of long form of CID command. + unsigned char ref_data[12]; + // this is the only form of the CID 18 header we are currently recognizig. + unsigned char impl_ref_data[12] = { 0,255,0,255,0,255,0,0,0,0,0,0 }; + + if (hpgs_istream_read(ref_data,1,sizeof(ref_data),reader->in) != sizeof(ref_data)) return -1; + + if (memcmp(ref_data,impl_ref_data,sizeof(ref_data)) != 0) + return hpgs_set_error(hpgs_i18n("PCL CID command with arg==18 and non-trivial colorspace is unimplemented.")); + } + else if (arg!=6) + return hpgs_set_error(hpgs_i18n("PCL CID command with arg!=6 and arg !=18 is unimplemented.")); + +#ifdef HPGS_PCL_DEBUG + hpgs_log("CID: %d %d %d %d %d %d.\n", + reader->pcl_palettes[reader->pcl_i_palette]->cid_space, + reader->pcl_palettes[reader->pcl_i_palette]->cid_enc, + reader->pcl_palettes[reader->pcl_i_palette]->cid_bpi, + reader->pcl_palettes[reader->pcl_i_palette]->cid_bpc[0], + reader->pcl_palettes[reader->pcl_i_palette]->cid_bpc[1], + reader->pcl_palettes[reader->pcl_i_palette]->cid_bpc[2] ); +#endif + + if (reader->pcl_palettes[reader->pcl_i_palette]->cid_enc == 0 && + (reader->pcl_palettes[reader->pcl_i_palette]->cid_bpi < 1 || reader->pcl_palettes[reader->pcl_i_palette]->cid_bpi > 8)) + return hpgs_set_error(hpgs_i18n("Invalid bits per index %d for PCL CID encoding 0."),reader->pcl_palettes[reader->pcl_i_palette]->cid_bpi); + + if (reader->pcl_palettes[reader->pcl_i_palette]->cid_enc == 1 && + (reader->pcl_palettes[reader->pcl_i_palette]->cid_bpi != 1 && + reader->pcl_palettes[reader->pcl_i_palette]->cid_bpi != 2 && + reader->pcl_palettes[reader->pcl_i_palette]->cid_bpi != 4 && + reader->pcl_palettes[reader->pcl_i_palette]->cid_bpi != 8 )) + return hpgs_set_error(hpgs_i18n("Inavlid bits per index %d for PCL CID encoding 1."),reader->pcl_palettes[reader->pcl_i_palette]->cid_bpi); + + if (reader->pcl_palettes[reader->pcl_i_palette]->cid_enc == 2) + reader->pcl_raster_planes = 3; + else if (reader->pcl_palettes[reader->pcl_i_palette]->cid_enc == 0) + reader->pcl_raster_planes = reader->pcl_palettes[reader->pcl_i_palette]->cid_bpi; + else + reader->pcl_raster_planes = 1; + + break; + + case MK_PCL_CMD('*','v','A'): // color component #1 + if (!have_arg) return -1; + reader->pcl_palettes[reader->pcl_i_palette]->last_color.r = arg; + break; + + case MK_PCL_CMD('*','v','B'): // color component #2 + if (!have_arg) return -1; + reader->pcl_palettes[reader->pcl_i_palette]->last_color.g = arg; + break; + + case MK_PCL_CMD('*','v','C'): // color component #3 + if (!have_arg) return -1; + reader->pcl_palettes[reader->pcl_i_palette]->last_color.b = arg; + break; + + case MK_PCL_CMD('*','v','I'): // assign color index + if (!have_arg) return -1; + if (arg < 0 || arg >= 256) + return hpgs_set_error(hpgs_i18n("PCL Color index %d is out of bounds."),arg); + + reader->pcl_palettes[reader->pcl_i_palette]->colors[arg] = reader->pcl_palettes[reader->pcl_i_palette]->last_color; + + reader->pcl_palettes[reader->pcl_i_palette]->last_color.r = 0; + reader->pcl_palettes[reader->pcl_i_palette]->last_color.g = 0; + reader->pcl_palettes[reader->pcl_i_palette]->last_color.b = 0; + break; + + case MK_PCL_CMD('*','r','A'): // start raster graphics + if (!have_arg) return -1; + // if (reader->pcl_raster_mode >= 0) + // return hpgs_set_error(hpgs_i18n("Nested PCL start raster graphics commands.")); + + reader->pcl_raster_mode = arg; + break; + + case MK_PCL_CMD('*','r','F'): // Raster Presentation Mode + if (!have_arg) return -1; + if (arg != 0 && arg != 3) + return hpgs_set_error(hpgs_i18n("PCL Raster Presentation Mode %d is invalid."),arg); + + reader->pcl_raster_presentation = arg; + break; + + case MK_PCL_CMD('*','t','R'): // Raster Resolution + if (!have_arg) return -1; + if (arg < 75 || arg > 2400) + return hpgs_set_error(hpgs_i18n("PCL Raster Resolution %d is out of bounds."),arg); + + reader->pcl_raster_res = arg; + break; + + case MK_PCL_CMD('*','r','S'): // source Raster Width + if (!have_arg) return -1; + + if (reader->pcl_raster_data[0]) + return hpgs_set_error(hpgs_i18n("PCL Source raster width command after image data.")); + + // if (reader->pcl_raster_src_width > 0) + // return hpgs_set_error("Repeated occurrence of PCL Source raster width."); + + if (arg < 0 || arg > 32767) + return hpgs_set_error(hpgs_i18n("PCL Source raster width %d is out of bounds."),arg); + + reader->pcl_raster_src_width = arg; + break; + + case MK_PCL_CMD('*','r','T'): // source Raster Height + if (!have_arg) return -1; + + if (reader->pcl_raster_data[0]) + return hpgs_set_error(hpgs_i18n("PCL Source raster height command after image data.")); + + // if (reader->pcl_raster_src_height > 0) + // return hpgs_set_error("Repeated occurrence of PCL Source raster height."); + + if (arg < 0 || arg > 32767) + return hpgs_set_error(hpgs_i18n("PCL Source raster height %d is out of bounds."),arg); + + reader->pcl_raster_src_height = arg; + break; + + case MK_PCL_CMD('*','t','H'): // destination Raster Width + if (!have_arg) return -1; + if (arg < 0 || arg > 65535) + return hpgs_set_error(hpgs_i18n("PCL Destination raster width %d is out of bounds."),arg); + + reader->pcl_raster_dest_width = arg; + break; + + case MK_PCL_CMD('*','t','V'): // destination Raster Height + if (!have_arg) return -1; + if (arg < 0 || arg > 65535) + return hpgs_set_error(hpgs_i18n("PCL Destination raster height %d is out of bounds."),arg); + + reader->pcl_raster_dest_height = arg; + break; + + case MK_PCL_CMD('*','b','Y'): // raster Y offset + if (!have_arg) return -1; + reader->pcl_raster_y_offset = arg; + break; + + case MK_PCL_CMD('*','b','M'): // Raster Compression Mode + if (!have_arg) return -1; + + if (!is_pcl_compression_supported(arg) && reader->verbosity > 0) + hpgs_log(hpgs_i18n("Warning: Ignoring image data in PCL Raster Compression Mode %d.\n"),arg); + + reader->pcl_raster_compression = arg; + break; + + case MK_PCL_CMD('*','b','V'): // Transfer Raster Data by Plane + if (!have_arg) return -1; + if (arg < 0) + return hpgs_set_error(hpgs_i18n("PCL Raster Row length %d is invalid."),arg); + + if (pcl_read_raster_row(reader,arg)) return -1; + reader->pcl_raster_plane = (reader->pcl_raster_plane+1)%reader->pcl_raster_planes; + break; + + case MK_PCL_CMD('*','b','W'): // Transfer Raster Data by Row + if (!have_arg) return -1; + if (arg < 0) + return hpgs_set_error(hpgs_i18n("PCL Raster Row length %d is invalid."),arg); + + if (pcl_read_raster_row(reader,arg)) return -1; + reader->pcl_raster_plane = 0; + + // For the sake of performance, only process image data + // for real drawing devices, not for the plotsize device. + // Additionally, ignore unknown raster compression modes. + if ((hpgs_device_capabilities(reader->device) & HPGS_DEVICE_CAP_PLOTSIZE) == 0 && + is_pcl_compression_supported(reader->pcl_raster_compression) && + reader->pcl_raster_src_width > 0 && + pcl_fill_scanline(reader)) + return -1; + + ++reader->pcl_raster_line; + + // emit partial images. + if (reader->pcl_raster_src_height > 1 && + reader->pcl_raster_line >= reader->pcl_raster_src_height) + { + if (pcl_put_image(reader)) return -1; + pcl_clear_raster_data(reader,PCL_RASTER_CLEAR_PARTIAL); + } + + break; + + case MK_PCL_CMD('*','r','B'): // End Raster Graphics + case MK_PCL_CMD('*','r','C'): // End Raster Graphics + if (have_arg) return -1; + if (pcl_put_image(reader)) return -1; + pcl_clear_raster_data(reader,PCL_RASTER_CLEAR_IMAGE); + break; + + default: + if (reader->verbosity) + hpgs_log(hpgs_i18n("Unknown PCL command %c%c%d%c found.\n"), + (char)(cmd >> 16),(char)(cmd >> 8),arg,(char)(cmd&0xff)); + } +#ifdef HPGS_PCL_DEBUG + if ((cmd >> 16) == '&' || cmd == MK_PCL_CMD('*','p','X') || cmd == MK_PCL_CMD('*','p','Y')) + hpgs_log("%c%c%d%c: pcl_point=(%lg,%lg).\n", + (char)(cmd >> 16),(char)(cmd >> 8),arg,(char)(cmd&0xff), + reader->pcl_point.x, + reader->pcl_point.y); +#endif + + return 0; +} + +/*! + Read a PCL block of the file. + + Return values: + \li -1 Error, unexpected EOF. + \li 0 Success, return to HPGL context. + \li 1 Success, return to PJL context. + \li 2 Success, EOF reached. +*/ +int hpgs_reader_do_PCL(hpgs_reader *reader, hpgs_bool take_pos) +{ + int cmd1,cmd2; + reader->bytes_ignored = 0; + reader->eoc = 0; + int ret = -1; + +#ifdef HPGS_PCL_DEBUG + hpgs_log("enter PCL: arg,pcl_point,hpgl_point=%d,(%lg,%lg),(%lg,%lg).\n", + take_pos, + reader->pcl_point.x, + reader->pcl_point.y, + reader->current_point.x, + reader->current_point.y ); +#endif + + if (take_pos) + { + reader->pcl_point.x = reader->current_point.x; + reader->pcl_point.y = reader->current_point.y; + } + else + if (reader->y_size >= reader->x_size) + { + reader->pcl_point.x = 0.0; + reader->pcl_point.y = HP_TO_PT * reader->y_size; + } + else + { + reader->pcl_point.x = 0.0; + reader->pcl_point.y = 0.0; + } + + hpgs_matrix_ixform(&reader->pcl_point,&reader->pcl_point,&reader->page_matrix); + + while ((reader->last_byte = hpgs_getc(reader->in)) != EOF) + { + if (reader->interrupted) goto interrupted_escape; + + if (reader->last_byte != HPGS_ESC) continue; + + reader->last_byte = hpgs_getc(reader->in); + + if (reader->last_byte == EOF) break; + + cmd1 = reader->last_byte; + cmd2 = ' '; + + switch (cmd1) + { + case 'E': + hpgs_reader_set_default_state (reader); + break; + case '&': + case '*': + reader->last_byte = hpgs_getc(reader->in); + if (reader->last_byte == EOF) goto unexpected_eof; + // invalid group character ? + if (reader->last_byte < 96 || reader->last_byte >126) break; + cmd2 = reader->last_byte; + case '%': + { + hpgs_bool do_continue; + do + { + int cmd = 0; + int arg,arg_sign; + int have_arg = hpgs_reader_read_pcl_int(reader,&arg,&arg_sign); + + // check for an ESC charcter here + // (which has already put back by ungetc() in pcl_read_int) + // and continue with command parsing from the beginning. + // This fixes some broken PCL files. + if (reader->last_byte == HPGS_ESC) break; + + do_continue = HPGS_FALSE; + + if (have_arg < 0) + goto unexpected_eof; + + reader->last_byte = hpgs_getc(reader->in); + + if (reader->last_byte == EOF) goto unexpected_eof; + + if (reader->last_byte >= 'a' && reader->last_byte <= 'z') + { + cmd = MK_PCL_CMD(cmd1,cmd2,reader->last_byte + ('A' - 'a')); + do_continue = HPGS_TRUE; + } + else if (reader->last_byte >= 'A' && reader->last_byte <= 'Z') + cmd = MK_PCL_CMD(cmd1,cmd2,reader->last_byte); + + if (cmd) + switch (pcl_do_cmd(reader,cmd,arg,arg_sign,have_arg)) + { + case 1: + return 0; + case 2: + return 1; + case 0: + break; + default: + goto unexpected_eof; + } + } + while (do_continue); + } + break; + } + } + + ret = 2; + + unexpected_eof: + + if (reader->pcl_image) + ret = hpgs_error_ctxt("Error in PCL image"); + + interrupted_escape: + pcl_clear_raster_data(reader,PCL_RASTER_CLEAR_FORCE); + return ret; +} diff --git a/src/add-ons/translators/hpgs/lib/hpgspe.c b/src/add-ons/translators/hpgs/lib/hpgspe.c new file mode 100644 index 0000000000..f22ef84ee1 --- /dev/null +++ b/src/add-ons/translators/hpgs/lib/hpgspe.c @@ -0,0 +1,290 @@ +/*********************************************************************** + * * + * $Id: hpgspe.c 347 2006-09-21 09:36:01Z softadm $ + * * + * hpgs - HPGl Script, a hpgl/2 interpreter, which uses a Postscript * + * API for rendering a scene and thus renders to a variety of * + * devices and fileformats. * + * * + * (C) 2004-2006 ev-i Informationstechnologie GmbH http://www.ev-i.at * + * * + * Author: Wolfgang Glas * + * * + * hpgs is free software; you can redistribute it and/or * + * modify it under the terms of the GNU Lesser General Public * + * License as published by the Free Software Foundation; either * + * version 2.1 of the License, or (at your option) any later version. * + * * + * hpgs is distributed in the hope that it will be useful, * + * but WITHOUT ANY WARRANTY; without even the implied warranty of * + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * + * Lesser General Public License for more details. * + * * + * You should have received a copy of the GNU Lesser General Public * + * License along with this library; if not, write to the * + * Free Software Foundation, Inc., 59 Temple Place, Suite 330, * + * Boston, MA 02111-1307 USA * + * * + *********************************************************************** + * * + * The implementation of the HPGL reader. * + * * + ***********************************************************************/ + +#include +#include +#include +#include + +//#define HPGS_DEBUG_PE + +/* + HPGL command PE (Polyline Encoded) +*/ +static int base32_decode (hpgs_reader *reader, unsigned *value) +{ + int digit; + int i=0; + + *value=0; + + while (i<7) + { + if (reader->last_byte == EOF) return -1; + + reader->last_byte &= 0x7f; + + if (reader->last_byte > 94) + digit = reader->last_byte - 95; + else + digit = reader->last_byte - 63; + + if (digit >= 0 && digit <= 31) + { + *value |= digit << (5*i); + + if (reader->last_byte > 94) return 0; + ++i; + } + else + // ignore all escape characters, including space. + if (reader->last_byte > 32) return -1; + + reader->last_byte = hpgs_getc(reader->in); + } + + return -1; +} + +static int base64_decode (hpgs_reader *reader, unsigned *value) +{ + int digit; + int i=0; + + *value=0; + + while (i<6) + { + if (reader->last_byte == EOF) return -1; + + if (reader->last_byte > 190) + digit = reader->last_byte - 191; + else + digit = reader->last_byte - 63; + + if (digit >= 0 && digit <= 63) + { + *value |= digit << (6*i); + + if (reader->last_byte > 190) return 0; + ++i; + } + else + // ignore all escape characters, including space. + if (reader->last_byte > 32) return -1; + + reader->last_byte = hpgs_getc(reader->in); + } + return -1; +} + +static int int_decode (hpgs_reader *reader, int *value, int b32) +{ + unsigned uval; + + if (b32) + { if (base32_decode(reader,&uval)) return -1; } + else + { if (base64_decode(reader,&uval)) return -1; } + + if (uval & 1) + *value = - (uval >> 1); + else + *value = uval >> 1; + + return 0; +} + + +static int double_decode (hpgs_reader *reader, double *value, + double fract_fac, int b32) +{ + int int_val; + + if (int_decode(reader,&int_val,b32)) + return -1; + + *value = int_val * fract_fac; + return 0; +} + +static int coord_decode (hpgs_reader *reader, hpgs_point *p, + double fract_fac, int b32, int rel) +{ + if (double_decode (reader,&p->x,fract_fac,b32)) return -1; + reader->last_byte = hpgs_getc(reader->in); + if (double_decode (reader,&p->y,fract_fac,b32)) return -1; + + if (rel) + { + hpgs_matrix_scale (p,&reader->total_matrix,p); + p->x+=reader->current_point.x; + p->y+=reader->current_point.y; + } + else + { + hpgs_matrix_xform (p,&reader->total_matrix,p); + } + + return 0; +} + + +int hpgs_reader_do_PE(hpgs_reader *reader) +{ + hpgs_point p0; + hpgs_point p; + + double fract_fac = 1.0; + int rel = 1; + int b32 = 0; + int rect = 0; + reader->pen_down = 1; + +#ifdef HPGS_DEBUG_PE + hpgs_log("PE start ***************\n"); +#endif + + while (1) + { + reader->last_byte = hpgs_getc(reader->in); + + if (reader->last_byte == EOF || reader->last_byte == ';') + { + reader->eoc = 1; + reader->bytes_ignored = 0; + return 0; + } + + switch (reader->last_byte & 0x7f) + { + case '7': + b32 = 1; + break; + case '9': + rect = 1; + reader->pen_down = 0; + break; + case ':': + { + int pen; + reader->last_byte = hpgs_getc(reader->in); + if (int_decode(reader,&pen,b32)) return -1; + if (hpgs_reader_do_setpen(reader,pen)) return -1; + } + break; + case '>': + { + int fract_bits; + reader->last_byte = hpgs_getc(reader->in); + if (int_decode(reader,&fract_bits,b32)) return -1; + + fract_fac = 1.0; + while (--fract_bits >= 0) + fract_fac *= 0.5; + } + break; + case '<': + reader->pen_down = 0; + rect = 0; + break; + case '=': + rel = 0; + break; + default: + if (isspace(reader->last_byte)) break; + + if (coord_decode(reader,&p,fract_fac,b32,rel)) + { + // Well, some HPGL drivers are so broken, that they + // can't write decent PE vommands. + // So let's hand over control to the recovery code in + // hpgs_read(). + // + if (reader->last_byte != EOF) + { + reader->eoc = 1; + reader->bytes_ignored = 1; + return 0; + } + + return -1; + } + +#ifdef HPGS_DEBUG_PE + hpgs_log("p,down,rect = (%lg,%lg),%d,%d.\n",p.x,p.y,reader->pen_down,rect); +#endif + switch (rect) + { + case 1: + if (hpgs_reader_checkpath(reader)) return -1; + p0 = p; + if (hpgs_reader_moveto(reader,&p0)) return -1; + rect = 2; + break; + case 2: + { + hpgs_point pp; + pp.x=p.x; + pp.y=p0.y; + if (hpgs_reader_lineto(reader,&pp)) return -1; + if (hpgs_reader_lineto(reader,&p)) + return -1; + pp.x=p0.x; + pp.y=p.y; + if (hpgs_reader_lineto(reader,&pp)) return -1; + if (hpgs_reader_lineto(reader,&p0)) return -1; + // only do a fill, if we are not in polygon mode. + if (!reader->polygon_mode && + hpgs_reader_fill(reader,1)) return -1; + } + reader->pen_down = 1; + rect = 1; + break; + default: + if (reader->pen_down) + { + if (hpgs_reader_lineto(reader,&p)) return -1; + } + else + { + if (hpgs_reader_checkpath(reader)) return -1; + if (hpgs_reader_moveto(reader,&p)) return -1; + } + + reader->pen_down = 1; + } + rel = 1; + } + } +} diff --git a/src/add-ons/translators/hpgs/lib/hpgspen.c b/src/add-ons/translators/hpgs/lib/hpgspen.c new file mode 100644 index 0000000000..5e2f9ed72b --- /dev/null +++ b/src/add-ons/translators/hpgs/lib/hpgspen.c @@ -0,0 +1,421 @@ +/*********************************************************************** + * * + * $Id: hpgspen.c 298 2006-03-05 18:18:03Z softadm $ + * * + * hpgs - HPGl Script, a hpgl/2 interpreter, which uses a Postscript * + * API for rendering a scene and thus renders to a variety of * + * devices and fileformats. * + * * + * (C) 2004-2006 ev-i Informationstechnologie GmbH http://www.ev-i.at * + * * + * Author: Wolfgang Glas * + * * + * hpgs is free software; you can redistribute it and/or * + * modify it under the terms of the GNU Lesser General Public * + * License as published by the Free Software Foundation; either * + * version 2.1 of the License, or (at your option) any later version. * + * * + * hpgs is distributed in the hope that it will be useful, * + * but WITHOUT ANY WARRANTY; without even the implied warranty of * + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * + * Lesser General Public License for more details. * + * * + * You should have received a copy of the GNU Lesser General Public * + * License along with this library; if not, write to the * + * Free Software Foundation, Inc., 59 Temple Place, Suite 330, * + * Boston, MA 02111-1307 USA * + * * + *********************************************************************** + * * + * The implementation of the HPGL reader. * + * * + ***********************************************************************/ + +#include +#include +#include +#include + +/* + Internal +*/ +static int hpgs_reader_set_number_of_pens(hpgs_reader *reader, int npens) +{ + double *pw =(double *)realloc(reader->pen_widths,npens*sizeof(double)); + + if (!pw) + return hpgs_set_error(hpgs_i18n("Out of memory growing pen width array.")); + + reader->pen_widths = pw; + + hpgs_color *pc = (hpgs_color *)realloc(reader->pen_colors,npens*sizeof(hpgs_color)); + + if (!pc) + return hpgs_set_error(hpgs_i18n("Out of memory growing pen color array.")); + + reader->pen_colors = pc; + + for (;reader->npensnpens) + { + reader->pen_widths[reader->npens] = 1.0; + reader->pen_colors[reader->npens].r = 0.0; + reader->pen_colors[reader->npens].g = 0.0; + reader->pen_colors[reader->npens].b = 0.0; + } + + return 0; +} + +/* + Do the pen select. +*/ +int hpgs_reader_do_setpen(hpgs_reader *reader, int pen) +{ + double width; + + if (hpgs_reader_checkpath(reader)) return -1; + + if (pen < 0) + return hpgs_set_error(hpgs_i18n("Illegal pen numer %d."),pen); + + if (pen >= reader->npens) + { + if (pen < 256) + { + if (hpgs_reader_set_number_of_pens(reader,pen+1)) + return -1; + } + else + { + if (reader->verbosity) + hpgs_log(hpgs_i18n("Illegal pen number %d replaced by %d.\n"), + pen, pen % reader->npens); + pen = pen % reader->npens; + } + } + + reader->current_pen = pen; + + width = reader->pen_widths[pen]; + + if (reader->pen_width_relative) + width *= hypot(reader->P2.x-reader->P1.x, + reader->P2.y-reader->P1.y ) * 0.001 * HP_TO_PT; + else + width *= HP_TO_PT / reader->world_scale; + + width *= reader->page_scale; + + if (hpgs_setlinewidth(reader->device,width*reader->lw_factor)) + return -1; + + return hpgs_setrgbcolor(reader->device, + &reader->pen_colors[pen]); +} + +/* + HPGL command NP (Number of Pens) +*/ +int hpgs_reader_do_NP (hpgs_reader *reader) +{ + int npens=8; + + if (!reader->eoc && + hpgs_reader_read_int(reader,&npens)) return -1; + + if (npens <= reader->npens) return 0; + + return hpgs_reader_set_number_of_pens(reader,npens); +} + +/* + HPGL command SP (Set Pen) +*/ +int hpgs_reader_do_SP (hpgs_reader *reader) +{ + int pen=0; + + if (!reader->eoc && + hpgs_reader_read_int(reader,&pen)) return -1; + + return hpgs_reader_do_setpen(reader,pen); +} + +/* + HPGL command PC (Pen Color) +*/ +int hpgs_reader_do_PC (hpgs_reader *reader) +{ + int pen=-1; + double r=-1.0e20,g=-1.0e20,b=-1.0e20; + + if (!reader->eoc && hpgs_reader_read_int(reader,&pen)) return -1; + if (!reader->eoc && hpgs_reader_read_double(reader,&r)) return -1; + if (!reader->eoc && hpgs_reader_read_double(reader,&g)) return -1; + if (!reader->eoc && hpgs_reader_read_double(reader,&b)) return -1; + + if (pen >= reader->npens) + { + if (pen < 256) + { + if (hpgs_reader_set_number_of_pens(reader,pen+1)) + return -1; + } + else + { + if (reader->verbosity) + hpgs_log(hpgs_i18n("PC: Illegal pen number %d.\n"),pen); + + return 0; + } + } + + if (pen < 0) + { + hpgs_reader_set_std_pen_colors(reader,0,reader->npens); + pen = reader->current_pen; + } + else + { + if (r==-1.0e20 || g==-1.0e20 || b==-1.0e20) + { + hpgs_reader_set_std_pen_colors(reader,pen,1); + } + else + { + reader->pen_colors[pen].r = + (r - reader->min_color.r) / (reader->max_color.r - reader->min_color.r); + if (reader->pen_colors[pen].r < 0.0) reader->pen_colors[pen].r = 0.0; + if (reader->pen_colors[pen].r > 1.0) reader->pen_colors[pen].r = 1.0; + + reader->pen_colors[pen].g = + (g - reader->min_color.g) / (reader->max_color.g - reader->min_color.g); + if (reader->pen_colors[pen].g < 0.0) reader->pen_colors[pen].g = 0.0; + if (reader->pen_colors[pen].g > 1.0) reader->pen_colors[pen].g = 1.0; + + reader->pen_colors[pen].b = + (b - reader->min_color.b) / (reader->max_color.b - reader->min_color.b); + if (reader->pen_colors[pen].b < 0.0) reader->pen_colors[pen].b = 0.0; + if (reader->pen_colors[pen].b > 1.0) reader->pen_colors[pen].b = 1.0; + } + } + + if (pen == reader->current_pen) + if (hpgs_setrgbcolor(reader->device, + &reader->pen_colors[pen])) + return -1; + + return 0; +} + +/* + HPGL command CR (Color Range) +*/ +int hpgs_reader_do_CR (hpgs_reader *reader) +{ + reader->min_color.r = 0.0; + reader->min_color.g = 0.0; + reader->min_color.b = 0.0; + + reader->max_color.r = 255.0; + reader->max_color.g = 255.0; + reader->max_color.b = 255.0; + + if (!reader->eoc) + { + if (hpgs_reader_read_double(reader,&reader->min_color.r)) return -1; + if (reader->eoc) return -1; + if (hpgs_reader_read_double(reader,&reader->max_color.r)) return -1; + if (reader->eoc) return -1; + if (hpgs_reader_read_double(reader,&reader->min_color.g)) return -1; + if (reader->eoc) return -1; + if (hpgs_reader_read_double(reader,&reader->max_color.g)) return -1; + if (reader->eoc) return -1; + if (hpgs_reader_read_double(reader,&reader->min_color.b)) return -1; + if (reader->eoc) return -1; + if (hpgs_reader_read_double(reader,&reader->max_color.b)) return -1; + } + + return 0; +} + +/* + HPGL command LA (Line Attributes) +*/ +int hpgs_reader_do_LA(hpgs_reader *reader) +{ + int kind; + int ivalue; + double rvalue; + + static hpgs_line_cap caps[5] = + { hpgs_cap_butt, + hpgs_cap_butt, + hpgs_cap_square, + hpgs_cap_round, + hpgs_cap_round }; + + static hpgs_line_join joins[7] = + { hpgs_join_miter, + hpgs_join_miter, + hpgs_join_miter, + hpgs_join_miter, + hpgs_join_round, + hpgs_join_bevel, + hpgs_join_miter }; + + while (!reader->eoc) + { + if (hpgs_reader_read_int(reader,&kind)) return -1; + if (reader->eoc) return -1; + + switch (kind) + { + case 3: + if (hpgs_reader_read_double(reader,&rvalue)) return -1; + if (hpgs_setmiterlimit(reader->device,rvalue)) return -1; + break; + case 1: + if (hpgs_reader_read_int(reader,&ivalue)) return -1; + if (ivalue >= 0 && ivalue < 5 && + hpgs_setlinecap(reader->device,caps[ivalue])) return -1; + break; + case 2: + if (hpgs_reader_read_int(reader,&ivalue)) return -1; + if (ivalue >= 0 && ivalue < 7 && + hpgs_setlinejoin(reader->device,joins[ivalue])) return -1; + break; + default: + return -1; + } + } + return 0; +} + +/* + HPGL command LT (Line Type) +*/ +int hpgs_reader_do_LT(hpgs_reader *reader) +{ + float dashes[20]; + int i,ndash; + int linetype=0; + double patlen = 4.0; + int mode = 0; + + if (hpgs_reader_checkpath(reader)) return -1; + + if (!reader->eoc && + hpgs_reader_read_int(reader,&linetype)) return -1; + + if (!reader->eoc && + hpgs_reader_read_double(reader,&patlen)) return -1; + + if (!reader->eoc && + hpgs_reader_read_int(reader,&mode)) return -1; + + if (linetype < -8 || linetype > 8) + { + if (reader->verbosity) + hpgs_log(hpgs_i18n("LT: Illegal linetype %d.\n"),linetype); + return 0; + } + + // line type are store as percentages. + patlen *= 0.01; + + if (mode) + patlen *= MM_TO_PT; + else + patlen *= hypot(reader->P2.x-reader->P1.x, + reader->P2.y-reader->P1.y ) * 0.01 * HP_TO_PT; + + ndash = reader->linetype_nsegs[linetype+8]; + if (ndash > 20) ndash = 20; + + for (i=0;ilinetype_segs[linetype+8][i] * patlen; + + return hpgs_setdash(reader->device, + dashes,ndash,0.0); +} + +/* + HPGL command PW (Pen Width) +*/ +int hpgs_reader_do_PW (hpgs_reader *reader) +{ + int pen=-1; + double width=1.0; + + if (!reader->eoc) + if (hpgs_reader_read_double(reader,&width)) return -1; + if (!reader->eoc) + { + if (hpgs_reader_read_int(reader,&pen)) return -1; + + if (pen < 0 || pen >= reader->npens) + { + if (pen >= reader->npens && pen < 256) + { + if (hpgs_reader_set_number_of_pens(reader,pen+1)) + return -1; + } + else + { + if (reader->verbosity) + hpgs_log(hpgs_i18n("PW: Illegal pen number %d.\n"),pen); + + return 0; + } + } + } + + if (reader->verbosity >= 2) + hpgs_log("PW: pen,width,rel = %d,%g,%d.\n",pen,width,reader->pen_width_relative); + + if (reader->pen_width_relative) + width *= 10.0; + else + width *= MM_TO_PT; + + if (pen < 0) + { + int i; + for (i=0;inpens;++i) + reader->pen_widths[i] = width; + } + else + reader->pen_widths[pen] = width; + + if (pen < 0 || pen == reader->current_pen) + { + if (hpgs_reader_checkpath(reader)) return -1; + + if (reader->pen_width_relative) + width *= hypot(reader->P2.x-reader->P1.x, + reader->P2.y-reader->P1.y ) * 0.001 * HP_TO_PT; + else + width *= HP_TO_PT / reader->world_scale; + + width *= reader->page_scale; + + if (hpgs_setlinewidth(reader->device,width*reader->lw_factor)) + return -1; + } + + return 0; +} + +/* + HPGL command WU (Width Unit selection) +*/ +int hpgs_reader_do_WU (hpgs_reader *reader) +{ + reader->pen_width_relative=0; + + if (!reader->eoc && + hpgs_reader_read_int(reader,&reader->pen_width_relative)) return -1; + return 0; +} + diff --git a/src/add-ons/translators/hpgs/lib/hpgspjl.c b/src/add-ons/translators/hpgs/lib/hpgspjl.c new file mode 100644 index 0000000000..c9a0cafa04 --- /dev/null +++ b/src/add-ons/translators/hpgs/lib/hpgspjl.c @@ -0,0 +1,261 @@ +/*********************************************************************** + * * + * $Id: hpgspjl.c 384 2007-03-18 18:31:15Z softadm $ + * * + * hpgs - HPGl Script, a hpgl/2 interpreter, which uses a Postscript * + * API for rendering a scene and thus renders to a variety of * + * devices and fileformats. * + * * + * (C) 2004-2006 ev-i Informationstechnologie GmbH http://www.ev-i.at * + * * + * Author: Wolfgang Glas * + * * + * hpgs is free software; you can redistribute it and/or * + * modify it under the terms of the GNU Lesser General Public * + * License as published by the Free Software Foundation; either * + * version 2.1 of the License, or (at your option) any later version. * + * * + * hpgs is distributed in the hope that it will be useful, * + * but WITHOUT ANY WARRANTY; without even the implied warranty of * + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * + * Lesser General Public License for more details. * + * * + * You should have received a copy of the GNU Lesser General Public * + * License along with this library; if not, write to the * + * Free Software Foundation, Inc., 59 Temple Place, Suite 330, * + * Boston, MA 02111-1307 USA * + * * + *********************************************************************** + * * + * The implementation of the PJL interpreter. * + * * + ***********************************************************************/ + +#include +#include +#include +#include +#include + +//#define HPGS_PJL_DEBUG + +static int pjl_read_line (hpgs_reader *reader, char term, char *buf, size_t buf_size) +{ + int i=0; + + while ((reader->last_byte = hpgs_getc(reader->in)) != EOF) + { + if (i == 0 && reader->last_byte== HPGS_ESC) + { + hpgs_ungetc(reader->last_byte,reader->in); + return -2; + } + + if (reader->last_byte==term) + { + while ((reader->last_byte = hpgs_getc(reader->in)) != EOF) + if (!isspace(reader->last_byte)) + { + hpgs_ungetc(reader->last_byte,reader->in); + break; + } + + while (i > 0 && (buf[i-1]=='\0' || isspace(buf[i-1]))) + --i; + + if (ilast_byte == '\n' && i==4 && strncmp(buf,"@PJL",4)==0) + { + i=0; + continue; + } + + if (reader->last_byte == '\n') continue; + + if (reader->last_byte != '\r' && ilast_byte : '\0'; + ++i; + } + } + + return EOF; +} + +/*! + Read a PJL block of the file. + + Return values: + \li -1 Error, unexpected EOF. + \li 0 Success, ESC found, continue with ESC evaluation. + \li 1 Success, return to HPGL context. + \li 2 Success, plotsize set, skip interpretation of file. + \li 3 Success, go to PCL context. +*/ +int hpgs_reader_do_PJL(hpgs_reader *reader) +{ + char buf[256]; + int r,arg,arg_sign; + int x_size = 0; + int y_size = 0; + reader->bytes_ignored = 0; + reader->eoc = 0; + size_t pos = 0; + + while ((r=pjl_read_line(reader,' ',buf,sizeof(buf))) != EOF) + { + if (r==-2) return 0; // ESC found. + + // HPGL autodetection. + if (pos >= 0 && r>=2 && + buf[0] >= 'A' && buf[0] <= 'Z' && + buf[1] >= 'A' && buf[1] <= 'Z' ) + { + if (hpgs_istream_seek(reader->in,pos)) + return -1; + + // overtake PCL papersize, if given. + if (x_size > 0 && y_size > 0) + { + // PJL paper sizes are apparently in PCL units. + x_size *= reader->pcl_scale/HP_TO_PT; + y_size *= reader->pcl_scale/HP_TO_PT; + + if (reader->verbosity) + hpgs_log(hpgs_i18n("Setting PJL papersize %dx%d.\n"),x_size,y_size); + + switch (hpgs_reader_set_plotsize(reader,x_size,y_size)) + { + case 2: + return 2; + case 0: + break; + default: + return -1; + } + } + + // return to HPGL context. + return 1; + } + + if (strcmp(buf,"@PJL")) + return hpgs_set_error(hpgs_i18n("Illegal line heading <%s> in PJL."),buf); + if (pjl_read_line(reader,' ',buf,sizeof(buf)) < 0) + return -1; + + if (strcmp(buf,"SET") == 0) + { + if (pjl_read_line(reader,'=',buf,sizeof(buf)) < 0) + return -1; + + if (strcmp(buf,"PAPERLENGTH") == 0) + { + switch (hpgs_reader_read_pcl_int(reader,&arg,&arg_sign)) + { + case -1: + return -1; + case 1: + break; + default: + return hpgs_set_error(hpgs_i18n("Missing number in PJL SET PAPERLENGTH.")); + } + + x_size = arg; + } + else if (strcmp(buf,"PAPERWIDTH") == 0) + { + switch (hpgs_reader_read_pcl_int(reader,&arg,&arg_sign)) + { + case -1: + return -1; + case 1: + break; + default: + return hpgs_set_error(hpgs_i18n("Missing number in PJL SET PAPERWIDTH.")); + } + + y_size = arg; + } + else if (strcmp(buf,"RESOLUTION") == 0) + { + switch (hpgs_reader_read_pcl_int(reader,&arg,&arg_sign)) + { + case -1: + return -1; + case 1: + break; + default: + return hpgs_set_error(hpgs_i18n("Missing number in PJL SET RESOLUTION.")); + } + + reader->pcl_scale = 72.0/(double)arg; + reader->pcl_raster_res = arg; + } + } + else if (strcmp(buf,"ENTER") == 0) + { + if (pjl_read_line(reader,'=',buf,sizeof(buf)) < 0) + return -1; + + if (strcmp(buf,"LANGUAGE") == 0) + { + if (pjl_read_line(reader,'\n',buf,sizeof(buf)) < 0) + return -1; + + if (x_size > 0 && y_size > 0) + { + // PJL paper sizes are apparently in PCL units. + x_size *= reader->pcl_scale/HP_TO_PT; + y_size *= reader->pcl_scale/HP_TO_PT; + + if (reader->verbosity) + hpgs_log(hpgs_i18n("Setting PJL papersize %dx%d\n"),x_size,y_size); + + switch (hpgs_reader_set_plotsize(reader,x_size,y_size)) + { + case 2: + return 2; + case 0: + break; + default: + return -1; + } + } + + if (strcmp(buf,"HPGL2") == 0 || + strcmp(buf,"HPGL/2") == 0 || + strcmp(buf,"HP-GL2") == 0 || + strcmp(buf,"HP-GL/2") == 0 ) + { + // probe for escape character + if ((reader->last_byte = hpgs_getc(reader->in)) == EOF) + return -1; + + hpgs_ungetc(reader->last_byte,reader->in); + return reader->last_byte == HPGS_ESC ? 0 : 1; + } + else if (strcmp(buf,"PCL3GUI") == 0 || + strcmp(buf,"PCL3") == 0 || + strcmp(buf,"PCL5") == 0 ) + return 3; + else + return hpgs_set_error(hpgs_i18n("Invalid language <%s> in PJL ENTER LANGUAGE."), + buf); + } + } + + if (pjl_read_line(reader,'\n',buf,sizeof(buf)) < 0) + return -1; + + // store position for HPGL autodetection. + if (hpgs_istream_tell(reader->in,&pos)) + return hpgs_set_error(hpgs_i18n("Cannot get file position in PJL interpretation.")); + } + + return -1; +} diff --git a/src/add-ons/translators/hpgs/lib/hpgsplugin.h b/src/add-ons/translators/hpgs/lib/hpgsplugin.h new file mode 100644 index 0000000000..787dfb3b3b --- /dev/null +++ b/src/add-ons/translators/hpgs/lib/hpgsplugin.h @@ -0,0 +1,87 @@ +/*********************************************************************** + * * + * $Id: hpgsplugin.h 325 2006-04-22 20:01:11Z softadm $ + * * + * hpgs - HPGl Script, a hpgl/2 interpreter, which uses a Postscript * + * API for rendering a scene and thus renders to a variety of * + * devices and fileformats. * + * * + * (C) 2004-2006 ev-i Informationstechnologie GmbH http://www.ev-i.at * + * * + * Author: Wolfgang Glas * + * * + * hpgs is free software; you can redistribute it and/or * + * modify it under the terms of the GNU Lesser General Public * + * License as published by the Free Software Foundation; either * + * version 2.1 of the License, or (at your option) any later version. * + * * + * hpgs is distributed in the hope that it will be useful, * + * but WITHOUT ANY WARRANTY; without even the implied warranty of * + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * + * Lesser General Public License for more details. * + * * + * You should have received a copy of the GNU Lesser General Public * + * License along with this library; if not, write to the * + * Free Software Foundation, Inc., 59 Temple Place, Suite 330, * + * Boston, MA 02111-1307 USA * + * * + *********************************************************************** + * * + * The extension classes located in my device plugin. * + * * + ***********************************************************************/ + +#ifndef __HPGS_PLUGIN_H +#define __HPGS_PLUGIN_H + +#include + +#ifdef __cplusplus +extern "C" { +#endif + +#ifdef HPGS_SHARED +# ifdef WIN32 +# ifdef __GNUC__ +# ifdef HPGS_BUILD_PLUGIN +# define HPGS_PLUGIN_API __attribute__((dllexport)) +# else +# define HPGS_PLUGIN_API __attribute__((dllimport)) +# endif +# else +# ifdef HPGS_BUILD_PLUGIN +# define HPGS_PLUGIN_API __declspec(dllexport) +# else +# define HPGS_PLUGIN_API __declspec(dllimport) +# endif +# endif +# else +# define HPGS_PLUGIN_API +# endif +#else +# define HPGS_PLUGIN_API +#endif + + +HPGS_PLUGIN_API int hpgs_plugin_new_device(hpgs_device **device, + void **asset_ctxt, + hpgs_reader_asset_func_t *page_asset_func, + void **frame_asset_ctxt, + hpgs_reader_asset_func_t *frame_asset_func, + const char *dev_name, + const char *out_fn, + const hpgs_bbox *bb, + double xres, double yres, + hpgs_bool do_rop3, + int argc, const char *argv[]); + +HPGS_PLUGIN_API void hpgs_plugin_version(int * major, int *minor); + +HPGS_PLUGIN_API void hpgs_plugin_init(); +HPGS_PLUGIN_API void hpgs_plugin_cleanup(); + +#ifdef __cplusplus +} // end of extern "C" +#endif + +#endif /* ! __HPGS_H */ diff --git a/src/add-ons/translators/hpgs/lib/hpgsreader.c b/src/add-ons/translators/hpgs/lib/hpgsreader.c new file mode 100644 index 0000000000..af2d918202 --- /dev/null +++ b/src/add-ons/translators/hpgs/lib/hpgsreader.c @@ -0,0 +1,1050 @@ +/*********************************************************************** + * * + * $Id: hpgsreader.c 382 2007-02-20 11:26:16Z softadm $ + * * + * hpgs - HPGl Script, a hpgl/2 interpreter, which uses a Postscript * + * API for rendering a scene and thus renders to a variety of * + * devices and fileformats. * + * * + * (C) 2004-2006 ev-i Informationstechnologie GmbH http://www.ev-i.at * + * * + * Author: Wolfgang Glas * + * * + * hpgs is free software; you can redistribute it and/or * + * modify it under the terms of the GNU Lesser General Public * + * License as published by the Free Software Foundation; either * + * version 2.1 of the License, or (at your option) any later version. * + * * + * hpgs is distributed in the hope that it will be useful, * + * but WITHOUT ANY WARRANTY; without even the implied warranty of * + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * + * Lesser General Public License for more details. * + * * + * You should have received a copy of the GNU Lesser General Public * + * License along with this library; if not, write to the * + * Free Software Foundation, Inc., 59 Temple Place, Suite 330, * + * Boston, MA 02111-1307 USA * + * * + *********************************************************************** + * * + * The implementation of the HPGL reader. * + * * + ***********************************************************************/ + +#include +#include +#include +#include +#include + +/*! + Contructs a HPGL reader on the heap using the given input device + \c in and the given output vector drawing device \c dev. + + The argument \c multipage specifies, whether the reader processes more than + one page. + + The argument \c v specifies the verbosity of the HPGL reader. + A value of 0 forces the reader to not report anything to \c hpgs_log(). + Value of 1 or 2 give diagnostics output to \c hpgs_log() with increasing + volume. + + You do not have to call neither \c hpgs_close on \c in nor + \c hpgs_destroy on \c dev. + + In the case of an error, a null pointer is returned. This only happens, + if the system is out of memory. +*/ +hpgs_reader *hpgs_new_reader(hpgs_istream *in, hpgs_device *dev, + hpgs_bool multipage, int v) +{ + int i; + hpgs_reader *ret = (hpgs_reader *)malloc(sizeof(hpgs_reader)); + + if (!ret) + { + hpgs_istream_close(in); + if (dev) + hpgs_device_destroy(dev); + return 0; + } + + ret->in = in; + ret->device = dev; + ret->verbosity = v; + ret->lw_factor = 1.0; + + ret->plotsize_device = 0; + ret->current_page = multipage ? 1 : -1; + + hpgs_matrix_set_identity(&ret->page_matrix); + ret->page_scale = 1.0; + + ret->page_bbox.llx = 0.0; + ret->page_bbox.lly = 0.0; + + ret->page_bbox.urx = 33600.0 * HP_TO_PT; + ret->page_bbox.ury = 47520.0 * HP_TO_PT; + + ret->content_bbox = ret->page_bbox; + ret->page_asset_ctxt = 0; + ret->page_asset_func = 0; + ret->frame_asset_ctxt = 0; + ret->frame_asset_func = 0; + + ret->page_mode=0; + + ret->page_width = 0.0; + ret->page_height = 0.0; + ret->page_angle = 0.0; + ret->page_border = 0.0; + + ret->pen_widths = NULL; + ret->pen_colors = NULL; + ret->poly_buffer = NULL; + + for (i=0;i<8;++i) + ret->pcl_raster_data[i] = 0; + + ret->pcl_image=0; + ret->png_dump_filename=0; + ret->png_dump_count=0; + ret->pcl_i_palette=-1; + + ret->interrupted = HPGS_FALSE; + + hpgs_reader_set_defaults (ret); + + return ret; +} + +/*! + Interrupt a currently running call to \c hpgs_reader_read from another + thread. There's no guarantee when \c hpgs_read will terminate after + calling \c hpgs_reader_interrupt. If the reader is currently performing + a time-consuming task like rendering a large imge to the device, + \c hpgs_read may continue for several seconds after this call. +*/ +void hpgs_reader_interrupt(hpgs_reader *reader) +{ + reader->interrupted = HPGS_TRUE; +} + +/*! + Set the factor \c lw_factor for scaling HPGL + linewidths to output linewidths. Usually you set this factor to 1.0, + although for rendering to pixel device with a low resolution + a factor of 0.5 may be useful to enforce the creation of thin + lines. +*/ +void hpgs_reader_set_lw_factor(hpgs_reader *reader, double lw_factor) +{ + reader->lw_factor=lw_factor; +} + +/*! + Sets a vector drawing device to a HPGL reader an resets the input + stream. + + The function return 0 in any case. +*/ +int hpgs_reader_imbue(hpgs_reader *reader, hpgs_device *dev) +{ + if (reader->device) + { + // overtake a plotsize device for transferring individual plot sizes + // for each page. + if (hpgs_device_capabilities(reader->device) & HPGS_DEVICE_CAP_PLOTSIZE) + { + if (reader->plotsize_device) + hpgs_device_destroy(reader->plotsize_device); + + reader->plotsize_device = reader->device; + } + else + hpgs_device_destroy(reader->device); + } + + reader->device = dev; + + if (reader->current_page <= 0) + reader->current_page = -1; + else + reader->current_page = 1; + + hpgs_reader_set_defaults (reader); + + return hpgs_istream_seek(reader->in,0); +} + +/*! + Attach a new input stream to a HPGL reader. This is useful + in multipage mode in order to collate multiple input files. + + The function return 0 in any case. +*/ +int hpgs_reader_attach(hpgs_reader *reader, hpgs_istream *in) +{ + if (reader->in) + hpgs_istream_close(reader->in); + + reader->in = in; + return 0; +} + +static int skip_ESC_block (hpgs_reader *reader) +{ + int arg = 0; + int arg_sign = 0; + int r; + + while (1) + { + switch (reader->bytes_ignored) + { + case 1: + if (reader->last_byte != HPGS_ESC) + reader->bytes_ignored = 0; + break; + case 2: + if (reader->last_byte == '.') + { + reader->last_byte = hpgs_getc(reader->in); + if (reader->last_byte == EOF) + return 1; + + // .( or .Y interpretation. + if (reader->last_byte == '(' || + reader->last_byte == 'Y' ) + return 0; + + reader->bytes_ignored = 0; + break; + } + + if (reader->last_byte != '%') + reader->bytes_ignored = 0; + break; + case 3: + switch (hpgs_reader_read_pcl_int(reader,&arg,&arg_sign)) + { + case -1: + return 1; + case 1: + break; + default: + reader->bytes_ignored = 0; + } + + break; + case 4: + reader->bytes_ignored = 0; + switch (reader->last_byte) + { + case 'B': + return 0; + case 'A': + r = hpgs_reader_do_PCL(reader,arg); + if (r <= 0) return r; + if (r==2) return 1; + case 'X': + r=1; + while (r) + switch (hpgs_reader_do_PJL(reader)) + { + case 0: // ESC found. + r = 0; + break; + case 1: // Enter HPGL mode. + return 0; + case 2: // plotsize found. skip rest of file. + return 1; + case 3: // Enter PCL mode. + r = hpgs_reader_do_PCL(reader,arg); + if (r <= 0) return r; + if (r==2) return 1; + break; + default: /* EOF, error */ + return 1; + } + } + break; + default: + reader->bytes_ignored = 0; + } + + if (reader->bytes_ignored != 2) + { + reader->last_byte = hpgs_getc(reader->in); + if (reader->last_byte == EOF) + return 1; + } + + ++reader->bytes_ignored; + } +} + +// skip until we reach 'ENDMF;' +static int skip_MF_block (hpgs_reader *reader, const char *stop_seq) +{ + while (1) + { + if (reader->bytes_ignored > 0) + { + if (reader->last_byte != stop_seq[reader->bytes_ignored-1]) + reader->bytes_ignored = 0; + } + + if (stop_seq[reader->bytes_ignored] == '\0') + { + reader->bytes_ignored = 0; + return 0; + } + + reader->last_byte = hpgs_getc(reader->in); + if (reader->last_byte == EOF) + return 1; + + ++reader->bytes_ignored; + } +} + +// a function which recovers from a malformed command. +static int hpgl_recover(hpgs_reader *reader) +{ + size_t pos; + + if (hpgs_istream_tell(reader->in,&pos)) + return -1; + + reader->bytes_ignored = 0; + + while (reader->bytes_ignored < 256 && + (reader->last_byte = hpgs_getc(reader->in)) != ';') + { + if (reader->last_byte == EOF) + return hpgs_set_error(hpgs_i18n("EOF during recovery from malformed HPGL command at file position %lu."),(unsigned long)pos); + + ++reader->bytes_ignored; + } + + if (reader->bytes_ignored >= 256) + return hpgs_set_error(hpgs_i18n("No semicolon in the next 256 bytes during recovery from malformed HPGL command at file position %lu."),(unsigned long)pos); + + reader->bytes_ignored = 0; + reader->eoc = 1; + + return 0; +} + +// this is a sorted table of hpgl commands and corersponding funtions. +typedef struct hpgs_reader_hpglcmd_rec_st hpgs_reader_hpglcmd_rec; + +struct hpgs_reader_hpglcmd_rec_st +{ + int cmd; + hpgs_reader_hpglcmd_func_t func; +}; + +static hpgs_reader_hpglcmd_rec hpglcmds[] = + { + { AA_CMD, hpgs_reader_do_AA }, + { AC_CMD, hpgs_reader_do_AC }, + { AD_CMD, hpgs_reader_do_AD }, + { AR_CMD, hpgs_reader_do_AR }, + { AT_CMD, hpgs_reader_do_AT }, + { BP_CMD, hpgs_reader_do_BP }, + { BR_CMD, hpgs_reader_do_BR }, + { BZ_CMD, hpgs_reader_do_BZ }, + { CI_CMD, hpgs_reader_do_CI }, + { CO_CMD, hpgs_reader_do_CO }, + { CP_CMD, hpgs_reader_do_CP }, + { CR_CMD, hpgs_reader_do_CR }, + { DI_CMD, hpgs_reader_do_DI }, + { DR_CMD, hpgs_reader_do_DR }, + { DT_CMD, hpgs_reader_do_DT }, + { DV_CMD, hpgs_reader_do_DV }, + { EA_CMD, hpgs_reader_do_EA }, + { EP_CMD, hpgs_reader_do_EP }, + { ER_CMD, hpgs_reader_do_ER }, + { ES_CMD, hpgs_reader_do_ES }, + { EW_CMD, hpgs_reader_do_EW }, + { FP_CMD, hpgs_reader_do_FP }, + { FR_CMD, hpgs_reader_do_FR }, + { FT_CMD, hpgs_reader_do_FT }, + { IN_CMD, hpgs_reader_do_IN }, + { IP_CMD, hpgs_reader_do_IP }, + { IR_CMD, hpgs_reader_do_IR }, + { IW_CMD, hpgs_reader_do_IW }, + { LA_CMD, hpgs_reader_do_LA }, + { LB_CMD, hpgs_reader_do_LB }, + { LO_CMD, hpgs_reader_do_LO }, + { LT_CMD, hpgs_reader_do_LT }, + { MC_CMD, hpgs_reader_do_MC }, + { MG_CMD, hpgs_reader_do_MG }, + { NP_CMD, hpgs_reader_do_NP }, + { PA_CMD, hpgs_reader_do_PA }, + { PC_CMD, hpgs_reader_do_PC }, + { PD_CMD, hpgs_reader_do_PD }, + { PE_CMD, hpgs_reader_do_PE }, + { PG_CMD, hpgs_reader_do_PG }, + { PM_CMD, hpgs_reader_do_PM }, + { PP_CMD, hpgs_reader_do_PP }, + { PR_CMD, hpgs_reader_do_PR }, + { PS_CMD, hpgs_reader_do_PS }, + { PU_CMD, hpgs_reader_do_PU }, + { PW_CMD, hpgs_reader_do_PW }, + { RA_CMD, hpgs_reader_do_RA }, + { RO_CMD, hpgs_reader_do_RO }, + { RR_CMD, hpgs_reader_do_RR }, + { RT_CMD, hpgs_reader_do_RT }, + { SA_CMD, hpgs_reader_do_SA }, + { SC_CMD, hpgs_reader_do_SC }, + { SD_CMD, hpgs_reader_do_SD }, + { SI_CMD, hpgs_reader_do_SI }, + { SL_CMD, hpgs_reader_do_SL }, + { SM_CMD, hpgs_reader_do_SM }, + { SP_CMD, hpgs_reader_do_SP }, + { SR_CMD, hpgs_reader_do_SR }, + { SS_CMD, hpgs_reader_do_SS }, + { TR_CMD, hpgs_reader_do_TR }, + { UL_CMD, hpgs_reader_do_UL }, + { WG_CMD, hpgs_reader_do_WG }, + { WU_CMD, hpgs_reader_do_WU } + }; + +/*! + Interprets the input stream associated with \c reader and + passes the result to the associated vector device. + + The argument \c finish specifies, whether this is the last + file written to the underlying \c hpgs_device. + If \c finish is \c HPGS_TRUE, \c hpgs_device_finish is called. + Otherwise, another input stream may be attached using + \c hpgs_reader_attach and \c hpgs_read may be called again. + This way, multiple input files may collated together in a single + output file. + + The function return 0 upon success. + A value of -1 is returned, when an error is encountered. + + You have to call \c hpgs_reader_get_error in order to + retrieve the error message in the latter case. +*/ +int hpgs_read(hpgs_reader *reader, hpgs_bool finish) +{ + int command=0; + int status = 0; + int i0,i1; + int ncmds = sizeof(hpglcmds)/sizeof(hpgs_reader_hpglcmd_rec); + hpgs_bool oce_special=HPGS_FALSE; /* Did we find *OceJobBegin ? */ + + hpgs_clear_error(); + + // restart for single page devices. + if (reader->current_page <= 0) + reader->current_page = -1; + else + { + // try to set the individual page size in multipage mode. + if (reader->plotsize_device && + (hpgs_device_capabilities(reader->device) & HPGS_DEVICE_CAP_MULTISIZE)) + { + hpgs_bbox page_bb; + + if (hpgs_getplotsize(reader->plotsize_device,reader->current_page,&page_bb) < 0) + goto syntax_error; + + if (reader->verbosity) + hpgs_log("Bounding Box of Page %d: %g %g %g %g.\n", + reader->current_page, + page_bb.llx,page_bb.lly, + page_bb.urx,page_bb.ury ); + + // change the page layout. + hpgs_reader_set_page_matrix(reader,&page_bb); + hpgs_reader_set_default_transformation(reader); + + if (hpgs_setplotsize(reader->device,&reader->page_bbox) < 0) + goto syntax_error; + } + } + + hpgs_reader_set_defaults (reader); + + if (hpgs_istream_seek(reader->in,0)) + return hpgs_set_error("I/O Error rewinding input stream."); + + /* Check for a BEGMF stanza. */ + if (hpgs_getc(reader->in) == 'B' && + hpgs_getc(reader->in) == 'E' && + hpgs_getc(reader->in) == 'G' && + hpgs_getc(reader->in) == 'M' && + hpgs_getc(reader->in) == 'F' ) + { + // just skip until we reach ENDMF... + if (skip_MF_block (reader,"ENDMF;")) + return hpgs_set_error(hpgs_i18n("Unexpected EOF after BEGMF;.")); + } + else + { + if (hpgs_istream_seek(reader->in,0)) + return hpgs_set_error(hpgs_i18n("I/O Error rewinding input stream.")); + + if (hpgs_getc(reader->in) == '*' && + hpgs_getc(reader->in) == 'O' && + hpgs_getc(reader->in) == 'c' && + hpgs_getc(reader->in) == 'e' && + hpgs_getc(reader->in) == 'J' && + hpgs_getc(reader->in) == 'o' && + hpgs_getc(reader->in) == 'b' && + hpgs_getc(reader->in) == 'B' && + hpgs_getc(reader->in) == 'e' && + hpgs_getc(reader->in) == 'g' && + hpgs_getc(reader->in) == 'i' && + hpgs_getc(reader->in) == 'n' ) + { + // just skip until we reach OceJobData... + if (skip_MF_block (reader,"*OceJobData")) + return hpgs_set_error(hpgs_i18n("Unexpected EOF after *OceJobBegin.")); + + oce_special = HPGS_TRUE; + } + else + { + if (hpgs_istream_seek(reader->in,0)) + return hpgs_set_error(hpgs_i18n("I/O Error rewinding input stream.")); + } + } + + while (!hpgs_istream_iseof(reader->in)) + { + start_of_command: + if (reader->interrupted) goto syntax_error; + + // build command + if (reader->bytes_ignored == 0) + { + do + { + reader->last_byte = hpgs_getc(reader->in); + if (reader->last_byte == EOF) + goto end_of_file; + } + while (!isalpha(reader->last_byte) && reader->last_byte!=HPGS_ESC && + (!oce_special || reader->last_byte != '*')); + reader->bytes_ignored = 1; + } + + if (reader->bytes_ignored == 1) + { + if (oce_special && reader->last_byte == '*') + { + if (hpgs_getc(reader->in) == 'O' && + hpgs_getc(reader->in) == 'c' && + hpgs_getc(reader->in) == 'e' && + hpgs_getc(reader->in) == 'J' && + hpgs_getc(reader->in) == 'o' && + hpgs_getc(reader->in) == 'b' && + hpgs_getc(reader->in) == 'E' && + hpgs_getc(reader->in) == 'n' && + hpgs_getc(reader->in) == 'd' ) + { + if (reader->verbosity) + hpgs_log("Found *OceJobEnd, skipping rest of file.\n"); + + goto end_of_file; + } + + return hpgs_set_error(hpgs_i18n("Invalid *-command after *OceJobData.")); + } + + while (reader->last_byte == HPGS_ESC) + { + command = 0; + switch (skip_ESC_block(reader)) + { + case 1: + goto end_of_file; + case -1: + goto syntax_error; + } + + reader->last_byte = hpgs_getc(reader->in); + if (reader->last_byte == EOF) + goto end_of_file; + } + + reader->bytes_ignored = reader->last_byte == ';' ? 0 : 1; + + command = toupper(reader->last_byte); + } + + while (reader->bytes_ignored < 2) + { + reader->last_byte=hpgs_getc(reader->in); + if (reader->last_byte==EOF) + return hpgs_set_error(hpgs_i18n("Unexpected EOF between commands.")); + + if (reader->last_byte == ';') + { + reader->bytes_ignored = 0; + continue; + } + + if (!isalpha(reader->last_byte)) + { + if (hpgl_recover(reader)) + return -1; + else + goto start_of_command; + } + + command = ((command & 0xff) << 8) | toupper(reader->last_byte); + ++reader->bytes_ignored; + } + + // check for empty command. + reader->bytes_ignored = 0; + + if (command != LB_CMD && command != DT_CMD && command != PE_CMD) + { + do + { + reader->last_byte = hpgs_getc(reader->in); + } + while (isspace(reader->last_byte)); + + if (reader->last_byte==EOF || reader->last_byte== ';') + reader->eoc = 1; + else if (isalpha(reader->last_byte) || reader->last_byte == HPGS_ESC) + { + reader->bytes_ignored = 1; + reader->eoc = 1; + } + else + { + hpgs_ungetc(reader->last_byte,reader->in); + reader->eoc = 0; + } + } + else + reader->eoc = 0; + + if (reader->interrupted) goto syntax_error; + + if (reader->verbosity >= 2) + hpgs_log("Command %c%c found.\n", + (char)(command >> 8),(char)(command&0xff)); + + // do a binary search in the command table. + i0 = 0; + i1 = ncmds; + + while (i1>i0) + { + int i = i0+(i1-i0)/2; + + if (hpglcmds[i].cmd < command) + i0 = i+1; + else + i1 = i; + } + + if (i0 < ncmds && hpglcmds[i0].cmd == command) + // command found -> exec. + status = hpglcmds[i0].func(reader); + else + { + // interpret unknown command. + if (reader->verbosity) + { + size_t pos=0; + hpgs_istream_tell(reader->in,&pos); + + hpgs_log(hpgs_i18n("Unknown command %c%c found at file position %lu.\n"), + (char)(command >> 8),(char)(command&0xff),(unsigned long)pos); + } + + while (!reader->eoc) + { + double x; + if (hpgs_reader_read_double(reader,&x)) + { + if (hpgl_recover(reader)) + return -1; + else + goto start_of_command; + } + } + } + + if (status == 2) goto end_of_file; + if (status) goto syntax_error; + + if (!reader->eoc) + { + size_t pos=0; + hpgs_istream_tell(reader->in,&pos); + + return hpgs_set_error(hpgs_i18n("Trailing garbage in command %c%c at file position %lu."), + (char)(command >> 8),(char)(command&0xff),(unsigned long)pos); + } + } + + end_of_file: + + while (reader->clipsave_depth > 0) + { + hpgs_cliprestore(reader->device); + --reader->clipsave_depth; + } + + // enforce a showpage + if ((reader->current_page == -1 || reader->current_page == 1) && + hpgs_reader_showpage(reader,0) < 0) + { + size_t pos=0; + hpgs_istream_tell(reader->in,&pos); + + return hpgs_error_ctxt("Error showing a single page at file position " HPGS_SIZE_T_FMT, + pos); + } + + if (finish && hpgs_device_finish(reader->device)) + { + size_t pos=0; + hpgs_istream_tell(reader->in,&pos); + + return hpgs_error_ctxt("Error finishing plot at file position " HPGS_SIZE_T_FMT, + pos); + } + + return 0; + + syntax_error: + { + char cmd_str[20]; + size_t pos=0; + hpgs_istream_tell(reader->in,&pos); + + if (command) + snprintf(cmd_str,sizeof(cmd_str),hpgs_i18n("command %c%c"), + (char)(command >> 8),(char)(command&0xff)); + else + strcpy(cmd_str,hpgs_i18n("PCL command")); + + if (reader->interrupted) + return hpgs_set_error(hpgs_i18n("The HPGL interpreter has been interrupted in %s at file position %lu."), + cmd_str,(unsigned long)pos); + else if (hpgs_istream_iserror(reader->in)) + return hpgs_set_error(hpgs_i18n("Read error in %s at file position %lu."), + cmd_str,(unsigned long)pos); + else if (hpgs_have_error()) + return hpgs_error_ctxt(hpgs_i18n("Error in %s at file position %lu."), + cmd_str,(unsigned long)pos); + else if (hpgs_istream_iseof(reader->in)) + return hpgs_set_error(hpgs_i18n("Unexpected EOF in %s at file position %lu."), + cmd_str,(unsigned long)pos); + else + return hpgs_set_error(hpgs_i18n("Syntax error in %s at position %lu."), + cmd_str,(unsigned long)pos); + } +} + +/*! + Force the placement of the content on a fixed page. + Call this subroutine after you determined the plot size using + a plotsize device. + + \c page_width and \c page_height specifiy the dimension of the + page in point (1/72 inch). \c border specifies the border from the + page to the HPGL content. + + \c bbox holds the bounding box of the HPGL content of the first + page on input and on output, the bounding box of the whole page + is returned. The returned bounding box should be used to set up + your device, which will be passed to \c hpgs_reader_imbue after + issuing this call. +*/ +void hpgs_reader_set_fixed_page(hpgs_reader *reader, + hpgs_bbox *bbox, + double page_width, + double page_height, + double border, + double angle ) +{ + reader->page_mode = 1; + reader->page_width = page_width; + reader->page_height = page_height; + reader->page_border = border; + reader->page_angle = angle; + + // change the page layout. + hpgs_reader_set_page_matrix(reader,bbox); + hpgs_reader_set_default_transformation(reader); + *bbox = reader->page_bbox; +} + +/*! + Force the placement of the content on a dynamically sized page. + Call this subroutine after you determined the plot size using + a plotsize device. + + \c max_page_width and \c max_page_height specifiy the maximal + dimension of the page, which will be adjusted to the size of + the HPGL content of each individual page. + \c border specifies the border from the page to the HPGL content. + + \c bbox holds the bounding box of the HPGL content of the first + page on input and on output, the bounding box of the whole page + is returned. The returned bounding box should be used to set up + your device, which will be passed to \c hpgs_reader_imbue after + issuing this call. +*/ +void hpgs_reader_set_dynamic_page(hpgs_reader *reader, + hpgs_bbox *bbox, + double max_page_width, + double max_page_height, + double border, + double angle ) +{ + reader->page_mode = 2; + reader->page_width = max_page_width; + reader->page_height = max_page_height; + reader->page_border = border; + reader->page_angle = angle; + + // change the page layout. + hpgs_reader_set_page_matrix(reader,bbox); + hpgs_reader_set_default_transformation(reader); + *bbox = reader->page_bbox; +} + +/*! + This call is deprecated, use \c hpgs_device_stamp instead. +*/ +int hpgs_reader_stamp(hpgs_reader *reader, + const hpgs_bbox *bb, + const char *stamp, const char *encoding, + double stamp_size) +{ + return hpgs_device_stamp(reader->device,bb,stamp,encoding,stamp_size); +} + +/*! + This is a highlevel interface to stamp the device with a + text prior to printing any data. This is used in order to print a + 'draft' or 'obsoleted' mark to the paper. + + If encodeing is a null pointer +*/ +int hpgs_device_stamp(hpgs_device *dev, + const hpgs_bbox *bb, + const char *stamp, const char *encoding, + double stamp_size) +{ + int l = strlen(stamp); + int nc; + + if (encoding && (strcmp(encoding,"utf8") == 0 || + strcmp(encoding,"UTF8") == 0 || + strcmp(encoding,"utf-8") == 0 || + strcmp(encoding,"UTF-8") == 0 ) + ) + nc = hpgs_utf8_strlen(stamp,-1); + else + nc = l; + + int i,j; + + // calculate the number of partitions. + int nx = (int)ceil((bb->urx-bb->llx)/stamp_size); + int ny = (int)ceil((sqrt(3.0)*(bb->ury-bb->lly))/stamp_size); + + int n = nx < ny ? nx : ny; + + // cell sizes + double a = nx < ny ? (bb->urx-bb->llx) : (bb->urx-bb->llx)*(double)ny/(double)nx; + double b = ny < nx ? (bb->ury-bb->lly) : (bb->ury-bb->lly)*(double)nx/(double)ny; + + double ratio = (n * nc + (n-1) - 0.1) * 0.8; + + double ah = (a - ratio*b)/(1.0 - ratio*ratio); + double bh = (b - ratio*a)/(1.0 - ratio*ratio); + + hpgs_point left_vec,up_vec,space_vec; + hpgs_color rgb; + + if (nc<=0) return 0; + + space_vec.x = (a-ah) / (n * nc + (n-1)); + space_vec.y = (b-bh) / (n * nc + (n-1)); + + left_vec.x = space_vec.x * 0.9; + left_vec.y = space_vec.y * 0.9; + + up_vec.x = -ah; + up_vec.y = bh; + + rgb.r = rgb.g = rgb.b = 0.8; + if (hpgs_setrgbcolor(dev,&rgb)) + return -1; + + a = space_vec.x * (nc+1); + b = space_vec.y * (nc+1); + + for (i = 0; i < nx; ++i) + { + hpgs_point pos; + + for (j = 0; j < ny; ++j) + { + pos.x = bb->llx + ah + i * a; + pos.y = bb->lly + j * b; + + if (hpgs_device_label(dev,&pos, + stamp, l, + 0, + encoding ? encoding : "ISO-8859-1", + 0, + 5, + &left_vec, + &up_vec, + &space_vec)) + return -1; + } + } + + rgb.r = rgb.g = rgb.b = 0.0; + if (hpgs_setrgbcolor(dev,&rgb)) + return -1; + + return 0; +} + +/*! + Sets a callback function, which allows to render additional + page assets before the reader calls \c hpgs_showpage. + + The call back function is passed the given \c ctxt pointer, + the device on which the reader operates, the bounding box + of the HPGL content and the transformation matrix from + HPGL coordinates to page coordinates. + */ +void hpgs_reader_set_page_asset_func(hpgs_reader *reader, + void *ctxt, + hpgs_reader_asset_func_t func) +{ + reader->page_asset_ctxt = ctxt; + reader->page_asset_func = func; +} + +/*! + Sets a callback function, which allows to render additional + frame assets before a HPGL FR command becomes effective or + the reader calls \c hpgs_showpage. + + The call back function is passed the given \c ctxt pointer, + the device on which the reader operates, the bounding box + of the HPGL content and the transformation matrix from + HPGL coordinates to page coordinates. + */ +void hpgs_reader_set_frame_asset_func(hpgs_reader *reader, + void *ctxt, + hpgs_reader_asset_func_t func) +{ + reader->frame_asset_ctxt = ctxt; + reader->frame_asset_func = func; +} + +/*! + Sets a filename for dumping inline PCL images in + PNG format. The actual filenames written are:" + filename0001.png, filename0002.png, ..... + If \c filename contains an extension .png the counter + is put between the basename and the .png extension. +*/ +int hpgs_reader_set_png_dump(hpgs_reader *reader, const char *filename) +{ + int l; + + if (reader->png_dump_filename) + free (reader->png_dump_filename); + + if (!filename) + { + reader->png_dump_filename = 0; + return 0; + } + + // strip png extension. + l = strlen(filename); + + if (l>4 && strcmp(filename+l-4,".png")==0) + l-=4; + + reader->png_dump_filename = (char*) malloc(l+1); + + if (!reader->png_dump_filename) + return hpgs_set_error(hpgs_i18n("Error allocating memory for png dump filename: %s"), + strerror(errno)); + + strncpy(reader->png_dump_filename,filename,l); + reader->png_dump_filename[l] = '\0'; + reader->png_dump_count=0; + + return 0; +} + +/*! + Returns the curent HPGL pen of the given \c reader structure. + This information might be used by page or frame asset functions. +*/ +int hpgs_reader_get_current_pen(hpgs_reader *reader) +{ + return reader->current_pen; +} + +/*! + Destroys the given \c reader structure and frees all allocated + resources of the HPGL reader. +*/ +void hpgs_destroy_reader(hpgs_reader *reader) +{ + int i; + + if (reader->pen_widths) + free(reader->pen_widths); + + if (reader->pen_colors) + free(reader->pen_colors); + + if (reader->in) + hpgs_istream_close(reader->in); + + if (reader->device) + hpgs_device_destroy(reader->device); + + if (reader->plotsize_device) + hpgs_device_destroy(reader->plotsize_device); + + if (reader->poly_buffer) + free(reader->poly_buffer); + + for (i=0;i<=reader->pcl_i_palette;++i) + if (reader->pcl_palettes[i]) + free(reader->pcl_palettes[i]); + + for (i=0;i<8;++i) + if (reader->pcl_raster_data[i]) + free(reader->pcl_raster_data[i]); + + if (reader->pcl_image) + hpgs_image_destroy(reader->pcl_image); + + if (reader->png_dump_filename) + free(reader->png_dump_filename); + + free(reader); +} diff --git a/src/add-ons/translators/hpgs/lib/hpgsreader.h b/src/add-ons/translators/hpgs/lib/hpgsreader.h new file mode 100644 index 0000000000..79c5ed6757 --- /dev/null +++ b/src/add-ons/translators/hpgs/lib/hpgsreader.h @@ -0,0 +1,515 @@ +/*********************************************************************** + * * + * $Id: hpgsreader.h 381 2007-02-20 09:06:38Z softadm $ + * * + * hpgs - HPGl Script, a hpgl/2 interpreter, which uses a Postscript * + * API for rendering a scene and thus renders to a variety of * + * devices and fileformats. * + * * + * (C) 2004-2006 ev-i Informationstechnologie GmbH http://www.ev-i.at * + * * + * Author: Wolfgang Glas * + * * + * hpgs is free software; you can redistribute it and/or * + * modify it under the terms of the GNU Lesser General Public * + * License as published by the Free Software Foundation; either * + * version 2.1 of the License, or (at your option) any later version. * + * * + * hpgs is distributed in the hope that it will be useful, * + * but WITHOUT ANY WARRANTY; without even the implied warranty of * + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * + * Lesser General Public License for more details. * + * * + * You should have received a copy of the GNU Lesser General Public * + * License along with this library; if not, write to the * + * Free Software Foundation, Inc., 59 Temple Place, Suite 330, * + * Boston, MA 02111-1307 USA * + * * + *********************************************************************** + * * + * Private subroutines used by the hpgs_reader. * + * * + ***********************************************************************/ + +#ifndef __HPGS_READER_H__ +#define __HPGS_READER_H__ + +#include + +#ifdef __cplusplus +extern "C" { +#endif + +/*! \file hpgsreader.h + + \brief The private interfaces for implementing the HPGL reader. + + A header file, which declares the private structures and functions + used to implement the HPGL reader \c hpgs_reader. +*/ + +#define HPGS_MAX_PCL_PALETTES 20 + +#define MM_TO_PT (72.0 / 25.4) +#define HP_TO_PT (72.0 / (25.4 * 40.0)) + +#define MAKE_COMMAND(a,b) (((int)(a) << 8) + (b)) + +#define AA_CMD MAKE_COMMAND('A','A') +#define AC_CMD MAKE_COMMAND('A','C') +#define AD_CMD MAKE_COMMAND('A','D') +#define AR_CMD MAKE_COMMAND('A','R') +#define AT_CMD MAKE_COMMAND('A','T') +#define BP_CMD MAKE_COMMAND('B','P') +#define BR_CMD MAKE_COMMAND('B','R') +#define BZ_CMD MAKE_COMMAND('B','Z') +#define CI_CMD MAKE_COMMAND('C','I') +#define CO_CMD MAKE_COMMAND('C','O') +#define CP_CMD MAKE_COMMAND('C','P') +#define CR_CMD MAKE_COMMAND('C','R') +#define DI_CMD MAKE_COMMAND('D','I') +#define DR_CMD MAKE_COMMAND('D','R') +#define DT_CMD MAKE_COMMAND('D','T') +#define DV_CMD MAKE_COMMAND('D','V') +#define EA_CMD MAKE_COMMAND('E','A') +#define EP_CMD MAKE_COMMAND('E','P') +#define ER_CMD MAKE_COMMAND('E','R') +#define ES_CMD MAKE_COMMAND('E','S') +#define EW_CMD MAKE_COMMAND('E','W') +#define FP_CMD MAKE_COMMAND('F','P') +#define FR_CMD MAKE_COMMAND('F','R') +#define FT_CMD MAKE_COMMAND('F','T') +#define IN_CMD MAKE_COMMAND('I','N') +#define IP_CMD MAKE_COMMAND('I','P') +#define IR_CMD MAKE_COMMAND('I','R') +#define IW_CMD MAKE_COMMAND('I','W') +#define LA_CMD MAKE_COMMAND('L','A') +#define LB_CMD MAKE_COMMAND('L','B') +#define LO_CMD MAKE_COMMAND('L','O') +#define LT_CMD MAKE_COMMAND('L','T') +#define MC_CMD MAKE_COMMAND('M','C') +#define MG_CMD MAKE_COMMAND('M','G') +#define NP_CMD MAKE_COMMAND('N','P') +#define PA_CMD MAKE_COMMAND('P','A') +#define PC_CMD MAKE_COMMAND('P','C') +#define PD_CMD MAKE_COMMAND('P','D') +#define PE_CMD MAKE_COMMAND('P','E') +#define PG_CMD MAKE_COMMAND('P','G') +#define PM_CMD MAKE_COMMAND('P','M') +#define PP_CMD MAKE_COMMAND('P','P') +#define PR_CMD MAKE_COMMAND('P','R') +#define PS_CMD MAKE_COMMAND('P','S') +#define PU_CMD MAKE_COMMAND('P','U') +#define PW_CMD MAKE_COMMAND('P','W') +#define RA_CMD MAKE_COMMAND('R','A') +#define RO_CMD MAKE_COMMAND('R','O') +#define RR_CMD MAKE_COMMAND('R','R') +#define RT_CMD MAKE_COMMAND('R','T') +#define SA_CMD MAKE_COMMAND('S','A') +#define SC_CMD MAKE_COMMAND('S','C') +#define SD_CMD MAKE_COMMAND('S','D') +#define SI_CMD MAKE_COMMAND('S','I') +#define SL_CMD MAKE_COMMAND('S','L') +#define SM_CMD MAKE_COMMAND('S','M') +#define SP_CMD MAKE_COMMAND('S','P') +#define SR_CMD MAKE_COMMAND('S','R') +#define SS_CMD MAKE_COMMAND('S','S') +#define TR_CMD MAKE_COMMAND('T','R') +#define UL_CMD MAKE_COMMAND('U','L') +#define WG_CMD MAKE_COMMAND('W','G') +#define WU_CMD MAKE_COMMAND('W','U') + +/*! @addtogroup reader + * @{ + */ + +typedef struct hpgs_reader_poly_point_st hpgs_reader_poly_point; + +/*! \brief A point in hte HPGL polygon buffer + + This structure holds a point in the polygon buffer of HPGL + used to implement PM, EP and FP commands. +*/ +struct hpgs_reader_poly_point_st +{ + hpgs_point p; //!< The coordinates of the point + int flag; //!< 0 moveto, 1 lineto, 2 curveto +}; + +typedef struct hpgs_reader_pcl_palette_st hpgs_reader_pcl_palette; + +/*! \brief A PCL palette as used by PCL push/pop palette. + + This structure holds all properties which are saved/resoterd through PCL push/pop palette. +*/ +struct hpgs_reader_pcl_palette_st +{ + hpgs_palette_color colors[256]; /*!< The palette colors. */ + hpgs_palette_color last_color; /*!< The PCL color currently being assembled. */ + + int cid_space; /*!< The current PCL color space. */ + int cid_enc; /*!< The current PCL pixel encoding scheme. */ + int cid_bpi; /*!< PCL Bits per color index. */ + int cid_bpc[3];/*!< PCL Bits per color component. */ +}; + +/*! \brief A HPGL interpreter. + + This structure holds all the states used during the interpretation + of a HPGL stream. Users of the library usually don't have to cope + with details of this structure. +*/ +struct hpgs_reader_st +{ + hpgs_istream *in; /*!< The current input stream. */ + hpgs_device *device; /*!< The current output device. */ + hpgs_device *plotsize_device; /*!< The current plotsize device. */ + + int current_page; /*!< The number of the current page. -1...single page mode. */ + + int verbosity; /*!< The verbosity level in effect. */ + + double lw_factor; /*!< The linewidth scaling factor. */ + /*@{ */ + /*! The paper size in PostScript pt (1/72 inch). */ + double x_size,y_size; /*@} */ + /*@{ */ + /*! The frame advance vector in PostScript pt (1/72 inch). */ + double frame_x,frame_y; /*@} */ + hpgs_point P1; /*!< HPGL frame point P1 in PostScript pt (1/72 inch). */ + hpgs_point P2; /*!< HPGL frame point P2 in PostScript pt (1/72 inch). */ + hpgs_point delta_P; /*!< The difference of P2-P1 as set by the IP command. */ + int rotation; /*!< The current rotation angle (90/180/270/360). */ + + /*@{ */ + /*! The current effective coordinate scaling of a SC command. */ + int sc_type; + double sc_xmin; + double sc_xmax; + double sc_ymin; + double sc_ymax; + double sc_left; + double sc_bottom; + /*@} */ + + int rop3; /*!< ROP3 operation in effect. */ + hpgs_bool src_transparency; /*!< ROP3 source transparency. */ + hpgs_bool pattern_transparency; /*!< ROP3 pattern transparency. */ + + hpgs_matrix world_matrix; /*!< transformation matrix for the transformation of HPGL to PostScript + (world) coordinates usually given in points (1/72 inch). */ + + double world_scale; /*!< sqrt(|det(world_matrix)|) */ + + hpgs_matrix page_matrix; /*!< transformation matrix for the transformation of + PostScript (world) coordinates usually given in points (1/72 inch) + to user defined page-coorindates. */ + + double page_scale; /*!< sqrt(|det(page_matrix)|) */ + + hpgs_matrix total_matrix; /*!< The concatenation of page_matrix and world_matrix. */ + + double total_scale; /*!< sqrt(|det(page_matrix)|) */ + + int page_mode; /*!< 0...untransformed, 1...fixed page, 2...dynamic page */ + + double page_width; /*!< The page width or the maximal page width in points. */ + double page_height; /*!< The page height or the maximal page height in points. */ + double page_angle; /*!< The rotation angle of the HPGL content on the page. */ + double page_border; /*!< The border of the HPGL border on the page. */ + + hpgs_bbox page_bbox; /*!< The currently active page bounding box. */ + hpgs_bbox content_bbox; /*!< The bounding box of the HPGL content of the current page. */ + + void *page_asset_ctxt; /*!< A callback for rendering additional page assets before showpage. */ + hpgs_reader_asset_func_t page_asset_func; /*!< A callback for rendering additional page assets before showpage. */ + + void *frame_asset_ctxt; /*!< A callback for rendering additional frame assets before frame advance/showpage. */ + hpgs_reader_asset_func_t frame_asset_func; /*!< A callback for rendering additional frame asset before frame advance/showpage. */ + + /*@{ */ + /*! linetype settings. (-8,...8) stored from 0...16 */ + int linetype_nsegs[17]; + float linetype_segs[17][20]; + /*@} */ + + /*@{ */ + /*! pen settings */ + int npens; + double *pen_widths; + hpgs_color *pen_colors; + /*@} */ + + hpgs_color min_color; /*!< The minimal RGB values. */ + hpgs_color max_color; /*!< The maximal RGB values. */ + + /*@{ */ + /*! label terminator settings */ + char label_term; + int label_term_ignore; + /*@} */ + + int polygon_mode; /*!< Are we in polygon mode? */ + + /*@{ */ + /*! the polygon buffer used in polygon mode. */ + hpgs_reader_poly_point *poly_buffer; + int poly_buffer_size; + int poly_buffer_alloc_size; + /*@} */ + + int polygon_open; /*!< Is a polygon currently open? */ + int pen_width_relative; /*!< Are pen widths specified relative? */ + int pen_down; /*!< Is the pen down? */ + int current_pen; /*!< Number of the current pen. */ + int current_linetype; /*!< Number of the current linetype. */ + int absolute_plotting; /*!< Are PU and PD coordinates absoulte, because a PA statement is in effect? */ + int have_current_point; /*!< Do we have a current pen position, aka current_point is a valid position. */ + hpgs_point current_point; /*!< The current pen position in PostScript pt (1/72 inch), + if \c have_current_point is true. */ + hpgs_point first_path_point;/*!< The first point in a path, if \c polygon_open is true. */ + hpgs_point min_path_point; /*!< The minimal x/y coordinates of all points in an open path. */ + hpgs_point max_path_point; /*!< The maximal x/y coordinates of all points in an open path. */ + hpgs_point anchor_point; /*!< The anchor point for fill patterns. */ + + int current_ft; /*!< The fill type currently in effect. */ + double ft3_angle; /*!< The current pattern angle of fill type 3. */ + double ft3_spacing;/*!< The current pattern spacing of fill type 3. */ + double ft4_angle; /*!< The current pattern angle of fill type 4. */ + double ft4_spacing;/*!< The current pattern spacing of fill type 4. */ + double ft10_level; /*!< The current color level for fill type 10. */ + + /*@{ */ + /*! the text state for the standard font. */ + int default_encoding; + int default_face; + int default_spacing; + double default_pitch; + double default_height; + int default_posture; + int default_weight; + /*@} */ + + /*@{ */ + /*! the text state for the alternate font. */ + int alternate_encoding; + int alternate_face; + int alternate_spacing; + double alternate_pitch; + double alternate_height; + int alternate_posture; + int alternate_weight; + /*@} */ + + int alternate_font; /*!< do we use the alternate font? */ + + /*@{ */ + /*! text attributes set through special commands. */ + hpgs_point cr_point; + hpgs_point current_char_size; + hpgs_point current_extra_space; + double current_slant; + int current_label_origin; + int current_text_path; + int current_text_line; + double current_label_angle; + /*@} */ + + double pcl_scale; /*!< The factor from PCL units to PostScript pt (1/72 inch). */ + double pcl_hmi; /*!< PCL horizontal motion index in pt. */ + double pcl_vmi; /*!< PCL vertical motion index in pt. */ + hpgs_point pcl_point; /*!< PCL point position in pt. */ + + hpgs_reader_pcl_palette *pcl_palettes[HPGS_MAX_PCL_PALETTES]; /*!< The PCL palette stack of palattes fo 256 colors .*/ + int pcl_i_palette; /*!< The number of of the current PCL palette on the stack. */ + + int pcl_raster_mode; /*!< The PCL ratser mode. + -1 no raster graphics, 0 horizontal graphics, 3 vertical graphics */ + int pcl_raster_presentation;/*!< The PCL raster presentation mode. */ + int pcl_raster_src_width; /*!< The PCL raster image source width. */ + int pcl_raster_src_height; /*!< The PCL raster image source height. */ + int pcl_raster_dest_width; /*!< The PCL raster image destination width. */ + int pcl_raster_dest_height; /*!< The PCL raster image destination height. */ + int pcl_raster_res; /*!< The PCL raster image resolution. */ + int pcl_raster_compression; /*!< The PCL raster compression in effect. */ + int pcl_raster_y_offset; /*!< The PCL raster y offset in effect. */ + int pcl_raster_plane; /*!< The current PCL raster plane for transfer data by plane. */ + int pcl_raster_line; /*!< The number of the raster line currently transferred. */ + + unsigned char *pcl_raster_data[8];/*!< The buffer for the data of the current raster. One pointer per plane. */ + int pcl_raster_data_size; /*!< The size of the raster data buffer. */ + int pcl_raster_planes; /*!< The number of planes of the raster data currently being transferred. */ + + + hpgs_image *pcl_image; /*!< The image currently filled by pcl. */ + + // The filename for dumped pcl images. + int png_dump_count; /*!< The number of PCL images dumped so far. */ + char *png_dump_filename; /*!< The base filename for dumped PCL images. */ + + int clipsave_depth; /*!< how many clipsaves have been issued? */ + + int last_byte; /*!< The last byte extracted from the stream? */ + int bytes_ignored;/*!< A byte counter for various purposes. */ + int eoc; /*!< Did we reach the end of a HPGL command? */ + hpgs_bool interrupted; /*!< Did someone call \c hpgs_reader_interrupt ? */ +}; + +HPGS_INTERNAL_API int hpgs_reader_check_param_end(hpgs_reader *reader); + +/*! read an integer argument from the stream - PCL version. + return values: + \li -1 read error/EOF + \li 0 no integer found. + \li 1 integer found. +*/ +HPGS_INTERNAL_API int hpgs_reader_read_pcl_int(hpgs_reader *reader, int *x, int *sign); + +/*! read an integer argument from the stream . + return values: + \li -1 read error/EOF + \li 0 success. + \li 1 End of command. +*/ +HPGS_INTERNAL_API int hpgs_reader_read_int(hpgs_reader *reader, int *x); + +/*" read a double argument from the stream. + return values: + \li -1 read error/EOF + \li 0 success. + \li 1 End of command. +*/ +HPGS_INTERNAL_API int hpgs_reader_read_double(hpgs_reader *reader, double *x); +HPGS_INTERNAL_API int hpgs_reader_read_point(hpgs_reader *reader, hpgs_point *p, int xform); + +/* read a new string argument from the stream + return values: + \li -1 read error/EOF + \li 0 success. + \li 1 End of command. +*/ +HPGS_INTERNAL_API int hpgs_reader_read_new_string(hpgs_reader *reader, char *str); +HPGS_INTERNAL_API int hpgs_reader_read_label_string(hpgs_reader *reader, char *str); + +HPGS_INTERNAL_API void hpgs_reader_set_page_matrix (hpgs_reader *reader, const hpgs_bbox *bb); +HPGS_INTERNAL_API void hpgs_reader_set_default_transformation (hpgs_reader *reader); +HPGS_INTERNAL_API void hpgs_reader_set_default_state (hpgs_reader *reader); +HPGS_INTERNAL_API void hpgs_reader_set_defaults (hpgs_reader *reader); +HPGS_INTERNAL_API int hpgs_reader_set_plotsize (hpgs_reader *reader, double xs, double ys); +HPGS_INTERNAL_API int hpgs_reader_showpage (hpgs_reader *reader, int ipage); + +HPGS_INTERNAL_API void hpgs_reader_set_std_pen_colors(hpgs_reader *reader, + int i0, int n); + +HPGS_INTERNAL_API int hpgs_reader_checkpath(hpgs_reader *reader); + +HPGS_INTERNAL_API int hpgs_reader_moveto(hpgs_reader *reader, hpgs_point *p); +HPGS_INTERNAL_API int hpgs_reader_lineto(hpgs_reader *reader, hpgs_point *p); +HPGS_INTERNAL_API int hpgs_reader_curveto(hpgs_reader *reader, + hpgs_point *p1, hpgs_point *p2, hpgs_point *p3); +HPGS_INTERNAL_API int hpgs_reader_stroke(hpgs_reader *reader); +HPGS_INTERNAL_API int hpgs_reader_fill(hpgs_reader *reader, hpgs_bool winding); +HPGS_INTERNAL_API int hpgs_reader_closepath(hpgs_reader *reader); + +HPGS_INTERNAL_API int hpgs_reader_do_setpen(hpgs_reader *reader, int pen); + +HPGS_INTERNAL_API int hpgs_reader_label(hpgs_reader *reader, + const char *str, int str_len, + int face, + int encoding, + int posture, + int weight, + const hpgs_point *left_vec, + const hpgs_point *up_vec, + const hpgs_point *space_vec); + +HPGS_INTERNAL_API int hpgs_device_label(hpgs_device *dev, + hpgs_point *pos, + const char *str, int str_len, + int face, + const char *encoding, + int posture, + int weight, + const hpgs_point *left_vec, + const hpgs_point *up_vec, + const hpgs_point *space_vec); + +typedef int (*hpgs_reader_hpglcmd_func_t)(hpgs_reader *reader); + +HPGS_INTERNAL_API int hpgs_reader_do_PCL(hpgs_reader *reader, hpgs_bool take_pos); +HPGS_INTERNAL_API int hpgs_reader_do_PJL(hpgs_reader *reader); + +HPGS_INTERNAL_API int hpgs_reader_push_pcl_palette (hpgs_reader *reader); +HPGS_INTERNAL_API int hpgs_reader_pop_pcl_palette (hpgs_reader *reader); + +HPGS_INTERNAL_API int hpgs_reader_do_AA(hpgs_reader *reader); +HPGS_INTERNAL_API int hpgs_reader_do_AC(hpgs_reader *reader); +HPGS_INTERNAL_API int hpgs_reader_do_AD(hpgs_reader *reader); +HPGS_INTERNAL_API int hpgs_reader_do_AR(hpgs_reader *reader); +HPGS_INTERNAL_API int hpgs_reader_do_AT(hpgs_reader *reader); +HPGS_INTERNAL_API int hpgs_reader_do_BP(hpgs_reader *reader); +HPGS_INTERNAL_API int hpgs_reader_do_BR(hpgs_reader *reader); +HPGS_INTERNAL_API int hpgs_reader_do_BZ(hpgs_reader *reader); +HPGS_INTERNAL_API int hpgs_reader_do_CI(hpgs_reader *reader); +HPGS_INTERNAL_API int hpgs_reader_do_CO(hpgs_reader *reader); +HPGS_INTERNAL_API int hpgs_reader_do_CP(hpgs_reader *reader); +HPGS_INTERNAL_API int hpgs_reader_do_CR(hpgs_reader *reader); +HPGS_INTERNAL_API int hpgs_reader_do_DI(hpgs_reader *reader); +HPGS_INTERNAL_API int hpgs_reader_do_DR(hpgs_reader *reader); +HPGS_INTERNAL_API int hpgs_reader_do_DT(hpgs_reader *reader); +HPGS_INTERNAL_API int hpgs_reader_do_DV(hpgs_reader *reader); +HPGS_INTERNAL_API int hpgs_reader_do_EA(hpgs_reader *reader); +HPGS_INTERNAL_API int hpgs_reader_do_EP(hpgs_reader *reader); +HPGS_INTERNAL_API int hpgs_reader_do_ER(hpgs_reader *reader); +HPGS_INTERNAL_API int hpgs_reader_do_ES(hpgs_reader *reader); +HPGS_INTERNAL_API int hpgs_reader_do_EW(hpgs_reader *reader); +HPGS_INTERNAL_API int hpgs_reader_do_FP(hpgs_reader *reader); +HPGS_INTERNAL_API int hpgs_reader_do_FR(hpgs_reader *reader); +HPGS_INTERNAL_API int hpgs_reader_do_FT(hpgs_reader *reader); +HPGS_INTERNAL_API int hpgs_reader_do_IN(hpgs_reader *reader); +HPGS_INTERNAL_API int hpgs_reader_do_IP(hpgs_reader *reader); +HPGS_INTERNAL_API int hpgs_reader_do_IR(hpgs_reader *reader); +HPGS_INTERNAL_API int hpgs_reader_do_IW(hpgs_reader *reader); +HPGS_INTERNAL_API int hpgs_reader_do_LA(hpgs_reader *reader); +HPGS_INTERNAL_API int hpgs_reader_do_LB(hpgs_reader *reader); +HPGS_INTERNAL_API int hpgs_reader_do_LO(hpgs_reader *reader); +HPGS_INTERNAL_API int hpgs_reader_do_LT(hpgs_reader *reader); +HPGS_INTERNAL_API int hpgs_reader_do_MC(hpgs_reader *reader); +HPGS_INTERNAL_API int hpgs_reader_do_MG(hpgs_reader *reader); +HPGS_INTERNAL_API int hpgs_reader_do_NP(hpgs_reader *reader); +HPGS_INTERNAL_API int hpgs_reader_do_PC(hpgs_reader *reader); +HPGS_INTERNAL_API int hpgs_reader_do_PA(hpgs_reader *reader); +HPGS_INTERNAL_API int hpgs_reader_do_PD(hpgs_reader *reader); +HPGS_INTERNAL_API int hpgs_reader_do_PE(hpgs_reader *reader); +HPGS_INTERNAL_API int hpgs_reader_do_PG(hpgs_reader *reader); +HPGS_INTERNAL_API int hpgs_reader_do_PM(hpgs_reader *reader); +HPGS_INTERNAL_API int hpgs_reader_do_PP(hpgs_reader *reader); +HPGS_INTERNAL_API int hpgs_reader_do_PR(hpgs_reader *reader); +HPGS_INTERNAL_API int hpgs_reader_do_PS(hpgs_reader *reader); +HPGS_INTERNAL_API int hpgs_reader_do_PU(hpgs_reader *reader); +HPGS_INTERNAL_API int hpgs_reader_do_PW(hpgs_reader *reader); +HPGS_INTERNAL_API int hpgs_reader_do_RA(hpgs_reader *reader); +HPGS_INTERNAL_API int hpgs_reader_do_RO(hpgs_reader *reader); +HPGS_INTERNAL_API int hpgs_reader_do_RR(hpgs_reader *reader); +HPGS_INTERNAL_API int hpgs_reader_do_RT(hpgs_reader *reader); +HPGS_INTERNAL_API int hpgs_reader_do_SA(hpgs_reader *reader); +HPGS_INTERNAL_API int hpgs_reader_do_SC(hpgs_reader *reader); +HPGS_INTERNAL_API int hpgs_reader_do_SD(hpgs_reader *reader); +HPGS_INTERNAL_API int hpgs_reader_do_SI(hpgs_reader *reader); +HPGS_INTERNAL_API int hpgs_reader_do_SL(hpgs_reader *reader); +HPGS_INTERNAL_API int hpgs_reader_do_SM(hpgs_reader *reader); +HPGS_INTERNAL_API int hpgs_reader_do_SP(hpgs_reader *reader); +HPGS_INTERNAL_API int hpgs_reader_do_SR(hpgs_reader *reader); +HPGS_INTERNAL_API int hpgs_reader_do_SS(hpgs_reader *reader); +HPGS_INTERNAL_API int hpgs_reader_do_TR(hpgs_reader *reader); +HPGS_INTERNAL_API int hpgs_reader_do_UL(hpgs_reader *reader); +HPGS_INTERNAL_API int hpgs_reader_do_WG(hpgs_reader *reader); +HPGS_INTERNAL_API int hpgs_reader_do_WU(hpgs_reader *reader); + +/*! @} */ /* end of group reader */ + +#ifdef __cplusplus +} // end of extern "C" +#endif + +#endif // ! __HPGS_READER_H__ diff --git a/src/add-ons/translators/hpgs/lib/hpgsrop.c b/src/add-ons/translators/hpgs/lib/hpgsrop.c new file mode 100644 index 0000000000..fbf8a98d9e --- /dev/null +++ b/src/add-ons/translators/hpgs/lib/hpgsrop.c @@ -0,0 +1,27560 @@ +/* Generated automatically by ./hpgsmkrop at Mon Mar 19 17:26:14 2007. + Do not edit! + */ +#include + +/* 0 source/pattern opaque. */ +static void rop3_0_0_0 (unsigned char *D, unsigned char S, unsigned char T) +{ + unsigned char stk1; + stk1 = 0; + *D = stk1; +} + +/* 0 source opaque/pattern transparent. */ +static void rop3_0_0_1 (unsigned char *D, unsigned char S, unsigned char T) +{ + unsigned char stk1; + stk1 = 0; + *D = (stk1 & S) | (stk1 & (~T)) | (T & (~S) & *D); +} + +/* 0 source transparent/pattern opaque. */ +static void rop3_0_1_0 (unsigned char *D, unsigned char S, unsigned char T) +{ + unsigned char stk1; + stk1 = 0; + *D = (stk1 & (~S)) | (*D & S); +} + +/* 0 source/pattern transparent. */ +static void rop3_0_1_1 (unsigned char *D, unsigned char S, unsigned char T) +{ + unsigned char stk1; + stk1 = 0; + *D = (stk1 & (~S) & (~T)) | (*D & S) | (*D & T); +} + +/* 0 source/pattern opaque. */ +static unsigned xrop3_0_0_0 (unsigned char s, unsigned char t) +{ + unsigned stk1; + stk1 = 0x0000; + return stk1; +} + +/* 0 source opaque/pattern transparent. */ +static unsigned xrop3_0_0_1 (unsigned char s, unsigned char t) +{ + unsigned D = 0x00ff; + unsigned S = ((unsigned)s << 8) | s; + unsigned T = ((unsigned)t << 8) | t; + unsigned stk1; + stk1 = 0x0000; + return (stk1 & S) | (stk1 & (~T)) | (T & (~S) & D); +} + +/* 0 source transparent/pattern opaque. */ +static unsigned xrop3_0_1_0 (unsigned char s, unsigned char t) +{ + unsigned D = 0x00ff; + unsigned S = ((unsigned)s << 8) | s; + unsigned stk1; + stk1 = 0x0000; + return (stk1 & (~S)) | (D & S); +} + +/* 0 source/pattern transparent. */ +static unsigned xrop3_0_1_1 (unsigned char s, unsigned char t) +{ + unsigned D = 0x00ff; + unsigned S = ((unsigned)s << 8) | s; + unsigned T = ((unsigned)t << 8) | t; + unsigned stk1; + stk1 = 0x0000; + return (stk1 & (~S) & (~T)) | (D & S) | (D & T); +} + +/* DTSoon source/pattern opaque. */ +static void rop3_1_0_0 (unsigned char *D, unsigned char S, unsigned char T) +{ + unsigned char stk1; + unsigned char stk2; + stk2 = T | S; + stk1 = *D | stk2; + stk1 = ~stk1; + *D = stk1; +} + +/* DTSoon source opaque/pattern transparent. */ +static void rop3_1_0_1 (unsigned char *D, unsigned char S, unsigned char T) +{ + unsigned char stk1; + unsigned char stk2; + stk2 = T | S; + stk1 = *D | stk2; + stk1 = ~stk1; + *D = (stk1 & S) | (stk1 & (~T)) | (T & (~S) & *D); +} + +/* DTSoon source transparent/pattern opaque. */ +static void rop3_1_1_0 (unsigned char *D, unsigned char S, unsigned char T) +{ + unsigned char stk1; + unsigned char stk2; + stk2 = T | S; + stk1 = *D | stk2; + stk1 = ~stk1; + *D = (stk1 & (~S)) | (*D & S); +} + +/* DTSoon source/pattern transparent. */ +static void rop3_1_1_1 (unsigned char *D, unsigned char S, unsigned char T) +{ + unsigned char stk1; + unsigned char stk2; + stk2 = T | S; + stk1 = *D | stk2; + stk1 = ~stk1; + *D = (stk1 & (~S) & (~T)) | (*D & S) | (*D & T); +} + +/* DTSoon source/pattern opaque. */ +static unsigned xrop3_1_0_0 (unsigned char s, unsigned char t) +{ + unsigned D = 0x00ff; + unsigned S = ((unsigned)s << 8) | s; + unsigned T = ((unsigned)t << 8) | t; + unsigned stk1; + unsigned stk2; + stk2 = T | S; + stk1 = D | stk2; + stk1 = ~stk1; + return stk1; +} + +/* DTSoon source opaque/pattern transparent. */ +static unsigned xrop3_1_0_1 (unsigned char s, unsigned char t) +{ + unsigned D = 0x00ff; + unsigned S = ((unsigned)s << 8) | s; + unsigned T = ((unsigned)t << 8) | t; + unsigned stk1; + unsigned stk2; + stk2 = T | S; + stk1 = D | stk2; + stk1 = ~stk1; + return (stk1 & S) | (stk1 & (~T)) | (T & (~S) & D); +} + +/* DTSoon source transparent/pattern opaque. */ +static unsigned xrop3_1_1_0 (unsigned char s, unsigned char t) +{ + unsigned D = 0x00ff; + unsigned S = ((unsigned)s << 8) | s; + unsigned T = ((unsigned)t << 8) | t; + unsigned stk1; + unsigned stk2; + stk2 = T | S; + stk1 = D | stk2; + stk1 = ~stk1; + return (stk1 & (~S)) | (D & S); +} + +/* DTSoon source/pattern transparent. */ +static unsigned xrop3_1_1_1 (unsigned char s, unsigned char t) +{ + unsigned D = 0x00ff; + unsigned S = ((unsigned)s << 8) | s; + unsigned T = ((unsigned)t << 8) | t; + unsigned stk1; + unsigned stk2; + stk2 = T | S; + stk1 = D | stk2; + stk1 = ~stk1; + return (stk1 & (~S) & (~T)) | (D & S) | (D & T); +} + +/* DTSona source/pattern opaque. */ +static void rop3_2_0_0 (unsigned char *D, unsigned char S, unsigned char T) +{ + unsigned char stk1; + unsigned char stk2; + stk2 = T | S; + stk2 = ~stk2; + stk1 = *D & stk2; + *D = stk1; +} + +/* DTSona source opaque/pattern transparent. */ +static void rop3_2_0_1 (unsigned char *D, unsigned char S, unsigned char T) +{ + unsigned char stk1; + unsigned char stk2; + stk2 = T | S; + stk2 = ~stk2; + stk1 = *D & stk2; + *D = (stk1 & S) | (stk1 & (~T)) | (T & (~S) & *D); +} + +/* DTSona source transparent/pattern opaque. */ +static void rop3_2_1_0 (unsigned char *D, unsigned char S, unsigned char T) +{ + unsigned char stk1; + unsigned char stk2; + stk2 = T | S; + stk2 = ~stk2; + stk1 = *D & stk2; + *D = (stk1 & (~S)) | (*D & S); +} + +/* DTSona source/pattern transparent. */ +static void rop3_2_1_1 (unsigned char *D, unsigned char S, unsigned char T) +{ + unsigned char stk1; + unsigned char stk2; + stk2 = T | S; + stk2 = ~stk2; + stk1 = *D & stk2; + *D = (stk1 & (~S) & (~T)) | (*D & S) | (*D & T); +} + +/* DTSona source/pattern opaque. */ +static unsigned xrop3_2_0_0 (unsigned char s, unsigned char t) +{ + unsigned D = 0x00ff; + unsigned S = ((unsigned)s << 8) | s; + unsigned T = ((unsigned)t << 8) | t; + unsigned stk1; + unsigned stk2; + stk2 = T | S; + stk2 = ~stk2; + stk1 = D & stk2; + return stk1; +} + +/* DTSona source opaque/pattern transparent. */ +static unsigned xrop3_2_0_1 (unsigned char s, unsigned char t) +{ + unsigned D = 0x00ff; + unsigned S = ((unsigned)s << 8) | s; + unsigned T = ((unsigned)t << 8) | t; + unsigned stk1; + unsigned stk2; + stk2 = T | S; + stk2 = ~stk2; + stk1 = D & stk2; + return (stk1 & S) | (stk1 & (~T)) | (T & (~S) & D); +} + +/* DTSona source transparent/pattern opaque. */ +static unsigned xrop3_2_1_0 (unsigned char s, unsigned char t) +{ + unsigned D = 0x00ff; + unsigned S = ((unsigned)s << 8) | s; + unsigned T = ((unsigned)t << 8) | t; + unsigned stk1; + unsigned stk2; + stk2 = T | S; + stk2 = ~stk2; + stk1 = D & stk2; + return (stk1 & (~S)) | (D & S); +} + +/* DTSona source/pattern transparent. */ +static unsigned xrop3_2_1_1 (unsigned char s, unsigned char t) +{ + unsigned D = 0x00ff; + unsigned S = ((unsigned)s << 8) | s; + unsigned T = ((unsigned)t << 8) | t; + unsigned stk1; + unsigned stk2; + stk2 = T | S; + stk2 = ~stk2; + stk1 = D & stk2; + return (stk1 & (~S) & (~T)) | (D & S) | (D & T); +} + +/* TSon source/pattern opaque. */ +static void rop3_3_0_0 (unsigned char *D, unsigned char S, unsigned char T) +{ + unsigned char stk1; + stk1 = T | S; + stk1 = ~stk1; + *D = stk1; +} + +/* TSon source opaque/pattern transparent. */ +static void rop3_3_0_1 (unsigned char *D, unsigned char S, unsigned char T) +{ + unsigned char stk1; + stk1 = T | S; + stk1 = ~stk1; + *D = (stk1 & S) | (stk1 & (~T)) | (T & (~S) & *D); +} + +/* TSon source transparent/pattern opaque. */ +static void rop3_3_1_0 (unsigned char *D, unsigned char S, unsigned char T) +{ + unsigned char stk1; + stk1 = T | S; + stk1 = ~stk1; + *D = (stk1 & (~S)) | (*D & S); +} + +/* TSon source/pattern transparent. */ +static void rop3_3_1_1 (unsigned char *D, unsigned char S, unsigned char T) +{ + unsigned char stk1; + stk1 = T | S; + stk1 = ~stk1; + *D = (stk1 & (~S) & (~T)) | (*D & S) | (*D & T); +} + +/* TSon source/pattern opaque. */ +static unsigned xrop3_3_0_0 (unsigned char s, unsigned char t) +{ + unsigned S = ((unsigned)s << 8) | s; + unsigned T = ((unsigned)t << 8) | t; + unsigned stk1; + stk1 = T | S; + stk1 = ~stk1; + return stk1; +} + +/* TSon source opaque/pattern transparent. */ +static unsigned xrop3_3_0_1 (unsigned char s, unsigned char t) +{ + unsigned D = 0x00ff; + unsigned S = ((unsigned)s << 8) | s; + unsigned T = ((unsigned)t << 8) | t; + unsigned stk1; + stk1 = T | S; + stk1 = ~stk1; + return (stk1 & S) | (stk1 & (~T)) | (T & (~S) & D); +} + +/* TSon source transparent/pattern opaque. */ +static unsigned xrop3_3_1_0 (unsigned char s, unsigned char t) +{ + unsigned D = 0x00ff; + unsigned S = ((unsigned)s << 8) | s; + unsigned T = ((unsigned)t << 8) | t; + unsigned stk1; + stk1 = T | S; + stk1 = ~stk1; + return (stk1 & (~S)) | (D & S); +} + +/* TSon source/pattern transparent. */ +static unsigned xrop3_3_1_1 (unsigned char s, unsigned char t) +{ + unsigned D = 0x00ff; + unsigned S = ((unsigned)s << 8) | s; + unsigned T = ((unsigned)t << 8) | t; + unsigned stk1; + stk1 = T | S; + stk1 = ~stk1; + return (stk1 & (~S) & (~T)) | (D & S) | (D & T); +} + +/* SDTona source/pattern opaque. */ +static void rop3_4_0_0 (unsigned char *D, unsigned char S, unsigned char T) +{ + unsigned char stk1; + unsigned char stk2; + stk2 = *D | T; + stk2 = ~stk2; + stk1 = S & stk2; + *D = stk1; +} + +/* SDTona source opaque/pattern transparent. */ +static void rop3_4_0_1 (unsigned char *D, unsigned char S, unsigned char T) +{ + unsigned char stk1; + unsigned char stk2; + stk2 = *D | T; + stk2 = ~stk2; + stk1 = S & stk2; + *D = (stk1 & S) | (stk1 & (~T)) | (T & (~S) & *D); +} + +/* SDTona source transparent/pattern opaque. */ +static void rop3_4_1_0 (unsigned char *D, unsigned char S, unsigned char T) +{ + unsigned char stk1; + unsigned char stk2; + stk2 = *D | T; + stk2 = ~stk2; + stk1 = S & stk2; + *D = (stk1 & (~S)) | (*D & S); +} + +/* SDTona source/pattern transparent. */ +static void rop3_4_1_1 (unsigned char *D, unsigned char S, unsigned char T) +{ + unsigned char stk1; + unsigned char stk2; + stk2 = *D | T; + stk2 = ~stk2; + stk1 = S & stk2; + *D = (stk1 & (~S) & (~T)) | (*D & S) | (*D & T); +} + +/* SDTona source/pattern opaque. */ +static unsigned xrop3_4_0_0 (unsigned char s, unsigned char t) +{ + unsigned D = 0x00ff; + unsigned S = ((unsigned)s << 8) | s; + unsigned T = ((unsigned)t << 8) | t; + unsigned stk1; + unsigned stk2; + stk2 = D | T; + stk2 = ~stk2; + stk1 = S & stk2; + return stk1; +} + +/* SDTona source opaque/pattern transparent. */ +static unsigned xrop3_4_0_1 (unsigned char s, unsigned char t) +{ + unsigned D = 0x00ff; + unsigned S = ((unsigned)s << 8) | s; + unsigned T = ((unsigned)t << 8) | t; + unsigned stk1; + unsigned stk2; + stk2 = D | T; + stk2 = ~stk2; + stk1 = S & stk2; + return (stk1 & S) | (stk1 & (~T)) | (T & (~S) & D); +} + +/* SDTona source transparent/pattern opaque. */ +static unsigned xrop3_4_1_0 (unsigned char s, unsigned char t) +{ + unsigned D = 0x00ff; + unsigned S = ((unsigned)s << 8) | s; + unsigned T = ((unsigned)t << 8) | t; + unsigned stk1; + unsigned stk2; + stk2 = D | T; + stk2 = ~stk2; + stk1 = S & stk2; + return (stk1 & (~S)) | (D & S); +} + +/* SDTona source/pattern transparent. */ +static unsigned xrop3_4_1_1 (unsigned char s, unsigned char t) +{ + unsigned D = 0x00ff; + unsigned S = ((unsigned)s << 8) | s; + unsigned T = ((unsigned)t << 8) | t; + unsigned stk1; + unsigned stk2; + stk2 = D | T; + stk2 = ~stk2; + stk1 = S & stk2; + return (stk1 & (~S) & (~T)) | (D & S) | (D & T); +} + +/* DTon source/pattern opaque. */ +static void rop3_5_0_0 (unsigned char *D, unsigned char S, unsigned char T) +{ + unsigned char stk1; + stk1 = *D | T; + stk1 = ~stk1; + *D = stk1; +} + +/* DTon source opaque/pattern transparent. */ +static void rop3_5_0_1 (unsigned char *D, unsigned char S, unsigned char T) +{ + unsigned char stk1; + stk1 = *D | T; + stk1 = ~stk1; + *D = (stk1 & S) | (stk1 & (~T)) | (T & (~S) & *D); +} + +/* DTon source transparent/pattern opaque. */ +static void rop3_5_1_0 (unsigned char *D, unsigned char S, unsigned char T) +{ + unsigned char stk1; + stk1 = *D | T; + stk1 = ~stk1; + *D = (stk1 & (~S)) | (*D & S); +} + +/* DTon source/pattern transparent. */ +static void rop3_5_1_1 (unsigned char *D, unsigned char S, unsigned char T) +{ + unsigned char stk1; + stk1 = *D | T; + stk1 = ~stk1; + *D = (stk1 & (~S) & (~T)) | (*D & S) | (*D & T); +} + +/* DTon source/pattern opaque. */ +static unsigned xrop3_5_0_0 (unsigned char s, unsigned char t) +{ + unsigned D = 0x00ff; + unsigned T = ((unsigned)t << 8) | t; + unsigned stk1; + stk1 = D | T; + stk1 = ~stk1; + return stk1; +} + +/* DTon source opaque/pattern transparent. */ +static unsigned xrop3_5_0_1 (unsigned char s, unsigned char t) +{ + unsigned D = 0x00ff; + unsigned S = ((unsigned)s << 8) | s; + unsigned T = ((unsigned)t << 8) | t; + unsigned stk1; + stk1 = D | T; + stk1 = ~stk1; + return (stk1 & S) | (stk1 & (~T)) | (T & (~S) & D); +} + +/* DTon source transparent/pattern opaque. */ +static unsigned xrop3_5_1_0 (unsigned char s, unsigned char t) +{ + unsigned D = 0x00ff; + unsigned S = ((unsigned)s << 8) | s; + unsigned T = ((unsigned)t << 8) | t; + unsigned stk1; + stk1 = D | T; + stk1 = ~stk1; + return (stk1 & (~S)) | (D & S); +} + +/* DTon source/pattern transparent. */ +static unsigned xrop3_5_1_1 (unsigned char s, unsigned char t) +{ + unsigned D = 0x00ff; + unsigned S = ((unsigned)s << 8) | s; + unsigned T = ((unsigned)t << 8) | t; + unsigned stk1; + stk1 = D | T; + stk1 = ~stk1; + return (stk1 & (~S) & (~T)) | (D & S) | (D & T); +} + +/* TDSxnon source/pattern opaque. */ +static void rop3_6_0_0 (unsigned char *D, unsigned char S, unsigned char T) +{ + unsigned char stk1; + unsigned char stk2; + stk2 = *D ^ S; + stk2 = ~stk2; + stk1 = T | stk2; + stk1 = ~stk1; + *D = stk1; +} + +/* TDSxnon source opaque/pattern transparent. */ +static void rop3_6_0_1 (unsigned char *D, unsigned char S, unsigned char T) +{ + unsigned char stk1; + unsigned char stk2; + stk2 = *D ^ S; + stk2 = ~stk2; + stk1 = T | stk2; + stk1 = ~stk1; + *D = (stk1 & S) | (stk1 & (~T)) | (T & (~S) & *D); +} + +/* TDSxnon source transparent/pattern opaque. */ +static void rop3_6_1_0 (unsigned char *D, unsigned char S, unsigned char T) +{ + unsigned char stk1; + unsigned char stk2; + stk2 = *D ^ S; + stk2 = ~stk2; + stk1 = T | stk2; + stk1 = ~stk1; + *D = (stk1 & (~S)) | (*D & S); +} + +/* TDSxnon source/pattern transparent. */ +static void rop3_6_1_1 (unsigned char *D, unsigned char S, unsigned char T) +{ + unsigned char stk1; + unsigned char stk2; + stk2 = *D ^ S; + stk2 = ~stk2; + stk1 = T | stk2; + stk1 = ~stk1; + *D = (stk1 & (~S) & (~T)) | (*D & S) | (*D & T); +} + +/* TDSxnon source/pattern opaque. */ +static unsigned xrop3_6_0_0 (unsigned char s, unsigned char t) +{ + unsigned D = 0x00ff; + unsigned S = ((unsigned)s << 8) | s; + unsigned T = ((unsigned)t << 8) | t; + unsigned stk1; + unsigned stk2; + stk2 = D ^ S; + stk2 = ~stk2; + stk1 = T | stk2; + stk1 = ~stk1; + return stk1; +} + +/* TDSxnon source opaque/pattern transparent. */ +static unsigned xrop3_6_0_1 (unsigned char s, unsigned char t) +{ + unsigned D = 0x00ff; + unsigned S = ((unsigned)s << 8) | s; + unsigned T = ((unsigned)t << 8) | t; + unsigned stk1; + unsigned stk2; + stk2 = D ^ S; + stk2 = ~stk2; + stk1 = T | stk2; + stk1 = ~stk1; + return (stk1 & S) | (stk1 & (~T)) | (T & (~S) & D); +} + +/* TDSxnon source transparent/pattern opaque. */ +static unsigned xrop3_6_1_0 (unsigned char s, unsigned char t) +{ + unsigned D = 0x00ff; + unsigned S = ((unsigned)s << 8) | s; + unsigned T = ((unsigned)t << 8) | t; + unsigned stk1; + unsigned stk2; + stk2 = D ^ S; + stk2 = ~stk2; + stk1 = T | stk2; + stk1 = ~stk1; + return (stk1 & (~S)) | (D & S); +} + +/* TDSxnon source/pattern transparent. */ +static unsigned xrop3_6_1_1 (unsigned char s, unsigned char t) +{ + unsigned D = 0x00ff; + unsigned S = ((unsigned)s << 8) | s; + unsigned T = ((unsigned)t << 8) | t; + unsigned stk1; + unsigned stk2; + stk2 = D ^ S; + stk2 = ~stk2; + stk1 = T | stk2; + stk1 = ~stk1; + return (stk1 & (~S) & (~T)) | (D & S) | (D & T); +} + +/* TDSaon source/pattern opaque. */ +static void rop3_7_0_0 (unsigned char *D, unsigned char S, unsigned char T) +{ + unsigned char stk1; + unsigned char stk2; + stk2 = *D & S; + stk1 = T | stk2; + stk1 = ~stk1; + *D = stk1; +} + +/* TDSaon source opaque/pattern transparent. */ +static void rop3_7_0_1 (unsigned char *D, unsigned char S, unsigned char T) +{ + unsigned char stk1; + unsigned char stk2; + stk2 = *D & S; + stk1 = T | stk2; + stk1 = ~stk1; + *D = (stk1 & S) | (stk1 & (~T)) | (T & (~S) & *D); +} + +/* TDSaon source transparent/pattern opaque. */ +static void rop3_7_1_0 (unsigned char *D, unsigned char S, unsigned char T) +{ + unsigned char stk1; + unsigned char stk2; + stk2 = *D & S; + stk1 = T | stk2; + stk1 = ~stk1; + *D = (stk1 & (~S)) | (*D & S); +} + +/* TDSaon source/pattern transparent. */ +static void rop3_7_1_1 (unsigned char *D, unsigned char S, unsigned char T) +{ + unsigned char stk1; + unsigned char stk2; + stk2 = *D & S; + stk1 = T | stk2; + stk1 = ~stk1; + *D = (stk1 & (~S) & (~T)) | (*D & S) | (*D & T); +} + +/* TDSaon source/pattern opaque. */ +static unsigned xrop3_7_0_0 (unsigned char s, unsigned char t) +{ + unsigned D = 0x00ff; + unsigned S = ((unsigned)s << 8) | s; + unsigned T = ((unsigned)t << 8) | t; + unsigned stk1; + unsigned stk2; + stk2 = D & S; + stk1 = T | stk2; + stk1 = ~stk1; + return stk1; +} + +/* TDSaon source opaque/pattern transparent. */ +static unsigned xrop3_7_0_1 (unsigned char s, unsigned char t) +{ + unsigned D = 0x00ff; + unsigned S = ((unsigned)s << 8) | s; + unsigned T = ((unsigned)t << 8) | t; + unsigned stk1; + unsigned stk2; + stk2 = D & S; + stk1 = T | stk2; + stk1 = ~stk1; + return (stk1 & S) | (stk1 & (~T)) | (T & (~S) & D); +} + +/* TDSaon source transparent/pattern opaque. */ +static unsigned xrop3_7_1_0 (unsigned char s, unsigned char t) +{ + unsigned D = 0x00ff; + unsigned S = ((unsigned)s << 8) | s; + unsigned T = ((unsigned)t << 8) | t; + unsigned stk1; + unsigned stk2; + stk2 = D & S; + stk1 = T | stk2; + stk1 = ~stk1; + return (stk1 & (~S)) | (D & S); +} + +/* TDSaon source/pattern transparent. */ +static unsigned xrop3_7_1_1 (unsigned char s, unsigned char t) +{ + unsigned D = 0x00ff; + unsigned S = ((unsigned)s << 8) | s; + unsigned T = ((unsigned)t << 8) | t; + unsigned stk1; + unsigned stk2; + stk2 = D & S; + stk1 = T | stk2; + stk1 = ~stk1; + return (stk1 & (~S) & (~T)) | (D & S) | (D & T); +} + +/* SDTnaa source/pattern opaque. */ +static void rop3_8_0_0 (unsigned char *D, unsigned char S, unsigned char T) +{ + unsigned char stk1; + unsigned char stk2; + unsigned char stk3; + stk3 = ~T; + stk2 = *D & stk3; + stk1 = S & stk2; + *D = stk1; +} + +/* SDTnaa source opaque/pattern transparent. */ +static void rop3_8_0_1 (unsigned char *D, unsigned char S, unsigned char T) +{ + unsigned char stk1; + unsigned char stk2; + unsigned char stk3; + stk3 = ~T; + stk2 = *D & stk3; + stk1 = S & stk2; + *D = (stk1 & S) | (stk1 & (~T)) | (T & (~S) & *D); +} + +/* SDTnaa source transparent/pattern opaque. */ +static void rop3_8_1_0 (unsigned char *D, unsigned char S, unsigned char T) +{ + unsigned char stk1; + unsigned char stk2; + unsigned char stk3; + stk3 = ~T; + stk2 = *D & stk3; + stk1 = S & stk2; + *D = (stk1 & (~S)) | (*D & S); +} + +/* SDTnaa source/pattern transparent. */ +static void rop3_8_1_1 (unsigned char *D, unsigned char S, unsigned char T) +{ + unsigned char stk1; + unsigned char stk2; + unsigned char stk3; + stk3 = ~T; + stk2 = *D & stk3; + stk1 = S & stk2; + *D = (stk1 & (~S) & (~T)) | (*D & S) | (*D & T); +} + +/* SDTnaa source/pattern opaque. */ +static unsigned xrop3_8_0_0 (unsigned char s, unsigned char t) +{ + unsigned D = 0x00ff; + unsigned S = ((unsigned)s << 8) | s; + unsigned T = ((unsigned)t << 8) | t; + unsigned stk1; + unsigned stk2; + unsigned stk3; + stk3 = ~T; + stk2 = D & stk3; + stk1 = S & stk2; + return stk1; +} + +/* SDTnaa source opaque/pattern transparent. */ +static unsigned xrop3_8_0_1 (unsigned char s, unsigned char t) +{ + unsigned D = 0x00ff; + unsigned S = ((unsigned)s << 8) | s; + unsigned T = ((unsigned)t << 8) | t; + unsigned stk1; + unsigned stk2; + unsigned stk3; + stk3 = ~T; + stk2 = D & stk3; + stk1 = S & stk2; + return (stk1 & S) | (stk1 & (~T)) | (T & (~S) & D); +} + +/* SDTnaa source transparent/pattern opaque. */ +static unsigned xrop3_8_1_0 (unsigned char s, unsigned char t) +{ + unsigned D = 0x00ff; + unsigned S = ((unsigned)s << 8) | s; + unsigned T = ((unsigned)t << 8) | t; + unsigned stk1; + unsigned stk2; + unsigned stk3; + stk3 = ~T; + stk2 = D & stk3; + stk1 = S & stk2; + return (stk1 & (~S)) | (D & S); +} + +/* SDTnaa source/pattern transparent. */ +static unsigned xrop3_8_1_1 (unsigned char s, unsigned char t) +{ + unsigned D = 0x00ff; + unsigned S = ((unsigned)s << 8) | s; + unsigned T = ((unsigned)t << 8) | t; + unsigned stk1; + unsigned stk2; + unsigned stk3; + stk3 = ~T; + stk2 = D & stk3; + stk1 = S & stk2; + return (stk1 & (~S) & (~T)) | (D & S) | (D & T); +} + +/* TDSxon source/pattern opaque. */ +static void rop3_9_0_0 (unsigned char *D, unsigned char S, unsigned char T) +{ + unsigned char stk1; + unsigned char stk2; + stk2 = *D ^ S; + stk1 = T | stk2; + stk1 = ~stk1; + *D = stk1; +} + +/* TDSxon source opaque/pattern transparent. */ +static void rop3_9_0_1 (unsigned char *D, unsigned char S, unsigned char T) +{ + unsigned char stk1; + unsigned char stk2; + stk2 = *D ^ S; + stk1 = T | stk2; + stk1 = ~stk1; + *D = (stk1 & S) | (stk1 & (~T)) | (T & (~S) & *D); +} + +/* TDSxon source transparent/pattern opaque. */ +static void rop3_9_1_0 (unsigned char *D, unsigned char S, unsigned char T) +{ + unsigned char stk1; + unsigned char stk2; + stk2 = *D ^ S; + stk1 = T | stk2; + stk1 = ~stk1; + *D = (stk1 & (~S)) | (*D & S); +} + +/* TDSxon source/pattern transparent. */ +static void rop3_9_1_1 (unsigned char *D, unsigned char S, unsigned char T) +{ + unsigned char stk1; + unsigned char stk2; + stk2 = *D ^ S; + stk1 = T | stk2; + stk1 = ~stk1; + *D = (stk1 & (~S) & (~T)) | (*D & S) | (*D & T); +} + +/* TDSxon source/pattern opaque. */ +static unsigned xrop3_9_0_0 (unsigned char s, unsigned char t) +{ + unsigned D = 0x00ff; + unsigned S = ((unsigned)s << 8) | s; + unsigned T = ((unsigned)t << 8) | t; + unsigned stk1; + unsigned stk2; + stk2 = D ^ S; + stk1 = T | stk2; + stk1 = ~stk1; + return stk1; +} + +/* TDSxon source opaque/pattern transparent. */ +static unsigned xrop3_9_0_1 (unsigned char s, unsigned char t) +{ + unsigned D = 0x00ff; + unsigned S = ((unsigned)s << 8) | s; + unsigned T = ((unsigned)t << 8) | t; + unsigned stk1; + unsigned stk2; + stk2 = D ^ S; + stk1 = T | stk2; + stk1 = ~stk1; + return (stk1 & S) | (stk1 & (~T)) | (T & (~S) & D); +} + +/* TDSxon source transparent/pattern opaque. */ +static unsigned xrop3_9_1_0 (unsigned char s, unsigned char t) +{ + unsigned D = 0x00ff; + unsigned S = ((unsigned)s << 8) | s; + unsigned T = ((unsigned)t << 8) | t; + unsigned stk1; + unsigned stk2; + stk2 = D ^ S; + stk1 = T | stk2; + stk1 = ~stk1; + return (stk1 & (~S)) | (D & S); +} + +/* TDSxon source/pattern transparent. */ +static unsigned xrop3_9_1_1 (unsigned char s, unsigned char t) +{ + unsigned D = 0x00ff; + unsigned S = ((unsigned)s << 8) | s; + unsigned T = ((unsigned)t << 8) | t; + unsigned stk1; + unsigned stk2; + stk2 = D ^ S; + stk1 = T | stk2; + stk1 = ~stk1; + return (stk1 & (~S) & (~T)) | (D & S) | (D & T); +} + +/* DTna source/pattern opaque. */ +static void rop3_10_0_0 (unsigned char *D, unsigned char S, unsigned char T) +{ + unsigned char stk1; + unsigned char stk2; + stk2 = ~T; + stk1 = *D & stk2; + *D = stk1; +} + +/* DTna source opaque/pattern transparent. */ +static void rop3_10_0_1 (unsigned char *D, unsigned char S, unsigned char T) +{ + unsigned char stk1; + unsigned char stk2; + stk2 = ~T; + stk1 = *D & stk2; + *D = (stk1 & S) | (stk1 & (~T)) | (T & (~S) & *D); +} + +/* DTna source transparent/pattern opaque. */ +static void rop3_10_1_0 (unsigned char *D, unsigned char S, unsigned char T) +{ + unsigned char stk1; + unsigned char stk2; + stk2 = ~T; + stk1 = *D & stk2; + *D = (stk1 & (~S)) | (*D & S); +} + +/* DTna source/pattern transparent. */ +static void rop3_10_1_1 (unsigned char *D, unsigned char S, unsigned char T) +{ + unsigned char stk1; + unsigned char stk2; + stk2 = ~T; + stk1 = *D & stk2; + *D = (stk1 & (~S) & (~T)) | (*D & S) | (*D & T); +} + +/* DTna source/pattern opaque. */ +static unsigned xrop3_10_0_0 (unsigned char s, unsigned char t) +{ + unsigned D = 0x00ff; + unsigned T = ((unsigned)t << 8) | t; + unsigned stk1; + unsigned stk2; + stk2 = ~T; + stk1 = D & stk2; + return stk1; +} + +/* DTna source opaque/pattern transparent. */ +static unsigned xrop3_10_0_1 (unsigned char s, unsigned char t) +{ + unsigned D = 0x00ff; + unsigned S = ((unsigned)s << 8) | s; + unsigned T = ((unsigned)t << 8) | t; + unsigned stk1; + unsigned stk2; + stk2 = ~T; + stk1 = D & stk2; + return (stk1 & S) | (stk1 & (~T)) | (T & (~S) & D); +} + +/* DTna source transparent/pattern opaque. */ +static unsigned xrop3_10_1_0 (unsigned char s, unsigned char t) +{ + unsigned D = 0x00ff; + unsigned S = ((unsigned)s << 8) | s; + unsigned T = ((unsigned)t << 8) | t; + unsigned stk1; + unsigned stk2; + stk2 = ~T; + stk1 = D & stk2; + return (stk1 & (~S)) | (D & S); +} + +/* DTna source/pattern transparent. */ +static unsigned xrop3_10_1_1 (unsigned char s, unsigned char t) +{ + unsigned D = 0x00ff; + unsigned S = ((unsigned)s << 8) | s; + unsigned T = ((unsigned)t << 8) | t; + unsigned stk1; + unsigned stk2; + stk2 = ~T; + stk1 = D & stk2; + return (stk1 & (~S) & (~T)) | (D & S) | (D & T); +} + +/* TSDnaon source/pattern opaque. */ +static void rop3_11_0_0 (unsigned char *D, unsigned char S, unsigned char T) +{ + unsigned char stk1; + unsigned char stk2; + unsigned char stk3; + stk3 = ~*D; + stk2 = S & stk3; + stk1 = T | stk2; + stk1 = ~stk1; + *D = stk1; +} + +/* TSDnaon source opaque/pattern transparent. */ +static void rop3_11_0_1 (unsigned char *D, unsigned char S, unsigned char T) +{ + unsigned char stk1; + unsigned char stk2; + unsigned char stk3; + stk3 = ~*D; + stk2 = S & stk3; + stk1 = T | stk2; + stk1 = ~stk1; + *D = (stk1 & S) | (stk1 & (~T)) | (T & (~S) & *D); +} + +/* TSDnaon source transparent/pattern opaque. */ +static void rop3_11_1_0 (unsigned char *D, unsigned char S, unsigned char T) +{ + unsigned char stk1; + unsigned char stk2; + unsigned char stk3; + stk3 = ~*D; + stk2 = S & stk3; + stk1 = T | stk2; + stk1 = ~stk1; + *D = (stk1 & (~S)) | (*D & S); +} + +/* TSDnaon source/pattern transparent. */ +static void rop3_11_1_1 (unsigned char *D, unsigned char S, unsigned char T) +{ + unsigned char stk1; + unsigned char stk2; + unsigned char stk3; + stk3 = ~*D; + stk2 = S & stk3; + stk1 = T | stk2; + stk1 = ~stk1; + *D = (stk1 & (~S) & (~T)) | (*D & S) | (*D & T); +} + +/* TSDnaon source/pattern opaque. */ +static unsigned xrop3_11_0_0 (unsigned char s, unsigned char t) +{ + unsigned D = 0x00ff; + unsigned S = ((unsigned)s << 8) | s; + unsigned T = ((unsigned)t << 8) | t; + unsigned stk1; + unsigned stk2; + unsigned stk3; + stk3 = ~D; + stk2 = S & stk3; + stk1 = T | stk2; + stk1 = ~stk1; + return stk1; +} + +/* TSDnaon source opaque/pattern transparent. */ +static unsigned xrop3_11_0_1 (unsigned char s, unsigned char t) +{ + unsigned D = 0x00ff; + unsigned S = ((unsigned)s << 8) | s; + unsigned T = ((unsigned)t << 8) | t; + unsigned stk1; + unsigned stk2; + unsigned stk3; + stk3 = ~D; + stk2 = S & stk3; + stk1 = T | stk2; + stk1 = ~stk1; + return (stk1 & S) | (stk1 & (~T)) | (T & (~S) & D); +} + +/* TSDnaon source transparent/pattern opaque. */ +static unsigned xrop3_11_1_0 (unsigned char s, unsigned char t) +{ + unsigned D = 0x00ff; + unsigned S = ((unsigned)s << 8) | s; + unsigned T = ((unsigned)t << 8) | t; + unsigned stk1; + unsigned stk2; + unsigned stk3; + stk3 = ~D; + stk2 = S & stk3; + stk1 = T | stk2; + stk1 = ~stk1; + return (stk1 & (~S)) | (D & S); +} + +/* TSDnaon source/pattern transparent. */ +static unsigned xrop3_11_1_1 (unsigned char s, unsigned char t) +{ + unsigned D = 0x00ff; + unsigned S = ((unsigned)s << 8) | s; + unsigned T = ((unsigned)t << 8) | t; + unsigned stk1; + unsigned stk2; + unsigned stk3; + stk3 = ~D; + stk2 = S & stk3; + stk1 = T | stk2; + stk1 = ~stk1; + return (stk1 & (~S) & (~T)) | (D & S) | (D & T); +} + +/* STna source/pattern opaque. */ +static void rop3_12_0_0 (unsigned char *D, unsigned char S, unsigned char T) +{ + unsigned char stk1; + unsigned char stk2; + stk2 = ~T; + stk1 = S & stk2; + *D = stk1; +} + +/* STna source opaque/pattern transparent. */ +static void rop3_12_0_1 (unsigned char *D, unsigned char S, unsigned char T) +{ + unsigned char stk1; + unsigned char stk2; + stk2 = ~T; + stk1 = S & stk2; + *D = (stk1 & S) | (stk1 & (~T)) | (T & (~S) & *D); +} + +/* STna source transparent/pattern opaque. */ +static void rop3_12_1_0 (unsigned char *D, unsigned char S, unsigned char T) +{ + unsigned char stk1; + unsigned char stk2; + stk2 = ~T; + stk1 = S & stk2; + *D = (stk1 & (~S)) | (*D & S); +} + +/* STna source/pattern transparent. */ +static void rop3_12_1_1 (unsigned char *D, unsigned char S, unsigned char T) +{ + unsigned char stk1; + unsigned char stk2; + stk2 = ~T; + stk1 = S & stk2; + *D = (stk1 & (~S) & (~T)) | (*D & S) | (*D & T); +} + +/* STna source/pattern opaque. */ +static unsigned xrop3_12_0_0 (unsigned char s, unsigned char t) +{ + unsigned S = ((unsigned)s << 8) | s; + unsigned T = ((unsigned)t << 8) | t; + unsigned stk1; + unsigned stk2; + stk2 = ~T; + stk1 = S & stk2; + return stk1; +} + +/* STna source opaque/pattern transparent. */ +static unsigned xrop3_12_0_1 (unsigned char s, unsigned char t) +{ + unsigned D = 0x00ff; + unsigned S = ((unsigned)s << 8) | s; + unsigned T = ((unsigned)t << 8) | t; + unsigned stk1; + unsigned stk2; + stk2 = ~T; + stk1 = S & stk2; + return (stk1 & S) | (stk1 & (~T)) | (T & (~S) & D); +} + +/* STna source transparent/pattern opaque. */ +static unsigned xrop3_12_1_0 (unsigned char s, unsigned char t) +{ + unsigned D = 0x00ff; + unsigned S = ((unsigned)s << 8) | s; + unsigned T = ((unsigned)t << 8) | t; + unsigned stk1; + unsigned stk2; + stk2 = ~T; + stk1 = S & stk2; + return (stk1 & (~S)) | (D & S); +} + +/* STna source/pattern transparent. */ +static unsigned xrop3_12_1_1 (unsigned char s, unsigned char t) +{ + unsigned D = 0x00ff; + unsigned S = ((unsigned)s << 8) | s; + unsigned T = ((unsigned)t << 8) | t; + unsigned stk1; + unsigned stk2; + stk2 = ~T; + stk1 = S & stk2; + return (stk1 & (~S) & (~T)) | (D & S) | (D & T); +} + +/* TDSnaon source/pattern opaque. */ +static void rop3_13_0_0 (unsigned char *D, unsigned char S, unsigned char T) +{ + unsigned char stk1; + unsigned char stk2; + unsigned char stk3; + stk3 = ~S; + stk2 = *D & stk3; + stk1 = T | stk2; + stk1 = ~stk1; + *D = stk1; +} + +/* TDSnaon source opaque/pattern transparent. */ +static void rop3_13_0_1 (unsigned char *D, unsigned char S, unsigned char T) +{ + unsigned char stk1; + unsigned char stk2; + unsigned char stk3; + stk3 = ~S; + stk2 = *D & stk3; + stk1 = T | stk2; + stk1 = ~stk1; + *D = (stk1 & S) | (stk1 & (~T)) | (T & (~S) & *D); +} + +/* TDSnaon source transparent/pattern opaque. */ +static void rop3_13_1_0 (unsigned char *D, unsigned char S, unsigned char T) +{ + unsigned char stk1; + unsigned char stk2; + unsigned char stk3; + stk3 = ~S; + stk2 = *D & stk3; + stk1 = T | stk2; + stk1 = ~stk1; + *D = (stk1 & (~S)) | (*D & S); +} + +/* TDSnaon source/pattern transparent. */ +static void rop3_13_1_1 (unsigned char *D, unsigned char S, unsigned char T) +{ + unsigned char stk1; + unsigned char stk2; + unsigned char stk3; + stk3 = ~S; + stk2 = *D & stk3; + stk1 = T | stk2; + stk1 = ~stk1; + *D = (stk1 & (~S) & (~T)) | (*D & S) | (*D & T); +} + +/* TDSnaon source/pattern opaque. */ +static unsigned xrop3_13_0_0 (unsigned char s, unsigned char t) +{ + unsigned D = 0x00ff; + unsigned S = ((unsigned)s << 8) | s; + unsigned T = ((unsigned)t << 8) | t; + unsigned stk1; + unsigned stk2; + unsigned stk3; + stk3 = ~S; + stk2 = D & stk3; + stk1 = T | stk2; + stk1 = ~stk1; + return stk1; +} + +/* TDSnaon source opaque/pattern transparent. */ +static unsigned xrop3_13_0_1 (unsigned char s, unsigned char t) +{ + unsigned D = 0x00ff; + unsigned S = ((unsigned)s << 8) | s; + unsigned T = ((unsigned)t << 8) | t; + unsigned stk1; + unsigned stk2; + unsigned stk3; + stk3 = ~S; + stk2 = D & stk3; + stk1 = T | stk2; + stk1 = ~stk1; + return (stk1 & S) | (stk1 & (~T)) | (T & (~S) & D); +} + +/* TDSnaon source transparent/pattern opaque. */ +static unsigned xrop3_13_1_0 (unsigned char s, unsigned char t) +{ + unsigned D = 0x00ff; + unsigned S = ((unsigned)s << 8) | s; + unsigned T = ((unsigned)t << 8) | t; + unsigned stk1; + unsigned stk2; + unsigned stk3; + stk3 = ~S; + stk2 = D & stk3; + stk1 = T | stk2; + stk1 = ~stk1; + return (stk1 & (~S)) | (D & S); +} + +/* TDSnaon source/pattern transparent. */ +static unsigned xrop3_13_1_1 (unsigned char s, unsigned char t) +{ + unsigned D = 0x00ff; + unsigned S = ((unsigned)s << 8) | s; + unsigned T = ((unsigned)t << 8) | t; + unsigned stk1; + unsigned stk2; + unsigned stk3; + stk3 = ~S; + stk2 = D & stk3; + stk1 = T | stk2; + stk1 = ~stk1; + return (stk1 & (~S) & (~T)) | (D & S) | (D & T); +} + +/* TDSonon source/pattern opaque. */ +static void rop3_14_0_0 (unsigned char *D, unsigned char S, unsigned char T) +{ + unsigned char stk1; + unsigned char stk2; + stk2 = *D | S; + stk2 = ~stk2; + stk1 = T | stk2; + stk1 = ~stk1; + *D = stk1; +} + +/* TDSonon source opaque/pattern transparent. */ +static void rop3_14_0_1 (unsigned char *D, unsigned char S, unsigned char T) +{ + unsigned char stk1; + unsigned char stk2; + stk2 = *D | S; + stk2 = ~stk2; + stk1 = T | stk2; + stk1 = ~stk1; + *D = (stk1 & S) | (stk1 & (~T)) | (T & (~S) & *D); +} + +/* TDSonon source transparent/pattern opaque. */ +static void rop3_14_1_0 (unsigned char *D, unsigned char S, unsigned char T) +{ + unsigned char stk1; + unsigned char stk2; + stk2 = *D | S; + stk2 = ~stk2; + stk1 = T | stk2; + stk1 = ~stk1; + *D = (stk1 & (~S)) | (*D & S); +} + +/* TDSonon source/pattern transparent. */ +static void rop3_14_1_1 (unsigned char *D, unsigned char S, unsigned char T) +{ + unsigned char stk1; + unsigned char stk2; + stk2 = *D | S; + stk2 = ~stk2; + stk1 = T | stk2; + stk1 = ~stk1; + *D = (stk1 & (~S) & (~T)) | (*D & S) | (*D & T); +} + +/* TDSonon source/pattern opaque. */ +static unsigned xrop3_14_0_0 (unsigned char s, unsigned char t) +{ + unsigned D = 0x00ff; + unsigned S = ((unsigned)s << 8) | s; + unsigned T = ((unsigned)t << 8) | t; + unsigned stk1; + unsigned stk2; + stk2 = D | S; + stk2 = ~stk2; + stk1 = T | stk2; + stk1 = ~stk1; + return stk1; +} + +/* TDSonon source opaque/pattern transparent. */ +static unsigned xrop3_14_0_1 (unsigned char s, unsigned char t) +{ + unsigned D = 0x00ff; + unsigned S = ((unsigned)s << 8) | s; + unsigned T = ((unsigned)t << 8) | t; + unsigned stk1; + unsigned stk2; + stk2 = D | S; + stk2 = ~stk2; + stk1 = T | stk2; + stk1 = ~stk1; + return (stk1 & S) | (stk1 & (~T)) | (T & (~S) & D); +} + +/* TDSonon source transparent/pattern opaque. */ +static unsigned xrop3_14_1_0 (unsigned char s, unsigned char t) +{ + unsigned D = 0x00ff; + unsigned S = ((unsigned)s << 8) | s; + unsigned T = ((unsigned)t << 8) | t; + unsigned stk1; + unsigned stk2; + stk2 = D | S; + stk2 = ~stk2; + stk1 = T | stk2; + stk1 = ~stk1; + return (stk1 & (~S)) | (D & S); +} + +/* TDSonon source/pattern transparent. */ +static unsigned xrop3_14_1_1 (unsigned char s, unsigned char t) +{ + unsigned D = 0x00ff; + unsigned S = ((unsigned)s << 8) | s; + unsigned T = ((unsigned)t << 8) | t; + unsigned stk1; + unsigned stk2; + stk2 = D | S; + stk2 = ~stk2; + stk1 = T | stk2; + stk1 = ~stk1; + return (stk1 & (~S) & (~T)) | (D & S) | (D & T); +} + +/* Tn source/pattern opaque. */ +static void rop3_15_0_0 (unsigned char *D, unsigned char S, unsigned char T) +{ + unsigned char stk1; + stk1 = ~T; + *D = stk1; +} + +/* Tn source opaque/pattern transparent. */ +static void rop3_15_0_1 (unsigned char *D, unsigned char S, unsigned char T) +{ + unsigned char stk1; + stk1 = ~T; + *D = (stk1 & S) | (stk1 & (~T)) | (T & (~S) & *D); +} + +/* Tn source transparent/pattern opaque. */ +static void rop3_15_1_0 (unsigned char *D, unsigned char S, unsigned char T) +{ + unsigned char stk1; + stk1 = ~T; + *D = (stk1 & (~S)) | (*D & S); +} + +/* Tn source/pattern transparent. */ +static void rop3_15_1_1 (unsigned char *D, unsigned char S, unsigned char T) +{ + unsigned char stk1; + stk1 = ~T; + *D = (stk1 & (~S) & (~T)) | (*D & S) | (*D & T); +} + +/* Tn source/pattern opaque. */ +static unsigned xrop3_15_0_0 (unsigned char s, unsigned char t) +{ + unsigned T = ((unsigned)t << 8) | t; + unsigned stk1; + stk1 = ~T; + return stk1; +} + +/* Tn source opaque/pattern transparent. */ +static unsigned xrop3_15_0_1 (unsigned char s, unsigned char t) +{ + unsigned D = 0x00ff; + unsigned S = ((unsigned)s << 8) | s; + unsigned T = ((unsigned)t << 8) | t; + unsigned stk1; + stk1 = ~T; + return (stk1 & S) | (stk1 & (~T)) | (T & (~S) & D); +} + +/* Tn source transparent/pattern opaque. */ +static unsigned xrop3_15_1_0 (unsigned char s, unsigned char t) +{ + unsigned D = 0x00ff; + unsigned S = ((unsigned)s << 8) | s; + unsigned T = ((unsigned)t << 8) | t; + unsigned stk1; + stk1 = ~T; + return (stk1 & (~S)) | (D & S); +} + +/* Tn source/pattern transparent. */ +static unsigned xrop3_15_1_1 (unsigned char s, unsigned char t) +{ + unsigned D = 0x00ff; + unsigned S = ((unsigned)s << 8) | s; + unsigned T = ((unsigned)t << 8) | t; + unsigned stk1; + stk1 = ~T; + return (stk1 & (~S) & (~T)) | (D & S) | (D & T); +} + +/* TDSona source/pattern opaque. */ +static void rop3_16_0_0 (unsigned char *D, unsigned char S, unsigned char T) +{ + unsigned char stk1; + unsigned char stk2; + stk2 = *D | S; + stk2 = ~stk2; + stk1 = T & stk2; + *D = stk1; +} + +/* TDSona source opaque/pattern transparent. */ +static void rop3_16_0_1 (unsigned char *D, unsigned char S, unsigned char T) +{ + unsigned char stk1; + unsigned char stk2; + stk2 = *D | S; + stk2 = ~stk2; + stk1 = T & stk2; + *D = (stk1 & S) | (stk1 & (~T)) | (T & (~S) & *D); +} + +/* TDSona source transparent/pattern opaque. */ +static void rop3_16_1_0 (unsigned char *D, unsigned char S, unsigned char T) +{ + unsigned char stk1; + unsigned char stk2; + stk2 = *D | S; + stk2 = ~stk2; + stk1 = T & stk2; + *D = (stk1 & (~S)) | (*D & S); +} + +/* TDSona source/pattern transparent. */ +static void rop3_16_1_1 (unsigned char *D, unsigned char S, unsigned char T) +{ + unsigned char stk1; + unsigned char stk2; + stk2 = *D | S; + stk2 = ~stk2; + stk1 = T & stk2; + *D = (stk1 & (~S) & (~T)) | (*D & S) | (*D & T); +} + +/* TDSona source/pattern opaque. */ +static unsigned xrop3_16_0_0 (unsigned char s, unsigned char t) +{ + unsigned D = 0x00ff; + unsigned S = ((unsigned)s << 8) | s; + unsigned T = ((unsigned)t << 8) | t; + unsigned stk1; + unsigned stk2; + stk2 = D | S; + stk2 = ~stk2; + stk1 = T & stk2; + return stk1; +} + +/* TDSona source opaque/pattern transparent. */ +static unsigned xrop3_16_0_1 (unsigned char s, unsigned char t) +{ + unsigned D = 0x00ff; + unsigned S = ((unsigned)s << 8) | s; + unsigned T = ((unsigned)t << 8) | t; + unsigned stk1; + unsigned stk2; + stk2 = D | S; + stk2 = ~stk2; + stk1 = T & stk2; + return (stk1 & S) | (stk1 & (~T)) | (T & (~S) & D); +} + +/* TDSona source transparent/pattern opaque. */ +static unsigned xrop3_16_1_0 (unsigned char s, unsigned char t) +{ + unsigned D = 0x00ff; + unsigned S = ((unsigned)s << 8) | s; + unsigned T = ((unsigned)t << 8) | t; + unsigned stk1; + unsigned stk2; + stk2 = D | S; + stk2 = ~stk2; + stk1 = T & stk2; + return (stk1 & (~S)) | (D & S); +} + +/* TDSona source/pattern transparent. */ +static unsigned xrop3_16_1_1 (unsigned char s, unsigned char t) +{ + unsigned D = 0x00ff; + unsigned S = ((unsigned)s << 8) | s; + unsigned T = ((unsigned)t << 8) | t; + unsigned stk1; + unsigned stk2; + stk2 = D | S; + stk2 = ~stk2; + stk1 = T & stk2; + return (stk1 & (~S) & (~T)) | (D & S) | (D & T); +} + +/* DSon source/pattern opaque. */ +static void rop3_17_0_0 (unsigned char *D, unsigned char S, unsigned char T) +{ + unsigned char stk1; + stk1 = *D | S; + stk1 = ~stk1; + *D = stk1; +} + +/* DSon source opaque/pattern transparent. */ +static void rop3_17_0_1 (unsigned char *D, unsigned char S, unsigned char T) +{ + unsigned char stk1; + stk1 = *D | S; + stk1 = ~stk1; + *D = (stk1 & S) | (stk1 & (~T)) | (T & (~S) & *D); +} + +/* DSon source transparent/pattern opaque. */ +static void rop3_17_1_0 (unsigned char *D, unsigned char S, unsigned char T) +{ + unsigned char stk1; + stk1 = *D | S; + stk1 = ~stk1; + *D = (stk1 & (~S)) | (*D & S); +} + +/* DSon source/pattern transparent. */ +static void rop3_17_1_1 (unsigned char *D, unsigned char S, unsigned char T) +{ + unsigned char stk1; + stk1 = *D | S; + stk1 = ~stk1; + *D = (stk1 & (~S) & (~T)) | (*D & S) | (*D & T); +} + +/* DSon source/pattern opaque. */ +static unsigned xrop3_17_0_0 (unsigned char s, unsigned char t) +{ + unsigned D = 0x00ff; + unsigned S = ((unsigned)s << 8) | s; + unsigned stk1; + stk1 = D | S; + stk1 = ~stk1; + return stk1; +} + +/* DSon source opaque/pattern transparent. */ +static unsigned xrop3_17_0_1 (unsigned char s, unsigned char t) +{ + unsigned D = 0x00ff; + unsigned S = ((unsigned)s << 8) | s; + unsigned T = ((unsigned)t << 8) | t; + unsigned stk1; + stk1 = D | S; + stk1 = ~stk1; + return (stk1 & S) | (stk1 & (~T)) | (T & (~S) & D); +} + +/* DSon source transparent/pattern opaque. */ +static unsigned xrop3_17_1_0 (unsigned char s, unsigned char t) +{ + unsigned D = 0x00ff; + unsigned S = ((unsigned)s << 8) | s; + unsigned stk1; + stk1 = D | S; + stk1 = ~stk1; + return (stk1 & (~S)) | (D & S); +} + +/* DSon source/pattern transparent. */ +static unsigned xrop3_17_1_1 (unsigned char s, unsigned char t) +{ + unsigned D = 0x00ff; + unsigned S = ((unsigned)s << 8) | s; + unsigned T = ((unsigned)t << 8) | t; + unsigned stk1; + stk1 = D | S; + stk1 = ~stk1; + return (stk1 & (~S) & (~T)) | (D & S) | (D & T); +} + +/* SDTxnon source/pattern opaque. */ +static void rop3_18_0_0 (unsigned char *D, unsigned char S, unsigned char T) +{ + unsigned char stk1; + unsigned char stk2; + stk2 = *D ^ T; + stk2 = ~stk2; + stk1 = S | stk2; + stk1 = ~stk1; + *D = stk1; +} + +/* SDTxnon source opaque/pattern transparent. */ +static void rop3_18_0_1 (unsigned char *D, unsigned char S, unsigned char T) +{ + unsigned char stk1; + unsigned char stk2; + stk2 = *D ^ T; + stk2 = ~stk2; + stk1 = S | stk2; + stk1 = ~stk1; + *D = (stk1 & S) | (stk1 & (~T)) | (T & (~S) & *D); +} + +/* SDTxnon source transparent/pattern opaque. */ +static void rop3_18_1_0 (unsigned char *D, unsigned char S, unsigned char T) +{ + unsigned char stk1; + unsigned char stk2; + stk2 = *D ^ T; + stk2 = ~stk2; + stk1 = S | stk2; + stk1 = ~stk1; + *D = (stk1 & (~S)) | (*D & S); +} + +/* SDTxnon source/pattern transparent. */ +static void rop3_18_1_1 (unsigned char *D, unsigned char S, unsigned char T) +{ + unsigned char stk1; + unsigned char stk2; + stk2 = *D ^ T; + stk2 = ~stk2; + stk1 = S | stk2; + stk1 = ~stk1; + *D = (stk1 & (~S) & (~T)) | (*D & S) | (*D & T); +} + +/* SDTxnon source/pattern opaque. */ +static unsigned xrop3_18_0_0 (unsigned char s, unsigned char t) +{ + unsigned D = 0x00ff; + unsigned S = ((unsigned)s << 8) | s; + unsigned T = ((unsigned)t << 8) | t; + unsigned stk1; + unsigned stk2; + stk2 = D ^ T; + stk2 = ~stk2; + stk1 = S | stk2; + stk1 = ~stk1; + return stk1; +} + +/* SDTxnon source opaque/pattern transparent. */ +static unsigned xrop3_18_0_1 (unsigned char s, unsigned char t) +{ + unsigned D = 0x00ff; + unsigned S = ((unsigned)s << 8) | s; + unsigned T = ((unsigned)t << 8) | t; + unsigned stk1; + unsigned stk2; + stk2 = D ^ T; + stk2 = ~stk2; + stk1 = S | stk2; + stk1 = ~stk1; + return (stk1 & S) | (stk1 & (~T)) | (T & (~S) & D); +} + +/* SDTxnon source transparent/pattern opaque. */ +static unsigned xrop3_18_1_0 (unsigned char s, unsigned char t) +{ + unsigned D = 0x00ff; + unsigned S = ((unsigned)s << 8) | s; + unsigned T = ((unsigned)t << 8) | t; + unsigned stk1; + unsigned stk2; + stk2 = D ^ T; + stk2 = ~stk2; + stk1 = S | stk2; + stk1 = ~stk1; + return (stk1 & (~S)) | (D & S); +} + +/* SDTxnon source/pattern transparent. */ +static unsigned xrop3_18_1_1 (unsigned char s, unsigned char t) +{ + unsigned D = 0x00ff; + unsigned S = ((unsigned)s << 8) | s; + unsigned T = ((unsigned)t << 8) | t; + unsigned stk1; + unsigned stk2; + stk2 = D ^ T; + stk2 = ~stk2; + stk1 = S | stk2; + stk1 = ~stk1; + return (stk1 & (~S) & (~T)) | (D & S) | (D & T); +} + +/* SDTaon source/pattern opaque. */ +static void rop3_19_0_0 (unsigned char *D, unsigned char S, unsigned char T) +{ + unsigned char stk1; + unsigned char stk2; + stk2 = *D & T; + stk1 = S | stk2; + stk1 = ~stk1; + *D = stk1; +} + +/* SDTaon source opaque/pattern transparent. */ +static void rop3_19_0_1 (unsigned char *D, unsigned char S, unsigned char T) +{ + unsigned char stk1; + unsigned char stk2; + stk2 = *D & T; + stk1 = S | stk2; + stk1 = ~stk1; + *D = (stk1 & S) | (stk1 & (~T)) | (T & (~S) & *D); +} + +/* SDTaon source transparent/pattern opaque. */ +static void rop3_19_1_0 (unsigned char *D, unsigned char S, unsigned char T) +{ + unsigned char stk1; + unsigned char stk2; + stk2 = *D & T; + stk1 = S | stk2; + stk1 = ~stk1; + *D = (stk1 & (~S)) | (*D & S); +} + +/* SDTaon source/pattern transparent. */ +static void rop3_19_1_1 (unsigned char *D, unsigned char S, unsigned char T) +{ + unsigned char stk1; + unsigned char stk2; + stk2 = *D & T; + stk1 = S | stk2; + stk1 = ~stk1; + *D = (stk1 & (~S) & (~T)) | (*D & S) | (*D & T); +} + +/* SDTaon source/pattern opaque. */ +static unsigned xrop3_19_0_0 (unsigned char s, unsigned char t) +{ + unsigned D = 0x00ff; + unsigned S = ((unsigned)s << 8) | s; + unsigned T = ((unsigned)t << 8) | t; + unsigned stk1; + unsigned stk2; + stk2 = D & T; + stk1 = S | stk2; + stk1 = ~stk1; + return stk1; +} + +/* SDTaon source opaque/pattern transparent. */ +static unsigned xrop3_19_0_1 (unsigned char s, unsigned char t) +{ + unsigned D = 0x00ff; + unsigned S = ((unsigned)s << 8) | s; + unsigned T = ((unsigned)t << 8) | t; + unsigned stk1; + unsigned stk2; + stk2 = D & T; + stk1 = S | stk2; + stk1 = ~stk1; + return (stk1 & S) | (stk1 & (~T)) | (T & (~S) & D); +} + +/* SDTaon source transparent/pattern opaque. */ +static unsigned xrop3_19_1_0 (unsigned char s, unsigned char t) +{ + unsigned D = 0x00ff; + unsigned S = ((unsigned)s << 8) | s; + unsigned T = ((unsigned)t << 8) | t; + unsigned stk1; + unsigned stk2; + stk2 = D & T; + stk1 = S | stk2; + stk1 = ~stk1; + return (stk1 & (~S)) | (D & S); +} + +/* SDTaon source/pattern transparent. */ +static unsigned xrop3_19_1_1 (unsigned char s, unsigned char t) +{ + unsigned D = 0x00ff; + unsigned S = ((unsigned)s << 8) | s; + unsigned T = ((unsigned)t << 8) | t; + unsigned stk1; + unsigned stk2; + stk2 = D & T; + stk1 = S | stk2; + stk1 = ~stk1; + return (stk1 & (~S) & (~T)) | (D & S) | (D & T); +} + +/* DTSxnon source/pattern opaque. */ +static void rop3_20_0_0 (unsigned char *D, unsigned char S, unsigned char T) +{ + unsigned char stk1; + unsigned char stk2; + stk2 = T ^ S; + stk2 = ~stk2; + stk1 = *D | stk2; + stk1 = ~stk1; + *D = stk1; +} + +/* DTSxnon source opaque/pattern transparent. */ +static void rop3_20_0_1 (unsigned char *D, unsigned char S, unsigned char T) +{ + unsigned char stk1; + unsigned char stk2; + stk2 = T ^ S; + stk2 = ~stk2; + stk1 = *D | stk2; + stk1 = ~stk1; + *D = (stk1 & S) | (stk1 & (~T)) | (T & (~S) & *D); +} + +/* DTSxnon source transparent/pattern opaque. */ +static void rop3_20_1_0 (unsigned char *D, unsigned char S, unsigned char T) +{ + unsigned char stk1; + unsigned char stk2; + stk2 = T ^ S; + stk2 = ~stk2; + stk1 = *D | stk2; + stk1 = ~stk1; + *D = (stk1 & (~S)) | (*D & S); +} + +/* DTSxnon source/pattern transparent. */ +static void rop3_20_1_1 (unsigned char *D, unsigned char S, unsigned char T) +{ + unsigned char stk1; + unsigned char stk2; + stk2 = T ^ S; + stk2 = ~stk2; + stk1 = *D | stk2; + stk1 = ~stk1; + *D = (stk1 & (~S) & (~T)) | (*D & S) | (*D & T); +} + +/* DTSxnon source/pattern opaque. */ +static unsigned xrop3_20_0_0 (unsigned char s, unsigned char t) +{ + unsigned D = 0x00ff; + unsigned S = ((unsigned)s << 8) | s; + unsigned T = ((unsigned)t << 8) | t; + unsigned stk1; + unsigned stk2; + stk2 = T ^ S; + stk2 = ~stk2; + stk1 = D | stk2; + stk1 = ~stk1; + return stk1; +} + +/* DTSxnon source opaque/pattern transparent. */ +static unsigned xrop3_20_0_1 (unsigned char s, unsigned char t) +{ + unsigned D = 0x00ff; + unsigned S = ((unsigned)s << 8) | s; + unsigned T = ((unsigned)t << 8) | t; + unsigned stk1; + unsigned stk2; + stk2 = T ^ S; + stk2 = ~stk2; + stk1 = D | stk2; + stk1 = ~stk1; + return (stk1 & S) | (stk1 & (~T)) | (T & (~S) & D); +} + +/* DTSxnon source transparent/pattern opaque. */ +static unsigned xrop3_20_1_0 (unsigned char s, unsigned char t) +{ + unsigned D = 0x00ff; + unsigned S = ((unsigned)s << 8) | s; + unsigned T = ((unsigned)t << 8) | t; + unsigned stk1; + unsigned stk2; + stk2 = T ^ S; + stk2 = ~stk2; + stk1 = D | stk2; + stk1 = ~stk1; + return (stk1 & (~S)) | (D & S); +} + +/* DTSxnon source/pattern transparent. */ +static unsigned xrop3_20_1_1 (unsigned char s, unsigned char t) +{ + unsigned D = 0x00ff; + unsigned S = ((unsigned)s << 8) | s; + unsigned T = ((unsigned)t << 8) | t; + unsigned stk1; + unsigned stk2; + stk2 = T ^ S; + stk2 = ~stk2; + stk1 = D | stk2; + stk1 = ~stk1; + return (stk1 & (~S) & (~T)) | (D & S) | (D & T); +} + +/* DTSaon source/pattern opaque. */ +static void rop3_21_0_0 (unsigned char *D, unsigned char S, unsigned char T) +{ + unsigned char stk1; + unsigned char stk2; + stk2 = T & S; + stk1 = *D | stk2; + stk1 = ~stk1; + *D = stk1; +} + +/* DTSaon source opaque/pattern transparent. */ +static void rop3_21_0_1 (unsigned char *D, unsigned char S, unsigned char T) +{ + unsigned char stk1; + unsigned char stk2; + stk2 = T & S; + stk1 = *D | stk2; + stk1 = ~stk1; + *D = (stk1 & S) | (stk1 & (~T)) | (T & (~S) & *D); +} + +/* DTSaon source transparent/pattern opaque. */ +static void rop3_21_1_0 (unsigned char *D, unsigned char S, unsigned char T) +{ + unsigned char stk1; + unsigned char stk2; + stk2 = T & S; + stk1 = *D | stk2; + stk1 = ~stk1; + *D = (stk1 & (~S)) | (*D & S); +} + +/* DTSaon source/pattern transparent. */ +static void rop3_21_1_1 (unsigned char *D, unsigned char S, unsigned char T) +{ + unsigned char stk1; + unsigned char stk2; + stk2 = T & S; + stk1 = *D | stk2; + stk1 = ~stk1; + *D = (stk1 & (~S) & (~T)) | (*D & S) | (*D & T); +} + +/* DTSaon source/pattern opaque. */ +static unsigned xrop3_21_0_0 (unsigned char s, unsigned char t) +{ + unsigned D = 0x00ff; + unsigned S = ((unsigned)s << 8) | s; + unsigned T = ((unsigned)t << 8) | t; + unsigned stk1; + unsigned stk2; + stk2 = T & S; + stk1 = D | stk2; + stk1 = ~stk1; + return stk1; +} + +/* DTSaon source opaque/pattern transparent. */ +static unsigned xrop3_21_0_1 (unsigned char s, unsigned char t) +{ + unsigned D = 0x00ff; + unsigned S = ((unsigned)s << 8) | s; + unsigned T = ((unsigned)t << 8) | t; + unsigned stk1; + unsigned stk2; + stk2 = T & S; + stk1 = D | stk2; + stk1 = ~stk1; + return (stk1 & S) | (stk1 & (~T)) | (T & (~S) & D); +} + +/* DTSaon source transparent/pattern opaque. */ +static unsigned xrop3_21_1_0 (unsigned char s, unsigned char t) +{ + unsigned D = 0x00ff; + unsigned S = ((unsigned)s << 8) | s; + unsigned T = ((unsigned)t << 8) | t; + unsigned stk1; + unsigned stk2; + stk2 = T & S; + stk1 = D | stk2; + stk1 = ~stk1; + return (stk1 & (~S)) | (D & S); +} + +/* DTSaon source/pattern transparent. */ +static unsigned xrop3_21_1_1 (unsigned char s, unsigned char t) +{ + unsigned D = 0x00ff; + unsigned S = ((unsigned)s << 8) | s; + unsigned T = ((unsigned)t << 8) | t; + unsigned stk1; + unsigned stk2; + stk2 = T & S; + stk1 = D | stk2; + stk1 = ~stk1; + return (stk1 & (~S) & (~T)) | (D & S) | (D & T); +} + +/* TSDTSanaxx source/pattern opaque. */ +static void rop3_22_0_0 (unsigned char *D, unsigned char S, unsigned char T) +{ + unsigned char stk1; + unsigned char stk2; + unsigned char stk3; + unsigned char stk4; + stk4 = T & S; + stk4 = ~stk4; + stk3 = *D & stk4; + stk2 = S ^ stk3; + stk1 = T ^ stk2; + *D = stk1; +} + +/* TSDTSanaxx source opaque/pattern transparent. */ +static void rop3_22_0_1 (unsigned char *D, unsigned char S, unsigned char T) +{ + unsigned char stk1; + unsigned char stk2; + unsigned char stk3; + unsigned char stk4; + stk4 = T & S; + stk4 = ~stk4; + stk3 = *D & stk4; + stk2 = S ^ stk3; + stk1 = T ^ stk2; + *D = (stk1 & S) | (stk1 & (~T)) | (T & (~S) & *D); +} + +/* TSDTSanaxx source transparent/pattern opaque. */ +static void rop3_22_1_0 (unsigned char *D, unsigned char S, unsigned char T) +{ + unsigned char stk1; + unsigned char stk2; + unsigned char stk3; + unsigned char stk4; + stk4 = T & S; + stk4 = ~stk4; + stk3 = *D & stk4; + stk2 = S ^ stk3; + stk1 = T ^ stk2; + *D = (stk1 & (~S)) | (*D & S); +} + +/* TSDTSanaxx source/pattern transparent. */ +static void rop3_22_1_1 (unsigned char *D, unsigned char S, unsigned char T) +{ + unsigned char stk1; + unsigned char stk2; + unsigned char stk3; + unsigned char stk4; + stk4 = T & S; + stk4 = ~stk4; + stk3 = *D & stk4; + stk2 = S ^ stk3; + stk1 = T ^ stk2; + *D = (stk1 & (~S) & (~T)) | (*D & S) | (*D & T); +} + +/* TSDTSanaxx source/pattern opaque. */ +static unsigned xrop3_22_0_0 (unsigned char s, unsigned char t) +{ + unsigned D = 0x00ff; + unsigned S = ((unsigned)s << 8) | s; + unsigned T = ((unsigned)t << 8) | t; + unsigned stk1; + unsigned stk2; + unsigned stk3; + unsigned stk4; + stk4 = T & S; + stk4 = ~stk4; + stk3 = D & stk4; + stk2 = S ^ stk3; + stk1 = T ^ stk2; + return stk1; +} + +/* TSDTSanaxx source opaque/pattern transparent. */ +static unsigned xrop3_22_0_1 (unsigned char s, unsigned char t) +{ + unsigned D = 0x00ff; + unsigned S = ((unsigned)s << 8) | s; + unsigned T = ((unsigned)t << 8) | t; + unsigned stk1; + unsigned stk2; + unsigned stk3; + unsigned stk4; + stk4 = T & S; + stk4 = ~stk4; + stk3 = D & stk4; + stk2 = S ^ stk3; + stk1 = T ^ stk2; + return (stk1 & S) | (stk1 & (~T)) | (T & (~S) & D); +} + +/* TSDTSanaxx source transparent/pattern opaque. */ +static unsigned xrop3_22_1_0 (unsigned char s, unsigned char t) +{ + unsigned D = 0x00ff; + unsigned S = ((unsigned)s << 8) | s; + unsigned T = ((unsigned)t << 8) | t; + unsigned stk1; + unsigned stk2; + unsigned stk3; + unsigned stk4; + stk4 = T & S; + stk4 = ~stk4; + stk3 = D & stk4; + stk2 = S ^ stk3; + stk1 = T ^ stk2; + return (stk1 & (~S)) | (D & S); +} + +/* TSDTSanaxx source/pattern transparent. */ +static unsigned xrop3_22_1_1 (unsigned char s, unsigned char t) +{ + unsigned D = 0x00ff; + unsigned S = ((unsigned)s << 8) | s; + unsigned T = ((unsigned)t << 8) | t; + unsigned stk1; + unsigned stk2; + unsigned stk3; + unsigned stk4; + stk4 = T & S; + stk4 = ~stk4; + stk3 = D & stk4; + stk2 = S ^ stk3; + stk1 = T ^ stk2; + return (stk1 & (~S) & (~T)) | (D & S) | (D & T); +} + +/* SSTxDSxaxn source/pattern opaque. */ +static void rop3_23_0_0 (unsigned char *D, unsigned char S, unsigned char T) +{ + unsigned char stk1; + unsigned char stk2; + unsigned char stk3; + stk2 = S ^ T; + stk3 = *D ^ S; + stk2 = stk2 & stk3; + stk1 = S ^ stk2; + stk1 = ~stk1; + *D = stk1; +} + +/* SSTxDSxaxn source opaque/pattern transparent. */ +static void rop3_23_0_1 (unsigned char *D, unsigned char S, unsigned char T) +{ + unsigned char stk1; + unsigned char stk2; + unsigned char stk3; + stk2 = S ^ T; + stk3 = *D ^ S; + stk2 = stk2 & stk3; + stk1 = S ^ stk2; + stk1 = ~stk1; + *D = (stk1 & S) | (stk1 & (~T)) | (T & (~S) & *D); +} + +/* SSTxDSxaxn source transparent/pattern opaque. */ +static void rop3_23_1_0 (unsigned char *D, unsigned char S, unsigned char T) +{ + unsigned char stk1; + unsigned char stk2; + unsigned char stk3; + stk2 = S ^ T; + stk3 = *D ^ S; + stk2 = stk2 & stk3; + stk1 = S ^ stk2; + stk1 = ~stk1; + *D = (stk1 & (~S)) | (*D & S); +} + +/* SSTxDSxaxn source/pattern transparent. */ +static void rop3_23_1_1 (unsigned char *D, unsigned char S, unsigned char T) +{ + unsigned char stk1; + unsigned char stk2; + unsigned char stk3; + stk2 = S ^ T; + stk3 = *D ^ S; + stk2 = stk2 & stk3; + stk1 = S ^ stk2; + stk1 = ~stk1; + *D = (stk1 & (~S) & (~T)) | (*D & S) | (*D & T); +} + +/* SSTxDSxaxn source/pattern opaque. */ +static unsigned xrop3_23_0_0 (unsigned char s, unsigned char t) +{ + unsigned D = 0x00ff; + unsigned S = ((unsigned)s << 8) | s; + unsigned T = ((unsigned)t << 8) | t; + unsigned stk1; + unsigned stk2; + unsigned stk3; + stk2 = S ^ T; + stk3 = D ^ S; + stk2 = stk2 & stk3; + stk1 = S ^ stk2; + stk1 = ~stk1; + return stk1; +} + +/* SSTxDSxaxn source opaque/pattern transparent. */ +static unsigned xrop3_23_0_1 (unsigned char s, unsigned char t) +{ + unsigned D = 0x00ff; + unsigned S = ((unsigned)s << 8) | s; + unsigned T = ((unsigned)t << 8) | t; + unsigned stk1; + unsigned stk2; + unsigned stk3; + stk2 = S ^ T; + stk3 = D ^ S; + stk2 = stk2 & stk3; + stk1 = S ^ stk2; + stk1 = ~stk1; + return (stk1 & S) | (stk1 & (~T)) | (T & (~S) & D); +} + +/* SSTxDSxaxn source transparent/pattern opaque. */ +static unsigned xrop3_23_1_0 (unsigned char s, unsigned char t) +{ + unsigned D = 0x00ff; + unsigned S = ((unsigned)s << 8) | s; + unsigned T = ((unsigned)t << 8) | t; + unsigned stk1; + unsigned stk2; + unsigned stk3; + stk2 = S ^ T; + stk3 = D ^ S; + stk2 = stk2 & stk3; + stk1 = S ^ stk2; + stk1 = ~stk1; + return (stk1 & (~S)) | (D & S); +} + +/* SSTxDSxaxn source/pattern transparent. */ +static unsigned xrop3_23_1_1 (unsigned char s, unsigned char t) +{ + unsigned D = 0x00ff; + unsigned S = ((unsigned)s << 8) | s; + unsigned T = ((unsigned)t << 8) | t; + unsigned stk1; + unsigned stk2; + unsigned stk3; + stk2 = S ^ T; + stk3 = D ^ S; + stk2 = stk2 & stk3; + stk1 = S ^ stk2; + stk1 = ~stk1; + return (stk1 & (~S) & (~T)) | (D & S) | (D & T); +} + +/* STxTDxa source/pattern opaque. */ +static void rop3_24_0_0 (unsigned char *D, unsigned char S, unsigned char T) +{ + unsigned char stk1; + unsigned char stk2; + stk1 = S ^ T; + stk2 = T ^ *D; + stk1 = stk1 & stk2; + *D = stk1; +} + +/* STxTDxa source opaque/pattern transparent. */ +static void rop3_24_0_1 (unsigned char *D, unsigned char S, unsigned char T) +{ + unsigned char stk1; + unsigned char stk2; + stk1 = S ^ T; + stk2 = T ^ *D; + stk1 = stk1 & stk2; + *D = (stk1 & S) | (stk1 & (~T)) | (T & (~S) & *D); +} + +/* STxTDxa source transparent/pattern opaque. */ +static void rop3_24_1_0 (unsigned char *D, unsigned char S, unsigned char T) +{ + unsigned char stk1; + unsigned char stk2; + stk1 = S ^ T; + stk2 = T ^ *D; + stk1 = stk1 & stk2; + *D = (stk1 & (~S)) | (*D & S); +} + +/* STxTDxa source/pattern transparent. */ +static void rop3_24_1_1 (unsigned char *D, unsigned char S, unsigned char T) +{ + unsigned char stk1; + unsigned char stk2; + stk1 = S ^ T; + stk2 = T ^ *D; + stk1 = stk1 & stk2; + *D = (stk1 & (~S) & (~T)) | (*D & S) | (*D & T); +} + +/* STxTDxa source/pattern opaque. */ +static unsigned xrop3_24_0_0 (unsigned char s, unsigned char t) +{ + unsigned D = 0x00ff; + unsigned S = ((unsigned)s << 8) | s; + unsigned T = ((unsigned)t << 8) | t; + unsigned stk1; + unsigned stk2; + stk1 = S ^ T; + stk2 = T ^ D; + stk1 = stk1 & stk2; + return stk1; +} + +/* STxTDxa source opaque/pattern transparent. */ +static unsigned xrop3_24_0_1 (unsigned char s, unsigned char t) +{ + unsigned D = 0x00ff; + unsigned S = ((unsigned)s << 8) | s; + unsigned T = ((unsigned)t << 8) | t; + unsigned stk1; + unsigned stk2; + stk1 = S ^ T; + stk2 = T ^ D; + stk1 = stk1 & stk2; + return (stk1 & S) | (stk1 & (~T)) | (T & (~S) & D); +} + +/* STxTDxa source transparent/pattern opaque. */ +static unsigned xrop3_24_1_0 (unsigned char s, unsigned char t) +{ + unsigned D = 0x00ff; + unsigned S = ((unsigned)s << 8) | s; + unsigned T = ((unsigned)t << 8) | t; + unsigned stk1; + unsigned stk2; + stk1 = S ^ T; + stk2 = T ^ D; + stk1 = stk1 & stk2; + return (stk1 & (~S)) | (D & S); +} + +/* STxTDxa source/pattern transparent. */ +static unsigned xrop3_24_1_1 (unsigned char s, unsigned char t) +{ + unsigned D = 0x00ff; + unsigned S = ((unsigned)s << 8) | s; + unsigned T = ((unsigned)t << 8) | t; + unsigned stk1; + unsigned stk2; + stk1 = S ^ T; + stk2 = T ^ D; + stk1 = stk1 & stk2; + return (stk1 & (~S) & (~T)) | (D & S) | (D & T); +} + +/* SDTSanaxn source/pattern opaque. */ +static void rop3_25_0_0 (unsigned char *D, unsigned char S, unsigned char T) +{ + unsigned char stk1; + unsigned char stk2; + unsigned char stk3; + stk3 = T & S; + stk3 = ~stk3; + stk2 = *D & stk3; + stk1 = S ^ stk2; + stk1 = ~stk1; + *D = stk1; +} + +/* SDTSanaxn source opaque/pattern transparent. */ +static void rop3_25_0_1 (unsigned char *D, unsigned char S, unsigned char T) +{ + unsigned char stk1; + unsigned char stk2; + unsigned char stk3; + stk3 = T & S; + stk3 = ~stk3; + stk2 = *D & stk3; + stk1 = S ^ stk2; + stk1 = ~stk1; + *D = (stk1 & S) | (stk1 & (~T)) | (T & (~S) & *D); +} + +/* SDTSanaxn source transparent/pattern opaque. */ +static void rop3_25_1_0 (unsigned char *D, unsigned char S, unsigned char T) +{ + unsigned char stk1; + unsigned char stk2; + unsigned char stk3; + stk3 = T & S; + stk3 = ~stk3; + stk2 = *D & stk3; + stk1 = S ^ stk2; + stk1 = ~stk1; + *D = (stk1 & (~S)) | (*D & S); +} + +/* SDTSanaxn source/pattern transparent. */ +static void rop3_25_1_1 (unsigned char *D, unsigned char S, unsigned char T) +{ + unsigned char stk1; + unsigned char stk2; + unsigned char stk3; + stk3 = T & S; + stk3 = ~stk3; + stk2 = *D & stk3; + stk1 = S ^ stk2; + stk1 = ~stk1; + *D = (stk1 & (~S) & (~T)) | (*D & S) | (*D & T); +} + +/* SDTSanaxn source/pattern opaque. */ +static unsigned xrop3_25_0_0 (unsigned char s, unsigned char t) +{ + unsigned D = 0x00ff; + unsigned S = ((unsigned)s << 8) | s; + unsigned T = ((unsigned)t << 8) | t; + unsigned stk1; + unsigned stk2; + unsigned stk3; + stk3 = T & S; + stk3 = ~stk3; + stk2 = D & stk3; + stk1 = S ^ stk2; + stk1 = ~stk1; + return stk1; +} + +/* SDTSanaxn source opaque/pattern transparent. */ +static unsigned xrop3_25_0_1 (unsigned char s, unsigned char t) +{ + unsigned D = 0x00ff; + unsigned S = ((unsigned)s << 8) | s; + unsigned T = ((unsigned)t << 8) | t; + unsigned stk1; + unsigned stk2; + unsigned stk3; + stk3 = T & S; + stk3 = ~stk3; + stk2 = D & stk3; + stk1 = S ^ stk2; + stk1 = ~stk1; + return (stk1 & S) | (stk1 & (~T)) | (T & (~S) & D); +} + +/* SDTSanaxn source transparent/pattern opaque. */ +static unsigned xrop3_25_1_0 (unsigned char s, unsigned char t) +{ + unsigned D = 0x00ff; + unsigned S = ((unsigned)s << 8) | s; + unsigned T = ((unsigned)t << 8) | t; + unsigned stk1; + unsigned stk2; + unsigned stk3; + stk3 = T & S; + stk3 = ~stk3; + stk2 = D & stk3; + stk1 = S ^ stk2; + stk1 = ~stk1; + return (stk1 & (~S)) | (D & S); +} + +/* SDTSanaxn source/pattern transparent. */ +static unsigned xrop3_25_1_1 (unsigned char s, unsigned char t) +{ + unsigned D = 0x00ff; + unsigned S = ((unsigned)s << 8) | s; + unsigned T = ((unsigned)t << 8) | t; + unsigned stk1; + unsigned stk2; + unsigned stk3; + stk3 = T & S; + stk3 = ~stk3; + stk2 = D & stk3; + stk1 = S ^ stk2; + stk1 = ~stk1; + return (stk1 & (~S) & (~T)) | (D & S) | (D & T); +} + +/* TDSTaox source/pattern opaque. */ +static void rop3_26_0_0 (unsigned char *D, unsigned char S, unsigned char T) +{ + unsigned char stk1; + unsigned char stk2; + unsigned char stk3; + stk3 = S & T; + stk2 = *D | stk3; + stk1 = T ^ stk2; + *D = stk1; +} + +/* TDSTaox source opaque/pattern transparent. */ +static void rop3_26_0_1 (unsigned char *D, unsigned char S, unsigned char T) +{ + unsigned char stk1; + unsigned char stk2; + unsigned char stk3; + stk3 = S & T; + stk2 = *D | stk3; + stk1 = T ^ stk2; + *D = (stk1 & S) | (stk1 & (~T)) | (T & (~S) & *D); +} + +/* TDSTaox source transparent/pattern opaque. */ +static void rop3_26_1_0 (unsigned char *D, unsigned char S, unsigned char T) +{ + unsigned char stk1; + unsigned char stk2; + unsigned char stk3; + stk3 = S & T; + stk2 = *D | stk3; + stk1 = T ^ stk2; + *D = (stk1 & (~S)) | (*D & S); +} + +/* TDSTaox source/pattern transparent. */ +static void rop3_26_1_1 (unsigned char *D, unsigned char S, unsigned char T) +{ + unsigned char stk1; + unsigned char stk2; + unsigned char stk3; + stk3 = S & T; + stk2 = *D | stk3; + stk1 = T ^ stk2; + *D = (stk1 & (~S) & (~T)) | (*D & S) | (*D & T); +} + +/* TDSTaox source/pattern opaque. */ +static unsigned xrop3_26_0_0 (unsigned char s, unsigned char t) +{ + unsigned D = 0x00ff; + unsigned S = ((unsigned)s << 8) | s; + unsigned T = ((unsigned)t << 8) | t; + unsigned stk1; + unsigned stk2; + unsigned stk3; + stk3 = S & T; + stk2 = D | stk3; + stk1 = T ^ stk2; + return stk1; +} + +/* TDSTaox source opaque/pattern transparent. */ +static unsigned xrop3_26_0_1 (unsigned char s, unsigned char t) +{ + unsigned D = 0x00ff; + unsigned S = ((unsigned)s << 8) | s; + unsigned T = ((unsigned)t << 8) | t; + unsigned stk1; + unsigned stk2; + unsigned stk3; + stk3 = S & T; + stk2 = D | stk3; + stk1 = T ^ stk2; + return (stk1 & S) | (stk1 & (~T)) | (T & (~S) & D); +} + +/* TDSTaox source transparent/pattern opaque. */ +static unsigned xrop3_26_1_0 (unsigned char s, unsigned char t) +{ + unsigned D = 0x00ff; + unsigned S = ((unsigned)s << 8) | s; + unsigned T = ((unsigned)t << 8) | t; + unsigned stk1; + unsigned stk2; + unsigned stk3; + stk3 = S & T; + stk2 = D | stk3; + stk1 = T ^ stk2; + return (stk1 & (~S)) | (D & S); +} + +/* TDSTaox source/pattern transparent. */ +static unsigned xrop3_26_1_1 (unsigned char s, unsigned char t) +{ + unsigned D = 0x00ff; + unsigned S = ((unsigned)s << 8) | s; + unsigned T = ((unsigned)t << 8) | t; + unsigned stk1; + unsigned stk2; + unsigned stk3; + stk3 = S & T; + stk2 = D | stk3; + stk1 = T ^ stk2; + return (stk1 & (~S) & (~T)) | (D & S) | (D & T); +} + +/* SDTSxaxn source/pattern opaque. */ +static void rop3_27_0_0 (unsigned char *D, unsigned char S, unsigned char T) +{ + unsigned char stk1; + unsigned char stk2; + unsigned char stk3; + stk3 = T ^ S; + stk2 = *D & stk3; + stk1 = S ^ stk2; + stk1 = ~stk1; + *D = stk1; +} + +/* SDTSxaxn source opaque/pattern transparent. */ +static void rop3_27_0_1 (unsigned char *D, unsigned char S, unsigned char T) +{ + unsigned char stk1; + unsigned char stk2; + unsigned char stk3; + stk3 = T ^ S; + stk2 = *D & stk3; + stk1 = S ^ stk2; + stk1 = ~stk1; + *D = (stk1 & S) | (stk1 & (~T)) | (T & (~S) & *D); +} + +/* SDTSxaxn source transparent/pattern opaque. */ +static void rop3_27_1_0 (unsigned char *D, unsigned char S, unsigned char T) +{ + unsigned char stk1; + unsigned char stk2; + unsigned char stk3; + stk3 = T ^ S; + stk2 = *D & stk3; + stk1 = S ^ stk2; + stk1 = ~stk1; + *D = (stk1 & (~S)) | (*D & S); +} + +/* SDTSxaxn source/pattern transparent. */ +static void rop3_27_1_1 (unsigned char *D, unsigned char S, unsigned char T) +{ + unsigned char stk1; + unsigned char stk2; + unsigned char stk3; + stk3 = T ^ S; + stk2 = *D & stk3; + stk1 = S ^ stk2; + stk1 = ~stk1; + *D = (stk1 & (~S) & (~T)) | (*D & S) | (*D & T); +} + +/* SDTSxaxn source/pattern opaque. */ +static unsigned xrop3_27_0_0 (unsigned char s, unsigned char t) +{ + unsigned D = 0x00ff; + unsigned S = ((unsigned)s << 8) | s; + unsigned T = ((unsigned)t << 8) | t; + unsigned stk1; + unsigned stk2; + unsigned stk3; + stk3 = T ^ S; + stk2 = D & stk3; + stk1 = S ^ stk2; + stk1 = ~stk1; + return stk1; +} + +/* SDTSxaxn source opaque/pattern transparent. */ +static unsigned xrop3_27_0_1 (unsigned char s, unsigned char t) +{ + unsigned D = 0x00ff; + unsigned S = ((unsigned)s << 8) | s; + unsigned T = ((unsigned)t << 8) | t; + unsigned stk1; + unsigned stk2; + unsigned stk3; + stk3 = T ^ S; + stk2 = D & stk3; + stk1 = S ^ stk2; + stk1 = ~stk1; + return (stk1 & S) | (stk1 & (~T)) | (T & (~S) & D); +} + +/* SDTSxaxn source transparent/pattern opaque. */ +static unsigned xrop3_27_1_0 (unsigned char s, unsigned char t) +{ + unsigned D = 0x00ff; + unsigned S = ((unsigned)s << 8) | s; + unsigned T = ((unsigned)t << 8) | t; + unsigned stk1; + unsigned stk2; + unsigned stk3; + stk3 = T ^ S; + stk2 = D & stk3; + stk1 = S ^ stk2; + stk1 = ~stk1; + return (stk1 & (~S)) | (D & S); +} + +/* SDTSxaxn source/pattern transparent. */ +static unsigned xrop3_27_1_1 (unsigned char s, unsigned char t) +{ + unsigned D = 0x00ff; + unsigned S = ((unsigned)s << 8) | s; + unsigned T = ((unsigned)t << 8) | t; + unsigned stk1; + unsigned stk2; + unsigned stk3; + stk3 = T ^ S; + stk2 = D & stk3; + stk1 = S ^ stk2; + stk1 = ~stk1; + return (stk1 & (~S) & (~T)) | (D & S) | (D & T); +} + +/* TSDTaox source/pattern opaque. */ +static void rop3_28_0_0 (unsigned char *D, unsigned char S, unsigned char T) +{ + unsigned char stk1; + unsigned char stk2; + unsigned char stk3; + stk3 = *D & T; + stk2 = S | stk3; + stk1 = T ^ stk2; + *D = stk1; +} + +/* TSDTaox source opaque/pattern transparent. */ +static void rop3_28_0_1 (unsigned char *D, unsigned char S, unsigned char T) +{ + unsigned char stk1; + unsigned char stk2; + unsigned char stk3; + stk3 = *D & T; + stk2 = S | stk3; + stk1 = T ^ stk2; + *D = (stk1 & S) | (stk1 & (~T)) | (T & (~S) & *D); +} + +/* TSDTaox source transparent/pattern opaque. */ +static void rop3_28_1_0 (unsigned char *D, unsigned char S, unsigned char T) +{ + unsigned char stk1; + unsigned char stk2; + unsigned char stk3; + stk3 = *D & T; + stk2 = S | stk3; + stk1 = T ^ stk2; + *D = (stk1 & (~S)) | (*D & S); +} + +/* TSDTaox source/pattern transparent. */ +static void rop3_28_1_1 (unsigned char *D, unsigned char S, unsigned char T) +{ + unsigned char stk1; + unsigned char stk2; + unsigned char stk3; + stk3 = *D & T; + stk2 = S | stk3; + stk1 = T ^ stk2; + *D = (stk1 & (~S) & (~T)) | (*D & S) | (*D & T); +} + +/* TSDTaox source/pattern opaque. */ +static unsigned xrop3_28_0_0 (unsigned char s, unsigned char t) +{ + unsigned D = 0x00ff; + unsigned S = ((unsigned)s << 8) | s; + unsigned T = ((unsigned)t << 8) | t; + unsigned stk1; + unsigned stk2; + unsigned stk3; + stk3 = D & T; + stk2 = S | stk3; + stk1 = T ^ stk2; + return stk1; +} + +/* TSDTaox source opaque/pattern transparent. */ +static unsigned xrop3_28_0_1 (unsigned char s, unsigned char t) +{ + unsigned D = 0x00ff; + unsigned S = ((unsigned)s << 8) | s; + unsigned T = ((unsigned)t << 8) | t; + unsigned stk1; + unsigned stk2; + unsigned stk3; + stk3 = D & T; + stk2 = S | stk3; + stk1 = T ^ stk2; + return (stk1 & S) | (stk1 & (~T)) | (T & (~S) & D); +} + +/* TSDTaox source transparent/pattern opaque. */ +static unsigned xrop3_28_1_0 (unsigned char s, unsigned char t) +{ + unsigned D = 0x00ff; + unsigned S = ((unsigned)s << 8) | s; + unsigned T = ((unsigned)t << 8) | t; + unsigned stk1; + unsigned stk2; + unsigned stk3; + stk3 = D & T; + stk2 = S | stk3; + stk1 = T ^ stk2; + return (stk1 & (~S)) | (D & S); +} + +/* TSDTaox source/pattern transparent. */ +static unsigned xrop3_28_1_1 (unsigned char s, unsigned char t) +{ + unsigned D = 0x00ff; + unsigned S = ((unsigned)s << 8) | s; + unsigned T = ((unsigned)t << 8) | t; + unsigned stk1; + unsigned stk2; + unsigned stk3; + stk3 = D & T; + stk2 = S | stk3; + stk1 = T ^ stk2; + return (stk1 & (~S) & (~T)) | (D & S) | (D & T); +} + +/* DSTDxaxn source/pattern opaque. */ +static void rop3_29_0_0 (unsigned char *D, unsigned char S, unsigned char T) +{ + unsigned char stk1; + unsigned char stk2; + unsigned char stk3; + stk3 = T ^ *D; + stk2 = S & stk3; + stk1 = *D ^ stk2; + stk1 = ~stk1; + *D = stk1; +} + +/* DSTDxaxn source opaque/pattern transparent. */ +static void rop3_29_0_1 (unsigned char *D, unsigned char S, unsigned char T) +{ + unsigned char stk1; + unsigned char stk2; + unsigned char stk3; + stk3 = T ^ *D; + stk2 = S & stk3; + stk1 = *D ^ stk2; + stk1 = ~stk1; + *D = (stk1 & S) | (stk1 & (~T)) | (T & (~S) & *D); +} + +/* DSTDxaxn source transparent/pattern opaque. */ +static void rop3_29_1_0 (unsigned char *D, unsigned char S, unsigned char T) +{ + unsigned char stk1; + unsigned char stk2; + unsigned char stk3; + stk3 = T ^ *D; + stk2 = S & stk3; + stk1 = *D ^ stk2; + stk1 = ~stk1; + *D = (stk1 & (~S)) | (*D & S); +} + +/* DSTDxaxn source/pattern transparent. */ +static void rop3_29_1_1 (unsigned char *D, unsigned char S, unsigned char T) +{ + unsigned char stk1; + unsigned char stk2; + unsigned char stk3; + stk3 = T ^ *D; + stk2 = S & stk3; + stk1 = *D ^ stk2; + stk1 = ~stk1; + *D = (stk1 & (~S) & (~T)) | (*D & S) | (*D & T); +} + +/* DSTDxaxn source/pattern opaque. */ +static unsigned xrop3_29_0_0 (unsigned char s, unsigned char t) +{ + unsigned D = 0x00ff; + unsigned S = ((unsigned)s << 8) | s; + unsigned T = ((unsigned)t << 8) | t; + unsigned stk1; + unsigned stk2; + unsigned stk3; + stk3 = T ^ D; + stk2 = S & stk3; + stk1 = D ^ stk2; + stk1 = ~stk1; + return stk1; +} + +/* DSTDxaxn source opaque/pattern transparent. */ +static unsigned xrop3_29_0_1 (unsigned char s, unsigned char t) +{ + unsigned D = 0x00ff; + unsigned S = ((unsigned)s << 8) | s; + unsigned T = ((unsigned)t << 8) | t; + unsigned stk1; + unsigned stk2; + unsigned stk3; + stk3 = T ^ D; + stk2 = S & stk3; + stk1 = D ^ stk2; + stk1 = ~stk1; + return (stk1 & S) | (stk1 & (~T)) | (T & (~S) & D); +} + +/* DSTDxaxn source transparent/pattern opaque. */ +static unsigned xrop3_29_1_0 (unsigned char s, unsigned char t) +{ + unsigned D = 0x00ff; + unsigned S = ((unsigned)s << 8) | s; + unsigned T = ((unsigned)t << 8) | t; + unsigned stk1; + unsigned stk2; + unsigned stk3; + stk3 = T ^ D; + stk2 = S & stk3; + stk1 = D ^ stk2; + stk1 = ~stk1; + return (stk1 & (~S)) | (D & S); +} + +/* DSTDxaxn source/pattern transparent. */ +static unsigned xrop3_29_1_1 (unsigned char s, unsigned char t) +{ + unsigned D = 0x00ff; + unsigned S = ((unsigned)s << 8) | s; + unsigned T = ((unsigned)t << 8) | t; + unsigned stk1; + unsigned stk2; + unsigned stk3; + stk3 = T ^ D; + stk2 = S & stk3; + stk1 = D ^ stk2; + stk1 = ~stk1; + return (stk1 & (~S) & (~T)) | (D & S) | (D & T); +} + +/* TDSox source/pattern opaque. */ +static void rop3_30_0_0 (unsigned char *D, unsigned char S, unsigned char T) +{ + unsigned char stk1; + unsigned char stk2; + stk2 = *D | S; + stk1 = T ^ stk2; + *D = stk1; +} + +/* TDSox source opaque/pattern transparent. */ +static void rop3_30_0_1 (unsigned char *D, unsigned char S, unsigned char T) +{ + unsigned char stk1; + unsigned char stk2; + stk2 = *D | S; + stk1 = T ^ stk2; + *D = (stk1 & S) | (stk1 & (~T)) | (T & (~S) & *D); +} + +/* TDSox source transparent/pattern opaque. */ +static void rop3_30_1_0 (unsigned char *D, unsigned char S, unsigned char T) +{ + unsigned char stk1; + unsigned char stk2; + stk2 = *D | S; + stk1 = T ^ stk2; + *D = (stk1 & (~S)) | (*D & S); +} + +/* TDSox source/pattern transparent. */ +static void rop3_30_1_1 (unsigned char *D, unsigned char S, unsigned char T) +{ + unsigned char stk1; + unsigned char stk2; + stk2 = *D | S; + stk1 = T ^ stk2; + *D = (stk1 & (~S) & (~T)) | (*D & S) | (*D & T); +} + +/* TDSox source/pattern opaque. */ +static unsigned xrop3_30_0_0 (unsigned char s, unsigned char t) +{ + unsigned D = 0x00ff; + unsigned S = ((unsigned)s << 8) | s; + unsigned T = ((unsigned)t << 8) | t; + unsigned stk1; + unsigned stk2; + stk2 = D | S; + stk1 = T ^ stk2; + return stk1; +} + +/* TDSox source opaque/pattern transparent. */ +static unsigned xrop3_30_0_1 (unsigned char s, unsigned char t) +{ + unsigned D = 0x00ff; + unsigned S = ((unsigned)s << 8) | s; + unsigned T = ((unsigned)t << 8) | t; + unsigned stk1; + unsigned stk2; + stk2 = D | S; + stk1 = T ^ stk2; + return (stk1 & S) | (stk1 & (~T)) | (T & (~S) & D); +} + +/* TDSox source transparent/pattern opaque. */ +static unsigned xrop3_30_1_0 (unsigned char s, unsigned char t) +{ + unsigned D = 0x00ff; + unsigned S = ((unsigned)s << 8) | s; + unsigned T = ((unsigned)t << 8) | t; + unsigned stk1; + unsigned stk2; + stk2 = D | S; + stk1 = T ^ stk2; + return (stk1 & (~S)) | (D & S); +} + +/* TDSox source/pattern transparent. */ +static unsigned xrop3_30_1_1 (unsigned char s, unsigned char t) +{ + unsigned D = 0x00ff; + unsigned S = ((unsigned)s << 8) | s; + unsigned T = ((unsigned)t << 8) | t; + unsigned stk1; + unsigned stk2; + stk2 = D | S; + stk1 = T ^ stk2; + return (stk1 & (~S) & (~T)) | (D & S) | (D & T); +} + +/* TDSoan source/pattern opaque. */ +static void rop3_31_0_0 (unsigned char *D, unsigned char S, unsigned char T) +{ + unsigned char stk1; + unsigned char stk2; + stk2 = *D | S; + stk1 = T & stk2; + stk1 = ~stk1; + *D = stk1; +} + +/* TDSoan source opaque/pattern transparent. */ +static void rop3_31_0_1 (unsigned char *D, unsigned char S, unsigned char T) +{ + unsigned char stk1; + unsigned char stk2; + stk2 = *D | S; + stk1 = T & stk2; + stk1 = ~stk1; + *D = (stk1 & S) | (stk1 & (~T)) | (T & (~S) & *D); +} + +/* TDSoan source transparent/pattern opaque. */ +static void rop3_31_1_0 (unsigned char *D, unsigned char S, unsigned char T) +{ + unsigned char stk1; + unsigned char stk2; + stk2 = *D | S; + stk1 = T & stk2; + stk1 = ~stk1; + *D = (stk1 & (~S)) | (*D & S); +} + +/* TDSoan source/pattern transparent. */ +static void rop3_31_1_1 (unsigned char *D, unsigned char S, unsigned char T) +{ + unsigned char stk1; + unsigned char stk2; + stk2 = *D | S; + stk1 = T & stk2; + stk1 = ~stk1; + *D = (stk1 & (~S) & (~T)) | (*D & S) | (*D & T); +} + +/* TDSoan source/pattern opaque. */ +static unsigned xrop3_31_0_0 (unsigned char s, unsigned char t) +{ + unsigned D = 0x00ff; + unsigned S = ((unsigned)s << 8) | s; + unsigned T = ((unsigned)t << 8) | t; + unsigned stk1; + unsigned stk2; + stk2 = D | S; + stk1 = T & stk2; + stk1 = ~stk1; + return stk1; +} + +/* TDSoan source opaque/pattern transparent. */ +static unsigned xrop3_31_0_1 (unsigned char s, unsigned char t) +{ + unsigned D = 0x00ff; + unsigned S = ((unsigned)s << 8) | s; + unsigned T = ((unsigned)t << 8) | t; + unsigned stk1; + unsigned stk2; + stk2 = D | S; + stk1 = T & stk2; + stk1 = ~stk1; + return (stk1 & S) | (stk1 & (~T)) | (T & (~S) & D); +} + +/* TDSoan source transparent/pattern opaque. */ +static unsigned xrop3_31_1_0 (unsigned char s, unsigned char t) +{ + unsigned D = 0x00ff; + unsigned S = ((unsigned)s << 8) | s; + unsigned T = ((unsigned)t << 8) | t; + unsigned stk1; + unsigned stk2; + stk2 = D | S; + stk1 = T & stk2; + stk1 = ~stk1; + return (stk1 & (~S)) | (D & S); +} + +/* TDSoan source/pattern transparent. */ +static unsigned xrop3_31_1_1 (unsigned char s, unsigned char t) +{ + unsigned D = 0x00ff; + unsigned S = ((unsigned)s << 8) | s; + unsigned T = ((unsigned)t << 8) | t; + unsigned stk1; + unsigned stk2; + stk2 = D | S; + stk1 = T & stk2; + stk1 = ~stk1; + return (stk1 & (~S) & (~T)) | (D & S) | (D & T); +} + +/* DTSnaa source/pattern opaque. */ +static void rop3_32_0_0 (unsigned char *D, unsigned char S, unsigned char T) +{ + unsigned char stk1; + unsigned char stk2; + unsigned char stk3; + stk3 = ~S; + stk2 = T & stk3; + stk1 = *D & stk2; + *D = stk1; +} + +/* DTSnaa source opaque/pattern transparent. */ +static void rop3_32_0_1 (unsigned char *D, unsigned char S, unsigned char T) +{ + unsigned char stk1; + unsigned char stk2; + unsigned char stk3; + stk3 = ~S; + stk2 = T & stk3; + stk1 = *D & stk2; + *D = (stk1 & S) | (stk1 & (~T)) | (T & (~S) & *D); +} + +/* DTSnaa source transparent/pattern opaque. */ +static void rop3_32_1_0 (unsigned char *D, unsigned char S, unsigned char T) +{ + unsigned char stk1; + unsigned char stk2; + unsigned char stk3; + stk3 = ~S; + stk2 = T & stk3; + stk1 = *D & stk2; + *D = (stk1 & (~S)) | (*D & S); +} + +/* DTSnaa source/pattern transparent. */ +static void rop3_32_1_1 (unsigned char *D, unsigned char S, unsigned char T) +{ + unsigned char stk1; + unsigned char stk2; + unsigned char stk3; + stk3 = ~S; + stk2 = T & stk3; + stk1 = *D & stk2; + *D = (stk1 & (~S) & (~T)) | (*D & S) | (*D & T); +} + +/* DTSnaa source/pattern opaque. */ +static unsigned xrop3_32_0_0 (unsigned char s, unsigned char t) +{ + unsigned D = 0x00ff; + unsigned S = ((unsigned)s << 8) | s; + unsigned T = ((unsigned)t << 8) | t; + unsigned stk1; + unsigned stk2; + unsigned stk3; + stk3 = ~S; + stk2 = T & stk3; + stk1 = D & stk2; + return stk1; +} + +/* DTSnaa source opaque/pattern transparent. */ +static unsigned xrop3_32_0_1 (unsigned char s, unsigned char t) +{ + unsigned D = 0x00ff; + unsigned S = ((unsigned)s << 8) | s; + unsigned T = ((unsigned)t << 8) | t; + unsigned stk1; + unsigned stk2; + unsigned stk3; + stk3 = ~S; + stk2 = T & stk3; + stk1 = D & stk2; + return (stk1 & S) | (stk1 & (~T)) | (T & (~S) & D); +} + +/* DTSnaa source transparent/pattern opaque. */ +static unsigned xrop3_32_1_0 (unsigned char s, unsigned char t) +{ + unsigned D = 0x00ff; + unsigned S = ((unsigned)s << 8) | s; + unsigned T = ((unsigned)t << 8) | t; + unsigned stk1; + unsigned stk2; + unsigned stk3; + stk3 = ~S; + stk2 = T & stk3; + stk1 = D & stk2; + return (stk1 & (~S)) | (D & S); +} + +/* DTSnaa source/pattern transparent. */ +static unsigned xrop3_32_1_1 (unsigned char s, unsigned char t) +{ + unsigned D = 0x00ff; + unsigned S = ((unsigned)s << 8) | s; + unsigned T = ((unsigned)t << 8) | t; + unsigned stk1; + unsigned stk2; + unsigned stk3; + stk3 = ~S; + stk2 = T & stk3; + stk1 = D & stk2; + return (stk1 & (~S) & (~T)) | (D & S) | (D & T); +} + +/* SDTxon source/pattern opaque. */ +static void rop3_33_0_0 (unsigned char *D, unsigned char S, unsigned char T) +{ + unsigned char stk1; + unsigned char stk2; + stk2 = *D ^ T; + stk1 = S | stk2; + stk1 = ~stk1; + *D = stk1; +} + +/* SDTxon source opaque/pattern transparent. */ +static void rop3_33_0_1 (unsigned char *D, unsigned char S, unsigned char T) +{ + unsigned char stk1; + unsigned char stk2; + stk2 = *D ^ T; + stk1 = S | stk2; + stk1 = ~stk1; + *D = (stk1 & S) | (stk1 & (~T)) | (T & (~S) & *D); +} + +/* SDTxon source transparent/pattern opaque. */ +static void rop3_33_1_0 (unsigned char *D, unsigned char S, unsigned char T) +{ + unsigned char stk1; + unsigned char stk2; + stk2 = *D ^ T; + stk1 = S | stk2; + stk1 = ~stk1; + *D = (stk1 & (~S)) | (*D & S); +} + +/* SDTxon source/pattern transparent. */ +static void rop3_33_1_1 (unsigned char *D, unsigned char S, unsigned char T) +{ + unsigned char stk1; + unsigned char stk2; + stk2 = *D ^ T; + stk1 = S | stk2; + stk1 = ~stk1; + *D = (stk1 & (~S) & (~T)) | (*D & S) | (*D & T); +} + +/* SDTxon source/pattern opaque. */ +static unsigned xrop3_33_0_0 (unsigned char s, unsigned char t) +{ + unsigned D = 0x00ff; + unsigned S = ((unsigned)s << 8) | s; + unsigned T = ((unsigned)t << 8) | t; + unsigned stk1; + unsigned stk2; + stk2 = D ^ T; + stk1 = S | stk2; + stk1 = ~stk1; + return stk1; +} + +/* SDTxon source opaque/pattern transparent. */ +static unsigned xrop3_33_0_1 (unsigned char s, unsigned char t) +{ + unsigned D = 0x00ff; + unsigned S = ((unsigned)s << 8) | s; + unsigned T = ((unsigned)t << 8) | t; + unsigned stk1; + unsigned stk2; + stk2 = D ^ T; + stk1 = S | stk2; + stk1 = ~stk1; + return (stk1 & S) | (stk1 & (~T)) | (T & (~S) & D); +} + +/* SDTxon source transparent/pattern opaque. */ +static unsigned xrop3_33_1_0 (unsigned char s, unsigned char t) +{ + unsigned D = 0x00ff; + unsigned S = ((unsigned)s << 8) | s; + unsigned T = ((unsigned)t << 8) | t; + unsigned stk1; + unsigned stk2; + stk2 = D ^ T; + stk1 = S | stk2; + stk1 = ~stk1; + return (stk1 & (~S)) | (D & S); +} + +/* SDTxon source/pattern transparent. */ +static unsigned xrop3_33_1_1 (unsigned char s, unsigned char t) +{ + unsigned D = 0x00ff; + unsigned S = ((unsigned)s << 8) | s; + unsigned T = ((unsigned)t << 8) | t; + unsigned stk1; + unsigned stk2; + stk2 = D ^ T; + stk1 = S | stk2; + stk1 = ~stk1; + return (stk1 & (~S) & (~T)) | (D & S) | (D & T); +} + +/* DSna source/pattern opaque. */ +static void rop3_34_0_0 (unsigned char *D, unsigned char S, unsigned char T) +{ + unsigned char stk1; + unsigned char stk2; + stk2 = ~S; + stk1 = *D & stk2; + *D = stk1; +} + +/* DSna source opaque/pattern transparent. */ +static void rop3_34_0_1 (unsigned char *D, unsigned char S, unsigned char T) +{ + unsigned char stk1; + unsigned char stk2; + stk2 = ~S; + stk1 = *D & stk2; + *D = (stk1 & S) | (stk1 & (~T)) | (T & (~S) & *D); +} + +/* DSna source transparent/pattern opaque. */ +static void rop3_34_1_0 (unsigned char *D, unsigned char S, unsigned char T) +{ + unsigned char stk1; + unsigned char stk2; + stk2 = ~S; + stk1 = *D & stk2; + *D = (stk1 & (~S)) | (*D & S); +} + +/* DSna source/pattern transparent. */ +static void rop3_34_1_1 (unsigned char *D, unsigned char S, unsigned char T) +{ + unsigned char stk1; + unsigned char stk2; + stk2 = ~S; + stk1 = *D & stk2; + *D = (stk1 & (~S) & (~T)) | (*D & S) | (*D & T); +} + +/* DSna source/pattern opaque. */ +static unsigned xrop3_34_0_0 (unsigned char s, unsigned char t) +{ + unsigned D = 0x00ff; + unsigned S = ((unsigned)s << 8) | s; + unsigned stk1; + unsigned stk2; + stk2 = ~S; + stk1 = D & stk2; + return stk1; +} + +/* DSna source opaque/pattern transparent. */ +static unsigned xrop3_34_0_1 (unsigned char s, unsigned char t) +{ + unsigned D = 0x00ff; + unsigned S = ((unsigned)s << 8) | s; + unsigned T = ((unsigned)t << 8) | t; + unsigned stk1; + unsigned stk2; + stk2 = ~S; + stk1 = D & stk2; + return (stk1 & S) | (stk1 & (~T)) | (T & (~S) & D); +} + +/* DSna source transparent/pattern opaque. */ +static unsigned xrop3_34_1_0 (unsigned char s, unsigned char t) +{ + unsigned D = 0x00ff; + unsigned S = ((unsigned)s << 8) | s; + unsigned stk1; + unsigned stk2; + stk2 = ~S; + stk1 = D & stk2; + return (stk1 & (~S)) | (D & S); +} + +/* DSna source/pattern transparent. */ +static unsigned xrop3_34_1_1 (unsigned char s, unsigned char t) +{ + unsigned D = 0x00ff; + unsigned S = ((unsigned)s << 8) | s; + unsigned T = ((unsigned)t << 8) | t; + unsigned stk1; + unsigned stk2; + stk2 = ~S; + stk1 = D & stk2; + return (stk1 & (~S) & (~T)) | (D & S) | (D & T); +} + +/* STDnaon source/pattern opaque. */ +static void rop3_35_0_0 (unsigned char *D, unsigned char S, unsigned char T) +{ + unsigned char stk1; + unsigned char stk2; + unsigned char stk3; + stk3 = ~*D; + stk2 = T & stk3; + stk1 = S | stk2; + stk1 = ~stk1; + *D = stk1; +} + +/* STDnaon source opaque/pattern transparent. */ +static void rop3_35_0_1 (unsigned char *D, unsigned char S, unsigned char T) +{ + unsigned char stk1; + unsigned char stk2; + unsigned char stk3; + stk3 = ~*D; + stk2 = T & stk3; + stk1 = S | stk2; + stk1 = ~stk1; + *D = (stk1 & S) | (stk1 & (~T)) | (T & (~S) & *D); +} + +/* STDnaon source transparent/pattern opaque. */ +static void rop3_35_1_0 (unsigned char *D, unsigned char S, unsigned char T) +{ + unsigned char stk1; + unsigned char stk2; + unsigned char stk3; + stk3 = ~*D; + stk2 = T & stk3; + stk1 = S | stk2; + stk1 = ~stk1; + *D = (stk1 & (~S)) | (*D & S); +} + +/* STDnaon source/pattern transparent. */ +static void rop3_35_1_1 (unsigned char *D, unsigned char S, unsigned char T) +{ + unsigned char stk1; + unsigned char stk2; + unsigned char stk3; + stk3 = ~*D; + stk2 = T & stk3; + stk1 = S | stk2; + stk1 = ~stk1; + *D = (stk1 & (~S) & (~T)) | (*D & S) | (*D & T); +} + +/* STDnaon source/pattern opaque. */ +static unsigned xrop3_35_0_0 (unsigned char s, unsigned char t) +{ + unsigned D = 0x00ff; + unsigned S = ((unsigned)s << 8) | s; + unsigned T = ((unsigned)t << 8) | t; + unsigned stk1; + unsigned stk2; + unsigned stk3; + stk3 = ~D; + stk2 = T & stk3; + stk1 = S | stk2; + stk1 = ~stk1; + return stk1; +} + +/* STDnaon source opaque/pattern transparent. */ +static unsigned xrop3_35_0_1 (unsigned char s, unsigned char t) +{ + unsigned D = 0x00ff; + unsigned S = ((unsigned)s << 8) | s; + unsigned T = ((unsigned)t << 8) | t; + unsigned stk1; + unsigned stk2; + unsigned stk3; + stk3 = ~D; + stk2 = T & stk3; + stk1 = S | stk2; + stk1 = ~stk1; + return (stk1 & S) | (stk1 & (~T)) | (T & (~S) & D); +} + +/* STDnaon source transparent/pattern opaque. */ +static unsigned xrop3_35_1_0 (unsigned char s, unsigned char t) +{ + unsigned D = 0x00ff; + unsigned S = ((unsigned)s << 8) | s; + unsigned T = ((unsigned)t << 8) | t; + unsigned stk1; + unsigned stk2; + unsigned stk3; + stk3 = ~D; + stk2 = T & stk3; + stk1 = S | stk2; + stk1 = ~stk1; + return (stk1 & (~S)) | (D & S); +} + +/* STDnaon source/pattern transparent. */ +static unsigned xrop3_35_1_1 (unsigned char s, unsigned char t) +{ + unsigned D = 0x00ff; + unsigned S = ((unsigned)s << 8) | s; + unsigned T = ((unsigned)t << 8) | t; + unsigned stk1; + unsigned stk2; + unsigned stk3; + stk3 = ~D; + stk2 = T & stk3; + stk1 = S | stk2; + stk1 = ~stk1; + return (stk1 & (~S) & (~T)) | (D & S) | (D & T); +} + +/* STxDSxa source/pattern opaque. */ +static void rop3_36_0_0 (unsigned char *D, unsigned char S, unsigned char T) +{ + unsigned char stk1; + unsigned char stk2; + stk1 = S ^ T; + stk2 = *D ^ S; + stk1 = stk1 & stk2; + *D = stk1; +} + +/* STxDSxa source opaque/pattern transparent. */ +static void rop3_36_0_1 (unsigned char *D, unsigned char S, unsigned char T) +{ + unsigned char stk1; + unsigned char stk2; + stk1 = S ^ T; + stk2 = *D ^ S; + stk1 = stk1 & stk2; + *D = (stk1 & S) | (stk1 & (~T)) | (T & (~S) & *D); +} + +/* STxDSxa source transparent/pattern opaque. */ +static void rop3_36_1_0 (unsigned char *D, unsigned char S, unsigned char T) +{ + unsigned char stk1; + unsigned char stk2; + stk1 = S ^ T; + stk2 = *D ^ S; + stk1 = stk1 & stk2; + *D = (stk1 & (~S)) | (*D & S); +} + +/* STxDSxa source/pattern transparent. */ +static void rop3_36_1_1 (unsigned char *D, unsigned char S, unsigned char T) +{ + unsigned char stk1; + unsigned char stk2; + stk1 = S ^ T; + stk2 = *D ^ S; + stk1 = stk1 & stk2; + *D = (stk1 & (~S) & (~T)) | (*D & S) | (*D & T); +} + +/* STxDSxa source/pattern opaque. */ +static unsigned xrop3_36_0_0 (unsigned char s, unsigned char t) +{ + unsigned D = 0x00ff; + unsigned S = ((unsigned)s << 8) | s; + unsigned T = ((unsigned)t << 8) | t; + unsigned stk1; + unsigned stk2; + stk1 = S ^ T; + stk2 = D ^ S; + stk1 = stk1 & stk2; + return stk1; +} + +/* STxDSxa source opaque/pattern transparent. */ +static unsigned xrop3_36_0_1 (unsigned char s, unsigned char t) +{ + unsigned D = 0x00ff; + unsigned S = ((unsigned)s << 8) | s; + unsigned T = ((unsigned)t << 8) | t; + unsigned stk1; + unsigned stk2; + stk1 = S ^ T; + stk2 = D ^ S; + stk1 = stk1 & stk2; + return (stk1 & S) | (stk1 & (~T)) | (T & (~S) & D); +} + +/* STxDSxa source transparent/pattern opaque. */ +static unsigned xrop3_36_1_0 (unsigned char s, unsigned char t) +{ + unsigned D = 0x00ff; + unsigned S = ((unsigned)s << 8) | s; + unsigned T = ((unsigned)t << 8) | t; + unsigned stk1; + unsigned stk2; + stk1 = S ^ T; + stk2 = D ^ S; + stk1 = stk1 & stk2; + return (stk1 & (~S)) | (D & S); +} + +/* STxDSxa source/pattern transparent. */ +static unsigned xrop3_36_1_1 (unsigned char s, unsigned char t) +{ + unsigned D = 0x00ff; + unsigned S = ((unsigned)s << 8) | s; + unsigned T = ((unsigned)t << 8) | t; + unsigned stk1; + unsigned stk2; + stk1 = S ^ T; + stk2 = D ^ S; + stk1 = stk1 & stk2; + return (stk1 & (~S) & (~T)) | (D & S) | (D & T); +} + +/* TDSTanaxn source/pattern opaque. */ +static void rop3_37_0_0 (unsigned char *D, unsigned char S, unsigned char T) +{ + unsigned char stk1; + unsigned char stk2; + unsigned char stk3; + stk3 = S & T; + stk3 = ~stk3; + stk2 = *D & stk3; + stk1 = T ^ stk2; + stk1 = ~stk1; + *D = stk1; +} + +/* TDSTanaxn source opaque/pattern transparent. */ +static void rop3_37_0_1 (unsigned char *D, unsigned char S, unsigned char T) +{ + unsigned char stk1; + unsigned char stk2; + unsigned char stk3; + stk3 = S & T; + stk3 = ~stk3; + stk2 = *D & stk3; + stk1 = T ^ stk2; + stk1 = ~stk1; + *D = (stk1 & S) | (stk1 & (~T)) | (T & (~S) & *D); +} + +/* TDSTanaxn source transparent/pattern opaque. */ +static void rop3_37_1_0 (unsigned char *D, unsigned char S, unsigned char T) +{ + unsigned char stk1; + unsigned char stk2; + unsigned char stk3; + stk3 = S & T; + stk3 = ~stk3; + stk2 = *D & stk3; + stk1 = T ^ stk2; + stk1 = ~stk1; + *D = (stk1 & (~S)) | (*D & S); +} + +/* TDSTanaxn source/pattern transparent. */ +static void rop3_37_1_1 (unsigned char *D, unsigned char S, unsigned char T) +{ + unsigned char stk1; + unsigned char stk2; + unsigned char stk3; + stk3 = S & T; + stk3 = ~stk3; + stk2 = *D & stk3; + stk1 = T ^ stk2; + stk1 = ~stk1; + *D = (stk1 & (~S) & (~T)) | (*D & S) | (*D & T); +} + +/* TDSTanaxn source/pattern opaque. */ +static unsigned xrop3_37_0_0 (unsigned char s, unsigned char t) +{ + unsigned D = 0x00ff; + unsigned S = ((unsigned)s << 8) | s; + unsigned T = ((unsigned)t << 8) | t; + unsigned stk1; + unsigned stk2; + unsigned stk3; + stk3 = S & T; + stk3 = ~stk3; + stk2 = D & stk3; + stk1 = T ^ stk2; + stk1 = ~stk1; + return stk1; +} + +/* TDSTanaxn source opaque/pattern transparent. */ +static unsigned xrop3_37_0_1 (unsigned char s, unsigned char t) +{ + unsigned D = 0x00ff; + unsigned S = ((unsigned)s << 8) | s; + unsigned T = ((unsigned)t << 8) | t; + unsigned stk1; + unsigned stk2; + unsigned stk3; + stk3 = S & T; + stk3 = ~stk3; + stk2 = D & stk3; + stk1 = T ^ stk2; + stk1 = ~stk1; + return (stk1 & S) | (stk1 & (~T)) | (T & (~S) & D); +} + +/* TDSTanaxn source transparent/pattern opaque. */ +static unsigned xrop3_37_1_0 (unsigned char s, unsigned char t) +{ + unsigned D = 0x00ff; + unsigned S = ((unsigned)s << 8) | s; + unsigned T = ((unsigned)t << 8) | t; + unsigned stk1; + unsigned stk2; + unsigned stk3; + stk3 = S & T; + stk3 = ~stk3; + stk2 = D & stk3; + stk1 = T ^ stk2; + stk1 = ~stk1; + return (stk1 & (~S)) | (D & S); +} + +/* TDSTanaxn source/pattern transparent. */ +static unsigned xrop3_37_1_1 (unsigned char s, unsigned char t) +{ + unsigned D = 0x00ff; + unsigned S = ((unsigned)s << 8) | s; + unsigned T = ((unsigned)t << 8) | t; + unsigned stk1; + unsigned stk2; + unsigned stk3; + stk3 = S & T; + stk3 = ~stk3; + stk2 = D & stk3; + stk1 = T ^ stk2; + stk1 = ~stk1; + return (stk1 & (~S) & (~T)) | (D & S) | (D & T); +} + +/* SDTSaox source/pattern opaque. */ +static void rop3_38_0_0 (unsigned char *D, unsigned char S, unsigned char T) +{ + unsigned char stk1; + unsigned char stk2; + unsigned char stk3; + stk3 = T & S; + stk2 = *D | stk3; + stk1 = S ^ stk2; + *D = stk1; +} + +/* SDTSaox source opaque/pattern transparent. */ +static void rop3_38_0_1 (unsigned char *D, unsigned char S, unsigned char T) +{ + unsigned char stk1; + unsigned char stk2; + unsigned char stk3; + stk3 = T & S; + stk2 = *D | stk3; + stk1 = S ^ stk2; + *D = (stk1 & S) | (stk1 & (~T)) | (T & (~S) & *D); +} + +/* SDTSaox source transparent/pattern opaque. */ +static void rop3_38_1_0 (unsigned char *D, unsigned char S, unsigned char T) +{ + unsigned char stk1; + unsigned char stk2; + unsigned char stk3; + stk3 = T & S; + stk2 = *D | stk3; + stk1 = S ^ stk2; + *D = (stk1 & (~S)) | (*D & S); +} + +/* SDTSaox source/pattern transparent. */ +static void rop3_38_1_1 (unsigned char *D, unsigned char S, unsigned char T) +{ + unsigned char stk1; + unsigned char stk2; + unsigned char stk3; + stk3 = T & S; + stk2 = *D | stk3; + stk1 = S ^ stk2; + *D = (stk1 & (~S) & (~T)) | (*D & S) | (*D & T); +} + +/* SDTSaox source/pattern opaque. */ +static unsigned xrop3_38_0_0 (unsigned char s, unsigned char t) +{ + unsigned D = 0x00ff; + unsigned S = ((unsigned)s << 8) | s; + unsigned T = ((unsigned)t << 8) | t; + unsigned stk1; + unsigned stk2; + unsigned stk3; + stk3 = T & S; + stk2 = D | stk3; + stk1 = S ^ stk2; + return stk1; +} + +/* SDTSaox source opaque/pattern transparent. */ +static unsigned xrop3_38_0_1 (unsigned char s, unsigned char t) +{ + unsigned D = 0x00ff; + unsigned S = ((unsigned)s << 8) | s; + unsigned T = ((unsigned)t << 8) | t; + unsigned stk1; + unsigned stk2; + unsigned stk3; + stk3 = T & S; + stk2 = D | stk3; + stk1 = S ^ stk2; + return (stk1 & S) | (stk1 & (~T)) | (T & (~S) & D); +} + +/* SDTSaox source transparent/pattern opaque. */ +static unsigned xrop3_38_1_0 (unsigned char s, unsigned char t) +{ + unsigned D = 0x00ff; + unsigned S = ((unsigned)s << 8) | s; + unsigned T = ((unsigned)t << 8) | t; + unsigned stk1; + unsigned stk2; + unsigned stk3; + stk3 = T & S; + stk2 = D | stk3; + stk1 = S ^ stk2; + return (stk1 & (~S)) | (D & S); +} + +/* SDTSaox source/pattern transparent. */ +static unsigned xrop3_38_1_1 (unsigned char s, unsigned char t) +{ + unsigned D = 0x00ff; + unsigned S = ((unsigned)s << 8) | s; + unsigned T = ((unsigned)t << 8) | t; + unsigned stk1; + unsigned stk2; + unsigned stk3; + stk3 = T & S; + stk2 = D | stk3; + stk1 = S ^ stk2; + return (stk1 & (~S) & (~T)) | (D & S) | (D & T); +} + +/* SDTSxnox source/pattern opaque. */ +static void rop3_39_0_0 (unsigned char *D, unsigned char S, unsigned char T) +{ + unsigned char stk1; + unsigned char stk2; + unsigned char stk3; + stk3 = T ^ S; + stk3 = ~stk3; + stk2 = *D | stk3; + stk1 = S ^ stk2; + *D = stk1; +} + +/* SDTSxnox source opaque/pattern transparent. */ +static void rop3_39_0_1 (unsigned char *D, unsigned char S, unsigned char T) +{ + unsigned char stk1; + unsigned char stk2; + unsigned char stk3; + stk3 = T ^ S; + stk3 = ~stk3; + stk2 = *D | stk3; + stk1 = S ^ stk2; + *D = (stk1 & S) | (stk1 & (~T)) | (T & (~S) & *D); +} + +/* SDTSxnox source transparent/pattern opaque. */ +static void rop3_39_1_0 (unsigned char *D, unsigned char S, unsigned char T) +{ + unsigned char stk1; + unsigned char stk2; + unsigned char stk3; + stk3 = T ^ S; + stk3 = ~stk3; + stk2 = *D | stk3; + stk1 = S ^ stk2; + *D = (stk1 & (~S)) | (*D & S); +} + +/* SDTSxnox source/pattern transparent. */ +static void rop3_39_1_1 (unsigned char *D, unsigned char S, unsigned char T) +{ + unsigned char stk1; + unsigned char stk2; + unsigned char stk3; + stk3 = T ^ S; + stk3 = ~stk3; + stk2 = *D | stk3; + stk1 = S ^ stk2; + *D = (stk1 & (~S) & (~T)) | (*D & S) | (*D & T); +} + +/* SDTSxnox source/pattern opaque. */ +static unsigned xrop3_39_0_0 (unsigned char s, unsigned char t) +{ + unsigned D = 0x00ff; + unsigned S = ((unsigned)s << 8) | s; + unsigned T = ((unsigned)t << 8) | t; + unsigned stk1; + unsigned stk2; + unsigned stk3; + stk3 = T ^ S; + stk3 = ~stk3; + stk2 = D | stk3; + stk1 = S ^ stk2; + return stk1; +} + +/* SDTSxnox source opaque/pattern transparent. */ +static unsigned xrop3_39_0_1 (unsigned char s, unsigned char t) +{ + unsigned D = 0x00ff; + unsigned S = ((unsigned)s << 8) | s; + unsigned T = ((unsigned)t << 8) | t; + unsigned stk1; + unsigned stk2; + unsigned stk3; + stk3 = T ^ S; + stk3 = ~stk3; + stk2 = D | stk3; + stk1 = S ^ stk2; + return (stk1 & S) | (stk1 & (~T)) | (T & (~S) & D); +} + +/* SDTSxnox source transparent/pattern opaque. */ +static unsigned xrop3_39_1_0 (unsigned char s, unsigned char t) +{ + unsigned D = 0x00ff; + unsigned S = ((unsigned)s << 8) | s; + unsigned T = ((unsigned)t << 8) | t; + unsigned stk1; + unsigned stk2; + unsigned stk3; + stk3 = T ^ S; + stk3 = ~stk3; + stk2 = D | stk3; + stk1 = S ^ stk2; + return (stk1 & (~S)) | (D & S); +} + +/* SDTSxnox source/pattern transparent. */ +static unsigned xrop3_39_1_1 (unsigned char s, unsigned char t) +{ + unsigned D = 0x00ff; + unsigned S = ((unsigned)s << 8) | s; + unsigned T = ((unsigned)t << 8) | t; + unsigned stk1; + unsigned stk2; + unsigned stk3; + stk3 = T ^ S; + stk3 = ~stk3; + stk2 = D | stk3; + stk1 = S ^ stk2; + return (stk1 & (~S) & (~T)) | (D & S) | (D & T); +} + +/* DTSxa source/pattern opaque. */ +static void rop3_40_0_0 (unsigned char *D, unsigned char S, unsigned char T) +{ + unsigned char stk1; + unsigned char stk2; + stk2 = T ^ S; + stk1 = *D & stk2; + *D = stk1; +} + +/* DTSxa source opaque/pattern transparent. */ +static void rop3_40_0_1 (unsigned char *D, unsigned char S, unsigned char T) +{ + unsigned char stk1; + unsigned char stk2; + stk2 = T ^ S; + stk1 = *D & stk2; + *D = (stk1 & S) | (stk1 & (~T)) | (T & (~S) & *D); +} + +/* DTSxa source transparent/pattern opaque. */ +static void rop3_40_1_0 (unsigned char *D, unsigned char S, unsigned char T) +{ + unsigned char stk1; + unsigned char stk2; + stk2 = T ^ S; + stk1 = *D & stk2; + *D = (stk1 & (~S)) | (*D & S); +} + +/* DTSxa source/pattern transparent. */ +static void rop3_40_1_1 (unsigned char *D, unsigned char S, unsigned char T) +{ + unsigned char stk1; + unsigned char stk2; + stk2 = T ^ S; + stk1 = *D & stk2; + *D = (stk1 & (~S) & (~T)) | (*D & S) | (*D & T); +} + +/* DTSxa source/pattern opaque. */ +static unsigned xrop3_40_0_0 (unsigned char s, unsigned char t) +{ + unsigned D = 0x00ff; + unsigned S = ((unsigned)s << 8) | s; + unsigned T = ((unsigned)t << 8) | t; + unsigned stk1; + unsigned stk2; + stk2 = T ^ S; + stk1 = D & stk2; + return stk1; +} + +/* DTSxa source opaque/pattern transparent. */ +static unsigned xrop3_40_0_1 (unsigned char s, unsigned char t) +{ + unsigned D = 0x00ff; + unsigned S = ((unsigned)s << 8) | s; + unsigned T = ((unsigned)t << 8) | t; + unsigned stk1; + unsigned stk2; + stk2 = T ^ S; + stk1 = D & stk2; + return (stk1 & S) | (stk1 & (~T)) | (T & (~S) & D); +} + +/* DTSxa source transparent/pattern opaque. */ +static unsigned xrop3_40_1_0 (unsigned char s, unsigned char t) +{ + unsigned D = 0x00ff; + unsigned S = ((unsigned)s << 8) | s; + unsigned T = ((unsigned)t << 8) | t; + unsigned stk1; + unsigned stk2; + stk2 = T ^ S; + stk1 = D & stk2; + return (stk1 & (~S)) | (D & S); +} + +/* DTSxa source/pattern transparent. */ +static unsigned xrop3_40_1_1 (unsigned char s, unsigned char t) +{ + unsigned D = 0x00ff; + unsigned S = ((unsigned)s << 8) | s; + unsigned T = ((unsigned)t << 8) | t; + unsigned stk1; + unsigned stk2; + stk2 = T ^ S; + stk1 = D & stk2; + return (stk1 & (~S) & (~T)) | (D & S) | (D & T); +} + +/* TSDTSaoxxn source/pattern opaque. */ +static void rop3_41_0_0 (unsigned char *D, unsigned char S, unsigned char T) +{ + unsigned char stk1; + unsigned char stk2; + unsigned char stk3; + unsigned char stk4; + stk4 = T & S; + stk3 = *D | stk4; + stk2 = S ^ stk3; + stk1 = T ^ stk2; + stk1 = ~stk1; + *D = stk1; +} + +/* TSDTSaoxxn source opaque/pattern transparent. */ +static void rop3_41_0_1 (unsigned char *D, unsigned char S, unsigned char T) +{ + unsigned char stk1; + unsigned char stk2; + unsigned char stk3; + unsigned char stk4; + stk4 = T & S; + stk3 = *D | stk4; + stk2 = S ^ stk3; + stk1 = T ^ stk2; + stk1 = ~stk1; + *D = (stk1 & S) | (stk1 & (~T)) | (T & (~S) & *D); +} + +/* TSDTSaoxxn source transparent/pattern opaque. */ +static void rop3_41_1_0 (unsigned char *D, unsigned char S, unsigned char T) +{ + unsigned char stk1; + unsigned char stk2; + unsigned char stk3; + unsigned char stk4; + stk4 = T & S; + stk3 = *D | stk4; + stk2 = S ^ stk3; + stk1 = T ^ stk2; + stk1 = ~stk1; + *D = (stk1 & (~S)) | (*D & S); +} + +/* TSDTSaoxxn source/pattern transparent. */ +static void rop3_41_1_1 (unsigned char *D, unsigned char S, unsigned char T) +{ + unsigned char stk1; + unsigned char stk2; + unsigned char stk3; + unsigned char stk4; + stk4 = T & S; + stk3 = *D | stk4; + stk2 = S ^ stk3; + stk1 = T ^ stk2; + stk1 = ~stk1; + *D = (stk1 & (~S) & (~T)) | (*D & S) | (*D & T); +} + +/* TSDTSaoxxn source/pattern opaque. */ +static unsigned xrop3_41_0_0 (unsigned char s, unsigned char t) +{ + unsigned D = 0x00ff; + unsigned S = ((unsigned)s << 8) | s; + unsigned T = ((unsigned)t << 8) | t; + unsigned stk1; + unsigned stk2; + unsigned stk3; + unsigned stk4; + stk4 = T & S; + stk3 = D | stk4; + stk2 = S ^ stk3; + stk1 = T ^ stk2; + stk1 = ~stk1; + return stk1; +} + +/* TSDTSaoxxn source opaque/pattern transparent. */ +static unsigned xrop3_41_0_1 (unsigned char s, unsigned char t) +{ + unsigned D = 0x00ff; + unsigned S = ((unsigned)s << 8) | s; + unsigned T = ((unsigned)t << 8) | t; + unsigned stk1; + unsigned stk2; + unsigned stk3; + unsigned stk4; + stk4 = T & S; + stk3 = D | stk4; + stk2 = S ^ stk3; + stk1 = T ^ stk2; + stk1 = ~stk1; + return (stk1 & S) | (stk1 & (~T)) | (T & (~S) & D); +} + +/* TSDTSaoxxn source transparent/pattern opaque. */ +static unsigned xrop3_41_1_0 (unsigned char s, unsigned char t) +{ + unsigned D = 0x00ff; + unsigned S = ((unsigned)s << 8) | s; + unsigned T = ((unsigned)t << 8) | t; + unsigned stk1; + unsigned stk2; + unsigned stk3; + unsigned stk4; + stk4 = T & S; + stk3 = D | stk4; + stk2 = S ^ stk3; + stk1 = T ^ stk2; + stk1 = ~stk1; + return (stk1 & (~S)) | (D & S); +} + +/* TSDTSaoxxn source/pattern transparent. */ +static unsigned xrop3_41_1_1 (unsigned char s, unsigned char t) +{ + unsigned D = 0x00ff; + unsigned S = ((unsigned)s << 8) | s; + unsigned T = ((unsigned)t << 8) | t; + unsigned stk1; + unsigned stk2; + unsigned stk3; + unsigned stk4; + stk4 = T & S; + stk3 = D | stk4; + stk2 = S ^ stk3; + stk1 = T ^ stk2; + stk1 = ~stk1; + return (stk1 & (~S) & (~T)) | (D & S) | (D & T); +} + +/* DTSana source/pattern opaque. */ +static void rop3_42_0_0 (unsigned char *D, unsigned char S, unsigned char T) +{ + unsigned char stk1; + unsigned char stk2; + stk2 = T & S; + stk2 = ~stk2; + stk1 = *D & stk2; + *D = stk1; +} + +/* DTSana source opaque/pattern transparent. */ +static void rop3_42_0_1 (unsigned char *D, unsigned char S, unsigned char T) +{ + unsigned char stk1; + unsigned char stk2; + stk2 = T & S; + stk2 = ~stk2; + stk1 = *D & stk2; + *D = (stk1 & S) | (stk1 & (~T)) | (T & (~S) & *D); +} + +/* DTSana source transparent/pattern opaque. */ +static void rop3_42_1_0 (unsigned char *D, unsigned char S, unsigned char T) +{ + unsigned char stk1; + unsigned char stk2; + stk2 = T & S; + stk2 = ~stk2; + stk1 = *D & stk2; + *D = (stk1 & (~S)) | (*D & S); +} + +/* DTSana source/pattern transparent. */ +static void rop3_42_1_1 (unsigned char *D, unsigned char S, unsigned char T) +{ + unsigned char stk1; + unsigned char stk2; + stk2 = T & S; + stk2 = ~stk2; + stk1 = *D & stk2; + *D = (stk1 & (~S) & (~T)) | (*D & S) | (*D & T); +} + +/* DTSana source/pattern opaque. */ +static unsigned xrop3_42_0_0 (unsigned char s, unsigned char t) +{ + unsigned D = 0x00ff; + unsigned S = ((unsigned)s << 8) | s; + unsigned T = ((unsigned)t << 8) | t; + unsigned stk1; + unsigned stk2; + stk2 = T & S; + stk2 = ~stk2; + stk1 = D & stk2; + return stk1; +} + +/* DTSana source opaque/pattern transparent. */ +static unsigned xrop3_42_0_1 (unsigned char s, unsigned char t) +{ + unsigned D = 0x00ff; + unsigned S = ((unsigned)s << 8) | s; + unsigned T = ((unsigned)t << 8) | t; + unsigned stk1; + unsigned stk2; + stk2 = T & S; + stk2 = ~stk2; + stk1 = D & stk2; + return (stk1 & S) | (stk1 & (~T)) | (T & (~S) & D); +} + +/* DTSana source transparent/pattern opaque. */ +static unsigned xrop3_42_1_0 (unsigned char s, unsigned char t) +{ + unsigned D = 0x00ff; + unsigned S = ((unsigned)s << 8) | s; + unsigned T = ((unsigned)t << 8) | t; + unsigned stk1; + unsigned stk2; + stk2 = T & S; + stk2 = ~stk2; + stk1 = D & stk2; + return (stk1 & (~S)) | (D & S); +} + +/* DTSana source/pattern transparent. */ +static unsigned xrop3_42_1_1 (unsigned char s, unsigned char t) +{ + unsigned D = 0x00ff; + unsigned S = ((unsigned)s << 8) | s; + unsigned T = ((unsigned)t << 8) | t; + unsigned stk1; + unsigned stk2; + stk2 = T & S; + stk2 = ~stk2; + stk1 = D & stk2; + return (stk1 & (~S) & (~T)) | (D & S) | (D & T); +} + +/* SSTxTDxaxn source/pattern opaque. */ +static void rop3_43_0_0 (unsigned char *D, unsigned char S, unsigned char T) +{ + unsigned char stk1; + unsigned char stk2; + unsigned char stk3; + stk2 = S ^ T; + stk3 = T ^ *D; + stk2 = stk2 & stk3; + stk1 = S ^ stk2; + stk1 = ~stk1; + *D = stk1; +} + +/* SSTxTDxaxn source opaque/pattern transparent. */ +static void rop3_43_0_1 (unsigned char *D, unsigned char S, unsigned char T) +{ + unsigned char stk1; + unsigned char stk2; + unsigned char stk3; + stk2 = S ^ T; + stk3 = T ^ *D; + stk2 = stk2 & stk3; + stk1 = S ^ stk2; + stk1 = ~stk1; + *D = (stk1 & S) | (stk1 & (~T)) | (T & (~S) & *D); +} + +/* SSTxTDxaxn source transparent/pattern opaque. */ +static void rop3_43_1_0 (unsigned char *D, unsigned char S, unsigned char T) +{ + unsigned char stk1; + unsigned char stk2; + unsigned char stk3; + stk2 = S ^ T; + stk3 = T ^ *D; + stk2 = stk2 & stk3; + stk1 = S ^ stk2; + stk1 = ~stk1; + *D = (stk1 & (~S)) | (*D & S); +} + +/* SSTxTDxaxn source/pattern transparent. */ +static void rop3_43_1_1 (unsigned char *D, unsigned char S, unsigned char T) +{ + unsigned char stk1; + unsigned char stk2; + unsigned char stk3; + stk2 = S ^ T; + stk3 = T ^ *D; + stk2 = stk2 & stk3; + stk1 = S ^ stk2; + stk1 = ~stk1; + *D = (stk1 & (~S) & (~T)) | (*D & S) | (*D & T); +} + +/* SSTxTDxaxn source/pattern opaque. */ +static unsigned xrop3_43_0_0 (unsigned char s, unsigned char t) +{ + unsigned D = 0x00ff; + unsigned S = ((unsigned)s << 8) | s; + unsigned T = ((unsigned)t << 8) | t; + unsigned stk1; + unsigned stk2; + unsigned stk3; + stk2 = S ^ T; + stk3 = T ^ D; + stk2 = stk2 & stk3; + stk1 = S ^ stk2; + stk1 = ~stk1; + return stk1; +} + +/* SSTxTDxaxn source opaque/pattern transparent. */ +static unsigned xrop3_43_0_1 (unsigned char s, unsigned char t) +{ + unsigned D = 0x00ff; + unsigned S = ((unsigned)s << 8) | s; + unsigned T = ((unsigned)t << 8) | t; + unsigned stk1; + unsigned stk2; + unsigned stk3; + stk2 = S ^ T; + stk3 = T ^ D; + stk2 = stk2 & stk3; + stk1 = S ^ stk2; + stk1 = ~stk1; + return (stk1 & S) | (stk1 & (~T)) | (T & (~S) & D); +} + +/* SSTxTDxaxn source transparent/pattern opaque. */ +static unsigned xrop3_43_1_0 (unsigned char s, unsigned char t) +{ + unsigned D = 0x00ff; + unsigned S = ((unsigned)s << 8) | s; + unsigned T = ((unsigned)t << 8) | t; + unsigned stk1; + unsigned stk2; + unsigned stk3; + stk2 = S ^ T; + stk3 = T ^ D; + stk2 = stk2 & stk3; + stk1 = S ^ stk2; + stk1 = ~stk1; + return (stk1 & (~S)) | (D & S); +} + +/* SSTxTDxaxn source/pattern transparent. */ +static unsigned xrop3_43_1_1 (unsigned char s, unsigned char t) +{ + unsigned D = 0x00ff; + unsigned S = ((unsigned)s << 8) | s; + unsigned T = ((unsigned)t << 8) | t; + unsigned stk1; + unsigned stk2; + unsigned stk3; + stk2 = S ^ T; + stk3 = T ^ D; + stk2 = stk2 & stk3; + stk1 = S ^ stk2; + stk1 = ~stk1; + return (stk1 & (~S) & (~T)) | (D & S) | (D & T); +} + +/* STDSoax source/pattern opaque. */ +static void rop3_44_0_0 (unsigned char *D, unsigned char S, unsigned char T) +{ + unsigned char stk1; + unsigned char stk2; + unsigned char stk3; + stk3 = *D | S; + stk2 = T & stk3; + stk1 = S ^ stk2; + *D = stk1; +} + +/* STDSoax source opaque/pattern transparent. */ +static void rop3_44_0_1 (unsigned char *D, unsigned char S, unsigned char T) +{ + unsigned char stk1; + unsigned char stk2; + unsigned char stk3; + stk3 = *D | S; + stk2 = T & stk3; + stk1 = S ^ stk2; + *D = (stk1 & S) | (stk1 & (~T)) | (T & (~S) & *D); +} + +/* STDSoax source transparent/pattern opaque. */ +static void rop3_44_1_0 (unsigned char *D, unsigned char S, unsigned char T) +{ + unsigned char stk1; + unsigned char stk2; + unsigned char stk3; + stk3 = *D | S; + stk2 = T & stk3; + stk1 = S ^ stk2; + *D = (stk1 & (~S)) | (*D & S); +} + +/* STDSoax source/pattern transparent. */ +static void rop3_44_1_1 (unsigned char *D, unsigned char S, unsigned char T) +{ + unsigned char stk1; + unsigned char stk2; + unsigned char stk3; + stk3 = *D | S; + stk2 = T & stk3; + stk1 = S ^ stk2; + *D = (stk1 & (~S) & (~T)) | (*D & S) | (*D & T); +} + +/* STDSoax source/pattern opaque. */ +static unsigned xrop3_44_0_0 (unsigned char s, unsigned char t) +{ + unsigned D = 0x00ff; + unsigned S = ((unsigned)s << 8) | s; + unsigned T = ((unsigned)t << 8) | t; + unsigned stk1; + unsigned stk2; + unsigned stk3; + stk3 = D | S; + stk2 = T & stk3; + stk1 = S ^ stk2; + return stk1; +} + +/* STDSoax source opaque/pattern transparent. */ +static unsigned xrop3_44_0_1 (unsigned char s, unsigned char t) +{ + unsigned D = 0x00ff; + unsigned S = ((unsigned)s << 8) | s; + unsigned T = ((unsigned)t << 8) | t; + unsigned stk1; + unsigned stk2; + unsigned stk3; + stk3 = D | S; + stk2 = T & stk3; + stk1 = S ^ stk2; + return (stk1 & S) | (stk1 & (~T)) | (T & (~S) & D); +} + +/* STDSoax source transparent/pattern opaque. */ +static unsigned xrop3_44_1_0 (unsigned char s, unsigned char t) +{ + unsigned D = 0x00ff; + unsigned S = ((unsigned)s << 8) | s; + unsigned T = ((unsigned)t << 8) | t; + unsigned stk1; + unsigned stk2; + unsigned stk3; + stk3 = D | S; + stk2 = T & stk3; + stk1 = S ^ stk2; + return (stk1 & (~S)) | (D & S); +} + +/* STDSoax source/pattern transparent. */ +static unsigned xrop3_44_1_1 (unsigned char s, unsigned char t) +{ + unsigned D = 0x00ff; + unsigned S = ((unsigned)s << 8) | s; + unsigned T = ((unsigned)t << 8) | t; + unsigned stk1; + unsigned stk2; + unsigned stk3; + stk3 = D | S; + stk2 = T & stk3; + stk1 = S ^ stk2; + return (stk1 & (~S) & (~T)) | (D & S) | (D & T); +} + +/* TSDnox source/pattern opaque. */ +static void rop3_45_0_0 (unsigned char *D, unsigned char S, unsigned char T) +{ + unsigned char stk1; + unsigned char stk2; + unsigned char stk3; + stk3 = ~*D; + stk2 = S | stk3; + stk1 = T ^ stk2; + *D = stk1; +} + +/* TSDnox source opaque/pattern transparent. */ +static void rop3_45_0_1 (unsigned char *D, unsigned char S, unsigned char T) +{ + unsigned char stk1; + unsigned char stk2; + unsigned char stk3; + stk3 = ~*D; + stk2 = S | stk3; + stk1 = T ^ stk2; + *D = (stk1 & S) | (stk1 & (~T)) | (T & (~S) & *D); +} + +/* TSDnox source transparent/pattern opaque. */ +static void rop3_45_1_0 (unsigned char *D, unsigned char S, unsigned char T) +{ + unsigned char stk1; + unsigned char stk2; + unsigned char stk3; + stk3 = ~*D; + stk2 = S | stk3; + stk1 = T ^ stk2; + *D = (stk1 & (~S)) | (*D & S); +} + +/* TSDnox source/pattern transparent. */ +static void rop3_45_1_1 (unsigned char *D, unsigned char S, unsigned char T) +{ + unsigned char stk1; + unsigned char stk2; + unsigned char stk3; + stk3 = ~*D; + stk2 = S | stk3; + stk1 = T ^ stk2; + *D = (stk1 & (~S) & (~T)) | (*D & S) | (*D & T); +} + +/* TSDnox source/pattern opaque. */ +static unsigned xrop3_45_0_0 (unsigned char s, unsigned char t) +{ + unsigned D = 0x00ff; + unsigned S = ((unsigned)s << 8) | s; + unsigned T = ((unsigned)t << 8) | t; + unsigned stk1; + unsigned stk2; + unsigned stk3; + stk3 = ~D; + stk2 = S | stk3; + stk1 = T ^ stk2; + return stk1; +} + +/* TSDnox source opaque/pattern transparent. */ +static unsigned xrop3_45_0_1 (unsigned char s, unsigned char t) +{ + unsigned D = 0x00ff; + unsigned S = ((unsigned)s << 8) | s; + unsigned T = ((unsigned)t << 8) | t; + unsigned stk1; + unsigned stk2; + unsigned stk3; + stk3 = ~D; + stk2 = S | stk3; + stk1 = T ^ stk2; + return (stk1 & S) | (stk1 & (~T)) | (T & (~S) & D); +} + +/* TSDnox source transparent/pattern opaque. */ +static unsigned xrop3_45_1_0 (unsigned char s, unsigned char t) +{ + unsigned D = 0x00ff; + unsigned S = ((unsigned)s << 8) | s; + unsigned T = ((unsigned)t << 8) | t; + unsigned stk1; + unsigned stk2; + unsigned stk3; + stk3 = ~D; + stk2 = S | stk3; + stk1 = T ^ stk2; + return (stk1 & (~S)) | (D & S); +} + +/* TSDnox source/pattern transparent. */ +static unsigned xrop3_45_1_1 (unsigned char s, unsigned char t) +{ + unsigned D = 0x00ff; + unsigned S = ((unsigned)s << 8) | s; + unsigned T = ((unsigned)t << 8) | t; + unsigned stk1; + unsigned stk2; + unsigned stk3; + stk3 = ~D; + stk2 = S | stk3; + stk1 = T ^ stk2; + return (stk1 & (~S) & (~T)) | (D & S) | (D & T); +} + +/* TSDTxox source/pattern opaque. */ +static void rop3_46_0_0 (unsigned char *D, unsigned char S, unsigned char T) +{ + unsigned char stk1; + unsigned char stk2; + unsigned char stk3; + stk3 = *D ^ T; + stk2 = S | stk3; + stk1 = T ^ stk2; + *D = stk1; +} + +/* TSDTxox source opaque/pattern transparent. */ +static void rop3_46_0_1 (unsigned char *D, unsigned char S, unsigned char T) +{ + unsigned char stk1; + unsigned char stk2; + unsigned char stk3; + stk3 = *D ^ T; + stk2 = S | stk3; + stk1 = T ^ stk2; + *D = (stk1 & S) | (stk1 & (~T)) | (T & (~S) & *D); +} + +/* TSDTxox source transparent/pattern opaque. */ +static void rop3_46_1_0 (unsigned char *D, unsigned char S, unsigned char T) +{ + unsigned char stk1; + unsigned char stk2; + unsigned char stk3; + stk3 = *D ^ T; + stk2 = S | stk3; + stk1 = T ^ stk2; + *D = (stk1 & (~S)) | (*D & S); +} + +/* TSDTxox source/pattern transparent. */ +static void rop3_46_1_1 (unsigned char *D, unsigned char S, unsigned char T) +{ + unsigned char stk1; + unsigned char stk2; + unsigned char stk3; + stk3 = *D ^ T; + stk2 = S | stk3; + stk1 = T ^ stk2; + *D = (stk1 & (~S) & (~T)) | (*D & S) | (*D & T); +} + +/* TSDTxox source/pattern opaque. */ +static unsigned xrop3_46_0_0 (unsigned char s, unsigned char t) +{ + unsigned D = 0x00ff; + unsigned S = ((unsigned)s << 8) | s; + unsigned T = ((unsigned)t << 8) | t; + unsigned stk1; + unsigned stk2; + unsigned stk3; + stk3 = D ^ T; + stk2 = S | stk3; + stk1 = T ^ stk2; + return stk1; +} + +/* TSDTxox source opaque/pattern transparent. */ +static unsigned xrop3_46_0_1 (unsigned char s, unsigned char t) +{ + unsigned D = 0x00ff; + unsigned S = ((unsigned)s << 8) | s; + unsigned T = ((unsigned)t << 8) | t; + unsigned stk1; + unsigned stk2; + unsigned stk3; + stk3 = D ^ T; + stk2 = S | stk3; + stk1 = T ^ stk2; + return (stk1 & S) | (stk1 & (~T)) | (T & (~S) & D); +} + +/* TSDTxox source transparent/pattern opaque. */ +static unsigned xrop3_46_1_0 (unsigned char s, unsigned char t) +{ + unsigned D = 0x00ff; + unsigned S = ((unsigned)s << 8) | s; + unsigned T = ((unsigned)t << 8) | t; + unsigned stk1; + unsigned stk2; + unsigned stk3; + stk3 = D ^ T; + stk2 = S | stk3; + stk1 = T ^ stk2; + return (stk1 & (~S)) | (D & S); +} + +/* TSDTxox source/pattern transparent. */ +static unsigned xrop3_46_1_1 (unsigned char s, unsigned char t) +{ + unsigned D = 0x00ff; + unsigned S = ((unsigned)s << 8) | s; + unsigned T = ((unsigned)t << 8) | t; + unsigned stk1; + unsigned stk2; + unsigned stk3; + stk3 = D ^ T; + stk2 = S | stk3; + stk1 = T ^ stk2; + return (stk1 & (~S) & (~T)) | (D & S) | (D & T); +} + +/* TSDnoan source/pattern opaque. */ +static void rop3_47_0_0 (unsigned char *D, unsigned char S, unsigned char T) +{ + unsigned char stk1; + unsigned char stk2; + unsigned char stk3; + stk3 = ~*D; + stk2 = S | stk3; + stk1 = T & stk2; + stk1 = ~stk1; + *D = stk1; +} + +/* TSDnoan source opaque/pattern transparent. */ +static void rop3_47_0_1 (unsigned char *D, unsigned char S, unsigned char T) +{ + unsigned char stk1; + unsigned char stk2; + unsigned char stk3; + stk3 = ~*D; + stk2 = S | stk3; + stk1 = T & stk2; + stk1 = ~stk1; + *D = (stk1 & S) | (stk1 & (~T)) | (T & (~S) & *D); +} + +/* TSDnoan source transparent/pattern opaque. */ +static void rop3_47_1_0 (unsigned char *D, unsigned char S, unsigned char T) +{ + unsigned char stk1; + unsigned char stk2; + unsigned char stk3; + stk3 = ~*D; + stk2 = S | stk3; + stk1 = T & stk2; + stk1 = ~stk1; + *D = (stk1 & (~S)) | (*D & S); +} + +/* TSDnoan source/pattern transparent. */ +static void rop3_47_1_1 (unsigned char *D, unsigned char S, unsigned char T) +{ + unsigned char stk1; + unsigned char stk2; + unsigned char stk3; + stk3 = ~*D; + stk2 = S | stk3; + stk1 = T & stk2; + stk1 = ~stk1; + *D = (stk1 & (~S) & (~T)) | (*D & S) | (*D & T); +} + +/* TSDnoan source/pattern opaque. */ +static unsigned xrop3_47_0_0 (unsigned char s, unsigned char t) +{ + unsigned D = 0x00ff; + unsigned S = ((unsigned)s << 8) | s; + unsigned T = ((unsigned)t << 8) | t; + unsigned stk1; + unsigned stk2; + unsigned stk3; + stk3 = ~D; + stk2 = S | stk3; + stk1 = T & stk2; + stk1 = ~stk1; + return stk1; +} + +/* TSDnoan source opaque/pattern transparent. */ +static unsigned xrop3_47_0_1 (unsigned char s, unsigned char t) +{ + unsigned D = 0x00ff; + unsigned S = ((unsigned)s << 8) | s; + unsigned T = ((unsigned)t << 8) | t; + unsigned stk1; + unsigned stk2; + unsigned stk3; + stk3 = ~D; + stk2 = S | stk3; + stk1 = T & stk2; + stk1 = ~stk1; + return (stk1 & S) | (stk1 & (~T)) | (T & (~S) & D); +} + +/* TSDnoan source transparent/pattern opaque. */ +static unsigned xrop3_47_1_0 (unsigned char s, unsigned char t) +{ + unsigned D = 0x00ff; + unsigned S = ((unsigned)s << 8) | s; + unsigned T = ((unsigned)t << 8) | t; + unsigned stk1; + unsigned stk2; + unsigned stk3; + stk3 = ~D; + stk2 = S | stk3; + stk1 = T & stk2; + stk1 = ~stk1; + return (stk1 & (~S)) | (D & S); +} + +/* TSDnoan source/pattern transparent. */ +static unsigned xrop3_47_1_1 (unsigned char s, unsigned char t) +{ + unsigned D = 0x00ff; + unsigned S = ((unsigned)s << 8) | s; + unsigned T = ((unsigned)t << 8) | t; + unsigned stk1; + unsigned stk2; + unsigned stk3; + stk3 = ~D; + stk2 = S | stk3; + stk1 = T & stk2; + stk1 = ~stk1; + return (stk1 & (~S) & (~T)) | (D & S) | (D & T); +} + +/* TSna source/pattern opaque. */ +static void rop3_48_0_0 (unsigned char *D, unsigned char S, unsigned char T) +{ + unsigned char stk1; + unsigned char stk2; + stk2 = ~S; + stk1 = T & stk2; + *D = stk1; +} + +/* TSna source opaque/pattern transparent. */ +static void rop3_48_0_1 (unsigned char *D, unsigned char S, unsigned char T) +{ + unsigned char stk1; + unsigned char stk2; + stk2 = ~S; + stk1 = T & stk2; + *D = (stk1 & S) | (stk1 & (~T)) | (T & (~S) & *D); +} + +/* TSna source transparent/pattern opaque. */ +static void rop3_48_1_0 (unsigned char *D, unsigned char S, unsigned char T) +{ + unsigned char stk1; + unsigned char stk2; + stk2 = ~S; + stk1 = T & stk2; + *D = (stk1 & (~S)) | (*D & S); +} + +/* TSna source/pattern transparent. */ +static void rop3_48_1_1 (unsigned char *D, unsigned char S, unsigned char T) +{ + unsigned char stk1; + unsigned char stk2; + stk2 = ~S; + stk1 = T & stk2; + *D = (stk1 & (~S) & (~T)) | (*D & S) | (*D & T); +} + +/* TSna source/pattern opaque. */ +static unsigned xrop3_48_0_0 (unsigned char s, unsigned char t) +{ + unsigned S = ((unsigned)s << 8) | s; + unsigned T = ((unsigned)t << 8) | t; + unsigned stk1; + unsigned stk2; + stk2 = ~S; + stk1 = T & stk2; + return stk1; +} + +/* TSna source opaque/pattern transparent. */ +static unsigned xrop3_48_0_1 (unsigned char s, unsigned char t) +{ + unsigned D = 0x00ff; + unsigned S = ((unsigned)s << 8) | s; + unsigned T = ((unsigned)t << 8) | t; + unsigned stk1; + unsigned stk2; + stk2 = ~S; + stk1 = T & stk2; + return (stk1 & S) | (stk1 & (~T)) | (T & (~S) & D); +} + +/* TSna source transparent/pattern opaque. */ +static unsigned xrop3_48_1_0 (unsigned char s, unsigned char t) +{ + unsigned D = 0x00ff; + unsigned S = ((unsigned)s << 8) | s; + unsigned T = ((unsigned)t << 8) | t; + unsigned stk1; + unsigned stk2; + stk2 = ~S; + stk1 = T & stk2; + return (stk1 & (~S)) | (D & S); +} + +/* TSna source/pattern transparent. */ +static unsigned xrop3_48_1_1 (unsigned char s, unsigned char t) +{ + unsigned D = 0x00ff; + unsigned S = ((unsigned)s << 8) | s; + unsigned T = ((unsigned)t << 8) | t; + unsigned stk1; + unsigned stk2; + stk2 = ~S; + stk1 = T & stk2; + return (stk1 & (~S) & (~T)) | (D & S) | (D & T); +} + +/* SDTnaon source/pattern opaque. */ +static void rop3_49_0_0 (unsigned char *D, unsigned char S, unsigned char T) +{ + unsigned char stk1; + unsigned char stk2; + unsigned char stk3; + stk3 = ~T; + stk2 = *D & stk3; + stk1 = S | stk2; + stk1 = ~stk1; + *D = stk1; +} + +/* SDTnaon source opaque/pattern transparent. */ +static void rop3_49_0_1 (unsigned char *D, unsigned char S, unsigned char T) +{ + unsigned char stk1; + unsigned char stk2; + unsigned char stk3; + stk3 = ~T; + stk2 = *D & stk3; + stk1 = S | stk2; + stk1 = ~stk1; + *D = (stk1 & S) | (stk1 & (~T)) | (T & (~S) & *D); +} + +/* SDTnaon source transparent/pattern opaque. */ +static void rop3_49_1_0 (unsigned char *D, unsigned char S, unsigned char T) +{ + unsigned char stk1; + unsigned char stk2; + unsigned char stk3; + stk3 = ~T; + stk2 = *D & stk3; + stk1 = S | stk2; + stk1 = ~stk1; + *D = (stk1 & (~S)) | (*D & S); +} + +/* SDTnaon source/pattern transparent. */ +static void rop3_49_1_1 (unsigned char *D, unsigned char S, unsigned char T) +{ + unsigned char stk1; + unsigned char stk2; + unsigned char stk3; + stk3 = ~T; + stk2 = *D & stk3; + stk1 = S | stk2; + stk1 = ~stk1; + *D = (stk1 & (~S) & (~T)) | (*D & S) | (*D & T); +} + +/* SDTnaon source/pattern opaque. */ +static unsigned xrop3_49_0_0 (unsigned char s, unsigned char t) +{ + unsigned D = 0x00ff; + unsigned S = ((unsigned)s << 8) | s; + unsigned T = ((unsigned)t << 8) | t; + unsigned stk1; + unsigned stk2; + unsigned stk3; + stk3 = ~T; + stk2 = D & stk3; + stk1 = S | stk2; + stk1 = ~stk1; + return stk1; +} + +/* SDTnaon source opaque/pattern transparent. */ +static unsigned xrop3_49_0_1 (unsigned char s, unsigned char t) +{ + unsigned D = 0x00ff; + unsigned S = ((unsigned)s << 8) | s; + unsigned T = ((unsigned)t << 8) | t; + unsigned stk1; + unsigned stk2; + unsigned stk3; + stk3 = ~T; + stk2 = D & stk3; + stk1 = S | stk2; + stk1 = ~stk1; + return (stk1 & S) | (stk1 & (~T)) | (T & (~S) & D); +} + +/* SDTnaon source transparent/pattern opaque. */ +static unsigned xrop3_49_1_0 (unsigned char s, unsigned char t) +{ + unsigned D = 0x00ff; + unsigned S = ((unsigned)s << 8) | s; + unsigned T = ((unsigned)t << 8) | t; + unsigned stk1; + unsigned stk2; + unsigned stk3; + stk3 = ~T; + stk2 = D & stk3; + stk1 = S | stk2; + stk1 = ~stk1; + return (stk1 & (~S)) | (D & S); +} + +/* SDTnaon source/pattern transparent. */ +static unsigned xrop3_49_1_1 (unsigned char s, unsigned char t) +{ + unsigned D = 0x00ff; + unsigned S = ((unsigned)s << 8) | s; + unsigned T = ((unsigned)t << 8) | t; + unsigned stk1; + unsigned stk2; + unsigned stk3; + stk3 = ~T; + stk2 = D & stk3; + stk1 = S | stk2; + stk1 = ~stk1; + return (stk1 & (~S) & (~T)) | (D & S) | (D & T); +} + +/* SDTSoox source/pattern opaque. */ +static void rop3_50_0_0 (unsigned char *D, unsigned char S, unsigned char T) +{ + unsigned char stk1; + unsigned char stk2; + unsigned char stk3; + stk3 = T | S; + stk2 = *D | stk3; + stk1 = S ^ stk2; + *D = stk1; +} + +/* SDTSoox source opaque/pattern transparent. */ +static void rop3_50_0_1 (unsigned char *D, unsigned char S, unsigned char T) +{ + unsigned char stk1; + unsigned char stk2; + unsigned char stk3; + stk3 = T | S; + stk2 = *D | stk3; + stk1 = S ^ stk2; + *D = (stk1 & S) | (stk1 & (~T)) | (T & (~S) & *D); +} + +/* SDTSoox source transparent/pattern opaque. */ +static void rop3_50_1_0 (unsigned char *D, unsigned char S, unsigned char T) +{ + unsigned char stk1; + unsigned char stk2; + unsigned char stk3; + stk3 = T | S; + stk2 = *D | stk3; + stk1 = S ^ stk2; + *D = (stk1 & (~S)) | (*D & S); +} + +/* SDTSoox source/pattern transparent. */ +static void rop3_50_1_1 (unsigned char *D, unsigned char S, unsigned char T) +{ + unsigned char stk1; + unsigned char stk2; + unsigned char stk3; + stk3 = T | S; + stk2 = *D | stk3; + stk1 = S ^ stk2; + *D = (stk1 & (~S) & (~T)) | (*D & S) | (*D & T); +} + +/* SDTSoox source/pattern opaque. */ +static unsigned xrop3_50_0_0 (unsigned char s, unsigned char t) +{ + unsigned D = 0x00ff; + unsigned S = ((unsigned)s << 8) | s; + unsigned T = ((unsigned)t << 8) | t; + unsigned stk1; + unsigned stk2; + unsigned stk3; + stk3 = T | S; + stk2 = D | stk3; + stk1 = S ^ stk2; + return stk1; +} + +/* SDTSoox source opaque/pattern transparent. */ +static unsigned xrop3_50_0_1 (unsigned char s, unsigned char t) +{ + unsigned D = 0x00ff; + unsigned S = ((unsigned)s << 8) | s; + unsigned T = ((unsigned)t << 8) | t; + unsigned stk1; + unsigned stk2; + unsigned stk3; + stk3 = T | S; + stk2 = D | stk3; + stk1 = S ^ stk2; + return (stk1 & S) | (stk1 & (~T)) | (T & (~S) & D); +} + +/* SDTSoox source transparent/pattern opaque. */ +static unsigned xrop3_50_1_0 (unsigned char s, unsigned char t) +{ + unsigned D = 0x00ff; + unsigned S = ((unsigned)s << 8) | s; + unsigned T = ((unsigned)t << 8) | t; + unsigned stk1; + unsigned stk2; + unsigned stk3; + stk3 = T | S; + stk2 = D | stk3; + stk1 = S ^ stk2; + return (stk1 & (~S)) | (D & S); +} + +/* SDTSoox source/pattern transparent. */ +static unsigned xrop3_50_1_1 (unsigned char s, unsigned char t) +{ + unsigned D = 0x00ff; + unsigned S = ((unsigned)s << 8) | s; + unsigned T = ((unsigned)t << 8) | t; + unsigned stk1; + unsigned stk2; + unsigned stk3; + stk3 = T | S; + stk2 = D | stk3; + stk1 = S ^ stk2; + return (stk1 & (~S) & (~T)) | (D & S) | (D & T); +} + +/* Sn source/pattern opaque. */ +static void rop3_51_0_0 (unsigned char *D, unsigned char S, unsigned char T) +{ + unsigned char stk1; + stk1 = ~S; + *D = stk1; +} + +/* Sn source opaque/pattern transparent. */ +static void rop3_51_0_1 (unsigned char *D, unsigned char S, unsigned char T) +{ + unsigned char stk1; + stk1 = ~S; + *D = (stk1 & S) | (stk1 & (~T)) | (T & (~S) & *D); +} + +/* Sn source transparent/pattern opaque. */ +static void rop3_51_1_0 (unsigned char *D, unsigned char S, unsigned char T) +{ + unsigned char stk1; + stk1 = ~S; + *D = (stk1 & (~S)) | (*D & S); +} + +/* Sn source/pattern transparent. */ +static void rop3_51_1_1 (unsigned char *D, unsigned char S, unsigned char T) +{ + unsigned char stk1; + stk1 = ~S; + *D = (stk1 & (~S) & (~T)) | (*D & S) | (*D & T); +} + +/* Sn source/pattern opaque. */ +static unsigned xrop3_51_0_0 (unsigned char s, unsigned char t) +{ + unsigned S = ((unsigned)s << 8) | s; + unsigned stk1; + stk1 = ~S; + return stk1; +} + +/* Sn source opaque/pattern transparent. */ +static unsigned xrop3_51_0_1 (unsigned char s, unsigned char t) +{ + unsigned D = 0x00ff; + unsigned S = ((unsigned)s << 8) | s; + unsigned T = ((unsigned)t << 8) | t; + unsigned stk1; + stk1 = ~S; + return (stk1 & S) | (stk1 & (~T)) | (T & (~S) & D); +} + +/* Sn source transparent/pattern opaque. */ +static unsigned xrop3_51_1_0 (unsigned char s, unsigned char t) +{ + unsigned D = 0x00ff; + unsigned S = ((unsigned)s << 8) | s; + unsigned stk1; + stk1 = ~S; + return (stk1 & (~S)) | (D & S); +} + +/* Sn source/pattern transparent. */ +static unsigned xrop3_51_1_1 (unsigned char s, unsigned char t) +{ + unsigned D = 0x00ff; + unsigned S = ((unsigned)s << 8) | s; + unsigned T = ((unsigned)t << 8) | t; + unsigned stk1; + stk1 = ~S; + return (stk1 & (~S) & (~T)) | (D & S) | (D & T); +} + +/* STDSaox source/pattern opaque. */ +static void rop3_52_0_0 (unsigned char *D, unsigned char S, unsigned char T) +{ + unsigned char stk1; + unsigned char stk2; + unsigned char stk3; + stk3 = *D & S; + stk2 = T | stk3; + stk1 = S ^ stk2; + *D = stk1; +} + +/* STDSaox source opaque/pattern transparent. */ +static void rop3_52_0_1 (unsigned char *D, unsigned char S, unsigned char T) +{ + unsigned char stk1; + unsigned char stk2; + unsigned char stk3; + stk3 = *D & S; + stk2 = T | stk3; + stk1 = S ^ stk2; + *D = (stk1 & S) | (stk1 & (~T)) | (T & (~S) & *D); +} + +/* STDSaox source transparent/pattern opaque. */ +static void rop3_52_1_0 (unsigned char *D, unsigned char S, unsigned char T) +{ + unsigned char stk1; + unsigned char stk2; + unsigned char stk3; + stk3 = *D & S; + stk2 = T | stk3; + stk1 = S ^ stk2; + *D = (stk1 & (~S)) | (*D & S); +} + +/* STDSaox source/pattern transparent. */ +static void rop3_52_1_1 (unsigned char *D, unsigned char S, unsigned char T) +{ + unsigned char stk1; + unsigned char stk2; + unsigned char stk3; + stk3 = *D & S; + stk2 = T | stk3; + stk1 = S ^ stk2; + *D = (stk1 & (~S) & (~T)) | (*D & S) | (*D & T); +} + +/* STDSaox source/pattern opaque. */ +static unsigned xrop3_52_0_0 (unsigned char s, unsigned char t) +{ + unsigned D = 0x00ff; + unsigned S = ((unsigned)s << 8) | s; + unsigned T = ((unsigned)t << 8) | t; + unsigned stk1; + unsigned stk2; + unsigned stk3; + stk3 = D & S; + stk2 = T | stk3; + stk1 = S ^ stk2; + return stk1; +} + +/* STDSaox source opaque/pattern transparent. */ +static unsigned xrop3_52_0_1 (unsigned char s, unsigned char t) +{ + unsigned D = 0x00ff; + unsigned S = ((unsigned)s << 8) | s; + unsigned T = ((unsigned)t << 8) | t; + unsigned stk1; + unsigned stk2; + unsigned stk3; + stk3 = D & S; + stk2 = T | stk3; + stk1 = S ^ stk2; + return (stk1 & S) | (stk1 & (~T)) | (T & (~S) & D); +} + +/* STDSaox source transparent/pattern opaque. */ +static unsigned xrop3_52_1_0 (unsigned char s, unsigned char t) +{ + unsigned D = 0x00ff; + unsigned S = ((unsigned)s << 8) | s; + unsigned T = ((unsigned)t << 8) | t; + unsigned stk1; + unsigned stk2; + unsigned stk3; + stk3 = D & S; + stk2 = T | stk3; + stk1 = S ^ stk2; + return (stk1 & (~S)) | (D & S); +} + +/* STDSaox source/pattern transparent. */ +static unsigned xrop3_52_1_1 (unsigned char s, unsigned char t) +{ + unsigned D = 0x00ff; + unsigned S = ((unsigned)s << 8) | s; + unsigned T = ((unsigned)t << 8) | t; + unsigned stk1; + unsigned stk2; + unsigned stk3; + stk3 = D & S; + stk2 = T | stk3; + stk1 = S ^ stk2; + return (stk1 & (~S) & (~T)) | (D & S) | (D & T); +} + +/* STDSxnox source/pattern opaque. */ +static void rop3_53_0_0 (unsigned char *D, unsigned char S, unsigned char T) +{ + unsigned char stk1; + unsigned char stk2; + unsigned char stk3; + stk3 = *D ^ S; + stk3 = ~stk3; + stk2 = T | stk3; + stk1 = S ^ stk2; + *D = stk1; +} + +/* STDSxnox source opaque/pattern transparent. */ +static void rop3_53_0_1 (unsigned char *D, unsigned char S, unsigned char T) +{ + unsigned char stk1; + unsigned char stk2; + unsigned char stk3; + stk3 = *D ^ S; + stk3 = ~stk3; + stk2 = T | stk3; + stk1 = S ^ stk2; + *D = (stk1 & S) | (stk1 & (~T)) | (T & (~S) & *D); +} + +/* STDSxnox source transparent/pattern opaque. */ +static void rop3_53_1_0 (unsigned char *D, unsigned char S, unsigned char T) +{ + unsigned char stk1; + unsigned char stk2; + unsigned char stk3; + stk3 = *D ^ S; + stk3 = ~stk3; + stk2 = T | stk3; + stk1 = S ^ stk2; + *D = (stk1 & (~S)) | (*D & S); +} + +/* STDSxnox source/pattern transparent. */ +static void rop3_53_1_1 (unsigned char *D, unsigned char S, unsigned char T) +{ + unsigned char stk1; + unsigned char stk2; + unsigned char stk3; + stk3 = *D ^ S; + stk3 = ~stk3; + stk2 = T | stk3; + stk1 = S ^ stk2; + *D = (stk1 & (~S) & (~T)) | (*D & S) | (*D & T); +} + +/* STDSxnox source/pattern opaque. */ +static unsigned xrop3_53_0_0 (unsigned char s, unsigned char t) +{ + unsigned D = 0x00ff; + unsigned S = ((unsigned)s << 8) | s; + unsigned T = ((unsigned)t << 8) | t; + unsigned stk1; + unsigned stk2; + unsigned stk3; + stk3 = D ^ S; + stk3 = ~stk3; + stk2 = T | stk3; + stk1 = S ^ stk2; + return stk1; +} + +/* STDSxnox source opaque/pattern transparent. */ +static unsigned xrop3_53_0_1 (unsigned char s, unsigned char t) +{ + unsigned D = 0x00ff; + unsigned S = ((unsigned)s << 8) | s; + unsigned T = ((unsigned)t << 8) | t; + unsigned stk1; + unsigned stk2; + unsigned stk3; + stk3 = D ^ S; + stk3 = ~stk3; + stk2 = T | stk3; + stk1 = S ^ stk2; + return (stk1 & S) | (stk1 & (~T)) | (T & (~S) & D); +} + +/* STDSxnox source transparent/pattern opaque. */ +static unsigned xrop3_53_1_0 (unsigned char s, unsigned char t) +{ + unsigned D = 0x00ff; + unsigned S = ((unsigned)s << 8) | s; + unsigned T = ((unsigned)t << 8) | t; + unsigned stk1; + unsigned stk2; + unsigned stk3; + stk3 = D ^ S; + stk3 = ~stk3; + stk2 = T | stk3; + stk1 = S ^ stk2; + return (stk1 & (~S)) | (D & S); +} + +/* STDSxnox source/pattern transparent. */ +static unsigned xrop3_53_1_1 (unsigned char s, unsigned char t) +{ + unsigned D = 0x00ff; + unsigned S = ((unsigned)s << 8) | s; + unsigned T = ((unsigned)t << 8) | t; + unsigned stk1; + unsigned stk2; + unsigned stk3; + stk3 = D ^ S; + stk3 = ~stk3; + stk2 = T | stk3; + stk1 = S ^ stk2; + return (stk1 & (~S) & (~T)) | (D & S) | (D & T); +} + +/* SDTox source/pattern opaque. */ +static void rop3_54_0_0 (unsigned char *D, unsigned char S, unsigned char T) +{ + unsigned char stk1; + unsigned char stk2; + stk2 = *D | T; + stk1 = S ^ stk2; + *D = stk1; +} + +/* SDTox source opaque/pattern transparent. */ +static void rop3_54_0_1 (unsigned char *D, unsigned char S, unsigned char T) +{ + unsigned char stk1; + unsigned char stk2; + stk2 = *D | T; + stk1 = S ^ stk2; + *D = (stk1 & S) | (stk1 & (~T)) | (T & (~S) & *D); +} + +/* SDTox source transparent/pattern opaque. */ +static void rop3_54_1_0 (unsigned char *D, unsigned char S, unsigned char T) +{ + unsigned char stk1; + unsigned char stk2; + stk2 = *D | T; + stk1 = S ^ stk2; + *D = (stk1 & (~S)) | (*D & S); +} + +/* SDTox source/pattern transparent. */ +static void rop3_54_1_1 (unsigned char *D, unsigned char S, unsigned char T) +{ + unsigned char stk1; + unsigned char stk2; + stk2 = *D | T; + stk1 = S ^ stk2; + *D = (stk1 & (~S) & (~T)) | (*D & S) | (*D & T); +} + +/* SDTox source/pattern opaque. */ +static unsigned xrop3_54_0_0 (unsigned char s, unsigned char t) +{ + unsigned D = 0x00ff; + unsigned S = ((unsigned)s << 8) | s; + unsigned T = ((unsigned)t << 8) | t; + unsigned stk1; + unsigned stk2; + stk2 = D | T; + stk1 = S ^ stk2; + return stk1; +} + +/* SDTox source opaque/pattern transparent. */ +static unsigned xrop3_54_0_1 (unsigned char s, unsigned char t) +{ + unsigned D = 0x00ff; + unsigned S = ((unsigned)s << 8) | s; + unsigned T = ((unsigned)t << 8) | t; + unsigned stk1; + unsigned stk2; + stk2 = D | T; + stk1 = S ^ stk2; + return (stk1 & S) | (stk1 & (~T)) | (T & (~S) & D); +} + +/* SDTox source transparent/pattern opaque. */ +static unsigned xrop3_54_1_0 (unsigned char s, unsigned char t) +{ + unsigned D = 0x00ff; + unsigned S = ((unsigned)s << 8) | s; + unsigned T = ((unsigned)t << 8) | t; + unsigned stk1; + unsigned stk2; + stk2 = D | T; + stk1 = S ^ stk2; + return (stk1 & (~S)) | (D & S); +} + +/* SDTox source/pattern transparent. */ +static unsigned xrop3_54_1_1 (unsigned char s, unsigned char t) +{ + unsigned D = 0x00ff; + unsigned S = ((unsigned)s << 8) | s; + unsigned T = ((unsigned)t << 8) | t; + unsigned stk1; + unsigned stk2; + stk2 = D | T; + stk1 = S ^ stk2; + return (stk1 & (~S) & (~T)) | (D & S) | (D & T); +} + +/* SDToan source/pattern opaque. */ +static void rop3_55_0_0 (unsigned char *D, unsigned char S, unsigned char T) +{ + unsigned char stk1; + unsigned char stk2; + stk2 = *D | T; + stk1 = S & stk2; + stk1 = ~stk1; + *D = stk1; +} + +/* SDToan source opaque/pattern transparent. */ +static void rop3_55_0_1 (unsigned char *D, unsigned char S, unsigned char T) +{ + unsigned char stk1; + unsigned char stk2; + stk2 = *D | T; + stk1 = S & stk2; + stk1 = ~stk1; + *D = (stk1 & S) | (stk1 & (~T)) | (T & (~S) & *D); +} + +/* SDToan source transparent/pattern opaque. */ +static void rop3_55_1_0 (unsigned char *D, unsigned char S, unsigned char T) +{ + unsigned char stk1; + unsigned char stk2; + stk2 = *D | T; + stk1 = S & stk2; + stk1 = ~stk1; + *D = (stk1 & (~S)) | (*D & S); +} + +/* SDToan source/pattern transparent. */ +static void rop3_55_1_1 (unsigned char *D, unsigned char S, unsigned char T) +{ + unsigned char stk1; + unsigned char stk2; + stk2 = *D | T; + stk1 = S & stk2; + stk1 = ~stk1; + *D = (stk1 & (~S) & (~T)) | (*D & S) | (*D & T); +} + +/* SDToan source/pattern opaque. */ +static unsigned xrop3_55_0_0 (unsigned char s, unsigned char t) +{ + unsigned D = 0x00ff; + unsigned S = ((unsigned)s << 8) | s; + unsigned T = ((unsigned)t << 8) | t; + unsigned stk1; + unsigned stk2; + stk2 = D | T; + stk1 = S & stk2; + stk1 = ~stk1; + return stk1; +} + +/* SDToan source opaque/pattern transparent. */ +static unsigned xrop3_55_0_1 (unsigned char s, unsigned char t) +{ + unsigned D = 0x00ff; + unsigned S = ((unsigned)s << 8) | s; + unsigned T = ((unsigned)t << 8) | t; + unsigned stk1; + unsigned stk2; + stk2 = D | T; + stk1 = S & stk2; + stk1 = ~stk1; + return (stk1 & S) | (stk1 & (~T)) | (T & (~S) & D); +} + +/* SDToan source transparent/pattern opaque. */ +static unsigned xrop3_55_1_0 (unsigned char s, unsigned char t) +{ + unsigned D = 0x00ff; + unsigned S = ((unsigned)s << 8) | s; + unsigned T = ((unsigned)t << 8) | t; + unsigned stk1; + unsigned stk2; + stk2 = D | T; + stk1 = S & stk2; + stk1 = ~stk1; + return (stk1 & (~S)) | (D & S); +} + +/* SDToan source/pattern transparent. */ +static unsigned xrop3_55_1_1 (unsigned char s, unsigned char t) +{ + unsigned D = 0x00ff; + unsigned S = ((unsigned)s << 8) | s; + unsigned T = ((unsigned)t << 8) | t; + unsigned stk1; + unsigned stk2; + stk2 = D | T; + stk1 = S & stk2; + stk1 = ~stk1; + return (stk1 & (~S) & (~T)) | (D & S) | (D & T); +} + +/* TSDToax source/pattern opaque. */ +static void rop3_56_0_0 (unsigned char *D, unsigned char S, unsigned char T) +{ + unsigned char stk1; + unsigned char stk2; + unsigned char stk3; + stk3 = *D | T; + stk2 = S & stk3; + stk1 = T ^ stk2; + *D = stk1; +} + +/* TSDToax source opaque/pattern transparent. */ +static void rop3_56_0_1 (unsigned char *D, unsigned char S, unsigned char T) +{ + unsigned char stk1; + unsigned char stk2; + unsigned char stk3; + stk3 = *D | T; + stk2 = S & stk3; + stk1 = T ^ stk2; + *D = (stk1 & S) | (stk1 & (~T)) | (T & (~S) & *D); +} + +/* TSDToax source transparent/pattern opaque. */ +static void rop3_56_1_0 (unsigned char *D, unsigned char S, unsigned char T) +{ + unsigned char stk1; + unsigned char stk2; + unsigned char stk3; + stk3 = *D | T; + stk2 = S & stk3; + stk1 = T ^ stk2; + *D = (stk1 & (~S)) | (*D & S); +} + +/* TSDToax source/pattern transparent. */ +static void rop3_56_1_1 (unsigned char *D, unsigned char S, unsigned char T) +{ + unsigned char stk1; + unsigned char stk2; + unsigned char stk3; + stk3 = *D | T; + stk2 = S & stk3; + stk1 = T ^ stk2; + *D = (stk1 & (~S) & (~T)) | (*D & S) | (*D & T); +} + +/* TSDToax source/pattern opaque. */ +static unsigned xrop3_56_0_0 (unsigned char s, unsigned char t) +{ + unsigned D = 0x00ff; + unsigned S = ((unsigned)s << 8) | s; + unsigned T = ((unsigned)t << 8) | t; + unsigned stk1; + unsigned stk2; + unsigned stk3; + stk3 = D | T; + stk2 = S & stk3; + stk1 = T ^ stk2; + return stk1; +} + +/* TSDToax source opaque/pattern transparent. */ +static unsigned xrop3_56_0_1 (unsigned char s, unsigned char t) +{ + unsigned D = 0x00ff; + unsigned S = ((unsigned)s << 8) | s; + unsigned T = ((unsigned)t << 8) | t; + unsigned stk1; + unsigned stk2; + unsigned stk3; + stk3 = D | T; + stk2 = S & stk3; + stk1 = T ^ stk2; + return (stk1 & S) | (stk1 & (~T)) | (T & (~S) & D); +} + +/* TSDToax source transparent/pattern opaque. */ +static unsigned xrop3_56_1_0 (unsigned char s, unsigned char t) +{ + unsigned D = 0x00ff; + unsigned S = ((unsigned)s << 8) | s; + unsigned T = ((unsigned)t << 8) | t; + unsigned stk1; + unsigned stk2; + unsigned stk3; + stk3 = D | T; + stk2 = S & stk3; + stk1 = T ^ stk2; + return (stk1 & (~S)) | (D & S); +} + +/* TSDToax source/pattern transparent. */ +static unsigned xrop3_56_1_1 (unsigned char s, unsigned char t) +{ + unsigned D = 0x00ff; + unsigned S = ((unsigned)s << 8) | s; + unsigned T = ((unsigned)t << 8) | t; + unsigned stk1; + unsigned stk2; + unsigned stk3; + stk3 = D | T; + stk2 = S & stk3; + stk1 = T ^ stk2; + return (stk1 & (~S) & (~T)) | (D & S) | (D & T); +} + +/* STDnox source/pattern opaque. */ +static void rop3_57_0_0 (unsigned char *D, unsigned char S, unsigned char T) +{ + unsigned char stk1; + unsigned char stk2; + unsigned char stk3; + stk3 = ~*D; + stk2 = T | stk3; + stk1 = S ^ stk2; + *D = stk1; +} + +/* STDnox source opaque/pattern transparent. */ +static void rop3_57_0_1 (unsigned char *D, unsigned char S, unsigned char T) +{ + unsigned char stk1; + unsigned char stk2; + unsigned char stk3; + stk3 = ~*D; + stk2 = T | stk3; + stk1 = S ^ stk2; + *D = (stk1 & S) | (stk1 & (~T)) | (T & (~S) & *D); +} + +/* STDnox source transparent/pattern opaque. */ +static void rop3_57_1_0 (unsigned char *D, unsigned char S, unsigned char T) +{ + unsigned char stk1; + unsigned char stk2; + unsigned char stk3; + stk3 = ~*D; + stk2 = T | stk3; + stk1 = S ^ stk2; + *D = (stk1 & (~S)) | (*D & S); +} + +/* STDnox source/pattern transparent. */ +static void rop3_57_1_1 (unsigned char *D, unsigned char S, unsigned char T) +{ + unsigned char stk1; + unsigned char stk2; + unsigned char stk3; + stk3 = ~*D; + stk2 = T | stk3; + stk1 = S ^ stk2; + *D = (stk1 & (~S) & (~T)) | (*D & S) | (*D & T); +} + +/* STDnox source/pattern opaque. */ +static unsigned xrop3_57_0_0 (unsigned char s, unsigned char t) +{ + unsigned D = 0x00ff; + unsigned S = ((unsigned)s << 8) | s; + unsigned T = ((unsigned)t << 8) | t; + unsigned stk1; + unsigned stk2; + unsigned stk3; + stk3 = ~D; + stk2 = T | stk3; + stk1 = S ^ stk2; + return stk1; +} + +/* STDnox source opaque/pattern transparent. */ +static unsigned xrop3_57_0_1 (unsigned char s, unsigned char t) +{ + unsigned D = 0x00ff; + unsigned S = ((unsigned)s << 8) | s; + unsigned T = ((unsigned)t << 8) | t; + unsigned stk1; + unsigned stk2; + unsigned stk3; + stk3 = ~D; + stk2 = T | stk3; + stk1 = S ^ stk2; + return (stk1 & S) | (stk1 & (~T)) | (T & (~S) & D); +} + +/* STDnox source transparent/pattern opaque. */ +static unsigned xrop3_57_1_0 (unsigned char s, unsigned char t) +{ + unsigned D = 0x00ff; + unsigned S = ((unsigned)s << 8) | s; + unsigned T = ((unsigned)t << 8) | t; + unsigned stk1; + unsigned stk2; + unsigned stk3; + stk3 = ~D; + stk2 = T | stk3; + stk1 = S ^ stk2; + return (stk1 & (~S)) | (D & S); +} + +/* STDnox source/pattern transparent. */ +static unsigned xrop3_57_1_1 (unsigned char s, unsigned char t) +{ + unsigned D = 0x00ff; + unsigned S = ((unsigned)s << 8) | s; + unsigned T = ((unsigned)t << 8) | t; + unsigned stk1; + unsigned stk2; + unsigned stk3; + stk3 = ~D; + stk2 = T | stk3; + stk1 = S ^ stk2; + return (stk1 & (~S) & (~T)) | (D & S) | (D & T); +} + +/* STDSxox source/pattern opaque. */ +static void rop3_58_0_0 (unsigned char *D, unsigned char S, unsigned char T) +{ + unsigned char stk1; + unsigned char stk2; + unsigned char stk3; + stk3 = *D ^ S; + stk2 = T | stk3; + stk1 = S ^ stk2; + *D = stk1; +} + +/* STDSxox source opaque/pattern transparent. */ +static void rop3_58_0_1 (unsigned char *D, unsigned char S, unsigned char T) +{ + unsigned char stk1; + unsigned char stk2; + unsigned char stk3; + stk3 = *D ^ S; + stk2 = T | stk3; + stk1 = S ^ stk2; + *D = (stk1 & S) | (stk1 & (~T)) | (T & (~S) & *D); +} + +/* STDSxox source transparent/pattern opaque. */ +static void rop3_58_1_0 (unsigned char *D, unsigned char S, unsigned char T) +{ + unsigned char stk1; + unsigned char stk2; + unsigned char stk3; + stk3 = *D ^ S; + stk2 = T | stk3; + stk1 = S ^ stk2; + *D = (stk1 & (~S)) | (*D & S); +} + +/* STDSxox source/pattern transparent. */ +static void rop3_58_1_1 (unsigned char *D, unsigned char S, unsigned char T) +{ + unsigned char stk1; + unsigned char stk2; + unsigned char stk3; + stk3 = *D ^ S; + stk2 = T | stk3; + stk1 = S ^ stk2; + *D = (stk1 & (~S) & (~T)) | (*D & S) | (*D & T); +} + +/* STDSxox source/pattern opaque. */ +static unsigned xrop3_58_0_0 (unsigned char s, unsigned char t) +{ + unsigned D = 0x00ff; + unsigned S = ((unsigned)s << 8) | s; + unsigned T = ((unsigned)t << 8) | t; + unsigned stk1; + unsigned stk2; + unsigned stk3; + stk3 = D ^ S; + stk2 = T | stk3; + stk1 = S ^ stk2; + return stk1; +} + +/* STDSxox source opaque/pattern transparent. */ +static unsigned xrop3_58_0_1 (unsigned char s, unsigned char t) +{ + unsigned D = 0x00ff; + unsigned S = ((unsigned)s << 8) | s; + unsigned T = ((unsigned)t << 8) | t; + unsigned stk1; + unsigned stk2; + unsigned stk3; + stk3 = D ^ S; + stk2 = T | stk3; + stk1 = S ^ stk2; + return (stk1 & S) | (stk1 & (~T)) | (T & (~S) & D); +} + +/* STDSxox source transparent/pattern opaque. */ +static unsigned xrop3_58_1_0 (unsigned char s, unsigned char t) +{ + unsigned D = 0x00ff; + unsigned S = ((unsigned)s << 8) | s; + unsigned T = ((unsigned)t << 8) | t; + unsigned stk1; + unsigned stk2; + unsigned stk3; + stk3 = D ^ S; + stk2 = T | stk3; + stk1 = S ^ stk2; + return (stk1 & (~S)) | (D & S); +} + +/* STDSxox source/pattern transparent. */ +static unsigned xrop3_58_1_1 (unsigned char s, unsigned char t) +{ + unsigned D = 0x00ff; + unsigned S = ((unsigned)s << 8) | s; + unsigned T = ((unsigned)t << 8) | t; + unsigned stk1; + unsigned stk2; + unsigned stk3; + stk3 = D ^ S; + stk2 = T | stk3; + stk1 = S ^ stk2; + return (stk1 & (~S) & (~T)) | (D & S) | (D & T); +} + +/* STDnoan source/pattern opaque. */ +static void rop3_59_0_0 (unsigned char *D, unsigned char S, unsigned char T) +{ + unsigned char stk1; + unsigned char stk2; + unsigned char stk3; + stk3 = ~*D; + stk2 = T | stk3; + stk1 = S & stk2; + stk1 = ~stk1; + *D = stk1; +} + +/* STDnoan source opaque/pattern transparent. */ +static void rop3_59_0_1 (unsigned char *D, unsigned char S, unsigned char T) +{ + unsigned char stk1; + unsigned char stk2; + unsigned char stk3; + stk3 = ~*D; + stk2 = T | stk3; + stk1 = S & stk2; + stk1 = ~stk1; + *D = (stk1 & S) | (stk1 & (~T)) | (T & (~S) & *D); +} + +/* STDnoan source transparent/pattern opaque. */ +static void rop3_59_1_0 (unsigned char *D, unsigned char S, unsigned char T) +{ + unsigned char stk1; + unsigned char stk2; + unsigned char stk3; + stk3 = ~*D; + stk2 = T | stk3; + stk1 = S & stk2; + stk1 = ~stk1; + *D = (stk1 & (~S)) | (*D & S); +} + +/* STDnoan source/pattern transparent. */ +static void rop3_59_1_1 (unsigned char *D, unsigned char S, unsigned char T) +{ + unsigned char stk1; + unsigned char stk2; + unsigned char stk3; + stk3 = ~*D; + stk2 = T | stk3; + stk1 = S & stk2; + stk1 = ~stk1; + *D = (stk1 & (~S) & (~T)) | (*D & S) | (*D & T); +} + +/* STDnoan source/pattern opaque. */ +static unsigned xrop3_59_0_0 (unsigned char s, unsigned char t) +{ + unsigned D = 0x00ff; + unsigned S = ((unsigned)s << 8) | s; + unsigned T = ((unsigned)t << 8) | t; + unsigned stk1; + unsigned stk2; + unsigned stk3; + stk3 = ~D; + stk2 = T | stk3; + stk1 = S & stk2; + stk1 = ~stk1; + return stk1; +} + +/* STDnoan source opaque/pattern transparent. */ +static unsigned xrop3_59_0_1 (unsigned char s, unsigned char t) +{ + unsigned D = 0x00ff; + unsigned S = ((unsigned)s << 8) | s; + unsigned T = ((unsigned)t << 8) | t; + unsigned stk1; + unsigned stk2; + unsigned stk3; + stk3 = ~D; + stk2 = T | stk3; + stk1 = S & stk2; + stk1 = ~stk1; + return (stk1 & S) | (stk1 & (~T)) | (T & (~S) & D); +} + +/* STDnoan source transparent/pattern opaque. */ +static unsigned xrop3_59_1_0 (unsigned char s, unsigned char t) +{ + unsigned D = 0x00ff; + unsigned S = ((unsigned)s << 8) | s; + unsigned T = ((unsigned)t << 8) | t; + unsigned stk1; + unsigned stk2; + unsigned stk3; + stk3 = ~D; + stk2 = T | stk3; + stk1 = S & stk2; + stk1 = ~stk1; + return (stk1 & (~S)) | (D & S); +} + +/* STDnoan source/pattern transparent. */ +static unsigned xrop3_59_1_1 (unsigned char s, unsigned char t) +{ + unsigned D = 0x00ff; + unsigned S = ((unsigned)s << 8) | s; + unsigned T = ((unsigned)t << 8) | t; + unsigned stk1; + unsigned stk2; + unsigned stk3; + stk3 = ~D; + stk2 = T | stk3; + stk1 = S & stk2; + stk1 = ~stk1; + return (stk1 & (~S) & (~T)) | (D & S) | (D & T); +} + +/* TSx source/pattern opaque. */ +static void rop3_60_0_0 (unsigned char *D, unsigned char S, unsigned char T) +{ + unsigned char stk1; + stk1 = T ^ S; + *D = stk1; +} + +/* TSx source opaque/pattern transparent. */ +static void rop3_60_0_1 (unsigned char *D, unsigned char S, unsigned char T) +{ + unsigned char stk1; + stk1 = T ^ S; + *D = (stk1 & S) | (stk1 & (~T)) | (T & (~S) & *D); +} + +/* TSx source transparent/pattern opaque. */ +static void rop3_60_1_0 (unsigned char *D, unsigned char S, unsigned char T) +{ + unsigned char stk1; + stk1 = T ^ S; + *D = (stk1 & (~S)) | (*D & S); +} + +/* TSx source/pattern transparent. */ +static void rop3_60_1_1 (unsigned char *D, unsigned char S, unsigned char T) +{ + unsigned char stk1; + stk1 = T ^ S; + *D = (stk1 & (~S) & (~T)) | (*D & S) | (*D & T); +} + +/* TSx source/pattern opaque. */ +static unsigned xrop3_60_0_0 (unsigned char s, unsigned char t) +{ + unsigned S = ((unsigned)s << 8) | s; + unsigned T = ((unsigned)t << 8) | t; + unsigned stk1; + stk1 = T ^ S; + return stk1; +} + +/* TSx source opaque/pattern transparent. */ +static unsigned xrop3_60_0_1 (unsigned char s, unsigned char t) +{ + unsigned D = 0x00ff; + unsigned S = ((unsigned)s << 8) | s; + unsigned T = ((unsigned)t << 8) | t; + unsigned stk1; + stk1 = T ^ S; + return (stk1 & S) | (stk1 & (~T)) | (T & (~S) & D); +} + +/* TSx source transparent/pattern opaque. */ +static unsigned xrop3_60_1_0 (unsigned char s, unsigned char t) +{ + unsigned D = 0x00ff; + unsigned S = ((unsigned)s << 8) | s; + unsigned T = ((unsigned)t << 8) | t; + unsigned stk1; + stk1 = T ^ S; + return (stk1 & (~S)) | (D & S); +} + +/* TSx source/pattern transparent. */ +static unsigned xrop3_60_1_1 (unsigned char s, unsigned char t) +{ + unsigned D = 0x00ff; + unsigned S = ((unsigned)s << 8) | s; + unsigned T = ((unsigned)t << 8) | t; + unsigned stk1; + stk1 = T ^ S; + return (stk1 & (~S) & (~T)) | (D & S) | (D & T); +} + +/* STDSonox source/pattern opaque. */ +static void rop3_61_0_0 (unsigned char *D, unsigned char S, unsigned char T) +{ + unsigned char stk1; + unsigned char stk2; + unsigned char stk3; + stk3 = *D | S; + stk3 = ~stk3; + stk2 = T | stk3; + stk1 = S ^ stk2; + *D = stk1; +} + +/* STDSonox source opaque/pattern transparent. */ +static void rop3_61_0_1 (unsigned char *D, unsigned char S, unsigned char T) +{ + unsigned char stk1; + unsigned char stk2; + unsigned char stk3; + stk3 = *D | S; + stk3 = ~stk3; + stk2 = T | stk3; + stk1 = S ^ stk2; + *D = (stk1 & S) | (stk1 & (~T)) | (T & (~S) & *D); +} + +/* STDSonox source transparent/pattern opaque. */ +static void rop3_61_1_0 (unsigned char *D, unsigned char S, unsigned char T) +{ + unsigned char stk1; + unsigned char stk2; + unsigned char stk3; + stk3 = *D | S; + stk3 = ~stk3; + stk2 = T | stk3; + stk1 = S ^ stk2; + *D = (stk1 & (~S)) | (*D & S); +} + +/* STDSonox source/pattern transparent. */ +static void rop3_61_1_1 (unsigned char *D, unsigned char S, unsigned char T) +{ + unsigned char stk1; + unsigned char stk2; + unsigned char stk3; + stk3 = *D | S; + stk3 = ~stk3; + stk2 = T | stk3; + stk1 = S ^ stk2; + *D = (stk1 & (~S) & (~T)) | (*D & S) | (*D & T); +} + +/* STDSonox source/pattern opaque. */ +static unsigned xrop3_61_0_0 (unsigned char s, unsigned char t) +{ + unsigned D = 0x00ff; + unsigned S = ((unsigned)s << 8) | s; + unsigned T = ((unsigned)t << 8) | t; + unsigned stk1; + unsigned stk2; + unsigned stk3; + stk3 = D | S; + stk3 = ~stk3; + stk2 = T | stk3; + stk1 = S ^ stk2; + return stk1; +} + +/* STDSonox source opaque/pattern transparent. */ +static unsigned xrop3_61_0_1 (unsigned char s, unsigned char t) +{ + unsigned D = 0x00ff; + unsigned S = ((unsigned)s << 8) | s; + unsigned T = ((unsigned)t << 8) | t; + unsigned stk1; + unsigned stk2; + unsigned stk3; + stk3 = D | S; + stk3 = ~stk3; + stk2 = T | stk3; + stk1 = S ^ stk2; + return (stk1 & S) | (stk1 & (~T)) | (T & (~S) & D); +} + +/* STDSonox source transparent/pattern opaque. */ +static unsigned xrop3_61_1_0 (unsigned char s, unsigned char t) +{ + unsigned D = 0x00ff; + unsigned S = ((unsigned)s << 8) | s; + unsigned T = ((unsigned)t << 8) | t; + unsigned stk1; + unsigned stk2; + unsigned stk3; + stk3 = D | S; + stk3 = ~stk3; + stk2 = T | stk3; + stk1 = S ^ stk2; + return (stk1 & (~S)) | (D & S); +} + +/* STDSonox source/pattern transparent. */ +static unsigned xrop3_61_1_1 (unsigned char s, unsigned char t) +{ + unsigned D = 0x00ff; + unsigned S = ((unsigned)s << 8) | s; + unsigned T = ((unsigned)t << 8) | t; + unsigned stk1; + unsigned stk2; + unsigned stk3; + stk3 = D | S; + stk3 = ~stk3; + stk2 = T | stk3; + stk1 = S ^ stk2; + return (stk1 & (~S) & (~T)) | (D & S) | (D & T); +} + +/* STDSnaox source/pattern opaque. */ +static void rop3_62_0_0 (unsigned char *D, unsigned char S, unsigned char T) +{ + unsigned char stk1; + unsigned char stk2; + unsigned char stk3; + unsigned char stk4; + stk4 = ~S; + stk3 = *D & stk4; + stk2 = T | stk3; + stk1 = S ^ stk2; + *D = stk1; +} + +/* STDSnaox source opaque/pattern transparent. */ +static void rop3_62_0_1 (unsigned char *D, unsigned char S, unsigned char T) +{ + unsigned char stk1; + unsigned char stk2; + unsigned char stk3; + unsigned char stk4; + stk4 = ~S; + stk3 = *D & stk4; + stk2 = T | stk3; + stk1 = S ^ stk2; + *D = (stk1 & S) | (stk1 & (~T)) | (T & (~S) & *D); +} + +/* STDSnaox source transparent/pattern opaque. */ +static void rop3_62_1_0 (unsigned char *D, unsigned char S, unsigned char T) +{ + unsigned char stk1; + unsigned char stk2; + unsigned char stk3; + unsigned char stk4; + stk4 = ~S; + stk3 = *D & stk4; + stk2 = T | stk3; + stk1 = S ^ stk2; + *D = (stk1 & (~S)) | (*D & S); +} + +/* STDSnaox source/pattern transparent. */ +static void rop3_62_1_1 (unsigned char *D, unsigned char S, unsigned char T) +{ + unsigned char stk1; + unsigned char stk2; + unsigned char stk3; + unsigned char stk4; + stk4 = ~S; + stk3 = *D & stk4; + stk2 = T | stk3; + stk1 = S ^ stk2; + *D = (stk1 & (~S) & (~T)) | (*D & S) | (*D & T); +} + +/* STDSnaox source/pattern opaque. */ +static unsigned xrop3_62_0_0 (unsigned char s, unsigned char t) +{ + unsigned D = 0x00ff; + unsigned S = ((unsigned)s << 8) | s; + unsigned T = ((unsigned)t << 8) | t; + unsigned stk1; + unsigned stk2; + unsigned stk3; + unsigned stk4; + stk4 = ~S; + stk3 = D & stk4; + stk2 = T | stk3; + stk1 = S ^ stk2; + return stk1; +} + +/* STDSnaox source opaque/pattern transparent. */ +static unsigned xrop3_62_0_1 (unsigned char s, unsigned char t) +{ + unsigned D = 0x00ff; + unsigned S = ((unsigned)s << 8) | s; + unsigned T = ((unsigned)t << 8) | t; + unsigned stk1; + unsigned stk2; + unsigned stk3; + unsigned stk4; + stk4 = ~S; + stk3 = D & stk4; + stk2 = T | stk3; + stk1 = S ^ stk2; + return (stk1 & S) | (stk1 & (~T)) | (T & (~S) & D); +} + +/* STDSnaox source transparent/pattern opaque. */ +static unsigned xrop3_62_1_0 (unsigned char s, unsigned char t) +{ + unsigned D = 0x00ff; + unsigned S = ((unsigned)s << 8) | s; + unsigned T = ((unsigned)t << 8) | t; + unsigned stk1; + unsigned stk2; + unsigned stk3; + unsigned stk4; + stk4 = ~S; + stk3 = D & stk4; + stk2 = T | stk3; + stk1 = S ^ stk2; + return (stk1 & (~S)) | (D & S); +} + +/* STDSnaox source/pattern transparent. */ +static unsigned xrop3_62_1_1 (unsigned char s, unsigned char t) +{ + unsigned D = 0x00ff; + unsigned S = ((unsigned)s << 8) | s; + unsigned T = ((unsigned)t << 8) | t; + unsigned stk1; + unsigned stk2; + unsigned stk3; + unsigned stk4; + stk4 = ~S; + stk3 = D & stk4; + stk2 = T | stk3; + stk1 = S ^ stk2; + return (stk1 & (~S) & (~T)) | (D & S) | (D & T); +} + +/* TSan source/pattern opaque. */ +static void rop3_63_0_0 (unsigned char *D, unsigned char S, unsigned char T) +{ + unsigned char stk1; + stk1 = T & S; + stk1 = ~stk1; + *D = stk1; +} + +/* TSan source opaque/pattern transparent. */ +static void rop3_63_0_1 (unsigned char *D, unsigned char S, unsigned char T) +{ + unsigned char stk1; + stk1 = T & S; + stk1 = ~stk1; + *D = (stk1 & S) | (stk1 & (~T)) | (T & (~S) & *D); +} + +/* TSan source transparent/pattern opaque. */ +static void rop3_63_1_0 (unsigned char *D, unsigned char S, unsigned char T) +{ + unsigned char stk1; + stk1 = T & S; + stk1 = ~stk1; + *D = (stk1 & (~S)) | (*D & S); +} + +/* TSan source/pattern transparent. */ +static void rop3_63_1_1 (unsigned char *D, unsigned char S, unsigned char T) +{ + unsigned char stk1; + stk1 = T & S; + stk1 = ~stk1; + *D = (stk1 & (~S) & (~T)) | (*D & S) | (*D & T); +} + +/* TSan source/pattern opaque. */ +static unsigned xrop3_63_0_0 (unsigned char s, unsigned char t) +{ + unsigned S = ((unsigned)s << 8) | s; + unsigned T = ((unsigned)t << 8) | t; + unsigned stk1; + stk1 = T & S; + stk1 = ~stk1; + return stk1; +} + +/* TSan source opaque/pattern transparent. */ +static unsigned xrop3_63_0_1 (unsigned char s, unsigned char t) +{ + unsigned D = 0x00ff; + unsigned S = ((unsigned)s << 8) | s; + unsigned T = ((unsigned)t << 8) | t; + unsigned stk1; + stk1 = T & S; + stk1 = ~stk1; + return (stk1 & S) | (stk1 & (~T)) | (T & (~S) & D); +} + +/* TSan source transparent/pattern opaque. */ +static unsigned xrop3_63_1_0 (unsigned char s, unsigned char t) +{ + unsigned D = 0x00ff; + unsigned S = ((unsigned)s << 8) | s; + unsigned T = ((unsigned)t << 8) | t; + unsigned stk1; + stk1 = T & S; + stk1 = ~stk1; + return (stk1 & (~S)) | (D & S); +} + +/* TSan source/pattern transparent. */ +static unsigned xrop3_63_1_1 (unsigned char s, unsigned char t) +{ + unsigned D = 0x00ff; + unsigned S = ((unsigned)s << 8) | s; + unsigned T = ((unsigned)t << 8) | t; + unsigned stk1; + stk1 = T & S; + stk1 = ~stk1; + return (stk1 & (~S) & (~T)) | (D & S) | (D & T); +} + +/* TSDnaa source/pattern opaque. */ +static void rop3_64_0_0 (unsigned char *D, unsigned char S, unsigned char T) +{ + unsigned char stk1; + unsigned char stk2; + unsigned char stk3; + stk3 = ~*D; + stk2 = S & stk3; + stk1 = T & stk2; + *D = stk1; +} + +/* TSDnaa source opaque/pattern transparent. */ +static void rop3_64_0_1 (unsigned char *D, unsigned char S, unsigned char T) +{ + unsigned char stk1; + unsigned char stk2; + unsigned char stk3; + stk3 = ~*D; + stk2 = S & stk3; + stk1 = T & stk2; + *D = (stk1 & S) | (stk1 & (~T)) | (T & (~S) & *D); +} + +/* TSDnaa source transparent/pattern opaque. */ +static void rop3_64_1_0 (unsigned char *D, unsigned char S, unsigned char T) +{ + unsigned char stk1; + unsigned char stk2; + unsigned char stk3; + stk3 = ~*D; + stk2 = S & stk3; + stk1 = T & stk2; + *D = (stk1 & (~S)) | (*D & S); +} + +/* TSDnaa source/pattern transparent. */ +static void rop3_64_1_1 (unsigned char *D, unsigned char S, unsigned char T) +{ + unsigned char stk1; + unsigned char stk2; + unsigned char stk3; + stk3 = ~*D; + stk2 = S & stk3; + stk1 = T & stk2; + *D = (stk1 & (~S) & (~T)) | (*D & S) | (*D & T); +} + +/* TSDnaa source/pattern opaque. */ +static unsigned xrop3_64_0_0 (unsigned char s, unsigned char t) +{ + unsigned D = 0x00ff; + unsigned S = ((unsigned)s << 8) | s; + unsigned T = ((unsigned)t << 8) | t; + unsigned stk1; + unsigned stk2; + unsigned stk3; + stk3 = ~D; + stk2 = S & stk3; + stk1 = T & stk2; + return stk1; +} + +/* TSDnaa source opaque/pattern transparent. */ +static unsigned xrop3_64_0_1 (unsigned char s, unsigned char t) +{ + unsigned D = 0x00ff; + unsigned S = ((unsigned)s << 8) | s; + unsigned T = ((unsigned)t << 8) | t; + unsigned stk1; + unsigned stk2; + unsigned stk3; + stk3 = ~D; + stk2 = S & stk3; + stk1 = T & stk2; + return (stk1 & S) | (stk1 & (~T)) | (T & (~S) & D); +} + +/* TSDnaa source transparent/pattern opaque. */ +static unsigned xrop3_64_1_0 (unsigned char s, unsigned char t) +{ + unsigned D = 0x00ff; + unsigned S = ((unsigned)s << 8) | s; + unsigned T = ((unsigned)t << 8) | t; + unsigned stk1; + unsigned stk2; + unsigned stk3; + stk3 = ~D; + stk2 = S & stk3; + stk1 = T & stk2; + return (stk1 & (~S)) | (D & S); +} + +/* TSDnaa source/pattern transparent. */ +static unsigned xrop3_64_1_1 (unsigned char s, unsigned char t) +{ + unsigned D = 0x00ff; + unsigned S = ((unsigned)s << 8) | s; + unsigned T = ((unsigned)t << 8) | t; + unsigned stk1; + unsigned stk2; + unsigned stk3; + stk3 = ~D; + stk2 = S & stk3; + stk1 = T & stk2; + return (stk1 & (~S) & (~T)) | (D & S) | (D & T); +} + +/* DTSxon source/pattern opaque. */ +static void rop3_65_0_0 (unsigned char *D, unsigned char S, unsigned char T) +{ + unsigned char stk1; + unsigned char stk2; + stk2 = T ^ S; + stk1 = *D | stk2; + stk1 = ~stk1; + *D = stk1; +} + +/* DTSxon source opaque/pattern transparent. */ +static void rop3_65_0_1 (unsigned char *D, unsigned char S, unsigned char T) +{ + unsigned char stk1; + unsigned char stk2; + stk2 = T ^ S; + stk1 = *D | stk2; + stk1 = ~stk1; + *D = (stk1 & S) | (stk1 & (~T)) | (T & (~S) & *D); +} + +/* DTSxon source transparent/pattern opaque. */ +static void rop3_65_1_0 (unsigned char *D, unsigned char S, unsigned char T) +{ + unsigned char stk1; + unsigned char stk2; + stk2 = T ^ S; + stk1 = *D | stk2; + stk1 = ~stk1; + *D = (stk1 & (~S)) | (*D & S); +} + +/* DTSxon source/pattern transparent. */ +static void rop3_65_1_1 (unsigned char *D, unsigned char S, unsigned char T) +{ + unsigned char stk1; + unsigned char stk2; + stk2 = T ^ S; + stk1 = *D | stk2; + stk1 = ~stk1; + *D = (stk1 & (~S) & (~T)) | (*D & S) | (*D & T); +} + +/* DTSxon source/pattern opaque. */ +static unsigned xrop3_65_0_0 (unsigned char s, unsigned char t) +{ + unsigned D = 0x00ff; + unsigned S = ((unsigned)s << 8) | s; + unsigned T = ((unsigned)t << 8) | t; + unsigned stk1; + unsigned stk2; + stk2 = T ^ S; + stk1 = D | stk2; + stk1 = ~stk1; + return stk1; +} + +/* DTSxon source opaque/pattern transparent. */ +static unsigned xrop3_65_0_1 (unsigned char s, unsigned char t) +{ + unsigned D = 0x00ff; + unsigned S = ((unsigned)s << 8) | s; + unsigned T = ((unsigned)t << 8) | t; + unsigned stk1; + unsigned stk2; + stk2 = T ^ S; + stk1 = D | stk2; + stk1 = ~stk1; + return (stk1 & S) | (stk1 & (~T)) | (T & (~S) & D); +} + +/* DTSxon source transparent/pattern opaque. */ +static unsigned xrop3_65_1_0 (unsigned char s, unsigned char t) +{ + unsigned D = 0x00ff; + unsigned S = ((unsigned)s << 8) | s; + unsigned T = ((unsigned)t << 8) | t; + unsigned stk1; + unsigned stk2; + stk2 = T ^ S; + stk1 = D | stk2; + stk1 = ~stk1; + return (stk1 & (~S)) | (D & S); +} + +/* DTSxon source/pattern transparent. */ +static unsigned xrop3_65_1_1 (unsigned char s, unsigned char t) +{ + unsigned D = 0x00ff; + unsigned S = ((unsigned)s << 8) | s; + unsigned T = ((unsigned)t << 8) | t; + unsigned stk1; + unsigned stk2; + stk2 = T ^ S; + stk1 = D | stk2; + stk1 = ~stk1; + return (stk1 & (~S) & (~T)) | (D & S) | (D & T); +} + +/* SDxTDxa source/pattern opaque. */ +static void rop3_66_0_0 (unsigned char *D, unsigned char S, unsigned char T) +{ + unsigned char stk1; + unsigned char stk2; + stk1 = S ^ *D; + stk2 = T ^ *D; + stk1 = stk1 & stk2; + *D = stk1; +} + +/* SDxTDxa source opaque/pattern transparent. */ +static void rop3_66_0_1 (unsigned char *D, unsigned char S, unsigned char T) +{ + unsigned char stk1; + unsigned char stk2; + stk1 = S ^ *D; + stk2 = T ^ *D; + stk1 = stk1 & stk2; + *D = (stk1 & S) | (stk1 & (~T)) | (T & (~S) & *D); +} + +/* SDxTDxa source transparent/pattern opaque. */ +static void rop3_66_1_0 (unsigned char *D, unsigned char S, unsigned char T) +{ + unsigned char stk1; + unsigned char stk2; + stk1 = S ^ *D; + stk2 = T ^ *D; + stk1 = stk1 & stk2; + *D = (stk1 & (~S)) | (*D & S); +} + +/* SDxTDxa source/pattern transparent. */ +static void rop3_66_1_1 (unsigned char *D, unsigned char S, unsigned char T) +{ + unsigned char stk1; + unsigned char stk2; + stk1 = S ^ *D; + stk2 = T ^ *D; + stk1 = stk1 & stk2; + *D = (stk1 & (~S) & (~T)) | (*D & S) | (*D & T); +} + +/* SDxTDxa source/pattern opaque. */ +static unsigned xrop3_66_0_0 (unsigned char s, unsigned char t) +{ + unsigned D = 0x00ff; + unsigned S = ((unsigned)s << 8) | s; + unsigned T = ((unsigned)t << 8) | t; + unsigned stk1; + unsigned stk2; + stk1 = S ^ D; + stk2 = T ^ D; + stk1 = stk1 & stk2; + return stk1; +} + +/* SDxTDxa source opaque/pattern transparent. */ +static unsigned xrop3_66_0_1 (unsigned char s, unsigned char t) +{ + unsigned D = 0x00ff; + unsigned S = ((unsigned)s << 8) | s; + unsigned T = ((unsigned)t << 8) | t; + unsigned stk1; + unsigned stk2; + stk1 = S ^ D; + stk2 = T ^ D; + stk1 = stk1 & stk2; + return (stk1 & S) | (stk1 & (~T)) | (T & (~S) & D); +} + +/* SDxTDxa source transparent/pattern opaque. */ +static unsigned xrop3_66_1_0 (unsigned char s, unsigned char t) +{ + unsigned D = 0x00ff; + unsigned S = ((unsigned)s << 8) | s; + unsigned T = ((unsigned)t << 8) | t; + unsigned stk1; + unsigned stk2; + stk1 = S ^ D; + stk2 = T ^ D; + stk1 = stk1 & stk2; + return (stk1 & (~S)) | (D & S); +} + +/* SDxTDxa source/pattern transparent. */ +static unsigned xrop3_66_1_1 (unsigned char s, unsigned char t) +{ + unsigned D = 0x00ff; + unsigned S = ((unsigned)s << 8) | s; + unsigned T = ((unsigned)t << 8) | t; + unsigned stk1; + unsigned stk2; + stk1 = S ^ D; + stk2 = T ^ D; + stk1 = stk1 & stk2; + return (stk1 & (~S) & (~T)) | (D & S) | (D & T); +} + +/* STDSanaxn source/pattern opaque. */ +static void rop3_67_0_0 (unsigned char *D, unsigned char S, unsigned char T) +{ + unsigned char stk1; + unsigned char stk2; + unsigned char stk3; + stk3 = *D & S; + stk3 = ~stk3; + stk2 = T & stk3; + stk1 = S ^ stk2; + stk1 = ~stk1; + *D = stk1; +} + +/* STDSanaxn source opaque/pattern transparent. */ +static void rop3_67_0_1 (unsigned char *D, unsigned char S, unsigned char T) +{ + unsigned char stk1; + unsigned char stk2; + unsigned char stk3; + stk3 = *D & S; + stk3 = ~stk3; + stk2 = T & stk3; + stk1 = S ^ stk2; + stk1 = ~stk1; + *D = (stk1 & S) | (stk1 & (~T)) | (T & (~S) & *D); +} + +/* STDSanaxn source transparent/pattern opaque. */ +static void rop3_67_1_0 (unsigned char *D, unsigned char S, unsigned char T) +{ + unsigned char stk1; + unsigned char stk2; + unsigned char stk3; + stk3 = *D & S; + stk3 = ~stk3; + stk2 = T & stk3; + stk1 = S ^ stk2; + stk1 = ~stk1; + *D = (stk1 & (~S)) | (*D & S); +} + +/* STDSanaxn source/pattern transparent. */ +static void rop3_67_1_1 (unsigned char *D, unsigned char S, unsigned char T) +{ + unsigned char stk1; + unsigned char stk2; + unsigned char stk3; + stk3 = *D & S; + stk3 = ~stk3; + stk2 = T & stk3; + stk1 = S ^ stk2; + stk1 = ~stk1; + *D = (stk1 & (~S) & (~T)) | (*D & S) | (*D & T); +} + +/* STDSanaxn source/pattern opaque. */ +static unsigned xrop3_67_0_0 (unsigned char s, unsigned char t) +{ + unsigned D = 0x00ff; + unsigned S = ((unsigned)s << 8) | s; + unsigned T = ((unsigned)t << 8) | t; + unsigned stk1; + unsigned stk2; + unsigned stk3; + stk3 = D & S; + stk3 = ~stk3; + stk2 = T & stk3; + stk1 = S ^ stk2; + stk1 = ~stk1; + return stk1; +} + +/* STDSanaxn source opaque/pattern transparent. */ +static unsigned xrop3_67_0_1 (unsigned char s, unsigned char t) +{ + unsigned D = 0x00ff; + unsigned S = ((unsigned)s << 8) | s; + unsigned T = ((unsigned)t << 8) | t; + unsigned stk1; + unsigned stk2; + unsigned stk3; + stk3 = D & S; + stk3 = ~stk3; + stk2 = T & stk3; + stk1 = S ^ stk2; + stk1 = ~stk1; + return (stk1 & S) | (stk1 & (~T)) | (T & (~S) & D); +} + +/* STDSanaxn source transparent/pattern opaque. */ +static unsigned xrop3_67_1_0 (unsigned char s, unsigned char t) +{ + unsigned D = 0x00ff; + unsigned S = ((unsigned)s << 8) | s; + unsigned T = ((unsigned)t << 8) | t; + unsigned stk1; + unsigned stk2; + unsigned stk3; + stk3 = D & S; + stk3 = ~stk3; + stk2 = T & stk3; + stk1 = S ^ stk2; + stk1 = ~stk1; + return (stk1 & (~S)) | (D & S); +} + +/* STDSanaxn source/pattern transparent. */ +static unsigned xrop3_67_1_1 (unsigned char s, unsigned char t) +{ + unsigned D = 0x00ff; + unsigned S = ((unsigned)s << 8) | s; + unsigned T = ((unsigned)t << 8) | t; + unsigned stk1; + unsigned stk2; + unsigned stk3; + stk3 = D & S; + stk3 = ~stk3; + stk2 = T & stk3; + stk1 = S ^ stk2; + stk1 = ~stk1; + return (stk1 & (~S) & (~T)) | (D & S) | (D & T); +} + +/* SDna source/pattern opaque. */ +static void rop3_68_0_0 (unsigned char *D, unsigned char S, unsigned char T) +{ + unsigned char stk1; + unsigned char stk2; + stk2 = ~*D; + stk1 = S & stk2; + *D = stk1; +} + +/* SDna source opaque/pattern transparent. */ +static void rop3_68_0_1 (unsigned char *D, unsigned char S, unsigned char T) +{ + unsigned char stk1; + unsigned char stk2; + stk2 = ~*D; + stk1 = S & stk2; + *D = (stk1 & S) | (stk1 & (~T)) | (T & (~S) & *D); +} + +/* SDna source transparent/pattern opaque. */ +static void rop3_68_1_0 (unsigned char *D, unsigned char S, unsigned char T) +{ + unsigned char stk1; + unsigned char stk2; + stk2 = ~*D; + stk1 = S & stk2; + *D = (stk1 & (~S)) | (*D & S); +} + +/* SDna source/pattern transparent. */ +static void rop3_68_1_1 (unsigned char *D, unsigned char S, unsigned char T) +{ + unsigned char stk1; + unsigned char stk2; + stk2 = ~*D; + stk1 = S & stk2; + *D = (stk1 & (~S) & (~T)) | (*D & S) | (*D & T); +} + +/* SDna source/pattern opaque. */ +static unsigned xrop3_68_0_0 (unsigned char s, unsigned char t) +{ + unsigned D = 0x00ff; + unsigned S = ((unsigned)s << 8) | s; + unsigned stk1; + unsigned stk2; + stk2 = ~D; + stk1 = S & stk2; + return stk1; +} + +/* SDna source opaque/pattern transparent. */ +static unsigned xrop3_68_0_1 (unsigned char s, unsigned char t) +{ + unsigned D = 0x00ff; + unsigned S = ((unsigned)s << 8) | s; + unsigned T = ((unsigned)t << 8) | t; + unsigned stk1; + unsigned stk2; + stk2 = ~D; + stk1 = S & stk2; + return (stk1 & S) | (stk1 & (~T)) | (T & (~S) & D); +} + +/* SDna source transparent/pattern opaque. */ +static unsigned xrop3_68_1_0 (unsigned char s, unsigned char t) +{ + unsigned D = 0x00ff; + unsigned S = ((unsigned)s << 8) | s; + unsigned stk1; + unsigned stk2; + stk2 = ~D; + stk1 = S & stk2; + return (stk1 & (~S)) | (D & S); +} + +/* SDna source/pattern transparent. */ +static unsigned xrop3_68_1_1 (unsigned char s, unsigned char t) +{ + unsigned D = 0x00ff; + unsigned S = ((unsigned)s << 8) | s; + unsigned T = ((unsigned)t << 8) | t; + unsigned stk1; + unsigned stk2; + stk2 = ~D; + stk1 = S & stk2; + return (stk1 & (~S) & (~T)) | (D & S) | (D & T); +} + +/* DTSnaon source/pattern opaque. */ +static void rop3_69_0_0 (unsigned char *D, unsigned char S, unsigned char T) +{ + unsigned char stk1; + unsigned char stk2; + unsigned char stk3; + stk3 = ~S; + stk2 = T & stk3; + stk1 = *D | stk2; + stk1 = ~stk1; + *D = stk1; +} + +/* DTSnaon source opaque/pattern transparent. */ +static void rop3_69_0_1 (unsigned char *D, unsigned char S, unsigned char T) +{ + unsigned char stk1; + unsigned char stk2; + unsigned char stk3; + stk3 = ~S; + stk2 = T & stk3; + stk1 = *D | stk2; + stk1 = ~stk1; + *D = (stk1 & S) | (stk1 & (~T)) | (T & (~S) & *D); +} + +/* DTSnaon source transparent/pattern opaque. */ +static void rop3_69_1_0 (unsigned char *D, unsigned char S, unsigned char T) +{ + unsigned char stk1; + unsigned char stk2; + unsigned char stk3; + stk3 = ~S; + stk2 = T & stk3; + stk1 = *D | stk2; + stk1 = ~stk1; + *D = (stk1 & (~S)) | (*D & S); +} + +/* DTSnaon source/pattern transparent. */ +static void rop3_69_1_1 (unsigned char *D, unsigned char S, unsigned char T) +{ + unsigned char stk1; + unsigned char stk2; + unsigned char stk3; + stk3 = ~S; + stk2 = T & stk3; + stk1 = *D | stk2; + stk1 = ~stk1; + *D = (stk1 & (~S) & (~T)) | (*D & S) | (*D & T); +} + +/* DTSnaon source/pattern opaque. */ +static unsigned xrop3_69_0_0 (unsigned char s, unsigned char t) +{ + unsigned D = 0x00ff; + unsigned S = ((unsigned)s << 8) | s; + unsigned T = ((unsigned)t << 8) | t; + unsigned stk1; + unsigned stk2; + unsigned stk3; + stk3 = ~S; + stk2 = T & stk3; + stk1 = D | stk2; + stk1 = ~stk1; + return stk1; +} + +/* DTSnaon source opaque/pattern transparent. */ +static unsigned xrop3_69_0_1 (unsigned char s, unsigned char t) +{ + unsigned D = 0x00ff; + unsigned S = ((unsigned)s << 8) | s; + unsigned T = ((unsigned)t << 8) | t; + unsigned stk1; + unsigned stk2; + unsigned stk3; + stk3 = ~S; + stk2 = T & stk3; + stk1 = D | stk2; + stk1 = ~stk1; + return (stk1 & S) | (stk1 & (~T)) | (T & (~S) & D); +} + +/* DTSnaon source transparent/pattern opaque. */ +static unsigned xrop3_69_1_0 (unsigned char s, unsigned char t) +{ + unsigned D = 0x00ff; + unsigned S = ((unsigned)s << 8) | s; + unsigned T = ((unsigned)t << 8) | t; + unsigned stk1; + unsigned stk2; + unsigned stk3; + stk3 = ~S; + stk2 = T & stk3; + stk1 = D | stk2; + stk1 = ~stk1; + return (stk1 & (~S)) | (D & S); +} + +/* DTSnaon source/pattern transparent. */ +static unsigned xrop3_69_1_1 (unsigned char s, unsigned char t) +{ + unsigned D = 0x00ff; + unsigned S = ((unsigned)s << 8) | s; + unsigned T = ((unsigned)t << 8) | t; + unsigned stk1; + unsigned stk2; + unsigned stk3; + stk3 = ~S; + stk2 = T & stk3; + stk1 = D | stk2; + stk1 = ~stk1; + return (stk1 & (~S) & (~T)) | (D & S) | (D & T); +} + +/* DSTDaox source/pattern opaque. */ +static void rop3_70_0_0 (unsigned char *D, unsigned char S, unsigned char T) +{ + unsigned char stk1; + unsigned char stk2; + unsigned char stk3; + stk3 = T & *D; + stk2 = S | stk3; + stk1 = *D ^ stk2; + *D = stk1; +} + +/* DSTDaox source opaque/pattern transparent. */ +static void rop3_70_0_1 (unsigned char *D, unsigned char S, unsigned char T) +{ + unsigned char stk1; + unsigned char stk2; + unsigned char stk3; + stk3 = T & *D; + stk2 = S | stk3; + stk1 = *D ^ stk2; + *D = (stk1 & S) | (stk1 & (~T)) | (T & (~S) & *D); +} + +/* DSTDaox source transparent/pattern opaque. */ +static void rop3_70_1_0 (unsigned char *D, unsigned char S, unsigned char T) +{ + unsigned char stk1; + unsigned char stk2; + unsigned char stk3; + stk3 = T & *D; + stk2 = S | stk3; + stk1 = *D ^ stk2; + *D = (stk1 & (~S)) | (*D & S); +} + +/* DSTDaox source/pattern transparent. */ +static void rop3_70_1_1 (unsigned char *D, unsigned char S, unsigned char T) +{ + unsigned char stk1; + unsigned char stk2; + unsigned char stk3; + stk3 = T & *D; + stk2 = S | stk3; + stk1 = *D ^ stk2; + *D = (stk1 & (~S) & (~T)) | (*D & S) | (*D & T); +} + +/* DSTDaox source/pattern opaque. */ +static unsigned xrop3_70_0_0 (unsigned char s, unsigned char t) +{ + unsigned D = 0x00ff; + unsigned S = ((unsigned)s << 8) | s; + unsigned T = ((unsigned)t << 8) | t; + unsigned stk1; + unsigned stk2; + unsigned stk3; + stk3 = T & D; + stk2 = S | stk3; + stk1 = D ^ stk2; + return stk1; +} + +/* DSTDaox source opaque/pattern transparent. */ +static unsigned xrop3_70_0_1 (unsigned char s, unsigned char t) +{ + unsigned D = 0x00ff; + unsigned S = ((unsigned)s << 8) | s; + unsigned T = ((unsigned)t << 8) | t; + unsigned stk1; + unsigned stk2; + unsigned stk3; + stk3 = T & D; + stk2 = S | stk3; + stk1 = D ^ stk2; + return (stk1 & S) | (stk1 & (~T)) | (T & (~S) & D); +} + +/* DSTDaox source transparent/pattern opaque. */ +static unsigned xrop3_70_1_0 (unsigned char s, unsigned char t) +{ + unsigned D = 0x00ff; + unsigned S = ((unsigned)s << 8) | s; + unsigned T = ((unsigned)t << 8) | t; + unsigned stk1; + unsigned stk2; + unsigned stk3; + stk3 = T & D; + stk2 = S | stk3; + stk1 = D ^ stk2; + return (stk1 & (~S)) | (D & S); +} + +/* DSTDaox source/pattern transparent. */ +static unsigned xrop3_70_1_1 (unsigned char s, unsigned char t) +{ + unsigned D = 0x00ff; + unsigned S = ((unsigned)s << 8) | s; + unsigned T = ((unsigned)t << 8) | t; + unsigned stk1; + unsigned stk2; + unsigned stk3; + stk3 = T & D; + stk2 = S | stk3; + stk1 = D ^ stk2; + return (stk1 & (~S) & (~T)) | (D & S) | (D & T); +} + +/* TSDTxaxn source/pattern opaque. */ +static void rop3_71_0_0 (unsigned char *D, unsigned char S, unsigned char T) +{ + unsigned char stk1; + unsigned char stk2; + unsigned char stk3; + stk3 = *D ^ T; + stk2 = S & stk3; + stk1 = T ^ stk2; + stk1 = ~stk1; + *D = stk1; +} + +/* TSDTxaxn source opaque/pattern transparent. */ +static void rop3_71_0_1 (unsigned char *D, unsigned char S, unsigned char T) +{ + unsigned char stk1; + unsigned char stk2; + unsigned char stk3; + stk3 = *D ^ T; + stk2 = S & stk3; + stk1 = T ^ stk2; + stk1 = ~stk1; + *D = (stk1 & S) | (stk1 & (~T)) | (T & (~S) & *D); +} + +/* TSDTxaxn source transparent/pattern opaque. */ +static void rop3_71_1_0 (unsigned char *D, unsigned char S, unsigned char T) +{ + unsigned char stk1; + unsigned char stk2; + unsigned char stk3; + stk3 = *D ^ T; + stk2 = S & stk3; + stk1 = T ^ stk2; + stk1 = ~stk1; + *D = (stk1 & (~S)) | (*D & S); +} + +/* TSDTxaxn source/pattern transparent. */ +static void rop3_71_1_1 (unsigned char *D, unsigned char S, unsigned char T) +{ + unsigned char stk1; + unsigned char stk2; + unsigned char stk3; + stk3 = *D ^ T; + stk2 = S & stk3; + stk1 = T ^ stk2; + stk1 = ~stk1; + *D = (stk1 & (~S) & (~T)) | (*D & S) | (*D & T); +} + +/* TSDTxaxn source/pattern opaque. */ +static unsigned xrop3_71_0_0 (unsigned char s, unsigned char t) +{ + unsigned D = 0x00ff; + unsigned S = ((unsigned)s << 8) | s; + unsigned T = ((unsigned)t << 8) | t; + unsigned stk1; + unsigned stk2; + unsigned stk3; + stk3 = D ^ T; + stk2 = S & stk3; + stk1 = T ^ stk2; + stk1 = ~stk1; + return stk1; +} + +/* TSDTxaxn source opaque/pattern transparent. */ +static unsigned xrop3_71_0_1 (unsigned char s, unsigned char t) +{ + unsigned D = 0x00ff; + unsigned S = ((unsigned)s << 8) | s; + unsigned T = ((unsigned)t << 8) | t; + unsigned stk1; + unsigned stk2; + unsigned stk3; + stk3 = D ^ T; + stk2 = S & stk3; + stk1 = T ^ stk2; + stk1 = ~stk1; + return (stk1 & S) | (stk1 & (~T)) | (T & (~S) & D); +} + +/* TSDTxaxn source transparent/pattern opaque. */ +static unsigned xrop3_71_1_0 (unsigned char s, unsigned char t) +{ + unsigned D = 0x00ff; + unsigned S = ((unsigned)s << 8) | s; + unsigned T = ((unsigned)t << 8) | t; + unsigned stk1; + unsigned stk2; + unsigned stk3; + stk3 = D ^ T; + stk2 = S & stk3; + stk1 = T ^ stk2; + stk1 = ~stk1; + return (stk1 & (~S)) | (D & S); +} + +/* TSDTxaxn source/pattern transparent. */ +static unsigned xrop3_71_1_1 (unsigned char s, unsigned char t) +{ + unsigned D = 0x00ff; + unsigned S = ((unsigned)s << 8) | s; + unsigned T = ((unsigned)t << 8) | t; + unsigned stk1; + unsigned stk2; + unsigned stk3; + stk3 = D ^ T; + stk2 = S & stk3; + stk1 = T ^ stk2; + stk1 = ~stk1; + return (stk1 & (~S) & (~T)) | (D & S) | (D & T); +} + +/* SDTxa source/pattern opaque. */ +static void rop3_72_0_0 (unsigned char *D, unsigned char S, unsigned char T) +{ + unsigned char stk1; + unsigned char stk2; + stk2 = *D ^ T; + stk1 = S & stk2; + *D = stk1; +} + +/* SDTxa source opaque/pattern transparent. */ +static void rop3_72_0_1 (unsigned char *D, unsigned char S, unsigned char T) +{ + unsigned char stk1; + unsigned char stk2; + stk2 = *D ^ T; + stk1 = S & stk2; + *D = (stk1 & S) | (stk1 & (~T)) | (T & (~S) & *D); +} + +/* SDTxa source transparent/pattern opaque. */ +static void rop3_72_1_0 (unsigned char *D, unsigned char S, unsigned char T) +{ + unsigned char stk1; + unsigned char stk2; + stk2 = *D ^ T; + stk1 = S & stk2; + *D = (stk1 & (~S)) | (*D & S); +} + +/* SDTxa source/pattern transparent. */ +static void rop3_72_1_1 (unsigned char *D, unsigned char S, unsigned char T) +{ + unsigned char stk1; + unsigned char stk2; + stk2 = *D ^ T; + stk1 = S & stk2; + *D = (stk1 & (~S) & (~T)) | (*D & S) | (*D & T); +} + +/* SDTxa source/pattern opaque. */ +static unsigned xrop3_72_0_0 (unsigned char s, unsigned char t) +{ + unsigned D = 0x00ff; + unsigned S = ((unsigned)s << 8) | s; + unsigned T = ((unsigned)t << 8) | t; + unsigned stk1; + unsigned stk2; + stk2 = D ^ T; + stk1 = S & stk2; + return stk1; +} + +/* SDTxa source opaque/pattern transparent. */ +static unsigned xrop3_72_0_1 (unsigned char s, unsigned char t) +{ + unsigned D = 0x00ff; + unsigned S = ((unsigned)s << 8) | s; + unsigned T = ((unsigned)t << 8) | t; + unsigned stk1; + unsigned stk2; + stk2 = D ^ T; + stk1 = S & stk2; + return (stk1 & S) | (stk1 & (~T)) | (T & (~S) & D); +} + +/* SDTxa source transparent/pattern opaque. */ +static unsigned xrop3_72_1_0 (unsigned char s, unsigned char t) +{ + unsigned D = 0x00ff; + unsigned S = ((unsigned)s << 8) | s; + unsigned T = ((unsigned)t << 8) | t; + unsigned stk1; + unsigned stk2; + stk2 = D ^ T; + stk1 = S & stk2; + return (stk1 & (~S)) | (D & S); +} + +/* SDTxa source/pattern transparent. */ +static unsigned xrop3_72_1_1 (unsigned char s, unsigned char t) +{ + unsigned D = 0x00ff; + unsigned S = ((unsigned)s << 8) | s; + unsigned T = ((unsigned)t << 8) | t; + unsigned stk1; + unsigned stk2; + stk2 = D ^ T; + stk1 = S & stk2; + return (stk1 & (~S) & (~T)) | (D & S) | (D & T); +} + +/* TDSTDaoxxn source/pattern opaque. */ +static void rop3_73_0_0 (unsigned char *D, unsigned char S, unsigned char T) +{ + unsigned char stk1; + unsigned char stk2; + unsigned char stk3; + unsigned char stk4; + stk4 = T & *D; + stk3 = S | stk4; + stk2 = *D ^ stk3; + stk1 = T ^ stk2; + stk1 = ~stk1; + *D = stk1; +} + +/* TDSTDaoxxn source opaque/pattern transparent. */ +static void rop3_73_0_1 (unsigned char *D, unsigned char S, unsigned char T) +{ + unsigned char stk1; + unsigned char stk2; + unsigned char stk3; + unsigned char stk4; + stk4 = T & *D; + stk3 = S | stk4; + stk2 = *D ^ stk3; + stk1 = T ^ stk2; + stk1 = ~stk1; + *D = (stk1 & S) | (stk1 & (~T)) | (T & (~S) & *D); +} + +/* TDSTDaoxxn source transparent/pattern opaque. */ +static void rop3_73_1_0 (unsigned char *D, unsigned char S, unsigned char T) +{ + unsigned char stk1; + unsigned char stk2; + unsigned char stk3; + unsigned char stk4; + stk4 = T & *D; + stk3 = S | stk4; + stk2 = *D ^ stk3; + stk1 = T ^ stk2; + stk1 = ~stk1; + *D = (stk1 & (~S)) | (*D & S); +} + +/* TDSTDaoxxn source/pattern transparent. */ +static void rop3_73_1_1 (unsigned char *D, unsigned char S, unsigned char T) +{ + unsigned char stk1; + unsigned char stk2; + unsigned char stk3; + unsigned char stk4; + stk4 = T & *D; + stk3 = S | stk4; + stk2 = *D ^ stk3; + stk1 = T ^ stk2; + stk1 = ~stk1; + *D = (stk1 & (~S) & (~T)) | (*D & S) | (*D & T); +} + +/* TDSTDaoxxn source/pattern opaque. */ +static unsigned xrop3_73_0_0 (unsigned char s, unsigned char t) +{ + unsigned D = 0x00ff; + unsigned S = ((unsigned)s << 8) | s; + unsigned T = ((unsigned)t << 8) | t; + unsigned stk1; + unsigned stk2; + unsigned stk3; + unsigned stk4; + stk4 = T & D; + stk3 = S | stk4; + stk2 = D ^ stk3; + stk1 = T ^ stk2; + stk1 = ~stk1; + return stk1; +} + +/* TDSTDaoxxn source opaque/pattern transparent. */ +static unsigned xrop3_73_0_1 (unsigned char s, unsigned char t) +{ + unsigned D = 0x00ff; + unsigned S = ((unsigned)s << 8) | s; + unsigned T = ((unsigned)t << 8) | t; + unsigned stk1; + unsigned stk2; + unsigned stk3; + unsigned stk4; + stk4 = T & D; + stk3 = S | stk4; + stk2 = D ^ stk3; + stk1 = T ^ stk2; + stk1 = ~stk1; + return (stk1 & S) | (stk1 & (~T)) | (T & (~S) & D); +} + +/* TDSTDaoxxn source transparent/pattern opaque. */ +static unsigned xrop3_73_1_0 (unsigned char s, unsigned char t) +{ + unsigned D = 0x00ff; + unsigned S = ((unsigned)s << 8) | s; + unsigned T = ((unsigned)t << 8) | t; + unsigned stk1; + unsigned stk2; + unsigned stk3; + unsigned stk4; + stk4 = T & D; + stk3 = S | stk4; + stk2 = D ^ stk3; + stk1 = T ^ stk2; + stk1 = ~stk1; + return (stk1 & (~S)) | (D & S); +} + +/* TDSTDaoxxn source/pattern transparent. */ +static unsigned xrop3_73_1_1 (unsigned char s, unsigned char t) +{ + unsigned D = 0x00ff; + unsigned S = ((unsigned)s << 8) | s; + unsigned T = ((unsigned)t << 8) | t; + unsigned stk1; + unsigned stk2; + unsigned stk3; + unsigned stk4; + stk4 = T & D; + stk3 = S | stk4; + stk2 = D ^ stk3; + stk1 = T ^ stk2; + stk1 = ~stk1; + return (stk1 & (~S) & (~T)) | (D & S) | (D & T); +} + +/* DTSDoax source/pattern opaque. */ +static void rop3_74_0_0 (unsigned char *D, unsigned char S, unsigned char T) +{ + unsigned char stk1; + unsigned char stk2; + unsigned char stk3; + stk3 = S | *D; + stk2 = T & stk3; + stk1 = *D ^ stk2; + *D = stk1; +} + +/* DTSDoax source opaque/pattern transparent. */ +static void rop3_74_0_1 (unsigned char *D, unsigned char S, unsigned char T) +{ + unsigned char stk1; + unsigned char stk2; + unsigned char stk3; + stk3 = S | *D; + stk2 = T & stk3; + stk1 = *D ^ stk2; + *D = (stk1 & S) | (stk1 & (~T)) | (T & (~S) & *D); +} + +/* DTSDoax source transparent/pattern opaque. */ +static void rop3_74_1_0 (unsigned char *D, unsigned char S, unsigned char T) +{ + unsigned char stk1; + unsigned char stk2; + unsigned char stk3; + stk3 = S | *D; + stk2 = T & stk3; + stk1 = *D ^ stk2; + *D = (stk1 & (~S)) | (*D & S); +} + +/* DTSDoax source/pattern transparent. */ +static void rop3_74_1_1 (unsigned char *D, unsigned char S, unsigned char T) +{ + unsigned char stk1; + unsigned char stk2; + unsigned char stk3; + stk3 = S | *D; + stk2 = T & stk3; + stk1 = *D ^ stk2; + *D = (stk1 & (~S) & (~T)) | (*D & S) | (*D & T); +} + +/* DTSDoax source/pattern opaque. */ +static unsigned xrop3_74_0_0 (unsigned char s, unsigned char t) +{ + unsigned D = 0x00ff; + unsigned S = ((unsigned)s << 8) | s; + unsigned T = ((unsigned)t << 8) | t; + unsigned stk1; + unsigned stk2; + unsigned stk3; + stk3 = S | D; + stk2 = T & stk3; + stk1 = D ^ stk2; + return stk1; +} + +/* DTSDoax source opaque/pattern transparent. */ +static unsigned xrop3_74_0_1 (unsigned char s, unsigned char t) +{ + unsigned D = 0x00ff; + unsigned S = ((unsigned)s << 8) | s; + unsigned T = ((unsigned)t << 8) | t; + unsigned stk1; + unsigned stk2; + unsigned stk3; + stk3 = S | D; + stk2 = T & stk3; + stk1 = D ^ stk2; + return (stk1 & S) | (stk1 & (~T)) | (T & (~S) & D); +} + +/* DTSDoax source transparent/pattern opaque. */ +static unsigned xrop3_74_1_0 (unsigned char s, unsigned char t) +{ + unsigned D = 0x00ff; + unsigned S = ((unsigned)s << 8) | s; + unsigned T = ((unsigned)t << 8) | t; + unsigned stk1; + unsigned stk2; + unsigned stk3; + stk3 = S | D; + stk2 = T & stk3; + stk1 = D ^ stk2; + return (stk1 & (~S)) | (D & S); +} + +/* DTSDoax source/pattern transparent. */ +static unsigned xrop3_74_1_1 (unsigned char s, unsigned char t) +{ + unsigned D = 0x00ff; + unsigned S = ((unsigned)s << 8) | s; + unsigned T = ((unsigned)t << 8) | t; + unsigned stk1; + unsigned stk2; + unsigned stk3; + stk3 = S | D; + stk2 = T & stk3; + stk1 = D ^ stk2; + return (stk1 & (~S) & (~T)) | (D & S) | (D & T); +} + +/* TDSnox source/pattern opaque. */ +static void rop3_75_0_0 (unsigned char *D, unsigned char S, unsigned char T) +{ + unsigned char stk1; + unsigned char stk2; + unsigned char stk3; + stk3 = ~S; + stk2 = *D | stk3; + stk1 = T ^ stk2; + *D = stk1; +} + +/* TDSnox source opaque/pattern transparent. */ +static void rop3_75_0_1 (unsigned char *D, unsigned char S, unsigned char T) +{ + unsigned char stk1; + unsigned char stk2; + unsigned char stk3; + stk3 = ~S; + stk2 = *D | stk3; + stk1 = T ^ stk2; + *D = (stk1 & S) | (stk1 & (~T)) | (T & (~S) & *D); +} + +/* TDSnox source transparent/pattern opaque. */ +static void rop3_75_1_0 (unsigned char *D, unsigned char S, unsigned char T) +{ + unsigned char stk1; + unsigned char stk2; + unsigned char stk3; + stk3 = ~S; + stk2 = *D | stk3; + stk1 = T ^ stk2; + *D = (stk1 & (~S)) | (*D & S); +} + +/* TDSnox source/pattern transparent. */ +static void rop3_75_1_1 (unsigned char *D, unsigned char S, unsigned char T) +{ + unsigned char stk1; + unsigned char stk2; + unsigned char stk3; + stk3 = ~S; + stk2 = *D | stk3; + stk1 = T ^ stk2; + *D = (stk1 & (~S) & (~T)) | (*D & S) | (*D & T); +} + +/* TDSnox source/pattern opaque. */ +static unsigned xrop3_75_0_0 (unsigned char s, unsigned char t) +{ + unsigned D = 0x00ff; + unsigned S = ((unsigned)s << 8) | s; + unsigned T = ((unsigned)t << 8) | t; + unsigned stk1; + unsigned stk2; + unsigned stk3; + stk3 = ~S; + stk2 = D | stk3; + stk1 = T ^ stk2; + return stk1; +} + +/* TDSnox source opaque/pattern transparent. */ +static unsigned xrop3_75_0_1 (unsigned char s, unsigned char t) +{ + unsigned D = 0x00ff; + unsigned S = ((unsigned)s << 8) | s; + unsigned T = ((unsigned)t << 8) | t; + unsigned stk1; + unsigned stk2; + unsigned stk3; + stk3 = ~S; + stk2 = D | stk3; + stk1 = T ^ stk2; + return (stk1 & S) | (stk1 & (~T)) | (T & (~S) & D); +} + +/* TDSnox source transparent/pattern opaque. */ +static unsigned xrop3_75_1_0 (unsigned char s, unsigned char t) +{ + unsigned D = 0x00ff; + unsigned S = ((unsigned)s << 8) | s; + unsigned T = ((unsigned)t << 8) | t; + unsigned stk1; + unsigned stk2; + unsigned stk3; + stk3 = ~S; + stk2 = D | stk3; + stk1 = T ^ stk2; + return (stk1 & (~S)) | (D & S); +} + +/* TDSnox source/pattern transparent. */ +static unsigned xrop3_75_1_1 (unsigned char s, unsigned char t) +{ + unsigned D = 0x00ff; + unsigned S = ((unsigned)s << 8) | s; + unsigned T = ((unsigned)t << 8) | t; + unsigned stk1; + unsigned stk2; + unsigned stk3; + stk3 = ~S; + stk2 = D | stk3; + stk1 = T ^ stk2; + return (stk1 & (~S) & (~T)) | (D & S) | (D & T); +} + +/* SDTana source/pattern opaque. */ +static void rop3_76_0_0 (unsigned char *D, unsigned char S, unsigned char T) +{ + unsigned char stk1; + unsigned char stk2; + stk2 = *D & T; + stk2 = ~stk2; + stk1 = S & stk2; + *D = stk1; +} + +/* SDTana source opaque/pattern transparent. */ +static void rop3_76_0_1 (unsigned char *D, unsigned char S, unsigned char T) +{ + unsigned char stk1; + unsigned char stk2; + stk2 = *D & T; + stk2 = ~stk2; + stk1 = S & stk2; + *D = (stk1 & S) | (stk1 & (~T)) | (T & (~S) & *D); +} + +/* SDTana source transparent/pattern opaque. */ +static void rop3_76_1_0 (unsigned char *D, unsigned char S, unsigned char T) +{ + unsigned char stk1; + unsigned char stk2; + stk2 = *D & T; + stk2 = ~stk2; + stk1 = S & stk2; + *D = (stk1 & (~S)) | (*D & S); +} + +/* SDTana source/pattern transparent. */ +static void rop3_76_1_1 (unsigned char *D, unsigned char S, unsigned char T) +{ + unsigned char stk1; + unsigned char stk2; + stk2 = *D & T; + stk2 = ~stk2; + stk1 = S & stk2; + *D = (stk1 & (~S) & (~T)) | (*D & S) | (*D & T); +} + +/* SDTana source/pattern opaque. */ +static unsigned xrop3_76_0_0 (unsigned char s, unsigned char t) +{ + unsigned D = 0x00ff; + unsigned S = ((unsigned)s << 8) | s; + unsigned T = ((unsigned)t << 8) | t; + unsigned stk1; + unsigned stk2; + stk2 = D & T; + stk2 = ~stk2; + stk1 = S & stk2; + return stk1; +} + +/* SDTana source opaque/pattern transparent. */ +static unsigned xrop3_76_0_1 (unsigned char s, unsigned char t) +{ + unsigned D = 0x00ff; + unsigned S = ((unsigned)s << 8) | s; + unsigned T = ((unsigned)t << 8) | t; + unsigned stk1; + unsigned stk2; + stk2 = D & T; + stk2 = ~stk2; + stk1 = S & stk2; + return (stk1 & S) | (stk1 & (~T)) | (T & (~S) & D); +} + +/* SDTana source transparent/pattern opaque. */ +static unsigned xrop3_76_1_0 (unsigned char s, unsigned char t) +{ + unsigned D = 0x00ff; + unsigned S = ((unsigned)s << 8) | s; + unsigned T = ((unsigned)t << 8) | t; + unsigned stk1; + unsigned stk2; + stk2 = D & T; + stk2 = ~stk2; + stk1 = S & stk2; + return (stk1 & (~S)) | (D & S); +} + +/* SDTana source/pattern transparent. */ +static unsigned xrop3_76_1_1 (unsigned char s, unsigned char t) +{ + unsigned D = 0x00ff; + unsigned S = ((unsigned)s << 8) | s; + unsigned T = ((unsigned)t << 8) | t; + unsigned stk1; + unsigned stk2; + stk2 = D & T; + stk2 = ~stk2; + stk1 = S & stk2; + return (stk1 & (~S) & (~T)) | (D & S) | (D & T); +} + +/* SSTxDSxoxn source/pattern opaque. */ +static void rop3_77_0_0 (unsigned char *D, unsigned char S, unsigned char T) +{ + unsigned char stk1; + unsigned char stk2; + unsigned char stk3; + stk2 = S ^ T; + stk3 = *D ^ S; + stk2 = stk2 | stk3; + stk1 = S ^ stk2; + stk1 = ~stk1; + *D = stk1; +} + +/* SSTxDSxoxn source opaque/pattern transparent. */ +static void rop3_77_0_1 (unsigned char *D, unsigned char S, unsigned char T) +{ + unsigned char stk1; + unsigned char stk2; + unsigned char stk3; + stk2 = S ^ T; + stk3 = *D ^ S; + stk2 = stk2 | stk3; + stk1 = S ^ stk2; + stk1 = ~stk1; + *D = (stk1 & S) | (stk1 & (~T)) | (T & (~S) & *D); +} + +/* SSTxDSxoxn source transparent/pattern opaque. */ +static void rop3_77_1_0 (unsigned char *D, unsigned char S, unsigned char T) +{ + unsigned char stk1; + unsigned char stk2; + unsigned char stk3; + stk2 = S ^ T; + stk3 = *D ^ S; + stk2 = stk2 | stk3; + stk1 = S ^ stk2; + stk1 = ~stk1; + *D = (stk1 & (~S)) | (*D & S); +} + +/* SSTxDSxoxn source/pattern transparent. */ +static void rop3_77_1_1 (unsigned char *D, unsigned char S, unsigned char T) +{ + unsigned char stk1; + unsigned char stk2; + unsigned char stk3; + stk2 = S ^ T; + stk3 = *D ^ S; + stk2 = stk2 | stk3; + stk1 = S ^ stk2; + stk1 = ~stk1; + *D = (stk1 & (~S) & (~T)) | (*D & S) | (*D & T); +} + +/* SSTxDSxoxn source/pattern opaque. */ +static unsigned xrop3_77_0_0 (unsigned char s, unsigned char t) +{ + unsigned D = 0x00ff; + unsigned S = ((unsigned)s << 8) | s; + unsigned T = ((unsigned)t << 8) | t; + unsigned stk1; + unsigned stk2; + unsigned stk3; + stk2 = S ^ T; + stk3 = D ^ S; + stk2 = stk2 | stk3; + stk1 = S ^ stk2; + stk1 = ~stk1; + return stk1; +} + +/* SSTxDSxoxn source opaque/pattern transparent. */ +static unsigned xrop3_77_0_1 (unsigned char s, unsigned char t) +{ + unsigned D = 0x00ff; + unsigned S = ((unsigned)s << 8) | s; + unsigned T = ((unsigned)t << 8) | t; + unsigned stk1; + unsigned stk2; + unsigned stk3; + stk2 = S ^ T; + stk3 = D ^ S; + stk2 = stk2 | stk3; + stk1 = S ^ stk2; + stk1 = ~stk1; + return (stk1 & S) | (stk1 & (~T)) | (T & (~S) & D); +} + +/* SSTxDSxoxn source transparent/pattern opaque. */ +static unsigned xrop3_77_1_0 (unsigned char s, unsigned char t) +{ + unsigned D = 0x00ff; + unsigned S = ((unsigned)s << 8) | s; + unsigned T = ((unsigned)t << 8) | t; + unsigned stk1; + unsigned stk2; + unsigned stk3; + stk2 = S ^ T; + stk3 = D ^ S; + stk2 = stk2 | stk3; + stk1 = S ^ stk2; + stk1 = ~stk1; + return (stk1 & (~S)) | (D & S); +} + +/* SSTxDSxoxn source/pattern transparent. */ +static unsigned xrop3_77_1_1 (unsigned char s, unsigned char t) +{ + unsigned D = 0x00ff; + unsigned S = ((unsigned)s << 8) | s; + unsigned T = ((unsigned)t << 8) | t; + unsigned stk1; + unsigned stk2; + unsigned stk3; + stk2 = S ^ T; + stk3 = D ^ S; + stk2 = stk2 | stk3; + stk1 = S ^ stk2; + stk1 = ~stk1; + return (stk1 & (~S) & (~T)) | (D & S) | (D & T); +} + +/* TDSTxox source/pattern opaque. */ +static void rop3_78_0_0 (unsigned char *D, unsigned char S, unsigned char T) +{ + unsigned char stk1; + unsigned char stk2; + unsigned char stk3; + stk3 = S ^ T; + stk2 = *D | stk3; + stk1 = T ^ stk2; + *D = stk1; +} + +/* TDSTxox source opaque/pattern transparent. */ +static void rop3_78_0_1 (unsigned char *D, unsigned char S, unsigned char T) +{ + unsigned char stk1; + unsigned char stk2; + unsigned char stk3; + stk3 = S ^ T; + stk2 = *D | stk3; + stk1 = T ^ stk2; + *D = (stk1 & S) | (stk1 & (~T)) | (T & (~S) & *D); +} + +/* TDSTxox source transparent/pattern opaque. */ +static void rop3_78_1_0 (unsigned char *D, unsigned char S, unsigned char T) +{ + unsigned char stk1; + unsigned char stk2; + unsigned char stk3; + stk3 = S ^ T; + stk2 = *D | stk3; + stk1 = T ^ stk2; + *D = (stk1 & (~S)) | (*D & S); +} + +/* TDSTxox source/pattern transparent. */ +static void rop3_78_1_1 (unsigned char *D, unsigned char S, unsigned char T) +{ + unsigned char stk1; + unsigned char stk2; + unsigned char stk3; + stk3 = S ^ T; + stk2 = *D | stk3; + stk1 = T ^ stk2; + *D = (stk1 & (~S) & (~T)) | (*D & S) | (*D & T); +} + +/* TDSTxox source/pattern opaque. */ +static unsigned xrop3_78_0_0 (unsigned char s, unsigned char t) +{ + unsigned D = 0x00ff; + unsigned S = ((unsigned)s << 8) | s; + unsigned T = ((unsigned)t << 8) | t; + unsigned stk1; + unsigned stk2; + unsigned stk3; + stk3 = S ^ T; + stk2 = D | stk3; + stk1 = T ^ stk2; + return stk1; +} + +/* TDSTxox source opaque/pattern transparent. */ +static unsigned xrop3_78_0_1 (unsigned char s, unsigned char t) +{ + unsigned D = 0x00ff; + unsigned S = ((unsigned)s << 8) | s; + unsigned T = ((unsigned)t << 8) | t; + unsigned stk1; + unsigned stk2; + unsigned stk3; + stk3 = S ^ T; + stk2 = D | stk3; + stk1 = T ^ stk2; + return (stk1 & S) | (stk1 & (~T)) | (T & (~S) & D); +} + +/* TDSTxox source transparent/pattern opaque. */ +static unsigned xrop3_78_1_0 (unsigned char s, unsigned char t) +{ + unsigned D = 0x00ff; + unsigned S = ((unsigned)s << 8) | s; + unsigned T = ((unsigned)t << 8) | t; + unsigned stk1; + unsigned stk2; + unsigned stk3; + stk3 = S ^ T; + stk2 = D | stk3; + stk1 = T ^ stk2; + return (stk1 & (~S)) | (D & S); +} + +/* TDSTxox source/pattern transparent. */ +static unsigned xrop3_78_1_1 (unsigned char s, unsigned char t) +{ + unsigned D = 0x00ff; + unsigned S = ((unsigned)s << 8) | s; + unsigned T = ((unsigned)t << 8) | t; + unsigned stk1; + unsigned stk2; + unsigned stk3; + stk3 = S ^ T; + stk2 = D | stk3; + stk1 = T ^ stk2; + return (stk1 & (~S) & (~T)) | (D & S) | (D & T); +} + +/* TDSnoan source/pattern opaque. */ +static void rop3_79_0_0 (unsigned char *D, unsigned char S, unsigned char T) +{ + unsigned char stk1; + unsigned char stk2; + unsigned char stk3; + stk3 = ~S; + stk2 = *D | stk3; + stk1 = T & stk2; + stk1 = ~stk1; + *D = stk1; +} + +/* TDSnoan source opaque/pattern transparent. */ +static void rop3_79_0_1 (unsigned char *D, unsigned char S, unsigned char T) +{ + unsigned char stk1; + unsigned char stk2; + unsigned char stk3; + stk3 = ~S; + stk2 = *D | stk3; + stk1 = T & stk2; + stk1 = ~stk1; + *D = (stk1 & S) | (stk1 & (~T)) | (T & (~S) & *D); +} + +/* TDSnoan source transparent/pattern opaque. */ +static void rop3_79_1_0 (unsigned char *D, unsigned char S, unsigned char T) +{ + unsigned char stk1; + unsigned char stk2; + unsigned char stk3; + stk3 = ~S; + stk2 = *D | stk3; + stk1 = T & stk2; + stk1 = ~stk1; + *D = (stk1 & (~S)) | (*D & S); +} + +/* TDSnoan source/pattern transparent. */ +static void rop3_79_1_1 (unsigned char *D, unsigned char S, unsigned char T) +{ + unsigned char stk1; + unsigned char stk2; + unsigned char stk3; + stk3 = ~S; + stk2 = *D | stk3; + stk1 = T & stk2; + stk1 = ~stk1; + *D = (stk1 & (~S) & (~T)) | (*D & S) | (*D & T); +} + +/* TDSnoan source/pattern opaque. */ +static unsigned xrop3_79_0_0 (unsigned char s, unsigned char t) +{ + unsigned D = 0x00ff; + unsigned S = ((unsigned)s << 8) | s; + unsigned T = ((unsigned)t << 8) | t; + unsigned stk1; + unsigned stk2; + unsigned stk3; + stk3 = ~S; + stk2 = D | stk3; + stk1 = T & stk2; + stk1 = ~stk1; + return stk1; +} + +/* TDSnoan source opaque/pattern transparent. */ +static unsigned xrop3_79_0_1 (unsigned char s, unsigned char t) +{ + unsigned D = 0x00ff; + unsigned S = ((unsigned)s << 8) | s; + unsigned T = ((unsigned)t << 8) | t; + unsigned stk1; + unsigned stk2; + unsigned stk3; + stk3 = ~S; + stk2 = D | stk3; + stk1 = T & stk2; + stk1 = ~stk1; + return (stk1 & S) | (stk1 & (~T)) | (T & (~S) & D); +} + +/* TDSnoan source transparent/pattern opaque. */ +static unsigned xrop3_79_1_0 (unsigned char s, unsigned char t) +{ + unsigned D = 0x00ff; + unsigned S = ((unsigned)s << 8) | s; + unsigned T = ((unsigned)t << 8) | t; + unsigned stk1; + unsigned stk2; + unsigned stk3; + stk3 = ~S; + stk2 = D | stk3; + stk1 = T & stk2; + stk1 = ~stk1; + return (stk1 & (~S)) | (D & S); +} + +/* TDSnoan source/pattern transparent. */ +static unsigned xrop3_79_1_1 (unsigned char s, unsigned char t) +{ + unsigned D = 0x00ff; + unsigned S = ((unsigned)s << 8) | s; + unsigned T = ((unsigned)t << 8) | t; + unsigned stk1; + unsigned stk2; + unsigned stk3; + stk3 = ~S; + stk2 = D | stk3; + stk1 = T & stk2; + stk1 = ~stk1; + return (stk1 & (~S) & (~T)) | (D & S) | (D & T); +} + +/* TDna source/pattern opaque. */ +static void rop3_80_0_0 (unsigned char *D, unsigned char S, unsigned char T) +{ + unsigned char stk1; + unsigned char stk2; + stk2 = ~*D; + stk1 = T & stk2; + *D = stk1; +} + +/* TDna source opaque/pattern transparent. */ +static void rop3_80_0_1 (unsigned char *D, unsigned char S, unsigned char T) +{ + unsigned char stk1; + unsigned char stk2; + stk2 = ~*D; + stk1 = T & stk2; + *D = (stk1 & S) | (stk1 & (~T)) | (T & (~S) & *D); +} + +/* TDna source transparent/pattern opaque. */ +static void rop3_80_1_0 (unsigned char *D, unsigned char S, unsigned char T) +{ + unsigned char stk1; + unsigned char stk2; + stk2 = ~*D; + stk1 = T & stk2; + *D = (stk1 & (~S)) | (*D & S); +} + +/* TDna source/pattern transparent. */ +static void rop3_80_1_1 (unsigned char *D, unsigned char S, unsigned char T) +{ + unsigned char stk1; + unsigned char stk2; + stk2 = ~*D; + stk1 = T & stk2; + *D = (stk1 & (~S) & (~T)) | (*D & S) | (*D & T); +} + +/* TDna source/pattern opaque. */ +static unsigned xrop3_80_0_0 (unsigned char s, unsigned char t) +{ + unsigned D = 0x00ff; + unsigned T = ((unsigned)t << 8) | t; + unsigned stk1; + unsigned stk2; + stk2 = ~D; + stk1 = T & stk2; + return stk1; +} + +/* TDna source opaque/pattern transparent. */ +static unsigned xrop3_80_0_1 (unsigned char s, unsigned char t) +{ + unsigned D = 0x00ff; + unsigned S = ((unsigned)s << 8) | s; + unsigned T = ((unsigned)t << 8) | t; + unsigned stk1; + unsigned stk2; + stk2 = ~D; + stk1 = T & stk2; + return (stk1 & S) | (stk1 & (~T)) | (T & (~S) & D); +} + +/* TDna source transparent/pattern opaque. */ +static unsigned xrop3_80_1_0 (unsigned char s, unsigned char t) +{ + unsigned D = 0x00ff; + unsigned S = ((unsigned)s << 8) | s; + unsigned T = ((unsigned)t << 8) | t; + unsigned stk1; + unsigned stk2; + stk2 = ~D; + stk1 = T & stk2; + return (stk1 & (~S)) | (D & S); +} + +/* TDna source/pattern transparent. */ +static unsigned xrop3_80_1_1 (unsigned char s, unsigned char t) +{ + unsigned D = 0x00ff; + unsigned S = ((unsigned)s << 8) | s; + unsigned T = ((unsigned)t << 8) | t; + unsigned stk1; + unsigned stk2; + stk2 = ~D; + stk1 = T & stk2; + return (stk1 & (~S) & (~T)) | (D & S) | (D & T); +} + +/* DSTnaon source/pattern opaque. */ +static void rop3_81_0_0 (unsigned char *D, unsigned char S, unsigned char T) +{ + unsigned char stk1; + unsigned char stk2; + unsigned char stk3; + stk3 = ~T; + stk2 = S & stk3; + stk1 = *D | stk2; + stk1 = ~stk1; + *D = stk1; +} + +/* DSTnaon source opaque/pattern transparent. */ +static void rop3_81_0_1 (unsigned char *D, unsigned char S, unsigned char T) +{ + unsigned char stk1; + unsigned char stk2; + unsigned char stk3; + stk3 = ~T; + stk2 = S & stk3; + stk1 = *D | stk2; + stk1 = ~stk1; + *D = (stk1 & S) | (stk1 & (~T)) | (T & (~S) & *D); +} + +/* DSTnaon source transparent/pattern opaque. */ +static void rop3_81_1_0 (unsigned char *D, unsigned char S, unsigned char T) +{ + unsigned char stk1; + unsigned char stk2; + unsigned char stk3; + stk3 = ~T; + stk2 = S & stk3; + stk1 = *D | stk2; + stk1 = ~stk1; + *D = (stk1 & (~S)) | (*D & S); +} + +/* DSTnaon source/pattern transparent. */ +static void rop3_81_1_1 (unsigned char *D, unsigned char S, unsigned char T) +{ + unsigned char stk1; + unsigned char stk2; + unsigned char stk3; + stk3 = ~T; + stk2 = S & stk3; + stk1 = *D | stk2; + stk1 = ~stk1; + *D = (stk1 & (~S) & (~T)) | (*D & S) | (*D & T); +} + +/* DSTnaon source/pattern opaque. */ +static unsigned xrop3_81_0_0 (unsigned char s, unsigned char t) +{ + unsigned D = 0x00ff; + unsigned S = ((unsigned)s << 8) | s; + unsigned T = ((unsigned)t << 8) | t; + unsigned stk1; + unsigned stk2; + unsigned stk3; + stk3 = ~T; + stk2 = S & stk3; + stk1 = D | stk2; + stk1 = ~stk1; + return stk1; +} + +/* DSTnaon source opaque/pattern transparent. */ +static unsigned xrop3_81_0_1 (unsigned char s, unsigned char t) +{ + unsigned D = 0x00ff; + unsigned S = ((unsigned)s << 8) | s; + unsigned T = ((unsigned)t << 8) | t; + unsigned stk1; + unsigned stk2; + unsigned stk3; + stk3 = ~T; + stk2 = S & stk3; + stk1 = D | stk2; + stk1 = ~stk1; + return (stk1 & S) | (stk1 & (~T)) | (T & (~S) & D); +} + +/* DSTnaon source transparent/pattern opaque. */ +static unsigned xrop3_81_1_0 (unsigned char s, unsigned char t) +{ + unsigned D = 0x00ff; + unsigned S = ((unsigned)s << 8) | s; + unsigned T = ((unsigned)t << 8) | t; + unsigned stk1; + unsigned stk2; + unsigned stk3; + stk3 = ~T; + stk2 = S & stk3; + stk1 = D | stk2; + stk1 = ~stk1; + return (stk1 & (~S)) | (D & S); +} + +/* DSTnaon source/pattern transparent. */ +static unsigned xrop3_81_1_1 (unsigned char s, unsigned char t) +{ + unsigned D = 0x00ff; + unsigned S = ((unsigned)s << 8) | s; + unsigned T = ((unsigned)t << 8) | t; + unsigned stk1; + unsigned stk2; + unsigned stk3; + stk3 = ~T; + stk2 = S & stk3; + stk1 = D | stk2; + stk1 = ~stk1; + return (stk1 & (~S) & (~T)) | (D & S) | (D & T); +} + +/* DTSDaox source/pattern opaque. */ +static void rop3_82_0_0 (unsigned char *D, unsigned char S, unsigned char T) +{ + unsigned char stk1; + unsigned char stk2; + unsigned char stk3; + stk3 = S & *D; + stk2 = T | stk3; + stk1 = *D ^ stk2; + *D = stk1; +} + +/* DTSDaox source opaque/pattern transparent. */ +static void rop3_82_0_1 (unsigned char *D, unsigned char S, unsigned char T) +{ + unsigned char stk1; + unsigned char stk2; + unsigned char stk3; + stk3 = S & *D; + stk2 = T | stk3; + stk1 = *D ^ stk2; + *D = (stk1 & S) | (stk1 & (~T)) | (T & (~S) & *D); +} + +/* DTSDaox source transparent/pattern opaque. */ +static void rop3_82_1_0 (unsigned char *D, unsigned char S, unsigned char T) +{ + unsigned char stk1; + unsigned char stk2; + unsigned char stk3; + stk3 = S & *D; + stk2 = T | stk3; + stk1 = *D ^ stk2; + *D = (stk1 & (~S)) | (*D & S); +} + +/* DTSDaox source/pattern transparent. */ +static void rop3_82_1_1 (unsigned char *D, unsigned char S, unsigned char T) +{ + unsigned char stk1; + unsigned char stk2; + unsigned char stk3; + stk3 = S & *D; + stk2 = T | stk3; + stk1 = *D ^ stk2; + *D = (stk1 & (~S) & (~T)) | (*D & S) | (*D & T); +} + +/* DTSDaox source/pattern opaque. */ +static unsigned xrop3_82_0_0 (unsigned char s, unsigned char t) +{ + unsigned D = 0x00ff; + unsigned S = ((unsigned)s << 8) | s; + unsigned T = ((unsigned)t << 8) | t; + unsigned stk1; + unsigned stk2; + unsigned stk3; + stk3 = S & D; + stk2 = T | stk3; + stk1 = D ^ stk2; + return stk1; +} + +/* DTSDaox source opaque/pattern transparent. */ +static unsigned xrop3_82_0_1 (unsigned char s, unsigned char t) +{ + unsigned D = 0x00ff; + unsigned S = ((unsigned)s << 8) | s; + unsigned T = ((unsigned)t << 8) | t; + unsigned stk1; + unsigned stk2; + unsigned stk3; + stk3 = S & D; + stk2 = T | stk3; + stk1 = D ^ stk2; + return (stk1 & S) | (stk1 & (~T)) | (T & (~S) & D); +} + +/* DTSDaox source transparent/pattern opaque. */ +static unsigned xrop3_82_1_0 (unsigned char s, unsigned char t) +{ + unsigned D = 0x00ff; + unsigned S = ((unsigned)s << 8) | s; + unsigned T = ((unsigned)t << 8) | t; + unsigned stk1; + unsigned stk2; + unsigned stk3; + stk3 = S & D; + stk2 = T | stk3; + stk1 = D ^ stk2; + return (stk1 & (~S)) | (D & S); +} + +/* DTSDaox source/pattern transparent. */ +static unsigned xrop3_82_1_1 (unsigned char s, unsigned char t) +{ + unsigned D = 0x00ff; + unsigned S = ((unsigned)s << 8) | s; + unsigned T = ((unsigned)t << 8) | t; + unsigned stk1; + unsigned stk2; + unsigned stk3; + stk3 = S & D; + stk2 = T | stk3; + stk1 = D ^ stk2; + return (stk1 & (~S) & (~T)) | (D & S) | (D & T); +} + +/* STDSxaxn source/pattern opaque. */ +static void rop3_83_0_0 (unsigned char *D, unsigned char S, unsigned char T) +{ + unsigned char stk1; + unsigned char stk2; + unsigned char stk3; + stk3 = *D ^ S; + stk2 = T & stk3; + stk1 = S ^ stk2; + stk1 = ~stk1; + *D = stk1; +} + +/* STDSxaxn source opaque/pattern transparent. */ +static void rop3_83_0_1 (unsigned char *D, unsigned char S, unsigned char T) +{ + unsigned char stk1; + unsigned char stk2; + unsigned char stk3; + stk3 = *D ^ S; + stk2 = T & stk3; + stk1 = S ^ stk2; + stk1 = ~stk1; + *D = (stk1 & S) | (stk1 & (~T)) | (T & (~S) & *D); +} + +/* STDSxaxn source transparent/pattern opaque. */ +static void rop3_83_1_0 (unsigned char *D, unsigned char S, unsigned char T) +{ + unsigned char stk1; + unsigned char stk2; + unsigned char stk3; + stk3 = *D ^ S; + stk2 = T & stk3; + stk1 = S ^ stk2; + stk1 = ~stk1; + *D = (stk1 & (~S)) | (*D & S); +} + +/* STDSxaxn source/pattern transparent. */ +static void rop3_83_1_1 (unsigned char *D, unsigned char S, unsigned char T) +{ + unsigned char stk1; + unsigned char stk2; + unsigned char stk3; + stk3 = *D ^ S; + stk2 = T & stk3; + stk1 = S ^ stk2; + stk1 = ~stk1; + *D = (stk1 & (~S) & (~T)) | (*D & S) | (*D & T); +} + +/* STDSxaxn source/pattern opaque. */ +static unsigned xrop3_83_0_0 (unsigned char s, unsigned char t) +{ + unsigned D = 0x00ff; + unsigned S = ((unsigned)s << 8) | s; + unsigned T = ((unsigned)t << 8) | t; + unsigned stk1; + unsigned stk2; + unsigned stk3; + stk3 = D ^ S; + stk2 = T & stk3; + stk1 = S ^ stk2; + stk1 = ~stk1; + return stk1; +} + +/* STDSxaxn source opaque/pattern transparent. */ +static unsigned xrop3_83_0_1 (unsigned char s, unsigned char t) +{ + unsigned D = 0x00ff; + unsigned S = ((unsigned)s << 8) | s; + unsigned T = ((unsigned)t << 8) | t; + unsigned stk1; + unsigned stk2; + unsigned stk3; + stk3 = D ^ S; + stk2 = T & stk3; + stk1 = S ^ stk2; + stk1 = ~stk1; + return (stk1 & S) | (stk1 & (~T)) | (T & (~S) & D); +} + +/* STDSxaxn source transparent/pattern opaque. */ +static unsigned xrop3_83_1_0 (unsigned char s, unsigned char t) +{ + unsigned D = 0x00ff; + unsigned S = ((unsigned)s << 8) | s; + unsigned T = ((unsigned)t << 8) | t; + unsigned stk1; + unsigned stk2; + unsigned stk3; + stk3 = D ^ S; + stk2 = T & stk3; + stk1 = S ^ stk2; + stk1 = ~stk1; + return (stk1 & (~S)) | (D & S); +} + +/* STDSxaxn source/pattern transparent. */ +static unsigned xrop3_83_1_1 (unsigned char s, unsigned char t) +{ + unsigned D = 0x00ff; + unsigned S = ((unsigned)s << 8) | s; + unsigned T = ((unsigned)t << 8) | t; + unsigned stk1; + unsigned stk2; + unsigned stk3; + stk3 = D ^ S; + stk2 = T & stk3; + stk1 = S ^ stk2; + stk1 = ~stk1; + return (stk1 & (~S) & (~T)) | (D & S) | (D & T); +} + +/* DTSonon source/pattern opaque. */ +static void rop3_84_0_0 (unsigned char *D, unsigned char S, unsigned char T) +{ + unsigned char stk1; + unsigned char stk2; + stk2 = T | S; + stk2 = ~stk2; + stk1 = *D | stk2; + stk1 = ~stk1; + *D = stk1; +} + +/* DTSonon source opaque/pattern transparent. */ +static void rop3_84_0_1 (unsigned char *D, unsigned char S, unsigned char T) +{ + unsigned char stk1; + unsigned char stk2; + stk2 = T | S; + stk2 = ~stk2; + stk1 = *D | stk2; + stk1 = ~stk1; + *D = (stk1 & S) | (stk1 & (~T)) | (T & (~S) & *D); +} + +/* DTSonon source transparent/pattern opaque. */ +static void rop3_84_1_0 (unsigned char *D, unsigned char S, unsigned char T) +{ + unsigned char stk1; + unsigned char stk2; + stk2 = T | S; + stk2 = ~stk2; + stk1 = *D | stk2; + stk1 = ~stk1; + *D = (stk1 & (~S)) | (*D & S); +} + +/* DTSonon source/pattern transparent. */ +static void rop3_84_1_1 (unsigned char *D, unsigned char S, unsigned char T) +{ + unsigned char stk1; + unsigned char stk2; + stk2 = T | S; + stk2 = ~stk2; + stk1 = *D | stk2; + stk1 = ~stk1; + *D = (stk1 & (~S) & (~T)) | (*D & S) | (*D & T); +} + +/* DTSonon source/pattern opaque. */ +static unsigned xrop3_84_0_0 (unsigned char s, unsigned char t) +{ + unsigned D = 0x00ff; + unsigned S = ((unsigned)s << 8) | s; + unsigned T = ((unsigned)t << 8) | t; + unsigned stk1; + unsigned stk2; + stk2 = T | S; + stk2 = ~stk2; + stk1 = D | stk2; + stk1 = ~stk1; + return stk1; +} + +/* DTSonon source opaque/pattern transparent. */ +static unsigned xrop3_84_0_1 (unsigned char s, unsigned char t) +{ + unsigned D = 0x00ff; + unsigned S = ((unsigned)s << 8) | s; + unsigned T = ((unsigned)t << 8) | t; + unsigned stk1; + unsigned stk2; + stk2 = T | S; + stk2 = ~stk2; + stk1 = D | stk2; + stk1 = ~stk1; + return (stk1 & S) | (stk1 & (~T)) | (T & (~S) & D); +} + +/* DTSonon source transparent/pattern opaque. */ +static unsigned xrop3_84_1_0 (unsigned char s, unsigned char t) +{ + unsigned D = 0x00ff; + unsigned S = ((unsigned)s << 8) | s; + unsigned T = ((unsigned)t << 8) | t; + unsigned stk1; + unsigned stk2; + stk2 = T | S; + stk2 = ~stk2; + stk1 = D | stk2; + stk1 = ~stk1; + return (stk1 & (~S)) | (D & S); +} + +/* DTSonon source/pattern transparent. */ +static unsigned xrop3_84_1_1 (unsigned char s, unsigned char t) +{ + unsigned D = 0x00ff; + unsigned S = ((unsigned)s << 8) | s; + unsigned T = ((unsigned)t << 8) | t; + unsigned stk1; + unsigned stk2; + stk2 = T | S; + stk2 = ~stk2; + stk1 = D | stk2; + stk1 = ~stk1; + return (stk1 & (~S) & (~T)) | (D & S) | (D & T); +} + +/* Dn source/pattern opaque. */ +static void rop3_85_0_0 (unsigned char *D, unsigned char S, unsigned char T) +{ + unsigned char stk1; + stk1 = ~*D; + *D = stk1; +} + +/* Dn source opaque/pattern transparent. */ +static void rop3_85_0_1 (unsigned char *D, unsigned char S, unsigned char T) +{ + unsigned char stk1; + stk1 = ~*D; + *D = (stk1 & S) | (stk1 & (~T)) | (T & (~S) & *D); +} + +/* Dn source transparent/pattern opaque. */ +static void rop3_85_1_0 (unsigned char *D, unsigned char S, unsigned char T) +{ + unsigned char stk1; + stk1 = ~*D; + *D = (stk1 & (~S)) | (*D & S); +} + +/* Dn source/pattern transparent. */ +static void rop3_85_1_1 (unsigned char *D, unsigned char S, unsigned char T) +{ + unsigned char stk1; + stk1 = ~*D; + *D = (stk1 & (~S) & (~T)) | (*D & S) | (*D & T); +} + +/* Dn source/pattern opaque. */ +static unsigned xrop3_85_0_0 (unsigned char s, unsigned char t) +{ + unsigned D = 0x00ff; + unsigned stk1; + stk1 = ~D; + return stk1; +} + +/* Dn source opaque/pattern transparent. */ +static unsigned xrop3_85_0_1 (unsigned char s, unsigned char t) +{ + unsigned D = 0x00ff; + unsigned S = ((unsigned)s << 8) | s; + unsigned T = ((unsigned)t << 8) | t; + unsigned stk1; + stk1 = ~D; + return (stk1 & S) | (stk1 & (~T)) | (T & (~S) & D); +} + +/* Dn source transparent/pattern opaque. */ +static unsigned xrop3_85_1_0 (unsigned char s, unsigned char t) +{ + unsigned D = 0x00ff; + unsigned S = ((unsigned)s << 8) | s; + unsigned stk1; + stk1 = ~D; + return (stk1 & (~S)) | (D & S); +} + +/* Dn source/pattern transparent. */ +static unsigned xrop3_85_1_1 (unsigned char s, unsigned char t) +{ + unsigned D = 0x00ff; + unsigned S = ((unsigned)s << 8) | s; + unsigned T = ((unsigned)t << 8) | t; + unsigned stk1; + stk1 = ~D; + return (stk1 & (~S) & (~T)) | (D & S) | (D & T); +} + +/* DTSox source/pattern opaque. */ +static void rop3_86_0_0 (unsigned char *D, unsigned char S, unsigned char T) +{ + unsigned char stk1; + unsigned char stk2; + stk2 = T | S; + stk1 = *D ^ stk2; + *D = stk1; +} + +/* DTSox source opaque/pattern transparent. */ +static void rop3_86_0_1 (unsigned char *D, unsigned char S, unsigned char T) +{ + unsigned char stk1; + unsigned char stk2; + stk2 = T | S; + stk1 = *D ^ stk2; + *D = (stk1 & S) | (stk1 & (~T)) | (T & (~S) & *D); +} + +/* DTSox source transparent/pattern opaque. */ +static void rop3_86_1_0 (unsigned char *D, unsigned char S, unsigned char T) +{ + unsigned char stk1; + unsigned char stk2; + stk2 = T | S; + stk1 = *D ^ stk2; + *D = (stk1 & (~S)) | (*D & S); +} + +/* DTSox source/pattern transparent. */ +static void rop3_86_1_1 (unsigned char *D, unsigned char S, unsigned char T) +{ + unsigned char stk1; + unsigned char stk2; + stk2 = T | S; + stk1 = *D ^ stk2; + *D = (stk1 & (~S) & (~T)) | (*D & S) | (*D & T); +} + +/* DTSox source/pattern opaque. */ +static unsigned xrop3_86_0_0 (unsigned char s, unsigned char t) +{ + unsigned D = 0x00ff; + unsigned S = ((unsigned)s << 8) | s; + unsigned T = ((unsigned)t << 8) | t; + unsigned stk1; + unsigned stk2; + stk2 = T | S; + stk1 = D ^ stk2; + return stk1; +} + +/* DTSox source opaque/pattern transparent. */ +static unsigned xrop3_86_0_1 (unsigned char s, unsigned char t) +{ + unsigned D = 0x00ff; + unsigned S = ((unsigned)s << 8) | s; + unsigned T = ((unsigned)t << 8) | t; + unsigned stk1; + unsigned stk2; + stk2 = T | S; + stk1 = D ^ stk2; + return (stk1 & S) | (stk1 & (~T)) | (T & (~S) & D); +} + +/* DTSox source transparent/pattern opaque. */ +static unsigned xrop3_86_1_0 (unsigned char s, unsigned char t) +{ + unsigned D = 0x00ff; + unsigned S = ((unsigned)s << 8) | s; + unsigned T = ((unsigned)t << 8) | t; + unsigned stk1; + unsigned stk2; + stk2 = T | S; + stk1 = D ^ stk2; + return (stk1 & (~S)) | (D & S); +} + +/* DTSox source/pattern transparent. */ +static unsigned xrop3_86_1_1 (unsigned char s, unsigned char t) +{ + unsigned D = 0x00ff; + unsigned S = ((unsigned)s << 8) | s; + unsigned T = ((unsigned)t << 8) | t; + unsigned stk1; + unsigned stk2; + stk2 = T | S; + stk1 = D ^ stk2; + return (stk1 & (~S) & (~T)) | (D & S) | (D & T); +} + +/* DTSoan source/pattern opaque. */ +static void rop3_87_0_0 (unsigned char *D, unsigned char S, unsigned char T) +{ + unsigned char stk1; + unsigned char stk2; + stk2 = T | S; + stk1 = *D & stk2; + stk1 = ~stk1; + *D = stk1; +} + +/* DTSoan source opaque/pattern transparent. */ +static void rop3_87_0_1 (unsigned char *D, unsigned char S, unsigned char T) +{ + unsigned char stk1; + unsigned char stk2; + stk2 = T | S; + stk1 = *D & stk2; + stk1 = ~stk1; + *D = (stk1 & S) | (stk1 & (~T)) | (T & (~S) & *D); +} + +/* DTSoan source transparent/pattern opaque. */ +static void rop3_87_1_0 (unsigned char *D, unsigned char S, unsigned char T) +{ + unsigned char stk1; + unsigned char stk2; + stk2 = T | S; + stk1 = *D & stk2; + stk1 = ~stk1; + *D = (stk1 & (~S)) | (*D & S); +} + +/* DTSoan source/pattern transparent. */ +static void rop3_87_1_1 (unsigned char *D, unsigned char S, unsigned char T) +{ + unsigned char stk1; + unsigned char stk2; + stk2 = T | S; + stk1 = *D & stk2; + stk1 = ~stk1; + *D = (stk1 & (~S) & (~T)) | (*D & S) | (*D & T); +} + +/* DTSoan source/pattern opaque. */ +static unsigned xrop3_87_0_0 (unsigned char s, unsigned char t) +{ + unsigned D = 0x00ff; + unsigned S = ((unsigned)s << 8) | s; + unsigned T = ((unsigned)t << 8) | t; + unsigned stk1; + unsigned stk2; + stk2 = T | S; + stk1 = D & stk2; + stk1 = ~stk1; + return stk1; +} + +/* DTSoan source opaque/pattern transparent. */ +static unsigned xrop3_87_0_1 (unsigned char s, unsigned char t) +{ + unsigned D = 0x00ff; + unsigned S = ((unsigned)s << 8) | s; + unsigned T = ((unsigned)t << 8) | t; + unsigned stk1; + unsigned stk2; + stk2 = T | S; + stk1 = D & stk2; + stk1 = ~stk1; + return (stk1 & S) | (stk1 & (~T)) | (T & (~S) & D); +} + +/* DTSoan source transparent/pattern opaque. */ +static unsigned xrop3_87_1_0 (unsigned char s, unsigned char t) +{ + unsigned D = 0x00ff; + unsigned S = ((unsigned)s << 8) | s; + unsigned T = ((unsigned)t << 8) | t; + unsigned stk1; + unsigned stk2; + stk2 = T | S; + stk1 = D & stk2; + stk1 = ~stk1; + return (stk1 & (~S)) | (D & S); +} + +/* DTSoan source/pattern transparent. */ +static unsigned xrop3_87_1_1 (unsigned char s, unsigned char t) +{ + unsigned D = 0x00ff; + unsigned S = ((unsigned)s << 8) | s; + unsigned T = ((unsigned)t << 8) | t; + unsigned stk1; + unsigned stk2; + stk2 = T | S; + stk1 = D & stk2; + stk1 = ~stk1; + return (stk1 & (~S) & (~T)) | (D & S) | (D & T); +} + +/* TDSToax source/pattern opaque. */ +static void rop3_88_0_0 (unsigned char *D, unsigned char S, unsigned char T) +{ + unsigned char stk1; + unsigned char stk2; + unsigned char stk3; + stk3 = S | T; + stk2 = *D & stk3; + stk1 = T ^ stk2; + *D = stk1; +} + +/* TDSToax source opaque/pattern transparent. */ +static void rop3_88_0_1 (unsigned char *D, unsigned char S, unsigned char T) +{ + unsigned char stk1; + unsigned char stk2; + unsigned char stk3; + stk3 = S | T; + stk2 = *D & stk3; + stk1 = T ^ stk2; + *D = (stk1 & S) | (stk1 & (~T)) | (T & (~S) & *D); +} + +/* TDSToax source transparent/pattern opaque. */ +static void rop3_88_1_0 (unsigned char *D, unsigned char S, unsigned char T) +{ + unsigned char stk1; + unsigned char stk2; + unsigned char stk3; + stk3 = S | T; + stk2 = *D & stk3; + stk1 = T ^ stk2; + *D = (stk1 & (~S)) | (*D & S); +} + +/* TDSToax source/pattern transparent. */ +static void rop3_88_1_1 (unsigned char *D, unsigned char S, unsigned char T) +{ + unsigned char stk1; + unsigned char stk2; + unsigned char stk3; + stk3 = S | T; + stk2 = *D & stk3; + stk1 = T ^ stk2; + *D = (stk1 & (~S) & (~T)) | (*D & S) | (*D & T); +} + +/* TDSToax source/pattern opaque. */ +static unsigned xrop3_88_0_0 (unsigned char s, unsigned char t) +{ + unsigned D = 0x00ff; + unsigned S = ((unsigned)s << 8) | s; + unsigned T = ((unsigned)t << 8) | t; + unsigned stk1; + unsigned stk2; + unsigned stk3; + stk3 = S | T; + stk2 = D & stk3; + stk1 = T ^ stk2; + return stk1; +} + +/* TDSToax source opaque/pattern transparent. */ +static unsigned xrop3_88_0_1 (unsigned char s, unsigned char t) +{ + unsigned D = 0x00ff; + unsigned S = ((unsigned)s << 8) | s; + unsigned T = ((unsigned)t << 8) | t; + unsigned stk1; + unsigned stk2; + unsigned stk3; + stk3 = S | T; + stk2 = D & stk3; + stk1 = T ^ stk2; + return (stk1 & S) | (stk1 & (~T)) | (T & (~S) & D); +} + +/* TDSToax source transparent/pattern opaque. */ +static unsigned xrop3_88_1_0 (unsigned char s, unsigned char t) +{ + unsigned D = 0x00ff; + unsigned S = ((unsigned)s << 8) | s; + unsigned T = ((unsigned)t << 8) | t; + unsigned stk1; + unsigned stk2; + unsigned stk3; + stk3 = S | T; + stk2 = D & stk3; + stk1 = T ^ stk2; + return (stk1 & (~S)) | (D & S); +} + +/* TDSToax source/pattern transparent. */ +static unsigned xrop3_88_1_1 (unsigned char s, unsigned char t) +{ + unsigned D = 0x00ff; + unsigned S = ((unsigned)s << 8) | s; + unsigned T = ((unsigned)t << 8) | t; + unsigned stk1; + unsigned stk2; + unsigned stk3; + stk3 = S | T; + stk2 = D & stk3; + stk1 = T ^ stk2; + return (stk1 & (~S) & (~T)) | (D & S) | (D & T); +} + +/* DTSnox source/pattern opaque. */ +static void rop3_89_0_0 (unsigned char *D, unsigned char S, unsigned char T) +{ + unsigned char stk1; + unsigned char stk2; + unsigned char stk3; + stk3 = ~S; + stk2 = T | stk3; + stk1 = *D ^ stk2; + *D = stk1; +} + +/* DTSnox source opaque/pattern transparent. */ +static void rop3_89_0_1 (unsigned char *D, unsigned char S, unsigned char T) +{ + unsigned char stk1; + unsigned char stk2; + unsigned char stk3; + stk3 = ~S; + stk2 = T | stk3; + stk1 = *D ^ stk2; + *D = (stk1 & S) | (stk1 & (~T)) | (T & (~S) & *D); +} + +/* DTSnox source transparent/pattern opaque. */ +static void rop3_89_1_0 (unsigned char *D, unsigned char S, unsigned char T) +{ + unsigned char stk1; + unsigned char stk2; + unsigned char stk3; + stk3 = ~S; + stk2 = T | stk3; + stk1 = *D ^ stk2; + *D = (stk1 & (~S)) | (*D & S); +} + +/* DTSnox source/pattern transparent. */ +static void rop3_89_1_1 (unsigned char *D, unsigned char S, unsigned char T) +{ + unsigned char stk1; + unsigned char stk2; + unsigned char stk3; + stk3 = ~S; + stk2 = T | stk3; + stk1 = *D ^ stk2; + *D = (stk1 & (~S) & (~T)) | (*D & S) | (*D & T); +} + +/* DTSnox source/pattern opaque. */ +static unsigned xrop3_89_0_0 (unsigned char s, unsigned char t) +{ + unsigned D = 0x00ff; + unsigned S = ((unsigned)s << 8) | s; + unsigned T = ((unsigned)t << 8) | t; + unsigned stk1; + unsigned stk2; + unsigned stk3; + stk3 = ~S; + stk2 = T | stk3; + stk1 = D ^ stk2; + return stk1; +} + +/* DTSnox source opaque/pattern transparent. */ +static unsigned xrop3_89_0_1 (unsigned char s, unsigned char t) +{ + unsigned D = 0x00ff; + unsigned S = ((unsigned)s << 8) | s; + unsigned T = ((unsigned)t << 8) | t; + unsigned stk1; + unsigned stk2; + unsigned stk3; + stk3 = ~S; + stk2 = T | stk3; + stk1 = D ^ stk2; + return (stk1 & S) | (stk1 & (~T)) | (T & (~S) & D); +} + +/* DTSnox source transparent/pattern opaque. */ +static unsigned xrop3_89_1_0 (unsigned char s, unsigned char t) +{ + unsigned D = 0x00ff; + unsigned S = ((unsigned)s << 8) | s; + unsigned T = ((unsigned)t << 8) | t; + unsigned stk1; + unsigned stk2; + unsigned stk3; + stk3 = ~S; + stk2 = T | stk3; + stk1 = D ^ stk2; + return (stk1 & (~S)) | (D & S); +} + +/* DTSnox source/pattern transparent. */ +static unsigned xrop3_89_1_1 (unsigned char s, unsigned char t) +{ + unsigned D = 0x00ff; + unsigned S = ((unsigned)s << 8) | s; + unsigned T = ((unsigned)t << 8) | t; + unsigned stk1; + unsigned stk2; + unsigned stk3; + stk3 = ~S; + stk2 = T | stk3; + stk1 = D ^ stk2; + return (stk1 & (~S) & (~T)) | (D & S) | (D & T); +} + +/* DTx source/pattern opaque. */ +static void rop3_90_0_0 (unsigned char *D, unsigned char S, unsigned char T) +{ + unsigned char stk1; + stk1 = *D ^ T; + *D = stk1; +} + +/* DTx source opaque/pattern transparent. */ +static void rop3_90_0_1 (unsigned char *D, unsigned char S, unsigned char T) +{ + unsigned char stk1; + stk1 = *D ^ T; + *D = (stk1 & S) | (stk1 & (~T)) | (T & (~S) & *D); +} + +/* DTx source transparent/pattern opaque. */ +static void rop3_90_1_0 (unsigned char *D, unsigned char S, unsigned char T) +{ + unsigned char stk1; + stk1 = *D ^ T; + *D = (stk1 & (~S)) | (*D & S); +} + +/* DTx source/pattern transparent. */ +static void rop3_90_1_1 (unsigned char *D, unsigned char S, unsigned char T) +{ + unsigned char stk1; + stk1 = *D ^ T; + *D = (stk1 & (~S) & (~T)) | (*D & S) | (*D & T); +} + +/* DTx source/pattern opaque. */ +static unsigned xrop3_90_0_0 (unsigned char s, unsigned char t) +{ + unsigned D = 0x00ff; + unsigned T = ((unsigned)t << 8) | t; + unsigned stk1; + stk1 = D ^ T; + return stk1; +} + +/* DTx source opaque/pattern transparent. */ +static unsigned xrop3_90_0_1 (unsigned char s, unsigned char t) +{ + unsigned D = 0x00ff; + unsigned S = ((unsigned)s << 8) | s; + unsigned T = ((unsigned)t << 8) | t; + unsigned stk1; + stk1 = D ^ T; + return (stk1 & S) | (stk1 & (~T)) | (T & (~S) & D); +} + +/* DTx source transparent/pattern opaque. */ +static unsigned xrop3_90_1_0 (unsigned char s, unsigned char t) +{ + unsigned D = 0x00ff; + unsigned S = ((unsigned)s << 8) | s; + unsigned T = ((unsigned)t << 8) | t; + unsigned stk1; + stk1 = D ^ T; + return (stk1 & (~S)) | (D & S); +} + +/* DTx source/pattern transparent. */ +static unsigned xrop3_90_1_1 (unsigned char s, unsigned char t) +{ + unsigned D = 0x00ff; + unsigned S = ((unsigned)s << 8) | s; + unsigned T = ((unsigned)t << 8) | t; + unsigned stk1; + stk1 = D ^ T; + return (stk1 & (~S) & (~T)) | (D & S) | (D & T); +} + +/* DTSDonox source/pattern opaque. */ +static void rop3_91_0_0 (unsigned char *D, unsigned char S, unsigned char T) +{ + unsigned char stk1; + unsigned char stk2; + unsigned char stk3; + stk3 = S | *D; + stk3 = ~stk3; + stk2 = T | stk3; + stk1 = *D ^ stk2; + *D = stk1; +} + +/* DTSDonox source opaque/pattern transparent. */ +static void rop3_91_0_1 (unsigned char *D, unsigned char S, unsigned char T) +{ + unsigned char stk1; + unsigned char stk2; + unsigned char stk3; + stk3 = S | *D; + stk3 = ~stk3; + stk2 = T | stk3; + stk1 = *D ^ stk2; + *D = (stk1 & S) | (stk1 & (~T)) | (T & (~S) & *D); +} + +/* DTSDonox source transparent/pattern opaque. */ +static void rop3_91_1_0 (unsigned char *D, unsigned char S, unsigned char T) +{ + unsigned char stk1; + unsigned char stk2; + unsigned char stk3; + stk3 = S | *D; + stk3 = ~stk3; + stk2 = T | stk3; + stk1 = *D ^ stk2; + *D = (stk1 & (~S)) | (*D & S); +} + +/* DTSDonox source/pattern transparent. */ +static void rop3_91_1_1 (unsigned char *D, unsigned char S, unsigned char T) +{ + unsigned char stk1; + unsigned char stk2; + unsigned char stk3; + stk3 = S | *D; + stk3 = ~stk3; + stk2 = T | stk3; + stk1 = *D ^ stk2; + *D = (stk1 & (~S) & (~T)) | (*D & S) | (*D & T); +} + +/* DTSDonox source/pattern opaque. */ +static unsigned xrop3_91_0_0 (unsigned char s, unsigned char t) +{ + unsigned D = 0x00ff; + unsigned S = ((unsigned)s << 8) | s; + unsigned T = ((unsigned)t << 8) | t; + unsigned stk1; + unsigned stk2; + unsigned stk3; + stk3 = S | D; + stk3 = ~stk3; + stk2 = T | stk3; + stk1 = D ^ stk2; + return stk1; +} + +/* DTSDonox source opaque/pattern transparent. */ +static unsigned xrop3_91_0_1 (unsigned char s, unsigned char t) +{ + unsigned D = 0x00ff; + unsigned S = ((unsigned)s << 8) | s; + unsigned T = ((unsigned)t << 8) | t; + unsigned stk1; + unsigned stk2; + unsigned stk3; + stk3 = S | D; + stk3 = ~stk3; + stk2 = T | stk3; + stk1 = D ^ stk2; + return (stk1 & S) | (stk1 & (~T)) | (T & (~S) & D); +} + +/* DTSDonox source transparent/pattern opaque. */ +static unsigned xrop3_91_1_0 (unsigned char s, unsigned char t) +{ + unsigned D = 0x00ff; + unsigned S = ((unsigned)s << 8) | s; + unsigned T = ((unsigned)t << 8) | t; + unsigned stk1; + unsigned stk2; + unsigned stk3; + stk3 = S | D; + stk3 = ~stk3; + stk2 = T | stk3; + stk1 = D ^ stk2; + return (stk1 & (~S)) | (D & S); +} + +/* DTSDonox source/pattern transparent. */ +static unsigned xrop3_91_1_1 (unsigned char s, unsigned char t) +{ + unsigned D = 0x00ff; + unsigned S = ((unsigned)s << 8) | s; + unsigned T = ((unsigned)t << 8) | t; + unsigned stk1; + unsigned stk2; + unsigned stk3; + stk3 = S | D; + stk3 = ~stk3; + stk2 = T | stk3; + stk1 = D ^ stk2; + return (stk1 & (~S) & (~T)) | (D & S) | (D & T); +} + +/* DTSDxox source/pattern opaque. */ +static void rop3_92_0_0 (unsigned char *D, unsigned char S, unsigned char T) +{ + unsigned char stk1; + unsigned char stk2; + unsigned char stk3; + stk3 = S ^ *D; + stk2 = T | stk3; + stk1 = *D ^ stk2; + *D = stk1; +} + +/* DTSDxox source opaque/pattern transparent. */ +static void rop3_92_0_1 (unsigned char *D, unsigned char S, unsigned char T) +{ + unsigned char stk1; + unsigned char stk2; + unsigned char stk3; + stk3 = S ^ *D; + stk2 = T | stk3; + stk1 = *D ^ stk2; + *D = (stk1 & S) | (stk1 & (~T)) | (T & (~S) & *D); +} + +/* DTSDxox source transparent/pattern opaque. */ +static void rop3_92_1_0 (unsigned char *D, unsigned char S, unsigned char T) +{ + unsigned char stk1; + unsigned char stk2; + unsigned char stk3; + stk3 = S ^ *D; + stk2 = T | stk3; + stk1 = *D ^ stk2; + *D = (stk1 & (~S)) | (*D & S); +} + +/* DTSDxox source/pattern transparent. */ +static void rop3_92_1_1 (unsigned char *D, unsigned char S, unsigned char T) +{ + unsigned char stk1; + unsigned char stk2; + unsigned char stk3; + stk3 = S ^ *D; + stk2 = T | stk3; + stk1 = *D ^ stk2; + *D = (stk1 & (~S) & (~T)) | (*D & S) | (*D & T); +} + +/* DTSDxox source/pattern opaque. */ +static unsigned xrop3_92_0_0 (unsigned char s, unsigned char t) +{ + unsigned D = 0x00ff; + unsigned S = ((unsigned)s << 8) | s; + unsigned T = ((unsigned)t << 8) | t; + unsigned stk1; + unsigned stk2; + unsigned stk3; + stk3 = S ^ D; + stk2 = T | stk3; + stk1 = D ^ stk2; + return stk1; +} + +/* DTSDxox source opaque/pattern transparent. */ +static unsigned xrop3_92_0_1 (unsigned char s, unsigned char t) +{ + unsigned D = 0x00ff; + unsigned S = ((unsigned)s << 8) | s; + unsigned T = ((unsigned)t << 8) | t; + unsigned stk1; + unsigned stk2; + unsigned stk3; + stk3 = S ^ D; + stk2 = T | stk3; + stk1 = D ^ stk2; + return (stk1 & S) | (stk1 & (~T)) | (T & (~S) & D); +} + +/* DTSDxox source transparent/pattern opaque. */ +static unsigned xrop3_92_1_0 (unsigned char s, unsigned char t) +{ + unsigned D = 0x00ff; + unsigned S = ((unsigned)s << 8) | s; + unsigned T = ((unsigned)t << 8) | t; + unsigned stk1; + unsigned stk2; + unsigned stk3; + stk3 = S ^ D; + stk2 = T | stk3; + stk1 = D ^ stk2; + return (stk1 & (~S)) | (D & S); +} + +/* DTSDxox source/pattern transparent. */ +static unsigned xrop3_92_1_1 (unsigned char s, unsigned char t) +{ + unsigned D = 0x00ff; + unsigned S = ((unsigned)s << 8) | s; + unsigned T = ((unsigned)t << 8) | t; + unsigned stk1; + unsigned stk2; + unsigned stk3; + stk3 = S ^ D; + stk2 = T | stk3; + stk1 = D ^ stk2; + return (stk1 & (~S) & (~T)) | (D & S) | (D & T); +} + +/* DTSnoan source/pattern opaque. */ +static void rop3_93_0_0 (unsigned char *D, unsigned char S, unsigned char T) +{ + unsigned char stk1; + unsigned char stk2; + unsigned char stk3; + stk3 = ~S; + stk2 = T | stk3; + stk1 = *D & stk2; + stk1 = ~stk1; + *D = stk1; +} + +/* DTSnoan source opaque/pattern transparent. */ +static void rop3_93_0_1 (unsigned char *D, unsigned char S, unsigned char T) +{ + unsigned char stk1; + unsigned char stk2; + unsigned char stk3; + stk3 = ~S; + stk2 = T | stk3; + stk1 = *D & stk2; + stk1 = ~stk1; + *D = (stk1 & S) | (stk1 & (~T)) | (T & (~S) & *D); +} + +/* DTSnoan source transparent/pattern opaque. */ +static void rop3_93_1_0 (unsigned char *D, unsigned char S, unsigned char T) +{ + unsigned char stk1; + unsigned char stk2; + unsigned char stk3; + stk3 = ~S; + stk2 = T | stk3; + stk1 = *D & stk2; + stk1 = ~stk1; + *D = (stk1 & (~S)) | (*D & S); +} + +/* DTSnoan source/pattern transparent. */ +static void rop3_93_1_1 (unsigned char *D, unsigned char S, unsigned char T) +{ + unsigned char stk1; + unsigned char stk2; + unsigned char stk3; + stk3 = ~S; + stk2 = T | stk3; + stk1 = *D & stk2; + stk1 = ~stk1; + *D = (stk1 & (~S) & (~T)) | (*D & S) | (*D & T); +} + +/* DTSnoan source/pattern opaque. */ +static unsigned xrop3_93_0_0 (unsigned char s, unsigned char t) +{ + unsigned D = 0x00ff; + unsigned S = ((unsigned)s << 8) | s; + unsigned T = ((unsigned)t << 8) | t; + unsigned stk1; + unsigned stk2; + unsigned stk3; + stk3 = ~S; + stk2 = T | stk3; + stk1 = D & stk2; + stk1 = ~stk1; + return stk1; +} + +/* DTSnoan source opaque/pattern transparent. */ +static unsigned xrop3_93_0_1 (unsigned char s, unsigned char t) +{ + unsigned D = 0x00ff; + unsigned S = ((unsigned)s << 8) | s; + unsigned T = ((unsigned)t << 8) | t; + unsigned stk1; + unsigned stk2; + unsigned stk3; + stk3 = ~S; + stk2 = T | stk3; + stk1 = D & stk2; + stk1 = ~stk1; + return (stk1 & S) | (stk1 & (~T)) | (T & (~S) & D); +} + +/* DTSnoan source transparent/pattern opaque. */ +static unsigned xrop3_93_1_0 (unsigned char s, unsigned char t) +{ + unsigned D = 0x00ff; + unsigned S = ((unsigned)s << 8) | s; + unsigned T = ((unsigned)t << 8) | t; + unsigned stk1; + unsigned stk2; + unsigned stk3; + stk3 = ~S; + stk2 = T | stk3; + stk1 = D & stk2; + stk1 = ~stk1; + return (stk1 & (~S)) | (D & S); +} + +/* DTSnoan source/pattern transparent. */ +static unsigned xrop3_93_1_1 (unsigned char s, unsigned char t) +{ + unsigned D = 0x00ff; + unsigned S = ((unsigned)s << 8) | s; + unsigned T = ((unsigned)t << 8) | t; + unsigned stk1; + unsigned stk2; + unsigned stk3; + stk3 = ~S; + stk2 = T | stk3; + stk1 = D & stk2; + stk1 = ~stk1; + return (stk1 & (~S) & (~T)) | (D & S) | (D & T); +} + +/* DTSDnaox source/pattern opaque. */ +static void rop3_94_0_0 (unsigned char *D, unsigned char S, unsigned char T) +{ + unsigned char stk1; + unsigned char stk2; + unsigned char stk3; + unsigned char stk4; + stk4 = ~*D; + stk3 = S & stk4; + stk2 = T | stk3; + stk1 = *D ^ stk2; + *D = stk1; +} + +/* DTSDnaox source opaque/pattern transparent. */ +static void rop3_94_0_1 (unsigned char *D, unsigned char S, unsigned char T) +{ + unsigned char stk1; + unsigned char stk2; + unsigned char stk3; + unsigned char stk4; + stk4 = ~*D; + stk3 = S & stk4; + stk2 = T | stk3; + stk1 = *D ^ stk2; + *D = (stk1 & S) | (stk1 & (~T)) | (T & (~S) & *D); +} + +/* DTSDnaox source transparent/pattern opaque. */ +static void rop3_94_1_0 (unsigned char *D, unsigned char S, unsigned char T) +{ + unsigned char stk1; + unsigned char stk2; + unsigned char stk3; + unsigned char stk4; + stk4 = ~*D; + stk3 = S & stk4; + stk2 = T | stk3; + stk1 = *D ^ stk2; + *D = (stk1 & (~S)) | (*D & S); +} + +/* DTSDnaox source/pattern transparent. */ +static void rop3_94_1_1 (unsigned char *D, unsigned char S, unsigned char T) +{ + unsigned char stk1; + unsigned char stk2; + unsigned char stk3; + unsigned char stk4; + stk4 = ~*D; + stk3 = S & stk4; + stk2 = T | stk3; + stk1 = *D ^ stk2; + *D = (stk1 & (~S) & (~T)) | (*D & S) | (*D & T); +} + +/* DTSDnaox source/pattern opaque. */ +static unsigned xrop3_94_0_0 (unsigned char s, unsigned char t) +{ + unsigned D = 0x00ff; + unsigned S = ((unsigned)s << 8) | s; + unsigned T = ((unsigned)t << 8) | t; + unsigned stk1; + unsigned stk2; + unsigned stk3; + unsigned stk4; + stk4 = ~D; + stk3 = S & stk4; + stk2 = T | stk3; + stk1 = D ^ stk2; + return stk1; +} + +/* DTSDnaox source opaque/pattern transparent. */ +static unsigned xrop3_94_0_1 (unsigned char s, unsigned char t) +{ + unsigned D = 0x00ff; + unsigned S = ((unsigned)s << 8) | s; + unsigned T = ((unsigned)t << 8) | t; + unsigned stk1; + unsigned stk2; + unsigned stk3; + unsigned stk4; + stk4 = ~D; + stk3 = S & stk4; + stk2 = T | stk3; + stk1 = D ^ stk2; + return (stk1 & S) | (stk1 & (~T)) | (T & (~S) & D); +} + +/* DTSDnaox source transparent/pattern opaque. */ +static unsigned xrop3_94_1_0 (unsigned char s, unsigned char t) +{ + unsigned D = 0x00ff; + unsigned S = ((unsigned)s << 8) | s; + unsigned T = ((unsigned)t << 8) | t; + unsigned stk1; + unsigned stk2; + unsigned stk3; + unsigned stk4; + stk4 = ~D; + stk3 = S & stk4; + stk2 = T | stk3; + stk1 = D ^ stk2; + return (stk1 & (~S)) | (D & S); +} + +/* DTSDnaox source/pattern transparent. */ +static unsigned xrop3_94_1_1 (unsigned char s, unsigned char t) +{ + unsigned D = 0x00ff; + unsigned S = ((unsigned)s << 8) | s; + unsigned T = ((unsigned)t << 8) | t; + unsigned stk1; + unsigned stk2; + unsigned stk3; + unsigned stk4; + stk4 = ~D; + stk3 = S & stk4; + stk2 = T | stk3; + stk1 = D ^ stk2; + return (stk1 & (~S) & (~T)) | (D & S) | (D & T); +} + +/* DTan source/pattern opaque. */ +static void rop3_95_0_0 (unsigned char *D, unsigned char S, unsigned char T) +{ + unsigned char stk1; + stk1 = *D & T; + stk1 = ~stk1; + *D = stk1; +} + +/* DTan source opaque/pattern transparent. */ +static void rop3_95_0_1 (unsigned char *D, unsigned char S, unsigned char T) +{ + unsigned char stk1; + stk1 = *D & T; + stk1 = ~stk1; + *D = (stk1 & S) | (stk1 & (~T)) | (T & (~S) & *D); +} + +/* DTan source transparent/pattern opaque. */ +static void rop3_95_1_0 (unsigned char *D, unsigned char S, unsigned char T) +{ + unsigned char stk1; + stk1 = *D & T; + stk1 = ~stk1; + *D = (stk1 & (~S)) | (*D & S); +} + +/* DTan source/pattern transparent. */ +static void rop3_95_1_1 (unsigned char *D, unsigned char S, unsigned char T) +{ + unsigned char stk1; + stk1 = *D & T; + stk1 = ~stk1; + *D = (stk1 & (~S) & (~T)) | (*D & S) | (*D & T); +} + +/* DTan source/pattern opaque. */ +static unsigned xrop3_95_0_0 (unsigned char s, unsigned char t) +{ + unsigned D = 0x00ff; + unsigned T = ((unsigned)t << 8) | t; + unsigned stk1; + stk1 = D & T; + stk1 = ~stk1; + return stk1; +} + +/* DTan source opaque/pattern transparent. */ +static unsigned xrop3_95_0_1 (unsigned char s, unsigned char t) +{ + unsigned D = 0x00ff; + unsigned S = ((unsigned)s << 8) | s; + unsigned T = ((unsigned)t << 8) | t; + unsigned stk1; + stk1 = D & T; + stk1 = ~stk1; + return (stk1 & S) | (stk1 & (~T)) | (T & (~S) & D); +} + +/* DTan source transparent/pattern opaque. */ +static unsigned xrop3_95_1_0 (unsigned char s, unsigned char t) +{ + unsigned D = 0x00ff; + unsigned S = ((unsigned)s << 8) | s; + unsigned T = ((unsigned)t << 8) | t; + unsigned stk1; + stk1 = D & T; + stk1 = ~stk1; + return (stk1 & (~S)) | (D & S); +} + +/* DTan source/pattern transparent. */ +static unsigned xrop3_95_1_1 (unsigned char s, unsigned char t) +{ + unsigned D = 0x00ff; + unsigned S = ((unsigned)s << 8) | s; + unsigned T = ((unsigned)t << 8) | t; + unsigned stk1; + stk1 = D & T; + stk1 = ~stk1; + return (stk1 & (~S) & (~T)) | (D & S) | (D & T); +} + +/* TDSxa source/pattern opaque. */ +static void rop3_96_0_0 (unsigned char *D, unsigned char S, unsigned char T) +{ + unsigned char stk1; + unsigned char stk2; + stk2 = *D ^ S; + stk1 = T & stk2; + *D = stk1; +} + +/* TDSxa source opaque/pattern transparent. */ +static void rop3_96_0_1 (unsigned char *D, unsigned char S, unsigned char T) +{ + unsigned char stk1; + unsigned char stk2; + stk2 = *D ^ S; + stk1 = T & stk2; + *D = (stk1 & S) | (stk1 & (~T)) | (T & (~S) & *D); +} + +/* TDSxa source transparent/pattern opaque. */ +static void rop3_96_1_0 (unsigned char *D, unsigned char S, unsigned char T) +{ + unsigned char stk1; + unsigned char stk2; + stk2 = *D ^ S; + stk1 = T & stk2; + *D = (stk1 & (~S)) | (*D & S); +} + +/* TDSxa source/pattern transparent. */ +static void rop3_96_1_1 (unsigned char *D, unsigned char S, unsigned char T) +{ + unsigned char stk1; + unsigned char stk2; + stk2 = *D ^ S; + stk1 = T & stk2; + *D = (stk1 & (~S) & (~T)) | (*D & S) | (*D & T); +} + +/* TDSxa source/pattern opaque. */ +static unsigned xrop3_96_0_0 (unsigned char s, unsigned char t) +{ + unsigned D = 0x00ff; + unsigned S = ((unsigned)s << 8) | s; + unsigned T = ((unsigned)t << 8) | t; + unsigned stk1; + unsigned stk2; + stk2 = D ^ S; + stk1 = T & stk2; + return stk1; +} + +/* TDSxa source opaque/pattern transparent. */ +static unsigned xrop3_96_0_1 (unsigned char s, unsigned char t) +{ + unsigned D = 0x00ff; + unsigned S = ((unsigned)s << 8) | s; + unsigned T = ((unsigned)t << 8) | t; + unsigned stk1; + unsigned stk2; + stk2 = D ^ S; + stk1 = T & stk2; + return (stk1 & S) | (stk1 & (~T)) | (T & (~S) & D); +} + +/* TDSxa source transparent/pattern opaque. */ +static unsigned xrop3_96_1_0 (unsigned char s, unsigned char t) +{ + unsigned D = 0x00ff; + unsigned S = ((unsigned)s << 8) | s; + unsigned T = ((unsigned)t << 8) | t; + unsigned stk1; + unsigned stk2; + stk2 = D ^ S; + stk1 = T & stk2; + return (stk1 & (~S)) | (D & S); +} + +/* TDSxa source/pattern transparent. */ +static unsigned xrop3_96_1_1 (unsigned char s, unsigned char t) +{ + unsigned D = 0x00ff; + unsigned S = ((unsigned)s << 8) | s; + unsigned T = ((unsigned)t << 8) | t; + unsigned stk1; + unsigned stk2; + stk2 = D ^ S; + stk1 = T & stk2; + return (stk1 & (~S) & (~T)) | (D & S) | (D & T); +} + +/* DSTDSaoxxn source/pattern opaque. */ +static void rop3_97_0_0 (unsigned char *D, unsigned char S, unsigned char T) +{ + unsigned char stk1; + unsigned char stk2; + unsigned char stk3; + unsigned char stk4; + stk4 = *D & S; + stk3 = T | stk4; + stk2 = S ^ stk3; + stk1 = *D ^ stk2; + stk1 = ~stk1; + *D = stk1; +} + +/* DSTDSaoxxn source opaque/pattern transparent. */ +static void rop3_97_0_1 (unsigned char *D, unsigned char S, unsigned char T) +{ + unsigned char stk1; + unsigned char stk2; + unsigned char stk3; + unsigned char stk4; + stk4 = *D & S; + stk3 = T | stk4; + stk2 = S ^ stk3; + stk1 = *D ^ stk2; + stk1 = ~stk1; + *D = (stk1 & S) | (stk1 & (~T)) | (T & (~S) & *D); +} + +/* DSTDSaoxxn source transparent/pattern opaque. */ +static void rop3_97_1_0 (unsigned char *D, unsigned char S, unsigned char T) +{ + unsigned char stk1; + unsigned char stk2; + unsigned char stk3; + unsigned char stk4; + stk4 = *D & S; + stk3 = T | stk4; + stk2 = S ^ stk3; + stk1 = *D ^ stk2; + stk1 = ~stk1; + *D = (stk1 & (~S)) | (*D & S); +} + +/* DSTDSaoxxn source/pattern transparent. */ +static void rop3_97_1_1 (unsigned char *D, unsigned char S, unsigned char T) +{ + unsigned char stk1; + unsigned char stk2; + unsigned char stk3; + unsigned char stk4; + stk4 = *D & S; + stk3 = T | stk4; + stk2 = S ^ stk3; + stk1 = *D ^ stk2; + stk1 = ~stk1; + *D = (stk1 & (~S) & (~T)) | (*D & S) | (*D & T); +} + +/* DSTDSaoxxn source/pattern opaque. */ +static unsigned xrop3_97_0_0 (unsigned char s, unsigned char t) +{ + unsigned D = 0x00ff; + unsigned S = ((unsigned)s << 8) | s; + unsigned T = ((unsigned)t << 8) | t; + unsigned stk1; + unsigned stk2; + unsigned stk3; + unsigned stk4; + stk4 = D & S; + stk3 = T | stk4; + stk2 = S ^ stk3; + stk1 = D ^ stk2; + stk1 = ~stk1; + return stk1; +} + +/* DSTDSaoxxn source opaque/pattern transparent. */ +static unsigned xrop3_97_0_1 (unsigned char s, unsigned char t) +{ + unsigned D = 0x00ff; + unsigned S = ((unsigned)s << 8) | s; + unsigned T = ((unsigned)t << 8) | t; + unsigned stk1; + unsigned stk2; + unsigned stk3; + unsigned stk4; + stk4 = D & S; + stk3 = T | stk4; + stk2 = S ^ stk3; + stk1 = D ^ stk2; + stk1 = ~stk1; + return (stk1 & S) | (stk1 & (~T)) | (T & (~S) & D); +} + +/* DSTDSaoxxn source transparent/pattern opaque. */ +static unsigned xrop3_97_1_0 (unsigned char s, unsigned char t) +{ + unsigned D = 0x00ff; + unsigned S = ((unsigned)s << 8) | s; + unsigned T = ((unsigned)t << 8) | t; + unsigned stk1; + unsigned stk2; + unsigned stk3; + unsigned stk4; + stk4 = D & S; + stk3 = T | stk4; + stk2 = S ^ stk3; + stk1 = D ^ stk2; + stk1 = ~stk1; + return (stk1 & (~S)) | (D & S); +} + +/* DSTDSaoxxn source/pattern transparent. */ +static unsigned xrop3_97_1_1 (unsigned char s, unsigned char t) +{ + unsigned D = 0x00ff; + unsigned S = ((unsigned)s << 8) | s; + unsigned T = ((unsigned)t << 8) | t; + unsigned stk1; + unsigned stk2; + unsigned stk3; + unsigned stk4; + stk4 = D & S; + stk3 = T | stk4; + stk2 = S ^ stk3; + stk1 = D ^ stk2; + stk1 = ~stk1; + return (stk1 & (~S) & (~T)) | (D & S) | (D & T); +} + +/* DSTDoax source/pattern opaque. */ +static void rop3_98_0_0 (unsigned char *D, unsigned char S, unsigned char T) +{ + unsigned char stk1; + unsigned char stk2; + unsigned char stk3; + stk3 = T | *D; + stk2 = S & stk3; + stk1 = *D ^ stk2; + *D = stk1; +} + +/* DSTDoax source opaque/pattern transparent. */ +static void rop3_98_0_1 (unsigned char *D, unsigned char S, unsigned char T) +{ + unsigned char stk1; + unsigned char stk2; + unsigned char stk3; + stk3 = T | *D; + stk2 = S & stk3; + stk1 = *D ^ stk2; + *D = (stk1 & S) | (stk1 & (~T)) | (T & (~S) & *D); +} + +/* DSTDoax source transparent/pattern opaque. */ +static void rop3_98_1_0 (unsigned char *D, unsigned char S, unsigned char T) +{ + unsigned char stk1; + unsigned char stk2; + unsigned char stk3; + stk3 = T | *D; + stk2 = S & stk3; + stk1 = *D ^ stk2; + *D = (stk1 & (~S)) | (*D & S); +} + +/* DSTDoax source/pattern transparent. */ +static void rop3_98_1_1 (unsigned char *D, unsigned char S, unsigned char T) +{ + unsigned char stk1; + unsigned char stk2; + unsigned char stk3; + stk3 = T | *D; + stk2 = S & stk3; + stk1 = *D ^ stk2; + *D = (stk1 & (~S) & (~T)) | (*D & S) | (*D & T); +} + +/* DSTDoax source/pattern opaque. */ +static unsigned xrop3_98_0_0 (unsigned char s, unsigned char t) +{ + unsigned D = 0x00ff; + unsigned S = ((unsigned)s << 8) | s; + unsigned T = ((unsigned)t << 8) | t; + unsigned stk1; + unsigned stk2; + unsigned stk3; + stk3 = T | D; + stk2 = S & stk3; + stk1 = D ^ stk2; + return stk1; +} + +/* DSTDoax source opaque/pattern transparent. */ +static unsigned xrop3_98_0_1 (unsigned char s, unsigned char t) +{ + unsigned D = 0x00ff; + unsigned S = ((unsigned)s << 8) | s; + unsigned T = ((unsigned)t << 8) | t; + unsigned stk1; + unsigned stk2; + unsigned stk3; + stk3 = T | D; + stk2 = S & stk3; + stk1 = D ^ stk2; + return (stk1 & S) | (stk1 & (~T)) | (T & (~S) & D); +} + +/* DSTDoax source transparent/pattern opaque. */ +static unsigned xrop3_98_1_0 (unsigned char s, unsigned char t) +{ + unsigned D = 0x00ff; + unsigned S = ((unsigned)s << 8) | s; + unsigned T = ((unsigned)t << 8) | t; + unsigned stk1; + unsigned stk2; + unsigned stk3; + stk3 = T | D; + stk2 = S & stk3; + stk1 = D ^ stk2; + return (stk1 & (~S)) | (D & S); +} + +/* DSTDoax source/pattern transparent. */ +static unsigned xrop3_98_1_1 (unsigned char s, unsigned char t) +{ + unsigned D = 0x00ff; + unsigned S = ((unsigned)s << 8) | s; + unsigned T = ((unsigned)t << 8) | t; + unsigned stk1; + unsigned stk2; + unsigned stk3; + stk3 = T | D; + stk2 = S & stk3; + stk1 = D ^ stk2; + return (stk1 & (~S) & (~T)) | (D & S) | (D & T); +} + +/* SDTnox source/pattern opaque. */ +static void rop3_99_0_0 (unsigned char *D, unsigned char S, unsigned char T) +{ + unsigned char stk1; + unsigned char stk2; + unsigned char stk3; + stk3 = ~T; + stk2 = *D | stk3; + stk1 = S ^ stk2; + *D = stk1; +} + +/* SDTnox source opaque/pattern transparent. */ +static void rop3_99_0_1 (unsigned char *D, unsigned char S, unsigned char T) +{ + unsigned char stk1; + unsigned char stk2; + unsigned char stk3; + stk3 = ~T; + stk2 = *D | stk3; + stk1 = S ^ stk2; + *D = (stk1 & S) | (stk1 & (~T)) | (T & (~S) & *D); +} + +/* SDTnox source transparent/pattern opaque. */ +static void rop3_99_1_0 (unsigned char *D, unsigned char S, unsigned char T) +{ + unsigned char stk1; + unsigned char stk2; + unsigned char stk3; + stk3 = ~T; + stk2 = *D | stk3; + stk1 = S ^ stk2; + *D = (stk1 & (~S)) | (*D & S); +} + +/* SDTnox source/pattern transparent. */ +static void rop3_99_1_1 (unsigned char *D, unsigned char S, unsigned char T) +{ + unsigned char stk1; + unsigned char stk2; + unsigned char stk3; + stk3 = ~T; + stk2 = *D | stk3; + stk1 = S ^ stk2; + *D = (stk1 & (~S) & (~T)) | (*D & S) | (*D & T); +} + +/* SDTnox source/pattern opaque. */ +static unsigned xrop3_99_0_0 (unsigned char s, unsigned char t) +{ + unsigned D = 0x00ff; + unsigned S = ((unsigned)s << 8) | s; + unsigned T = ((unsigned)t << 8) | t; + unsigned stk1; + unsigned stk2; + unsigned stk3; + stk3 = ~T; + stk2 = D | stk3; + stk1 = S ^ stk2; + return stk1; +} + +/* SDTnox source opaque/pattern transparent. */ +static unsigned xrop3_99_0_1 (unsigned char s, unsigned char t) +{ + unsigned D = 0x00ff; + unsigned S = ((unsigned)s << 8) | s; + unsigned T = ((unsigned)t << 8) | t; + unsigned stk1; + unsigned stk2; + unsigned stk3; + stk3 = ~T; + stk2 = D | stk3; + stk1 = S ^ stk2; + return (stk1 & S) | (stk1 & (~T)) | (T & (~S) & D); +} + +/* SDTnox source transparent/pattern opaque. */ +static unsigned xrop3_99_1_0 (unsigned char s, unsigned char t) +{ + unsigned D = 0x00ff; + unsigned S = ((unsigned)s << 8) | s; + unsigned T = ((unsigned)t << 8) | t; + unsigned stk1; + unsigned stk2; + unsigned stk3; + stk3 = ~T; + stk2 = D | stk3; + stk1 = S ^ stk2; + return (stk1 & (~S)) | (D & S); +} + +/* SDTnox source/pattern transparent. */ +static unsigned xrop3_99_1_1 (unsigned char s, unsigned char t) +{ + unsigned D = 0x00ff; + unsigned S = ((unsigned)s << 8) | s; + unsigned T = ((unsigned)t << 8) | t; + unsigned stk1; + unsigned stk2; + unsigned stk3; + stk3 = ~T; + stk2 = D | stk3; + stk1 = S ^ stk2; + return (stk1 & (~S) & (~T)) | (D & S) | (D & T); +} + +/* SDTSoax source/pattern opaque. */ +static void rop3_100_0_0 (unsigned char *D, unsigned char S, unsigned char T) +{ + unsigned char stk1; + unsigned char stk2; + unsigned char stk3; + stk3 = T | S; + stk2 = *D & stk3; + stk1 = S ^ stk2; + *D = stk1; +} + +/* SDTSoax source opaque/pattern transparent. */ +static void rop3_100_0_1 (unsigned char *D, unsigned char S, unsigned char T) +{ + unsigned char stk1; + unsigned char stk2; + unsigned char stk3; + stk3 = T | S; + stk2 = *D & stk3; + stk1 = S ^ stk2; + *D = (stk1 & S) | (stk1 & (~T)) | (T & (~S) & *D); +} + +/* SDTSoax source transparent/pattern opaque. */ +static void rop3_100_1_0 (unsigned char *D, unsigned char S, unsigned char T) +{ + unsigned char stk1; + unsigned char stk2; + unsigned char stk3; + stk3 = T | S; + stk2 = *D & stk3; + stk1 = S ^ stk2; + *D = (stk1 & (~S)) | (*D & S); +} + +/* SDTSoax source/pattern transparent. */ +static void rop3_100_1_1 (unsigned char *D, unsigned char S, unsigned char T) +{ + unsigned char stk1; + unsigned char stk2; + unsigned char stk3; + stk3 = T | S; + stk2 = *D & stk3; + stk1 = S ^ stk2; + *D = (stk1 & (~S) & (~T)) | (*D & S) | (*D & T); +} + +/* SDTSoax source/pattern opaque. */ +static unsigned xrop3_100_0_0 (unsigned char s, unsigned char t) +{ + unsigned D = 0x00ff; + unsigned S = ((unsigned)s << 8) | s; + unsigned T = ((unsigned)t << 8) | t; + unsigned stk1; + unsigned stk2; + unsigned stk3; + stk3 = T | S; + stk2 = D & stk3; + stk1 = S ^ stk2; + return stk1; +} + +/* SDTSoax source opaque/pattern transparent. */ +static unsigned xrop3_100_0_1 (unsigned char s, unsigned char t) +{ + unsigned D = 0x00ff; + unsigned S = ((unsigned)s << 8) | s; + unsigned T = ((unsigned)t << 8) | t; + unsigned stk1; + unsigned stk2; + unsigned stk3; + stk3 = T | S; + stk2 = D & stk3; + stk1 = S ^ stk2; + return (stk1 & S) | (stk1 & (~T)) | (T & (~S) & D); +} + +/* SDTSoax source transparent/pattern opaque. */ +static unsigned xrop3_100_1_0 (unsigned char s, unsigned char t) +{ + unsigned D = 0x00ff; + unsigned S = ((unsigned)s << 8) | s; + unsigned T = ((unsigned)t << 8) | t; + unsigned stk1; + unsigned stk2; + unsigned stk3; + stk3 = T | S; + stk2 = D & stk3; + stk1 = S ^ stk2; + return (stk1 & (~S)) | (D & S); +} + +/* SDTSoax source/pattern transparent. */ +static unsigned xrop3_100_1_1 (unsigned char s, unsigned char t) +{ + unsigned D = 0x00ff; + unsigned S = ((unsigned)s << 8) | s; + unsigned T = ((unsigned)t << 8) | t; + unsigned stk1; + unsigned stk2; + unsigned stk3; + stk3 = T | S; + stk2 = D & stk3; + stk1 = S ^ stk2; + return (stk1 & (~S) & (~T)) | (D & S) | (D & T); +} + +/* DSTnox source/pattern opaque. */ +static void rop3_101_0_0 (unsigned char *D, unsigned char S, unsigned char T) +{ + unsigned char stk1; + unsigned char stk2; + unsigned char stk3; + stk3 = ~T; + stk2 = S | stk3; + stk1 = *D ^ stk2; + *D = stk1; +} + +/* DSTnox source opaque/pattern transparent. */ +static void rop3_101_0_1 (unsigned char *D, unsigned char S, unsigned char T) +{ + unsigned char stk1; + unsigned char stk2; + unsigned char stk3; + stk3 = ~T; + stk2 = S | stk3; + stk1 = *D ^ stk2; + *D = (stk1 & S) | (stk1 & (~T)) | (T & (~S) & *D); +} + +/* DSTnox source transparent/pattern opaque. */ +static void rop3_101_1_0 (unsigned char *D, unsigned char S, unsigned char T) +{ + unsigned char stk1; + unsigned char stk2; + unsigned char stk3; + stk3 = ~T; + stk2 = S | stk3; + stk1 = *D ^ stk2; + *D = (stk1 & (~S)) | (*D & S); +} + +/* DSTnox source/pattern transparent. */ +static void rop3_101_1_1 (unsigned char *D, unsigned char S, unsigned char T) +{ + unsigned char stk1; + unsigned char stk2; + unsigned char stk3; + stk3 = ~T; + stk2 = S | stk3; + stk1 = *D ^ stk2; + *D = (stk1 & (~S) & (~T)) | (*D & S) | (*D & T); +} + +/* DSTnox source/pattern opaque. */ +static unsigned xrop3_101_0_0 (unsigned char s, unsigned char t) +{ + unsigned D = 0x00ff; + unsigned S = ((unsigned)s << 8) | s; + unsigned T = ((unsigned)t << 8) | t; + unsigned stk1; + unsigned stk2; + unsigned stk3; + stk3 = ~T; + stk2 = S | stk3; + stk1 = D ^ stk2; + return stk1; +} + +/* DSTnox source opaque/pattern transparent. */ +static unsigned xrop3_101_0_1 (unsigned char s, unsigned char t) +{ + unsigned D = 0x00ff; + unsigned S = ((unsigned)s << 8) | s; + unsigned T = ((unsigned)t << 8) | t; + unsigned stk1; + unsigned stk2; + unsigned stk3; + stk3 = ~T; + stk2 = S | stk3; + stk1 = D ^ stk2; + return (stk1 & S) | (stk1 & (~T)) | (T & (~S) & D); +} + +/* DSTnox source transparent/pattern opaque. */ +static unsigned xrop3_101_1_0 (unsigned char s, unsigned char t) +{ + unsigned D = 0x00ff; + unsigned S = ((unsigned)s << 8) | s; + unsigned T = ((unsigned)t << 8) | t; + unsigned stk1; + unsigned stk2; + unsigned stk3; + stk3 = ~T; + stk2 = S | stk3; + stk1 = D ^ stk2; + return (stk1 & (~S)) | (D & S); +} + +/* DSTnox source/pattern transparent. */ +static unsigned xrop3_101_1_1 (unsigned char s, unsigned char t) +{ + unsigned D = 0x00ff; + unsigned S = ((unsigned)s << 8) | s; + unsigned T = ((unsigned)t << 8) | t; + unsigned stk1; + unsigned stk2; + unsigned stk3; + stk3 = ~T; + stk2 = S | stk3; + stk1 = D ^ stk2; + return (stk1 & (~S) & (~T)) | (D & S) | (D & T); +} + +/* DSx source/pattern opaque. */ +static void rop3_102_0_0 (unsigned char *D, unsigned char S, unsigned char T) +{ + unsigned char stk1; + stk1 = *D ^ S; + *D = stk1; +} + +/* DSx source opaque/pattern transparent. */ +static void rop3_102_0_1 (unsigned char *D, unsigned char S, unsigned char T) +{ + unsigned char stk1; + stk1 = *D ^ S; + *D = (stk1 & S) | (stk1 & (~T)) | (T & (~S) & *D); +} + +/* DSx source transparent/pattern opaque. */ +static void rop3_102_1_0 (unsigned char *D, unsigned char S, unsigned char T) +{ + unsigned char stk1; + stk1 = *D ^ S; + *D = (stk1 & (~S)) | (*D & S); +} + +/* DSx source/pattern transparent. */ +static void rop3_102_1_1 (unsigned char *D, unsigned char S, unsigned char T) +{ + unsigned char stk1; + stk1 = *D ^ S; + *D = (stk1 & (~S) & (~T)) | (*D & S) | (*D & T); +} + +/* DSx source/pattern opaque. */ +static unsigned xrop3_102_0_0 (unsigned char s, unsigned char t) +{ + unsigned D = 0x00ff; + unsigned S = ((unsigned)s << 8) | s; + unsigned stk1; + stk1 = D ^ S; + return stk1; +} + +/* DSx source opaque/pattern transparent. */ +static unsigned xrop3_102_0_1 (unsigned char s, unsigned char t) +{ + unsigned D = 0x00ff; + unsigned S = ((unsigned)s << 8) | s; + unsigned T = ((unsigned)t << 8) | t; + unsigned stk1; + stk1 = D ^ S; + return (stk1 & S) | (stk1 & (~T)) | (T & (~S) & D); +} + +/* DSx source transparent/pattern opaque. */ +static unsigned xrop3_102_1_0 (unsigned char s, unsigned char t) +{ + unsigned D = 0x00ff; + unsigned S = ((unsigned)s << 8) | s; + unsigned stk1; + stk1 = D ^ S; + return (stk1 & (~S)) | (D & S); +} + +/* DSx source/pattern transparent. */ +static unsigned xrop3_102_1_1 (unsigned char s, unsigned char t) +{ + unsigned D = 0x00ff; + unsigned S = ((unsigned)s << 8) | s; + unsigned T = ((unsigned)t << 8) | t; + unsigned stk1; + stk1 = D ^ S; + return (stk1 & (~S) & (~T)) | (D & S) | (D & T); +} + +/* SDTSonox source/pattern opaque. */ +static void rop3_103_0_0 (unsigned char *D, unsigned char S, unsigned char T) +{ + unsigned char stk1; + unsigned char stk2; + unsigned char stk3; + stk3 = T | S; + stk3 = ~stk3; + stk2 = *D | stk3; + stk1 = S ^ stk2; + *D = stk1; +} + +/* SDTSonox source opaque/pattern transparent. */ +static void rop3_103_0_1 (unsigned char *D, unsigned char S, unsigned char T) +{ + unsigned char stk1; + unsigned char stk2; + unsigned char stk3; + stk3 = T | S; + stk3 = ~stk3; + stk2 = *D | stk3; + stk1 = S ^ stk2; + *D = (stk1 & S) | (stk1 & (~T)) | (T & (~S) & *D); +} + +/* SDTSonox source transparent/pattern opaque. */ +static void rop3_103_1_0 (unsigned char *D, unsigned char S, unsigned char T) +{ + unsigned char stk1; + unsigned char stk2; + unsigned char stk3; + stk3 = T | S; + stk3 = ~stk3; + stk2 = *D | stk3; + stk1 = S ^ stk2; + *D = (stk1 & (~S)) | (*D & S); +} + +/* SDTSonox source/pattern transparent. */ +static void rop3_103_1_1 (unsigned char *D, unsigned char S, unsigned char T) +{ + unsigned char stk1; + unsigned char stk2; + unsigned char stk3; + stk3 = T | S; + stk3 = ~stk3; + stk2 = *D | stk3; + stk1 = S ^ stk2; + *D = (stk1 & (~S) & (~T)) | (*D & S) | (*D & T); +} + +/* SDTSonox source/pattern opaque. */ +static unsigned xrop3_103_0_0 (unsigned char s, unsigned char t) +{ + unsigned D = 0x00ff; + unsigned S = ((unsigned)s << 8) | s; + unsigned T = ((unsigned)t << 8) | t; + unsigned stk1; + unsigned stk2; + unsigned stk3; + stk3 = T | S; + stk3 = ~stk3; + stk2 = D | stk3; + stk1 = S ^ stk2; + return stk1; +} + +/* SDTSonox source opaque/pattern transparent. */ +static unsigned xrop3_103_0_1 (unsigned char s, unsigned char t) +{ + unsigned D = 0x00ff; + unsigned S = ((unsigned)s << 8) | s; + unsigned T = ((unsigned)t << 8) | t; + unsigned stk1; + unsigned stk2; + unsigned stk3; + stk3 = T | S; + stk3 = ~stk3; + stk2 = D | stk3; + stk1 = S ^ stk2; + return (stk1 & S) | (stk1 & (~T)) | (T & (~S) & D); +} + +/* SDTSonox source transparent/pattern opaque. */ +static unsigned xrop3_103_1_0 (unsigned char s, unsigned char t) +{ + unsigned D = 0x00ff; + unsigned S = ((unsigned)s << 8) | s; + unsigned T = ((unsigned)t << 8) | t; + unsigned stk1; + unsigned stk2; + unsigned stk3; + stk3 = T | S; + stk3 = ~stk3; + stk2 = D | stk3; + stk1 = S ^ stk2; + return (stk1 & (~S)) | (D & S); +} + +/* SDTSonox source/pattern transparent. */ +static unsigned xrop3_103_1_1 (unsigned char s, unsigned char t) +{ + unsigned D = 0x00ff; + unsigned S = ((unsigned)s << 8) | s; + unsigned T = ((unsigned)t << 8) | t; + unsigned stk1; + unsigned stk2; + unsigned stk3; + stk3 = T | S; + stk3 = ~stk3; + stk2 = D | stk3; + stk1 = S ^ stk2; + return (stk1 & (~S) & (~T)) | (D & S) | (D & T); +} + +/* DSTDSonoxxn source/pattern opaque. */ +static void rop3_104_0_0 (unsigned char *D, unsigned char S, unsigned char T) +{ + unsigned char stk1; + unsigned char stk2; + unsigned char stk3; + unsigned char stk4; + stk4 = *D | S; + stk4 = ~stk4; + stk3 = T | stk4; + stk2 = S ^ stk3; + stk1 = *D ^ stk2; + stk1 = ~stk1; + *D = stk1; +} + +/* DSTDSonoxxn source opaque/pattern transparent. */ +static void rop3_104_0_1 (unsigned char *D, unsigned char S, unsigned char T) +{ + unsigned char stk1; + unsigned char stk2; + unsigned char stk3; + unsigned char stk4; + stk4 = *D | S; + stk4 = ~stk4; + stk3 = T | stk4; + stk2 = S ^ stk3; + stk1 = *D ^ stk2; + stk1 = ~stk1; + *D = (stk1 & S) | (stk1 & (~T)) | (T & (~S) & *D); +} + +/* DSTDSonoxxn source transparent/pattern opaque. */ +static void rop3_104_1_0 (unsigned char *D, unsigned char S, unsigned char T) +{ + unsigned char stk1; + unsigned char stk2; + unsigned char stk3; + unsigned char stk4; + stk4 = *D | S; + stk4 = ~stk4; + stk3 = T | stk4; + stk2 = S ^ stk3; + stk1 = *D ^ stk2; + stk1 = ~stk1; + *D = (stk1 & (~S)) | (*D & S); +} + +/* DSTDSonoxxn source/pattern transparent. */ +static void rop3_104_1_1 (unsigned char *D, unsigned char S, unsigned char T) +{ + unsigned char stk1; + unsigned char stk2; + unsigned char stk3; + unsigned char stk4; + stk4 = *D | S; + stk4 = ~stk4; + stk3 = T | stk4; + stk2 = S ^ stk3; + stk1 = *D ^ stk2; + stk1 = ~stk1; + *D = (stk1 & (~S) & (~T)) | (*D & S) | (*D & T); +} + +/* DSTDSonoxxn source/pattern opaque. */ +static unsigned xrop3_104_0_0 (unsigned char s, unsigned char t) +{ + unsigned D = 0x00ff; + unsigned S = ((unsigned)s << 8) | s; + unsigned T = ((unsigned)t << 8) | t; + unsigned stk1; + unsigned stk2; + unsigned stk3; + unsigned stk4; + stk4 = D | S; + stk4 = ~stk4; + stk3 = T | stk4; + stk2 = S ^ stk3; + stk1 = D ^ stk2; + stk1 = ~stk1; + return stk1; +} + +/* DSTDSonoxxn source opaque/pattern transparent. */ +static unsigned xrop3_104_0_1 (unsigned char s, unsigned char t) +{ + unsigned D = 0x00ff; + unsigned S = ((unsigned)s << 8) | s; + unsigned T = ((unsigned)t << 8) | t; + unsigned stk1; + unsigned stk2; + unsigned stk3; + unsigned stk4; + stk4 = D | S; + stk4 = ~stk4; + stk3 = T | stk4; + stk2 = S ^ stk3; + stk1 = D ^ stk2; + stk1 = ~stk1; + return (stk1 & S) | (stk1 & (~T)) | (T & (~S) & D); +} + +/* DSTDSonoxxn source transparent/pattern opaque. */ +static unsigned xrop3_104_1_0 (unsigned char s, unsigned char t) +{ + unsigned D = 0x00ff; + unsigned S = ((unsigned)s << 8) | s; + unsigned T = ((unsigned)t << 8) | t; + unsigned stk1; + unsigned stk2; + unsigned stk3; + unsigned stk4; + stk4 = D | S; + stk4 = ~stk4; + stk3 = T | stk4; + stk2 = S ^ stk3; + stk1 = D ^ stk2; + stk1 = ~stk1; + return (stk1 & (~S)) | (D & S); +} + +/* DSTDSonoxxn source/pattern transparent. */ +static unsigned xrop3_104_1_1 (unsigned char s, unsigned char t) +{ + unsigned D = 0x00ff; + unsigned S = ((unsigned)s << 8) | s; + unsigned T = ((unsigned)t << 8) | t; + unsigned stk1; + unsigned stk2; + unsigned stk3; + unsigned stk4; + stk4 = D | S; + stk4 = ~stk4; + stk3 = T | stk4; + stk2 = S ^ stk3; + stk1 = D ^ stk2; + stk1 = ~stk1; + return (stk1 & (~S) & (~T)) | (D & S) | (D & T); +} + +/* TDSxxn source/pattern opaque. */ +static void rop3_105_0_0 (unsigned char *D, unsigned char S, unsigned char T) +{ + unsigned char stk1; + unsigned char stk2; + stk2 = *D ^ S; + stk1 = T ^ stk2; + stk1 = ~stk1; + *D = stk1; +} + +/* TDSxxn source opaque/pattern transparent. */ +static void rop3_105_0_1 (unsigned char *D, unsigned char S, unsigned char T) +{ + unsigned char stk1; + unsigned char stk2; + stk2 = *D ^ S; + stk1 = T ^ stk2; + stk1 = ~stk1; + *D = (stk1 & S) | (stk1 & (~T)) | (T & (~S) & *D); +} + +/* TDSxxn source transparent/pattern opaque. */ +static void rop3_105_1_0 (unsigned char *D, unsigned char S, unsigned char T) +{ + unsigned char stk1; + unsigned char stk2; + stk2 = *D ^ S; + stk1 = T ^ stk2; + stk1 = ~stk1; + *D = (stk1 & (~S)) | (*D & S); +} + +/* TDSxxn source/pattern transparent. */ +static void rop3_105_1_1 (unsigned char *D, unsigned char S, unsigned char T) +{ + unsigned char stk1; + unsigned char stk2; + stk2 = *D ^ S; + stk1 = T ^ stk2; + stk1 = ~stk1; + *D = (stk1 & (~S) & (~T)) | (*D & S) | (*D & T); +} + +/* TDSxxn source/pattern opaque. */ +static unsigned xrop3_105_0_0 (unsigned char s, unsigned char t) +{ + unsigned D = 0x00ff; + unsigned S = ((unsigned)s << 8) | s; + unsigned T = ((unsigned)t << 8) | t; + unsigned stk1; + unsigned stk2; + stk2 = D ^ S; + stk1 = T ^ stk2; + stk1 = ~stk1; + return stk1; +} + +/* TDSxxn source opaque/pattern transparent. */ +static unsigned xrop3_105_0_1 (unsigned char s, unsigned char t) +{ + unsigned D = 0x00ff; + unsigned S = ((unsigned)s << 8) | s; + unsigned T = ((unsigned)t << 8) | t; + unsigned stk1; + unsigned stk2; + stk2 = D ^ S; + stk1 = T ^ stk2; + stk1 = ~stk1; + return (stk1 & S) | (stk1 & (~T)) | (T & (~S) & D); +} + +/* TDSxxn source transparent/pattern opaque. */ +static unsigned xrop3_105_1_0 (unsigned char s, unsigned char t) +{ + unsigned D = 0x00ff; + unsigned S = ((unsigned)s << 8) | s; + unsigned T = ((unsigned)t << 8) | t; + unsigned stk1; + unsigned stk2; + stk2 = D ^ S; + stk1 = T ^ stk2; + stk1 = ~stk1; + return (stk1 & (~S)) | (D & S); +} + +/* TDSxxn source/pattern transparent. */ +static unsigned xrop3_105_1_1 (unsigned char s, unsigned char t) +{ + unsigned D = 0x00ff; + unsigned S = ((unsigned)s << 8) | s; + unsigned T = ((unsigned)t << 8) | t; + unsigned stk1; + unsigned stk2; + stk2 = D ^ S; + stk1 = T ^ stk2; + stk1 = ~stk1; + return (stk1 & (~S) & (~T)) | (D & S) | (D & T); +} + +/* DTSax source/pattern opaque. */ +static void rop3_106_0_0 (unsigned char *D, unsigned char S, unsigned char T) +{ + unsigned char stk1; + unsigned char stk2; + stk2 = T & S; + stk1 = *D ^ stk2; + *D = stk1; +} + +/* DTSax source opaque/pattern transparent. */ +static void rop3_106_0_1 (unsigned char *D, unsigned char S, unsigned char T) +{ + unsigned char stk1; + unsigned char stk2; + stk2 = T & S; + stk1 = *D ^ stk2; + *D = (stk1 & S) | (stk1 & (~T)) | (T & (~S) & *D); +} + +/* DTSax source transparent/pattern opaque. */ +static void rop3_106_1_0 (unsigned char *D, unsigned char S, unsigned char T) +{ + unsigned char stk1; + unsigned char stk2; + stk2 = T & S; + stk1 = *D ^ stk2; + *D = (stk1 & (~S)) | (*D & S); +} + +/* DTSax source/pattern transparent. */ +static void rop3_106_1_1 (unsigned char *D, unsigned char S, unsigned char T) +{ + unsigned char stk1; + unsigned char stk2; + stk2 = T & S; + stk1 = *D ^ stk2; + *D = (stk1 & (~S) & (~T)) | (*D & S) | (*D & T); +} + +/* DTSax source/pattern opaque. */ +static unsigned xrop3_106_0_0 (unsigned char s, unsigned char t) +{ + unsigned D = 0x00ff; + unsigned S = ((unsigned)s << 8) | s; + unsigned T = ((unsigned)t << 8) | t; + unsigned stk1; + unsigned stk2; + stk2 = T & S; + stk1 = D ^ stk2; + return stk1; +} + +/* DTSax source opaque/pattern transparent. */ +static unsigned xrop3_106_0_1 (unsigned char s, unsigned char t) +{ + unsigned D = 0x00ff; + unsigned S = ((unsigned)s << 8) | s; + unsigned T = ((unsigned)t << 8) | t; + unsigned stk1; + unsigned stk2; + stk2 = T & S; + stk1 = D ^ stk2; + return (stk1 & S) | (stk1 & (~T)) | (T & (~S) & D); +} + +/* DTSax source transparent/pattern opaque. */ +static unsigned xrop3_106_1_0 (unsigned char s, unsigned char t) +{ + unsigned D = 0x00ff; + unsigned S = ((unsigned)s << 8) | s; + unsigned T = ((unsigned)t << 8) | t; + unsigned stk1; + unsigned stk2; + stk2 = T & S; + stk1 = D ^ stk2; + return (stk1 & (~S)) | (D & S); +} + +/* DTSax source/pattern transparent. */ +static unsigned xrop3_106_1_1 (unsigned char s, unsigned char t) +{ + unsigned D = 0x00ff; + unsigned S = ((unsigned)s << 8) | s; + unsigned T = ((unsigned)t << 8) | t; + unsigned stk1; + unsigned stk2; + stk2 = T & S; + stk1 = D ^ stk2; + return (stk1 & (~S) & (~T)) | (D & S) | (D & T); +} + +/* TSDTSoaxxn source/pattern opaque. */ +static void rop3_107_0_0 (unsigned char *D, unsigned char S, unsigned char T) +{ + unsigned char stk1; + unsigned char stk2; + unsigned char stk3; + unsigned char stk4; + stk4 = T | S; + stk3 = *D & stk4; + stk2 = S ^ stk3; + stk1 = T ^ stk2; + stk1 = ~stk1; + *D = stk1; +} + +/* TSDTSoaxxn source opaque/pattern transparent. */ +static void rop3_107_0_1 (unsigned char *D, unsigned char S, unsigned char T) +{ + unsigned char stk1; + unsigned char stk2; + unsigned char stk3; + unsigned char stk4; + stk4 = T | S; + stk3 = *D & stk4; + stk2 = S ^ stk3; + stk1 = T ^ stk2; + stk1 = ~stk1; + *D = (stk1 & S) | (stk1 & (~T)) | (T & (~S) & *D); +} + +/* TSDTSoaxxn source transparent/pattern opaque. */ +static void rop3_107_1_0 (unsigned char *D, unsigned char S, unsigned char T) +{ + unsigned char stk1; + unsigned char stk2; + unsigned char stk3; + unsigned char stk4; + stk4 = T | S; + stk3 = *D & stk4; + stk2 = S ^ stk3; + stk1 = T ^ stk2; + stk1 = ~stk1; + *D = (stk1 & (~S)) | (*D & S); +} + +/* TSDTSoaxxn source/pattern transparent. */ +static void rop3_107_1_1 (unsigned char *D, unsigned char S, unsigned char T) +{ + unsigned char stk1; + unsigned char stk2; + unsigned char stk3; + unsigned char stk4; + stk4 = T | S; + stk3 = *D & stk4; + stk2 = S ^ stk3; + stk1 = T ^ stk2; + stk1 = ~stk1; + *D = (stk1 & (~S) & (~T)) | (*D & S) | (*D & T); +} + +/* TSDTSoaxxn source/pattern opaque. */ +static unsigned xrop3_107_0_0 (unsigned char s, unsigned char t) +{ + unsigned D = 0x00ff; + unsigned S = ((unsigned)s << 8) | s; + unsigned T = ((unsigned)t << 8) | t; + unsigned stk1; + unsigned stk2; + unsigned stk3; + unsigned stk4; + stk4 = T | S; + stk3 = D & stk4; + stk2 = S ^ stk3; + stk1 = T ^ stk2; + stk1 = ~stk1; + return stk1; +} + +/* TSDTSoaxxn source opaque/pattern transparent. */ +static unsigned xrop3_107_0_1 (unsigned char s, unsigned char t) +{ + unsigned D = 0x00ff; + unsigned S = ((unsigned)s << 8) | s; + unsigned T = ((unsigned)t << 8) | t; + unsigned stk1; + unsigned stk2; + unsigned stk3; + unsigned stk4; + stk4 = T | S; + stk3 = D & stk4; + stk2 = S ^ stk3; + stk1 = T ^ stk2; + stk1 = ~stk1; + return (stk1 & S) | (stk1 & (~T)) | (T & (~S) & D); +} + +/* TSDTSoaxxn source transparent/pattern opaque. */ +static unsigned xrop3_107_1_0 (unsigned char s, unsigned char t) +{ + unsigned D = 0x00ff; + unsigned S = ((unsigned)s << 8) | s; + unsigned T = ((unsigned)t << 8) | t; + unsigned stk1; + unsigned stk2; + unsigned stk3; + unsigned stk4; + stk4 = T | S; + stk3 = D & stk4; + stk2 = S ^ stk3; + stk1 = T ^ stk2; + stk1 = ~stk1; + return (stk1 & (~S)) | (D & S); +} + +/* TSDTSoaxxn source/pattern transparent. */ +static unsigned xrop3_107_1_1 (unsigned char s, unsigned char t) +{ + unsigned D = 0x00ff; + unsigned S = ((unsigned)s << 8) | s; + unsigned T = ((unsigned)t << 8) | t; + unsigned stk1; + unsigned stk2; + unsigned stk3; + unsigned stk4; + stk4 = T | S; + stk3 = D & stk4; + stk2 = S ^ stk3; + stk1 = T ^ stk2; + stk1 = ~stk1; + return (stk1 & (~S) & (~T)) | (D & S) | (D & T); +} + +/* SDTax source/pattern opaque. */ +static void rop3_108_0_0 (unsigned char *D, unsigned char S, unsigned char T) +{ + unsigned char stk1; + unsigned char stk2; + stk2 = *D & T; + stk1 = S ^ stk2; + *D = stk1; +} + +/* SDTax source opaque/pattern transparent. */ +static void rop3_108_0_1 (unsigned char *D, unsigned char S, unsigned char T) +{ + unsigned char stk1; + unsigned char stk2; + stk2 = *D & T; + stk1 = S ^ stk2; + *D = (stk1 & S) | (stk1 & (~T)) | (T & (~S) & *D); +} + +/* SDTax source transparent/pattern opaque. */ +static void rop3_108_1_0 (unsigned char *D, unsigned char S, unsigned char T) +{ + unsigned char stk1; + unsigned char stk2; + stk2 = *D & T; + stk1 = S ^ stk2; + *D = (stk1 & (~S)) | (*D & S); +} + +/* SDTax source/pattern transparent. */ +static void rop3_108_1_1 (unsigned char *D, unsigned char S, unsigned char T) +{ + unsigned char stk1; + unsigned char stk2; + stk2 = *D & T; + stk1 = S ^ stk2; + *D = (stk1 & (~S) & (~T)) | (*D & S) | (*D & T); +} + +/* SDTax source/pattern opaque. */ +static unsigned xrop3_108_0_0 (unsigned char s, unsigned char t) +{ + unsigned D = 0x00ff; + unsigned S = ((unsigned)s << 8) | s; + unsigned T = ((unsigned)t << 8) | t; + unsigned stk1; + unsigned stk2; + stk2 = D & T; + stk1 = S ^ stk2; + return stk1; +} + +/* SDTax source opaque/pattern transparent. */ +static unsigned xrop3_108_0_1 (unsigned char s, unsigned char t) +{ + unsigned D = 0x00ff; + unsigned S = ((unsigned)s << 8) | s; + unsigned T = ((unsigned)t << 8) | t; + unsigned stk1; + unsigned stk2; + stk2 = D & T; + stk1 = S ^ stk2; + return (stk1 & S) | (stk1 & (~T)) | (T & (~S) & D); +} + +/* SDTax source transparent/pattern opaque. */ +static unsigned xrop3_108_1_0 (unsigned char s, unsigned char t) +{ + unsigned D = 0x00ff; + unsigned S = ((unsigned)s << 8) | s; + unsigned T = ((unsigned)t << 8) | t; + unsigned stk1; + unsigned stk2; + stk2 = D & T; + stk1 = S ^ stk2; + return (stk1 & (~S)) | (D & S); +} + +/* SDTax source/pattern transparent. */ +static unsigned xrop3_108_1_1 (unsigned char s, unsigned char t) +{ + unsigned D = 0x00ff; + unsigned S = ((unsigned)s << 8) | s; + unsigned T = ((unsigned)t << 8) | t; + unsigned stk1; + unsigned stk2; + stk2 = D & T; + stk1 = S ^ stk2; + return (stk1 & (~S) & (~T)) | (D & S) | (D & T); +} + +/* TDSTDoaxxn source/pattern opaque. */ +static void rop3_109_0_0 (unsigned char *D, unsigned char S, unsigned char T) +{ + unsigned char stk1; + unsigned char stk2; + unsigned char stk3; + unsigned char stk4; + stk4 = T | *D; + stk3 = S & stk4; + stk2 = *D ^ stk3; + stk1 = T ^ stk2; + stk1 = ~stk1; + *D = stk1; +} + +/* TDSTDoaxxn source opaque/pattern transparent. */ +static void rop3_109_0_1 (unsigned char *D, unsigned char S, unsigned char T) +{ + unsigned char stk1; + unsigned char stk2; + unsigned char stk3; + unsigned char stk4; + stk4 = T | *D; + stk3 = S & stk4; + stk2 = *D ^ stk3; + stk1 = T ^ stk2; + stk1 = ~stk1; + *D = (stk1 & S) | (stk1 & (~T)) | (T & (~S) & *D); +} + +/* TDSTDoaxxn source transparent/pattern opaque. */ +static void rop3_109_1_0 (unsigned char *D, unsigned char S, unsigned char T) +{ + unsigned char stk1; + unsigned char stk2; + unsigned char stk3; + unsigned char stk4; + stk4 = T | *D; + stk3 = S & stk4; + stk2 = *D ^ stk3; + stk1 = T ^ stk2; + stk1 = ~stk1; + *D = (stk1 & (~S)) | (*D & S); +} + +/* TDSTDoaxxn source/pattern transparent. */ +static void rop3_109_1_1 (unsigned char *D, unsigned char S, unsigned char T) +{ + unsigned char stk1; + unsigned char stk2; + unsigned char stk3; + unsigned char stk4; + stk4 = T | *D; + stk3 = S & stk4; + stk2 = *D ^ stk3; + stk1 = T ^ stk2; + stk1 = ~stk1; + *D = (stk1 & (~S) & (~T)) | (*D & S) | (*D & T); +} + +/* TDSTDoaxxn source/pattern opaque. */ +static unsigned xrop3_109_0_0 (unsigned char s, unsigned char t) +{ + unsigned D = 0x00ff; + unsigned S = ((unsigned)s << 8) | s; + unsigned T = ((unsigned)t << 8) | t; + unsigned stk1; + unsigned stk2; + unsigned stk3; + unsigned stk4; + stk4 = T | D; + stk3 = S & stk4; + stk2 = D ^ stk3; + stk1 = T ^ stk2; + stk1 = ~stk1; + return stk1; +} + +/* TDSTDoaxxn source opaque/pattern transparent. */ +static unsigned xrop3_109_0_1 (unsigned char s, unsigned char t) +{ + unsigned D = 0x00ff; + unsigned S = ((unsigned)s << 8) | s; + unsigned T = ((unsigned)t << 8) | t; + unsigned stk1; + unsigned stk2; + unsigned stk3; + unsigned stk4; + stk4 = T | D; + stk3 = S & stk4; + stk2 = D ^ stk3; + stk1 = T ^ stk2; + stk1 = ~stk1; + return (stk1 & S) | (stk1 & (~T)) | (T & (~S) & D); +} + +/* TDSTDoaxxn source transparent/pattern opaque. */ +static unsigned xrop3_109_1_0 (unsigned char s, unsigned char t) +{ + unsigned D = 0x00ff; + unsigned S = ((unsigned)s << 8) | s; + unsigned T = ((unsigned)t << 8) | t; + unsigned stk1; + unsigned stk2; + unsigned stk3; + unsigned stk4; + stk4 = T | D; + stk3 = S & stk4; + stk2 = D ^ stk3; + stk1 = T ^ stk2; + stk1 = ~stk1; + return (stk1 & (~S)) | (D & S); +} + +/* TDSTDoaxxn source/pattern transparent. */ +static unsigned xrop3_109_1_1 (unsigned char s, unsigned char t) +{ + unsigned D = 0x00ff; + unsigned S = ((unsigned)s << 8) | s; + unsigned T = ((unsigned)t << 8) | t; + unsigned stk1; + unsigned stk2; + unsigned stk3; + unsigned stk4; + stk4 = T | D; + stk3 = S & stk4; + stk2 = D ^ stk3; + stk1 = T ^ stk2; + stk1 = ~stk1; + return (stk1 & (~S) & (~T)) | (D & S) | (D & T); +} + +/* SDTSnoax source/pattern opaque. */ +static void rop3_110_0_0 (unsigned char *D, unsigned char S, unsigned char T) +{ + unsigned char stk1; + unsigned char stk2; + unsigned char stk3; + unsigned char stk4; + stk4 = ~S; + stk3 = T | stk4; + stk2 = *D & stk3; + stk1 = S ^ stk2; + *D = stk1; +} + +/* SDTSnoax source opaque/pattern transparent. */ +static void rop3_110_0_1 (unsigned char *D, unsigned char S, unsigned char T) +{ + unsigned char stk1; + unsigned char stk2; + unsigned char stk3; + unsigned char stk4; + stk4 = ~S; + stk3 = T | stk4; + stk2 = *D & stk3; + stk1 = S ^ stk2; + *D = (stk1 & S) | (stk1 & (~T)) | (T & (~S) & *D); +} + +/* SDTSnoax source transparent/pattern opaque. */ +static void rop3_110_1_0 (unsigned char *D, unsigned char S, unsigned char T) +{ + unsigned char stk1; + unsigned char stk2; + unsigned char stk3; + unsigned char stk4; + stk4 = ~S; + stk3 = T | stk4; + stk2 = *D & stk3; + stk1 = S ^ stk2; + *D = (stk1 & (~S)) | (*D & S); +} + +/* SDTSnoax source/pattern transparent. */ +static void rop3_110_1_1 (unsigned char *D, unsigned char S, unsigned char T) +{ + unsigned char stk1; + unsigned char stk2; + unsigned char stk3; + unsigned char stk4; + stk4 = ~S; + stk3 = T | stk4; + stk2 = *D & stk3; + stk1 = S ^ stk2; + *D = (stk1 & (~S) & (~T)) | (*D & S) | (*D & T); +} + +/* SDTSnoax source/pattern opaque. */ +static unsigned xrop3_110_0_0 (unsigned char s, unsigned char t) +{ + unsigned D = 0x00ff; + unsigned S = ((unsigned)s << 8) | s; + unsigned T = ((unsigned)t << 8) | t; + unsigned stk1; + unsigned stk2; + unsigned stk3; + unsigned stk4; + stk4 = ~S; + stk3 = T | stk4; + stk2 = D & stk3; + stk1 = S ^ stk2; + return stk1; +} + +/* SDTSnoax source opaque/pattern transparent. */ +static unsigned xrop3_110_0_1 (unsigned char s, unsigned char t) +{ + unsigned D = 0x00ff; + unsigned S = ((unsigned)s << 8) | s; + unsigned T = ((unsigned)t << 8) | t; + unsigned stk1; + unsigned stk2; + unsigned stk3; + unsigned stk4; + stk4 = ~S; + stk3 = T | stk4; + stk2 = D & stk3; + stk1 = S ^ stk2; + return (stk1 & S) | (stk1 & (~T)) | (T & (~S) & D); +} + +/* SDTSnoax source transparent/pattern opaque. */ +static unsigned xrop3_110_1_0 (unsigned char s, unsigned char t) +{ + unsigned D = 0x00ff; + unsigned S = ((unsigned)s << 8) | s; + unsigned T = ((unsigned)t << 8) | t; + unsigned stk1; + unsigned stk2; + unsigned stk3; + unsigned stk4; + stk4 = ~S; + stk3 = T | stk4; + stk2 = D & stk3; + stk1 = S ^ stk2; + return (stk1 & (~S)) | (D & S); +} + +/* SDTSnoax source/pattern transparent. */ +static unsigned xrop3_110_1_1 (unsigned char s, unsigned char t) +{ + unsigned D = 0x00ff; + unsigned S = ((unsigned)s << 8) | s; + unsigned T = ((unsigned)t << 8) | t; + unsigned stk1; + unsigned stk2; + unsigned stk3; + unsigned stk4; + stk4 = ~S; + stk3 = T | stk4; + stk2 = D & stk3; + stk1 = S ^ stk2; + return (stk1 & (~S) & (~T)) | (D & S) | (D & T); +} + +/* TDSxnan source/pattern opaque. */ +static void rop3_111_0_0 (unsigned char *D, unsigned char S, unsigned char T) +{ + unsigned char stk1; + unsigned char stk2; + stk2 = *D ^ S; + stk2 = ~stk2; + stk1 = T & stk2; + stk1 = ~stk1; + *D = stk1; +} + +/* TDSxnan source opaque/pattern transparent. */ +static void rop3_111_0_1 (unsigned char *D, unsigned char S, unsigned char T) +{ + unsigned char stk1; + unsigned char stk2; + stk2 = *D ^ S; + stk2 = ~stk2; + stk1 = T & stk2; + stk1 = ~stk1; + *D = (stk1 & S) | (stk1 & (~T)) | (T & (~S) & *D); +} + +/* TDSxnan source transparent/pattern opaque. */ +static void rop3_111_1_0 (unsigned char *D, unsigned char S, unsigned char T) +{ + unsigned char stk1; + unsigned char stk2; + stk2 = *D ^ S; + stk2 = ~stk2; + stk1 = T & stk2; + stk1 = ~stk1; + *D = (stk1 & (~S)) | (*D & S); +} + +/* TDSxnan source/pattern transparent. */ +static void rop3_111_1_1 (unsigned char *D, unsigned char S, unsigned char T) +{ + unsigned char stk1; + unsigned char stk2; + stk2 = *D ^ S; + stk2 = ~stk2; + stk1 = T & stk2; + stk1 = ~stk1; + *D = (stk1 & (~S) & (~T)) | (*D & S) | (*D & T); +} + +/* TDSxnan source/pattern opaque. */ +static unsigned xrop3_111_0_0 (unsigned char s, unsigned char t) +{ + unsigned D = 0x00ff; + unsigned S = ((unsigned)s << 8) | s; + unsigned T = ((unsigned)t << 8) | t; + unsigned stk1; + unsigned stk2; + stk2 = D ^ S; + stk2 = ~stk2; + stk1 = T & stk2; + stk1 = ~stk1; + return stk1; +} + +/* TDSxnan source opaque/pattern transparent. */ +static unsigned xrop3_111_0_1 (unsigned char s, unsigned char t) +{ + unsigned D = 0x00ff; + unsigned S = ((unsigned)s << 8) | s; + unsigned T = ((unsigned)t << 8) | t; + unsigned stk1; + unsigned stk2; + stk2 = D ^ S; + stk2 = ~stk2; + stk1 = T & stk2; + stk1 = ~stk1; + return (stk1 & S) | (stk1 & (~T)) | (T & (~S) & D); +} + +/* TDSxnan source transparent/pattern opaque. */ +static unsigned xrop3_111_1_0 (unsigned char s, unsigned char t) +{ + unsigned D = 0x00ff; + unsigned S = ((unsigned)s << 8) | s; + unsigned T = ((unsigned)t << 8) | t; + unsigned stk1; + unsigned stk2; + stk2 = D ^ S; + stk2 = ~stk2; + stk1 = T & stk2; + stk1 = ~stk1; + return (stk1 & (~S)) | (D & S); +} + +/* TDSxnan source/pattern transparent. */ +static unsigned xrop3_111_1_1 (unsigned char s, unsigned char t) +{ + unsigned D = 0x00ff; + unsigned S = ((unsigned)s << 8) | s; + unsigned T = ((unsigned)t << 8) | t; + unsigned stk1; + unsigned stk2; + stk2 = D ^ S; + stk2 = ~stk2; + stk1 = T & stk2; + stk1 = ~stk1; + return (stk1 & (~S) & (~T)) | (D & S) | (D & T); +} + +/* TDSana source/pattern opaque. */ +static void rop3_112_0_0 (unsigned char *D, unsigned char S, unsigned char T) +{ + unsigned char stk1; + unsigned char stk2; + stk2 = *D & S; + stk2 = ~stk2; + stk1 = T & stk2; + *D = stk1; +} + +/* TDSana source opaque/pattern transparent. */ +static void rop3_112_0_1 (unsigned char *D, unsigned char S, unsigned char T) +{ + unsigned char stk1; + unsigned char stk2; + stk2 = *D & S; + stk2 = ~stk2; + stk1 = T & stk2; + *D = (stk1 & S) | (stk1 & (~T)) | (T & (~S) & *D); +} + +/* TDSana source transparent/pattern opaque. */ +static void rop3_112_1_0 (unsigned char *D, unsigned char S, unsigned char T) +{ + unsigned char stk1; + unsigned char stk2; + stk2 = *D & S; + stk2 = ~stk2; + stk1 = T & stk2; + *D = (stk1 & (~S)) | (*D & S); +} + +/* TDSana source/pattern transparent. */ +static void rop3_112_1_1 (unsigned char *D, unsigned char S, unsigned char T) +{ + unsigned char stk1; + unsigned char stk2; + stk2 = *D & S; + stk2 = ~stk2; + stk1 = T & stk2; + *D = (stk1 & (~S) & (~T)) | (*D & S) | (*D & T); +} + +/* TDSana source/pattern opaque. */ +static unsigned xrop3_112_0_0 (unsigned char s, unsigned char t) +{ + unsigned D = 0x00ff; + unsigned S = ((unsigned)s << 8) | s; + unsigned T = ((unsigned)t << 8) | t; + unsigned stk1; + unsigned stk2; + stk2 = D & S; + stk2 = ~stk2; + stk1 = T & stk2; + return stk1; +} + +/* TDSana source opaque/pattern transparent. */ +static unsigned xrop3_112_0_1 (unsigned char s, unsigned char t) +{ + unsigned D = 0x00ff; + unsigned S = ((unsigned)s << 8) | s; + unsigned T = ((unsigned)t << 8) | t; + unsigned stk1; + unsigned stk2; + stk2 = D & S; + stk2 = ~stk2; + stk1 = T & stk2; + return (stk1 & S) | (stk1 & (~T)) | (T & (~S) & D); +} + +/* TDSana source transparent/pattern opaque. */ +static unsigned xrop3_112_1_0 (unsigned char s, unsigned char t) +{ + unsigned D = 0x00ff; + unsigned S = ((unsigned)s << 8) | s; + unsigned T = ((unsigned)t << 8) | t; + unsigned stk1; + unsigned stk2; + stk2 = D & S; + stk2 = ~stk2; + stk1 = T & stk2; + return (stk1 & (~S)) | (D & S); +} + +/* TDSana source/pattern transparent. */ +static unsigned xrop3_112_1_1 (unsigned char s, unsigned char t) +{ + unsigned D = 0x00ff; + unsigned S = ((unsigned)s << 8) | s; + unsigned T = ((unsigned)t << 8) | t; + unsigned stk1; + unsigned stk2; + stk2 = D & S; + stk2 = ~stk2; + stk1 = T & stk2; + return (stk1 & (~S) & (~T)) | (D & S) | (D & T); +} + +/* SSDxTDxaxn source/pattern opaque. */ +static void rop3_113_0_0 (unsigned char *D, unsigned char S, unsigned char T) +{ + unsigned char stk1; + unsigned char stk2; + unsigned char stk3; + stk2 = S ^ *D; + stk3 = T ^ *D; + stk2 = stk2 & stk3; + stk1 = S ^ stk2; + stk1 = ~stk1; + *D = stk1; +} + +/* SSDxTDxaxn source opaque/pattern transparent. */ +static void rop3_113_0_1 (unsigned char *D, unsigned char S, unsigned char T) +{ + unsigned char stk1; + unsigned char stk2; + unsigned char stk3; + stk2 = S ^ *D; + stk3 = T ^ *D; + stk2 = stk2 & stk3; + stk1 = S ^ stk2; + stk1 = ~stk1; + *D = (stk1 & S) | (stk1 & (~T)) | (T & (~S) & *D); +} + +/* SSDxTDxaxn source transparent/pattern opaque. */ +static void rop3_113_1_0 (unsigned char *D, unsigned char S, unsigned char T) +{ + unsigned char stk1; + unsigned char stk2; + unsigned char stk3; + stk2 = S ^ *D; + stk3 = T ^ *D; + stk2 = stk2 & stk3; + stk1 = S ^ stk2; + stk1 = ~stk1; + *D = (stk1 & (~S)) | (*D & S); +} + +/* SSDxTDxaxn source/pattern transparent. */ +static void rop3_113_1_1 (unsigned char *D, unsigned char S, unsigned char T) +{ + unsigned char stk1; + unsigned char stk2; + unsigned char stk3; + stk2 = S ^ *D; + stk3 = T ^ *D; + stk2 = stk2 & stk3; + stk1 = S ^ stk2; + stk1 = ~stk1; + *D = (stk1 & (~S) & (~T)) | (*D & S) | (*D & T); +} + +/* SSDxTDxaxn source/pattern opaque. */ +static unsigned xrop3_113_0_0 (unsigned char s, unsigned char t) +{ + unsigned D = 0x00ff; + unsigned S = ((unsigned)s << 8) | s; + unsigned T = ((unsigned)t << 8) | t; + unsigned stk1; + unsigned stk2; + unsigned stk3; + stk2 = S ^ D; + stk3 = T ^ D; + stk2 = stk2 & stk3; + stk1 = S ^ stk2; + stk1 = ~stk1; + return stk1; +} + +/* SSDxTDxaxn source opaque/pattern transparent. */ +static unsigned xrop3_113_0_1 (unsigned char s, unsigned char t) +{ + unsigned D = 0x00ff; + unsigned S = ((unsigned)s << 8) | s; + unsigned T = ((unsigned)t << 8) | t; + unsigned stk1; + unsigned stk2; + unsigned stk3; + stk2 = S ^ D; + stk3 = T ^ D; + stk2 = stk2 & stk3; + stk1 = S ^ stk2; + stk1 = ~stk1; + return (stk1 & S) | (stk1 & (~T)) | (T & (~S) & D); +} + +/* SSDxTDxaxn source transparent/pattern opaque. */ +static unsigned xrop3_113_1_0 (unsigned char s, unsigned char t) +{ + unsigned D = 0x00ff; + unsigned S = ((unsigned)s << 8) | s; + unsigned T = ((unsigned)t << 8) | t; + unsigned stk1; + unsigned stk2; + unsigned stk3; + stk2 = S ^ D; + stk3 = T ^ D; + stk2 = stk2 & stk3; + stk1 = S ^ stk2; + stk1 = ~stk1; + return (stk1 & (~S)) | (D & S); +} + +/* SSDxTDxaxn source/pattern transparent. */ +static unsigned xrop3_113_1_1 (unsigned char s, unsigned char t) +{ + unsigned D = 0x00ff; + unsigned S = ((unsigned)s << 8) | s; + unsigned T = ((unsigned)t << 8) | t; + unsigned stk1; + unsigned stk2; + unsigned stk3; + stk2 = S ^ D; + stk3 = T ^ D; + stk2 = stk2 & stk3; + stk1 = S ^ stk2; + stk1 = ~stk1; + return (stk1 & (~S) & (~T)) | (D & S) | (D & T); +} + +/* SDTSxox source/pattern opaque. */ +static void rop3_114_0_0 (unsigned char *D, unsigned char S, unsigned char T) +{ + unsigned char stk1; + unsigned char stk2; + unsigned char stk3; + stk3 = T ^ S; + stk2 = *D | stk3; + stk1 = S ^ stk2; + *D = stk1; +} + +/* SDTSxox source opaque/pattern transparent. */ +static void rop3_114_0_1 (unsigned char *D, unsigned char S, unsigned char T) +{ + unsigned char stk1; + unsigned char stk2; + unsigned char stk3; + stk3 = T ^ S; + stk2 = *D | stk3; + stk1 = S ^ stk2; + *D = (stk1 & S) | (stk1 & (~T)) | (T & (~S) & *D); +} + +/* SDTSxox source transparent/pattern opaque. */ +static void rop3_114_1_0 (unsigned char *D, unsigned char S, unsigned char T) +{ + unsigned char stk1; + unsigned char stk2; + unsigned char stk3; + stk3 = T ^ S; + stk2 = *D | stk3; + stk1 = S ^ stk2; + *D = (stk1 & (~S)) | (*D & S); +} + +/* SDTSxox source/pattern transparent. */ +static void rop3_114_1_1 (unsigned char *D, unsigned char S, unsigned char T) +{ + unsigned char stk1; + unsigned char stk2; + unsigned char stk3; + stk3 = T ^ S; + stk2 = *D | stk3; + stk1 = S ^ stk2; + *D = (stk1 & (~S) & (~T)) | (*D & S) | (*D & T); +} + +/* SDTSxox source/pattern opaque. */ +static unsigned xrop3_114_0_0 (unsigned char s, unsigned char t) +{ + unsigned D = 0x00ff; + unsigned S = ((unsigned)s << 8) | s; + unsigned T = ((unsigned)t << 8) | t; + unsigned stk1; + unsigned stk2; + unsigned stk3; + stk3 = T ^ S; + stk2 = D | stk3; + stk1 = S ^ stk2; + return stk1; +} + +/* SDTSxox source opaque/pattern transparent. */ +static unsigned xrop3_114_0_1 (unsigned char s, unsigned char t) +{ + unsigned D = 0x00ff; + unsigned S = ((unsigned)s << 8) | s; + unsigned T = ((unsigned)t << 8) | t; + unsigned stk1; + unsigned stk2; + unsigned stk3; + stk3 = T ^ S; + stk2 = D | stk3; + stk1 = S ^ stk2; + return (stk1 & S) | (stk1 & (~T)) | (T & (~S) & D); +} + +/* SDTSxox source transparent/pattern opaque. */ +static unsigned xrop3_114_1_0 (unsigned char s, unsigned char t) +{ + unsigned D = 0x00ff; + unsigned S = ((unsigned)s << 8) | s; + unsigned T = ((unsigned)t << 8) | t; + unsigned stk1; + unsigned stk2; + unsigned stk3; + stk3 = T ^ S; + stk2 = D | stk3; + stk1 = S ^ stk2; + return (stk1 & (~S)) | (D & S); +} + +/* SDTSxox source/pattern transparent. */ +static unsigned xrop3_114_1_1 (unsigned char s, unsigned char t) +{ + unsigned D = 0x00ff; + unsigned S = ((unsigned)s << 8) | s; + unsigned T = ((unsigned)t << 8) | t; + unsigned stk1; + unsigned stk2; + unsigned stk3; + stk3 = T ^ S; + stk2 = D | stk3; + stk1 = S ^ stk2; + return (stk1 & (~S) & (~T)) | (D & S) | (D & T); +} + +/* SDTnoan source/pattern opaque. */ +static void rop3_115_0_0 (unsigned char *D, unsigned char S, unsigned char T) +{ + unsigned char stk1; + unsigned char stk2; + unsigned char stk3; + stk3 = ~T; + stk2 = *D | stk3; + stk1 = S & stk2; + stk1 = ~stk1; + *D = stk1; +} + +/* SDTnoan source opaque/pattern transparent. */ +static void rop3_115_0_1 (unsigned char *D, unsigned char S, unsigned char T) +{ + unsigned char stk1; + unsigned char stk2; + unsigned char stk3; + stk3 = ~T; + stk2 = *D | stk3; + stk1 = S & stk2; + stk1 = ~stk1; + *D = (stk1 & S) | (stk1 & (~T)) | (T & (~S) & *D); +} + +/* SDTnoan source transparent/pattern opaque. */ +static void rop3_115_1_0 (unsigned char *D, unsigned char S, unsigned char T) +{ + unsigned char stk1; + unsigned char stk2; + unsigned char stk3; + stk3 = ~T; + stk2 = *D | stk3; + stk1 = S & stk2; + stk1 = ~stk1; + *D = (stk1 & (~S)) | (*D & S); +} + +/* SDTnoan source/pattern transparent. */ +static void rop3_115_1_1 (unsigned char *D, unsigned char S, unsigned char T) +{ + unsigned char stk1; + unsigned char stk2; + unsigned char stk3; + stk3 = ~T; + stk2 = *D | stk3; + stk1 = S & stk2; + stk1 = ~stk1; + *D = (stk1 & (~S) & (~T)) | (*D & S) | (*D & T); +} + +/* SDTnoan source/pattern opaque. */ +static unsigned xrop3_115_0_0 (unsigned char s, unsigned char t) +{ + unsigned D = 0x00ff; + unsigned S = ((unsigned)s << 8) | s; + unsigned T = ((unsigned)t << 8) | t; + unsigned stk1; + unsigned stk2; + unsigned stk3; + stk3 = ~T; + stk2 = D | stk3; + stk1 = S & stk2; + stk1 = ~stk1; + return stk1; +} + +/* SDTnoan source opaque/pattern transparent. */ +static unsigned xrop3_115_0_1 (unsigned char s, unsigned char t) +{ + unsigned D = 0x00ff; + unsigned S = ((unsigned)s << 8) | s; + unsigned T = ((unsigned)t << 8) | t; + unsigned stk1; + unsigned stk2; + unsigned stk3; + stk3 = ~T; + stk2 = D | stk3; + stk1 = S & stk2; + stk1 = ~stk1; + return (stk1 & S) | (stk1 & (~T)) | (T & (~S) & D); +} + +/* SDTnoan source transparent/pattern opaque. */ +static unsigned xrop3_115_1_0 (unsigned char s, unsigned char t) +{ + unsigned D = 0x00ff; + unsigned S = ((unsigned)s << 8) | s; + unsigned T = ((unsigned)t << 8) | t; + unsigned stk1; + unsigned stk2; + unsigned stk3; + stk3 = ~T; + stk2 = D | stk3; + stk1 = S & stk2; + stk1 = ~stk1; + return (stk1 & (~S)) | (D & S); +} + +/* SDTnoan source/pattern transparent. */ +static unsigned xrop3_115_1_1 (unsigned char s, unsigned char t) +{ + unsigned D = 0x00ff; + unsigned S = ((unsigned)s << 8) | s; + unsigned T = ((unsigned)t << 8) | t; + unsigned stk1; + unsigned stk2; + unsigned stk3; + stk3 = ~T; + stk2 = D | stk3; + stk1 = S & stk2; + stk1 = ~stk1; + return (stk1 & (~S) & (~T)) | (D & S) | (D & T); +} + +/* DSTDxox source/pattern opaque. */ +static void rop3_116_0_0 (unsigned char *D, unsigned char S, unsigned char T) +{ + unsigned char stk1; + unsigned char stk2; + unsigned char stk3; + stk3 = T ^ *D; + stk2 = S | stk3; + stk1 = *D ^ stk2; + *D = stk1; +} + +/* DSTDxox source opaque/pattern transparent. */ +static void rop3_116_0_1 (unsigned char *D, unsigned char S, unsigned char T) +{ + unsigned char stk1; + unsigned char stk2; + unsigned char stk3; + stk3 = T ^ *D; + stk2 = S | stk3; + stk1 = *D ^ stk2; + *D = (stk1 & S) | (stk1 & (~T)) | (T & (~S) & *D); +} + +/* DSTDxox source transparent/pattern opaque. */ +static void rop3_116_1_0 (unsigned char *D, unsigned char S, unsigned char T) +{ + unsigned char stk1; + unsigned char stk2; + unsigned char stk3; + stk3 = T ^ *D; + stk2 = S | stk3; + stk1 = *D ^ stk2; + *D = (stk1 & (~S)) | (*D & S); +} + +/* DSTDxox source/pattern transparent. */ +static void rop3_116_1_1 (unsigned char *D, unsigned char S, unsigned char T) +{ + unsigned char stk1; + unsigned char stk2; + unsigned char stk3; + stk3 = T ^ *D; + stk2 = S | stk3; + stk1 = *D ^ stk2; + *D = (stk1 & (~S) & (~T)) | (*D & S) | (*D & T); +} + +/* DSTDxox source/pattern opaque. */ +static unsigned xrop3_116_0_0 (unsigned char s, unsigned char t) +{ + unsigned D = 0x00ff; + unsigned S = ((unsigned)s << 8) | s; + unsigned T = ((unsigned)t << 8) | t; + unsigned stk1; + unsigned stk2; + unsigned stk3; + stk3 = T ^ D; + stk2 = S | stk3; + stk1 = D ^ stk2; + return stk1; +} + +/* DSTDxox source opaque/pattern transparent. */ +static unsigned xrop3_116_0_1 (unsigned char s, unsigned char t) +{ + unsigned D = 0x00ff; + unsigned S = ((unsigned)s << 8) | s; + unsigned T = ((unsigned)t << 8) | t; + unsigned stk1; + unsigned stk2; + unsigned stk3; + stk3 = T ^ D; + stk2 = S | stk3; + stk1 = D ^ stk2; + return (stk1 & S) | (stk1 & (~T)) | (T & (~S) & D); +} + +/* DSTDxox source transparent/pattern opaque. */ +static unsigned xrop3_116_1_0 (unsigned char s, unsigned char t) +{ + unsigned D = 0x00ff; + unsigned S = ((unsigned)s << 8) | s; + unsigned T = ((unsigned)t << 8) | t; + unsigned stk1; + unsigned stk2; + unsigned stk3; + stk3 = T ^ D; + stk2 = S | stk3; + stk1 = D ^ stk2; + return (stk1 & (~S)) | (D & S); +} + +/* DSTDxox source/pattern transparent. */ +static unsigned xrop3_116_1_1 (unsigned char s, unsigned char t) +{ + unsigned D = 0x00ff; + unsigned S = ((unsigned)s << 8) | s; + unsigned T = ((unsigned)t << 8) | t; + unsigned stk1; + unsigned stk2; + unsigned stk3; + stk3 = T ^ D; + stk2 = S | stk3; + stk1 = D ^ stk2; + return (stk1 & (~S) & (~T)) | (D & S) | (D & T); +} + +/* DSTnoan source/pattern opaque. */ +static void rop3_117_0_0 (unsigned char *D, unsigned char S, unsigned char T) +{ + unsigned char stk1; + unsigned char stk2; + unsigned char stk3; + stk3 = ~T; + stk2 = S | stk3; + stk1 = *D & stk2; + stk1 = ~stk1; + *D = stk1; +} + +/* DSTnoan source opaque/pattern transparent. */ +static void rop3_117_0_1 (unsigned char *D, unsigned char S, unsigned char T) +{ + unsigned char stk1; + unsigned char stk2; + unsigned char stk3; + stk3 = ~T; + stk2 = S | stk3; + stk1 = *D & stk2; + stk1 = ~stk1; + *D = (stk1 & S) | (stk1 & (~T)) | (T & (~S) & *D); +} + +/* DSTnoan source transparent/pattern opaque. */ +static void rop3_117_1_0 (unsigned char *D, unsigned char S, unsigned char T) +{ + unsigned char stk1; + unsigned char stk2; + unsigned char stk3; + stk3 = ~T; + stk2 = S | stk3; + stk1 = *D & stk2; + stk1 = ~stk1; + *D = (stk1 & (~S)) | (*D & S); +} + +/* DSTnoan source/pattern transparent. */ +static void rop3_117_1_1 (unsigned char *D, unsigned char S, unsigned char T) +{ + unsigned char stk1; + unsigned char stk2; + unsigned char stk3; + stk3 = ~T; + stk2 = S | stk3; + stk1 = *D & stk2; + stk1 = ~stk1; + *D = (stk1 & (~S) & (~T)) | (*D & S) | (*D & T); +} + +/* DSTnoan source/pattern opaque. */ +static unsigned xrop3_117_0_0 (unsigned char s, unsigned char t) +{ + unsigned D = 0x00ff; + unsigned S = ((unsigned)s << 8) | s; + unsigned T = ((unsigned)t << 8) | t; + unsigned stk1; + unsigned stk2; + unsigned stk3; + stk3 = ~T; + stk2 = S | stk3; + stk1 = D & stk2; + stk1 = ~stk1; + return stk1; +} + +/* DSTnoan source opaque/pattern transparent. */ +static unsigned xrop3_117_0_1 (unsigned char s, unsigned char t) +{ + unsigned D = 0x00ff; + unsigned S = ((unsigned)s << 8) | s; + unsigned T = ((unsigned)t << 8) | t; + unsigned stk1; + unsigned stk2; + unsigned stk3; + stk3 = ~T; + stk2 = S | stk3; + stk1 = D & stk2; + stk1 = ~stk1; + return (stk1 & S) | (stk1 & (~T)) | (T & (~S) & D); +} + +/* DSTnoan source transparent/pattern opaque. */ +static unsigned xrop3_117_1_0 (unsigned char s, unsigned char t) +{ + unsigned D = 0x00ff; + unsigned S = ((unsigned)s << 8) | s; + unsigned T = ((unsigned)t << 8) | t; + unsigned stk1; + unsigned stk2; + unsigned stk3; + stk3 = ~T; + stk2 = S | stk3; + stk1 = D & stk2; + stk1 = ~stk1; + return (stk1 & (~S)) | (D & S); +} + +/* DSTnoan source/pattern transparent. */ +static unsigned xrop3_117_1_1 (unsigned char s, unsigned char t) +{ + unsigned D = 0x00ff; + unsigned S = ((unsigned)s << 8) | s; + unsigned T = ((unsigned)t << 8) | t; + unsigned stk1; + unsigned stk2; + unsigned stk3; + stk3 = ~T; + stk2 = S | stk3; + stk1 = D & stk2; + stk1 = ~stk1; + return (stk1 & (~S) & (~T)) | (D & S) | (D & T); +} + +/* SDTSnaox source/pattern opaque. */ +static void rop3_118_0_0 (unsigned char *D, unsigned char S, unsigned char T) +{ + unsigned char stk1; + unsigned char stk2; + unsigned char stk3; + unsigned char stk4; + stk4 = ~S; + stk3 = T & stk4; + stk2 = *D | stk3; + stk1 = S ^ stk2; + *D = stk1; +} + +/* SDTSnaox source opaque/pattern transparent. */ +static void rop3_118_0_1 (unsigned char *D, unsigned char S, unsigned char T) +{ + unsigned char stk1; + unsigned char stk2; + unsigned char stk3; + unsigned char stk4; + stk4 = ~S; + stk3 = T & stk4; + stk2 = *D | stk3; + stk1 = S ^ stk2; + *D = (stk1 & S) | (stk1 & (~T)) | (T & (~S) & *D); +} + +/* SDTSnaox source transparent/pattern opaque. */ +static void rop3_118_1_0 (unsigned char *D, unsigned char S, unsigned char T) +{ + unsigned char stk1; + unsigned char stk2; + unsigned char stk3; + unsigned char stk4; + stk4 = ~S; + stk3 = T & stk4; + stk2 = *D | stk3; + stk1 = S ^ stk2; + *D = (stk1 & (~S)) | (*D & S); +} + +/* SDTSnaox source/pattern transparent. */ +static void rop3_118_1_1 (unsigned char *D, unsigned char S, unsigned char T) +{ + unsigned char stk1; + unsigned char stk2; + unsigned char stk3; + unsigned char stk4; + stk4 = ~S; + stk3 = T & stk4; + stk2 = *D | stk3; + stk1 = S ^ stk2; + *D = (stk1 & (~S) & (~T)) | (*D & S) | (*D & T); +} + +/* SDTSnaox source/pattern opaque. */ +static unsigned xrop3_118_0_0 (unsigned char s, unsigned char t) +{ + unsigned D = 0x00ff; + unsigned S = ((unsigned)s << 8) | s; + unsigned T = ((unsigned)t << 8) | t; + unsigned stk1; + unsigned stk2; + unsigned stk3; + unsigned stk4; + stk4 = ~S; + stk3 = T & stk4; + stk2 = D | stk3; + stk1 = S ^ stk2; + return stk1; +} + +/* SDTSnaox source opaque/pattern transparent. */ +static unsigned xrop3_118_0_1 (unsigned char s, unsigned char t) +{ + unsigned D = 0x00ff; + unsigned S = ((unsigned)s << 8) | s; + unsigned T = ((unsigned)t << 8) | t; + unsigned stk1; + unsigned stk2; + unsigned stk3; + unsigned stk4; + stk4 = ~S; + stk3 = T & stk4; + stk2 = D | stk3; + stk1 = S ^ stk2; + return (stk1 & S) | (stk1 & (~T)) | (T & (~S) & D); +} + +/* SDTSnaox source transparent/pattern opaque. */ +static unsigned xrop3_118_1_0 (unsigned char s, unsigned char t) +{ + unsigned D = 0x00ff; + unsigned S = ((unsigned)s << 8) | s; + unsigned T = ((unsigned)t << 8) | t; + unsigned stk1; + unsigned stk2; + unsigned stk3; + unsigned stk4; + stk4 = ~S; + stk3 = T & stk4; + stk2 = D | stk3; + stk1 = S ^ stk2; + return (stk1 & (~S)) | (D & S); +} + +/* SDTSnaox source/pattern transparent. */ +static unsigned xrop3_118_1_1 (unsigned char s, unsigned char t) +{ + unsigned D = 0x00ff; + unsigned S = ((unsigned)s << 8) | s; + unsigned T = ((unsigned)t << 8) | t; + unsigned stk1; + unsigned stk2; + unsigned stk3; + unsigned stk4; + stk4 = ~S; + stk3 = T & stk4; + stk2 = D | stk3; + stk1 = S ^ stk2; + return (stk1 & (~S) & (~T)) | (D & S) | (D & T); +} + +/* DSan source/pattern opaque. */ +static void rop3_119_0_0 (unsigned char *D, unsigned char S, unsigned char T) +{ + unsigned char stk1; + stk1 = *D & S; + stk1 = ~stk1; + *D = stk1; +} + +/* DSan source opaque/pattern transparent. */ +static void rop3_119_0_1 (unsigned char *D, unsigned char S, unsigned char T) +{ + unsigned char stk1; + stk1 = *D & S; + stk1 = ~stk1; + *D = (stk1 & S) | (stk1 & (~T)) | (T & (~S) & *D); +} + +/* DSan source transparent/pattern opaque. */ +static void rop3_119_1_0 (unsigned char *D, unsigned char S, unsigned char T) +{ + unsigned char stk1; + stk1 = *D & S; + stk1 = ~stk1; + *D = (stk1 & (~S)) | (*D & S); +} + +/* DSan source/pattern transparent. */ +static void rop3_119_1_1 (unsigned char *D, unsigned char S, unsigned char T) +{ + unsigned char stk1; + stk1 = *D & S; + stk1 = ~stk1; + *D = (stk1 & (~S) & (~T)) | (*D & S) | (*D & T); +} + +/* DSan source/pattern opaque. */ +static unsigned xrop3_119_0_0 (unsigned char s, unsigned char t) +{ + unsigned D = 0x00ff; + unsigned S = ((unsigned)s << 8) | s; + unsigned stk1; + stk1 = D & S; + stk1 = ~stk1; + return stk1; +} + +/* DSan source opaque/pattern transparent. */ +static unsigned xrop3_119_0_1 (unsigned char s, unsigned char t) +{ + unsigned D = 0x00ff; + unsigned S = ((unsigned)s << 8) | s; + unsigned T = ((unsigned)t << 8) | t; + unsigned stk1; + stk1 = D & S; + stk1 = ~stk1; + return (stk1 & S) | (stk1 & (~T)) | (T & (~S) & D); +} + +/* DSan source transparent/pattern opaque. */ +static unsigned xrop3_119_1_0 (unsigned char s, unsigned char t) +{ + unsigned D = 0x00ff; + unsigned S = ((unsigned)s << 8) | s; + unsigned stk1; + stk1 = D & S; + stk1 = ~stk1; + return (stk1 & (~S)) | (D & S); +} + +/* DSan source/pattern transparent. */ +static unsigned xrop3_119_1_1 (unsigned char s, unsigned char t) +{ + unsigned D = 0x00ff; + unsigned S = ((unsigned)s << 8) | s; + unsigned T = ((unsigned)t << 8) | t; + unsigned stk1; + stk1 = D & S; + stk1 = ~stk1; + return (stk1 & (~S) & (~T)) | (D & S) | (D & T); +} + +/* TDSax source/pattern opaque. */ +static void rop3_120_0_0 (unsigned char *D, unsigned char S, unsigned char T) +{ + unsigned char stk1; + unsigned char stk2; + stk2 = *D & S; + stk1 = T ^ stk2; + *D = stk1; +} + +/* TDSax source opaque/pattern transparent. */ +static void rop3_120_0_1 (unsigned char *D, unsigned char S, unsigned char T) +{ + unsigned char stk1; + unsigned char stk2; + stk2 = *D & S; + stk1 = T ^ stk2; + *D = (stk1 & S) | (stk1 & (~T)) | (T & (~S) & *D); +} + +/* TDSax source transparent/pattern opaque. */ +static void rop3_120_1_0 (unsigned char *D, unsigned char S, unsigned char T) +{ + unsigned char stk1; + unsigned char stk2; + stk2 = *D & S; + stk1 = T ^ stk2; + *D = (stk1 & (~S)) | (*D & S); +} + +/* TDSax source/pattern transparent. */ +static void rop3_120_1_1 (unsigned char *D, unsigned char S, unsigned char T) +{ + unsigned char stk1; + unsigned char stk2; + stk2 = *D & S; + stk1 = T ^ stk2; + *D = (stk1 & (~S) & (~T)) | (*D & S) | (*D & T); +} + +/* TDSax source/pattern opaque. */ +static unsigned xrop3_120_0_0 (unsigned char s, unsigned char t) +{ + unsigned D = 0x00ff; + unsigned S = ((unsigned)s << 8) | s; + unsigned T = ((unsigned)t << 8) | t; + unsigned stk1; + unsigned stk2; + stk2 = D & S; + stk1 = T ^ stk2; + return stk1; +} + +/* TDSax source opaque/pattern transparent. */ +static unsigned xrop3_120_0_1 (unsigned char s, unsigned char t) +{ + unsigned D = 0x00ff; + unsigned S = ((unsigned)s << 8) | s; + unsigned T = ((unsigned)t << 8) | t; + unsigned stk1; + unsigned stk2; + stk2 = D & S; + stk1 = T ^ stk2; + return (stk1 & S) | (stk1 & (~T)) | (T & (~S) & D); +} + +/* TDSax source transparent/pattern opaque. */ +static unsigned xrop3_120_1_0 (unsigned char s, unsigned char t) +{ + unsigned D = 0x00ff; + unsigned S = ((unsigned)s << 8) | s; + unsigned T = ((unsigned)t << 8) | t; + unsigned stk1; + unsigned stk2; + stk2 = D & S; + stk1 = T ^ stk2; + return (stk1 & (~S)) | (D & S); +} + +/* TDSax source/pattern transparent. */ +static unsigned xrop3_120_1_1 (unsigned char s, unsigned char t) +{ + unsigned D = 0x00ff; + unsigned S = ((unsigned)s << 8) | s; + unsigned T = ((unsigned)t << 8) | t; + unsigned stk1; + unsigned stk2; + stk2 = D & S; + stk1 = T ^ stk2; + return (stk1 & (~S) & (~T)) | (D & S) | (D & T); +} + +/* DSTDSoaxxn source/pattern opaque. */ +static void rop3_121_0_0 (unsigned char *D, unsigned char S, unsigned char T) +{ + unsigned char stk1; + unsigned char stk2; + unsigned char stk3; + unsigned char stk4; + stk4 = *D | S; + stk3 = T & stk4; + stk2 = S ^ stk3; + stk1 = *D ^ stk2; + stk1 = ~stk1; + *D = stk1; +} + +/* DSTDSoaxxn source opaque/pattern transparent. */ +static void rop3_121_0_1 (unsigned char *D, unsigned char S, unsigned char T) +{ + unsigned char stk1; + unsigned char stk2; + unsigned char stk3; + unsigned char stk4; + stk4 = *D | S; + stk3 = T & stk4; + stk2 = S ^ stk3; + stk1 = *D ^ stk2; + stk1 = ~stk1; + *D = (stk1 & S) | (stk1 & (~T)) | (T & (~S) & *D); +} + +/* DSTDSoaxxn source transparent/pattern opaque. */ +static void rop3_121_1_0 (unsigned char *D, unsigned char S, unsigned char T) +{ + unsigned char stk1; + unsigned char stk2; + unsigned char stk3; + unsigned char stk4; + stk4 = *D | S; + stk3 = T & stk4; + stk2 = S ^ stk3; + stk1 = *D ^ stk2; + stk1 = ~stk1; + *D = (stk1 & (~S)) | (*D & S); +} + +/* DSTDSoaxxn source/pattern transparent. */ +static void rop3_121_1_1 (unsigned char *D, unsigned char S, unsigned char T) +{ + unsigned char stk1; + unsigned char stk2; + unsigned char stk3; + unsigned char stk4; + stk4 = *D | S; + stk3 = T & stk4; + stk2 = S ^ stk3; + stk1 = *D ^ stk2; + stk1 = ~stk1; + *D = (stk1 & (~S) & (~T)) | (*D & S) | (*D & T); +} + +/* DSTDSoaxxn source/pattern opaque. */ +static unsigned xrop3_121_0_0 (unsigned char s, unsigned char t) +{ + unsigned D = 0x00ff; + unsigned S = ((unsigned)s << 8) | s; + unsigned T = ((unsigned)t << 8) | t; + unsigned stk1; + unsigned stk2; + unsigned stk3; + unsigned stk4; + stk4 = D | S; + stk3 = T & stk4; + stk2 = S ^ stk3; + stk1 = D ^ stk2; + stk1 = ~stk1; + return stk1; +} + +/* DSTDSoaxxn source opaque/pattern transparent. */ +static unsigned xrop3_121_0_1 (unsigned char s, unsigned char t) +{ + unsigned D = 0x00ff; + unsigned S = ((unsigned)s << 8) | s; + unsigned T = ((unsigned)t << 8) | t; + unsigned stk1; + unsigned stk2; + unsigned stk3; + unsigned stk4; + stk4 = D | S; + stk3 = T & stk4; + stk2 = S ^ stk3; + stk1 = D ^ stk2; + stk1 = ~stk1; + return (stk1 & S) | (stk1 & (~T)) | (T & (~S) & D); +} + +/* DSTDSoaxxn source transparent/pattern opaque. */ +static unsigned xrop3_121_1_0 (unsigned char s, unsigned char t) +{ + unsigned D = 0x00ff; + unsigned S = ((unsigned)s << 8) | s; + unsigned T = ((unsigned)t << 8) | t; + unsigned stk1; + unsigned stk2; + unsigned stk3; + unsigned stk4; + stk4 = D | S; + stk3 = T & stk4; + stk2 = S ^ stk3; + stk1 = D ^ stk2; + stk1 = ~stk1; + return (stk1 & (~S)) | (D & S); +} + +/* DSTDSoaxxn source/pattern transparent. */ +static unsigned xrop3_121_1_1 (unsigned char s, unsigned char t) +{ + unsigned D = 0x00ff; + unsigned S = ((unsigned)s << 8) | s; + unsigned T = ((unsigned)t << 8) | t; + unsigned stk1; + unsigned stk2; + unsigned stk3; + unsigned stk4; + stk4 = D | S; + stk3 = T & stk4; + stk2 = S ^ stk3; + stk1 = D ^ stk2; + stk1 = ~stk1; + return (stk1 & (~S) & (~T)) | (D & S) | (D & T); +} + +/* DTSDnoax source/pattern opaque. */ +static void rop3_122_0_0 (unsigned char *D, unsigned char S, unsigned char T) +{ + unsigned char stk1; + unsigned char stk2; + unsigned char stk3; + unsigned char stk4; + stk4 = ~*D; + stk3 = S | stk4; + stk2 = T & stk3; + stk1 = *D ^ stk2; + *D = stk1; +} + +/* DTSDnoax source opaque/pattern transparent. */ +static void rop3_122_0_1 (unsigned char *D, unsigned char S, unsigned char T) +{ + unsigned char stk1; + unsigned char stk2; + unsigned char stk3; + unsigned char stk4; + stk4 = ~*D; + stk3 = S | stk4; + stk2 = T & stk3; + stk1 = *D ^ stk2; + *D = (stk1 & S) | (stk1 & (~T)) | (T & (~S) & *D); +} + +/* DTSDnoax source transparent/pattern opaque. */ +static void rop3_122_1_0 (unsigned char *D, unsigned char S, unsigned char T) +{ + unsigned char stk1; + unsigned char stk2; + unsigned char stk3; + unsigned char stk4; + stk4 = ~*D; + stk3 = S | stk4; + stk2 = T & stk3; + stk1 = *D ^ stk2; + *D = (stk1 & (~S)) | (*D & S); +} + +/* DTSDnoax source/pattern transparent. */ +static void rop3_122_1_1 (unsigned char *D, unsigned char S, unsigned char T) +{ + unsigned char stk1; + unsigned char stk2; + unsigned char stk3; + unsigned char stk4; + stk4 = ~*D; + stk3 = S | stk4; + stk2 = T & stk3; + stk1 = *D ^ stk2; + *D = (stk1 & (~S) & (~T)) | (*D & S) | (*D & T); +} + +/* DTSDnoax source/pattern opaque. */ +static unsigned xrop3_122_0_0 (unsigned char s, unsigned char t) +{ + unsigned D = 0x00ff; + unsigned S = ((unsigned)s << 8) | s; + unsigned T = ((unsigned)t << 8) | t; + unsigned stk1; + unsigned stk2; + unsigned stk3; + unsigned stk4; + stk4 = ~D; + stk3 = S | stk4; + stk2 = T & stk3; + stk1 = D ^ stk2; + return stk1; +} + +/* DTSDnoax source opaque/pattern transparent. */ +static unsigned xrop3_122_0_1 (unsigned char s, unsigned char t) +{ + unsigned D = 0x00ff; + unsigned S = ((unsigned)s << 8) | s; + unsigned T = ((unsigned)t << 8) | t; + unsigned stk1; + unsigned stk2; + unsigned stk3; + unsigned stk4; + stk4 = ~D; + stk3 = S | stk4; + stk2 = T & stk3; + stk1 = D ^ stk2; + return (stk1 & S) | (stk1 & (~T)) | (T & (~S) & D); +} + +/* DTSDnoax source transparent/pattern opaque. */ +static unsigned xrop3_122_1_0 (unsigned char s, unsigned char t) +{ + unsigned D = 0x00ff; + unsigned S = ((unsigned)s << 8) | s; + unsigned T = ((unsigned)t << 8) | t; + unsigned stk1; + unsigned stk2; + unsigned stk3; + unsigned stk4; + stk4 = ~D; + stk3 = S | stk4; + stk2 = T & stk3; + stk1 = D ^ stk2; + return (stk1 & (~S)) | (D & S); +} + +/* DTSDnoax source/pattern transparent. */ +static unsigned xrop3_122_1_1 (unsigned char s, unsigned char t) +{ + unsigned D = 0x00ff; + unsigned S = ((unsigned)s << 8) | s; + unsigned T = ((unsigned)t << 8) | t; + unsigned stk1; + unsigned stk2; + unsigned stk3; + unsigned stk4; + stk4 = ~D; + stk3 = S | stk4; + stk2 = T & stk3; + stk1 = D ^ stk2; + return (stk1 & (~S) & (~T)) | (D & S) | (D & T); +} + +/* SDTxnan source/pattern opaque. */ +static void rop3_123_0_0 (unsigned char *D, unsigned char S, unsigned char T) +{ + unsigned char stk1; + unsigned char stk2; + stk2 = *D ^ T; + stk2 = ~stk2; + stk1 = S & stk2; + stk1 = ~stk1; + *D = stk1; +} + +/* SDTxnan source opaque/pattern transparent. */ +static void rop3_123_0_1 (unsigned char *D, unsigned char S, unsigned char T) +{ + unsigned char stk1; + unsigned char stk2; + stk2 = *D ^ T; + stk2 = ~stk2; + stk1 = S & stk2; + stk1 = ~stk1; + *D = (stk1 & S) | (stk1 & (~T)) | (T & (~S) & *D); +} + +/* SDTxnan source transparent/pattern opaque. */ +static void rop3_123_1_0 (unsigned char *D, unsigned char S, unsigned char T) +{ + unsigned char stk1; + unsigned char stk2; + stk2 = *D ^ T; + stk2 = ~stk2; + stk1 = S & stk2; + stk1 = ~stk1; + *D = (stk1 & (~S)) | (*D & S); +} + +/* SDTxnan source/pattern transparent. */ +static void rop3_123_1_1 (unsigned char *D, unsigned char S, unsigned char T) +{ + unsigned char stk1; + unsigned char stk2; + stk2 = *D ^ T; + stk2 = ~stk2; + stk1 = S & stk2; + stk1 = ~stk1; + *D = (stk1 & (~S) & (~T)) | (*D & S) | (*D & T); +} + +/* SDTxnan source/pattern opaque. */ +static unsigned xrop3_123_0_0 (unsigned char s, unsigned char t) +{ + unsigned D = 0x00ff; + unsigned S = ((unsigned)s << 8) | s; + unsigned T = ((unsigned)t << 8) | t; + unsigned stk1; + unsigned stk2; + stk2 = D ^ T; + stk2 = ~stk2; + stk1 = S & stk2; + stk1 = ~stk1; + return stk1; +} + +/* SDTxnan source opaque/pattern transparent. */ +static unsigned xrop3_123_0_1 (unsigned char s, unsigned char t) +{ + unsigned D = 0x00ff; + unsigned S = ((unsigned)s << 8) | s; + unsigned T = ((unsigned)t << 8) | t; + unsigned stk1; + unsigned stk2; + stk2 = D ^ T; + stk2 = ~stk2; + stk1 = S & stk2; + stk1 = ~stk1; + return (stk1 & S) | (stk1 & (~T)) | (T & (~S) & D); +} + +/* SDTxnan source transparent/pattern opaque. */ +static unsigned xrop3_123_1_0 (unsigned char s, unsigned char t) +{ + unsigned D = 0x00ff; + unsigned S = ((unsigned)s << 8) | s; + unsigned T = ((unsigned)t << 8) | t; + unsigned stk1; + unsigned stk2; + stk2 = D ^ T; + stk2 = ~stk2; + stk1 = S & stk2; + stk1 = ~stk1; + return (stk1 & (~S)) | (D & S); +} + +/* SDTxnan source/pattern transparent. */ +static unsigned xrop3_123_1_1 (unsigned char s, unsigned char t) +{ + unsigned D = 0x00ff; + unsigned S = ((unsigned)s << 8) | s; + unsigned T = ((unsigned)t << 8) | t; + unsigned stk1; + unsigned stk2; + stk2 = D ^ T; + stk2 = ~stk2; + stk1 = S & stk2; + stk1 = ~stk1; + return (stk1 & (~S) & (~T)) | (D & S) | (D & T); +} + +/* STDSnoax source/pattern opaque. */ +static void rop3_124_0_0 (unsigned char *D, unsigned char S, unsigned char T) +{ + unsigned char stk1; + unsigned char stk2; + unsigned char stk3; + unsigned char stk4; + stk4 = ~S; + stk3 = *D | stk4; + stk2 = T & stk3; + stk1 = S ^ stk2; + *D = stk1; +} + +/* STDSnoax source opaque/pattern transparent. */ +static void rop3_124_0_1 (unsigned char *D, unsigned char S, unsigned char T) +{ + unsigned char stk1; + unsigned char stk2; + unsigned char stk3; + unsigned char stk4; + stk4 = ~S; + stk3 = *D | stk4; + stk2 = T & stk3; + stk1 = S ^ stk2; + *D = (stk1 & S) | (stk1 & (~T)) | (T & (~S) & *D); +} + +/* STDSnoax source transparent/pattern opaque. */ +static void rop3_124_1_0 (unsigned char *D, unsigned char S, unsigned char T) +{ + unsigned char stk1; + unsigned char stk2; + unsigned char stk3; + unsigned char stk4; + stk4 = ~S; + stk3 = *D | stk4; + stk2 = T & stk3; + stk1 = S ^ stk2; + *D = (stk1 & (~S)) | (*D & S); +} + +/* STDSnoax source/pattern transparent. */ +static void rop3_124_1_1 (unsigned char *D, unsigned char S, unsigned char T) +{ + unsigned char stk1; + unsigned char stk2; + unsigned char stk3; + unsigned char stk4; + stk4 = ~S; + stk3 = *D | stk4; + stk2 = T & stk3; + stk1 = S ^ stk2; + *D = (stk1 & (~S) & (~T)) | (*D & S) | (*D & T); +} + +/* STDSnoax source/pattern opaque. */ +static unsigned xrop3_124_0_0 (unsigned char s, unsigned char t) +{ + unsigned D = 0x00ff; + unsigned S = ((unsigned)s << 8) | s; + unsigned T = ((unsigned)t << 8) | t; + unsigned stk1; + unsigned stk2; + unsigned stk3; + unsigned stk4; + stk4 = ~S; + stk3 = D | stk4; + stk2 = T & stk3; + stk1 = S ^ stk2; + return stk1; +} + +/* STDSnoax source opaque/pattern transparent. */ +static unsigned xrop3_124_0_1 (unsigned char s, unsigned char t) +{ + unsigned D = 0x00ff; + unsigned S = ((unsigned)s << 8) | s; + unsigned T = ((unsigned)t << 8) | t; + unsigned stk1; + unsigned stk2; + unsigned stk3; + unsigned stk4; + stk4 = ~S; + stk3 = D | stk4; + stk2 = T & stk3; + stk1 = S ^ stk2; + return (stk1 & S) | (stk1 & (~T)) | (T & (~S) & D); +} + +/* STDSnoax source transparent/pattern opaque. */ +static unsigned xrop3_124_1_0 (unsigned char s, unsigned char t) +{ + unsigned D = 0x00ff; + unsigned S = ((unsigned)s << 8) | s; + unsigned T = ((unsigned)t << 8) | t; + unsigned stk1; + unsigned stk2; + unsigned stk3; + unsigned stk4; + stk4 = ~S; + stk3 = D | stk4; + stk2 = T & stk3; + stk1 = S ^ stk2; + return (stk1 & (~S)) | (D & S); +} + +/* STDSnoax source/pattern transparent. */ +static unsigned xrop3_124_1_1 (unsigned char s, unsigned char t) +{ + unsigned D = 0x00ff; + unsigned S = ((unsigned)s << 8) | s; + unsigned T = ((unsigned)t << 8) | t; + unsigned stk1; + unsigned stk2; + unsigned stk3; + unsigned stk4; + stk4 = ~S; + stk3 = D | stk4; + stk2 = T & stk3; + stk1 = S ^ stk2; + return (stk1 & (~S) & (~T)) | (D & S) | (D & T); +} + +/* DTSxnan source/pattern opaque. */ +static void rop3_125_0_0 (unsigned char *D, unsigned char S, unsigned char T) +{ + unsigned char stk1; + unsigned char stk2; + stk2 = T ^ S; + stk2 = ~stk2; + stk1 = *D & stk2; + stk1 = ~stk1; + *D = stk1; +} + +/* DTSxnan source opaque/pattern transparent. */ +static void rop3_125_0_1 (unsigned char *D, unsigned char S, unsigned char T) +{ + unsigned char stk1; + unsigned char stk2; + stk2 = T ^ S; + stk2 = ~stk2; + stk1 = *D & stk2; + stk1 = ~stk1; + *D = (stk1 & S) | (stk1 & (~T)) | (T & (~S) & *D); +} + +/* DTSxnan source transparent/pattern opaque. */ +static void rop3_125_1_0 (unsigned char *D, unsigned char S, unsigned char T) +{ + unsigned char stk1; + unsigned char stk2; + stk2 = T ^ S; + stk2 = ~stk2; + stk1 = *D & stk2; + stk1 = ~stk1; + *D = (stk1 & (~S)) | (*D & S); +} + +/* DTSxnan source/pattern transparent. */ +static void rop3_125_1_1 (unsigned char *D, unsigned char S, unsigned char T) +{ + unsigned char stk1; + unsigned char stk2; + stk2 = T ^ S; + stk2 = ~stk2; + stk1 = *D & stk2; + stk1 = ~stk1; + *D = (stk1 & (~S) & (~T)) | (*D & S) | (*D & T); +} + +/* DTSxnan source/pattern opaque. */ +static unsigned xrop3_125_0_0 (unsigned char s, unsigned char t) +{ + unsigned D = 0x00ff; + unsigned S = ((unsigned)s << 8) | s; + unsigned T = ((unsigned)t << 8) | t; + unsigned stk1; + unsigned stk2; + stk2 = T ^ S; + stk2 = ~stk2; + stk1 = D & stk2; + stk1 = ~stk1; + return stk1; +} + +/* DTSxnan source opaque/pattern transparent. */ +static unsigned xrop3_125_0_1 (unsigned char s, unsigned char t) +{ + unsigned D = 0x00ff; + unsigned S = ((unsigned)s << 8) | s; + unsigned T = ((unsigned)t << 8) | t; + unsigned stk1; + unsigned stk2; + stk2 = T ^ S; + stk2 = ~stk2; + stk1 = D & stk2; + stk1 = ~stk1; + return (stk1 & S) | (stk1 & (~T)) | (T & (~S) & D); +} + +/* DTSxnan source transparent/pattern opaque. */ +static unsigned xrop3_125_1_0 (unsigned char s, unsigned char t) +{ + unsigned D = 0x00ff; + unsigned S = ((unsigned)s << 8) | s; + unsigned T = ((unsigned)t << 8) | t; + unsigned stk1; + unsigned stk2; + stk2 = T ^ S; + stk2 = ~stk2; + stk1 = D & stk2; + stk1 = ~stk1; + return (stk1 & (~S)) | (D & S); +} + +/* DTSxnan source/pattern transparent. */ +static unsigned xrop3_125_1_1 (unsigned char s, unsigned char t) +{ + unsigned D = 0x00ff; + unsigned S = ((unsigned)s << 8) | s; + unsigned T = ((unsigned)t << 8) | t; + unsigned stk1; + unsigned stk2; + stk2 = T ^ S; + stk2 = ~stk2; + stk1 = D & stk2; + stk1 = ~stk1; + return (stk1 & (~S) & (~T)) | (D & S) | (D & T); +} + +/* STxDSxo source/pattern opaque. */ +static void rop3_126_0_0 (unsigned char *D, unsigned char S, unsigned char T) +{ + unsigned char stk1; + unsigned char stk2; + stk1 = S ^ T; + stk2 = *D ^ S; + stk1 = stk1 | stk2; + *D = stk1; +} + +/* STxDSxo source opaque/pattern transparent. */ +static void rop3_126_0_1 (unsigned char *D, unsigned char S, unsigned char T) +{ + unsigned char stk1; + unsigned char stk2; + stk1 = S ^ T; + stk2 = *D ^ S; + stk1 = stk1 | stk2; + *D = (stk1 & S) | (stk1 & (~T)) | (T & (~S) & *D); +} + +/* STxDSxo source transparent/pattern opaque. */ +static void rop3_126_1_0 (unsigned char *D, unsigned char S, unsigned char T) +{ + unsigned char stk1; + unsigned char stk2; + stk1 = S ^ T; + stk2 = *D ^ S; + stk1 = stk1 | stk2; + *D = (stk1 & (~S)) | (*D & S); +} + +/* STxDSxo source/pattern transparent. */ +static void rop3_126_1_1 (unsigned char *D, unsigned char S, unsigned char T) +{ + unsigned char stk1; + unsigned char stk2; + stk1 = S ^ T; + stk2 = *D ^ S; + stk1 = stk1 | stk2; + *D = (stk1 & (~S) & (~T)) | (*D & S) | (*D & T); +} + +/* STxDSxo source/pattern opaque. */ +static unsigned xrop3_126_0_0 (unsigned char s, unsigned char t) +{ + unsigned D = 0x00ff; + unsigned S = ((unsigned)s << 8) | s; + unsigned T = ((unsigned)t << 8) | t; + unsigned stk1; + unsigned stk2; + stk1 = S ^ T; + stk2 = D ^ S; + stk1 = stk1 | stk2; + return stk1; +} + +/* STxDSxo source opaque/pattern transparent. */ +static unsigned xrop3_126_0_1 (unsigned char s, unsigned char t) +{ + unsigned D = 0x00ff; + unsigned S = ((unsigned)s << 8) | s; + unsigned T = ((unsigned)t << 8) | t; + unsigned stk1; + unsigned stk2; + stk1 = S ^ T; + stk2 = D ^ S; + stk1 = stk1 | stk2; + return (stk1 & S) | (stk1 & (~T)) | (T & (~S) & D); +} + +/* STxDSxo source transparent/pattern opaque. */ +static unsigned xrop3_126_1_0 (unsigned char s, unsigned char t) +{ + unsigned D = 0x00ff; + unsigned S = ((unsigned)s << 8) | s; + unsigned T = ((unsigned)t << 8) | t; + unsigned stk1; + unsigned stk2; + stk1 = S ^ T; + stk2 = D ^ S; + stk1 = stk1 | stk2; + return (stk1 & (~S)) | (D & S); +} + +/* STxDSxo source/pattern transparent. */ +static unsigned xrop3_126_1_1 (unsigned char s, unsigned char t) +{ + unsigned D = 0x00ff; + unsigned S = ((unsigned)s << 8) | s; + unsigned T = ((unsigned)t << 8) | t; + unsigned stk1; + unsigned stk2; + stk1 = S ^ T; + stk2 = D ^ S; + stk1 = stk1 | stk2; + return (stk1 & (~S) & (~T)) | (D & S) | (D & T); +} + +/* DTSaan source/pattern opaque. */ +static void rop3_127_0_0 (unsigned char *D, unsigned char S, unsigned char T) +{ + unsigned char stk1; + unsigned char stk2; + stk2 = T & S; + stk1 = *D & stk2; + stk1 = ~stk1; + *D = stk1; +} + +/* DTSaan source opaque/pattern transparent. */ +static void rop3_127_0_1 (unsigned char *D, unsigned char S, unsigned char T) +{ + unsigned char stk1; + unsigned char stk2; + stk2 = T & S; + stk1 = *D & stk2; + stk1 = ~stk1; + *D = (stk1 & S) | (stk1 & (~T)) | (T & (~S) & *D); +} + +/* DTSaan source transparent/pattern opaque. */ +static void rop3_127_1_0 (unsigned char *D, unsigned char S, unsigned char T) +{ + unsigned char stk1; + unsigned char stk2; + stk2 = T & S; + stk1 = *D & stk2; + stk1 = ~stk1; + *D = (stk1 & (~S)) | (*D & S); +} + +/* DTSaan source/pattern transparent. */ +static void rop3_127_1_1 (unsigned char *D, unsigned char S, unsigned char T) +{ + unsigned char stk1; + unsigned char stk2; + stk2 = T & S; + stk1 = *D & stk2; + stk1 = ~stk1; + *D = (stk1 & (~S) & (~T)) | (*D & S) | (*D & T); +} + +/* DTSaan source/pattern opaque. */ +static unsigned xrop3_127_0_0 (unsigned char s, unsigned char t) +{ + unsigned D = 0x00ff; + unsigned S = ((unsigned)s << 8) | s; + unsigned T = ((unsigned)t << 8) | t; + unsigned stk1; + unsigned stk2; + stk2 = T & S; + stk1 = D & stk2; + stk1 = ~stk1; + return stk1; +} + +/* DTSaan source opaque/pattern transparent. */ +static unsigned xrop3_127_0_1 (unsigned char s, unsigned char t) +{ + unsigned D = 0x00ff; + unsigned S = ((unsigned)s << 8) | s; + unsigned T = ((unsigned)t << 8) | t; + unsigned stk1; + unsigned stk2; + stk2 = T & S; + stk1 = D & stk2; + stk1 = ~stk1; + return (stk1 & S) | (stk1 & (~T)) | (T & (~S) & D); +} + +/* DTSaan source transparent/pattern opaque. */ +static unsigned xrop3_127_1_0 (unsigned char s, unsigned char t) +{ + unsigned D = 0x00ff; + unsigned S = ((unsigned)s << 8) | s; + unsigned T = ((unsigned)t << 8) | t; + unsigned stk1; + unsigned stk2; + stk2 = T & S; + stk1 = D & stk2; + stk1 = ~stk1; + return (stk1 & (~S)) | (D & S); +} + +/* DTSaan source/pattern transparent. */ +static unsigned xrop3_127_1_1 (unsigned char s, unsigned char t) +{ + unsigned D = 0x00ff; + unsigned S = ((unsigned)s << 8) | s; + unsigned T = ((unsigned)t << 8) | t; + unsigned stk1; + unsigned stk2; + stk2 = T & S; + stk1 = D & stk2; + stk1 = ~stk1; + return (stk1 & (~S) & (~T)) | (D & S) | (D & T); +} + +/* DTSaa source/pattern opaque. */ +static void rop3_128_0_0 (unsigned char *D, unsigned char S, unsigned char T) +{ + unsigned char stk1; + unsigned char stk2; + stk2 = T & S; + stk1 = *D & stk2; + *D = stk1; +} + +/* DTSaa source opaque/pattern transparent. */ +static void rop3_128_0_1 (unsigned char *D, unsigned char S, unsigned char T) +{ + unsigned char stk1; + unsigned char stk2; + stk2 = T & S; + stk1 = *D & stk2; + *D = (stk1 & S) | (stk1 & (~T)) | (T & (~S) & *D); +} + +/* DTSaa source transparent/pattern opaque. */ +static void rop3_128_1_0 (unsigned char *D, unsigned char S, unsigned char T) +{ + unsigned char stk1; + unsigned char stk2; + stk2 = T & S; + stk1 = *D & stk2; + *D = (stk1 & (~S)) | (*D & S); +} + +/* DTSaa source/pattern transparent. */ +static void rop3_128_1_1 (unsigned char *D, unsigned char S, unsigned char T) +{ + unsigned char stk1; + unsigned char stk2; + stk2 = T & S; + stk1 = *D & stk2; + *D = (stk1 & (~S) & (~T)) | (*D & S) | (*D & T); +} + +/* DTSaa source/pattern opaque. */ +static unsigned xrop3_128_0_0 (unsigned char s, unsigned char t) +{ + unsigned D = 0x00ff; + unsigned S = ((unsigned)s << 8) | s; + unsigned T = ((unsigned)t << 8) | t; + unsigned stk1; + unsigned stk2; + stk2 = T & S; + stk1 = D & stk2; + return stk1; +} + +/* DTSaa source opaque/pattern transparent. */ +static unsigned xrop3_128_0_1 (unsigned char s, unsigned char t) +{ + unsigned D = 0x00ff; + unsigned S = ((unsigned)s << 8) | s; + unsigned T = ((unsigned)t << 8) | t; + unsigned stk1; + unsigned stk2; + stk2 = T & S; + stk1 = D & stk2; + return (stk1 & S) | (stk1 & (~T)) | (T & (~S) & D); +} + +/* DTSaa source transparent/pattern opaque. */ +static unsigned xrop3_128_1_0 (unsigned char s, unsigned char t) +{ + unsigned D = 0x00ff; + unsigned S = ((unsigned)s << 8) | s; + unsigned T = ((unsigned)t << 8) | t; + unsigned stk1; + unsigned stk2; + stk2 = T & S; + stk1 = D & stk2; + return (stk1 & (~S)) | (D & S); +} + +/* DTSaa source/pattern transparent. */ +static unsigned xrop3_128_1_1 (unsigned char s, unsigned char t) +{ + unsigned D = 0x00ff; + unsigned S = ((unsigned)s << 8) | s; + unsigned T = ((unsigned)t << 8) | t; + unsigned stk1; + unsigned stk2; + stk2 = T & S; + stk1 = D & stk2; + return (stk1 & (~S) & (~T)) | (D & S) | (D & T); +} + +/* STxDSxon source/pattern opaque. */ +static void rop3_129_0_0 (unsigned char *D, unsigned char S, unsigned char T) +{ + unsigned char stk1; + unsigned char stk2; + stk1 = S ^ T; + stk2 = *D ^ S; + stk1 = stk1 | stk2; + stk1 = ~stk1; + *D = stk1; +} + +/* STxDSxon source opaque/pattern transparent. */ +static void rop3_129_0_1 (unsigned char *D, unsigned char S, unsigned char T) +{ + unsigned char stk1; + unsigned char stk2; + stk1 = S ^ T; + stk2 = *D ^ S; + stk1 = stk1 | stk2; + stk1 = ~stk1; + *D = (stk1 & S) | (stk1 & (~T)) | (T & (~S) & *D); +} + +/* STxDSxon source transparent/pattern opaque. */ +static void rop3_129_1_0 (unsigned char *D, unsigned char S, unsigned char T) +{ + unsigned char stk1; + unsigned char stk2; + stk1 = S ^ T; + stk2 = *D ^ S; + stk1 = stk1 | stk2; + stk1 = ~stk1; + *D = (stk1 & (~S)) | (*D & S); +} + +/* STxDSxon source/pattern transparent. */ +static void rop3_129_1_1 (unsigned char *D, unsigned char S, unsigned char T) +{ + unsigned char stk1; + unsigned char stk2; + stk1 = S ^ T; + stk2 = *D ^ S; + stk1 = stk1 | stk2; + stk1 = ~stk1; + *D = (stk1 & (~S) & (~T)) | (*D & S) | (*D & T); +} + +/* STxDSxon source/pattern opaque. */ +static unsigned xrop3_129_0_0 (unsigned char s, unsigned char t) +{ + unsigned D = 0x00ff; + unsigned S = ((unsigned)s << 8) | s; + unsigned T = ((unsigned)t << 8) | t; + unsigned stk1; + unsigned stk2; + stk1 = S ^ T; + stk2 = D ^ S; + stk1 = stk1 | stk2; + stk1 = ~stk1; + return stk1; +} + +/* STxDSxon source opaque/pattern transparent. */ +static unsigned xrop3_129_0_1 (unsigned char s, unsigned char t) +{ + unsigned D = 0x00ff; + unsigned S = ((unsigned)s << 8) | s; + unsigned T = ((unsigned)t << 8) | t; + unsigned stk1; + unsigned stk2; + stk1 = S ^ T; + stk2 = D ^ S; + stk1 = stk1 | stk2; + stk1 = ~stk1; + return (stk1 & S) | (stk1 & (~T)) | (T & (~S) & D); +} + +/* STxDSxon source transparent/pattern opaque. */ +static unsigned xrop3_129_1_0 (unsigned char s, unsigned char t) +{ + unsigned D = 0x00ff; + unsigned S = ((unsigned)s << 8) | s; + unsigned T = ((unsigned)t << 8) | t; + unsigned stk1; + unsigned stk2; + stk1 = S ^ T; + stk2 = D ^ S; + stk1 = stk1 | stk2; + stk1 = ~stk1; + return (stk1 & (~S)) | (D & S); +} + +/* STxDSxon source/pattern transparent. */ +static unsigned xrop3_129_1_1 (unsigned char s, unsigned char t) +{ + unsigned D = 0x00ff; + unsigned S = ((unsigned)s << 8) | s; + unsigned T = ((unsigned)t << 8) | t; + unsigned stk1; + unsigned stk2; + stk1 = S ^ T; + stk2 = D ^ S; + stk1 = stk1 | stk2; + stk1 = ~stk1; + return (stk1 & (~S) & (~T)) | (D & S) | (D & T); +} + +/* DTSxna source/pattern opaque. */ +static void rop3_130_0_0 (unsigned char *D, unsigned char S, unsigned char T) +{ + unsigned char stk1; + unsigned char stk2; + stk2 = T ^ S; + stk2 = ~stk2; + stk1 = *D & stk2; + *D = stk1; +} + +/* DTSxna source opaque/pattern transparent. */ +static void rop3_130_0_1 (unsigned char *D, unsigned char S, unsigned char T) +{ + unsigned char stk1; + unsigned char stk2; + stk2 = T ^ S; + stk2 = ~stk2; + stk1 = *D & stk2; + *D = (stk1 & S) | (stk1 & (~T)) | (T & (~S) & *D); +} + +/* DTSxna source transparent/pattern opaque. */ +static void rop3_130_1_0 (unsigned char *D, unsigned char S, unsigned char T) +{ + unsigned char stk1; + unsigned char stk2; + stk2 = T ^ S; + stk2 = ~stk2; + stk1 = *D & stk2; + *D = (stk1 & (~S)) | (*D & S); +} + +/* DTSxna source/pattern transparent. */ +static void rop3_130_1_1 (unsigned char *D, unsigned char S, unsigned char T) +{ + unsigned char stk1; + unsigned char stk2; + stk2 = T ^ S; + stk2 = ~stk2; + stk1 = *D & stk2; + *D = (stk1 & (~S) & (~T)) | (*D & S) | (*D & T); +} + +/* DTSxna source/pattern opaque. */ +static unsigned xrop3_130_0_0 (unsigned char s, unsigned char t) +{ + unsigned D = 0x00ff; + unsigned S = ((unsigned)s << 8) | s; + unsigned T = ((unsigned)t << 8) | t; + unsigned stk1; + unsigned stk2; + stk2 = T ^ S; + stk2 = ~stk2; + stk1 = D & stk2; + return stk1; +} + +/* DTSxna source opaque/pattern transparent. */ +static unsigned xrop3_130_0_1 (unsigned char s, unsigned char t) +{ + unsigned D = 0x00ff; + unsigned S = ((unsigned)s << 8) | s; + unsigned T = ((unsigned)t << 8) | t; + unsigned stk1; + unsigned stk2; + stk2 = T ^ S; + stk2 = ~stk2; + stk1 = D & stk2; + return (stk1 & S) | (stk1 & (~T)) | (T & (~S) & D); +} + +/* DTSxna source transparent/pattern opaque. */ +static unsigned xrop3_130_1_0 (unsigned char s, unsigned char t) +{ + unsigned D = 0x00ff; + unsigned S = ((unsigned)s << 8) | s; + unsigned T = ((unsigned)t << 8) | t; + unsigned stk1; + unsigned stk2; + stk2 = T ^ S; + stk2 = ~stk2; + stk1 = D & stk2; + return (stk1 & (~S)) | (D & S); +} + +/* DTSxna source/pattern transparent. */ +static unsigned xrop3_130_1_1 (unsigned char s, unsigned char t) +{ + unsigned D = 0x00ff; + unsigned S = ((unsigned)s << 8) | s; + unsigned T = ((unsigned)t << 8) | t; + unsigned stk1; + unsigned stk2; + stk2 = T ^ S; + stk2 = ~stk2; + stk1 = D & stk2; + return (stk1 & (~S) & (~T)) | (D & S) | (D & T); +} + +/* STDSnoaxn source/pattern opaque. */ +static void rop3_131_0_0 (unsigned char *D, unsigned char S, unsigned char T) +{ + unsigned char stk1; + unsigned char stk2; + unsigned char stk3; + unsigned char stk4; + stk4 = ~S; + stk3 = *D | stk4; + stk2 = T & stk3; + stk1 = S ^ stk2; + stk1 = ~stk1; + *D = stk1; +} + +/* STDSnoaxn source opaque/pattern transparent. */ +static void rop3_131_0_1 (unsigned char *D, unsigned char S, unsigned char T) +{ + unsigned char stk1; + unsigned char stk2; + unsigned char stk3; + unsigned char stk4; + stk4 = ~S; + stk3 = *D | stk4; + stk2 = T & stk3; + stk1 = S ^ stk2; + stk1 = ~stk1; + *D = (stk1 & S) | (stk1 & (~T)) | (T & (~S) & *D); +} + +/* STDSnoaxn source transparent/pattern opaque. */ +static void rop3_131_1_0 (unsigned char *D, unsigned char S, unsigned char T) +{ + unsigned char stk1; + unsigned char stk2; + unsigned char stk3; + unsigned char stk4; + stk4 = ~S; + stk3 = *D | stk4; + stk2 = T & stk3; + stk1 = S ^ stk2; + stk1 = ~stk1; + *D = (stk1 & (~S)) | (*D & S); +} + +/* STDSnoaxn source/pattern transparent. */ +static void rop3_131_1_1 (unsigned char *D, unsigned char S, unsigned char T) +{ + unsigned char stk1; + unsigned char stk2; + unsigned char stk3; + unsigned char stk4; + stk4 = ~S; + stk3 = *D | stk4; + stk2 = T & stk3; + stk1 = S ^ stk2; + stk1 = ~stk1; + *D = (stk1 & (~S) & (~T)) | (*D & S) | (*D & T); +} + +/* STDSnoaxn source/pattern opaque. */ +static unsigned xrop3_131_0_0 (unsigned char s, unsigned char t) +{ + unsigned D = 0x00ff; + unsigned S = ((unsigned)s << 8) | s; + unsigned T = ((unsigned)t << 8) | t; + unsigned stk1; + unsigned stk2; + unsigned stk3; + unsigned stk4; + stk4 = ~S; + stk3 = D | stk4; + stk2 = T & stk3; + stk1 = S ^ stk2; + stk1 = ~stk1; + return stk1; +} + +/* STDSnoaxn source opaque/pattern transparent. */ +static unsigned xrop3_131_0_1 (unsigned char s, unsigned char t) +{ + unsigned D = 0x00ff; + unsigned S = ((unsigned)s << 8) | s; + unsigned T = ((unsigned)t << 8) | t; + unsigned stk1; + unsigned stk2; + unsigned stk3; + unsigned stk4; + stk4 = ~S; + stk3 = D | stk4; + stk2 = T & stk3; + stk1 = S ^ stk2; + stk1 = ~stk1; + return (stk1 & S) | (stk1 & (~T)) | (T & (~S) & D); +} + +/* STDSnoaxn source transparent/pattern opaque. */ +static unsigned xrop3_131_1_0 (unsigned char s, unsigned char t) +{ + unsigned D = 0x00ff; + unsigned S = ((unsigned)s << 8) | s; + unsigned T = ((unsigned)t << 8) | t; + unsigned stk1; + unsigned stk2; + unsigned stk3; + unsigned stk4; + stk4 = ~S; + stk3 = D | stk4; + stk2 = T & stk3; + stk1 = S ^ stk2; + stk1 = ~stk1; + return (stk1 & (~S)) | (D & S); +} + +/* STDSnoaxn source/pattern transparent. */ +static unsigned xrop3_131_1_1 (unsigned char s, unsigned char t) +{ + unsigned D = 0x00ff; + unsigned S = ((unsigned)s << 8) | s; + unsigned T = ((unsigned)t << 8) | t; + unsigned stk1; + unsigned stk2; + unsigned stk3; + unsigned stk4; + stk4 = ~S; + stk3 = D | stk4; + stk2 = T & stk3; + stk1 = S ^ stk2; + stk1 = ~stk1; + return (stk1 & (~S) & (~T)) | (D & S) | (D & T); +} + +/* SDTxna source/pattern opaque. */ +static void rop3_132_0_0 (unsigned char *D, unsigned char S, unsigned char T) +{ + unsigned char stk1; + unsigned char stk2; + stk2 = *D ^ T; + stk2 = ~stk2; + stk1 = S & stk2; + *D = stk1; +} + +/* SDTxna source opaque/pattern transparent. */ +static void rop3_132_0_1 (unsigned char *D, unsigned char S, unsigned char T) +{ + unsigned char stk1; + unsigned char stk2; + stk2 = *D ^ T; + stk2 = ~stk2; + stk1 = S & stk2; + *D = (stk1 & S) | (stk1 & (~T)) | (T & (~S) & *D); +} + +/* SDTxna source transparent/pattern opaque. */ +static void rop3_132_1_0 (unsigned char *D, unsigned char S, unsigned char T) +{ + unsigned char stk1; + unsigned char stk2; + stk2 = *D ^ T; + stk2 = ~stk2; + stk1 = S & stk2; + *D = (stk1 & (~S)) | (*D & S); +} + +/* SDTxna source/pattern transparent. */ +static void rop3_132_1_1 (unsigned char *D, unsigned char S, unsigned char T) +{ + unsigned char stk1; + unsigned char stk2; + stk2 = *D ^ T; + stk2 = ~stk2; + stk1 = S & stk2; + *D = (stk1 & (~S) & (~T)) | (*D & S) | (*D & T); +} + +/* SDTxna source/pattern opaque. */ +static unsigned xrop3_132_0_0 (unsigned char s, unsigned char t) +{ + unsigned D = 0x00ff; + unsigned S = ((unsigned)s << 8) | s; + unsigned T = ((unsigned)t << 8) | t; + unsigned stk1; + unsigned stk2; + stk2 = D ^ T; + stk2 = ~stk2; + stk1 = S & stk2; + return stk1; +} + +/* SDTxna source opaque/pattern transparent. */ +static unsigned xrop3_132_0_1 (unsigned char s, unsigned char t) +{ + unsigned D = 0x00ff; + unsigned S = ((unsigned)s << 8) | s; + unsigned T = ((unsigned)t << 8) | t; + unsigned stk1; + unsigned stk2; + stk2 = D ^ T; + stk2 = ~stk2; + stk1 = S & stk2; + return (stk1 & S) | (stk1 & (~T)) | (T & (~S) & D); +} + +/* SDTxna source transparent/pattern opaque. */ +static unsigned xrop3_132_1_0 (unsigned char s, unsigned char t) +{ + unsigned D = 0x00ff; + unsigned S = ((unsigned)s << 8) | s; + unsigned T = ((unsigned)t << 8) | t; + unsigned stk1; + unsigned stk2; + stk2 = D ^ T; + stk2 = ~stk2; + stk1 = S & stk2; + return (stk1 & (~S)) | (D & S); +} + +/* SDTxna source/pattern transparent. */ +static unsigned xrop3_132_1_1 (unsigned char s, unsigned char t) +{ + unsigned D = 0x00ff; + unsigned S = ((unsigned)s << 8) | s; + unsigned T = ((unsigned)t << 8) | t; + unsigned stk1; + unsigned stk2; + stk2 = D ^ T; + stk2 = ~stk2; + stk1 = S & stk2; + return (stk1 & (~S) & (~T)) | (D & S) | (D & T); +} + +/* TDSTnoaxn source/pattern opaque. */ +static void rop3_133_0_0 (unsigned char *D, unsigned char S, unsigned char T) +{ + unsigned char stk1; + unsigned char stk2; + unsigned char stk3; + unsigned char stk4; + stk4 = ~T; + stk3 = S | stk4; + stk2 = *D & stk3; + stk1 = T ^ stk2; + stk1 = ~stk1; + *D = stk1; +} + +/* TDSTnoaxn source opaque/pattern transparent. */ +static void rop3_133_0_1 (unsigned char *D, unsigned char S, unsigned char T) +{ + unsigned char stk1; + unsigned char stk2; + unsigned char stk3; + unsigned char stk4; + stk4 = ~T; + stk3 = S | stk4; + stk2 = *D & stk3; + stk1 = T ^ stk2; + stk1 = ~stk1; + *D = (stk1 & S) | (stk1 & (~T)) | (T & (~S) & *D); +} + +/* TDSTnoaxn source transparent/pattern opaque. */ +static void rop3_133_1_0 (unsigned char *D, unsigned char S, unsigned char T) +{ + unsigned char stk1; + unsigned char stk2; + unsigned char stk3; + unsigned char stk4; + stk4 = ~T; + stk3 = S | stk4; + stk2 = *D & stk3; + stk1 = T ^ stk2; + stk1 = ~stk1; + *D = (stk1 & (~S)) | (*D & S); +} + +/* TDSTnoaxn source/pattern transparent. */ +static void rop3_133_1_1 (unsigned char *D, unsigned char S, unsigned char T) +{ + unsigned char stk1; + unsigned char stk2; + unsigned char stk3; + unsigned char stk4; + stk4 = ~T; + stk3 = S | stk4; + stk2 = *D & stk3; + stk1 = T ^ stk2; + stk1 = ~stk1; + *D = (stk1 & (~S) & (~T)) | (*D & S) | (*D & T); +} + +/* TDSTnoaxn source/pattern opaque. */ +static unsigned xrop3_133_0_0 (unsigned char s, unsigned char t) +{ + unsigned D = 0x00ff; + unsigned S = ((unsigned)s << 8) | s; + unsigned T = ((unsigned)t << 8) | t; + unsigned stk1; + unsigned stk2; + unsigned stk3; + unsigned stk4; + stk4 = ~T; + stk3 = S | stk4; + stk2 = D & stk3; + stk1 = T ^ stk2; + stk1 = ~stk1; + return stk1; +} + +/* TDSTnoaxn source opaque/pattern transparent. */ +static unsigned xrop3_133_0_1 (unsigned char s, unsigned char t) +{ + unsigned D = 0x00ff; + unsigned S = ((unsigned)s << 8) | s; + unsigned T = ((unsigned)t << 8) | t; + unsigned stk1; + unsigned stk2; + unsigned stk3; + unsigned stk4; + stk4 = ~T; + stk3 = S | stk4; + stk2 = D & stk3; + stk1 = T ^ stk2; + stk1 = ~stk1; + return (stk1 & S) | (stk1 & (~T)) | (T & (~S) & D); +} + +/* TDSTnoaxn source transparent/pattern opaque. */ +static unsigned xrop3_133_1_0 (unsigned char s, unsigned char t) +{ + unsigned D = 0x00ff; + unsigned S = ((unsigned)s << 8) | s; + unsigned T = ((unsigned)t << 8) | t; + unsigned stk1; + unsigned stk2; + unsigned stk3; + unsigned stk4; + stk4 = ~T; + stk3 = S | stk4; + stk2 = D & stk3; + stk1 = T ^ stk2; + stk1 = ~stk1; + return (stk1 & (~S)) | (D & S); +} + +/* TDSTnoaxn source/pattern transparent. */ +static unsigned xrop3_133_1_1 (unsigned char s, unsigned char t) +{ + unsigned D = 0x00ff; + unsigned S = ((unsigned)s << 8) | s; + unsigned T = ((unsigned)t << 8) | t; + unsigned stk1; + unsigned stk2; + unsigned stk3; + unsigned stk4; + stk4 = ~T; + stk3 = S | stk4; + stk2 = D & stk3; + stk1 = T ^ stk2; + stk1 = ~stk1; + return (stk1 & (~S) & (~T)) | (D & S) | (D & T); +} + +/* DSTDSoaxx source/pattern opaque. */ +static void rop3_134_0_0 (unsigned char *D, unsigned char S, unsigned char T) +{ + unsigned char stk1; + unsigned char stk2; + unsigned char stk3; + unsigned char stk4; + stk4 = *D | S; + stk3 = T & stk4; + stk2 = S ^ stk3; + stk1 = *D ^ stk2; + *D = stk1; +} + +/* DSTDSoaxx source opaque/pattern transparent. */ +static void rop3_134_0_1 (unsigned char *D, unsigned char S, unsigned char T) +{ + unsigned char stk1; + unsigned char stk2; + unsigned char stk3; + unsigned char stk4; + stk4 = *D | S; + stk3 = T & stk4; + stk2 = S ^ stk3; + stk1 = *D ^ stk2; + *D = (stk1 & S) | (stk1 & (~T)) | (T & (~S) & *D); +} + +/* DSTDSoaxx source transparent/pattern opaque. */ +static void rop3_134_1_0 (unsigned char *D, unsigned char S, unsigned char T) +{ + unsigned char stk1; + unsigned char stk2; + unsigned char stk3; + unsigned char stk4; + stk4 = *D | S; + stk3 = T & stk4; + stk2 = S ^ stk3; + stk1 = *D ^ stk2; + *D = (stk1 & (~S)) | (*D & S); +} + +/* DSTDSoaxx source/pattern transparent. */ +static void rop3_134_1_1 (unsigned char *D, unsigned char S, unsigned char T) +{ + unsigned char stk1; + unsigned char stk2; + unsigned char stk3; + unsigned char stk4; + stk4 = *D | S; + stk3 = T & stk4; + stk2 = S ^ stk3; + stk1 = *D ^ stk2; + *D = (stk1 & (~S) & (~T)) | (*D & S) | (*D & T); +} + +/* DSTDSoaxx source/pattern opaque. */ +static unsigned xrop3_134_0_0 (unsigned char s, unsigned char t) +{ + unsigned D = 0x00ff; + unsigned S = ((unsigned)s << 8) | s; + unsigned T = ((unsigned)t << 8) | t; + unsigned stk1; + unsigned stk2; + unsigned stk3; + unsigned stk4; + stk4 = D | S; + stk3 = T & stk4; + stk2 = S ^ stk3; + stk1 = D ^ stk2; + return stk1; +} + +/* DSTDSoaxx source opaque/pattern transparent. */ +static unsigned xrop3_134_0_1 (unsigned char s, unsigned char t) +{ + unsigned D = 0x00ff; + unsigned S = ((unsigned)s << 8) | s; + unsigned T = ((unsigned)t << 8) | t; + unsigned stk1; + unsigned stk2; + unsigned stk3; + unsigned stk4; + stk4 = D | S; + stk3 = T & stk4; + stk2 = S ^ stk3; + stk1 = D ^ stk2; + return (stk1 & S) | (stk1 & (~T)) | (T & (~S) & D); +} + +/* DSTDSoaxx source transparent/pattern opaque. */ +static unsigned xrop3_134_1_0 (unsigned char s, unsigned char t) +{ + unsigned D = 0x00ff; + unsigned S = ((unsigned)s << 8) | s; + unsigned T = ((unsigned)t << 8) | t; + unsigned stk1; + unsigned stk2; + unsigned stk3; + unsigned stk4; + stk4 = D | S; + stk3 = T & stk4; + stk2 = S ^ stk3; + stk1 = D ^ stk2; + return (stk1 & (~S)) | (D & S); +} + +/* DSTDSoaxx source/pattern transparent. */ +static unsigned xrop3_134_1_1 (unsigned char s, unsigned char t) +{ + unsigned D = 0x00ff; + unsigned S = ((unsigned)s << 8) | s; + unsigned T = ((unsigned)t << 8) | t; + unsigned stk1; + unsigned stk2; + unsigned stk3; + unsigned stk4; + stk4 = D | S; + stk3 = T & stk4; + stk2 = S ^ stk3; + stk1 = D ^ stk2; + return (stk1 & (~S) & (~T)) | (D & S) | (D & T); +} + +/* TDSaxn source/pattern opaque. */ +static void rop3_135_0_0 (unsigned char *D, unsigned char S, unsigned char T) +{ + unsigned char stk1; + unsigned char stk2; + stk2 = *D & S; + stk1 = T ^ stk2; + stk1 = ~stk1; + *D = stk1; +} + +/* TDSaxn source opaque/pattern transparent. */ +static void rop3_135_0_1 (unsigned char *D, unsigned char S, unsigned char T) +{ + unsigned char stk1; + unsigned char stk2; + stk2 = *D & S; + stk1 = T ^ stk2; + stk1 = ~stk1; + *D = (stk1 & S) | (stk1 & (~T)) | (T & (~S) & *D); +} + +/* TDSaxn source transparent/pattern opaque. */ +static void rop3_135_1_0 (unsigned char *D, unsigned char S, unsigned char T) +{ + unsigned char stk1; + unsigned char stk2; + stk2 = *D & S; + stk1 = T ^ stk2; + stk1 = ~stk1; + *D = (stk1 & (~S)) | (*D & S); +} + +/* TDSaxn source/pattern transparent. */ +static void rop3_135_1_1 (unsigned char *D, unsigned char S, unsigned char T) +{ + unsigned char stk1; + unsigned char stk2; + stk2 = *D & S; + stk1 = T ^ stk2; + stk1 = ~stk1; + *D = (stk1 & (~S) & (~T)) | (*D & S) | (*D & T); +} + +/* TDSaxn source/pattern opaque. */ +static unsigned xrop3_135_0_0 (unsigned char s, unsigned char t) +{ + unsigned D = 0x00ff; + unsigned S = ((unsigned)s << 8) | s; + unsigned T = ((unsigned)t << 8) | t; + unsigned stk1; + unsigned stk2; + stk2 = D & S; + stk1 = T ^ stk2; + stk1 = ~stk1; + return stk1; +} + +/* TDSaxn source opaque/pattern transparent. */ +static unsigned xrop3_135_0_1 (unsigned char s, unsigned char t) +{ + unsigned D = 0x00ff; + unsigned S = ((unsigned)s << 8) | s; + unsigned T = ((unsigned)t << 8) | t; + unsigned stk1; + unsigned stk2; + stk2 = D & S; + stk1 = T ^ stk2; + stk1 = ~stk1; + return (stk1 & S) | (stk1 & (~T)) | (T & (~S) & D); +} + +/* TDSaxn source transparent/pattern opaque. */ +static unsigned xrop3_135_1_0 (unsigned char s, unsigned char t) +{ + unsigned D = 0x00ff; + unsigned S = ((unsigned)s << 8) | s; + unsigned T = ((unsigned)t << 8) | t; + unsigned stk1; + unsigned stk2; + stk2 = D & S; + stk1 = T ^ stk2; + stk1 = ~stk1; + return (stk1 & (~S)) | (D & S); +} + +/* TDSaxn source/pattern transparent. */ +static unsigned xrop3_135_1_1 (unsigned char s, unsigned char t) +{ + unsigned D = 0x00ff; + unsigned S = ((unsigned)s << 8) | s; + unsigned T = ((unsigned)t << 8) | t; + unsigned stk1; + unsigned stk2; + stk2 = D & S; + stk1 = T ^ stk2; + stk1 = ~stk1; + return (stk1 & (~S) & (~T)) | (D & S) | (D & T); +} + +/* DSa source/pattern opaque. */ +static void rop3_136_0_0 (unsigned char *D, unsigned char S, unsigned char T) +{ + unsigned char stk1; + stk1 = *D & S; + *D = stk1; +} + +/* DSa source opaque/pattern transparent. */ +static void rop3_136_0_1 (unsigned char *D, unsigned char S, unsigned char T) +{ + unsigned char stk1; + stk1 = *D & S; + *D = (stk1 & S) | (stk1 & (~T)) | (T & (~S) & *D); +} + +/* DSa source transparent/pattern opaque. */ +static void rop3_136_1_0 (unsigned char *D, unsigned char S, unsigned char T) +{ + unsigned char stk1; + stk1 = *D & S; + *D = (stk1 & (~S)) | (*D & S); +} + +/* DSa source/pattern transparent. */ +static void rop3_136_1_1 (unsigned char *D, unsigned char S, unsigned char T) +{ + unsigned char stk1; + stk1 = *D & S; + *D = (stk1 & (~S) & (~T)) | (*D & S) | (*D & T); +} + +/* DSa source/pattern opaque. */ +static unsigned xrop3_136_0_0 (unsigned char s, unsigned char t) +{ + unsigned D = 0x00ff; + unsigned S = ((unsigned)s << 8) | s; + unsigned stk1; + stk1 = D & S; + return stk1; +} + +/* DSa source opaque/pattern transparent. */ +static unsigned xrop3_136_0_1 (unsigned char s, unsigned char t) +{ + unsigned D = 0x00ff; + unsigned S = ((unsigned)s << 8) | s; + unsigned T = ((unsigned)t << 8) | t; + unsigned stk1; + stk1 = D & S; + return (stk1 & S) | (stk1 & (~T)) | (T & (~S) & D); +} + +/* DSa source transparent/pattern opaque. */ +static unsigned xrop3_136_1_0 (unsigned char s, unsigned char t) +{ + unsigned D = 0x00ff; + unsigned S = ((unsigned)s << 8) | s; + unsigned stk1; + stk1 = D & S; + return (stk1 & (~S)) | (D & S); +} + +/* DSa source/pattern transparent. */ +static unsigned xrop3_136_1_1 (unsigned char s, unsigned char t) +{ + unsigned D = 0x00ff; + unsigned S = ((unsigned)s << 8) | s; + unsigned T = ((unsigned)t << 8) | t; + unsigned stk1; + stk1 = D & S; + return (stk1 & (~S) & (~T)) | (D & S) | (D & T); +} + +/* SDTSnaoxn source/pattern opaque. */ +static void rop3_137_0_0 (unsigned char *D, unsigned char S, unsigned char T) +{ + unsigned char stk1; + unsigned char stk2; + unsigned char stk3; + unsigned char stk4; + stk4 = ~S; + stk3 = T & stk4; + stk2 = *D | stk3; + stk1 = S ^ stk2; + stk1 = ~stk1; + *D = stk1; +} + +/* SDTSnaoxn source opaque/pattern transparent. */ +static void rop3_137_0_1 (unsigned char *D, unsigned char S, unsigned char T) +{ + unsigned char stk1; + unsigned char stk2; + unsigned char stk3; + unsigned char stk4; + stk4 = ~S; + stk3 = T & stk4; + stk2 = *D | stk3; + stk1 = S ^ stk2; + stk1 = ~stk1; + *D = (stk1 & S) | (stk1 & (~T)) | (T & (~S) & *D); +} + +/* SDTSnaoxn source transparent/pattern opaque. */ +static void rop3_137_1_0 (unsigned char *D, unsigned char S, unsigned char T) +{ + unsigned char stk1; + unsigned char stk2; + unsigned char stk3; + unsigned char stk4; + stk4 = ~S; + stk3 = T & stk4; + stk2 = *D | stk3; + stk1 = S ^ stk2; + stk1 = ~stk1; + *D = (stk1 & (~S)) | (*D & S); +} + +/* SDTSnaoxn source/pattern transparent. */ +static void rop3_137_1_1 (unsigned char *D, unsigned char S, unsigned char T) +{ + unsigned char stk1; + unsigned char stk2; + unsigned char stk3; + unsigned char stk4; + stk4 = ~S; + stk3 = T & stk4; + stk2 = *D | stk3; + stk1 = S ^ stk2; + stk1 = ~stk1; + *D = (stk1 & (~S) & (~T)) | (*D & S) | (*D & T); +} + +/* SDTSnaoxn source/pattern opaque. */ +static unsigned xrop3_137_0_0 (unsigned char s, unsigned char t) +{ + unsigned D = 0x00ff; + unsigned S = ((unsigned)s << 8) | s; + unsigned T = ((unsigned)t << 8) | t; + unsigned stk1; + unsigned stk2; + unsigned stk3; + unsigned stk4; + stk4 = ~S; + stk3 = T & stk4; + stk2 = D | stk3; + stk1 = S ^ stk2; + stk1 = ~stk1; + return stk1; +} + +/* SDTSnaoxn source opaque/pattern transparent. */ +static unsigned xrop3_137_0_1 (unsigned char s, unsigned char t) +{ + unsigned D = 0x00ff; + unsigned S = ((unsigned)s << 8) | s; + unsigned T = ((unsigned)t << 8) | t; + unsigned stk1; + unsigned stk2; + unsigned stk3; + unsigned stk4; + stk4 = ~S; + stk3 = T & stk4; + stk2 = D | stk3; + stk1 = S ^ stk2; + stk1 = ~stk1; + return (stk1 & S) | (stk1 & (~T)) | (T & (~S) & D); +} + +/* SDTSnaoxn source transparent/pattern opaque. */ +static unsigned xrop3_137_1_0 (unsigned char s, unsigned char t) +{ + unsigned D = 0x00ff; + unsigned S = ((unsigned)s << 8) | s; + unsigned T = ((unsigned)t << 8) | t; + unsigned stk1; + unsigned stk2; + unsigned stk3; + unsigned stk4; + stk4 = ~S; + stk3 = T & stk4; + stk2 = D | stk3; + stk1 = S ^ stk2; + stk1 = ~stk1; + return (stk1 & (~S)) | (D & S); +} + +/* SDTSnaoxn source/pattern transparent. */ +static unsigned xrop3_137_1_1 (unsigned char s, unsigned char t) +{ + unsigned D = 0x00ff; + unsigned S = ((unsigned)s << 8) | s; + unsigned T = ((unsigned)t << 8) | t; + unsigned stk1; + unsigned stk2; + unsigned stk3; + unsigned stk4; + stk4 = ~S; + stk3 = T & stk4; + stk2 = D | stk3; + stk1 = S ^ stk2; + stk1 = ~stk1; + return (stk1 & (~S) & (~T)) | (D & S) | (D & T); +} + +/* DSTnoa source/pattern opaque. */ +static void rop3_138_0_0 (unsigned char *D, unsigned char S, unsigned char T) +{ + unsigned char stk1; + unsigned char stk2; + unsigned char stk3; + stk3 = ~T; + stk2 = S | stk3; + stk1 = *D & stk2; + *D = stk1; +} + +/* DSTnoa source opaque/pattern transparent. */ +static void rop3_138_0_1 (unsigned char *D, unsigned char S, unsigned char T) +{ + unsigned char stk1; + unsigned char stk2; + unsigned char stk3; + stk3 = ~T; + stk2 = S | stk3; + stk1 = *D & stk2; + *D = (stk1 & S) | (stk1 & (~T)) | (T & (~S) & *D); +} + +/* DSTnoa source transparent/pattern opaque. */ +static void rop3_138_1_0 (unsigned char *D, unsigned char S, unsigned char T) +{ + unsigned char stk1; + unsigned char stk2; + unsigned char stk3; + stk3 = ~T; + stk2 = S | stk3; + stk1 = *D & stk2; + *D = (stk1 & (~S)) | (*D & S); +} + +/* DSTnoa source/pattern transparent. */ +static void rop3_138_1_1 (unsigned char *D, unsigned char S, unsigned char T) +{ + unsigned char stk1; + unsigned char stk2; + unsigned char stk3; + stk3 = ~T; + stk2 = S | stk3; + stk1 = *D & stk2; + *D = (stk1 & (~S) & (~T)) | (*D & S) | (*D & T); +} + +/* DSTnoa source/pattern opaque. */ +static unsigned xrop3_138_0_0 (unsigned char s, unsigned char t) +{ + unsigned D = 0x00ff; + unsigned S = ((unsigned)s << 8) | s; + unsigned T = ((unsigned)t << 8) | t; + unsigned stk1; + unsigned stk2; + unsigned stk3; + stk3 = ~T; + stk2 = S | stk3; + stk1 = D & stk2; + return stk1; +} + +/* DSTnoa source opaque/pattern transparent. */ +static unsigned xrop3_138_0_1 (unsigned char s, unsigned char t) +{ + unsigned D = 0x00ff; + unsigned S = ((unsigned)s << 8) | s; + unsigned T = ((unsigned)t << 8) | t; + unsigned stk1; + unsigned stk2; + unsigned stk3; + stk3 = ~T; + stk2 = S | stk3; + stk1 = D & stk2; + return (stk1 & S) | (stk1 & (~T)) | (T & (~S) & D); +} + +/* DSTnoa source transparent/pattern opaque. */ +static unsigned xrop3_138_1_0 (unsigned char s, unsigned char t) +{ + unsigned D = 0x00ff; + unsigned S = ((unsigned)s << 8) | s; + unsigned T = ((unsigned)t << 8) | t; + unsigned stk1; + unsigned stk2; + unsigned stk3; + stk3 = ~T; + stk2 = S | stk3; + stk1 = D & stk2; + return (stk1 & (~S)) | (D & S); +} + +/* DSTnoa source/pattern transparent. */ +static unsigned xrop3_138_1_1 (unsigned char s, unsigned char t) +{ + unsigned D = 0x00ff; + unsigned S = ((unsigned)s << 8) | s; + unsigned T = ((unsigned)t << 8) | t; + unsigned stk1; + unsigned stk2; + unsigned stk3; + stk3 = ~T; + stk2 = S | stk3; + stk1 = D & stk2; + return (stk1 & (~S) & (~T)) | (D & S) | (D & T); +} + +/* DSTDxoxn source/pattern opaque. */ +static void rop3_139_0_0 (unsigned char *D, unsigned char S, unsigned char T) +{ + unsigned char stk1; + unsigned char stk2; + unsigned char stk3; + stk3 = T ^ *D; + stk2 = S | stk3; + stk1 = *D ^ stk2; + stk1 = ~stk1; + *D = stk1; +} + +/* DSTDxoxn source opaque/pattern transparent. */ +static void rop3_139_0_1 (unsigned char *D, unsigned char S, unsigned char T) +{ + unsigned char stk1; + unsigned char stk2; + unsigned char stk3; + stk3 = T ^ *D; + stk2 = S | stk3; + stk1 = *D ^ stk2; + stk1 = ~stk1; + *D = (stk1 & S) | (stk1 & (~T)) | (T & (~S) & *D); +} + +/* DSTDxoxn source transparent/pattern opaque. */ +static void rop3_139_1_0 (unsigned char *D, unsigned char S, unsigned char T) +{ + unsigned char stk1; + unsigned char stk2; + unsigned char stk3; + stk3 = T ^ *D; + stk2 = S | stk3; + stk1 = *D ^ stk2; + stk1 = ~stk1; + *D = (stk1 & (~S)) | (*D & S); +} + +/* DSTDxoxn source/pattern transparent. */ +static void rop3_139_1_1 (unsigned char *D, unsigned char S, unsigned char T) +{ + unsigned char stk1; + unsigned char stk2; + unsigned char stk3; + stk3 = T ^ *D; + stk2 = S | stk3; + stk1 = *D ^ stk2; + stk1 = ~stk1; + *D = (stk1 & (~S) & (~T)) | (*D & S) | (*D & T); +} + +/* DSTDxoxn source/pattern opaque. */ +static unsigned xrop3_139_0_0 (unsigned char s, unsigned char t) +{ + unsigned D = 0x00ff; + unsigned S = ((unsigned)s << 8) | s; + unsigned T = ((unsigned)t << 8) | t; + unsigned stk1; + unsigned stk2; + unsigned stk3; + stk3 = T ^ D; + stk2 = S | stk3; + stk1 = D ^ stk2; + stk1 = ~stk1; + return stk1; +} + +/* DSTDxoxn source opaque/pattern transparent. */ +static unsigned xrop3_139_0_1 (unsigned char s, unsigned char t) +{ + unsigned D = 0x00ff; + unsigned S = ((unsigned)s << 8) | s; + unsigned T = ((unsigned)t << 8) | t; + unsigned stk1; + unsigned stk2; + unsigned stk3; + stk3 = T ^ D; + stk2 = S | stk3; + stk1 = D ^ stk2; + stk1 = ~stk1; + return (stk1 & S) | (stk1 & (~T)) | (T & (~S) & D); +} + +/* DSTDxoxn source transparent/pattern opaque. */ +static unsigned xrop3_139_1_0 (unsigned char s, unsigned char t) +{ + unsigned D = 0x00ff; + unsigned S = ((unsigned)s << 8) | s; + unsigned T = ((unsigned)t << 8) | t; + unsigned stk1; + unsigned stk2; + unsigned stk3; + stk3 = T ^ D; + stk2 = S | stk3; + stk1 = D ^ stk2; + stk1 = ~stk1; + return (stk1 & (~S)) | (D & S); +} + +/* DSTDxoxn source/pattern transparent. */ +static unsigned xrop3_139_1_1 (unsigned char s, unsigned char t) +{ + unsigned D = 0x00ff; + unsigned S = ((unsigned)s << 8) | s; + unsigned T = ((unsigned)t << 8) | t; + unsigned stk1; + unsigned stk2; + unsigned stk3; + stk3 = T ^ D; + stk2 = S | stk3; + stk1 = D ^ stk2; + stk1 = ~stk1; + return (stk1 & (~S) & (~T)) | (D & S) | (D & T); +} + +/* SDTnoa source/pattern opaque. */ +static void rop3_140_0_0 (unsigned char *D, unsigned char S, unsigned char T) +{ + unsigned char stk1; + unsigned char stk2; + unsigned char stk3; + stk3 = ~T; + stk2 = *D | stk3; + stk1 = S & stk2; + *D = stk1; +} + +/* SDTnoa source opaque/pattern transparent. */ +static void rop3_140_0_1 (unsigned char *D, unsigned char S, unsigned char T) +{ + unsigned char stk1; + unsigned char stk2; + unsigned char stk3; + stk3 = ~T; + stk2 = *D | stk3; + stk1 = S & stk2; + *D = (stk1 & S) | (stk1 & (~T)) | (T & (~S) & *D); +} + +/* SDTnoa source transparent/pattern opaque. */ +static void rop3_140_1_0 (unsigned char *D, unsigned char S, unsigned char T) +{ + unsigned char stk1; + unsigned char stk2; + unsigned char stk3; + stk3 = ~T; + stk2 = *D | stk3; + stk1 = S & stk2; + *D = (stk1 & (~S)) | (*D & S); +} + +/* SDTnoa source/pattern transparent. */ +static void rop3_140_1_1 (unsigned char *D, unsigned char S, unsigned char T) +{ + unsigned char stk1; + unsigned char stk2; + unsigned char stk3; + stk3 = ~T; + stk2 = *D | stk3; + stk1 = S & stk2; + *D = (stk1 & (~S) & (~T)) | (*D & S) | (*D & T); +} + +/* SDTnoa source/pattern opaque. */ +static unsigned xrop3_140_0_0 (unsigned char s, unsigned char t) +{ + unsigned D = 0x00ff; + unsigned S = ((unsigned)s << 8) | s; + unsigned T = ((unsigned)t << 8) | t; + unsigned stk1; + unsigned stk2; + unsigned stk3; + stk3 = ~T; + stk2 = D | stk3; + stk1 = S & stk2; + return stk1; +} + +/* SDTnoa source opaque/pattern transparent. */ +static unsigned xrop3_140_0_1 (unsigned char s, unsigned char t) +{ + unsigned D = 0x00ff; + unsigned S = ((unsigned)s << 8) | s; + unsigned T = ((unsigned)t << 8) | t; + unsigned stk1; + unsigned stk2; + unsigned stk3; + stk3 = ~T; + stk2 = D | stk3; + stk1 = S & stk2; + return (stk1 & S) | (stk1 & (~T)) | (T & (~S) & D); +} + +/* SDTnoa source transparent/pattern opaque. */ +static unsigned xrop3_140_1_0 (unsigned char s, unsigned char t) +{ + unsigned D = 0x00ff; + unsigned S = ((unsigned)s << 8) | s; + unsigned T = ((unsigned)t << 8) | t; + unsigned stk1; + unsigned stk2; + unsigned stk3; + stk3 = ~T; + stk2 = D | stk3; + stk1 = S & stk2; + return (stk1 & (~S)) | (D & S); +} + +/* SDTnoa source/pattern transparent. */ +static unsigned xrop3_140_1_1 (unsigned char s, unsigned char t) +{ + unsigned D = 0x00ff; + unsigned S = ((unsigned)s << 8) | s; + unsigned T = ((unsigned)t << 8) | t; + unsigned stk1; + unsigned stk2; + unsigned stk3; + stk3 = ~T; + stk2 = D | stk3; + stk1 = S & stk2; + return (stk1 & (~S) & (~T)) | (D & S) | (D & T); +} + +/* SDTSxoxn source/pattern opaque. */ +static void rop3_141_0_0 (unsigned char *D, unsigned char S, unsigned char T) +{ + unsigned char stk1; + unsigned char stk2; + unsigned char stk3; + stk3 = T ^ S; + stk2 = *D | stk3; + stk1 = S ^ stk2; + stk1 = ~stk1; + *D = stk1; +} + +/* SDTSxoxn source opaque/pattern transparent. */ +static void rop3_141_0_1 (unsigned char *D, unsigned char S, unsigned char T) +{ + unsigned char stk1; + unsigned char stk2; + unsigned char stk3; + stk3 = T ^ S; + stk2 = *D | stk3; + stk1 = S ^ stk2; + stk1 = ~stk1; + *D = (stk1 & S) | (stk1 & (~T)) | (T & (~S) & *D); +} + +/* SDTSxoxn source transparent/pattern opaque. */ +static void rop3_141_1_0 (unsigned char *D, unsigned char S, unsigned char T) +{ + unsigned char stk1; + unsigned char stk2; + unsigned char stk3; + stk3 = T ^ S; + stk2 = *D | stk3; + stk1 = S ^ stk2; + stk1 = ~stk1; + *D = (stk1 & (~S)) | (*D & S); +} + +/* SDTSxoxn source/pattern transparent. */ +static void rop3_141_1_1 (unsigned char *D, unsigned char S, unsigned char T) +{ + unsigned char stk1; + unsigned char stk2; + unsigned char stk3; + stk3 = T ^ S; + stk2 = *D | stk3; + stk1 = S ^ stk2; + stk1 = ~stk1; + *D = (stk1 & (~S) & (~T)) | (*D & S) | (*D & T); +} + +/* SDTSxoxn source/pattern opaque. */ +static unsigned xrop3_141_0_0 (unsigned char s, unsigned char t) +{ + unsigned D = 0x00ff; + unsigned S = ((unsigned)s << 8) | s; + unsigned T = ((unsigned)t << 8) | t; + unsigned stk1; + unsigned stk2; + unsigned stk3; + stk3 = T ^ S; + stk2 = D | stk3; + stk1 = S ^ stk2; + stk1 = ~stk1; + return stk1; +} + +/* SDTSxoxn source opaque/pattern transparent. */ +static unsigned xrop3_141_0_1 (unsigned char s, unsigned char t) +{ + unsigned D = 0x00ff; + unsigned S = ((unsigned)s << 8) | s; + unsigned T = ((unsigned)t << 8) | t; + unsigned stk1; + unsigned stk2; + unsigned stk3; + stk3 = T ^ S; + stk2 = D | stk3; + stk1 = S ^ stk2; + stk1 = ~stk1; + return (stk1 & S) | (stk1 & (~T)) | (T & (~S) & D); +} + +/* SDTSxoxn source transparent/pattern opaque. */ +static unsigned xrop3_141_1_0 (unsigned char s, unsigned char t) +{ + unsigned D = 0x00ff; + unsigned S = ((unsigned)s << 8) | s; + unsigned T = ((unsigned)t << 8) | t; + unsigned stk1; + unsigned stk2; + unsigned stk3; + stk3 = T ^ S; + stk2 = D | stk3; + stk1 = S ^ stk2; + stk1 = ~stk1; + return (stk1 & (~S)) | (D & S); +} + +/* SDTSxoxn source/pattern transparent. */ +static unsigned xrop3_141_1_1 (unsigned char s, unsigned char t) +{ + unsigned D = 0x00ff; + unsigned S = ((unsigned)s << 8) | s; + unsigned T = ((unsigned)t << 8) | t; + unsigned stk1; + unsigned stk2; + unsigned stk3; + stk3 = T ^ S; + stk2 = D | stk3; + stk1 = S ^ stk2; + stk1 = ~stk1; + return (stk1 & (~S) & (~T)) | (D & S) | (D & T); +} + +/* SSDxTDxax source/pattern opaque. */ +static void rop3_142_0_0 (unsigned char *D, unsigned char S, unsigned char T) +{ + unsigned char stk1; + unsigned char stk2; + unsigned char stk3; + stk2 = S ^ *D; + stk3 = T ^ *D; + stk2 = stk2 & stk3; + stk1 = S ^ stk2; + *D = stk1; +} + +/* SSDxTDxax source opaque/pattern transparent. */ +static void rop3_142_0_1 (unsigned char *D, unsigned char S, unsigned char T) +{ + unsigned char stk1; + unsigned char stk2; + unsigned char stk3; + stk2 = S ^ *D; + stk3 = T ^ *D; + stk2 = stk2 & stk3; + stk1 = S ^ stk2; + *D = (stk1 & S) | (stk1 & (~T)) | (T & (~S) & *D); +} + +/* SSDxTDxax source transparent/pattern opaque. */ +static void rop3_142_1_0 (unsigned char *D, unsigned char S, unsigned char T) +{ + unsigned char stk1; + unsigned char stk2; + unsigned char stk3; + stk2 = S ^ *D; + stk3 = T ^ *D; + stk2 = stk2 & stk3; + stk1 = S ^ stk2; + *D = (stk1 & (~S)) | (*D & S); +} + +/* SSDxTDxax source/pattern transparent. */ +static void rop3_142_1_1 (unsigned char *D, unsigned char S, unsigned char T) +{ + unsigned char stk1; + unsigned char stk2; + unsigned char stk3; + stk2 = S ^ *D; + stk3 = T ^ *D; + stk2 = stk2 & stk3; + stk1 = S ^ stk2; + *D = (stk1 & (~S) & (~T)) | (*D & S) | (*D & T); +} + +/* SSDxTDxax source/pattern opaque. */ +static unsigned xrop3_142_0_0 (unsigned char s, unsigned char t) +{ + unsigned D = 0x00ff; + unsigned S = ((unsigned)s << 8) | s; + unsigned T = ((unsigned)t << 8) | t; + unsigned stk1; + unsigned stk2; + unsigned stk3; + stk2 = S ^ D; + stk3 = T ^ D; + stk2 = stk2 & stk3; + stk1 = S ^ stk2; + return stk1; +} + +/* SSDxTDxax source opaque/pattern transparent. */ +static unsigned xrop3_142_0_1 (unsigned char s, unsigned char t) +{ + unsigned D = 0x00ff; + unsigned S = ((unsigned)s << 8) | s; + unsigned T = ((unsigned)t << 8) | t; + unsigned stk1; + unsigned stk2; + unsigned stk3; + stk2 = S ^ D; + stk3 = T ^ D; + stk2 = stk2 & stk3; + stk1 = S ^ stk2; + return (stk1 & S) | (stk1 & (~T)) | (T & (~S) & D); +} + +/* SSDxTDxax source transparent/pattern opaque. */ +static unsigned xrop3_142_1_0 (unsigned char s, unsigned char t) +{ + unsigned D = 0x00ff; + unsigned S = ((unsigned)s << 8) | s; + unsigned T = ((unsigned)t << 8) | t; + unsigned stk1; + unsigned stk2; + unsigned stk3; + stk2 = S ^ D; + stk3 = T ^ D; + stk2 = stk2 & stk3; + stk1 = S ^ stk2; + return (stk1 & (~S)) | (D & S); +} + +/* SSDxTDxax source/pattern transparent. */ +static unsigned xrop3_142_1_1 (unsigned char s, unsigned char t) +{ + unsigned D = 0x00ff; + unsigned S = ((unsigned)s << 8) | s; + unsigned T = ((unsigned)t << 8) | t; + unsigned stk1; + unsigned stk2; + unsigned stk3; + stk2 = S ^ D; + stk3 = T ^ D; + stk2 = stk2 & stk3; + stk1 = S ^ stk2; + return (stk1 & (~S) & (~T)) | (D & S) | (D & T); +} + +/* TDSanan source/pattern opaque. */ +static void rop3_143_0_0 (unsigned char *D, unsigned char S, unsigned char T) +{ + unsigned char stk1; + unsigned char stk2; + stk2 = *D & S; + stk2 = ~stk2; + stk1 = T & stk2; + stk1 = ~stk1; + *D = stk1; +} + +/* TDSanan source opaque/pattern transparent. */ +static void rop3_143_0_1 (unsigned char *D, unsigned char S, unsigned char T) +{ + unsigned char stk1; + unsigned char stk2; + stk2 = *D & S; + stk2 = ~stk2; + stk1 = T & stk2; + stk1 = ~stk1; + *D = (stk1 & S) | (stk1 & (~T)) | (T & (~S) & *D); +} + +/* TDSanan source transparent/pattern opaque. */ +static void rop3_143_1_0 (unsigned char *D, unsigned char S, unsigned char T) +{ + unsigned char stk1; + unsigned char stk2; + stk2 = *D & S; + stk2 = ~stk2; + stk1 = T & stk2; + stk1 = ~stk1; + *D = (stk1 & (~S)) | (*D & S); +} + +/* TDSanan source/pattern transparent. */ +static void rop3_143_1_1 (unsigned char *D, unsigned char S, unsigned char T) +{ + unsigned char stk1; + unsigned char stk2; + stk2 = *D & S; + stk2 = ~stk2; + stk1 = T & stk2; + stk1 = ~stk1; + *D = (stk1 & (~S) & (~T)) | (*D & S) | (*D & T); +} + +/* TDSanan source/pattern opaque. */ +static unsigned xrop3_143_0_0 (unsigned char s, unsigned char t) +{ + unsigned D = 0x00ff; + unsigned S = ((unsigned)s << 8) | s; + unsigned T = ((unsigned)t << 8) | t; + unsigned stk1; + unsigned stk2; + stk2 = D & S; + stk2 = ~stk2; + stk1 = T & stk2; + stk1 = ~stk1; + return stk1; +} + +/* TDSanan source opaque/pattern transparent. */ +static unsigned xrop3_143_0_1 (unsigned char s, unsigned char t) +{ + unsigned D = 0x00ff; + unsigned S = ((unsigned)s << 8) | s; + unsigned T = ((unsigned)t << 8) | t; + unsigned stk1; + unsigned stk2; + stk2 = D & S; + stk2 = ~stk2; + stk1 = T & stk2; + stk1 = ~stk1; + return (stk1 & S) | (stk1 & (~T)) | (T & (~S) & D); +} + +/* TDSanan source transparent/pattern opaque. */ +static unsigned xrop3_143_1_0 (unsigned char s, unsigned char t) +{ + unsigned D = 0x00ff; + unsigned S = ((unsigned)s << 8) | s; + unsigned T = ((unsigned)t << 8) | t; + unsigned stk1; + unsigned stk2; + stk2 = D & S; + stk2 = ~stk2; + stk1 = T & stk2; + stk1 = ~stk1; + return (stk1 & (~S)) | (D & S); +} + +/* TDSanan source/pattern transparent. */ +static unsigned xrop3_143_1_1 (unsigned char s, unsigned char t) +{ + unsigned D = 0x00ff; + unsigned S = ((unsigned)s << 8) | s; + unsigned T = ((unsigned)t << 8) | t; + unsigned stk1; + unsigned stk2; + stk2 = D & S; + stk2 = ~stk2; + stk1 = T & stk2; + stk1 = ~stk1; + return (stk1 & (~S) & (~T)) | (D & S) | (D & T); +} + +/* TDSxna source/pattern opaque. */ +static void rop3_144_0_0 (unsigned char *D, unsigned char S, unsigned char T) +{ + unsigned char stk1; + unsigned char stk2; + stk2 = *D ^ S; + stk2 = ~stk2; + stk1 = T & stk2; + *D = stk1; +} + +/* TDSxna source opaque/pattern transparent. */ +static void rop3_144_0_1 (unsigned char *D, unsigned char S, unsigned char T) +{ + unsigned char stk1; + unsigned char stk2; + stk2 = *D ^ S; + stk2 = ~stk2; + stk1 = T & stk2; + *D = (stk1 & S) | (stk1 & (~T)) | (T & (~S) & *D); +} + +/* TDSxna source transparent/pattern opaque. */ +static void rop3_144_1_0 (unsigned char *D, unsigned char S, unsigned char T) +{ + unsigned char stk1; + unsigned char stk2; + stk2 = *D ^ S; + stk2 = ~stk2; + stk1 = T & stk2; + *D = (stk1 & (~S)) | (*D & S); +} + +/* TDSxna source/pattern transparent. */ +static void rop3_144_1_1 (unsigned char *D, unsigned char S, unsigned char T) +{ + unsigned char stk1; + unsigned char stk2; + stk2 = *D ^ S; + stk2 = ~stk2; + stk1 = T & stk2; + *D = (stk1 & (~S) & (~T)) | (*D & S) | (*D & T); +} + +/* TDSxna source/pattern opaque. */ +static unsigned xrop3_144_0_0 (unsigned char s, unsigned char t) +{ + unsigned D = 0x00ff; + unsigned S = ((unsigned)s << 8) | s; + unsigned T = ((unsigned)t << 8) | t; + unsigned stk1; + unsigned stk2; + stk2 = D ^ S; + stk2 = ~stk2; + stk1 = T & stk2; + return stk1; +} + +/* TDSxna source opaque/pattern transparent. */ +static unsigned xrop3_144_0_1 (unsigned char s, unsigned char t) +{ + unsigned D = 0x00ff; + unsigned S = ((unsigned)s << 8) | s; + unsigned T = ((unsigned)t << 8) | t; + unsigned stk1; + unsigned stk2; + stk2 = D ^ S; + stk2 = ~stk2; + stk1 = T & stk2; + return (stk1 & S) | (stk1 & (~T)) | (T & (~S) & D); +} + +/* TDSxna source transparent/pattern opaque. */ +static unsigned xrop3_144_1_0 (unsigned char s, unsigned char t) +{ + unsigned D = 0x00ff; + unsigned S = ((unsigned)s << 8) | s; + unsigned T = ((unsigned)t << 8) | t; + unsigned stk1; + unsigned stk2; + stk2 = D ^ S; + stk2 = ~stk2; + stk1 = T & stk2; + return (stk1 & (~S)) | (D & S); +} + +/* TDSxna source/pattern transparent. */ +static unsigned xrop3_144_1_1 (unsigned char s, unsigned char t) +{ + unsigned D = 0x00ff; + unsigned S = ((unsigned)s << 8) | s; + unsigned T = ((unsigned)t << 8) | t; + unsigned stk1; + unsigned stk2; + stk2 = D ^ S; + stk2 = ~stk2; + stk1 = T & stk2; + return (stk1 & (~S) & (~T)) | (D & S) | (D & T); +} + +/* SDTSnoaxn source/pattern opaque. */ +static void rop3_145_0_0 (unsigned char *D, unsigned char S, unsigned char T) +{ + unsigned char stk1; + unsigned char stk2; + unsigned char stk3; + unsigned char stk4; + stk4 = ~S; + stk3 = T | stk4; + stk2 = *D & stk3; + stk1 = S ^ stk2; + stk1 = ~stk1; + *D = stk1; +} + +/* SDTSnoaxn source opaque/pattern transparent. */ +static void rop3_145_0_1 (unsigned char *D, unsigned char S, unsigned char T) +{ + unsigned char stk1; + unsigned char stk2; + unsigned char stk3; + unsigned char stk4; + stk4 = ~S; + stk3 = T | stk4; + stk2 = *D & stk3; + stk1 = S ^ stk2; + stk1 = ~stk1; + *D = (stk1 & S) | (stk1 & (~T)) | (T & (~S) & *D); +} + +/* SDTSnoaxn source transparent/pattern opaque. */ +static void rop3_145_1_0 (unsigned char *D, unsigned char S, unsigned char T) +{ + unsigned char stk1; + unsigned char stk2; + unsigned char stk3; + unsigned char stk4; + stk4 = ~S; + stk3 = T | stk4; + stk2 = *D & stk3; + stk1 = S ^ stk2; + stk1 = ~stk1; + *D = (stk1 & (~S)) | (*D & S); +} + +/* SDTSnoaxn source/pattern transparent. */ +static void rop3_145_1_1 (unsigned char *D, unsigned char S, unsigned char T) +{ + unsigned char stk1; + unsigned char stk2; + unsigned char stk3; + unsigned char stk4; + stk4 = ~S; + stk3 = T | stk4; + stk2 = *D & stk3; + stk1 = S ^ stk2; + stk1 = ~stk1; + *D = (stk1 & (~S) & (~T)) | (*D & S) | (*D & T); +} + +/* SDTSnoaxn source/pattern opaque. */ +static unsigned xrop3_145_0_0 (unsigned char s, unsigned char t) +{ + unsigned D = 0x00ff; + unsigned S = ((unsigned)s << 8) | s; + unsigned T = ((unsigned)t << 8) | t; + unsigned stk1; + unsigned stk2; + unsigned stk3; + unsigned stk4; + stk4 = ~S; + stk3 = T | stk4; + stk2 = D & stk3; + stk1 = S ^ stk2; + stk1 = ~stk1; + return stk1; +} + +/* SDTSnoaxn source opaque/pattern transparent. */ +static unsigned xrop3_145_0_1 (unsigned char s, unsigned char t) +{ + unsigned D = 0x00ff; + unsigned S = ((unsigned)s << 8) | s; + unsigned T = ((unsigned)t << 8) | t; + unsigned stk1; + unsigned stk2; + unsigned stk3; + unsigned stk4; + stk4 = ~S; + stk3 = T | stk4; + stk2 = D & stk3; + stk1 = S ^ stk2; + stk1 = ~stk1; + return (stk1 & S) | (stk1 & (~T)) | (T & (~S) & D); +} + +/* SDTSnoaxn source transparent/pattern opaque. */ +static unsigned xrop3_145_1_0 (unsigned char s, unsigned char t) +{ + unsigned D = 0x00ff; + unsigned S = ((unsigned)s << 8) | s; + unsigned T = ((unsigned)t << 8) | t; + unsigned stk1; + unsigned stk2; + unsigned stk3; + unsigned stk4; + stk4 = ~S; + stk3 = T | stk4; + stk2 = D & stk3; + stk1 = S ^ stk2; + stk1 = ~stk1; + return (stk1 & (~S)) | (D & S); +} + +/* SDTSnoaxn source/pattern transparent. */ +static unsigned xrop3_145_1_1 (unsigned char s, unsigned char t) +{ + unsigned D = 0x00ff; + unsigned S = ((unsigned)s << 8) | s; + unsigned T = ((unsigned)t << 8) | t; + unsigned stk1; + unsigned stk2; + unsigned stk3; + unsigned stk4; + stk4 = ~S; + stk3 = T | stk4; + stk2 = D & stk3; + stk1 = S ^ stk2; + stk1 = ~stk1; + return (stk1 & (~S) & (~T)) | (D & S) | (D & T); +} + +/* DTSDToaxx source/pattern opaque. */ +static void rop3_146_0_0 (unsigned char *D, unsigned char S, unsigned char T) +{ + unsigned char stk1; + unsigned char stk2; + unsigned char stk3; + unsigned char stk4; + stk4 = *D | T; + stk3 = S & stk4; + stk2 = T ^ stk3; + stk1 = *D ^ stk2; + *D = stk1; +} + +/* DTSDToaxx source opaque/pattern transparent. */ +static void rop3_146_0_1 (unsigned char *D, unsigned char S, unsigned char T) +{ + unsigned char stk1; + unsigned char stk2; + unsigned char stk3; + unsigned char stk4; + stk4 = *D | T; + stk3 = S & stk4; + stk2 = T ^ stk3; + stk1 = *D ^ stk2; + *D = (stk1 & S) | (stk1 & (~T)) | (T & (~S) & *D); +} + +/* DTSDToaxx source transparent/pattern opaque. */ +static void rop3_146_1_0 (unsigned char *D, unsigned char S, unsigned char T) +{ + unsigned char stk1; + unsigned char stk2; + unsigned char stk3; + unsigned char stk4; + stk4 = *D | T; + stk3 = S & stk4; + stk2 = T ^ stk3; + stk1 = *D ^ stk2; + *D = (stk1 & (~S)) | (*D & S); +} + +/* DTSDToaxx source/pattern transparent. */ +static void rop3_146_1_1 (unsigned char *D, unsigned char S, unsigned char T) +{ + unsigned char stk1; + unsigned char stk2; + unsigned char stk3; + unsigned char stk4; + stk4 = *D | T; + stk3 = S & stk4; + stk2 = T ^ stk3; + stk1 = *D ^ stk2; + *D = (stk1 & (~S) & (~T)) | (*D & S) | (*D & T); +} + +/* DTSDToaxx source/pattern opaque. */ +static unsigned xrop3_146_0_0 (unsigned char s, unsigned char t) +{ + unsigned D = 0x00ff; + unsigned S = ((unsigned)s << 8) | s; + unsigned T = ((unsigned)t << 8) | t; + unsigned stk1; + unsigned stk2; + unsigned stk3; + unsigned stk4; + stk4 = D | T; + stk3 = S & stk4; + stk2 = T ^ stk3; + stk1 = D ^ stk2; + return stk1; +} + +/* DTSDToaxx source opaque/pattern transparent. */ +static unsigned xrop3_146_0_1 (unsigned char s, unsigned char t) +{ + unsigned D = 0x00ff; + unsigned S = ((unsigned)s << 8) | s; + unsigned T = ((unsigned)t << 8) | t; + unsigned stk1; + unsigned stk2; + unsigned stk3; + unsigned stk4; + stk4 = D | T; + stk3 = S & stk4; + stk2 = T ^ stk3; + stk1 = D ^ stk2; + return (stk1 & S) | (stk1 & (~T)) | (T & (~S) & D); +} + +/* DTSDToaxx source transparent/pattern opaque. */ +static unsigned xrop3_146_1_0 (unsigned char s, unsigned char t) +{ + unsigned D = 0x00ff; + unsigned S = ((unsigned)s << 8) | s; + unsigned T = ((unsigned)t << 8) | t; + unsigned stk1; + unsigned stk2; + unsigned stk3; + unsigned stk4; + stk4 = D | T; + stk3 = S & stk4; + stk2 = T ^ stk3; + stk1 = D ^ stk2; + return (stk1 & (~S)) | (D & S); +} + +/* DTSDToaxx source/pattern transparent. */ +static unsigned xrop3_146_1_1 (unsigned char s, unsigned char t) +{ + unsigned D = 0x00ff; + unsigned S = ((unsigned)s << 8) | s; + unsigned T = ((unsigned)t << 8) | t; + unsigned stk1; + unsigned stk2; + unsigned stk3; + unsigned stk4; + stk4 = D | T; + stk3 = S & stk4; + stk2 = T ^ stk3; + stk1 = D ^ stk2; + return (stk1 & (~S) & (~T)) | (D & S) | (D & T); +} + +/* STDaxn source/pattern opaque. */ +static void rop3_147_0_0 (unsigned char *D, unsigned char S, unsigned char T) +{ + unsigned char stk1; + unsigned char stk2; + stk2 = T & *D; + stk1 = S ^ stk2; + stk1 = ~stk1; + *D = stk1; +} + +/* STDaxn source opaque/pattern transparent. */ +static void rop3_147_0_1 (unsigned char *D, unsigned char S, unsigned char T) +{ + unsigned char stk1; + unsigned char stk2; + stk2 = T & *D; + stk1 = S ^ stk2; + stk1 = ~stk1; + *D = (stk1 & S) | (stk1 & (~T)) | (T & (~S) & *D); +} + +/* STDaxn source transparent/pattern opaque. */ +static void rop3_147_1_0 (unsigned char *D, unsigned char S, unsigned char T) +{ + unsigned char stk1; + unsigned char stk2; + stk2 = T & *D; + stk1 = S ^ stk2; + stk1 = ~stk1; + *D = (stk1 & (~S)) | (*D & S); +} + +/* STDaxn source/pattern transparent. */ +static void rop3_147_1_1 (unsigned char *D, unsigned char S, unsigned char T) +{ + unsigned char stk1; + unsigned char stk2; + stk2 = T & *D; + stk1 = S ^ stk2; + stk1 = ~stk1; + *D = (stk1 & (~S) & (~T)) | (*D & S) | (*D & T); +} + +/* STDaxn source/pattern opaque. */ +static unsigned xrop3_147_0_0 (unsigned char s, unsigned char t) +{ + unsigned D = 0x00ff; + unsigned S = ((unsigned)s << 8) | s; + unsigned T = ((unsigned)t << 8) | t; + unsigned stk1; + unsigned stk2; + stk2 = T & D; + stk1 = S ^ stk2; + stk1 = ~stk1; + return stk1; +} + +/* STDaxn source opaque/pattern transparent. */ +static unsigned xrop3_147_0_1 (unsigned char s, unsigned char t) +{ + unsigned D = 0x00ff; + unsigned S = ((unsigned)s << 8) | s; + unsigned T = ((unsigned)t << 8) | t; + unsigned stk1; + unsigned stk2; + stk2 = T & D; + stk1 = S ^ stk2; + stk1 = ~stk1; + return (stk1 & S) | (stk1 & (~T)) | (T & (~S) & D); +} + +/* STDaxn source transparent/pattern opaque. */ +static unsigned xrop3_147_1_0 (unsigned char s, unsigned char t) +{ + unsigned D = 0x00ff; + unsigned S = ((unsigned)s << 8) | s; + unsigned T = ((unsigned)t << 8) | t; + unsigned stk1; + unsigned stk2; + stk2 = T & D; + stk1 = S ^ stk2; + stk1 = ~stk1; + return (stk1 & (~S)) | (D & S); +} + +/* STDaxn source/pattern transparent. */ +static unsigned xrop3_147_1_1 (unsigned char s, unsigned char t) +{ + unsigned D = 0x00ff; + unsigned S = ((unsigned)s << 8) | s; + unsigned T = ((unsigned)t << 8) | t; + unsigned stk1; + unsigned stk2; + stk2 = T & D; + stk1 = S ^ stk2; + stk1 = ~stk1; + return (stk1 & (~S) & (~T)) | (D & S) | (D & T); +} + +/* TSDTSoaxx source/pattern opaque. */ +static void rop3_148_0_0 (unsigned char *D, unsigned char S, unsigned char T) +{ + unsigned char stk1; + unsigned char stk2; + unsigned char stk3; + unsigned char stk4; + stk4 = T | S; + stk3 = *D & stk4; + stk2 = S ^ stk3; + stk1 = T ^ stk2; + *D = stk1; +} + +/* TSDTSoaxx source opaque/pattern transparent. */ +static void rop3_148_0_1 (unsigned char *D, unsigned char S, unsigned char T) +{ + unsigned char stk1; + unsigned char stk2; + unsigned char stk3; + unsigned char stk4; + stk4 = T | S; + stk3 = *D & stk4; + stk2 = S ^ stk3; + stk1 = T ^ stk2; + *D = (stk1 & S) | (stk1 & (~T)) | (T & (~S) & *D); +} + +/* TSDTSoaxx source transparent/pattern opaque. */ +static void rop3_148_1_0 (unsigned char *D, unsigned char S, unsigned char T) +{ + unsigned char stk1; + unsigned char stk2; + unsigned char stk3; + unsigned char stk4; + stk4 = T | S; + stk3 = *D & stk4; + stk2 = S ^ stk3; + stk1 = T ^ stk2; + *D = (stk1 & (~S)) | (*D & S); +} + +/* TSDTSoaxx source/pattern transparent. */ +static void rop3_148_1_1 (unsigned char *D, unsigned char S, unsigned char T) +{ + unsigned char stk1; + unsigned char stk2; + unsigned char stk3; + unsigned char stk4; + stk4 = T | S; + stk3 = *D & stk4; + stk2 = S ^ stk3; + stk1 = T ^ stk2; + *D = (stk1 & (~S) & (~T)) | (*D & S) | (*D & T); +} + +/* TSDTSoaxx source/pattern opaque. */ +static unsigned xrop3_148_0_0 (unsigned char s, unsigned char t) +{ + unsigned D = 0x00ff; + unsigned S = ((unsigned)s << 8) | s; + unsigned T = ((unsigned)t << 8) | t; + unsigned stk1; + unsigned stk2; + unsigned stk3; + unsigned stk4; + stk4 = T | S; + stk3 = D & stk4; + stk2 = S ^ stk3; + stk1 = T ^ stk2; + return stk1; +} + +/* TSDTSoaxx source opaque/pattern transparent. */ +static unsigned xrop3_148_0_1 (unsigned char s, unsigned char t) +{ + unsigned D = 0x00ff; + unsigned S = ((unsigned)s << 8) | s; + unsigned T = ((unsigned)t << 8) | t; + unsigned stk1; + unsigned stk2; + unsigned stk3; + unsigned stk4; + stk4 = T | S; + stk3 = D & stk4; + stk2 = S ^ stk3; + stk1 = T ^ stk2; + return (stk1 & S) | (stk1 & (~T)) | (T & (~S) & D); +} + +/* TSDTSoaxx source transparent/pattern opaque. */ +static unsigned xrop3_148_1_0 (unsigned char s, unsigned char t) +{ + unsigned D = 0x00ff; + unsigned S = ((unsigned)s << 8) | s; + unsigned T = ((unsigned)t << 8) | t; + unsigned stk1; + unsigned stk2; + unsigned stk3; + unsigned stk4; + stk4 = T | S; + stk3 = D & stk4; + stk2 = S ^ stk3; + stk1 = T ^ stk2; + return (stk1 & (~S)) | (D & S); +} + +/* TSDTSoaxx source/pattern transparent. */ +static unsigned xrop3_148_1_1 (unsigned char s, unsigned char t) +{ + unsigned D = 0x00ff; + unsigned S = ((unsigned)s << 8) | s; + unsigned T = ((unsigned)t << 8) | t; + unsigned stk1; + unsigned stk2; + unsigned stk3; + unsigned stk4; + stk4 = T | S; + stk3 = D & stk4; + stk2 = S ^ stk3; + stk1 = T ^ stk2; + return (stk1 & (~S) & (~T)) | (D & S) | (D & T); +} + +/* DTSaxn source/pattern opaque. */ +static void rop3_149_0_0 (unsigned char *D, unsigned char S, unsigned char T) +{ + unsigned char stk1; + unsigned char stk2; + stk2 = T & S; + stk1 = *D ^ stk2; + stk1 = ~stk1; + *D = stk1; +} + +/* DTSaxn source opaque/pattern transparent. */ +static void rop3_149_0_1 (unsigned char *D, unsigned char S, unsigned char T) +{ + unsigned char stk1; + unsigned char stk2; + stk2 = T & S; + stk1 = *D ^ stk2; + stk1 = ~stk1; + *D = (stk1 & S) | (stk1 & (~T)) | (T & (~S) & *D); +} + +/* DTSaxn source transparent/pattern opaque. */ +static void rop3_149_1_0 (unsigned char *D, unsigned char S, unsigned char T) +{ + unsigned char stk1; + unsigned char stk2; + stk2 = T & S; + stk1 = *D ^ stk2; + stk1 = ~stk1; + *D = (stk1 & (~S)) | (*D & S); +} + +/* DTSaxn source/pattern transparent. */ +static void rop3_149_1_1 (unsigned char *D, unsigned char S, unsigned char T) +{ + unsigned char stk1; + unsigned char stk2; + stk2 = T & S; + stk1 = *D ^ stk2; + stk1 = ~stk1; + *D = (stk1 & (~S) & (~T)) | (*D & S) | (*D & T); +} + +/* DTSaxn source/pattern opaque. */ +static unsigned xrop3_149_0_0 (unsigned char s, unsigned char t) +{ + unsigned D = 0x00ff; + unsigned S = ((unsigned)s << 8) | s; + unsigned T = ((unsigned)t << 8) | t; + unsigned stk1; + unsigned stk2; + stk2 = T & S; + stk1 = D ^ stk2; + stk1 = ~stk1; + return stk1; +} + +/* DTSaxn source opaque/pattern transparent. */ +static unsigned xrop3_149_0_1 (unsigned char s, unsigned char t) +{ + unsigned D = 0x00ff; + unsigned S = ((unsigned)s << 8) | s; + unsigned T = ((unsigned)t << 8) | t; + unsigned stk1; + unsigned stk2; + stk2 = T & S; + stk1 = D ^ stk2; + stk1 = ~stk1; + return (stk1 & S) | (stk1 & (~T)) | (T & (~S) & D); +} + +/* DTSaxn source transparent/pattern opaque. */ +static unsigned xrop3_149_1_0 (unsigned char s, unsigned char t) +{ + unsigned D = 0x00ff; + unsigned S = ((unsigned)s << 8) | s; + unsigned T = ((unsigned)t << 8) | t; + unsigned stk1; + unsigned stk2; + stk2 = T & S; + stk1 = D ^ stk2; + stk1 = ~stk1; + return (stk1 & (~S)) | (D & S); +} + +/* DTSaxn source/pattern transparent. */ +static unsigned xrop3_149_1_1 (unsigned char s, unsigned char t) +{ + unsigned D = 0x00ff; + unsigned S = ((unsigned)s << 8) | s; + unsigned T = ((unsigned)t << 8) | t; + unsigned stk1; + unsigned stk2; + stk2 = T & S; + stk1 = D ^ stk2; + stk1 = ~stk1; + return (stk1 & (~S) & (~T)) | (D & S) | (D & T); +} + +/* DTSxx source/pattern opaque. */ +static void rop3_150_0_0 (unsigned char *D, unsigned char S, unsigned char T) +{ + unsigned char stk1; + unsigned char stk2; + stk2 = T ^ S; + stk1 = *D ^ stk2; + *D = stk1; +} + +/* DTSxx source opaque/pattern transparent. */ +static void rop3_150_0_1 (unsigned char *D, unsigned char S, unsigned char T) +{ + unsigned char stk1; + unsigned char stk2; + stk2 = T ^ S; + stk1 = *D ^ stk2; + *D = (stk1 & S) | (stk1 & (~T)) | (T & (~S) & *D); +} + +/* DTSxx source transparent/pattern opaque. */ +static void rop3_150_1_0 (unsigned char *D, unsigned char S, unsigned char T) +{ + unsigned char stk1; + unsigned char stk2; + stk2 = T ^ S; + stk1 = *D ^ stk2; + *D = (stk1 & (~S)) | (*D & S); +} + +/* DTSxx source/pattern transparent. */ +static void rop3_150_1_1 (unsigned char *D, unsigned char S, unsigned char T) +{ + unsigned char stk1; + unsigned char stk2; + stk2 = T ^ S; + stk1 = *D ^ stk2; + *D = (stk1 & (~S) & (~T)) | (*D & S) | (*D & T); +} + +/* DTSxx source/pattern opaque. */ +static unsigned xrop3_150_0_0 (unsigned char s, unsigned char t) +{ + unsigned D = 0x00ff; + unsigned S = ((unsigned)s << 8) | s; + unsigned T = ((unsigned)t << 8) | t; + unsigned stk1; + unsigned stk2; + stk2 = T ^ S; + stk1 = D ^ stk2; + return stk1; +} + +/* DTSxx source opaque/pattern transparent. */ +static unsigned xrop3_150_0_1 (unsigned char s, unsigned char t) +{ + unsigned D = 0x00ff; + unsigned S = ((unsigned)s << 8) | s; + unsigned T = ((unsigned)t << 8) | t; + unsigned stk1; + unsigned stk2; + stk2 = T ^ S; + stk1 = D ^ stk2; + return (stk1 & S) | (stk1 & (~T)) | (T & (~S) & D); +} + +/* DTSxx source transparent/pattern opaque. */ +static unsigned xrop3_150_1_0 (unsigned char s, unsigned char t) +{ + unsigned D = 0x00ff; + unsigned S = ((unsigned)s << 8) | s; + unsigned T = ((unsigned)t << 8) | t; + unsigned stk1; + unsigned stk2; + stk2 = T ^ S; + stk1 = D ^ stk2; + return (stk1 & (~S)) | (D & S); +} + +/* DTSxx source/pattern transparent. */ +static unsigned xrop3_150_1_1 (unsigned char s, unsigned char t) +{ + unsigned D = 0x00ff; + unsigned S = ((unsigned)s << 8) | s; + unsigned T = ((unsigned)t << 8) | t; + unsigned stk1; + unsigned stk2; + stk2 = T ^ S; + stk1 = D ^ stk2; + return (stk1 & (~S) & (~T)) | (D & S) | (D & T); +} + +/* TSDTSonoxx source/pattern opaque. */ +static void rop3_151_0_0 (unsigned char *D, unsigned char S, unsigned char T) +{ + unsigned char stk1; + unsigned char stk2; + unsigned char stk3; + unsigned char stk4; + stk4 = T | S; + stk4 = ~stk4; + stk3 = *D | stk4; + stk2 = S ^ stk3; + stk1 = T ^ stk2; + *D = stk1; +} + +/* TSDTSonoxx source opaque/pattern transparent. */ +static void rop3_151_0_1 (unsigned char *D, unsigned char S, unsigned char T) +{ + unsigned char stk1; + unsigned char stk2; + unsigned char stk3; + unsigned char stk4; + stk4 = T | S; + stk4 = ~stk4; + stk3 = *D | stk4; + stk2 = S ^ stk3; + stk1 = T ^ stk2; + *D = (stk1 & S) | (stk1 & (~T)) | (T & (~S) & *D); +} + +/* TSDTSonoxx source transparent/pattern opaque. */ +static void rop3_151_1_0 (unsigned char *D, unsigned char S, unsigned char T) +{ + unsigned char stk1; + unsigned char stk2; + unsigned char stk3; + unsigned char stk4; + stk4 = T | S; + stk4 = ~stk4; + stk3 = *D | stk4; + stk2 = S ^ stk3; + stk1 = T ^ stk2; + *D = (stk1 & (~S)) | (*D & S); +} + +/* TSDTSonoxx source/pattern transparent. */ +static void rop3_151_1_1 (unsigned char *D, unsigned char S, unsigned char T) +{ + unsigned char stk1; + unsigned char stk2; + unsigned char stk3; + unsigned char stk4; + stk4 = T | S; + stk4 = ~stk4; + stk3 = *D | stk4; + stk2 = S ^ stk3; + stk1 = T ^ stk2; + *D = (stk1 & (~S) & (~T)) | (*D & S) | (*D & T); +} + +/* TSDTSonoxx source/pattern opaque. */ +static unsigned xrop3_151_0_0 (unsigned char s, unsigned char t) +{ + unsigned D = 0x00ff; + unsigned S = ((unsigned)s << 8) | s; + unsigned T = ((unsigned)t << 8) | t; + unsigned stk1; + unsigned stk2; + unsigned stk3; + unsigned stk4; + stk4 = T | S; + stk4 = ~stk4; + stk3 = D | stk4; + stk2 = S ^ stk3; + stk1 = T ^ stk2; + return stk1; +} + +/* TSDTSonoxx source opaque/pattern transparent. */ +static unsigned xrop3_151_0_1 (unsigned char s, unsigned char t) +{ + unsigned D = 0x00ff; + unsigned S = ((unsigned)s << 8) | s; + unsigned T = ((unsigned)t << 8) | t; + unsigned stk1; + unsigned stk2; + unsigned stk3; + unsigned stk4; + stk4 = T | S; + stk4 = ~stk4; + stk3 = D | stk4; + stk2 = S ^ stk3; + stk1 = T ^ stk2; + return (stk1 & S) | (stk1 & (~T)) | (T & (~S) & D); +} + +/* TSDTSonoxx source transparent/pattern opaque. */ +static unsigned xrop3_151_1_0 (unsigned char s, unsigned char t) +{ + unsigned D = 0x00ff; + unsigned S = ((unsigned)s << 8) | s; + unsigned T = ((unsigned)t << 8) | t; + unsigned stk1; + unsigned stk2; + unsigned stk3; + unsigned stk4; + stk4 = T | S; + stk4 = ~stk4; + stk3 = D | stk4; + stk2 = S ^ stk3; + stk1 = T ^ stk2; + return (stk1 & (~S)) | (D & S); +} + +/* TSDTSonoxx source/pattern transparent. */ +static unsigned xrop3_151_1_1 (unsigned char s, unsigned char t) +{ + unsigned D = 0x00ff; + unsigned S = ((unsigned)s << 8) | s; + unsigned T = ((unsigned)t << 8) | t; + unsigned stk1; + unsigned stk2; + unsigned stk3; + unsigned stk4; + stk4 = T | S; + stk4 = ~stk4; + stk3 = D | stk4; + stk2 = S ^ stk3; + stk1 = T ^ stk2; + return (stk1 & (~S) & (~T)) | (D & S) | (D & T); +} + +/* SDTSonoxn source/pattern opaque. */ +static void rop3_152_0_0 (unsigned char *D, unsigned char S, unsigned char T) +{ + unsigned char stk1; + unsigned char stk2; + unsigned char stk3; + stk3 = T | S; + stk3 = ~stk3; + stk2 = *D | stk3; + stk1 = S ^ stk2; + stk1 = ~stk1; + *D = stk1; +} + +/* SDTSonoxn source opaque/pattern transparent. */ +static void rop3_152_0_1 (unsigned char *D, unsigned char S, unsigned char T) +{ + unsigned char stk1; + unsigned char stk2; + unsigned char stk3; + stk3 = T | S; + stk3 = ~stk3; + stk2 = *D | stk3; + stk1 = S ^ stk2; + stk1 = ~stk1; + *D = (stk1 & S) | (stk1 & (~T)) | (T & (~S) & *D); +} + +/* SDTSonoxn source transparent/pattern opaque. */ +static void rop3_152_1_0 (unsigned char *D, unsigned char S, unsigned char T) +{ + unsigned char stk1; + unsigned char stk2; + unsigned char stk3; + stk3 = T | S; + stk3 = ~stk3; + stk2 = *D | stk3; + stk1 = S ^ stk2; + stk1 = ~stk1; + *D = (stk1 & (~S)) | (*D & S); +} + +/* SDTSonoxn source/pattern transparent. */ +static void rop3_152_1_1 (unsigned char *D, unsigned char S, unsigned char T) +{ + unsigned char stk1; + unsigned char stk2; + unsigned char stk3; + stk3 = T | S; + stk3 = ~stk3; + stk2 = *D | stk3; + stk1 = S ^ stk2; + stk1 = ~stk1; + *D = (stk1 & (~S) & (~T)) | (*D & S) | (*D & T); +} + +/* SDTSonoxn source/pattern opaque. */ +static unsigned xrop3_152_0_0 (unsigned char s, unsigned char t) +{ + unsigned D = 0x00ff; + unsigned S = ((unsigned)s << 8) | s; + unsigned T = ((unsigned)t << 8) | t; + unsigned stk1; + unsigned stk2; + unsigned stk3; + stk3 = T | S; + stk3 = ~stk3; + stk2 = D | stk3; + stk1 = S ^ stk2; + stk1 = ~stk1; + return stk1; +} + +/* SDTSonoxn source opaque/pattern transparent. */ +static unsigned xrop3_152_0_1 (unsigned char s, unsigned char t) +{ + unsigned D = 0x00ff; + unsigned S = ((unsigned)s << 8) | s; + unsigned T = ((unsigned)t << 8) | t; + unsigned stk1; + unsigned stk2; + unsigned stk3; + stk3 = T | S; + stk3 = ~stk3; + stk2 = D | stk3; + stk1 = S ^ stk2; + stk1 = ~stk1; + return (stk1 & S) | (stk1 & (~T)) | (T & (~S) & D); +} + +/* SDTSonoxn source transparent/pattern opaque. */ +static unsigned xrop3_152_1_0 (unsigned char s, unsigned char t) +{ + unsigned D = 0x00ff; + unsigned S = ((unsigned)s << 8) | s; + unsigned T = ((unsigned)t << 8) | t; + unsigned stk1; + unsigned stk2; + unsigned stk3; + stk3 = T | S; + stk3 = ~stk3; + stk2 = D | stk3; + stk1 = S ^ stk2; + stk1 = ~stk1; + return (stk1 & (~S)) | (D & S); +} + +/* SDTSonoxn source/pattern transparent. */ +static unsigned xrop3_152_1_1 (unsigned char s, unsigned char t) +{ + unsigned D = 0x00ff; + unsigned S = ((unsigned)s << 8) | s; + unsigned T = ((unsigned)t << 8) | t; + unsigned stk1; + unsigned stk2; + unsigned stk3; + stk3 = T | S; + stk3 = ~stk3; + stk2 = D | stk3; + stk1 = S ^ stk2; + stk1 = ~stk1; + return (stk1 & (~S) & (~T)) | (D & S) | (D & T); +} + +/* DSxn source/pattern opaque. */ +static void rop3_153_0_0 (unsigned char *D, unsigned char S, unsigned char T) +{ + unsigned char stk1; + stk1 = *D ^ S; + stk1 = ~stk1; + *D = stk1; +} + +/* DSxn source opaque/pattern transparent. */ +static void rop3_153_0_1 (unsigned char *D, unsigned char S, unsigned char T) +{ + unsigned char stk1; + stk1 = *D ^ S; + stk1 = ~stk1; + *D = (stk1 & S) | (stk1 & (~T)) | (T & (~S) & *D); +} + +/* DSxn source transparent/pattern opaque. */ +static void rop3_153_1_0 (unsigned char *D, unsigned char S, unsigned char T) +{ + unsigned char stk1; + stk1 = *D ^ S; + stk1 = ~stk1; + *D = (stk1 & (~S)) | (*D & S); +} + +/* DSxn source/pattern transparent. */ +static void rop3_153_1_1 (unsigned char *D, unsigned char S, unsigned char T) +{ + unsigned char stk1; + stk1 = *D ^ S; + stk1 = ~stk1; + *D = (stk1 & (~S) & (~T)) | (*D & S) | (*D & T); +} + +/* DSxn source/pattern opaque. */ +static unsigned xrop3_153_0_0 (unsigned char s, unsigned char t) +{ + unsigned D = 0x00ff; + unsigned S = ((unsigned)s << 8) | s; + unsigned stk1; + stk1 = D ^ S; + stk1 = ~stk1; + return stk1; +} + +/* DSxn source opaque/pattern transparent. */ +static unsigned xrop3_153_0_1 (unsigned char s, unsigned char t) +{ + unsigned D = 0x00ff; + unsigned S = ((unsigned)s << 8) | s; + unsigned T = ((unsigned)t << 8) | t; + unsigned stk1; + stk1 = D ^ S; + stk1 = ~stk1; + return (stk1 & S) | (stk1 & (~T)) | (T & (~S) & D); +} + +/* DSxn source transparent/pattern opaque. */ +static unsigned xrop3_153_1_0 (unsigned char s, unsigned char t) +{ + unsigned D = 0x00ff; + unsigned S = ((unsigned)s << 8) | s; + unsigned stk1; + stk1 = D ^ S; + stk1 = ~stk1; + return (stk1 & (~S)) | (D & S); +} + +/* DSxn source/pattern transparent. */ +static unsigned xrop3_153_1_1 (unsigned char s, unsigned char t) +{ + unsigned D = 0x00ff; + unsigned S = ((unsigned)s << 8) | s; + unsigned T = ((unsigned)t << 8) | t; + unsigned stk1; + stk1 = D ^ S; + stk1 = ~stk1; + return (stk1 & (~S) & (~T)) | (D & S) | (D & T); +} + +/* DTSnax source/pattern opaque. */ +static void rop3_154_0_0 (unsigned char *D, unsigned char S, unsigned char T) +{ + unsigned char stk1; + unsigned char stk2; + unsigned char stk3; + stk3 = ~S; + stk2 = T & stk3; + stk1 = *D ^ stk2; + *D = stk1; +} + +/* DTSnax source opaque/pattern transparent. */ +static void rop3_154_0_1 (unsigned char *D, unsigned char S, unsigned char T) +{ + unsigned char stk1; + unsigned char stk2; + unsigned char stk3; + stk3 = ~S; + stk2 = T & stk3; + stk1 = *D ^ stk2; + *D = (stk1 & S) | (stk1 & (~T)) | (T & (~S) & *D); +} + +/* DTSnax source transparent/pattern opaque. */ +static void rop3_154_1_0 (unsigned char *D, unsigned char S, unsigned char T) +{ + unsigned char stk1; + unsigned char stk2; + unsigned char stk3; + stk3 = ~S; + stk2 = T & stk3; + stk1 = *D ^ stk2; + *D = (stk1 & (~S)) | (*D & S); +} + +/* DTSnax source/pattern transparent. */ +static void rop3_154_1_1 (unsigned char *D, unsigned char S, unsigned char T) +{ + unsigned char stk1; + unsigned char stk2; + unsigned char stk3; + stk3 = ~S; + stk2 = T & stk3; + stk1 = *D ^ stk2; + *D = (stk1 & (~S) & (~T)) | (*D & S) | (*D & T); +} + +/* DTSnax source/pattern opaque. */ +static unsigned xrop3_154_0_0 (unsigned char s, unsigned char t) +{ + unsigned D = 0x00ff; + unsigned S = ((unsigned)s << 8) | s; + unsigned T = ((unsigned)t << 8) | t; + unsigned stk1; + unsigned stk2; + unsigned stk3; + stk3 = ~S; + stk2 = T & stk3; + stk1 = D ^ stk2; + return stk1; +} + +/* DTSnax source opaque/pattern transparent. */ +static unsigned xrop3_154_0_1 (unsigned char s, unsigned char t) +{ + unsigned D = 0x00ff; + unsigned S = ((unsigned)s << 8) | s; + unsigned T = ((unsigned)t << 8) | t; + unsigned stk1; + unsigned stk2; + unsigned stk3; + stk3 = ~S; + stk2 = T & stk3; + stk1 = D ^ stk2; + return (stk1 & S) | (stk1 & (~T)) | (T & (~S) & D); +} + +/* DTSnax source transparent/pattern opaque. */ +static unsigned xrop3_154_1_0 (unsigned char s, unsigned char t) +{ + unsigned D = 0x00ff; + unsigned S = ((unsigned)s << 8) | s; + unsigned T = ((unsigned)t << 8) | t; + unsigned stk1; + unsigned stk2; + unsigned stk3; + stk3 = ~S; + stk2 = T & stk3; + stk1 = D ^ stk2; + return (stk1 & (~S)) | (D & S); +} + +/* DTSnax source/pattern transparent. */ +static unsigned xrop3_154_1_1 (unsigned char s, unsigned char t) +{ + unsigned D = 0x00ff; + unsigned S = ((unsigned)s << 8) | s; + unsigned T = ((unsigned)t << 8) | t; + unsigned stk1; + unsigned stk2; + unsigned stk3; + stk3 = ~S; + stk2 = T & stk3; + stk1 = D ^ stk2; + return (stk1 & (~S) & (~T)) | (D & S) | (D & T); +} + +/* SDTSoaxn source/pattern opaque. */ +static void rop3_155_0_0 (unsigned char *D, unsigned char S, unsigned char T) +{ + unsigned char stk1; + unsigned char stk2; + unsigned char stk3; + stk3 = T | S; + stk2 = *D & stk3; + stk1 = S ^ stk2; + stk1 = ~stk1; + *D = stk1; +} + +/* SDTSoaxn source opaque/pattern transparent. */ +static void rop3_155_0_1 (unsigned char *D, unsigned char S, unsigned char T) +{ + unsigned char stk1; + unsigned char stk2; + unsigned char stk3; + stk3 = T | S; + stk2 = *D & stk3; + stk1 = S ^ stk2; + stk1 = ~stk1; + *D = (stk1 & S) | (stk1 & (~T)) | (T & (~S) & *D); +} + +/* SDTSoaxn source transparent/pattern opaque. */ +static void rop3_155_1_0 (unsigned char *D, unsigned char S, unsigned char T) +{ + unsigned char stk1; + unsigned char stk2; + unsigned char stk3; + stk3 = T | S; + stk2 = *D & stk3; + stk1 = S ^ stk2; + stk1 = ~stk1; + *D = (stk1 & (~S)) | (*D & S); +} + +/* SDTSoaxn source/pattern transparent. */ +static void rop3_155_1_1 (unsigned char *D, unsigned char S, unsigned char T) +{ + unsigned char stk1; + unsigned char stk2; + unsigned char stk3; + stk3 = T | S; + stk2 = *D & stk3; + stk1 = S ^ stk2; + stk1 = ~stk1; + *D = (stk1 & (~S) & (~T)) | (*D & S) | (*D & T); +} + +/* SDTSoaxn source/pattern opaque. */ +static unsigned xrop3_155_0_0 (unsigned char s, unsigned char t) +{ + unsigned D = 0x00ff; + unsigned S = ((unsigned)s << 8) | s; + unsigned T = ((unsigned)t << 8) | t; + unsigned stk1; + unsigned stk2; + unsigned stk3; + stk3 = T | S; + stk2 = D & stk3; + stk1 = S ^ stk2; + stk1 = ~stk1; + return stk1; +} + +/* SDTSoaxn source opaque/pattern transparent. */ +static unsigned xrop3_155_0_1 (unsigned char s, unsigned char t) +{ + unsigned D = 0x00ff; + unsigned S = ((unsigned)s << 8) | s; + unsigned T = ((unsigned)t << 8) | t; + unsigned stk1; + unsigned stk2; + unsigned stk3; + stk3 = T | S; + stk2 = D & stk3; + stk1 = S ^ stk2; + stk1 = ~stk1; + return (stk1 & S) | (stk1 & (~T)) | (T & (~S) & D); +} + +/* SDTSoaxn source transparent/pattern opaque. */ +static unsigned xrop3_155_1_0 (unsigned char s, unsigned char t) +{ + unsigned D = 0x00ff; + unsigned S = ((unsigned)s << 8) | s; + unsigned T = ((unsigned)t << 8) | t; + unsigned stk1; + unsigned stk2; + unsigned stk3; + stk3 = T | S; + stk2 = D & stk3; + stk1 = S ^ stk2; + stk1 = ~stk1; + return (stk1 & (~S)) | (D & S); +} + +/* SDTSoaxn source/pattern transparent. */ +static unsigned xrop3_155_1_1 (unsigned char s, unsigned char t) +{ + unsigned D = 0x00ff; + unsigned S = ((unsigned)s << 8) | s; + unsigned T = ((unsigned)t << 8) | t; + unsigned stk1; + unsigned stk2; + unsigned stk3; + stk3 = T | S; + stk2 = D & stk3; + stk1 = S ^ stk2; + stk1 = ~stk1; + return (stk1 & (~S) & (~T)) | (D & S) | (D & T); +} + +/* STDnax source/pattern opaque. */ +static void rop3_156_0_0 (unsigned char *D, unsigned char S, unsigned char T) +{ + unsigned char stk1; + unsigned char stk2; + unsigned char stk3; + stk3 = ~*D; + stk2 = T & stk3; + stk1 = S ^ stk2; + *D = stk1; +} + +/* STDnax source opaque/pattern transparent. */ +static void rop3_156_0_1 (unsigned char *D, unsigned char S, unsigned char T) +{ + unsigned char stk1; + unsigned char stk2; + unsigned char stk3; + stk3 = ~*D; + stk2 = T & stk3; + stk1 = S ^ stk2; + *D = (stk1 & S) | (stk1 & (~T)) | (T & (~S) & *D); +} + +/* STDnax source transparent/pattern opaque. */ +static void rop3_156_1_0 (unsigned char *D, unsigned char S, unsigned char T) +{ + unsigned char stk1; + unsigned char stk2; + unsigned char stk3; + stk3 = ~*D; + stk2 = T & stk3; + stk1 = S ^ stk2; + *D = (stk1 & (~S)) | (*D & S); +} + +/* STDnax source/pattern transparent. */ +static void rop3_156_1_1 (unsigned char *D, unsigned char S, unsigned char T) +{ + unsigned char stk1; + unsigned char stk2; + unsigned char stk3; + stk3 = ~*D; + stk2 = T & stk3; + stk1 = S ^ stk2; + *D = (stk1 & (~S) & (~T)) | (*D & S) | (*D & T); +} + +/* STDnax source/pattern opaque. */ +static unsigned xrop3_156_0_0 (unsigned char s, unsigned char t) +{ + unsigned D = 0x00ff; + unsigned S = ((unsigned)s << 8) | s; + unsigned T = ((unsigned)t << 8) | t; + unsigned stk1; + unsigned stk2; + unsigned stk3; + stk3 = ~D; + stk2 = T & stk3; + stk1 = S ^ stk2; + return stk1; +} + +/* STDnax source opaque/pattern transparent. */ +static unsigned xrop3_156_0_1 (unsigned char s, unsigned char t) +{ + unsigned D = 0x00ff; + unsigned S = ((unsigned)s << 8) | s; + unsigned T = ((unsigned)t << 8) | t; + unsigned stk1; + unsigned stk2; + unsigned stk3; + stk3 = ~D; + stk2 = T & stk3; + stk1 = S ^ stk2; + return (stk1 & S) | (stk1 & (~T)) | (T & (~S) & D); +} + +/* STDnax source transparent/pattern opaque. */ +static unsigned xrop3_156_1_0 (unsigned char s, unsigned char t) +{ + unsigned D = 0x00ff; + unsigned S = ((unsigned)s << 8) | s; + unsigned T = ((unsigned)t << 8) | t; + unsigned stk1; + unsigned stk2; + unsigned stk3; + stk3 = ~D; + stk2 = T & stk3; + stk1 = S ^ stk2; + return (stk1 & (~S)) | (D & S); +} + +/* STDnax source/pattern transparent. */ +static unsigned xrop3_156_1_1 (unsigned char s, unsigned char t) +{ + unsigned D = 0x00ff; + unsigned S = ((unsigned)s << 8) | s; + unsigned T = ((unsigned)t << 8) | t; + unsigned stk1; + unsigned stk2; + unsigned stk3; + stk3 = ~D; + stk2 = T & stk3; + stk1 = S ^ stk2; + return (stk1 & (~S) & (~T)) | (D & S) | (D & T); +} + +/* DSTDoaxn source/pattern opaque. */ +static void rop3_157_0_0 (unsigned char *D, unsigned char S, unsigned char T) +{ + unsigned char stk1; + unsigned char stk2; + unsigned char stk3; + stk3 = T | *D; + stk2 = S & stk3; + stk1 = *D ^ stk2; + stk1 = ~stk1; + *D = stk1; +} + +/* DSTDoaxn source opaque/pattern transparent. */ +static void rop3_157_0_1 (unsigned char *D, unsigned char S, unsigned char T) +{ + unsigned char stk1; + unsigned char stk2; + unsigned char stk3; + stk3 = T | *D; + stk2 = S & stk3; + stk1 = *D ^ stk2; + stk1 = ~stk1; + *D = (stk1 & S) | (stk1 & (~T)) | (T & (~S) & *D); +} + +/* DSTDoaxn source transparent/pattern opaque. */ +static void rop3_157_1_0 (unsigned char *D, unsigned char S, unsigned char T) +{ + unsigned char stk1; + unsigned char stk2; + unsigned char stk3; + stk3 = T | *D; + stk2 = S & stk3; + stk1 = *D ^ stk2; + stk1 = ~stk1; + *D = (stk1 & (~S)) | (*D & S); +} + +/* DSTDoaxn source/pattern transparent. */ +static void rop3_157_1_1 (unsigned char *D, unsigned char S, unsigned char T) +{ + unsigned char stk1; + unsigned char stk2; + unsigned char stk3; + stk3 = T | *D; + stk2 = S & stk3; + stk1 = *D ^ stk2; + stk1 = ~stk1; + *D = (stk1 & (~S) & (~T)) | (*D & S) | (*D & T); +} + +/* DSTDoaxn source/pattern opaque. */ +static unsigned xrop3_157_0_0 (unsigned char s, unsigned char t) +{ + unsigned D = 0x00ff; + unsigned S = ((unsigned)s << 8) | s; + unsigned T = ((unsigned)t << 8) | t; + unsigned stk1; + unsigned stk2; + unsigned stk3; + stk3 = T | D; + stk2 = S & stk3; + stk1 = D ^ stk2; + stk1 = ~stk1; + return stk1; +} + +/* DSTDoaxn source opaque/pattern transparent. */ +static unsigned xrop3_157_0_1 (unsigned char s, unsigned char t) +{ + unsigned D = 0x00ff; + unsigned S = ((unsigned)s << 8) | s; + unsigned T = ((unsigned)t << 8) | t; + unsigned stk1; + unsigned stk2; + unsigned stk3; + stk3 = T | D; + stk2 = S & stk3; + stk1 = D ^ stk2; + stk1 = ~stk1; + return (stk1 & S) | (stk1 & (~T)) | (T & (~S) & D); +} + +/* DSTDoaxn source transparent/pattern opaque. */ +static unsigned xrop3_157_1_0 (unsigned char s, unsigned char t) +{ + unsigned D = 0x00ff; + unsigned S = ((unsigned)s << 8) | s; + unsigned T = ((unsigned)t << 8) | t; + unsigned stk1; + unsigned stk2; + unsigned stk3; + stk3 = T | D; + stk2 = S & stk3; + stk1 = D ^ stk2; + stk1 = ~stk1; + return (stk1 & (~S)) | (D & S); +} + +/* DSTDoaxn source/pattern transparent. */ +static unsigned xrop3_157_1_1 (unsigned char s, unsigned char t) +{ + unsigned D = 0x00ff; + unsigned S = ((unsigned)s << 8) | s; + unsigned T = ((unsigned)t << 8) | t; + unsigned stk1; + unsigned stk2; + unsigned stk3; + stk3 = T | D; + stk2 = S & stk3; + stk1 = D ^ stk2; + stk1 = ~stk1; + return (stk1 & (~S) & (~T)) | (D & S) | (D & T); +} + +/* DSTDSaoxx source/pattern opaque. */ +static void rop3_158_0_0 (unsigned char *D, unsigned char S, unsigned char T) +{ + unsigned char stk1; + unsigned char stk2; + unsigned char stk3; + unsigned char stk4; + stk4 = *D & S; + stk3 = T | stk4; + stk2 = S ^ stk3; + stk1 = *D ^ stk2; + *D = stk1; +} + +/* DSTDSaoxx source opaque/pattern transparent. */ +static void rop3_158_0_1 (unsigned char *D, unsigned char S, unsigned char T) +{ + unsigned char stk1; + unsigned char stk2; + unsigned char stk3; + unsigned char stk4; + stk4 = *D & S; + stk3 = T | stk4; + stk2 = S ^ stk3; + stk1 = *D ^ stk2; + *D = (stk1 & S) | (stk1 & (~T)) | (T & (~S) & *D); +} + +/* DSTDSaoxx source transparent/pattern opaque. */ +static void rop3_158_1_0 (unsigned char *D, unsigned char S, unsigned char T) +{ + unsigned char stk1; + unsigned char stk2; + unsigned char stk3; + unsigned char stk4; + stk4 = *D & S; + stk3 = T | stk4; + stk2 = S ^ stk3; + stk1 = *D ^ stk2; + *D = (stk1 & (~S)) | (*D & S); +} + +/* DSTDSaoxx source/pattern transparent. */ +static void rop3_158_1_1 (unsigned char *D, unsigned char S, unsigned char T) +{ + unsigned char stk1; + unsigned char stk2; + unsigned char stk3; + unsigned char stk4; + stk4 = *D & S; + stk3 = T | stk4; + stk2 = S ^ stk3; + stk1 = *D ^ stk2; + *D = (stk1 & (~S) & (~T)) | (*D & S) | (*D & T); +} + +/* DSTDSaoxx source/pattern opaque. */ +static unsigned xrop3_158_0_0 (unsigned char s, unsigned char t) +{ + unsigned D = 0x00ff; + unsigned S = ((unsigned)s << 8) | s; + unsigned T = ((unsigned)t << 8) | t; + unsigned stk1; + unsigned stk2; + unsigned stk3; + unsigned stk4; + stk4 = D & S; + stk3 = T | stk4; + stk2 = S ^ stk3; + stk1 = D ^ stk2; + return stk1; +} + +/* DSTDSaoxx source opaque/pattern transparent. */ +static unsigned xrop3_158_0_1 (unsigned char s, unsigned char t) +{ + unsigned D = 0x00ff; + unsigned S = ((unsigned)s << 8) | s; + unsigned T = ((unsigned)t << 8) | t; + unsigned stk1; + unsigned stk2; + unsigned stk3; + unsigned stk4; + stk4 = D & S; + stk3 = T | stk4; + stk2 = S ^ stk3; + stk1 = D ^ stk2; + return (stk1 & S) | (stk1 & (~T)) | (T & (~S) & D); +} + +/* DSTDSaoxx source transparent/pattern opaque. */ +static unsigned xrop3_158_1_0 (unsigned char s, unsigned char t) +{ + unsigned D = 0x00ff; + unsigned S = ((unsigned)s << 8) | s; + unsigned T = ((unsigned)t << 8) | t; + unsigned stk1; + unsigned stk2; + unsigned stk3; + unsigned stk4; + stk4 = D & S; + stk3 = T | stk4; + stk2 = S ^ stk3; + stk1 = D ^ stk2; + return (stk1 & (~S)) | (D & S); +} + +/* DSTDSaoxx source/pattern transparent. */ +static unsigned xrop3_158_1_1 (unsigned char s, unsigned char t) +{ + unsigned D = 0x00ff; + unsigned S = ((unsigned)s << 8) | s; + unsigned T = ((unsigned)t << 8) | t; + unsigned stk1; + unsigned stk2; + unsigned stk3; + unsigned stk4; + stk4 = D & S; + stk3 = T | stk4; + stk2 = S ^ stk3; + stk1 = D ^ stk2; + return (stk1 & (~S) & (~T)) | (D & S) | (D & T); +} + +/* TDSxan source/pattern opaque. */ +static void rop3_159_0_0 (unsigned char *D, unsigned char S, unsigned char T) +{ + unsigned char stk1; + unsigned char stk2; + stk2 = *D ^ S; + stk1 = T & stk2; + stk1 = ~stk1; + *D = stk1; +} + +/* TDSxan source opaque/pattern transparent. */ +static void rop3_159_0_1 (unsigned char *D, unsigned char S, unsigned char T) +{ + unsigned char stk1; + unsigned char stk2; + stk2 = *D ^ S; + stk1 = T & stk2; + stk1 = ~stk1; + *D = (stk1 & S) | (stk1 & (~T)) | (T & (~S) & *D); +} + +/* TDSxan source transparent/pattern opaque. */ +static void rop3_159_1_0 (unsigned char *D, unsigned char S, unsigned char T) +{ + unsigned char stk1; + unsigned char stk2; + stk2 = *D ^ S; + stk1 = T & stk2; + stk1 = ~stk1; + *D = (stk1 & (~S)) | (*D & S); +} + +/* TDSxan source/pattern transparent. */ +static void rop3_159_1_1 (unsigned char *D, unsigned char S, unsigned char T) +{ + unsigned char stk1; + unsigned char stk2; + stk2 = *D ^ S; + stk1 = T & stk2; + stk1 = ~stk1; + *D = (stk1 & (~S) & (~T)) | (*D & S) | (*D & T); +} + +/* TDSxan source/pattern opaque. */ +static unsigned xrop3_159_0_0 (unsigned char s, unsigned char t) +{ + unsigned D = 0x00ff; + unsigned S = ((unsigned)s << 8) | s; + unsigned T = ((unsigned)t << 8) | t; + unsigned stk1; + unsigned stk2; + stk2 = D ^ S; + stk1 = T & stk2; + stk1 = ~stk1; + return stk1; +} + +/* TDSxan source opaque/pattern transparent. */ +static unsigned xrop3_159_0_1 (unsigned char s, unsigned char t) +{ + unsigned D = 0x00ff; + unsigned S = ((unsigned)s << 8) | s; + unsigned T = ((unsigned)t << 8) | t; + unsigned stk1; + unsigned stk2; + stk2 = D ^ S; + stk1 = T & stk2; + stk1 = ~stk1; + return (stk1 & S) | (stk1 & (~T)) | (T & (~S) & D); +} + +/* TDSxan source transparent/pattern opaque. */ +static unsigned xrop3_159_1_0 (unsigned char s, unsigned char t) +{ + unsigned D = 0x00ff; + unsigned S = ((unsigned)s << 8) | s; + unsigned T = ((unsigned)t << 8) | t; + unsigned stk1; + unsigned stk2; + stk2 = D ^ S; + stk1 = T & stk2; + stk1 = ~stk1; + return (stk1 & (~S)) | (D & S); +} + +/* TDSxan source/pattern transparent. */ +static unsigned xrop3_159_1_1 (unsigned char s, unsigned char t) +{ + unsigned D = 0x00ff; + unsigned S = ((unsigned)s << 8) | s; + unsigned T = ((unsigned)t << 8) | t; + unsigned stk1; + unsigned stk2; + stk2 = D ^ S; + stk1 = T & stk2; + stk1 = ~stk1; + return (stk1 & (~S) & (~T)) | (D & S) | (D & T); +} + +/* DTa source/pattern opaque. */ +static void rop3_160_0_0 (unsigned char *D, unsigned char S, unsigned char T) +{ + unsigned char stk1; + stk1 = *D & T; + *D = stk1; +} + +/* DTa source opaque/pattern transparent. */ +static void rop3_160_0_1 (unsigned char *D, unsigned char S, unsigned char T) +{ + unsigned char stk1; + stk1 = *D & T; + *D = (stk1 & S) | (stk1 & (~T)) | (T & (~S) & *D); +} + +/* DTa source transparent/pattern opaque. */ +static void rop3_160_1_0 (unsigned char *D, unsigned char S, unsigned char T) +{ + unsigned char stk1; + stk1 = *D & T; + *D = (stk1 & (~S)) | (*D & S); +} + +/* DTa source/pattern transparent. */ +static void rop3_160_1_1 (unsigned char *D, unsigned char S, unsigned char T) +{ + unsigned char stk1; + stk1 = *D & T; + *D = (stk1 & (~S) & (~T)) | (*D & S) | (*D & T); +} + +/* DTa source/pattern opaque. */ +static unsigned xrop3_160_0_0 (unsigned char s, unsigned char t) +{ + unsigned D = 0x00ff; + unsigned T = ((unsigned)t << 8) | t; + unsigned stk1; + stk1 = D & T; + return stk1; +} + +/* DTa source opaque/pattern transparent. */ +static unsigned xrop3_160_0_1 (unsigned char s, unsigned char t) +{ + unsigned D = 0x00ff; + unsigned S = ((unsigned)s << 8) | s; + unsigned T = ((unsigned)t << 8) | t; + unsigned stk1; + stk1 = D & T; + return (stk1 & S) | (stk1 & (~T)) | (T & (~S) & D); +} + +/* DTa source transparent/pattern opaque. */ +static unsigned xrop3_160_1_0 (unsigned char s, unsigned char t) +{ + unsigned D = 0x00ff; + unsigned S = ((unsigned)s << 8) | s; + unsigned T = ((unsigned)t << 8) | t; + unsigned stk1; + stk1 = D & T; + return (stk1 & (~S)) | (D & S); +} + +/* DTa source/pattern transparent. */ +static unsigned xrop3_160_1_1 (unsigned char s, unsigned char t) +{ + unsigned D = 0x00ff; + unsigned S = ((unsigned)s << 8) | s; + unsigned T = ((unsigned)t << 8) | t; + unsigned stk1; + stk1 = D & T; + return (stk1 & (~S) & (~T)) | (D & S) | (D & T); +} + +/* TDSTnaoxn source/pattern opaque. */ +static void rop3_161_0_0 (unsigned char *D, unsigned char S, unsigned char T) +{ + unsigned char stk1; + unsigned char stk2; + unsigned char stk3; + unsigned char stk4; + stk4 = ~T; + stk3 = S & stk4; + stk2 = *D | stk3; + stk1 = T ^ stk2; + stk1 = ~stk1; + *D = stk1; +} + +/* TDSTnaoxn source opaque/pattern transparent. */ +static void rop3_161_0_1 (unsigned char *D, unsigned char S, unsigned char T) +{ + unsigned char stk1; + unsigned char stk2; + unsigned char stk3; + unsigned char stk4; + stk4 = ~T; + stk3 = S & stk4; + stk2 = *D | stk3; + stk1 = T ^ stk2; + stk1 = ~stk1; + *D = (stk1 & S) | (stk1 & (~T)) | (T & (~S) & *D); +} + +/* TDSTnaoxn source transparent/pattern opaque. */ +static void rop3_161_1_0 (unsigned char *D, unsigned char S, unsigned char T) +{ + unsigned char stk1; + unsigned char stk2; + unsigned char stk3; + unsigned char stk4; + stk4 = ~T; + stk3 = S & stk4; + stk2 = *D | stk3; + stk1 = T ^ stk2; + stk1 = ~stk1; + *D = (stk1 & (~S)) | (*D & S); +} + +/* TDSTnaoxn source/pattern transparent. */ +static void rop3_161_1_1 (unsigned char *D, unsigned char S, unsigned char T) +{ + unsigned char stk1; + unsigned char stk2; + unsigned char stk3; + unsigned char stk4; + stk4 = ~T; + stk3 = S & stk4; + stk2 = *D | stk3; + stk1 = T ^ stk2; + stk1 = ~stk1; + *D = (stk1 & (~S) & (~T)) | (*D & S) | (*D & T); +} + +/* TDSTnaoxn source/pattern opaque. */ +static unsigned xrop3_161_0_0 (unsigned char s, unsigned char t) +{ + unsigned D = 0x00ff; + unsigned S = ((unsigned)s << 8) | s; + unsigned T = ((unsigned)t << 8) | t; + unsigned stk1; + unsigned stk2; + unsigned stk3; + unsigned stk4; + stk4 = ~T; + stk3 = S & stk4; + stk2 = D | stk3; + stk1 = T ^ stk2; + stk1 = ~stk1; + return stk1; +} + +/* TDSTnaoxn source opaque/pattern transparent. */ +static unsigned xrop3_161_0_1 (unsigned char s, unsigned char t) +{ + unsigned D = 0x00ff; + unsigned S = ((unsigned)s << 8) | s; + unsigned T = ((unsigned)t << 8) | t; + unsigned stk1; + unsigned stk2; + unsigned stk3; + unsigned stk4; + stk4 = ~T; + stk3 = S & stk4; + stk2 = D | stk3; + stk1 = T ^ stk2; + stk1 = ~stk1; + return (stk1 & S) | (stk1 & (~T)) | (T & (~S) & D); +} + +/* TDSTnaoxn source transparent/pattern opaque. */ +static unsigned xrop3_161_1_0 (unsigned char s, unsigned char t) +{ + unsigned D = 0x00ff; + unsigned S = ((unsigned)s << 8) | s; + unsigned T = ((unsigned)t << 8) | t; + unsigned stk1; + unsigned stk2; + unsigned stk3; + unsigned stk4; + stk4 = ~T; + stk3 = S & stk4; + stk2 = D | stk3; + stk1 = T ^ stk2; + stk1 = ~stk1; + return (stk1 & (~S)) | (D & S); +} + +/* TDSTnaoxn source/pattern transparent. */ +static unsigned xrop3_161_1_1 (unsigned char s, unsigned char t) +{ + unsigned D = 0x00ff; + unsigned S = ((unsigned)s << 8) | s; + unsigned T = ((unsigned)t << 8) | t; + unsigned stk1; + unsigned stk2; + unsigned stk3; + unsigned stk4; + stk4 = ~T; + stk3 = S & stk4; + stk2 = D | stk3; + stk1 = T ^ stk2; + stk1 = ~stk1; + return (stk1 & (~S) & (~T)) | (D & S) | (D & T); +} + +/* DTSnoa source/pattern opaque. */ +static void rop3_162_0_0 (unsigned char *D, unsigned char S, unsigned char T) +{ + unsigned char stk1; + unsigned char stk2; + unsigned char stk3; + stk3 = ~S; + stk2 = T | stk3; + stk1 = *D & stk2; + *D = stk1; +} + +/* DTSnoa source opaque/pattern transparent. */ +static void rop3_162_0_1 (unsigned char *D, unsigned char S, unsigned char T) +{ + unsigned char stk1; + unsigned char stk2; + unsigned char stk3; + stk3 = ~S; + stk2 = T | stk3; + stk1 = *D & stk2; + *D = (stk1 & S) | (stk1 & (~T)) | (T & (~S) & *D); +} + +/* DTSnoa source transparent/pattern opaque. */ +static void rop3_162_1_0 (unsigned char *D, unsigned char S, unsigned char T) +{ + unsigned char stk1; + unsigned char stk2; + unsigned char stk3; + stk3 = ~S; + stk2 = T | stk3; + stk1 = *D & stk2; + *D = (stk1 & (~S)) | (*D & S); +} + +/* DTSnoa source/pattern transparent. */ +static void rop3_162_1_1 (unsigned char *D, unsigned char S, unsigned char T) +{ + unsigned char stk1; + unsigned char stk2; + unsigned char stk3; + stk3 = ~S; + stk2 = T | stk3; + stk1 = *D & stk2; + *D = (stk1 & (~S) & (~T)) | (*D & S) | (*D & T); +} + +/* DTSnoa source/pattern opaque. */ +static unsigned xrop3_162_0_0 (unsigned char s, unsigned char t) +{ + unsigned D = 0x00ff; + unsigned S = ((unsigned)s << 8) | s; + unsigned T = ((unsigned)t << 8) | t; + unsigned stk1; + unsigned stk2; + unsigned stk3; + stk3 = ~S; + stk2 = T | stk3; + stk1 = D & stk2; + return stk1; +} + +/* DTSnoa source opaque/pattern transparent. */ +static unsigned xrop3_162_0_1 (unsigned char s, unsigned char t) +{ + unsigned D = 0x00ff; + unsigned S = ((unsigned)s << 8) | s; + unsigned T = ((unsigned)t << 8) | t; + unsigned stk1; + unsigned stk2; + unsigned stk3; + stk3 = ~S; + stk2 = T | stk3; + stk1 = D & stk2; + return (stk1 & S) | (stk1 & (~T)) | (T & (~S) & D); +} + +/* DTSnoa source transparent/pattern opaque. */ +static unsigned xrop3_162_1_0 (unsigned char s, unsigned char t) +{ + unsigned D = 0x00ff; + unsigned S = ((unsigned)s << 8) | s; + unsigned T = ((unsigned)t << 8) | t; + unsigned stk1; + unsigned stk2; + unsigned stk3; + stk3 = ~S; + stk2 = T | stk3; + stk1 = D & stk2; + return (stk1 & (~S)) | (D & S); +} + +/* DTSnoa source/pattern transparent. */ +static unsigned xrop3_162_1_1 (unsigned char s, unsigned char t) +{ + unsigned D = 0x00ff; + unsigned S = ((unsigned)s << 8) | s; + unsigned T = ((unsigned)t << 8) | t; + unsigned stk1; + unsigned stk2; + unsigned stk3; + stk3 = ~S; + stk2 = T | stk3; + stk1 = D & stk2; + return (stk1 & (~S) & (~T)) | (D & S) | (D & T); +} + +/* DTSDxoxn source/pattern opaque. */ +static void rop3_163_0_0 (unsigned char *D, unsigned char S, unsigned char T) +{ + unsigned char stk1; + unsigned char stk2; + unsigned char stk3; + stk3 = S ^ *D; + stk2 = T | stk3; + stk1 = *D ^ stk2; + stk1 = ~stk1; + *D = stk1; +} + +/* DTSDxoxn source opaque/pattern transparent. */ +static void rop3_163_0_1 (unsigned char *D, unsigned char S, unsigned char T) +{ + unsigned char stk1; + unsigned char stk2; + unsigned char stk3; + stk3 = S ^ *D; + stk2 = T | stk3; + stk1 = *D ^ stk2; + stk1 = ~stk1; + *D = (stk1 & S) | (stk1 & (~T)) | (T & (~S) & *D); +} + +/* DTSDxoxn source transparent/pattern opaque. */ +static void rop3_163_1_0 (unsigned char *D, unsigned char S, unsigned char T) +{ + unsigned char stk1; + unsigned char stk2; + unsigned char stk3; + stk3 = S ^ *D; + stk2 = T | stk3; + stk1 = *D ^ stk2; + stk1 = ~stk1; + *D = (stk1 & (~S)) | (*D & S); +} + +/* DTSDxoxn source/pattern transparent. */ +static void rop3_163_1_1 (unsigned char *D, unsigned char S, unsigned char T) +{ + unsigned char stk1; + unsigned char stk2; + unsigned char stk3; + stk3 = S ^ *D; + stk2 = T | stk3; + stk1 = *D ^ stk2; + stk1 = ~stk1; + *D = (stk1 & (~S) & (~T)) | (*D & S) | (*D & T); +} + +/* DTSDxoxn source/pattern opaque. */ +static unsigned xrop3_163_0_0 (unsigned char s, unsigned char t) +{ + unsigned D = 0x00ff; + unsigned S = ((unsigned)s << 8) | s; + unsigned T = ((unsigned)t << 8) | t; + unsigned stk1; + unsigned stk2; + unsigned stk3; + stk3 = S ^ D; + stk2 = T | stk3; + stk1 = D ^ stk2; + stk1 = ~stk1; + return stk1; +} + +/* DTSDxoxn source opaque/pattern transparent. */ +static unsigned xrop3_163_0_1 (unsigned char s, unsigned char t) +{ + unsigned D = 0x00ff; + unsigned S = ((unsigned)s << 8) | s; + unsigned T = ((unsigned)t << 8) | t; + unsigned stk1; + unsigned stk2; + unsigned stk3; + stk3 = S ^ D; + stk2 = T | stk3; + stk1 = D ^ stk2; + stk1 = ~stk1; + return (stk1 & S) | (stk1 & (~T)) | (T & (~S) & D); +} + +/* DTSDxoxn source transparent/pattern opaque. */ +static unsigned xrop3_163_1_0 (unsigned char s, unsigned char t) +{ + unsigned D = 0x00ff; + unsigned S = ((unsigned)s << 8) | s; + unsigned T = ((unsigned)t << 8) | t; + unsigned stk1; + unsigned stk2; + unsigned stk3; + stk3 = S ^ D; + stk2 = T | stk3; + stk1 = D ^ stk2; + stk1 = ~stk1; + return (stk1 & (~S)) | (D & S); +} + +/* DTSDxoxn source/pattern transparent. */ +static unsigned xrop3_163_1_1 (unsigned char s, unsigned char t) +{ + unsigned D = 0x00ff; + unsigned S = ((unsigned)s << 8) | s; + unsigned T = ((unsigned)t << 8) | t; + unsigned stk1; + unsigned stk2; + unsigned stk3; + stk3 = S ^ D; + stk2 = T | stk3; + stk1 = D ^ stk2; + stk1 = ~stk1; + return (stk1 & (~S) & (~T)) | (D & S) | (D & T); +} + +/* TDSTonoxn source/pattern opaque. */ +static void rop3_164_0_0 (unsigned char *D, unsigned char S, unsigned char T) +{ + unsigned char stk1; + unsigned char stk2; + unsigned char stk3; + stk3 = S | T; + stk3 = ~stk3; + stk2 = *D | stk3; + stk1 = T ^ stk2; + stk1 = ~stk1; + *D = stk1; +} + +/* TDSTonoxn source opaque/pattern transparent. */ +static void rop3_164_0_1 (unsigned char *D, unsigned char S, unsigned char T) +{ + unsigned char stk1; + unsigned char stk2; + unsigned char stk3; + stk3 = S | T; + stk3 = ~stk3; + stk2 = *D | stk3; + stk1 = T ^ stk2; + stk1 = ~stk1; + *D = (stk1 & S) | (stk1 & (~T)) | (T & (~S) & *D); +} + +/* TDSTonoxn source transparent/pattern opaque. */ +static void rop3_164_1_0 (unsigned char *D, unsigned char S, unsigned char T) +{ + unsigned char stk1; + unsigned char stk2; + unsigned char stk3; + stk3 = S | T; + stk3 = ~stk3; + stk2 = *D | stk3; + stk1 = T ^ stk2; + stk1 = ~stk1; + *D = (stk1 & (~S)) | (*D & S); +} + +/* TDSTonoxn source/pattern transparent. */ +static void rop3_164_1_1 (unsigned char *D, unsigned char S, unsigned char T) +{ + unsigned char stk1; + unsigned char stk2; + unsigned char stk3; + stk3 = S | T; + stk3 = ~stk3; + stk2 = *D | stk3; + stk1 = T ^ stk2; + stk1 = ~stk1; + *D = (stk1 & (~S) & (~T)) | (*D & S) | (*D & T); +} + +/* TDSTonoxn source/pattern opaque. */ +static unsigned xrop3_164_0_0 (unsigned char s, unsigned char t) +{ + unsigned D = 0x00ff; + unsigned S = ((unsigned)s << 8) | s; + unsigned T = ((unsigned)t << 8) | t; + unsigned stk1; + unsigned stk2; + unsigned stk3; + stk3 = S | T; + stk3 = ~stk3; + stk2 = D | stk3; + stk1 = T ^ stk2; + stk1 = ~stk1; + return stk1; +} + +/* TDSTonoxn source opaque/pattern transparent. */ +static unsigned xrop3_164_0_1 (unsigned char s, unsigned char t) +{ + unsigned D = 0x00ff; + unsigned S = ((unsigned)s << 8) | s; + unsigned T = ((unsigned)t << 8) | t; + unsigned stk1; + unsigned stk2; + unsigned stk3; + stk3 = S | T; + stk3 = ~stk3; + stk2 = D | stk3; + stk1 = T ^ stk2; + stk1 = ~stk1; + return (stk1 & S) | (stk1 & (~T)) | (T & (~S) & D); +} + +/* TDSTonoxn source transparent/pattern opaque. */ +static unsigned xrop3_164_1_0 (unsigned char s, unsigned char t) +{ + unsigned D = 0x00ff; + unsigned S = ((unsigned)s << 8) | s; + unsigned T = ((unsigned)t << 8) | t; + unsigned stk1; + unsigned stk2; + unsigned stk3; + stk3 = S | T; + stk3 = ~stk3; + stk2 = D | stk3; + stk1 = T ^ stk2; + stk1 = ~stk1; + return (stk1 & (~S)) | (D & S); +} + +/* TDSTonoxn source/pattern transparent. */ +static unsigned xrop3_164_1_1 (unsigned char s, unsigned char t) +{ + unsigned D = 0x00ff; + unsigned S = ((unsigned)s << 8) | s; + unsigned T = ((unsigned)t << 8) | t; + unsigned stk1; + unsigned stk2; + unsigned stk3; + stk3 = S | T; + stk3 = ~stk3; + stk2 = D | stk3; + stk1 = T ^ stk2; + stk1 = ~stk1; + return (stk1 & (~S) & (~T)) | (D & S) | (D & T); +} + +/* TDxn source/pattern opaque. */ +static void rop3_165_0_0 (unsigned char *D, unsigned char S, unsigned char T) +{ + unsigned char stk1; + stk1 = T ^ *D; + stk1 = ~stk1; + *D = stk1; +} + +/* TDxn source opaque/pattern transparent. */ +static void rop3_165_0_1 (unsigned char *D, unsigned char S, unsigned char T) +{ + unsigned char stk1; + stk1 = T ^ *D; + stk1 = ~stk1; + *D = (stk1 & S) | (stk1 & (~T)) | (T & (~S) & *D); +} + +/* TDxn source transparent/pattern opaque. */ +static void rop3_165_1_0 (unsigned char *D, unsigned char S, unsigned char T) +{ + unsigned char stk1; + stk1 = T ^ *D; + stk1 = ~stk1; + *D = (stk1 & (~S)) | (*D & S); +} + +/* TDxn source/pattern transparent. */ +static void rop3_165_1_1 (unsigned char *D, unsigned char S, unsigned char T) +{ + unsigned char stk1; + stk1 = T ^ *D; + stk1 = ~stk1; + *D = (stk1 & (~S) & (~T)) | (*D & S) | (*D & T); +} + +/* TDxn source/pattern opaque. */ +static unsigned xrop3_165_0_0 (unsigned char s, unsigned char t) +{ + unsigned D = 0x00ff; + unsigned T = ((unsigned)t << 8) | t; + unsigned stk1; + stk1 = T ^ D; + stk1 = ~stk1; + return stk1; +} + +/* TDxn source opaque/pattern transparent. */ +static unsigned xrop3_165_0_1 (unsigned char s, unsigned char t) +{ + unsigned D = 0x00ff; + unsigned S = ((unsigned)s << 8) | s; + unsigned T = ((unsigned)t << 8) | t; + unsigned stk1; + stk1 = T ^ D; + stk1 = ~stk1; + return (stk1 & S) | (stk1 & (~T)) | (T & (~S) & D); +} + +/* TDxn source transparent/pattern opaque. */ +static unsigned xrop3_165_1_0 (unsigned char s, unsigned char t) +{ + unsigned D = 0x00ff; + unsigned S = ((unsigned)s << 8) | s; + unsigned T = ((unsigned)t << 8) | t; + unsigned stk1; + stk1 = T ^ D; + stk1 = ~stk1; + return (stk1 & (~S)) | (D & S); +} + +/* TDxn source/pattern transparent. */ +static unsigned xrop3_165_1_1 (unsigned char s, unsigned char t) +{ + unsigned D = 0x00ff; + unsigned S = ((unsigned)s << 8) | s; + unsigned T = ((unsigned)t << 8) | t; + unsigned stk1; + stk1 = T ^ D; + stk1 = ~stk1; + return (stk1 & (~S) & (~T)) | (D & S) | (D & T); +} + +/* DSTnax source/pattern opaque. */ +static void rop3_166_0_0 (unsigned char *D, unsigned char S, unsigned char T) +{ + unsigned char stk1; + unsigned char stk2; + unsigned char stk3; + stk3 = ~T; + stk2 = S & stk3; + stk1 = *D ^ stk2; + *D = stk1; +} + +/* DSTnax source opaque/pattern transparent. */ +static void rop3_166_0_1 (unsigned char *D, unsigned char S, unsigned char T) +{ + unsigned char stk1; + unsigned char stk2; + unsigned char stk3; + stk3 = ~T; + stk2 = S & stk3; + stk1 = *D ^ stk2; + *D = (stk1 & S) | (stk1 & (~T)) | (T & (~S) & *D); +} + +/* DSTnax source transparent/pattern opaque. */ +static void rop3_166_1_0 (unsigned char *D, unsigned char S, unsigned char T) +{ + unsigned char stk1; + unsigned char stk2; + unsigned char stk3; + stk3 = ~T; + stk2 = S & stk3; + stk1 = *D ^ stk2; + *D = (stk1 & (~S)) | (*D & S); +} + +/* DSTnax source/pattern transparent. */ +static void rop3_166_1_1 (unsigned char *D, unsigned char S, unsigned char T) +{ + unsigned char stk1; + unsigned char stk2; + unsigned char stk3; + stk3 = ~T; + stk2 = S & stk3; + stk1 = *D ^ stk2; + *D = (stk1 & (~S) & (~T)) | (*D & S) | (*D & T); +} + +/* DSTnax source/pattern opaque. */ +static unsigned xrop3_166_0_0 (unsigned char s, unsigned char t) +{ + unsigned D = 0x00ff; + unsigned S = ((unsigned)s << 8) | s; + unsigned T = ((unsigned)t << 8) | t; + unsigned stk1; + unsigned stk2; + unsigned stk3; + stk3 = ~T; + stk2 = S & stk3; + stk1 = D ^ stk2; + return stk1; +} + +/* DSTnax source opaque/pattern transparent. */ +static unsigned xrop3_166_0_1 (unsigned char s, unsigned char t) +{ + unsigned D = 0x00ff; + unsigned S = ((unsigned)s << 8) | s; + unsigned T = ((unsigned)t << 8) | t; + unsigned stk1; + unsigned stk2; + unsigned stk3; + stk3 = ~T; + stk2 = S & stk3; + stk1 = D ^ stk2; + return (stk1 & S) | (stk1 & (~T)) | (T & (~S) & D); +} + +/* DSTnax source transparent/pattern opaque. */ +static unsigned xrop3_166_1_0 (unsigned char s, unsigned char t) +{ + unsigned D = 0x00ff; + unsigned S = ((unsigned)s << 8) | s; + unsigned T = ((unsigned)t << 8) | t; + unsigned stk1; + unsigned stk2; + unsigned stk3; + stk3 = ~T; + stk2 = S & stk3; + stk1 = D ^ stk2; + return (stk1 & (~S)) | (D & S); +} + +/* DSTnax source/pattern transparent. */ +static unsigned xrop3_166_1_1 (unsigned char s, unsigned char t) +{ + unsigned D = 0x00ff; + unsigned S = ((unsigned)s << 8) | s; + unsigned T = ((unsigned)t << 8) | t; + unsigned stk1; + unsigned stk2; + unsigned stk3; + stk3 = ~T; + stk2 = S & stk3; + stk1 = D ^ stk2; + return (stk1 & (~S) & (~T)) | (D & S) | (D & T); +} + +/* TDSToaxn source/pattern opaque. */ +static void rop3_167_0_0 (unsigned char *D, unsigned char S, unsigned char T) +{ + unsigned char stk1; + unsigned char stk2; + unsigned char stk3; + stk3 = S | T; + stk2 = *D & stk3; + stk1 = T ^ stk2; + stk1 = ~stk1; + *D = stk1; +} + +/* TDSToaxn source opaque/pattern transparent. */ +static void rop3_167_0_1 (unsigned char *D, unsigned char S, unsigned char T) +{ + unsigned char stk1; + unsigned char stk2; + unsigned char stk3; + stk3 = S | T; + stk2 = *D & stk3; + stk1 = T ^ stk2; + stk1 = ~stk1; + *D = (stk1 & S) | (stk1 & (~T)) | (T & (~S) & *D); +} + +/* TDSToaxn source transparent/pattern opaque. */ +static void rop3_167_1_0 (unsigned char *D, unsigned char S, unsigned char T) +{ + unsigned char stk1; + unsigned char stk2; + unsigned char stk3; + stk3 = S | T; + stk2 = *D & stk3; + stk1 = T ^ stk2; + stk1 = ~stk1; + *D = (stk1 & (~S)) | (*D & S); +} + +/* TDSToaxn source/pattern transparent. */ +static void rop3_167_1_1 (unsigned char *D, unsigned char S, unsigned char T) +{ + unsigned char stk1; + unsigned char stk2; + unsigned char stk3; + stk3 = S | T; + stk2 = *D & stk3; + stk1 = T ^ stk2; + stk1 = ~stk1; + *D = (stk1 & (~S) & (~T)) | (*D & S) | (*D & T); +} + +/* TDSToaxn source/pattern opaque. */ +static unsigned xrop3_167_0_0 (unsigned char s, unsigned char t) +{ + unsigned D = 0x00ff; + unsigned S = ((unsigned)s << 8) | s; + unsigned T = ((unsigned)t << 8) | t; + unsigned stk1; + unsigned stk2; + unsigned stk3; + stk3 = S | T; + stk2 = D & stk3; + stk1 = T ^ stk2; + stk1 = ~stk1; + return stk1; +} + +/* TDSToaxn source opaque/pattern transparent. */ +static unsigned xrop3_167_0_1 (unsigned char s, unsigned char t) +{ + unsigned D = 0x00ff; + unsigned S = ((unsigned)s << 8) | s; + unsigned T = ((unsigned)t << 8) | t; + unsigned stk1; + unsigned stk2; + unsigned stk3; + stk3 = S | T; + stk2 = D & stk3; + stk1 = T ^ stk2; + stk1 = ~stk1; + return (stk1 & S) | (stk1 & (~T)) | (T & (~S) & D); +} + +/* TDSToaxn source transparent/pattern opaque. */ +static unsigned xrop3_167_1_0 (unsigned char s, unsigned char t) +{ + unsigned D = 0x00ff; + unsigned S = ((unsigned)s << 8) | s; + unsigned T = ((unsigned)t << 8) | t; + unsigned stk1; + unsigned stk2; + unsigned stk3; + stk3 = S | T; + stk2 = D & stk3; + stk1 = T ^ stk2; + stk1 = ~stk1; + return (stk1 & (~S)) | (D & S); +} + +/* TDSToaxn source/pattern transparent. */ +static unsigned xrop3_167_1_1 (unsigned char s, unsigned char t) +{ + unsigned D = 0x00ff; + unsigned S = ((unsigned)s << 8) | s; + unsigned T = ((unsigned)t << 8) | t; + unsigned stk1; + unsigned stk2; + unsigned stk3; + stk3 = S | T; + stk2 = D & stk3; + stk1 = T ^ stk2; + stk1 = ~stk1; + return (stk1 & (~S) & (~T)) | (D & S) | (D & T); +} + +/* DTSoa source/pattern opaque. */ +static void rop3_168_0_0 (unsigned char *D, unsigned char S, unsigned char T) +{ + unsigned char stk1; + unsigned char stk2; + stk2 = T | S; + stk1 = *D & stk2; + *D = stk1; +} + +/* DTSoa source opaque/pattern transparent. */ +static void rop3_168_0_1 (unsigned char *D, unsigned char S, unsigned char T) +{ + unsigned char stk1; + unsigned char stk2; + stk2 = T | S; + stk1 = *D & stk2; + *D = (stk1 & S) | (stk1 & (~T)) | (T & (~S) & *D); +} + +/* DTSoa source transparent/pattern opaque. */ +static void rop3_168_1_0 (unsigned char *D, unsigned char S, unsigned char T) +{ + unsigned char stk1; + unsigned char stk2; + stk2 = T | S; + stk1 = *D & stk2; + *D = (stk1 & (~S)) | (*D & S); +} + +/* DTSoa source/pattern transparent. */ +static void rop3_168_1_1 (unsigned char *D, unsigned char S, unsigned char T) +{ + unsigned char stk1; + unsigned char stk2; + stk2 = T | S; + stk1 = *D & stk2; + *D = (stk1 & (~S) & (~T)) | (*D & S) | (*D & T); +} + +/* DTSoa source/pattern opaque. */ +static unsigned xrop3_168_0_0 (unsigned char s, unsigned char t) +{ + unsigned D = 0x00ff; + unsigned S = ((unsigned)s << 8) | s; + unsigned T = ((unsigned)t << 8) | t; + unsigned stk1; + unsigned stk2; + stk2 = T | S; + stk1 = D & stk2; + return stk1; +} + +/* DTSoa source opaque/pattern transparent. */ +static unsigned xrop3_168_0_1 (unsigned char s, unsigned char t) +{ + unsigned D = 0x00ff; + unsigned S = ((unsigned)s << 8) | s; + unsigned T = ((unsigned)t << 8) | t; + unsigned stk1; + unsigned stk2; + stk2 = T | S; + stk1 = D & stk2; + return (stk1 & S) | (stk1 & (~T)) | (T & (~S) & D); +} + +/* DTSoa source transparent/pattern opaque. */ +static unsigned xrop3_168_1_0 (unsigned char s, unsigned char t) +{ + unsigned D = 0x00ff; + unsigned S = ((unsigned)s << 8) | s; + unsigned T = ((unsigned)t << 8) | t; + unsigned stk1; + unsigned stk2; + stk2 = T | S; + stk1 = D & stk2; + return (stk1 & (~S)) | (D & S); +} + +/* DTSoa source/pattern transparent. */ +static unsigned xrop3_168_1_1 (unsigned char s, unsigned char t) +{ + unsigned D = 0x00ff; + unsigned S = ((unsigned)s << 8) | s; + unsigned T = ((unsigned)t << 8) | t; + unsigned stk1; + unsigned stk2; + stk2 = T | S; + stk1 = D & stk2; + return (stk1 & (~S) & (~T)) | (D & S) | (D & T); +} + +/* DTSoxn source/pattern opaque. */ +static void rop3_169_0_0 (unsigned char *D, unsigned char S, unsigned char T) +{ + unsigned char stk1; + unsigned char stk2; + stk2 = T | S; + stk1 = *D ^ stk2; + stk1 = ~stk1; + *D = stk1; +} + +/* DTSoxn source opaque/pattern transparent. */ +static void rop3_169_0_1 (unsigned char *D, unsigned char S, unsigned char T) +{ + unsigned char stk1; + unsigned char stk2; + stk2 = T | S; + stk1 = *D ^ stk2; + stk1 = ~stk1; + *D = (stk1 & S) | (stk1 & (~T)) | (T & (~S) & *D); +} + +/* DTSoxn source transparent/pattern opaque. */ +static void rop3_169_1_0 (unsigned char *D, unsigned char S, unsigned char T) +{ + unsigned char stk1; + unsigned char stk2; + stk2 = T | S; + stk1 = *D ^ stk2; + stk1 = ~stk1; + *D = (stk1 & (~S)) | (*D & S); +} + +/* DTSoxn source/pattern transparent. */ +static void rop3_169_1_1 (unsigned char *D, unsigned char S, unsigned char T) +{ + unsigned char stk1; + unsigned char stk2; + stk2 = T | S; + stk1 = *D ^ stk2; + stk1 = ~stk1; + *D = (stk1 & (~S) & (~T)) | (*D & S) | (*D & T); +} + +/* DTSoxn source/pattern opaque. */ +static unsigned xrop3_169_0_0 (unsigned char s, unsigned char t) +{ + unsigned D = 0x00ff; + unsigned S = ((unsigned)s << 8) | s; + unsigned T = ((unsigned)t << 8) | t; + unsigned stk1; + unsigned stk2; + stk2 = T | S; + stk1 = D ^ stk2; + stk1 = ~stk1; + return stk1; +} + +/* DTSoxn source opaque/pattern transparent. */ +static unsigned xrop3_169_0_1 (unsigned char s, unsigned char t) +{ + unsigned D = 0x00ff; + unsigned S = ((unsigned)s << 8) | s; + unsigned T = ((unsigned)t << 8) | t; + unsigned stk1; + unsigned stk2; + stk2 = T | S; + stk1 = D ^ stk2; + stk1 = ~stk1; + return (stk1 & S) | (stk1 & (~T)) | (T & (~S) & D); +} + +/* DTSoxn source transparent/pattern opaque. */ +static unsigned xrop3_169_1_0 (unsigned char s, unsigned char t) +{ + unsigned D = 0x00ff; + unsigned S = ((unsigned)s << 8) | s; + unsigned T = ((unsigned)t << 8) | t; + unsigned stk1; + unsigned stk2; + stk2 = T | S; + stk1 = D ^ stk2; + stk1 = ~stk1; + return (stk1 & (~S)) | (D & S); +} + +/* DTSoxn source/pattern transparent. */ +static unsigned xrop3_169_1_1 (unsigned char s, unsigned char t) +{ + unsigned D = 0x00ff; + unsigned S = ((unsigned)s << 8) | s; + unsigned T = ((unsigned)t << 8) | t; + unsigned stk1; + unsigned stk2; + stk2 = T | S; + stk1 = D ^ stk2; + stk1 = ~stk1; + return (stk1 & (~S) & (~T)) | (D & S) | (D & T); +} + +/* D source/pattern opaque. */ +static void rop3_170_0_0 (unsigned char *D, unsigned char S, unsigned char T) +{ +} + +/* D source opaque/pattern transparent. */ +static void rop3_170_0_1 (unsigned char *D, unsigned char S, unsigned char T) +{ + *D = (*D & S) | (*D & (~T)) | (T & (~S) & *D); +} + +/* D source transparent/pattern opaque. */ +static void rop3_170_1_0 (unsigned char *D, unsigned char S, unsigned char T) +{ + *D = (*D & (~S)) | (*D & S); +} + +/* D source/pattern transparent. */ +static void rop3_170_1_1 (unsigned char *D, unsigned char S, unsigned char T) +{ + *D = (*D & (~S) & (~T)) | (*D & S) | (*D & T); +} + +/* D source/pattern opaque. */ +static unsigned xrop3_170_0_0 (unsigned char s, unsigned char t) +{ + unsigned D = 0x00ff; + return D; +} + +/* D source opaque/pattern transparent. */ +static unsigned xrop3_170_0_1 (unsigned char s, unsigned char t) +{ + unsigned D = 0x00ff; + unsigned S = ((unsigned)s << 8) | s; + unsigned T = ((unsigned)t << 8) | t; + return (D & S) | (D & (~T)) | (T & (~S) & D); +} + +/* D source transparent/pattern opaque. */ +static unsigned xrop3_170_1_0 (unsigned char s, unsigned char t) +{ + unsigned D = 0x00ff; + unsigned S = ((unsigned)s << 8) | s; + return (D & (~S)) | (D & S); +} + +/* D source/pattern transparent. */ +static unsigned xrop3_170_1_1 (unsigned char s, unsigned char t) +{ + unsigned D = 0x00ff; + unsigned S = ((unsigned)s << 8) | s; + unsigned T = ((unsigned)t << 8) | t; + return (D & (~S) & (~T)) | (D & S) | (D & T); +} + +/* DTSono source/pattern opaque. */ +static void rop3_171_0_0 (unsigned char *D, unsigned char S, unsigned char T) +{ + unsigned char stk1; + unsigned char stk2; + stk2 = T | S; + stk2 = ~stk2; + stk1 = *D | stk2; + *D = stk1; +} + +/* DTSono source opaque/pattern transparent. */ +static void rop3_171_0_1 (unsigned char *D, unsigned char S, unsigned char T) +{ + unsigned char stk1; + unsigned char stk2; + stk2 = T | S; + stk2 = ~stk2; + stk1 = *D | stk2; + *D = (stk1 & S) | (stk1 & (~T)) | (T & (~S) & *D); +} + +/* DTSono source transparent/pattern opaque. */ +static void rop3_171_1_0 (unsigned char *D, unsigned char S, unsigned char T) +{ + unsigned char stk1; + unsigned char stk2; + stk2 = T | S; + stk2 = ~stk2; + stk1 = *D | stk2; + *D = (stk1 & (~S)) | (*D & S); +} + +/* DTSono source/pattern transparent. */ +static void rop3_171_1_1 (unsigned char *D, unsigned char S, unsigned char T) +{ + unsigned char stk1; + unsigned char stk2; + stk2 = T | S; + stk2 = ~stk2; + stk1 = *D | stk2; + *D = (stk1 & (~S) & (~T)) | (*D & S) | (*D & T); +} + +/* DTSono source/pattern opaque. */ +static unsigned xrop3_171_0_0 (unsigned char s, unsigned char t) +{ + unsigned D = 0x00ff; + unsigned S = ((unsigned)s << 8) | s; + unsigned T = ((unsigned)t << 8) | t; + unsigned stk1; + unsigned stk2; + stk2 = T | S; + stk2 = ~stk2; + stk1 = D | stk2; + return stk1; +} + +/* DTSono source opaque/pattern transparent. */ +static unsigned xrop3_171_0_1 (unsigned char s, unsigned char t) +{ + unsigned D = 0x00ff; + unsigned S = ((unsigned)s << 8) | s; + unsigned T = ((unsigned)t << 8) | t; + unsigned stk1; + unsigned stk2; + stk2 = T | S; + stk2 = ~stk2; + stk1 = D | stk2; + return (stk1 & S) | (stk1 & (~T)) | (T & (~S) & D); +} + +/* DTSono source transparent/pattern opaque. */ +static unsigned xrop3_171_1_0 (unsigned char s, unsigned char t) +{ + unsigned D = 0x00ff; + unsigned S = ((unsigned)s << 8) | s; + unsigned T = ((unsigned)t << 8) | t; + unsigned stk1; + unsigned stk2; + stk2 = T | S; + stk2 = ~stk2; + stk1 = D | stk2; + return (stk1 & (~S)) | (D & S); +} + +/* DTSono source/pattern transparent. */ +static unsigned xrop3_171_1_1 (unsigned char s, unsigned char t) +{ + unsigned D = 0x00ff; + unsigned S = ((unsigned)s << 8) | s; + unsigned T = ((unsigned)t << 8) | t; + unsigned stk1; + unsigned stk2; + stk2 = T | S; + stk2 = ~stk2; + stk1 = D | stk2; + return (stk1 & (~S) & (~T)) | (D & S) | (D & T); +} + +/* STDSxax source/pattern opaque. */ +static void rop3_172_0_0 (unsigned char *D, unsigned char S, unsigned char T) +{ + unsigned char stk1; + unsigned char stk2; + unsigned char stk3; + stk3 = *D ^ S; + stk2 = T & stk3; + stk1 = S ^ stk2; + *D = stk1; +} + +/* STDSxax source opaque/pattern transparent. */ +static void rop3_172_0_1 (unsigned char *D, unsigned char S, unsigned char T) +{ + unsigned char stk1; + unsigned char stk2; + unsigned char stk3; + stk3 = *D ^ S; + stk2 = T & stk3; + stk1 = S ^ stk2; + *D = (stk1 & S) | (stk1 & (~T)) | (T & (~S) & *D); +} + +/* STDSxax source transparent/pattern opaque. */ +static void rop3_172_1_0 (unsigned char *D, unsigned char S, unsigned char T) +{ + unsigned char stk1; + unsigned char stk2; + unsigned char stk3; + stk3 = *D ^ S; + stk2 = T & stk3; + stk1 = S ^ stk2; + *D = (stk1 & (~S)) | (*D & S); +} + +/* STDSxax source/pattern transparent. */ +static void rop3_172_1_1 (unsigned char *D, unsigned char S, unsigned char T) +{ + unsigned char stk1; + unsigned char stk2; + unsigned char stk3; + stk3 = *D ^ S; + stk2 = T & stk3; + stk1 = S ^ stk2; + *D = (stk1 & (~S) & (~T)) | (*D & S) | (*D & T); +} + +/* STDSxax source/pattern opaque. */ +static unsigned xrop3_172_0_0 (unsigned char s, unsigned char t) +{ + unsigned D = 0x00ff; + unsigned S = ((unsigned)s << 8) | s; + unsigned T = ((unsigned)t << 8) | t; + unsigned stk1; + unsigned stk2; + unsigned stk3; + stk3 = D ^ S; + stk2 = T & stk3; + stk1 = S ^ stk2; + return stk1; +} + +/* STDSxax source opaque/pattern transparent. */ +static unsigned xrop3_172_0_1 (unsigned char s, unsigned char t) +{ + unsigned D = 0x00ff; + unsigned S = ((unsigned)s << 8) | s; + unsigned T = ((unsigned)t << 8) | t; + unsigned stk1; + unsigned stk2; + unsigned stk3; + stk3 = D ^ S; + stk2 = T & stk3; + stk1 = S ^ stk2; + return (stk1 & S) | (stk1 & (~T)) | (T & (~S) & D); +} + +/* STDSxax source transparent/pattern opaque. */ +static unsigned xrop3_172_1_0 (unsigned char s, unsigned char t) +{ + unsigned D = 0x00ff; + unsigned S = ((unsigned)s << 8) | s; + unsigned T = ((unsigned)t << 8) | t; + unsigned stk1; + unsigned stk2; + unsigned stk3; + stk3 = D ^ S; + stk2 = T & stk3; + stk1 = S ^ stk2; + return (stk1 & (~S)) | (D & S); +} + +/* STDSxax source/pattern transparent. */ +static unsigned xrop3_172_1_1 (unsigned char s, unsigned char t) +{ + unsigned D = 0x00ff; + unsigned S = ((unsigned)s << 8) | s; + unsigned T = ((unsigned)t << 8) | t; + unsigned stk1; + unsigned stk2; + unsigned stk3; + stk3 = D ^ S; + stk2 = T & stk3; + stk1 = S ^ stk2; + return (stk1 & (~S) & (~T)) | (D & S) | (D & T); +} + +/* DTSDaoxn source/pattern opaque. */ +static void rop3_173_0_0 (unsigned char *D, unsigned char S, unsigned char T) +{ + unsigned char stk1; + unsigned char stk2; + unsigned char stk3; + stk3 = S & *D; + stk2 = T | stk3; + stk1 = *D ^ stk2; + stk1 = ~stk1; + *D = stk1; +} + +/* DTSDaoxn source opaque/pattern transparent. */ +static void rop3_173_0_1 (unsigned char *D, unsigned char S, unsigned char T) +{ + unsigned char stk1; + unsigned char stk2; + unsigned char stk3; + stk3 = S & *D; + stk2 = T | stk3; + stk1 = *D ^ stk2; + stk1 = ~stk1; + *D = (stk1 & S) | (stk1 & (~T)) | (T & (~S) & *D); +} + +/* DTSDaoxn source transparent/pattern opaque. */ +static void rop3_173_1_0 (unsigned char *D, unsigned char S, unsigned char T) +{ + unsigned char stk1; + unsigned char stk2; + unsigned char stk3; + stk3 = S & *D; + stk2 = T | stk3; + stk1 = *D ^ stk2; + stk1 = ~stk1; + *D = (stk1 & (~S)) | (*D & S); +} + +/* DTSDaoxn source/pattern transparent. */ +static void rop3_173_1_1 (unsigned char *D, unsigned char S, unsigned char T) +{ + unsigned char stk1; + unsigned char stk2; + unsigned char stk3; + stk3 = S & *D; + stk2 = T | stk3; + stk1 = *D ^ stk2; + stk1 = ~stk1; + *D = (stk1 & (~S) & (~T)) | (*D & S) | (*D & T); +} + +/* DTSDaoxn source/pattern opaque. */ +static unsigned xrop3_173_0_0 (unsigned char s, unsigned char t) +{ + unsigned D = 0x00ff; + unsigned S = ((unsigned)s << 8) | s; + unsigned T = ((unsigned)t << 8) | t; + unsigned stk1; + unsigned stk2; + unsigned stk3; + stk3 = S & D; + stk2 = T | stk3; + stk1 = D ^ stk2; + stk1 = ~stk1; + return stk1; +} + +/* DTSDaoxn source opaque/pattern transparent. */ +static unsigned xrop3_173_0_1 (unsigned char s, unsigned char t) +{ + unsigned D = 0x00ff; + unsigned S = ((unsigned)s << 8) | s; + unsigned T = ((unsigned)t << 8) | t; + unsigned stk1; + unsigned stk2; + unsigned stk3; + stk3 = S & D; + stk2 = T | stk3; + stk1 = D ^ stk2; + stk1 = ~stk1; + return (stk1 & S) | (stk1 & (~T)) | (T & (~S) & D); +} + +/* DTSDaoxn source transparent/pattern opaque. */ +static unsigned xrop3_173_1_0 (unsigned char s, unsigned char t) +{ + unsigned D = 0x00ff; + unsigned S = ((unsigned)s << 8) | s; + unsigned T = ((unsigned)t << 8) | t; + unsigned stk1; + unsigned stk2; + unsigned stk3; + stk3 = S & D; + stk2 = T | stk3; + stk1 = D ^ stk2; + stk1 = ~stk1; + return (stk1 & (~S)) | (D & S); +} + +/* DTSDaoxn source/pattern transparent. */ +static unsigned xrop3_173_1_1 (unsigned char s, unsigned char t) +{ + unsigned D = 0x00ff; + unsigned S = ((unsigned)s << 8) | s; + unsigned T = ((unsigned)t << 8) | t; + unsigned stk1; + unsigned stk2; + unsigned stk3; + stk3 = S & D; + stk2 = T | stk3; + stk1 = D ^ stk2; + stk1 = ~stk1; + return (stk1 & (~S) & (~T)) | (D & S) | (D & T); +} + +/* DSTnao source/pattern opaque. */ +static void rop3_174_0_0 (unsigned char *D, unsigned char S, unsigned char T) +{ + unsigned char stk1; + unsigned char stk2; + unsigned char stk3; + stk3 = ~T; + stk2 = S & stk3; + stk1 = *D | stk2; + *D = stk1; +} + +/* DSTnao source opaque/pattern transparent. */ +static void rop3_174_0_1 (unsigned char *D, unsigned char S, unsigned char T) +{ + unsigned char stk1; + unsigned char stk2; + unsigned char stk3; + stk3 = ~T; + stk2 = S & stk3; + stk1 = *D | stk2; + *D = (stk1 & S) | (stk1 & (~T)) | (T & (~S) & *D); +} + +/* DSTnao source transparent/pattern opaque. */ +static void rop3_174_1_0 (unsigned char *D, unsigned char S, unsigned char T) +{ + unsigned char stk1; + unsigned char stk2; + unsigned char stk3; + stk3 = ~T; + stk2 = S & stk3; + stk1 = *D | stk2; + *D = (stk1 & (~S)) | (*D & S); +} + +/* DSTnao source/pattern transparent. */ +static void rop3_174_1_1 (unsigned char *D, unsigned char S, unsigned char T) +{ + unsigned char stk1; + unsigned char stk2; + unsigned char stk3; + stk3 = ~T; + stk2 = S & stk3; + stk1 = *D | stk2; + *D = (stk1 & (~S) & (~T)) | (*D & S) | (*D & T); +} + +/* DSTnao source/pattern opaque. */ +static unsigned xrop3_174_0_0 (unsigned char s, unsigned char t) +{ + unsigned D = 0x00ff; + unsigned S = ((unsigned)s << 8) | s; + unsigned T = ((unsigned)t << 8) | t; + unsigned stk1; + unsigned stk2; + unsigned stk3; + stk3 = ~T; + stk2 = S & stk3; + stk1 = D | stk2; + return stk1; +} + +/* DSTnao source opaque/pattern transparent. */ +static unsigned xrop3_174_0_1 (unsigned char s, unsigned char t) +{ + unsigned D = 0x00ff; + unsigned S = ((unsigned)s << 8) | s; + unsigned T = ((unsigned)t << 8) | t; + unsigned stk1; + unsigned stk2; + unsigned stk3; + stk3 = ~T; + stk2 = S & stk3; + stk1 = D | stk2; + return (stk1 & S) | (stk1 & (~T)) | (T & (~S) & D); +} + +/* DSTnao source transparent/pattern opaque. */ +static unsigned xrop3_174_1_0 (unsigned char s, unsigned char t) +{ + unsigned D = 0x00ff; + unsigned S = ((unsigned)s << 8) | s; + unsigned T = ((unsigned)t << 8) | t; + unsigned stk1; + unsigned stk2; + unsigned stk3; + stk3 = ~T; + stk2 = S & stk3; + stk1 = D | stk2; + return (stk1 & (~S)) | (D & S); +} + +/* DSTnao source/pattern transparent. */ +static unsigned xrop3_174_1_1 (unsigned char s, unsigned char t) +{ + unsigned D = 0x00ff; + unsigned S = ((unsigned)s << 8) | s; + unsigned T = ((unsigned)t << 8) | t; + unsigned stk1; + unsigned stk2; + unsigned stk3; + stk3 = ~T; + stk2 = S & stk3; + stk1 = D | stk2; + return (stk1 & (~S) & (~T)) | (D & S) | (D & T); +} + +/* DTno source/pattern opaque. */ +static void rop3_175_0_0 (unsigned char *D, unsigned char S, unsigned char T) +{ + unsigned char stk1; + unsigned char stk2; + stk2 = ~T; + stk1 = *D | stk2; + *D = stk1; +} + +/* DTno source opaque/pattern transparent. */ +static void rop3_175_0_1 (unsigned char *D, unsigned char S, unsigned char T) +{ + unsigned char stk1; + unsigned char stk2; + stk2 = ~T; + stk1 = *D | stk2; + *D = (stk1 & S) | (stk1 & (~T)) | (T & (~S) & *D); +} + +/* DTno source transparent/pattern opaque. */ +static void rop3_175_1_0 (unsigned char *D, unsigned char S, unsigned char T) +{ + unsigned char stk1; + unsigned char stk2; + stk2 = ~T; + stk1 = *D | stk2; + *D = (stk1 & (~S)) | (*D & S); +} + +/* DTno source/pattern transparent. */ +static void rop3_175_1_1 (unsigned char *D, unsigned char S, unsigned char T) +{ + unsigned char stk1; + unsigned char stk2; + stk2 = ~T; + stk1 = *D | stk2; + *D = (stk1 & (~S) & (~T)) | (*D & S) | (*D & T); +} + +/* DTno source/pattern opaque. */ +static unsigned xrop3_175_0_0 (unsigned char s, unsigned char t) +{ + unsigned D = 0x00ff; + unsigned T = ((unsigned)t << 8) | t; + unsigned stk1; + unsigned stk2; + stk2 = ~T; + stk1 = D | stk2; + return stk1; +} + +/* DTno source opaque/pattern transparent. */ +static unsigned xrop3_175_0_1 (unsigned char s, unsigned char t) +{ + unsigned D = 0x00ff; + unsigned S = ((unsigned)s << 8) | s; + unsigned T = ((unsigned)t << 8) | t; + unsigned stk1; + unsigned stk2; + stk2 = ~T; + stk1 = D | stk2; + return (stk1 & S) | (stk1 & (~T)) | (T & (~S) & D); +} + +/* DTno source transparent/pattern opaque. */ +static unsigned xrop3_175_1_0 (unsigned char s, unsigned char t) +{ + unsigned D = 0x00ff; + unsigned S = ((unsigned)s << 8) | s; + unsigned T = ((unsigned)t << 8) | t; + unsigned stk1; + unsigned stk2; + stk2 = ~T; + stk1 = D | stk2; + return (stk1 & (~S)) | (D & S); +} + +/* DTno source/pattern transparent. */ +static unsigned xrop3_175_1_1 (unsigned char s, unsigned char t) +{ + unsigned D = 0x00ff; + unsigned S = ((unsigned)s << 8) | s; + unsigned T = ((unsigned)t << 8) | t; + unsigned stk1; + unsigned stk2; + stk2 = ~T; + stk1 = D | stk2; + return (stk1 & (~S) & (~T)) | (D & S) | (D & T); +} + +/* TDSnoa source/pattern opaque. */ +static void rop3_176_0_0 (unsigned char *D, unsigned char S, unsigned char T) +{ + unsigned char stk1; + unsigned char stk2; + unsigned char stk3; + stk3 = ~S; + stk2 = *D | stk3; + stk1 = T & stk2; + *D = stk1; +} + +/* TDSnoa source opaque/pattern transparent. */ +static void rop3_176_0_1 (unsigned char *D, unsigned char S, unsigned char T) +{ + unsigned char stk1; + unsigned char stk2; + unsigned char stk3; + stk3 = ~S; + stk2 = *D | stk3; + stk1 = T & stk2; + *D = (stk1 & S) | (stk1 & (~T)) | (T & (~S) & *D); +} + +/* TDSnoa source transparent/pattern opaque. */ +static void rop3_176_1_0 (unsigned char *D, unsigned char S, unsigned char T) +{ + unsigned char stk1; + unsigned char stk2; + unsigned char stk3; + stk3 = ~S; + stk2 = *D | stk3; + stk1 = T & stk2; + *D = (stk1 & (~S)) | (*D & S); +} + +/* TDSnoa source/pattern transparent. */ +static void rop3_176_1_1 (unsigned char *D, unsigned char S, unsigned char T) +{ + unsigned char stk1; + unsigned char stk2; + unsigned char stk3; + stk3 = ~S; + stk2 = *D | stk3; + stk1 = T & stk2; + *D = (stk1 & (~S) & (~T)) | (*D & S) | (*D & T); +} + +/* TDSnoa source/pattern opaque. */ +static unsigned xrop3_176_0_0 (unsigned char s, unsigned char t) +{ + unsigned D = 0x00ff; + unsigned S = ((unsigned)s << 8) | s; + unsigned T = ((unsigned)t << 8) | t; + unsigned stk1; + unsigned stk2; + unsigned stk3; + stk3 = ~S; + stk2 = D | stk3; + stk1 = T & stk2; + return stk1; +} + +/* TDSnoa source opaque/pattern transparent. */ +static unsigned xrop3_176_0_1 (unsigned char s, unsigned char t) +{ + unsigned D = 0x00ff; + unsigned S = ((unsigned)s << 8) | s; + unsigned T = ((unsigned)t << 8) | t; + unsigned stk1; + unsigned stk2; + unsigned stk3; + stk3 = ~S; + stk2 = D | stk3; + stk1 = T & stk2; + return (stk1 & S) | (stk1 & (~T)) | (T & (~S) & D); +} + +/* TDSnoa source transparent/pattern opaque. */ +static unsigned xrop3_176_1_0 (unsigned char s, unsigned char t) +{ + unsigned D = 0x00ff; + unsigned S = ((unsigned)s << 8) | s; + unsigned T = ((unsigned)t << 8) | t; + unsigned stk1; + unsigned stk2; + unsigned stk3; + stk3 = ~S; + stk2 = D | stk3; + stk1 = T & stk2; + return (stk1 & (~S)) | (D & S); +} + +/* TDSnoa source/pattern transparent. */ +static unsigned xrop3_176_1_1 (unsigned char s, unsigned char t) +{ + unsigned D = 0x00ff; + unsigned S = ((unsigned)s << 8) | s; + unsigned T = ((unsigned)t << 8) | t; + unsigned stk1; + unsigned stk2; + unsigned stk3; + stk3 = ~S; + stk2 = D | stk3; + stk1 = T & stk2; + return (stk1 & (~S) & (~T)) | (D & S) | (D & T); +} + +/* TDSTxoxn source/pattern opaque. */ +static void rop3_177_0_0 (unsigned char *D, unsigned char S, unsigned char T) +{ + unsigned char stk1; + unsigned char stk2; + unsigned char stk3; + stk3 = S ^ T; + stk2 = *D | stk3; + stk1 = T ^ stk2; + stk1 = ~stk1; + *D = stk1; +} + +/* TDSTxoxn source opaque/pattern transparent. */ +static void rop3_177_0_1 (unsigned char *D, unsigned char S, unsigned char T) +{ + unsigned char stk1; + unsigned char stk2; + unsigned char stk3; + stk3 = S ^ T; + stk2 = *D | stk3; + stk1 = T ^ stk2; + stk1 = ~stk1; + *D = (stk1 & S) | (stk1 & (~T)) | (T & (~S) & *D); +} + +/* TDSTxoxn source transparent/pattern opaque. */ +static void rop3_177_1_0 (unsigned char *D, unsigned char S, unsigned char T) +{ + unsigned char stk1; + unsigned char stk2; + unsigned char stk3; + stk3 = S ^ T; + stk2 = *D | stk3; + stk1 = T ^ stk2; + stk1 = ~stk1; + *D = (stk1 & (~S)) | (*D & S); +} + +/* TDSTxoxn source/pattern transparent. */ +static void rop3_177_1_1 (unsigned char *D, unsigned char S, unsigned char T) +{ + unsigned char stk1; + unsigned char stk2; + unsigned char stk3; + stk3 = S ^ T; + stk2 = *D | stk3; + stk1 = T ^ stk2; + stk1 = ~stk1; + *D = (stk1 & (~S) & (~T)) | (*D & S) | (*D & T); +} + +/* TDSTxoxn source/pattern opaque. */ +static unsigned xrop3_177_0_0 (unsigned char s, unsigned char t) +{ + unsigned D = 0x00ff; + unsigned S = ((unsigned)s << 8) | s; + unsigned T = ((unsigned)t << 8) | t; + unsigned stk1; + unsigned stk2; + unsigned stk3; + stk3 = S ^ T; + stk2 = D | stk3; + stk1 = T ^ stk2; + stk1 = ~stk1; + return stk1; +} + +/* TDSTxoxn source opaque/pattern transparent. */ +static unsigned xrop3_177_0_1 (unsigned char s, unsigned char t) +{ + unsigned D = 0x00ff; + unsigned S = ((unsigned)s << 8) | s; + unsigned T = ((unsigned)t << 8) | t; + unsigned stk1; + unsigned stk2; + unsigned stk3; + stk3 = S ^ T; + stk2 = D | stk3; + stk1 = T ^ stk2; + stk1 = ~stk1; + return (stk1 & S) | (stk1 & (~T)) | (T & (~S) & D); +} + +/* TDSTxoxn source transparent/pattern opaque. */ +static unsigned xrop3_177_1_0 (unsigned char s, unsigned char t) +{ + unsigned D = 0x00ff; + unsigned S = ((unsigned)s << 8) | s; + unsigned T = ((unsigned)t << 8) | t; + unsigned stk1; + unsigned stk2; + unsigned stk3; + stk3 = S ^ T; + stk2 = D | stk3; + stk1 = T ^ stk2; + stk1 = ~stk1; + return (stk1 & (~S)) | (D & S); +} + +/* TDSTxoxn source/pattern transparent. */ +static unsigned xrop3_177_1_1 (unsigned char s, unsigned char t) +{ + unsigned D = 0x00ff; + unsigned S = ((unsigned)s << 8) | s; + unsigned T = ((unsigned)t << 8) | t; + unsigned stk1; + unsigned stk2; + unsigned stk3; + stk3 = S ^ T; + stk2 = D | stk3; + stk1 = T ^ stk2; + stk1 = ~stk1; + return (stk1 & (~S) & (~T)) | (D & S) | (D & T); +} + +/* SSTxDSxox source/pattern opaque. */ +static void rop3_178_0_0 (unsigned char *D, unsigned char S, unsigned char T) +{ + unsigned char stk1; + unsigned char stk2; + unsigned char stk3; + stk2 = S ^ T; + stk3 = *D ^ S; + stk2 = stk2 | stk3; + stk1 = S ^ stk2; + *D = stk1; +} + +/* SSTxDSxox source opaque/pattern transparent. */ +static void rop3_178_0_1 (unsigned char *D, unsigned char S, unsigned char T) +{ + unsigned char stk1; + unsigned char stk2; + unsigned char stk3; + stk2 = S ^ T; + stk3 = *D ^ S; + stk2 = stk2 | stk3; + stk1 = S ^ stk2; + *D = (stk1 & S) | (stk1 & (~T)) | (T & (~S) & *D); +} + +/* SSTxDSxox source transparent/pattern opaque. */ +static void rop3_178_1_0 (unsigned char *D, unsigned char S, unsigned char T) +{ + unsigned char stk1; + unsigned char stk2; + unsigned char stk3; + stk2 = S ^ T; + stk3 = *D ^ S; + stk2 = stk2 | stk3; + stk1 = S ^ stk2; + *D = (stk1 & (~S)) | (*D & S); +} + +/* SSTxDSxox source/pattern transparent. */ +static void rop3_178_1_1 (unsigned char *D, unsigned char S, unsigned char T) +{ + unsigned char stk1; + unsigned char stk2; + unsigned char stk3; + stk2 = S ^ T; + stk3 = *D ^ S; + stk2 = stk2 | stk3; + stk1 = S ^ stk2; + *D = (stk1 & (~S) & (~T)) | (*D & S) | (*D & T); +} + +/* SSTxDSxox source/pattern opaque. */ +static unsigned xrop3_178_0_0 (unsigned char s, unsigned char t) +{ + unsigned D = 0x00ff; + unsigned S = ((unsigned)s << 8) | s; + unsigned T = ((unsigned)t << 8) | t; + unsigned stk1; + unsigned stk2; + unsigned stk3; + stk2 = S ^ T; + stk3 = D ^ S; + stk2 = stk2 | stk3; + stk1 = S ^ stk2; + return stk1; +} + +/* SSTxDSxox source opaque/pattern transparent. */ +static unsigned xrop3_178_0_1 (unsigned char s, unsigned char t) +{ + unsigned D = 0x00ff; + unsigned S = ((unsigned)s << 8) | s; + unsigned T = ((unsigned)t << 8) | t; + unsigned stk1; + unsigned stk2; + unsigned stk3; + stk2 = S ^ T; + stk3 = D ^ S; + stk2 = stk2 | stk3; + stk1 = S ^ stk2; + return (stk1 & S) | (stk1 & (~T)) | (T & (~S) & D); +} + +/* SSTxDSxox source transparent/pattern opaque. */ +static unsigned xrop3_178_1_0 (unsigned char s, unsigned char t) +{ + unsigned D = 0x00ff; + unsigned S = ((unsigned)s << 8) | s; + unsigned T = ((unsigned)t << 8) | t; + unsigned stk1; + unsigned stk2; + unsigned stk3; + stk2 = S ^ T; + stk3 = D ^ S; + stk2 = stk2 | stk3; + stk1 = S ^ stk2; + return (stk1 & (~S)) | (D & S); +} + +/* SSTxDSxox source/pattern transparent. */ +static unsigned xrop3_178_1_1 (unsigned char s, unsigned char t) +{ + unsigned D = 0x00ff; + unsigned S = ((unsigned)s << 8) | s; + unsigned T = ((unsigned)t << 8) | t; + unsigned stk1; + unsigned stk2; + unsigned stk3; + stk2 = S ^ T; + stk3 = D ^ S; + stk2 = stk2 | stk3; + stk1 = S ^ stk2; + return (stk1 & (~S) & (~T)) | (D & S) | (D & T); +} + +/* SDTanan source/pattern opaque. */ +static void rop3_179_0_0 (unsigned char *D, unsigned char S, unsigned char T) +{ + unsigned char stk1; + unsigned char stk2; + stk2 = *D & T; + stk2 = ~stk2; + stk1 = S & stk2; + stk1 = ~stk1; + *D = stk1; +} + +/* SDTanan source opaque/pattern transparent. */ +static void rop3_179_0_1 (unsigned char *D, unsigned char S, unsigned char T) +{ + unsigned char stk1; + unsigned char stk2; + stk2 = *D & T; + stk2 = ~stk2; + stk1 = S & stk2; + stk1 = ~stk1; + *D = (stk1 & S) | (stk1 & (~T)) | (T & (~S) & *D); +} + +/* SDTanan source transparent/pattern opaque. */ +static void rop3_179_1_0 (unsigned char *D, unsigned char S, unsigned char T) +{ + unsigned char stk1; + unsigned char stk2; + stk2 = *D & T; + stk2 = ~stk2; + stk1 = S & stk2; + stk1 = ~stk1; + *D = (stk1 & (~S)) | (*D & S); +} + +/* SDTanan source/pattern transparent. */ +static void rop3_179_1_1 (unsigned char *D, unsigned char S, unsigned char T) +{ + unsigned char stk1; + unsigned char stk2; + stk2 = *D & T; + stk2 = ~stk2; + stk1 = S & stk2; + stk1 = ~stk1; + *D = (stk1 & (~S) & (~T)) | (*D & S) | (*D & T); +} + +/* SDTanan source/pattern opaque. */ +static unsigned xrop3_179_0_0 (unsigned char s, unsigned char t) +{ + unsigned D = 0x00ff; + unsigned S = ((unsigned)s << 8) | s; + unsigned T = ((unsigned)t << 8) | t; + unsigned stk1; + unsigned stk2; + stk2 = D & T; + stk2 = ~stk2; + stk1 = S & stk2; + stk1 = ~stk1; + return stk1; +} + +/* SDTanan source opaque/pattern transparent. */ +static unsigned xrop3_179_0_1 (unsigned char s, unsigned char t) +{ + unsigned D = 0x00ff; + unsigned S = ((unsigned)s << 8) | s; + unsigned T = ((unsigned)t << 8) | t; + unsigned stk1; + unsigned stk2; + stk2 = D & T; + stk2 = ~stk2; + stk1 = S & stk2; + stk1 = ~stk1; + return (stk1 & S) | (stk1 & (~T)) | (T & (~S) & D); +} + +/* SDTanan source transparent/pattern opaque. */ +static unsigned xrop3_179_1_0 (unsigned char s, unsigned char t) +{ + unsigned D = 0x00ff; + unsigned S = ((unsigned)s << 8) | s; + unsigned T = ((unsigned)t << 8) | t; + unsigned stk1; + unsigned stk2; + stk2 = D & T; + stk2 = ~stk2; + stk1 = S & stk2; + stk1 = ~stk1; + return (stk1 & (~S)) | (D & S); +} + +/* SDTanan source/pattern transparent. */ +static unsigned xrop3_179_1_1 (unsigned char s, unsigned char t) +{ + unsigned D = 0x00ff; + unsigned S = ((unsigned)s << 8) | s; + unsigned T = ((unsigned)t << 8) | t; + unsigned stk1; + unsigned stk2; + stk2 = D & T; + stk2 = ~stk2; + stk1 = S & stk2; + stk1 = ~stk1; + return (stk1 & (~S) & (~T)) | (D & S) | (D & T); +} + +/* TSDnax source/pattern opaque. */ +static void rop3_180_0_0 (unsigned char *D, unsigned char S, unsigned char T) +{ + unsigned char stk1; + unsigned char stk2; + unsigned char stk3; + stk3 = ~*D; + stk2 = S & stk3; + stk1 = T ^ stk2; + *D = stk1; +} + +/* TSDnax source opaque/pattern transparent. */ +static void rop3_180_0_1 (unsigned char *D, unsigned char S, unsigned char T) +{ + unsigned char stk1; + unsigned char stk2; + unsigned char stk3; + stk3 = ~*D; + stk2 = S & stk3; + stk1 = T ^ stk2; + *D = (stk1 & S) | (stk1 & (~T)) | (T & (~S) & *D); +} + +/* TSDnax source transparent/pattern opaque. */ +static void rop3_180_1_0 (unsigned char *D, unsigned char S, unsigned char T) +{ + unsigned char stk1; + unsigned char stk2; + unsigned char stk3; + stk3 = ~*D; + stk2 = S & stk3; + stk1 = T ^ stk2; + *D = (stk1 & (~S)) | (*D & S); +} + +/* TSDnax source/pattern transparent. */ +static void rop3_180_1_1 (unsigned char *D, unsigned char S, unsigned char T) +{ + unsigned char stk1; + unsigned char stk2; + unsigned char stk3; + stk3 = ~*D; + stk2 = S & stk3; + stk1 = T ^ stk2; + *D = (stk1 & (~S) & (~T)) | (*D & S) | (*D & T); +} + +/* TSDnax source/pattern opaque. */ +static unsigned xrop3_180_0_0 (unsigned char s, unsigned char t) +{ + unsigned D = 0x00ff; + unsigned S = ((unsigned)s << 8) | s; + unsigned T = ((unsigned)t << 8) | t; + unsigned stk1; + unsigned stk2; + unsigned stk3; + stk3 = ~D; + stk2 = S & stk3; + stk1 = T ^ stk2; + return stk1; +} + +/* TSDnax source opaque/pattern transparent. */ +static unsigned xrop3_180_0_1 (unsigned char s, unsigned char t) +{ + unsigned D = 0x00ff; + unsigned S = ((unsigned)s << 8) | s; + unsigned T = ((unsigned)t << 8) | t; + unsigned stk1; + unsigned stk2; + unsigned stk3; + stk3 = ~D; + stk2 = S & stk3; + stk1 = T ^ stk2; + return (stk1 & S) | (stk1 & (~T)) | (T & (~S) & D); +} + +/* TSDnax source transparent/pattern opaque. */ +static unsigned xrop3_180_1_0 (unsigned char s, unsigned char t) +{ + unsigned D = 0x00ff; + unsigned S = ((unsigned)s << 8) | s; + unsigned T = ((unsigned)t << 8) | t; + unsigned stk1; + unsigned stk2; + unsigned stk3; + stk3 = ~D; + stk2 = S & stk3; + stk1 = T ^ stk2; + return (stk1 & (~S)) | (D & S); +} + +/* TSDnax source/pattern transparent. */ +static unsigned xrop3_180_1_1 (unsigned char s, unsigned char t) +{ + unsigned D = 0x00ff; + unsigned S = ((unsigned)s << 8) | s; + unsigned T = ((unsigned)t << 8) | t; + unsigned stk1; + unsigned stk2; + unsigned stk3; + stk3 = ~D; + stk2 = S & stk3; + stk1 = T ^ stk2; + return (stk1 & (~S) & (~T)) | (D & S) | (D & T); +} + +/* DTSDoaxn source/pattern opaque. */ +static void rop3_181_0_0 (unsigned char *D, unsigned char S, unsigned char T) +{ + unsigned char stk1; + unsigned char stk2; + unsigned char stk3; + stk3 = S | *D; + stk2 = T & stk3; + stk1 = *D ^ stk2; + stk1 = ~stk1; + *D = stk1; +} + +/* DTSDoaxn source opaque/pattern transparent. */ +static void rop3_181_0_1 (unsigned char *D, unsigned char S, unsigned char T) +{ + unsigned char stk1; + unsigned char stk2; + unsigned char stk3; + stk3 = S | *D; + stk2 = T & stk3; + stk1 = *D ^ stk2; + stk1 = ~stk1; + *D = (stk1 & S) | (stk1 & (~T)) | (T & (~S) & *D); +} + +/* DTSDoaxn source transparent/pattern opaque. */ +static void rop3_181_1_0 (unsigned char *D, unsigned char S, unsigned char T) +{ + unsigned char stk1; + unsigned char stk2; + unsigned char stk3; + stk3 = S | *D; + stk2 = T & stk3; + stk1 = *D ^ stk2; + stk1 = ~stk1; + *D = (stk1 & (~S)) | (*D & S); +} + +/* DTSDoaxn source/pattern transparent. */ +static void rop3_181_1_1 (unsigned char *D, unsigned char S, unsigned char T) +{ + unsigned char stk1; + unsigned char stk2; + unsigned char stk3; + stk3 = S | *D; + stk2 = T & stk3; + stk1 = *D ^ stk2; + stk1 = ~stk1; + *D = (stk1 & (~S) & (~T)) | (*D & S) | (*D & T); +} + +/* DTSDoaxn source/pattern opaque. */ +static unsigned xrop3_181_0_0 (unsigned char s, unsigned char t) +{ + unsigned D = 0x00ff; + unsigned S = ((unsigned)s << 8) | s; + unsigned T = ((unsigned)t << 8) | t; + unsigned stk1; + unsigned stk2; + unsigned stk3; + stk3 = S | D; + stk2 = T & stk3; + stk1 = D ^ stk2; + stk1 = ~stk1; + return stk1; +} + +/* DTSDoaxn source opaque/pattern transparent. */ +static unsigned xrop3_181_0_1 (unsigned char s, unsigned char t) +{ + unsigned D = 0x00ff; + unsigned S = ((unsigned)s << 8) | s; + unsigned T = ((unsigned)t << 8) | t; + unsigned stk1; + unsigned stk2; + unsigned stk3; + stk3 = S | D; + stk2 = T & stk3; + stk1 = D ^ stk2; + stk1 = ~stk1; + return (stk1 & S) | (stk1 & (~T)) | (T & (~S) & D); +} + +/* DTSDoaxn source transparent/pattern opaque. */ +static unsigned xrop3_181_1_0 (unsigned char s, unsigned char t) +{ + unsigned D = 0x00ff; + unsigned S = ((unsigned)s << 8) | s; + unsigned T = ((unsigned)t << 8) | t; + unsigned stk1; + unsigned stk2; + unsigned stk3; + stk3 = S | D; + stk2 = T & stk3; + stk1 = D ^ stk2; + stk1 = ~stk1; + return (stk1 & (~S)) | (D & S); +} + +/* DTSDoaxn source/pattern transparent. */ +static unsigned xrop3_181_1_1 (unsigned char s, unsigned char t) +{ + unsigned D = 0x00ff; + unsigned S = ((unsigned)s << 8) | s; + unsigned T = ((unsigned)t << 8) | t; + unsigned stk1; + unsigned stk2; + unsigned stk3; + stk3 = S | D; + stk2 = T & stk3; + stk1 = D ^ stk2; + stk1 = ~stk1; + return (stk1 & (~S) & (~T)) | (D & S) | (D & T); +} + +/* DTSDTaoxx source/pattern opaque. */ +static void rop3_182_0_0 (unsigned char *D, unsigned char S, unsigned char T) +{ + unsigned char stk1; + unsigned char stk2; + unsigned char stk3; + unsigned char stk4; + stk4 = *D & T; + stk3 = S | stk4; + stk2 = T ^ stk3; + stk1 = *D ^ stk2; + *D = stk1; +} + +/* DTSDTaoxx source opaque/pattern transparent. */ +static void rop3_182_0_1 (unsigned char *D, unsigned char S, unsigned char T) +{ + unsigned char stk1; + unsigned char stk2; + unsigned char stk3; + unsigned char stk4; + stk4 = *D & T; + stk3 = S | stk4; + stk2 = T ^ stk3; + stk1 = *D ^ stk2; + *D = (stk1 & S) | (stk1 & (~T)) | (T & (~S) & *D); +} + +/* DTSDTaoxx source transparent/pattern opaque. */ +static void rop3_182_1_0 (unsigned char *D, unsigned char S, unsigned char T) +{ + unsigned char stk1; + unsigned char stk2; + unsigned char stk3; + unsigned char stk4; + stk4 = *D & T; + stk3 = S | stk4; + stk2 = T ^ stk3; + stk1 = *D ^ stk2; + *D = (stk1 & (~S)) | (*D & S); +} + +/* DTSDTaoxx source/pattern transparent. */ +static void rop3_182_1_1 (unsigned char *D, unsigned char S, unsigned char T) +{ + unsigned char stk1; + unsigned char stk2; + unsigned char stk3; + unsigned char stk4; + stk4 = *D & T; + stk3 = S | stk4; + stk2 = T ^ stk3; + stk1 = *D ^ stk2; + *D = (stk1 & (~S) & (~T)) | (*D & S) | (*D & T); +} + +/* DTSDTaoxx source/pattern opaque. */ +static unsigned xrop3_182_0_0 (unsigned char s, unsigned char t) +{ + unsigned D = 0x00ff; + unsigned S = ((unsigned)s << 8) | s; + unsigned T = ((unsigned)t << 8) | t; + unsigned stk1; + unsigned stk2; + unsigned stk3; + unsigned stk4; + stk4 = D & T; + stk3 = S | stk4; + stk2 = T ^ stk3; + stk1 = D ^ stk2; + return stk1; +} + +/* DTSDTaoxx source opaque/pattern transparent. */ +static unsigned xrop3_182_0_1 (unsigned char s, unsigned char t) +{ + unsigned D = 0x00ff; + unsigned S = ((unsigned)s << 8) | s; + unsigned T = ((unsigned)t << 8) | t; + unsigned stk1; + unsigned stk2; + unsigned stk3; + unsigned stk4; + stk4 = D & T; + stk3 = S | stk4; + stk2 = T ^ stk3; + stk1 = D ^ stk2; + return (stk1 & S) | (stk1 & (~T)) | (T & (~S) & D); +} + +/* DTSDTaoxx source transparent/pattern opaque. */ +static unsigned xrop3_182_1_0 (unsigned char s, unsigned char t) +{ + unsigned D = 0x00ff; + unsigned S = ((unsigned)s << 8) | s; + unsigned T = ((unsigned)t << 8) | t; + unsigned stk1; + unsigned stk2; + unsigned stk3; + unsigned stk4; + stk4 = D & T; + stk3 = S | stk4; + stk2 = T ^ stk3; + stk1 = D ^ stk2; + return (stk1 & (~S)) | (D & S); +} + +/* DTSDTaoxx source/pattern transparent. */ +static unsigned xrop3_182_1_1 (unsigned char s, unsigned char t) +{ + unsigned D = 0x00ff; + unsigned S = ((unsigned)s << 8) | s; + unsigned T = ((unsigned)t << 8) | t; + unsigned stk1; + unsigned stk2; + unsigned stk3; + unsigned stk4; + stk4 = D & T; + stk3 = S | stk4; + stk2 = T ^ stk3; + stk1 = D ^ stk2; + return (stk1 & (~S) & (~T)) | (D & S) | (D & T); +} + +/* SDTxan source/pattern opaque. */ +static void rop3_183_0_0 (unsigned char *D, unsigned char S, unsigned char T) +{ + unsigned char stk1; + unsigned char stk2; + stk2 = *D ^ T; + stk1 = S & stk2; + stk1 = ~stk1; + *D = stk1; +} + +/* SDTxan source opaque/pattern transparent. */ +static void rop3_183_0_1 (unsigned char *D, unsigned char S, unsigned char T) +{ + unsigned char stk1; + unsigned char stk2; + stk2 = *D ^ T; + stk1 = S & stk2; + stk1 = ~stk1; + *D = (stk1 & S) | (stk1 & (~T)) | (T & (~S) & *D); +} + +/* SDTxan source transparent/pattern opaque. */ +static void rop3_183_1_0 (unsigned char *D, unsigned char S, unsigned char T) +{ + unsigned char stk1; + unsigned char stk2; + stk2 = *D ^ T; + stk1 = S & stk2; + stk1 = ~stk1; + *D = (stk1 & (~S)) | (*D & S); +} + +/* SDTxan source/pattern transparent. */ +static void rop3_183_1_1 (unsigned char *D, unsigned char S, unsigned char T) +{ + unsigned char stk1; + unsigned char stk2; + stk2 = *D ^ T; + stk1 = S & stk2; + stk1 = ~stk1; + *D = (stk1 & (~S) & (~T)) | (*D & S) | (*D & T); +} + +/* SDTxan source/pattern opaque. */ +static unsigned xrop3_183_0_0 (unsigned char s, unsigned char t) +{ + unsigned D = 0x00ff; + unsigned S = ((unsigned)s << 8) | s; + unsigned T = ((unsigned)t << 8) | t; + unsigned stk1; + unsigned stk2; + stk2 = D ^ T; + stk1 = S & stk2; + stk1 = ~stk1; + return stk1; +} + +/* SDTxan source opaque/pattern transparent. */ +static unsigned xrop3_183_0_1 (unsigned char s, unsigned char t) +{ + unsigned D = 0x00ff; + unsigned S = ((unsigned)s << 8) | s; + unsigned T = ((unsigned)t << 8) | t; + unsigned stk1; + unsigned stk2; + stk2 = D ^ T; + stk1 = S & stk2; + stk1 = ~stk1; + return (stk1 & S) | (stk1 & (~T)) | (T & (~S) & D); +} + +/* SDTxan source transparent/pattern opaque. */ +static unsigned xrop3_183_1_0 (unsigned char s, unsigned char t) +{ + unsigned D = 0x00ff; + unsigned S = ((unsigned)s << 8) | s; + unsigned T = ((unsigned)t << 8) | t; + unsigned stk1; + unsigned stk2; + stk2 = D ^ T; + stk1 = S & stk2; + stk1 = ~stk1; + return (stk1 & (~S)) | (D & S); +} + +/* SDTxan source/pattern transparent. */ +static unsigned xrop3_183_1_1 (unsigned char s, unsigned char t) +{ + unsigned D = 0x00ff; + unsigned S = ((unsigned)s << 8) | s; + unsigned T = ((unsigned)t << 8) | t; + unsigned stk1; + unsigned stk2; + stk2 = D ^ T; + stk1 = S & stk2; + stk1 = ~stk1; + return (stk1 & (~S) & (~T)) | (D & S) | (D & T); +} + +/* TSDTxax source/pattern opaque. */ +static void rop3_184_0_0 (unsigned char *D, unsigned char S, unsigned char T) +{ + unsigned char stk1; + unsigned char stk2; + unsigned char stk3; + stk3 = *D ^ T; + stk2 = S & stk3; + stk1 = T ^ stk2; + *D = stk1; +} + +/* TSDTxax source opaque/pattern transparent. */ +static void rop3_184_0_1 (unsigned char *D, unsigned char S, unsigned char T) +{ + unsigned char stk1; + unsigned char stk2; + unsigned char stk3; + stk3 = *D ^ T; + stk2 = S & stk3; + stk1 = T ^ stk2; + *D = (stk1 & S) | (stk1 & (~T)) | (T & (~S) & *D); +} + +/* TSDTxax source transparent/pattern opaque. */ +static void rop3_184_1_0 (unsigned char *D, unsigned char S, unsigned char T) +{ + unsigned char stk1; + unsigned char stk2; + unsigned char stk3; + stk3 = *D ^ T; + stk2 = S & stk3; + stk1 = T ^ stk2; + *D = (stk1 & (~S)) | (*D & S); +} + +/* TSDTxax source/pattern transparent. */ +static void rop3_184_1_1 (unsigned char *D, unsigned char S, unsigned char T) +{ + unsigned char stk1; + unsigned char stk2; + unsigned char stk3; + stk3 = *D ^ T; + stk2 = S & stk3; + stk1 = T ^ stk2; + *D = (stk1 & (~S) & (~T)) | (*D & S) | (*D & T); +} + +/* TSDTxax source/pattern opaque. */ +static unsigned xrop3_184_0_0 (unsigned char s, unsigned char t) +{ + unsigned D = 0x00ff; + unsigned S = ((unsigned)s << 8) | s; + unsigned T = ((unsigned)t << 8) | t; + unsigned stk1; + unsigned stk2; + unsigned stk3; + stk3 = D ^ T; + stk2 = S & stk3; + stk1 = T ^ stk2; + return stk1; +} + +/* TSDTxax source opaque/pattern transparent. */ +static unsigned xrop3_184_0_1 (unsigned char s, unsigned char t) +{ + unsigned D = 0x00ff; + unsigned S = ((unsigned)s << 8) | s; + unsigned T = ((unsigned)t << 8) | t; + unsigned stk1; + unsigned stk2; + unsigned stk3; + stk3 = D ^ T; + stk2 = S & stk3; + stk1 = T ^ stk2; + return (stk1 & S) | (stk1 & (~T)) | (T & (~S) & D); +} + +/* TSDTxax source transparent/pattern opaque. */ +static unsigned xrop3_184_1_0 (unsigned char s, unsigned char t) +{ + unsigned D = 0x00ff; + unsigned S = ((unsigned)s << 8) | s; + unsigned T = ((unsigned)t << 8) | t; + unsigned stk1; + unsigned stk2; + unsigned stk3; + stk3 = D ^ T; + stk2 = S & stk3; + stk1 = T ^ stk2; + return (stk1 & (~S)) | (D & S); +} + +/* TSDTxax source/pattern transparent. */ +static unsigned xrop3_184_1_1 (unsigned char s, unsigned char t) +{ + unsigned D = 0x00ff; + unsigned S = ((unsigned)s << 8) | s; + unsigned T = ((unsigned)t << 8) | t; + unsigned stk1; + unsigned stk2; + unsigned stk3; + stk3 = D ^ T; + stk2 = S & stk3; + stk1 = T ^ stk2; + return (stk1 & (~S) & (~T)) | (D & S) | (D & T); +} + +/* DSTDaoxn source/pattern opaque. */ +static void rop3_185_0_0 (unsigned char *D, unsigned char S, unsigned char T) +{ + unsigned char stk1; + unsigned char stk2; + unsigned char stk3; + stk3 = T & *D; + stk2 = S | stk3; + stk1 = *D ^ stk2; + stk1 = ~stk1; + *D = stk1; +} + +/* DSTDaoxn source opaque/pattern transparent. */ +static void rop3_185_0_1 (unsigned char *D, unsigned char S, unsigned char T) +{ + unsigned char stk1; + unsigned char stk2; + unsigned char stk3; + stk3 = T & *D; + stk2 = S | stk3; + stk1 = *D ^ stk2; + stk1 = ~stk1; + *D = (stk1 & S) | (stk1 & (~T)) | (T & (~S) & *D); +} + +/* DSTDaoxn source transparent/pattern opaque. */ +static void rop3_185_1_0 (unsigned char *D, unsigned char S, unsigned char T) +{ + unsigned char stk1; + unsigned char stk2; + unsigned char stk3; + stk3 = T & *D; + stk2 = S | stk3; + stk1 = *D ^ stk2; + stk1 = ~stk1; + *D = (stk1 & (~S)) | (*D & S); +} + +/* DSTDaoxn source/pattern transparent. */ +static void rop3_185_1_1 (unsigned char *D, unsigned char S, unsigned char T) +{ + unsigned char stk1; + unsigned char stk2; + unsigned char stk3; + stk3 = T & *D; + stk2 = S | stk3; + stk1 = *D ^ stk2; + stk1 = ~stk1; + *D = (stk1 & (~S) & (~T)) | (*D & S) | (*D & T); +} + +/* DSTDaoxn source/pattern opaque. */ +static unsigned xrop3_185_0_0 (unsigned char s, unsigned char t) +{ + unsigned D = 0x00ff; + unsigned S = ((unsigned)s << 8) | s; + unsigned T = ((unsigned)t << 8) | t; + unsigned stk1; + unsigned stk2; + unsigned stk3; + stk3 = T & D; + stk2 = S | stk3; + stk1 = D ^ stk2; + stk1 = ~stk1; + return stk1; +} + +/* DSTDaoxn source opaque/pattern transparent. */ +static unsigned xrop3_185_0_1 (unsigned char s, unsigned char t) +{ + unsigned D = 0x00ff; + unsigned S = ((unsigned)s << 8) | s; + unsigned T = ((unsigned)t << 8) | t; + unsigned stk1; + unsigned stk2; + unsigned stk3; + stk3 = T & D; + stk2 = S | stk3; + stk1 = D ^ stk2; + stk1 = ~stk1; + return (stk1 & S) | (stk1 & (~T)) | (T & (~S) & D); +} + +/* DSTDaoxn source transparent/pattern opaque. */ +static unsigned xrop3_185_1_0 (unsigned char s, unsigned char t) +{ + unsigned D = 0x00ff; + unsigned S = ((unsigned)s << 8) | s; + unsigned T = ((unsigned)t << 8) | t; + unsigned stk1; + unsigned stk2; + unsigned stk3; + stk3 = T & D; + stk2 = S | stk3; + stk1 = D ^ stk2; + stk1 = ~stk1; + return (stk1 & (~S)) | (D & S); +} + +/* DSTDaoxn source/pattern transparent. */ +static unsigned xrop3_185_1_1 (unsigned char s, unsigned char t) +{ + unsigned D = 0x00ff; + unsigned S = ((unsigned)s << 8) | s; + unsigned T = ((unsigned)t << 8) | t; + unsigned stk1; + unsigned stk2; + unsigned stk3; + stk3 = T & D; + stk2 = S | stk3; + stk1 = D ^ stk2; + stk1 = ~stk1; + return (stk1 & (~S) & (~T)) | (D & S) | (D & T); +} + +/* DTSnao source/pattern opaque. */ +static void rop3_186_0_0 (unsigned char *D, unsigned char S, unsigned char T) +{ + unsigned char stk1; + unsigned char stk2; + unsigned char stk3; + stk3 = ~S; + stk2 = T & stk3; + stk1 = *D | stk2; + *D = stk1; +} + +/* DTSnao source opaque/pattern transparent. */ +static void rop3_186_0_1 (unsigned char *D, unsigned char S, unsigned char T) +{ + unsigned char stk1; + unsigned char stk2; + unsigned char stk3; + stk3 = ~S; + stk2 = T & stk3; + stk1 = *D | stk2; + *D = (stk1 & S) | (stk1 & (~T)) | (T & (~S) & *D); +} + +/* DTSnao source transparent/pattern opaque. */ +static void rop3_186_1_0 (unsigned char *D, unsigned char S, unsigned char T) +{ + unsigned char stk1; + unsigned char stk2; + unsigned char stk3; + stk3 = ~S; + stk2 = T & stk3; + stk1 = *D | stk2; + *D = (stk1 & (~S)) | (*D & S); +} + +/* DTSnao source/pattern transparent. */ +static void rop3_186_1_1 (unsigned char *D, unsigned char S, unsigned char T) +{ + unsigned char stk1; + unsigned char stk2; + unsigned char stk3; + stk3 = ~S; + stk2 = T & stk3; + stk1 = *D | stk2; + *D = (stk1 & (~S) & (~T)) | (*D & S) | (*D & T); +} + +/* DTSnao source/pattern opaque. */ +static unsigned xrop3_186_0_0 (unsigned char s, unsigned char t) +{ + unsigned D = 0x00ff; + unsigned S = ((unsigned)s << 8) | s; + unsigned T = ((unsigned)t << 8) | t; + unsigned stk1; + unsigned stk2; + unsigned stk3; + stk3 = ~S; + stk2 = T & stk3; + stk1 = D | stk2; + return stk1; +} + +/* DTSnao source opaque/pattern transparent. */ +static unsigned xrop3_186_0_1 (unsigned char s, unsigned char t) +{ + unsigned D = 0x00ff; + unsigned S = ((unsigned)s << 8) | s; + unsigned T = ((unsigned)t << 8) | t; + unsigned stk1; + unsigned stk2; + unsigned stk3; + stk3 = ~S; + stk2 = T & stk3; + stk1 = D | stk2; + return (stk1 & S) | (stk1 & (~T)) | (T & (~S) & D); +} + +/* DTSnao source transparent/pattern opaque. */ +static unsigned xrop3_186_1_0 (unsigned char s, unsigned char t) +{ + unsigned D = 0x00ff; + unsigned S = ((unsigned)s << 8) | s; + unsigned T = ((unsigned)t << 8) | t; + unsigned stk1; + unsigned stk2; + unsigned stk3; + stk3 = ~S; + stk2 = T & stk3; + stk1 = D | stk2; + return (stk1 & (~S)) | (D & S); +} + +/* DTSnao source/pattern transparent. */ +static unsigned xrop3_186_1_1 (unsigned char s, unsigned char t) +{ + unsigned D = 0x00ff; + unsigned S = ((unsigned)s << 8) | s; + unsigned T = ((unsigned)t << 8) | t; + unsigned stk1; + unsigned stk2; + unsigned stk3; + stk3 = ~S; + stk2 = T & stk3; + stk1 = D | stk2; + return (stk1 & (~S) & (~T)) | (D & S) | (D & T); +} + +/* DSno source/pattern opaque. */ +static void rop3_187_0_0 (unsigned char *D, unsigned char S, unsigned char T) +{ + unsigned char stk1; + unsigned char stk2; + stk2 = ~S; + stk1 = *D | stk2; + *D = stk1; +} + +/* DSno source opaque/pattern transparent. */ +static void rop3_187_0_1 (unsigned char *D, unsigned char S, unsigned char T) +{ + unsigned char stk1; + unsigned char stk2; + stk2 = ~S; + stk1 = *D | stk2; + *D = (stk1 & S) | (stk1 & (~T)) | (T & (~S) & *D); +} + +/* DSno source transparent/pattern opaque. */ +static void rop3_187_1_0 (unsigned char *D, unsigned char S, unsigned char T) +{ + unsigned char stk1; + unsigned char stk2; + stk2 = ~S; + stk1 = *D | stk2; + *D = (stk1 & (~S)) | (*D & S); +} + +/* DSno source/pattern transparent. */ +static void rop3_187_1_1 (unsigned char *D, unsigned char S, unsigned char T) +{ + unsigned char stk1; + unsigned char stk2; + stk2 = ~S; + stk1 = *D | stk2; + *D = (stk1 & (~S) & (~T)) | (*D & S) | (*D & T); +} + +/* DSno source/pattern opaque. */ +static unsigned xrop3_187_0_0 (unsigned char s, unsigned char t) +{ + unsigned D = 0x00ff; + unsigned S = ((unsigned)s << 8) | s; + unsigned stk1; + unsigned stk2; + stk2 = ~S; + stk1 = D | stk2; + return stk1; +} + +/* DSno source opaque/pattern transparent. */ +static unsigned xrop3_187_0_1 (unsigned char s, unsigned char t) +{ + unsigned D = 0x00ff; + unsigned S = ((unsigned)s << 8) | s; + unsigned T = ((unsigned)t << 8) | t; + unsigned stk1; + unsigned stk2; + stk2 = ~S; + stk1 = D | stk2; + return (stk1 & S) | (stk1 & (~T)) | (T & (~S) & D); +} + +/* DSno source transparent/pattern opaque. */ +static unsigned xrop3_187_1_0 (unsigned char s, unsigned char t) +{ + unsigned D = 0x00ff; + unsigned S = ((unsigned)s << 8) | s; + unsigned stk1; + unsigned stk2; + stk2 = ~S; + stk1 = D | stk2; + return (stk1 & (~S)) | (D & S); +} + +/* DSno source/pattern transparent. */ +static unsigned xrop3_187_1_1 (unsigned char s, unsigned char t) +{ + unsigned D = 0x00ff; + unsigned S = ((unsigned)s << 8) | s; + unsigned T = ((unsigned)t << 8) | t; + unsigned stk1; + unsigned stk2; + stk2 = ~S; + stk1 = D | stk2; + return (stk1 & (~S) & (~T)) | (D & S) | (D & T); +} + +/* STDSanax source/pattern opaque. */ +static void rop3_188_0_0 (unsigned char *D, unsigned char S, unsigned char T) +{ + unsigned char stk1; + unsigned char stk2; + unsigned char stk3; + stk3 = *D & S; + stk3 = ~stk3; + stk2 = T & stk3; + stk1 = S ^ stk2; + *D = stk1; +} + +/* STDSanax source opaque/pattern transparent. */ +static void rop3_188_0_1 (unsigned char *D, unsigned char S, unsigned char T) +{ + unsigned char stk1; + unsigned char stk2; + unsigned char stk3; + stk3 = *D & S; + stk3 = ~stk3; + stk2 = T & stk3; + stk1 = S ^ stk2; + *D = (stk1 & S) | (stk1 & (~T)) | (T & (~S) & *D); +} + +/* STDSanax source transparent/pattern opaque. */ +static void rop3_188_1_0 (unsigned char *D, unsigned char S, unsigned char T) +{ + unsigned char stk1; + unsigned char stk2; + unsigned char stk3; + stk3 = *D & S; + stk3 = ~stk3; + stk2 = T & stk3; + stk1 = S ^ stk2; + *D = (stk1 & (~S)) | (*D & S); +} + +/* STDSanax source/pattern transparent. */ +static void rop3_188_1_1 (unsigned char *D, unsigned char S, unsigned char T) +{ + unsigned char stk1; + unsigned char stk2; + unsigned char stk3; + stk3 = *D & S; + stk3 = ~stk3; + stk2 = T & stk3; + stk1 = S ^ stk2; + *D = (stk1 & (~S) & (~T)) | (*D & S) | (*D & T); +} + +/* STDSanax source/pattern opaque. */ +static unsigned xrop3_188_0_0 (unsigned char s, unsigned char t) +{ + unsigned D = 0x00ff; + unsigned S = ((unsigned)s << 8) | s; + unsigned T = ((unsigned)t << 8) | t; + unsigned stk1; + unsigned stk2; + unsigned stk3; + stk3 = D & S; + stk3 = ~stk3; + stk2 = T & stk3; + stk1 = S ^ stk2; + return stk1; +} + +/* STDSanax source opaque/pattern transparent. */ +static unsigned xrop3_188_0_1 (unsigned char s, unsigned char t) +{ + unsigned D = 0x00ff; + unsigned S = ((unsigned)s << 8) | s; + unsigned T = ((unsigned)t << 8) | t; + unsigned stk1; + unsigned stk2; + unsigned stk3; + stk3 = D & S; + stk3 = ~stk3; + stk2 = T & stk3; + stk1 = S ^ stk2; + return (stk1 & S) | (stk1 & (~T)) | (T & (~S) & D); +} + +/* STDSanax source transparent/pattern opaque. */ +static unsigned xrop3_188_1_0 (unsigned char s, unsigned char t) +{ + unsigned D = 0x00ff; + unsigned S = ((unsigned)s << 8) | s; + unsigned T = ((unsigned)t << 8) | t; + unsigned stk1; + unsigned stk2; + unsigned stk3; + stk3 = D & S; + stk3 = ~stk3; + stk2 = T & stk3; + stk1 = S ^ stk2; + return (stk1 & (~S)) | (D & S); +} + +/* STDSanax source/pattern transparent. */ +static unsigned xrop3_188_1_1 (unsigned char s, unsigned char t) +{ + unsigned D = 0x00ff; + unsigned S = ((unsigned)s << 8) | s; + unsigned T = ((unsigned)t << 8) | t; + unsigned stk1; + unsigned stk2; + unsigned stk3; + stk3 = D & S; + stk3 = ~stk3; + stk2 = T & stk3; + stk1 = S ^ stk2; + return (stk1 & (~S) & (~T)) | (D & S) | (D & T); +} + +/* SDxTDxan source/pattern opaque. */ +static void rop3_189_0_0 (unsigned char *D, unsigned char S, unsigned char T) +{ + unsigned char stk1; + unsigned char stk2; + stk1 = S ^ *D; + stk2 = T ^ *D; + stk1 = stk1 & stk2; + stk1 = ~stk1; + *D = stk1; +} + +/* SDxTDxan source opaque/pattern transparent. */ +static void rop3_189_0_1 (unsigned char *D, unsigned char S, unsigned char T) +{ + unsigned char stk1; + unsigned char stk2; + stk1 = S ^ *D; + stk2 = T ^ *D; + stk1 = stk1 & stk2; + stk1 = ~stk1; + *D = (stk1 & S) | (stk1 & (~T)) | (T & (~S) & *D); +} + +/* SDxTDxan source transparent/pattern opaque. */ +static void rop3_189_1_0 (unsigned char *D, unsigned char S, unsigned char T) +{ + unsigned char stk1; + unsigned char stk2; + stk1 = S ^ *D; + stk2 = T ^ *D; + stk1 = stk1 & stk2; + stk1 = ~stk1; + *D = (stk1 & (~S)) | (*D & S); +} + +/* SDxTDxan source/pattern transparent. */ +static void rop3_189_1_1 (unsigned char *D, unsigned char S, unsigned char T) +{ + unsigned char stk1; + unsigned char stk2; + stk1 = S ^ *D; + stk2 = T ^ *D; + stk1 = stk1 & stk2; + stk1 = ~stk1; + *D = (stk1 & (~S) & (~T)) | (*D & S) | (*D & T); +} + +/* SDxTDxan source/pattern opaque. */ +static unsigned xrop3_189_0_0 (unsigned char s, unsigned char t) +{ + unsigned D = 0x00ff; + unsigned S = ((unsigned)s << 8) | s; + unsigned T = ((unsigned)t << 8) | t; + unsigned stk1; + unsigned stk2; + stk1 = S ^ D; + stk2 = T ^ D; + stk1 = stk1 & stk2; + stk1 = ~stk1; + return stk1; +} + +/* SDxTDxan source opaque/pattern transparent. */ +static unsigned xrop3_189_0_1 (unsigned char s, unsigned char t) +{ + unsigned D = 0x00ff; + unsigned S = ((unsigned)s << 8) | s; + unsigned T = ((unsigned)t << 8) | t; + unsigned stk1; + unsigned stk2; + stk1 = S ^ D; + stk2 = T ^ D; + stk1 = stk1 & stk2; + stk1 = ~stk1; + return (stk1 & S) | (stk1 & (~T)) | (T & (~S) & D); +} + +/* SDxTDxan source transparent/pattern opaque. */ +static unsigned xrop3_189_1_0 (unsigned char s, unsigned char t) +{ + unsigned D = 0x00ff; + unsigned S = ((unsigned)s << 8) | s; + unsigned T = ((unsigned)t << 8) | t; + unsigned stk1; + unsigned stk2; + stk1 = S ^ D; + stk2 = T ^ D; + stk1 = stk1 & stk2; + stk1 = ~stk1; + return (stk1 & (~S)) | (D & S); +} + +/* SDxTDxan source/pattern transparent. */ +static unsigned xrop3_189_1_1 (unsigned char s, unsigned char t) +{ + unsigned D = 0x00ff; + unsigned S = ((unsigned)s << 8) | s; + unsigned T = ((unsigned)t << 8) | t; + unsigned stk1; + unsigned stk2; + stk1 = S ^ D; + stk2 = T ^ D; + stk1 = stk1 & stk2; + stk1 = ~stk1; + return (stk1 & (~S) & (~T)) | (D & S) | (D & T); +} + +/* DTSxo source/pattern opaque. */ +static void rop3_190_0_0 (unsigned char *D, unsigned char S, unsigned char T) +{ + unsigned char stk1; + unsigned char stk2; + stk2 = T ^ S; + stk1 = *D | stk2; + *D = stk1; +} + +/* DTSxo source opaque/pattern transparent. */ +static void rop3_190_0_1 (unsigned char *D, unsigned char S, unsigned char T) +{ + unsigned char stk1; + unsigned char stk2; + stk2 = T ^ S; + stk1 = *D | stk2; + *D = (stk1 & S) | (stk1 & (~T)) | (T & (~S) & *D); +} + +/* DTSxo source transparent/pattern opaque. */ +static void rop3_190_1_0 (unsigned char *D, unsigned char S, unsigned char T) +{ + unsigned char stk1; + unsigned char stk2; + stk2 = T ^ S; + stk1 = *D | stk2; + *D = (stk1 & (~S)) | (*D & S); +} + +/* DTSxo source/pattern transparent. */ +static void rop3_190_1_1 (unsigned char *D, unsigned char S, unsigned char T) +{ + unsigned char stk1; + unsigned char stk2; + stk2 = T ^ S; + stk1 = *D | stk2; + *D = (stk1 & (~S) & (~T)) | (*D & S) | (*D & T); +} + +/* DTSxo source/pattern opaque. */ +static unsigned xrop3_190_0_0 (unsigned char s, unsigned char t) +{ + unsigned D = 0x00ff; + unsigned S = ((unsigned)s << 8) | s; + unsigned T = ((unsigned)t << 8) | t; + unsigned stk1; + unsigned stk2; + stk2 = T ^ S; + stk1 = D | stk2; + return stk1; +} + +/* DTSxo source opaque/pattern transparent. */ +static unsigned xrop3_190_0_1 (unsigned char s, unsigned char t) +{ + unsigned D = 0x00ff; + unsigned S = ((unsigned)s << 8) | s; + unsigned T = ((unsigned)t << 8) | t; + unsigned stk1; + unsigned stk2; + stk2 = T ^ S; + stk1 = D | stk2; + return (stk1 & S) | (stk1 & (~T)) | (T & (~S) & D); +} + +/* DTSxo source transparent/pattern opaque. */ +static unsigned xrop3_190_1_0 (unsigned char s, unsigned char t) +{ + unsigned D = 0x00ff; + unsigned S = ((unsigned)s << 8) | s; + unsigned T = ((unsigned)t << 8) | t; + unsigned stk1; + unsigned stk2; + stk2 = T ^ S; + stk1 = D | stk2; + return (stk1 & (~S)) | (D & S); +} + +/* DTSxo source/pattern transparent. */ +static unsigned xrop3_190_1_1 (unsigned char s, unsigned char t) +{ + unsigned D = 0x00ff; + unsigned S = ((unsigned)s << 8) | s; + unsigned T = ((unsigned)t << 8) | t; + unsigned stk1; + unsigned stk2; + stk2 = T ^ S; + stk1 = D | stk2; + return (stk1 & (~S) & (~T)) | (D & S) | (D & T); +} + +/* DTSano source/pattern opaque. */ +static void rop3_191_0_0 (unsigned char *D, unsigned char S, unsigned char T) +{ + unsigned char stk1; + unsigned char stk2; + stk2 = T & S; + stk2 = ~stk2; + stk1 = *D | stk2; + *D = stk1; +} + +/* DTSano source opaque/pattern transparent. */ +static void rop3_191_0_1 (unsigned char *D, unsigned char S, unsigned char T) +{ + unsigned char stk1; + unsigned char stk2; + stk2 = T & S; + stk2 = ~stk2; + stk1 = *D | stk2; + *D = (stk1 & S) | (stk1 & (~T)) | (T & (~S) & *D); +} + +/* DTSano source transparent/pattern opaque. */ +static void rop3_191_1_0 (unsigned char *D, unsigned char S, unsigned char T) +{ + unsigned char stk1; + unsigned char stk2; + stk2 = T & S; + stk2 = ~stk2; + stk1 = *D | stk2; + *D = (stk1 & (~S)) | (*D & S); +} + +/* DTSano source/pattern transparent. */ +static void rop3_191_1_1 (unsigned char *D, unsigned char S, unsigned char T) +{ + unsigned char stk1; + unsigned char stk2; + stk2 = T & S; + stk2 = ~stk2; + stk1 = *D | stk2; + *D = (stk1 & (~S) & (~T)) | (*D & S) | (*D & T); +} + +/* DTSano source/pattern opaque. */ +static unsigned xrop3_191_0_0 (unsigned char s, unsigned char t) +{ + unsigned D = 0x00ff; + unsigned S = ((unsigned)s << 8) | s; + unsigned T = ((unsigned)t << 8) | t; + unsigned stk1; + unsigned stk2; + stk2 = T & S; + stk2 = ~stk2; + stk1 = D | stk2; + return stk1; +} + +/* DTSano source opaque/pattern transparent. */ +static unsigned xrop3_191_0_1 (unsigned char s, unsigned char t) +{ + unsigned D = 0x00ff; + unsigned S = ((unsigned)s << 8) | s; + unsigned T = ((unsigned)t << 8) | t; + unsigned stk1; + unsigned stk2; + stk2 = T & S; + stk2 = ~stk2; + stk1 = D | stk2; + return (stk1 & S) | (stk1 & (~T)) | (T & (~S) & D); +} + +/* DTSano source transparent/pattern opaque. */ +static unsigned xrop3_191_1_0 (unsigned char s, unsigned char t) +{ + unsigned D = 0x00ff; + unsigned S = ((unsigned)s << 8) | s; + unsigned T = ((unsigned)t << 8) | t; + unsigned stk1; + unsigned stk2; + stk2 = T & S; + stk2 = ~stk2; + stk1 = D | stk2; + return (stk1 & (~S)) | (D & S); +} + +/* DTSano source/pattern transparent. */ +static unsigned xrop3_191_1_1 (unsigned char s, unsigned char t) +{ + unsigned D = 0x00ff; + unsigned S = ((unsigned)s << 8) | s; + unsigned T = ((unsigned)t << 8) | t; + unsigned stk1; + unsigned stk2; + stk2 = T & S; + stk2 = ~stk2; + stk1 = D | stk2; + return (stk1 & (~S) & (~T)) | (D & S) | (D & T); +} + +/* TSa source/pattern opaque. */ +static void rop3_192_0_0 (unsigned char *D, unsigned char S, unsigned char T) +{ + unsigned char stk1; + stk1 = T & S; + *D = stk1; +} + +/* TSa source opaque/pattern transparent. */ +static void rop3_192_0_1 (unsigned char *D, unsigned char S, unsigned char T) +{ + unsigned char stk1; + stk1 = T & S; + *D = (stk1 & S) | (stk1 & (~T)) | (T & (~S) & *D); +} + +/* TSa source transparent/pattern opaque. */ +static void rop3_192_1_0 (unsigned char *D, unsigned char S, unsigned char T) +{ + unsigned char stk1; + stk1 = T & S; + *D = (stk1 & (~S)) | (*D & S); +} + +/* TSa source/pattern transparent. */ +static void rop3_192_1_1 (unsigned char *D, unsigned char S, unsigned char T) +{ + unsigned char stk1; + stk1 = T & S; + *D = (stk1 & (~S) & (~T)) | (*D & S) | (*D & T); +} + +/* TSa source/pattern opaque. */ +static unsigned xrop3_192_0_0 (unsigned char s, unsigned char t) +{ + unsigned S = ((unsigned)s << 8) | s; + unsigned T = ((unsigned)t << 8) | t; + unsigned stk1; + stk1 = T & S; + return stk1; +} + +/* TSa source opaque/pattern transparent. */ +static unsigned xrop3_192_0_1 (unsigned char s, unsigned char t) +{ + unsigned D = 0x00ff; + unsigned S = ((unsigned)s << 8) | s; + unsigned T = ((unsigned)t << 8) | t; + unsigned stk1; + stk1 = T & S; + return (stk1 & S) | (stk1 & (~T)) | (T & (~S) & D); +} + +/* TSa source transparent/pattern opaque. */ +static unsigned xrop3_192_1_0 (unsigned char s, unsigned char t) +{ + unsigned D = 0x00ff; + unsigned S = ((unsigned)s << 8) | s; + unsigned T = ((unsigned)t << 8) | t; + unsigned stk1; + stk1 = T & S; + return (stk1 & (~S)) | (D & S); +} + +/* TSa source/pattern transparent. */ +static unsigned xrop3_192_1_1 (unsigned char s, unsigned char t) +{ + unsigned D = 0x00ff; + unsigned S = ((unsigned)s << 8) | s; + unsigned T = ((unsigned)t << 8) | t; + unsigned stk1; + stk1 = T & S; + return (stk1 & (~S) & (~T)) | (D & S) | (D & T); +} + +/* STDSnaoxn source/pattern opaque. */ +static void rop3_193_0_0 (unsigned char *D, unsigned char S, unsigned char T) +{ + unsigned char stk1; + unsigned char stk2; + unsigned char stk3; + unsigned char stk4; + stk4 = ~S; + stk3 = *D & stk4; + stk2 = T | stk3; + stk1 = S ^ stk2; + stk1 = ~stk1; + *D = stk1; +} + +/* STDSnaoxn source opaque/pattern transparent. */ +static void rop3_193_0_1 (unsigned char *D, unsigned char S, unsigned char T) +{ + unsigned char stk1; + unsigned char stk2; + unsigned char stk3; + unsigned char stk4; + stk4 = ~S; + stk3 = *D & stk4; + stk2 = T | stk3; + stk1 = S ^ stk2; + stk1 = ~stk1; + *D = (stk1 & S) | (stk1 & (~T)) | (T & (~S) & *D); +} + +/* STDSnaoxn source transparent/pattern opaque. */ +static void rop3_193_1_0 (unsigned char *D, unsigned char S, unsigned char T) +{ + unsigned char stk1; + unsigned char stk2; + unsigned char stk3; + unsigned char stk4; + stk4 = ~S; + stk3 = *D & stk4; + stk2 = T | stk3; + stk1 = S ^ stk2; + stk1 = ~stk1; + *D = (stk1 & (~S)) | (*D & S); +} + +/* STDSnaoxn source/pattern transparent. */ +static void rop3_193_1_1 (unsigned char *D, unsigned char S, unsigned char T) +{ + unsigned char stk1; + unsigned char stk2; + unsigned char stk3; + unsigned char stk4; + stk4 = ~S; + stk3 = *D & stk4; + stk2 = T | stk3; + stk1 = S ^ stk2; + stk1 = ~stk1; + *D = (stk1 & (~S) & (~T)) | (*D & S) | (*D & T); +} + +/* STDSnaoxn source/pattern opaque. */ +static unsigned xrop3_193_0_0 (unsigned char s, unsigned char t) +{ + unsigned D = 0x00ff; + unsigned S = ((unsigned)s << 8) | s; + unsigned T = ((unsigned)t << 8) | t; + unsigned stk1; + unsigned stk2; + unsigned stk3; + unsigned stk4; + stk4 = ~S; + stk3 = D & stk4; + stk2 = T | stk3; + stk1 = S ^ stk2; + stk1 = ~stk1; + return stk1; +} + +/* STDSnaoxn source opaque/pattern transparent. */ +static unsigned xrop3_193_0_1 (unsigned char s, unsigned char t) +{ + unsigned D = 0x00ff; + unsigned S = ((unsigned)s << 8) | s; + unsigned T = ((unsigned)t << 8) | t; + unsigned stk1; + unsigned stk2; + unsigned stk3; + unsigned stk4; + stk4 = ~S; + stk3 = D & stk4; + stk2 = T | stk3; + stk1 = S ^ stk2; + stk1 = ~stk1; + return (stk1 & S) | (stk1 & (~T)) | (T & (~S) & D); +} + +/* STDSnaoxn source transparent/pattern opaque. */ +static unsigned xrop3_193_1_0 (unsigned char s, unsigned char t) +{ + unsigned D = 0x00ff; + unsigned S = ((unsigned)s << 8) | s; + unsigned T = ((unsigned)t << 8) | t; + unsigned stk1; + unsigned stk2; + unsigned stk3; + unsigned stk4; + stk4 = ~S; + stk3 = D & stk4; + stk2 = T | stk3; + stk1 = S ^ stk2; + stk1 = ~stk1; + return (stk1 & (~S)) | (D & S); +} + +/* STDSnaoxn source/pattern transparent. */ +static unsigned xrop3_193_1_1 (unsigned char s, unsigned char t) +{ + unsigned D = 0x00ff; + unsigned S = ((unsigned)s << 8) | s; + unsigned T = ((unsigned)t << 8) | t; + unsigned stk1; + unsigned stk2; + unsigned stk3; + unsigned stk4; + stk4 = ~S; + stk3 = D & stk4; + stk2 = T | stk3; + stk1 = S ^ stk2; + stk1 = ~stk1; + return (stk1 & (~S) & (~T)) | (D & S) | (D & T); +} + +/* STDSonoxn source/pattern opaque. */ +static void rop3_194_0_0 (unsigned char *D, unsigned char S, unsigned char T) +{ + unsigned char stk1; + unsigned char stk2; + unsigned char stk3; + stk3 = *D | S; + stk3 = ~stk3; + stk2 = T | stk3; + stk1 = S ^ stk2; + stk1 = ~stk1; + *D = stk1; +} + +/* STDSonoxn source opaque/pattern transparent. */ +static void rop3_194_0_1 (unsigned char *D, unsigned char S, unsigned char T) +{ + unsigned char stk1; + unsigned char stk2; + unsigned char stk3; + stk3 = *D | S; + stk3 = ~stk3; + stk2 = T | stk3; + stk1 = S ^ stk2; + stk1 = ~stk1; + *D = (stk1 & S) | (stk1 & (~T)) | (T & (~S) & *D); +} + +/* STDSonoxn source transparent/pattern opaque. */ +static void rop3_194_1_0 (unsigned char *D, unsigned char S, unsigned char T) +{ + unsigned char stk1; + unsigned char stk2; + unsigned char stk3; + stk3 = *D | S; + stk3 = ~stk3; + stk2 = T | stk3; + stk1 = S ^ stk2; + stk1 = ~stk1; + *D = (stk1 & (~S)) | (*D & S); +} + +/* STDSonoxn source/pattern transparent. */ +static void rop3_194_1_1 (unsigned char *D, unsigned char S, unsigned char T) +{ + unsigned char stk1; + unsigned char stk2; + unsigned char stk3; + stk3 = *D | S; + stk3 = ~stk3; + stk2 = T | stk3; + stk1 = S ^ stk2; + stk1 = ~stk1; + *D = (stk1 & (~S) & (~T)) | (*D & S) | (*D & T); +} + +/* STDSonoxn source/pattern opaque. */ +static unsigned xrop3_194_0_0 (unsigned char s, unsigned char t) +{ + unsigned D = 0x00ff; + unsigned S = ((unsigned)s << 8) | s; + unsigned T = ((unsigned)t << 8) | t; + unsigned stk1; + unsigned stk2; + unsigned stk3; + stk3 = D | S; + stk3 = ~stk3; + stk2 = T | stk3; + stk1 = S ^ stk2; + stk1 = ~stk1; + return stk1; +} + +/* STDSonoxn source opaque/pattern transparent. */ +static unsigned xrop3_194_0_1 (unsigned char s, unsigned char t) +{ + unsigned D = 0x00ff; + unsigned S = ((unsigned)s << 8) | s; + unsigned T = ((unsigned)t << 8) | t; + unsigned stk1; + unsigned stk2; + unsigned stk3; + stk3 = D | S; + stk3 = ~stk3; + stk2 = T | stk3; + stk1 = S ^ stk2; + stk1 = ~stk1; + return (stk1 & S) | (stk1 & (~T)) | (T & (~S) & D); +} + +/* STDSonoxn source transparent/pattern opaque. */ +static unsigned xrop3_194_1_0 (unsigned char s, unsigned char t) +{ + unsigned D = 0x00ff; + unsigned S = ((unsigned)s << 8) | s; + unsigned T = ((unsigned)t << 8) | t; + unsigned stk1; + unsigned stk2; + unsigned stk3; + stk3 = D | S; + stk3 = ~stk3; + stk2 = T | stk3; + stk1 = S ^ stk2; + stk1 = ~stk1; + return (stk1 & (~S)) | (D & S); +} + +/* STDSonoxn source/pattern transparent. */ +static unsigned xrop3_194_1_1 (unsigned char s, unsigned char t) +{ + unsigned D = 0x00ff; + unsigned S = ((unsigned)s << 8) | s; + unsigned T = ((unsigned)t << 8) | t; + unsigned stk1; + unsigned stk2; + unsigned stk3; + stk3 = D | S; + stk3 = ~stk3; + stk2 = T | stk3; + stk1 = S ^ stk2; + stk1 = ~stk1; + return (stk1 & (~S) & (~T)) | (D & S) | (D & T); +} + +/* TSxn source/pattern opaque. */ +static void rop3_195_0_0 (unsigned char *D, unsigned char S, unsigned char T) +{ + unsigned char stk1; + stk1 = T ^ S; + stk1 = ~stk1; + *D = stk1; +} + +/* TSxn source opaque/pattern transparent. */ +static void rop3_195_0_1 (unsigned char *D, unsigned char S, unsigned char T) +{ + unsigned char stk1; + stk1 = T ^ S; + stk1 = ~stk1; + *D = (stk1 & S) | (stk1 & (~T)) | (T & (~S) & *D); +} + +/* TSxn source transparent/pattern opaque. */ +static void rop3_195_1_0 (unsigned char *D, unsigned char S, unsigned char T) +{ + unsigned char stk1; + stk1 = T ^ S; + stk1 = ~stk1; + *D = (stk1 & (~S)) | (*D & S); +} + +/* TSxn source/pattern transparent. */ +static void rop3_195_1_1 (unsigned char *D, unsigned char S, unsigned char T) +{ + unsigned char stk1; + stk1 = T ^ S; + stk1 = ~stk1; + *D = (stk1 & (~S) & (~T)) | (*D & S) | (*D & T); +} + +/* TSxn source/pattern opaque. */ +static unsigned xrop3_195_0_0 (unsigned char s, unsigned char t) +{ + unsigned S = ((unsigned)s << 8) | s; + unsigned T = ((unsigned)t << 8) | t; + unsigned stk1; + stk1 = T ^ S; + stk1 = ~stk1; + return stk1; +} + +/* TSxn source opaque/pattern transparent. */ +static unsigned xrop3_195_0_1 (unsigned char s, unsigned char t) +{ + unsigned D = 0x00ff; + unsigned S = ((unsigned)s << 8) | s; + unsigned T = ((unsigned)t << 8) | t; + unsigned stk1; + stk1 = T ^ S; + stk1 = ~stk1; + return (stk1 & S) | (stk1 & (~T)) | (T & (~S) & D); +} + +/* TSxn source transparent/pattern opaque. */ +static unsigned xrop3_195_1_0 (unsigned char s, unsigned char t) +{ + unsigned D = 0x00ff; + unsigned S = ((unsigned)s << 8) | s; + unsigned T = ((unsigned)t << 8) | t; + unsigned stk1; + stk1 = T ^ S; + stk1 = ~stk1; + return (stk1 & (~S)) | (D & S); +} + +/* TSxn source/pattern transparent. */ +static unsigned xrop3_195_1_1 (unsigned char s, unsigned char t) +{ + unsigned D = 0x00ff; + unsigned S = ((unsigned)s << 8) | s; + unsigned T = ((unsigned)t << 8) | t; + unsigned stk1; + stk1 = T ^ S; + stk1 = ~stk1; + return (stk1 & (~S) & (~T)) | (D & S) | (D & T); +} + +/* STDnoa source/pattern opaque. */ +static void rop3_196_0_0 (unsigned char *D, unsigned char S, unsigned char T) +{ + unsigned char stk1; + unsigned char stk2; + unsigned char stk3; + stk3 = ~*D; + stk2 = T | stk3; + stk1 = S & stk2; + *D = stk1; +} + +/* STDnoa source opaque/pattern transparent. */ +static void rop3_196_0_1 (unsigned char *D, unsigned char S, unsigned char T) +{ + unsigned char stk1; + unsigned char stk2; + unsigned char stk3; + stk3 = ~*D; + stk2 = T | stk3; + stk1 = S & stk2; + *D = (stk1 & S) | (stk1 & (~T)) | (T & (~S) & *D); +} + +/* STDnoa source transparent/pattern opaque. */ +static void rop3_196_1_0 (unsigned char *D, unsigned char S, unsigned char T) +{ + unsigned char stk1; + unsigned char stk2; + unsigned char stk3; + stk3 = ~*D; + stk2 = T | stk3; + stk1 = S & stk2; + *D = (stk1 & (~S)) | (*D & S); +} + +/* STDnoa source/pattern transparent. */ +static void rop3_196_1_1 (unsigned char *D, unsigned char S, unsigned char T) +{ + unsigned char stk1; + unsigned char stk2; + unsigned char stk3; + stk3 = ~*D; + stk2 = T | stk3; + stk1 = S & stk2; + *D = (stk1 & (~S) & (~T)) | (*D & S) | (*D & T); +} + +/* STDnoa source/pattern opaque. */ +static unsigned xrop3_196_0_0 (unsigned char s, unsigned char t) +{ + unsigned D = 0x00ff; + unsigned S = ((unsigned)s << 8) | s; + unsigned T = ((unsigned)t << 8) | t; + unsigned stk1; + unsigned stk2; + unsigned stk3; + stk3 = ~D; + stk2 = T | stk3; + stk1 = S & stk2; + return stk1; +} + +/* STDnoa source opaque/pattern transparent. */ +static unsigned xrop3_196_0_1 (unsigned char s, unsigned char t) +{ + unsigned D = 0x00ff; + unsigned S = ((unsigned)s << 8) | s; + unsigned T = ((unsigned)t << 8) | t; + unsigned stk1; + unsigned stk2; + unsigned stk3; + stk3 = ~D; + stk2 = T | stk3; + stk1 = S & stk2; + return (stk1 & S) | (stk1 & (~T)) | (T & (~S) & D); +} + +/* STDnoa source transparent/pattern opaque. */ +static unsigned xrop3_196_1_0 (unsigned char s, unsigned char t) +{ + unsigned D = 0x00ff; + unsigned S = ((unsigned)s << 8) | s; + unsigned T = ((unsigned)t << 8) | t; + unsigned stk1; + unsigned stk2; + unsigned stk3; + stk3 = ~D; + stk2 = T | stk3; + stk1 = S & stk2; + return (stk1 & (~S)) | (D & S); +} + +/* STDnoa source/pattern transparent. */ +static unsigned xrop3_196_1_1 (unsigned char s, unsigned char t) +{ + unsigned D = 0x00ff; + unsigned S = ((unsigned)s << 8) | s; + unsigned T = ((unsigned)t << 8) | t; + unsigned stk1; + unsigned stk2; + unsigned stk3; + stk3 = ~D; + stk2 = T | stk3; + stk1 = S & stk2; + return (stk1 & (~S) & (~T)) | (D & S) | (D & T); +} + +/* STDSxoxn source/pattern opaque. */ +static void rop3_197_0_0 (unsigned char *D, unsigned char S, unsigned char T) +{ + unsigned char stk1; + unsigned char stk2; + unsigned char stk3; + stk3 = *D ^ S; + stk2 = T | stk3; + stk1 = S ^ stk2; + stk1 = ~stk1; + *D = stk1; +} + +/* STDSxoxn source opaque/pattern transparent. */ +static void rop3_197_0_1 (unsigned char *D, unsigned char S, unsigned char T) +{ + unsigned char stk1; + unsigned char stk2; + unsigned char stk3; + stk3 = *D ^ S; + stk2 = T | stk3; + stk1 = S ^ stk2; + stk1 = ~stk1; + *D = (stk1 & S) | (stk1 & (~T)) | (T & (~S) & *D); +} + +/* STDSxoxn source transparent/pattern opaque. */ +static void rop3_197_1_0 (unsigned char *D, unsigned char S, unsigned char T) +{ + unsigned char stk1; + unsigned char stk2; + unsigned char stk3; + stk3 = *D ^ S; + stk2 = T | stk3; + stk1 = S ^ stk2; + stk1 = ~stk1; + *D = (stk1 & (~S)) | (*D & S); +} + +/* STDSxoxn source/pattern transparent. */ +static void rop3_197_1_1 (unsigned char *D, unsigned char S, unsigned char T) +{ + unsigned char stk1; + unsigned char stk2; + unsigned char stk3; + stk3 = *D ^ S; + stk2 = T | stk3; + stk1 = S ^ stk2; + stk1 = ~stk1; + *D = (stk1 & (~S) & (~T)) | (*D & S) | (*D & T); +} + +/* STDSxoxn source/pattern opaque. */ +static unsigned xrop3_197_0_0 (unsigned char s, unsigned char t) +{ + unsigned D = 0x00ff; + unsigned S = ((unsigned)s << 8) | s; + unsigned T = ((unsigned)t << 8) | t; + unsigned stk1; + unsigned stk2; + unsigned stk3; + stk3 = D ^ S; + stk2 = T | stk3; + stk1 = S ^ stk2; + stk1 = ~stk1; + return stk1; +} + +/* STDSxoxn source opaque/pattern transparent. */ +static unsigned xrop3_197_0_1 (unsigned char s, unsigned char t) +{ + unsigned D = 0x00ff; + unsigned S = ((unsigned)s << 8) | s; + unsigned T = ((unsigned)t << 8) | t; + unsigned stk1; + unsigned stk2; + unsigned stk3; + stk3 = D ^ S; + stk2 = T | stk3; + stk1 = S ^ stk2; + stk1 = ~stk1; + return (stk1 & S) | (stk1 & (~T)) | (T & (~S) & D); +} + +/* STDSxoxn source transparent/pattern opaque. */ +static unsigned xrop3_197_1_0 (unsigned char s, unsigned char t) +{ + unsigned D = 0x00ff; + unsigned S = ((unsigned)s << 8) | s; + unsigned T = ((unsigned)t << 8) | t; + unsigned stk1; + unsigned stk2; + unsigned stk3; + stk3 = D ^ S; + stk2 = T | stk3; + stk1 = S ^ stk2; + stk1 = ~stk1; + return (stk1 & (~S)) | (D & S); +} + +/* STDSxoxn source/pattern transparent. */ +static unsigned xrop3_197_1_1 (unsigned char s, unsigned char t) +{ + unsigned D = 0x00ff; + unsigned S = ((unsigned)s << 8) | s; + unsigned T = ((unsigned)t << 8) | t; + unsigned stk1; + unsigned stk2; + unsigned stk3; + stk3 = D ^ S; + stk2 = T | stk3; + stk1 = S ^ stk2; + stk1 = ~stk1; + return (stk1 & (~S) & (~T)) | (D & S) | (D & T); +} + +/* SDTnax source/pattern opaque. */ +static void rop3_198_0_0 (unsigned char *D, unsigned char S, unsigned char T) +{ + unsigned char stk1; + unsigned char stk2; + unsigned char stk3; + stk3 = ~T; + stk2 = *D & stk3; + stk1 = S ^ stk2; + *D = stk1; +} + +/* SDTnax source opaque/pattern transparent. */ +static void rop3_198_0_1 (unsigned char *D, unsigned char S, unsigned char T) +{ + unsigned char stk1; + unsigned char stk2; + unsigned char stk3; + stk3 = ~T; + stk2 = *D & stk3; + stk1 = S ^ stk2; + *D = (stk1 & S) | (stk1 & (~T)) | (T & (~S) & *D); +} + +/* SDTnax source transparent/pattern opaque. */ +static void rop3_198_1_0 (unsigned char *D, unsigned char S, unsigned char T) +{ + unsigned char stk1; + unsigned char stk2; + unsigned char stk3; + stk3 = ~T; + stk2 = *D & stk3; + stk1 = S ^ stk2; + *D = (stk1 & (~S)) | (*D & S); +} + +/* SDTnax source/pattern transparent. */ +static void rop3_198_1_1 (unsigned char *D, unsigned char S, unsigned char T) +{ + unsigned char stk1; + unsigned char stk2; + unsigned char stk3; + stk3 = ~T; + stk2 = *D & stk3; + stk1 = S ^ stk2; + *D = (stk1 & (~S) & (~T)) | (*D & S) | (*D & T); +} + +/* SDTnax source/pattern opaque. */ +static unsigned xrop3_198_0_0 (unsigned char s, unsigned char t) +{ + unsigned D = 0x00ff; + unsigned S = ((unsigned)s << 8) | s; + unsigned T = ((unsigned)t << 8) | t; + unsigned stk1; + unsigned stk2; + unsigned stk3; + stk3 = ~T; + stk2 = D & stk3; + stk1 = S ^ stk2; + return stk1; +} + +/* SDTnax source opaque/pattern transparent. */ +static unsigned xrop3_198_0_1 (unsigned char s, unsigned char t) +{ + unsigned D = 0x00ff; + unsigned S = ((unsigned)s << 8) | s; + unsigned T = ((unsigned)t << 8) | t; + unsigned stk1; + unsigned stk2; + unsigned stk3; + stk3 = ~T; + stk2 = D & stk3; + stk1 = S ^ stk2; + return (stk1 & S) | (stk1 & (~T)) | (T & (~S) & D); +} + +/* SDTnax source transparent/pattern opaque. */ +static unsigned xrop3_198_1_0 (unsigned char s, unsigned char t) +{ + unsigned D = 0x00ff; + unsigned S = ((unsigned)s << 8) | s; + unsigned T = ((unsigned)t << 8) | t; + unsigned stk1; + unsigned stk2; + unsigned stk3; + stk3 = ~T; + stk2 = D & stk3; + stk1 = S ^ stk2; + return (stk1 & (~S)) | (D & S); +} + +/* SDTnax source/pattern transparent. */ +static unsigned xrop3_198_1_1 (unsigned char s, unsigned char t) +{ + unsigned D = 0x00ff; + unsigned S = ((unsigned)s << 8) | s; + unsigned T = ((unsigned)t << 8) | t; + unsigned stk1; + unsigned stk2; + unsigned stk3; + stk3 = ~T; + stk2 = D & stk3; + stk1 = S ^ stk2; + return (stk1 & (~S) & (~T)) | (D & S) | (D & T); +} + +/* TSDToaxn source/pattern opaque. */ +static void rop3_199_0_0 (unsigned char *D, unsigned char S, unsigned char T) +{ + unsigned char stk1; + unsigned char stk2; + unsigned char stk3; + stk3 = *D | T; + stk2 = S & stk3; + stk1 = T ^ stk2; + stk1 = ~stk1; + *D = stk1; +} + +/* TSDToaxn source opaque/pattern transparent. */ +static void rop3_199_0_1 (unsigned char *D, unsigned char S, unsigned char T) +{ + unsigned char stk1; + unsigned char stk2; + unsigned char stk3; + stk3 = *D | T; + stk2 = S & stk3; + stk1 = T ^ stk2; + stk1 = ~stk1; + *D = (stk1 & S) | (stk1 & (~T)) | (T & (~S) & *D); +} + +/* TSDToaxn source transparent/pattern opaque. */ +static void rop3_199_1_0 (unsigned char *D, unsigned char S, unsigned char T) +{ + unsigned char stk1; + unsigned char stk2; + unsigned char stk3; + stk3 = *D | T; + stk2 = S & stk3; + stk1 = T ^ stk2; + stk1 = ~stk1; + *D = (stk1 & (~S)) | (*D & S); +} + +/* TSDToaxn source/pattern transparent. */ +static void rop3_199_1_1 (unsigned char *D, unsigned char S, unsigned char T) +{ + unsigned char stk1; + unsigned char stk2; + unsigned char stk3; + stk3 = *D | T; + stk2 = S & stk3; + stk1 = T ^ stk2; + stk1 = ~stk1; + *D = (stk1 & (~S) & (~T)) | (*D & S) | (*D & T); +} + +/* TSDToaxn source/pattern opaque. */ +static unsigned xrop3_199_0_0 (unsigned char s, unsigned char t) +{ + unsigned D = 0x00ff; + unsigned S = ((unsigned)s << 8) | s; + unsigned T = ((unsigned)t << 8) | t; + unsigned stk1; + unsigned stk2; + unsigned stk3; + stk3 = D | T; + stk2 = S & stk3; + stk1 = T ^ stk2; + stk1 = ~stk1; + return stk1; +} + +/* TSDToaxn source opaque/pattern transparent. */ +static unsigned xrop3_199_0_1 (unsigned char s, unsigned char t) +{ + unsigned D = 0x00ff; + unsigned S = ((unsigned)s << 8) | s; + unsigned T = ((unsigned)t << 8) | t; + unsigned stk1; + unsigned stk2; + unsigned stk3; + stk3 = D | T; + stk2 = S & stk3; + stk1 = T ^ stk2; + stk1 = ~stk1; + return (stk1 & S) | (stk1 & (~T)) | (T & (~S) & D); +} + +/* TSDToaxn source transparent/pattern opaque. */ +static unsigned xrop3_199_1_0 (unsigned char s, unsigned char t) +{ + unsigned D = 0x00ff; + unsigned S = ((unsigned)s << 8) | s; + unsigned T = ((unsigned)t << 8) | t; + unsigned stk1; + unsigned stk2; + unsigned stk3; + stk3 = D | T; + stk2 = S & stk3; + stk1 = T ^ stk2; + stk1 = ~stk1; + return (stk1 & (~S)) | (D & S); +} + +/* TSDToaxn source/pattern transparent. */ +static unsigned xrop3_199_1_1 (unsigned char s, unsigned char t) +{ + unsigned D = 0x00ff; + unsigned S = ((unsigned)s << 8) | s; + unsigned T = ((unsigned)t << 8) | t; + unsigned stk1; + unsigned stk2; + unsigned stk3; + stk3 = D | T; + stk2 = S & stk3; + stk1 = T ^ stk2; + stk1 = ~stk1; + return (stk1 & (~S) & (~T)) | (D & S) | (D & T); +} + +/* SDToa source/pattern opaque. */ +static void rop3_200_0_0 (unsigned char *D, unsigned char S, unsigned char T) +{ + unsigned char stk1; + unsigned char stk2; + stk2 = *D | T; + stk1 = S & stk2; + *D = stk1; +} + +/* SDToa source opaque/pattern transparent. */ +static void rop3_200_0_1 (unsigned char *D, unsigned char S, unsigned char T) +{ + unsigned char stk1; + unsigned char stk2; + stk2 = *D | T; + stk1 = S & stk2; + *D = (stk1 & S) | (stk1 & (~T)) | (T & (~S) & *D); +} + +/* SDToa source transparent/pattern opaque. */ +static void rop3_200_1_0 (unsigned char *D, unsigned char S, unsigned char T) +{ + unsigned char stk1; + unsigned char stk2; + stk2 = *D | T; + stk1 = S & stk2; + *D = (stk1 & (~S)) | (*D & S); +} + +/* SDToa source/pattern transparent. */ +static void rop3_200_1_1 (unsigned char *D, unsigned char S, unsigned char T) +{ + unsigned char stk1; + unsigned char stk2; + stk2 = *D | T; + stk1 = S & stk2; + *D = (stk1 & (~S) & (~T)) | (*D & S) | (*D & T); +} + +/* SDToa source/pattern opaque. */ +static unsigned xrop3_200_0_0 (unsigned char s, unsigned char t) +{ + unsigned D = 0x00ff; + unsigned S = ((unsigned)s << 8) | s; + unsigned T = ((unsigned)t << 8) | t; + unsigned stk1; + unsigned stk2; + stk2 = D | T; + stk1 = S & stk2; + return stk1; +} + +/* SDToa source opaque/pattern transparent. */ +static unsigned xrop3_200_0_1 (unsigned char s, unsigned char t) +{ + unsigned D = 0x00ff; + unsigned S = ((unsigned)s << 8) | s; + unsigned T = ((unsigned)t << 8) | t; + unsigned stk1; + unsigned stk2; + stk2 = D | T; + stk1 = S & stk2; + return (stk1 & S) | (stk1 & (~T)) | (T & (~S) & D); +} + +/* SDToa source transparent/pattern opaque. */ +static unsigned xrop3_200_1_0 (unsigned char s, unsigned char t) +{ + unsigned D = 0x00ff; + unsigned S = ((unsigned)s << 8) | s; + unsigned T = ((unsigned)t << 8) | t; + unsigned stk1; + unsigned stk2; + stk2 = D | T; + stk1 = S & stk2; + return (stk1 & (~S)) | (D & S); +} + +/* SDToa source/pattern transparent. */ +static unsigned xrop3_200_1_1 (unsigned char s, unsigned char t) +{ + unsigned D = 0x00ff; + unsigned S = ((unsigned)s << 8) | s; + unsigned T = ((unsigned)t << 8) | t; + unsigned stk1; + unsigned stk2; + stk2 = D | T; + stk1 = S & stk2; + return (stk1 & (~S) & (~T)) | (D & S) | (D & T); +} + +/* STDoxn source/pattern opaque. */ +static void rop3_201_0_0 (unsigned char *D, unsigned char S, unsigned char T) +{ + unsigned char stk1; + unsigned char stk2; + stk2 = T | *D; + stk1 = S ^ stk2; + stk1 = ~stk1; + *D = stk1; +} + +/* STDoxn source opaque/pattern transparent. */ +static void rop3_201_0_1 (unsigned char *D, unsigned char S, unsigned char T) +{ + unsigned char stk1; + unsigned char stk2; + stk2 = T | *D; + stk1 = S ^ stk2; + stk1 = ~stk1; + *D = (stk1 & S) | (stk1 & (~T)) | (T & (~S) & *D); +} + +/* STDoxn source transparent/pattern opaque. */ +static void rop3_201_1_0 (unsigned char *D, unsigned char S, unsigned char T) +{ + unsigned char stk1; + unsigned char stk2; + stk2 = T | *D; + stk1 = S ^ stk2; + stk1 = ~stk1; + *D = (stk1 & (~S)) | (*D & S); +} + +/* STDoxn source/pattern transparent. */ +static void rop3_201_1_1 (unsigned char *D, unsigned char S, unsigned char T) +{ + unsigned char stk1; + unsigned char stk2; + stk2 = T | *D; + stk1 = S ^ stk2; + stk1 = ~stk1; + *D = (stk1 & (~S) & (~T)) | (*D & S) | (*D & T); +} + +/* STDoxn source/pattern opaque. */ +static unsigned xrop3_201_0_0 (unsigned char s, unsigned char t) +{ + unsigned D = 0x00ff; + unsigned S = ((unsigned)s << 8) | s; + unsigned T = ((unsigned)t << 8) | t; + unsigned stk1; + unsigned stk2; + stk2 = T | D; + stk1 = S ^ stk2; + stk1 = ~stk1; + return stk1; +} + +/* STDoxn source opaque/pattern transparent. */ +static unsigned xrop3_201_0_1 (unsigned char s, unsigned char t) +{ + unsigned D = 0x00ff; + unsigned S = ((unsigned)s << 8) | s; + unsigned T = ((unsigned)t << 8) | t; + unsigned stk1; + unsigned stk2; + stk2 = T | D; + stk1 = S ^ stk2; + stk1 = ~stk1; + return (stk1 & S) | (stk1 & (~T)) | (T & (~S) & D); +} + +/* STDoxn source transparent/pattern opaque. */ +static unsigned xrop3_201_1_0 (unsigned char s, unsigned char t) +{ + unsigned D = 0x00ff; + unsigned S = ((unsigned)s << 8) | s; + unsigned T = ((unsigned)t << 8) | t; + unsigned stk1; + unsigned stk2; + stk2 = T | D; + stk1 = S ^ stk2; + stk1 = ~stk1; + return (stk1 & (~S)) | (D & S); +} + +/* STDoxn source/pattern transparent. */ +static unsigned xrop3_201_1_1 (unsigned char s, unsigned char t) +{ + unsigned D = 0x00ff; + unsigned S = ((unsigned)s << 8) | s; + unsigned T = ((unsigned)t << 8) | t; + unsigned stk1; + unsigned stk2; + stk2 = T | D; + stk1 = S ^ stk2; + stk1 = ~stk1; + return (stk1 & (~S) & (~T)) | (D & S) | (D & T); +} + +/* DTSDxax source/pattern opaque. */ +static void rop3_202_0_0 (unsigned char *D, unsigned char S, unsigned char T) +{ + unsigned char stk1; + unsigned char stk2; + unsigned char stk3; + stk3 = S ^ *D; + stk2 = T & stk3; + stk1 = *D ^ stk2; + *D = stk1; +} + +/* DTSDxax source opaque/pattern transparent. */ +static void rop3_202_0_1 (unsigned char *D, unsigned char S, unsigned char T) +{ + unsigned char stk1; + unsigned char stk2; + unsigned char stk3; + stk3 = S ^ *D; + stk2 = T & stk3; + stk1 = *D ^ stk2; + *D = (stk1 & S) | (stk1 & (~T)) | (T & (~S) & *D); +} + +/* DTSDxax source transparent/pattern opaque. */ +static void rop3_202_1_0 (unsigned char *D, unsigned char S, unsigned char T) +{ + unsigned char stk1; + unsigned char stk2; + unsigned char stk3; + stk3 = S ^ *D; + stk2 = T & stk3; + stk1 = *D ^ stk2; + *D = (stk1 & (~S)) | (*D & S); +} + +/* DTSDxax source/pattern transparent. */ +static void rop3_202_1_1 (unsigned char *D, unsigned char S, unsigned char T) +{ + unsigned char stk1; + unsigned char stk2; + unsigned char stk3; + stk3 = S ^ *D; + stk2 = T & stk3; + stk1 = *D ^ stk2; + *D = (stk1 & (~S) & (~T)) | (*D & S) | (*D & T); +} + +/* DTSDxax source/pattern opaque. */ +static unsigned xrop3_202_0_0 (unsigned char s, unsigned char t) +{ + unsigned D = 0x00ff; + unsigned S = ((unsigned)s << 8) | s; + unsigned T = ((unsigned)t << 8) | t; + unsigned stk1; + unsigned stk2; + unsigned stk3; + stk3 = S ^ D; + stk2 = T & stk3; + stk1 = D ^ stk2; + return stk1; +} + +/* DTSDxax source opaque/pattern transparent. */ +static unsigned xrop3_202_0_1 (unsigned char s, unsigned char t) +{ + unsigned D = 0x00ff; + unsigned S = ((unsigned)s << 8) | s; + unsigned T = ((unsigned)t << 8) | t; + unsigned stk1; + unsigned stk2; + unsigned stk3; + stk3 = S ^ D; + stk2 = T & stk3; + stk1 = D ^ stk2; + return (stk1 & S) | (stk1 & (~T)) | (T & (~S) & D); +} + +/* DTSDxax source transparent/pattern opaque. */ +static unsigned xrop3_202_1_0 (unsigned char s, unsigned char t) +{ + unsigned D = 0x00ff; + unsigned S = ((unsigned)s << 8) | s; + unsigned T = ((unsigned)t << 8) | t; + unsigned stk1; + unsigned stk2; + unsigned stk3; + stk3 = S ^ D; + stk2 = T & stk3; + stk1 = D ^ stk2; + return (stk1 & (~S)) | (D & S); +} + +/* DTSDxax source/pattern transparent. */ +static unsigned xrop3_202_1_1 (unsigned char s, unsigned char t) +{ + unsigned D = 0x00ff; + unsigned S = ((unsigned)s << 8) | s; + unsigned T = ((unsigned)t << 8) | t; + unsigned stk1; + unsigned stk2; + unsigned stk3; + stk3 = S ^ D; + stk2 = T & stk3; + stk1 = D ^ stk2; + return (stk1 & (~S) & (~T)) | (D & S) | (D & T); +} + +/* STDSaoxn source/pattern opaque. */ +static void rop3_203_0_0 (unsigned char *D, unsigned char S, unsigned char T) +{ + unsigned char stk1; + unsigned char stk2; + unsigned char stk3; + stk3 = *D & S; + stk2 = T | stk3; + stk1 = S ^ stk2; + stk1 = ~stk1; + *D = stk1; +} + +/* STDSaoxn source opaque/pattern transparent. */ +static void rop3_203_0_1 (unsigned char *D, unsigned char S, unsigned char T) +{ + unsigned char stk1; + unsigned char stk2; + unsigned char stk3; + stk3 = *D & S; + stk2 = T | stk3; + stk1 = S ^ stk2; + stk1 = ~stk1; + *D = (stk1 & S) | (stk1 & (~T)) | (T & (~S) & *D); +} + +/* STDSaoxn source transparent/pattern opaque. */ +static void rop3_203_1_0 (unsigned char *D, unsigned char S, unsigned char T) +{ + unsigned char stk1; + unsigned char stk2; + unsigned char stk3; + stk3 = *D & S; + stk2 = T | stk3; + stk1 = S ^ stk2; + stk1 = ~stk1; + *D = (stk1 & (~S)) | (*D & S); +} + +/* STDSaoxn source/pattern transparent. */ +static void rop3_203_1_1 (unsigned char *D, unsigned char S, unsigned char T) +{ + unsigned char stk1; + unsigned char stk2; + unsigned char stk3; + stk3 = *D & S; + stk2 = T | stk3; + stk1 = S ^ stk2; + stk1 = ~stk1; + *D = (stk1 & (~S) & (~T)) | (*D & S) | (*D & T); +} + +/* STDSaoxn source/pattern opaque. */ +static unsigned xrop3_203_0_0 (unsigned char s, unsigned char t) +{ + unsigned D = 0x00ff; + unsigned S = ((unsigned)s << 8) | s; + unsigned T = ((unsigned)t << 8) | t; + unsigned stk1; + unsigned stk2; + unsigned stk3; + stk3 = D & S; + stk2 = T | stk3; + stk1 = S ^ stk2; + stk1 = ~stk1; + return stk1; +} + +/* STDSaoxn source opaque/pattern transparent. */ +static unsigned xrop3_203_0_1 (unsigned char s, unsigned char t) +{ + unsigned D = 0x00ff; + unsigned S = ((unsigned)s << 8) | s; + unsigned T = ((unsigned)t << 8) | t; + unsigned stk1; + unsigned stk2; + unsigned stk3; + stk3 = D & S; + stk2 = T | stk3; + stk1 = S ^ stk2; + stk1 = ~stk1; + return (stk1 & S) | (stk1 & (~T)) | (T & (~S) & D); +} + +/* STDSaoxn source transparent/pattern opaque. */ +static unsigned xrop3_203_1_0 (unsigned char s, unsigned char t) +{ + unsigned D = 0x00ff; + unsigned S = ((unsigned)s << 8) | s; + unsigned T = ((unsigned)t << 8) | t; + unsigned stk1; + unsigned stk2; + unsigned stk3; + stk3 = D & S; + stk2 = T | stk3; + stk1 = S ^ stk2; + stk1 = ~stk1; + return (stk1 & (~S)) | (D & S); +} + +/* STDSaoxn source/pattern transparent. */ +static unsigned xrop3_203_1_1 (unsigned char s, unsigned char t) +{ + unsigned D = 0x00ff; + unsigned S = ((unsigned)s << 8) | s; + unsigned T = ((unsigned)t << 8) | t; + unsigned stk1; + unsigned stk2; + unsigned stk3; + stk3 = D & S; + stk2 = T | stk3; + stk1 = S ^ stk2; + stk1 = ~stk1; + return (stk1 & (~S) & (~T)) | (D & S) | (D & T); +} + +/* S source/pattern opaque. */ +static void rop3_204_0_0 (unsigned char *D, unsigned char S, unsigned char T) +{ + *D = S; +} + +/* S source opaque/pattern transparent. */ +static void rop3_204_0_1 (unsigned char *D, unsigned char S, unsigned char T) +{ + *D = (S & S) | (S & (~T)) | (T & (~S) & *D); +} + +/* S source transparent/pattern opaque. */ +static void rop3_204_1_0 (unsigned char *D, unsigned char S, unsigned char T) +{ + *D = (S & (~S)) | (*D & S); +} + +/* S source/pattern transparent. */ +static void rop3_204_1_1 (unsigned char *D, unsigned char S, unsigned char T) +{ + *D = (S & (~S) & (~T)) | (*D & S) | (*D & T); +} + +/* S source/pattern opaque. */ +static unsigned xrop3_204_0_0 (unsigned char s, unsigned char t) +{ + unsigned S = ((unsigned)s << 8) | s; + return S; +} + +/* S source opaque/pattern transparent. */ +static unsigned xrop3_204_0_1 (unsigned char s, unsigned char t) +{ + unsigned D = 0x00ff; + unsigned S = ((unsigned)s << 8) | s; + unsigned T = ((unsigned)t << 8) | t; + return (S & S) | (S & (~T)) | (T & (~S) & D); +} + +/* S source transparent/pattern opaque. */ +static unsigned xrop3_204_1_0 (unsigned char s, unsigned char t) +{ + unsigned D = 0x00ff; + unsigned S = ((unsigned)s << 8) | s; + return (S & (~S)) | (D & S); +} + +/* S source/pattern transparent. */ +static unsigned xrop3_204_1_1 (unsigned char s, unsigned char t) +{ + unsigned D = 0x00ff; + unsigned S = ((unsigned)s << 8) | s; + unsigned T = ((unsigned)t << 8) | t; + return (S & (~S) & (~T)) | (D & S) | (D & T); +} + +/* SDTono source/pattern opaque. */ +static void rop3_205_0_0 (unsigned char *D, unsigned char S, unsigned char T) +{ + unsigned char stk1; + unsigned char stk2; + stk2 = *D | T; + stk2 = ~stk2; + stk1 = S | stk2; + *D = stk1; +} + +/* SDTono source opaque/pattern transparent. */ +static void rop3_205_0_1 (unsigned char *D, unsigned char S, unsigned char T) +{ + unsigned char stk1; + unsigned char stk2; + stk2 = *D | T; + stk2 = ~stk2; + stk1 = S | stk2; + *D = (stk1 & S) | (stk1 & (~T)) | (T & (~S) & *D); +} + +/* SDTono source transparent/pattern opaque. */ +static void rop3_205_1_0 (unsigned char *D, unsigned char S, unsigned char T) +{ + unsigned char stk1; + unsigned char stk2; + stk2 = *D | T; + stk2 = ~stk2; + stk1 = S | stk2; + *D = (stk1 & (~S)) | (*D & S); +} + +/* SDTono source/pattern transparent. */ +static void rop3_205_1_1 (unsigned char *D, unsigned char S, unsigned char T) +{ + unsigned char stk1; + unsigned char stk2; + stk2 = *D | T; + stk2 = ~stk2; + stk1 = S | stk2; + *D = (stk1 & (~S) & (~T)) | (*D & S) | (*D & T); +} + +/* SDTono source/pattern opaque. */ +static unsigned xrop3_205_0_0 (unsigned char s, unsigned char t) +{ + unsigned D = 0x00ff; + unsigned S = ((unsigned)s << 8) | s; + unsigned T = ((unsigned)t << 8) | t; + unsigned stk1; + unsigned stk2; + stk2 = D | T; + stk2 = ~stk2; + stk1 = S | stk2; + return stk1; +} + +/* SDTono source opaque/pattern transparent. */ +static unsigned xrop3_205_0_1 (unsigned char s, unsigned char t) +{ + unsigned D = 0x00ff; + unsigned S = ((unsigned)s << 8) | s; + unsigned T = ((unsigned)t << 8) | t; + unsigned stk1; + unsigned stk2; + stk2 = D | T; + stk2 = ~stk2; + stk1 = S | stk2; + return (stk1 & S) | (stk1 & (~T)) | (T & (~S) & D); +} + +/* SDTono source transparent/pattern opaque. */ +static unsigned xrop3_205_1_0 (unsigned char s, unsigned char t) +{ + unsigned D = 0x00ff; + unsigned S = ((unsigned)s << 8) | s; + unsigned T = ((unsigned)t << 8) | t; + unsigned stk1; + unsigned stk2; + stk2 = D | T; + stk2 = ~stk2; + stk1 = S | stk2; + return (stk1 & (~S)) | (D & S); +} + +/* SDTono source/pattern transparent. */ +static unsigned xrop3_205_1_1 (unsigned char s, unsigned char t) +{ + unsigned D = 0x00ff; + unsigned S = ((unsigned)s << 8) | s; + unsigned T = ((unsigned)t << 8) | t; + unsigned stk1; + unsigned stk2; + stk2 = D | T; + stk2 = ~stk2; + stk1 = S | stk2; + return (stk1 & (~S) & (~T)) | (D & S) | (D & T); +} + +/* SDTnao source/pattern opaque. */ +static void rop3_206_0_0 (unsigned char *D, unsigned char S, unsigned char T) +{ + unsigned char stk1; + unsigned char stk2; + unsigned char stk3; + stk3 = ~T; + stk2 = *D & stk3; + stk1 = S | stk2; + *D = stk1; +} + +/* SDTnao source opaque/pattern transparent. */ +static void rop3_206_0_1 (unsigned char *D, unsigned char S, unsigned char T) +{ + unsigned char stk1; + unsigned char stk2; + unsigned char stk3; + stk3 = ~T; + stk2 = *D & stk3; + stk1 = S | stk2; + *D = (stk1 & S) | (stk1 & (~T)) | (T & (~S) & *D); +} + +/* SDTnao source transparent/pattern opaque. */ +static void rop3_206_1_0 (unsigned char *D, unsigned char S, unsigned char T) +{ + unsigned char stk1; + unsigned char stk2; + unsigned char stk3; + stk3 = ~T; + stk2 = *D & stk3; + stk1 = S | stk2; + *D = (stk1 & (~S)) | (*D & S); +} + +/* SDTnao source/pattern transparent. */ +static void rop3_206_1_1 (unsigned char *D, unsigned char S, unsigned char T) +{ + unsigned char stk1; + unsigned char stk2; + unsigned char stk3; + stk3 = ~T; + stk2 = *D & stk3; + stk1 = S | stk2; + *D = (stk1 & (~S) & (~T)) | (*D & S) | (*D & T); +} + +/* SDTnao source/pattern opaque. */ +static unsigned xrop3_206_0_0 (unsigned char s, unsigned char t) +{ + unsigned D = 0x00ff; + unsigned S = ((unsigned)s << 8) | s; + unsigned T = ((unsigned)t << 8) | t; + unsigned stk1; + unsigned stk2; + unsigned stk3; + stk3 = ~T; + stk2 = D & stk3; + stk1 = S | stk2; + return stk1; +} + +/* SDTnao source opaque/pattern transparent. */ +static unsigned xrop3_206_0_1 (unsigned char s, unsigned char t) +{ + unsigned D = 0x00ff; + unsigned S = ((unsigned)s << 8) | s; + unsigned T = ((unsigned)t << 8) | t; + unsigned stk1; + unsigned stk2; + unsigned stk3; + stk3 = ~T; + stk2 = D & stk3; + stk1 = S | stk2; + return (stk1 & S) | (stk1 & (~T)) | (T & (~S) & D); +} + +/* SDTnao source transparent/pattern opaque. */ +static unsigned xrop3_206_1_0 (unsigned char s, unsigned char t) +{ + unsigned D = 0x00ff; + unsigned S = ((unsigned)s << 8) | s; + unsigned T = ((unsigned)t << 8) | t; + unsigned stk1; + unsigned stk2; + unsigned stk3; + stk3 = ~T; + stk2 = D & stk3; + stk1 = S | stk2; + return (stk1 & (~S)) | (D & S); +} + +/* SDTnao source/pattern transparent. */ +static unsigned xrop3_206_1_1 (unsigned char s, unsigned char t) +{ + unsigned D = 0x00ff; + unsigned S = ((unsigned)s << 8) | s; + unsigned T = ((unsigned)t << 8) | t; + unsigned stk1; + unsigned stk2; + unsigned stk3; + stk3 = ~T; + stk2 = D & stk3; + stk1 = S | stk2; + return (stk1 & (~S) & (~T)) | (D & S) | (D & T); +} + +/* STno source/pattern opaque. */ +static void rop3_207_0_0 (unsigned char *D, unsigned char S, unsigned char T) +{ + unsigned char stk1; + unsigned char stk2; + stk2 = ~T; + stk1 = S | stk2; + *D = stk1; +} + +/* STno source opaque/pattern transparent. */ +static void rop3_207_0_1 (unsigned char *D, unsigned char S, unsigned char T) +{ + unsigned char stk1; + unsigned char stk2; + stk2 = ~T; + stk1 = S | stk2; + *D = (stk1 & S) | (stk1 & (~T)) | (T & (~S) & *D); +} + +/* STno source transparent/pattern opaque. */ +static void rop3_207_1_0 (unsigned char *D, unsigned char S, unsigned char T) +{ + unsigned char stk1; + unsigned char stk2; + stk2 = ~T; + stk1 = S | stk2; + *D = (stk1 & (~S)) | (*D & S); +} + +/* STno source/pattern transparent. */ +static void rop3_207_1_1 (unsigned char *D, unsigned char S, unsigned char T) +{ + unsigned char stk1; + unsigned char stk2; + stk2 = ~T; + stk1 = S | stk2; + *D = (stk1 & (~S) & (~T)) | (*D & S) | (*D & T); +} + +/* STno source/pattern opaque. */ +static unsigned xrop3_207_0_0 (unsigned char s, unsigned char t) +{ + unsigned S = ((unsigned)s << 8) | s; + unsigned T = ((unsigned)t << 8) | t; + unsigned stk1; + unsigned stk2; + stk2 = ~T; + stk1 = S | stk2; + return stk1; +} + +/* STno source opaque/pattern transparent. */ +static unsigned xrop3_207_0_1 (unsigned char s, unsigned char t) +{ + unsigned D = 0x00ff; + unsigned S = ((unsigned)s << 8) | s; + unsigned T = ((unsigned)t << 8) | t; + unsigned stk1; + unsigned stk2; + stk2 = ~T; + stk1 = S | stk2; + return (stk1 & S) | (stk1 & (~T)) | (T & (~S) & D); +} + +/* STno source transparent/pattern opaque. */ +static unsigned xrop3_207_1_0 (unsigned char s, unsigned char t) +{ + unsigned D = 0x00ff; + unsigned S = ((unsigned)s << 8) | s; + unsigned T = ((unsigned)t << 8) | t; + unsigned stk1; + unsigned stk2; + stk2 = ~T; + stk1 = S | stk2; + return (stk1 & (~S)) | (D & S); +} + +/* STno source/pattern transparent. */ +static unsigned xrop3_207_1_1 (unsigned char s, unsigned char t) +{ + unsigned D = 0x00ff; + unsigned S = ((unsigned)s << 8) | s; + unsigned T = ((unsigned)t << 8) | t; + unsigned stk1; + unsigned stk2; + stk2 = ~T; + stk1 = S | stk2; + return (stk1 & (~S) & (~T)) | (D & S) | (D & T); +} + +/* TSDnoa source/pattern opaque. */ +static void rop3_208_0_0 (unsigned char *D, unsigned char S, unsigned char T) +{ + unsigned char stk1; + unsigned char stk2; + unsigned char stk3; + stk3 = ~*D; + stk2 = S | stk3; + stk1 = T & stk2; + *D = stk1; +} + +/* TSDnoa source opaque/pattern transparent. */ +static void rop3_208_0_1 (unsigned char *D, unsigned char S, unsigned char T) +{ + unsigned char stk1; + unsigned char stk2; + unsigned char stk3; + stk3 = ~*D; + stk2 = S | stk3; + stk1 = T & stk2; + *D = (stk1 & S) | (stk1 & (~T)) | (T & (~S) & *D); +} + +/* TSDnoa source transparent/pattern opaque. */ +static void rop3_208_1_0 (unsigned char *D, unsigned char S, unsigned char T) +{ + unsigned char stk1; + unsigned char stk2; + unsigned char stk3; + stk3 = ~*D; + stk2 = S | stk3; + stk1 = T & stk2; + *D = (stk1 & (~S)) | (*D & S); +} + +/* TSDnoa source/pattern transparent. */ +static void rop3_208_1_1 (unsigned char *D, unsigned char S, unsigned char T) +{ + unsigned char stk1; + unsigned char stk2; + unsigned char stk3; + stk3 = ~*D; + stk2 = S | stk3; + stk1 = T & stk2; + *D = (stk1 & (~S) & (~T)) | (*D & S) | (*D & T); +} + +/* TSDnoa source/pattern opaque. */ +static unsigned xrop3_208_0_0 (unsigned char s, unsigned char t) +{ + unsigned D = 0x00ff; + unsigned S = ((unsigned)s << 8) | s; + unsigned T = ((unsigned)t << 8) | t; + unsigned stk1; + unsigned stk2; + unsigned stk3; + stk3 = ~D; + stk2 = S | stk3; + stk1 = T & stk2; + return stk1; +} + +/* TSDnoa source opaque/pattern transparent. */ +static unsigned xrop3_208_0_1 (unsigned char s, unsigned char t) +{ + unsigned D = 0x00ff; + unsigned S = ((unsigned)s << 8) | s; + unsigned T = ((unsigned)t << 8) | t; + unsigned stk1; + unsigned stk2; + unsigned stk3; + stk3 = ~D; + stk2 = S | stk3; + stk1 = T & stk2; + return (stk1 & S) | (stk1 & (~T)) | (T & (~S) & D); +} + +/* TSDnoa source transparent/pattern opaque. */ +static unsigned xrop3_208_1_0 (unsigned char s, unsigned char t) +{ + unsigned D = 0x00ff; + unsigned S = ((unsigned)s << 8) | s; + unsigned T = ((unsigned)t << 8) | t; + unsigned stk1; + unsigned stk2; + unsigned stk3; + stk3 = ~D; + stk2 = S | stk3; + stk1 = T & stk2; + return (stk1 & (~S)) | (D & S); +} + +/* TSDnoa source/pattern transparent. */ +static unsigned xrop3_208_1_1 (unsigned char s, unsigned char t) +{ + unsigned D = 0x00ff; + unsigned S = ((unsigned)s << 8) | s; + unsigned T = ((unsigned)t << 8) | t; + unsigned stk1; + unsigned stk2; + unsigned stk3; + stk3 = ~D; + stk2 = S | stk3; + stk1 = T & stk2; + return (stk1 & (~S) & (~T)) | (D & S) | (D & T); +} + +/* TSDTxoxn source/pattern opaque. */ +static void rop3_209_0_0 (unsigned char *D, unsigned char S, unsigned char T) +{ + unsigned char stk1; + unsigned char stk2; + unsigned char stk3; + stk3 = *D ^ T; + stk2 = S | stk3; + stk1 = T ^ stk2; + stk1 = ~stk1; + *D = stk1; +} + +/* TSDTxoxn source opaque/pattern transparent. */ +static void rop3_209_0_1 (unsigned char *D, unsigned char S, unsigned char T) +{ + unsigned char stk1; + unsigned char stk2; + unsigned char stk3; + stk3 = *D ^ T; + stk2 = S | stk3; + stk1 = T ^ stk2; + stk1 = ~stk1; + *D = (stk1 & S) | (stk1 & (~T)) | (T & (~S) & *D); +} + +/* TSDTxoxn source transparent/pattern opaque. */ +static void rop3_209_1_0 (unsigned char *D, unsigned char S, unsigned char T) +{ + unsigned char stk1; + unsigned char stk2; + unsigned char stk3; + stk3 = *D ^ T; + stk2 = S | stk3; + stk1 = T ^ stk2; + stk1 = ~stk1; + *D = (stk1 & (~S)) | (*D & S); +} + +/* TSDTxoxn source/pattern transparent. */ +static void rop3_209_1_1 (unsigned char *D, unsigned char S, unsigned char T) +{ + unsigned char stk1; + unsigned char stk2; + unsigned char stk3; + stk3 = *D ^ T; + stk2 = S | stk3; + stk1 = T ^ stk2; + stk1 = ~stk1; + *D = (stk1 & (~S) & (~T)) | (*D & S) | (*D & T); +} + +/* TSDTxoxn source/pattern opaque. */ +static unsigned xrop3_209_0_0 (unsigned char s, unsigned char t) +{ + unsigned D = 0x00ff; + unsigned S = ((unsigned)s << 8) | s; + unsigned T = ((unsigned)t << 8) | t; + unsigned stk1; + unsigned stk2; + unsigned stk3; + stk3 = D ^ T; + stk2 = S | stk3; + stk1 = T ^ stk2; + stk1 = ~stk1; + return stk1; +} + +/* TSDTxoxn source opaque/pattern transparent. */ +static unsigned xrop3_209_0_1 (unsigned char s, unsigned char t) +{ + unsigned D = 0x00ff; + unsigned S = ((unsigned)s << 8) | s; + unsigned T = ((unsigned)t << 8) | t; + unsigned stk1; + unsigned stk2; + unsigned stk3; + stk3 = D ^ T; + stk2 = S | stk3; + stk1 = T ^ stk2; + stk1 = ~stk1; + return (stk1 & S) | (stk1 & (~T)) | (T & (~S) & D); +} + +/* TSDTxoxn source transparent/pattern opaque. */ +static unsigned xrop3_209_1_0 (unsigned char s, unsigned char t) +{ + unsigned D = 0x00ff; + unsigned S = ((unsigned)s << 8) | s; + unsigned T = ((unsigned)t << 8) | t; + unsigned stk1; + unsigned stk2; + unsigned stk3; + stk3 = D ^ T; + stk2 = S | stk3; + stk1 = T ^ stk2; + stk1 = ~stk1; + return (stk1 & (~S)) | (D & S); +} + +/* TSDTxoxn source/pattern transparent. */ +static unsigned xrop3_209_1_1 (unsigned char s, unsigned char t) +{ + unsigned D = 0x00ff; + unsigned S = ((unsigned)s << 8) | s; + unsigned T = ((unsigned)t << 8) | t; + unsigned stk1; + unsigned stk2; + unsigned stk3; + stk3 = D ^ T; + stk2 = S | stk3; + stk1 = T ^ stk2; + stk1 = ~stk1; + return (stk1 & (~S) & (~T)) | (D & S) | (D & T); +} + +/* TDSnax source/pattern opaque. */ +static void rop3_210_0_0 (unsigned char *D, unsigned char S, unsigned char T) +{ + unsigned char stk1; + unsigned char stk2; + unsigned char stk3; + stk3 = ~S; + stk2 = *D & stk3; + stk1 = T ^ stk2; + *D = stk1; +} + +/* TDSnax source opaque/pattern transparent. */ +static void rop3_210_0_1 (unsigned char *D, unsigned char S, unsigned char T) +{ + unsigned char stk1; + unsigned char stk2; + unsigned char stk3; + stk3 = ~S; + stk2 = *D & stk3; + stk1 = T ^ stk2; + *D = (stk1 & S) | (stk1 & (~T)) | (T & (~S) & *D); +} + +/* TDSnax source transparent/pattern opaque. */ +static void rop3_210_1_0 (unsigned char *D, unsigned char S, unsigned char T) +{ + unsigned char stk1; + unsigned char stk2; + unsigned char stk3; + stk3 = ~S; + stk2 = *D & stk3; + stk1 = T ^ stk2; + *D = (stk1 & (~S)) | (*D & S); +} + +/* TDSnax source/pattern transparent. */ +static void rop3_210_1_1 (unsigned char *D, unsigned char S, unsigned char T) +{ + unsigned char stk1; + unsigned char stk2; + unsigned char stk3; + stk3 = ~S; + stk2 = *D & stk3; + stk1 = T ^ stk2; + *D = (stk1 & (~S) & (~T)) | (*D & S) | (*D & T); +} + +/* TDSnax source/pattern opaque. */ +static unsigned xrop3_210_0_0 (unsigned char s, unsigned char t) +{ + unsigned D = 0x00ff; + unsigned S = ((unsigned)s << 8) | s; + unsigned T = ((unsigned)t << 8) | t; + unsigned stk1; + unsigned stk2; + unsigned stk3; + stk3 = ~S; + stk2 = D & stk3; + stk1 = T ^ stk2; + return stk1; +} + +/* TDSnax source opaque/pattern transparent. */ +static unsigned xrop3_210_0_1 (unsigned char s, unsigned char t) +{ + unsigned D = 0x00ff; + unsigned S = ((unsigned)s << 8) | s; + unsigned T = ((unsigned)t << 8) | t; + unsigned stk1; + unsigned stk2; + unsigned stk3; + stk3 = ~S; + stk2 = D & stk3; + stk1 = T ^ stk2; + return (stk1 & S) | (stk1 & (~T)) | (T & (~S) & D); +} + +/* TDSnax source transparent/pattern opaque. */ +static unsigned xrop3_210_1_0 (unsigned char s, unsigned char t) +{ + unsigned D = 0x00ff; + unsigned S = ((unsigned)s << 8) | s; + unsigned T = ((unsigned)t << 8) | t; + unsigned stk1; + unsigned stk2; + unsigned stk3; + stk3 = ~S; + stk2 = D & stk3; + stk1 = T ^ stk2; + return (stk1 & (~S)) | (D & S); +} + +/* TDSnax source/pattern transparent. */ +static unsigned xrop3_210_1_1 (unsigned char s, unsigned char t) +{ + unsigned D = 0x00ff; + unsigned S = ((unsigned)s << 8) | s; + unsigned T = ((unsigned)t << 8) | t; + unsigned stk1; + unsigned stk2; + unsigned stk3; + stk3 = ~S; + stk2 = D & stk3; + stk1 = T ^ stk2; + return (stk1 & (~S) & (~T)) | (D & S) | (D & T); +} + +/* STDSoaxn source/pattern opaque. */ +static void rop3_211_0_0 (unsigned char *D, unsigned char S, unsigned char T) +{ + unsigned char stk1; + unsigned char stk2; + unsigned char stk3; + stk3 = *D | S; + stk2 = T & stk3; + stk1 = S ^ stk2; + stk1 = ~stk1; + *D = stk1; +} + +/* STDSoaxn source opaque/pattern transparent. */ +static void rop3_211_0_1 (unsigned char *D, unsigned char S, unsigned char T) +{ + unsigned char stk1; + unsigned char stk2; + unsigned char stk3; + stk3 = *D | S; + stk2 = T & stk3; + stk1 = S ^ stk2; + stk1 = ~stk1; + *D = (stk1 & S) | (stk1 & (~T)) | (T & (~S) & *D); +} + +/* STDSoaxn source transparent/pattern opaque. */ +static void rop3_211_1_0 (unsigned char *D, unsigned char S, unsigned char T) +{ + unsigned char stk1; + unsigned char stk2; + unsigned char stk3; + stk3 = *D | S; + stk2 = T & stk3; + stk1 = S ^ stk2; + stk1 = ~stk1; + *D = (stk1 & (~S)) | (*D & S); +} + +/* STDSoaxn source/pattern transparent. */ +static void rop3_211_1_1 (unsigned char *D, unsigned char S, unsigned char T) +{ + unsigned char stk1; + unsigned char stk2; + unsigned char stk3; + stk3 = *D | S; + stk2 = T & stk3; + stk1 = S ^ stk2; + stk1 = ~stk1; + *D = (stk1 & (~S) & (~T)) | (*D & S) | (*D & T); +} + +/* STDSoaxn source/pattern opaque. */ +static unsigned xrop3_211_0_0 (unsigned char s, unsigned char t) +{ + unsigned D = 0x00ff; + unsigned S = ((unsigned)s << 8) | s; + unsigned T = ((unsigned)t << 8) | t; + unsigned stk1; + unsigned stk2; + unsigned stk3; + stk3 = D | S; + stk2 = T & stk3; + stk1 = S ^ stk2; + stk1 = ~stk1; + return stk1; +} + +/* STDSoaxn source opaque/pattern transparent. */ +static unsigned xrop3_211_0_1 (unsigned char s, unsigned char t) +{ + unsigned D = 0x00ff; + unsigned S = ((unsigned)s << 8) | s; + unsigned T = ((unsigned)t << 8) | t; + unsigned stk1; + unsigned stk2; + unsigned stk3; + stk3 = D | S; + stk2 = T & stk3; + stk1 = S ^ stk2; + stk1 = ~stk1; + return (stk1 & S) | (stk1 & (~T)) | (T & (~S) & D); +} + +/* STDSoaxn source transparent/pattern opaque. */ +static unsigned xrop3_211_1_0 (unsigned char s, unsigned char t) +{ + unsigned D = 0x00ff; + unsigned S = ((unsigned)s << 8) | s; + unsigned T = ((unsigned)t << 8) | t; + unsigned stk1; + unsigned stk2; + unsigned stk3; + stk3 = D | S; + stk2 = T & stk3; + stk1 = S ^ stk2; + stk1 = ~stk1; + return (stk1 & (~S)) | (D & S); +} + +/* STDSoaxn source/pattern transparent. */ +static unsigned xrop3_211_1_1 (unsigned char s, unsigned char t) +{ + unsigned D = 0x00ff; + unsigned S = ((unsigned)s << 8) | s; + unsigned T = ((unsigned)t << 8) | t; + unsigned stk1; + unsigned stk2; + unsigned stk3; + stk3 = D | S; + stk2 = T & stk3; + stk1 = S ^ stk2; + stk1 = ~stk1; + return (stk1 & (~S) & (~T)) | (D & S) | (D & T); +} + +/* SSTxTDxax source/pattern opaque. */ +static void rop3_212_0_0 (unsigned char *D, unsigned char S, unsigned char T) +{ + unsigned char stk1; + unsigned char stk2; + unsigned char stk3; + stk2 = S ^ T; + stk3 = T ^ *D; + stk2 = stk2 & stk3; + stk1 = S ^ stk2; + *D = stk1; +} + +/* SSTxTDxax source opaque/pattern transparent. */ +static void rop3_212_0_1 (unsigned char *D, unsigned char S, unsigned char T) +{ + unsigned char stk1; + unsigned char stk2; + unsigned char stk3; + stk2 = S ^ T; + stk3 = T ^ *D; + stk2 = stk2 & stk3; + stk1 = S ^ stk2; + *D = (stk1 & S) | (stk1 & (~T)) | (T & (~S) & *D); +} + +/* SSTxTDxax source transparent/pattern opaque. */ +static void rop3_212_1_0 (unsigned char *D, unsigned char S, unsigned char T) +{ + unsigned char stk1; + unsigned char stk2; + unsigned char stk3; + stk2 = S ^ T; + stk3 = T ^ *D; + stk2 = stk2 & stk3; + stk1 = S ^ stk2; + *D = (stk1 & (~S)) | (*D & S); +} + +/* SSTxTDxax source/pattern transparent. */ +static void rop3_212_1_1 (unsigned char *D, unsigned char S, unsigned char T) +{ + unsigned char stk1; + unsigned char stk2; + unsigned char stk3; + stk2 = S ^ T; + stk3 = T ^ *D; + stk2 = stk2 & stk3; + stk1 = S ^ stk2; + *D = (stk1 & (~S) & (~T)) | (*D & S) | (*D & T); +} + +/* SSTxTDxax source/pattern opaque. */ +static unsigned xrop3_212_0_0 (unsigned char s, unsigned char t) +{ + unsigned D = 0x00ff; + unsigned S = ((unsigned)s << 8) | s; + unsigned T = ((unsigned)t << 8) | t; + unsigned stk1; + unsigned stk2; + unsigned stk3; + stk2 = S ^ T; + stk3 = T ^ D; + stk2 = stk2 & stk3; + stk1 = S ^ stk2; + return stk1; +} + +/* SSTxTDxax source opaque/pattern transparent. */ +static unsigned xrop3_212_0_1 (unsigned char s, unsigned char t) +{ + unsigned D = 0x00ff; + unsigned S = ((unsigned)s << 8) | s; + unsigned T = ((unsigned)t << 8) | t; + unsigned stk1; + unsigned stk2; + unsigned stk3; + stk2 = S ^ T; + stk3 = T ^ D; + stk2 = stk2 & stk3; + stk1 = S ^ stk2; + return (stk1 & S) | (stk1 & (~T)) | (T & (~S) & D); +} + +/* SSTxTDxax source transparent/pattern opaque. */ +static unsigned xrop3_212_1_0 (unsigned char s, unsigned char t) +{ + unsigned D = 0x00ff; + unsigned S = ((unsigned)s << 8) | s; + unsigned T = ((unsigned)t << 8) | t; + unsigned stk1; + unsigned stk2; + unsigned stk3; + stk2 = S ^ T; + stk3 = T ^ D; + stk2 = stk2 & stk3; + stk1 = S ^ stk2; + return (stk1 & (~S)) | (D & S); +} + +/* SSTxTDxax source/pattern transparent. */ +static unsigned xrop3_212_1_1 (unsigned char s, unsigned char t) +{ + unsigned D = 0x00ff; + unsigned S = ((unsigned)s << 8) | s; + unsigned T = ((unsigned)t << 8) | t; + unsigned stk1; + unsigned stk2; + unsigned stk3; + stk2 = S ^ T; + stk3 = T ^ D; + stk2 = stk2 & stk3; + stk1 = S ^ stk2; + return (stk1 & (~S) & (~T)) | (D & S) | (D & T); +} + +/* DTSanan source/pattern opaque. */ +static void rop3_213_0_0 (unsigned char *D, unsigned char S, unsigned char T) +{ + unsigned char stk1; + unsigned char stk2; + stk2 = T & S; + stk2 = ~stk2; + stk1 = *D & stk2; + stk1 = ~stk1; + *D = stk1; +} + +/* DTSanan source opaque/pattern transparent. */ +static void rop3_213_0_1 (unsigned char *D, unsigned char S, unsigned char T) +{ + unsigned char stk1; + unsigned char stk2; + stk2 = T & S; + stk2 = ~stk2; + stk1 = *D & stk2; + stk1 = ~stk1; + *D = (stk1 & S) | (stk1 & (~T)) | (T & (~S) & *D); +} + +/* DTSanan source transparent/pattern opaque. */ +static void rop3_213_1_0 (unsigned char *D, unsigned char S, unsigned char T) +{ + unsigned char stk1; + unsigned char stk2; + stk2 = T & S; + stk2 = ~stk2; + stk1 = *D & stk2; + stk1 = ~stk1; + *D = (stk1 & (~S)) | (*D & S); +} + +/* DTSanan source/pattern transparent. */ +static void rop3_213_1_1 (unsigned char *D, unsigned char S, unsigned char T) +{ + unsigned char stk1; + unsigned char stk2; + stk2 = T & S; + stk2 = ~stk2; + stk1 = *D & stk2; + stk1 = ~stk1; + *D = (stk1 & (~S) & (~T)) | (*D & S) | (*D & T); +} + +/* DTSanan source/pattern opaque. */ +static unsigned xrop3_213_0_0 (unsigned char s, unsigned char t) +{ + unsigned D = 0x00ff; + unsigned S = ((unsigned)s << 8) | s; + unsigned T = ((unsigned)t << 8) | t; + unsigned stk1; + unsigned stk2; + stk2 = T & S; + stk2 = ~stk2; + stk1 = D & stk2; + stk1 = ~stk1; + return stk1; +} + +/* DTSanan source opaque/pattern transparent. */ +static unsigned xrop3_213_0_1 (unsigned char s, unsigned char t) +{ + unsigned D = 0x00ff; + unsigned S = ((unsigned)s << 8) | s; + unsigned T = ((unsigned)t << 8) | t; + unsigned stk1; + unsigned stk2; + stk2 = T & S; + stk2 = ~stk2; + stk1 = D & stk2; + stk1 = ~stk1; + return (stk1 & S) | (stk1 & (~T)) | (T & (~S) & D); +} + +/* DTSanan source transparent/pattern opaque. */ +static unsigned xrop3_213_1_0 (unsigned char s, unsigned char t) +{ + unsigned D = 0x00ff; + unsigned S = ((unsigned)s << 8) | s; + unsigned T = ((unsigned)t << 8) | t; + unsigned stk1; + unsigned stk2; + stk2 = T & S; + stk2 = ~stk2; + stk1 = D & stk2; + stk1 = ~stk1; + return (stk1 & (~S)) | (D & S); +} + +/* DTSanan source/pattern transparent. */ +static unsigned xrop3_213_1_1 (unsigned char s, unsigned char t) +{ + unsigned D = 0x00ff; + unsigned S = ((unsigned)s << 8) | s; + unsigned T = ((unsigned)t << 8) | t; + unsigned stk1; + unsigned stk2; + stk2 = T & S; + stk2 = ~stk2; + stk1 = D & stk2; + stk1 = ~stk1; + return (stk1 & (~S) & (~T)) | (D & S) | (D & T); +} + +/* TSDTSaoxx source/pattern opaque. */ +static void rop3_214_0_0 (unsigned char *D, unsigned char S, unsigned char T) +{ + unsigned char stk1; + unsigned char stk2; + unsigned char stk3; + unsigned char stk4; + stk4 = T & S; + stk3 = *D | stk4; + stk2 = S ^ stk3; + stk1 = T ^ stk2; + *D = stk1; +} + +/* TSDTSaoxx source opaque/pattern transparent. */ +static void rop3_214_0_1 (unsigned char *D, unsigned char S, unsigned char T) +{ + unsigned char stk1; + unsigned char stk2; + unsigned char stk3; + unsigned char stk4; + stk4 = T & S; + stk3 = *D | stk4; + stk2 = S ^ stk3; + stk1 = T ^ stk2; + *D = (stk1 & S) | (stk1 & (~T)) | (T & (~S) & *D); +} + +/* TSDTSaoxx source transparent/pattern opaque. */ +static void rop3_214_1_0 (unsigned char *D, unsigned char S, unsigned char T) +{ + unsigned char stk1; + unsigned char stk2; + unsigned char stk3; + unsigned char stk4; + stk4 = T & S; + stk3 = *D | stk4; + stk2 = S ^ stk3; + stk1 = T ^ stk2; + *D = (stk1 & (~S)) | (*D & S); +} + +/* TSDTSaoxx source/pattern transparent. */ +static void rop3_214_1_1 (unsigned char *D, unsigned char S, unsigned char T) +{ + unsigned char stk1; + unsigned char stk2; + unsigned char stk3; + unsigned char stk4; + stk4 = T & S; + stk3 = *D | stk4; + stk2 = S ^ stk3; + stk1 = T ^ stk2; + *D = (stk1 & (~S) & (~T)) | (*D & S) | (*D & T); +} + +/* TSDTSaoxx source/pattern opaque. */ +static unsigned xrop3_214_0_0 (unsigned char s, unsigned char t) +{ + unsigned D = 0x00ff; + unsigned S = ((unsigned)s << 8) | s; + unsigned T = ((unsigned)t << 8) | t; + unsigned stk1; + unsigned stk2; + unsigned stk3; + unsigned stk4; + stk4 = T & S; + stk3 = D | stk4; + stk2 = S ^ stk3; + stk1 = T ^ stk2; + return stk1; +} + +/* TSDTSaoxx source opaque/pattern transparent. */ +static unsigned xrop3_214_0_1 (unsigned char s, unsigned char t) +{ + unsigned D = 0x00ff; + unsigned S = ((unsigned)s << 8) | s; + unsigned T = ((unsigned)t << 8) | t; + unsigned stk1; + unsigned stk2; + unsigned stk3; + unsigned stk4; + stk4 = T & S; + stk3 = D | stk4; + stk2 = S ^ stk3; + stk1 = T ^ stk2; + return (stk1 & S) | (stk1 & (~T)) | (T & (~S) & D); +} + +/* TSDTSaoxx source transparent/pattern opaque. */ +static unsigned xrop3_214_1_0 (unsigned char s, unsigned char t) +{ + unsigned D = 0x00ff; + unsigned S = ((unsigned)s << 8) | s; + unsigned T = ((unsigned)t << 8) | t; + unsigned stk1; + unsigned stk2; + unsigned stk3; + unsigned stk4; + stk4 = T & S; + stk3 = D | stk4; + stk2 = S ^ stk3; + stk1 = T ^ stk2; + return (stk1 & (~S)) | (D & S); +} + +/* TSDTSaoxx source/pattern transparent. */ +static unsigned xrop3_214_1_1 (unsigned char s, unsigned char t) +{ + unsigned D = 0x00ff; + unsigned S = ((unsigned)s << 8) | s; + unsigned T = ((unsigned)t << 8) | t; + unsigned stk1; + unsigned stk2; + unsigned stk3; + unsigned stk4; + stk4 = T & S; + stk3 = D | stk4; + stk2 = S ^ stk3; + stk1 = T ^ stk2; + return (stk1 & (~S) & (~T)) | (D & S) | (D & T); +} + +/* DTSxan source/pattern opaque. */ +static void rop3_215_0_0 (unsigned char *D, unsigned char S, unsigned char T) +{ + unsigned char stk1; + unsigned char stk2; + stk2 = T ^ S; + stk1 = *D & stk2; + stk1 = ~stk1; + *D = stk1; +} + +/* DTSxan source opaque/pattern transparent. */ +static void rop3_215_0_1 (unsigned char *D, unsigned char S, unsigned char T) +{ + unsigned char stk1; + unsigned char stk2; + stk2 = T ^ S; + stk1 = *D & stk2; + stk1 = ~stk1; + *D = (stk1 & S) | (stk1 & (~T)) | (T & (~S) & *D); +} + +/* DTSxan source transparent/pattern opaque. */ +static void rop3_215_1_0 (unsigned char *D, unsigned char S, unsigned char T) +{ + unsigned char stk1; + unsigned char stk2; + stk2 = T ^ S; + stk1 = *D & stk2; + stk1 = ~stk1; + *D = (stk1 & (~S)) | (*D & S); +} + +/* DTSxan source/pattern transparent. */ +static void rop3_215_1_1 (unsigned char *D, unsigned char S, unsigned char T) +{ + unsigned char stk1; + unsigned char stk2; + stk2 = T ^ S; + stk1 = *D & stk2; + stk1 = ~stk1; + *D = (stk1 & (~S) & (~T)) | (*D & S) | (*D & T); +} + +/* DTSxan source/pattern opaque. */ +static unsigned xrop3_215_0_0 (unsigned char s, unsigned char t) +{ + unsigned D = 0x00ff; + unsigned S = ((unsigned)s << 8) | s; + unsigned T = ((unsigned)t << 8) | t; + unsigned stk1; + unsigned stk2; + stk2 = T ^ S; + stk1 = D & stk2; + stk1 = ~stk1; + return stk1; +} + +/* DTSxan source opaque/pattern transparent. */ +static unsigned xrop3_215_0_1 (unsigned char s, unsigned char t) +{ + unsigned D = 0x00ff; + unsigned S = ((unsigned)s << 8) | s; + unsigned T = ((unsigned)t << 8) | t; + unsigned stk1; + unsigned stk2; + stk2 = T ^ S; + stk1 = D & stk2; + stk1 = ~stk1; + return (stk1 & S) | (stk1 & (~T)) | (T & (~S) & D); +} + +/* DTSxan source transparent/pattern opaque. */ +static unsigned xrop3_215_1_0 (unsigned char s, unsigned char t) +{ + unsigned D = 0x00ff; + unsigned S = ((unsigned)s << 8) | s; + unsigned T = ((unsigned)t << 8) | t; + unsigned stk1; + unsigned stk2; + stk2 = T ^ S; + stk1 = D & stk2; + stk1 = ~stk1; + return (stk1 & (~S)) | (D & S); +} + +/* DTSxan source/pattern transparent. */ +static unsigned xrop3_215_1_1 (unsigned char s, unsigned char t) +{ + unsigned D = 0x00ff; + unsigned S = ((unsigned)s << 8) | s; + unsigned T = ((unsigned)t << 8) | t; + unsigned stk1; + unsigned stk2; + stk2 = T ^ S; + stk1 = D & stk2; + stk1 = ~stk1; + return (stk1 & (~S) & (~T)) | (D & S) | (D & T); +} + +/* TDSTxax source/pattern opaque. */ +static void rop3_216_0_0 (unsigned char *D, unsigned char S, unsigned char T) +{ + unsigned char stk1; + unsigned char stk2; + unsigned char stk3; + stk3 = S ^ T; + stk2 = *D & stk3; + stk1 = T ^ stk2; + *D = stk1; +} + +/* TDSTxax source opaque/pattern transparent. */ +static void rop3_216_0_1 (unsigned char *D, unsigned char S, unsigned char T) +{ + unsigned char stk1; + unsigned char stk2; + unsigned char stk3; + stk3 = S ^ T; + stk2 = *D & stk3; + stk1 = T ^ stk2; + *D = (stk1 & S) | (stk1 & (~T)) | (T & (~S) & *D); +} + +/* TDSTxax source transparent/pattern opaque. */ +static void rop3_216_1_0 (unsigned char *D, unsigned char S, unsigned char T) +{ + unsigned char stk1; + unsigned char stk2; + unsigned char stk3; + stk3 = S ^ T; + stk2 = *D & stk3; + stk1 = T ^ stk2; + *D = (stk1 & (~S)) | (*D & S); +} + +/* TDSTxax source/pattern transparent. */ +static void rop3_216_1_1 (unsigned char *D, unsigned char S, unsigned char T) +{ + unsigned char stk1; + unsigned char stk2; + unsigned char stk3; + stk3 = S ^ T; + stk2 = *D & stk3; + stk1 = T ^ stk2; + *D = (stk1 & (~S) & (~T)) | (*D & S) | (*D & T); +} + +/* TDSTxax source/pattern opaque. */ +static unsigned xrop3_216_0_0 (unsigned char s, unsigned char t) +{ + unsigned D = 0x00ff; + unsigned S = ((unsigned)s << 8) | s; + unsigned T = ((unsigned)t << 8) | t; + unsigned stk1; + unsigned stk2; + unsigned stk3; + stk3 = S ^ T; + stk2 = D & stk3; + stk1 = T ^ stk2; + return stk1; +} + +/* TDSTxax source opaque/pattern transparent. */ +static unsigned xrop3_216_0_1 (unsigned char s, unsigned char t) +{ + unsigned D = 0x00ff; + unsigned S = ((unsigned)s << 8) | s; + unsigned T = ((unsigned)t << 8) | t; + unsigned stk1; + unsigned stk2; + unsigned stk3; + stk3 = S ^ T; + stk2 = D & stk3; + stk1 = T ^ stk2; + return (stk1 & S) | (stk1 & (~T)) | (T & (~S) & D); +} + +/* TDSTxax source transparent/pattern opaque. */ +static unsigned xrop3_216_1_0 (unsigned char s, unsigned char t) +{ + unsigned D = 0x00ff; + unsigned S = ((unsigned)s << 8) | s; + unsigned T = ((unsigned)t << 8) | t; + unsigned stk1; + unsigned stk2; + unsigned stk3; + stk3 = S ^ T; + stk2 = D & stk3; + stk1 = T ^ stk2; + return (stk1 & (~S)) | (D & S); +} + +/* TDSTxax source/pattern transparent. */ +static unsigned xrop3_216_1_1 (unsigned char s, unsigned char t) +{ + unsigned D = 0x00ff; + unsigned S = ((unsigned)s << 8) | s; + unsigned T = ((unsigned)t << 8) | t; + unsigned stk1; + unsigned stk2; + unsigned stk3; + stk3 = S ^ T; + stk2 = D & stk3; + stk1 = T ^ stk2; + return (stk1 & (~S) & (~T)) | (D & S) | (D & T); +} + +/* SDTSaoxn source/pattern opaque. */ +static void rop3_217_0_0 (unsigned char *D, unsigned char S, unsigned char T) +{ + unsigned char stk1; + unsigned char stk2; + unsigned char stk3; + stk3 = T & S; + stk2 = *D | stk3; + stk1 = S ^ stk2; + stk1 = ~stk1; + *D = stk1; +} + +/* SDTSaoxn source opaque/pattern transparent. */ +static void rop3_217_0_1 (unsigned char *D, unsigned char S, unsigned char T) +{ + unsigned char stk1; + unsigned char stk2; + unsigned char stk3; + stk3 = T & S; + stk2 = *D | stk3; + stk1 = S ^ stk2; + stk1 = ~stk1; + *D = (stk1 & S) | (stk1 & (~T)) | (T & (~S) & *D); +} + +/* SDTSaoxn source transparent/pattern opaque. */ +static void rop3_217_1_0 (unsigned char *D, unsigned char S, unsigned char T) +{ + unsigned char stk1; + unsigned char stk2; + unsigned char stk3; + stk3 = T & S; + stk2 = *D | stk3; + stk1 = S ^ stk2; + stk1 = ~stk1; + *D = (stk1 & (~S)) | (*D & S); +} + +/* SDTSaoxn source/pattern transparent. */ +static void rop3_217_1_1 (unsigned char *D, unsigned char S, unsigned char T) +{ + unsigned char stk1; + unsigned char stk2; + unsigned char stk3; + stk3 = T & S; + stk2 = *D | stk3; + stk1 = S ^ stk2; + stk1 = ~stk1; + *D = (stk1 & (~S) & (~T)) | (*D & S) | (*D & T); +} + +/* SDTSaoxn source/pattern opaque. */ +static unsigned xrop3_217_0_0 (unsigned char s, unsigned char t) +{ + unsigned D = 0x00ff; + unsigned S = ((unsigned)s << 8) | s; + unsigned T = ((unsigned)t << 8) | t; + unsigned stk1; + unsigned stk2; + unsigned stk3; + stk3 = T & S; + stk2 = D | stk3; + stk1 = S ^ stk2; + stk1 = ~stk1; + return stk1; +} + +/* SDTSaoxn source opaque/pattern transparent. */ +static unsigned xrop3_217_0_1 (unsigned char s, unsigned char t) +{ + unsigned D = 0x00ff; + unsigned S = ((unsigned)s << 8) | s; + unsigned T = ((unsigned)t << 8) | t; + unsigned stk1; + unsigned stk2; + unsigned stk3; + stk3 = T & S; + stk2 = D | stk3; + stk1 = S ^ stk2; + stk1 = ~stk1; + return (stk1 & S) | (stk1 & (~T)) | (T & (~S) & D); +} + +/* SDTSaoxn source transparent/pattern opaque. */ +static unsigned xrop3_217_1_0 (unsigned char s, unsigned char t) +{ + unsigned D = 0x00ff; + unsigned S = ((unsigned)s << 8) | s; + unsigned T = ((unsigned)t << 8) | t; + unsigned stk1; + unsigned stk2; + unsigned stk3; + stk3 = T & S; + stk2 = D | stk3; + stk1 = S ^ stk2; + stk1 = ~stk1; + return (stk1 & (~S)) | (D & S); +} + +/* SDTSaoxn source/pattern transparent. */ +static unsigned xrop3_217_1_1 (unsigned char s, unsigned char t) +{ + unsigned D = 0x00ff; + unsigned S = ((unsigned)s << 8) | s; + unsigned T = ((unsigned)t << 8) | t; + unsigned stk1; + unsigned stk2; + unsigned stk3; + stk3 = T & S; + stk2 = D | stk3; + stk1 = S ^ stk2; + stk1 = ~stk1; + return (stk1 & (~S) & (~T)) | (D & S) | (D & T); +} + +/* DTSDanax source/pattern opaque. */ +static void rop3_218_0_0 (unsigned char *D, unsigned char S, unsigned char T) +{ + unsigned char stk1; + unsigned char stk2; + unsigned char stk3; + stk3 = S & *D; + stk3 = ~stk3; + stk2 = T & stk3; + stk1 = *D ^ stk2; + *D = stk1; +} + +/* DTSDanax source opaque/pattern transparent. */ +static void rop3_218_0_1 (unsigned char *D, unsigned char S, unsigned char T) +{ + unsigned char stk1; + unsigned char stk2; + unsigned char stk3; + stk3 = S & *D; + stk3 = ~stk3; + stk2 = T & stk3; + stk1 = *D ^ stk2; + *D = (stk1 & S) | (stk1 & (~T)) | (T & (~S) & *D); +} + +/* DTSDanax source transparent/pattern opaque. */ +static void rop3_218_1_0 (unsigned char *D, unsigned char S, unsigned char T) +{ + unsigned char stk1; + unsigned char stk2; + unsigned char stk3; + stk3 = S & *D; + stk3 = ~stk3; + stk2 = T & stk3; + stk1 = *D ^ stk2; + *D = (stk1 & (~S)) | (*D & S); +} + +/* DTSDanax source/pattern transparent. */ +static void rop3_218_1_1 (unsigned char *D, unsigned char S, unsigned char T) +{ + unsigned char stk1; + unsigned char stk2; + unsigned char stk3; + stk3 = S & *D; + stk3 = ~stk3; + stk2 = T & stk3; + stk1 = *D ^ stk2; + *D = (stk1 & (~S) & (~T)) | (*D & S) | (*D & T); +} + +/* DTSDanax source/pattern opaque. */ +static unsigned xrop3_218_0_0 (unsigned char s, unsigned char t) +{ + unsigned D = 0x00ff; + unsigned S = ((unsigned)s << 8) | s; + unsigned T = ((unsigned)t << 8) | t; + unsigned stk1; + unsigned stk2; + unsigned stk3; + stk3 = S & D; + stk3 = ~stk3; + stk2 = T & stk3; + stk1 = D ^ stk2; + return stk1; +} + +/* DTSDanax source opaque/pattern transparent. */ +static unsigned xrop3_218_0_1 (unsigned char s, unsigned char t) +{ + unsigned D = 0x00ff; + unsigned S = ((unsigned)s << 8) | s; + unsigned T = ((unsigned)t << 8) | t; + unsigned stk1; + unsigned stk2; + unsigned stk3; + stk3 = S & D; + stk3 = ~stk3; + stk2 = T & stk3; + stk1 = D ^ stk2; + return (stk1 & S) | (stk1 & (~T)) | (T & (~S) & D); +} + +/* DTSDanax source transparent/pattern opaque. */ +static unsigned xrop3_218_1_0 (unsigned char s, unsigned char t) +{ + unsigned D = 0x00ff; + unsigned S = ((unsigned)s << 8) | s; + unsigned T = ((unsigned)t << 8) | t; + unsigned stk1; + unsigned stk2; + unsigned stk3; + stk3 = S & D; + stk3 = ~stk3; + stk2 = T & stk3; + stk1 = D ^ stk2; + return (stk1 & (~S)) | (D & S); +} + +/* DTSDanax source/pattern transparent. */ +static unsigned xrop3_218_1_1 (unsigned char s, unsigned char t) +{ + unsigned D = 0x00ff; + unsigned S = ((unsigned)s << 8) | s; + unsigned T = ((unsigned)t << 8) | t; + unsigned stk1; + unsigned stk2; + unsigned stk3; + stk3 = S & D; + stk3 = ~stk3; + stk2 = T & stk3; + stk1 = D ^ stk2; + return (stk1 & (~S) & (~T)) | (D & S) | (D & T); +} + +/* STxDSxan source/pattern opaque. */ +static void rop3_219_0_0 (unsigned char *D, unsigned char S, unsigned char T) +{ + unsigned char stk1; + unsigned char stk2; + stk1 = S ^ T; + stk2 = *D ^ S; + stk1 = stk1 & stk2; + stk1 = ~stk1; + *D = stk1; +} + +/* STxDSxan source opaque/pattern transparent. */ +static void rop3_219_0_1 (unsigned char *D, unsigned char S, unsigned char T) +{ + unsigned char stk1; + unsigned char stk2; + stk1 = S ^ T; + stk2 = *D ^ S; + stk1 = stk1 & stk2; + stk1 = ~stk1; + *D = (stk1 & S) | (stk1 & (~T)) | (T & (~S) & *D); +} + +/* STxDSxan source transparent/pattern opaque. */ +static void rop3_219_1_0 (unsigned char *D, unsigned char S, unsigned char T) +{ + unsigned char stk1; + unsigned char stk2; + stk1 = S ^ T; + stk2 = *D ^ S; + stk1 = stk1 & stk2; + stk1 = ~stk1; + *D = (stk1 & (~S)) | (*D & S); +} + +/* STxDSxan source/pattern transparent. */ +static void rop3_219_1_1 (unsigned char *D, unsigned char S, unsigned char T) +{ + unsigned char stk1; + unsigned char stk2; + stk1 = S ^ T; + stk2 = *D ^ S; + stk1 = stk1 & stk2; + stk1 = ~stk1; + *D = (stk1 & (~S) & (~T)) | (*D & S) | (*D & T); +} + +/* STxDSxan source/pattern opaque. */ +static unsigned xrop3_219_0_0 (unsigned char s, unsigned char t) +{ + unsigned D = 0x00ff; + unsigned S = ((unsigned)s << 8) | s; + unsigned T = ((unsigned)t << 8) | t; + unsigned stk1; + unsigned stk2; + stk1 = S ^ T; + stk2 = D ^ S; + stk1 = stk1 & stk2; + stk1 = ~stk1; + return stk1; +} + +/* STxDSxan source opaque/pattern transparent. */ +static unsigned xrop3_219_0_1 (unsigned char s, unsigned char t) +{ + unsigned D = 0x00ff; + unsigned S = ((unsigned)s << 8) | s; + unsigned T = ((unsigned)t << 8) | t; + unsigned stk1; + unsigned stk2; + stk1 = S ^ T; + stk2 = D ^ S; + stk1 = stk1 & stk2; + stk1 = ~stk1; + return (stk1 & S) | (stk1 & (~T)) | (T & (~S) & D); +} + +/* STxDSxan source transparent/pattern opaque. */ +static unsigned xrop3_219_1_0 (unsigned char s, unsigned char t) +{ + unsigned D = 0x00ff; + unsigned S = ((unsigned)s << 8) | s; + unsigned T = ((unsigned)t << 8) | t; + unsigned stk1; + unsigned stk2; + stk1 = S ^ T; + stk2 = D ^ S; + stk1 = stk1 & stk2; + stk1 = ~stk1; + return (stk1 & (~S)) | (D & S); +} + +/* STxDSxan source/pattern transparent. */ +static unsigned xrop3_219_1_1 (unsigned char s, unsigned char t) +{ + unsigned D = 0x00ff; + unsigned S = ((unsigned)s << 8) | s; + unsigned T = ((unsigned)t << 8) | t; + unsigned stk1; + unsigned stk2; + stk1 = S ^ T; + stk2 = D ^ S; + stk1 = stk1 & stk2; + stk1 = ~stk1; + return (stk1 & (~S) & (~T)) | (D & S) | (D & T); +} + +/* STDnao source/pattern opaque. */ +static void rop3_220_0_0 (unsigned char *D, unsigned char S, unsigned char T) +{ + unsigned char stk1; + unsigned char stk2; + unsigned char stk3; + stk3 = ~*D; + stk2 = T & stk3; + stk1 = S | stk2; + *D = stk1; +} + +/* STDnao source opaque/pattern transparent. */ +static void rop3_220_0_1 (unsigned char *D, unsigned char S, unsigned char T) +{ + unsigned char stk1; + unsigned char stk2; + unsigned char stk3; + stk3 = ~*D; + stk2 = T & stk3; + stk1 = S | stk2; + *D = (stk1 & S) | (stk1 & (~T)) | (T & (~S) & *D); +} + +/* STDnao source transparent/pattern opaque. */ +static void rop3_220_1_0 (unsigned char *D, unsigned char S, unsigned char T) +{ + unsigned char stk1; + unsigned char stk2; + unsigned char stk3; + stk3 = ~*D; + stk2 = T & stk3; + stk1 = S | stk2; + *D = (stk1 & (~S)) | (*D & S); +} + +/* STDnao source/pattern transparent. */ +static void rop3_220_1_1 (unsigned char *D, unsigned char S, unsigned char T) +{ + unsigned char stk1; + unsigned char stk2; + unsigned char stk3; + stk3 = ~*D; + stk2 = T & stk3; + stk1 = S | stk2; + *D = (stk1 & (~S) & (~T)) | (*D & S) | (*D & T); +} + +/* STDnao source/pattern opaque. */ +static unsigned xrop3_220_0_0 (unsigned char s, unsigned char t) +{ + unsigned D = 0x00ff; + unsigned S = ((unsigned)s << 8) | s; + unsigned T = ((unsigned)t << 8) | t; + unsigned stk1; + unsigned stk2; + unsigned stk3; + stk3 = ~D; + stk2 = T & stk3; + stk1 = S | stk2; + return stk1; +} + +/* STDnao source opaque/pattern transparent. */ +static unsigned xrop3_220_0_1 (unsigned char s, unsigned char t) +{ + unsigned D = 0x00ff; + unsigned S = ((unsigned)s << 8) | s; + unsigned T = ((unsigned)t << 8) | t; + unsigned stk1; + unsigned stk2; + unsigned stk3; + stk3 = ~D; + stk2 = T & stk3; + stk1 = S | stk2; + return (stk1 & S) | (stk1 & (~T)) | (T & (~S) & D); +} + +/* STDnao source transparent/pattern opaque. */ +static unsigned xrop3_220_1_0 (unsigned char s, unsigned char t) +{ + unsigned D = 0x00ff; + unsigned S = ((unsigned)s << 8) | s; + unsigned T = ((unsigned)t << 8) | t; + unsigned stk1; + unsigned stk2; + unsigned stk3; + stk3 = ~D; + stk2 = T & stk3; + stk1 = S | stk2; + return (stk1 & (~S)) | (D & S); +} + +/* STDnao source/pattern transparent. */ +static unsigned xrop3_220_1_1 (unsigned char s, unsigned char t) +{ + unsigned D = 0x00ff; + unsigned S = ((unsigned)s << 8) | s; + unsigned T = ((unsigned)t << 8) | t; + unsigned stk1; + unsigned stk2; + unsigned stk3; + stk3 = ~D; + stk2 = T & stk3; + stk1 = S | stk2; + return (stk1 & (~S) & (~T)) | (D & S) | (D & T); +} + +/* SDno source/pattern opaque. */ +static void rop3_221_0_0 (unsigned char *D, unsigned char S, unsigned char T) +{ + unsigned char stk1; + unsigned char stk2; + stk2 = ~*D; + stk1 = S | stk2; + *D = stk1; +} + +/* SDno source opaque/pattern transparent. */ +static void rop3_221_0_1 (unsigned char *D, unsigned char S, unsigned char T) +{ + unsigned char stk1; + unsigned char stk2; + stk2 = ~*D; + stk1 = S | stk2; + *D = (stk1 & S) | (stk1 & (~T)) | (T & (~S) & *D); +} + +/* SDno source transparent/pattern opaque. */ +static void rop3_221_1_0 (unsigned char *D, unsigned char S, unsigned char T) +{ + unsigned char stk1; + unsigned char stk2; + stk2 = ~*D; + stk1 = S | stk2; + *D = (stk1 & (~S)) | (*D & S); +} + +/* SDno source/pattern transparent. */ +static void rop3_221_1_1 (unsigned char *D, unsigned char S, unsigned char T) +{ + unsigned char stk1; + unsigned char stk2; + stk2 = ~*D; + stk1 = S | stk2; + *D = (stk1 & (~S) & (~T)) | (*D & S) | (*D & T); +} + +/* SDno source/pattern opaque. */ +static unsigned xrop3_221_0_0 (unsigned char s, unsigned char t) +{ + unsigned D = 0x00ff; + unsigned S = ((unsigned)s << 8) | s; + unsigned stk1; + unsigned stk2; + stk2 = ~D; + stk1 = S | stk2; + return stk1; +} + +/* SDno source opaque/pattern transparent. */ +static unsigned xrop3_221_0_1 (unsigned char s, unsigned char t) +{ + unsigned D = 0x00ff; + unsigned S = ((unsigned)s << 8) | s; + unsigned T = ((unsigned)t << 8) | t; + unsigned stk1; + unsigned stk2; + stk2 = ~D; + stk1 = S | stk2; + return (stk1 & S) | (stk1 & (~T)) | (T & (~S) & D); +} + +/* SDno source transparent/pattern opaque. */ +static unsigned xrop3_221_1_0 (unsigned char s, unsigned char t) +{ + unsigned D = 0x00ff; + unsigned S = ((unsigned)s << 8) | s; + unsigned stk1; + unsigned stk2; + stk2 = ~D; + stk1 = S | stk2; + return (stk1 & (~S)) | (D & S); +} + +/* SDno source/pattern transparent. */ +static unsigned xrop3_221_1_1 (unsigned char s, unsigned char t) +{ + unsigned D = 0x00ff; + unsigned S = ((unsigned)s << 8) | s; + unsigned T = ((unsigned)t << 8) | t; + unsigned stk1; + unsigned stk2; + stk2 = ~D; + stk1 = S | stk2; + return (stk1 & (~S) & (~T)) | (D & S) | (D & T); +} + +/* SDTxo source/pattern opaque. */ +static void rop3_222_0_0 (unsigned char *D, unsigned char S, unsigned char T) +{ + unsigned char stk1; + unsigned char stk2; + stk2 = *D ^ T; + stk1 = S | stk2; + *D = stk1; +} + +/* SDTxo source opaque/pattern transparent. */ +static void rop3_222_0_1 (unsigned char *D, unsigned char S, unsigned char T) +{ + unsigned char stk1; + unsigned char stk2; + stk2 = *D ^ T; + stk1 = S | stk2; + *D = (stk1 & S) | (stk1 & (~T)) | (T & (~S) & *D); +} + +/* SDTxo source transparent/pattern opaque. */ +static void rop3_222_1_0 (unsigned char *D, unsigned char S, unsigned char T) +{ + unsigned char stk1; + unsigned char stk2; + stk2 = *D ^ T; + stk1 = S | stk2; + *D = (stk1 & (~S)) | (*D & S); +} + +/* SDTxo source/pattern transparent. */ +static void rop3_222_1_1 (unsigned char *D, unsigned char S, unsigned char T) +{ + unsigned char stk1; + unsigned char stk2; + stk2 = *D ^ T; + stk1 = S | stk2; + *D = (stk1 & (~S) & (~T)) | (*D & S) | (*D & T); +} + +/* SDTxo source/pattern opaque. */ +static unsigned xrop3_222_0_0 (unsigned char s, unsigned char t) +{ + unsigned D = 0x00ff; + unsigned S = ((unsigned)s << 8) | s; + unsigned T = ((unsigned)t << 8) | t; + unsigned stk1; + unsigned stk2; + stk2 = D ^ T; + stk1 = S | stk2; + return stk1; +} + +/* SDTxo source opaque/pattern transparent. */ +static unsigned xrop3_222_0_1 (unsigned char s, unsigned char t) +{ + unsigned D = 0x00ff; + unsigned S = ((unsigned)s << 8) | s; + unsigned T = ((unsigned)t << 8) | t; + unsigned stk1; + unsigned stk2; + stk2 = D ^ T; + stk1 = S | stk2; + return (stk1 & S) | (stk1 & (~T)) | (T & (~S) & D); +} + +/* SDTxo source transparent/pattern opaque. */ +static unsigned xrop3_222_1_0 (unsigned char s, unsigned char t) +{ + unsigned D = 0x00ff; + unsigned S = ((unsigned)s << 8) | s; + unsigned T = ((unsigned)t << 8) | t; + unsigned stk1; + unsigned stk2; + stk2 = D ^ T; + stk1 = S | stk2; + return (stk1 & (~S)) | (D & S); +} + +/* SDTxo source/pattern transparent. */ +static unsigned xrop3_222_1_1 (unsigned char s, unsigned char t) +{ + unsigned D = 0x00ff; + unsigned S = ((unsigned)s << 8) | s; + unsigned T = ((unsigned)t << 8) | t; + unsigned stk1; + unsigned stk2; + stk2 = D ^ T; + stk1 = S | stk2; + return (stk1 & (~S) & (~T)) | (D & S) | (D & T); +} + +/* SDTano source/pattern opaque. */ +static void rop3_223_0_0 (unsigned char *D, unsigned char S, unsigned char T) +{ + unsigned char stk1; + unsigned char stk2; + stk2 = *D & T; + stk2 = ~stk2; + stk1 = S | stk2; + *D = stk1; +} + +/* SDTano source opaque/pattern transparent. */ +static void rop3_223_0_1 (unsigned char *D, unsigned char S, unsigned char T) +{ + unsigned char stk1; + unsigned char stk2; + stk2 = *D & T; + stk2 = ~stk2; + stk1 = S | stk2; + *D = (stk1 & S) | (stk1 & (~T)) | (T & (~S) & *D); +} + +/* SDTano source transparent/pattern opaque. */ +static void rop3_223_1_0 (unsigned char *D, unsigned char S, unsigned char T) +{ + unsigned char stk1; + unsigned char stk2; + stk2 = *D & T; + stk2 = ~stk2; + stk1 = S | stk2; + *D = (stk1 & (~S)) | (*D & S); +} + +/* SDTano source/pattern transparent. */ +static void rop3_223_1_1 (unsigned char *D, unsigned char S, unsigned char T) +{ + unsigned char stk1; + unsigned char stk2; + stk2 = *D & T; + stk2 = ~stk2; + stk1 = S | stk2; + *D = (stk1 & (~S) & (~T)) | (*D & S) | (*D & T); +} + +/* SDTano source/pattern opaque. */ +static unsigned xrop3_223_0_0 (unsigned char s, unsigned char t) +{ + unsigned D = 0x00ff; + unsigned S = ((unsigned)s << 8) | s; + unsigned T = ((unsigned)t << 8) | t; + unsigned stk1; + unsigned stk2; + stk2 = D & T; + stk2 = ~stk2; + stk1 = S | stk2; + return stk1; +} + +/* SDTano source opaque/pattern transparent. */ +static unsigned xrop3_223_0_1 (unsigned char s, unsigned char t) +{ + unsigned D = 0x00ff; + unsigned S = ((unsigned)s << 8) | s; + unsigned T = ((unsigned)t << 8) | t; + unsigned stk1; + unsigned stk2; + stk2 = D & T; + stk2 = ~stk2; + stk1 = S | stk2; + return (stk1 & S) | (stk1 & (~T)) | (T & (~S) & D); +} + +/* SDTano source transparent/pattern opaque. */ +static unsigned xrop3_223_1_0 (unsigned char s, unsigned char t) +{ + unsigned D = 0x00ff; + unsigned S = ((unsigned)s << 8) | s; + unsigned T = ((unsigned)t << 8) | t; + unsigned stk1; + unsigned stk2; + stk2 = D & T; + stk2 = ~stk2; + stk1 = S | stk2; + return (stk1 & (~S)) | (D & S); +} + +/* SDTano source/pattern transparent. */ +static unsigned xrop3_223_1_1 (unsigned char s, unsigned char t) +{ + unsigned D = 0x00ff; + unsigned S = ((unsigned)s << 8) | s; + unsigned T = ((unsigned)t << 8) | t; + unsigned stk1; + unsigned stk2; + stk2 = D & T; + stk2 = ~stk2; + stk1 = S | stk2; + return (stk1 & (~S) & (~T)) | (D & S) | (D & T); +} + +/* TDSoa source/pattern opaque. */ +static void rop3_224_0_0 (unsigned char *D, unsigned char S, unsigned char T) +{ + unsigned char stk1; + unsigned char stk2; + stk2 = *D | S; + stk1 = T & stk2; + *D = stk1; +} + +/* TDSoa source opaque/pattern transparent. */ +static void rop3_224_0_1 (unsigned char *D, unsigned char S, unsigned char T) +{ + unsigned char stk1; + unsigned char stk2; + stk2 = *D | S; + stk1 = T & stk2; + *D = (stk1 & S) | (stk1 & (~T)) | (T & (~S) & *D); +} + +/* TDSoa source transparent/pattern opaque. */ +static void rop3_224_1_0 (unsigned char *D, unsigned char S, unsigned char T) +{ + unsigned char stk1; + unsigned char stk2; + stk2 = *D | S; + stk1 = T & stk2; + *D = (stk1 & (~S)) | (*D & S); +} + +/* TDSoa source/pattern transparent. */ +static void rop3_224_1_1 (unsigned char *D, unsigned char S, unsigned char T) +{ + unsigned char stk1; + unsigned char stk2; + stk2 = *D | S; + stk1 = T & stk2; + *D = (stk1 & (~S) & (~T)) | (*D & S) | (*D & T); +} + +/* TDSoa source/pattern opaque. */ +static unsigned xrop3_224_0_0 (unsigned char s, unsigned char t) +{ + unsigned D = 0x00ff; + unsigned S = ((unsigned)s << 8) | s; + unsigned T = ((unsigned)t << 8) | t; + unsigned stk1; + unsigned stk2; + stk2 = D | S; + stk1 = T & stk2; + return stk1; +} + +/* TDSoa source opaque/pattern transparent. */ +static unsigned xrop3_224_0_1 (unsigned char s, unsigned char t) +{ + unsigned D = 0x00ff; + unsigned S = ((unsigned)s << 8) | s; + unsigned T = ((unsigned)t << 8) | t; + unsigned stk1; + unsigned stk2; + stk2 = D | S; + stk1 = T & stk2; + return (stk1 & S) | (stk1 & (~T)) | (T & (~S) & D); +} + +/* TDSoa source transparent/pattern opaque. */ +static unsigned xrop3_224_1_0 (unsigned char s, unsigned char t) +{ + unsigned D = 0x00ff; + unsigned S = ((unsigned)s << 8) | s; + unsigned T = ((unsigned)t << 8) | t; + unsigned stk1; + unsigned stk2; + stk2 = D | S; + stk1 = T & stk2; + return (stk1 & (~S)) | (D & S); +} + +/* TDSoa source/pattern transparent. */ +static unsigned xrop3_224_1_1 (unsigned char s, unsigned char t) +{ + unsigned D = 0x00ff; + unsigned S = ((unsigned)s << 8) | s; + unsigned T = ((unsigned)t << 8) | t; + unsigned stk1; + unsigned stk2; + stk2 = D | S; + stk1 = T & stk2; + return (stk1 & (~S) & (~T)) | (D & S) | (D & T); +} + +/* TDSoxn source/pattern opaque. */ +static void rop3_225_0_0 (unsigned char *D, unsigned char S, unsigned char T) +{ + unsigned char stk1; + unsigned char stk2; + stk2 = *D | S; + stk1 = T ^ stk2; + stk1 = ~stk1; + *D = stk1; +} + +/* TDSoxn source opaque/pattern transparent. */ +static void rop3_225_0_1 (unsigned char *D, unsigned char S, unsigned char T) +{ + unsigned char stk1; + unsigned char stk2; + stk2 = *D | S; + stk1 = T ^ stk2; + stk1 = ~stk1; + *D = (stk1 & S) | (stk1 & (~T)) | (T & (~S) & *D); +} + +/* TDSoxn source transparent/pattern opaque. */ +static void rop3_225_1_0 (unsigned char *D, unsigned char S, unsigned char T) +{ + unsigned char stk1; + unsigned char stk2; + stk2 = *D | S; + stk1 = T ^ stk2; + stk1 = ~stk1; + *D = (stk1 & (~S)) | (*D & S); +} + +/* TDSoxn source/pattern transparent. */ +static void rop3_225_1_1 (unsigned char *D, unsigned char S, unsigned char T) +{ + unsigned char stk1; + unsigned char stk2; + stk2 = *D | S; + stk1 = T ^ stk2; + stk1 = ~stk1; + *D = (stk1 & (~S) & (~T)) | (*D & S) | (*D & T); +} + +/* TDSoxn source/pattern opaque. */ +static unsigned xrop3_225_0_0 (unsigned char s, unsigned char t) +{ + unsigned D = 0x00ff; + unsigned S = ((unsigned)s << 8) | s; + unsigned T = ((unsigned)t << 8) | t; + unsigned stk1; + unsigned stk2; + stk2 = D | S; + stk1 = T ^ stk2; + stk1 = ~stk1; + return stk1; +} + +/* TDSoxn source opaque/pattern transparent. */ +static unsigned xrop3_225_0_1 (unsigned char s, unsigned char t) +{ + unsigned D = 0x00ff; + unsigned S = ((unsigned)s << 8) | s; + unsigned T = ((unsigned)t << 8) | t; + unsigned stk1; + unsigned stk2; + stk2 = D | S; + stk1 = T ^ stk2; + stk1 = ~stk1; + return (stk1 & S) | (stk1 & (~T)) | (T & (~S) & D); +} + +/* TDSoxn source transparent/pattern opaque. */ +static unsigned xrop3_225_1_0 (unsigned char s, unsigned char t) +{ + unsigned D = 0x00ff; + unsigned S = ((unsigned)s << 8) | s; + unsigned T = ((unsigned)t << 8) | t; + unsigned stk1; + unsigned stk2; + stk2 = D | S; + stk1 = T ^ stk2; + stk1 = ~stk1; + return (stk1 & (~S)) | (D & S); +} + +/* TDSoxn source/pattern transparent. */ +static unsigned xrop3_225_1_1 (unsigned char s, unsigned char t) +{ + unsigned D = 0x00ff; + unsigned S = ((unsigned)s << 8) | s; + unsigned T = ((unsigned)t << 8) | t; + unsigned stk1; + unsigned stk2; + stk2 = D | S; + stk1 = T ^ stk2; + stk1 = ~stk1; + return (stk1 & (~S) & (~T)) | (D & S) | (D & T); +} + +/* DSTDxax source/pattern opaque. */ +static void rop3_226_0_0 (unsigned char *D, unsigned char S, unsigned char T) +{ + unsigned char stk1; + unsigned char stk2; + unsigned char stk3; + stk3 = T ^ *D; + stk2 = S & stk3; + stk1 = *D ^ stk2; + *D = stk1; +} + +/* DSTDxax source opaque/pattern transparent. */ +static void rop3_226_0_1 (unsigned char *D, unsigned char S, unsigned char T) +{ + unsigned char stk1; + unsigned char stk2; + unsigned char stk3; + stk3 = T ^ *D; + stk2 = S & stk3; + stk1 = *D ^ stk2; + *D = (stk1 & S) | (stk1 & (~T)) | (T & (~S) & *D); +} + +/* DSTDxax source transparent/pattern opaque. */ +static void rop3_226_1_0 (unsigned char *D, unsigned char S, unsigned char T) +{ + unsigned char stk1; + unsigned char stk2; + unsigned char stk3; + stk3 = T ^ *D; + stk2 = S & stk3; + stk1 = *D ^ stk2; + *D = (stk1 & (~S)) | (*D & S); +} + +/* DSTDxax source/pattern transparent. */ +static void rop3_226_1_1 (unsigned char *D, unsigned char S, unsigned char T) +{ + unsigned char stk1; + unsigned char stk2; + unsigned char stk3; + stk3 = T ^ *D; + stk2 = S & stk3; + stk1 = *D ^ stk2; + *D = (stk1 & (~S) & (~T)) | (*D & S) | (*D & T); +} + +/* DSTDxax source/pattern opaque. */ +static unsigned xrop3_226_0_0 (unsigned char s, unsigned char t) +{ + unsigned D = 0x00ff; + unsigned S = ((unsigned)s << 8) | s; + unsigned T = ((unsigned)t << 8) | t; + unsigned stk1; + unsigned stk2; + unsigned stk3; + stk3 = T ^ D; + stk2 = S & stk3; + stk1 = D ^ stk2; + return stk1; +} + +/* DSTDxax source opaque/pattern transparent. */ +static unsigned xrop3_226_0_1 (unsigned char s, unsigned char t) +{ + unsigned D = 0x00ff; + unsigned S = ((unsigned)s << 8) | s; + unsigned T = ((unsigned)t << 8) | t; + unsigned stk1; + unsigned stk2; + unsigned stk3; + stk3 = T ^ D; + stk2 = S & stk3; + stk1 = D ^ stk2; + return (stk1 & S) | (stk1 & (~T)) | (T & (~S) & D); +} + +/* DSTDxax source transparent/pattern opaque. */ +static unsigned xrop3_226_1_0 (unsigned char s, unsigned char t) +{ + unsigned D = 0x00ff; + unsigned S = ((unsigned)s << 8) | s; + unsigned T = ((unsigned)t << 8) | t; + unsigned stk1; + unsigned stk2; + unsigned stk3; + stk3 = T ^ D; + stk2 = S & stk3; + stk1 = D ^ stk2; + return (stk1 & (~S)) | (D & S); +} + +/* DSTDxax source/pattern transparent. */ +static unsigned xrop3_226_1_1 (unsigned char s, unsigned char t) +{ + unsigned D = 0x00ff; + unsigned S = ((unsigned)s << 8) | s; + unsigned T = ((unsigned)t << 8) | t; + unsigned stk1; + unsigned stk2; + unsigned stk3; + stk3 = T ^ D; + stk2 = S & stk3; + stk1 = D ^ stk2; + return (stk1 & (~S) & (~T)) | (D & S) | (D & T); +} + +/* TSDTaoxn source/pattern opaque. */ +static void rop3_227_0_0 (unsigned char *D, unsigned char S, unsigned char T) +{ + unsigned char stk1; + unsigned char stk2; + unsigned char stk3; + stk3 = *D & T; + stk2 = S | stk3; + stk1 = T ^ stk2; + stk1 = ~stk1; + *D = stk1; +} + +/* TSDTaoxn source opaque/pattern transparent. */ +static void rop3_227_0_1 (unsigned char *D, unsigned char S, unsigned char T) +{ + unsigned char stk1; + unsigned char stk2; + unsigned char stk3; + stk3 = *D & T; + stk2 = S | stk3; + stk1 = T ^ stk2; + stk1 = ~stk1; + *D = (stk1 & S) | (stk1 & (~T)) | (T & (~S) & *D); +} + +/* TSDTaoxn source transparent/pattern opaque. */ +static void rop3_227_1_0 (unsigned char *D, unsigned char S, unsigned char T) +{ + unsigned char stk1; + unsigned char stk2; + unsigned char stk3; + stk3 = *D & T; + stk2 = S | stk3; + stk1 = T ^ stk2; + stk1 = ~stk1; + *D = (stk1 & (~S)) | (*D & S); +} + +/* TSDTaoxn source/pattern transparent. */ +static void rop3_227_1_1 (unsigned char *D, unsigned char S, unsigned char T) +{ + unsigned char stk1; + unsigned char stk2; + unsigned char stk3; + stk3 = *D & T; + stk2 = S | stk3; + stk1 = T ^ stk2; + stk1 = ~stk1; + *D = (stk1 & (~S) & (~T)) | (*D & S) | (*D & T); +} + +/* TSDTaoxn source/pattern opaque. */ +static unsigned xrop3_227_0_0 (unsigned char s, unsigned char t) +{ + unsigned D = 0x00ff; + unsigned S = ((unsigned)s << 8) | s; + unsigned T = ((unsigned)t << 8) | t; + unsigned stk1; + unsigned stk2; + unsigned stk3; + stk3 = D & T; + stk2 = S | stk3; + stk1 = T ^ stk2; + stk1 = ~stk1; + return stk1; +} + +/* TSDTaoxn source opaque/pattern transparent. */ +static unsigned xrop3_227_0_1 (unsigned char s, unsigned char t) +{ + unsigned D = 0x00ff; + unsigned S = ((unsigned)s << 8) | s; + unsigned T = ((unsigned)t << 8) | t; + unsigned stk1; + unsigned stk2; + unsigned stk3; + stk3 = D & T; + stk2 = S | stk3; + stk1 = T ^ stk2; + stk1 = ~stk1; + return (stk1 & S) | (stk1 & (~T)) | (T & (~S) & D); +} + +/* TSDTaoxn source transparent/pattern opaque. */ +static unsigned xrop3_227_1_0 (unsigned char s, unsigned char t) +{ + unsigned D = 0x00ff; + unsigned S = ((unsigned)s << 8) | s; + unsigned T = ((unsigned)t << 8) | t; + unsigned stk1; + unsigned stk2; + unsigned stk3; + stk3 = D & T; + stk2 = S | stk3; + stk1 = T ^ stk2; + stk1 = ~stk1; + return (stk1 & (~S)) | (D & S); +} + +/* TSDTaoxn source/pattern transparent. */ +static unsigned xrop3_227_1_1 (unsigned char s, unsigned char t) +{ + unsigned D = 0x00ff; + unsigned S = ((unsigned)s << 8) | s; + unsigned T = ((unsigned)t << 8) | t; + unsigned stk1; + unsigned stk2; + unsigned stk3; + stk3 = D & T; + stk2 = S | stk3; + stk1 = T ^ stk2; + stk1 = ~stk1; + return (stk1 & (~S) & (~T)) | (D & S) | (D & T); +} + +/* SDTSxax source/pattern opaque. */ +static void rop3_228_0_0 (unsigned char *D, unsigned char S, unsigned char T) +{ + unsigned char stk1; + unsigned char stk2; + unsigned char stk3; + stk3 = T ^ S; + stk2 = *D & stk3; + stk1 = S ^ stk2; + *D = stk1; +} + +/* SDTSxax source opaque/pattern transparent. */ +static void rop3_228_0_1 (unsigned char *D, unsigned char S, unsigned char T) +{ + unsigned char stk1; + unsigned char stk2; + unsigned char stk3; + stk3 = T ^ S; + stk2 = *D & stk3; + stk1 = S ^ stk2; + *D = (stk1 & S) | (stk1 & (~T)) | (T & (~S) & *D); +} + +/* SDTSxax source transparent/pattern opaque. */ +static void rop3_228_1_0 (unsigned char *D, unsigned char S, unsigned char T) +{ + unsigned char stk1; + unsigned char stk2; + unsigned char stk3; + stk3 = T ^ S; + stk2 = *D & stk3; + stk1 = S ^ stk2; + *D = (stk1 & (~S)) | (*D & S); +} + +/* SDTSxax source/pattern transparent. */ +static void rop3_228_1_1 (unsigned char *D, unsigned char S, unsigned char T) +{ + unsigned char stk1; + unsigned char stk2; + unsigned char stk3; + stk3 = T ^ S; + stk2 = *D & stk3; + stk1 = S ^ stk2; + *D = (stk1 & (~S) & (~T)) | (*D & S) | (*D & T); +} + +/* SDTSxax source/pattern opaque. */ +static unsigned xrop3_228_0_0 (unsigned char s, unsigned char t) +{ + unsigned D = 0x00ff; + unsigned S = ((unsigned)s << 8) | s; + unsigned T = ((unsigned)t << 8) | t; + unsigned stk1; + unsigned stk2; + unsigned stk3; + stk3 = T ^ S; + stk2 = D & stk3; + stk1 = S ^ stk2; + return stk1; +} + +/* SDTSxax source opaque/pattern transparent. */ +static unsigned xrop3_228_0_1 (unsigned char s, unsigned char t) +{ + unsigned D = 0x00ff; + unsigned S = ((unsigned)s << 8) | s; + unsigned T = ((unsigned)t << 8) | t; + unsigned stk1; + unsigned stk2; + unsigned stk3; + stk3 = T ^ S; + stk2 = D & stk3; + stk1 = S ^ stk2; + return (stk1 & S) | (stk1 & (~T)) | (T & (~S) & D); +} + +/* SDTSxax source transparent/pattern opaque. */ +static unsigned xrop3_228_1_0 (unsigned char s, unsigned char t) +{ + unsigned D = 0x00ff; + unsigned S = ((unsigned)s << 8) | s; + unsigned T = ((unsigned)t << 8) | t; + unsigned stk1; + unsigned stk2; + unsigned stk3; + stk3 = T ^ S; + stk2 = D & stk3; + stk1 = S ^ stk2; + return (stk1 & (~S)) | (D & S); +} + +/* SDTSxax source/pattern transparent. */ +static unsigned xrop3_228_1_1 (unsigned char s, unsigned char t) +{ + unsigned D = 0x00ff; + unsigned S = ((unsigned)s << 8) | s; + unsigned T = ((unsigned)t << 8) | t; + unsigned stk1; + unsigned stk2; + unsigned stk3; + stk3 = T ^ S; + stk2 = D & stk3; + stk1 = S ^ stk2; + return (stk1 & (~S) & (~T)) | (D & S) | (D & T); +} + +/* TDSTaoxn source/pattern opaque. */ +static void rop3_229_0_0 (unsigned char *D, unsigned char S, unsigned char T) +{ + unsigned char stk1; + unsigned char stk2; + unsigned char stk3; + stk3 = S & T; + stk2 = *D | stk3; + stk1 = T ^ stk2; + stk1 = ~stk1; + *D = stk1; +} + +/* TDSTaoxn source opaque/pattern transparent. */ +static void rop3_229_0_1 (unsigned char *D, unsigned char S, unsigned char T) +{ + unsigned char stk1; + unsigned char stk2; + unsigned char stk3; + stk3 = S & T; + stk2 = *D | stk3; + stk1 = T ^ stk2; + stk1 = ~stk1; + *D = (stk1 & S) | (stk1 & (~T)) | (T & (~S) & *D); +} + +/* TDSTaoxn source transparent/pattern opaque. */ +static void rop3_229_1_0 (unsigned char *D, unsigned char S, unsigned char T) +{ + unsigned char stk1; + unsigned char stk2; + unsigned char stk3; + stk3 = S & T; + stk2 = *D | stk3; + stk1 = T ^ stk2; + stk1 = ~stk1; + *D = (stk1 & (~S)) | (*D & S); +} + +/* TDSTaoxn source/pattern transparent. */ +static void rop3_229_1_1 (unsigned char *D, unsigned char S, unsigned char T) +{ + unsigned char stk1; + unsigned char stk2; + unsigned char stk3; + stk3 = S & T; + stk2 = *D | stk3; + stk1 = T ^ stk2; + stk1 = ~stk1; + *D = (stk1 & (~S) & (~T)) | (*D & S) | (*D & T); +} + +/* TDSTaoxn source/pattern opaque. */ +static unsigned xrop3_229_0_0 (unsigned char s, unsigned char t) +{ + unsigned D = 0x00ff; + unsigned S = ((unsigned)s << 8) | s; + unsigned T = ((unsigned)t << 8) | t; + unsigned stk1; + unsigned stk2; + unsigned stk3; + stk3 = S & T; + stk2 = D | stk3; + stk1 = T ^ stk2; + stk1 = ~stk1; + return stk1; +} + +/* TDSTaoxn source opaque/pattern transparent. */ +static unsigned xrop3_229_0_1 (unsigned char s, unsigned char t) +{ + unsigned D = 0x00ff; + unsigned S = ((unsigned)s << 8) | s; + unsigned T = ((unsigned)t << 8) | t; + unsigned stk1; + unsigned stk2; + unsigned stk3; + stk3 = S & T; + stk2 = D | stk3; + stk1 = T ^ stk2; + stk1 = ~stk1; + return (stk1 & S) | (stk1 & (~T)) | (T & (~S) & D); +} + +/* TDSTaoxn source transparent/pattern opaque. */ +static unsigned xrop3_229_1_0 (unsigned char s, unsigned char t) +{ + unsigned D = 0x00ff; + unsigned S = ((unsigned)s << 8) | s; + unsigned T = ((unsigned)t << 8) | t; + unsigned stk1; + unsigned stk2; + unsigned stk3; + stk3 = S & T; + stk2 = D | stk3; + stk1 = T ^ stk2; + stk1 = ~stk1; + return (stk1 & (~S)) | (D & S); +} + +/* TDSTaoxn source/pattern transparent. */ +static unsigned xrop3_229_1_1 (unsigned char s, unsigned char t) +{ + unsigned D = 0x00ff; + unsigned S = ((unsigned)s << 8) | s; + unsigned T = ((unsigned)t << 8) | t; + unsigned stk1; + unsigned stk2; + unsigned stk3; + stk3 = S & T; + stk2 = D | stk3; + stk1 = T ^ stk2; + stk1 = ~stk1; + return (stk1 & (~S) & (~T)) | (D & S) | (D & T); +} + +/* SDTSanax source/pattern opaque. */ +static void rop3_230_0_0 (unsigned char *D, unsigned char S, unsigned char T) +{ + unsigned char stk1; + unsigned char stk2; + unsigned char stk3; + stk3 = T & S; + stk3 = ~stk3; + stk2 = *D & stk3; + stk1 = S ^ stk2; + *D = stk1; +} + +/* SDTSanax source opaque/pattern transparent. */ +static void rop3_230_0_1 (unsigned char *D, unsigned char S, unsigned char T) +{ + unsigned char stk1; + unsigned char stk2; + unsigned char stk3; + stk3 = T & S; + stk3 = ~stk3; + stk2 = *D & stk3; + stk1 = S ^ stk2; + *D = (stk1 & S) | (stk1 & (~T)) | (T & (~S) & *D); +} + +/* SDTSanax source transparent/pattern opaque. */ +static void rop3_230_1_0 (unsigned char *D, unsigned char S, unsigned char T) +{ + unsigned char stk1; + unsigned char stk2; + unsigned char stk3; + stk3 = T & S; + stk3 = ~stk3; + stk2 = *D & stk3; + stk1 = S ^ stk2; + *D = (stk1 & (~S)) | (*D & S); +} + +/* SDTSanax source/pattern transparent. */ +static void rop3_230_1_1 (unsigned char *D, unsigned char S, unsigned char T) +{ + unsigned char stk1; + unsigned char stk2; + unsigned char stk3; + stk3 = T & S; + stk3 = ~stk3; + stk2 = *D & stk3; + stk1 = S ^ stk2; + *D = (stk1 & (~S) & (~T)) | (*D & S) | (*D & T); +} + +/* SDTSanax source/pattern opaque. */ +static unsigned xrop3_230_0_0 (unsigned char s, unsigned char t) +{ + unsigned D = 0x00ff; + unsigned S = ((unsigned)s << 8) | s; + unsigned T = ((unsigned)t << 8) | t; + unsigned stk1; + unsigned stk2; + unsigned stk3; + stk3 = T & S; + stk3 = ~stk3; + stk2 = D & stk3; + stk1 = S ^ stk2; + return stk1; +} + +/* SDTSanax source opaque/pattern transparent. */ +static unsigned xrop3_230_0_1 (unsigned char s, unsigned char t) +{ + unsigned D = 0x00ff; + unsigned S = ((unsigned)s << 8) | s; + unsigned T = ((unsigned)t << 8) | t; + unsigned stk1; + unsigned stk2; + unsigned stk3; + stk3 = T & S; + stk3 = ~stk3; + stk2 = D & stk3; + stk1 = S ^ stk2; + return (stk1 & S) | (stk1 & (~T)) | (T & (~S) & D); +} + +/* SDTSanax source transparent/pattern opaque. */ +static unsigned xrop3_230_1_0 (unsigned char s, unsigned char t) +{ + unsigned D = 0x00ff; + unsigned S = ((unsigned)s << 8) | s; + unsigned T = ((unsigned)t << 8) | t; + unsigned stk1; + unsigned stk2; + unsigned stk3; + stk3 = T & S; + stk3 = ~stk3; + stk2 = D & stk3; + stk1 = S ^ stk2; + return (stk1 & (~S)) | (D & S); +} + +/* SDTSanax source/pattern transparent. */ +static unsigned xrop3_230_1_1 (unsigned char s, unsigned char t) +{ + unsigned D = 0x00ff; + unsigned S = ((unsigned)s << 8) | s; + unsigned T = ((unsigned)t << 8) | t; + unsigned stk1; + unsigned stk2; + unsigned stk3; + stk3 = T & S; + stk3 = ~stk3; + stk2 = D & stk3; + stk1 = S ^ stk2; + return (stk1 & (~S) & (~T)) | (D & S) | (D & T); +} + +/* STxTDxan source/pattern opaque. */ +static void rop3_231_0_0 (unsigned char *D, unsigned char S, unsigned char T) +{ + unsigned char stk1; + unsigned char stk2; + stk1 = S ^ T; + stk2 = T ^ *D; + stk1 = stk1 & stk2; + stk1 = ~stk1; + *D = stk1; +} + +/* STxTDxan source opaque/pattern transparent. */ +static void rop3_231_0_1 (unsigned char *D, unsigned char S, unsigned char T) +{ + unsigned char stk1; + unsigned char stk2; + stk1 = S ^ T; + stk2 = T ^ *D; + stk1 = stk1 & stk2; + stk1 = ~stk1; + *D = (stk1 & S) | (stk1 & (~T)) | (T & (~S) & *D); +} + +/* STxTDxan source transparent/pattern opaque. */ +static void rop3_231_1_0 (unsigned char *D, unsigned char S, unsigned char T) +{ + unsigned char stk1; + unsigned char stk2; + stk1 = S ^ T; + stk2 = T ^ *D; + stk1 = stk1 & stk2; + stk1 = ~stk1; + *D = (stk1 & (~S)) | (*D & S); +} + +/* STxTDxan source/pattern transparent. */ +static void rop3_231_1_1 (unsigned char *D, unsigned char S, unsigned char T) +{ + unsigned char stk1; + unsigned char stk2; + stk1 = S ^ T; + stk2 = T ^ *D; + stk1 = stk1 & stk2; + stk1 = ~stk1; + *D = (stk1 & (~S) & (~T)) | (*D & S) | (*D & T); +} + +/* STxTDxan source/pattern opaque. */ +static unsigned xrop3_231_0_0 (unsigned char s, unsigned char t) +{ + unsigned D = 0x00ff; + unsigned S = ((unsigned)s << 8) | s; + unsigned T = ((unsigned)t << 8) | t; + unsigned stk1; + unsigned stk2; + stk1 = S ^ T; + stk2 = T ^ D; + stk1 = stk1 & stk2; + stk1 = ~stk1; + return stk1; +} + +/* STxTDxan source opaque/pattern transparent. */ +static unsigned xrop3_231_0_1 (unsigned char s, unsigned char t) +{ + unsigned D = 0x00ff; + unsigned S = ((unsigned)s << 8) | s; + unsigned T = ((unsigned)t << 8) | t; + unsigned stk1; + unsigned stk2; + stk1 = S ^ T; + stk2 = T ^ D; + stk1 = stk1 & stk2; + stk1 = ~stk1; + return (stk1 & S) | (stk1 & (~T)) | (T & (~S) & D); +} + +/* STxTDxan source transparent/pattern opaque. */ +static unsigned xrop3_231_1_0 (unsigned char s, unsigned char t) +{ + unsigned D = 0x00ff; + unsigned S = ((unsigned)s << 8) | s; + unsigned T = ((unsigned)t << 8) | t; + unsigned stk1; + unsigned stk2; + stk1 = S ^ T; + stk2 = T ^ D; + stk1 = stk1 & stk2; + stk1 = ~stk1; + return (stk1 & (~S)) | (D & S); +} + +/* STxTDxan source/pattern transparent. */ +static unsigned xrop3_231_1_1 (unsigned char s, unsigned char t) +{ + unsigned D = 0x00ff; + unsigned S = ((unsigned)s << 8) | s; + unsigned T = ((unsigned)t << 8) | t; + unsigned stk1; + unsigned stk2; + stk1 = S ^ T; + stk2 = T ^ D; + stk1 = stk1 & stk2; + stk1 = ~stk1; + return (stk1 & (~S) & (~T)) | (D & S) | (D & T); +} + +/* SSTxDSxax source/pattern opaque. */ +static void rop3_232_0_0 (unsigned char *D, unsigned char S, unsigned char T) +{ + unsigned char stk1; + unsigned char stk2; + unsigned char stk3; + stk2 = S ^ T; + stk3 = *D ^ S; + stk2 = stk2 & stk3; + stk1 = S ^ stk2; + *D = stk1; +} + +/* SSTxDSxax source opaque/pattern transparent. */ +static void rop3_232_0_1 (unsigned char *D, unsigned char S, unsigned char T) +{ + unsigned char stk1; + unsigned char stk2; + unsigned char stk3; + stk2 = S ^ T; + stk3 = *D ^ S; + stk2 = stk2 & stk3; + stk1 = S ^ stk2; + *D = (stk1 & S) | (stk1 & (~T)) | (T & (~S) & *D); +} + +/* SSTxDSxax source transparent/pattern opaque. */ +static void rop3_232_1_0 (unsigned char *D, unsigned char S, unsigned char T) +{ + unsigned char stk1; + unsigned char stk2; + unsigned char stk3; + stk2 = S ^ T; + stk3 = *D ^ S; + stk2 = stk2 & stk3; + stk1 = S ^ stk2; + *D = (stk1 & (~S)) | (*D & S); +} + +/* SSTxDSxax source/pattern transparent. */ +static void rop3_232_1_1 (unsigned char *D, unsigned char S, unsigned char T) +{ + unsigned char stk1; + unsigned char stk2; + unsigned char stk3; + stk2 = S ^ T; + stk3 = *D ^ S; + stk2 = stk2 & stk3; + stk1 = S ^ stk2; + *D = (stk1 & (~S) & (~T)) | (*D & S) | (*D & T); +} + +/* SSTxDSxax source/pattern opaque. */ +static unsigned xrop3_232_0_0 (unsigned char s, unsigned char t) +{ + unsigned D = 0x00ff; + unsigned S = ((unsigned)s << 8) | s; + unsigned T = ((unsigned)t << 8) | t; + unsigned stk1; + unsigned stk2; + unsigned stk3; + stk2 = S ^ T; + stk3 = D ^ S; + stk2 = stk2 & stk3; + stk1 = S ^ stk2; + return stk1; +} + +/* SSTxDSxax source opaque/pattern transparent. */ +static unsigned xrop3_232_0_1 (unsigned char s, unsigned char t) +{ + unsigned D = 0x00ff; + unsigned S = ((unsigned)s << 8) | s; + unsigned T = ((unsigned)t << 8) | t; + unsigned stk1; + unsigned stk2; + unsigned stk3; + stk2 = S ^ T; + stk3 = D ^ S; + stk2 = stk2 & stk3; + stk1 = S ^ stk2; + return (stk1 & S) | (stk1 & (~T)) | (T & (~S) & D); +} + +/* SSTxDSxax source transparent/pattern opaque. */ +static unsigned xrop3_232_1_0 (unsigned char s, unsigned char t) +{ + unsigned D = 0x00ff; + unsigned S = ((unsigned)s << 8) | s; + unsigned T = ((unsigned)t << 8) | t; + unsigned stk1; + unsigned stk2; + unsigned stk3; + stk2 = S ^ T; + stk3 = D ^ S; + stk2 = stk2 & stk3; + stk1 = S ^ stk2; + return (stk1 & (~S)) | (D & S); +} + +/* SSTxDSxax source/pattern transparent. */ +static unsigned xrop3_232_1_1 (unsigned char s, unsigned char t) +{ + unsigned D = 0x00ff; + unsigned S = ((unsigned)s << 8) | s; + unsigned T = ((unsigned)t << 8) | t; + unsigned stk1; + unsigned stk2; + unsigned stk3; + stk2 = S ^ T; + stk3 = D ^ S; + stk2 = stk2 & stk3; + stk1 = S ^ stk2; + return (stk1 & (~S) & (~T)) | (D & S) | (D & T); +} + +/* DSTDSanaxxn source/pattern opaque. */ +static void rop3_233_0_0 (unsigned char *D, unsigned char S, unsigned char T) +{ + unsigned char stk1; + unsigned char stk2; + unsigned char stk3; + unsigned char stk4; + stk4 = *D & S; + stk4 = ~stk4; + stk3 = T & stk4; + stk2 = S ^ stk3; + stk1 = *D ^ stk2; + stk1 = ~stk1; + *D = stk1; +} + +/* DSTDSanaxxn source opaque/pattern transparent. */ +static void rop3_233_0_1 (unsigned char *D, unsigned char S, unsigned char T) +{ + unsigned char stk1; + unsigned char stk2; + unsigned char stk3; + unsigned char stk4; + stk4 = *D & S; + stk4 = ~stk4; + stk3 = T & stk4; + stk2 = S ^ stk3; + stk1 = *D ^ stk2; + stk1 = ~stk1; + *D = (stk1 & S) | (stk1 & (~T)) | (T & (~S) & *D); +} + +/* DSTDSanaxxn source transparent/pattern opaque. */ +static void rop3_233_1_0 (unsigned char *D, unsigned char S, unsigned char T) +{ + unsigned char stk1; + unsigned char stk2; + unsigned char stk3; + unsigned char stk4; + stk4 = *D & S; + stk4 = ~stk4; + stk3 = T & stk4; + stk2 = S ^ stk3; + stk1 = *D ^ stk2; + stk1 = ~stk1; + *D = (stk1 & (~S)) | (*D & S); +} + +/* DSTDSanaxxn source/pattern transparent. */ +static void rop3_233_1_1 (unsigned char *D, unsigned char S, unsigned char T) +{ + unsigned char stk1; + unsigned char stk2; + unsigned char stk3; + unsigned char stk4; + stk4 = *D & S; + stk4 = ~stk4; + stk3 = T & stk4; + stk2 = S ^ stk3; + stk1 = *D ^ stk2; + stk1 = ~stk1; + *D = (stk1 & (~S) & (~T)) | (*D & S) | (*D & T); +} + +/* DSTDSanaxxn source/pattern opaque. */ +static unsigned xrop3_233_0_0 (unsigned char s, unsigned char t) +{ + unsigned D = 0x00ff; + unsigned S = ((unsigned)s << 8) | s; + unsigned T = ((unsigned)t << 8) | t; + unsigned stk1; + unsigned stk2; + unsigned stk3; + unsigned stk4; + stk4 = D & S; + stk4 = ~stk4; + stk3 = T & stk4; + stk2 = S ^ stk3; + stk1 = D ^ stk2; + stk1 = ~stk1; + return stk1; +} + +/* DSTDSanaxxn source opaque/pattern transparent. */ +static unsigned xrop3_233_0_1 (unsigned char s, unsigned char t) +{ + unsigned D = 0x00ff; + unsigned S = ((unsigned)s << 8) | s; + unsigned T = ((unsigned)t << 8) | t; + unsigned stk1; + unsigned stk2; + unsigned stk3; + unsigned stk4; + stk4 = D & S; + stk4 = ~stk4; + stk3 = T & stk4; + stk2 = S ^ stk3; + stk1 = D ^ stk2; + stk1 = ~stk1; + return (stk1 & S) | (stk1 & (~T)) | (T & (~S) & D); +} + +/* DSTDSanaxxn source transparent/pattern opaque. */ +static unsigned xrop3_233_1_0 (unsigned char s, unsigned char t) +{ + unsigned D = 0x00ff; + unsigned S = ((unsigned)s << 8) | s; + unsigned T = ((unsigned)t << 8) | t; + unsigned stk1; + unsigned stk2; + unsigned stk3; + unsigned stk4; + stk4 = D & S; + stk4 = ~stk4; + stk3 = T & stk4; + stk2 = S ^ stk3; + stk1 = D ^ stk2; + stk1 = ~stk1; + return (stk1 & (~S)) | (D & S); +} + +/* DSTDSanaxxn source/pattern transparent. */ +static unsigned xrop3_233_1_1 (unsigned char s, unsigned char t) +{ + unsigned D = 0x00ff; + unsigned S = ((unsigned)s << 8) | s; + unsigned T = ((unsigned)t << 8) | t; + unsigned stk1; + unsigned stk2; + unsigned stk3; + unsigned stk4; + stk4 = D & S; + stk4 = ~stk4; + stk3 = T & stk4; + stk2 = S ^ stk3; + stk1 = D ^ stk2; + stk1 = ~stk1; + return (stk1 & (~S) & (~T)) | (D & S) | (D & T); +} + +/* DTSao source/pattern opaque. */ +static void rop3_234_0_0 (unsigned char *D, unsigned char S, unsigned char T) +{ + unsigned char stk1; + unsigned char stk2; + stk2 = T & S; + stk1 = *D | stk2; + *D = stk1; +} + +/* DTSao source opaque/pattern transparent. */ +static void rop3_234_0_1 (unsigned char *D, unsigned char S, unsigned char T) +{ + unsigned char stk1; + unsigned char stk2; + stk2 = T & S; + stk1 = *D | stk2; + *D = (stk1 & S) | (stk1 & (~T)) | (T & (~S) & *D); +} + +/* DTSao source transparent/pattern opaque. */ +static void rop3_234_1_0 (unsigned char *D, unsigned char S, unsigned char T) +{ + unsigned char stk1; + unsigned char stk2; + stk2 = T & S; + stk1 = *D | stk2; + *D = (stk1 & (~S)) | (*D & S); +} + +/* DTSao source/pattern transparent. */ +static void rop3_234_1_1 (unsigned char *D, unsigned char S, unsigned char T) +{ + unsigned char stk1; + unsigned char stk2; + stk2 = T & S; + stk1 = *D | stk2; + *D = (stk1 & (~S) & (~T)) | (*D & S) | (*D & T); +} + +/* DTSao source/pattern opaque. */ +static unsigned xrop3_234_0_0 (unsigned char s, unsigned char t) +{ + unsigned D = 0x00ff; + unsigned S = ((unsigned)s << 8) | s; + unsigned T = ((unsigned)t << 8) | t; + unsigned stk1; + unsigned stk2; + stk2 = T & S; + stk1 = D | stk2; + return stk1; +} + +/* DTSao source opaque/pattern transparent. */ +static unsigned xrop3_234_0_1 (unsigned char s, unsigned char t) +{ + unsigned D = 0x00ff; + unsigned S = ((unsigned)s << 8) | s; + unsigned T = ((unsigned)t << 8) | t; + unsigned stk1; + unsigned stk2; + stk2 = T & S; + stk1 = D | stk2; + return (stk1 & S) | (stk1 & (~T)) | (T & (~S) & D); +} + +/* DTSao source transparent/pattern opaque. */ +static unsigned xrop3_234_1_0 (unsigned char s, unsigned char t) +{ + unsigned D = 0x00ff; + unsigned S = ((unsigned)s << 8) | s; + unsigned T = ((unsigned)t << 8) | t; + unsigned stk1; + unsigned stk2; + stk2 = T & S; + stk1 = D | stk2; + return (stk1 & (~S)) | (D & S); +} + +/* DTSao source/pattern transparent. */ +static unsigned xrop3_234_1_1 (unsigned char s, unsigned char t) +{ + unsigned D = 0x00ff; + unsigned S = ((unsigned)s << 8) | s; + unsigned T = ((unsigned)t << 8) | t; + unsigned stk1; + unsigned stk2; + stk2 = T & S; + stk1 = D | stk2; + return (stk1 & (~S) & (~T)) | (D & S) | (D & T); +} + +/* DTSxno source/pattern opaque. */ +static void rop3_235_0_0 (unsigned char *D, unsigned char S, unsigned char T) +{ + unsigned char stk1; + unsigned char stk2; + stk2 = T ^ S; + stk2 = ~stk2; + stk1 = *D | stk2; + *D = stk1; +} + +/* DTSxno source opaque/pattern transparent. */ +static void rop3_235_0_1 (unsigned char *D, unsigned char S, unsigned char T) +{ + unsigned char stk1; + unsigned char stk2; + stk2 = T ^ S; + stk2 = ~stk2; + stk1 = *D | stk2; + *D = (stk1 & S) | (stk1 & (~T)) | (T & (~S) & *D); +} + +/* DTSxno source transparent/pattern opaque. */ +static void rop3_235_1_0 (unsigned char *D, unsigned char S, unsigned char T) +{ + unsigned char stk1; + unsigned char stk2; + stk2 = T ^ S; + stk2 = ~stk2; + stk1 = *D | stk2; + *D = (stk1 & (~S)) | (*D & S); +} + +/* DTSxno source/pattern transparent. */ +static void rop3_235_1_1 (unsigned char *D, unsigned char S, unsigned char T) +{ + unsigned char stk1; + unsigned char stk2; + stk2 = T ^ S; + stk2 = ~stk2; + stk1 = *D | stk2; + *D = (stk1 & (~S) & (~T)) | (*D & S) | (*D & T); +} + +/* DTSxno source/pattern opaque. */ +static unsigned xrop3_235_0_0 (unsigned char s, unsigned char t) +{ + unsigned D = 0x00ff; + unsigned S = ((unsigned)s << 8) | s; + unsigned T = ((unsigned)t << 8) | t; + unsigned stk1; + unsigned stk2; + stk2 = T ^ S; + stk2 = ~stk2; + stk1 = D | stk2; + return stk1; +} + +/* DTSxno source opaque/pattern transparent. */ +static unsigned xrop3_235_0_1 (unsigned char s, unsigned char t) +{ + unsigned D = 0x00ff; + unsigned S = ((unsigned)s << 8) | s; + unsigned T = ((unsigned)t << 8) | t; + unsigned stk1; + unsigned stk2; + stk2 = T ^ S; + stk2 = ~stk2; + stk1 = D | stk2; + return (stk1 & S) | (stk1 & (~T)) | (T & (~S) & D); +} + +/* DTSxno source transparent/pattern opaque. */ +static unsigned xrop3_235_1_0 (unsigned char s, unsigned char t) +{ + unsigned D = 0x00ff; + unsigned S = ((unsigned)s << 8) | s; + unsigned T = ((unsigned)t << 8) | t; + unsigned stk1; + unsigned stk2; + stk2 = T ^ S; + stk2 = ~stk2; + stk1 = D | stk2; + return (stk1 & (~S)) | (D & S); +} + +/* DTSxno source/pattern transparent. */ +static unsigned xrop3_235_1_1 (unsigned char s, unsigned char t) +{ + unsigned D = 0x00ff; + unsigned S = ((unsigned)s << 8) | s; + unsigned T = ((unsigned)t << 8) | t; + unsigned stk1; + unsigned stk2; + stk2 = T ^ S; + stk2 = ~stk2; + stk1 = D | stk2; + return (stk1 & (~S) & (~T)) | (D & S) | (D & T); +} + +/* SDTao source/pattern opaque. */ +static void rop3_236_0_0 (unsigned char *D, unsigned char S, unsigned char T) +{ + unsigned char stk1; + unsigned char stk2; + stk2 = *D & T; + stk1 = S | stk2; + *D = stk1; +} + +/* SDTao source opaque/pattern transparent. */ +static void rop3_236_0_1 (unsigned char *D, unsigned char S, unsigned char T) +{ + unsigned char stk1; + unsigned char stk2; + stk2 = *D & T; + stk1 = S | stk2; + *D = (stk1 & S) | (stk1 & (~T)) | (T & (~S) & *D); +} + +/* SDTao source transparent/pattern opaque. */ +static void rop3_236_1_0 (unsigned char *D, unsigned char S, unsigned char T) +{ + unsigned char stk1; + unsigned char stk2; + stk2 = *D & T; + stk1 = S | stk2; + *D = (stk1 & (~S)) | (*D & S); +} + +/* SDTao source/pattern transparent. */ +static void rop3_236_1_1 (unsigned char *D, unsigned char S, unsigned char T) +{ + unsigned char stk1; + unsigned char stk2; + stk2 = *D & T; + stk1 = S | stk2; + *D = (stk1 & (~S) & (~T)) | (*D & S) | (*D & T); +} + +/* SDTao source/pattern opaque. */ +static unsigned xrop3_236_0_0 (unsigned char s, unsigned char t) +{ + unsigned D = 0x00ff; + unsigned S = ((unsigned)s << 8) | s; + unsigned T = ((unsigned)t << 8) | t; + unsigned stk1; + unsigned stk2; + stk2 = D & T; + stk1 = S | stk2; + return stk1; +} + +/* SDTao source opaque/pattern transparent. */ +static unsigned xrop3_236_0_1 (unsigned char s, unsigned char t) +{ + unsigned D = 0x00ff; + unsigned S = ((unsigned)s << 8) | s; + unsigned T = ((unsigned)t << 8) | t; + unsigned stk1; + unsigned stk2; + stk2 = D & T; + stk1 = S | stk2; + return (stk1 & S) | (stk1 & (~T)) | (T & (~S) & D); +} + +/* SDTao source transparent/pattern opaque. */ +static unsigned xrop3_236_1_0 (unsigned char s, unsigned char t) +{ + unsigned D = 0x00ff; + unsigned S = ((unsigned)s << 8) | s; + unsigned T = ((unsigned)t << 8) | t; + unsigned stk1; + unsigned stk2; + stk2 = D & T; + stk1 = S | stk2; + return (stk1 & (~S)) | (D & S); +} + +/* SDTao source/pattern transparent. */ +static unsigned xrop3_236_1_1 (unsigned char s, unsigned char t) +{ + unsigned D = 0x00ff; + unsigned S = ((unsigned)s << 8) | s; + unsigned T = ((unsigned)t << 8) | t; + unsigned stk1; + unsigned stk2; + stk2 = D & T; + stk1 = S | stk2; + return (stk1 & (~S) & (~T)) | (D & S) | (D & T); +} + +/* SDTxno source/pattern opaque. */ +static void rop3_237_0_0 (unsigned char *D, unsigned char S, unsigned char T) +{ + unsigned char stk1; + unsigned char stk2; + stk2 = *D ^ T; + stk2 = ~stk2; + stk1 = S | stk2; + *D = stk1; +} + +/* SDTxno source opaque/pattern transparent. */ +static void rop3_237_0_1 (unsigned char *D, unsigned char S, unsigned char T) +{ + unsigned char stk1; + unsigned char stk2; + stk2 = *D ^ T; + stk2 = ~stk2; + stk1 = S | stk2; + *D = (stk1 & S) | (stk1 & (~T)) | (T & (~S) & *D); +} + +/* SDTxno source transparent/pattern opaque. */ +static void rop3_237_1_0 (unsigned char *D, unsigned char S, unsigned char T) +{ + unsigned char stk1; + unsigned char stk2; + stk2 = *D ^ T; + stk2 = ~stk2; + stk1 = S | stk2; + *D = (stk1 & (~S)) | (*D & S); +} + +/* SDTxno source/pattern transparent. */ +static void rop3_237_1_1 (unsigned char *D, unsigned char S, unsigned char T) +{ + unsigned char stk1; + unsigned char stk2; + stk2 = *D ^ T; + stk2 = ~stk2; + stk1 = S | stk2; + *D = (stk1 & (~S) & (~T)) | (*D & S) | (*D & T); +} + +/* SDTxno source/pattern opaque. */ +static unsigned xrop3_237_0_0 (unsigned char s, unsigned char t) +{ + unsigned D = 0x00ff; + unsigned S = ((unsigned)s << 8) | s; + unsigned T = ((unsigned)t << 8) | t; + unsigned stk1; + unsigned stk2; + stk2 = D ^ T; + stk2 = ~stk2; + stk1 = S | stk2; + return stk1; +} + +/* SDTxno source opaque/pattern transparent. */ +static unsigned xrop3_237_0_1 (unsigned char s, unsigned char t) +{ + unsigned D = 0x00ff; + unsigned S = ((unsigned)s << 8) | s; + unsigned T = ((unsigned)t << 8) | t; + unsigned stk1; + unsigned stk2; + stk2 = D ^ T; + stk2 = ~stk2; + stk1 = S | stk2; + return (stk1 & S) | (stk1 & (~T)) | (T & (~S) & D); +} + +/* SDTxno source transparent/pattern opaque. */ +static unsigned xrop3_237_1_0 (unsigned char s, unsigned char t) +{ + unsigned D = 0x00ff; + unsigned S = ((unsigned)s << 8) | s; + unsigned T = ((unsigned)t << 8) | t; + unsigned stk1; + unsigned stk2; + stk2 = D ^ T; + stk2 = ~stk2; + stk1 = S | stk2; + return (stk1 & (~S)) | (D & S); +} + +/* SDTxno source/pattern transparent. */ +static unsigned xrop3_237_1_1 (unsigned char s, unsigned char t) +{ + unsigned D = 0x00ff; + unsigned S = ((unsigned)s << 8) | s; + unsigned T = ((unsigned)t << 8) | t; + unsigned stk1; + unsigned stk2; + stk2 = D ^ T; + stk2 = ~stk2; + stk1 = S | stk2; + return (stk1 & (~S) & (~T)) | (D & S) | (D & T); +} + +/* DSo source/pattern opaque. */ +static void rop3_238_0_0 (unsigned char *D, unsigned char S, unsigned char T) +{ + unsigned char stk1; + stk1 = *D | S; + *D = stk1; +} + +/* DSo source opaque/pattern transparent. */ +static void rop3_238_0_1 (unsigned char *D, unsigned char S, unsigned char T) +{ + unsigned char stk1; + stk1 = *D | S; + *D = (stk1 & S) | (stk1 & (~T)) | (T & (~S) & *D); +} + +/* DSo source transparent/pattern opaque. */ +static void rop3_238_1_0 (unsigned char *D, unsigned char S, unsigned char T) +{ + unsigned char stk1; + stk1 = *D | S; + *D = (stk1 & (~S)) | (*D & S); +} + +/* DSo source/pattern transparent. */ +static void rop3_238_1_1 (unsigned char *D, unsigned char S, unsigned char T) +{ + unsigned char stk1; + stk1 = *D | S; + *D = (stk1 & (~S) & (~T)) | (*D & S) | (*D & T); +} + +/* DSo source/pattern opaque. */ +static unsigned xrop3_238_0_0 (unsigned char s, unsigned char t) +{ + unsigned D = 0x00ff; + unsigned S = ((unsigned)s << 8) | s; + unsigned stk1; + stk1 = D | S; + return stk1; +} + +/* DSo source opaque/pattern transparent. */ +static unsigned xrop3_238_0_1 (unsigned char s, unsigned char t) +{ + unsigned D = 0x00ff; + unsigned S = ((unsigned)s << 8) | s; + unsigned T = ((unsigned)t << 8) | t; + unsigned stk1; + stk1 = D | S; + return (stk1 & S) | (stk1 & (~T)) | (T & (~S) & D); +} + +/* DSo source transparent/pattern opaque. */ +static unsigned xrop3_238_1_0 (unsigned char s, unsigned char t) +{ + unsigned D = 0x00ff; + unsigned S = ((unsigned)s << 8) | s; + unsigned stk1; + stk1 = D | S; + return (stk1 & (~S)) | (D & S); +} + +/* DSo source/pattern transparent. */ +static unsigned xrop3_238_1_1 (unsigned char s, unsigned char t) +{ + unsigned D = 0x00ff; + unsigned S = ((unsigned)s << 8) | s; + unsigned T = ((unsigned)t << 8) | t; + unsigned stk1; + stk1 = D | S; + return (stk1 & (~S) & (~T)) | (D & S) | (D & T); +} + +/* SDTnoo source/pattern opaque. */ +static void rop3_239_0_0 (unsigned char *D, unsigned char S, unsigned char T) +{ + unsigned char stk1; + unsigned char stk2; + unsigned char stk3; + stk3 = ~T; + stk2 = *D | stk3; + stk1 = S | stk2; + *D = stk1; +} + +/* SDTnoo source opaque/pattern transparent. */ +static void rop3_239_0_1 (unsigned char *D, unsigned char S, unsigned char T) +{ + unsigned char stk1; + unsigned char stk2; + unsigned char stk3; + stk3 = ~T; + stk2 = *D | stk3; + stk1 = S | stk2; + *D = (stk1 & S) | (stk1 & (~T)) | (T & (~S) & *D); +} + +/* SDTnoo source transparent/pattern opaque. */ +static void rop3_239_1_0 (unsigned char *D, unsigned char S, unsigned char T) +{ + unsigned char stk1; + unsigned char stk2; + unsigned char stk3; + stk3 = ~T; + stk2 = *D | stk3; + stk1 = S | stk2; + *D = (stk1 & (~S)) | (*D & S); +} + +/* SDTnoo source/pattern transparent. */ +static void rop3_239_1_1 (unsigned char *D, unsigned char S, unsigned char T) +{ + unsigned char stk1; + unsigned char stk2; + unsigned char stk3; + stk3 = ~T; + stk2 = *D | stk3; + stk1 = S | stk2; + *D = (stk1 & (~S) & (~T)) | (*D & S) | (*D & T); +} + +/* SDTnoo source/pattern opaque. */ +static unsigned xrop3_239_0_0 (unsigned char s, unsigned char t) +{ + unsigned D = 0x00ff; + unsigned S = ((unsigned)s << 8) | s; + unsigned T = ((unsigned)t << 8) | t; + unsigned stk1; + unsigned stk2; + unsigned stk3; + stk3 = ~T; + stk2 = D | stk3; + stk1 = S | stk2; + return stk1; +} + +/* SDTnoo source opaque/pattern transparent. */ +static unsigned xrop3_239_0_1 (unsigned char s, unsigned char t) +{ + unsigned D = 0x00ff; + unsigned S = ((unsigned)s << 8) | s; + unsigned T = ((unsigned)t << 8) | t; + unsigned stk1; + unsigned stk2; + unsigned stk3; + stk3 = ~T; + stk2 = D | stk3; + stk1 = S | stk2; + return (stk1 & S) | (stk1 & (~T)) | (T & (~S) & D); +} + +/* SDTnoo source transparent/pattern opaque. */ +static unsigned xrop3_239_1_0 (unsigned char s, unsigned char t) +{ + unsigned D = 0x00ff; + unsigned S = ((unsigned)s << 8) | s; + unsigned T = ((unsigned)t << 8) | t; + unsigned stk1; + unsigned stk2; + unsigned stk3; + stk3 = ~T; + stk2 = D | stk3; + stk1 = S | stk2; + return (stk1 & (~S)) | (D & S); +} + +/* SDTnoo source/pattern transparent. */ +static unsigned xrop3_239_1_1 (unsigned char s, unsigned char t) +{ + unsigned D = 0x00ff; + unsigned S = ((unsigned)s << 8) | s; + unsigned T = ((unsigned)t << 8) | t; + unsigned stk1; + unsigned stk2; + unsigned stk3; + stk3 = ~T; + stk2 = D | stk3; + stk1 = S | stk2; + return (stk1 & (~S) & (~T)) | (D & S) | (D & T); +} + +/* T source/pattern opaque. */ +static void rop3_240_0_0 (unsigned char *D, unsigned char S, unsigned char T) +{ + *D = T; +} + +/* T source opaque/pattern transparent. */ +static void rop3_240_0_1 (unsigned char *D, unsigned char S, unsigned char T) +{ + *D = (T & S) | (T & (~T)) | (T & (~S) & *D); +} + +/* T source transparent/pattern opaque. */ +static void rop3_240_1_0 (unsigned char *D, unsigned char S, unsigned char T) +{ + *D = (T & (~S)) | (*D & S); +} + +/* T source/pattern transparent. */ +static void rop3_240_1_1 (unsigned char *D, unsigned char S, unsigned char T) +{ + *D = (T & (~S) & (~T)) | (*D & S) | (*D & T); +} + +/* T source/pattern opaque. */ +static unsigned xrop3_240_0_0 (unsigned char s, unsigned char t) +{ + unsigned T = ((unsigned)t << 8) | t; + return T; +} + +/* T source opaque/pattern transparent. */ +static unsigned xrop3_240_0_1 (unsigned char s, unsigned char t) +{ + unsigned D = 0x00ff; + unsigned S = ((unsigned)s << 8) | s; + unsigned T = ((unsigned)t << 8) | t; + return (T & S) | (T & (~T)) | (T & (~S) & D); +} + +/* T source transparent/pattern opaque. */ +static unsigned xrop3_240_1_0 (unsigned char s, unsigned char t) +{ + unsigned D = 0x00ff; + unsigned S = ((unsigned)s << 8) | s; + unsigned T = ((unsigned)t << 8) | t; + return (T & (~S)) | (D & S); +} + +/* T source/pattern transparent. */ +static unsigned xrop3_240_1_1 (unsigned char s, unsigned char t) +{ + unsigned D = 0x00ff; + unsigned S = ((unsigned)s << 8) | s; + unsigned T = ((unsigned)t << 8) | t; + return (T & (~S) & (~T)) | (D & S) | (D & T); +} + +/* TDSono source/pattern opaque. */ +static void rop3_241_0_0 (unsigned char *D, unsigned char S, unsigned char T) +{ + unsigned char stk1; + unsigned char stk2; + stk2 = *D | S; + stk2 = ~stk2; + stk1 = T | stk2; + *D = stk1; +} + +/* TDSono source opaque/pattern transparent. */ +static void rop3_241_0_1 (unsigned char *D, unsigned char S, unsigned char T) +{ + unsigned char stk1; + unsigned char stk2; + stk2 = *D | S; + stk2 = ~stk2; + stk1 = T | stk2; + *D = (stk1 & S) | (stk1 & (~T)) | (T & (~S) & *D); +} + +/* TDSono source transparent/pattern opaque. */ +static void rop3_241_1_0 (unsigned char *D, unsigned char S, unsigned char T) +{ + unsigned char stk1; + unsigned char stk2; + stk2 = *D | S; + stk2 = ~stk2; + stk1 = T | stk2; + *D = (stk1 & (~S)) | (*D & S); +} + +/* TDSono source/pattern transparent. */ +static void rop3_241_1_1 (unsigned char *D, unsigned char S, unsigned char T) +{ + unsigned char stk1; + unsigned char stk2; + stk2 = *D | S; + stk2 = ~stk2; + stk1 = T | stk2; + *D = (stk1 & (~S) & (~T)) | (*D & S) | (*D & T); +} + +/* TDSono source/pattern opaque. */ +static unsigned xrop3_241_0_0 (unsigned char s, unsigned char t) +{ + unsigned D = 0x00ff; + unsigned S = ((unsigned)s << 8) | s; + unsigned T = ((unsigned)t << 8) | t; + unsigned stk1; + unsigned stk2; + stk2 = D | S; + stk2 = ~stk2; + stk1 = T | stk2; + return stk1; +} + +/* TDSono source opaque/pattern transparent. */ +static unsigned xrop3_241_0_1 (unsigned char s, unsigned char t) +{ + unsigned D = 0x00ff; + unsigned S = ((unsigned)s << 8) | s; + unsigned T = ((unsigned)t << 8) | t; + unsigned stk1; + unsigned stk2; + stk2 = D | S; + stk2 = ~stk2; + stk1 = T | stk2; + return (stk1 & S) | (stk1 & (~T)) | (T & (~S) & D); +} + +/* TDSono source transparent/pattern opaque. */ +static unsigned xrop3_241_1_0 (unsigned char s, unsigned char t) +{ + unsigned D = 0x00ff; + unsigned S = ((unsigned)s << 8) | s; + unsigned T = ((unsigned)t << 8) | t; + unsigned stk1; + unsigned stk2; + stk2 = D | S; + stk2 = ~stk2; + stk1 = T | stk2; + return (stk1 & (~S)) | (D & S); +} + +/* TDSono source/pattern transparent. */ +static unsigned xrop3_241_1_1 (unsigned char s, unsigned char t) +{ + unsigned D = 0x00ff; + unsigned S = ((unsigned)s << 8) | s; + unsigned T = ((unsigned)t << 8) | t; + unsigned stk1; + unsigned stk2; + stk2 = D | S; + stk2 = ~stk2; + stk1 = T | stk2; + return (stk1 & (~S) & (~T)) | (D & S) | (D & T); +} + +/* TDSnao source/pattern opaque. */ +static void rop3_242_0_0 (unsigned char *D, unsigned char S, unsigned char T) +{ + unsigned char stk1; + unsigned char stk2; + unsigned char stk3; + stk3 = ~S; + stk2 = *D & stk3; + stk1 = T | stk2; + *D = stk1; +} + +/* TDSnao source opaque/pattern transparent. */ +static void rop3_242_0_1 (unsigned char *D, unsigned char S, unsigned char T) +{ + unsigned char stk1; + unsigned char stk2; + unsigned char stk3; + stk3 = ~S; + stk2 = *D & stk3; + stk1 = T | stk2; + *D = (stk1 & S) | (stk1 & (~T)) | (T & (~S) & *D); +} + +/* TDSnao source transparent/pattern opaque. */ +static void rop3_242_1_0 (unsigned char *D, unsigned char S, unsigned char T) +{ + unsigned char stk1; + unsigned char stk2; + unsigned char stk3; + stk3 = ~S; + stk2 = *D & stk3; + stk1 = T | stk2; + *D = (stk1 & (~S)) | (*D & S); +} + +/* TDSnao source/pattern transparent. */ +static void rop3_242_1_1 (unsigned char *D, unsigned char S, unsigned char T) +{ + unsigned char stk1; + unsigned char stk2; + unsigned char stk3; + stk3 = ~S; + stk2 = *D & stk3; + stk1 = T | stk2; + *D = (stk1 & (~S) & (~T)) | (*D & S) | (*D & T); +} + +/* TDSnao source/pattern opaque. */ +static unsigned xrop3_242_0_0 (unsigned char s, unsigned char t) +{ + unsigned D = 0x00ff; + unsigned S = ((unsigned)s << 8) | s; + unsigned T = ((unsigned)t << 8) | t; + unsigned stk1; + unsigned stk2; + unsigned stk3; + stk3 = ~S; + stk2 = D & stk3; + stk1 = T | stk2; + return stk1; +} + +/* TDSnao source opaque/pattern transparent. */ +static unsigned xrop3_242_0_1 (unsigned char s, unsigned char t) +{ + unsigned D = 0x00ff; + unsigned S = ((unsigned)s << 8) | s; + unsigned T = ((unsigned)t << 8) | t; + unsigned stk1; + unsigned stk2; + unsigned stk3; + stk3 = ~S; + stk2 = D & stk3; + stk1 = T | stk2; + return (stk1 & S) | (stk1 & (~T)) | (T & (~S) & D); +} + +/* TDSnao source transparent/pattern opaque. */ +static unsigned xrop3_242_1_0 (unsigned char s, unsigned char t) +{ + unsigned D = 0x00ff; + unsigned S = ((unsigned)s << 8) | s; + unsigned T = ((unsigned)t << 8) | t; + unsigned stk1; + unsigned stk2; + unsigned stk3; + stk3 = ~S; + stk2 = D & stk3; + stk1 = T | stk2; + return (stk1 & (~S)) | (D & S); +} + +/* TDSnao source/pattern transparent. */ +static unsigned xrop3_242_1_1 (unsigned char s, unsigned char t) +{ + unsigned D = 0x00ff; + unsigned S = ((unsigned)s << 8) | s; + unsigned T = ((unsigned)t << 8) | t; + unsigned stk1; + unsigned stk2; + unsigned stk3; + stk3 = ~S; + stk2 = D & stk3; + stk1 = T | stk2; + return (stk1 & (~S) & (~T)) | (D & S) | (D & T); +} + +/* TSno source/pattern opaque. */ +static void rop3_243_0_0 (unsigned char *D, unsigned char S, unsigned char T) +{ + unsigned char stk1; + unsigned char stk2; + stk2 = ~S; + stk1 = T | stk2; + *D = stk1; +} + +/* TSno source opaque/pattern transparent. */ +static void rop3_243_0_1 (unsigned char *D, unsigned char S, unsigned char T) +{ + unsigned char stk1; + unsigned char stk2; + stk2 = ~S; + stk1 = T | stk2; + *D = (stk1 & S) | (stk1 & (~T)) | (T & (~S) & *D); +} + +/* TSno source transparent/pattern opaque. */ +static void rop3_243_1_0 (unsigned char *D, unsigned char S, unsigned char T) +{ + unsigned char stk1; + unsigned char stk2; + stk2 = ~S; + stk1 = T | stk2; + *D = (stk1 & (~S)) | (*D & S); +} + +/* TSno source/pattern transparent. */ +static void rop3_243_1_1 (unsigned char *D, unsigned char S, unsigned char T) +{ + unsigned char stk1; + unsigned char stk2; + stk2 = ~S; + stk1 = T | stk2; + *D = (stk1 & (~S) & (~T)) | (*D & S) | (*D & T); +} + +/* TSno source/pattern opaque. */ +static unsigned xrop3_243_0_0 (unsigned char s, unsigned char t) +{ + unsigned S = ((unsigned)s << 8) | s; + unsigned T = ((unsigned)t << 8) | t; + unsigned stk1; + unsigned stk2; + stk2 = ~S; + stk1 = T | stk2; + return stk1; +} + +/* TSno source opaque/pattern transparent. */ +static unsigned xrop3_243_0_1 (unsigned char s, unsigned char t) +{ + unsigned D = 0x00ff; + unsigned S = ((unsigned)s << 8) | s; + unsigned T = ((unsigned)t << 8) | t; + unsigned stk1; + unsigned stk2; + stk2 = ~S; + stk1 = T | stk2; + return (stk1 & S) | (stk1 & (~T)) | (T & (~S) & D); +} + +/* TSno source transparent/pattern opaque. */ +static unsigned xrop3_243_1_0 (unsigned char s, unsigned char t) +{ + unsigned D = 0x00ff; + unsigned S = ((unsigned)s << 8) | s; + unsigned T = ((unsigned)t << 8) | t; + unsigned stk1; + unsigned stk2; + stk2 = ~S; + stk1 = T | stk2; + return (stk1 & (~S)) | (D & S); +} + +/* TSno source/pattern transparent. */ +static unsigned xrop3_243_1_1 (unsigned char s, unsigned char t) +{ + unsigned D = 0x00ff; + unsigned S = ((unsigned)s << 8) | s; + unsigned T = ((unsigned)t << 8) | t; + unsigned stk1; + unsigned stk2; + stk2 = ~S; + stk1 = T | stk2; + return (stk1 & (~S) & (~T)) | (D & S) | (D & T); +} + +/* TSDnao source/pattern opaque. */ +static void rop3_244_0_0 (unsigned char *D, unsigned char S, unsigned char T) +{ + unsigned char stk1; + unsigned char stk2; + unsigned char stk3; + stk3 = ~*D; + stk2 = S & stk3; + stk1 = T | stk2; + *D = stk1; +} + +/* TSDnao source opaque/pattern transparent. */ +static void rop3_244_0_1 (unsigned char *D, unsigned char S, unsigned char T) +{ + unsigned char stk1; + unsigned char stk2; + unsigned char stk3; + stk3 = ~*D; + stk2 = S & stk3; + stk1 = T | stk2; + *D = (stk1 & S) | (stk1 & (~T)) | (T & (~S) & *D); +} + +/* TSDnao source transparent/pattern opaque. */ +static void rop3_244_1_0 (unsigned char *D, unsigned char S, unsigned char T) +{ + unsigned char stk1; + unsigned char stk2; + unsigned char stk3; + stk3 = ~*D; + stk2 = S & stk3; + stk1 = T | stk2; + *D = (stk1 & (~S)) | (*D & S); +} + +/* TSDnao source/pattern transparent. */ +static void rop3_244_1_1 (unsigned char *D, unsigned char S, unsigned char T) +{ + unsigned char stk1; + unsigned char stk2; + unsigned char stk3; + stk3 = ~*D; + stk2 = S & stk3; + stk1 = T | stk2; + *D = (stk1 & (~S) & (~T)) | (*D & S) | (*D & T); +} + +/* TSDnao source/pattern opaque. */ +static unsigned xrop3_244_0_0 (unsigned char s, unsigned char t) +{ + unsigned D = 0x00ff; + unsigned S = ((unsigned)s << 8) | s; + unsigned T = ((unsigned)t << 8) | t; + unsigned stk1; + unsigned stk2; + unsigned stk3; + stk3 = ~D; + stk2 = S & stk3; + stk1 = T | stk2; + return stk1; +} + +/* TSDnao source opaque/pattern transparent. */ +static unsigned xrop3_244_0_1 (unsigned char s, unsigned char t) +{ + unsigned D = 0x00ff; + unsigned S = ((unsigned)s << 8) | s; + unsigned T = ((unsigned)t << 8) | t; + unsigned stk1; + unsigned stk2; + unsigned stk3; + stk3 = ~D; + stk2 = S & stk3; + stk1 = T | stk2; + return (stk1 & S) | (stk1 & (~T)) | (T & (~S) & D); +} + +/* TSDnao source transparent/pattern opaque. */ +static unsigned xrop3_244_1_0 (unsigned char s, unsigned char t) +{ + unsigned D = 0x00ff; + unsigned S = ((unsigned)s << 8) | s; + unsigned T = ((unsigned)t << 8) | t; + unsigned stk1; + unsigned stk2; + unsigned stk3; + stk3 = ~D; + stk2 = S & stk3; + stk1 = T | stk2; + return (stk1 & (~S)) | (D & S); +} + +/* TSDnao source/pattern transparent. */ +static unsigned xrop3_244_1_1 (unsigned char s, unsigned char t) +{ + unsigned D = 0x00ff; + unsigned S = ((unsigned)s << 8) | s; + unsigned T = ((unsigned)t << 8) | t; + unsigned stk1; + unsigned stk2; + unsigned stk3; + stk3 = ~D; + stk2 = S & stk3; + stk1 = T | stk2; + return (stk1 & (~S) & (~T)) | (D & S) | (D & T); +} + +/* TDno source/pattern opaque. */ +static void rop3_245_0_0 (unsigned char *D, unsigned char S, unsigned char T) +{ + unsigned char stk1; + unsigned char stk2; + stk2 = ~*D; + stk1 = T | stk2; + *D = stk1; +} + +/* TDno source opaque/pattern transparent. */ +static void rop3_245_0_1 (unsigned char *D, unsigned char S, unsigned char T) +{ + unsigned char stk1; + unsigned char stk2; + stk2 = ~*D; + stk1 = T | stk2; + *D = (stk1 & S) | (stk1 & (~T)) | (T & (~S) & *D); +} + +/* TDno source transparent/pattern opaque. */ +static void rop3_245_1_0 (unsigned char *D, unsigned char S, unsigned char T) +{ + unsigned char stk1; + unsigned char stk2; + stk2 = ~*D; + stk1 = T | stk2; + *D = (stk1 & (~S)) | (*D & S); +} + +/* TDno source/pattern transparent. */ +static void rop3_245_1_1 (unsigned char *D, unsigned char S, unsigned char T) +{ + unsigned char stk1; + unsigned char stk2; + stk2 = ~*D; + stk1 = T | stk2; + *D = (stk1 & (~S) & (~T)) | (*D & S) | (*D & T); +} + +/* TDno source/pattern opaque. */ +static unsigned xrop3_245_0_0 (unsigned char s, unsigned char t) +{ + unsigned D = 0x00ff; + unsigned T = ((unsigned)t << 8) | t; + unsigned stk1; + unsigned stk2; + stk2 = ~D; + stk1 = T | stk2; + return stk1; +} + +/* TDno source opaque/pattern transparent. */ +static unsigned xrop3_245_0_1 (unsigned char s, unsigned char t) +{ + unsigned D = 0x00ff; + unsigned S = ((unsigned)s << 8) | s; + unsigned T = ((unsigned)t << 8) | t; + unsigned stk1; + unsigned stk2; + stk2 = ~D; + stk1 = T | stk2; + return (stk1 & S) | (stk1 & (~T)) | (T & (~S) & D); +} + +/* TDno source transparent/pattern opaque. */ +static unsigned xrop3_245_1_0 (unsigned char s, unsigned char t) +{ + unsigned D = 0x00ff; + unsigned S = ((unsigned)s << 8) | s; + unsigned T = ((unsigned)t << 8) | t; + unsigned stk1; + unsigned stk2; + stk2 = ~D; + stk1 = T | stk2; + return (stk1 & (~S)) | (D & S); +} + +/* TDno source/pattern transparent. */ +static unsigned xrop3_245_1_1 (unsigned char s, unsigned char t) +{ + unsigned D = 0x00ff; + unsigned S = ((unsigned)s << 8) | s; + unsigned T = ((unsigned)t << 8) | t; + unsigned stk1; + unsigned stk2; + stk2 = ~D; + stk1 = T | stk2; + return (stk1 & (~S) & (~T)) | (D & S) | (D & T); +} + +/* TDSxo source/pattern opaque. */ +static void rop3_246_0_0 (unsigned char *D, unsigned char S, unsigned char T) +{ + unsigned char stk1; + unsigned char stk2; + stk2 = *D ^ S; + stk1 = T | stk2; + *D = stk1; +} + +/* TDSxo source opaque/pattern transparent. */ +static void rop3_246_0_1 (unsigned char *D, unsigned char S, unsigned char T) +{ + unsigned char stk1; + unsigned char stk2; + stk2 = *D ^ S; + stk1 = T | stk2; + *D = (stk1 & S) | (stk1 & (~T)) | (T & (~S) & *D); +} + +/* TDSxo source transparent/pattern opaque. */ +static void rop3_246_1_0 (unsigned char *D, unsigned char S, unsigned char T) +{ + unsigned char stk1; + unsigned char stk2; + stk2 = *D ^ S; + stk1 = T | stk2; + *D = (stk1 & (~S)) | (*D & S); +} + +/* TDSxo source/pattern transparent. */ +static void rop3_246_1_1 (unsigned char *D, unsigned char S, unsigned char T) +{ + unsigned char stk1; + unsigned char stk2; + stk2 = *D ^ S; + stk1 = T | stk2; + *D = (stk1 & (~S) & (~T)) | (*D & S) | (*D & T); +} + +/* TDSxo source/pattern opaque. */ +static unsigned xrop3_246_0_0 (unsigned char s, unsigned char t) +{ + unsigned D = 0x00ff; + unsigned S = ((unsigned)s << 8) | s; + unsigned T = ((unsigned)t << 8) | t; + unsigned stk1; + unsigned stk2; + stk2 = D ^ S; + stk1 = T | stk2; + return stk1; +} + +/* TDSxo source opaque/pattern transparent. */ +static unsigned xrop3_246_0_1 (unsigned char s, unsigned char t) +{ + unsigned D = 0x00ff; + unsigned S = ((unsigned)s << 8) | s; + unsigned T = ((unsigned)t << 8) | t; + unsigned stk1; + unsigned stk2; + stk2 = D ^ S; + stk1 = T | stk2; + return (stk1 & S) | (stk1 & (~T)) | (T & (~S) & D); +} + +/* TDSxo source transparent/pattern opaque. */ +static unsigned xrop3_246_1_0 (unsigned char s, unsigned char t) +{ + unsigned D = 0x00ff; + unsigned S = ((unsigned)s << 8) | s; + unsigned T = ((unsigned)t << 8) | t; + unsigned stk1; + unsigned stk2; + stk2 = D ^ S; + stk1 = T | stk2; + return (stk1 & (~S)) | (D & S); +} + +/* TDSxo source/pattern transparent. */ +static unsigned xrop3_246_1_1 (unsigned char s, unsigned char t) +{ + unsigned D = 0x00ff; + unsigned S = ((unsigned)s << 8) | s; + unsigned T = ((unsigned)t << 8) | t; + unsigned stk1; + unsigned stk2; + stk2 = D ^ S; + stk1 = T | stk2; + return (stk1 & (~S) & (~T)) | (D & S) | (D & T); +} + +/* TDSano source/pattern opaque. */ +static void rop3_247_0_0 (unsigned char *D, unsigned char S, unsigned char T) +{ + unsigned char stk1; + unsigned char stk2; + stk2 = *D & S; + stk2 = ~stk2; + stk1 = T | stk2; + *D = stk1; +} + +/* TDSano source opaque/pattern transparent. */ +static void rop3_247_0_1 (unsigned char *D, unsigned char S, unsigned char T) +{ + unsigned char stk1; + unsigned char stk2; + stk2 = *D & S; + stk2 = ~stk2; + stk1 = T | stk2; + *D = (stk1 & S) | (stk1 & (~T)) | (T & (~S) & *D); +} + +/* TDSano source transparent/pattern opaque. */ +static void rop3_247_1_0 (unsigned char *D, unsigned char S, unsigned char T) +{ + unsigned char stk1; + unsigned char stk2; + stk2 = *D & S; + stk2 = ~stk2; + stk1 = T | stk2; + *D = (stk1 & (~S)) | (*D & S); +} + +/* TDSano source/pattern transparent. */ +static void rop3_247_1_1 (unsigned char *D, unsigned char S, unsigned char T) +{ + unsigned char stk1; + unsigned char stk2; + stk2 = *D & S; + stk2 = ~stk2; + stk1 = T | stk2; + *D = (stk1 & (~S) & (~T)) | (*D & S) | (*D & T); +} + +/* TDSano source/pattern opaque. */ +static unsigned xrop3_247_0_0 (unsigned char s, unsigned char t) +{ + unsigned D = 0x00ff; + unsigned S = ((unsigned)s << 8) | s; + unsigned T = ((unsigned)t << 8) | t; + unsigned stk1; + unsigned stk2; + stk2 = D & S; + stk2 = ~stk2; + stk1 = T | stk2; + return stk1; +} + +/* TDSano source opaque/pattern transparent. */ +static unsigned xrop3_247_0_1 (unsigned char s, unsigned char t) +{ + unsigned D = 0x00ff; + unsigned S = ((unsigned)s << 8) | s; + unsigned T = ((unsigned)t << 8) | t; + unsigned stk1; + unsigned stk2; + stk2 = D & S; + stk2 = ~stk2; + stk1 = T | stk2; + return (stk1 & S) | (stk1 & (~T)) | (T & (~S) & D); +} + +/* TDSano source transparent/pattern opaque. */ +static unsigned xrop3_247_1_0 (unsigned char s, unsigned char t) +{ + unsigned D = 0x00ff; + unsigned S = ((unsigned)s << 8) | s; + unsigned T = ((unsigned)t << 8) | t; + unsigned stk1; + unsigned stk2; + stk2 = D & S; + stk2 = ~stk2; + stk1 = T | stk2; + return (stk1 & (~S)) | (D & S); +} + +/* TDSano source/pattern transparent. */ +static unsigned xrop3_247_1_1 (unsigned char s, unsigned char t) +{ + unsigned D = 0x00ff; + unsigned S = ((unsigned)s << 8) | s; + unsigned T = ((unsigned)t << 8) | t; + unsigned stk1; + unsigned stk2; + stk2 = D & S; + stk2 = ~stk2; + stk1 = T | stk2; + return (stk1 & (~S) & (~T)) | (D & S) | (D & T); +} + +/* TDSao source/pattern opaque. */ +static void rop3_248_0_0 (unsigned char *D, unsigned char S, unsigned char T) +{ + unsigned char stk1; + unsigned char stk2; + stk2 = *D & S; + stk1 = T | stk2; + *D = stk1; +} + +/* TDSao source opaque/pattern transparent. */ +static void rop3_248_0_1 (unsigned char *D, unsigned char S, unsigned char T) +{ + unsigned char stk1; + unsigned char stk2; + stk2 = *D & S; + stk1 = T | stk2; + *D = (stk1 & S) | (stk1 & (~T)) | (T & (~S) & *D); +} + +/* TDSao source transparent/pattern opaque. */ +static void rop3_248_1_0 (unsigned char *D, unsigned char S, unsigned char T) +{ + unsigned char stk1; + unsigned char stk2; + stk2 = *D & S; + stk1 = T | stk2; + *D = (stk1 & (~S)) | (*D & S); +} + +/* TDSao source/pattern transparent. */ +static void rop3_248_1_1 (unsigned char *D, unsigned char S, unsigned char T) +{ + unsigned char stk1; + unsigned char stk2; + stk2 = *D & S; + stk1 = T | stk2; + *D = (stk1 & (~S) & (~T)) | (*D & S) | (*D & T); +} + +/* TDSao source/pattern opaque. */ +static unsigned xrop3_248_0_0 (unsigned char s, unsigned char t) +{ + unsigned D = 0x00ff; + unsigned S = ((unsigned)s << 8) | s; + unsigned T = ((unsigned)t << 8) | t; + unsigned stk1; + unsigned stk2; + stk2 = D & S; + stk1 = T | stk2; + return stk1; +} + +/* TDSao source opaque/pattern transparent. */ +static unsigned xrop3_248_0_1 (unsigned char s, unsigned char t) +{ + unsigned D = 0x00ff; + unsigned S = ((unsigned)s << 8) | s; + unsigned T = ((unsigned)t << 8) | t; + unsigned stk1; + unsigned stk2; + stk2 = D & S; + stk1 = T | stk2; + return (stk1 & S) | (stk1 & (~T)) | (T & (~S) & D); +} + +/* TDSao source transparent/pattern opaque. */ +static unsigned xrop3_248_1_0 (unsigned char s, unsigned char t) +{ + unsigned D = 0x00ff; + unsigned S = ((unsigned)s << 8) | s; + unsigned T = ((unsigned)t << 8) | t; + unsigned stk1; + unsigned stk2; + stk2 = D & S; + stk1 = T | stk2; + return (stk1 & (~S)) | (D & S); +} + +/* TDSao source/pattern transparent. */ +static unsigned xrop3_248_1_1 (unsigned char s, unsigned char t) +{ + unsigned D = 0x00ff; + unsigned S = ((unsigned)s << 8) | s; + unsigned T = ((unsigned)t << 8) | t; + unsigned stk1; + unsigned stk2; + stk2 = D & S; + stk1 = T | stk2; + return (stk1 & (~S) & (~T)) | (D & S) | (D & T); +} + +/* TDSxno source/pattern opaque. */ +static void rop3_249_0_0 (unsigned char *D, unsigned char S, unsigned char T) +{ + unsigned char stk1; + unsigned char stk2; + stk2 = *D ^ S; + stk2 = ~stk2; + stk1 = T | stk2; + *D = stk1; +} + +/* TDSxno source opaque/pattern transparent. */ +static void rop3_249_0_1 (unsigned char *D, unsigned char S, unsigned char T) +{ + unsigned char stk1; + unsigned char stk2; + stk2 = *D ^ S; + stk2 = ~stk2; + stk1 = T | stk2; + *D = (stk1 & S) | (stk1 & (~T)) | (T & (~S) & *D); +} + +/* TDSxno source transparent/pattern opaque. */ +static void rop3_249_1_0 (unsigned char *D, unsigned char S, unsigned char T) +{ + unsigned char stk1; + unsigned char stk2; + stk2 = *D ^ S; + stk2 = ~stk2; + stk1 = T | stk2; + *D = (stk1 & (~S)) | (*D & S); +} + +/* TDSxno source/pattern transparent. */ +static void rop3_249_1_1 (unsigned char *D, unsigned char S, unsigned char T) +{ + unsigned char stk1; + unsigned char stk2; + stk2 = *D ^ S; + stk2 = ~stk2; + stk1 = T | stk2; + *D = (stk1 & (~S) & (~T)) | (*D & S) | (*D & T); +} + +/* TDSxno source/pattern opaque. */ +static unsigned xrop3_249_0_0 (unsigned char s, unsigned char t) +{ + unsigned D = 0x00ff; + unsigned S = ((unsigned)s << 8) | s; + unsigned T = ((unsigned)t << 8) | t; + unsigned stk1; + unsigned stk2; + stk2 = D ^ S; + stk2 = ~stk2; + stk1 = T | stk2; + return stk1; +} + +/* TDSxno source opaque/pattern transparent. */ +static unsigned xrop3_249_0_1 (unsigned char s, unsigned char t) +{ + unsigned D = 0x00ff; + unsigned S = ((unsigned)s << 8) | s; + unsigned T = ((unsigned)t << 8) | t; + unsigned stk1; + unsigned stk2; + stk2 = D ^ S; + stk2 = ~stk2; + stk1 = T | stk2; + return (stk1 & S) | (stk1 & (~T)) | (T & (~S) & D); +} + +/* TDSxno source transparent/pattern opaque. */ +static unsigned xrop3_249_1_0 (unsigned char s, unsigned char t) +{ + unsigned D = 0x00ff; + unsigned S = ((unsigned)s << 8) | s; + unsigned T = ((unsigned)t << 8) | t; + unsigned stk1; + unsigned stk2; + stk2 = D ^ S; + stk2 = ~stk2; + stk1 = T | stk2; + return (stk1 & (~S)) | (D & S); +} + +/* TDSxno source/pattern transparent. */ +static unsigned xrop3_249_1_1 (unsigned char s, unsigned char t) +{ + unsigned D = 0x00ff; + unsigned S = ((unsigned)s << 8) | s; + unsigned T = ((unsigned)t << 8) | t; + unsigned stk1; + unsigned stk2; + stk2 = D ^ S; + stk2 = ~stk2; + stk1 = T | stk2; + return (stk1 & (~S) & (~T)) | (D & S) | (D & T); +} + +/* DTo source/pattern opaque. */ +static void rop3_250_0_0 (unsigned char *D, unsigned char S, unsigned char T) +{ + unsigned char stk1; + stk1 = *D | T; + *D = stk1; +} + +/* DTo source opaque/pattern transparent. */ +static void rop3_250_0_1 (unsigned char *D, unsigned char S, unsigned char T) +{ + unsigned char stk1; + stk1 = *D | T; + *D = (stk1 & S) | (stk1 & (~T)) | (T & (~S) & *D); +} + +/* DTo source transparent/pattern opaque. */ +static void rop3_250_1_0 (unsigned char *D, unsigned char S, unsigned char T) +{ + unsigned char stk1; + stk1 = *D | T; + *D = (stk1 & (~S)) | (*D & S); +} + +/* DTo source/pattern transparent. */ +static void rop3_250_1_1 (unsigned char *D, unsigned char S, unsigned char T) +{ + unsigned char stk1; + stk1 = *D | T; + *D = (stk1 & (~S) & (~T)) | (*D & S) | (*D & T); +} + +/* DTo source/pattern opaque. */ +static unsigned xrop3_250_0_0 (unsigned char s, unsigned char t) +{ + unsigned D = 0x00ff; + unsigned T = ((unsigned)t << 8) | t; + unsigned stk1; + stk1 = D | T; + return stk1; +} + +/* DTo source opaque/pattern transparent. */ +static unsigned xrop3_250_0_1 (unsigned char s, unsigned char t) +{ + unsigned D = 0x00ff; + unsigned S = ((unsigned)s << 8) | s; + unsigned T = ((unsigned)t << 8) | t; + unsigned stk1; + stk1 = D | T; + return (stk1 & S) | (stk1 & (~T)) | (T & (~S) & D); +} + +/* DTo source transparent/pattern opaque. */ +static unsigned xrop3_250_1_0 (unsigned char s, unsigned char t) +{ + unsigned D = 0x00ff; + unsigned S = ((unsigned)s << 8) | s; + unsigned T = ((unsigned)t << 8) | t; + unsigned stk1; + stk1 = D | T; + return (stk1 & (~S)) | (D & S); +} + +/* DTo source/pattern transparent. */ +static unsigned xrop3_250_1_1 (unsigned char s, unsigned char t) +{ + unsigned D = 0x00ff; + unsigned S = ((unsigned)s << 8) | s; + unsigned T = ((unsigned)t << 8) | t; + unsigned stk1; + stk1 = D | T; + return (stk1 & (~S) & (~T)) | (D & S) | (D & T); +} + +/* DTSnoo source/pattern opaque. */ +static void rop3_251_0_0 (unsigned char *D, unsigned char S, unsigned char T) +{ + unsigned char stk1; + unsigned char stk2; + unsigned char stk3; + stk3 = ~S; + stk2 = T | stk3; + stk1 = *D | stk2; + *D = stk1; +} + +/* DTSnoo source opaque/pattern transparent. */ +static void rop3_251_0_1 (unsigned char *D, unsigned char S, unsigned char T) +{ + unsigned char stk1; + unsigned char stk2; + unsigned char stk3; + stk3 = ~S; + stk2 = T | stk3; + stk1 = *D | stk2; + *D = (stk1 & S) | (stk1 & (~T)) | (T & (~S) & *D); +} + +/* DTSnoo source transparent/pattern opaque. */ +static void rop3_251_1_0 (unsigned char *D, unsigned char S, unsigned char T) +{ + unsigned char stk1; + unsigned char stk2; + unsigned char stk3; + stk3 = ~S; + stk2 = T | stk3; + stk1 = *D | stk2; + *D = (stk1 & (~S)) | (*D & S); +} + +/* DTSnoo source/pattern transparent. */ +static void rop3_251_1_1 (unsigned char *D, unsigned char S, unsigned char T) +{ + unsigned char stk1; + unsigned char stk2; + unsigned char stk3; + stk3 = ~S; + stk2 = T | stk3; + stk1 = *D | stk2; + *D = (stk1 & (~S) & (~T)) | (*D & S) | (*D & T); +} + +/* DTSnoo source/pattern opaque. */ +static unsigned xrop3_251_0_0 (unsigned char s, unsigned char t) +{ + unsigned D = 0x00ff; + unsigned S = ((unsigned)s << 8) | s; + unsigned T = ((unsigned)t << 8) | t; + unsigned stk1; + unsigned stk2; + unsigned stk3; + stk3 = ~S; + stk2 = T | stk3; + stk1 = D | stk2; + return stk1; +} + +/* DTSnoo source opaque/pattern transparent. */ +static unsigned xrop3_251_0_1 (unsigned char s, unsigned char t) +{ + unsigned D = 0x00ff; + unsigned S = ((unsigned)s << 8) | s; + unsigned T = ((unsigned)t << 8) | t; + unsigned stk1; + unsigned stk2; + unsigned stk3; + stk3 = ~S; + stk2 = T | stk3; + stk1 = D | stk2; + return (stk1 & S) | (stk1 & (~T)) | (T & (~S) & D); +} + +/* DTSnoo source transparent/pattern opaque. */ +static unsigned xrop3_251_1_0 (unsigned char s, unsigned char t) +{ + unsigned D = 0x00ff; + unsigned S = ((unsigned)s << 8) | s; + unsigned T = ((unsigned)t << 8) | t; + unsigned stk1; + unsigned stk2; + unsigned stk3; + stk3 = ~S; + stk2 = T | stk3; + stk1 = D | stk2; + return (stk1 & (~S)) | (D & S); +} + +/* DTSnoo source/pattern transparent. */ +static unsigned xrop3_251_1_1 (unsigned char s, unsigned char t) +{ + unsigned D = 0x00ff; + unsigned S = ((unsigned)s << 8) | s; + unsigned T = ((unsigned)t << 8) | t; + unsigned stk1; + unsigned stk2; + unsigned stk3; + stk3 = ~S; + stk2 = T | stk3; + stk1 = D | stk2; + return (stk1 & (~S) & (~T)) | (D & S) | (D & T); +} + +/* TSo source/pattern opaque. */ +static void rop3_252_0_0 (unsigned char *D, unsigned char S, unsigned char T) +{ + unsigned char stk1; + stk1 = T | S; + *D = stk1; +} + +/* TSo source opaque/pattern transparent. */ +static void rop3_252_0_1 (unsigned char *D, unsigned char S, unsigned char T) +{ + unsigned char stk1; + stk1 = T | S; + *D = (stk1 & S) | (stk1 & (~T)) | (T & (~S) & *D); +} + +/* TSo source transparent/pattern opaque. */ +static void rop3_252_1_0 (unsigned char *D, unsigned char S, unsigned char T) +{ + unsigned char stk1; + stk1 = T | S; + *D = (stk1 & (~S)) | (*D & S); +} + +/* TSo source/pattern transparent. */ +static void rop3_252_1_1 (unsigned char *D, unsigned char S, unsigned char T) +{ + unsigned char stk1; + stk1 = T | S; + *D = (stk1 & (~S) & (~T)) | (*D & S) | (*D & T); +} + +/* TSo source/pattern opaque. */ +static unsigned xrop3_252_0_0 (unsigned char s, unsigned char t) +{ + unsigned S = ((unsigned)s << 8) | s; + unsigned T = ((unsigned)t << 8) | t; + unsigned stk1; + stk1 = T | S; + return stk1; +} + +/* TSo source opaque/pattern transparent. */ +static unsigned xrop3_252_0_1 (unsigned char s, unsigned char t) +{ + unsigned D = 0x00ff; + unsigned S = ((unsigned)s << 8) | s; + unsigned T = ((unsigned)t << 8) | t; + unsigned stk1; + stk1 = T | S; + return (stk1 & S) | (stk1 & (~T)) | (T & (~S) & D); +} + +/* TSo source transparent/pattern opaque. */ +static unsigned xrop3_252_1_0 (unsigned char s, unsigned char t) +{ + unsigned D = 0x00ff; + unsigned S = ((unsigned)s << 8) | s; + unsigned T = ((unsigned)t << 8) | t; + unsigned stk1; + stk1 = T | S; + return (stk1 & (~S)) | (D & S); +} + +/* TSo source/pattern transparent. */ +static unsigned xrop3_252_1_1 (unsigned char s, unsigned char t) +{ + unsigned D = 0x00ff; + unsigned S = ((unsigned)s << 8) | s; + unsigned T = ((unsigned)t << 8) | t; + unsigned stk1; + stk1 = T | S; + return (stk1 & (~S) & (~T)) | (D & S) | (D & T); +} + +/* TSDnoo source/pattern opaque. */ +static void rop3_253_0_0 (unsigned char *D, unsigned char S, unsigned char T) +{ + unsigned char stk1; + unsigned char stk2; + unsigned char stk3; + stk3 = ~*D; + stk2 = S | stk3; + stk1 = T | stk2; + *D = stk1; +} + +/* TSDnoo source opaque/pattern transparent. */ +static void rop3_253_0_1 (unsigned char *D, unsigned char S, unsigned char T) +{ + unsigned char stk1; + unsigned char stk2; + unsigned char stk3; + stk3 = ~*D; + stk2 = S | stk3; + stk1 = T | stk2; + *D = (stk1 & S) | (stk1 & (~T)) | (T & (~S) & *D); +} + +/* TSDnoo source transparent/pattern opaque. */ +static void rop3_253_1_0 (unsigned char *D, unsigned char S, unsigned char T) +{ + unsigned char stk1; + unsigned char stk2; + unsigned char stk3; + stk3 = ~*D; + stk2 = S | stk3; + stk1 = T | stk2; + *D = (stk1 & (~S)) | (*D & S); +} + +/* TSDnoo source/pattern transparent. */ +static void rop3_253_1_1 (unsigned char *D, unsigned char S, unsigned char T) +{ + unsigned char stk1; + unsigned char stk2; + unsigned char stk3; + stk3 = ~*D; + stk2 = S | stk3; + stk1 = T | stk2; + *D = (stk1 & (~S) & (~T)) | (*D & S) | (*D & T); +} + +/* TSDnoo source/pattern opaque. */ +static unsigned xrop3_253_0_0 (unsigned char s, unsigned char t) +{ + unsigned D = 0x00ff; + unsigned S = ((unsigned)s << 8) | s; + unsigned T = ((unsigned)t << 8) | t; + unsigned stk1; + unsigned stk2; + unsigned stk3; + stk3 = ~D; + stk2 = S | stk3; + stk1 = T | stk2; + return stk1; +} + +/* TSDnoo source opaque/pattern transparent. */ +static unsigned xrop3_253_0_1 (unsigned char s, unsigned char t) +{ + unsigned D = 0x00ff; + unsigned S = ((unsigned)s << 8) | s; + unsigned T = ((unsigned)t << 8) | t; + unsigned stk1; + unsigned stk2; + unsigned stk3; + stk3 = ~D; + stk2 = S | stk3; + stk1 = T | stk2; + return (stk1 & S) | (stk1 & (~T)) | (T & (~S) & D); +} + +/* TSDnoo source transparent/pattern opaque. */ +static unsigned xrop3_253_1_0 (unsigned char s, unsigned char t) +{ + unsigned D = 0x00ff; + unsigned S = ((unsigned)s << 8) | s; + unsigned T = ((unsigned)t << 8) | t; + unsigned stk1; + unsigned stk2; + unsigned stk3; + stk3 = ~D; + stk2 = S | stk3; + stk1 = T | stk2; + return (stk1 & (~S)) | (D & S); +} + +/* TSDnoo source/pattern transparent. */ +static unsigned xrop3_253_1_1 (unsigned char s, unsigned char t) +{ + unsigned D = 0x00ff; + unsigned S = ((unsigned)s << 8) | s; + unsigned T = ((unsigned)t << 8) | t; + unsigned stk1; + unsigned stk2; + unsigned stk3; + stk3 = ~D; + stk2 = S | stk3; + stk1 = T | stk2; + return (stk1 & (~S) & (~T)) | (D & S) | (D & T); +} + +/* DTSoo source/pattern opaque. */ +static void rop3_254_0_0 (unsigned char *D, unsigned char S, unsigned char T) +{ + unsigned char stk1; + unsigned char stk2; + stk2 = T | S; + stk1 = *D | stk2; + *D = stk1; +} + +/* DTSoo source opaque/pattern transparent. */ +static void rop3_254_0_1 (unsigned char *D, unsigned char S, unsigned char T) +{ + unsigned char stk1; + unsigned char stk2; + stk2 = T | S; + stk1 = *D | stk2; + *D = (stk1 & S) | (stk1 & (~T)) | (T & (~S) & *D); +} + +/* DTSoo source transparent/pattern opaque. */ +static void rop3_254_1_0 (unsigned char *D, unsigned char S, unsigned char T) +{ + unsigned char stk1; + unsigned char stk2; + stk2 = T | S; + stk1 = *D | stk2; + *D = (stk1 & (~S)) | (*D & S); +} + +/* DTSoo source/pattern transparent. */ +static void rop3_254_1_1 (unsigned char *D, unsigned char S, unsigned char T) +{ + unsigned char stk1; + unsigned char stk2; + stk2 = T | S; + stk1 = *D | stk2; + *D = (stk1 & (~S) & (~T)) | (*D & S) | (*D & T); +} + +/* DTSoo source/pattern opaque. */ +static unsigned xrop3_254_0_0 (unsigned char s, unsigned char t) +{ + unsigned D = 0x00ff; + unsigned S = ((unsigned)s << 8) | s; + unsigned T = ((unsigned)t << 8) | t; + unsigned stk1; + unsigned stk2; + stk2 = T | S; + stk1 = D | stk2; + return stk1; +} + +/* DTSoo source opaque/pattern transparent. */ +static unsigned xrop3_254_0_1 (unsigned char s, unsigned char t) +{ + unsigned D = 0x00ff; + unsigned S = ((unsigned)s << 8) | s; + unsigned T = ((unsigned)t << 8) | t; + unsigned stk1; + unsigned stk2; + stk2 = T | S; + stk1 = D | stk2; + return (stk1 & S) | (stk1 & (~T)) | (T & (~S) & D); +} + +/* DTSoo source transparent/pattern opaque. */ +static unsigned xrop3_254_1_0 (unsigned char s, unsigned char t) +{ + unsigned D = 0x00ff; + unsigned S = ((unsigned)s << 8) | s; + unsigned T = ((unsigned)t << 8) | t; + unsigned stk1; + unsigned stk2; + stk2 = T | S; + stk1 = D | stk2; + return (stk1 & (~S)) | (D & S); +} + +/* DTSoo source/pattern transparent. */ +static unsigned xrop3_254_1_1 (unsigned char s, unsigned char t) +{ + unsigned D = 0x00ff; + unsigned S = ((unsigned)s << 8) | s; + unsigned T = ((unsigned)t << 8) | t; + unsigned stk1; + unsigned stk2; + stk2 = T | S; + stk1 = D | stk2; + return (stk1 & (~S) & (~T)) | (D & S) | (D & T); +} + +/* 1 source/pattern opaque. */ +static void rop3_255_0_0 (unsigned char *D, unsigned char S, unsigned char T) +{ + unsigned char stk1; + stk1 = 255; + *D = stk1; +} + +/* 1 source opaque/pattern transparent. */ +static void rop3_255_0_1 (unsigned char *D, unsigned char S, unsigned char T) +{ + unsigned char stk1; + stk1 = 255; + *D = (stk1 & S) | (stk1 & (~T)) | (T & (~S) & *D); +} + +/* 1 source transparent/pattern opaque. */ +static void rop3_255_1_0 (unsigned char *D, unsigned char S, unsigned char T) +{ + unsigned char stk1; + stk1 = 255; + *D = (stk1 & (~S)) | (*D & S); +} + +/* 1 source/pattern transparent. */ +static void rop3_255_1_1 (unsigned char *D, unsigned char S, unsigned char T) +{ + unsigned char stk1; + stk1 = 255; + *D = (stk1 & (~S) & (~T)) | (*D & S) | (*D & T); +} + +/* 1 source/pattern opaque. */ +static unsigned xrop3_255_0_0 (unsigned char s, unsigned char t) +{ + unsigned stk1; + stk1 = 0xffff; + return stk1; +} + +/* 1 source opaque/pattern transparent. */ +static unsigned xrop3_255_0_1 (unsigned char s, unsigned char t) +{ + unsigned D = 0x00ff; + unsigned S = ((unsigned)s << 8) | s; + unsigned T = ((unsigned)t << 8) | t; + unsigned stk1; + stk1 = 0xffff; + return (stk1 & S) | (stk1 & (~T)) | (T & (~S) & D); +} + +/* 1 source transparent/pattern opaque. */ +static unsigned xrop3_255_1_0 (unsigned char s, unsigned char t) +{ + unsigned D = 0x00ff; + unsigned S = ((unsigned)s << 8) | s; + unsigned stk1; + stk1 = 0xffff; + return (stk1 & (~S)) | (D & S); +} + +/* 1 source/pattern transparent. */ +static unsigned xrop3_255_1_1 (unsigned char s, unsigned char t) +{ + unsigned D = 0x00ff; + unsigned S = ((unsigned)s << 8) | s; + unsigned T = ((unsigned)t << 8) | t; + unsigned stk1; + stk1 = 0xffff; + return (stk1 & (~S) & (~T)) | (D & S) | (D & T); +} + +static hpgs_rop3_func_t rop3_table[][2][2] = { + {{rop3_0_0_0,rop3_0_0_1},{rop3_0_1_0,rop3_0_1_1}}, + {{rop3_1_0_0,rop3_1_0_1},{rop3_1_1_0,rop3_1_1_1}}, + {{rop3_2_0_0,rop3_2_0_1},{rop3_2_1_0,rop3_2_1_1}}, + {{rop3_3_0_0,rop3_3_0_1},{rop3_3_1_0,rop3_3_1_1}}, + {{rop3_4_0_0,rop3_4_0_1},{rop3_4_1_0,rop3_4_1_1}}, + {{rop3_5_0_0,rop3_5_0_1},{rop3_5_1_0,rop3_5_1_1}}, + {{rop3_6_0_0,rop3_6_0_1},{rop3_6_1_0,rop3_6_1_1}}, + {{rop3_7_0_0,rop3_7_0_1},{rop3_7_1_0,rop3_7_1_1}}, + {{rop3_8_0_0,rop3_8_0_1},{rop3_8_1_0,rop3_8_1_1}}, + {{rop3_9_0_0,rop3_9_0_1},{rop3_9_1_0,rop3_9_1_1}}, + {{rop3_10_0_0,rop3_10_0_1},{rop3_10_1_0,rop3_10_1_1}}, + {{rop3_11_0_0,rop3_11_0_1},{rop3_11_1_0,rop3_11_1_1}}, + {{rop3_12_0_0,rop3_12_0_1},{rop3_12_1_0,rop3_12_1_1}}, + {{rop3_13_0_0,rop3_13_0_1},{rop3_13_1_0,rop3_13_1_1}}, + {{rop3_14_0_0,rop3_14_0_1},{rop3_14_1_0,rop3_14_1_1}}, + {{rop3_15_0_0,rop3_15_0_1},{rop3_15_1_0,rop3_15_1_1}}, + {{rop3_16_0_0,rop3_16_0_1},{rop3_16_1_0,rop3_16_1_1}}, + {{rop3_17_0_0,rop3_17_0_1},{rop3_17_1_0,rop3_17_1_1}}, + {{rop3_18_0_0,rop3_18_0_1},{rop3_18_1_0,rop3_18_1_1}}, + {{rop3_19_0_0,rop3_19_0_1},{rop3_19_1_0,rop3_19_1_1}}, + {{rop3_20_0_0,rop3_20_0_1},{rop3_20_1_0,rop3_20_1_1}}, + {{rop3_21_0_0,rop3_21_0_1},{rop3_21_1_0,rop3_21_1_1}}, + {{rop3_22_0_0,rop3_22_0_1},{rop3_22_1_0,rop3_22_1_1}}, + {{rop3_23_0_0,rop3_23_0_1},{rop3_23_1_0,rop3_23_1_1}}, + {{rop3_24_0_0,rop3_24_0_1},{rop3_24_1_0,rop3_24_1_1}}, + {{rop3_25_0_0,rop3_25_0_1},{rop3_25_1_0,rop3_25_1_1}}, + {{rop3_26_0_0,rop3_26_0_1},{rop3_26_1_0,rop3_26_1_1}}, + {{rop3_27_0_0,rop3_27_0_1},{rop3_27_1_0,rop3_27_1_1}}, + {{rop3_28_0_0,rop3_28_0_1},{rop3_28_1_0,rop3_28_1_1}}, + {{rop3_29_0_0,rop3_29_0_1},{rop3_29_1_0,rop3_29_1_1}}, + {{rop3_30_0_0,rop3_30_0_1},{rop3_30_1_0,rop3_30_1_1}}, + {{rop3_31_0_0,rop3_31_0_1},{rop3_31_1_0,rop3_31_1_1}}, + {{rop3_32_0_0,rop3_32_0_1},{rop3_32_1_0,rop3_32_1_1}}, + {{rop3_33_0_0,rop3_33_0_1},{rop3_33_1_0,rop3_33_1_1}}, + {{rop3_34_0_0,rop3_34_0_1},{rop3_34_1_0,rop3_34_1_1}}, + {{rop3_35_0_0,rop3_35_0_1},{rop3_35_1_0,rop3_35_1_1}}, + {{rop3_36_0_0,rop3_36_0_1},{rop3_36_1_0,rop3_36_1_1}}, + {{rop3_37_0_0,rop3_37_0_1},{rop3_37_1_0,rop3_37_1_1}}, + {{rop3_38_0_0,rop3_38_0_1},{rop3_38_1_0,rop3_38_1_1}}, + {{rop3_39_0_0,rop3_39_0_1},{rop3_39_1_0,rop3_39_1_1}}, + {{rop3_40_0_0,rop3_40_0_1},{rop3_40_1_0,rop3_40_1_1}}, + {{rop3_41_0_0,rop3_41_0_1},{rop3_41_1_0,rop3_41_1_1}}, + {{rop3_42_0_0,rop3_42_0_1},{rop3_42_1_0,rop3_42_1_1}}, + {{rop3_43_0_0,rop3_43_0_1},{rop3_43_1_0,rop3_43_1_1}}, + {{rop3_44_0_0,rop3_44_0_1},{rop3_44_1_0,rop3_44_1_1}}, + {{rop3_45_0_0,rop3_45_0_1},{rop3_45_1_0,rop3_45_1_1}}, + {{rop3_46_0_0,rop3_46_0_1},{rop3_46_1_0,rop3_46_1_1}}, + {{rop3_47_0_0,rop3_47_0_1},{rop3_47_1_0,rop3_47_1_1}}, + {{rop3_48_0_0,rop3_48_0_1},{rop3_48_1_0,rop3_48_1_1}}, + {{rop3_49_0_0,rop3_49_0_1},{rop3_49_1_0,rop3_49_1_1}}, + {{rop3_50_0_0,rop3_50_0_1},{rop3_50_1_0,rop3_50_1_1}}, + {{rop3_51_0_0,rop3_51_0_1},{rop3_51_1_0,rop3_51_1_1}}, + {{rop3_52_0_0,rop3_52_0_1},{rop3_52_1_0,rop3_52_1_1}}, + {{rop3_53_0_0,rop3_53_0_1},{rop3_53_1_0,rop3_53_1_1}}, + {{rop3_54_0_0,rop3_54_0_1},{rop3_54_1_0,rop3_54_1_1}}, + {{rop3_55_0_0,rop3_55_0_1},{rop3_55_1_0,rop3_55_1_1}}, + {{rop3_56_0_0,rop3_56_0_1},{rop3_56_1_0,rop3_56_1_1}}, + {{rop3_57_0_0,rop3_57_0_1},{rop3_57_1_0,rop3_57_1_1}}, + {{rop3_58_0_0,rop3_58_0_1},{rop3_58_1_0,rop3_58_1_1}}, + {{rop3_59_0_0,rop3_59_0_1},{rop3_59_1_0,rop3_59_1_1}}, + {{rop3_60_0_0,rop3_60_0_1},{rop3_60_1_0,rop3_60_1_1}}, + {{rop3_61_0_0,rop3_61_0_1},{rop3_61_1_0,rop3_61_1_1}}, + {{rop3_62_0_0,rop3_62_0_1},{rop3_62_1_0,rop3_62_1_1}}, + {{rop3_63_0_0,rop3_63_0_1},{rop3_63_1_0,rop3_63_1_1}}, + {{rop3_64_0_0,rop3_64_0_1},{rop3_64_1_0,rop3_64_1_1}}, + {{rop3_65_0_0,rop3_65_0_1},{rop3_65_1_0,rop3_65_1_1}}, + {{rop3_66_0_0,rop3_66_0_1},{rop3_66_1_0,rop3_66_1_1}}, + {{rop3_67_0_0,rop3_67_0_1},{rop3_67_1_0,rop3_67_1_1}}, + {{rop3_68_0_0,rop3_68_0_1},{rop3_68_1_0,rop3_68_1_1}}, + {{rop3_69_0_0,rop3_69_0_1},{rop3_69_1_0,rop3_69_1_1}}, + {{rop3_70_0_0,rop3_70_0_1},{rop3_70_1_0,rop3_70_1_1}}, + {{rop3_71_0_0,rop3_71_0_1},{rop3_71_1_0,rop3_71_1_1}}, + {{rop3_72_0_0,rop3_72_0_1},{rop3_72_1_0,rop3_72_1_1}}, + {{rop3_73_0_0,rop3_73_0_1},{rop3_73_1_0,rop3_73_1_1}}, + {{rop3_74_0_0,rop3_74_0_1},{rop3_74_1_0,rop3_74_1_1}}, + {{rop3_75_0_0,rop3_75_0_1},{rop3_75_1_0,rop3_75_1_1}}, + {{rop3_76_0_0,rop3_76_0_1},{rop3_76_1_0,rop3_76_1_1}}, + {{rop3_77_0_0,rop3_77_0_1},{rop3_77_1_0,rop3_77_1_1}}, + {{rop3_78_0_0,rop3_78_0_1},{rop3_78_1_0,rop3_78_1_1}}, + {{rop3_79_0_0,rop3_79_0_1},{rop3_79_1_0,rop3_79_1_1}}, + {{rop3_80_0_0,rop3_80_0_1},{rop3_80_1_0,rop3_80_1_1}}, + {{rop3_81_0_0,rop3_81_0_1},{rop3_81_1_0,rop3_81_1_1}}, + {{rop3_82_0_0,rop3_82_0_1},{rop3_82_1_0,rop3_82_1_1}}, + {{rop3_83_0_0,rop3_83_0_1},{rop3_83_1_0,rop3_83_1_1}}, + {{rop3_84_0_0,rop3_84_0_1},{rop3_84_1_0,rop3_84_1_1}}, + {{rop3_85_0_0,rop3_85_0_1},{rop3_85_1_0,rop3_85_1_1}}, + {{rop3_86_0_0,rop3_86_0_1},{rop3_86_1_0,rop3_86_1_1}}, + {{rop3_87_0_0,rop3_87_0_1},{rop3_87_1_0,rop3_87_1_1}}, + {{rop3_88_0_0,rop3_88_0_1},{rop3_88_1_0,rop3_88_1_1}}, + {{rop3_89_0_0,rop3_89_0_1},{rop3_89_1_0,rop3_89_1_1}}, + {{rop3_90_0_0,rop3_90_0_1},{rop3_90_1_0,rop3_90_1_1}}, + {{rop3_91_0_0,rop3_91_0_1},{rop3_91_1_0,rop3_91_1_1}}, + {{rop3_92_0_0,rop3_92_0_1},{rop3_92_1_0,rop3_92_1_1}}, + {{rop3_93_0_0,rop3_93_0_1},{rop3_93_1_0,rop3_93_1_1}}, + {{rop3_94_0_0,rop3_94_0_1},{rop3_94_1_0,rop3_94_1_1}}, + {{rop3_95_0_0,rop3_95_0_1},{rop3_95_1_0,rop3_95_1_1}}, + {{rop3_96_0_0,rop3_96_0_1},{rop3_96_1_0,rop3_96_1_1}}, + {{rop3_97_0_0,rop3_97_0_1},{rop3_97_1_0,rop3_97_1_1}}, + {{rop3_98_0_0,rop3_98_0_1},{rop3_98_1_0,rop3_98_1_1}}, + {{rop3_99_0_0,rop3_99_0_1},{rop3_99_1_0,rop3_99_1_1}}, + {{rop3_100_0_0,rop3_100_0_1},{rop3_100_1_0,rop3_100_1_1}}, + {{rop3_101_0_0,rop3_101_0_1},{rop3_101_1_0,rop3_101_1_1}}, + {{rop3_102_0_0,rop3_102_0_1},{rop3_102_1_0,rop3_102_1_1}}, + {{rop3_103_0_0,rop3_103_0_1},{rop3_103_1_0,rop3_103_1_1}}, + {{rop3_104_0_0,rop3_104_0_1},{rop3_104_1_0,rop3_104_1_1}}, + {{rop3_105_0_0,rop3_105_0_1},{rop3_105_1_0,rop3_105_1_1}}, + {{rop3_106_0_0,rop3_106_0_1},{rop3_106_1_0,rop3_106_1_1}}, + {{rop3_107_0_0,rop3_107_0_1},{rop3_107_1_0,rop3_107_1_1}}, + {{rop3_108_0_0,rop3_108_0_1},{rop3_108_1_0,rop3_108_1_1}}, + {{rop3_109_0_0,rop3_109_0_1},{rop3_109_1_0,rop3_109_1_1}}, + {{rop3_110_0_0,rop3_110_0_1},{rop3_110_1_0,rop3_110_1_1}}, + {{rop3_111_0_0,rop3_111_0_1},{rop3_111_1_0,rop3_111_1_1}}, + {{rop3_112_0_0,rop3_112_0_1},{rop3_112_1_0,rop3_112_1_1}}, + {{rop3_113_0_0,rop3_113_0_1},{rop3_113_1_0,rop3_113_1_1}}, + {{rop3_114_0_0,rop3_114_0_1},{rop3_114_1_0,rop3_114_1_1}}, + {{rop3_115_0_0,rop3_115_0_1},{rop3_115_1_0,rop3_115_1_1}}, + {{rop3_116_0_0,rop3_116_0_1},{rop3_116_1_0,rop3_116_1_1}}, + {{rop3_117_0_0,rop3_117_0_1},{rop3_117_1_0,rop3_117_1_1}}, + {{rop3_118_0_0,rop3_118_0_1},{rop3_118_1_0,rop3_118_1_1}}, + {{rop3_119_0_0,rop3_119_0_1},{rop3_119_1_0,rop3_119_1_1}}, + {{rop3_120_0_0,rop3_120_0_1},{rop3_120_1_0,rop3_120_1_1}}, + {{rop3_121_0_0,rop3_121_0_1},{rop3_121_1_0,rop3_121_1_1}}, + {{rop3_122_0_0,rop3_122_0_1},{rop3_122_1_0,rop3_122_1_1}}, + {{rop3_123_0_0,rop3_123_0_1},{rop3_123_1_0,rop3_123_1_1}}, + {{rop3_124_0_0,rop3_124_0_1},{rop3_124_1_0,rop3_124_1_1}}, + {{rop3_125_0_0,rop3_125_0_1},{rop3_125_1_0,rop3_125_1_1}}, + {{rop3_126_0_0,rop3_126_0_1},{rop3_126_1_0,rop3_126_1_1}}, + {{rop3_127_0_0,rop3_127_0_1},{rop3_127_1_0,rop3_127_1_1}}, + {{rop3_128_0_0,rop3_128_0_1},{rop3_128_1_0,rop3_128_1_1}}, + {{rop3_129_0_0,rop3_129_0_1},{rop3_129_1_0,rop3_129_1_1}}, + {{rop3_130_0_0,rop3_130_0_1},{rop3_130_1_0,rop3_130_1_1}}, + {{rop3_131_0_0,rop3_131_0_1},{rop3_131_1_0,rop3_131_1_1}}, + {{rop3_132_0_0,rop3_132_0_1},{rop3_132_1_0,rop3_132_1_1}}, + {{rop3_133_0_0,rop3_133_0_1},{rop3_133_1_0,rop3_133_1_1}}, + {{rop3_134_0_0,rop3_134_0_1},{rop3_134_1_0,rop3_134_1_1}}, + {{rop3_135_0_0,rop3_135_0_1},{rop3_135_1_0,rop3_135_1_1}}, + {{rop3_136_0_0,rop3_136_0_1},{rop3_136_1_0,rop3_136_1_1}}, + {{rop3_137_0_0,rop3_137_0_1},{rop3_137_1_0,rop3_137_1_1}}, + {{rop3_138_0_0,rop3_138_0_1},{rop3_138_1_0,rop3_138_1_1}}, + {{rop3_139_0_0,rop3_139_0_1},{rop3_139_1_0,rop3_139_1_1}}, + {{rop3_140_0_0,rop3_140_0_1},{rop3_140_1_0,rop3_140_1_1}}, + {{rop3_141_0_0,rop3_141_0_1},{rop3_141_1_0,rop3_141_1_1}}, + {{rop3_142_0_0,rop3_142_0_1},{rop3_142_1_0,rop3_142_1_1}}, + {{rop3_143_0_0,rop3_143_0_1},{rop3_143_1_0,rop3_143_1_1}}, + {{rop3_144_0_0,rop3_144_0_1},{rop3_144_1_0,rop3_144_1_1}}, + {{rop3_145_0_0,rop3_145_0_1},{rop3_145_1_0,rop3_145_1_1}}, + {{rop3_146_0_0,rop3_146_0_1},{rop3_146_1_0,rop3_146_1_1}}, + {{rop3_147_0_0,rop3_147_0_1},{rop3_147_1_0,rop3_147_1_1}}, + {{rop3_148_0_0,rop3_148_0_1},{rop3_148_1_0,rop3_148_1_1}}, + {{rop3_149_0_0,rop3_149_0_1},{rop3_149_1_0,rop3_149_1_1}}, + {{rop3_150_0_0,rop3_150_0_1},{rop3_150_1_0,rop3_150_1_1}}, + {{rop3_151_0_0,rop3_151_0_1},{rop3_151_1_0,rop3_151_1_1}}, + {{rop3_152_0_0,rop3_152_0_1},{rop3_152_1_0,rop3_152_1_1}}, + {{rop3_153_0_0,rop3_153_0_1},{rop3_153_1_0,rop3_153_1_1}}, + {{rop3_154_0_0,rop3_154_0_1},{rop3_154_1_0,rop3_154_1_1}}, + {{rop3_155_0_0,rop3_155_0_1},{rop3_155_1_0,rop3_155_1_1}}, + {{rop3_156_0_0,rop3_156_0_1},{rop3_156_1_0,rop3_156_1_1}}, + {{rop3_157_0_0,rop3_157_0_1},{rop3_157_1_0,rop3_157_1_1}}, + {{rop3_158_0_0,rop3_158_0_1},{rop3_158_1_0,rop3_158_1_1}}, + {{rop3_159_0_0,rop3_159_0_1},{rop3_159_1_0,rop3_159_1_1}}, + {{rop3_160_0_0,rop3_160_0_1},{rop3_160_1_0,rop3_160_1_1}}, + {{rop3_161_0_0,rop3_161_0_1},{rop3_161_1_0,rop3_161_1_1}}, + {{rop3_162_0_0,rop3_162_0_1},{rop3_162_1_0,rop3_162_1_1}}, + {{rop3_163_0_0,rop3_163_0_1},{rop3_163_1_0,rop3_163_1_1}}, + {{rop3_164_0_0,rop3_164_0_1},{rop3_164_1_0,rop3_164_1_1}}, + {{rop3_165_0_0,rop3_165_0_1},{rop3_165_1_0,rop3_165_1_1}}, + {{rop3_166_0_0,rop3_166_0_1},{rop3_166_1_0,rop3_166_1_1}}, + {{rop3_167_0_0,rop3_167_0_1},{rop3_167_1_0,rop3_167_1_1}}, + {{rop3_168_0_0,rop3_168_0_1},{rop3_168_1_0,rop3_168_1_1}}, + {{rop3_169_0_0,rop3_169_0_1},{rop3_169_1_0,rop3_169_1_1}}, + {{rop3_170_0_0,rop3_170_0_1},{rop3_170_1_0,rop3_170_1_1}}, + {{rop3_171_0_0,rop3_171_0_1},{rop3_171_1_0,rop3_171_1_1}}, + {{rop3_172_0_0,rop3_172_0_1},{rop3_172_1_0,rop3_172_1_1}}, + {{rop3_173_0_0,rop3_173_0_1},{rop3_173_1_0,rop3_173_1_1}}, + {{rop3_174_0_0,rop3_174_0_1},{rop3_174_1_0,rop3_174_1_1}}, + {{rop3_175_0_0,rop3_175_0_1},{rop3_175_1_0,rop3_175_1_1}}, + {{rop3_176_0_0,rop3_176_0_1},{rop3_176_1_0,rop3_176_1_1}}, + {{rop3_177_0_0,rop3_177_0_1},{rop3_177_1_0,rop3_177_1_1}}, + {{rop3_178_0_0,rop3_178_0_1},{rop3_178_1_0,rop3_178_1_1}}, + {{rop3_179_0_0,rop3_179_0_1},{rop3_179_1_0,rop3_179_1_1}}, + {{rop3_180_0_0,rop3_180_0_1},{rop3_180_1_0,rop3_180_1_1}}, + {{rop3_181_0_0,rop3_181_0_1},{rop3_181_1_0,rop3_181_1_1}}, + {{rop3_182_0_0,rop3_182_0_1},{rop3_182_1_0,rop3_182_1_1}}, + {{rop3_183_0_0,rop3_183_0_1},{rop3_183_1_0,rop3_183_1_1}}, + {{rop3_184_0_0,rop3_184_0_1},{rop3_184_1_0,rop3_184_1_1}}, + {{rop3_185_0_0,rop3_185_0_1},{rop3_185_1_0,rop3_185_1_1}}, + {{rop3_186_0_0,rop3_186_0_1},{rop3_186_1_0,rop3_186_1_1}}, + {{rop3_187_0_0,rop3_187_0_1},{rop3_187_1_0,rop3_187_1_1}}, + {{rop3_188_0_0,rop3_188_0_1},{rop3_188_1_0,rop3_188_1_1}}, + {{rop3_189_0_0,rop3_189_0_1},{rop3_189_1_0,rop3_189_1_1}}, + {{rop3_190_0_0,rop3_190_0_1},{rop3_190_1_0,rop3_190_1_1}}, + {{rop3_191_0_0,rop3_191_0_1},{rop3_191_1_0,rop3_191_1_1}}, + {{rop3_192_0_0,rop3_192_0_1},{rop3_192_1_0,rop3_192_1_1}}, + {{rop3_193_0_0,rop3_193_0_1},{rop3_193_1_0,rop3_193_1_1}}, + {{rop3_194_0_0,rop3_194_0_1},{rop3_194_1_0,rop3_194_1_1}}, + {{rop3_195_0_0,rop3_195_0_1},{rop3_195_1_0,rop3_195_1_1}}, + {{rop3_196_0_0,rop3_196_0_1},{rop3_196_1_0,rop3_196_1_1}}, + {{rop3_197_0_0,rop3_197_0_1},{rop3_197_1_0,rop3_197_1_1}}, + {{rop3_198_0_0,rop3_198_0_1},{rop3_198_1_0,rop3_198_1_1}}, + {{rop3_199_0_0,rop3_199_0_1},{rop3_199_1_0,rop3_199_1_1}}, + {{rop3_200_0_0,rop3_200_0_1},{rop3_200_1_0,rop3_200_1_1}}, + {{rop3_201_0_0,rop3_201_0_1},{rop3_201_1_0,rop3_201_1_1}}, + {{rop3_202_0_0,rop3_202_0_1},{rop3_202_1_0,rop3_202_1_1}}, + {{rop3_203_0_0,rop3_203_0_1},{rop3_203_1_0,rop3_203_1_1}}, + {{rop3_204_0_0,rop3_204_0_1},{rop3_204_1_0,rop3_204_1_1}}, + {{rop3_205_0_0,rop3_205_0_1},{rop3_205_1_0,rop3_205_1_1}}, + {{rop3_206_0_0,rop3_206_0_1},{rop3_206_1_0,rop3_206_1_1}}, + {{rop3_207_0_0,rop3_207_0_1},{rop3_207_1_0,rop3_207_1_1}}, + {{rop3_208_0_0,rop3_208_0_1},{rop3_208_1_0,rop3_208_1_1}}, + {{rop3_209_0_0,rop3_209_0_1},{rop3_209_1_0,rop3_209_1_1}}, + {{rop3_210_0_0,rop3_210_0_1},{rop3_210_1_0,rop3_210_1_1}}, + {{rop3_211_0_0,rop3_211_0_1},{rop3_211_1_0,rop3_211_1_1}}, + {{rop3_212_0_0,rop3_212_0_1},{rop3_212_1_0,rop3_212_1_1}}, + {{rop3_213_0_0,rop3_213_0_1},{rop3_213_1_0,rop3_213_1_1}}, + {{rop3_214_0_0,rop3_214_0_1},{rop3_214_1_0,rop3_214_1_1}}, + {{rop3_215_0_0,rop3_215_0_1},{rop3_215_1_0,rop3_215_1_1}}, + {{rop3_216_0_0,rop3_216_0_1},{rop3_216_1_0,rop3_216_1_1}}, + {{rop3_217_0_0,rop3_217_0_1},{rop3_217_1_0,rop3_217_1_1}}, + {{rop3_218_0_0,rop3_218_0_1},{rop3_218_1_0,rop3_218_1_1}}, + {{rop3_219_0_0,rop3_219_0_1},{rop3_219_1_0,rop3_219_1_1}}, + {{rop3_220_0_0,rop3_220_0_1},{rop3_220_1_0,rop3_220_1_1}}, + {{rop3_221_0_0,rop3_221_0_1},{rop3_221_1_0,rop3_221_1_1}}, + {{rop3_222_0_0,rop3_222_0_1},{rop3_222_1_0,rop3_222_1_1}}, + {{rop3_223_0_0,rop3_223_0_1},{rop3_223_1_0,rop3_223_1_1}}, + {{rop3_224_0_0,rop3_224_0_1},{rop3_224_1_0,rop3_224_1_1}}, + {{rop3_225_0_0,rop3_225_0_1},{rop3_225_1_0,rop3_225_1_1}}, + {{rop3_226_0_0,rop3_226_0_1},{rop3_226_1_0,rop3_226_1_1}}, + {{rop3_227_0_0,rop3_227_0_1},{rop3_227_1_0,rop3_227_1_1}}, + {{rop3_228_0_0,rop3_228_0_1},{rop3_228_1_0,rop3_228_1_1}}, + {{rop3_229_0_0,rop3_229_0_1},{rop3_229_1_0,rop3_229_1_1}}, + {{rop3_230_0_0,rop3_230_0_1},{rop3_230_1_0,rop3_230_1_1}}, + {{rop3_231_0_0,rop3_231_0_1},{rop3_231_1_0,rop3_231_1_1}}, + {{rop3_232_0_0,rop3_232_0_1},{rop3_232_1_0,rop3_232_1_1}}, + {{rop3_233_0_0,rop3_233_0_1},{rop3_233_1_0,rop3_233_1_1}}, + {{rop3_234_0_0,rop3_234_0_1},{rop3_234_1_0,rop3_234_1_1}}, + {{rop3_235_0_0,rop3_235_0_1},{rop3_235_1_0,rop3_235_1_1}}, + {{rop3_236_0_0,rop3_236_0_1},{rop3_236_1_0,rop3_236_1_1}}, + {{rop3_237_0_0,rop3_237_0_1},{rop3_237_1_0,rop3_237_1_1}}, + {{rop3_238_0_0,rop3_238_0_1},{rop3_238_1_0,rop3_238_1_1}}, + {{rop3_239_0_0,rop3_239_0_1},{rop3_239_1_0,rop3_239_1_1}}, + {{rop3_240_0_0,rop3_240_0_1},{rop3_240_1_0,rop3_240_1_1}}, + {{rop3_241_0_0,rop3_241_0_1},{rop3_241_1_0,rop3_241_1_1}}, + {{rop3_242_0_0,rop3_242_0_1},{rop3_242_1_0,rop3_242_1_1}}, + {{rop3_243_0_0,rop3_243_0_1},{rop3_243_1_0,rop3_243_1_1}}, + {{rop3_244_0_0,rop3_244_0_1},{rop3_244_1_0,rop3_244_1_1}}, + {{rop3_245_0_0,rop3_245_0_1},{rop3_245_1_0,rop3_245_1_1}}, + {{rop3_246_0_0,rop3_246_0_1},{rop3_246_1_0,rop3_246_1_1}}, + {{rop3_247_0_0,rop3_247_0_1},{rop3_247_1_0,rop3_247_1_1}}, + {{rop3_248_0_0,rop3_248_0_1},{rop3_248_1_0,rop3_248_1_1}}, + {{rop3_249_0_0,rop3_249_0_1},{rop3_249_1_0,rop3_249_1_1}}, + {{rop3_250_0_0,rop3_250_0_1},{rop3_250_1_0,rop3_250_1_1}}, + {{rop3_251_0_0,rop3_251_0_1},{rop3_251_1_0,rop3_251_1_1}}, + {{rop3_252_0_0,rop3_252_0_1},{rop3_252_1_0,rop3_252_1_1}}, + {{rop3_253_0_0,rop3_253_0_1},{rop3_253_1_0,rop3_253_1_1}}, + {{rop3_254_0_0,rop3_254_0_1},{rop3_254_1_0,rop3_254_1_1}}, + {{rop3_255_0_0,rop3_255_0_1},{rop3_255_1_0,rop3_255_1_1}} +}; + +hpgs_rop3_func_t hpgs_rop3_func(int rop3, + hpgs_bool src_transparency, + hpgs_bool pattern_transparency) +{ + if (rop3 < 0 || rop3 >= 256) return 0; + return rop3_table[rop3][src_transparency!=0][pattern_transparency!=0]; +} +static hpgs_xrop3_func_t xrop3_table[][2][2] = { + {{xrop3_0_0_0,xrop3_0_0_1},{xrop3_0_1_0,xrop3_0_1_1}}, + {{xrop3_1_0_0,xrop3_1_0_1},{xrop3_1_1_0,xrop3_1_1_1}}, + {{xrop3_2_0_0,xrop3_2_0_1},{xrop3_2_1_0,xrop3_2_1_1}}, + {{xrop3_3_0_0,xrop3_3_0_1},{xrop3_3_1_0,xrop3_3_1_1}}, + {{xrop3_4_0_0,xrop3_4_0_1},{xrop3_4_1_0,xrop3_4_1_1}}, + {{xrop3_5_0_0,xrop3_5_0_1},{xrop3_5_1_0,xrop3_5_1_1}}, + {{xrop3_6_0_0,xrop3_6_0_1},{xrop3_6_1_0,xrop3_6_1_1}}, + {{xrop3_7_0_0,xrop3_7_0_1},{xrop3_7_1_0,xrop3_7_1_1}}, + {{xrop3_8_0_0,xrop3_8_0_1},{xrop3_8_1_0,xrop3_8_1_1}}, + {{xrop3_9_0_0,xrop3_9_0_1},{xrop3_9_1_0,xrop3_9_1_1}}, + {{xrop3_10_0_0,xrop3_10_0_1},{xrop3_10_1_0,xrop3_10_1_1}}, + {{xrop3_11_0_0,xrop3_11_0_1},{xrop3_11_1_0,xrop3_11_1_1}}, + {{xrop3_12_0_0,xrop3_12_0_1},{xrop3_12_1_0,xrop3_12_1_1}}, + {{xrop3_13_0_0,xrop3_13_0_1},{xrop3_13_1_0,xrop3_13_1_1}}, + {{xrop3_14_0_0,xrop3_14_0_1},{xrop3_14_1_0,xrop3_14_1_1}}, + {{xrop3_15_0_0,xrop3_15_0_1},{xrop3_15_1_0,xrop3_15_1_1}}, + {{xrop3_16_0_0,xrop3_16_0_1},{xrop3_16_1_0,xrop3_16_1_1}}, + {{xrop3_17_0_0,xrop3_17_0_1},{xrop3_17_1_0,xrop3_17_1_1}}, + {{xrop3_18_0_0,xrop3_18_0_1},{xrop3_18_1_0,xrop3_18_1_1}}, + {{xrop3_19_0_0,xrop3_19_0_1},{xrop3_19_1_0,xrop3_19_1_1}}, + {{xrop3_20_0_0,xrop3_20_0_1},{xrop3_20_1_0,xrop3_20_1_1}}, + {{xrop3_21_0_0,xrop3_21_0_1},{xrop3_21_1_0,xrop3_21_1_1}}, + {{xrop3_22_0_0,xrop3_22_0_1},{xrop3_22_1_0,xrop3_22_1_1}}, + {{xrop3_23_0_0,xrop3_23_0_1},{xrop3_23_1_0,xrop3_23_1_1}}, + {{xrop3_24_0_0,xrop3_24_0_1},{xrop3_24_1_0,xrop3_24_1_1}}, + {{xrop3_25_0_0,xrop3_25_0_1},{xrop3_25_1_0,xrop3_25_1_1}}, + {{xrop3_26_0_0,xrop3_26_0_1},{xrop3_26_1_0,xrop3_26_1_1}}, + {{xrop3_27_0_0,xrop3_27_0_1},{xrop3_27_1_0,xrop3_27_1_1}}, + {{xrop3_28_0_0,xrop3_28_0_1},{xrop3_28_1_0,xrop3_28_1_1}}, + {{xrop3_29_0_0,xrop3_29_0_1},{xrop3_29_1_0,xrop3_29_1_1}}, + {{xrop3_30_0_0,xrop3_30_0_1},{xrop3_30_1_0,xrop3_30_1_1}}, + {{xrop3_31_0_0,xrop3_31_0_1},{xrop3_31_1_0,xrop3_31_1_1}}, + {{xrop3_32_0_0,xrop3_32_0_1},{xrop3_32_1_0,xrop3_32_1_1}}, + {{xrop3_33_0_0,xrop3_33_0_1},{xrop3_33_1_0,xrop3_33_1_1}}, + {{xrop3_34_0_0,xrop3_34_0_1},{xrop3_34_1_0,xrop3_34_1_1}}, + {{xrop3_35_0_0,xrop3_35_0_1},{xrop3_35_1_0,xrop3_35_1_1}}, + {{xrop3_36_0_0,xrop3_36_0_1},{xrop3_36_1_0,xrop3_36_1_1}}, + {{xrop3_37_0_0,xrop3_37_0_1},{xrop3_37_1_0,xrop3_37_1_1}}, + {{xrop3_38_0_0,xrop3_38_0_1},{xrop3_38_1_0,xrop3_38_1_1}}, + {{xrop3_39_0_0,xrop3_39_0_1},{xrop3_39_1_0,xrop3_39_1_1}}, + {{xrop3_40_0_0,xrop3_40_0_1},{xrop3_40_1_0,xrop3_40_1_1}}, + {{xrop3_41_0_0,xrop3_41_0_1},{xrop3_41_1_0,xrop3_41_1_1}}, + {{xrop3_42_0_0,xrop3_42_0_1},{xrop3_42_1_0,xrop3_42_1_1}}, + {{xrop3_43_0_0,xrop3_43_0_1},{xrop3_43_1_0,xrop3_43_1_1}}, + {{xrop3_44_0_0,xrop3_44_0_1},{xrop3_44_1_0,xrop3_44_1_1}}, + {{xrop3_45_0_0,xrop3_45_0_1},{xrop3_45_1_0,xrop3_45_1_1}}, + {{xrop3_46_0_0,xrop3_46_0_1},{xrop3_46_1_0,xrop3_46_1_1}}, + {{xrop3_47_0_0,xrop3_47_0_1},{xrop3_47_1_0,xrop3_47_1_1}}, + {{xrop3_48_0_0,xrop3_48_0_1},{xrop3_48_1_0,xrop3_48_1_1}}, + {{xrop3_49_0_0,xrop3_49_0_1},{xrop3_49_1_0,xrop3_49_1_1}}, + {{xrop3_50_0_0,xrop3_50_0_1},{xrop3_50_1_0,xrop3_50_1_1}}, + {{xrop3_51_0_0,xrop3_51_0_1},{xrop3_51_1_0,xrop3_51_1_1}}, + {{xrop3_52_0_0,xrop3_52_0_1},{xrop3_52_1_0,xrop3_52_1_1}}, + {{xrop3_53_0_0,xrop3_53_0_1},{xrop3_53_1_0,xrop3_53_1_1}}, + {{xrop3_54_0_0,xrop3_54_0_1},{xrop3_54_1_0,xrop3_54_1_1}}, + {{xrop3_55_0_0,xrop3_55_0_1},{xrop3_55_1_0,xrop3_55_1_1}}, + {{xrop3_56_0_0,xrop3_56_0_1},{xrop3_56_1_0,xrop3_56_1_1}}, + {{xrop3_57_0_0,xrop3_57_0_1},{xrop3_57_1_0,xrop3_57_1_1}}, + {{xrop3_58_0_0,xrop3_58_0_1},{xrop3_58_1_0,xrop3_58_1_1}}, + {{xrop3_59_0_0,xrop3_59_0_1},{xrop3_59_1_0,xrop3_59_1_1}}, + {{xrop3_60_0_0,xrop3_60_0_1},{xrop3_60_1_0,xrop3_60_1_1}}, + {{xrop3_61_0_0,xrop3_61_0_1},{xrop3_61_1_0,xrop3_61_1_1}}, + {{xrop3_62_0_0,xrop3_62_0_1},{xrop3_62_1_0,xrop3_62_1_1}}, + {{xrop3_63_0_0,xrop3_63_0_1},{xrop3_63_1_0,xrop3_63_1_1}}, + {{xrop3_64_0_0,xrop3_64_0_1},{xrop3_64_1_0,xrop3_64_1_1}}, + {{xrop3_65_0_0,xrop3_65_0_1},{xrop3_65_1_0,xrop3_65_1_1}}, + {{xrop3_66_0_0,xrop3_66_0_1},{xrop3_66_1_0,xrop3_66_1_1}}, + {{xrop3_67_0_0,xrop3_67_0_1},{xrop3_67_1_0,xrop3_67_1_1}}, + {{xrop3_68_0_0,xrop3_68_0_1},{xrop3_68_1_0,xrop3_68_1_1}}, + {{xrop3_69_0_0,xrop3_69_0_1},{xrop3_69_1_0,xrop3_69_1_1}}, + {{xrop3_70_0_0,xrop3_70_0_1},{xrop3_70_1_0,xrop3_70_1_1}}, + {{xrop3_71_0_0,xrop3_71_0_1},{xrop3_71_1_0,xrop3_71_1_1}}, + {{xrop3_72_0_0,xrop3_72_0_1},{xrop3_72_1_0,xrop3_72_1_1}}, + {{xrop3_73_0_0,xrop3_73_0_1},{xrop3_73_1_0,xrop3_73_1_1}}, + {{xrop3_74_0_0,xrop3_74_0_1},{xrop3_74_1_0,xrop3_74_1_1}}, + {{xrop3_75_0_0,xrop3_75_0_1},{xrop3_75_1_0,xrop3_75_1_1}}, + {{xrop3_76_0_0,xrop3_76_0_1},{xrop3_76_1_0,xrop3_76_1_1}}, + {{xrop3_77_0_0,xrop3_77_0_1},{xrop3_77_1_0,xrop3_77_1_1}}, + {{xrop3_78_0_0,xrop3_78_0_1},{xrop3_78_1_0,xrop3_78_1_1}}, + {{xrop3_79_0_0,xrop3_79_0_1},{xrop3_79_1_0,xrop3_79_1_1}}, + {{xrop3_80_0_0,xrop3_80_0_1},{xrop3_80_1_0,xrop3_80_1_1}}, + {{xrop3_81_0_0,xrop3_81_0_1},{xrop3_81_1_0,xrop3_81_1_1}}, + {{xrop3_82_0_0,xrop3_82_0_1},{xrop3_82_1_0,xrop3_82_1_1}}, + {{xrop3_83_0_0,xrop3_83_0_1},{xrop3_83_1_0,xrop3_83_1_1}}, + {{xrop3_84_0_0,xrop3_84_0_1},{xrop3_84_1_0,xrop3_84_1_1}}, + {{xrop3_85_0_0,xrop3_85_0_1},{xrop3_85_1_0,xrop3_85_1_1}}, + {{xrop3_86_0_0,xrop3_86_0_1},{xrop3_86_1_0,xrop3_86_1_1}}, + {{xrop3_87_0_0,xrop3_87_0_1},{xrop3_87_1_0,xrop3_87_1_1}}, + {{xrop3_88_0_0,xrop3_88_0_1},{xrop3_88_1_0,xrop3_88_1_1}}, + {{xrop3_89_0_0,xrop3_89_0_1},{xrop3_89_1_0,xrop3_89_1_1}}, + {{xrop3_90_0_0,xrop3_90_0_1},{xrop3_90_1_0,xrop3_90_1_1}}, + {{xrop3_91_0_0,xrop3_91_0_1},{xrop3_91_1_0,xrop3_91_1_1}}, + {{xrop3_92_0_0,xrop3_92_0_1},{xrop3_92_1_0,xrop3_92_1_1}}, + {{xrop3_93_0_0,xrop3_93_0_1},{xrop3_93_1_0,xrop3_93_1_1}}, + {{xrop3_94_0_0,xrop3_94_0_1},{xrop3_94_1_0,xrop3_94_1_1}}, + {{xrop3_95_0_0,xrop3_95_0_1},{xrop3_95_1_0,xrop3_95_1_1}}, + {{xrop3_96_0_0,xrop3_96_0_1},{xrop3_96_1_0,xrop3_96_1_1}}, + {{xrop3_97_0_0,xrop3_97_0_1},{xrop3_97_1_0,xrop3_97_1_1}}, + {{xrop3_98_0_0,xrop3_98_0_1},{xrop3_98_1_0,xrop3_98_1_1}}, + {{xrop3_99_0_0,xrop3_99_0_1},{xrop3_99_1_0,xrop3_99_1_1}}, + {{xrop3_100_0_0,xrop3_100_0_1},{xrop3_100_1_0,xrop3_100_1_1}}, + {{xrop3_101_0_0,xrop3_101_0_1},{xrop3_101_1_0,xrop3_101_1_1}}, + {{xrop3_102_0_0,xrop3_102_0_1},{xrop3_102_1_0,xrop3_102_1_1}}, + {{xrop3_103_0_0,xrop3_103_0_1},{xrop3_103_1_0,xrop3_103_1_1}}, + {{xrop3_104_0_0,xrop3_104_0_1},{xrop3_104_1_0,xrop3_104_1_1}}, + {{xrop3_105_0_0,xrop3_105_0_1},{xrop3_105_1_0,xrop3_105_1_1}}, + {{xrop3_106_0_0,xrop3_106_0_1},{xrop3_106_1_0,xrop3_106_1_1}}, + {{xrop3_107_0_0,xrop3_107_0_1},{xrop3_107_1_0,xrop3_107_1_1}}, + {{xrop3_108_0_0,xrop3_108_0_1},{xrop3_108_1_0,xrop3_108_1_1}}, + {{xrop3_109_0_0,xrop3_109_0_1},{xrop3_109_1_0,xrop3_109_1_1}}, + {{xrop3_110_0_0,xrop3_110_0_1},{xrop3_110_1_0,xrop3_110_1_1}}, + {{xrop3_111_0_0,xrop3_111_0_1},{xrop3_111_1_0,xrop3_111_1_1}}, + {{xrop3_112_0_0,xrop3_112_0_1},{xrop3_112_1_0,xrop3_112_1_1}}, + {{xrop3_113_0_0,xrop3_113_0_1},{xrop3_113_1_0,xrop3_113_1_1}}, + {{xrop3_114_0_0,xrop3_114_0_1},{xrop3_114_1_0,xrop3_114_1_1}}, + {{xrop3_115_0_0,xrop3_115_0_1},{xrop3_115_1_0,xrop3_115_1_1}}, + {{xrop3_116_0_0,xrop3_116_0_1},{xrop3_116_1_0,xrop3_116_1_1}}, + {{xrop3_117_0_0,xrop3_117_0_1},{xrop3_117_1_0,xrop3_117_1_1}}, + {{xrop3_118_0_0,xrop3_118_0_1},{xrop3_118_1_0,xrop3_118_1_1}}, + {{xrop3_119_0_0,xrop3_119_0_1},{xrop3_119_1_0,xrop3_119_1_1}}, + {{xrop3_120_0_0,xrop3_120_0_1},{xrop3_120_1_0,xrop3_120_1_1}}, + {{xrop3_121_0_0,xrop3_121_0_1},{xrop3_121_1_0,xrop3_121_1_1}}, + {{xrop3_122_0_0,xrop3_122_0_1},{xrop3_122_1_0,xrop3_122_1_1}}, + {{xrop3_123_0_0,xrop3_123_0_1},{xrop3_123_1_0,xrop3_123_1_1}}, + {{xrop3_124_0_0,xrop3_124_0_1},{xrop3_124_1_0,xrop3_124_1_1}}, + {{xrop3_125_0_0,xrop3_125_0_1},{xrop3_125_1_0,xrop3_125_1_1}}, + {{xrop3_126_0_0,xrop3_126_0_1},{xrop3_126_1_0,xrop3_126_1_1}}, + {{xrop3_127_0_0,xrop3_127_0_1},{xrop3_127_1_0,xrop3_127_1_1}}, + {{xrop3_128_0_0,xrop3_128_0_1},{xrop3_128_1_0,xrop3_128_1_1}}, + {{xrop3_129_0_0,xrop3_129_0_1},{xrop3_129_1_0,xrop3_129_1_1}}, + {{xrop3_130_0_0,xrop3_130_0_1},{xrop3_130_1_0,xrop3_130_1_1}}, + {{xrop3_131_0_0,xrop3_131_0_1},{xrop3_131_1_0,xrop3_131_1_1}}, + {{xrop3_132_0_0,xrop3_132_0_1},{xrop3_132_1_0,xrop3_132_1_1}}, + {{xrop3_133_0_0,xrop3_133_0_1},{xrop3_133_1_0,xrop3_133_1_1}}, + {{xrop3_134_0_0,xrop3_134_0_1},{xrop3_134_1_0,xrop3_134_1_1}}, + {{xrop3_135_0_0,xrop3_135_0_1},{xrop3_135_1_0,xrop3_135_1_1}}, + {{xrop3_136_0_0,xrop3_136_0_1},{xrop3_136_1_0,xrop3_136_1_1}}, + {{xrop3_137_0_0,xrop3_137_0_1},{xrop3_137_1_0,xrop3_137_1_1}}, + {{xrop3_138_0_0,xrop3_138_0_1},{xrop3_138_1_0,xrop3_138_1_1}}, + {{xrop3_139_0_0,xrop3_139_0_1},{xrop3_139_1_0,xrop3_139_1_1}}, + {{xrop3_140_0_0,xrop3_140_0_1},{xrop3_140_1_0,xrop3_140_1_1}}, + {{xrop3_141_0_0,xrop3_141_0_1},{xrop3_141_1_0,xrop3_141_1_1}}, + {{xrop3_142_0_0,xrop3_142_0_1},{xrop3_142_1_0,xrop3_142_1_1}}, + {{xrop3_143_0_0,xrop3_143_0_1},{xrop3_143_1_0,xrop3_143_1_1}}, + {{xrop3_144_0_0,xrop3_144_0_1},{xrop3_144_1_0,xrop3_144_1_1}}, + {{xrop3_145_0_0,xrop3_145_0_1},{xrop3_145_1_0,xrop3_145_1_1}}, + {{xrop3_146_0_0,xrop3_146_0_1},{xrop3_146_1_0,xrop3_146_1_1}}, + {{xrop3_147_0_0,xrop3_147_0_1},{xrop3_147_1_0,xrop3_147_1_1}}, + {{xrop3_148_0_0,xrop3_148_0_1},{xrop3_148_1_0,xrop3_148_1_1}}, + {{xrop3_149_0_0,xrop3_149_0_1},{xrop3_149_1_0,xrop3_149_1_1}}, + {{xrop3_150_0_0,xrop3_150_0_1},{xrop3_150_1_0,xrop3_150_1_1}}, + {{xrop3_151_0_0,xrop3_151_0_1},{xrop3_151_1_0,xrop3_151_1_1}}, + {{xrop3_152_0_0,xrop3_152_0_1},{xrop3_152_1_0,xrop3_152_1_1}}, + {{xrop3_153_0_0,xrop3_153_0_1},{xrop3_153_1_0,xrop3_153_1_1}}, + {{xrop3_154_0_0,xrop3_154_0_1},{xrop3_154_1_0,xrop3_154_1_1}}, + {{xrop3_155_0_0,xrop3_155_0_1},{xrop3_155_1_0,xrop3_155_1_1}}, + {{xrop3_156_0_0,xrop3_156_0_1},{xrop3_156_1_0,xrop3_156_1_1}}, + {{xrop3_157_0_0,xrop3_157_0_1},{xrop3_157_1_0,xrop3_157_1_1}}, + {{xrop3_158_0_0,xrop3_158_0_1},{xrop3_158_1_0,xrop3_158_1_1}}, + {{xrop3_159_0_0,xrop3_159_0_1},{xrop3_159_1_0,xrop3_159_1_1}}, + {{xrop3_160_0_0,xrop3_160_0_1},{xrop3_160_1_0,xrop3_160_1_1}}, + {{xrop3_161_0_0,xrop3_161_0_1},{xrop3_161_1_0,xrop3_161_1_1}}, + {{xrop3_162_0_0,xrop3_162_0_1},{xrop3_162_1_0,xrop3_162_1_1}}, + {{xrop3_163_0_0,xrop3_163_0_1},{xrop3_163_1_0,xrop3_163_1_1}}, + {{xrop3_164_0_0,xrop3_164_0_1},{xrop3_164_1_0,xrop3_164_1_1}}, + {{xrop3_165_0_0,xrop3_165_0_1},{xrop3_165_1_0,xrop3_165_1_1}}, + {{xrop3_166_0_0,xrop3_166_0_1},{xrop3_166_1_0,xrop3_166_1_1}}, + {{xrop3_167_0_0,xrop3_167_0_1},{xrop3_167_1_0,xrop3_167_1_1}}, + {{xrop3_168_0_0,xrop3_168_0_1},{xrop3_168_1_0,xrop3_168_1_1}}, + {{xrop3_169_0_0,xrop3_169_0_1},{xrop3_169_1_0,xrop3_169_1_1}}, + {{xrop3_170_0_0,xrop3_170_0_1},{xrop3_170_1_0,xrop3_170_1_1}}, + {{xrop3_171_0_0,xrop3_171_0_1},{xrop3_171_1_0,xrop3_171_1_1}}, + {{xrop3_172_0_0,xrop3_172_0_1},{xrop3_172_1_0,xrop3_172_1_1}}, + {{xrop3_173_0_0,xrop3_173_0_1},{xrop3_173_1_0,xrop3_173_1_1}}, + {{xrop3_174_0_0,xrop3_174_0_1},{xrop3_174_1_0,xrop3_174_1_1}}, + {{xrop3_175_0_0,xrop3_175_0_1},{xrop3_175_1_0,xrop3_175_1_1}}, + {{xrop3_176_0_0,xrop3_176_0_1},{xrop3_176_1_0,xrop3_176_1_1}}, + {{xrop3_177_0_0,xrop3_177_0_1},{xrop3_177_1_0,xrop3_177_1_1}}, + {{xrop3_178_0_0,xrop3_178_0_1},{xrop3_178_1_0,xrop3_178_1_1}}, + {{xrop3_179_0_0,xrop3_179_0_1},{xrop3_179_1_0,xrop3_179_1_1}}, + {{xrop3_180_0_0,xrop3_180_0_1},{xrop3_180_1_0,xrop3_180_1_1}}, + {{xrop3_181_0_0,xrop3_181_0_1},{xrop3_181_1_0,xrop3_181_1_1}}, + {{xrop3_182_0_0,xrop3_182_0_1},{xrop3_182_1_0,xrop3_182_1_1}}, + {{xrop3_183_0_0,xrop3_183_0_1},{xrop3_183_1_0,xrop3_183_1_1}}, + {{xrop3_184_0_0,xrop3_184_0_1},{xrop3_184_1_0,xrop3_184_1_1}}, + {{xrop3_185_0_0,xrop3_185_0_1},{xrop3_185_1_0,xrop3_185_1_1}}, + {{xrop3_186_0_0,xrop3_186_0_1},{xrop3_186_1_0,xrop3_186_1_1}}, + {{xrop3_187_0_0,xrop3_187_0_1},{xrop3_187_1_0,xrop3_187_1_1}}, + {{xrop3_188_0_0,xrop3_188_0_1},{xrop3_188_1_0,xrop3_188_1_1}}, + {{xrop3_189_0_0,xrop3_189_0_1},{xrop3_189_1_0,xrop3_189_1_1}}, + {{xrop3_190_0_0,xrop3_190_0_1},{xrop3_190_1_0,xrop3_190_1_1}}, + {{xrop3_191_0_0,xrop3_191_0_1},{xrop3_191_1_0,xrop3_191_1_1}}, + {{xrop3_192_0_0,xrop3_192_0_1},{xrop3_192_1_0,xrop3_192_1_1}}, + {{xrop3_193_0_0,xrop3_193_0_1},{xrop3_193_1_0,xrop3_193_1_1}}, + {{xrop3_194_0_0,xrop3_194_0_1},{xrop3_194_1_0,xrop3_194_1_1}}, + {{xrop3_195_0_0,xrop3_195_0_1},{xrop3_195_1_0,xrop3_195_1_1}}, + {{xrop3_196_0_0,xrop3_196_0_1},{xrop3_196_1_0,xrop3_196_1_1}}, + {{xrop3_197_0_0,xrop3_197_0_1},{xrop3_197_1_0,xrop3_197_1_1}}, + {{xrop3_198_0_0,xrop3_198_0_1},{xrop3_198_1_0,xrop3_198_1_1}}, + {{xrop3_199_0_0,xrop3_199_0_1},{xrop3_199_1_0,xrop3_199_1_1}}, + {{xrop3_200_0_0,xrop3_200_0_1},{xrop3_200_1_0,xrop3_200_1_1}}, + {{xrop3_201_0_0,xrop3_201_0_1},{xrop3_201_1_0,xrop3_201_1_1}}, + {{xrop3_202_0_0,xrop3_202_0_1},{xrop3_202_1_0,xrop3_202_1_1}}, + {{xrop3_203_0_0,xrop3_203_0_1},{xrop3_203_1_0,xrop3_203_1_1}}, + {{xrop3_204_0_0,xrop3_204_0_1},{xrop3_204_1_0,xrop3_204_1_1}}, + {{xrop3_205_0_0,xrop3_205_0_1},{xrop3_205_1_0,xrop3_205_1_1}}, + {{xrop3_206_0_0,xrop3_206_0_1},{xrop3_206_1_0,xrop3_206_1_1}}, + {{xrop3_207_0_0,xrop3_207_0_1},{xrop3_207_1_0,xrop3_207_1_1}}, + {{xrop3_208_0_0,xrop3_208_0_1},{xrop3_208_1_0,xrop3_208_1_1}}, + {{xrop3_209_0_0,xrop3_209_0_1},{xrop3_209_1_0,xrop3_209_1_1}}, + {{xrop3_210_0_0,xrop3_210_0_1},{xrop3_210_1_0,xrop3_210_1_1}}, + {{xrop3_211_0_0,xrop3_211_0_1},{xrop3_211_1_0,xrop3_211_1_1}}, + {{xrop3_212_0_0,xrop3_212_0_1},{xrop3_212_1_0,xrop3_212_1_1}}, + {{xrop3_213_0_0,xrop3_213_0_1},{xrop3_213_1_0,xrop3_213_1_1}}, + {{xrop3_214_0_0,xrop3_214_0_1},{xrop3_214_1_0,xrop3_214_1_1}}, + {{xrop3_215_0_0,xrop3_215_0_1},{xrop3_215_1_0,xrop3_215_1_1}}, + {{xrop3_216_0_0,xrop3_216_0_1},{xrop3_216_1_0,xrop3_216_1_1}}, + {{xrop3_217_0_0,xrop3_217_0_1},{xrop3_217_1_0,xrop3_217_1_1}}, + {{xrop3_218_0_0,xrop3_218_0_1},{xrop3_218_1_0,xrop3_218_1_1}}, + {{xrop3_219_0_0,xrop3_219_0_1},{xrop3_219_1_0,xrop3_219_1_1}}, + {{xrop3_220_0_0,xrop3_220_0_1},{xrop3_220_1_0,xrop3_220_1_1}}, + {{xrop3_221_0_0,xrop3_221_0_1},{xrop3_221_1_0,xrop3_221_1_1}}, + {{xrop3_222_0_0,xrop3_222_0_1},{xrop3_222_1_0,xrop3_222_1_1}}, + {{xrop3_223_0_0,xrop3_223_0_1},{xrop3_223_1_0,xrop3_223_1_1}}, + {{xrop3_224_0_0,xrop3_224_0_1},{xrop3_224_1_0,xrop3_224_1_1}}, + {{xrop3_225_0_0,xrop3_225_0_1},{xrop3_225_1_0,xrop3_225_1_1}}, + {{xrop3_226_0_0,xrop3_226_0_1},{xrop3_226_1_0,xrop3_226_1_1}}, + {{xrop3_227_0_0,xrop3_227_0_1},{xrop3_227_1_0,xrop3_227_1_1}}, + {{xrop3_228_0_0,xrop3_228_0_1},{xrop3_228_1_0,xrop3_228_1_1}}, + {{xrop3_229_0_0,xrop3_229_0_1},{xrop3_229_1_0,xrop3_229_1_1}}, + {{xrop3_230_0_0,xrop3_230_0_1},{xrop3_230_1_0,xrop3_230_1_1}}, + {{xrop3_231_0_0,xrop3_231_0_1},{xrop3_231_1_0,xrop3_231_1_1}}, + {{xrop3_232_0_0,xrop3_232_0_1},{xrop3_232_1_0,xrop3_232_1_1}}, + {{xrop3_233_0_0,xrop3_233_0_1},{xrop3_233_1_0,xrop3_233_1_1}}, + {{xrop3_234_0_0,xrop3_234_0_1},{xrop3_234_1_0,xrop3_234_1_1}}, + {{xrop3_235_0_0,xrop3_235_0_1},{xrop3_235_1_0,xrop3_235_1_1}}, + {{xrop3_236_0_0,xrop3_236_0_1},{xrop3_236_1_0,xrop3_236_1_1}}, + {{xrop3_237_0_0,xrop3_237_0_1},{xrop3_237_1_0,xrop3_237_1_1}}, + {{xrop3_238_0_0,xrop3_238_0_1},{xrop3_238_1_0,xrop3_238_1_1}}, + {{xrop3_239_0_0,xrop3_239_0_1},{xrop3_239_1_0,xrop3_239_1_1}}, + {{xrop3_240_0_0,xrop3_240_0_1},{xrop3_240_1_0,xrop3_240_1_1}}, + {{xrop3_241_0_0,xrop3_241_0_1},{xrop3_241_1_0,xrop3_241_1_1}}, + {{xrop3_242_0_0,xrop3_242_0_1},{xrop3_242_1_0,xrop3_242_1_1}}, + {{xrop3_243_0_0,xrop3_243_0_1},{xrop3_243_1_0,xrop3_243_1_1}}, + {{xrop3_244_0_0,xrop3_244_0_1},{xrop3_244_1_0,xrop3_244_1_1}}, + {{xrop3_245_0_0,xrop3_245_0_1},{xrop3_245_1_0,xrop3_245_1_1}}, + {{xrop3_246_0_0,xrop3_246_0_1},{xrop3_246_1_0,xrop3_246_1_1}}, + {{xrop3_247_0_0,xrop3_247_0_1},{xrop3_247_1_0,xrop3_247_1_1}}, + {{xrop3_248_0_0,xrop3_248_0_1},{xrop3_248_1_0,xrop3_248_1_1}}, + {{xrop3_249_0_0,xrop3_249_0_1},{xrop3_249_1_0,xrop3_249_1_1}}, + {{xrop3_250_0_0,xrop3_250_0_1},{xrop3_250_1_0,xrop3_250_1_1}}, + {{xrop3_251_0_0,xrop3_251_0_1},{xrop3_251_1_0,xrop3_251_1_1}}, + {{xrop3_252_0_0,xrop3_252_0_1},{xrop3_252_1_0,xrop3_252_1_1}}, + {{xrop3_253_0_0,xrop3_253_0_1},{xrop3_253_1_0,xrop3_253_1_1}}, + {{xrop3_254_0_0,xrop3_254_0_1},{xrop3_254_1_0,xrop3_254_1_1}}, + {{xrop3_255_0_0,xrop3_255_0_1},{xrop3_255_1_0,xrop3_255_1_1}} +}; + +hpgs_xrop3_func_t hpgs_xrop3_func(int rop3, + hpgs_bool src_transparency, + hpgs_bool pattern_transparency) +{ + if (rop3 < 0 || rop3 >= 256) return 0; + return xrop3_table[rop3][src_transparency!=0][pattern_transparency!=0]; +} diff --git a/src/add-ons/translators/hpgs/lib/hpgsscanline.c b/src/add-ons/translators/hpgs/lib/hpgsscanline.c new file mode 100644 index 0000000000..5fa4514bba --- /dev/null +++ b/src/add-ons/translators/hpgs/lib/hpgsscanline.c @@ -0,0 +1,2585 @@ +/*********************************************************************** + * * + * $Id: hpgsscanline.c 374 2007-01-24 15:57:52Z softadm $ + * * + * hpgs - HPGl Script, a hpgl/2 interpreter, which uses a Postscript * + * API for rendering a scene and thus renders to a variety of * + * devices and fileformats. * + * * + * (C) 2004-2006 ev-i Informationstechnologie GmbH http://www.ev-i.at * + * * + * Author: Wolfgang Glas * + * * + * hpgs is free software; you can redistribute it and/or * + * modify it under the terms of the GNU Lesser General Public * + * License as published by the Free Software Foundation; either * + * version 2.1 of the License, or (at your option) any later version. * + * * + * hpgs is distributed in the hope that it will be useful, * + * but WITHOUT ANY WARRANTY; without even the implied warranty of * + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * + * Lesser General Public License for more details. * + * * + * You should have received a copy of the GNU Lesser General Public * + * License along with this library; if not, write to the * + * Free Software Foundation, Inc., 59 Temple Place, Suite 330, * + * Boston, MA 02111-1307 USA * + * * + *********************************************************************** + * * + * The implementation of the API for scanline handling. * + * * + ***********************************************************************/ + +#include +#include +#include +#if defined ( __MINGW32__ ) || defined ( _MSC_VER ) +#include +#else +#include +#endif + +//#define HPGS_DEBUG_CUT +//#define HPGS_DEBUG_THIN_CUT +//#define HPGS_DEBUG_ALPHA_CUT +//#define HPGS_DEBUG_EMIT_ALPHA +//#define HPGS_DEBUG_EMIT_0 +//#define HPGS_DEBUG_CLIP + +static int hpgs_paint_scanline_add_point(hpgs_paint_scanline *s, double x, int o); +static int hpgs_paint_scanline_add_slope(hpgs_paint_scanline *s, double x1, double x2, int o1, int o2); + +/*! \defgroup scanline scanline handling. + + This module contains the documentation of the internals + of the vector graphics renderer \c hpgs_paint_device. + + The dcomumentation of \c hpgs_paint_clipper_st explains the + concepts used throughout the implementation of the objects + in this module. +*/ + +/*! + Initializes the given scanline structure for the given initial size \c msize + of intersection points. The minimal value of \c msize is 4. + + Return value: + \li 0 Success. + \li -1 The system is out of memory. +*/ +static int hpgs_paint_scanline_init(hpgs_paint_scanline *s, int msize) +{ + s->points_malloc_size = msize < 4 ? 4 : msize; + s->n_points = 0; + s->points = (hpgs_scanline_point *)malloc(sizeof(hpgs_scanline_point)*s->points_malloc_size); + + return s->points ? 0 : -1; +} + +/*! + Frees the vector of of intersection points of the given scanline. +*/ +static void hpgs_paint_scanline_cleanup(hpgs_paint_scanline *s) +{ + if (s->points) + free(s->points); +} + +/* Internal: + Adds an edge of a path to the given scanline. + + \c order 1 is the intersection order + (1 upwards, 0 horizontal, -1 downwards) + of the path segment before the given edge point. + + \c order2 is the intersection order + of the path segment after the given edge point. + + If the two orders are of a different sign ((1,-1) or (-1,1)), + the edge is inserted twice with an opposite sign in order to draw + line segments of width 0. + + Return value: + \li 0 Success. + \li -1 The system is out of memory. +*/ +static int add_edge(hpgs_paint_scanline *s, + hpgs_path_point *point, + int order1, int order2) +{ +#ifdef HPGS_DEBUG_CUT + hpgs_log("add_edge: x,y,o1,o2 = %lg,%lg,%d,%d.\n", + point->p.x,point->p.y,order1,order2); +#endif + if (order1+order2 > 0) + { + if (hpgs_paint_scanline_add_point(s,point->p.x,1)) + return -1; + } + else if (order1+order2 < 0) + { + if (hpgs_paint_scanline_add_point(s,point->p.x,-1)) + return -1; + } + else + if (order1 > 0) + { + if (hpgs_paint_scanline_add_point(s,point->p.x,1) || + hpgs_paint_scanline_add_point(s,point->p.x,-1) ) + return -1; + } + else if (order1 < 0) + { + if (hpgs_paint_scanline_add_point(s,point->p.x,-1) || + hpgs_paint_scanline_add_point(s,point->p.x,1) ) + return -1; + } + + return 0; +} + +/* Internal: + Sorts the intersection points of the the given scanline + using merge sort. Merge sort is used in order to preserve + the order of two equal x positions with opposite sign. + (see add_egde above) + + As a side effect, this approach is ways faster than qsort(). + + Internal routine. Driver routine below. +*/ +static void scanline_msort(hpgs_scanline_point *a, int n, + hpgs_scanline_point *res, + hpgs_scanline_point *tmp ) +{ + int n1 = n/2; + int n2 = n - n1; + hpgs_scanline_point *b=a+n1; + hpgs_scanline_point *te=tmp+n1; + hpgs_scanline_point *be=a+n; + + // sort first half of a into tmp. + switch (n1) + { + case 1: + *tmp = *a; + case 0: + break; + default: + scanline_msort(a,n1,tmp,te); + } + + // sort second half of a (aka b) in place. + if (n2 > 1) + scanline_msort(b,n2,b,te); + + // now merge the results. + while (tmp < te && b < be) + { + // stable sort characteristics: prefer first half. + if (tmp->x <= b->x) + *res = *tmp++; + else + *res = *b++; + + ++res; + } + + // copy rest of first sorted half + while (tmp < te) + *res++ = *tmp++; + + // copy rest of second half, if not co-located + if (res!=b) + while (b < be) + *res++ = *b++; +} + +/* Internal: + Sorts the intersection points of the the given scanline + using merge sort. Internal subroutine and docs above. +*/ +static void scanline_sort (hpgs_scanline_point *a, int n) +{ + hpgs_scanline_point *tmp = hpgs_alloca(sizeof(hpgs_scanline_point) * n); + + scanline_msort(a,n,a,tmp); +} + +/* Internal: + Cuts the bezier segment with the scanlines of the clipper. + + Returns the scanline number of the endpoint hit or -1, + if endpoint is not an exact hit. + + Upon memory error return -2; +*/ + +static int bezier_clipper_cut (hpgs_paint_clipper *c, + hpgs_paint_path *path, int i, + double t0, double t1, + double y0, + double y1, + double y2, + double y3 ) +{ + double ymin0 = (y0 < y1) ? y0 : y1; + double ymin1 = (y2 < y3) ? y2 : y3; + double ymin = ymin0 y1) ? y0 : y1; + double ymax1 = (y2 > y3) ? y2 : y3; + double ymax = ymax0>ymax1 ? ymax0 : ymax1; + + double dscan0 = (c->y0 - ymax)/c->yfac; + double dscan1 = (c->y0 - ymin)/c->yfac; + + double rdscan0 = ceil(dscan0); + double rdscan1 = floor(dscan1); + + int iscan0 = (int)rdscan0; + int iscan1 = (int)rdscan1; + + if (iscan0 > iscan1 || iscan1 < 0 || iscan0 >= c->n_scanlines) + { + return -1; + } + else if (t1-t0 < 1.0e-8 && iscan0 == iscan1) + { + int o0; + + if (y1 > y0) o0 = 1; + else if (y1 < y0) o0 = -1; + else if (y2 > y0) o0 = 1; + else if (y2 < y0) o0 = -1; + else if (y3 > y0) o0 = 1; + else if (y3 < y0) o0 = -1; + else o0 = 0; + + int o1; + + if (y2 > y3) o1 = -1; + else if (y2 < y3) o1 = 1; + else if (y1 > y3) o1 = -1; + else if (y1 < y3) o1 = 1; + else if (y0 > y3) o1 = -1; + else if (y0 < y3) o1 = 1; + else o1 = 0; + + // horizontal cut. + if (o0*o1 == 0) + { + return -1; + } + + // filter out startpoint hit. + if (t0 == -0.5 && + ((y0 == ymin && dscan1 == rdscan1) || + (y0 == ymax && dscan0 == rdscan0) )) return -1; + + // filter out endpoint hit. + if (t1 == 0.5 && + ((y3 == ymin && dscan1 == rdscan1) || + (y3 == ymax && dscan0 == rdscan0) )) return iscan0; + + if (iscan0 < c->iscan0) c->iscan0 = iscan0; + if (iscan0 > c->iscan1) c->iscan1 = iscan0; + + if (o0*o1 > 0) + { + if (hpgs_paint_scanline_add_point(c->scanlines+iscan0, + hpgs_bezier_path_x(path,i,0.5*(t0+t1)), + o0)) + return -2; + + return -1; + } + else + { + if (hpgs_paint_scanline_add_point(c->scanlines+iscan0, + hpgs_bezier_path_x(path,i,t0), + o0)) + return -2; + + if (hpgs_paint_scanline_add_point(c->scanlines+iscan0, + hpgs_bezier_path_x(path,i,t1), + o1)) + return -2; + + return -1; + } + } + else if (t1-t0 < 1.0e-15) + { + return -1; + } + else + { + // partition the spline. + double tmid = 0.5*(t0+t1); + + // midpoint. + double ymid,y1l,y2l,y1u,y2u; + + y1l = 0.5 * (y0 + y1); + + y2l = 0.25 * (y0 + y2) + 0.5 * y1; + + ymid = + (y0 + y3) * 0.125 + 0.375 * (y1 + y2); + + y1u = 0.25 * (y1 + y3) + 0.5 * y2; + + y2u = 0.5 * (y2 + y3); + + if (bezier_clipper_cut (c,path,i,t0,tmid,y0,y1l,y2l,ymid) < -1) + return -2; + + return bezier_clipper_cut (c,path,i,tmid,t1,ymid,y1u,y2u,y3); + } +} + +/*! + Cuts te given \c path with the scanlines of the given + clipper \c c. If you emit the clipper afterwards, the interior + of the given path is drawn to the image. + + If you want to stroke the path use either \c hpgs_paint_clipper_thin_cut + for thin lines or contruct the outline of a thick line using + the line style of a graphics state with \c hpgs_paint_path_stroke_path. + + Return value: + \li 0 Success. + \li -1 The system is out of memory. +*/ +static int hpgs_paint_clipper_cut_0(hpgs_paint_clipper *c, + hpgs_paint_path *path) +{ + int i; + int start_order=0,last_order=0; + hpgs_path_point *deferred_edge_cut = 0; + int deferred_edge_cut_is = -1; + int iscan; + + // catch path' which lie outside of the area of interest. + if (path->bb.urx < c->bb.llx) return 0; + if (path->bb.llx > c->bb.urx) return 0; + if (path->bb.ury < c->bb.lly) return 0; + if (path->bb.lly > c->bb.ury) return 0; + + for (i=0;in_points;++i) + { + hpgs_path_point *point = &path->points[i]; + hpgs_path_point *next_point; + hpgs_path_point *next_edge_cut=0; + int next_edge_cut_is=-1; + + int order1 = 0; + int order2 = 0; + int iscan0,iscan1; + + switch (point->flags & HPGS_POINT_ROLE_MASK) + { + case HPGS_POINT_LINE: + case HPGS_POINT_FILL_LINE: + { + next_point = &path->points[i+1]; + + double dscan0 = (c->y0 - point->p.y)/c->yfac; + double dscan1 = (c->y0 - next_point->p.y)/c->yfac; + +#ifdef HPGS_DEBUG_CUT + hpgs_log("cut_line: x1,y1,x2,y2 = %lg,%lg,%lg,%lg.\n", + point->p.x,point->p.y,next_point->p.x,next_point->p.y); +#endif + + + if (dscan0 < dscan1) + { + double rdscan0 = ceil(dscan0); + double rdscan1 = floor(dscan1); + + iscan0 = (int)rdscan0; + iscan1 = (int)rdscan1; + + // startpoint hit + if (rdscan0 == dscan0) + ++iscan0; + + // endpoint hit + if (rdscan1 == dscan1) + { + if (iscan1 >= 0 && iscan1 < c->n_scanlines) + { + next_edge_cut = next_point; + next_edge_cut_is = iscan1; + } + --iscan1; + } + } + else + { + double rdscan0 = ceil(dscan1); + double rdscan1 = floor(dscan0); + + iscan0 = (int)rdscan0; + iscan1 = (int)rdscan1; + + // startpoint hit + if (rdscan1 == dscan1) + --iscan1; + + // endpoint hit + if (rdscan0 == dscan0) + { + if (iscan0 >= 0 && iscan0 < c->n_scanlines) + { + next_edge_cut = next_point; + next_edge_cut_is = iscan0; + } + ++iscan0; + } + } + + if (iscan0 < 0) iscan0 = 0; + if (iscan1 >= c->n_scanlines) iscan1 = c->n_scanlines-1; + + if (iscan0 < c->iscan0) c->iscan0 = iscan0; + if (iscan1 > c->iscan1) c->iscan1 = iscan1; + + if (next_point->p.y > point->p.y) + order1 = 1; + else if (next_point->p.y < point->p.y) + order1 = -1; + else + order1 = 0; + + order2 = order1; + + if (point->p.x != next_point->p.x) + for (iscan=iscan0;iscan<=iscan1;++iscan) + { + double y = c->y0 - iscan * c->yfac; + double x = + (point->p.x * (next_point->p.y - y) + + next_point->p.x * (y - point->p.y) ) / + (next_point->p.y - point->p.y); + + if (hpgs_paint_scanline_add_point(c->scanlines+iscan,x,order1)) + return -1; + } + else + for (iscan=iscan0;iscan<=iscan1;++iscan) + { + if (hpgs_paint_scanline_add_point(c->scanlines+iscan, + point->p.x,order1)) + return -1; + } + } + break; + case HPGS_POINT_BEZIER: + next_point = &path->points[i+3]; + +#ifdef HPGS_DEBUG_CUT + hpgs_log("cut_bezier: x1,y1,x4,y4 = %lg,%lg,%lg,%lg.\n", + point->p.x,point->p.y,next_point->p.x,next_point->p.y); +#endif + + if (path->points[i+1].p.y > point->p.y) + order1 = 1; + else if (path->points[i+1].p.y < point->p.y) + order1 = -1; + else if (path->points[i+2].p.y > point->p.y) + order1 = 1; + else if (path->points[i+2].p.y < point->p.y) + order1 = -1; + else if (next_point->p.y > point->p.y) + order1 = 1; + else if (next_point->p.y < point->p.y) + order1 = -1; + else + order1 = 0; + + if (path->points[i+2].p.y < next_point->p.y) + order2 = 1; + else if (path->points[i+2].p.y > next_point->p.y) + order2 = -1; + else if (path->points[i+1].p.y < next_point->p.y) + order2 = 1; + else if (path->points[i+1].p.y > next_point->p.y) + order2 = -1; + else if (point->p.y < next_point->p.y) + order2 = 1; + else if (point->p.y > next_point->p.y) + order2 = -1; + else + order2 = 0; + + iscan1 = bezier_clipper_cut (c,path,i,-0.5,0.5, + point->p.y, + path->points[i+1].p.y, + path->points[i+2].p.y, + next_point->p.y ); + + if (iscan1 < -1) return -1; + + if (iscan1 >= 0 && iscan1 < c->n_scanlines) + { + next_edge_cut = next_point; + next_edge_cut_is = iscan1; + } + + // ignore control points. + i+=2; + break; + } + + if (point->flags & HPGS_POINT_SUBPATH_END) + { + if (deferred_edge_cut) + if (add_edge(c->scanlines+deferred_edge_cut_is, + deferred_edge_cut,last_order,start_order)) + return -1; + } + else + { + if (deferred_edge_cut) + if (add_edge(c->scanlines+deferred_edge_cut_is, + deferred_edge_cut,last_order,order1)) + return -1; + } + + if (point->flags & HPGS_POINT_SUBPATH_START) + start_order = order1; + + last_order = order2; + deferred_edge_cut = next_edge_cut; + deferred_edge_cut_is = next_edge_cut_is; + } + + if (deferred_edge_cut) + if (add_edge(c->scanlines+deferred_edge_cut_is, + deferred_edge_cut,last_order,start_order)) + return -1; + + // search for minimal figures, which did not hit any scanline + // (horizontal fills with a height below 1 pixel...). + if (c->iscan0 > c->iscan1 && path->n_points) + { + iscan = (int)floor((c->y0 - 0.5 * (path->bb.lly + path->bb.ury))/c->yfac + 0.5); + +#ifdef HPGS_DEBUG_CUT + hpgs_log("cut_minimal: llx,lly,urx,ury,iscan,n = %lg,%lg,%lg,%lg.\n", + path->bb.llx,path->bb.lly,path->bb.urx,path->bb.ury); +#endif + + if (iscan < 0 || iscan >= c->n_scanlines) return 0; + + c->iscan0 = c->iscan1 = iscan; + + if (hpgs_paint_scanline_add_point(c->scanlines+iscan,path->bb.llx,1) || + hpgs_paint_scanline_add_point(c->scanlines+iscan,path->bb.urx,-1) ) + return -1; + + return 0; + } + + for (iscan = c->iscan0;iscan<=c->iscan1;++iscan) + { + scanline_sort(c->scanlines[iscan].points,c->scanlines[iscan].n_points); +#ifdef HPGS_DEBUG_CUT + { + int j; + + hpgs_log("iscan = %d, np = %d ****************************************\n", + iscan,c->scanlines[iscan].n_points); + + if (c->scanlines[iscan].n_points & 1) + hpgs_log("np odd !!!!!!!!!!!!!!!\n"); + + for (j=0;jscanlines[iscan].n_points;++j) + hpgs_log("%lg(%d) ", + c->scanlines[iscan].points[j].x, + c->scanlines[iscan].points[j].order); + + hpgs_log("\n"); + } +#endif + } + + return 0; +} + +/* Internal: + Cuts the bezier segment with the scanlines of the clipper + as for thin lines. + + Returns 0 upon success or -1 on memory error. +*/ + +typedef struct hpgs_bezier_clipper_thin_cut_data_st hpgs_bezier_clipper_thin_cut_data; + +struct hpgs_bezier_clipper_thin_cut_data_st +{ + hpgs_paint_clipper *c; + hpgs_paint_path *path; + int i; + + double t0; + double t1; + + double t_last; + double x_last; + int iscan_last; +}; + +static int hpgs_bezier_clipper_thin_cut_data_push(hpgs_bezier_clipper_thin_cut_data *d, + double t, double x, int iscan, int o) +{ + if (d->iscan_last >= 0 && d->iscan_last < d->c->n_scanlines) + { + if (d->iscan_last < d->c->iscan0) + d->c->iscan0 = d->iscan_last; + + if (d->iscan_last > d->c->iscan1) + d->c->iscan1 = d->iscan_last; + + int order = x > d->x_last ? 1 : -1; + + if (hpgs_paint_scanline_add_point(d->c->scanlines+d->iscan_last,d->x_last,order)) + return -1; + + if (hpgs_paint_scanline_add_point(d->c->scanlines+d->iscan_last,x,-order)) + return -1; + } + + if (o > 0) + d->iscan_last = iscan; + else + d->iscan_last = iscan+1; + + d->x_last = x; + d->t_last = t; + + return 0; +} + +static int bezier_clipper_thin_cut (hpgs_bezier_clipper_thin_cut_data *d, + double t0, double t1, + double y0, + double y1, + double y2, + double y3 ) +{ + double ymin0 = (y0 < y1) ? y0 : y1; + double ymin1 = (y2 < y3) ? y2 : y3; + double ymin = ymin0 y1) ? y0 : y1; + double ymax1 = (y2 > y3) ? y2 : y3; + double ymax = ymax0>ymax1 ? ymax0 : ymax1; + + double dscan0 = (d->c->y0 - ymax)/d->c->yfac - 0.5; + double dscan1 = (d->c->y0 - ymin)/d->c->yfac - 0.5; + + double rdscan0 = ceil(dscan0); + double rdscan1 = floor(dscan1); + + int iscan0 = (int)rdscan0; + int iscan1 = (int)rdscan1; + + if (iscan0 > iscan1 || iscan1 < -1 || iscan0 >= d->c->n_scanlines) + { + return 0; + } + else if (t1-t0 < 1.0e-8 && iscan0 == iscan1) + { + int o0; + + if (y1 > y0) o0 = 1; + else if (y1 < y0) o0 = -1; + else if (y2 > y0) o0 = 1; + else if (y2 < y0) o0 = -1; + else if (y3 > y0) o0 = 1; + else if (y3 < y0) o0 = -1; + else o0 = 0; + + int o1; + + if (y2 > y3) o1 = -1; + else if (y2 < y3) o1 = 1; + else if (y1 > y3) o1 = -1; + else if (y1 < y3) o1 = 1; + else if (y0 > y3) o1 = -1; + else if (y0 < y3) o1 = 1; + else o1 = 0; + + // horizontal cut. + if (o0*o1 == 0) + { + return 0; + } + + // filter out startpoint hit. + if (t0 == d->t0 && + ((y0 == ymin && dscan1 == rdscan1) || + (y0 == ymax && dscan0 == rdscan0) )) return 0; + + // filter out endpoint hit. + if (t1 == d->t1 && + ((y3 == ymin && dscan1 == rdscan1) || + (y3 == ymax && dscan0 == rdscan0) )) return 0; + + if (iscan0 < d->c->iscan0) + { + if (iscan0 < 0) + d->c->iscan0 = 0; + else + d->c->iscan0 = iscan0; + } + + if (iscan0 >= d->c->iscan1) + { + if (iscan0+1 >= d->c->n_scanlines) + d->c->iscan1 = d->c->n_scanlines-1; + else + d->c->iscan1 = iscan0+1; + } + + if (o0*o1 > 0) + { + double t = 0.5*(t0+t1); + double x = hpgs_bezier_path_x(d->path,d->i,t); + + return hpgs_bezier_clipper_thin_cut_data_push(d,t,x,iscan0,o0); + } + else + { + double x0 = hpgs_bezier_path_x(d->path,d->i,t0); + double x1 = hpgs_bezier_path_x(d->path,d->i,t1); + + if (hpgs_bezier_clipper_thin_cut_data_push(d,t0,x0,iscan0,o0)) + return -1; + + return hpgs_bezier_clipper_thin_cut_data_push(d,t1,x1,iscan0,o1); + } + } + else if (t1-t0 < 1.0e-15) + { + return 0; + } + else + { + // partition the spline. + double tmid = 0.5*(t0+t1); + + // midpoint. + double ymid,y1l,y2l,y1u,y2u; + + y1l = 0.5 * (y0 + y1); + + y2l = 0.25 * (y0 + y2) + 0.5 * y1; + + ymid = + (y0 + y3) * 0.125 + 0.375 * (y1 + y2); + + y1u = 0.25 * (y1 + y3) + 0.5 * y2; + + y2u = 0.5 * (y2 + y3); + + if (bezier_clipper_thin_cut (d,t0,tmid,y0,y1l,y2l,ymid)) + return -1; + + if (bezier_clipper_thin_cut (d,tmid,t1,ymid,y1u,y2u,y3)) + return -1; + + return 0; + } +} + +static int thin_push_dot(hpgs_paint_clipper *c, const hpgs_point *p) +{ + int iscan = floor((c->y0 - p->y)/c->yfac + 0.5); + + if (iscan < 0 || iscan >= c->n_scanlines) return 0; + +#ifdef HPGS_DEBUG_CUT + hpgs_log("push_dot: x,y,iscan = %lg,%lg,%d.\n", + p->x,p->y,iscan); +#endif + + if (hpgs_paint_scanline_add_point(c->scanlines+iscan,p->x,1) || + hpgs_paint_scanline_add_point(c->scanlines+iscan,p->x,-1) ) + return -1; + + if (iscan < c->iscan0) c->iscan0 = iscan; + if (iscan > c->iscan1) c->iscan1 = iscan; + return 0; +} + +/* Internal: + Cut a part of a path with a linewidth below the width of a pixel with + the scanlines of the given clipper \c c. + + The subpath starts at the path segment starting at point \c i0 at the + curve parameter \c t0 (t=-0.5 start of segment, t=0.5 end of segment). + + The scanline ends at the path segment starting at point \c i1 at the + curve parameter \c t1. + + The actual intersections are undertaken at an y value in the middle between + the two y values of adjacent scanlines. The actual intersection points with + this intermediate scanline is inserted twice, once in the adjacent scanline + above and below the intermediate scanline. +*/ +static int thin_cut_segment(hpgs_paint_clipper *c, + hpgs_paint_path *path, + int i0, double t0, + int i1, double t1 ) +{ + int i; + int iscan; + + for (i=i0;i<=i1;++i) + { + hpgs_path_point *point = &path->points[i]; + hpgs_path_point *next_point; + double x0,x1,y0,y1; + int iscan0,iscan1,order; + + double tt0 = (i == i0) ? t0 : -0.5; + double tt1 = (i == i1) ? t1 : 0.5; + + switch (point->flags & HPGS_POINT_ROLE_MASK) + { + case HPGS_POINT_DOT: + if (thin_push_dot(c,&path->points[i].p)) return -1; + break; + + case HPGS_POINT_LINE: + next_point = &path->points[i+1]; + + if (tt0 > -0.5) + { + x0 = (0.5 - tt0) * point->p.x + (0.5 + tt0) * next_point->p.x; + y0 = (0.5 - tt0) * point->p.y + (0.5 + tt0) * next_point->p.y; + } + else + { + x0 = point->p.x; + y0 = point->p.y; + } + + if (tt1 < 0.5) + { + x1 = (0.5 - tt1) * point->p.x + (0.5 + tt1) * next_point->p.x; + y1 = (0.5 - tt1) * point->p.y + (0.5 + tt1) * next_point->p.y; + } + else + { + x1 = next_point->p.x; + y1 = next_point->p.y; + } + + order = x1 < x0 ? -1 : 1; + + iscan0 = + (int)floor((c->y0 - y0)/c->yfac + 0.5); + iscan1 = + (int)floor((c->y0 - y1)/c->yfac + 0.5); + + if (iscan0 >= 0 && iscan0 < c->n_scanlines && + hpgs_paint_scanline_add_point(c->scanlines+iscan0,x0,order)) + return -1; + + if (iscan1 >= 0 && iscan1 < c->n_scanlines && + hpgs_paint_scanline_add_point(c->scanlines+iscan1,x1,-order)) + return -1; + + if (iscan0 > iscan1) + { int tmp = iscan0; iscan0 = iscan1; iscan1 = tmp; order = -order; } + + if (iscan0 < 0) + { + iscan0 = -1; + c->iscan0 = 0; + } + else + if (iscan0 < c->iscan0) + c->iscan0 = iscan0; + + if (iscan1 >= c->n_scanlines) + { + iscan1 = c->n_scanlines; + c->iscan1 = c->n_scanlines-1; + } + else + if (iscan1 > c->iscan1) + c->iscan1 = iscan1; + + if (point->p.x != next_point->p.x) + for (iscan=iscan0;iscany0 - (iscan + 0.5) * c->yfac; + + double x = + (point->p.x * (next_point->p.y - y) + + next_point->p.x * (y - point->p.y) ) / + (next_point->p.y - point->p.y); + + if (iscan >= 0 && + hpgs_paint_scanline_add_point(c->scanlines+iscan,x,-order)) + return -1; + + if (iscan < c->n_scanlines-1 && + hpgs_paint_scanline_add_point(c->scanlines+iscan+1,x,order)) + return -1; + } + else + for (iscan=iscan0;iscan= 0 && + hpgs_paint_scanline_add_point(c->scanlines+iscan, + point->p.x,-order)) + return -1; + + if (iscan < c->n_scanlines-1 && + hpgs_paint_scanline_add_point(c->scanlines+iscan+1, + point->p.x,order)) + return -1; + } + + break; + case HPGS_POINT_BEZIER: + next_point = &path->points[i+3]; + + { + double yc0,yc1; + + // start point. + if (tt0 > -0.5) + { + x0 = hpgs_bezier_path_x(path,i,tt0); + y0 = hpgs_bezier_path_y(path,i,tt0); + } + else + { + x0 = point->p.x; + y0 = point->p.y; + } + + + // end point + if (tt1 < 0.5) + { + x1 = hpgs_bezier_path_x(path,i,tt1); + y1 = hpgs_bezier_path_y(path,i,tt1); + } + else + { + x1 = next_point->p.x; + y1 = next_point->p.y; + } + + // control points + if (tt0 > -0.5 || tt1 < 0.5) + { + yc0 = y0 + (tt1-tt0) * hpgs_bezier_path_delta_y(path,i,tt0)/3.0; + yc1 = y1 - (tt1-tt0) * hpgs_bezier_path_delta_y(path,i,tt1)/3.0; + } + else + { + yc0 = path->points[i+1].p.y; + yc1 = path->points[i+2].p.y; + } + + hpgs_bezier_clipper_thin_cut_data d = + { c,path,i,tt0,tt1,tt0,x0, + (int)floor((c->y0 - y0)/c->yfac + 0.5) }; + + if (bezier_clipper_thin_cut (&d,tt0,tt1,y0,yc0,yc1,y1)) + return -1; + + // add endpoint with appropriate order. + if (d.iscan_last >= 0 && d.iscan_last < c->n_scanlines) + { + int order = x1 > d.x_last ? 1 : -1; + + if (d.iscan_last < c->iscan0) + c->iscan0 = d.iscan_last; + + if (d.iscan_last > c->iscan1) + c->iscan1 = d.iscan_last; + + if (hpgs_paint_scanline_add_point(c->scanlines+d.iscan_last,d.x_last,order)) + return -1; + + if (hpgs_paint_scanline_add_point(c->scanlines+d.iscan_last,x1,-order)) + return -1; + } + } + // ignore control points. + i+=2; + break; + } + } + + return 0; +} + +/* Internal: + Cut path which is dashed according to the given \c gstate and has a linewidth + below the width of a pixel with the scanlines of the given clipper \c c. +*/ +static int thin_cut_dashed(hpgs_paint_clipper *c, + hpgs_paint_path *path, + const hpgs_gstate *gstate) +{ + int i0=0,i1=-1,i; + int idash = 0; + double t0=-0.5; + double t1=0.5; + + double l=gstate->dash_offset; + int out_state = 0; + double ltot = 0.0; + double next_l = 0.0; + double lseg; + + hpgs_bezier_length bl; + + for (idash=0;idashn_dashes;++idash) + ltot += gstate->dash_lengths[idash]; + + for (i=0;in_points;++i) + { + int role = path->points[i].flags & HPGS_POINT_ROLE_MASK; + int end_line = 0; + + if (role == HPGS_POINT_BEZIER || role == HPGS_POINT_LINE) + i1 = i; + + if (path->points[i].flags & HPGS_POINT_SUBPATH_START) + { + if (role == HPGS_POINT_DOT) + { + if (thin_push_dot(c,&path->points[i].p)) return -1; + i1 = -1; + continue; + } + else + { + i0 = i1; + t0 = -0.5; + + l=fmod(gstate->dash_offset,ltot); + if (l<0.0) l+= ltot; + + next_l = 0.0; + for (idash=0;idashn_dashes;++idash) + { + next_l += gstate->dash_lengths[idash]; + if (next_l > l) + break; + } + + out_state = (idash+1) & 1; + } + } + + switch (role) + { + case HPGS_POINT_LINE: + lseg = hypot(path->points[i+1].p.x - path->points[i].p.x, + path->points[i+1].p.y - path->points[i].p.y ); + + end_line = + (path->points[i+1].flags & HPGS_POINT_SUBPATH_END) || + i >= path->n_points-2; + + break; + case HPGS_POINT_BEZIER: + hpgs_bezier_length_init(&bl,path,i); + + lseg = bl.l[HPGS_BEZIER_NSEGS]; + + end_line = + (path->points[i+3].flags & HPGS_POINT_SUBPATH_END) || + i >= path->n_points-4; + break; + + default: + lseg = 0.0; + } + + if (role == HPGS_POINT_BEZIER || role == HPGS_POINT_LINE) + { + while (l+lseg > next_l) + { + if (role == HPGS_POINT_BEZIER) + t1 = hpgs_bezier_length_param(&bl,next_l - l); + else + t1 = (next_l - l) / lseg - 0.5; + + idash = (idash+1) % gstate->n_dashes; + next_l += gstate->dash_lengths[idash]; + + if (out_state) + { + if (thin_cut_segment(c,path,i0,t0,i1,t1)) + return -1; + } + + i0 = i1; + t0 = t1; + + out_state = (idash+1) & 1; + } + + l+=lseg; + } + + if (end_line && out_state && (i0n_points < 1) return 0; + + // catch path' which lie outside of the area of interest. + if (path->bb.urx < c->bb.llx) return 0; + if (path->bb.llx > c->bb.urx) return 0; + if (path->bb.ury < c->bb.lly) return 0; + if (path->bb.lly > c->bb.ury) return 0; + + if (gstate->n_dashes == 0) + { + if (thin_cut_segment (c,path, + 0,-0.5,path->n_points-1,0.5)) + return -1; + } + else + { + if (thin_cut_dashed(c,path,gstate)) + return -1; + } + + for (iscan = c->iscan0;iscan<=c->iscan1;++iscan) + { + scanline_sort(c->scanlines[iscan].points,c->scanlines[iscan].n_points); + +#ifdef HPGS_DEBUG_THIN_CUT + { + int j; + + hpgs_log("iscan = %d, np = %d ****************************************\n", + iscan,c->scanlines[iscan].n_points); + + if (c->scanlines[iscan].n_points & 1) + hpgs_log("np odd !!!!!!!!!!!!!!!\n"); + + for (j=0;jscanlines[iscan].n_points;++j) + hpgs_log("%lg(%d) ", + c->scanlines[iscan].points[j].x, + c->scanlines[iscan].points[j].order); + + hpgs_log("\n"); + } +#endif + } + + return 0; +} + +/* Internal: + Cuts the bezier segment with the scanlines of the clipper + and creates alpha slopes on the generated scanline intersection points. + + Returns 0 upon success or -1 on memory error. +*/ + +typedef struct hpgs_bezier_clipper_alpha_cut_data_st hpgs_bezier_clipper_alpha_cut_data; + +struct hpgs_bezier_clipper_alpha_cut_data_st +{ + hpgs_paint_clipper *c; + hpgs_paint_path *path; + int i; + + double t_last; + double x_last; + int o_last; + int iscan_last; +}; + +static int hpgs_bezier_clipper_alpha_cut_data_push(hpgs_bezier_clipper_alpha_cut_data *d, + double t, double x, + int iscan, int order, + int o) +{ + if (d->iscan_last >= 0 && d->iscan_last < d->c->n_scanlines) + { + if (d->iscan_last < d->c->iscan0) + d->c->iscan0 = d->iscan_last; + + if (d->iscan_last > d->c->iscan1) + d->c->iscan1 = d->iscan_last; + + if (hpgs_paint_scanline_add_slope(d->c->scanlines+d->iscan_last,d->x_last,x, + d->o_last,o<=0 ? order : 0)) + return -1; + } + + if (o < 0) + { + d->iscan_last = iscan+1; + d->o_last = 0; + } + else + { + d->iscan_last = iscan; + d->o_last = order; + } + + d->x_last = x; + d->t_last = t; + + return 0; +} + +static int bezier_clipper_alpha_cut_isolate_extrema (hpgs_bezier_clipper_alpha_cut_data *d, + double t0, double t1, + double y0, + double y1, + double y2, + double y3, hpgs_bool do_max ) +{ + // Ya olde golden cut... + double c0 = .38196601125010515180; + double c1 = .61803398874989484820; + + double tt0 = -0.5; + double tt1 = -0.5 * c1 + 0.5 * c0; + double tt2 = -0.5 * c0 + 0.5 * c1; + double tt3 = 0.5; + + double tp = tt1 + 0.5; + double tm = 0.5 - tt1; + + double yy1 = y0 *tm*tm*tm + 3.0 * tm*tp * (y1 * tm + y2 * tp) + y3 * tp*tp*tp; + + tp = tt2 + 0.5; + tm = 0.5 - tt2; + + double yy2 = y0 *tm*tm*tm + 3.0 * tm*tp * (y1 * tm + y2 * tp) + y3 * tp*tp*tp; + + + while ((tt2-tt1)*(t1-t0) > 1.0e-8) + if ((do_max && yy1 > yy2) || (!do_max && yy1 < yy2)) + { + tt3 = tt2; + tt2 = tt1; + yy2 = yy1; + tt1 = tt3 * c0 + tt0 * c1; + + tp = tt1 + 0.5; + tm = 0.5 - tt1; + yy1 = y0 *tm*tm*tm + 3.0 * tm*tp * (y1 * tm + y2 * tp) + y3 * tp*tp*tp; + } + else + { + tt0 = tt1; + tt1 = tt2; + yy1 = yy2; + tt2 = tt3 * c1 + tt0 * c0; + + tp = tt2 + 0.5; + tm = 0.5 - tt2; + yy2 = y0 *tm*tm*tm + 3.0 * tm*tp * (y1 * tm + y2 * tp) + y3 * tp*tp*tp; + } + + double tt = 0.5 * (tt1+tt2); + double t = t0 * (0.5-tt) + t1 * (0.5+tt); + double x = hpgs_bezier_path_x(d->path,d->i,t); + + double dscan = (d->c->y0 - 0.5 * (yy1+yy2))/d->c->yfac + 0.5; + double rdscan = floor(dscan); + int iscan = (int)rdscan; + int order = (int)((dscan-rdscan)*256.0+0.5); + + return hpgs_bezier_clipper_alpha_cut_data_push(d,t,x,iscan,order,0); +} + +static int bezier_clipper_alpha_cut (hpgs_bezier_clipper_alpha_cut_data *d, + double t0, double t1, + double y0, + double y1, + double y2, + double y3 ) +{ + double ymin0 = (y0 < y1) ? y0 : y1; + double ymin1 = (y2 < y3) ? y2 : y3; + double ymin = ymin0 y1) ? y0 : y1; + double ymax1 = (y2 > y3) ? y2 : y3; + double ymax = ymax0>ymax1 ? ymax0 : ymax1; + + double dscan0 = (d->c->y0 - ymax)/d->c->yfac - 0.5; + double dscan1 = (d->c->y0 - ymin)/d->c->yfac - 0.5; + + double rdscan0 = ceil(dscan0); + double rdscan1 = floor(dscan1); + + int iscan0 = (int)rdscan0; + int iscan1 = (int)rdscan1; + + if ((iscan0 > iscan1 && + (((y1 != ymin || y0 == ymin) && + y2 != ymin && + (y1 != ymax || y0 == ymax) && + y2 != ymax ) || ymin == ymax)) || + iscan1 < -1 || iscan0 >= d->c->n_scanlines) + { + return 0; + } + else if (t1-t0 < 1.0e-8 && iscan0 == iscan1) + { + int o0; + + if (y1 > y0) o0 = 1; + else if (y1 < y0) o0 = -1; + else if (y2 > y0) o0 = 1; + else if (y2 < y0) o0 = -1; + else if (y3 > y0) o0 = 1; + else if (y3 < y0) o0 = -1; + else o0 = 0; + + int o1; + + if (y2 > y3) o1 = -1; + else if (y2 < y3) o1 = 1; + else if (y1 > y3) o1 = -1; + else if (y1 < y3) o1 = 1; + else if (y0 > y3) o1 = -1; + else if (y0 < y3) o1 = 1; + else o1 = 0; + + // horizontal cut. + if (o0*o1 == 0) + { + return 0; + } + + // filter out startpoint hit. + if (t0 == -0.5 && + ((y0 == ymin && dscan1 == rdscan1) || + (y0 == ymax && dscan0 == rdscan0) )) return 0; + + // filter out endpoint hit. + if (t1 == 0.5 && + ((y3 == ymin && dscan1 == rdscan1) || + (y3 == ymax && dscan0 == rdscan0) )) return 0; + + double t = 0.5*(t0+t1); + double x = hpgs_bezier_path_x(d->path,d->i,t); + int o; + + if (o0*o1 > 0) + o=o0; + else + o=0; + + return hpgs_bezier_clipper_alpha_cut_data_push(d,t,x,iscan0,256,o); + } + else if (iscan0 == iscan1+1 && + ((y1 == ymin && y0 != ymin) || + y2 == ymin )) + { + if (y2 == ymin && y2 == y3) + { + if (t1 != 0.5) + { + int order = (int)((dscan1-rdscan1)*256.0+0.5); + double x = hpgs_bezier_path_x(d->path,d->i,t1); + return hpgs_bezier_clipper_alpha_cut_data_push(d,t1,x,iscan0,order,0); + } + else + return 0; + } + else + return bezier_clipper_alpha_cut_isolate_extrema (d,t0,t1,y0,y1,y2,y3,HPGS_FALSE); + } + else if (iscan0 == iscan1+1 && + ((y1 == ymax && y0 != ymax) || + y2 == ymax )) + { + if (y2 == ymax && y2 == y3) + { + if (t1 != 0.5) + { + int order = (int)((dscan1-rdscan1)*256.0+0.5); + double x = hpgs_bezier_path_x(d->path,d->i,t1); + return hpgs_bezier_clipper_alpha_cut_data_push(d,t1,x,iscan0,order,0); + } + else + return 0; + } + + return bezier_clipper_alpha_cut_isolate_extrema (d,t0,t1,y0,y1,y2,y3,HPGS_TRUE); + } + else if (t1-t0 < 1.0e-15) + { + return 0; + } + else + { + // partition the spline. + double tmid = 0.5*(t0+t1); + + // midpoint. + double ymid,y1l,y2l,y1u,y2u; + + y1l = 0.5 * (y0 + y1); + + y2l = 0.25 * (y0 + y2) + 0.5 * y1; + + ymid = + (y0 + y3) * 0.125 + 0.375 * (y1 + y2); + + y1u = 0.25 * (y1 + y3) + 0.5 * y2; + + y2u = 0.5 * (y2 + y3); + + if (bezier_clipper_alpha_cut (d,t0,tmid,y0,y1l,y2l,ymid)) + return -1; + + if (bezier_clipper_alpha_cut (d,tmid,t1,ymid,y1u,y2u,y3)) + return -1; + + return 0; + } +} + +/*! + Cuts the border of the given \c path with the scanlines of the given + clipper \c cand creates alpha slopes on the generated scanline + intersection points. This methid is used in order to create the + basic data for antialiasing output in \c scanline_emit_alpha + + Return value: + \li 0 Success. + \li -1 The system is out of memory. +*/ +static int hpgs_paint_clipper_alpha_cut(hpgs_paint_clipper *c, + hpgs_paint_path *path) +{ + int i; + int iscan; + + if (path->n_points < 2) return 0; + + // catch path' which lie outside of the area of interest. + if (path->bb.urx < c->bb.llx) return 0; + if (path->bb.llx > c->bb.urx) return 0; + if (path->bb.ury < c->bb.lly) return 0; + if (path->bb.lly > c->bb.ury) return 0; + + for (i=0;in_points;++i) + { + hpgs_path_point *point = &path->points[i]; + hpgs_path_point *next_point; + double dscan0,dscan1,rdscan0,rdscan1,x0,y0,x1,y1; + int iscan0,iscan1,o,order; + + switch (point->flags & HPGS_POINT_ROLE_MASK) + { + case HPGS_POINT_LINE: + case HPGS_POINT_FILL_LINE: + next_point = &path->points[i+1]; + + if (next_point->p.y < point->p.y) + { + o = 1; + + x0 = point->p.x; + y0 = point->p.y; + x1 = next_point->p.x; + y1 = next_point->p.y; + } + else + { + o = -1; + + x0 = next_point->p.x; + y0 = next_point->p.y; + x1 = point->p.x; + y1 = point->p.y; + } + + dscan0 = (c->y0 - y0)/c->yfac + 0.5; + dscan1 = (c->y0 - y1)/c->yfac + 0.5; + + rdscan0 = floor(dscan0); + rdscan1 = floor(dscan1); + + iscan0 = (int)rdscan0; + iscan1 = (int)rdscan1; + + if (iscan0 < c->n_scanlines) + { + int last_order; + double last_x; + + if (iscan0 < 0) + { + if (iscan1 < 0) continue; + + double y = c->y0 + 0.5 * c->yfac; + + if (x0!=x1) + last_x = + (x0 * (y1 - y) + x1 * (y - y0) ) / (y1 - y0); + else + last_x = x0; + + iscan0 = 0; + last_order = 0; + c->iscan0 = 0; + } + else + { + last_order = o * (int)(256 * (dscan0 - rdscan0) + 0.5); + last_x = x0; + + if (iscan0 < c->iscan0) + c->iscan0 = iscan0; + } + + if (x0 != x1) + for (iscan=iscan0;iscann_scanlines;++iscan) + { + double y = c->y0 - (iscan + 0.5) * c->yfac; + + double x = + (x0 * (y1 - y) + x1 * (y - y0) ) / (y1 - y0); + + if (hpgs_paint_scanline_add_slope(c->scanlines+iscan,last_x,x,last_order,o*256)) + return -1; + + last_x = x; + last_order = 0; + } + else + for (iscan=iscan0;iscann_scanlines;++iscan) + { + if (hpgs_paint_scanline_add_slope(c->scanlines+iscan,last_x,last_x,last_order,o*256)) + return -1; + + last_order = 0; + } + + if (iscan < c->n_scanlines) + { + order = o*(int)(256 * (dscan1 - rdscan1) + 0.5); + + if (hpgs_paint_scanline_add_slope(c->scanlines+iscan,last_x,x1,last_order,order)) + return -1; + + if (iscan > c->iscan1) c->iscan1=iscan; + } + else + c->iscan1 = c->n_scanlines-1; + } + + break; + case HPGS_POINT_BEZIER: + next_point = &path->points[i+3]; + + { + double yc0,yc1; + + // start point. + x0 = point->p.x; + y0 = point->p.y; + + // end point + x1 = next_point->p.x; + y1 = next_point->p.y; + + // control points + yc0 = path->points[i+1].p.y; + yc1 = path->points[i+2].p.y; + + dscan0 = (c->y0 - y0)/c->yfac + 0.5; + rdscan0 = floor(dscan0); + + hpgs_bezier_clipper_alpha_cut_data d = + { c,path,i,-0.5,x0,(int)((dscan0-rdscan0)*256.0+0.5),(int)rdscan0 }; + + if (bezier_clipper_alpha_cut (&d,-0.5,0.5,y0,yc0,yc1,y1)) + return -1; + + // add endpoint with appropriate order. + if (d.iscan_last >= 0 && d.iscan_last < c->n_scanlines) + { + dscan1 = (c->y0 - y1)/c->yfac + 0.5; + rdscan1 = floor(dscan1); + iscan1=(int)rdscan1; + + if (d.iscan_last < c->iscan0) + c->iscan0 = d.iscan_last; + + if (d.iscan_last > c->iscan1) + c->iscan1 = d.iscan_last; + + order = (int)((dscan1-rdscan1)*256.0+0.5); + + if (hpgs_paint_scanline_add_slope(c->scanlines+d.iscan_last, + d.x_last,x1, + d.o_last, + order)) + return -1; + } + } + // ignore control points. + i+=2; + break; + } + } + +#ifdef HPGS_DEBUG_ALPHA_CUT + for (iscan = c->iscan0;iscan<=c->iscan1;++iscan) + { + int j; + int so = 0; + + hpgs_log("iscan = %d, np = %d ****************************************\n", + iscan,c->scanlines[iscan].n_points); + + for (j=0;jscanlines[iscan].n_points;++j) + { + so += c->scanlines[iscan].points[j].order; + hpgs_log("%lg(%d,%d) ", + c->scanlines[iscan].points[j].x, + c->scanlines[iscan].points[j].order,so); + } + + if (so) + hpgs_log("so !!!!!!!!!!!!!!!"); + + hpgs_log("\n"); + } +#endif + + return 0; +} + +static int hpgs_paint_scanline_reserve_point(hpgs_paint_scanline *s) +{ + if (s->n_points >= s->points_malloc_size) + { + int nsz = s->points_malloc_size * 2; + hpgs_scanline_point *np = (hpgs_scanline_point *) + realloc(s->points, + sizeof(hpgs_scanline_point)*nsz); + + if (!np) return -1; + s->points = np; + s->points_malloc_size = nsz; + } + + return 0; +} + +/*! + Adds an intersection point with coordinate \c x and order \c 0 to the + given scanline \c s. + + Return value: + \li 0 Success. + \li -1 The system is out of memory. +*/ +int hpgs_paint_scanline_add_point(hpgs_paint_scanline *s, double x, int o) +{ + if (hpgs_paint_scanline_reserve_point(s)) + return -1; + + s->points[s->n_points].x = x; + s->points[s->n_points].order = o; + ++s->n_points; + return 0; +} + +int hpgs_paint_scanline_add_slope(hpgs_paint_scanline *s, double x1, double x2, int o1, int o2) +{ + int o = o2-o1; + + if (x1 > x2) + { + double tmp = x1; + x1 = x2; + x2 = tmp; + } + + // binary search for x1. + int i0 = 0; + int i1 = s->n_points; + + while (i1>i0) + { + int i = i0+(i1-i0)/2; + + if (s->points[i].x < x1) + i0 = i+1; + else + i1 = i; + } + + // insert x1, if not found + if (i0 >= s->n_points || s->points[i0].x > x1) + { + if (hpgs_paint_scanline_reserve_point(s)) + return -1; + + if (s->n_points - i0) + memmove(s->points+i0+1,s->points+i0, + sizeof(hpgs_scanline_point) * (s->n_points - i0)); + ++s->n_points; + + // interpolate order of already exiting segment. + s->points[i0].x = x1; + int order = + (i0 > 0 && i0+1 < s->n_points) ? + (int)((s->points[i0+1].order * (x1-s->points[i0-1].x) )/ + (s->points[i0+1].x-s->points[i0-1].x)+0.5 ) + : 0; + + s->points[i0].order = order; + + // subtract intermediate order from already existing next point. + ++i0; + if (order) + s->points[i0].order -= order; + } + else + ++i0; + + int last_order = 0; + + // go on to x2. + while (i0 < s->n_points && s->points[i0].x < x2) + { + int order = + (int)((o * (s->points[i0].x-x1))/(x2-x1)+0.5); + + s->points[i0].order += order - last_order; + last_order = order; + ++i0; + } + + // insert x2, if not found + if (i0 >= s->n_points || s->points[i0].x > x2) + { + if (hpgs_paint_scanline_reserve_point(s)) + return -1; + + if (s->n_points - i0) + memmove(s->points+i0+1,s->points+i0, + sizeof(hpgs_scanline_point) * (s->n_points - i0)); + ++s->n_points; + + // interpolate order of already exiting segment. + int order = + (i0 > 0 && i0+1 < s->n_points) ? + (int)((s->points[i0+1].order * (x2-s->points[i0-1].x) )/ + (s->points[i0+1].x-s->points[i0-1].x)+0.5 ) + : 0; + + s->points[i0].x = x2; + s->points[i0].order = order + o - last_order; + + // subtract intermediate order from already existing next point. + ++i0; + if (order) + s->points[i0].order -= order; + } + else + // x2 already present -> add point. + s->points[i0].order += o-last_order; + + return 0; +} + +/*! + Cuts te given \c path with the scanlines of the given + clipper \c c. If you emit the clipper afterwards, the interior + of the given path is drawn to the image. + + If you want to stroke the path use either \c hpgs_paint_clipper_thin_cut + for thin lines or contruct the outline of a thick line using + the line style of a graphics state with \c hpgs_paint_path_stroke_path. + + Return value: + \li 0 Success. + \li -1 The system is out of memory. +*/ +int hpgs_paint_clipper_cut(hpgs_paint_clipper *c, + hpgs_paint_path *path) +{ + if (c->overscan) + return hpgs_paint_clipper_alpha_cut(c,path); + else + return hpgs_paint_clipper_cut_0(c,path); +} + + +/*! Sets the intersection of the given scanlines \c orig and \c clip + to the scanline \c res. This is the worker function, which + finds the intersection of visible segment of \c orig with the + visible segments of \c clip and adds them to \c res. + + If \c winding is \c HPGS_TRUE, the non-zero winding rule is used for the + segment intersection, otherwise the exclusive-or rule applies. + + Return values: + + \li 0 Sucess. + \li -1 The system is out of memory. +*/ +static int hpgs_paint_scanline_clip(hpgs_paint_scanline *res, + const hpgs_paint_scanline *orig, + const hpgs_paint_scanline *clip, + hpgs_bool winding) +{ + int io = 0; + int ic = 0; + int owind=0; + int cwind=0; + + int last_out_state = 0; + double last_x=0.0; + + res->n_points = 0; + + while (io < orig->n_points && ic < clip->n_points) + { + int out_state; + double x= orig->points[io].x; + + if (clip->points[ic].x < x) x = clip->points[ic].x; + + while (io < orig->n_points && x == orig->points[io].x) + { + owind += orig->points[io].order; + ++io; + } + + while (ic < clip->n_points && x == clip->points[ic].x) + { + cwind += clip->points[ic].order; + ++ic; + } + + out_state = + cwind && ((winding && owind) || (!winding && (owind & 1))); + + if (!out_state && last_out_state) + { + if (hpgs_paint_scanline_add_point(res,last_x,1) || + hpgs_paint_scanline_add_point(res,x,-1) ) + return -1; + } + + last_out_state = out_state; + if (out_state) last_x = x; + } + + return 0; +} + +/*! Sets the intersection of the given scanlines \c orig and \c clip + to the scanline \c res. This is the worker function, which + finds the intersection of visible segment of \c orig with the + visible segments of \c clip and adds them to \c res. + + Antialiasing method with broken down winding counts for alpha + calculation. + + If \c winding is \c HPGS_TRUE, the non-zero winding rule is used for the + segment intersection, otherwise the exclusive-or rule applies. + + Return values: + + \li 0 Sucess. + \li -1 The system is out of memory. +*/ +static int hpgs_paint_scanline_clip_alpha(hpgs_paint_scanline *res, + const hpgs_paint_scanline *orig, + const hpgs_paint_scanline *clip, + hpgs_bool winding) +{ + int io = 0; + int ic = 0; + int owind=0; + int cwind=0; + int last_out_state = 0; + + res->n_points = 0; + + while (io < orig->n_points && ic < clip->n_points) + { + int out_state; + hpgs_bool have_2; + double x= orig->points[io].x; + + if (clip->points[ic].x < x) x = clip->points[ic].x; + + if (io < orig->n_points && x == orig->points[io].x) + { + owind += orig->points[io].order; + ++io; + } + + if (ic < clip->n_points && x == clip->points[ic].x) + { + cwind += clip->points[ic].order; + ++ic; + } + + if (winding) + { + if (owind <= -256 || owind >= 256) + out_state = 256; + else if (owind >= 0) + out_state = owind; + else + out_state = -owind; + } + else + { + if (owind & 0x100) + out_state = 256 - (owind & 0xff); + else + out_state = (owind & 0xff); + } + + if (out_state > cwind) out_state=cwind; + + if (hpgs_paint_scanline_add_point(res,x,out_state-last_out_state)) + return -1; + + last_out_state = out_state; + + have_2 = HPGS_FALSE; + + while (io < orig->n_points && x == orig->points[io].x) + { + owind += orig->points[io].order; + ++io; + have_2 = HPGS_TRUE; + } + + while (ic < clip->n_points && x == clip->points[ic].x) + { + cwind += clip->points[ic].order; + ++ic; + have_2 = HPGS_TRUE; + } + + if (have_2) + { + if (winding) + { + if (owind <= -256 || owind >= 256) + out_state = 256; + else if (owind >= 0) + out_state = owind; + else + out_state = -owind; + } + else + { + if (owind & 0x100) + out_state = 256 - (owind & 0xff); + else + out_state = (owind & 0xff); + } + + if (out_state > cwind) out_state=cwind; + + if (out_state != last_out_state) + { + if (hpgs_paint_scanline_add_point(res,x,out_state-last_out_state)) + return -1; + + last_out_state = out_state; + } + } + } + + return 0; +} + +/*! Returna a new clipper on the heap, which holds the intersection of the + given path clipper with the current clip clipper. + + If \c winding is \c HPGS_TRUE, the non-zero winding rule is used for the + path intersection, otherwise the exclusive-or rule applies. + + Use \c hpgs_paint_clipper_destroy in order to destroy the returned + \c hpgs_paint_clipper from the heap. + + Returns a null pointer, if the system is out of memory. +*/ +hpgs_paint_clipper *hpgs_paint_clipper_clip(const hpgs_paint_clipper *orig, + const hpgs_paint_clipper *clip, + hpgs_bool winding) +{ + hpgs_paint_clipper *ret = 0; + int i; + + if (clip->height != orig->height || + clip->n_scanlines != orig->n_scanlines) + return ret; + + ret = hpgs_new_paint_clipper(&orig->bb, + orig->height, + 16,orig->overscan); + + if (!ret) return ret; + +#ifdef HPGS_DEBUG_CLIP + hpgs_log("orig: iscan0,iscan1 = %d,%d.\n",orig->iscan0,orig->iscan1); + hpgs_log("clip: iscan0,iscan1 = %d,%d.\n",clip->iscan0,clip->iscan1); +#endif + + ret->iscan0 = orig->iscan0 > clip->iscan0 ? orig->iscan0 : clip->iscan0; + ret->iscan1 = orig->iscan1 < clip->iscan1 ? orig->iscan1 : clip->iscan1; + + if (orig->overscan) + { + for (i=ret->iscan0;i<=ret->iscan1;++i) + { + if (hpgs_paint_scanline_clip_alpha(ret->scanlines+i, + orig->scanlines+i, + clip->scanlines+i,winding)) + { hpgs_paint_clipper_destroy(ret); ret =0; break; } + } + } + else + { + for (i=ret->iscan0;i<=ret->iscan1;++i) + { + if (hpgs_paint_scanline_clip(ret->scanlines+i, + orig->scanlines+i, + clip->scanlines+i,winding)) + { hpgs_paint_clipper_destroy(ret); ret =0; break; } + } + } + + return ret; +} + +/* Internal: + Worker routine, which finds the visible segments from the + intersection of the two scanlines and writes them to the physical + row\c iy of the image. +*/ +static int scanline_emit_0(hpgs_image *image, + double llx, double urx, int iy, + const hpgs_paint_scanline *img, + const hpgs_paint_scanline *clip, + const hpgs_paint_color *c, + hpgs_bool winding, hpgs_bool stroke) +{ + int io = 0; + int ic = 0; + int owind=0; + int cwind=0; + + int last_out_state = 0; + double last_x=0.0; + + while (io < img->n_points && ic < clip->n_points) + { + int out_state; + double x= img->points[io].x; + + if (clip->points[ic].x < x) x = clip->points[ic].x; + + while (io < img->n_points && x == img->points[io].x) + { + owind += img->points[io].order; + ++io; + // output zero-width chunks for stroke, + // so we quit here. + if (stroke) break; + } + + while (ic < clip->n_points && x == clip->points[ic].x) + { + cwind += clip->points[ic].order; + ++ic; + } + + if (winding) + out_state = cwind && owind; + else + out_state = cwind && (owind & 1); + + if (last_out_state && out_state!=last_out_state) + { + // overestimate the thickness of chunks + int ix1 = (int)(image->width*(last_x - llx)/(urx-llx)); + int ix2 = (int)(image->width*(x - llx)/(urx-llx)); + + if (ix1 < 0) ix1=0; + else if (ix1 >= image->width) ix1=image->width-1; + + if (ix2 < 0) ix2=0; + else if (ix2 >= image->width) ix2=image->width-1; + + if (ix2n_points && ic < clip->n_points) + { + int out_state; + double x= img->points[io].x; + double alpha; + double clip_alpha; + + if (clip->points[ic].x < x) x = clip->points[ic].x; + + if (io < img->n_points && x == img->points[io].x) + { + owind += img->points[io].order; + ++io; + } + + if (ic < clip->n_points && x == clip->points[ic].x) + { + clip_last_x = clip->points[ic].x; + cwind += clip->points[ic].order; + ++ic; + } + + if (ic == 0 || ic >= clip->n_points || x == clip_last_x) + clip_alpha = (double)cwind/256.0; + else + clip_alpha = + (cwind+clip->points[ic].order*(x-clip_last_x)/(clip->points[ic].x-clip_last_x))/256.0; + +#ifdef HPGS_DEBUG_EMIT_ALPHA + hpgs_log("ic,x,clip_last_x,cx,cwind,o,clip_alpha = %d,%lg,%lg,%lg,%d,%d,%lg.\n", + ic,x,clip_last_x, + ic < clip->n_points ? clip->points[ic].x : -1.0e20, + cwind, + ic < clip->n_points ? clip->points[ic].order : -1, + clip_alpha); +#endif + + if (winding) + { + if (owind <= -256 || owind >= 256) + out_state = 256; + else if (owind >= 0) + out_state = owind; + else + out_state = -owind; + } + else + { + if (owind & 0x100) + out_state = 256 - (owind & 0xff); + else + out_state = (owind & 0xff); + } + + + alpha = out_state / 256.0; + + if (alpha > clip_alpha) + alpha=clip_alpha; + + if (x>last_x && (alpha > 0.0 || last_alpha > 0.0)) + { + double x1 = image->width*(last_x - llx)/(urx-llx); + double x2 = image->width*(x - llx)/(urx-llx); + + int i,ix1,ix2; + +#ifdef HPGS_DEBUG_EMIT_ALPHA + hpgs_log("last_x,x,out_state,last_alpha,alpha = %lg,%lg,%d,%lg,%lg.\n", + last_x,x,out_state,last_alpha,alpha); + +#endif + ix1 = (int)floor(x1); + ix2 = (int)floor(x2); + + if (ix1 < -1) ix1=-1; + else if (ix1 >= image->width) ix1=image->width-1; + + if (ix2 < 0) ix2=0; + else if (ix2 >= image->width) ix2=image->width; + + // alpha value for a given pixel position. +#define ALPHA_X(xx) ((last_alpha*(x2-(xx))+alpha*((xx)-x1))/(x2-x1)) + + // emit first partial pixel. + if (ix1 >= 0) + { + double aa; + + if (ix2 > ix1) + aa = (1.0 - (x1 - ix1)) * 0.5 * (last_alpha+ALPHA_X(ix1+1)); + else + aa = (x2 - x1) * 0.5 * (last_alpha + alpha); + + if (ix1 != last_partial_ix) + { + if (last_partial_ix >= 0 && + hpgs_image_rop3_pixel (image,last_partial_ix,iy, + c,last_partial_alpha)) + return -1; + + last_partial_ix = ix1; + last_partial_alpha = 0.0; + } + + last_partial_alpha += aa; + } + + // emit solid core segment. + if (last_alpha == 1.0 && alpha == 1.0) + { + if (ix2 > ix1+1 && hpgs_image_rop3_chunk (image,ix1+1,ix2-1,iy,c)) + return -1; + } + else + { + for (i=ix1+1;iwidth && ix2 > ix1) + { + double aa = (x2 - ix2) * 0.5 * (alpha + ALPHA_X(ix2)); + + if (ix2 != last_partial_ix) + { + if (last_partial_ix >= 0 && + hpgs_image_rop3_pixel (image,last_partial_ix,iy, + c,last_partial_alpha)) + return -1; + + last_partial_ix = ix2; + last_partial_alpha = 0.0; + } + + last_partial_alpha += aa; + } +#undef ALPHA_X + } + + last_alpha = alpha; + last_x = x; + } + + if (last_partial_ix >= 0 && + hpgs_image_rop3_pixel (image,last_partial_ix,iy, + c,last_partial_alpha)) + return -1; + + return 0; +} + +/*! Emits the intersection of the visible segments of the given clippers + \c img and \c clip to the given image \c img using + the given color \c c. + + If \c stroke is \c HPGS_TRUE, zero-width segments are also emitted, which + is feasible for clippers retrieved through \c hpgs_paint_clipper_thin_cut. + + If \c winding is \c HPGS_TRUE, the non-zero winding rule is used for the + segment intersection, otherwise the exclusive-or rule applies. + + Return values: + + \li 0 Sucess. + \li -1 The system is out of memory or an error from the image has occurred. +*/ +int hpgs_paint_clipper_emit (hpgs_image *image, + const hpgs_paint_clipper *img, + const hpgs_paint_clipper *clip, + const hpgs_paint_color *c, + hpgs_bool winding, hpgs_bool stroke) +{ + int iscan0,iscan1,iscan; + + if (image->height != img->height || + image->height != clip->height || + clip->n_scanlines != img->n_scanlines) + return -1; + + iscan0 = img->iscan0 > clip->iscan0 ? img->iscan0 : clip->iscan0; + iscan1 = img->iscan1 < clip->iscan1 ? img->iscan1 : clip->iscan1; + +#if defined (HPGS_DEBUG_EMIT_0) || defined(HPGS_DEBUG_EMIT_ALPHA) + hpgs_log("emit: iscan0,iscan1 = %d,%d *************************\n",iscan0,iscan1); +#endif + + if (img->overscan) + { + for (iscan = iscan0; iscan<=iscan1; ++iscan) + { +#ifdef HPGS_DEBUG_EMIT_ALPHA + hpgs_log("emit_alpha: iscan = %d ********************\n",iscan); +#endif + if (scanline_emit_alpha(image,img->bb.llx,img->bb.urx,iscan, + img->scanlines + iscan, + clip->scanlines + iscan, + c,winding)) + return -1; + } + } + else + { + for (iscan = iscan0; iscan<=iscan1; ++iscan) + { +#ifdef HPGS_DEBUG_EMIT_0 + hpgs_log("emit_0: iscan = %d **************************\n",iscan); +#endif + if (scanline_emit_0(image,img->bb.llx,img->bb.urx,iscan, + img->scanlines + iscan, + clip->scanlines + iscan, + c,winding,stroke)) + return -1; + } + } + return 0; +} + +/*! Returns a new clipper on the heap, which covers the given bounding box + an applies to an image with \c height rows. + + \c scanline_msize determines the number of intersection points, for which + memory is preallocated in each scanline. + + The value of \c overscan determines the type of antialiasing applied as + described under \c hpgs_paint_device_st::overscan. + + Use \c hpgs_paint_clipper_destroy in order to destroy the returned + \c hpgs_paint_clipper from the heap. + + Returns a null pointer, if the system is out of memory. +*/ +hpgs_paint_clipper *hpgs_new_paint_clipper(const hpgs_bbox * bb, + int height, + int scanline_msize, + int overscan) +{ + hpgs_paint_clipper *ret = + (hpgs_paint_clipper *)malloc(sizeof(hpgs_paint_clipper)); + + if (ret) + { + int i; + + ret->bb = *bb; + + ret->n_scanlines = height; + // slightly reinterpret lly and ury in order to + // meet scanline y coordinates + ret->yfac = (bb->ury-bb->lly) / height; + ret->y0 = bb->ury - 0.5 * ret->yfac; + + ret->overscan = overscan; + ret->height = height; + ret->iscan0 = ret->n_scanlines; + ret->iscan1 = -1; + + ret->scanlines = (hpgs_paint_scanline *) + malloc(sizeof(hpgs_paint_scanline)*ret->n_scanlines); + + if (ret->scanlines) + for (i=0;in_scanlines;++i) + { + if (hpgs_paint_scanline_init(ret->scanlines+i,scanline_msize)) + break; + } + else + i=-1; + + // error recovery + if (in_scanlines) + { + for (;i>=0;--i) + hpgs_paint_scanline_cleanup(ret->scanlines+i); + + if (ret->scanlines) free(ret->scanlines); + + free(ret); + ret = 0; + } + } + return ret; +} + +/*! Resets a clipper to be empty and to cover the whole + rectanlge of an image covering the \c x coordinates in the range + from \c llx to \c urx. + + \li 0 Sucess. + \li -1 The system is out of memory. +*/ +int hpgs_paint_clipper_reset(hpgs_paint_clipper *c, double llx, double urx) +{ + int i; + + if (c->overscan) + { + for (i=0;in_scanlines;++i) + { + hpgs_paint_scanline *s = c->scanlines+i; + + s->n_points=0; + if (hpgs_paint_scanline_add_point(s,llx,0) || + hpgs_paint_scanline_add_point(s,llx,256) || + hpgs_paint_scanline_add_point(s,urx,0) || + hpgs_paint_scanline_add_point(s,urx,-256) ) + return -1; + } + } + else + { + for (i=0;in_scanlines;++i) + { + hpgs_paint_scanline *s = c->scanlines+i; + + s->n_points=0; + if (hpgs_paint_scanline_add_point(s,llx,1) || + hpgs_paint_scanline_add_point(s,urx,-1) ) + return -1; + } + } + + c->iscan0 = 0; + c->iscan1 = c->n_scanlines-1; + + return 0; +} + +/*! Resets a clipper to be completely empty . + + \li 0 Sucess. + \li -1 The system is out of memory. +*/ +void hpgs_paint_clipper_clear(hpgs_paint_clipper *c) +{ + int i; + + for (i=c->iscan0;i<=c->iscan1;++i) + { + hpgs_paint_scanline *s = c->scanlines+i; + + s->n_points=0; + } + + c->iscan0 = c->n_scanlines; + c->iscan1 = -1; +} + +/*! Destroys a clipper from the heap. +*/ +void hpgs_paint_clipper_destroy(hpgs_paint_clipper *c) +{ + int i; + + if (c->scanlines) + { + for (i=0;in_scanlines;++i) + hpgs_paint_scanline_cleanup(c->scanlines+i); + + free(c->scanlines); + } + + free(c); +} + diff --git a/src/add-ons/translators/hpgs/lib/hpgssetup.c b/src/add-ons/translators/hpgs/lib/hpgssetup.c new file mode 100644 index 0000000000..56fbde883e --- /dev/null +++ b/src/add-ons/translators/hpgs/lib/hpgssetup.c @@ -0,0 +1,627 @@ +/*********************************************************************** + * * + * $Id: hpgssetup.c 362 2006-10-16 14:13:48Z softadm $ + * * + * hpgs - HPGl Script, a hpgl/2 interpreter, which uses a Postscript * + * API for rendering a scene and thus renders to a variety of * + * devices and fileformats. * + * * + * (C) 2004-2006 ev-i Informationstechnologie GmbH http://www.ev-i.at * + * * + * Author: Wolfgang Glas * + * * + * hpgs is free software; you can redistribute it and/or * + * modify it under the terms of the GNU Lesser General Public * + * License as published by the Free Software Foundation; either * + * version 2.1 of the License, or (at your option) any later version. * + * * + * hpgs is distributed in the hope that it will be useful, * + * but WITHOUT ANY WARRANTY; without even the implied warranty of * + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * + * Lesser General Public License for more details. * + * * + * You should have received a copy of the GNU Lesser General Public * + * License along with this library; if not, write to the * + * Free Software Foundation, Inc., 59 Temple Place, Suite 330, * + * Boston, MA 02111-1307 USA * + * * + *********************************************************************** + * * + * The implementation of the HPGL reader. * + * * + ***********************************************************************/ + +#include +#include +#include +#include +#include + +/* + Standard values. +*/ +static hpgs_color std_pen_colors[8] = + { + { 1.0, 1.0, 1.0 }, + { 0.0, 0.0, 0.0 }, + { 1.0, 0.0, 0.0 }, + { 0.0, 1.0, 0.0 }, + { 1.0, 1.0, 0.0 }, + { 0.0, 0.0, 1.0 }, + { 1.0, 0.0, 1.0 }, + { 0.0, 1.0, 1.0 } + }; + +static double std_pen_widths[8] = + { + 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0 + }; + +static int std_linetype_nsegs[17] = + { + 9, 7, 7, 5, 5, 3, 3, 3, 0, 2, 2, 2, 4, 4, 6, 6, 8 + }; + +static float std_linetype_segs[17][20] = + { + {24, 10, 1, 10, 10, 10, 1, 10, 24, 0,0,0,0,0,0,0,0,0,0,0}, + {34, 10, 1, 10, 1, 10, 34, 0, 0, 0,0,0,0,0,0,0,0,0,0,0}, + {25, 10, 10, 10, 10, 10, 25, 0, 0, 0,0,0,0,0,0,0,0,0,0,0}, + {35, 10, 10, 10, 35, 0, 0, 0, 0, 0,0,0,0,0,0,0,0,0,0,0}, + {40, 10, 1, 10, 39, 0, 0, 0, 0, 0,0,0,0,0,0,0,0,0,0,0}, + {35, 30, 35, 0, 0, 0, 0, 0, 0, 0,0,0,0,0,0,0,0,0,0,0}, + {25, 50, 25, 0, 0, 0, 0, 0, 0, 0,0,0,0,0,0,0,0,0,0,0}, + { 1, 99, 0, 0, 0, 0, 0, 0, 0, 0,0,0,0,0,0,0,0,0,0,0}, + { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,0,0,0,0,0,0,0,0,0,0}, + { 1, 99, 0, 0, 0, 0, 0, 0, 0, 0,0,0,0,0,0,0,0,0,0,0}, + {50, 50, 0, 0, 0, 0, 0, 0, 0, 0,0,0,0,0,0,0,0,0,0,0}, + {70, 30, 0, 0, 0, 0, 0, 0, 0, 0,0,0,0,0,0,0,0,0,0,0}, + {79, 10, 1, 10, 0, 0, 0, 0, 0, 0,0,0,0,0,0,0,0,0,0,0}, + {70, 10, 10, 10, 0, 0, 0, 0, 0, 0,0,0,0,0,0,0,0,0,0,0}, + {50, 10, 10, 10, 10, 10, 0, 0, 0, 0,0,0,0,0,0,0,0,0,0,0}, + {68, 10, 1, 10, 1, 10, 0, 0, 0, 0,0,0,0,0,0,0,0,0,0,0}, + {48, 10, 1, 10, 10, 10, 1, 10, 0, 0,0,0,0,0,0,0,0,0,0,0} + }; + + +void hpgs_reader_set_default_state (hpgs_reader *reader) +{ + reader->frame_x=0.0; + reader->frame_y=0.0; + + reader->x_size = 47520.0 * HP_TO_PT; + reader->y_size = 33600.0 * HP_TO_PT; + + reader->P1.x = 0.0; + reader->P1.y = 0.0; + reader->P2.x = reader->x_size; + reader->P2.y = reader->y_size; + reader->delta_P.x = reader->P2.x - reader->P1.x; + reader->delta_P.y = reader->P2.y - reader->P1.y; + + reader->rotation=0; + + reader->sc_type=-1; + reader->sc_xmin=0.0; + reader->sc_xmax=1.0; + reader->sc_ymin=0.0; + reader->sc_ymax=1.0; + reader->sc_left = 50.0; + reader->sc_bottom = 50.0; + + hpgs_reader_set_default_transformation (reader); + + reader->rop3 = 252; + reader->src_transparency = HPGS_TRUE; + reader->pattern_transparency = HPGS_TRUE; + + reader->pen_down = 0; + reader->pen_width_relative = 0; + + reader->label_term= '\003'; + reader->label_term_ignore = 1; + reader->polygon_mode = 0; + reader->poly_buffer_size = 0; + reader->polygon_open = 0; + reader->have_current_point = 0; + reader->current_point.x = reader->page_matrix.dx; + reader->current_point.y = reader->page_matrix.dy; + reader->current_pen = 0; + reader->current_linetype = 0; + reader->absolute_plotting = 1; + reader->anchor_point.x = 0.0; + reader->anchor_point.y = 0.0; + + reader->current_ft = 1; + reader->ft3_angle = 0.0; + reader->ft3_spacing = 0.0; + reader->ft4_angle = 0.0; + reader->ft4_spacing = 0.0; + reader->ft10_level = 100.0; + + reader->default_encoding = 0; + reader->default_face = 0; + reader->default_spacing = 0; + reader->default_pitch = 9.0; + reader->default_height = 11.5; + reader->default_posture = 0; + reader->default_weight = 0; + + reader->alternate_encoding = 0; + reader->alternate_face = 0; + reader->alternate_spacing = 0; + reader->alternate_pitch = 9.0; + reader->alternate_height = 11.5; + reader->alternate_posture = 0; + reader->alternate_weight = 0; + + reader->alternate_font = 0; + reader->cr_point = reader->current_point; + reader->current_char_size.x = 0.0; + reader->current_char_size.y = 0.0; + reader->current_extra_space.x = 0.0; + reader->current_extra_space.y = 0.0; + reader->current_slant = 0.0; + reader->current_label_origin = 1; + reader->current_text_path = 0; + reader->current_text_line = 0; + reader->current_label_angle = 0.0; + + // standard linetypes. (-8,...8) + memcpy(reader->linetype_nsegs,std_linetype_nsegs,sizeof(std_linetype_nsegs)); + memcpy(reader->linetype_segs,std_linetype_segs,sizeof(std_linetype_segs)); +} + +void hpgs_reader_set_std_pen_colors(hpgs_reader *reader, + int i0, int n) +{ + int n_std = sizeof(std_pen_colors)/sizeof(hpgs_color); + + if (i0 >= n_std) return; + if (n <= 0) return; + if (i0+n >= n_std) n = n_std-i0; + + memcpy(reader->pen_colors+i0,std_pen_colors+i0,sizeof(hpgs_color)*n); +} + +static hpgs_reader_pcl_palette *hpgs_reader_new_pcl_palette () +{ + hpgs_reader_pcl_palette *ret=(hpgs_reader_pcl_palette *)malloc(sizeof(hpgs_reader_pcl_palette)); + + if (!ret) return 0; + + memset(ret->colors,0,sizeof(hpgs_palette_color)*256); + ret->colors[0].r = 0xff; + ret->colors[0].g = 0xff; + ret->colors[0].b = 0xff; + + ret->last_color.r = 0; + ret->last_color.g = 0; + ret->last_color.b = 0; + + ret->cid_space = 0; + ret->cid_enc = 1; + ret->cid_bpi = 1; + ret->cid_bpc[0] = 8; + ret->cid_bpc[1] = 8; + ret->cid_bpc[2] = 8; + + return ret; +} + +static hpgs_reader_pcl_palette *hpgs_reader_dup_pcl_palette (const hpgs_reader_pcl_palette *p) +{ + hpgs_reader_pcl_palette *ret=(hpgs_reader_pcl_palette *)malloc(sizeof(hpgs_reader_pcl_palette)); + + if (!ret) return 0; + + memcpy(ret,p,sizeof(hpgs_reader_pcl_palette)); + + return ret; +} + +static void hpgs_reader_destroy_pcl_palette (hpgs_reader_pcl_palette *p) +{ + if (p) + free(p); +} + +int hpgs_reader_push_pcl_palette (hpgs_reader *reader) +{ + if (reader->pcl_i_palette >= HPGS_MAX_PCL_PALETTES-1) + return hpgs_set_error(hpgs_i18n("PCL palette stack overflow (maximal stack size = %d)."), + HPGS_MAX_PCL_PALETTES); + + + if (reader->pcl_i_palette >= 0) + reader->pcl_palettes[reader->pcl_i_palette+1] = + hpgs_reader_dup_pcl_palette (reader->pcl_palettes[reader->pcl_i_palette]); + else + reader->pcl_palettes[reader->pcl_i_palette+1] = + hpgs_reader_new_pcl_palette (); + + if (!reader->pcl_palettes[reader->pcl_i_palette+1]) + return hpgs_set_error(hpgs_i18n("Out of memory pushing PCL palette.")); + + ++reader->pcl_i_palette; + + return 0; +} + +int hpgs_reader_pop_pcl_palette (hpgs_reader *reader) +{ + if (reader->pcl_i_palette <= 0) + return hpgs_set_error(hpgs_i18n("PCL palette stack underflow.")); + + hpgs_reader_destroy_pcl_palette(reader->pcl_palettes[reader->pcl_i_palette]); + + --reader->pcl_i_palette; + + return 0; +} + +void hpgs_reader_set_defaults (hpgs_reader *reader) +{ + int i; + + if (reader->pen_widths) + free(reader->pen_widths); + + if (reader->pen_colors) + free(reader->pen_colors); + + if (reader->poly_buffer) + free(reader->poly_buffer); + + // standard pen widths. + reader->npens = 8; + + reader->pen_widths = (double*)malloc(sizeof(std_pen_widths)); + memcpy(reader->pen_widths,std_pen_widths,sizeof(std_pen_widths)); + + reader->pen_colors = (hpgs_color *)malloc(sizeof(std_pen_colors)); + memcpy(reader->pen_colors,std_pen_colors,sizeof(std_pen_colors)); + + reader->min_color.r=0.0; + reader->min_color.g=0.0; + reader->min_color.b=0.0; + + reader->max_color.r=255.0; + reader->max_color.g=255.0; + reader->max_color.b=255.0; + + reader->poly_buffer_alloc_size = 256; + reader->poly_buffer_size = 0; + + reader->poly_buffer = (hpgs_reader_poly_point *) + malloc(sizeof(hpgs_reader_poly_point)*reader->poly_buffer_alloc_size); + + hpgs_reader_set_default_state (reader); + + reader->clipsave_depth = 0; + + for (i=0;i<=reader->pcl_i_palette;++i) + hpgs_reader_destroy_pcl_palette(reader->pcl_palettes[i]); + + reader->pcl_i_palette = -1; + + hpgs_reader_push_pcl_palette(reader); + + for (i=0;i<8;++i) + if (reader->pcl_raster_data[i]) + { + free(reader->pcl_raster_data[i]); + reader->pcl_raster_data[i] = 0; + } + + if (reader->pcl_image) + hpgs_image_destroy(reader->pcl_image); + + reader->pcl_scale = 72.0/300.0; + reader->pcl_hmi = 7.2; + reader->pcl_vmi = 12.0; + reader->pcl_point.x = 0.0; + reader->pcl_point.y = 0.0; + + reader->pcl_raster_mode = -1; + reader->pcl_raster_presentation = 0; + reader->pcl_raster_src_width = 0; + reader->pcl_raster_src_height = 0; + reader->pcl_raster_dest_width = 0; + reader->pcl_raster_dest_height = 0; + reader->pcl_raster_res = 75; + reader->pcl_raster_compression = 0; + reader->pcl_raster_y_offset = 0; + reader->pcl_raster_plane = 0; + reader->pcl_raster_line = 0; + + reader->pcl_raster_data_size = 0; + reader->pcl_raster_planes = 1; + + reader->pcl_image=0; + + reader->bytes_ignored = 0; + reader->eoc = 0; +} + +/* initializes the device */ +static int init_device(hpgs_reader *reader) +{ + hpgs_color pat = { 0.0,0.0,0.0 }; + + reader->rop3 = 252; + reader->src_transparency = HPGS_TRUE; + reader->pattern_transparency = HPGS_TRUE; + + if (hpgs_setlinejoin(reader->device,hpgs_join_miter)) return -1; + if (hpgs_setlinecap(reader->device,hpgs_cap_butt)) return -1; + if (hpgs_setmiterlimit(reader->device,5.0)) return -1; + if (hpgs_setrop3(reader->device, + reader->rop3, + reader->src_transparency, + reader->pattern_transparency)) return -1; + if (hpgs_setpatcol(reader->device,&pat)) return -1; + + return 0; +} + +/* + HPGL command BP (Begin Plot) +*/ +int hpgs_reader_do_BP (hpgs_reader *reader) +{ + while (!reader->eoc) + { + int kind; + int dummy; + char header[HPGS_MAX_LABEL_SIZE]; + if (hpgs_reader_read_int(reader,&kind)) return -1; + if (reader->eoc) return 0; + + switch (kind) + { + case 1: + if (hpgs_reader_read_new_string(reader,header)) return -1; + if (reader->verbosity) + hpgs_log(hpgs_i18n("Plot Title: %.*s\n"),HPGS_MAX_LABEL_SIZE,header); + break; + case 2: + case 3: + case 4: + case 5: + if (hpgs_reader_read_int(reader,&dummy)) return -1; + break; + default: + return -1; + } + } + + return init_device(reader); +} + +/* + HPGL command CO (COmment) +*/ +int hpgs_reader_do_CO (hpgs_reader *reader) +{ + char comment[HPGS_MAX_LABEL_SIZE]; + + if (reader->eoc) return 0; + + if (hpgs_reader_read_new_string(reader,comment)) return -1; + + if (reader->verbosity) + hpgs_log(hpgs_i18n("Comment: %.*s\n"),HPGS_MAX_LABEL_SIZE,comment); + + return reader->eoc ? 0 : -1; +} + +/* + HPGL command IN (Initialize Plot) +*/ +int hpgs_reader_do_IN (hpgs_reader *reader) +{ + int i; + + if (hpgs_reader_checkpath(reader)) return -1; + + if (!reader->eoc) + { + int dummy; + if (hpgs_reader_read_int(reader,&dummy)) return -1; + } + + while (reader->clipsave_depth > 0) + { + hpgs_cliprestore(reader->device); + --reader->clipsave_depth; + } + + hpgs_reader_set_default_state (reader); + + for (i=0;inpens;++i) + reader->pen_widths[i] = 1.0; + + return init_device(reader); +} + +/* + Internal function, which calls the page asset callback and + does a showpage on the device. + */ +int hpgs_reader_showpage (hpgs_reader *reader, int ipage) +{ + if (hpgs_reader_checkpath(reader)) return -1; + + while (reader->clipsave_depth > 0) + { + hpgs_cliprestore(reader->device); + --reader->clipsave_depth; + } + + if (reader->frame_asset_func) + { + hpgs_bbox frame_bbox; + + frame_bbox.llx = reader->frame_x == 0.0 ? reader->content_bbox.llx : reader->frame_x; + frame_bbox.lly = reader->content_bbox.lly; + frame_bbox.urx = reader->content_bbox.urx; + frame_bbox.ury = reader->content_bbox.ury; + + if (frame_bbox.urx > frame_bbox.llx) + { + int ipage = reader->current_page; + + if (reader->frame_asset_func(reader->frame_asset_ctxt, + reader->device, + &reader->page_matrix, + &reader->total_matrix, + &frame_bbox,ipage <= 1 ? 0 : ipage-1) ) + return -1; + } + } + + if (reader->page_asset_func && + reader->page_asset_func(reader->page_asset_ctxt, + reader->device, + &reader->page_matrix, + &reader->total_matrix, + &reader->content_bbox,ipage <= 1 ? 0 : ipage-1) ) + return -1; + + return hpgs_showpage(reader->device,ipage); +} + +/* + HPGL command PG (advance PaGe) +*/ +int hpgs_reader_do_PG(hpgs_reader *reader) +{ + int ret; + + ret = hpgs_reader_showpage(reader,reader->current_page); + + if (ret) return -1; + + ++reader->current_page; + + // if wee are not in singlepage mode, + // try to set the individual page size. + if (reader->current_page > 0 && + reader->plotsize_device && + (hpgs_device_capabilities(reader->device) & HPGS_DEVICE_CAP_MULTISIZE)) + { + hpgs_bbox page_bb; + int ret = hpgs_getplotsize(reader->plotsize_device,reader->current_page,&page_bb); + + if (ret < 0) return -1; + + // if ret is 1, we got the overall bounding box and the plotsize device + // knows about no more pages. + // So we stop the interpretation at this point. + return 2; + + // set the plotsize of the next page. + if (reader->verbosity) + hpgs_log(hpgs_i18n("Bounding Box of Page %d: %g %g %g %g.\n"), + reader->current_page, + page_bb.llx,page_bb.lly, + page_bb.urx,page_bb.ury ); + + // change the page layout. + hpgs_reader_set_page_matrix(reader,&page_bb); + hpgs_reader_set_default_transformation(reader); + + if (hpgs_setplotsize(reader->device,&reader->page_bbox) < 0) + return -1; + } + + // stop the interpretation, if we are in singlepage mode. + return reader->current_page > 0 ? 0 : 2; +} + +/* + HPGL command UL (User defined Linetype) +*/ +int hpgs_reader_do_UL (hpgs_reader *reader) +{ + int itype,nsegs; + + if (reader->eoc) + { + memcpy(reader->linetype_nsegs,std_linetype_nsegs,sizeof(std_linetype_nsegs)); + memcpy(reader->linetype_segs,std_linetype_segs,sizeof(std_linetype_segs)); + return 0; + } + + if (hpgs_reader_read_int(reader,&itype)) return -1; + + if (itype < -8 || itype > 8) + return hpgs_set_error(hpgs_i18n("Illegal linetype %d given."),itype); + + if (reader->eoc) + { + memcpy(reader->linetype_segs[8+itype], + std_linetype_segs[8+itype],sizeof(std_linetype_segs[0])); + memcpy(reader->linetype_segs[8-itype], + std_linetype_segs[8-itype],sizeof(std_linetype_segs[0])); + + reader->linetype_nsegs[8+itype] = std_linetype_nsegs[8+itype]; + reader->linetype_nsegs[8+itype] = std_linetype_nsegs[8-itype]; + return 0; + } + + nsegs = 0; + + while (!reader->eoc) + { + double gap; + if (hpgs_reader_read_double(reader,&gap)) return -1; + + reader->linetype_segs[8+itype][nsegs] = gap; + reader->linetype_segs[8-itype][nsegs] = gap; + ++nsegs; + } + + reader->linetype_nsegs[8+itype] = nsegs; + reader->linetype_nsegs[8-itype] = nsegs; + + return 0; +} + +/* + HPGL command MC (Merge Control) +*/ +int hpgs_reader_do_MC (hpgs_reader *reader) +{ + int mode=0,rop=252; + + if (!reader->eoc && + hpgs_reader_read_int(reader,&mode)) return -1; + + if (!reader->eoc && + hpgs_reader_read_int(reader,&rop)) return -1; + + reader->rop3 = mode ? rop : 252; + + return hpgs_setrop3(reader->device,reader->rop3, + reader->src_transparency, + reader->pattern_transparency ); +} + +/* + HPGL command TR (Transparency Mode) +*/ +int hpgs_reader_do_TR (hpgs_reader *reader) +{ + int n=1; + + if (!reader->eoc && + hpgs_reader_read_int(reader,&n)) return -1; + + reader->src_transparency = (n != 0); + + return hpgs_setrop3(reader->device,reader->rop3, + reader->src_transparency, + reader->pattern_transparency ); +} diff --git a/src/add-ons/translators/hpgs/lib/hpgstransform.c b/src/add-ons/translators/hpgs/lib/hpgstransform.c new file mode 100644 index 0000000000..3a9b3f88c0 --- /dev/null +++ b/src/add-ons/translators/hpgs/lib/hpgstransform.c @@ -0,0 +1,773 @@ +/*********************************************************************** + * * + * $Id: hpgstransform.c 362 2006-10-16 14:13:48Z softadm $ + * * + * hpgs - HPGl Script, a hpgl/2 interpreter, which uses a Postscript * + * API for rendering a scene and thus renders to a variety of * + * devices and fileformats. * + * * + * (C) 2004-2006 ev-i Informationstechnologie GmbH http://www.ev-i.at * + * * + * Author: Wolfgang Glas * + * * + * hpgs is free software; you can redistribute it and/or * + * modify it under the terms of the GNU Lesser General Public * + * License as published by the Free Software Foundation; either * + * version 2.1 of the License, or (at your option) any later version. * + * * + * hpgs is distributed in the hope that it will be useful, * + * but WITHOUT ANY WARRANTY; without even the implied warranty of * + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * + * Lesser General Public License for more details. * + * * + * You should have received a copy of the GNU Lesser General Public * + * License along with this library; if not, write to the * + * Free Software Foundation, Inc., 59 Temple Place, Suite 330, * + * Boston, MA 02111-1307 USA * + * * + *********************************************************************** + * * + * The implementation of the HPGL reader. * + * * + ***********************************************************************/ + +#include +#include + +//#define HPGS_DEBUG_XFORM + +static void apply_scale(hpgs_reader *reader, + const hpgs_point *p1, const hpgs_point *p2) +{ + double xf,yf; + double dx = 0.0,dy=0.0; + hpgs_point p2u; + + if (reader->sc_type < 0) return; + + // get P2 in old user coordinates + p2u.x = reader->frame_x + p2->x * HP_TO_PT; + p2u.y = reader->frame_y + p2->y * HP_TO_PT; + + hpgs_matrix_ixform(&p2u,&p2u,&reader->world_matrix); + +#ifdef HPGS_DEBUG_XFORM + { + hpgs_point p1u; + + p1u.x = reader->frame_x + p1->x * HP_TO_PT; + p1u.y = reader->frame_y + p1->y * HP_TO_PT; + + hpgs_matrix_ixform(&p1u,&reader->world_matrix,&p1u); + + hpgs_log("SC: P1 = %g,%g.\n",p1->x,p1->y); + hpgs_log("SC: P2 = %g,%g.\n",p2->x,p2->y); + hpgs_log("SC: p1u = %g,%g.\n",p1u.x,p1u.y); + hpgs_log("SC: p2u = %g,%g.\n",p2u.x,p2u.y); + hpgs_log("SC: xmin,xmax = %g,%g.\n",reader->sc_xmin,reader->sc_xmax); + hpgs_log("SC: ymin,ymax = %g,%g.\n",reader->sc_ymin,reader->sc_ymax); + } +#endif + + switch (reader->sc_type) + { + case 0: + xf = p2u.x / (reader->sc_xmax - reader->sc_xmin); + yf = p2u.y / (reader->sc_ymax - reader->sc_ymin); + break; + case 1: + xf = p2u.x / (reader->sc_xmax - reader->sc_xmin); + yf = p2u.y / (reader->sc_ymax - reader->sc_ymin); + + if (xf < yf) + { + dy = (yf-xf) * (reader->sc_ymax - reader->sc_ymin) * 0.01 * reader->sc_left; + yf = xf; + } + else + { + dx = (xf-yf) * (reader->sc_xmax - reader->sc_xmin) * 0.01 * reader->sc_bottom; + xf = yf; + } + break; + + case 2: + xf = reader->sc_xmax; + yf = reader->sc_ymax; + break; + + default: + return; + } + +#ifdef HPGS_DEBUG_XFORM + hpgs_log("SC: xf,yf = %g,%g.\n",xf,yf); +#endif + + dx -= reader->sc_xmin * xf; + dy -= reader->sc_ymin * yf; + + // concatenate transofrmation matrices. + // + // | 1 0 0 | | 1 0 0 | + // | x0 mxx mxy |* | dx xf 0 | = + // | y0 myx myy | | dy 0 yf | + // + // | 1 0 0 | + // | x0+mxx*dx+mxy*dy mxx*xf mxy*yf | + // | y0+myx*dx+myy*dy myx*xf myy*yf | + // + + reader->world_matrix.dx += reader->world_matrix.mxx*dx + reader->world_matrix.mxy*dy; + reader->world_matrix.dy += reader->world_matrix.myx*dx + reader->world_matrix.myy*dy; + + reader->world_matrix.mxx *= xf; + reader->world_matrix.myx *= xf; + reader->world_matrix.mxy *= yf; + reader->world_matrix.myy *= yf; + +#ifdef HPGS_DEBUG_XFORM + hpgs_log("SC: %10g %10g %10g\n",reader->world_matrix.dx,reader->world_matrix.mxx,reader->world_matrix.mxy); + hpgs_log("SC: %10g %10g %10g\n",reader->world_matrix.dy,reader->world_matrix.myx,reader->world_matrix.myy); +#endif +} + +void hpgs_reader_set_default_transformation (hpgs_reader *reader) +{ + // transformation matrix for user to PS coordinates. + int angle = reader->y_size >= reader->x_size ? 90 : 0; + + hpgs_point p1 = reader->P1; + hpgs_point p2 = reader->P2; + + angle += reader->rotation; + + if ((angle % 180) == 90) + { + p2.y -= p1.y; + p1.y = 0.0; + } + + + reader->world_matrix.dx = reader->frame_x + p1.x * HP_TO_PT; + reader->world_matrix.dy = reader->frame_y + p1.y * HP_TO_PT; + + switch (angle % 360) + { + case 90: + reader->world_matrix.mxx = 0.0; + reader->world_matrix.mxy = -HP_TO_PT; + reader->world_matrix.myx = HP_TO_PT; + reader->world_matrix.myy = 0.0; + break; + case 180: + reader->world_matrix.mxx = -HP_TO_PT; + reader->world_matrix.mxy = 0.0; + reader->world_matrix.myx = 0.0; + reader->world_matrix.myy = -HP_TO_PT; + break; + case 270: + reader->world_matrix.mxx = 0.0; + reader->world_matrix.mxy = HP_TO_PT; + reader->world_matrix.myx = -HP_TO_PT; + reader->world_matrix.myy = 0.0; + break; + default: // 0 + reader->world_matrix.mxx = HP_TO_PT; + reader->world_matrix.mxy = 0.0; + reader->world_matrix.myx = 0.0; + reader->world_matrix.myy = HP_TO_PT; + } + +#ifdef HPGS_DEBUG_XFORM + hpgs_log("xform: %10g %10g %10g\n",reader->world_matrix.dx,reader->world_matrix.mxx,reader->world_matrix.mxy); + hpgs_log("xform: %10g %10g %10g\n",reader->world_matrix.dy,reader->world_matrix.myx,reader->world_matrix.myy); +#endif + + apply_scale(reader,&p1,&p2); + + reader->world_scale = + sqrt (fabs(reader->world_matrix.mxx * reader->world_matrix.myy - + reader->world_matrix.mxy * reader->world_matrix.myx ) ); + + // finally transform from model space to the page. + hpgs_matrix_concat(&reader->total_matrix,&reader->page_matrix,&reader->world_matrix); + + reader->total_scale = reader->page_scale * reader->world_scale; +} + +/* + HPGL command PS (Plot Size) +*/ +int hpgs_reader_do_PS (hpgs_reader *reader) +{ + double x_size=reader->x_size/HP_TO_PT; + double y_size=reader->y_size/HP_TO_PT; + + if (reader->eoc) + { + // Well it seems, that some oldstyle HPGL files use + // PS w/o arguments in order to enforce a coordinate setup + // as if a portrait paper size has been selected. + // (resulting in a prerotation of 90 degrees). + x_size = 33600.0; + y_size = 47520.0; + } + else + { + if (hpgs_reader_read_double(reader,&x_size)) return -1; + + // set y-size to sqrt(0.5) * x_size in order to prevent + // the picture from rotation. This is better then setting + // the y-size to the (fictional) hard-clip limit, because + // without rotation we definitely can calculate our own plotsize + // using -i. + if (reader->eoc) + y_size = sqrt(0.5) * x_size; + } + + if (!reader->eoc && + hpgs_reader_read_double(reader,&y_size)) return -1; + + return hpgs_reader_set_plotsize (reader,x_size,y_size); +} + +/* + Actually set the plot size. User by PS command above and by PJL parser. +*/ +int hpgs_reader_set_plotsize (hpgs_reader *reader, double x_size, double y_size) +{ + hpgs_bbox bb = { 0.0,0.0,x_size*HP_TO_PT,y_size*HP_TO_PT }; + + reader->x_size = x_size; + reader->y_size = y_size; + + if (y_size >= x_size) + { + reader->P1.x = x_size; + reader->P1.y = 0.0; + reader->P2.x = 0.0; + reader->P2.y = y_size; + } + else + { + reader->P1.x = 0.0; + reader->P1.y = 0.0; + reader->P2.x = x_size; + reader->P2.y = y_size; + } + + reader->delta_P.x = reader->P2.x - reader->P1.x; + reader->delta_P.y = reader->P2.y - reader->P1.y; + + // undo any effects from an RO or SC statement. + reader->rotation = 0; + reader->sc_type = -1; + + // change the page matrix only, if we don't have a plotsize device. + if (!reader->plotsize_device) + hpgs_reader_set_page_matrix (reader,&bb); + + hpgs_reader_set_default_transformation(reader); + + // report plot size only if + // when we don't have a plotsize device at hands. + if (reader->plotsize_device) + return 0; + + return hpgs_setplotsize(reader->device,&reader->page_bbox); +} + +/* + Change the page matrix according to this content bounding box. +*/ +void hpgs_reader_set_page_matrix (hpgs_reader *reader, const hpgs_bbox *bb) +{ + hpgs_bbox rbb; + double xscale,yscale; + hpgs_point rcp; + + hpgs_matrix_ixform(&rcp,&reader->current_point,&reader->page_matrix); + + // save the content bounding box for propagating it to the + // page_asset function. + reader->content_bbox = *bb; + + if (reader->page_mode == 0) + { + reader->page_bbox = *bb; + hpgs_matrix_set_identity(&reader->page_matrix); + reader->page_scale = 1.0; + goto restore_cb; + } + + reader->page_matrix.mxx = cos(reader->page_angle * M_PI / 180.0); + reader->page_matrix.mxy = -sin(reader->page_angle * M_PI / 180.0); + + reader->page_matrix.myx = sin(reader->page_angle * M_PI / 180.0); + reader->page_matrix.myy = cos(reader->page_angle * M_PI / 180.0); + + reader->page_matrix.dx = 0.0; + reader->page_matrix.dy = 0.0; + + if (reader->page_mode == 2) // dynamic page. + { + hpgs_matrix_xform_bbox(&rbb,&reader->page_matrix,bb); + + reader->page_bbox.llx = 0.0; + reader->page_bbox.lly = 0.0; + + reader->page_bbox.urx = (rbb.urx-rbb.llx) + 2.0 * reader->page_border; + reader->page_bbox.ury = (rbb.ury-rbb.lly) + 2.0 * reader->page_border; + + reader->page_matrix.dx = reader->page_border - rbb.llx; + reader->page_matrix.dy = reader->page_border - rbb.lly; + + // do we fit on the maximal page size? + if ((reader->page_width <= 0.0 || reader->page_bbox.urx <= reader->page_width) && + (reader->page_height <= 0.0 || reader->page_bbox.ury <= reader->page_height) ) + { + reader->page_scale = 1.0; + goto restore_cb; + } + + if (reader->page_bbox.urx > reader->page_width) + xscale = reader->page_width/reader->page_bbox.urx; + else + xscale = 1.0; + + if (reader->page_bbox.ury> reader->page_height) + yscale = reader->page_height/reader->page_bbox.ury; + else + yscale = 1.0; + + reader->page_scale = HPGS_MIN(xscale,yscale); + + double rscale = 0.0; + double xx = 1.0; + + // transform the scale to a human-interceptable scale. + do + { + xx *= 0.1; + rscale = floor(reader->page_scale / xx); + } + while (rscale < 2.0); + + reader->page_scale = rscale * xx; + + reader->page_matrix.mxx *= reader->page_scale; + reader->page_matrix.mxy *= reader->page_scale; + + reader->page_matrix.myx *= reader->page_scale; + reader->page_matrix.myy *= reader->page_scale; + + reader->page_matrix.dx *= reader->page_scale; + reader->page_matrix.dy *= reader->page_scale; + + reader->page_bbox.urx *= reader->page_scale; + reader->page_bbox.ury *= reader->page_scale; + + goto restore_cb; + } + + // fixed page. + reader->page_bbox.llx = 0.0; + reader->page_bbox.lly = 0.0; + + reader->page_bbox.urx = reader->page_width; + reader->page_bbox.ury = reader->page_height; + + hpgs_matrix_xform_bbox(&rbb,&reader->page_matrix,bb); + + xscale = (reader->page_width - 2.0 * reader->page_border) / (rbb.urx-rbb.llx); + yscale = (reader->page_height - 2.0 * reader->page_border) / (rbb.ury-rbb.lly); + + reader->page_scale = HPGS_MIN(xscale,yscale); + + reader->page_matrix.mxx *= reader->page_scale; + reader->page_matrix.mxy *= reader->page_scale; + + reader->page_matrix.myx *= reader->page_scale; + reader->page_matrix.myy *= reader->page_scale; + + if (reader->page_scale == xscale) + { + reader->page_matrix.dx = reader->page_border - reader->page_scale * rbb.llx; + reader->page_matrix.dy = + 0.5 * (reader->page_height - reader->page_scale * (rbb.ury-rbb.lly)) - reader->page_scale * rbb.lly; + } + else + { + reader->page_matrix.dx = + 0.5 * (reader->page_width - reader->page_scale * (rbb.urx-rbb.llx)) - reader->page_scale * rbb.llx; + reader->page_matrix.dy = reader->page_border - reader->page_scale * rbb.lly; + } + + restore_cb: + hpgs_matrix_xform(&reader->current_point,&reader->page_matrix,&rcp); +} + +/* + HPGL command FR (advance FRame) +*/ +int hpgs_reader_do_FR (hpgs_reader *reader) +{ + double advance = reader->x_size; + + if (!reader->eoc) + { + if (hpgs_reader_read_double(reader,&advance)) return -1; + } + + if (hpgs_reader_checkpath(reader)) return -1; + + while (reader->clipsave_depth > 0) + { + hpgs_cliprestore(reader->device); + --reader->clipsave_depth; + } + + if (reader->frame_asset_func) + { + hpgs_bbox frame_bbox; + + frame_bbox.llx = reader->frame_x == 0.0 ? reader->content_bbox.llx : reader->frame_x; + frame_bbox.lly = reader->content_bbox.lly; + frame_bbox.urx = reader->frame_x + advance * HP_TO_PT; + frame_bbox.ury = reader->content_bbox.ury; + + if (frame_bbox.urx > frame_bbox.llx) + { + int ipage = reader->current_page; + + if (reader->frame_asset_func(reader->frame_asset_ctxt, + reader->device, + &reader->page_matrix, + &reader->total_matrix, + &frame_bbox,ipage <= 1 ? 0 : ipage-1) ) + return -1; + } + } + + reader->frame_x += advance * HP_TO_PT; + reader->P1.x -= advance; + reader->P2.x -= advance; + + return 0; +} + +/* + HPGL command RO (ROtate) +*/ +int hpgs_reader_do_RO (hpgs_reader *reader) +{ + int rot=0; + hpgs_point p1,p2; + double dx,dy; + + if (!reader->eoc && + hpgs_reader_read_int(reader,&rot)) return -1; + + switch ((rot - reader->rotation) % 360) + { + case 90: + p1.x = -reader->P1.y; + p1.y = reader->P1.x; + p2.x = -reader->P2.y; + p2.y = reader->P2.x; + break; + case 180: + p1.x = -reader->P1.x; + p1.y = -reader->P1.y; + p2.x = -reader->P2.x; + p2.y = -reader->P2.x; + break; + case 270: + p1.x = reader->P1.y; + p1.y = -reader->P1.x; + p2.x = reader->P2.y; + p2.y = -reader->P2.x; + break; + default: /* 0,360 */ + p1.x = reader->P1.x; + p1.y = reader->P1.y; + p2.x = reader->P2.x; + p2.y = reader->P2.x; + break; + } + + dx = p1.x < p2.x ? p1.x : p2.x; + dy = p1.y < p2.y ? p1.y : p2.y; + +#ifdef HPGS_DEBUG_XFORM + hpgs_log("RO: rot_old,rot = %d,%d.\n",reader->rotation,rot); + hpgs_log("RO: P1 = %g,%g.\n",reader->P1.x,reader->P1.y); + hpgs_log("RO: P2 = %g,%g.\n",reader->P2.x,reader->P2.y); +#endif + + reader->P1.x = p1.x-dx; + reader->P1.y = p1.y-dy; + reader->P2.x = p2.x-dx; + reader->P2.y = p2.y-dy; + +#ifdef HPGS_DEBUG_XFORM + hpgs_log("RO: P1 = %g,%g.\n",reader->P1.x,reader->P1.y); + hpgs_log("RO: P2 = %g,%g.\n",reader->P2.x,reader->P2.y); +#endif + + reader->rotation = rot; + + hpgs_reader_set_default_transformation(reader); + + return 0; +} + +/* + HPGL command SC (SCale) +*/ +int hpgs_reader_do_SC (hpgs_reader *reader) +{ + double xmin,xmax,ymin,ymax,left=50.0,bottom=50.0; + int type=0; + + if (reader->eoc) + { + reader->sc_type = -1; + hpgs_reader_set_default_transformation(reader); + return 0; + } + + if (hpgs_reader_read_double(reader,&xmin)) return -1; + if (reader->eoc) return -1; + if (hpgs_reader_read_double(reader,&xmax)) return -1; + if (reader->eoc) return -1; + if (hpgs_reader_read_double(reader,&ymin)) return -1; + if (reader->eoc) return -1; + if (hpgs_reader_read_double(reader,&ymax)) return -1; + if (!reader->eoc && + hpgs_reader_read_int(reader,&type)) return -1; + + if (type == 1 && !reader->eoc) + { + if (hpgs_reader_read_double(reader,&left)) return -1; + if (reader->eoc) return -1; + if (hpgs_reader_read_double(reader,&bottom)) return -1; + } + + reader->sc_type = type; + reader->sc_xmin = xmin; + reader->sc_xmax = xmax; + reader->sc_ymin = ymin; + reader->sc_ymax = ymax; + reader->sc_bottom = bottom; + reader->sc_left = left; + + hpgs_reader_set_default_transformation(reader); + return 0; +} + +/* + HPGL command IP (Input Point) +*/ +int hpgs_reader_do_IP (hpgs_reader *reader) +{ + // get default input point. + int angle = reader->y_size >= reader->x_size ? 90 : 0; + + angle += reader->rotation; + + switch (angle % 360) + { + case 90: + reader->P1.x = reader->x_size; + reader->P1.y = 0.0; + reader->P2.x = 0.0; + reader->P2.y = reader->y_size; + break; + case 180: + break; + reader->P1.x = reader->x_size; + reader->P1.y = reader->y_size; + reader->P2.x = 0.0; + reader->P2.y = 0.0; + break; + case 270: + reader->P1.x = 0.0; + reader->P1.y = reader->y_size; + reader->P2.x = reader->x_size; + reader->P2.y = 0.0; + break; + default: /* 0 */ + reader->P1.x = 0.0; + reader->P1.y = 0.0; + reader->P2.x = reader->x_size; + reader->P2.y = reader->y_size; + } + + + // read input point + if (!reader->eoc) + { + if (hpgs_reader_read_double(reader, + angle%180 ? + &reader->P1.y : + &reader->P1.x )) return -1; + if (reader->eoc) return -1; + if (hpgs_reader_read_double(reader,angle%180 ? + &reader->P2.x : + &reader->P1.y )) return -1; + } + + if (!reader->eoc) + { + if (hpgs_reader_read_double(reader, + angle%180 ? + &reader->P2.y : + &reader->P2.x )) return -1; + if (reader->eoc) return -1; + if (hpgs_reader_read_double(reader, + angle%180 ? + &reader->P1.x : + &reader->P2.y )) return -1; + } + + reader->delta_P.x = reader->P2.x - reader->P1.x; + reader->delta_P.y = reader->P2.y - reader->P1.y; + +#ifdef HPGS_DEBUG_XFORM + hpgs_log("IP: angle = %d.\n",angle); + hpgs_log("IP: P1 = %g,%g.\n",reader->P1.x,reader->P1.y); + hpgs_log("IP: P2 = %g,%g.\n",reader->P2.x,reader->P2.y); +#endif + + reader->sc_type = -1; + hpgs_reader_set_default_transformation(reader); + + return 0; +} + +/* + HPGL command IR (Input point Relative) +*/ +int hpgs_reader_do_IR (hpgs_reader *reader) +{ + // get default input point. + double p1x=0.0,p1y=0.0,p2x,p2y; + + int angle = reader->y_size >= reader->x_size ? 90 : 0; + + angle += reader->rotation; + + switch (angle % 360) + { + case 90: + p1x = reader->x_size; + p1y = 0.0; + p2x = 0.0; + p2y = reader->y_size; + break; + case 180: + break; + p1x = reader->x_size; + p1y = reader->y_size; + p2x = 0.0; + p2y = 0.0; + break; + case 270: + p1x = 0.0; + p1y = reader->y_size; + p2x = reader->x_size; + p2y = 0.0; + break; + default: + p1x = 0.0; + p1y = 0.0; + p2x = reader->x_size; + p2y = reader->y_size; + } + + // read input point + if (!reader->eoc) + { + double x,y; + + if (hpgs_reader_read_double(reader,&x)) return -1; + if (hpgs_reader_read_double(reader,&y)) return -1; + + p1x = reader->x_size * x * 0.01; + p2x = p1x + reader->delta_P.x; + p1y = reader->y_size * y * 0.01; + p2y = p1y + reader->delta_P.y; + } + + if (!reader->eoc) + { + if (hpgs_reader_read_double(reader,&p2x)) return -1; + if (hpgs_reader_read_double(reader,&p2y)) return -1; + + p2x = reader->x_size * p2x * 0.01; + p2y = reader->y_size * p2y * 0.01; + + reader->delta_P.x = p2x - p1x; + reader->delta_P.y = p2y - p1y; + } + + reader->P1.x = p1x; + reader->P1.y = p1y; + reader->P2.x = p2x; + reader->P2.y = p2y; + +#ifdef HPGS_DEBUG_XFORM + hpgs_log("IR: P1 = %g,%g.\n",reader->P1.x,reader->P1.y); + hpgs_log("IR: P2 = %g,%g.\n",reader->P2.x,reader->P2.y); +#endif + + hpgs_reader_set_default_transformation(reader); + + return 0; +} + +/* + HPGL command IW (Input Window) +*/ +int hpgs_reader_do_IW (hpgs_reader *reader) +{ + // get default input point. + hpgs_point ll; + hpgs_point ur; + hpgs_point p; + + if (hpgs_reader_checkpath(reader)) return -1; + + while (reader->clipsave_depth > 0) + { + hpgs_cliprestore(reader->device); + --reader->clipsave_depth; + } + + if (reader->eoc) return 0; + + // read input point + if (hpgs_reader_read_point(reader,&ll,1)) return -1; + if (hpgs_reader_read_point(reader,&ur,1)) return -1; + + if (hpgs_clipsave(reader->device)) return -1; + ++reader->clipsave_depth; + + if (hpgs_newpath(reader->device)) return -1; + if (hpgs_moveto(reader->device,&ll)) return -1; + p.x = ll.x; + p.y = ur.y; + if (hpgs_lineto(reader->device,&p)) return -1; + if (hpgs_lineto(reader->device,&ur)) return -1; + p.x = ur.x; + p.y = ll.y; + if (hpgs_lineto(reader->device,&p)) return -1; + if (hpgs_closepath(reader->device)) return -1; + if (hpgs_clip(reader->device,HPGS_TRUE)) return -1; + + reader->have_current_point = 0; + + return hpgs_newpath(reader->device); +} diff --git a/src/add-ons/translators/hpgs/lib/hpgszostream.c b/src/add-ons/translators/hpgs/lib/hpgszostream.c new file mode 100644 index 0000000000..fe8bed3d8a --- /dev/null +++ b/src/add-ons/translators/hpgs/lib/hpgszostream.c @@ -0,0 +1,329 @@ +/*********************************************************************** + * * + * $Id: hpgszostream.c 368 2006-12-31 15:18:08Z softadm $ + * * + * hpgs - HPGl Script, a hpgl/2 interpreter, which uses a Postscript * + * API for rendering a scene and thus renders to a variety of * + * devices and fileformats. * + * * + * (C) 2004-2006 ev-i Informationstechnologie GmbH http://www.ev-i.at * + * * + * Author: Wolfgang Glas * + * * + * hpgs is free software; you can redistribute it and/or * + * modify it under the terms of the GNU Lesser General Public * + * License as published by the Free Software Foundation; either * + * version 2.1 of the License, or (at your option) any later version. * + * * + * hpgs is distributed in the hope that it will be useful, * + * but WITHOUT ANY WARRANTY; without even the implied warranty of * + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * + * Lesser General Public License for more details. * + * * + * You should have received a copy of the GNU Lesser General Public * + * License along with this library; if not, write to the * + * Free Software Foundation, Inc., 59 Temple Place, Suite 330, * + * Boston, MA 02111-1307 USA * + * * + *********************************************************************** + * * + * The implementation of a deflate output stream. * + * * + ***********************************************************************/ + +#include +#include +#include +#ifdef WIN32 +#include +#else +#include +#endif + +// Internals of hpgs_z_ostream +typedef struct hpgs_z_ostream_stream_st hpgs_z_ostream_stream; + +#define Z_OSTREAM_BUF_SIZE 16384 +#define Z_OSTREAM_XFER_SIZE 4096 + +struct hpgs_z_ostream_stream_st +{ + hpgs_ostream *base; + + int compression; + hpgs_bool take_base; + + unsigned char buffer [Z_OSTREAM_BUF_SIZE]; + unsigned char xfer [Z_OSTREAM_XFER_SIZE]; + + unsigned char *pptr; + + int errflg; + + z_stream zstream; + size_t total_bytes; +}; + +static int z_init(hpgs_z_ostream_stream *stream) +{ + if (deflateInit(&stream->zstream,stream->compression)==Z_OK) + { + stream->zstream.next_out = (Bytef *)stream->xfer; + stream->zstream.avail_out = sizeof(stream->xfer); + stream->zstream.total_out = 0; + stream->zstream.avail_in = 0; + stream->zstream.total_in = 0; + stream->total_bytes = 0; + return 0; + } + return -1; +} + +static int z_consume(hpgs_z_ostream_stream *stream, int flags) +{ + int cnt=stream->pptr-stream->buffer; + + int zret; + + if (stream->errflg) + return EOF; + + if (!stream->zstream.next_out && z_init(stream)) return EOF; + + if (cnt <= 0 && flags == Z_NO_FLUSH) return 0; + + stream->zstream.avail_in=cnt; + stream->zstream.total_in=0; + stream->zstream.next_in=(Bytef *)stream->buffer; + + do + { + stream->zstream.avail_out=Z_OSTREAM_XFER_SIZE; + stream->zstream.total_out=0; + stream->zstream.next_out=(Bytef *)stream->xfer; + + zret=deflate (&stream->zstream,flags); + + if (hpgs_ostream_write(stream->xfer,1,stream->zstream.total_out,stream->base) < stream->zstream.total_out) + { stream->errflg = 1; return -1; } + } + + while (zret == Z_OK && + stream->zstream.avail_out == 0); + + stream->pptr = stream->buffer; + + + if (stream->zstream.avail_in==0) + { + stream->total_bytes += cnt; + return 0; + } + else + { + stream->errflg = 1; + return -1; + } +} + +static int z_putc (int c, hpgs_z_ostream_stream *stream) +{ + if (stream->pptr >= stream->buffer + Z_OSTREAM_BUF_SIZE) + z_consume(stream,Z_NO_FLUSH); + + if (stream->errflg) + return EOF; + + *stream->pptr = c; + ++stream->pptr; + + return c & 0xff; +} + +static int z_write (void *ptr, size_t size, size_t nmemb, hpgs_z_ostream_stream *stream) +{ + size_t tot_bytes = size*nmemb; + size_t avail_bytes = stream->buffer + Z_OSTREAM_BUF_SIZE - stream->pptr; + size_t put_bytes = tot_bytes < avail_bytes ? tot_bytes : avail_bytes; + + if (stream->errflg) + return EOF; + + memcpy(stream->pptr,ptr,put_bytes); + stream->pptr += put_bytes; + + while (stream->pptr >= stream->buffer + Z_OSTREAM_BUF_SIZE && + z_consume(stream,Z_NO_FLUSH) == 0) + { + ptr += put_bytes; + tot_bytes -= put_bytes; + + put_bytes = tot_bytes < Z_OSTREAM_BUF_SIZE ? tot_bytes : Z_OSTREAM_BUF_SIZE ; + + memcpy(stream->pptr,ptr,put_bytes); + stream->pptr += put_bytes; + } + + return stream->errflg ? 0 : nmemb; +} + +static int z_vprintf (hpgs_z_ostream_stream *stream, const char *fmt, va_list ap) +{ + int n; + size_t size=1024; + char *buf; + + while (1) + { + if (stream->errflg) + return EOF; + + buf = hpgs_alloca(size); + + /* Try to print in the allocated space. */ + va_list aq; + va_copy(aq, ap); +#ifdef WIN32 + n = _vsnprintf (buf, size, fmt, aq); +#else + n = vsnprintf (buf, size, fmt, aq); +#endif + va_end(aq); + + /* If that worked, push the string. */ + if (n > -1 && n < size) + return z_write(buf,n,1,stream) ? n : -1; + + /* Else try again with more space. */ + if (n < 0) + size *= 2; + else + size = n+1; + } + + return 0; +} + +static int z_flush (hpgs_z_ostream_stream *stream) +{ + if (stream->zstream.next_out == 0 && stream->pptr <= stream->buffer) return 0; + int ret = z_consume(stream,Z_FINISH); + + deflateEnd (&stream->zstream); + stream->zstream.next_out = 0; + + return ret; +} + +static int z_close (hpgs_z_ostream_stream *stream) +{ + int ret=0; + + if (stream->zstream.next_out) + deflateEnd (&stream->zstream); + + if (stream->take_base && hpgs_ostream_close(stream->base)) + ret = -1; + + free(stream); + + return ret; +} + +static int z_iserror (hpgs_z_ostream_stream *stream) +{ + return stream->errflg; +} + +static hpgs_istream *z_getbuf (hpgs_z_ostream_stream *stream) +{ + z_flush(stream); + return hpgs_ostream_getbuf(stream->base); +} + +static int z_tell (hpgs_z_ostream_stream *stream, int layer, size_t *pos) +{ + if (layer > 0) + return hpgs_ostream_tell(stream->base,layer-1,pos); + else if (layer == 0) + { + *pos = stream->total_bytes; + return 0; + } + else + return -1; +} + +static int z_seek (hpgs_z_ostream_stream *stream, size_t pos) +{ + // only seek(0) is supported in order to reuse the stream. + if (pos) return -1; + + z_flush(stream); + + return hpgs_ostream_seek(stream->base,0); +} + +static hpgs_ostream_vtable z_vtable = + { + (hpgs_ostream_putc_func_t) z_putc, + (hpgs_ostream_write_func_t) z_write, + (hpgs_ostream_vprintf_func_t) z_vprintf, + (hpgs_ostream_flush_func_t) z_flush, + (hpgs_ostream_close_func_t) z_close, + (hpgs_ostream_iserror_func_t) z_iserror, + (hpgs_ostream_getbuf_func_t) z_getbuf, + (hpgs_ostream_tell_func_t) z_tell, + (hpgs_ostream_seek_func_t) z_seek, + }; + +/*! Returns a new \c hpgs_ostream created on the heap, + which operates on a given \c hpgs_ostream and writes + the given data through a zlib deflate stream using + the given compression. + + If \c take_base is false, the stream \c base is closed, when + the returned stream is closed. In this case, don't close it at + your own. + + Returns a null pointer, when the system is out of memory. + */ +hpgs_ostream *hpgs_new_z_ostream (hpgs_ostream *base, int compression, hpgs_bool take_base) +{ + hpgs_z_ostream_stream *stream; + hpgs_ostream *ret = (hpgs_ostream *)malloc(sizeof(hpgs_ostream)); + + if (!ret) + return 0; + + stream = + (hpgs_z_ostream_stream *)malloc(sizeof(hpgs_z_ostream_stream)); + + if (!stream) + { + free (ret); + return 0; + } + + stream->base = base; + stream->compression = compression; + stream->take_base = take_base; + + stream->zstream.zalloc = Z_NULL; + stream->zstream.zfree = Z_NULL; + stream->zstream.opaque = Z_NULL; + + stream->zstream.next_out = 0; + stream->zstream.avail_out = 0; + stream->zstream.total_out = 0; + stream->zstream.avail_in = 0; + stream->zstream.total_in = 0; + stream->pptr = stream->buffer; + stream->total_bytes = 0; + stream->errflg = 0; + + ret->stream = stream; + ret->vtable = &z_vtable; + + return ret; +}