This is resize.c in view mode; [Download] [Up]
#include <stdio.h>
#include <libc.h>
#include <objc/objc.h>
#include <stdlib.h>
#include "../common.h"
#include "../getpixel.h"
static void resizeCopy(float factor, commonInfo *newinf,
unsigned char *map[], unsigned char *newmap[])
{
int i, x, y, px, nx, pnum, alp;
int elm[MAXPLANE];
unsigned char *pp[MAXPLANE];
int rstab[MAXWidth];
pnum = (newinf->numcolors == 1) ? 1 : 3;
alp = (newinf->alpha) ? pnum : 0;
if ((x = newinf->width) < newinf->height)
x = newinf->height;
for (i = 0; i < x; i++)
rstab[i] = (float)i / factor;
for (i = 0; i < 5; i++)
pp[i] = newmap[i];
for (y = 0; y < newinf->height; y++) {
resetPixel(map, rstab[y]);
for (px = -1, x = 0; x < newinf->width; x++) {
for (nx = rstab[x]; px < nx; px++)
getPixelA(elm);
for (i = 0; i < pnum; i++)
*pp[i]++ = elm[i];
if (alp)
*pp[alp]++ = elm[ALPHA];
}
}
}
commonInfo *makeResizedMap(float factor, commonInfo *cinf,
unsigned char *map[], unsigned char *newmap[])
{
commonInfo *newinf = NULL;
unsigned char *planes[MAXPLANE];
int pn;
planes[0] = NULL;
if ((newinf = (commonInfo *)malloc(sizeof(commonInfo))) == NULL)
goto ErrEXIT;
*newinf = *cinf;
newinf->width = cinf->width * factor;
newinf->height = cinf->height * factor;
newinf->xbytes = byte_length(newinf->bits, newinf->width);
if (newinf->cspace == NX_OneIsBlackColorSpace)
newinf->cspace = NX_OneIsWhiteColorSpace;
newinf->isplanar = YES;
if (newinf->width > MAXWidth)
goto ErrEXIT;
newinf->palette = NULL;
if (cinf->palette) {
newinf->palette = copyPalette(cinf->palette, cinf->palsteps);
if (newinf->palette == NULL)
goto ErrEXIT;
}
pn = (cinf->numcolors == 1) ? 1 : 3;
if (cinf->alpha) ++pn;
if (allocImage(planes, newinf->width, newinf->height, 8, pn))
goto ErrEXIT;
if (initGetPixel(cinf) != 0)
goto ErrEXIT;
resizeCopy(factor, newinf, map, planes);
if (newinf->bits == 8) {
int i;
for (i = 0; i < pn; i++)
newmap[i] = planes[i];
}else {
if (allocImage(newmap,
newinf->width, newinf->height, newinf->bits, pn))
goto ErrEXIT;
packWorkingImage(newinf, pn, planes, newmap);
free((void *)planes[0]);
}
return newinf;
ErrEXIT:
if (newinf) {
if (newinf->palette) free((void *)newinf->palette);
free((void *)newinf);
}
if (planes[0]) free((void *)planes[0]);
return NULL;
}
These are the contents of the former NiCE NeXT User Group NeXTSTEP/OpenStep software archive, currently hosted by Netfuture.ch.