The R Project SVN R

Rev

Rev 45017 | Show entire file | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed

Rev 45017 Rev 76910
Line 64... Line 64...
64
    img->width  = width;
64
    img->width  = width;
65
    img->height = height;
65
    img->height = height;
66
 
66
 
67
    if (depth == 8) {
67
    if (depth == 8) {
68
	img->depth  = 8;
68
	img->depth  = 8;
69
	img->pixels = array(width*height, byte);
69
	img->pixels = array(width*height, GAbyte);
70
    }
70
    }
71
    else {
71
    else {
72
	img->depth  = 32;
72
	img->depth  = 32;
73
	img->pixels = (byte *) array(width*height, rgb);
73
	img->pixels = (GAbyte *) array(width*height, rgb);
74
    }
74
    }
75
 
75
 
76
    return img;
76
    return img;
77
}
77
}
78
 
78
 
Line 144... Line 144...
144
int imageheight(image img) { return ((img)?(img->height):0);}
144
int imageheight(image img) { return ((img)?(img->height):0);}
145
 
145
 
146
/*
146
/*
147
 *  Change an image's pixels:
147
 *  Change an image's pixels:
148
 */
148
 */
149
void setpixels(image img, byte pixels[])
149
void setpixels(image img, GAbyte pixels[])
150
{
150
{
151
    long i, length;
151
    long i, length;
152
 
152
 
153
    if (! img)
153
    if (! img)
154
	return;
154
	return;
Line 162... Line 162...
162
}
162
}
163
 
163
 
164
/*
164
/*
165
 *  Return an image's pixel array:
165
 *  Return an image's pixel array:
166
 */
166
 */
