home *** CD-ROM | disk | FTP | other *** search
/ Big Green CD 8 / BGCD_8_Dev.iso / NEXTSTEP / Graphics / ToyViewer-2.6a / src / TVpbService.m < prev    next >
Encoding:
Text File  |  1996-12-16  |  2.3 KB  |  92 lines

  1. #import <appkit/publicWraps.h>
  2. #import <appkit/Application.h>
  3. #import <appkit/NXImage.h>
  4. #import <appkit/Pasteboard.h>
  5. #import <appkit/Listener.h>
  6. #import <appkit/nextstd.h>
  7. #import <appkit/errors.h>
  8. #import <stdio.h>
  9. #import <stdlib.h>
  10. #import <string.h>
  11. #import <libc.h>
  12. #import <sys/types.h>
  13. #import "TVController.h"
  14. #import "ToyWin.h"
  15. #import "strfunc.h"
  16. #import "common.h"
  17.  
  18. /*  Program by T. Ogihara
  19.     This code is based on:
  20.     GIFFilter.m, Graphics Interchange Format (GIF) image filter service.
  21.     Author: Michael McCulloch
  22. */
  23.  
  24. @implementation TVController (PBService)
  25.  
  26. extern const char **fileTypeBuffer;
  27. extern short *fileTypeIDBuffer;
  28.  
  29.  
  30. - convertToTIFF:pasteboard userData:(const char *)userData 
  31.           error:(char **)errorMessage
  32. {
  33.     int i;
  34.     NXAtom currentType;
  35.     char *data;
  36.     int dataLen;
  37.     char filename[MAXFILENAMELEN];
  38.     NXStream *tiffStream;
  39.     static int numTypes = 0;
  40.     static NXAtom *convTypes = NULL;
  41.  
  42.     if(!numTypes){
  43.         for (i = 0; fileTypeBuffer[i]; i++) ;
  44.         convTypes = (NXAtom *)malloc(sizeof(NXAtom) * i);
  45.         for (i = 0, numTypes = 0; fileTypeBuffer[i]; i++) {
  46.             if (fileTypeIDBuffer[i] != Type_tiff
  47.                 && fileTypeIDBuffer[i] != Type_eps)
  48.             convTypes[numTypes++]
  49.                 = NXCreateFilenamePboardType(fileTypeBuffer[i]);
  50.         }
  51.         convTypes[numTypes] = NULL;
  52.     }
  53.  
  54.     currentType = [pasteboard findAvailableTypeFrom:convTypes num:numTypes];
  55.     if (!currentType)
  56.         return self;
  57.     [pasteboard readType:currentType data:&data length:&dataLen];
  58.     if(!data || dataLen <= 0)
  59.         return self;
  60.     /* Get the first name of the file list... */
  61.     for (i = 0; i < dataLen; i++) {
  62.         if (data[i] == 0 || data[i] == '\t') {
  63.             filename[i] = 0;
  64.             break;
  65.         }
  66.         filename[i] = data[i];
  67.     }
  68.     // Deallocate the file name list
  69.     [pasteboard deallocatePasteboardData:data length:dataLen];
  70.  
  71.     if ((i = getExtension(filename)) == 0)
  72.         return self; /* No Extension */
  73.     if (access(filename, R_OK) != 0)
  74.         return self;
  75.     tiffStream = [self openStreamFromFile:filename : &filename[i]];
  76.     if (tiffStream == NULL)
  77.         return self;
  78.  
  79.     NX_DURING
  80.     [pasteboard declareTypes:&NXTIFFPboardType num:1 owner:self];
  81.     [pasteboard writeType:NXTIFFPboardType fromStream:tiffStream];
  82.     NX_HANDLER
  83.     NXLogError("Error occurred while converting file %s:",filename);
  84.     NXReportError(&NXLocalHandler);
  85.     NX_ENDHANDLER
  86.  
  87.     NXCloseMemory(tiffStream, NX_FREEBUFFER);
  88.     return self;
  89. }
  90.  
  91. @end
  92.