OpenCores
URL https://opencores.org/ocsvn/or1k/or1k/trunk

Subversion Repositories or1k

[/] [or1k/] [tags/] [MW_0_8_9PRE7/] [mw/] [src/] [demos/] [nanox/] [nxview.c] - Diff between revs 673 and 674

Go to most recent revision | Only display areas with differences | Details | Blame | View Log

Rev 673 Rev 674
/*
/*
 * Copyright (c) 2000, 2001 Greg Haerr <greg@censoft.com>
 * Copyright (c) 2000, 2001 Greg Haerr <greg@censoft.com>
 *
 *
 * nxview - Nano-X image viewer
 * nxview - Nano-X image viewer
 *
 *
 * Autorecognizes and displays BMP, GIF, JPEG, PNG and XPM files
 * Autorecognizes and displays BMP, GIF, JPEG, PNG and XPM files
 */
 */
#include <stdio.h>
#include <stdio.h>
#include <stdlib.h>
#include <stdlib.h>
#include <string.h>
#include <string.h>
#define MWINCLUDECOLORS
#define MWINCLUDECOLORS
#include "nano-X.h"
#include "nano-X.h"
 
 
int
int
main(int argc,char **argv)
main(int argc,char **argv)
{
{
        GR_IMAGE_ID     image_id;
        GR_IMAGE_ID     image_id;
        GR_WINDOW_ID    window_id;
        GR_WINDOW_ID    window_id;
        GR_GC_ID        gc_id;
        GR_GC_ID        gc_id;
        GR_SIZE         w = -1;
        GR_SIZE         w = -1;
        GR_SIZE         h = -1;
        GR_SIZE         h = -1;
        GR_EVENT        event;
        GR_EVENT        event;
        GR_SCREEN_INFO  sinfo;
        GR_SCREEN_INFO  sinfo;
        GR_IMAGE_INFO   info;
        GR_IMAGE_INFO   info;
        char            title[256];
        char            title[256];
 
 
        if (argc < 2) {
        if (argc < 2) {
                printf("Usage: nxview <image file> [stretch]\n");
                printf("Usage: nxview <image file> [stretch]\n");
                exit(1);
                exit(1);
        }
        }
 
 
        if (GrOpen() < 0) {
        if (GrOpen() < 0) {
                fprintf(stderr, "cannot open graphics\n");
                fprintf(stderr, "cannot open graphics\n");
                exit(1);
                exit(1);
        }
        }
 
 
        if (!(image_id = GrLoadImageFromFile(argv[1], 0))) {
        if (!(image_id = GrLoadImageFromFile(argv[1], 0))) {
                fprintf(stderr, "Can't load image file: %s\n", argv[1]);
                fprintf(stderr, "Can't load image file: %s\n", argv[1]);
                exit(1);
                exit(1);
        }
        }
 
 
        if(argc > 2) {
        if(argc > 2) {
                /* stretch to half screen size*/
                /* stretch to half screen size*/
                GrGetScreenInfo(&sinfo);
                GrGetScreenInfo(&sinfo);
                w = sinfo.cols/2;
                w = sinfo.cols/2;
                h = sinfo.rows/2;
                h = sinfo.rows/2;
        } else {
        } else {
                GrGetImageInfo(image_id, &info);
                GrGetImageInfo(image_id, &info);
                w = info.width;
                w = info.width;
                h = info.height;
                h = info.height;
        }
        }
 
 
        sprintf(title, "nxview %s", argv[1]);
        sprintf(title, "nxview %s", argv[1]);
        window_id = GrNewWindowEx(GR_WM_PROPS_APPWINDOW, title,
        window_id = GrNewWindowEx(GR_WM_PROPS_APPWINDOW, title,
                GR_ROOT_WINDOW_ID, 0, 0, w, h, BLACK);
                GR_ROOT_WINDOW_ID, 0, 0, w, h, BLACK);
 
 
        GrSelectEvents(window_id,
        GrSelectEvents(window_id,
                GR_EVENT_MASK_CLOSE_REQ|GR_EVENT_MASK_EXPOSURE);
                GR_EVENT_MASK_CLOSE_REQ|GR_EVENT_MASK_EXPOSURE);
 
 
        GrMapWindow(window_id);
        GrMapWindow(window_id);
 
 
        gc_id = GrNewGC();
        gc_id = GrNewGC();
 
 
        while (1) {
        while (1) {
                GrGetNextEvent(&event);
                GrGetNextEvent(&event);
                switch(event.type) {
                switch(event.type) {
                case GR_EVENT_TYPE_CLOSE_REQ:
                case GR_EVENT_TYPE_CLOSE_REQ:
                        GrDestroyWindow(window_id);
                        GrDestroyWindow(window_id);
                        GrDestroyGC(gc_id);
                        GrDestroyGC(gc_id);
                        GrFreeImage(image_id);
                        GrFreeImage(image_id);
                        GrClose();
                        GrClose();
                        exit(0);
                        exit(0);
                        /* no return*/
                        /* no return*/
                case GR_EVENT_TYPE_EXPOSURE:
                case GR_EVENT_TYPE_EXPOSURE:
                        GrDrawImageToFit(window_id, gc_id, 0,0, w,h, image_id);
                        GrDrawImageToFit(window_id, gc_id, 0,0, w,h, image_id);
                        break;
                        break;
                }
                }
        }
        }
 
 
        return 0;
        return 0;
}
}
 
 

powered by: WebSVN 2.1.0

© copyright 1999-2024 OpenCores.org, equivalent to Oliscience, all rights reserved. OpenCores®, registered trademark.