167
byte * getpixels(image img)
167
GAbyte * getpixels(image img)
168
{
168
{
169
    if (img)
169
    if (img)
170
	return img->pixels;
170
	return img->pixels;
171
    else
171
    else
172
	return NULL;
172
	return NULL;
Line 220... Line 220...
220
static image fast_find_cmap (image img)
220
static image fast_find_cmap (image img)
221
{
221
{
222
    image new_img;
222
    image new_img;
223
    long   i, j, length;
223
    long   i, j, length;
224
    rgb *  pixel32;
224
    rgb *  pixel32;
225
    byte * pixel8;
225
    GAbyte * pixel8;
226
    int    cmapsize, low, high, mid;
226
    int    cmapsize, low, high, mid;
227
    rgb    col;
227
    rgb    col;
228
    rgb    cmap[256];
228
    rgb    cmap[256];
229
 
229
 
230
    pixel32 = (rgb *) img->pixels;
230
    pixel32 = (rgb *) img->pixels;
Line 270... Line 270...
270
    setpalette(new_img, cmapsize, cmap);
270
    setpalette(new_img, cmapsize, cmap);
271
 
271
 
272
    /* now convert each 32-bit pixel into an 8-bit pixel: */
272
    /* now convert each 32-bit pixel into an 8-bit pixel: */
273
 
273
 
274
    pixel32 = (rgb *) img->pixels;
274
    pixel32 = (rgb *) img->pixels;
275
    pixel8 = (byte *) new_img->pixels;
275
    pixel8 = (GAbyte *) new_img->pixels;
276
 
276
 
277
    for (i=0; i < length; i++)
277
    for (i=0; i < length; i++)
278
    {
278
    {
279
	col = *pixel32 ++;
279
	col = *pixel32 ++;
280
 
280
 
Line 315... Line 315...
315
{
315
{
316
    image new_img;
316
    image new_img;
317
    long   i, length, col;
317
    long   i, length, col;
318
    int    r, g, b, value;
318
    int    r, g, b, value;
319
    rgb *  pixel32;
319
    rgb *  pixel32;
320
    byte * pixel8;
320
    GAbyte * pixel8;
321
    rgb    cmap[256];
321
    rgb    cmap[256];
322
 
322
 
323
    /* Generate the colour map: */
323
    /* Generate the colour map: */
324
 
324
 
325
    for (r=0; r<7; r++)		/* 7x7x5 colour cube */
325
    for (r=0; r<7; r++)		/* 7x7x5 colour cube */
Line 344... Line 344...
344
 
344
 
345
    /* Translate the pixels from 32-bit to 8-bit: */
345
    /* Translate the pixels from 32-bit to 8-bit: */
346
 
346
 
347
    length = img->width * img->height;
347
    length = img->width * img->height;
348
    pixel32 = (rgb *) img->pixels;
348
    pixel32 = (rgb *) img->pixels;
349
    pixel8 = (byte *) new_img->pixels;
349
    pixel8 = (GAbyte *) new_img->pixels;
350
 
350
 
351
    for (i=0; i < length; i++) {
351
    for (i=0; i < length; i++) {
352
	col = *pixel32 ++;
352
	col = *pixel32 ++;
353
	r = getred(col);
353
	r = getred(col);
354
	g = getgreen(col);
354
	g = getgreen(col);
Line 409... Line 409...
409
image convert8to32 (image img)
409
image convert8to32 (image img)
410
{
410
{
411
    image new_img;
411
    image new_img;
412
    long i;
412
    long i;
413
    rgb *pixel32;
413
    rgb *pixel32;
414
    byte *pixel8;
414
    GAbyte *pixel8;
415
    byte value;
415
    GAbyte value;
416
 
416
 
417
    if (! img)
417
    if (! img)
418
	return img;
418
	return img;
419
 
419
 
420
    new_img = newimage(img->width, img->height, 32);
420
    new_img = newimage(img->width, img->height, 32);
421
    if (! new_img)
421
    if (! new_img)
422
	return new_img;
422
	return new_img;
423
 
423
 
424
    pixel32 = (rgb *) new_img->pixels;
424
    pixel32 = (rgb *) new_img->pixels;
425
    pixel8 = (byte *) img->pixels;
425
    pixel8 = (GAbyte *) img->pixels;
426
 
426
 
427
    for (i=img->width * img->height; i; i--) {
427
    for (i=img->width * img->height; i; i--) {
428
	value = *pixel8 ++;
428
	value = *pixel8 ++;
429
	if (value >= img->cmapsize)
429
	if (value >= img->cmapsize)
430
	    value = img->cmapsize - 1;
430
	    value = img->cmapsize - 1;
Line 461... Line 461...
461
    long	i, j, length;
461
    long	i, j, length;
462
    int	old_value, new_value;
462
    int	old_value, new_value;
463
    rgb	col;
463
    rgb	col;
464
    int	new_size;
464
    int	new_size;
465
    long *	histogram;
465
    long *	histogram;
466
    byte *	translate;
466
    GAbyte *	translate;
467
    rgb *	new_cmap;
467
    rgb *	new_cmap;
468
 
468
 
469
    if (! img)
469
    if (! img)
470
	return;
470
	return;
471
    if (img->depth > 8)
471
    if (img->depth > 8)
472
	return;
472
	return;
473
 
473
 
474
    histogram = array(256, long);
474
    histogram = array(256, long);
475
    translate = array(256, byte);
475
    translate = array(256, GAbyte);
476
 
476
 
477
    /* Generate a colour histogram: */
477
    /* Generate a colour histogram: */
478
    length = img->width * img->height;
478
    length = img->width * img->height;
479
    for (i=0; i < length; i++)
479
    for (i=0; i < length; i++)
480
	histogram[img->pixels[i]] ++;
480
	histogram[img->pixels[i]] ++;
Line 629... Line 629...
629
    long  i, size;
629
    long  i, size;
630
    int   width = 0, height = 0, depth = 8;
630
    int   width = 0, height = 0, depth = 8;
631
    int   cmapsize = 0;
631
    int   cmapsize = 0;
632
    rgb * cmap = NULL;
632
    rgb * cmap = NULL;
633
    rgb  *pixel32;
633
    rgb  *pixel32;
634
    byte *pixel8;
634
    GAbyte *pixel8;
635
    image img = NULL;
635
    image img = NULL;
636
 
636
 
637
    if (file == NULL)
637
    if (file == NULL)
638
	return NULL;
638
	return NULL;
639
 
639
 
Line 698... Line 698...
698
static void save_header_image_file(FILE *file, char *name, image img)
698
static void save_header_image_file(FILE *file, char *name, image img)
699
{
699
{
700
    long i, size;
700
    long i, size;
701
    int width;
701
    int width;
702
    rgb * pixel32;
702
    rgb * pixel32;
703
    byte *pixel8;
703
    GAbyte *pixel8;
704
 
704
 
705
    if (file == NULL)
705
    if (file == NULL)
706
	return;
706
	return;
707
    if (img == NULL)
707
    if (img == NULL)
708
	return;
708
	return;
Line 965... Line 965...
965
{
965
{
966
    int value;
966
    int value;
967
    long x, y;
967
    long x, y;
968
    long dx, dy, sx, sy;
968
    long dx, dy, sx, sy;
969
    long dw, dh, sw, sh;
969
    long dw, dh, sw, sh;
970
    byte * src_pixels = src->pixels;
970
    GAbyte * src_pixels = src->pixels;
971
    byte * dest_pixels = dest->pixels;
971
    GAbyte * dest_pixels = dest->pixels;
972
 
972
 
973
    dw = dest->width;
973
    dw = dest->width;
974
    dh = dest->height;
974
    dh = dest->height;
975
    sw = src->width;
975
    sw = src->width;
976
    sh = src->height;
976
    sh = src->height;