Lines 45-50
Link Here
|
45 |
* Lorens Younes (d93-hyo@nada.kth.se) 4/96 |
45 |
* Lorens Younes (d93-hyo@nada.kth.se) 4/96 |
46 |
*/ |
46 |
*/ |
47 |
|
47 |
|
|
|
48 |
/* October 2004, source code review by Thomas Biege <thomas@suse.de> */ |
49 |
|
48 |
#include "XpmI.h" |
50 |
#include "XpmI.h" |
49 |
#include <ctype.h> |
51 |
#include <ctype.h> |
50 |
|
52 |
|
Lines 125-140
Link Here
|
125 |
unsigned int height, unsigned int *pixelindex, |
127 |
unsigned int height, unsigned int *pixelindex, |
126 |
Pixel *pixels)); |
128 |
Pixel *pixels)); |
127 |
|
129 |
|
128 |
LFUNC(PutPixel1, int, (XImage *ximage, int x, int y, unsigned long pixel)); |
130 |
LFUNC(PutPixel1, int, (XImage *ximage, unsigned x, unsigned y, unsigned long pixel)); |
129 |
LFUNC(PutPixel, int, (XImage *ximage, int x, int y, unsigned long pixel)); |
131 |
LFUNC(PutPixel, int, (XImage *ximage, unsigned x, unsigned y, unsigned long pixel)); |
130 |
LFUNC(PutPixel32, int, (XImage *ximage, int x, int y, unsigned long pixel)); |
132 |
LFUNC(PutPixel32, int, (XImage *ximage, unsigned x, unsigned y, unsigned long pixel)); |
131 |
LFUNC(PutPixel32MSB, int, (XImage *ximage, int x, int y, unsigned long pixel)); |
133 |
LFUNC(PutPixel32MSB, int, (XImage *ximage, unsigned x, unsigned y, unsigned long pixel)); |
132 |
LFUNC(PutPixel32LSB, int, (XImage *ximage, int x, int y, unsigned long pixel)); |
134 |
LFUNC(PutPixel32LSB, int, (XImage *ximage, unsigned x, unsigned y, unsigned long pixel)); |
133 |
LFUNC(PutPixel16MSB, int, (XImage *ximage, int x, int y, unsigned long pixel)); |
135 |
LFUNC(PutPixel16MSB, int, (XImage *ximage, unsigned x, unsigned y, unsigned long pixel)); |
134 |
LFUNC(PutPixel16LSB, int, (XImage *ximage, int x, int y, unsigned long pixel)); |
136 |
LFUNC(PutPixel16LSB, int, (XImage *ximage, unsigned x, unsigned y, unsigned long pixel)); |
135 |
LFUNC(PutPixel8, int, (XImage *ximage, int x, int y, unsigned long pixel)); |
137 |
LFUNC(PutPixel8, int, (XImage *ximage, unsigned x, unsigned y, unsigned long pixel)); |
136 |
LFUNC(PutPixel1MSB, int, (XImage *ximage, int x, int y, unsigned long pixel)); |
138 |
LFUNC(PutPixel1MSB, int, (XImage *ximage, unsigned x, unsigned y, unsigned long pixel)); |
137 |
LFUNC(PutPixel1LSB, int, (XImage *ximage, int x, int y, unsigned long pixel)); |
139 |
LFUNC(PutPixel1LSB, int, (XImage *ximage, unsigned x, unsigned y, unsigned long pixel)); |
138 |
|
140 |
|
139 |
# else /* AMIGA */ |
141 |
# else /* AMIGA */ |
140 |
LFUNC(APutImagePixels, void, (XImage *ximage, unsigned int width, |
142 |
LFUNC(APutImagePixels, void, (XImage *ximage, unsigned int width, |
Lines 584-590
Link Here
|
584 |
*/ |
586 |
*/ |
585 |
} else { |
587 |
} else { |
586 |
#endif |
588 |
#endif |
587 |
int i; |
589 |
unsigned int i; |
588 |
|
590 |
|
589 |
#ifndef AMIGA |
591 |
#ifndef AMIGA |
590 |
ncols = visual->map_entries; |
592 |
ncols = visual->map_entries; |
Lines 744-755
Link Here
|
744 |
|
746 |
|
745 |
|
747 |
|
746 |
/* function call in case of error */ |
748 |
/* function call in case of error */ |
|
|
749 |
|
747 |
#undef RETURN |
750 |
#undef RETURN |
748 |
#define RETURN(status) \ |
751 |
#define RETURN(status) \ |
|
|
752 |
do \ |
749 |
{ \ |
753 |
{ \ |
750 |
ErrorStatus = status; \ |
754 |
ErrorStatus = status; \ |
751 |
goto error; \ |
755 |
goto error; \ |
752 |
} |
756 |
} while(0) |
753 |
|
757 |
|
754 |
int |
758 |
int |
755 |
XpmCreateImageFromXpmImage(display, image, |
759 |
XpmCreateImageFromXpmImage(display, image, |
Lines 995-1005
Link Here
|
995 |
return (XpmNoMemory); |
999 |
return (XpmNoMemory); |
996 |
|
1000 |
|
997 |
#if !defined(FOR_MSW) && !defined(AMIGA) |
1001 |
#if !defined(FOR_MSW) && !defined(AMIGA) |
998 |
if (height != 0 && (*image_return)->bytes_per_line >= SIZE_MAX / height) { |
1002 |
if (height != 0 && (*image_return)->bytes_per_line >= INT_MAX / height) { |
999 |
XDestroyImage(*image_return); |
1003 |
XDestroyImage(*image_return); |
1000 |
return XpmNoMemory; |
1004 |
return XpmNoMemory; |
1001 |
} |
1005 |
} |
1002 |
/* now that bytes_per_line must have been set properly alloc data */ |
1006 |
/* now that bytes_per_line must have been set properly alloc data */ |
|
|
1007 |
if((*image_return)->bytes_per_line == 0 || height == 0) |
1008 |
return XpmNoMemory; |
1003 |
(*image_return)->data = |
1009 |
(*image_return)->data = |
1004 |
(char *) XpmMalloc((*image_return)->bytes_per_line * height); |
1010 |
(char *) XpmMalloc((*image_return)->bytes_per_line * height); |
1005 |
|
1011 |
|
Lines 1028-1034
Link Here
|
1028 |
LFUNC(_putbits, void, (register char *src, int dstoffset, |
1034 |
LFUNC(_putbits, void, (register char *src, int dstoffset, |
1029 |
register int numbits, register char *dst)); |
1035 |
register int numbits, register char *dst)); |
1030 |
|
1036 |
|
1031 |
LFUNC(_XReverse_Bytes, int, (register unsigned char *bpt, register int nb)); |
1037 |
LFUNC(_XReverse_Bytes, int, (register unsigned char *bpt, register unsigned int nb)); |
1032 |
|
1038 |
|
1033 |
static unsigned char Const _reverse_byte[0x100] = { |
1039 |
static unsigned char Const _reverse_byte[0x100] = { |
1034 |
0x00, 0x80, 0x40, 0xc0, 0x20, 0xa0, 0x60, 0xe0, |
1040 |
0x00, 0x80, 0x40, 0xc0, 0x20, 0xa0, 0x60, 0xe0, |
Lines 1068-1079
Link Here
|
1068 |
static int |
1074 |
static int |
1069 |
_XReverse_Bytes(bpt, nb) |
1075 |
_XReverse_Bytes(bpt, nb) |
1070 |
register unsigned char *bpt; |
1076 |
register unsigned char *bpt; |
1071 |
register int nb; |
1077 |
register unsigned int nb; |
1072 |
{ |
1078 |
{ |
1073 |
do { |
1079 |
do { |
1074 |
*bpt = _reverse_byte[*bpt]; |
1080 |
*bpt = _reverse_byte[*bpt]; |
1075 |
bpt++; |
1081 |
bpt++; |
1076 |
} while (--nb > 0); |
1082 |
} while (--nb > 0); /* is nb user-controled? */ |
1077 |
return 0; |
1083 |
return 0; |
1078 |
} |
1084 |
} |
1079 |
|
1085 |
|
Lines 1212-1218
Link Here
|
1212 |
register char *src; |
1218 |
register char *src; |
1213 |
register char *dst; |
1219 |
register char *dst; |
1214 |
register unsigned int *iptr; |
1220 |
register unsigned int *iptr; |
1215 |
register int x, y, i; |
1221 |
register unsigned int x, y, i; |
1216 |
register char *data; |
1222 |
register char *data; |
1217 |
Pixel pixel, px; |
1223 |
Pixel pixel, px; |
1218 |
int nbytes, depth, ibu, ibpp; |
1224 |
int nbytes, depth, ibu, ibpp; |
Lines 1222-1229
Link Here
|
1222 |
depth = image->depth; |
1228 |
depth = image->depth; |
1223 |
if (depth == 1) { |
1229 |
if (depth == 1) { |
1224 |
ibu = image->bitmap_unit; |
1230 |
ibu = image->bitmap_unit; |
1225 |
for (y = 0; y < height; y++) |
1231 |
for (y = 0; y < height; y++) /* how can we trust height */ |
1226 |
for (x = 0; x < width; x++, iptr++) { |
1232 |
for (x = 0; x < width; x++, iptr++) { /* how can we trust width */ |
1227 |
pixel = pixels[*iptr]; |
1233 |
pixel = pixels[*iptr]; |
1228 |
for (i = 0, px = pixel; i < sizeof(unsigned long); |
1234 |
for (i = 0, px = pixel; i < sizeof(unsigned long); |
1229 |
i++, px >>= 8) |
1235 |
i++, px >>= 8) |
Lines 1298-1309
Link Here
|
1298 |
{ |
1304 |
{ |
1299 |
unsigned char *data; |
1305 |
unsigned char *data; |
1300 |
unsigned int *iptr; |
1306 |
unsigned int *iptr; |
1301 |
int y; |
1307 |
unsigned int y; |
1302 |
Pixel pixel; |
1308 |
Pixel pixel; |
1303 |
|
1309 |
|
1304 |
#ifdef WITHOUT_SPEEDUPS |
1310 |
#ifdef WITHOUT_SPEEDUPS |
1305 |
|
1311 |
|
1306 |
int x; |
1312 |
unsigned int x; |
1307 |
unsigned char *addr; |
1313 |
unsigned char *addr; |
1308 |
|
1314 |
|
1309 |
data = (unsigned char *) image->data; |
1315 |
data = (unsigned char *) image->data; |
Lines 1340-1346
Link Here
|
1340 |
|
1346 |
|
1341 |
#else /* WITHOUT_SPEEDUPS */ |
1347 |
#else /* WITHOUT_SPEEDUPS */ |
1342 |
|
1348 |
|
1343 |
int bpl = image->bytes_per_line; |
1349 |
unsigned int bpl = image->bytes_per_line; |
1344 |
unsigned char *data_ptr, *max_data; |
1350 |
unsigned char *data_ptr, *max_data; |
1345 |
|
1351 |
|
1346 |
data = (unsigned char *) image->data; |
1352 |
data = (unsigned char *) image->data; |
Lines 1408-1418
Link Here
|
1408 |
{ |
1414 |
{ |
1409 |
unsigned char *data; |
1415 |
unsigned char *data; |
1410 |
unsigned int *iptr; |
1416 |
unsigned int *iptr; |
1411 |
int y; |
1417 |
unsigned int y; |
1412 |
|
1418 |
|
1413 |
#ifdef WITHOUT_SPEEDUPS |
1419 |
#ifdef WITHOUT_SPEEDUPS |
1414 |
|
1420 |
|
1415 |
int x; |
1421 |
unsigned int x; |
1416 |
unsigned char *addr; |
1422 |
unsigned char *addr; |
1417 |
|
1423 |
|
1418 |
data = (unsigned char *) image->data; |
1424 |
data = (unsigned char *) image->data; |
Lines 1436-1442
Link Here
|
1436 |
|
1442 |
|
1437 |
Pixel pixel; |
1443 |
Pixel pixel; |
1438 |
|
1444 |
|
1439 |
int bpl = image->bytes_per_line; |
1445 |
unsigned int bpl = image->bytes_per_line; |
1440 |
unsigned char *data_ptr, *max_data; |
1446 |
unsigned char *data_ptr, *max_data; |
1441 |
|
1447 |
|
1442 |
data = (unsigned char *) image->data; |
1448 |
data = (unsigned char *) image->data; |
Lines 1489-1499
Link Here
|
1489 |
{ |
1495 |
{ |
1490 |
char *data; |
1496 |
char *data; |
1491 |
unsigned int *iptr; |
1497 |
unsigned int *iptr; |
1492 |
int y; |
1498 |
unsigned int y; |
1493 |
|
1499 |
|
1494 |
#ifdef WITHOUT_SPEEDUPS |
1500 |
#ifdef WITHOUT_SPEEDUPS |
1495 |
|
1501 |
|
1496 |
int x; |
1502 |
unsigned int x; |
1497 |
|
1503 |
|
1498 |
data = image->data; |
1504 |
data = image->data; |
1499 |
iptr = pixelindex; |
1505 |
iptr = pixelindex; |
Lines 1503-1509
Link Here
|
1503 |
|
1509 |
|
1504 |
#else /* WITHOUT_SPEEDUPS */ |
1510 |
#else /* WITHOUT_SPEEDUPS */ |
1505 |
|
1511 |
|
1506 |
int bpl = image->bytes_per_line; |
1512 |
unsigned int bpl = image->bytes_per_line; |
1507 |
char *data_ptr, *max_data; |
1513 |
char *data_ptr, *max_data; |
1508 |
|
1514 |
|
1509 |
data = image->data; |
1515 |
data = image->data; |
Lines 1538-1549
Link Here
|
1538 |
PutImagePixels(image, width, height, pixelindex, pixels); |
1544 |
PutImagePixels(image, width, height, pixelindex, pixels); |
1539 |
else { |
1545 |
else { |
1540 |
unsigned int *iptr; |
1546 |
unsigned int *iptr; |
1541 |
int y; |
1547 |
unsigned int y; |
1542 |
char *data; |
1548 |
char *data; |
1543 |
|
1549 |
|
1544 |
#ifdef WITHOUT_SPEEDUPS |
1550 |
#ifdef WITHOUT_SPEEDUPS |
1545 |
|
1551 |
|
1546 |
int x; |
1552 |
unsigned int x; |
1547 |
|
1553 |
|
1548 |
data = image->data; |
1554 |
data = image->data; |
1549 |
iptr = pixelindex; |
1555 |
iptr = pixelindex; |
Lines 1756-1763
Link Here
|
1756 |
static int |
1762 |
static int |
1757 |
PutPixel1(ximage, x, y, pixel) |
1763 |
PutPixel1(ximage, x, y, pixel) |
1758 |
register XImage *ximage; |
1764 |
register XImage *ximage; |
1759 |
int x; |
1765 |
unsigned int x; |
1760 |
int y; |
1766 |
unsigned int y; |
1761 |
unsigned long pixel; |
1767 |
unsigned long pixel; |
1762 |
{ |
1768 |
{ |
1763 |
register char *src; |
1769 |
register char *src; |
Lines 1788-1802
Link Here
|
1788 |
static int |
1794 |
static int |
1789 |
PutPixel(ximage, x, y, pixel) |
1795 |
PutPixel(ximage, x, y, pixel) |
1790 |
register XImage *ximage; |
1796 |
register XImage *ximage; |
1791 |
int x; |
1797 |
unsigned int x; |
1792 |
int y; |
1798 |
unsigned int y; |
1793 |
unsigned long pixel; |
1799 |
unsigned long pixel; |
1794 |
{ |
1800 |
{ |
1795 |
register char *src; |
1801 |
register char *src; |
1796 |
register char *dst; |
1802 |
register char *dst; |
1797 |
register int i; |
1803 |
register int i; |
1798 |
Pixel px; |
1804 |
Pixel px; |
1799 |
int nbytes, ibpp; |
1805 |
unsigned int nbytes, ibpp; |
1800 |
|
1806 |
|
1801 |
ibpp = ximage->bits_per_pixel; |
1807 |
ibpp = ximage->bits_per_pixel; |
1802 |
if (ximage->depth == 4) |
1808 |
if (ximage->depth == 4) |
Lines 1823-1830
Link Here
|
1823 |
static int |
1829 |
static int |
1824 |
PutPixel32(ximage, x, y, pixel) |
1830 |
PutPixel32(ximage, x, y, pixel) |
1825 |
register XImage *ximage; |
1831 |
register XImage *ximage; |
1826 |
int x; |
1832 |
unsigned int x; |
1827 |
int y; |
1833 |
unsigned int y; |
1828 |
unsigned long pixel; |
1834 |
unsigned long pixel; |
1829 |
{ |
1835 |
{ |
1830 |
unsigned char *addr; |
1836 |
unsigned char *addr; |
Lines 1837-1844
Link Here
|
1837 |
static int |
1843 |
static int |
1838 |
PutPixel32MSB(ximage, x, y, pixel) |
1844 |
PutPixel32MSB(ximage, x, y, pixel) |
1839 |
register XImage *ximage; |
1845 |
register XImage *ximage; |
1840 |
int x; |
1846 |
unsigned int x; |
1841 |
int y; |
1847 |
unsigned int y; |
1842 |
unsigned long pixel; |
1848 |
unsigned long pixel; |
1843 |
{ |
1849 |
{ |
1844 |
unsigned char *addr; |
1850 |
unsigned char *addr; |
Lines 1854-1861
Link Here
|
1854 |
static int |
1860 |
static int |
1855 |
PutPixel32LSB(ximage, x, y, pixel) |
1861 |
PutPixel32LSB(ximage, x, y, pixel) |
1856 |
register XImage *ximage; |
1862 |
register XImage *ximage; |
1857 |
int x; |
1863 |
unsigned int x; |
1858 |
int y; |
1864 |
unsigned int y; |
1859 |
unsigned long pixel; |
1865 |
unsigned long pixel; |
1860 |
{ |
1866 |
{ |
1861 |
unsigned char *addr; |
1867 |
unsigned char *addr; |
Lines 1871-1878
Link Here
|
1871 |
static int |
1877 |
static int |
1872 |
PutPixel16MSB(ximage, x, y, pixel) |
1878 |
PutPixel16MSB(ximage, x, y, pixel) |
1873 |
register XImage *ximage; |
1879 |
register XImage *ximage; |
1874 |
int x; |
1880 |
unsigned int x; |
1875 |
int y; |
1881 |
unsigned int y; |
1876 |
unsigned long pixel; |
1882 |
unsigned long pixel; |
1877 |
{ |
1883 |
{ |
1878 |
unsigned char *addr; |
1884 |
unsigned char *addr; |
Lines 1886-1893
Link Here
|
1886 |
static int |
1892 |
static int |
1887 |
PutPixel16LSB(ximage, x, y, pixel) |
1893 |
PutPixel16LSB(ximage, x, y, pixel) |
1888 |
register XImage *ximage; |
1894 |
register XImage *ximage; |
1889 |
int x; |
1895 |
unsigned int x; |
1890 |
int y; |
1896 |
unsigned int y; |
1891 |
unsigned long pixel; |
1897 |
unsigned long pixel; |
1892 |
{ |
1898 |
{ |
1893 |
unsigned char *addr; |
1899 |
unsigned char *addr; |
Lines 1901-1908
Link Here
|
1901 |
static int |
1907 |
static int |
1902 |
PutPixel8(ximage, x, y, pixel) |
1908 |
PutPixel8(ximage, x, y, pixel) |
1903 |
register XImage *ximage; |
1909 |
register XImage *ximage; |
1904 |
int x; |
1910 |
unsigned int x; |
1905 |
int y; |
1911 |
unsigned int y; |
1906 |
unsigned long pixel; |
1912 |
unsigned long pixel; |
1907 |
{ |
1913 |
{ |
1908 |
ximage->data[ZINDEX8(x, y, ximage)] = pixel; |
1914 |
ximage->data[ZINDEX8(x, y, ximage)] = pixel; |
Lines 1912-1919
Link Here
|
1912 |
static int |
1918 |
static int |
1913 |
PutPixel1MSB(ximage, x, y, pixel) |
1919 |
PutPixel1MSB(ximage, x, y, pixel) |
1914 |
register XImage *ximage; |
1920 |
register XImage *ximage; |
1915 |
int x; |
1921 |
unsigned int x; |
1916 |
int y; |
1922 |
unsigned int y; |
1917 |
unsigned long pixel; |
1923 |
unsigned long pixel; |
1918 |
{ |
1924 |
{ |
1919 |
if (pixel & 1) |
1925 |
if (pixel & 1) |
Lines 1926-1933
Link Here
|
1926 |
static int |
1932 |
static int |
1927 |
PutPixel1LSB(ximage, x, y, pixel) |
1933 |
PutPixel1LSB(ximage, x, y, pixel) |
1928 |
register XImage *ximage; |
1934 |
register XImage *ximage; |
1929 |
int x; |
1935 |
unsigned int x; |
1930 |
int y; |
1936 |
unsigned int y; |
1931 |
unsigned long pixel; |
1937 |
unsigned long pixel; |
1932 |
{ |
1938 |
{ |
1933 |
if (pixel & 1) |
1939 |
if (pixel & 1) |
Lines 2182-2188
Link Here
|
2182 |
* free the hastable |
2188 |
* free the hastable |
2183 |
*/ |
2189 |
*/ |
2184 |
if (ErrorStatus != XpmSuccess) |
2190 |
if (ErrorStatus != XpmSuccess) |
2185 |
RETURN(ErrorStatus) |
2191 |
RETURN(ErrorStatus); |
2186 |
else if (USE_HASHTABLE) |
2192 |
else if (USE_HASHTABLE) |
2187 |
xpmHashTableFree(&hashtable); |
2193 |
xpmHashTableFree(&hashtable); |
2188 |
|
2194 |
|
Lines 2378-2384
Link Here
|
2378 |
|
2384 |
|
2379 |
bzero((char *)cidx, 256 * sizeof(unsigned short *)); /* init */ |
2385 |
bzero((char *)cidx, 256 * sizeof(unsigned short *)); /* init */ |
2380 |
for (a = 0; a < ncolors; a++) { |
2386 |
for (a = 0; a < ncolors; a++) { |
2381 |
char1 = colorTable[a].string[0]; |
2387 |
char1 = (unsigned char) colorTable[a].string[0]; |
2382 |
if (cidx[char1] == NULL) { /* get new memory */ |
2388 |
if (cidx[char1] == NULL) { /* get new memory */ |
2383 |
cidx[char1] = (unsigned short *) |
2389 |
cidx[char1] = (unsigned short *) |
2384 |
XpmCalloc(256, sizeof(unsigned short)); |
2390 |
XpmCalloc(256, sizeof(unsigned short)); |