Ignore:
Timestamp:
Mar 2, 2016, 3:08:27 PM (9 years ago)
Author:
meunier
Message:
  • Bug fixes in Rosenfeld
Location:
soft/giet_vm/applications/rosenfeld/nrc2
Files:
4 edited

Legend:

Unmodified
Added
Removed
  • soft/giet_vm/applications/rosenfeld/nrc2/Makefile

    r793 r798  
    77
    88# -- File list ----------
    9 FILE = nralloc1.c, nralloc2.c, nralloc2x.c, nrarith0.c, nrarith1.c, nrarith2.c, nrarith2x.c, nrbool1.c, nrbool2.c,  nrhisto.c, nrio0.c, nrio1.c, nrio2.c, nrkernel.c, nrlinalg.c, nrlut.c, nrmem1.c, nrmem1x.c, nrmem2.c, nrmem2x.c, nrset1.c, nrset2.c, nrset2x.c, nrsort1.c, nrsort2.c, nrwrap1.c, nrwrap2.c
     9FILE = nralloc1.c, nralloc2.c, nralloc2x.c, nrarith0.c, nrarith1.c, nrarith2.c, nrarith2x.c, nrbool1.c, nrbool2.c, nrhisto.c, nrio0.c, nrio1.c, nrio2.c, nrkernel.c, nrlinalg.c, nrlut.c, nrmem1.c, nrmem1x.c, nrmem2.c, nrmem2x.c, nrset1.c, nrset2.c, nrset2x.c, nrsort1.c, nrsort2.c, nrwrap1.c, nrwrap2.c
    1010
    1111
     
    1919C_DEBUG_FLAGS = -O0
    2020C_OPTIMISATION_FLAGS = -std=c99 -O2 -fstrict-aliasing
    21 C_OS_FLAGS = -DGTODay
     21C_OS_FLAGS = -DGTODay -DTARGET_OS=GIETVM
    2222C_CONFIG_FLAGS = -DCLI
    2323C_INC_FLAGS = -I$(INC_PATH) -I../../.. -I../../../giet_libs
     
    4141CFLAGSW := -Wredundant-decls -Wdisabled-optimization -Winline -Wpointer-arith -Wsign-compare -Wendif-labels
    4242CFLAGSCPU := -mips32 -EL -G0 -mhard-float
    43 CFLAGS := $(CFLAGS) -g -Wall -fomit-frame-pointer $(CFLAGSW) $(CFLAGSCPU) -I$(DIR_INC) -fno-builtin -ffreestanding
     43CFLAGS := $(CFLAGS) -g -Wall -fomit-frame-pointer $(CFLAGSW) $(CFLAGSCPU) -fno-builtin -ffreestanding
    4444
    4545
  • soft/giet_vm/applications/rosenfeld/nrc2/include/nrc_os_config.h

    r791 r798  
    11
    2 #define TARGET_OS GIETVM
    32
    4 #if TARGET_OS==GIETVM
     3#define GIETVM 1
     4#define LINUX 2
     5
     6#if TARGET_OS == GIETVM
    57    #define printf(...)  giet_tty_printf(__VA_ARGS__)
    68
     
    1214    #define fscanf(x, ...)  ;
    1315    #define exit(x)         giet_pthread_exit(NULL)
     16#else
    1417#endif
    1518
  • soft/giet_vm/applications/rosenfeld/nrc2/include/nrio2.h

    r772 r798  
    239239IMAGE_EXPORT(uint8 **) LoadPGM_bmatrix  (char *filename, int *nrl, int *nrh, int *ncl, int *nch);
    240240IMAGE_EXPORT(void)     LoadPGM_bmatrix2 (char *filename, int *nrl, int *nrh, int *ncl, int *nch, uint8 **m);
    241 IMAGE_EXPORT(void)    MLoadPGM_bmatrix (char *filename, int nrl, int nrh, int ncl, int nch, uint8 **m);
     241IMAGE_EXPORT(void)     MLoadPGM_bmatrix (char *filename, int nrl, int nrh, int ncl, int nch, uint8 **m);
    242242
    243243IMAGE_EXPORT(void)     SavePGM_bmatrix  (uint8 **m, int nrl, int nrh, int ncl, int nch, char *filename);
    244244IMAGE_EXPORT(void)     SavePGM_ui8matrix(uint8 **m, int nrl, int nrh, int ncl, int nch, char *filename);
    245245
    246 IMAGE_EXPORT(rgb8 **) LoadPPM_rgb8matrix (char *filename, int *nrl, int *nrh, int *ncl, int *nch);
    247 IMAGE_EXPORT(void)    LoadPPM_rgb8matrix2(char *filename, int *nrl, int *nrh, int *ncl, int *nch, rgb8 **m);
    248 
    249 IMAGE_EXPORT(void)    SavePPM_rgb8matrix(rgb8 **m, int nrl, int nrh, int ncl, int nch, char *filename);
     246IMAGE_EXPORT(rgb8 **)  LoadPPM_rgb8matrix (char *filename, int *nrl, int *nrh, int *ncl, int *nch);
     247IMAGE_EXPORT(void)     LoadPPM_rgb8matrix2(char *filename, int *nrl, int *nrh, int *ncl, int *nch, rgb8 **m);
     248
     249IMAGE_EXPORT(void)     SavePPM_rgb8matrix(rgb8 **m, int nrl, int nrh, int ncl, int nch, char *filename);
     250
     251
     252
    250253#ifdef __cplusplus
    251254}
  • soft/giet_vm/applications/rosenfeld/nrc2/src/nrio2.c

    r772 r798  
    1313
    1414#include <stdio.h>
    15 #include <stddef.h>
    1615#include <stdlib.h>
     16#include <string.h>
    1717
    1818#include "nrc_os_config.h"
     19
     20#if TARGET_OS == LINUX
     21    #include <sys/types.h>
     22    #include <sys/stat.h>
     23    #include <fcntl.h>
     24    #include <unistd.h>
     25#endif
     26
     27
    1928#include "mypredef.h"
    2029#include "nrtype.h"
     
    2837#include "nrio1.h"
    2938#include "nrio2.h"
     39
     40#define isalnum(x) (((x) >= 0x30 && (x) <= 0x39) \
     41                 || ((x) >= 0x41 && (x) <= 0x5A) \
     42                 || ((x) >= 0x61 && (x) <= 0x7A))
     43
    3044
    3145/*
     
    870884    }   
    871885}
     886
     887
     888
     889/* --------------------------------------- */
     890static char * readitem(int fd, char * buffer)
     891/* --------------------------------------- */
     892{
     893    char * aux;
     894    int k;
     895    int n;
     896   
     897    k = 0;
     898    aux = buffer;
     899    while (1) {
     900        n = read(fd, aux, 1);
     901        if (n == 0) {
     902            break;
     903        }
     904        switch (k) {
     905            case 0:
     906                if (*aux == '#') {
     907                    k = 1;
     908                }
     909                if (isalnum(*aux)) {
     910                    k = 2;
     911                    aux++;
     912                }
     913                break;
     914            case 1:
     915                if (*aux == 0xA) {
     916                    k = 0;
     917                }
     918                break;
     919            case 2:
     920                if (!isalnum(*aux)) {
     921                    *aux = 0;
     922                    return buffer;
     923                }
     924                aux++;
     925                break;
     926        }
     927    }
     928    *aux = 0;
     929    return buffer;
     930}
     931
     932
     933/* ------------------------------------------------- */
     934static void ReadPGMrow(int fd, int width, uint8 * line)
     935/* ------------------------------------------------- */
     936{
     937    read(fd, &line[0], sizeof(uint8) * width);
     938}
     939
     940
     941/* -------------------------------------------------- */
     942static void WritePGMrow(uint8 * line, int width, int fd)
     943/* -------------------------------------------------- */
     944{
     945    write(fd, &line[0], sizeof(uint8) * width);
     946}
     947
     948
     949/* ----------------------------------------------------------------------------------------------- */
     950IMAGE_EXPORT(uint8 **) LoadPGM_ui8matrix(char * filename, int * nrl, int * nrh, int * ncl, int * nch)
     951/* ----------------------------------------------------------------------------------------------- */
     952{
     953    // only for P5 binary type, not for text type
     954   
     955    int height, width, gris;
     956    uint8 ** m;
     957    int fd;
     958   
     959    char buffer[80];
     960    int i;
     961   
     962    // open file
     963    fd = open(filename, O_RDONLY);
     964    if (fd < 0) {
     965        printf("*** Error: Can't open file %s in %s.\n", filename, __func__);
     966    }
     967   
     968    // read PGM header
     969    readitem(fd, &buffer[0]);
     970    if (strcmp(&buffer[0], "P5") != 0) {
     971        printf("*** Error: Invalid file header in file %s\n", filename);
     972    }
     973   
     974    width  = atoi(readitem(fd, &buffer[0]));
     975    height = atoi(readitem(fd, &buffer[0]));
     976    gris   = atoi(readitem(fd, &buffer[0]));
     977   
     978    *nrl = 0;
     979    *nrh = height - 1;
     980    *ncl = 0;
     981    *nch = width - 1;
     982    m = ui8matrix(*nrl, *nrh, *ncl, *nch);
     983   
     984    for (i = 0; i < height; i++) {
     985        ReadPGMrow(fd, width, m[i]);
     986    }
     987   
     988    close(fd);
     989   
     990    return m;
     991}
     992
     993
     994/* ----------------------------------------------------------------------------------------------- */
     995IMAGE_EXPORT(void) SavePGM_ui8matrix(uint8 ** m, int nrl, int nrh, int ncl, int nch, char * filename)
     996/* ----------------------------------------------------------------------------------------------- */
     997{
     998    int nrow = nrh - nrl + 1;
     999    int ncol = nch - ncl + 1;
     1000   
     1001    char buffer[80];
     1002   
     1003    int fd;
     1004    int i;
     1005   
     1006    fd = open(filename, O_TRUNC | O_CREAT);
     1007    if (fd < 0) {
     1008        printf("*** Error: Impossible to open file %s in %s\n", filename, __func__);
     1009    }
     1010   
     1011    /* enregistrement de l'image au format rpgm */
     1012    snprintf(buffer, 80, "P5\n%d %d\n255\n", ncol, nrow);
     1013    write(fd, buffer, strlen(buffer));
     1014    for (i = nrl; i <= nrh; i++) {
     1015        WritePGMrow(m[i], ncol, fd);
     1016    }
     1017   
     1018    /* fermeture du fichier */
     1019    close(fd);
     1020}
     1021
     1022
     1023
Note: See TracChangeset for help on using the changeset viewer.