Commit 42e72ef5 authored by Reinhard Tartler's avatar Reinhard Tartler

Imported nxcompext-3.1.0-2.tar.gz

Summary: Imported nxcompext-3.1.0-2.tar.gz Keywords: Imported nxcompext-3.1.0-2.tar.gz into Git repository
parent a840692e
/**************************************************************************/
/* */
/* Copyright (c) 2001, 2007 NoMachine, http://www.nomachine.com/. */
/* */
/* NXCOMPEXT, NX protocol compression and NX extensions to this software */
/* are copyright of NoMachine. Redistribution and use of the present */
/* software is allowed according to terms specified in the file LICENSE */
/* which comes in the source distribution. */
/* */
/* Check http://www.nomachine.com/licensing.html for applicability. */
/* */
/* NX and NoMachine are trademarks of NoMachine S.r.l. */
/* */
/* All rigths reserved. */
/* */
/**************************************************************************/
#include <zlib.h>
#include "NXlib.h"
#include "Alpha.h"
#include "Z.h"
#define PANIC
#define WARNING
#undef TEST
#undef DEBUG
#define ALPHA_COMPRESSION_LEVEL 1
#define ALPHA_COMPRESSION_THRESHOLD 32
#define ALPHA_COMPRESSION_STRATEGY Z_RLE
static int alphaCompressionLevel = ALPHA_COMPRESSION_LEVEL;
static int alphaCompressionThreshold = ALPHA_COMPRESSION_THRESHOLD;
static int alphaCompressionStrategy = ALPHA_COMPRESSION_STRATEGY;
char *AlphaCompressData(const char *data, unsigned int size, unsigned int *compressed_size)
{
return ZCompressData(data, size, alphaCompressionThreshold, alphaCompressionLevel,
alphaCompressionStrategy, compressed_size);
}
/**************************************************************************/
/* */
/* Copyright (c) 2001, 2007 NoMachine, http://www.nomachine.com/. */
/* */
/* NXCOMPEXT, NX protocol compression and NX extensions to this software */
/* are copyright of NoMachine. Redistribution and use of the present */
/* software is allowed according to terms specified in the file LICENSE */
/* which comes in the source distribution. */
/* */
/* Check http://www.nomachine.com/licensing.html for applicability. */
/* */
/* NX and NoMachine are trademarks of NoMachine S.r.l. */
/* */
/* All rigths reserved. */
/* */
/**************************************************************************/
#ifndef Alpha_H
#define Alpha_H
#ifdef __cplusplus
extern "C" {
#endif
extern char *AlphaCompressData(
#if NeedFunctionPrototypes
const char* /* data */,
unsigned int /* size */,
unsigned int* /* compressed_size */
#endif
);
#ifdef __cplusplus
}
#endif
#endif /* Alpha_H */
/**************************************************************************/
/* */
/* Copyright (c) 2001, 2007 NoMachine, http://www.nomachine.com/. */
/* */
/* NXCOMPEXT, NX protocol compression and NX extensions to this software */
/* are copyright of NoMachine. Redistribution and use of the present */
/* software is allowed according to terms specified in the file LICENSE */
/* which comes in the source distribution. */
/* */
/* Check http://www.nomachine.com/licensing.html for applicability. */
/* */
/* NX and NoMachine are trademarks of NoMachine S.r.l. */
/* */
/* All rigths reserved. */
/* */
/**************************************************************************/
#include <stdio.h>
#include <stdlib.h>
#include "NXlib.h"
#include "Bitmap.h"
#define PANIC
#define WARNING
#undef TEST
#undef DEBUG
char *BitmapCompressData(XImage *image, unsigned int *size)
{
if (image -> bits_per_pixel != 32)
{
#ifdef TEST
fprintf(stderr, "******BitmapCompressData: Nothing to do with image of [%d] bpp and size [%d].\n",
image -> bits_per_pixel, image -> bytes_per_line * image -> height);
#endif
*size = image -> bytes_per_line * image -> height;
return image -> data;
}
else
{
/*
* Remove the 4th byte from the bitmap.
*/
char *data;
char *next_src;
char *next_dst;
#ifdef TEST
if (image -> bytes_per_line != 4 * image -> width)
{
fprintf(stderr, "******BitmapCompressData: PANIC! Image as [%d] bytes per line with expected [%d].\n",
image -> bytes_per_line, 4 * image -> width);
return NULL;
}
#endif
*size = image -> width * image -> height * 3;
data = Xmalloc(*size);
if (data == NULL)
{
#ifdef PANIC
fprintf(stderr, "******BitmapCompressData: PANIC! Failed to allocate [%d] bytes for the destination.\n",
*size);
#endif
*size = image -> bytes_per_line * image -> height;
return image -> data;
}
next_src = image -> data;
next_dst = data;
if (image -> byte_order == LSBFirst)
{
while (next_src < image -> data +
image -> bytes_per_line * image -> height)
{
*next_dst++ = *next_src++;
*next_dst++ = *next_src++;
*next_dst++ = *next_src++;
next_src++;
}
}
else
{
while (next_src < image -> data +
image -> bytes_per_line * image -> height)
{
next_src++;
*next_dst++ = *next_src++;
*next_dst++ = *next_src++;
*next_dst++ = *next_src++;
}
}
return data;
}
}
/**************************************************************************/
/* */
/* Copyright (c) 2001, 2007 NoMachine, http://www.nomachine.com/. */
/* */
/* NXCOMPEXT, NX protocol compression and NX extensions to this software */
/* are copyright of NoMachine. Redistribution and use of the present */
/* software is allowed according to terms specified in the file LICENSE */
/* which comes in the source distribution. */
/* */
/* Check http://www.nomachine.com/licensing.html for applicability. */
/* */
/* NX and NoMachine are trademarks of NoMachine S.r.l. */
/* */
/* All rigths reserved. */
/* */
/**************************************************************************/
#ifndef Bitmap_H
#define Bitmap_H
#ifdef __cplusplus
extern "C" {
#endif
extern char *BitmapCompressData(
#if NeedFunctionPrototypes
XImage* /* image */,
unsigned int* /* compressed_size */
#endif
);
#ifdef __cplusplus
}
#endif
#endif /* Bitmap_H */
ChangeLog:
nxcompext-3.1.0-2
- Updated file VERSION to match the current release version.
nxcompext-3.1.0-1
- Opened the 3.1.0 branch based on nxcompext-3.0.0-18.
nxcompext-3.0.0-18
- Removed the remaining debug output.
nxcompext-3.0.0-17
- Changed the copyright notices at the beginning of the files that
were referring to NXPROXY to refer to NXCOMPEXT.
nxcompext-3.0.0-16
- Handle the reply failure in NXGetShmemParameters().
nxcompext-3.0.0-15
- Separated the functionalities made available by NXQueryDisplay()
in three distinct functions:
NXDisplayReadable() Query the number of bytes readable from
the display connection.
NXDisplayFlushable() Query the number of the outstanding bytes
to flush to the display connection.
NXDisplayCongestion() Return a value between 0 and 9 indicating
the congestion level of the NX transport.
- Renamed NXQueryDisplayError() to NXDisplayError().
nxcompext-3.0.0-14
- Removed support for Rdp, Tight and Hextile packed images encod-
ing since they have been made obsolete by the new NX server.
- Changed the copyright attribution from Medialogic to NoMachine.
nxcompext-3.0.0-13
- Allocate 1024 additional bytes for the Jpeg compression, instead
of 512, to avoid failures on very tiny images.
- Removed support for the special *PNG_JPEG* pack method.
nxcompext-3.0.0-12
- Implemented the NXEncodeBitmap() method. This is a very simple
encoder removing the 4th byte in 32 bits-per-plane images. For
the other pixmap depths it simply returns a pointer to the orig-
inal image data, saving the copy. This encoding is intended to
better leverage the stream compression on low bandwidth links.
- Removed the quality parameter from the RGB/RLE encoding function.
nxcompext-3.0.0-11
- Removed the additional parameter in the call to NXTransFlush().
nxcompext-3.0.0-10
- Moved the _NXRDPGlyph and _NXRDPText declarations from NXlib.h
to NXproto.h to force fields to be CARD32.
- Fixed a typo in NXSetDisplayBuffer() that could cause a double
free.
- Fixed a compilation error with old GCC versions.
- Removed the warning issued on AMD64 when compiling with the logs
enabled.
nxcompext-3.0.0-9
- Added the NXDisplayCongestion query type to NXQueryDisplay(). It
returns a value between 0 and 9, with 9 meaning that the link is
congested and no further data can be sent.
- Added the NXSetDisplayBuffer() function. It allows the caller to
set the display output buffer size at runtime.
- Removed the congestion and synchronization callbacks.
nxcompext-3.0.0-8
- Removed the warnings issued when purging the collected data at
display reset.
nxcompext-3.0.0-7
- Added the NXSetDisplayWriteHandler() interface. The function
registers a callback that will be invoked every time more data
is written to the display socket.
nxcompext-3.0.0-6
- Made NXQueryDisplay() take into account the bytes in the display
buffer when queried for the bytes flushable.
nxcompext-3.0.0-5
- Added file COPYING.
nxcompext-3.0.0-4
- Updated copyright notices to the current year.
nxcompext-3.0.0-3
- Imported changes up to nxcompext-2.1.0-4.
- Fixed TR12D01564. Changed configure script to build library with
-fPIC option.
- Added 256 byte to the size of Jpeg destination buffer.
nxcompext-3.0.0-2
- Updated the file VERSION.
nxcompext-3.0.0-1
- Opened the 3.0.0 branch based on nxcompext-2.0.0-33.
nxcompext-2.0.0-33
- Placed the inclusion of jpeglib.h after the X includes to fix a
possible compilation error.
nxcompext-2.0.0-32
- Avoid to copy the data to the scratch buffer and yield the task
of padding the output to _XSend() in the NXPutPackedImage(), NX-
SetUnpackAlpha() and NXSetUnpackColormap() requests.
- Added support for the RLE pack method.
nxcompext-2.0.0-31
- The X_NXSetUnpackColormap and X_NXSetUnpackAlpha now carry their
data in compressed form. The alpha data is compressed using the
ZLIB RLE encoding, while the colormap data is compressed using
the default ZLIB deflate.
- Created new message structures to handle the compatibility with
the old proxy versions. When connected to an old proxy version
the agent should use the NXSetUnpackColormapCompat() and NXSet-
UnpackAlpha() interfaces.
nxcompext-2.0.0-30
- Removed the unfriendly warning printed if a client tried to reset
the library multiple times.
nxcompext-2.0.0-29
- Made possible to compile even if makedepend is not found.
nxcompext-2.0.0-28
- Added the NXSetDisplaySynchronizationHandler() interface. The NX
transport will use the callback to report when the agent can use
the available bandwidth to synchronize the X objects that are
corrupted or incomplete.
- Bytes from 14 to 24 in the NXGetControlParameters() reply report,
respectively, the frame timeout, the ping timeout, the preferred
image split mode and the split size threshold.
nxcompext-2.0.0-27
- Changed the image cleanup functions and the Png and Jpeg encoders
to be independent from the host endianess.
- Enabled again the image cleanup on big endian machines.
nxcompext-2.0.0-26
- Added the NXAbortSplit() request.
- Added information about the size of the shared memory segment used
by the remote proxy in the NXGetShmemParameters() reply.
nxcompext-2.0.0-25
- Renamed the NXGetSplitResource() and NXGetUnpackResource() utili-
ties to NXAllocSplit() and NXAllocUnpack(). They can be called
with a NXAnyResource parameter to get the first available id or
requre a specific resource. From this version the resource must
be explicitly reserved. NXFreeUnpack() and NXFreeSplit() check
if the resource was allocated and don't do anything if it is not
the case. NXAllocSplit() and NXAllocUnpack() return NXNoResource
if the resource can't be reserved.
nxcompext-2.0.0-24
- NXFlushDisplay() now verifies whether the XlibDisplayWriting flag
is set before flushing the display buffer. in this case, it only
flushes the NX link.
nxcompext-2.0.0-23
- Implemented a move-to-front strategy for the image cache, to mi-
nimize the number of lookups.
- Fixed the problems imtroduced by the new cache implementation by
modifying the memory allocation routines in Jpeg.c and Pgn.c.
- Temporarily fixed the cleanup problems on big-endian machines by
skipping the operation.
- Added a NXSetDisplayStatisticsHandler() to let the agent include
arbitrary data in the transport statistics. The parameter is a
pointer to a pointer to a null terminated string. The pointer is
set at the time the handler is registered. The pointed string can
be filled by the agent with its statistics data.
nxcompext-2.0.0-22
- The NXCacheFindImage() returns a pointer to the checksum, if the
image is found.
- The image cache uses the data passed to NXCacheAddImage() instead
of making a copy.
- The Z stream used by the RGB encoder is allocated at initializat-
ion and freed at reset.
nxcompext-2.0.0-21
- Removed the reliance on the local byte order in the image cleanup
functions.
nxcompext-2.0.0-20
- Added the NXFinishSplit() request. It forces the proxy to comple-
tely transfer all the split messages for the given resource, and
then notify the agent.
nxcompext-2.0.0-19
- Enabled again the cleanup of images.
- Updated to comply with the new NXTransFlush() interface.
nxcompext-2.0.0-18
- Moved all the declarations in Rgb.c at the beginning of the block
to avoid the possible compilation errors with old compilers.
nxcompext-2.0.0-17
- Added a new RGB image encoder. For now the encoder uses a static
Z stream to compress the image data in the destination buffer and
allows the agent to use the simplest encoding by still separating
the alpha channel from the image data. The new encoder can be the
the base for implementing color reduction by dithering or a color-
mapped translation of the image similar to PNG, but without the
PNG overhead and with the colormap being sent to the client using
the NXSetUnpackColormap() opcode.
- Created a new NXCleanImage() function that takes a XImage pointer
and uses either the CleanXYImage() or the CleanZImage() routines
to cleanup the padding bits.
nxcompext-2.0.0-16
- Added a parameter to NXFlushDisplay() to specify what needs to be
flushed. The parameter can be one the following values, defined
in NXvars.h:
NXFlushBuffer Only the Xlib buffer is to be flushed.
NXFlushLink Flush both the Xlib buffer and any pending
data encoded by the NX transport.
NXFlushIdle Inform the NX transport that the agent is
idle. This will let the NX transport encode
more low-priority data, and then flush the
link.
- Ensured that the padding bytes are cleaned when creating a new
PNG image. It seems that some images are still missed. This is
to be investigated.
nxcompext-2.0.0-15
- Ensured that the packed image cache is recreated only on a size
change.
nxcompext-2.0.0-14
- Updated to get the karma delay field from the X_NXGetControlPara-
meters reply.
nxcompext-2.0.0-13
- Added the NXSetDisplayPolicy() and NXSetDisplayFlushHandler() in-
terfaces. The second function registers a callback that will be
invoked by the NX transport when the number of bytes encoded by
the proxy exceeds the threshold set for the scheduled write.
- Added the NXFlushDisplay() and NXQueryDisplay() interfaces. They
are used to hide the corresponding NX transport functions to the
application. NXQueryDisplay() can be called with the NXDisplay-
Flushable or NXDisplayReadable parameters, to get, repectively,
the number of bytes that are queued to the NX transport and the
number of bytes that is possible to read.
- Included the remote proxy version in the NXGetControlParameter()
reply.
nxcompext-2.0.0-12
- Added the NXGetSplitResource() and NXGetUnpackResource utilities.
These can be used by the client to find out the first unused id
available for a split or unpack operation.
- Added the NXFreeSplit() request function. It makes the resource
available for the next operation and tells the proxy to destroy
all the storage associated to the split.
- Renamed the NXNumberOfConnections constant to NXNumberOfResources.
nxcompext-2.0.0-11
- Changed NXForceDisplayError() to also shut down the NX transport
by calling NXTransClose().
- Updated to comply with the new NX function prototypes introduced
in nxcomp-2.0.0-31.
nxcompext-2.0.0-10
- NXQueryDisplayError() now checks the predicate function only if
the I/O error was not encountered already.
nxcompext-2.0.0-9
- Added the NXSetDisplayErrorPredicate(), NXSetDisplayBlockHand-
ler(), NXSetDisplayCongestionHandler(), NXSetLostSequenceHand-
ler() interfaces to let the user set the values used internal-
ly. All functions return the previous handler. See ChangeLog
in nx-X11-2.0.0-16 and nx-X11-2.0.0-17.
- Moved all the internal variables shared between Xlib, nxcompext
and the X server in nxcomp. Declarations and function prototypes
moved to NXvars.h.
- Some name changes. In particular the NXContinueOnDisplayError()
function iss renamed NXHandleDisplayError() and NXDisplayError()
is now renamed NXQueryDisplayError(). To verify if the display
is valid, NXQueryDisplayError() will now call the _NXDisplayEr-
rorPredicate function, or, if the predicate function is not set,
will simply check the value of the XlibDisplayIOError flag.
- Removed the NXGetCleanupParameters() and NXGetImageParameters()
interfaces and the remaining references to the unused display
buffer and image cleanup functions.
- Updated the NoMachine copyright notice to year 2006.
nxcompext-2.0.0-8
- Removed the unused screen parameter from XSetUnpackGeometry().
- NXSetUnpackGeometry() now fails if no visual is provided.
nxcompext-2.0.0-7
- Changed the LICENSE file to state that the software is only made
available under the version 2 of the GPL.
- Removed the misplaced DXPC copyright notices from the license.
They were copied from NXCOMP but they don't apply in any way to
NXCOMPEXT.
nxcompext-2.0.0-6
- Added the NXSetCacheParameters() request. It tells to the local
proxy how to handle the X requests, namely if the next requests
have to be stored in the memory cache, split in smal data chunks,
and in the case of images, saved on disk in the persistent image
cache. The request will affect all X messages, including plain
and packed images. It can be used to tell the proxy to discard
images coming from some selected operations, like GLX or XVideo.
nxcompext-2.0.0-5
- Added the NXGetFontParameters() request and reply. If the proxy
has been configured accordingly, the request returns the X font
path that can be set by the agent to tunnel the font server con-
nections through the NX link.
nxcompext-2.0.0-4
- Initial work on font server tunneling.
nxcompext-2.0.0-3
- Renamed the NXSetExposeEvents request to NXSetExposeParameters.
nxcompext-2.0.0-2
- Modified the configure and the makefiles to support the Cygwin
environment.
- Renamed Png.h to Pgn.h to avoid name clashes on Windows.
- The distclean target now removes the autom4te.cache directory.
nxcompext-2.0.0-1
- Opened the 2.0.0 branch based on nxcompext-1.5.0-20.
nxcompext-1.5.0-20
- Removed the code installing a SIGSEGV handler before trying to
clean an image in NXCleanImageInPlace().
nxcompext-1.5.0-19
- Added the NXUnsetLibraryPath() function to specify the behaviour
of the Popen() in the X server. If the _NXUnsetLibraryPath flag
is set, the Popen() will remove the LD_LIBRARY_PATH variable from
the environment before running the child process. This will cause
the X server to run the process (for example the keyboard initia-
lization utilities) by using the native system libraries, instead
of the libraries shipped with the NX environment.
nxcompext-1.5.0-18
- Moved the declarations of _NXEnable* and related structures from
Xlibint.h to NXlibint.h.
- Use the include files from nx-X11 if the nx-X11/include directory
is found. The previous configure checked the presence of nx-X11/
exports/include, that might not be built at the time this library
is compiled.
nxcompext-1.5.0-17
- Added the -fPIC GCC flag when compiling on AMD64 architectures.
- Removed all warnings when compiling with GCC4.
- Small changes to configure.in to have specific CFLAGS.
- Created a new configure using autoconf 2.59.
nxcompext-1.5.0-16
- Added the 'mode' field in the NXStartSplit() request. It determi-
nes the strategy that the proxy will adopt to handle the image.
If set to 'eager', the proxy will only split the messages whose
size exceeds the split threshold (the threshold can be found in
the NXGetControlParameters() reply). If mode is set to lazy, the
proxy will split any image that it is not able to find in its
cache.
The opcode and the two available modes are defined in NXproto.h,
currently:
#define NXSplitModeDefault 0
#define NXSplitModeEager 1
#define NXSplitModeLazy 2
- All requests related to image streaming now carry a 'resource' id.
The id is currently ignored by the proxy in the case of NXCommit-
Split() requests.
nxcompext-1.5.0-15
- Removed the NXSync() and NXKarma() operations, not used anymore
by the NX agents.
- Updated to comply with changes occurred in the numbering of the
notification events and in the interface to the image streaming
functions.
nxcompext-1.5.0-14
- Accounted for the missing xoffset field in clean-up of XYPixmaps.
nxcompext-1.5.0-13
- Added a 'commit' field in NXCommitSplit(). When zero, the remote
proxy will remove the message from the split store, without send-
ing the recomposed image to the X server.
nxcompext-1.5.0-12
- Added the NXContinueOnDisplayError() function to specify the be-
haviour of the Xlib I/O error handler. If the flag is set to true,
Xlib will simply return, instead of quitting the program. This
leaves to the application the responsibility of checking the sta-
te of the XlibDisplayIOError flag.
- Changed NXDisplayIsValid() to NXDisplayError() and inverted the
logic. Now the function returns true if the display pointer is
NULL or the XlibDisplayIOError flag is set.
- Added the NXForceDisplayError() function, to shutdown the display
descriptor and force Xlib to set the I/O error flag.
nxcompext-1.5.0-11
- Added -I../nx-X11/exports/include to CCINCLUDES in Makefile.in.
nxcompext-1.5.0-10
- Added FindLSB() to replace ffs() that may be not present on some
systems.
- Some cosmetic changes.
nxcompext-1.5.0-9
- Fixed a printf() that prevented the code to compile if TEST was
enabled.
nxcompext-1.5.0-8
- Implemented the NXLib interface for asynchronous handling of the
XGetInputFocus requests and replies.
nxcompext-1.5.0-7
- Removed the _NXFlushSize parameter. New agents run the NX trans-
port in-process, so we don't get any benefit from increasing the
display buffer size.
nxcompext-1.5.0-6
- Added a NXDisplayIsValid() to check that the display is not NULL
and that the descriptor was not shut down after an IOError. The
reason a function is needed for this is that the flags field is
only in Xlibint and it is not visible to Xlib applications.
nxcompext-1.5.0-5
- Added the NXGetCollect*Resource utility functions, returning the
first available small integer resource id that can be used in a
subsequent collect request.
nxcompext-1.5.0-4
- Added the NXNumberOfConnections constant.
nxcompext-1.5.0-3
- Implemented the NXLib interface for the asynchronous handling of
the XGrabPointer requests and replies.
- Solved an error in image cleaning that prevented the 8 bits-per-
pixel images to be completely cleaned. Due to the bug, only half
of the total lines were cleaned.
- Removed a bug that prevented the cleaning of XYPixmaps images of
bitmap unit 32 and byte order LSB.
- Renamed the NXImageCache variables to show they are global. They
are currently used in the nxagent code.
nxcompext-1.5.0-2
- Changed VERSION file.
nxcompext-1.5.0-1
- Opened the 1.5.0 branch.
nxcompext-1.4.1-1
- Removed the configure option --with-static. There are two options
now, --with-static-png and --with-static-jpeg, to offer a greater
degree of control on the resulting library.
- This version differs from the 1.4.0-3-KRY1 in the way that the con-
figure script is generated by GNU Autoconf 2.57, the same version
used for nxcomp.
- Opened the 1.4.1 branch.
nxcompext-1.4.0-3
- Updated the VERSION file to reflect the 1.4.0 status.
nxcompext-1.4.0-2
- Imported changes from the latest 1.3.2 development branch.
- The 1.4.0 branch already had a 1.4.0-1 version. The changes from
the 1.4.0-1 were up to date with the 1.3.2-2 version.
nxcompext-1.3.2-6
- Fixed problem with icons in KDE and Mozilla on SPARC Solaris. The
problem was related to cleaning of one-bit XYPixmaps on big-endian
hosts, where shift of the cleaning mask executed in the wrong di-
rection.
nxcompext-1.3.2-5
- Changes in Clean.c to compile on Solaris.
nxcompext-1.3.2-4
- Fixed a bug in clean image procedures for 1bit XYPixmaps. The bug
caused Mozilla to trash some transparent icons in web pages and
the toolbar.
- Added cleaning of the padding bytes at the end of the data chunk
inside XImage structure
- Implemented handling of SIGSEGV during cleanup in case of static
data.
- Moved image cleanup and masking code in new Clean.c and Mask.c
sources.
- Corrected few typos in NXCollectImage code.
nxcompext-1.3.2-2
- Imported 1.4.0-1 changes from the 1.4.0 development branch.
- Modified NXAllocColors to handle errors generated allocating
each requested color. A per-color result code is now returned
to the caller.
- Code cleanup in Png.h and Png.c.
nxcompext-1.3.2-1
- Opened the 1.3.2 branch.
nxcompext-1.3.1-2
- Removed the underline characters and added a colon in the
title of this ChangeLog to fully comply with format used in
the release notices.
nxcompext-1.3.1-1
- Opened the 1.3.1 branch.
nxcompext-1.3.0-18
- Added the _NXLostSequenceHandler function to let NX agents
suppress the error message and modify the default Xlib
behaviour when out-of-order sequence numbers are received.
Pointer to function is assigned to _NXLostSequenceFunction
in XlibInt.c.
- Original output buffer size in stock XFree86 is 2048. We try
to reduce context switches and help stream compression by
increasing the maximum size of the buffer 8192. _NXFlushSize
determines when the display buffer is actually flushed. It is
set by default to 4096 in XlibInt.c and set to 0 to use the
maximum available size at the time NXGetControlParameters()
is called.
nxcompext-1.3.0-17
- In handling of asynchronous GetProperty replies a warning
message was printed in session log when a null property was
stored in the state structure. This message is now printed
only if TEST is defined.
nxcompext-1.3.0-16
- Added asynchronous handling of GetProperty request and reply
by means of the NXCollectProperty and NXGetCollectedProperty
requests and the NXCollectPropertyNotify event.
nxcompext-1.3.0-15
- Added 4 new fields to the X_NXGetControlParameters reply.
nxcompext-1.3.0-14
- Added request X_NXFreeUnpack to free the resources allocated
by the remote proxy to unpack images for the given agent's
client
nxcompext-1.3.0-13
- Modified the following requests to carry the id of the
agent's client in the field resource:
- X_NXSetUnpackGeometry
- X_NXSetUnpackColormap
- X_NXSetUnpackAlpha
- X_NXPutPackedImage
nxcompext-1.3.0-11
- Modified the MIT-SHM initialization procedure to always send
all the 3 protocol requests also in the case of early failures.
nxcompext-1.3.0-10
- Added handling of X_NXSetUnpackAlpha request.
- It has been made possible to send both X_NXSetUnpackColormap
and X_NXSetUnpackAlpha messages with 0 entries to temporarily
disable use of the colormap or the alpha channel and free the
resources allocated by the remote proxy.
nxcompext-1.3.0-9
- Solved a compatibility problem when mixing proxy versions
1.2.2 and 1.3.0 due to the missing X_NXGetShmemParameters
request.
nxcompext-1.3.0-7
- Reduced the number of requests needed to setup the shared
segment at X server proxy from 4 to 3.
- Small changes to the shared memory interface to support
path X agent to X client proxy.
nxcompext-1.3.0-6
- Implemented initial support for MIT-SHM extension in the
network path between the X server proxy and the real X
server.
- Configure script now checks for the FreeBSD environment.
- New configure script generated using autoconf-2.57-3.
- Removed the XFree86 CCDEFINES from Makefile.in.
nxcompext-1.3.0-5
- Cosmetic changes.
- Started to convert configure.in to the new layout adopted
for nxcomp.
- Created file CHANGELOG.
nxcompext-1.3.0-4
- More fixes in image clean-up.
nxcompext-1.3.0-3
- Many fixes in image clean-up functions to handle differences
in endianess between client and X server.
nxcompext-1.3.0-2
- Modified configure.in to compile under Solaris.
nxcompext-1.3.0-1
- First 1.3.0 version based on nxcompext-1.2.2-12.
GNU GENERAL PUBLIC LICENSE
Version 2, June 1991
Copyright (C) 1989, 1991 Free Software Foundation, Inc.,
51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
Everyone is permitted to copy and distribute verbatim copies
of this license document, but changing it is not allowed.
Preamble
The licenses for most software are designed to take away your
freedom to share and change it. By contrast, the GNU General Public
License is intended to guarantee your freedom to share and change free
software--to make sure the software is free for all its users. This
General Public License applies to most of the Free Software
Foundation's software and to any other program whose authors commit to
using it. (Some other Free Software Foundation software is covered by
the GNU Lesser General Public License instead.) You can apply it to
your programs, too.
When we speak of free software, we are referring to freedom, not
price. Our General Public Licenses are designed to make sure that you
have the freedom to distribute copies of free software (and charge for
this service if you wish), that you receive source code or can get it
if you want it, that you can change the software or use pieces of it
in new free programs; and that you know you can do these things.
To protect your rights, we need to make restrictions that forbid
anyone to deny you these rights or to ask you to surrender the rights.
These restrictions translate to certain responsibilities for you if you
distribute copies of the software, or if you modify it.
For example, if you distribute copies of such a program, whether
gratis or for a fee, you must give the recipients all the rights that
you have. You must make sure that they, too, receive or can get the
source code. And you must show them these terms so they know their
rights.
We protect your rights with two steps: (1) copyright the software, and
(2) offer you this license which gives you legal permission to copy,
distribute and/or modify the software.
Also, for each author's protection and ours, we want to make certain
that everyone understands that there is no warranty for this free
software. If the software is modified by someone else and passed on, we
want its recipients to know that what they have is not the original, so
that any problems introduced by others will not reflect on the original
authors' reputations.
Finally, any free program is threatened constantly by software
patents. We wish to avoid the danger that redistributors of a free
program will individually obtain patent licenses, in effect making the
program proprietary. To prevent this, we have made it clear that any
patent must be licensed for everyone's free use or not licensed at all.
The precise terms and conditions for copying, distribution and
modification follow.
GNU GENERAL PUBLIC LICENSE
TERMS AND CONDITIONS FOR COPYING, DISTRIBUTION AND MODIFICATION
0. This License applies to any program or other work which contains
a notice placed by the copyright holder saying it may be distributed
under the terms of this General Public License. The "Program", below,
refers to any such program or work, and a "work based on the Program"
means either the Program or any derivative work under copyright law:
that is to say, a work containing the Program or a portion of it,
either verbatim or with modifications and/or translated into another
language. (Hereinafter, translation is included without limitation in
the term "modification".) Each licensee is addressed as "you".
Activities other than copying, distribution and modification are not
covered by this License; they are outside its scope. The act of
running the Program is not restricted, and the output from the Program
is covered only if its contents constitute a work based on the
Program (independent of having been made by running the Program).
Whether that is true depends on what the Program does.
1. You may copy and distribute verbatim copies of the Program's
source code as you receive it, in any medium, provided that you
conspicuously and appropriately publish on each copy an appropriate
copyright notice and disclaimer of warranty; keep intact all the
notices that refer to this License and to the absence of any warranty;
and give any other recipients of the Program a copy of this License
along with the Program.
You may charge a fee for the physical act of transferring a copy, and
you may at your option offer warranty protection in exchange for a fee.
2. You may modify your copy or copies of the Program or any portion
of it, thus forming a work based on the Program, and copy and
distribute such modifications or work under the terms of Section 1
above, provided that you also meet all of these conditions:
a) You must cause the modified files to carry prominent notices
stating that you changed the files and the date of any change.
b) You must cause any work that you distribute or publish, that in
whole or in part contains or is derived from the Program or any
part thereof, to be licensed as a whole at no charge to all third
parties under the terms of this License.
c) If the modified program normally reads commands interactively
when run, you must cause it, when started running for such
interactive use in the most ordinary way, to print or display an
announcement including an appropriate copyright notice and a
notice that there is no warranty (or else, saying that you provide
a warranty) and that users may redistribute the program under
these conditions, and telling the user how to view a copy of this
License. (Exception: if the Program itself is interactive but
does not normally print such an announcement, your work based on
the Program is not required to print an announcement.)
These requirements apply to the modified work as a whole. If
identifiable sections of that work are not derived from the Program,
and can be reasonably considered independent and separate works in
themselves, then this License, and its terms, do not apply to those
sections when you distribute them as separate works. But when you
distribute the same sections as part of a whole which is a work based
on the Program, the distribution of the whole must be on the terms of
this License, whose permissions for other licensees extend to the
entire whole, and thus to each and every part regardless of who wrote it.
Thus, it is not the intent of this section to claim rights or contest
your rights to work written entirely by you; rather, the intent is to
exercise the right to control the distribution of derivative or
collective works based on the Program.
In addition, mere aggregation of another work not based on the Program
with the Program (or with a work based on the Program) on a volume of
a storage or distribution medium does not bring the other work under
the scope of this License.
3. You may copy and distribute the Program (or a work based on it,
under Section 2) in object code or executable form under the terms of
Sections 1 and 2 above provided that you also do one of the following:
a) Accompany it with the complete corresponding machine-readable
source code, which must be distributed under the terms of Sections
1 and 2 above on a medium customarily used for software interchange; or,
b) Accompany it with a written offer, valid for at least three
years, to give any third party, for a charge no more than your
cost of physically performing source distribution, a complete
machine-readable copy of the corresponding source code, to be
distributed under the terms of Sections 1 and 2 above on a medium
customarily used for software interchange; or,
c) Accompany it with the information you received as to the offer
to distribute corresponding source code. (This alternative is
allowed only for noncommercial distribution and only if you
received the program in object code or executable form with such
an offer, in accord with Subsection b above.)
The source code for a work means the preferred form of the work for
making modifications to it. For an executable work, complete source
code means all the source code for all modules it contains, plus any
associated interface definition files, plus the scripts used to
control compilation and installation of the executable. However, as a
special exception, the source code distributed need not include
anything that is normally distributed (in either source or binary
form) with the major components (compiler, kernel, and so on) of the
operating system on which the executable runs, unless that component
itself accompanies the executable.
If distribution of executable or object code is made by offering
access to copy from a designated place, then offering equivalent
access to copy the source code from the same place counts as
distribution of the source code, even though third parties are not
compelled to copy the source along with the object code.
4. You may not copy, modify, sublicense, or distribute the Program
except as expressly provided under this License. Any attempt
otherwise to copy, modify, sublicense or distribute the Program is
void, and will automatically terminate your rights under this License.
However, parties who have received copies, or rights, from you under
this License will not have their licenses terminated so long as such
parties remain in full compliance.
5. You are not required to accept this License, since you have not
signed it. However, nothing else grants you permission to modify or
distribute the Program or its derivative works. These actions are
prohibited by law if you do not accept this License. Therefore, by
modifying or distributing the Program (or any work based on the
Program), you indicate your acceptance of this License to do so, and
all its terms and conditions for copying, distributing or modifying
the Program or works based on it.
6. Each time you redistribute the Program (or any work based on the
Program), the recipient automatically receives a license from the
original licensor to copy, distribute or modify the Program subject to
these terms and conditions. You may not impose any further
restrictions on the recipients' exercise of the rights granted herein.
You are not responsible for enforcing compliance by third parties to
this License.
7. If, as a consequence of a court judgment or allegation of patent
infringement or for any other reason (not limited to patent issues),
conditions are imposed on you (whether by court order, agreement or
otherwise) that contradict the conditions of this License, they do not
excuse you from the conditions of this License. If you cannot
distribute so as to satisfy simultaneously your obligations under this
License and any other pertinent obligations, then as a consequence you
may not distribute the Program at all. For example, if a patent
license would not permit royalty-free redistribution of the Program by
all those who receive copies directly or indirectly through you, then
the only way you could satisfy both it and this License would be to
refrain entirely from distribution of the Program.
If any portion of this section is held invalid or unenforceable under
any particular circumstance, the balance of the section is intended to
apply and the section as a whole is intended to apply in other
circumstances.
It is not the purpose of this section to induce you to infringe any
patents or other property right claims or to contest validity of any
such claims; this section has the sole purpose of protecting the
integrity of the free software distribution system, which is
implemented by public license practices. Many people have made
generous contributions to the wide range of software distributed
through that system in reliance on consistent application of that
system; it is up to the author/donor to decide if he or she is willing
to distribute software through any other system and a licensee cannot
impose that choice.
This section is intended to make thoroughly clear what is believed to
be a consequence of the rest of this License.
8. If the distribution and/or use of the Program is restricted in
certain countries either by patents or by copyrighted interfaces, the
original copyright holder who places the Program under this License
may add an explicit geographical distribution limitation excluding
those countries, so that distribution is permitted only in or among
countries not thus excluded. In such case, this License incorporates
the limitation as if written in the body of this License.
9. The Free Software Foundation may publish revised and/or new versions
of the General Public License from time to time. Such new versions will
be similar in spirit to the present version, but may differ in detail to
address new problems or concerns.
Each version is given a distinguishing version number. If the Program
specifies a version number of this License which applies to it and "any
later version", you have the option of following the terms and conditions
either of that version or of any later version published by the Free
Software Foundation. If the Program does not specify a version number of
this License, you may choose any version ever published by the Free Software
Foundation.
10. If you wish to incorporate parts of the Program into other free
programs whose distribution conditions are different, write to the author
to ask for permission. For software which is copyrighted by the Free
Software Foundation, write to the Free Software Foundation; we sometimes
make exceptions for this. Our decision will be guided by the two goals
of preserving the free status of all derivatives of our free software and
of promoting the sharing and reuse of software generally.
NO WARRANTY
11. BECAUSE THE PROGRAM IS LICENSED FREE OF CHARGE, THERE IS NO WARRANTY
FOR THE PROGRAM, TO THE EXTENT PERMITTED BY APPLICABLE LAW. EXCEPT WHEN
OTHERWISE STATED IN WRITING THE COPYRIGHT HOLDERS AND/OR OTHER PARTIES
PROVIDE THE PROGRAM "AS IS" WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED
OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. THE ENTIRE RISK AS
TO THE QUALITY AND PERFORMANCE OF THE PROGRAM IS WITH YOU. SHOULD THE
PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF ALL NECESSARY SERVICING,
REPAIR OR CORRECTION.
12. IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING
WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MAY MODIFY AND/OR
REDISTRIBUTE THE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES,
INCLUDING ANY GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING
OUT OF THE USE OR INABILITY TO USE THE PROGRAM (INCLUDING BUT NOT LIMITED
TO LOSS OF DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY
YOU OR THIRD PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER
PROGRAMS), EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE
POSSIBILITY OF SUCH DAMAGES.
END OF TERMS AND CONDITIONS
How to Apply These Terms to Your New Programs
If you develop a new program, and you want it to be of the greatest
possible use to the public, the best way to achieve this is to make it
free software which everyone can redistribute and change under these terms.
To do so, attach the following notices to the program. It is safest
to attach them to the start of each source file to most effectively
convey the exclusion of warranty; and each file should have at least
the "copyright" line and a pointer to where the full notice is found.
<one line to give the program's name and a brief idea of what it does.>
Copyright (C) <year> <name of author>
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2 of the License, or
(at your option) any later version.
This program 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 General Public License for more details.
You should have received a copy of the GNU General Public License along
with this program; if not, write to the Free Software Foundation, Inc.,
51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
Also add information on how to contact you by electronic and paper mail.
If the program is interactive, make it output a short notice like this
when it starts in an interactive mode:
Gnomovision version 69, Copyright (C) year name of author
Gnomovision comes with ABSOLUTELY NO WARRANTY; for details type `show w'.
This is free software, and you are welcome to redistribute it
under certain conditions; type `show c' for details.
The hypothetical commands `show w' and `show c' should show the appropriate
parts of the General Public License. Of course, the commands you use may
be called something other than `show w' and `show c'; they could even be
mouse-clicks or menu items--whatever suits your program.
You should also get your employer (if you work as a programmer) or your
school, if any, to sign a "copyright disclaimer" for the program, if
necessary. Here is a sample; alter the names:
Yoyodyne, Inc., hereby disclaims all copyright interest in the program
`Gnomovision' (which makes passes at compilers) written by James Hacker.
<signature of Ty Coon>, 1 April 1989
Ty Coon, President of Vice
This General Public License does not permit incorporating your program into
proprietary programs. If your program is a subroutine library, you may
consider it more useful to permit linking proprietary applications with the
library. If this is what you want to do, use the GNU Lesser General
Public License instead of this License.
/**************************************************************************/
/* */
/* Copyright (c) 2001, 2007 NoMachine, http://www.nomachine.com/. */
/* */
/* NXCOMPEXT, NX protocol compression and NX extensions to this software */
/* are copyright of NoMachine. Redistribution and use of the present */
/* software is allowed according to terms specified in the file LICENSE */
/* which comes in the source distribution. */
/* */
/* Check http://www.nomachine.com/licensing.html for applicability. */
/* */
/* NX and NoMachine are trademarks of NoMachine S.r.l. */
/* */
/* All rigths reserved. */
/* */
/**************************************************************************/
#include <stdio.h>
#include <signal.h>
#include "os.h"
#include "NXlib.h"
#include "Clean.h"
#define PANIC
#define WARNING
#undef TEST
#undef DEBUG
int CleanXYImage(XImage *image)
{
int i, j, k, plane;
int bitsToClean = (image -> bytes_per_line << 3) - image -> width - image -> xoffset;
unsigned int bytesToClean = bitsToClean >> 3;
bitsToClean &= 7;
for (k = 0; k < image -> depth; k++)
{
plane = k * (image -> bytes_per_line * image -> height);
for (i = 1; i <= image -> height; i++)
{
if (image -> byte_order == image -> bitmap_bit_order)
{
for (j = 1; j <= bytesToClean; j++)
{
image -> data[plane + i * (image -> bytes_per_line) - j] = 0x00;
}
}
else
{
for (j = bytesToClean; j >= 1; j--)
{
image -> data[plane + i * (image -> bytes_per_line) - j] = 0x00;
}
}
if (image -> bitmap_bit_order == MSBFirst)
{
image -> data[plane + i * (image -> bytes_per_line) - j] &= 0xff << bitsToClean;
}
else
{
image -> data[plane + i * (image -> bytes_per_line) - j] &= 0xff >> bitsToClean;
}
}
}
return 1;
}
int CleanZImage(XImage *image)
{
unsigned int bytesToClean;
unsigned int j;
unsigned int imageLength;
#ifdef TEST
fprintf(stderr, "*****CleanZImage: Going to clean image of [%d] bits per pixel.\n",
image -> bits_per_pixel);
#endif
switch (image -> bits_per_pixel)
{
case 32:
{
/*
* The caller should pay attention at extracting
* the alpha channel prior to cleaning the image.
* Cleaning an image which is carrying the alpha
* channel will result in the image being treated
* as fully transparent.
*/
register int i;
bytesToClean = image -> bytes_per_line * image -> height;
#ifdef DEBUG
fprintf(stderr, "*****CleanZImage: Cleaning [%d] bytes with bits per pixel [%d] "
"width [%d] bytes per line [%d] height [%d].\n", bytesToClean,
image -> bits_per_pixel, image -> width, image ->
bytes_per_line, image -> height);
#endif
if (image -> byte_order == LSBFirst)
{
for (i = 3; i < bytesToClean; i += 4)
{
((unsigned char *) image -> data)[i] = 0x00;
}
}
else
{
for (i = 0; i < bytesToClean; i += 4)
{
((unsigned char *) image -> data)[i] = 0x00;
}
}
break;
}
case 24:
case 15:
case 16:
case 8:
{
register int i, j;
bytesToClean = image -> bytes_per_line -
((image -> width * image -> bits_per_pixel) >> 3);
for (i = 1; i <= image -> height; i++)
{
for (j = bytesToClean; j > 0; j--)
{
((unsigned char *) image -> data)[(i * image -> bytes_per_line) - j] = 0x00;
}
}
break;
}
default:
{
#ifdef PANIC
fprintf(stderr, "*****CleanZImage: PANIC! Cannot clean image with [%d] bits per pixel.\n",
image -> bits_per_pixel);
#endif
}
}
/*
* Clean the padding bytes at the real
* end of the buffer.
*/
imageLength = image -> bytes_per_line * image -> height;
bytesToClean = imageLength % 4;
for (j = 0; j < bytesToClean; j++)
{
((unsigned char *)image -> data)[(imageLength + j)] = 0x00;
}
return 1;
}
/*
* Copy a clean version of src_image into dst_image.
* This code is not taking care of the image format.
* The agent doesn't use it and you have to consider
* it unsupported.
*/
int CopyAndCleanImage(XImage *src_image, XImage *dst_image)
{
register long data_size;
register int i;
data_size = (src_image -> bytes_per_line * src_image -> height) >> 2;
#ifdef WARNING
fprintf(stderr, "******CleanImage: WARNING! Function called with image of [%d] bits per pixel.\n",
src_image -> bits_per_pixel);
#endif
switch (src_image -> bits_per_pixel)
{
case 32:
{
unsigned int mask;
if (src_image -> byte_order == MSBFirst)
{
mask = 0xffffff00;
}
else
{
mask = 0x00ffffff;
}
for (i = 0; i < data_size; i++)
{
((unsigned int *)dst_image -> data)[i] = ((unsigned int *)src_image -> data)[i] & mask;
}
break;
}
case 24:
{
unsigned int bytes_to_clean;
for (i = 0; i < data_size; i++)
{
((unsigned int *)dst_image -> data)[i] = ((unsigned int *)src_image -> data)[i];
}
bytes_to_clean = dst_image -> bytes_per_line - ((dst_image -> width *
dst_image -> bits_per_pixel) >> 3);
if (bytes_to_clean)
{
register unsigned int mask = 0xffffffff;
register int line_size;
register int i;
line_size = dst_image -> bytes_per_line >> 2;
if (dst_image -> byte_order == MSBFirst)
{
mask = mask << (bytes_to_clean << 3);
}
else
{
mask = mask >> (bytes_to_clean << 3);
}
for (i = 0; i < dst_image -> height;)
{
((unsigned char *)dst_image -> data)[(++i * line_size) -1] &= mask;
}
}
break;
}
case 15:
case 16:
{
for (i = 0; i < data_size; i++)
{
((unsigned int *) dst_image -> data)[i] = ((unsigned int *) src_image -> data)[i];
}
if (src_image -> width & 0x00000001)
{
int card32_per_line = dst_image -> bytes_per_line >> 2;
for (i = 0; i < dst_image -> height;)
{
((unsigned int *) dst_image -> data)[(++i * card32_per_line) -1] &= 0x0000ffff;
}
}
break;
}
case 8:
{
unsigned int mask = 0x00000000;
switch (dst_image -> width % 4)
{
case 3:
{
mask = 0x00ffffff;
break;
}
case 2:
{
mask = 0x0000ffff;
break;
}
case 1:
{
mask = 0x000000ff;
break;
}
default:
{
/*
* Nothing to clean.
*/
break;
}
}
for (i = 0; i < data_size; i++)
{
((unsigned int *) dst_image -> data)[i] = ((unsigned int *) src_image -> data)[i];
}
if (mask)
{
int card32_per_line;
int i;
card32_per_line = dst_image -> bytes_per_line >> 2;
for (i = 0; i < dst_image -> height; i++)
{
((unsigned int *) dst_image -> data)[(++i * card32_per_line) -1] &= mask;
}
}
break;
}
default:
{
#ifdef PANIC
fprintf(stderr, "******CleanImage: PANIC! Cannot clean image of [%d] bits per pixel.\n",
src_image -> bits_per_pixel);
#endif
return 0;
}
}
return 1;
}
/**************************************************************************/
/* */
/* Copyright (c) 2001, 2007 NoMachine, http://www.nomachine.com/. */
/* */
/* NXCOMPEXT, NX protocol compression and NX extensions to this software */
/* are copyright of NoMachine. Redistribution and use of the present */
/* software is allowed according to terms specified in the file LICENSE */
/* which comes in the source distribution. */
/* */
/* Check http://www.nomachine.com/licensing.html for applicability. */
/* */
/* NX and NoMachine are trademarks of NoMachine S.r.l. */
/* */
/* All rigths reserved. */
/* */
/**************************************************************************/
#ifndef Clean_H
#define Clean_H
#ifdef __cplusplus
extern "C" {
#endif
#include "Xlib.h"
int CleanXYImage(XImage *image);
int CleanZImage(XImage *image);
int CopyAndCleanImage(XImage *src_image, XImage *dst_image);
#ifdef __cplusplus
}
#endif
#endif /* Clean_H */
/**************************************************************************/
/* */
/* Copyright (c) 2001, 2007 NoMachine, http://www.nomachine.com/. */
/* */
/* NXCOMPEXT, NX protocol compression and NX extensions to this software */
/* are copyright of NoMachine. Redistribution and use of the present */
/* software is allowed according to terms specified in the file LICENSE */
/* which comes in the source distribution. */
/* */
/* Check http://www.nomachine.com/licensing.html for applicability. */
/* */
/* NX and NoMachine are trademarks of NoMachine S.r.l. */
/* */
/* All rigths reserved. */
/* */
/**************************************************************************/
#include <zlib.h>
#include "NXlib.h"
#include "Colormap.h"
#include "Z.h"
#define PANIC
#define WARNING
#undef TEST
#undef DEBUG
#define COLORMAP_COMPRESSION_LEVEL 4
#define COLORMAP_COMPRESSION_THRESHOLD 32
#define COLORMAP_COMPRESSION_STRATEGY Z_DEFAULT_STRATEGY
static int colormapCompressionLevel = COLORMAP_COMPRESSION_LEVEL;
static int colormapCompressionThreshold = COLORMAP_COMPRESSION_THRESHOLD;
static int colormapCompressionStrategy = COLORMAP_COMPRESSION_STRATEGY;
char *ColormapCompressData(const char *data, unsigned int size, unsigned int *compressed_size)
{
return ZCompressData(data, size, colormapCompressionThreshold, colormapCompressionLevel,
colormapCompressionStrategy, compressed_size);
}
/**************************************************************************/
/* */
/* Copyright (c) 2001, 2007 NoMachine, http://www.nomachine.com/. */
/* */
/* NXCOMPEXT, NX protocol compression and NX extensions to this software */
/* are copyright of NoMachine. Redistribution and use of the present */
/* software is allowed according to terms specified in the file LICENSE */
/* which comes in the source distribution. */
/* */
/* Check http://www.nomachine.com/licensing.html for applicability. */
/* */
/* NX and NoMachine are trademarks of NoMachine S.r.l. */
/* */
/* All rigths reserved. */
/* */
/**************************************************************************/
#ifndef Colormap_H
#define Colormap_H
#ifdef __cplusplus
extern "C" {
#endif
extern char *ColormapCompressData(
#if NeedFunctionPrototypes
const char* /* data */,
unsigned int /* size */,
unsigned int* /* compressed_size */
#endif
);
#ifdef __cplusplus
}
#endif
#endif /* Colormap_H */
/**************************************************************************/
/* */
/* Copyright (c) 2001, 2007 NoMachine, http://www.nomachine.com/. */
/* */
/* NXCOMPEXT, NX protocol compression and NX extensions to this software */
/* are copyright of NoMachine. Redistribution and use of the present */
/* software is allowed according to terms specified in the file LICENSE */
/* which comes in the source distribution. */
/* */
/* Check http://www.nomachine.com/licensing.html for applicability. */
/* */
/* NX and NoMachine are trademarks of NoMachine S.r.l. */
/* */
/* All rigths reserved. */
/* */
/**************************************************************************/
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include "X11/X.h"
#include "X11/Xlib.h"
#include "X11/Xmd.h"
#include <jpeglib.h>
#include "NXlib.h"
#include "Mask.h"
#include "Jpeg.h"
#define PANIC
#define WARNING
#undef TEST
#undef DEBUG
#define JPEG_DEST_SIZE(width, height) ((width) * 3 * (height) + 1024)
/*
* Local function prototypes.
*/
static void PrepareRowForJpeg(CARD8 *dst, int y, int count);
static void PrepareRowForJpeg24(CARD8 *dst, int y, int count);
static void PrepareRowForJpeg16(CARD8 *dst, int y, int count);
static void PrepareRowForJpeg32(CARD8 *dst, int y, int count);
static int JpegEmptyOutputBuffer(j_compress_ptr cinfo);
static void JpegInitDestination(j_compress_ptr cinfo);
static void JpegTermDestination(j_compress_ptr cinfo);
static void JpegSetDstManager(j_compress_ptr cinfo);
/*
* Quality levels.
*/
static int jpegQuality[10] = {20, 30, 40, 50, 55, 60, 65, 70, 75, 80};
/*
* Image characteristics.
*/
static int bytesPerLine;
static CARD8 bitsPerPixel;
static CARD16 redMax, greenMax, blueMax;
static CARD8 redShift, greenShift, blueShift;
static int byteOrder;
/*
* Other variables used for the Jpeg
* encoding.
*/
static char *jpegBeforeBuf = NULL;
static char *jpegCompBuf;
static int jpegCompBufSize;
static int jpegError;
static int jpegDstDataLen;
static struct jpeg_destination_mgr jpegDstManager;
/*
* Just for debugging purpose.
*/
#ifdef DEBUG
static int jpegId;
static char jpegName[10];
static FILE *jpegFile;
#endif
/*
* Function declarations
*/
char *JpegCompressData(XImage *image, int level, int *compressed_size)
{
struct jpeg_compress_struct cinfo;
struct jpeg_error_mgr jerr;
CARD8 *srcBuf;
JSAMPROW rowPointer[1];
int dy, w, h;
*compressed_size = 0;
/*
* Initialize the image stuff
*/
bitsPerPixel = image -> bits_per_pixel;
bytesPerLine = image -> bytes_per_line;
byteOrder = image -> byte_order;
#ifdef TEST
fprintf(stderr, "******JpegCompressData: Image byte order [%d] bitmap bit order [%d].\n",
image -> byte_order, image -> bitmap_bit_order);
fprintf(stderr, "******JpegCompressData: Bits per pixel [%d] bytes per line [%d].\n",
bitsPerPixel, bytesPerLine);
#endif
redShift = FindLSB(image -> red_mask) - 1;
greenShift = FindLSB(image -> green_mask) - 1;
blueShift = FindLSB(image -> blue_mask) - 1;
#ifdef TEST
fprintf(stderr, "******JpegCompressData: Red mask [0x%lx] green mask [0x%lx] blue mask [0x%lx].\n",
image -> red_mask, image -> green_mask, image -> blue_mask);
fprintf(stderr, "******JpegCompressData: Red shift [%d] green shift [%d] blue shift [%d].\n",
redShift, greenShift, blueShift);
#endif
redMax = image -> red_mask >> redShift;
greenMax = image -> green_mask >> greenShift;
blueMax = image -> blue_mask >> blueShift;
#ifdef TEST
fprintf(stderr, "******JpegCompressData: Red max [0x%x] green max [0x%x] blue max [0x%x].\n",
redMax, greenMax, blueMax);
#endif
w = image -> width;
h = image -> height;
jpegBeforeBuf = image -> data;
#ifdef DEBUG
fprintf(stderr, "******JpegCompressData: Width [%d] height [%d] level [%d].\n",
w, h, level);
#endif
if (bitsPerPixel == 1 ||
bitsPerPixel == 8)
{
#ifdef PANIC
fprintf(stderr, "******JpegCompressData: PANIC! Invalid bits per pixel [%d].\n",
bitsPerPixel);
#endif
return NULL;
}
/*
* Allocate space for one line of the
* resulting image, 3 bytes per pixel.
*/
#ifdef DEBUG
fprintf(stderr, "******JpegCompressData: Allocating [%d] bytes for the scanline.\n",
w * 3);
#endif
srcBuf = (CARD8 *) malloc(w * 3);
if (srcBuf == NULL)
{
#ifdef PANIC
fprintf(stderr, "******JpegCompressData: PANIC! Cannot allocate [%d] bytes.\n",
w * 3);
#endif
return NULL;
}
rowPointer[0] = srcBuf;
cinfo.err = jpeg_std_error(&jerr);
jpeg_create_compress(&cinfo);
cinfo.image_width = w;
cinfo.image_height = h;
cinfo.input_components = 3;
cinfo.in_color_space = JCS_RGB;
jpeg_set_defaults(&cinfo);
jpeg_set_quality(&cinfo, jpegQuality[level], 1);
/*
* Allocate memory for the destination
* buffer.
*/
jpegCompBufSize = JPEG_DEST_SIZE(w, h);
#ifdef TEST
fprintf(stderr, "******JpegCompressData: Allocating [%d] bytes for the destination data.\n",
jpegCompBufSize);
#endif
jpegCompBuf = malloc(jpegCompBufSize);
if (jpegCompBuf == NULL)
{
#ifdef PANIC
fprintf(stderr, "******JpegCompressData: PANIC! Error allocating [%d] bytes for the Jpeg data.\n",
jpegCompBufSize);
#endif
return NULL;
}
JpegSetDstManager(&cinfo);
jpeg_start_compress(&cinfo, 1);
#ifdef DEBUG
fprintf(stderr, "******JpegCompressedData: Initialization finished.\n");
#endif
for (dy = 0; dy < h; dy++)
{
PrepareRowForJpeg(srcBuf, dy, w);
jpeg_write_scanlines(&cinfo, rowPointer, 1);
if (jpegError != 0)
{
break;
}
}
#ifdef DEBUG
fprintf(stderr, "******JpegCompressedData: Compression finished. Lines handled [%d,%d]. Error is [%d].\n",
dy, h, jpegError);
#endif
if (jpegError == 0)
{
jpeg_finish_compress(&cinfo);
}
jpeg_destroy_compress(&cinfo);
free((char *) srcBuf);
if (jpegError != 0)
{
#ifdef PANIC
fprintf(stderr, "******JpegCompressedData: PANIC! Compression failed. Error is [%d].\n",
jpegError);
#endif
free(jpegCompBuf);
return NULL;
}
/*
* Check the size of the resulting data.
*/
if (jpegDstDataLen > 0)
{
/*
* Save the image on disk to help with
* the debug.
*/
#ifdef DEBUG
int i = 0;
fprintf(stderr, "******JpegCompressedData: Compressed size [%d].\n",
jpegDstDataLen);
jpegId++;
sprintf(jpegName, "jpeg%d", jpegId);
jpegFile = fopen(jpegName, "w");
for (i = 0; i < jpegDstDataLen; i++)
{
fprintf(jpegFile, "%c", *(jpegCompBuf + i));
}
fclose(jpegFile);
#endif
*compressed_size = jpegDstDataLen;
return jpegCompBuf;
}
else
{
#ifdef PANIC
fprintf(stderr, "******JpegCompressedData: PANIC! Invalid size of the compressed data [%d].\n",
jpegDstDataLen);
#endif
free(jpegCompBuf);
return NULL;
}
}
void PrepareRowForJpeg(CARD8 *dst, int y, int count)
{
if (bitsPerPixel == 32)
{
if (redMax == 0xff &&
greenMax == 0xff &&
blueMax == 0xff)
{
PrepareRowForJpeg24(dst, y, count);
}
else
{
PrepareRowForJpeg32(dst, y, count);
}
}
else if (bitsPerPixel == 24)
{
memcpy(dst, jpegBeforeBuf + y * bytesPerLine, count * 3);
}
else
{
/*
* 16 bpp assumed.
*/
PrepareRowForJpeg16(dst, y, count);
}
}
void PrepareRowForJpeg24(CARD8 *dst, int y, int count)
{
CARD8 *fbptr;
CARD32 pix;
fbptr = (CARD8 *) (jpegBeforeBuf + y * bytesPerLine);
while (count--)
{
if (byteOrder == LSBFirst)
{
pix = (CARD32) *(fbptr + 2);
pix = (pix << 8) | (CARD32) *(fbptr+1);
pix = (pix << 8) | (CARD32) *fbptr;
}
else
{
pix = (CARD32) *(fbptr + 1);
pix = (pix << 8) | (CARD32) *(fbptr + 2);
pix = (pix << 8) | (CARD32) *(fbptr + 3);
}
*dst++ = (CARD8)(pix >> redShift);
*dst++ = (CARD8)(pix >> greenShift);
*dst++ = (CARD8)(pix >> blueShift);
fbptr+=4;
}
}
#define DEFINE_JPEG_GET_ROW_FUNCTION(bpp) \
\
void PrepareRowForJpeg##bpp(CARD8 *dst, int y, int count) \
{ \
CARD8 *fbptr; \
CARD##bpp pix; \
int inRed, inGreen, inBlue; \
int i; \
\
fbptr = (CARD8 *) (jpegBeforeBuf + y * bytesPerLine); \
\
while (count--) \
{ \
pix = 0; \
\
if (byteOrder == LSBFirst) \
{ \
for (i = (bpp >> 3) - 1; i >= 0; i--) \
{ \
pix = (pix << 8) | (CARD32) *(fbptr + i); \
} \
} \
else \
{ \
for (i = 0; i < (bpp >> 3); i++) \
{ \
pix = (pix << 8) | (CARD32) *(fbptr + i); \
} \
} \
\
fbptr += bpp >> 3; \
\
inRed = (int) \
(pix >> redShift & redMax); \
inGreen = (int) \
(pix >> greenShift & greenMax); \
inBlue = (int) \
(pix >> blueShift & blueMax); \
\
*dst++ = (CARD8)((inRed * 255 + redMax / 2) / \
redMax); \
*dst++ = (CARD8)((inGreen * 255 + greenMax / 2) / \
greenMax); \
*dst++ = (CARD8)((inBlue * 255 + blueMax / 2) / \
blueMax); \
} \
}
DEFINE_JPEG_GET_ROW_FUNCTION(16)
DEFINE_JPEG_GET_ROW_FUNCTION(32)
/*
* Destination manager implementation for JPEG library.
*/
void JpegInitDestination(j_compress_ptr cinfo)
{
jpegError = 0;
jpegDstManager.next_output_byte = (JOCTET *) jpegCompBuf;
jpegDstManager.free_in_buffer = (size_t) jpegCompBufSize;
}
int JpegEmptyOutputBuffer(j_compress_ptr cinfo)
{
jpegError = 1;
jpegDstManager.next_output_byte = (JOCTET *) jpegCompBuf;
jpegDstManager.free_in_buffer = (size_t) jpegCompBufSize;
return 1;
}
void JpegTermDestination(j_compress_ptr cinfo)
{
jpegDstDataLen = jpegCompBufSize - jpegDstManager.free_in_buffer;
}
void JpegSetDstManager(j_compress_ptr cinfo)
{
jpegDstManager.init_destination = JpegInitDestination;
jpegDstManager.empty_output_buffer = JpegEmptyOutputBuffer;
jpegDstManager.term_destination = JpegTermDestination;
cinfo -> dest = &jpegDstManager;
}
/**************************************************************************/
/* */
/* Copyright (c) 2001, 2007 NoMachine, http://www.nomachine.com/. */
/* */
/* NXCOMPEXT, NX protocol compression and NX extensions to this software */
/* are copyright of NoMachine. Redistribution and use of the present */
/* software is allowed according to terms specified in the file LICENSE */
/* which comes in the source distribution. */
/* */
/* Check http://www.nomachine.com/licensing.html for applicability. */
/* */
/* NX and NoMachine are trademarks of NoMachine S.r.l. */
/* */
/* All rigths reserved. */
/* */
/**************************************************************************/
#ifndef Jpeg_H
#define Jpeg_H
#ifdef __cplusplus
extern "C" {
#endif
extern char *JpegCompressData(
#if NeedFunctionPrototypes
XImage* /* image */,
int /* level */,
int* /* compressed_size */
#endif
);
#ifdef __cplusplus
}
#endif
#endif /* Jpeg_H */
Copyright (C) 2001, 2007 NoMachine - http://www.nomachine.com/.
NXCOMPEXT library and NX extensions to X are copyright of NoMachine.
Redistribution and use of this software is allowed according to the
following terms:
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License Version 2, and
not any other version, as published by the Free Software Foundation.
This program is distributed in the hope that it will be useful, but
WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTA-
BILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General
Public License for more details.
You should have received a copy of the GNU General Public License
along with this program; if not, you can request a copy to NoMachine
or write to the Free Software Foundation, Inc., 59 Temple Place,
Suite 330, Boston, MA 02111-1307 USA
All rights reserved.
############################################################################
# #
# Copyright (c) 2001, 2007 NoMachine, http://www.nomachine.com. #
# #
# NXCOMPEXT, NX protocol compression and NX extensions to this software #
# are copyright of NoMachine. Redistribution and use of the present #
# software is allowed according to terms specified in the file LICENSE #
# which comes in the source distribution. #
# #
# Check http://www.nomachine.com/licensing.html for applicability. #
# #
# NX and NoMachine are trademarks of NoMachine S.r.l. #
# #
# All rights reserved. #
# #
############################################################################
#
# Get values from configure script.
#
VERSION=@VERSION@
LIBVERSION=@LIBVERSION@
#
# We want to enable really all warnings. -Wredundant-decls,
# though, gives a warning caused by pthread.h and unistd.h.
#
CXX = @CXX@
CXXFLAGS = @CXXFLAGS@ @X_CFLAGS@ @DEFS@ \
-Wall -Wpointer-arith -Wstrict-prototypes -Wmissing-prototypes \
-Wmissing-declarations -Wnested-externs
CXXINCLUDES = -I. -I../nxcomp
CXXDEFINES =
CC = @CC@
CCFLAGS = @CFLAGS@ @X_CFLAGS@ @DEFS@ \
-Wall -Wpointer-arith -Wstrict-prototypes -Wmissing-prototypes \
-Wmissing-declarations -Wnested-externs
CCINCLUDES = -I. -I../nxcomp
CCDEFINES =
LDFLAGS = @LDFLAGS@ -L../nxcomp
LIBS = @LIBS@ -lz -lX11 -lXcomp
#
# Only if THREADS is defined
#
# LIBS = @LIBS@ -lz -ljpeg -lpthread -lX11 -lXcomp
#
srcdir = @srcdir@
prefix = @prefix@
exec_prefix = @exec_prefix@
bindir = @bindir@
man1dir = @mandir@/man1
VPATH = @srcdir@
INSTALL = @INSTALL@
INSTALL_PROGRAM = @INSTALL_PROGRAM@
INSTALL_DATA = @INSTALL_DATA@
#
# This should be autodetected.
#
MAKEDEPEND = @MAKEDEPEND@
DEPENDINCLUDES = -I/usr/include/c++ -I/usr/include/g++ -I/usr/include/g++-3
.SUFFIXES: .cpp.c
.cpp.o:
$(CXX) -c $(CXXFLAGS) $(CXXINCLUDES) $<
.c.o:
$(CC) -c $(CCFLAGS) $(CCINCLUDES) $<
LIBRARY = Xcompext
LIBNAME = lib$(LIBRARY)
LIBFULL = lib$(LIBRARY).so.$(VERSION)
LIBLOAD = lib$(LIBRARY).so.$(LIBVERSION)
LIBSHARED = lib$(LIBRARY).so
LIBARCHIVE = lib$(LIBRARY).a
LIBCYGSHARED = cyg$(LIBRARY).dll
LIBCYGARCHIVE = lib$(LIBRARY).dll.a
all: depend @ALL@
MSRC=
CSRC= NXlib.c \
Clean.c \
Mask.c \
Colormap.c \
Alpha.c \
Jpeg.c \
Pgn.c \
Bitmap.c \
Rgb.c \
Rle.c \
Z.c
CXXSRC=
MOBJ = $(MSRC:.c=.o)
COBJ = $(CSRC:.c=.o)
CXXOBJ = $(CXXSRC:.cpp=.o)
$(LIBFULL): $(CXXOBJ) $(COBJ)
$(CXX) -o $@ $(LDFLAGS) $(CXXOBJ) $(COBJ) $(LIBS)
$(LIBLOAD): $(LIBFULL)
rm -f $(LIBLOAD)
ln -s $(LIBFULL) $(LIBLOAD)
$(LIBSHARED): $(LIBFULL)
rm -f $(LIBSHARED)
ln -s $(LIBFULL) $(LIBSHARED)
$(LIBARCHIVE): $(CXXOBJ) $(COBJ)
rm -f $(LIBARCHIVE)
ar clq $(LIBARCHIVE) $(CXXOBJ) $(COBJ)
ranlib $(LIBARCHIVE)
$(LIBCYGSHARED): $(LIBARCHIVE)
$(CC) -shared -o $(LIBCYGSHARED) \
-Wl,--out-implib=$(LIBCYGARCHIVE) \
-Wl,--export-all-symbols \
-Wl,--enable-auto-import \
-Wl,--whole-archive $(LIBARCHIVE) \
-Wl,--no-whole-archive $(LIBS) \
$(LDFLAGS)
$(LIBCYGARCHIVE): $(LIBCYGSHARED)
depends: depend.status
depend: depend.status
depend.status:
if [ -x $(MAKEDEPEND) ] ; then \
$(MAKEDEPEND) $(CXXINCLUDES) $(CCINCLUDES) \
$(DEPENDINCLUDES) -f Makefile $(MSRC) $(CSRC) \
$(CXXSRC) 2>/dev/null; \
fi
touch depend.status
install: install.bin install.man
install.bin:
install.man:
clean:
-rm -f *~ *.o *.bak *.orig *.rej st?????? core core.* *.out.* \
@ALL@
distclean: clean
-rm -rf autom4te.cache config.status config.log \
config.cache depend.status Makefile tags
/**************************************************************************/
/* */
/* Copyright (c) 2001, 2007 NoMachine, http://www.nomachine.com/. */
/* */
/* NXCOMPEXT, NX protocol compression and NX extensions to this software */
/* are copyright of NoMachine. Redistribution and use of the present */
/* software is allowed according to terms specified in the file LICENSE */
/* which comes in the source distribution. */
/* */
/* Check http://www.nomachine.com/licensing.html for applicability. */
/* */
/* NX and NoMachine are trademarks of NoMachine S.r.l. */
/* */
/* All rigths reserved. */
/* */
/**************************************************************************/
#include <stdio.h>
#include "Xlib.h"
#include "NXpack.h"
#include "Mask.h"
#define PANIC
#define WARNING
#undef TEST
#undef DEBUG
/*
* Try first to reduce to a white or black
* pixel. If not possible, apply the mask.
* Note that correction is applied at the
* time pixel is unpacked.
*/
#define MaskPixel(red, green, blue, mask) \
\
if (red > mask -> white_threshold && \
green > mask -> white_threshold && \
blue > mask -> white_threshold) \
{ \
red = green = blue = 0xff; \
} \
else if (red < mask -> black_threshold && \
green < mask -> black_threshold && \
blue < mask -> black_threshold) \
{ \
red = green = blue = 0x00; \
} \
else \
{ \
red = red & mask -> color_mask; \
green = green & mask -> color_mask; \
blue = blue & mask -> color_mask; \
}
int MaskImage(const ColorMask *mask, XImage *src_image, XImage *dst_image)
{
unsigned long pixel;
register unsigned int red;
register unsigned int green;
register unsigned int blue;
register unsigned long data_size;
register unsigned int i;
data_size = (src_image -> bytes_per_line * src_image -> height) >> 2;
#ifdef TEST
fprintf(stderr, "******MaskImage: Going to mask image with [%d] bits per pixel.\n",
src_image -> bits_per_pixel);
#endif
if (src_image -> bits_per_pixel == 24 || src_image -> bits_per_pixel == 32)
{
register unsigned char *pixel_addr;
for (i = 0; i < data_size; i++)
{
pixel = ((unsigned long *) src_image -> data)[i];
pixel_addr = (unsigned char *) &pixel;
red = pixel_addr[2];
green = pixel_addr[1];
blue = pixel_addr[0];
#ifdef DEBUG
fprintf(stderr, "******MaskImage: 24/32 bits original R [%d] G [%d] B [%d] A [%d].\n",
red, green, blue, pixel_addr[3]);
#endif
MaskPixel(red, green, blue, mask);
#ifdef DEBUG
fprintf(stderr, "******MaskImage: 24/32 bits masked R [%d] G [%d] B [%d] A [%d].\n",
red, green, blue, pixel_addr[3]);
#endif
#ifdef DEBUG
fprintf(stderr, "******MaskImage: 24/32 bits pixel 0x%lx", pixel);
#endif
pixel_addr[2] = red;
pixel_addr[1] = green;
pixel_addr[0] = blue;
((unsigned long*)dst_image -> data)[i] = pixel;
#ifdef DEBUG
fprintf(stderr, " -> 0x%lx\n", pixel);
#endif
}
return 1;
}
else if (src_image -> bits_per_pixel == 16)
{
/*
* FIXME: Masking doesn't work in 16 bpp.
*
unsigned long src_addr, *dst_addr;
unsigned short *src_pixels_addr, *dst_pixels_addr;
for (i = 0; i < data_size; i++)
{
src_addr = ((unsigned long *)src_image -> data)[i];
dst_addr = (unsigned long *)((unsigned long *)dst_image -> data + i);
src_pixels_addr = ((unsigned short *) &src_addr);
dst_pixels_addr = ((unsigned short *) dst_addr);
red = (src_pixels_addr[0] & src_image -> red_mask) >> 8;
green = (src_pixels_addr[0] & src_image -> green_mask) >> 3;
blue = (src_pixels_addr[0] & src_image -> blue_mask) << 3;
#ifdef DEBUG
fprintf(stderr, "******MaskImage: 16 bits original R [%d] G [%d] B [%d].\n",
red, green, blue);
#endif
MaskPixel(red, green, blue, mask);
#ifdef DEBUG
fprintf(stderr, "******MaskImage: 16 bits masked R [%d] G [%d] B [%d].\n",
red, green, blue);
#endif
dst_pixels_addr[0] = ((red << 8) & src_image -> red_mask) |
((green << 3) & src_image -> green_mask) |
((blue >> 3) & src_image -> blue_mask);
#ifdef DEBUG
fprintf(stderr, "******MaskImage: 16 bits pixel 0x%x", dst_pixels_addr[0]);
#endif
red = (src_pixels_addr[1] & src_image -> red_mask) >> 8;
green = (src_pixels_addr[1] & src_image -> green_mask) >> 3;
blue = (src_pixels_addr[1] & src_image -> blue_mask) << 3;
#ifdef DEBUG
fprintf(stderr, "******MaskImage: 16 bits original R [%d] G [%d] B [%d].\n",
red, green, blue);
#endif
MaskPixel(red, green, blue, mask);
#ifdef DEBUG
fprintf(stderr, "******MaskImage: 16 bits masked R [%d] G [%d] B [%d].\n",
red, green, blue);
#endif
dst_pixels_addr[1] = ((red << 8) & src_image -> red_mask) |
((green << 3) & src_image -> green_mask) |
((blue >> 3) & src_image -> blue_mask);
#ifdef DEBUG
fprintf(stderr, "******MaskImage: 16 bits pixel 0x%x", dst_pixels_addr[0]);
#endif
}
if (dst_image -> width & 0x00000001)
{
int card32_per_line;
int i;
card32_per_line = dst_image -> bytes_per_line >> 2;
for (i = 0; i < dst_image -> height;)
{
((CARD32 *) dst_image -> data)[(++i * card32_per_line) - 1] &= 0x0000ffff;
}
}
*
* End of FIXME.
*/
}
else
{
#ifdef TEST
fprintf(stderr, "******MaskImage: PANIC! Cannot apply mask with [%d] bits per pixel.\n",
src_image -> bits_per_pixel);
#endif
return 0;
}
return 1;
}
int MaskInPlaceImage(const ColorMask *mask, XImage *image)
{
unsigned long pixel;
register unsigned int red;
register unsigned int green;
register unsigned int blue;
register unsigned int i;
register unsigned long data_size;
data_size = (image -> bytes_per_line * image -> height)>>2;
#ifdef TEST
fprintf(stderr, "******MaskInPlaceImage: Going to mask image with [%d] bits per pixel.\n",
image -> bits_per_pixel);
#endif
if (image -> bits_per_pixel == 24 || image -> bits_per_pixel == 32)
{
register unsigned char *pixel_addr;
for (i = 0; i < data_size; i++)
{
pixel = ((unsigned long *) image -> data)[i];
pixel_addr = (unsigned char *) &pixel;
red = pixel_addr[2];
green = pixel_addr[1];
blue = pixel_addr[0];
#ifdef DEBUG
fprintf(stderr, "******MaskInPlaceImage: 24/32 bits original R [%d] G [%d] B [%d] A [%d].\n",
red, green, blue, pixel_addr[3]);
#endif
MaskPixel(red, green, blue, mask);
#ifdef DEBUG
fprintf(stderr, "******MaskInPlaceImage: 24/32 bits masked R [%d] G [%d] B [%d] A [%d].\n",
red, green, blue, pixel_addr[3]);
#endif
#ifdef DEBUG
fprintf(stderr, "******MaskInPlaceImage: 24/32 bits pixel 0x%lx", pixel);
#endif
pixel_addr[2] = red;
pixel_addr[1] = green;
pixel_addr[0] = blue;
((unsigned long *) image -> data)[i] = pixel;
#ifdef DEBUG
fprintf(stderr, " -> 0x%lx\n", pixel);
#endif
}
return 1;
}
else if (image -> bits_per_pixel == 16)
{
/*
* FIXME: Mask doesn't still work for 16 bits.
*
unsigned long addr;
register unsigned short *pixels_addr;
for (i = 0; i < data_size; i++)
{
addr = ((unsigned long *) image -> data)[i];
pixels_addr = ((unsigned short *) &addr);
red = (pixels_addr[0] & image -> red_mask) >> 8;
green = (pixels_addr[0] & image -> green_mask) >> 3;
blue = (pixels_addr[0] & image -> blue_mask) << 3;
#ifdef DEBUG
fprintf(stderr, "******MaskInPlaceImage: 16 bits original R [%d] G [%d] B [%d].\n",
red, green, blue);
#endif
MaskPixel(red, green, blue, mask);
#ifdef DEBUG
fprintf(stderr, "******MaskInPlaceImage: 16 bits masked R [%d] G [%d] B [%d].\n",
red, green, blue);
#endif
pixels_addr[0] = ((red << 8) & image -> red_mask) |
((green << 3) & image -> green_mask) |
((blue >> 3) & image -> blue_mask);
#ifdef DEBUG
fprintf(stderr, "******MaskInPlaceImage: 16 bits pixel 0x%x", pixels_addr[0]);
#endif
red = (pixels_addr[1] & image -> red_mask) >> 8;
green = (pixels_addr[1] & image -> green_mask) >> 3;
blue = (pixels_addr[1] & image -> blue_mask) << 3;
#ifdef DEBUG
fprintf(stderr, "******MaskInPlaceImage: 16 bits original R [%d] G [%d] B [%d].\n",
red, green, blue);
#endif
MaskPixel(red, green, blue, mask);
#ifdef DEBUG
fprintf(stderr, "******MaskInPlaceImage: 16 bits masked R [%d] G [%d] B [%d].\n",
red, green, blue);
#endif
pixels_addr[1] = ((red << 8) & image -> red_mask) |
((green << 3) & image -> green_mask) |
((blue >> 3) & image -> blue_mask);
#ifdef DEBUG
fprintf(stderr, "******MaskInPlaceImage: 16 bits pixel 0x%x", pixels_addr[1]);
#endif
}
if (image -> width & 0x00000001)
{
int card32_per_line;
int i;
card32_per_line = image -> bytes_per_line >> 2;
for (i = 0; i < image -> height;)
{
((CARD32 *) image -> data)[(++i * card32_per_line) - 1] &= 0x0000ffff;
}
}
*
* End of FIXME.
*/
}
else
{
#ifdef TEST
fprintf(stderr, "******MaskImage: PANIC! Cannot apply mask with [%d] bits per pixel.\n",
image -> bits_per_pixel);
#endif
return 0;
}
return 1;
}
static int Pack16To8(unsigned int src_data_size, XImage *src_image, XImage *dst_image)
{
unsigned short *src_pixel = (unsigned short *) src_image -> data;
unsigned char *dst_pixel = (unsigned char *) dst_image -> data;
#ifdef DEBUG
unsigned int counter = 0;
#endif
while (src_pixel < ((unsigned short *) (src_image -> data + src_data_size)))
{
#ifdef DEBUG
fprintf(stderr, "******PackImage: Pixel [%d] value [0x%x] red [0x%x] green [0x%x] blue [0x%x].\n",
counter, *src_pixel, (*src_pixel & 0xc000) >> 8,
((*src_pixel & 0x600) >> 3), (*src_pixel & 0x18) << 3);
#endif
if (*src_pixel == 0x0)
{
*dst_pixel = 0x0;
}
else if (*src_pixel == 0xffff)
{
*dst_pixel = 0xff;
}
else
{
*dst_pixel = ((*src_pixel & 0xc000) >> 10) |
((*src_pixel & 0x600) >> 7) |
((*src_pixel & 0x18) >> 3);
}
#ifdef DEBUG
fprintf(stderr, "******PackImage: Pixel [%d] destination [0x%x].\n",
counter++, *dst_pixel);
#endif
src_pixel++;
dst_pixel++;
}
return 1;
}
static int Pack24To8(unsigned int src_data_size, XImage *src_image, XImage *dst_image)
{
unsigned char *src_pixel = (unsigned char *) src_image -> data;
unsigned char *dst_pixel = (unsigned char *) dst_image -> data;
int i;
unsigned int bytes_per_line = src_image -> bytes_per_line;
unsigned char *end_of_line = (unsigned char *) (src_pixel + bytes_per_line);
#ifdef DEBUG
unsigned int counter = 0;
#endif
for (i = 0; i < src_image -> height; i++ )
{
#ifdef DEBUG
fprintf(stderr, "******PackImage: Pixel [%d] value [0x%x%x%x] red [0x%x] green [0x%x] blue [0x%x].\n",
counter, src_pixel[0], src_pixel[1], src_pixel[2], src_pixel[0] & 0xc0,
src_pixel[1] & 0xc0, src_pixel[2] & 0xc0);
#endif
while(src_pixel < end_of_line - 2)
{
if (src_pixel[0] == 0x00 &&
src_pixel[1] == 0x00 &&
src_pixel[2] == 0x00)
{
*dst_pixel = 0x0;
}
else if (src_pixel[0] == 0xff &&
src_pixel[1] == 0xff &&
src_pixel[2] == 0xff)
{
*dst_pixel = 0xff;
}
else
{
/*
* Pixel layout:
*
* 24 bit RRRRR000 GGGGG000 BBBBB000 -> 8 bit 00RRGGBB
*/
*dst_pixel = (src_pixel[0] & 0xc0) >> 2 |
((src_pixel[1] & 0xc0) >> 4) |
((src_pixel[2] & 0xc0) >> 6);
}
#ifdef DEBUG
fprintf(stderr, "******PackImage: Pixel [%d] destination [0x%x].\n",
counter++, *dst_pixel);
#endif
src_pixel += 3;
dst_pixel += 1;
}
src_pixel = end_of_line;
end_of_line += bytes_per_line;
}
return 1;
}
static int Pack24To16(unsigned int src_data_size, XImage *src_image, XImage *dst_image)
{
unsigned char *src_pixel = (unsigned char *) src_image -> data;
unsigned short *dst_pixel = (unsigned short *) dst_image -> data;
int i;
unsigned int bytes_per_line = src_image -> bytes_per_line;
unsigned char *end_of_line = (unsigned char *) (src_pixel + bytes_per_line);
#ifdef DEBUG
unsigned int counter = 0;
#endif
for (i = 0; i < src_image -> height; i++ )
{
while(src_pixel < end_of_line - 2)
{
#ifdef DEBUG
fprintf(stderr, "******PackImage: Pixel [%d] value [0x%x%x%x] red [0x%x] green [0x%x] blue [0x%x].\n",
counter, src_pixel[0], src_pixel[1], src_pixel[2], src_pixel[0] & 0xf8,
src_pixel[1] & 0xf8, src_pixel[2] & 0xf8);
#endif
if (src_pixel[0] == 0x00 &&
src_pixel[1] == 0x00 &&
src_pixel[2] == 0x00)
{
*dst_pixel = 0x0;
}
else if (src_pixel[0] == 0xff &&
src_pixel[1] == 0xff &&
src_pixel[2] == 0xff)
{
*dst_pixel = 0xffff;
}
else
{
/*
* Pixel layout:
*
* 24 bit RRRRR000 GGGGG000 BBBBB000 -> 16 bit 0RRRRRGG GGGBBBBB
*/
*dst_pixel = ((src_pixel[0] & 0xf8) << 7) |
((src_pixel[1] & 0xf8) << 2) |
((src_pixel[2] & 0xf8) >> 3);
}
#ifdef DEBUG
fprintf(stderr, "******PackImage: Pixel [%d] destination [0x%x].\n",
counter++, *dst_pixel);
#endif
src_pixel += 3;
dst_pixel += 1;
}
src_pixel = end_of_line;
end_of_line += bytes_per_line;
}
return 1;
}
static int Pack32To8(unsigned int src_data_size, XImage *src_image, XImage *dst_image)
{
unsigned int *src_pixel = (unsigned int *) src_image -> data;
unsigned char *dst_pixel = (unsigned char *) dst_image -> data;
#ifdef DEBUG
unsigned int counter = 0;
#endif
while (src_pixel < ((unsigned int *) (src_image -> data + src_data_size)))
{
#ifdef DEBUG
fprintf(stderr, "******PackImage: Pixel [%d] value [0x%x] red [0x%x] green [0x%x] blue [0x%x].\n",
counter, *src_pixel, (*src_pixel & 0xc00000),
(*src_pixel & 0xc000), (*src_pixel & 0xc0));
#endif
if (*src_pixel == 0x0)
{
*dst_pixel = 0x0;
}
else if (*src_pixel == 0xffffff)
{
*dst_pixel = 0xff;
}
else
{
*dst_pixel = ((*src_pixel & 0xc00000) >> 18) |
((*src_pixel & 0xc000) >> 12) |
((*src_pixel & 0xc0) >> 6);
}
#ifdef DEBUG
fprintf(stderr, "******PackImage: Pixel [%d] destination [0x%x].\n",
counter++, *dst_pixel);
#endif
src_pixel++;
dst_pixel++;
}
return 1;
}
static int Pack32To16(unsigned int src_data_size, XImage *src_image, XImage *dst_image)
{
unsigned int *src_pixel = (unsigned int *) src_image -> data;
unsigned short *dst_pixel = (unsigned short *) dst_image -> data;
#ifdef DEBUG
unsigned int counter = 0;
#endif
while (src_pixel < ((unsigned int *) (src_image -> data + src_data_size)))
{
#ifdef DEBUG
fprintf(stderr, "******PackImage: Pixel [%d] value [0x%x] red [0x%x] green [0x%x] blue [0x%x].\n",
counter, *src_pixel, (*src_pixel & 0xf80000),
(*src_pixel & 0xf800), (*src_pixel & 0xf8));
#endif
if (*src_pixel == 0x0)
{
*dst_pixel = 0x0;
}
else if (*src_pixel == 0xffffff)
{
*dst_pixel = 0xffff;
}
else
{
*dst_pixel = ((*src_pixel & 0xf80000) >> 9) |
((*src_pixel & 0xf800) >> 6) |
((*src_pixel & 0xf8) >> 3);
}
#ifdef DEBUG
fprintf(stderr, "******PackImage: Pixel [%d] destination [0x%x].\n",
counter++, *dst_pixel);
#endif
src_pixel++;
dst_pixel++;
}
return 1;
}
static int Pack32To24(unsigned int src_data_size, XImage *src_image, XImage *dst_image)
{
unsigned int *src_pixel = (unsigned int *) src_image -> data;
unsigned char *dst_pixel = (unsigned char *) dst_image -> data;
#ifdef DEBUG
unsigned int counter = 0;
#endif
while (src_pixel < ((unsigned int *) (src_image -> data + src_data_size)))
{
#ifdef DEBUG
fprintf(stderr, "******PackImage: Pixel [%d] value [0x%x] red [0x%x] green [0x%x] blue [0x%x].\n",
counter, *src_pixel, ((*src_pixel & 0xff0000) >> 16),
((*src_pixel & 0x00ff00) >> 8), (*src_pixel & 0xff));
#endif
if (*src_pixel == 0x0)
{
dst_pixel[0] = dst_pixel[1] = dst_pixel[2] = 0x0;
}
else if (*src_pixel == 0xffffff)
{
dst_pixel[0] = dst_pixel[1] = dst_pixel[2] = 0xff;
}
else
{
dst_pixel[0] = (*src_pixel & 0xff0000) >> 16;
dst_pixel[1] = (*src_pixel & 0x00ff00) >> 8;
dst_pixel[2] = (*src_pixel & 0x0000ff);
}
#ifdef DEBUG
fprintf(stderr, "******PackImage: Pixel [%d] destination [0x%x], [0x%x], [0x%x].\n",
counter++, dst_pixel[0], dst_pixel[1], dst_pixel[2]);
#endif
src_pixel += 1;
dst_pixel += 3;
}
return 1;
}
int PackImage(unsigned int method, unsigned int src_data_size, XImage *src_image,
unsigned int dst_data_size, XImage *dst_image)
{
unsigned int src_bits_per_pixel;
unsigned int dst_bits_per_pixel;
src_bits_per_pixel = src_image -> bits_per_pixel;
dst_bits_per_pixel = MethodBitsPerPixel(method);
#ifdef TEST
fprintf(stderr, "******PackImage: Source bits per pixel [%d], destination bits per pixel [%d].\n",
src_bits_per_pixel, dst_bits_per_pixel);
fprintf(stderr, "******PackImage: Source data size [%d], destination data size [%d].\n",
src_data_size, dst_data_size);
#endif
if (dst_bits_per_pixel >= src_bits_per_pixel)
{
#ifdef PANIC
fprintf(stderr, "******PackImage: PANIC! Cannot pack image from [%d] to [%d] bytes per pixel.\n",
src_bits_per_pixel, dst_bits_per_pixel);
#endif
return 0;
}
switch (src_bits_per_pixel)
{
case 16:
{
switch (dst_bits_per_pixel)
{
case 8:
{
return Pack16To8(src_data_size, src_image, dst_image);
}
default:
{
return 0;
}
}
}
case 24:
{
switch (dst_bits_per_pixel)
{
case 8:
{
return Pack24To8(src_data_size, src_image, dst_image);
}
case 16:
{
return Pack24To16(src_data_size, src_image, dst_image);
}
default:
{
return 0;
}
}
}
case 32:
{
switch (dst_bits_per_pixel)
{
case 8:
{
return Pack32To8(src_data_size, src_image, dst_image);
}
case 16:
{
return Pack32To16(src_data_size, src_image, dst_image);
}
case 24:
{
return Pack32To24(src_data_size, src_image, dst_image);
}
default:
{
return 0;
}
}
}
default:
{
return 0;
}
}
}
/*
* Replace the ffs() call that may be not
* present on some systems.
*/
int FindLSB(int word)
{
int t = word;
int m = 1;
int i = 0;
for (; i < sizeof(word) << 3; i++, m <<= 1)
{
if (t & m)
{
return i + 1;
}
}
return 0;
}
/**************************************************************************/
/* */
/* Copyright (c) 2001, 2007 NoMachine, http://www.nomachine.com/. */
/* */
/* NXCOMPEXT, NX protocol compression and NX extensions to this software */
/* are copyright of NoMachine. Redistribution and use of the present */
/* software is allowed according to terms specified in the file LICENSE */
/* which comes in the source distribution. */
/* */
/* Check http://www.nomachine.com/licensing.html for applicability. */
/* */
/* NX and NoMachine are trademarks of NoMachine S.r.l. */
/* */
/* All rigths reserved. */
/* */
/**************************************************************************/
#ifndef Mask_H
#define Mask_H
#ifdef __cplusplus
extern "C" {
#endif
#include "Xlib.h"
extern int MaskImage(const ColorMask *mask, XImage *src_image, XImage *dst_image);
extern int MaskInPlaceImage(const ColorMask *mask, XImage *image);
extern int PackImage(unsigned int method, unsigned int src_data_size, XImage *src_image,
unsigned int dst_data_size, XImage *dst_image);
int FindLSB(int word);
#ifdef __cplusplus
}
#endif
#endif /* Mask_H */
This source diff could not be displayed because it is too large. You can view the blob instead.
/**************************************************************************/
/* */
/* Copyright (c) 2001, 2007 NoMachine, http://www.nomachine.com/. */
/* */
/* NXCOMPEXT, NX protocol compression and NX extensions to this software */
/* are copyright of NoMachine. Redistribution and use of the present */
/* software is allowed according to terms specified in the file LICENSE */
/* which comes in the source distribution. */
/* */
/* Check http://www.nomachine.com/licensing.html for applicability. */
/* */
/* NX and NoMachine are trademarks of NoMachine S.r.l. */
/* */
/* All rigths reserved. */
/* */
/**************************************************************************/
#ifndef NXlib_H
#define NXlib_H
#ifdef __cplusplus
extern "C" {
#endif
#include <X11/X.h>
#include <X11/Xlib.h>
#include "NX.h"
#include "NXpack.h"
#include "NXproto.h"
#include "NXvars.h"
/*
* All the NX code should use these.
*/
#define Xmalloc(size) malloc((size))
#define Xfree(ptr) free((ptr))
/*
* Maximum number of supported pack methods.
*/
#define NXNumberOfPackMethods 128
/*
* Assume this as the limit of resources that
* can be provided to the split and unpack
* requests.
*/
#define NXNumberOfResources 256
#define NXNoResource 256 + 1
#define NXAnyResource 256 + 2
/*
* Initialize the internal structures used by
* the library. Should be executed again after
* having reopened the display.
*/
extern int NXInitDisplay(
#if NeedFunctionPrototypes
Display* /* display */
#endif
);
/*
* Reset all the internal structures. Should be
* executed after closing the display.
*/
extern int NXResetDisplay(
#if NeedFunctionPrototypes
Display* /* display */
#endif
);
/*
* Set the NX display flush policy. The policy can
* be either NXFlushDeferred or NXFlushImmediate.
*/
extern int NXSetDisplayPolicy(
#if NeedFunctionPrototypes
Display* /* display */,
int /* policy */
#endif
);
/*
* Set the display output buffer size.
*/
extern int NXSetDisplayBuffer(
#if NeedFunctionPrototypes
Display* /* display */,
int /* size */
#endif
);
/*
* If set, the Popen() function in the X server
* wil remove the LD_LIBRARY_PATH variable from
* the environment before calling the execl()
* function on the child process. The function
* returns the previous value.
*/
extern int NXUnsetLibraryPath(
#if NeedFunctionPrototypes
int /* value */
#endif
);
/*
* If the parameter is true, the Xlib I/O error
* handler will return, instead of quitting the
* program. The function returns the previous
* value.
*/
extern int NXHandleDisplayError(
#if NeedFunctionPrototypes
int /* value */
#endif
);
/*
* Shutdown the display descriptor and force Xlib
* to set the I/O error flag.
*/
extern Bool NXForceDisplayError(
#if NeedFunctionPrototypes
Display* /* display */
#endif
);
/*
* Check the value of the XlibDisplayIOError flag.
* If not set, try to call the display error hand-
* ler to give to the application a chance to see
* whether it needs to close the connection.
*/
extern int NXDisplayError(
#if NeedFunctionPrototypes
Display* /* display */
#endif
);
/*
* Query the number of bytes readable from the
* display connection.
*/
extern int NXDisplayReadable(
#if NeedFunctionPrototypes
Display* /* display */
#endif
);
/*
* Query the number of the outstanding bytes to
* flush to the display connection.
*/
extern int NXDisplayFlushable(
#if NeedFunctionPrototypes
Display* /* display */
#endif
);
/*
* Return a value between 0 and 9 indicating the
* congestion level of the NX transport based on
* the tokens remaining. A value of 9 means that
* the link is congested and no further data can
* be sent.
*/
extern int NXDisplayCongestion(
#if NeedFunctionPrototypes
Display* /* display */
#endif
);
/*
* Flush the Xlib display buffer and/or the
* outstanding data accumulated by the NX
* transport.
*/
extern int NXFlushDisplay(
#if NeedFunctionPrototypes
Display* /* display */,
int /* what */
#endif
);
/*
* Public interfaces used to set the handlers.
* They all return the previous handler.
*/
extern NXDisplayErrorPredicate NXSetDisplayErrorPredicate(
#if NeedFunctionPrototypes
NXDisplayErrorPredicate /* predicate */
#endif
);
/*
* Called when the display blocks waiting to read or
* write more data.
*/
extern NXDisplayBlockHandler NXSetDisplayBlockHandler(
#if NeedFunctionPrototypes
NXDisplayBlockHandler /* handler */
#endif
);
/*
* Called after more data is written to the display.
* When the NX transport is running, data may be queued
* until an explicit flush.
*/
extern NXDisplayWriteHandler NXSetDisplayWriteHandler(
#if NeedFunctionPrototypes
NXDisplayWriteHandler /* handler */
#endif
);
/*
* Called after more data is sent to the remote proxy.
*
* Here the display pointer is passed as the second
* parameter to make clear that the function does not
* tie the callback to the display, but, similarly to
* all the Xlib error handlers, to a global variable
* shared by all the Xlib functions. The display
* pointer will be passed back by nxcomp at the time
* it will call the handler. This is because nxcomp
* doesn't have access to the display structure.
*/
extern NXDisplayFlushHandler NXSetDisplayFlushHandler(
#if NeedFunctionPrototypes
NXDisplayFlushHandler /* handler */,
Display* /* display */
#endif
);
/*
* Get an arbitrary null terminated buffer to be added
* to the NX statistics.
*/
extern NXDisplayStatisticsHandler NXSetDisplayStatisticsHandler(
#if NeedFunctionPrototypes
NXDisplayStatisticsHandler /* handler */,
char ** /* buffer */
#endif
);
/*
* Redefine the function called by Xlib in the case of
* an out-of-order sequence number received in the X
* protocol stream.
*/
extern NXLostSequenceHandler NXSetLostSequenceHandler(
#if NeedFunctionPrototypes
NXLostSequenceHandler /* handler */
#endif
);
/*
* The agent should get the NX parameters at startup, just after
* having opened the display. If the agent is not able to satisfy
* the pack method set by user (because a method is not applica-
* ble, it is not supported by the remote or it simply requires a
* screen depth greater than the depth available), it should fall
* back to the nearest method of the same type.
*/
extern Status NXGetControlParameters(
#if NeedFunctionPrototypes
Display* /* display */,
unsigned int* /* link_type */,
unsigned int* /* local_major */,
unsigned int* /* local_minor */,
unsigned int* /* local_patch */,
unsigned int* /* remote_major */,
unsigned int* /* remote_minor */,
unsigned int* /* remote_patch */,
int* /* frame_timeout */,
int* /* ping_timeout */,
int* /* split_mode */,
int* /* split_size */,
unsigned int* /* pack_method */,
unsigned int* /* pack_quality */,
int* /* data_level */,
int* /* stream_level */,
int* /* delta_level */,
unsigned int* /* load_cache */,
unsigned int* /* save_cache */,
unsigned int* /* startup_cache */
#endif
);
/*
* Which unpack methods are supported by the remote proxy?
*/
extern Status NXGetUnpackParameters(
#if NeedFunctionPrototypes
Display* /* display */,
unsigned int* /* entries */,
unsigned char[] /* supported_methods */
#endif
);
/*
* Query and enable shared memory support on path agent to X
* client proxy and X server proxy to real X server. At the
* moment only the path proxy to real X server is implemented.
* On return flags will say if support has been successfully
* activated. Segments will contain the XID associated to the
* shared memory blocks. A MIT-SHM compliant protocol is used
* between proxy and the real server, while a simplified
* version is used between the agent and the client proxy to
* accomodate both packed images and plain X bitmaps.
*/
extern Status NXGetShmemParameters(
#if NeedFunctionPrototypes
Display* /* display */,
unsigned int* /* enable_client */,
unsigned int* /* enable_server */,
unsigned int* /* client_segment */,
unsigned int* /* server_segment */,
unsigned int* /* client_size */,
unsigned int* /* server_size */
#endif
);
/*
* Get the path to the font server that can be used by the X
* server to tunnel the font connections across the NX link.
* The path actually represents the TCP port where the proxy
* on the NX client side is listening. The agent can tempora-
* rily enable the tunneling when it needs a font that is not
* available on the client, for example when the session is
* migrated from a different X server.
*/
extern Status NXGetFontParameters(
#if NeedFunctionPrototypes
Display* /* display */,
unsigned int /* path_length */,
char[] /* path_data */
#endif
);
/*
* This set of functions is used to leverage the image stream-
* ing capabilities built in nxcomp. An image can be streamed
* by sending a start-split message, followed by the X messages
* that will have to be split by the proxy, followed by an end-
* split closure. Usually, in the middle of a start-split/end-
* split sequence there will be a single PutImage() or PutPack-
* edImage(), that, in turn, can generate multiple partial
* requests, like a SetUnpackColormap() and SetUnpackAlpha()
* that will be later used to decompress the image to its ori-
* ginal form. Multiple requests may be also generated because
* of the maximum size of a X request being exceeded, so that
* Xlib has to divide the single image in multiple sub-image re-
* quests. The agent doesn't need to take care of these details
* but will rather have to track the result of the split opera-
* tion. By monitoring the notify events sent by the proxy, the
* agent will have to implement its own strategy to deal with
* the resources. For example, it will be able to:
*
* - Mark a drawable as dirty, if the image was not sent
* synchronously, in the main X oputput stream.
*
* - Choose to commit or discard the original image, at the
* time it will be recomposed at the remote side. This may
* include all the messages that were part of the split
* (the colormap, the alpha channel, etc.)
*
* - Mark the drawable as clean again, if the image was
* committed and the drawable didn't change in the mean-
* while.
*
* At the time the proxy receives the end-split, it reports the
* result of the operation to the agent. The agent will be able
* to identify the original split operation (the one referenced
* in the start-split/end-split sequence) by the small integer
* number (0-255) named 'resource' sent in the events.
*
* One of the following cases may be encountered:
*
*
* NXNoSplitNotify All messages were sent in the main out-
* put stream, so that no split actually
* took place.
*
* NXStartSplitNotify One or more messages were split, so,
* at discrection of the agent, the client
* may be suspended until the transferral
* is completed.
*
* NXCommitSplitNotify One of the requests that made up the
* split was recomposed. The agent should
* either commit the given request or tell
* the proxy to discard it.
*
* NXEndSplitNotify The split was duly completed. The agent
* can restart the client.
*
* NXEmptySplitNotify No more split operation are pending.
* The agent can use this information to
* implement specific strategies requiring
* that all messages have been recomposed
* at the remote end, like updating the
* drawables that were not synchronized
* because of the lazy encoding.
*
* The 'mode' field that is sent by the agent in the start-split
* request, determines the strategy that the proxy will adopt to
* deal with the image. If set to 'eager', the proxy will only
* split the messages whose size exceeds the split threshold (the
* current threshold can be found in the NXGetControlParameters()
* reply). If the mode is set to lazy, the proxy will split any
* image that would have generated an actual transfer of the data
* part (in practice all images that are not found in the cache).
* This second strategy can be leveraged by an agent to further
* reduce the bandwidth requirements. For example, by setting the
* mode to lazy and by monitoring the result, an agent can easi-
* ly verify if the drawable was successfully updated, mark the
* drawable if not, and synchronize it at later time.
*
* See NXproto.h for the definition of the available modes.
*/
extern unsigned int NXAllocSplit(
#if NeedFunctionPrototypes
Display* /* display */,
unsigned int /* resource */
#endif
);
extern int NXStartSplit(
#if NeedFunctionPrototypes
Display* /* display */,
unsigned int /* resource */,
unsigned int /* mode */
#endif
);
extern int NXEndSplit(
#if NeedFunctionPrototypes
Display* /* display */,
unsigned int /* resource */
#endif
);
extern int NXCommitSplit(
#if NeedFunctionPrototypes
Display* /* display */,
unsigned int /* resource */,
unsigned int /* propagate */,
unsigned char /* request */,
unsigned int /* position */
#endif
);
extern int NXAbortSplit(
#if NeedFunctionPrototypes
Display* /* display */,
unsigned int /* resource */
#endif
);
extern int NXFinishSplit(
#if NeedFunctionPrototypes
Display* /* display */,
unsigned int /* resource */
#endif
);
extern int NXFreeSplit(
#if NeedFunctionPrototypes
Display* /* display */,
unsigned int /* resource */
#endif
);
extern int NXSetExposeParameters(
#if NeedFunctionPrototypes
Display* /* display */,
int /* expose */,
int /* graphics_expose */,
int /* no_expose */
#endif
);
extern int NXSetCacheParameters(
#if NeedFunctionPrototypes
Display* /* display */,
int /* enable_cache */,
int /* enable_split */,
int /* enable_save */,
int /* enable_load */
#endif
);
extern unsigned int NXAllocUnpack(
#if NeedFunctionPrototypes
Display* /* display */,
unsigned int /* resource */
#endif
);
extern int NXSetUnpackGeometry(
#if NeedFunctionPrototypes
Display* /* display */,
unsigned int /* resource */,
Visual* /* visual */
#endif
);
extern int NXSetUnpackColormap(
#if NeedFunctionPrototypes
Display* /* display */,
unsigned int /* resource */,
unsigned int /* method */,
unsigned int /* entries */,
const char* /* data */,
unsigned int /* data_length */
#endif
);
extern int NXSetUnpackAlpha(
#if NeedFunctionPrototypes
Display* /* display */,
unsigned int /* resource */,
unsigned int /* method */,
unsigned int /* entries */,
const char* /* data */,
unsigned int /* data_length */
#endif
);
extern int NXSetUnpackColormapCompat(
#if NeedFunctionPrototypes
Display* /* display */,
unsigned int /* resource */,
unsigned int /* entries */,
const char* /* data */
#endif
);
extern int NXSetUnpackAlphaCompat(
#if NeedFunctionPrototypes
Display* /* display */,
unsigned int /* resource */,
unsigned int /* entries */,
const char* /* data */
#endif
);
extern int NXFreeUnpack(
#if NeedFunctionPrototypes
Display* /* display */,
unsigned int /* resource */
#endif
);
/*
* A packed image is a XImage but with
* offset field containing total amount
* of packed image data.
*/
typedef XImage NXPackedImage;
NXPackedImage *NXCreatePackedImage(
#if NeedFunctionPrototypes
Display* /* display */,
Visual* /* visual */,
unsigned int /* method */,
unsigned int /* depth */,
int /* format */,
char* /* data */,
int /* data_length */,
unsigned int /* width */,
unsigned int /* height */,
int /* bitmap_pad */,
int /* bytes_per_line */
#endif
);
extern int NXDestroyPackedImage(
#if NeedFunctionPrototypes
NXPackedImage* /* image */
#endif
);
NXPackedImage *NXPackImage(
#if NeedFunctionPrototypes
Display* /* display */,
XImage* /* src_image */,
unsigned int /* method */
#endif
);
NXPackedImage *NXInPlacePackImage(
#if NeedFunctionPrototypes
Display* /* display */,
XImage* /* src_image */,
unsigned int /* method */
#endif
);
/*
* GC is declared void * to get rid of mess
* with different GC definitions in some X
* server code (like in nxagent).
*/
extern int NXPutPackedImage(
#if NeedFunctionPrototypes
Display* /* display */,
unsigned int /* resource */,
Drawable /* drawable */,
void* /* gc */,
NXPackedImage* /* image */,
unsigned int /* method */,
unsigned int /* depth */,
int /* src_x */,
int /* src_y */,
int /* dst_x */,
int /* dst_y */,
unsigned int /* width */,
unsigned int /* height */
#endif
);
/*
* Get multiple colors with a single call by
* pipelining X_AllocColor requests/replies.
*/
extern int NXAllocColors(
#if NeedFunctionPrototypes
Display* /* display */,
Colormap /* colormap */,
unsigned int /* entries */,
XColor[] /* screens_in_out */,
Bool [] /* flags allocation errors */
#endif
);
/*
* Encode the data in the given format.
*/
extern char *NXEncodeColormap(
#if NeedFunctionPrototypes
const char* /* src_data */,
unsigned int /* src_size */,
unsigned int* /* dst_size */
#endif
);
extern char *NXEncodeAlpha(
#if NeedFunctionPrototypes
const char* /* src_data */,
unsigned int /* src_size */,
unsigned int* /* dst_size */
#endif
);
extern NXPackedImage *NXEncodeRgb(
#if NeedFunctionPrototypes
XImage* /* src_image */,
unsigned int /* method */,
unsigned int /* quality */
#endif
);
extern NXPackedImage *NXEncodeRle(
#if NeedFunctionPrototypes
XImage* /* src_image */,
unsigned int /* method */,
unsigned int /* quality */
#endif
);
extern NXPackedImage *NXEncodeJpeg(
#if NeedFunctionPrototypes
XImage* /* src_image */,
unsigned int /* method */,
unsigned int /* quality */
#endif
);
typedef struct
{
long pixel;
int found;
} NXColorTable;
extern int NXEncodeColors(
#if NeedFunctionPrototypes
XImage* /* src_image */,
NXColorTable* /* color_table */,
int /* nb_max */
#endif
);
extern NXPackedImage *NXEncodePng(
#if NeedFunctionPrototypes
XImage* /* src_image */,
unsigned int /* method */,
unsigned int /* quality */
#endif
);
extern NXPackedImage *NXEncodeBitmap(
#if NeedFunctionPrototypes
XImage* /* src_image */,
unsigned int /* method */,
unsigned int /* quality */
#endif
);
extern int NXCleanImage(
#if NeedFunctionPrototypes
XImage*
#endif
);
extern void NXMaskImage(
#if NeedFunctionPrototypes
XImage* /* pointer to image to mask */ ,
unsigned int /* method */
#endif
);
extern int NXImageCacheSize;
extern void NXInitCache(
#if NeedFunctionPrototypes
Display* /* display */,
int /* entries in image cache */
#endif
);
extern void NXFreeCache(
#if NeedFunctionPrototypes
Display* /* display */
#endif
);
extern XImage *NXCacheFindImage(
#if NeedFunctionPrototypes
NXPackedImage* /* packed image to find */,
unsigned int* /* pointer to the pack method if found */,
unsigned char** /* pointer to the calculated MD5 if found */
#endif
);
extern int NXCacheAddImage(
#if NeedFunctionPrototypes
NXPackedImage* /* packed image to be added to the cache */,
unsigned int /* pack method of the image to add */,
unsigned char* /* pointer to MD5 of the original unpacked image */
#endif
);
extern int NXGetCollectImageResource(
#if NeedFunctionPrototypes
Display* /* display */
#endif
);
extern int NXCollectImage(
#if NeedFunctionPrototypes
Display* /* display */,
unsigned int /* resource */,
Drawable /* drawable */,
int /* src_x */,
int /* src_y */,
unsigned int /* width */,
unsigned int /* height */,
unsigned long /* plane_mask */,
int /* format */
#endif
);
extern int NXGetCollectedImage(
#if NeedFunctionPrototypes
Display* /* display */,
unsigned int /* resource */,
XImage** /* image */
#endif
);
extern int NXGetCollectPropertyResource(
#if NeedFunctionPrototypes
Display* /* display */
#endif
);
extern int NXCollectProperty(
#if NeedFunctionPrototypes
Display* /* display */,
unsigned int /* resource */,
Window /* window */,
Atom /* property */,
long /* long_offset */,
long /* long_length */,
Bool /* delete */,
Atom /* req_type */
#endif
);
extern int NXGetCollectedProperty(
#if NeedFunctionPrototypes
Display* /* display */,
unsigned int /* resource */,
Atom* /* actual_type_return */,
int* /* actual_format_return */,
unsigned long* /* nitems_return */,
unsigned long* /* bytes_after_return */,
unsigned char** /* data */
#endif
);
extern int NXGetCollectGrabPointerResource(
#if NeedFunctionPrototypes
Display* /* display */
#endif
);
extern int NXCollectGrabPointer(
#if NeedFunctionPrototypes
Display* /* display */,
unsigned int /* resource */,
Window /* grab_window */,
Bool /* owner_events */,
unsigned int /* event_mask */,
int /* pointer_mode */,
int /* keyboard_mode */,
Window /* confine_to */,
Cursor /* cursor */,
Time /* time */
#endif
);
extern int NXGetCollectedGrabPointer(
#if NeedFunctionPrototypes
Display* /* display */,
unsigned int /* resource */,
int* /* status */
#endif
);
extern int NXGetCollectInputFocusResource(
#if NeedFunctionPrototypes
Display* /* display */
#endif
);
extern int NXCollectInputFocus(
#if NeedFunctionPrototypes
Display* /* display */,
unsigned int /* resource */
#endif
);
extern int NXGetCollectedInputFocus(
#if NeedFunctionPrototypes
Display* /* display */,
unsigned int /* resource */,
Window* /* focus_return */,
int* /* revert_to_return */
#endif
);
#ifdef __cplusplus
}
#endif
#endif /* NXlib_H */
/**************************************************************************/
/* */
/* Copyright (c) 2001, 2007 NoMachine, http://www.nomachine.com/. */
/* */
/* NXCOMPEXT, NX protocol compression and NX extensions to this software */
/* are copyright of NoMachine. Redistribution and use of the present */
/* software is allowed according to terms specified in the file LICENSE */
/* which comes in the source distribution. */
/* */
/* Check http://www.nomachine.com/licensing.html for applicability. */
/* */
/* NX and NoMachine are trademarks of NoMachine S.r.l. */
/* */
/* All rigths reserved. */
/* */
/**************************************************************************/
#ifndef NXlibint_H
#define NXlibint_H
#ifdef __cplusplus
extern "C" {
#endif
#include "NXvars.h"
#ifdef __cplusplus
}
#endif
#endif /* NXlibint_H */
/**************************************************************************/
/* */
/* Copyright (c) 2001, 2007 NoMachine, http://www.nomachine.com/. */
/* */
/* NXCOMPEXT, NX protocol compression and NX extensions to this software */
/* are copyright of NoMachine. Redistribution and use of the present */
/* software is allowed according to terms specified in the file LICENSE */
/* which comes in the source distribution. */
/* */
/* Check http://www.nomachine.com/licensing.html for applicability. */
/* */
/* NX and NoMachine are trademarks of NoMachine S.r.l. */
/* */
/* All rigths reserved. */
/* */
/**************************************************************************/
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include "Xutil.h"
#include "NXlib.h"
#include "Mask.h"
#include "Pgn.h"
#define PANIC
#define WARNING
#undef TEST
#undef DEBUG
/*
* Selected ZLIB compression level.
*/
#define PNG_Z_LEVEL 4
/*
* Local function prototypes.
*/
static void PrepareRowForPng(CARD8 *dst, int y, int count);
static void PrepareRowForPng24(CARD8 *dst, int y, int count);
static void PrepareRowForPng16(CARD8 *dst, int y, int count);
static void PrepareRowForPng32(CARD8 *dst, int y, int count);
static void PngWriteData(png_structp png_ptr, png_bytep data, png_size_t length);
static void PngFlushData(png_structp png_ptr);
/*
* Image characteristics.
*/
static int bytesPerLine;
static int byteOrder;
static CARD8 bitsPerPixel;
static CARD16 redMax, greenMax, blueMax;
static CARD8 redShift, greenShift, blueShift;
/*
* Other variables used for the Png
* encoding.
*/
png_byte color_type;
png_structp png_ptr;
png_infop info_ptr;
png_colorp palette;
static char *pngCompBuf;
static int pngDataLen;
static char *pngBeforeBuf = NULL;
/*
* Allocate data for the compressed image.
* We need to ensure that there is enough
* space to include the palette and the
* header.
*/
#define PNG_DEST_SIZE(width, height) ((width) * 3 * (height) + 1024 + 256)
/*
* Just for debug purposes.
*/
#ifdef DEBUG
static int pngId;
static char pngName[10];
static FILE *pngFile;
#endif
int PngCompareColorTable(NXColorTable *c1, NXColorTable *c2)
{
return (c1 -> pixel - c2 -> pixel);
}
#define NB_COLOR_MAX 256
int NXCreatePalette32(XImage *src_image, NXColorTable *color_table, CARD8 *image_index, int nb_max)
{
int x, y, t, p;
CARD8 *fbptr;
CARD32 pixel;
fbptr = (CARD8 *) (src_image -> data);
/*
* TODO: Find a more intelligent way to
* estimate the number of colors.
*/
memset(color_table, 0, nb_max * sizeof(NXColorTable));
for (x = 0, p = 0; x < src_image -> height; x++)
{
for (y = 0; y < src_image -> width; y++)
{
if (byteOrder == LSBFirst)
{
pixel = (CARD32) *(fbptr + 3);
pixel = (pixel << 8) | (CARD32) *(fbptr + 2);
pixel = (pixel << 8) | (CARD32) *(fbptr + 1);
pixel = (pixel << 8) | (CARD32) *fbptr;
}
else
{
pixel = (CARD32) *fbptr;
pixel = (pixel << 8) | (CARD32) *(fbptr + 1);
pixel = (pixel << 8) | (CARD32) *(fbptr + 2);
pixel = (pixel << 8) | (CARD32) *(fbptr + 3);
}
fbptr += 4;
for (t = 0; t < nb_max; t++)
{
if (color_table[t].found == 0)
{
color_table[t].pixel = pixel;
color_table[t].found = 1;
p++;
image_index[((x * src_image -> width) + y)] = t;
break;
}
else if ((CARD32)(color_table[t].pixel) == pixel)
{
image_index[((x * src_image -> width) + y)] = t;
break;
}
}
if (p == nb_max)
{
return nb_max + 1;
}
}
}
return p;
}
int NXCreatePalette16(XImage *src_image, NXColorTable *color_table, CARD8 *image_index, int nb_max)
{
int x, y, t, p;
CARD8 *fbptr;
CARD16 pixel;
fbptr = (CARD8 *) (src_image -> data);
/*
* TODO: Find a more intelligent way to
* estimate the number of colors.
*/
memset(color_table, 0, nb_max * sizeof(NXColorTable));
for (x = 0, p = 0; x < src_image -> height; x++)
{
for (y = 0; y < src_image -> width; y++)
{
if (byteOrder == LSBFirst)
{
pixel = (CARD16) *(fbptr + 1);
pixel = (pixel << 8) | (CARD16) *fbptr;
}
else
{
pixel = (CARD16) *fbptr;
pixel = (pixel << 8) | (CARD16) *(fbptr + 1);
}
fbptr += 2;
for (t = 0; t < nb_max; t++)
{
if (color_table[t].found == 0)
{
color_table[t].pixel = pixel;
color_table[t].found = 1;
p++;
image_index[((x * src_image -> width) + y)] = t;
break;
}
else if ((color_table[t].pixel) == pixel)
{
image_index[((x * src_image -> width) + y)] = t;
break;
}
}
/*
* In case the number of 16bit words is not even
* we have 2 padding bytes that we have to skip.
*/
if ((y == src_image -> width - 1) && (src_image -> width % 2 == 1)) fbptr += 2;
if (p == nb_max)
{
return nb_max + 1;
}
}
}
return p;
}
char *PngCompressData(XImage *image, int *compressed_size)
{
unsigned int num = 0;
CARD8 *srcBuf;
int dy, w, h;
int nb_colors;
NXColorTable color_table[NB_COLOR_MAX];
CARD8 *image_index;
image_index = (CARD8 *) malloc((image -> height) * (image -> width) * sizeof(CARD8));
/*
* TODO: Be sure the padded bytes are cleaned.
* It would be better to set to zero the bytes
* that are not alligned to the word boundary
* at the end of the procedure.
*/
memset(image_index, 0, (image -> height) * (image -> width) * sizeof(CARD8));
*compressed_size = 0;
pngDataLen = 0;
/*
* Initialize the image stuff.
*/
bitsPerPixel = image -> bits_per_pixel;
bytesPerLine = image -> bytes_per_line;
byteOrder = image -> byte_order;
if (bitsPerPixel < 15)
{
#ifdef PANIC
fprintf(stderr, "******PngCompressData: PANIC! Can't compress images with [%d] bits per pixel.\n",
bitsPerPixel);
#endif
return NULL;
}
redShift = FindLSB(image -> red_mask) - 1;
greenShift = FindLSB(image -> green_mask) - 1;
blueShift = FindLSB(image -> blue_mask) - 1;
redMax = image -> red_mask >> redShift;
greenMax = image -> green_mask >> greenShift;
blueMax = image -> blue_mask >> blueShift;
w = image -> width;
h = image -> height;
pngBeforeBuf = image -> data;
#ifdef DEBUG
fprintf(stderr, "******PngCompressData: Compressing image with width [%d] height [%d].\n",
w, h );
#endif
/*
* Initialize the PNG stuff.
*/
png_ptr = png_create_write_struct(PNG_LIBPNG_VER_STRING, NULL, NULL, NULL);
if (png_ptr == NULL)
{
#ifdef PANIC
fprintf(stderr, "******PngCompressData: PANIC! Failed creating the png_create_write_struct.\n");
#endif
return NULL;
}
info_ptr = png_create_info_struct(png_ptr);
if (info_ptr == NULL)
{
#ifdef PANIC
fprintf(stderr, "******PngCompressData: PANIC! Failed creating the png_create_info_struct.\n");
#endif
png_destroy_write_struct(&png_ptr, NULL);
return NULL;
}
if (setjmp(png_jmpbuf(png_ptr)))
{
#ifdef PANIC
fprintf(stderr, "******PngCompressData: PANIC! Error during compression initialization.\n");
#endif
png_destroy_write_struct(&png_ptr, &info_ptr);
return NULL;
}
/*
* Be sure we allocate enough data.
*/
#ifdef TEST
fprintf(stderr, "******PngCompressData: Allocating [%d] bytes for the destination data.\n",
PNG_DEST_SIZE(w, h));
#endif
pngCompBuf = malloc(PNG_DEST_SIZE(w, h));
if (pngCompBuf == NULL)
{
#ifdef PANIC
fprintf(stderr, "******PngCompressData: PANIC! Error allocating [%d] bytes for the Png data.\n",
PNG_DEST_SIZE(w, h));
#endif
return NULL;
}
png_set_write_fn(png_ptr, (void *) pngCompBuf, PngWriteData, PngFlushData);
if (setjmp(png_jmpbuf(png_ptr)))
{
#ifdef PANIC
fprintf(stderr, "******PngCompressData: PANIC! Error writing the header.\n");
#endif
png_destroy_write_struct(&png_ptr, &info_ptr);
free(pngCompBuf);
return NULL;
}
png_set_compression_level(png_ptr, PNG_Z_LEVEL);
if (bitsPerPixel == 16)
{
nb_colors = NXCreatePalette16(image, color_table, image_index, NB_COLOR_MAX);
}
else
{
nb_colors = NXCreatePalette32(image, color_table, image_index, NB_COLOR_MAX);
}
if (nb_colors <= NB_COLOR_MAX)
{
color_type = PNG_COLOR_TYPE_PALETTE;
}
else
{
color_type = PNG_COLOR_TYPE_RGB;
}
png_set_IHDR(png_ptr, info_ptr, w, h,
8, color_type, PNG_INTERLACE_NONE,
PNG_COMPRESSION_TYPE_BASE, PNG_FILTER_TYPE_BASE);
if (color_type == PNG_COLOR_TYPE_PALETTE)
{
palette = png_malloc(png_ptr, sizeof(*palette) * 256);
/*
* TODO: Do we need to clean these bytes?
*
* memset(palette, 0, sizeof(*palette) * 256);
*/
for (num = 0; num < 256 && color_table[num].found != 0; num++)
{
if (bitsPerPixel == 24)
{
palette[num].red = (color_table[num].pixel >> redShift) & redMax;
palette[num].green = (color_table[num].pixel >> greenShift) & greenMax;
palette[num].blue = color_table[num].pixel >> blueShift & blueMax;
}
else
{
int inRed, inGreen, inBlue;
inRed = (color_table[num].pixel >> redShift) & redMax;
inGreen = (color_table[num].pixel >> greenShift) & greenMax;
inBlue = color_table[num].pixel >> blueShift & blueMax;
palette[num].red = (CARD8)((inRed * 255 + redMax / 2) / redMax);
palette[num].green = (CARD8)((inGreen * 255 + greenMax / 2) / greenMax);
palette[num].blue = (CARD8)((inBlue * 255 + blueMax / 2) / blueMax);
}
#ifdef DEBUG
fprintf(stderr, "******PngCompressData: pixel[%d] r[%d] g[%d] b[%d].\n",
(int) color_table[num].pixel,palette[num].red,palette[num].green,palette[num].blue);
#endif
}
png_set_PLTE(png_ptr, info_ptr, palette, num);
#ifdef DEBUG
fprintf(stderr, "******PngCompressedData: Setting palette.\n");
#endif
}
/*
* End of palette.
*/
png_write_info(png_ptr, info_ptr);
/*
* Allocate space for one line of
* the image, 3 bytes per pixel.
*/
#ifdef DEBUG
fprintf(stderr, "******PngCompressedData: Initialization finished.\n");
#endif
if (setjmp(png_jmpbuf(png_ptr)))
{
#ifdef PANIC
fprintf(stderr, "******PngCompressData: PANIC! Error while writing the image rows.\n");
#endif
png_destroy_write_struct(&png_ptr, &info_ptr);
free(pngCompBuf);
return NULL;
}
if (color_type == PNG_COLOR_TYPE_PALETTE)
{
srcBuf = (CARD8 *) malloc(w * sizeof(CARD8));
if (srcBuf == NULL)
{
#ifdef PANIC
fprintf(stderr, "******PngCompressData: PANIC! Cannot allocate [%d] bytes.\n",
(int) (w * sizeof(CARD8)));
#endif
return NULL;
}
/*
* TODO: Be sure the padded bytes are cleaned.
* It would be better to set to zero the bytes
* that are not alligned to the word boundary
* at the end of the procedure.
*/
memset(srcBuf, 0, w * sizeof(CARD8));
}
else
{
srcBuf = (CARD8 *) malloc(w * 3 * sizeof(CARD8));
/*
* TODO: See above.
*/
memset(srcBuf, 0, w * 3 * sizeof(CARD8));
}
if (srcBuf == NULL)
{
#ifdef PANIC
fprintf(stderr, "******PngCompressData: PANIC! Cannot allocate [%d] bytes.\n",
w * 3);
#endif
free(pngCompBuf);
return NULL;
}
for (dy = 0; dy < h; dy++)
{
if (color_type == PNG_COLOR_TYPE_RGB)
{
PrepareRowForPng(srcBuf, dy, w);
}
else
{
memcpy(srcBuf, image_index + (dy * w), w);
}
png_write_row(png_ptr, srcBuf);
}
#ifdef DEBUG
fprintf(stderr, "******PngCompressedData: Compression finished. Lines handled [%d,%d].\n",
dy, h);
#endif
free(srcBuf);
free(image_index);
if (setjmp(png_jmpbuf(png_ptr)))
{
#ifdef PANIC
fprintf(stderr, "******PngCompressData: PANIC! error during end of write.\n");
#endif
png_destroy_write_struct(&png_ptr, &info_ptr);
free(pngCompBuf);
return NULL;
}
png_write_end(png_ptr, NULL);
png_destroy_write_struct(&png_ptr, &info_ptr);
if (color_type == PNG_COLOR_TYPE_PALETTE)
{
png_free(png_ptr, palette);
}
/*
* Check the size of the resulting data.
*/
if (pngDataLen > 0)
{
#ifdef DEBUG
int i = 0;
fprintf(stderr, "******PngCompressedData: Compressed size [%d].\n",
pngDataLen);
pngId++;
sprintf(pngName, "png%d", pngId);
pngFile = fopen(pngName, "w");
for (i = 0; i < pngDataLen; i++)
{
fprintf(pngFile, "%c", *(pngCompBuf + i));
}
fclose(pngFile);
#endif
*compressed_size = pngDataLen;
return pngCompBuf;
}
else
{
#ifdef DEBUG
fprintf(stderr, "******PngCompressedData: PANIC! Invalid size of the compressed data [%d].\n",
pngDataLen);
#endif
free(pngCompBuf);
return NULL;
}
}
static void PngWriteData(png_structp png_ptr, png_bytep data, png_size_t length)
{
memcpy(((char *) png_get_io_ptr(png_ptr) + pngDataLen), data, length);
pngDataLen += length;
}
static void PngFlushData(png_structp png_ptr)
{
}
void PrepareRowForPng(CARD8 *dst, int y, int count)
{
if (bitsPerPixel == 32)
{
if (redMax == 0xff &&
greenMax == 0xff &&
blueMax == 0xff)
{
PrepareRowForPng24(dst, y, count);
}
else
{
PrepareRowForPng32(dst, y, count);
}
}
else if (bitsPerPixel == 24)
{
memcpy(dst, pngBeforeBuf + y * bytesPerLine, count * 3);
}
else
{
/*
* 16 bpp assumed.
*/
PrepareRowForPng16(dst, y, count);
}
}
void PrepareRowForPng24(CARD8 *dst, int y, int count)
{
CARD8 *fbptr;
CARD32 pix;
fbptr = (CARD8 *) (pngBeforeBuf + y * bytesPerLine);
while (count--)
{
if (byteOrder == LSBFirst)
{
pix = (CARD32) *(fbptr + 2);
pix = (pix << 8) | (CARD32) *(fbptr+1);
pix = (pix << 8) | (CARD32) *fbptr;
}
else
{
pix = (CARD32) *(fbptr + 1);
pix = (pix << 8) | (CARD32) *(fbptr + 2);
pix = (pix << 8) | (CARD32) *(fbptr + 3);
}
*dst++ = (CARD8)(pix >> redShift);
*dst++ = (CARD8)(pix >> greenShift);
*dst++ = (CARD8)(pix >> blueShift);
fbptr+=4;
}
}
#define DEFINE_PNG_GET_ROW_FUNCTION(bpp) \
\
void PrepareRowForPng##bpp(CARD8 *dst, int y, int count) \
{ \
CARD8 *fbptr; \
CARD##bpp pix; \
int inRed, inGreen, inBlue; \
int i; \
\
fbptr = (CARD8 *) (pngBeforeBuf + y * bytesPerLine); \
\
while (count--) \
{ \
pix = 0; \
\
if (byteOrder == LSBFirst) \
{ \
for (i = (bpp >> 3) - 1; i >= 0; i--) \
{ \
pix = (pix << 8) | (CARD32) *(fbptr + i); \
} \
} \
else \
{ \
for (i = 0; i < (bpp >> 3); i++) \
{ \
pix = (pix << 8) | (CARD32) *(fbptr + i); \
} \
} \
\
fbptr += (bpp >> 3); \
\
inRed = (int) \
(pix >> redShift & redMax); \
inGreen = (int) \
(pix >> greenShift & greenMax); \
inBlue = (int) \
(pix >> blueShift & blueMax); \
*dst++ = (CARD8)((inRed * 255 + redMax / 2) / \
redMax); \
*dst++ = (CARD8)((inGreen * 255 + greenMax / 2) / \
greenMax); \
*dst++ = (CARD8)((inBlue * 255 + blueMax / 2) / \
blueMax); \
} \
}
DEFINE_PNG_GET_ROW_FUNCTION(16)
DEFINE_PNG_GET_ROW_FUNCTION(32)
/**************************************************************************/
/* */
/* Copyright (c) 2001, 2007 NoMachine, http://www.nomachine.com/. */
/* */
/* NXCOMPEXT, NX protocol compression and NX extensions to this software */
/* are copyright of NoMachine. Redistribution and use of the present */
/* software is allowed according to terms specified in the file LICENSE */
/* which comes in the source distribution. */
/* */
/* Check http://www.nomachine.com/licensing.html for applicability. */
/* */
/* NX and NoMachine are trademarks of NoMachine S.r.l. */
/* */
/* All rigths reserved. */
/* */
/**************************************************************************/
#ifndef Pgn_H
#define Pgn_H
#ifdef __cplusplus
extern "C" {
#endif
#include "X11/X.h"
#include "X11/Xlib.h"
#include "X11/Xmd.h"
#include <png.h>
extern int PngCompareColorTable(
#if NeedFunctionPrototypes
NXColorTable* /* color_table_1 */,
NXColorTable* /* color_table_2 */
#endif
);
extern char *PngCompressData(
#if NeedFunctionPrototypes
XImage* /* image */,
int* /* compressed_size */
#endif
);
int NXCreatePalette16(
#if NeedFunctionPrototypes
XImage* /* src_image */,
NXColorTable* /* color_table */,
CARD8* /* image_index */,
int /* nb_max */
#endif
);
int NXCreatePalette32(
#if NeedFunctionPrototypes
XImage* /* src_image */,
NXColorTable* /* color_table */,
CARD8* /* image_index */,
int /* nb_max */
#endif
);
#ifdef __cplusplus
}
#endif
#endif /* Pgn_H */
README
------
1. To compile:
> tar zxvf nxcompext-X.Y.Z-N.tar.gz
> cd nxcompext
> ./configure
> make
You'll have to run gmake under Solaris.
2. The 'make install' target is not currently supported
in the Makefile, but it should be simple to fix.
/**************************************************************************/
/* */
/* Copyright (c) 2001, 2007 NoMachine, http://www.nomachine.com/. */
/* */
/* NXCOMPEXT, NX protocol compression and NX extensions to this software */
/* are copyright of NoMachine. Redistribution and use of the present */
/* software is allowed according to terms specified in the file LICENSE */
/* which comes in the source distribution. */
/* */
/* Check http://www.nomachine.com/licensing.html for applicability. */
/* */
/* NX and NoMachine are trademarks of NoMachine S.r.l. */
/* */
/* All rigths reserved. */
/* */
/**************************************************************************/
#include <zlib.h>
#include "NXlib.h"
#include "Rgb.h"
#include "Z.h"
#define PANIC
#define WARNING
#undef TEST
#undef DEBUG
#define RGB_COMPRESSION_LEVEL 4
#define RGB_COMPRESSION_THRESHOLD 32
#define RGB_COMPRESSION_STRATEGY Z_DEFAULT_STRATEGY
static int rgbCompressionLevel = RGB_COMPRESSION_LEVEL;
static int rgbCompressionThreshold = RGB_COMPRESSION_THRESHOLD;
static int rgbCompressionStrategy = RGB_COMPRESSION_STRATEGY;
char *RgbCompressData(XImage *image, unsigned int *size)
{
return ZCompressData(image -> data, image -> bytes_per_line * image -> height,
rgbCompressionThreshold, rgbCompressionLevel,
rgbCompressionStrategy, size);
}
/**************************************************************************/
/* */
/* Copyright (c) 2001, 2007 NoMachine, http://www.nomachine.com/. */
/* */
/* NXCOMPEXT, NX protocol compression and NX extensions to this software */
/* are copyright of NoMachine. Redistribution and use of the present */
/* software is allowed according to terms specified in the file LICENSE */
/* which comes in the source distribution. */
/* */
/* Check http://www.nomachine.com/licensing.html for applicability. */
/* */
/* NX and NoMachine are trademarks of NoMachine S.r.l. */
/* */
/* All rigths reserved. */
/* */
/**************************************************************************/
#ifndef Rgb_H
#define Rgb_H
#ifdef __cplusplus
extern "C" {
#endif
extern char *RgbCompressData(
#if NeedFunctionPrototypes
XImage* /* image */,
unsigned int* /* compressed_size */
#endif
);
#ifdef __cplusplus
}
#endif
#endif /* Rgb_H */
/**************************************************************************/
/* */
/* Copyright (c) 2001, 2007 NoMachine, http://www.nomachine.com/. */
/* */
/* NXCOMPEXT, NX protocol compression and NX extensions to this software */
/* are copyright of NoMachine. Redistribution and use of the present */
/* software is allowed according to terms specified in the file LICENSE */
/* which comes in the source distribution. */
/* */
/* Check http://www.nomachine.com/licensing.html for applicability. */
/* */
/* NX and NoMachine are trademarks of NoMachine S.r.l. */
/* */
/* All rigths reserved. */
/* */
/**************************************************************************/
#include <zlib.h>
#include "NXlib.h"
#include "Rle.h"
#include "Z.h"
#define PANIC
#define WARNING
#undef TEST
#undef DEBUG
#define RLE_COMPRESSION_LEVEL 1
#define RLE_COMPRESSION_THRESHOLD 32
#define RLE_COMPRESSION_STRATEGY Z_RLE
static int rleCompressionLevel = RLE_COMPRESSION_LEVEL;
static int rleCompressionThreshold = RLE_COMPRESSION_THRESHOLD;
static int rleCompressionStrategy = RLE_COMPRESSION_STRATEGY;
char *RleCompressData(XImage *image, unsigned int *size)
{
return ZCompressData(image -> data, image -> bytes_per_line * image -> height,
rleCompressionThreshold, rleCompressionLevel,
rleCompressionStrategy, size);
}
/**************************************************************************/
/* */
/* Copyright (c) 2001, 2007 NoMachine, http://www.nomachine.com/. */
/* */
/* NXCOMPEXT, NX protocol compression and NX extensions to this software */
/* are copyright of NoMachine. Redistribution and use of the present */
/* software is allowed according to terms specified in the file LICENSE */
/* which comes in the source distribution. */
/* */
/* Check http://www.nomachine.com/licensing.html for applicability. */
/* */
/* NX and NoMachine are trademarks of NoMachine S.r.l. */
/* */
/* All rigths reserved. */
/* */
/**************************************************************************/
#ifndef Rle_H
#define Rle_H
#ifdef __cplusplus
extern "C" {
#endif
extern char *RleCompressData(
#if NeedFunctionPrototypes
XImage* /* image */,
unsigned int* /* compressed_size */
#endif
);
#ifdef __cplusplus
}
#endif
#endif /* Rle_H */
/**************************************************************************/
/* */
/* Copyright (c) 2001, 2007 NoMachine, http://www.nomachine.com/. */
/* */
/* NXCOMPEXT, NX protocol compression and NX extensions to this software */
/* are copyright of NoMachine. Redistribution and use of the present */
/* software is allowed according to terms specified in the file LICENSE */
/* which comes in the source distribution. */
/* */
/* Check http://www.nomachine.com/licensing.html for applicability. */
/* */
/* NX and NoMachine are trademarks of NoMachine S.r.l. */
/* */
/* All rigths reserved. */
/* */
/**************************************************************************/
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <zlib.h>
#include "NXlib.h"
#include "Z.h"
#define PANIC
#define WARNING
#undef TEST
#undef DEBUG
#define Z_COMPRESSION_LEVEL 4
#define Z_COMPRESSION_THRESHOLD 32
#define Z_COMPRESSION_STRATEGY Z_DEFAULT_STRATEGY
static int zCompressionLevel = Z_COMPRESSION_LEVEL;
static int zCompressionStrategy = Z_COMPRESSION_STRATEGY;
static z_stream *zStream;
static int zInitialized;
static int ZConfigure(int level, int strategy);
static int ZDeflate(char *dest, unsigned int *destLen,
const char *source, unsigned int sourceLen);
char *ZCompressData(const char *plainData, unsigned int plainSize, int threshold,
int level, int strategy, unsigned int *compressedSize)
{
char *compressedData;
/*
* Determine the size of the source image
* data and make sure there is enough
* space in the destination buffer.
*/
*compressedSize = plainSize + (plainSize / 1000) + 12 + 1;
compressedData = Xmalloc(*compressedSize);
if (compressedData == NULL)
{
#ifdef PANIC
fprintf(stderr, "******ZCompressData: PANIC! Failed to allocate [%d] bytes for the destination.\n",
*compressedSize);
#endif
*compressedSize = 0;
return NULL;
}
if (level == Z_NO_COMPRESSION || plainSize < threshold)
{
#ifdef TEST
fprintf(stderr, "******ZCompressData: Not compressing [%d] bytes with level [%d] and "
"threshold [%d].\n", plainSize, level, threshold);
#endif
/*
* Tell in the first byte of the buffer
* if the remaining data is compressed
* or not. This same byte can be used
* in future to store some other flag.
*/
*compressedData = 0;
memcpy(compressedData + 1, plainData, plainSize);
*compressedSize = plainSize + 1;
return compressedData;
}
else
{
int result;
/*
* Reconfigure the stream if needed.
*/
if (zCompressionLevel != level ||
zCompressionStrategy != strategy)
{
ZConfigure(level, strategy);
zCompressionLevel = level;
zCompressionStrategy = strategy;
}
result = ZDeflate(compressedData + 1, compressedSize, plainData, plainSize);
if (result != Z_OK)
{
#ifdef PANIC
fprintf(stderr, "******ZCompressData: PANIC! Failed to compress [%d] bytes with error [%s].\n",
plainSize, zError(result));
#endif
Xfree(compressedData);
*compressedSize = 0;
return NULL;
}
#ifdef TEST
fprintf(stderr, "******ZCompressData: Source data of [%d] bytes compressed to [%d].\n",
plainSize, *compressedSize);
#endif
*compressedData = 1;
*compressedSize = *compressedSize + 1;
return compressedData;
}
}
int ZConfigure(int level, int strategy)
{
/*
* ZLIB wants the avail_out to be
* non zero, even if the stream was
* already flushed.
*/
unsigned char dest[1];
zStream -> next_out = dest;
zStream -> avail_out = 1;
if (deflateParams(zStream, level, strategy) != Z_OK)
{
#ifdef PANIC
fprintf(stderr, "******ZConfigure: PANIC! Failed to set level to [%d] and strategy to [%d].\n",
level, strategy);
#endif
return -1;
}
#ifdef TEST
else
{
fprintf(stderr, "******ZConfigure: Reconfigured the stream with level [%d] and strategy [%d].\n",
level, strategy);
}
#endif
return 1;
}
int ZDeflate(char *dest, unsigned int *destLen, const char *source, unsigned int sourceLen)
{
int saveOut;
int result;
/*
* Deal with the possible overflow.
*/
if (zStream -> total_out & 0x80000000)
{
#ifdef TEST
fprintf(stderr, "******ZDeflate: Reset Z stream counters with total in [%ld] total out [%ld].\n",
zStream -> total_in, zStream -> total_out);
#endif
zStream -> total_in = 0;
zStream -> total_out = 0;
}
saveOut = zStream -> total_out;
zStream -> next_in = (Bytef *) source;
zStream -> avail_in = (uInt) sourceLen;
#ifdef MAXSEG_64K
/*
* Check if the source is greater
* than 64K on a 16-bit machine.
*/
if ((uLong) zStream -> avail_in != sourceLen) return Z_BUF_ERROR;
#endif
zStream -> next_out = (unsigned char *) dest;
zStream -> avail_out = (uInt) *destLen;
if ((uLong) zStream -> avail_out != *destLen) return Z_BUF_ERROR;
result = deflate(zStream, Z_FINISH);
if (result != Z_STREAM_END)
{
deflateReset(zStream);
return (result == Z_OK ? Z_BUF_ERROR : result);
}
*destLen = zStream -> total_out - saveOut;
result = deflateReset(zStream);
return result;
}
int ZInitEncoder()
{
if (zInitialized == 0)
{
int result;
zStream = Xmalloc(sizeof(z_stream));
if (zStream == NULL)
{
#ifdef PANIC
fprintf(stderr, "******ZInitEncoder: PANIC! Failed to allocate memory for the stream.\n");
#endif
return -1;
}
zStream -> zalloc = (alloc_func) 0;
zStream -> zfree = (free_func) 0;
zStream -> opaque = (voidpf) 0;
#ifdef TEST
fprintf(stderr, "******ZInitEncoder: Initializing compressor with level [%d] and startegy [%d].\n",
zCompressionLevel, zCompressionStrategy);
#endif
result = deflateInit2(zStream, zCompressionLevel, Z_DEFLATED,
15, 9, zCompressionStrategy);
if (result != Z_OK)
{
#ifdef PANIC
fprintf(stderr, "******ZInitEncoder: Failed to initialize the compressor with error [%s].\n",
zError(result));
#endif
return -1;
}
zInitialized = 1;
}
return zInitialized;
}
int ZResetEncoder()
{
int result;
if (zInitialized == 1)
{
result = deflateEnd(zStream);
if (result != Z_OK)
{
#ifdef WARNING
fprintf(stderr, "******ZResetEncoder: WARNING! Failed to deinitialize the compressor with error [%s].\n",
zError(result));
#endif
}
Xfree(zStream);
}
zInitialized = 0;
return 1;
}
/**************************************************************************/
/* */
/* Copyright (c) 2001, 2007 NoMachine, http://www.nomachine.com/. */
/* */
/* NXCOMPEXT, NX protocol compression and NX extensions to this software */
/* are copyright of NoMachine. Redistribution and use of the present */
/* software is allowed according to terms specified in the file LICENSE */
/* which comes in the source distribution. */
/* */
/* Check http://www.nomachine.com/licensing.html for applicability. */
/* */
/* NX and NoMachine are trademarks of NoMachine S.r.l. */
/* */
/* All rigths reserved. */
/* */
/**************************************************************************/
#ifndef Z_H
#define Z_H
#ifdef __cplusplus
extern "C" {
#endif
int ZInitEncoder(
#if NeedFunctionPrototypes
void
#endif
);
int ZResetEncoder(
#if NeedFunctionPrototypes
void
#endif
);
extern char *ZCompressData(
#if NeedFunctionPrototypes
const char* /* data */,
unsigned int /* size */,
int /* threshold */,
int /* level */,
int /* strategy */,
unsigned int* /* compressed_size */
#endif
);
#ifdef __cplusplus
}
#endif
#endif /* Z_H */
This source diff could not be displayed because it is too large. You can view the blob instead.
dnl Process this file with autoconf to produce a configure script.
dnl Prolog
AC_INIT(NXlib.h)
AC_PREREQ(2.13)
dnl Reset default compilation flags.
CXXFLAGS="-O3"
CFLAGS="-O3"
dnl Reset default linking directives.
LIBSTATIC=""
LIBSHARED=""
dnl Prefer headers and libraries from nx-X11, if present.
if test -d "../nx-X11/include" ; then
CXXFLAGS="$CXXFLAGS -I../nx-X11/exports/include -I../nx-X11/lib/X11 \
-I../nx-X11/include -I../nx-X11/programs/Xserver/include"
CFLAGS="$CFLAGS -I../nx-X11/exports/include -I../nx-X11/lib/X11 \
-I../nx-X11/include -I../nx-X11/programs/Xserver/include"
LDFLAGS="$LDFLAGS -L../nx-X11/exports/lib"
fi
dnl Check for programs.
AC_PROG_CXX
AC_PROG_CC
AC_LANG_CPLUSPLUS
dnl Check for BSD compatible install.
AC_PROG_INSTALL
dnl Check for extra header files.
AC_PATH_XTRA
dnl Custom addition.
ac_help="$ac_help
--with-symbols add the -g flag to produce the debug symbols
--with-info enable basic log output to trace the program
--with-valgrind clean up allocated buffers to avoid valgrind warnings
--with-version use this version for produced libraries
--with-static-png enable static linking of PNG library
--with-static-jpeg enable static linking of JPEG library"
dnl Check to see if we're running under Cygwin32.
AC_DEFUN(nxproxy_CYGWIN32,
[AC_CACHE_CHECK(for Cygwin32 environment, nxproxy_cv_cygwin32,
[AC_TRY_COMPILE(,[return __CYGWIN32__;],
nxproxy_cv_cygwin32=yes, nxproxy_cv_cygwin32=no)
rm -f conftest*])
CYGWIN32=
test "$nxproxy_cv_cygwin32" = yes && CYGWIN32=yes])
dnl CygWin32 requires the stdc++ library explicitly linked.
nxproxy_CYGWIN32
if test "$CYGWIN32" = yes; then
LIBS="$LIBS -mwindows -lstdc++"
fi
dnl Check whether we're building on a AMD64.
AC_DEFUN(nxconf_AMD64,
[AC_CACHE_CHECK(for Amd64 environment, nxconf_cv_amd64,
[AC_TRY_COMPILE(,[return (__amd64__ || __x86_64__);],
nxconf_cv_amd64=yes, nxconf_cv_amd64=no)
rm -f conftest*])
AMD64=
test "$nxconf_cv_amd64" = yes && AMD64=yes])
nxconf_AMD64
dnl Check to see if we're running under Solaris.
AC_DEFUN(nxconf_SUN,
[AC_CACHE_CHECK(for SunOS environment, nxconf_cv_sun,
[AC_TRY_COMPILE(,[return __sun;],
nxconf_cv_sun=yes, nxconf_cv_sun=no)
rm -f conftest*])
SUN=
test "$nxconf_cv_sun" = yes && SUN=yes])
nxconf_SUN
if test "$SUN" = yes; then
CFLAGS="$CFLAGS -I/usr/sfw/include"
fi
if test "$SUN" = yes; then
LDFLAGS="$LDFLAGS -G -h \$(LIBLOAD) -L/usr/sfw/lib"
else
LDFLAGS="$LDFLAGS -shared -Wl,-soname,\$(LIBLOAD)"
fi
dnl Check to see if we're running under FreeBSD.
AC_DEFUN(nxconf_FreeBSD,
[AC_CACHE_CHECK(for FreeBSD environment, nxconf_cv_freebsd,
[AC_TRY_COMPILE(,[return __FreeBSD__;],
nxconf_cv_freebsd=yes, nxconf_cv_freebsd=no)
rm -f conftest*])
FreeBSD=
test "$nxconf_cv_freebsd" = yes && FreeBSD=yes])
nxconf_FreeBSD
dnl Build PIC libraries.
if test "$CYGWIN32" != yes -a "$DARWIN" != yes; then
CXXFLAGS="$CXXFLAGS -fPIC"
CFLAGS="$CFLAGS -fPIC"
fi
dnl On FreeBSD search libraries and includes under /usr/local.
if test "$FreeBSD" = yes; then
LIBS="$LIBS -L/usr/local/lib"
CXXFLAGS="$CXXFLAGS -I/usr/local/include"
CFLAGS="$CFLAGS -I/usr/local/include"
fi
dnl Check whether --with-static-png was
dnl given and add -lpng or libpng.a to linking.
if test "${with_static_png}" = yes; then
echo -e "enabling static linking of PNG library"
if test "$CYGWIN32" = yes; then
LIBS="$LIBSTATIC -static -lpng"
else
if test -f "/usr/lib/libpng.a" ; then
LIBS="/usr/lib/libpng.a $LIBS"
else
if test -f "/usr/local/lib/libpng.a" ; then
echo -e "assuming libpng.a in /usr/local/lib"
LIBS="/usr/local/lib/libpng.a $LIBS"
else
echo -e "assuming libpng.a in default linker path"
LIBS="libpng.a $LIBS"
fi
fi
fi
else
echo -e "enabling dynamic linking of PNG library"
LIBS="-lpng $LIBS"
fi
dnl Check whether --with-static-jpeg was
dnl given and add -ljpeg or libjpeg.a to linking.
if test "${with_static_jpeg}" = yes; then
echo -e "enabling static linking of JPEG library"
if test "$CYGWIN32" = yes; then
LIBSTATIC="$LIBS -static -ljpeg"
else
if test -f "/usr/lib/libjpeg.a" ; then
LIBS="/usr/lib/libjpeg.a $LIBS"
else
if test -f "/usr/local/lib/libjpeg.a" ; then
echo -e "assuming libjpeg.a in /usr/local/lib"
LIBS="/usr/local/lib/libjpeg.a $LIBS"
else
echo -e "assuming libjpeg.a in default linker path"
LIBS="libjpeg.a $LIBS"
fi
fi
fi
else
echo -e "enabling dynamic linking of JPEG library"
LIBS="-ljpeg $LIBS"
fi
dnl Check whether --with-symbols or --without-symbols was
dnl given and set the required optimization level.
if test "${with_symbols}" = yes; then
echo -e "enabling production of debug symbols"
CXXFLAGS="-g $CXXFLAGS"
CFLAGS="-g $CFLAGS"
else
echo -e "disabling production of debug symbols"
fi
dnl Check whether --with-info or --without-info was given.
if test "${with_info}" = yes; then
echo -e "enabling info output in the log file"
CXXFLAGS="$CXXFLAGS -DINFO"
CFLAGS="$CFLAGS -DINFO"
else
echo -e "disabling info output in the log file"
fi
dnl Check whether --with-valgrind or --without-valgrind was given.
if test "${with_valgrind}" = yes; then
echo -e "enabling valgrind memory checker workarounds"
CXXFLAGS="$CXXFLAGS -DVALGRIND"
CFLAGS="$CFLAGS -DVALGRIND"
else
echo -e "disabling valgrind memory checker workarounds"
fi
dnl Check whether --with-version was given.
AC_SUBST(LIBVERSION)
AC_SUBST(VERSION)
if test "${with_version}" = yes; then
VERSION=${ac_option}
else
VERSION=`cat VERSION`
fi
echo -e "compiling version ${VERSION}"
LIBVERSION=`echo ${VERSION} | cut -d '.' -f 1`
CXXFLAGS="$CXXFLAGS -DVERSION=\\\"${VERSION}\\\""
CFLAGS="$CFLAGS -DVERSION=\\\"${VERSION}\\\""
dnl Find makedepend somewhere.
AC_SUBST(MAKEDEPEND)
if test -x "../nx-X11/config/makedepend/makedepend" ; then
MAKEDEPEND=../nx-X11/config/makedepend/makedepend
else
if test -x "/usr/X11R6/bin/makedepend" ; then
MAKEDEPEND=/usr/X11R6/bin/makedepend
else
if test -x "/usr/openwin/bin/makedepend" ; then
MAKEDEPEND=/usr/openwin/bin/makedepend
else
MAKEDEPEND=/usr/bin/makedepend
fi
fi
fi
dnl Determine what to build based on the platform.
dnl Override the LIBS settings on Cygwin32 so that
dnl we always link with the exact set of libraries.
AC_SUBST(ALL)
if test "$CYGWIN32" = yes; then
ALL="\$(LIBCYGARCHIVE) \$(LIBCYGSHARED) \$(LIBARCHIVE)"
else
ALL="\$(LIBFULL) \$(LIBLOAD) \$(LIBSHARED) \$(LIBARCHIVE)"
fi
AC_OUTPUT(Makefile)
#! /bin/sh
#
# install - install a program, script, or datafile
# This comes from X11R5.
#
# Calling this script install-sh is preferred over install.sh, to prevent
# `make' implicit rules from creating a file called install from it
# when there is no Makefile.
#
# This script is compatible with the BSD install script, but was written
# from scratch.
#
# set DOITPROG to echo to test this script
# Don't use :- since 4.3BSD and earlier shells don't like it.
doit="${DOITPROG-}"
# put in absolute paths if you don't have them in your path; or use env. vars.
mvprog="${MVPROG-mv}"
cpprog="${CPPROG-cp}"
chmodprog="${CHMODPROG-chmod}"
chownprog="${CHOWNPROG-chown}"
chgrpprog="${CHGRPPROG-chgrp}"
stripprog="${STRIPPROG-strip}"
rmprog="${RMPROG-rm}"
mkdirprog="${MKDIRPROG-mkdir}"
transformbasename=""
transform_arg=""
instcmd="$mvprog"
chmodcmd="$chmodprog 0755"
chowncmd=""
chgrpcmd=""
stripcmd=""
rmcmd="$rmprog -f"
mvcmd="$mvprog"
src=""
dst=""
dir_arg=""
while [ x"$1" != x ]; do
case $1 in
-c) instcmd="$cpprog"
shift
continue;;
-d) dir_arg=true
shift
continue;;
-m) chmodcmd="$chmodprog $2"
shift
shift
continue;;
-o) chowncmd="$chownprog $2"
shift
shift
continue;;
-g) chgrpcmd="$chgrpprog $2"
shift
shift
continue;;
-s) stripcmd="$stripprog"
shift
continue;;
-t=*) transformarg=`echo $1 | sed 's/-t=//'`
shift
continue;;
-b=*) transformbasename=`echo $1 | sed 's/-b=//'`
shift
continue;;
*) if [ x"$src" = x ]
then
src=$1
else
# this colon is to work around a 386BSD /bin/sh bug
:
dst=$1
fi
shift
continue;;
esac
done
if [ x"$src" = x ]
then
echo "install: no input file specified"
exit 1
else
true
fi
if [ x"$dir_arg" != x ]; then
dst=$src
src=""
if [ -d $dst ]; then
instcmd=:
else
instcmd=mkdir
fi
else
# Waiting for this to be detected by the "$instcmd $src $dsttmp" command
# might cause directories to be created, which would be especially bad
# if $src (and thus $dsttmp) contains '*'.
if [ -f $src -o -d $src ]
then
true
else
echo "install: $src does not exist"
exit 1
fi
if [ x"$dst" = x ]
then
echo "install: no destination specified"
exit 1
else
true
fi
# If destination is a directory, append the input filename; if your system
# does not like double slashes in filenames, you may need to add some logic
if [ -d $dst ]
then
dst="$dst"/`basename $src`
else
true
fi
fi
## this sed command emulates the dirname command
dstdir=`echo $dst | sed -e 's,[^/]*$,,;s,/$,,;s,^$,.,'`
# Make sure that the destination directory exists.
# this part is taken from Noah Friedman's mkinstalldirs script
# Skip lots of stat calls in the usual case.
if [ ! -d "$dstdir" ]; then
defaultIFS='
'
IFS="${IFS-${defaultIFS}}"
oIFS="${IFS}"
# Some sh's can't handle IFS=/ for some reason.
IFS='%'
set - `echo ${dstdir} | sed -e 's@/@%@g' -e 's@^%@/@'`
IFS="${oIFS}"
pathcomp=''
while [ $# -ne 0 ] ; do
pathcomp="${pathcomp}${1}"
shift
if [ ! -d "${pathcomp}" ] ;
then
$mkdirprog "${pathcomp}"
else
true
fi
pathcomp="${pathcomp}/"
done
fi
if [ x"$dir_arg" != x ]
then
$doit $instcmd $dst &&
if [ x"$chowncmd" != x ]; then $doit $chowncmd $dst; else true ; fi &&
if [ x"$chgrpcmd" != x ]; then $doit $chgrpcmd $dst; else true ; fi &&
if [ x"$stripcmd" != x ]; then $doit $stripcmd $dst; else true ; fi &&
if [ x"$chmodcmd" != x ]; then $doit $chmodcmd $dst; else true ; fi
else
# If we're going to rename the final executable, determine the name now.
if [ x"$transformarg" = x ]
then
dstfile=`basename $dst`
else
dstfile=`basename $dst $transformbasename |
sed $transformarg`$transformbasename
fi
# don't allow the sed command to completely eliminate the filename
if [ x"$dstfile" = x ]
then
dstfile=`basename $dst`
else
true
fi
# Make a temp file name in the proper directory.
dsttmp=$dstdir/#inst.$$#
# Move or copy the file name to the temp name
$doit $instcmd $src $dsttmp &&
trap "rm -f ${dsttmp}" 0 &&
# and set any options; do chmod last to preserve setuid bits
# If any of these fail, we abort the whole thing. If we want to
# ignore errors from any of these, just make sure not to ignore
# errors from the above "$doit $instcmd $src $dsttmp" command.
if [ x"$chowncmd" != x ]; then $doit $chowncmd $dsttmp; else true;fi &&
if [ x"$chgrpcmd" != x ]; then $doit $chgrpcmd $dsttmp; else true;fi &&
if [ x"$stripcmd" != x ]; then $doit $stripcmd $dsttmp; else true;fi &&
if [ x"$chmodcmd" != x ]; then $doit $chmodcmd $dsttmp; else true;fi &&
# Now rename the file to the real destination.
$doit $rmcmd -f $dstdir/$dstfile &&
$doit $mvcmd $dsttmp $dstdir/$dstfile
fi &&
exit 0
#! /bin/sh
# mkinstalldirs --- make directory hierarchy
# Author: Noah Friedman <friedman@prep.ai.mit.edu>
# Created: 1993-05-16
# Last modified: 1995-03-05
# Public domain
errstatus=0
for file in ${1+"$@"} ; do
set fnord `echo ":$file" | sed -ne 's/^:\//#/;s/^://;s/\// /g;s/^#/\//;p'`
shift
pathcomp=
for d in ${1+"$@"} ; do
pathcomp="$pathcomp$d"
case "$pathcomp" in
-* ) pathcomp=./$pathcomp ;;
esac
if test ! -d "$pathcomp"; then
echo "mkdir $pathcomp" 1>&2
mkdir "$pathcomp" > /dev/null 2>&1 || lasterr=$?
fi
if test ! -d "$pathcomp"; then
errstatus=$lasterr
fi
pathcomp="$pathcomp/"
done
done
exit $errstatus
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment