Página principal | Jerarquía de la clase | Lista alfabética | Lista de componentes | Lista de archivos | Miembros de las clases | Archivos de los miembros | Páginas relacionadas

_img_sgi.C

Ir a la documentación de este archivo.
00001 //===========================================================================
00002 //= _img_sgi.cc                                           Noviembre de 1999 =
00003 //=-------------------------------------------------------------------------=
00004 //= Lector de archivos de imagen en formato SGI RGB.                        =
00005 //=-------------------------------------------------------------------------=
00006 //= ADVERTENCIA: ESTE SOFTWARE NO ESTA CONCEBIDO NI DISENNADO PARA EL USO   =
00007 //= EN EQUIPO DE CONTROL EN LINEA EN ENTORNOS PELIGROSOS QUE REQUIERAN UN   =
00008 //= DESEMPENNO LIBRE DE FALLAS, COMO LA OPERACION DE PLANTAS NUCLEARES,     = 
00009 //= SISTEMAS DE NAVEGACION O COMUNICACION EN AVIONES, TRAFICO AEREO,        =
00010 //= EQUIPO MEDICO DEL CUAL DEPENDAN VIDAS HUMANAS O SISTEMAS DE ARMAMENTO,  =
00011 //= EN LOS CUALES UNA FALLA EN EL SOFTWARE PUEDA IMPLICAR DIRECTAMENTE LA   =
00012 //= MUERTE, DANNOS PERSONALES O DANNOS FISICOS Y/O AMBIENTALES GRAVES       =
00013 //= ("ACTIVIDADES DE ALGO RIESGO").                                         =
00014 //=-------------------------------------------------------------------------=
00015 //= Autor original: Oscar J. Chavarro G.  A.K.A. JEDILINK. Copyright (c),   =
00016 //= 1997 - 2003, oscarchavarro@hotmail.com                                  =
00017 //= AQUYNZA es software libre, y se rige bajo los terminos de la licencia   =
00018 //= LGPL de GNU (http://www.gnu.org). Para mayor informacion respecto a la  =
00019 //= licencia de uso, consulte el archivo ./doc/LICENCIA en la distribucion. =
00020 //===========================================================================
00021 
00022 #include "toolkits/media/_img_sgi.h"
00023 
00024 //===========================================================================
00025 //= Constantes y macros                                                     =
00026 //===========================================================================
00027 
00028 #define IMAGIC      0x01da
00029 #define IMAGIC_SWAP 0xda01
00030 
00031 #define SWAP_SHORT_BYTES(x) ((((x) & 0xff) << 8) | (((x) & 0xff00) >> 8))
00032 #define SWAP_LONG_BYTES(x) (((((x) & 0xff) << 24) | (((x) & 0xff00) << 8)) | \
00033 ((((x) & 0xff0000) >> 8) | (((x) & 0xff000000) >> 24)))
00034 
00035 //===========================================================================
00036 //= Clase LECTOR_SGIRGB                                                     =
00037 //===========================================================================
00038 
00039 BOOLEAN
00040 LECTOR_SGIRGB::init(FILE *_fd)
00041 {
00042     unsigned long *rinic, *rtam, ulTmp;
00043     int x, i;
00044 
00045     fd = _fd;
00046     /* Read the image header */
00047     fread(this, 1, 12, fd);
00048     /* Check byte order  */
00049     if ( imagic == IMAGIC_SWAP ) {
00050         type = (UWORD)SWAP_SHORT_BYTES(type);
00051         dim = (UWORD)SWAP_SHORT_BYTES(dim);
00052         x_tam = (UWORD)SWAP_SHORT_BYTES(x_tam);
00053         y_tam = (UWORD)SWAP_SHORT_BYTES(y_tam);
00054         sizeZ = (UWORD)SWAP_SHORT_BYTES(sizeZ);
00055     }
00056 
00057     for ( i = 0 ; i <= sizeZ ; i++ ) {
00058         tmp[i] = new BYTE [x_tam*256];
00059         if ( !tmp[i] ) {
00060             fprintf(stderr, "Out of memory!\n");
00061             return FALSE;
00062         }
00063     }
00064 
00065     if ( (type & 0xFF00) == 0x0100 ) /* RLE image */ {
00066         x = y_tam * sizeZ * sizeof(long);
00067         rowStart = new unsigned long [ x/sizeof(long) ];
00068         rowSize = new unsigned long [ x/sizeof(long) ];
00069         if (rowStart == NULL || rowSize == NULL) {
00070             fprintf(stderr, "Out of memory!\n");
00071             return FALSE;
00072         }
00073         rleEnd = 512 + (2 * x);
00074         fseek(fd, 512, SEEK_SET);
00075         fread(rowStart, 1, x, fd);
00076         fread(rowSize, 1, x, fd);
00077         if (imagic == IMAGIC_SWAP) {
00078             x /= sizeof(long);
00079             rinic = rowStart;
00080             rtam = rowSize;
00081             while ( x-- ) {
00082                 ulTmp = *rinic;
00083                 *rinic++ = SWAP_LONG_BYTES(ulTmp);
00084                 ulTmp = *rtam;
00085                 *rtam++ = SWAP_LONG_BYTES(ulTmp);
00086             }
00087         }
00088     }
00089     return TRUE;
00090 }
00091 
00092 void
00093 LECTOR_SGIRGB::elim(void)
00094 {
00095     int i;
00096 
00097     for ( i = 0 ; i <= sizeZ ; i++ ) delete tmp[i];
00098 }
00099 
00100 void
00101 LECTOR_SGIRGB::leer_linea(unsigned char *buf, int y, int z)
00102 {
00103     unsigned char *iPtr, *oPtr, pixel;
00104     int count;
00105 
00106     if ((type & 0xFF00) == 0x0100)  /* RLE image */ {
00107         fseek(fd, rowStart[y+z*y_tam], SEEK_SET);
00108         fread(tmp[0], 1, (unsigned int)rowSize[y+z*y_tam],
00109               fd);
00110 
00111         iPtr = tmp[0];
00112         oPtr = buf;
00113         do {
00114             pixel = *iPtr++;
00115             count = (int)(pixel & 0x7F);
00116             if ( !count ) return;
00117             if ( pixel & 0x80 ) {
00118                 while ( count-- ) *oPtr++ = *iPtr++;                
00119               }
00120               else {
00121                 pixel = *iPtr++;
00122                 while ( count-- ) *oPtr++ = pixel;
00123                 count = 1;
00124             }
00125          } while ( count );
00126       }
00127       else /* verbatim image */ {
00128         fseek(fd, 512+(y*x_tam)+(z*x_tam*y_tam),
00129               SEEK_SET);
00130         fread(buf, 1, x_tam, fd);
00131     }
00132 }
00133 
00134 void
00135 LECTOR_SGIRGB::leer(BYTE *Data)
00136 {
00137     int i, j, k;
00138     int remain = 0;
00139 
00140     switch ( sizeZ ) {
00141       case 1:
00142         remain = x_tam % 4;
00143         break;
00144       case 2:
00145         remain = x_tam % 2;
00146         break;
00147       case 3:
00148         remain = (x_tam * 3) & 0x3;
00149         if (remain)
00150             remain = 4 - remain;
00151         break;
00152       case 4:
00153         remain = 0;
00154         break;
00155     }
00156 
00157     for (i = 0; i < y_tam; i++) 
00158     {
00159         for ( k = 0; k < sizeZ ; k++ )
00160             leer_linea(tmp[k+1], i, k);
00161         for (j = 0; j < x_tam; j++) 
00162             for ( k = 1; k <= sizeZ ; k++ )
00163                 *Data++ = *(tmp[k] + j);
00164         Data += remain;
00165     }
00166 }
00167 
00168 //===========================================================================
00169 //= EOF                                                                     =
00170 //===========================================================================
00171 

Este archivo HTML ha sido generado automáticamente a partir del código fuente AQUYNZA. NO LO EDITE. Para mayor información contacte al autor.