diff options
Diffstat (limited to 'nx-X11/programs/Xserver/hw/nxagent/Image.c')
-rw-r--r-- | nx-X11/programs/Xserver/hw/nxagent/Image.c | 521 |
1 files changed, 200 insertions, 321 deletions
diff --git a/nx-X11/programs/Xserver/hw/nxagent/Image.c b/nx-X11/programs/Xserver/hw/nxagent/Image.c index e55ed2dd2..34d5cf9f9 100644 --- a/nx-X11/programs/Xserver/hw/nxagent/Image.c +++ b/nx-X11/programs/Xserver/hw/nxagent/Image.c @@ -59,9 +59,8 @@ #undef DUMP /* - * Don't pack the images having a width, a - * height or a data size smaller or equal - * to these thresholds. + * Don't pack the images having a width, a height or a data size + * smaller or equal to these thresholds. */ #define IMAGE_PACK_WIDTH 2 @@ -69,16 +68,14 @@ #define IMAGE_PACK_LENGTH 512 /* - * Compress the image with a lossless encoder - * if the percentage of discrete pixels in the - * image is below this threshold. + * Compress the image with a lossless encoder if the percentage of + * discrete pixels in the image is below this threshold. */ #define IMAGE_UNIQUE_RATIO 10 /* - * Preferred pack and split parameters we - * got from the NX transport. + * Preferred pack and split parameters we got from the NX transport. */ int nxagentPackLossless = -1; @@ -94,8 +91,8 @@ int nxagentAlphaEnabled = 0; int nxagentAlphaCompat = 0; /* - * Used to reformat image when connecting to - * displays having different byte order. + * Used to reformat image when connecting to displays having different + * byte order. */ extern void nxagentBitOrderInvert(unsigned char *, int); @@ -103,22 +100,20 @@ extern void nxagentTwoByteSwap(unsigned char *, register int); extern void nxagentFourByteSwap(register unsigned char *, register int); /* - * Store the last visual used to unpack - * the images for the given client. + * Store the last visual used to unpack the images for the given + * client. */ static VisualID nxagentUnpackVisualId[MAX_CONNECTIONS]; /* - * Store the last alpha data set for the - * client. + * Store the last alpha data set for the client. */ typedef struct _UnpackAlpha { char *data; int size; - } UnpackAlphaRec; typedef UnpackAlphaRec *UnpackAlphaPtr; @@ -126,9 +121,8 @@ typedef UnpackAlphaRec *UnpackAlphaPtr; static UnpackAlphaPtr nxagentUnpackAlpha[MAX_CONNECTIONS]; /* - * Encode the imade alpha channel by using - * a specific encoding, separating it from - * the rest of the RGB data. + * Encode the imade alpha channel by using a specific encoding, + * separating it from the rest of the RGB data. */ static char *nxagentImageAlpha(XImage *ximage); @@ -141,10 +135,9 @@ static void nxagentSetUnpackAlpha(DrawablePtr pDrawable, XImage *pImage, ClientP static char *nxagentImageCopy(XImage *source, XImage *destination); /* - * Return true if the image can be cached. - * Don't cache the images packed with the - * bitmap method as the encoding is little - * more expensive than a copy. + * Return true if the image can be cached. Don't cache the images + * packed with the bitmap method as the encoding is little more + * expensive than a copy. */ #define nxagentNeedCache(image, method) \ @@ -152,10 +145,8 @@ static char *nxagentImageCopy(XImage *source, XImage *destination); ((method) != PACK_BITMAP_16M_COLORS) /* - * With the bitmap encoding, if the image - * is 32 bits-per-pixel the 4th byte is not - * transmitted, so we don't need to clean - * the image. + * With the bitmap encoding, if the image is 32 bits-per-pixel the 4th + * byte is not transmitted, so we don't need to clean the image. */ #define nxagentNeedClean(image, method) \ @@ -180,7 +171,6 @@ typedef struct _ImageStatisticsRec double totalMatches; double totalEncoded; double totalAdded; - } ImageStatisticsRec; ImageStatisticsRec nxagentImageStatistics; @@ -188,11 +178,10 @@ ImageStatisticsRec nxagentImageStatistics; int nxagentImageReformat(char *base, int nbytes, int bpp, int order) { /* - * This is used whenever we need to swap the image data. - * If we got an image from an X server having a different - * endianness, we will need to reformat the image to match - * our own image-order so that ProcGetImage can return - * the expected format to the client. + * This is used whenever we need to swap the image data. If we got + * an image from an X server having a different endianness, we will + * need to reformat the image to match our own image-order so that + * ProcGetImage can return the expected format to the client. */ switch (bpp) @@ -266,7 +255,6 @@ int nxagentImageLength(int width, int height, int format, int leftPad, int depth else if (format == XYPixmap) { line = BitmapBytePad(width + leftPad); - line *= depth; } else if (format == ZPixmap) @@ -298,10 +286,9 @@ int nxagentImagePad(int width, int format, int leftPad, int depth) } /* - * Only copy the data, not the structure. - * The data pointed by the destination is - * lost. Used to clone two images that - * point to the same data. + * Only copy the data, not the structure. The data pointed by the + * destination is lost. Used to clone two images that point to the + * same data. */ char *nxagentImageCopy(XImage *source, XImage *destination) @@ -330,21 +317,13 @@ char *nxagentImageCopy(XImage *source, XImage *destination) char *nxagentImageAlpha(XImage *image) { - char *pData; - - char *pSrcData; - char *pDstData; - - int size; - int offset; - /* * Use one byte per pixel. */ - size = (image -> bytes_per_line * image -> height) >> 2; + int size = (image -> bytes_per_line * image -> height) >> 2; - pData = malloc(size); + char *pData = malloc(size); if (pData == NULL) { @@ -352,14 +331,13 @@ char *nxagentImageAlpha(XImage *image) } /* - * The image is supposed to be in - * server order. + * The image is supposed to be in server order. */ - offset = (image -> byte_order == MSBFirst) ? 0 : 3; + int offset = (image -> byte_order == MSBFirst) ? 0 : 3; - pSrcData = image -> data; - pDstData = pData; + char *pSrcData = image -> data; + char *pDstData = pData; while (size-- > 0) { @@ -372,8 +350,7 @@ char *nxagentImageAlpha(XImage *image) } /* - * Write down the image cache statistics - * to the buffer. + * Write down the image cache statistics to the buffer. */ void nxagentImageStatisticsHandler(char **buffer, int type) @@ -389,9 +366,8 @@ FIXME: Agent cache statistics have to be implemented. } /* - * This should be called only for drawables - * having a depth of 32. In the other cases, - * it would only generate useless traffic. + * This should be called only for drawables having a depth of 32. In + * the other cases, it would only generate useless traffic. */ void nxagentSetUnpackAlpha(DrawablePtr pDrawable, XImage *pImage, ClientPtr pClient) @@ -412,16 +388,15 @@ void nxagentSetUnpackAlpha(DrawablePtr pDrawable, XImage *pImage, ClientPtr pCli } /* - * If we are synchronizing the drawable, discard - * any unpack alpha stored for the client. The - * alpha data, in fact, may be still traveling - * and so we either wait until the end of the - * split or send a fresh copy. + * If we are synchronizing the drawable, discard any unpack alpha + * stored for the client. The alpha data, in fact, may be still + * traveling and so we either wait until the end of the split or + * send a fresh copy. */ /* -FIXME: Here the split trap is always set and so the caching of - the alpha channel is useless. I remember we set the trap - because of the cursor but why is it always set now? +FIXME: Here the split trap is always set and so the caching of the + alpha channel is useless. I remember we set the trap because of + the cursor but why is it always set now? */ #ifdef DEBUG fprintf(stderr, "nxagentSetUnpackAlpha: Checking alpha channel for client [%d] with trap [%d].\n", @@ -439,9 +414,8 @@ FIXME: Here the split trap is always set and so the caching of #endif /* - * Check if we are connected to a newer proxy - * version and so can send the alpha data in - * compressed form. + * Check if we are connected to a newer proxy version and so can + * send the alpha data in compressed form. */ if (nxagentAlphaCompat == 0) @@ -488,16 +462,14 @@ FIXME: Here the split trap is always set and so the caching of } /* - * The NX agent's implementation of the - * X server's image functions. + * The NX agent's implementation of the X server's image functions. */ void nxagentPutImage(DrawablePtr pDrawable, GCPtr pGC, int depth, int dstX, int dstY, int dstWidth, int dstHeight, int leftPad, int format, char *data) { - int length; - + /* will be checked at nxagentPutImageEnd */ RegionPtr pRegion = NullRegion; int resource = 0; @@ -511,21 +483,18 @@ void nxagentPutImage(DrawablePtr pDrawable, GCPtr pGC, int depth, #endif /* - * If the display is down and there is not an - * nxagent attached, sleep for a while but - * still give a chance to the client to write + * If the display is down and there is not an nxagent attached, + * sleep for a while but still give a chance to the client to write * to the framebuffer. */ - length = nxagentImageLength(dstWidth, dstHeight, format, leftPad, depth); + int length = nxagentImageLength(dstWidth, dstHeight, format, leftPad, depth); if (nxagentShadowCounter == 0 && NXDisplayError(nxagentDisplay) == 1 && nxagentOption(SleepTime) > 0) { - int us; - - us = nxagentOption(SleepTime) * 4 * (length / 1024); + int us = nxagentOption(SleepTime) * 4 * (length / 1024); us = (us < 10000 ? 10000 : (us > 1000000 ? 1000000 : us)); @@ -538,11 +507,11 @@ void nxagentPutImage(DrawablePtr pDrawable, GCPtr pGC, int depth, } /* - * This is of little use because clients usually write - * to windows only after an expose event, and, in the - * rare case they use a direct put image to the window - * (for a media player it should be a necessity), they - * are likely to monitor the visibility of the window. + * This is of little use because clients usually write to windows + * only after an expose event, and, in the rare case they use a + * direct put image to the window (for a media player it should be a + * necessity), they are likely to monitor the visibility of the + * window. */ if (nxagentOption(IgnoreVisibility) == 0 && pDrawable -> type == DRAWABLE_WINDOW && @@ -559,9 +528,8 @@ void nxagentPutImage(DrawablePtr pDrawable, GCPtr pGC, int depth, } /* - * This is more interesting. Check if the operation - * will produce a visible result based on the clip - * list of the window and the GC. + * This is more interesting. Check if the operation will produce a + * visible result based on the clip list of the window and the GC. */ pRegion = nxagentCreateRegion(pDrawable, pGC, dstX, dstY, dstWidth, dstHeight); @@ -618,9 +586,8 @@ FIXME: Should use these. } /* - * We are going to realize the operation - * on the real display. Let's check if - * the link is down. + * We are going to realize the operation on the real display. Let's + * check if the link is down. */ if (NXDisplayError(nxagentDisplay) == 1) @@ -629,13 +596,11 @@ FIXME: Should use these. } /* - * Mark the region as corrupted and skip the operation - * if we went out of bandwidth. The drawable will be - * synchronized at later time. Don't do that if the - * image is likely to be a shape or a clip mask, if we - * are here because we are actually synchronizing the - * drawable or if the drawable's corrupted region is - * over-age. + * Mark the region as corrupted and skip the operation if we went + * out of bandwidth. The drawable will be synchronized at later + * time. Don't do that if the image is likely to be a shape or a + * clip mask, if we are here because we are actually synchronizing + * the drawable or if the drawable's corrupted region is over-age. */ if (NXAGENT_SHOULD_DEFER_PUTIMAGE(pDrawable)) @@ -687,8 +652,7 @@ FIXME: Should use these. #endif /* - * Check whether we need to enclose the - * image in a split sequence. + * Check whether we need to enclose the image in a split sequence. */ /* FIXME: Should we disable the split with link LAN? @@ -700,12 +664,11 @@ FIXME: Should we disable the split with link LAN? split = (nxagentOption(Streaming) == 1 && nxagentOption(LinkType) != LINK_TYPE_NONE /* -FIXME: Do we stream the images from GLX or Xv? If we do that, - we should also write on the frame buffer, including the - images put on windows, to be able to reconstruct the - region that is out of sync. Surely we should not try to - cache the GLX and Xv images in memory or save them in - the image cache on disk. +FIXME: Do we stream the images from GLX or Xv? If we do that, we + should also write on the frame buffer, including the images put + on windows, to be able to reconstruct the region that is out of + sync. Surely we should not try to cache the GLX and Xv images + in memory or save them in the image cache on disk. */ /* FIXME: Temporarily stream the GLX data. @@ -716,21 +679,18 @@ FIXME: Temporarily stream the GLX data. ); /* - * Never split images whose depth - * is less than 15. + * Never split images whose depth is less than 15. */ if (split == 1 && (nxagentSplitTrap == 1 || depth < 15)) { #ifdef TEST - if (nxagentSplitTrap == 1 || nxagentReconnectTrap == 1) { fprintf(stderr, "nxagentPutImage: Not splitting with reconnection [%d] trap [%d] " "depth [%d].\n", nxagentSplitTrap, nxagentReconnectTrap, depth); } - #endif split = 0; @@ -744,7 +704,6 @@ FIXME: Temporarily stream the GLX data. #endif #ifdef TEST - if (split == 1) { fprintf(stderr, "nxagentPutImage: Splitting the image with size [%d] " @@ -757,13 +716,11 @@ FIXME: Temporarily stream the GLX data. "link [%d] GLX [%d] Xv [%d].\n", length, nxagentOption(LinkType), nxagentGlxTrap, nxagentXvTrap); } - #endif /* - * If the image was originated by a GLX - * or Xvideo request, temporarily disable - * the use of the cache. + * If the image was originated by a GLX or Xvideo request, + * temporarily disable the use of the cache. */ if (nxagentOption(LinkType) != LINK_TYPE_NONE && @@ -779,17 +736,15 @@ FIXME: Temporarily stream the GLX data. } /* - * Enclose the next messages in a split - * sequence. The proxy will tell us if - * the split took place. + * Enclose the next messages in a split sequence. The proxy will + * tell us if the split took place. */ if (split == 1) { /* - * If the drawable is already being split, - * expand the region. Currently drawables - * can't have more than a single split + * If the drawable is already being split, expand the + * region. Currently drawables can't have more than a single split * region. */ @@ -800,9 +755,8 @@ FIXME: Temporarily stream the GLX data. (void *) pDrawable); #endif /* -FIXME: Should probably intersect the region with - the region being split to also invalidate - the commits. +FIXME: Should probably intersect the region with the region being + split to also invalidate the commits. */ nxagentMarkCorruptedRegion(pDrawable, pRegion); @@ -811,9 +765,8 @@ FIXME: Should probably intersect the region with else { /* - * Assign a new resource to the drawable. - * Will also assign the GC to use for the - * operation. + * Assign a new resource to the drawable. Will also assign the + * GC to use for the operation. */ resource = nxagentCreateSplit(pDrawable, &pGC); @@ -835,12 +788,11 @@ FIXME: Should probably intersect the region with NXEndSplit(nxagentDisplay, resource); /* - * Now we need to check if all the messages went - * straight through the output stream or any of - * them required a split. If no split will take - * place, we will remove the association with the - * drawable and release the resource at the time - * we will handle the no-split event. + * Now we need to check if all the messages went straight through + * the output stream or any of them required a split. If no split + * will take place, we will remove the association with the + * drawable and release the resource at the time we will handle + * the no-split event. */ split = nxagentWaitSplitEvent(resource); @@ -854,10 +806,9 @@ FIXME: Should probably intersect the region with #endif /* - * Marking the corrupted region we will check - * if the region intersects the split region, - * therefore the split region must be added - * later. + * Marking the corrupted region we will check if the region + * intersects the split region, therefore the split region must + * be added later. */ nxagentMarkCorruptedRegion(pDrawable, pRegion); @@ -873,9 +824,8 @@ FIXME: Should probably intersect the region with } /* - * The split value could be changed by a - * no-split event in the block above, so - * here we have to check the value again. + * The split value could be changed by a no-split event in the block + * above, so here we have to check the value again. */ if (split == 0) @@ -883,9 +833,8 @@ FIXME: Should probably intersect the region with if (nxagentDrawableStatus(pDrawable) == NotSynchronized) { /* - * We just covered the drawable with - * a solid image. We can consider the - * overlapping region as synchronized. + * We just covered the drawable with a solid image. We can + * consider the overlapping region as synchronized. */ #ifdef TEST @@ -923,15 +872,9 @@ void nxagentRealizeImage(DrawablePtr pDrawable, GCPtr pGC, int depth, int x, int y, int w, int h, int leftPad, int format, char *data) { - int length; - - int bytesPerLine; - int numSubImages; - int totalHeight; - /* - * NXPutPackedImage is longer than PutPackedImage - * so that we subtract the bigger one to be sure. + * NXPutPackedImage is longer than PutPackedImage so that we + * subtract the bigger one to be sure. */ const int subSize = (MAX_REQUEST_SIZE << 2) - sizeof(xNXPutPackedImageReq); @@ -942,7 +885,6 @@ void nxagentRealizeImage(DrawablePtr pDrawable, GCPtr pGC, int depth, XImage *image = NULL; - if (NXDisplayError(nxagentDisplay) == 1) { #ifdef TEST @@ -953,8 +895,7 @@ void nxagentRealizeImage(DrawablePtr pDrawable, GCPtr pGC, int depth, } /* - * Get the visual according to the - * drawable and depth. + * Get the visual according to the drawable and depth. */ pVisual = nxagentImageVisual(pDrawable, depth); @@ -972,21 +913,21 @@ void nxagentRealizeImage(DrawablePtr pDrawable, GCPtr pGC, int depth, * Get bytes per line according to format. */ - bytesPerLine = nxagentImagePad(w, format, leftPad, depth); + int bytesPerLine = nxagentImagePad(w, format, leftPad, depth); if (nxagentOption(Shadow) == 1 && format == ZPixmap && (nxagentOption(XRatio) != DONT_SCALE || nxagentOption(YRatio) != DONT_SCALE) && pDrawable == (DrawablePtr) nxagentShadowPixmapPtr) { - int scaledx; - int scaledy; - image = XCreateImage(nxagentDisplay, pVisual, depth, ZPixmap, 0, data, w, h, BitmapPad(nxagentDisplay), bytesPerLine); if (image != NULL) { + int scaledx; + int scaledy; + image -> byte_order = IMAGE_BYTE_ORDER; image -> bitmap_bit_order = BITMAP_BIT_ORDER; @@ -1021,13 +962,13 @@ void nxagentRealizeImage(DrawablePtr pDrawable, GCPtr pGC, int depth, goto nxagentRealizeImageEnd; } - totalHeight = h; + int totalHeight = h; - length = bytesPerLine * h; + int length = bytesPerLine * h; h = (subSize < length ? subSize : length) / bytesPerLine; - numSubImages = totalHeight / h + 1; + int numSubImages = totalHeight / h + 1; while (numSubImages > 0) { @@ -1096,13 +1037,13 @@ void nxagentPutSubImage(DrawablePtr pDrawable, GCPtr pGC, int depth, /* * XCreateImage is the place where the leftPad should be passed. - * The image data is received from our client unmodified. In - * theory what we would need to do is just creating an appropri- - * ate XImage structure based on the incoming data and let Xlib - * do the rest. Probably we don't have to pass leftPad again in - * the src_x of XPutImage otherwise the src_x would make Xlib - * to take into account the xoffset field twice. Unfortunately - * passing the leftPad doesn't work. + * The image data is received from our client unmodified. In theory + * what we would need to do is just creating an appropriate XImage + * structure based on the incoming data and let Xlib do the + * rest. Probably we don't have to pass leftPad again in the src_x + * of XPutImage otherwise the src_x would make Xlib to take into + * account the xoffset field twice. Unfortunately passing the + * leftPad doesn't work. * * plainImage = XCreateImage(nxagentDisplay, pVisual, * depth, format, leftPad, data, @@ -1156,10 +1097,9 @@ FIXME: Should use an unpack resource here. #endif /* - * We got the image data from the X client or - * from the frame-buffer with our own endianness. - * Byte swap the image data if the display has - * a different endianness than our own. + * We got the image data from the X client or from the frame-buffer + * with our own endianness. Byte swap the image data if the display + * has a different endianness than our own. */ if (nxagentImageNormalize(plainImage) != 0) @@ -1176,10 +1116,9 @@ FIXME: Should use an unpack resource here. #endif /* - * Check if the user requested to pack the - * image but don't pack it if we are not - * connected to a proxy or if the depth is - * less than 15 bpp. + * Check if the user requested to pack the image but don't pack it + * if we are not connected to a proxy or if the depth is less than + * 15 bpp. */ pack = (nxagentOption(LinkType) != LINK_TYPE_NONE && @@ -1190,9 +1129,8 @@ FIXME: Should use an unpack resource here. if (pack == 1 && lossless == 0) { /* - * Force the image to be sent as a plain - * bitmap if we don't have any lossless - * encoder available. + * Force the image to be sent as a plain bitmap if we don't have + * any lossless encoder available. */ if (w <= IMAGE_PACK_WIDTH || h <= IMAGE_PACK_HEIGHT || @@ -1231,8 +1169,8 @@ FIXME: Should use an unpack resource here. if (pack == 1) { /* - * Set the geometry and alpha channel - * to be used for the unpacked image. + * Set the geometry and alpha channel to be used for the unpacked + * image. */ if (nxagentUnpackVisualId[client -> index] != pVisual -> visualid) @@ -1248,9 +1186,8 @@ FIXME: Should use an unpack resource here. } /* - * Check if the image is supposed to carry - * the alpha data in the fourth byte and, - * if so, send the alpha channel using the + * Check if the image is supposed to carry the alpha data in the + * fourth byte and, if so, send the alpha channel using the * specific encoding. */ @@ -1260,46 +1197,43 @@ FIXME: Should use an unpack resource here. } /* - * If the image doesn't come from the XVideo or the - * GLX extension try to locate it in the cache. The - * case of the lossless trap is also special, as we - * want to eventually encode the image again using - * a lossless compression. + * If the image doesn't come from the XVideo or the GLX extension + * try to locate it in the cache. The case of the lossless trap is + * also special, as we want to eventually encode the image again + * using a lossless compression. */ /* -FIXME: Should try to locate the image anyway, if the lossless - trap is set, and if the image was encoded by a lossy - compressor, roll back the changes and encode the image - again using the preferred method. +FIXME: Should try to locate the image anyway, if the lossless trap is + set, and if the image was encoded by a lossy compressor, roll + back the changes and encode the image again using the preferred + method. */ if (nxagentNeedCache(plainImage, packMethod) && nxagentGlxTrap == 0 && nxagentXvTrap == 0 && nxagentLosslessTrap == 0 && NXImageCacheSize > 0) { /* - * Be sure that the padding bits are - * cleaned before calculating the MD5 - * checksum. + * Be sure that the padding bits are cleaned before calculating + * the MD5 checksum. */ /* FIXME: There should be a callback registered by the agent that - provides a statistics report, in text format, telling - for example how many images were searched in the cache, - how many were found, how many drawables are to be synch- - ronized, etc. This statistics report would be included - by the proxy in its stat output. + provides a statistics report, in text format, telling for + example how many images were searched in the cache, how many + were found, how many drawables are to be synchronized, + etc. This statistics report would be included by the proxy in + its stat output. */ clean = 1; NXCleanImage(plainImage); /* - * Will return a pointer to the image and checksum - * taken from the cache, if found. If the image is - * not found, the function returns a null image and - * a pointer to the calculated checksum. It is up - * to the application to free the memory. We will - * use the checksum to add the image in the cache. + * Will return a pointer to the image and checksum taken from + * the cache, if found. If the image is not found, the function + * returns a null image and a pointer to the calculated + * checksum. It is up to the application to free the memory. We + * will use the checksum to add the image in the cache. */ packedImage = NXCacheFindImage(plainImage, &packMethod, &packedChecksum); @@ -1336,9 +1270,8 @@ FIXME: There should be a callback registered by the agent that } /* - * If a specific encoder was not mandated, - * try to guess if a lossless encoder will - * compress better. + * If a specific encoder was not mandated, try to guess if a + * lossless encoder will compress better. */ if (lossless == 0 && nxagentOption(Adaptive) == 1) @@ -1366,8 +1299,7 @@ FIXME: There should be a callback registered by the agent that } /* - * Encode the image using the selected - * pack method. + * Encode the image using the selected pack method. */ if (packMethod == PACK_RLE_16M_COLORS || @@ -1375,13 +1307,11 @@ FIXME: There should be a callback registered by the agent that packMethod == PACK_BITMAP_16M_COLORS) { /* - * Cleanup the image if we didn't do that yet. - * We assume that the JPEG and PNG compression - * methods will actually ignore the padding - * bytes. In other words, bitmap images prod- - * ucing the same visual output should produce - * compressed images that are bitwise the same - * regardless the padding bits. + * Cleanup the image if we didn't do that yet. We assume that + * the JPEG and PNG compression methods will actually ignore the + * padding bytes. In other words, bitmap images producing the + * same visual output should produce compressed images that are + * bitwise the same regardless the padding bits. */ if (clean == 0) @@ -1397,30 +1327,25 @@ FIXME: There should be a callback registered by the agent that switch (packMethod) { /* - * If nothing is done by the bitmap encoder, - * it saves an allocation and a memory copy - * by setting the data field of the packed - * image to the original data. We need to - * check this at the time we will free the - * packed image. + * If nothing is done by the bitmap encoder, it saves an + * allocation and a memory copy by setting the data field of + * the packed image to the original data. We need to check + * this at the time we will free the packed image. */ case PACK_BITMAP_16M_COLORS: { packedImage = NXEncodeBitmap(plainImage, packMethod, packQuality); - break; } case PACK_RGB_16M_COLORS: { packedImage = NXEncodeRgb(plainImage, packMethod, packQuality); - break; } default: { packedImage = NXEncodeRle(plainImage, packMethod, packQuality); - break; } } @@ -1447,8 +1372,8 @@ FIXME: There should be a callback registered by the agent that } /* - * If we didn't produce a valid packed - * image, send the image as a X bitmap. + * If we didn't produce a valid packed image, send the image as a X + * bitmap. */ if (packedImage != NULL) @@ -1467,10 +1392,8 @@ FIXME: There should be a callback registered by the agent that 0, 0, x, y, w, h); /* - * Add the image only if we have a valid - * checksum. This is the case only if we - * originally tried to find the image in - * cache. + * Add the image only if we have a valid checksum. This is the + * case only if we originally tried to find the image in cache. */ if (NXImageCacheSize > 0 && packedChecksum != NULL) @@ -1481,9 +1404,8 @@ FIXME: There should be a callback registered by the agent that #endif /* - * Check if both the plain and the packed - * image point to the same data. In this - * case we need a copy. + * Check if both the plain and the packed image point to the + * same data. In this case we need a copy. */ if (packedImage -> data == plainImage -> data && @@ -1504,19 +1426,17 @@ FIXME: There should be a callback registered by the agent that else { /* - * Clean the image to help the proxy to match - * the checksum in its cache. Do that only if - * the differential compression is enabled and - * if the image is not supposed to carry the - * alpha data in the fourth byte of the pixel. + * Clean the image to help the proxy to match the checksum in its + * cache. Do that only if the differential compression is enabled + * and if the image is not supposed to carry the alpha data in the + * fourth byte of the pixel. */ /* FIXME: If we failed to encode the image by any of the available - methods, for example if we couldn't allocate memory, we - may need to ripristinate the alpha channel, that in the - meanwhile was sent in the unpack alpha message. This can - be done here, if the clean flag is true and we are going - to send a plain image. + methods, for example if we couldn't allocate memory, we may + need to ripristinate the alpha channel, that in the meanwhile + was sent in the unpack alpha message. This can be done here, if + the clean flag is true and we are going to send a plain image. */ if (clean == 0) { @@ -1610,17 +1530,14 @@ void nxagentGetImage(DrawablePtr pDrawable, int x, int y, int w, int h, } /* - * We have to reset the visual cache before - * connecting to another display, so that a - * new unpack geometry can be communicated - * to the new proxy. + * We have to reset the visual cache before connecting to another + * display, so that a new unpack geometry can be communicated to the + * new proxy. */ void nxagentResetVisualCache(void) { - int i; - - for (i = 0; i < MAX_CONNECTIONS; i++) + for (int i = 0; i < MAX_CONNECTIONS; i++) { nxagentUnpackVisualId[i] = None; } @@ -1628,9 +1545,7 @@ void nxagentResetVisualCache(void) void nxagentResetAlphaCache(void) { - int i; - - for (i = 0; i < MAX_CONNECTIONS; i++) + for (int i = 0; i < MAX_CONNECTIONS; i++) { if (nxagentUnpackAlpha[i]) { @@ -1643,55 +1558,25 @@ void nxagentResetAlphaCache(void) int nxagentScaleImage(int x, int y, unsigned xRatio, unsigned yRatio, XImage **pImage, int *scaledx, int *scaledy) { - int x1; - int x2; - int y1; - int y2; - - int xx1; - int xx2; - int yy1; - int yy2; - - int newWidth; - int newHeight; - - int i; - int j; - int k; - int l; - - unsigned long val; - - XImage *newImage; XImage *image = *pImage; - #ifdef FAST_GET_PUT_PIXEL - - register char *srcPixel; - register char *dstPixel; - - int i; - - #endif - if (image == NULL) { return 0; } - x1 = (xRatio * x) >> PRECISION; - x2 = (xRatio * (x + image -> width)) >> PRECISION; + int x1 = (xRatio * x) >> PRECISION; + int x2 = (xRatio * (x + image -> width)) >> PRECISION; - y1 = (yRatio * y) >> PRECISION; - y2 = (yRatio * (y + image -> height)) >> PRECISION; + int y1 = (yRatio * y) >> PRECISION; + int y2 = (yRatio * (y + image -> height)) >> PRECISION; - newWidth = x2 - x1; - newHeight = y2 - y1; + int newWidth = x2 - x1; + int newHeight = y2 - y1; - newImage = XCreateImage(nxagentDisplay, NULL, image -> depth, image -> format, 0, NULL, - newWidth, newHeight, BitmapPad(nxagentDisplay), - PixmapBytePad(newWidth, image -> depth)); + XImage *newImage = XCreateImage(nxagentDisplay, NULL, image -> depth, image -> format, 0, NULL, + newWidth, newHeight, BitmapPad(nxagentDisplay), + PixmapBytePad(newWidth, image -> depth)); if (newImage == NULL) { @@ -1725,39 +1610,40 @@ int nxagentScaleImage(int x, int y, unsigned xRatio, unsigned yRatio, newImage -> width = newWidth; newImage -> height = newHeight; - for (j = y; j < y + image -> height; j++) + for (int j = y; j < y + image -> height; j++) { - yy1 = (yRatio * j) >> PRECISION; - yy2 = (yRatio * (j + 1)) >> PRECISION; + int yy1 = (yRatio * j) >> PRECISION; + int yy2 = (yRatio * (j + 1)) >> PRECISION; - for (i = x; i < x + image -> width; i++) + for (int i = x; i < x + image -> width; i++) { + unsigned long val; + #ifndef FAST_GET_PUT_PIXEL val = XGetPixel(image, i - x, j - y); #else - srcPixel = &image -> data[(j * image -> bytes_per_line) + - ((i * image -> bits_per_pixel) >> 3)]; - - dstPixel = (char *) &val; + char * srcPixel = &image -> data[(j * image -> bytes_per_line) + + ((i * image -> bits_per_pixel) >> 3)]; + char * dstPixel = (char *) &val; val = 0; - for (i = (image -> bits_per_pixel + 7) >> 3; --i >= 0; ) + for (int m = (image -> bits_per_pixel + 7) >> 3; --m >= 0; ) { *dstPixel++ = *srcPixel++; } #endif - xx1 = (xRatio * i) >> PRECISION; - xx2 = (xRatio * (i + 1)) >> PRECISION; + int xx1 = (xRatio * i) >> PRECISION; + int xx2 = (xRatio * (i + 1)) >> PRECISION; - for (l = yy1; l < yy2; l++) + for (int l = yy1; l < yy2; l++) { - for (k = xx1; k < xx2; k++) + for (int k = xx1; k < xx2; k++) { #ifndef FAST_GET_PUT_PIXEL @@ -1765,12 +1651,12 @@ int nxagentScaleImage(int x, int y, unsigned xRatio, unsigned yRatio, #else - dstPixel = &newImage -> data[((l - y1) * newImage -> bytes_per_line) + + char *dstPixel = &newImage -> data[((l - y1) * newImage -> bytes_per_line) + (((k - x1) * newImage -> bits_per_pixel) >> 3)]; - srcPixel = (char *) &val; + char *srcPixel = (char *) &val; - for (i = (newImage -> bits_per_pixel + 7) >> 3; --i >= 0; ) + for (int m = (newImage -> bits_per_pixel + 7) >> 3; --m >= 0; ) { *dstPixel++ = *srcPixel++; } @@ -1794,19 +1680,12 @@ int nxagentScaleImage(int x, int y, unsigned xRatio, unsigned yRatio, char *nxagentAllocateImageData(int width, int height, int depth, int *length, int *format) { - char *data; - - int leftPad; - - leftPad = 0; - *format = (depth == 1) ? XYPixmap : ZPixmap; - *length = nxagentImageLength(width, height, *format, leftPad, depth); + *length = nxagentImageLength(width, height, *format, 0, depth); - data = NULL; - - if ((data = malloc(*length)) == NULL) + char *data = malloc(*length); + if (data == NULL) { #ifdef WARNING fprintf(stderr, "nxagentAllocateImageData: WARNING! Failed to allocate [%d] bytes of memory.\n", *length); |