/*
+ *
* xtiff - view a TIFF file in an X window
*
* Dan Sears
*/
#include <math.h>
#include <stdio.h>
+#include <stdlib.h>
#include <tiffio.h>
#include <X11/Xatom.h>
#include <X11/Intrinsic.h>
#include "xtifficon.h"
#define TIFF_GAMMA "2.2" /* default gamma from the TIFF 5.0 spec */
-#define ROUND(x) (u_short) ((x) + 0.5)
+#define ROUND(x) (uint16) ((x) + 0.5)
#define SCALE(x, s) (((x) * 65535L) / (s))
#define MCHECK(m) if (!m) { fprintf(stderr, "malloc failed\n"); exit(0); }
#define MIN(a, b) (((a) < (b)) ? (a) : (b))
#define PP(args) ()
#endif
-void main PP((int argc, char **argv));
+int main PP((int argc, char **argv));
void OpenTIFFFile PP((void));
void GetTIFFHeader PP((void));
void SetNameLabel PP((void));
Boolean help;
float gamma;
Boolean usePixmap;
- int viewportWidth;
- int viewportHeight;
+ uint32 viewportWidth;
+ uint32 viewportHeight;
int translate;
Boolean verbose;
} AppData, *AppDataPtr;
GC xWinGc;
int xImageDepth, xScreen, xRedMask, xGreenMask, xBlueMask,
xOffset = 0, yOffset = 0, grabX = -1, grabY = -1;
-u_char basePixel = 0;
+unsigned char basePixel = 0;
/*
* TIFF data structures
*/
TIFF * tfFile = NULL;
-u_long tfImageWidth, tfImageHeight;
-u_short tfBitsPerSample, tfSamplesPerPixel, tfPlanarConfiguration,
+uint32 tfImageWidth, tfImageHeight;
+uint16 tfBitsPerSample, tfSamplesPerPixel, tfPlanarConfiguration,
tfPhotometricInterpretation, tfGrayResponseUnit,
tfImageDepth, tfBytesPerRow;
int tfDirectory = 0, tfMultiPage = False;
/*
* shared data structures
*/
-u_short * redMap = NULL, *greenMap = NULL, *blueMap = NULL,
+uint16 * redMap = NULL, *greenMap = NULL, *blueMap = NULL,
*grayMap = NULL, colormapSize;
-u_char * imageMemory;
+char * imageMemory;
char * fileName;
-void
-main(argc, argv)
- int argc;
- char ** argv;
+int
+main(int argc, char **argv)
{
XSetWindowAttributes window_attributes;
Widget widget_list[3];
CreateXImage();
XtMainLoop();
+
+ return 0;
}
void
*/
switch (tfPhotometricInterpretation) {
case PHOTOMETRIC_RGB:
- redMap = (u_short *) malloc(colormapSize * sizeof(u_short));
- greenMap = (u_short *) malloc(colormapSize * sizeof(u_short));
- blueMap = (u_short *) malloc(colormapSize * sizeof(u_short));
+ redMap = (uint16 *) malloc(colormapSize * sizeof(uint16));
+ greenMap = (uint16 *) malloc(colormapSize * sizeof(uint16));
+ blueMap = (uint16 *) malloc(colormapSize * sizeof(uint16));
MCHECK(redMap); MCHECK(greenMap); MCHECK(blueMap);
for (i = 0; i < colormapSize; i++)
dRed[i] = dGreen[i] = dBlue[i]
case PHOTOMETRIC_PALETTE:
if (!TIFFGetField(tfFile, TIFFTAG_COLORMAP,
&redMap, &greenMap, &blueMap)) {
- redMap = (u_short *) malloc(colormapSize * sizeof(u_short));
- greenMap = (u_short *) malloc(colormapSize * sizeof(u_short));
- blueMap = (u_short *) malloc(colormapSize * sizeof(u_short));
+ redMap = (uint16 *) malloc(colormapSize * sizeof(uint16));
+ greenMap = (uint16 *) malloc(colormapSize * sizeof(uint16));
+ blueMap = (uint16 *) malloc(colormapSize * sizeof(uint16));
MCHECK(redMap); MCHECK(greenMap); MCHECK(blueMap);
for (i = 0; i < colormapSize; i++)
dRed[i] = dGreen[i] = dBlue[i]
}
break;
case PHOTOMETRIC_MINISWHITE:
- redMap = (u_short *) malloc(colormapSize * sizeof(u_short));
- greenMap = (u_short *) malloc(colormapSize * sizeof(u_short));
- blueMap = (u_short *) malloc(colormapSize * sizeof(u_short));
+ redMap = (uint16 *) malloc(colormapSize * sizeof(uint16));
+ greenMap = (uint16 *) malloc(colormapSize * sizeof(uint16));
+ blueMap = (uint16 *) malloc(colormapSize * sizeof(uint16));
MCHECK(redMap); MCHECK(greenMap); MCHECK(blueMap);
for (i = 0; i < colormapSize; i++)
dRed[i] = dGreen[i] = dBlue[i] = (double)
SCALE(colormapSize-1-i, colormapSize-1);
break;
case PHOTOMETRIC_MINISBLACK:
- redMap = (u_short *) malloc(colormapSize * sizeof(u_short));
- greenMap = (u_short *) malloc(colormapSize * sizeof(u_short));
- blueMap = (u_short *) malloc(colormapSize * sizeof(u_short));
+ redMap = (uint16 *) malloc(colormapSize * sizeof(uint16));
+ greenMap = (uint16 *) malloc(colormapSize * sizeof(uint16));
+ blueMap = (uint16 *) malloc(colormapSize * sizeof(uint16));
MCHECK(redMap); MCHECK(greenMap); MCHECK(blueMap);
for (i = 0; i < colormapSize; i++)
dRed[i] = dGreen[i] = dBlue[i] = (double) SCALE(i, colormapSize-1);
void
GetVisual()
{
- register XColor *colors = NULL;
- register u_long *pixels = NULL;
- register int i;
+ XColor *colors = NULL;
+ unsigned long *pixels = NULL;
+ unsigned long i;
switch (tfImageDepth) {
/*
MCHECK(colors);
for (i = 0; i < colormapSize; i++) {
- colors[i].pixel = (u_long) (i << 16) + (i << 8) + i;
+ colors[i].pixel = (i << 16) + (i << 8) + i;
colors[i].red = redMap[i];
colors[i].green = greenMap[i];
colors[i].blue = blueMap[i];
MCHECK(colors);
for (i = 0; i < colormapSize; i++) {
- colors[i].pixel = (u_long) i;
+ colors[i].pixel = i;
colors[i].red = redMap[i];
colors[i].green = greenMap[i];
colors[i].blue = blueMap[i];
else {
xColormap = XCreateColormap(xDisplay, RootWindow(xDisplay, xScreen),
xVisual, AllocNone);
- pixels = (u_long *) malloc(colormapSize * sizeof(u_long));
+ pixels = (unsigned long *)
+ malloc(colormapSize * sizeof(unsigned long));
MCHECK(pixels);
(void) XAllocColorCells(xDisplay, xColormap, True,
NULL, 0, pixels, colormapSize);
- basePixel = (u_char) pixels[0];
+ basePixel = (unsigned char) pixels[0];
free(pixels);
}
XStoreColors(xDisplay, xColormap, colors, colormapSize);
GetTIFFImage()
{
int pixel_map[3], red_shift, green_shift, blue_shift;
- register u_char *scan_line, *output_p, *input_p;
- register int i, j, s;
+ char *scan_line, *output_p, *input_p;
+ uint32 i, j;
+ uint16 s;
- scan_line = (u_char *) malloc(tfBytesPerRow = TIFFScanlineSize(tfFile));
+ scan_line = (char *) malloc(tfBytesPerRow = TIFFScanlineSize(tfFile));
MCHECK(scan_line);
if ((tfImageDepth == 32) || (tfImageDepth == 24)) {
- output_p = imageMemory = (u_char *)
+ output_p = imageMemory = (char *)
malloc(tfImageWidth * tfImageHeight * 4);
MCHECK(imageMemory);
}
} else {
if (xImageDepth == tfImageDepth) {
- output_p = imageMemory = (u_char *)
+ output_p = imageMemory = (char *)
malloc(tfBytesPerRow * tfImageHeight);
MCHECK(imageMemory);
if (TIFFReadScanline(tfFile, output_p, i, 0) < 0)
break;
} else if ((xImageDepth == 8) && (tfImageDepth == 4)) {
- output_p = imageMemory = (u_char *)
+ output_p = imageMemory = (char *)
malloc(tfBytesPerRow * 2 * tfImageHeight + 2);
MCHECK(imageMemory);
}
}
} else if ((xImageDepth == 8) && (tfImageDepth == 2)) {
- output_p = imageMemory = (u_char *)
+ output_p = imageMemory = (char *)
malloc(tfBytesPerRow * 4 * tfImageHeight + 4);
MCHECK(imageMemory);
}
}
} else if ((xImageDepth == 4) && (tfImageDepth == 2)) {
- output_p = imageMemory = (u_char *)
+ output_p = imageMemory = (char *)
malloc(tfBytesPerRow * 2 * tfImageHeight + 2);
MCHECK(imageMemory);
fprintf(stderr, "\t[-verbose (True | False)]\n");
exit(0);
}
+
+/* vim: set ts=8 sts=8 sw=8 noet: */
+
+/*
+ * Local Variables:
+ * mode: c
+ * c-basic-offset: 8
+ * fill-column: 78
+ * End:
+ */