/* * * (c) COPYRIGHT INRIA, 1996. * Please first read the full copyright statement in file COPYRIGHT. * */ /* * Warning: * This module is part of the Thot library, which was originally * developed in French. That's why some comments are still in * French, but their translation is in progress and the full module * will be available in English in the next release. * */ /* * Author: N. Layaida (INRIA) * R. Guetari (W3C/INRIA) Windows NT/95 */ #include "thot_sys.h" #include "constmedia.h" #include "typemedia.h" #include "picture.h" #include "frame.h" #define THOT_EXPORT extern #include "picture_tv.h" #include "frame_tv.h" #include "picture_f.h" #include "font_f.h" #include "units_f.h" /*---------------------------------------------------------------------- XbmCreate reads and produces the bitmap read from the file fn. updates the wif, hif, xif , yif ----------------------------------------------------------------------*/ #ifdef __STDC__ Drawable XbmCreate (char* fn, PictureScaling pres, int* xif, int* yif, int* wif, int* hif, unsigned long BackGroundPixel, Drawable* mask1) #else /* __STDC__ */ Drawable XbmCreate (fn, pres, xif, yif, wif, hif, BackGroundPixel, mask1) char *fn; PictureScaling pres; int *xif; int *yif; int *wif; int *hif; unsigned long BackGroundPixel; Drawable *mask1; #endif /* __STDC__ */ { Pixmap pixmap; # ifndef _WINDOWS int status; int w, h; Pixmap bitmap; int xHot, yHot; *mask1 = None; status = XReadBitmapFile (TtDisplay, TtRootWindow, fn, &w, &h, &bitmap, &xHot, &yHot); if (status != BitmapSuccess) return (Drawable) None; else { *xif = 0; *yif = 0; *wif = w; *hif = h; pixmap = XCreatePixmap (TtDisplay, TtRootWindow, w, h, DefaultDepth (TtDisplay, DefaultScreen (TtDisplay))); XCopyPlane (TtDisplay, bitmap, pixmap, GCpicture, 0, 0, w, h, 0, 0, 1); XFreePixmap (TtDisplay, bitmap); return pixmap; } # else /* _WINDOWS */ pixmap = (HBITMAP) 0; # if 0 HANDLE hBmFileName ; BITMAPFILEHEADER bmFileHeader ; BITMAPINFOHEADER bmInfoHeader ; BITMAPINFO* bmInfo ; BITMAP bmp; DWORD dwRead ; HGLOBAL hMem1; HGLOBAL hMem2; BYTE* lpvBits; /* Retrieve a handle identifying the file. */ hBmFileName = CreateFile (fn, GENERIC_READ, FILE_SHARE_READ, (LPSECURITY_ATTRIBUTES) NULL, OPEN_EXISTING, FILE_ATTRIBUTE_READONLY, (HANDLE) NULL); /* Retrieve the BITMAPFILEHEADER structure. */ ReadFile (hBmFileName, &bmFileHeader, sizeof (BITMAPFILEHEADER), &dwRead, (LPOVERLAPPED) NULL); /* Retrieve the BITMAPFILEHEADER structure. */ ReadFile (hBmFileName, &bmInfoHeader, sizeof (BITMAPINFOHEADER), &dwRead, (LPOVERLAPPED) NULL); /* Allocate memory for the BITMAPINFO structure. */ hMem1 = GlobalAlloc (GHND, sizeof(BITMAPINFOHEADER) + ((1<bmiHeader.biSize = bmInfoHeader.biSize; bmInfo->bmiHeader.biWidth = bmInfoHeader.biWidth; bmInfo->bmiHeader.biHeight = bmInfoHeader.biHeight; bmInfo->bmiHeader.biPlanes = bmInfoHeader.biPlanes; bmInfo->bmiHeader.biBitCount = bmInfoHeader.biBitCount; bmInfo->bmiHeader.biCompression = bmInfoHeader.biCompression; bmInfo->bmiHeader.biSizeImage = bmInfoHeader.biSizeImage; bmInfo->bmiHeader.biXPelsPerMeter = bmInfoHeader.biXPelsPerMeter; bmInfo->bmiHeader.biYPelsPerMeter = bmInfoHeader.biYPelsPerMeter; bmInfo->bmiHeader.biClrUsed = bmInfoHeader.biClrUsed; bmInfo->bmiHeader.biClrImportant = bmInfoHeader.biClrImportant; /* * Retrieve the color table. * 1 << bmInfoHeader.biBitCount == 2 ^ bmInfoHeader.biBitCount */ ReadFile (hBmFileName, bmInfo->bmiColors, ((1< 0) { xif += delta; wif = PicWArea; } else { xtmp = -delta; PicWArea = wif; } delta = (hif - PicHArea) / 2; if (delta > 0) { yif += delta; hif = PicHArea; } else { ytmp = -delta; PicHArea = hif; } break; case ReScale: if ((float) PicHArea / (float) PicWArea <= (float) hif / (float) wif) { Scx = (float) wif / (float) PicWArea; yif += (hif - (PicHArea * Scx)) / 2; hif = PicHArea * Scx; } else { Scy = (float) hif / (float) PicHArea; xif += (wif - (PicWArea * Scy)) / 2; wif = PicWArea * Scy; } break; default: break; } if (pix != None) { pict = XGetImage (TtDisplay, pix, xtmp, ytmp, (unsigned int) PicWArea, (unsigned int) PicHArea, AllPlanes, XYPixmap); wim = pict->width; him = pict->height; fprintf ((FILE *) fd, "gsave %d -%d translate\n", PixelToPoint (xif), PixelToPoint (yif + hif)); fprintf ((FILE *) fd, "%d %d %d %d DumpImage\n", pict->width, pict->height, PixelToPoint (wif), PixelToPoint (hif)); nbb = (wim + 7) / 8; if (ImageByteOrder (TtDisplay) == LSBFirst) LittleXBigEndian ((unsigned char *) pict->data, (long) (pict->bytes_per_line * him)); for (j = 0, pt1 = pict->data; j < him; j++, pt1 += pict->bytes_per_line) { for (i = 0, pt = pt1; i < nbb; i++) fprintf ((FILE *) fd, "%02x", ((*pt++) & 0xff) ^ 0xff); fprintf ((FILE *) fd, "\n"); } fprintf ((FILE *) fd, "grestore\n"); /* frees the allocated space for the bitmap in memory */ XDestroyImage (pict); XFreePixmap (TtDisplay, pix); } #endif /* !_WINDOWS */ } /*---------------------------------------------------------------------- IsXbmFormat check if the file header is of an xbm format ----------------------------------------------------------------------*/ #ifdef __STDC__ boolean IsXbmFormat (char *fn) #else /* __STDC__ */ boolean IsXbmFormat (fn) char *fn; #endif /* __STDC__ */ { #ifdef _WINDOWS return (FALSE); #else /* _WINDOWS */ int status; int w, h; Pixmap bitmap = None; int xHot, yHot; status = XReadBitmapFile (TtDisplay, TtRootWindow, fn, &w, &h, &bitmap, &xHot, &yHot); if (bitmap != None) XFreePixmap (TtDisplay, bitmap); return (status == BitmapSuccess); #endif /* !_WINDOWS */ }