void BWCopy(Widget w, Position at_x, Position at_y, int value) { BitmapWidget BW = (BitmapWidget) w; XImage *storage; char *storage_data; Dimension width, height; if (QuerySet(BW->bitmap.mark.from_x, BW->bitmap.mark.from_y)) { width = BW->bitmap.mark.to_x - BW->bitmap.mark.from_x + 1; height = BW->bitmap.mark.to_y - BW->bitmap.mark.from_y + 1; storage_data = CreateCleanData(Length(width, height)); storage = CreateBitmapImage(BW, storage_data, width, height); CopyImageData(BW->bitmap.image, storage, BW->bitmap.mark.from_x, BW->bitmap.mark.from_y, BW->bitmap.mark.to_x, BW->bitmap.mark.to_y, 0, 0); DrawImageData(BW, storage, at_x, at_y, value); DestroyBitmapImage(&storage); } }
void BWStore(Widget w) { BitmapWidget BW = (BitmapWidget) w; Dimension width, height; char *storage_data; if (QuerySet(BW->bitmap.mark.from_x, BW->bitmap.mark.from_y)) { DestroyBitmapImage(&BW->bitmap.storage); width = BW->bitmap.mark.to_x - BW->bitmap.mark.from_x + 1; height = BW->bitmap.mark.to_y - BW->bitmap.mark.from_y + 1; storage_data = CreateCleanData(Length(width, height)); BW->bitmap.storage = CreateBitmapImage(BW, storage_data, width, height); CopyImageData(BW->bitmap.image, BW->bitmap.storage, BW->bitmap.mark.from_x, BW->bitmap.mark.from_y, BW->bitmap.mark.to_x, BW->bitmap.mark.to_y, 0, 0); } }
XImage * ScaleBitmapImage(BitmapWidget BW, XImage *src, double scale_x, double scale_y) { char *data; XImage *dst; Table table; Position x, y, w, h; Dimension width, height; bit pixel; width = max(rint(scale_x * src->width), 1); height = max(rint(scale_y * src->height), 1); data = CreateCleanData(Length(width, height)); dst = CreateBitmapImage(BW, data, width, height); /* * It would be nice to check if width or height < 1.0 and * average the skipped pixels. But, it is slow as it is now. */ if (scale_x == 1.0 && scale_y == 1.0) memmove( dst->data, src->data, Length(width, height)); else { table.x = (Position *) XtMalloc(sizeof(Position) * src->width); table.y = (Position *) XtMalloc(sizeof(Position) * src->height); table.width = (Dimension *) XtMalloc(sizeof(Dimension) * src->width); table.height = (Dimension *) XtMalloc(sizeof(Dimension) * src->height); for (x = 0; x < src->width; x++) { table.x[x] = rint(scale_x * x); table.width[x] = rint(scale_x * (x + 1)) - rint(scale_x * x); } for (y = 0; y < src->height; y++) { table.y[y] = rint(scale_y * y); table.height[y] = rint(scale_y * (y + 1)) - rint(scale_y * y); } for (x = 0; x < src->width; x++) for (y = 0; y < src->height; y++) { pixel = GetBit(src, x, y); for (w = 0; (int)w < (int)table.width[x]; w++) for (h = 0; (int)h < (int)table.height[y]; h++) if (pixel) SetBit(dst, table.x[x] + w, table.y[y] + h); } XtFree((char *)table.x); XtFree((char *)table.y); XtFree((char *)table.width); XtFree((char *)table.height); } return (dst); }
/* ARGSUSED */ static Boolean ConvertSelection(Widget w, Atom *selection, Atom *target, Atom *type, XtPointer *val_ret, unsigned long *length, int *format) { XPointer *value = (XPointer *)val_ret; BitmapWidget BW = (BitmapWidget) w; Pixmap *pixmap; char *data; XImage *image; Dimension width, height; switch (*target) { /* XA_TARGETS undefined ?!? case XA_TARGETS: *type = XA_ATOM; *value = (XPointer) bitmapClassRec.bitmap_class.targets; *length = bitmapClassRec.bitmap_class.num_targets; *format = 32; return True; */ case XA_BITMAP: case XA_PIXMAP: if (BWQueryMarked(w)) { width = BW->bitmap.mark.to_x - BW->bitmap.mark.from_x + 1; height = BW->bitmap.mark.to_y - BW->bitmap.mark.from_y + 1; data = CreateCleanData(Length(width, height)); image = CreateBitmapImage(BW, data, width, height); CopyImageData(BW->bitmap.image, image, BW->bitmap.mark.from_x, BW->bitmap.mark.from_y, BW->bitmap.mark.to_x, BW->bitmap.mark.to_y, 0, 0); pixmap = (Pixmap *) XtMalloc(sizeof(Pixmap)); *pixmap = GetPixmap(BW, image); DestroyBitmapImage(&image); } else if (BWQueryStored(w)) { pixmap = (Pixmap *) XtMalloc(sizeof(Pixmap)); *pixmap = GetPixmap(BW, BW->bitmap.storage); } else return False; *type = XA_PIXMAP; *value = (XPointer) pixmap; *length = 1; *format = 32; return True; default: return False; } }
void BWFold(Widget w) { BitmapWidget BW = (BitmapWidget) w; Position x, y, new_x, new_y; Dimension horiz, vert; char *storage_data; XImage *storage; storage_data = CreateCleanData(Length(BW->bitmap.image->width, BW->bitmap.image->height)); storage = CreateBitmapImage(BW, storage_data, (Dimension) BW->bitmap.image->width, (Dimension) BW->bitmap.image->height); TransferImageData(BW->bitmap.image, storage); BW->bitmap.fold ^= True; horiz = (BW->bitmap.image->width + BW->bitmap.fold) / 2; vert = (BW->bitmap.image->height + BW->bitmap.fold) / 2; for (x = 0; x < BW->bitmap.image->width; x++) for (y = 0; y < BW->bitmap.image->height; y++) { new_x = (int)(x + horiz) % (int)BW->bitmap.image->width; new_y = (int)(y + vert) % (int)BW->bitmap.image->height; if(GetBit(BW->bitmap.image, new_x, new_y) != GetBit(storage, x, y)) InvertPoint(BW, new_x, new_y); } DestroyBitmapImage(&storage); if (QuerySet(BW->bitmap.hot.x, BW->bitmap.hot.y)) BWSetHotSpot(w, (Position) ((int)(BW->bitmap.hot.x+horiz) %(int)BW->bitmap.image->width), (Position) ((int)(BW->bitmap.hot.y+vert) %(int)BW->bitmap.image->height) ); }
XImage * ConvertToBitmapImage(BitmapWidget BW, XImage *image) { XImage *bitmap_image; char *data; Position x, y; data = CreateCleanData(Length(image->width, image->height)); bitmap_image = CreateBitmapImage(BW, data, (Dimension) image->width, (Dimension) image->height); for (x = 0; x < min(image->width, bitmap_image->width); x++) for (y = 0; y < min(image->height, bitmap_image->height); y++) if ((XGetPixel(image, x, y) != 0) != GetBit(bitmap_image, x, y)) InvertBit(bitmap_image, x, y); return bitmap_image; }