From fb44ccb82ddc0f80e67730416568fe74ac466efb Mon Sep 17 00:00:00 2001 From: kaetemi Date: Wed, 19 Nov 2014 16:20:14 +0100 Subject: [PATCH 1/7] Remove PIC library --- code/nel/tools/3d/tile_edit/Browse.cpp | 6 +- code/nel/tools/3d/tile_edit/CMakeLists.txt | 2 +- .../nel/tools/3d/tile_edit/PIC/PIC_System.cpp | 126 ---- code/nel/tools/3d/tile_edit/PIC/Pic_BMP.cpp | 215 ------ code/nel/tools/3d/tile_edit/PIC/Pic_JPG.cpp | 160 ----- .../nel/tools/3d/tile_edit/PIC/Pic_Manage.cpp | 637 ------------------ code/nel/tools/3d/tile_edit/PIC/Pic_TGA.cpp | 215 ------ code/nel/tools/3d/tile_edit/PIC/pic.h | 58 -- code/nel/tools/3d/tile_edit/PIC/pic_private.h | 81 --- code/nel/tools/3d/tile_edit/PIC/readpic.cpp | 84 --- code/nel/tools/3d/tile_edit/PIC/readpic.h | 40 -- code/nel/tools/3d/tile_edit/View.cpp | 45 +- 12 files changed, 42 insertions(+), 1627 deletions(-) delete mode 100644 code/nel/tools/3d/tile_edit/PIC/PIC_System.cpp delete mode 100644 code/nel/tools/3d/tile_edit/PIC/Pic_BMP.cpp delete mode 100644 code/nel/tools/3d/tile_edit/PIC/Pic_JPG.cpp delete mode 100644 code/nel/tools/3d/tile_edit/PIC/Pic_Manage.cpp delete mode 100644 code/nel/tools/3d/tile_edit/PIC/Pic_TGA.cpp delete mode 100644 code/nel/tools/3d/tile_edit/PIC/pic.h delete mode 100644 code/nel/tools/3d/tile_edit/PIC/pic_private.h delete mode 100644 code/nel/tools/3d/tile_edit/PIC/readpic.cpp delete mode 100644 code/nel/tools/3d/tile_edit/PIC/readpic.h diff --git a/code/nel/tools/3d/tile_edit/Browse.cpp b/code/nel/tools/3d/tile_edit/Browse.cpp index 0d71ffad7..7c4f6d745 100644 --- a/code/nel/tools/3d/tile_edit/Browse.cpp +++ b/code/nel/tools/3d/tile_edit/Browse.cpp @@ -885,7 +885,7 @@ void Browse::OnChangeVariety() void Browse::OnBatchLoad () { CFileDialog sFile (true, NULL, NULL, OFN_ENABLESIZING, - "Targa bitmap (*.tga)|*.tga|All files (*.*)|*.*||",NULL); + "PNG Bitmap (*.png)|*.png|Targa bitmap (*.tga)|*.tga|All files (*.*)|*.*||",NULL); if (sFile.DoModal()==IDOK) { @@ -1365,7 +1365,7 @@ void Browse::OnExportBorder() { // Select a file CFileDialog sFile (false, NULL, NULL, OFN_ENABLESIZING, - "Targa bitmap (*.tga)|*.tga|All files (*.*)|*.*||",NULL); + "PNG Bitmap (*.png)|*.png|Targa bitmap (*.tga)|*.tga|All files (*.*)|*.*||",NULL); if (sFile.DoModal()==IDOK) { // Get the border of the bank @@ -1431,7 +1431,7 @@ void Browse::OnImportBorder() { // Select a file CFileDialog sFile (true, NULL, NULL, OFN_ENABLESIZING, - "Targa bitmap (*.tga)|*.tga|All files (*.*)|*.*||",NULL); + "PNG Bitmap (*.png)|*.png|Targa bitmap (*.tga)|*.tga|All files (*.*)|*.*||",NULL); if (sFile.DoModal()==IDOK) { // Get the border of the bank diff --git a/code/nel/tools/3d/tile_edit/CMakeLists.txt b/code/nel/tools/3d/tile_edit/CMakeLists.txt index ea7e1ac77..394359cd0 100644 --- a/code/nel/tools/3d/tile_edit/CMakeLists.txt +++ b/code/nel/tools/3d/tile_edit/CMakeLists.txt @@ -1,4 +1,4 @@ -FILE(GLOB SRC *.cpp *.h PIC/*.cpp PIC/*.h) +FILE(GLOB SRC *.cpp *.h) FILE(GLOB SRC2 cpu.cpp DllEntry.cpp Popup.* thread_win32.* TileCtrl.* TileList.* TileView.*) LIST(REMOVE_ITEM SRC ${SRC2}) diff --git a/code/nel/tools/3d/tile_edit/PIC/PIC_System.cpp b/code/nel/tools/3d/tile_edit/PIC/PIC_System.cpp deleted file mode 100644 index 439de9979..000000000 --- a/code/nel/tools/3d/tile_edit/PIC/PIC_System.cpp +++ /dev/null @@ -1,126 +0,0 @@ -#include -#include -#include -#include -#include - -#define PIC_ERRSIZE 256 - -static unsigned long PIC_Sys_MEM_Allocated; -static unsigned long PIC_Sys_MEM_NbAllocs; - -// ---------------------------------------------------------------------------------------------------------------------------------- - -void *Pic_malloc(unsigned long size) -{ - void *mem; - mem=malloc(size); - if (mem) - { - PIC_Sys_MEM_Allocated+=size; - PIC_Sys_MEM_NbAllocs++; - } - return(mem); -} -// ----- -void *Pic_calloc(unsigned long count, unsigned long size) -{ - void *mem; - mem=calloc(count,size); - if (mem) - { - PIC_Sys_MEM_Allocated+=(size*count); - PIC_Sys_MEM_NbAllocs++; - } - return(mem); -} -// ----- -void Pic_free(void *memblock) -{ - unsigned long size; - size=(unsigned long)_msize(memblock); - PIC_Sys_MEM_Allocated-=size; - PIC_Sys_MEM_NbAllocs--; - free(memblock); -} -// ----- -unsigned long Pic__msize(void *memblock) -{ - return(unsigned long)(_msize(memblock)); -} -// ----- -unsigned long PIC_GetMemNbAllocs(void) -{ - return(PIC_Sys_MEM_NbAllocs); -} -// ----- -unsigned long PIC_GetMemAllocated(void) -{ - return(PIC_Sys_MEM_Allocated); -} - -// ---------------------------------------------------------------------------------------------------------------------------------- - -static char PIC_ErrorFlag; -static char PIC_ErrorString[PIC_ERRSIZE]; -static unsigned char PIC_Sys_FnctActive=0; -static void (*PIC_Sys_Fnct)(void); - -void Pic_SetError(const char *msg, ...) -{ - char curerr[PIC_ERRSIZE],olderr[PIC_ERRSIZE]; - va_list args; - - va_start(args,msg); - vsprintf(curerr,msg,args); - va_end(args); - if ( (strlen(curerr)+strlen(PIC_ErrorString))>PIC_ERRSIZE ) return; - - if (PIC_ErrorFlag) - { - strcpy(olderr,PIC_ErrorString); - sprintf(PIC_ErrorString,"--- [PIC#%03d] :\n%s",PIC_ErrorFlag,curerr); - strcat(PIC_ErrorString,"\n"); - strcat(PIC_ErrorString,olderr); - } - else - { - sprintf(PIC_ErrorString,"--- [PIC#%03d] :\n%s",PIC_ErrorFlag,curerr); - } - PIC_ErrorFlag++; - if (PIC_Sys_FnctActive) PIC_Sys_Fnct(); - return; -} -// ----- -char* PIC_GetError(void) -{ - return(PIC_ErrorString); -} -// ----- -unsigned char PIC_Error(void) -{ - return(PIC_ErrorFlag); -} -// ----- -void PIC_ResetError(void) -{ - strcpy(PIC_ErrorString,""); - PIC_ErrorFlag=0; -} -// ----- -unsigned char PIC_OnErrorCall( void pFnct(void) ) -{ - if (pFnct != NULL) - { - PIC_Sys_Fnct=pFnct; - PIC_Sys_FnctActive=1; - } - else - { - PIC_Sys_FnctActive=0; - } - return(1); -} - -// ---------------------------------------------------------------------------------------------------------------------------------- - diff --git a/code/nel/tools/3d/tile_edit/PIC/Pic_BMP.cpp b/code/nel/tools/3d/tile_edit/PIC/Pic_BMP.cpp deleted file mode 100644 index 9ea55e029..000000000 --- a/code/nel/tools/3d/tile_edit/PIC/Pic_BMP.cpp +++ /dev/null @@ -1,215 +0,0 @@ -#include -#include -#include - -#include "pic_private.h" -#include "pic.h" - -// ---------------------------------------------------------------------------------------------------------------------------------- - -#pragma pack(1) -typedef struct BMP_HEADER -{ - unsigned short bfType; - unsigned long bfSize; - unsigned short Res1; - unsigned short Res2; - unsigned long bfOffBits; - unsigned long biSize; - unsigned long biWidth; - unsigned long biHeight; - unsigned short biPlanes; - unsigned short biBitCount; - unsigned long biCompression; - unsigned long biSizeImage; - unsigned long biXPelsPerMeter; - unsigned long biYPelsPerMeter; - unsigned long biClrUsed; - unsigned long biClrImportant; -} BMP_HEADER; -#pragma pack() - -// ---------------------------------------------------------------------------------------------------------------------------------- - -unsigned long Pic_BMP_Write( const char *FileName, - char *pPal, char *pDatas, - unsigned long w, unsigned long h, unsigned long d) - -{ - FILE *file; - BMP_HEADER bmph; - unsigned long slsize; - unsigned char *scanline; - unsigned long i; - long x,y,rest; - unsigned char r,g,b; - - file=fopen(FileName,"wb"); - if (!file) - { - return(0); - } - memset(&bmph,0,sizeof(BMP_HEADER)); - bmph.bfType=19778; - bmph.bfSize=sizeof(BMP_HEADER); - bmph.bfSize+=w*h*d/8; - if (pPal) - { - bmph.bfSize+=(256*4); - } - bmph.bfOffBits=sizeof(BMP_HEADER); - if (pPal) - { - bmph.bfOffBits+=(256*4); - } - bmph.biSize=40;//sizeof(BMP_HEADER); - bmph.biWidth=w; - bmph.biHeight=h; - bmph.biPlanes=1; - bmph.biBitCount=(unsigned short)d; - bmph.biCompression=0; - bmph.biSizeImage=w*h*d/8; - - fwrite(&bmph,1,sizeof(BMP_HEADER),file); - if (pPal) - { - for(i=0 ; i<256 ; i++) - { - fwrite(&pPal[i*3+0],1,1,file); - fwrite(&pPal[i*3+1],1,1,file); - fwrite(&pPal[i*3+2],1,1,file); - fwrite(&pPal[i*3+2],1,1,file); - } - } - slsize=w*d/8; - scanline=(unsigned char*)Pic_calloc(1,slsize); - if (!scanline) - { - Pic_SetError("BMP_Write, not enough memory for scanline"); - return(0); - } - for(rest=0 ; ((w*d/8)+rest)%4!=0 ; rest++); - for(y=0 ; y<(long)h ; y++) - { - memcpy(scanline,&pDatas[(h-y-1)*slsize],slsize); - if (d==24) - { - for(x=0 ; x<(long)w ; x++) - { - b=scanline[x*3+0]; - g=scanline[x*3+1]; - r=scanline[x*3+2]; - scanline[x*3+0]=b; - scanline[x*3+1]=g; - scanline[x*3+2]=r; - } - } - fwrite(scanline,1,slsize,file); - if (rest) - { - fwrite(scanline,1,rest,file); - } - } - Pic_free(scanline); - fclose(file); - return(1); -} - -// ---------------------------------------------------------------------------------------------------------------------------------- - -unsigned long Pic_BMP_Read( const char *FileName, - char **ppPal, char **ppDatas, - unsigned long *pWidth, unsigned long *pHeight, - unsigned long *pDepth) -{ - FILE *file; - BMP_HEADER bmph; - char *pPal; - char *pDatas; - unsigned char *scanline; - long w,h,d; - long i,x,y,rest; - unsigned char r,g,b; - unsigned char pad[4]; - - pPal=NULL; - pDatas=NULL; - file=fopen(FileName,"rb"); - if (!file) - { - Pic_SetError("BMP_Read, unable to open %s",FileName); - return(0); - } - fread(&bmph,1,sizeof(BMP_HEADER),file); - *pWidth=w=bmph.biWidth; - *pHeight=h=bmph.biHeight; - *pDepth=d=bmph.biBitCount; - if (d!=8 && d!=24) - { - Pic_SetError("BMP_Read, number of bits per pixel unsupported"); - return(0); - } - if (*pDepth==8) - { - pPal=(char*)Pic_calloc(1,256*3); - if (!pPal) - { - Pic_SetError("BMP_Read, not enough memory for palette"); - return(0); - } - for(i=0 ; i<256 ; i++) - { - fread(&pPal[i*3+2],1,1,file); - fread(&pPal[i*3+1],1,1,file); - fread(&pPal[i*3+0],1,1,file); - fread(&pad[0],1,1,file); - } - } - pDatas=(char*)Pic_calloc(1,w*h*d/8); - if (!pDatas) - { - if (pPal) - { - Pic_free(pPal); - } - Pic_SetError("BMP_Read, not enough memory for datas"); - return(0); - } - scanline=(unsigned char*)Pic_calloc(1,w*h*d/8); - if (!scanline) - { - if (pPal) - { - Pic_free(pPal); - } - Pic_free(pDatas); - Pic_SetError("BMP_Read, not enough memory for scanline"); - return(0); - } - for(rest=0 ; (w+rest)%4!=0 ; rest++); - for(y=0 ; y -#include -#include -#include - -#include -#include "pic_private.h" -#include "pic.h" - -// ---------------------------------------------------------------------------------------------------------------------------------- - -struct my_error_mgr -{ - struct jpeg_error_mgr pub; - jmp_buf setjmp_buffer; -}; -typedef struct my_error_mgr * my_error_ptr; - -// ---------------------------------------------------------------------------------------------------------------------------------- - -static unsigned char error; - -// ---------------------------------------------------------------------------------------------------------------------------------- - -void my_error_exit(j_common_ptr cinfo) -{ - my_error_ptr myerr = (my_error_ptr) cinfo->err; - error=1; - longjmp(myerr->setjmp_buffer, 1); -} - -// ---------------------------------------------------------------------------------------------------------------------------------- - -unsigned long Pic_JPG_Read(const char *FileName, char **ppPal, char **ppDatas, unsigned long *w, unsigned long *h) -{ - struct jpeg_decompress_struct cinfo; - struct my_error_mgr jerr; - FILE *file; - JSAMPARRAY buffer; - int row_stride,i; - char *pDatas,*pPal; - unsigned long ptr; - - error=0; - ptr=0; - file=fopen(FileName, "rb"); - if (!file) - { - Pic_SetError("JPG_Read, unable to open %s",FileName); - return(0); - } - cinfo.err = jpeg_std_error(&jerr.pub); - jerr.pub.error_exit = my_error_exit; - setjmp(jerr.setjmp_buffer); - if (error) - { - Pic_SetError("JPG_Read, internal decompression error"); - jpeg_destroy_decompress(&cinfo); - return(0); - } - jpeg_create_decompress(&cinfo); - jpeg_stdio_src(&cinfo, file); - (void) jpeg_read_header(&cinfo, TRUE); - *w=cinfo.image_width; - *h=cinfo.image_height; - if (!ppPal) - { - pDatas=(char*)Pic_calloc(1,(*w)*(*h)*3); - } - else - { - pDatas=(char*)Pic_calloc(1,(*w)*(*h)); - pPal=(char*)Pic_calloc(1,256*3); - if (!pPal) - { - Pic_SetError("JPG_Read, not enough memory for palette"); - return(0); - } - cinfo.desired_number_of_colors = 256; - cinfo.quantize_colors = TRUE; - cinfo.dither_mode = JDITHER_ORDERED; - } - if (!pDatas) - { - Pic_SetError("JPG_Read, not enough memory for pic"); - return(0); - } - (void) jpeg_start_decompress(&cinfo); - row_stride = cinfo.output_width * cinfo.output_components; - buffer = (*cinfo.mem->alloc_sarray) - ((j_common_ptr) &cinfo, JPOOL_IMAGE, row_stride, 1); - while (cinfo.output_scanline < cinfo.output_height) - { - (void) jpeg_read_scanlines(&cinfo, buffer, 1); - memcpy(&pDatas[ptr],buffer[0],row_stride); - ptr+=row_stride; - } - *ppDatas=pDatas; - if (ppPal) - { - for(i=0 ; i<256 ; i++) - { - pPal[i*3+0]=cinfo.colormap[2][i]; - pPal[i*3+1]=cinfo.colormap[1][i]; - pPal[i*3+2]=cinfo.colormap[0][i]; - } - *ppPal=pPal; - } - (void) jpeg_finish_decompress(&cinfo); - jpeg_destroy_decompress(&cinfo); - fclose(file); - return(1); -} - -// ---------------------------------------------------------------------------------------------------------------------------------- - -unsigned long Pic_JPG_Write(const char *FileName, unsigned long Qual, char *pDatas, unsigned long w, unsigned long h) -{ - struct jpeg_compress_struct cinfo; - struct my_error_mgr jerr; - FILE *file; - JSAMPROW row_pointer[1]; - int row_stride; - - error=0; - file=fopen(FileName,"wb"); - if (!file) - { - Pic_SetError("JPG_Write, unable to open %s",FileName); - return(0); - } - jpeg_create_compress(&cinfo); - cinfo.err = jpeg_std_error(&jerr.pub); - jerr.pub.error_exit = my_error_exit; - setjmp(jerr.setjmp_buffer); - if (error) - { - Pic_SetError("JPG_Write, internal compression error"); - jpeg_destroy_compress(&cinfo); - return(0); - } - jpeg_stdio_dest(&cinfo, file); - cinfo.image_width = w; - cinfo.image_height = h; - cinfo.input_components = 3; - cinfo.in_color_space = JCS_RGB; - jpeg_set_defaults(&cinfo); - jpeg_set_quality(&cinfo, Qual, TRUE); - jpeg_start_compress(&cinfo, TRUE); - row_stride = w * 3; - while(cinfo.next_scanline -#include "pic_private.h" -#include "pic.h" - -static unsigned long NbPics=0; -static PIC_PICTURE *HeadPic=NULL; - -// ---------------------------------------------------------------------------------------------------------------------------------- - -static PIC_PICTURE *GetPic(unsigned long id) -{ - PIC_PICTURE *pic; - - for(pic=HeadPic ; pic ; pic=pic->Next) - { - if (pic->ID==id) - { - return(pic); - } - } - return(NULL); -} - -// ---------------------------------------------------------------------------------------------------------------------------------- - -unsigned long PIC_Load(char* FileName, unsigned char Quantize) -{ - char ext[4]; - unsigned long type; - unsigned long i,taken,id; - PIC_PICTURE *pic; - char *pDatas; - char *pPal; - unsigned long w,h,Depth; - unsigned long ret; - - // --- Init - ret=0; - type=0; - id=0; - taken=0; - w=0; - h=0; - Depth=0; - pic=NULL; - pDatas=NULL; - pPal=NULL; - // --- Get 1st available ID - for(i=1 ; i<=NbPics+1 ; i++) - { - taken=0; - for(pic=HeadPic ; pic ; pic=pic->Next) - { - if (pic->ID==i) - { - taken=1; - break; - } - } - if (!taken) - { - id=i; - break; - } - } - if (!id) - { - Pic_SetError("Load, unable to create ID"); - return(0); - } - // --- Load pic - if (FileName) - { - ext[0]=FileName[strlen(FileName)-3]; - ext[1]=FileName[strlen(FileName)-2]; - ext[2]=FileName[strlen(FileName)-1]; - ext[3]=0; - strupr(ext); - if ( !strcmp(ext,"JPG") ) - { - type=1; - } - else if ( !strcmp(ext,"TGA") ) - { - type=2; - } - else if ( !strcmp(ext,"BMP") ) - { - type=3; - } - - switch(type) - { - // - JPG - case 1: - if (!Quantize) - { - Depth=24; - ret=Pic_JPG_Read(FileName,NULL,&pDatas,&w,&h); - } - else - { - Depth=8; - ret=Pic_JPG_Read(FileName,&pPal,&pDatas,&w,&h); - } - if (!ret) - { - Pic_SetError("Load, unable to load JPG file %s",FileName); - return(0); - } - break; - // - TGA - case 2: - ret=Pic_TGA_Read(FileName,&pPal,&pDatas,&w,&h,&Depth); - if (!ret) - { - Pic_SetError("Load, unable to load TGA file %s",FileName); - return(0); - } - break; - // - BMP - case 3: - ret=Pic_BMP_Read(FileName,&pPal,&pDatas,&w,&h,&Depth); - if (!ret) - { - Pic_SetError("Load, unable to load BMP file %s",FileName); - return(0); - } - break; - // - Unknown - default: - Pic_SetError("Load, unknown extension for %s",FileName); - return(0); - } - } - - // --- Create and place new pic struct - pic=(PIC_PICTURE *)Pic_calloc(1,sizeof(PIC_PICTURE)); - if (!pic) - { - Pic_SetError("Load, not enough memory for internal structure"); - return(0); - } - pic->Next=HeadPic; - HeadPic=pic; - NbPics++; - pic->ID=id; - pic->pDatas=pDatas; - pic->pPal=pPal; - pic->Width=w; - pic->Height=h; - pic->Depth=Depth; - return(id); -} - -// ---------------------------------------------------------------------------------------------------------------------------------- - -unsigned long PIC_Create(char* pPal, char* pDatas, unsigned long w, unsigned long h, unsigned long d) -{ - unsigned long i,taken,id; - PIC_PICTURE *pic; - - // --- Init - id=0; - taken=0; - pic=NULL; - // --- Get 1st available ID - for(i=1 ; i<=NbPics+1 ; i++) - { - taken=0; - for(pic=HeadPic ; pic ; pic=pic->Next) - { - if (pic->ID==i) - { - taken=1; - break; - } - } - if (!taken) - { - id=i; - break; - } - } - if (!id) - { - Pic_SetError("Create, unable to create ID"); - return(0); - } - // --- Create pic - if (!pDatas) - { - pDatas=(char *)Pic_calloc(1,w*h*d/8); - if (!pDatas) - { - Pic_SetError("Create, not enough memory for datas"); - return(0); - } - } - if (d==8) - { - if (!pPal) - { - pPal=(char *)Pic_calloc(1,256*3); - if (!pPal) - { - Pic_SetError("Create, not enough memory for palette"); - return(0); - } - } - } - else - { - pPal=NULL; - } - // --- Create and place new pic struct - pic=(PIC_PICTURE *)Pic_calloc(1,sizeof(PIC_PICTURE)); - if (!pic) - { - Pic_SetError("Create, not enough memory for internal structure"); - return(0); - } - pic->Next=HeadPic; - HeadPic=pic; - NbPics++; - pic->ID=id; - pic->pDatas=pDatas; - pic->pPal=pPal; - pic->Width=w; - pic->Height=h; - pic->Depth=d; - return(id); - -} - -// ---------------------------------------------------------------------------------------------------------------------------------- - -unsigned long PIC_GetInfos( unsigned long id, - char **ppPal, char **ppDatas, - unsigned long *pW, unsigned long *pH, unsigned long *pD) -{ - PIC_PICTURE *pic; - - pic=GetPic(id); - if (!pic) - { - Pic_SetError("GetInfos, picture internal structure not found"); - return(0); - } - if (ppPal) - { - *ppPal=pic->pPal; - } - if (ppDatas) - { - *ppDatas=pic->pDatas; - } - if (pW) - { - *pW=pic->Width; - } - if (pH) - { - *pH=pic->Height; - } - if (pD) - { - *pD=pic->Depth; - } - return(id); -} - -// ---------------------------------------------------------------------------------------------------------------------------------- - -static char* Conv8To24(unsigned long id) -{ - PIC_PICTURE *pic; - char *buf; - unsigned long i; - - pic=GetPic(id); - if (!pic) - { - Pic_SetError("Conv8To24, picture internal structure not found"); - return(NULL); - } - buf=(char *)Pic_malloc(pic->Width*pic->Height*3); - if (!buf) - { - Pic_SetError("Conv8To24, not enough memory for temporary buffer"); - return(NULL); - } - for(i=0 ; iWidth*pic->Height ; i++) - { - buf[i*3+0]=pic->pPal[pic->pDatas[i]*3+0]; - buf[i*3+1]=pic->pPal[pic->pDatas[i]*3+1]; - buf[i*3+2]=pic->pPal[pic->pDatas[i]*3+2]; - } - return(buf); -} - -// ---------------------------------------- -static char* Conv8To16(unsigned long id) -{ - PIC_PICTURE *pic; - unsigned short *buf; - unsigned long i; - unsigned short r,g,b,pix16; - - pic=GetPic(id); - if (!pic) - { - Pic_SetError("Conv8To24, picture internal structure not found"); - return(NULL); - } - buf=(unsigned short*)Pic_malloc(pic->Width*pic->Height*2); - if (!buf) - { - Pic_SetError("Conv8To24, not enough memory for temporary buffer"); - return(NULL); - } - for(i=0 ; iWidth*pic->Height ; i++) - { - b=pic->pPal[pic->pDatas[i]*3+0]; - g=pic->pPal[pic->pDatas[i]*3+1]; - r=pic->pPal[pic->pDatas[i]*3+2]; - r>>=3; - g>>=3; g&=0x3E; - b>>=3; - pix16=(r<<10)+(g<<5)+b; - buf[i]=pix16; - } - return (char*)buf; -} - -// ---------------------------------------- - -static char* Conv16To24(unsigned long id) -{ - PIC_PICTURE *pic; - unsigned short *pDatas; - unsigned char *buf; - unsigned long i; - unsigned short r,g,b; - - pic=GetPic(id); - if (!pic) - { - Pic_SetError("Conv16To24, picture internal structure not found"); - return(NULL); - } - buf=(unsigned char *)Pic_malloc(pic->Width*pic->Height*3); - if (!buf) - { - Pic_SetError("Conv16To24, not enough memory for temporary buffer"); - return(NULL); - } - pDatas=(unsigned short*)pic->pDatas; - for(i=0 ; iWidth*pic->Height ; i++) - { - r=(pDatas[i] & 0x7C00)>>(10-3); - g=(pDatas[i] & 0x03E0)>>(5-3); - b=(pDatas[i] & 0x001F)<<3; - buf[i*3+0]=(unsigned char)r; - buf[i*3+1]=(unsigned char)g; - buf[i*3+2]=(unsigned char)b; - } - return (char*)buf; -} - -// ---------------------------------------- - -static char* Conv24To16(unsigned long id) -{ - PIC_PICTURE *pic; - unsigned short *buf; - unsigned long i; - unsigned short r,g,b; - unsigned short pix16; - - pic=GetPic(id); - if (!pic) - { - Pic_SetError("Conv24To16, picture internal structure not found"); - return(NULL); - } - buf=(unsigned short*)Pic_malloc(pic->Width*pic->Height*2); - if (!buf) - { - Pic_SetError("Conv24To16, not enough memory for temporary buffer"); - return(NULL); - } - for(i=0 ; iWidth*pic->Height ; i++) - { - r=pic->pDatas[i*3+0]; - g=pic->pDatas[i*3+1]; - b=pic->pDatas[i*3+2]; - // r : 5 bits forts (0x7C) - // g : 5 bits (6e zapped) (0x3E) - // b : 5 bits faibles (0x1F) - r>>=3; - g>>=3; g&=0x3E; - b>>=3; - pix16=(r<<10)+(g<<5)+b; - buf[i]=pix16; - } - return (char*)buf; -} - -// ---------------------------------------- - -static char* ConvPic(PIC_PICTURE *pic, unsigned long type, char* pErr) -{ - char *buf; - unsigned long src,dst; - - *pErr=0; - buf=NULL; - src=pic->Depth; - if (type==PIC_TYPE_TGA8 || type==PIC_TYPE_BMP8) - { - dst=8; - } - if (type==PIC_TYPE_TGA16) - { - dst=16; - } - if (type==PIC_TYPE_JPG || type==PIC_TYPE_TGA24 || type==PIC_TYPE_BMP24) - { - dst=24; - } - // --- - if (src==dst) - { - return(NULL); - } - // --- - if (src==8 && dst==24) - { - buf=Conv8To24(pic->ID); - if (!buf) - { - *pErr=1; - } - return(buf); - } - if (src==8 && dst==16) - { - buf=Conv8To16(pic->ID); - if (!buf) - { - *pErr=1; - } - return(buf); - } - // --- - if (src==16 && dst==24) - { - buf=Conv16To24(pic->ID); - if (!buf) - { - *pErr=1; - } - return(buf); - } - // --- - if (src==24 && dst==16) - { - buf=Conv24To16(pic->ID); - if (!buf) - { - *pErr=1; - } - return buf; - } - // --- - if (src==24 && dst==8) - { - Pic_SetError("ConvPic, downsampling 24 to 8 bits unsupported"); - *pErr=1; - return(NULL); - } - Pic_SetError("ConvPic, conversion %d to %d unsupported",src,dst); - *pErr=1; - return(NULL); -} - -// ---------------------------------------- - -unsigned long PIC_Save(unsigned long id, char* FileName, unsigned long type, unsigned long qual) -{ - PIC_PICTURE *pic; - char err; - char *buf; - char *freeit; - unsigned long depth; - - freeit=NULL; - pic=GetPic(id); - if (!pic) - { - Pic_SetError("Save %s, picture internal structure not found",FileName); - return(0); - } - freeit = ConvPic(pic,type,&err); - if (err) - { - Pic_SetError("Save %s, error while converting picture",FileName); - return(0); - } - if (!freeit) - { - buf=pic->pDatas; - } - else - { - buf=freeit; - } - err=0; - switch(type) - { - // --- - case PIC_TYPE_JPG: - if ( !Pic_JPG_Write(FileName,qual,buf,pic->Width,pic->Height) ) - { - if (freeit) - { - Pic_free(buf); - } - Pic_SetError("Save %s, error while saving JPG file",FileName); - err=1; - } - break; - // --- - case PIC_TYPE_TGA8: - case PIC_TYPE_TGA16: - case PIC_TYPE_TGA24: - if (type==PIC_TYPE_TGA8) - { - depth=8; - } - if (type==PIC_TYPE_TGA16) - { - depth=16; - } - if (type==PIC_TYPE_TGA24) - { - depth=24; - } - if ( !Pic_TGA_Write(FileName,pic->pPal,buf,pic->Width,pic->Height,depth) ) - { - if (freeit) - { - Pic_free(freeit); - } - Pic_SetError("Save %s, error while saving TGA file",FileName); - err=1; - } - break; - // --- - case PIC_TYPE_BMP8: - case PIC_TYPE_BMP24: - if (type==PIC_TYPE_BMP8) - { - depth=8; - } - if (type==PIC_TYPE_BMP24) - { - depth=24; - } - if ( !Pic_BMP_Write(FileName,pic->pPal,buf,pic->Width,pic->Height,depth) ) - { - if (freeit) - { - Pic_free(freeit); - } - Pic_SetError("Save %s, error while saving BMP file",FileName); - err=1; - } - break; - // --- - default: - Pic_SetError("Save %s, unknow save format/type",FileName); - err=1; - break; - } - if (freeit) - { - Pic_free(freeit); - } - return(err-1); -} - -// ---------------------------------------------------------------------------------------------------------------------------------- - -unsigned long PIC_Destroy(unsigned long id) -{ - PIC_PICTURE *prevpic,*pic; - unsigned long found; - - prevpic=NULL; - found=0; - for(pic=HeadPic ; pic ; pic=pic->Next) - { - if (pic->ID==id) - { - found=1; - break; - } - prevpic=pic; - } - if (!found) - { - Pic_SetError("Destroy, picture internal structure not found"); - return(0); - } - if (prevpic) - { - prevpic->Next=pic->Next; - } - if (pic->pDatas) - { - Pic_free(pic->pDatas); - } - if (pic->pPal) - { - Pic_free(pic->pPal); - } - if (pic==HeadPic) - { - HeadPic=pic->Next; - } - Pic_free(pic); - return(1); -} - -// ---------------------------------------------------------------------------------------------------------------------------------- \ No newline at end of file diff --git a/code/nel/tools/3d/tile_edit/PIC/Pic_TGA.cpp b/code/nel/tools/3d/tile_edit/PIC/Pic_TGA.cpp deleted file mode 100644 index 6d69b914e..000000000 --- a/code/nel/tools/3d/tile_edit/PIC/Pic_TGA.cpp +++ /dev/null @@ -1,215 +0,0 @@ -#include -#include -#include - -#include "pic_private.h" -#include "pic.h" - -// ---------------------------------------------------------------------------------------------------------------------------------- - -#pragma pack(1) -typedef struct TGA_HEADER -{ - unsigned char LengthID; - unsigned char CMapType; - unsigned char ImageType; - unsigned short Origin; - unsigned short Length; - unsigned char Depth; - unsigned short XOrg; - unsigned short YOrg; - unsigned short Width; - unsigned short Height; - unsigned char ImageDepth; - unsigned char Desc; -} TGA_HEADER; -#pragma pack() - -// ---------------------------------------------------------------------------------------------------------------------------------- - -unsigned long Pic_TGA_Read( const char *FileName, - char **ppPal, char **ppDatas, - unsigned long *pWidth, unsigned long *pHeight, - unsigned long *pDepth) -{ - FILE *file; - TGA_HEADER tgah; - long w,h,d; - unsigned long size; - char *pDatas; - char *pPal; - long x,y; - long slsize; - unsigned char *scanline; - unsigned char r,g,b; - long i; - int upSideDown; - - pDatas=NULL; - pPal=NULL; - file=fopen(FileName,"rb"); - if (!file) - { - Pic_SetError("TGA_Read, unable to open %s",FileName); - return(0); - } - fread(&tgah,1,sizeof(TGA_HEADER),file); - if (tgah.ImageType>3) - { - Pic_SetError("TGA_Read, unsupported TGA format"); - return(0); - } - *pWidth=w=tgah.Width; - *pHeight=h=tgah.Height; - *pDepth=d=tgah.ImageDepth; - upSideDown = ((tgah.Desc & (1 << 5))==0); - - size=tgah.Width*tgah.Height*(tgah.ImageDepth/8); - pDatas=(char*)Pic_malloc(size); - if (!pDatas) - { - Pic_SetError("TGA_Read, not enough memory"); - return(0); - } - if (*pDepth==8) - { - if (!ppPal) - { - Pic_free(pDatas); - Pic_SetError("TGA_Read, need a pointer to palette"); - return(0); - } - pPal=(char*)Pic_calloc(1,256*3); - if (!pPal) - { - Pic_SetError("TGA_Read, not enough memory for palette"); - return(0); - } - if (tgah.ImageType==1) - { - for(i=0 ; i<256*3 ; i+=3) - { - fread(&pPal[i+2],1,1,file); - fread(&pPal[i+1],1,1,file); - fread(&pPal[i+0],1,1,file); - } - } - *ppPal=pPal; - } - - slsize=w*d/8; - scanline=(unsigned char*)Pic_calloc(1,slsize); - if (!scanline) - { - if (pPal) - { - Pic_free(pPal); - } - Pic_free(pDatas); - Pic_SetError("TGA_Read, not enough memory for scanline"); - return(0); - } - for(y=0 ; y8) - { - tgah.CMapType=0; - tgah.ImageType=2; - tgah.Length=0; - tgah.Depth=0; - } - else - { - tgah.CMapType=1; - tgah.ImageType=1; - tgah.Length=256; - tgah.Depth=24; - } - tgah.Origin=0; - tgah.XOrg=0; - tgah.YOrg=0; - tgah.Width=(unsigned short)w; - tgah.Height=(unsigned short)h; - tgah.ImageDepth=(unsigned char)d; - tgah.Desc=0; - fwrite(&tgah,1,sizeof(TGA_HEADER),file); - if (d==8) - { - fwrite(pPal,1,256*3,file); - } - slsize=w*d/8; - scanline=(unsigned char*)Pic_calloc(1,slsize); - if (!scanline) - { - Pic_SetError("TGA_Write, not enough memory for scanline"); - return(0); - } - for(y=0 ; y<(long)h ; y++) - { - memcpy(scanline,&pDatas[(h-y-1)*slsize],slsize); - if (d==24) - { - for(x=0 ; x<(long)w ; x++) - { - r=scanline[x*3+0]; - g=scanline[x*3+1]; - b=scanline[x*3+2]; - scanline[x*3+0]=b; - scanline[x*3+1]=g; - scanline[x*3+2]=r; - } - } - fwrite(scanline,1,slsize,file); - } - Pic_free(scanline); - fclose(file); - return(1); -} diff --git a/code/nel/tools/3d/tile_edit/PIC/pic.h b/code/nel/tools/3d/tile_edit/PIC/pic.h deleted file mode 100644 index ec6582c6b..000000000 --- a/code/nel/tools/3d/tile_edit/PIC/pic.h +++ /dev/null @@ -1,58 +0,0 @@ -// Ryzom - MMORPG Framework -// Copyright (C) 2010 Winch Gate Property Limited -// -// This program is free software: you can redistribute it and/or modify -// it under the terms of the GNU Affero General Public License as -// published by the Free Software Foundation, either version 3 of the -// License, or (at your option) any later version. -// -// This program is distributed in the hope that it will be useful, -// but WITHOUT ANY WARRANTY; without even the implied warranty of -// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -// GNU Affero General Public License for more details. -// -// You should have received a copy of the GNU Affero General Public License -// along with this program. If not, see . - -#ifndef _PIC_H_ -#define _PIC_H_ - -// ---------------------------------------------------------------------------------------------------------------------------------- - -#define PIC_TYPE_JPG 1 -#define PIC_TYPE_TGA8 2 -#define PIC_TYPE_TGA16 3 -#define PIC_TYPE_TGA24 4 -#define PIC_TYPE_BMP8 5 -#define PIC_TYPE_BMP24 6 - -// ---------------------------------------------------------------------------------------------------------------------------------- - -// -// Basic API -// -extern unsigned long PIC_Load(char* FileName, unsigned char Quantize); - -extern unsigned long PIC_Create(char* pPal, char* pDatas, unsigned long w, unsigned long h, unsigned long d); - -extern unsigned long PIC_Save(unsigned long id, char* FileName, unsigned long type, unsigned long qual); - -extern unsigned long PIC_GetInfos( unsigned long id, - char **ppPal, char **ppDatas, - unsigned long *pW, unsigned long *pH, unsigned long *pD); - - -extern unsigned long PIC_Destroy(unsigned long id); -// -// System -// -extern unsigned long PIC_GetMemNbAllocs(void); -extern unsigned long PIC_GetMemAllocated(void); -extern char* PIC_GetError(void); -extern unsigned char PIC_Error(void); -extern void PIC_ResetError(void); -extern unsigned char PIC_OnErrorCall( void pFnct(void) ); - -// ---------------------------------------------------------------------------------------------------------------------------------- - -#endif diff --git a/code/nel/tools/3d/tile_edit/PIC/pic_private.h b/code/nel/tools/3d/tile_edit/PIC/pic_private.h deleted file mode 100644 index 4a67bbc9c..000000000 --- a/code/nel/tools/3d/tile_edit/PIC/pic_private.h +++ /dev/null @@ -1,81 +0,0 @@ -// Ryzom - MMORPG Framework -// Copyright (C) 2010 Winch Gate Property Limited -// -// This program is free software: you can redistribute it and/or modify -// it under the terms of the GNU Affero General Public License as -// published by the Free Software Foundation, either version 3 of the -// License, or (at your option) any later version. -// -// This program is distributed in the hope that it will be useful, -// but WITHOUT ANY WARRANTY; without even the implied warranty of -// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -// GNU Affero General Public License for more details. -// -// You should have received a copy of the GNU Affero General Public License -// along with this program. If not, see . - -#ifndef _PIC_PRIVATE_H_ -#define _PIC_PRIVATE_H_ - -// ---------------------------------------------------------------------------------------------------------------------------------- - -typedef struct PIC_PICTURE -{ - unsigned long ID; - unsigned long Width; - unsigned long Height; - unsigned long Depth; - char *pDatas; - char *pPal; - struct PIC_PICTURE *Next; -} PIC_PICTURE; - -// ---------------------------------------------------------------------------------------------------------------------------------- - - -// -// JPG -// - - -extern unsigned long Pic_JPG_Read( const char *FileName, - char **ppPal, char **ppDatas, - unsigned long *w, unsigned long *h); - -extern unsigned long Pic_JPG_Write( const char *FileName, - unsigned long Qual, - char *pDatas, - unsigned long w, unsigned long h); -// -// TGA -// -extern unsigned long Pic_TGA_Read( const char *FileName, - char **ppPal, char **ppDatas, - unsigned long *pWidth, unsigned long *pHeight, - unsigned long *pDepth); -extern unsigned long Pic_TGA_Write( const char *FileName, - char *pPal, char *pDatas, - unsigned long w, unsigned long h, unsigned long d); -// -// BMP -// -extern unsigned long Pic_BMP_Read( const char *FileName, - char **ppPal, char **ppDatas, - unsigned long *pWidth, unsigned long *pHeight, - unsigned long *pDepth); - -extern unsigned long Pic_BMP_Write( const char *FileName, - char *pPal, char *pDatas, - unsigned long w, unsigned long h, unsigned long d); -// -// System -// -extern void* Pic_malloc(unsigned long size); -extern void* Pic_calloc(unsigned long count, unsigned long size); -extern void Pic_free(void *memblock); -extern unsigned long Pic__msize(void *memblock); -extern void Pic_SetError(const char *msg, ...); - -// ---------------------------------------------------------------------------------------------------------------------------------- - -#endif \ No newline at end of file diff --git a/code/nel/tools/3d/tile_edit/PIC/readpic.cpp b/code/nel/tools/3d/tile_edit/PIC/readpic.cpp deleted file mode 100644 index 8afac2b45..000000000 --- a/code/nel/tools/3d/tile_edit/PIC/readpic.cpp +++ /dev/null @@ -1,84 +0,0 @@ -// Ryzom - MMORPG Framework -// Copyright (C) 2010 Winch Gate Property Limited -// -// This program is free software: you can redistribute it and/or modify -// it under the terms of the GNU Affero General Public License as -// published by the Free Software Foundation, either version 3 of the -// License, or (at your option) any later version. -// -// This program is distributed in the hope that it will be useful, -// but WITHOUT ANY WARRANTY; without even the implied warranty of -// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -// GNU Affero General Public License for more details. -// -// You should have received a copy of the GNU Affero General Public License -// along with this program. If not, see . - - -#include -#include -#include "readpic.h" -#include "pic.h" -#include - -using namespace std; - -//============================================================ -// Image API. -//============================================================ - - -bool PIC_LoadPic(string path, vector &tampon, uint &Width, uint &Height) -{ - uint32 id; - char *pal, *data; - unsigned long w,h,depth; - uint i; - - - // Loadons l'image. - id= PIC_Load((char*)path.c_str(), 0); - if(id==0) - return false; - PIC_GetInfos( id, &pal, &data, &w, &h, &depth); - Width=w; - Height=h; - - // On traduit en RGBA. - tampon.resize(w*h); - switch(depth) - { - case 8: - for(i=0;i -// Copyright (C) 2010 Winch Gate Property Limited -// -// This program is free software: you can redistribute it and/or modify -// it under the terms of the GNU Affero General Public License as -// published by the Free Software Foundation, either version 3 of the -// License, or (at your option) any later version. -// -// This program is distributed in the hope that it will be useful, -// but WITHOUT ANY WARRANTY; without even the implied warranty of -// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -// GNU Affero General Public License for more details. -// -// You should have received a copy of the GNU Affero General Public License -// along with this program. If not, see . - -#ifndef _READPIC_H_ -#define _READPIC_H_ - -#ifdef _MSC_VER -#pragma warning(disable:4786) -#endif - - -#include -#include - -#include -#include - -//============================================================ -// API. -//============================================================ - - -bool PIC_LoadPic(std::string Path, std::vector &Tampon, uint &Width, uint &Height); - - - -#endif \ No newline at end of file diff --git a/code/nel/tools/3d/tile_edit/View.cpp b/code/nel/tools/3d/tile_edit/View.cpp index 2ac9bdeb3..81f5fe784 100644 --- a/code/nel/tools/3d/tile_edit/View.cpp +++ b/code/nel/tools/3d/tile_edit/View.cpp @@ -24,7 +24,7 @@ #include //#include "ListGroup.h" //#include "ViewPopup.h" -#include "pic/readpic.h" +//#include "pic/readpic.h" using namespace std; using namespace NL3D; @@ -74,6 +74,37 @@ void rotateBuffer (uint &Width, uint &Height, std::vector& Tampon Height=tmp; } +static bool loadPic(const string &path, std::vector &tampon, uint &width, uint &height) +{ + try + { + NLMISC::CIFile file; + if (file.open(path.c_str())) + { + NLMISC::CBitmap bitmap; + bitmap.load(file); + width = bitmap.getWidth(); + height = bitmap.getHeight(); + tampon.resize(width * height); + bitmap.convertToType(NLMISC::CBitmap::RGBA); + for (uint y = 0; y < height; ++y) + { + for (uint x = 0; x < width; ++x) + { + NLMISC::CRGBA c = bitmap.getPixelColor(x, y, 0); + c.R = (c.R * c.A) / 255; + c.G = (c.G * c.A) / 255; + c.B = (c.B * c.A) / 255; + tampon[(y * width) + x] = c; + } + } + return true; + } + } + catch (NLMISC::Exception& ) { } + return false; +} + ///////////////////////////////////////////////////////////////////////////// // CTView //Attention : windows veut que le buffer image commence du bas vers le haut @@ -82,7 +113,7 @@ int _LoadBitmap(const std::string& path,LPBITMAPINFO BitmapInfo, std::vector Tampon; uint Width; uint Height; - if (PIC_LoadPic(path, Tampon, Width, Height)) + if (loadPic(path, Tampon, Width, Height)) { BitmapInfo->bmiHeader.biSize=sizeof(BITMAPINFOHEADER); BitmapInfo->bmiHeader.biWidth=Width; @@ -207,7 +238,7 @@ int TileList::setTile128 (int tile, const std::string& name, NL3D::CTile::TBitma vector tampon; uint Width; uint Height; - if (!PIC_LoadPic(tileBank2.getAbsPath ()+troncated, tampon, Width, Height)) + if (!loadPic(tileBank2.getAbsPath ()+troncated, tampon, Width, Height)) { return (int)(MessageBox (NULL, ((tileBank2.getAbsPath ()+troncated)+"\nContinue ?").c_str(), "Can't load bitmap.", MB_YESNO|MB_ICONEXCLAMATION)==IDYES); } @@ -272,7 +303,7 @@ int TileList::setTile256 (int tile, const std::string& name, NL3D::CTile::TBitma vector tampon; uint Width; uint Height; - if (!PIC_LoadPic(tileBank2.getAbsPath ()+troncated, tampon, Width, Height)) + if (!loadPic(tileBank2.getAbsPath ()+troncated, tampon, Width, Height)) { return (int)(MessageBox (NULL, ((tileBank2.getAbsPath ()+troncated)+"\nContinue ?").c_str(), "Can't load bitmap.", MB_YESNO|MB_ICONEXCLAMATION)==IDYES); } @@ -338,7 +369,7 @@ int TileList::setTileTransition (int tile, const std::string& name, NL3D::CTile: vector tampon; uint Width; uint Height; - if (!PIC_LoadPic(tileBank2.getAbsPath ()+troncated, tampon, Width, Height)) + if (!loadPic(tileBank2.getAbsPath ()+troncated, tampon, Width, Height)) { return (int)(MessageBox (NULL, ((tileBank2.getAbsPath ()+troncated)+"\nContinue ?").c_str(), "Can't load bitmap.", MB_YESNO|MB_ICONEXCLAMATION)==IDYES); } @@ -451,7 +482,7 @@ int TileList::setTileTransitionAlpha (int tile, const std::string& name, int rot vector tampon; uint Width; uint Height; - if (!PIC_LoadPic(tileBank2.getAbsPath ()+troncated, tampon, Width, Height)) + if (!loadPic(tileBank2.getAbsPath ()+troncated, tampon, Width, Height)) { return MessageBox (NULL, ((tileBank2.getAbsPath ()+troncated)+"\nContinue ?").c_str(), "Can't load bitmap.", MB_YESNO|MB_ICONEXCLAMATION)==IDYES; } @@ -1490,7 +1521,7 @@ LRESULT CTView::WindowProc(UINT message, WPARAM wParam, LPARAM lParam) { _chdir (LastPath.c_str()); CFileDialog load(true, NULL, LastPath.c_str(), OFN_ENABLESIZING | OFN_ALLOWMULTISELECT, - "Targa bitmap (*.tga)|*.tga|All files (*.*)|*.*||",NULL); + "PNG Bitmap (*.png)|*.png|Targa bitmap (*.tga)|*.tga|All files (*.*)|*.*||",NULL); load.m_ofn.lpstrFile = new char[10000]; // buffer contains filenames list load.m_ofn.lpstrFile[0] = 0; // with 10 KB we should be large enough... From 9fba7eff72a7ede9b64e0324f23d7320e45d24f0 Mon Sep 17 00:00:00 2001 From: kaetemi Date: Wed, 19 Nov 2014 16:30:14 +0100 Subject: [PATCH 2/7] Fix bug causing patch painter fail to open more than once --- code/nel/src/3d/driver/opengl/driver_opengl_window.cpp | 1 + 1 file changed, 1 insertion(+) diff --git a/code/nel/src/3d/driver/opengl/driver_opengl_window.cpp b/code/nel/src/3d/driver/opengl/driver_opengl_window.cpp index 5bea65771..9df2a53f9 100644 --- a/code/nel/src/3d/driver/opengl/driver_opengl_window.cpp +++ b/code/nel/src/3d/driver/opengl/driver_opengl_window.cpp @@ -463,6 +463,7 @@ bool CDriverGL::unInit() { nlwarning("Can't unregister NLClass"); } + _Registered = 0; // Restaure monitor color parameters if (_NeedToRestaureGammaRamp) From 39bb02454f250576655eeabbf64519e18eb02281 Mon Sep 17 00:00:00 2001 From: kaetemi Date: Mon, 24 Nov 2014 15:04:53 +0100 Subject: [PATCH 4/7] Adjust version --- code/ryzom/common/src/game_share/ryzom_version.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/code/ryzom/common/src/game_share/ryzom_version.h b/code/ryzom/common/src/game_share/ryzom_version.h index de4524626..b47cff50b 100644 --- a/code/ryzom/common/src/game_share/ryzom_version.h +++ b/code/ryzom/common/src/game_share/ryzom_version.h @@ -17,7 +17,7 @@ #ifndef RYZOM_VERSION_H #define RYZOM_VERSION_H -#define RYZOM_VERSION "ryzomcore/v0.11.1" +#define RYZOM_VERSION "ryzomcore/v0.11.1-dev" #endif // RYZOM_VERSION_H From 972611e5c023c331219f204cb9ae46b73dbb24f1 Mon Sep 17 00:00:00 2001 From: kaetemi Date: Mon, 24 Nov 2014 16:07:17 +0100 Subject: [PATCH 5/7] Separate version string --- code/ryzom/common/src/game_share/ryzom_version.h | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/code/ryzom/common/src/game_share/ryzom_version.h b/code/ryzom/common/src/game_share/ryzom_version.h index b47cff50b..f398c989f 100644 --- a/code/ryzom/common/src/game_share/ryzom_version.h +++ b/code/ryzom/common/src/game_share/ryzom_version.h @@ -17,7 +17,9 @@ #ifndef RYZOM_VERSION_H #define RYZOM_VERSION_H -#define RYZOM_VERSION "ryzomcore/v0.11.1-dev" +#define RYZOM_VERSION "ryzomcore/" \ + "v0.11.1" \ + "-dev" #endif // RYZOM_VERSION_H From c7e0627bb5df8bad1d954f6a88cb2d545d6ec825 Mon Sep 17 00:00:00 2001 From: kaetemi Date: Wed, 3 Dec 2014 15:16:39 +0100 Subject: [PATCH 6/7] Increase patch painter distance --- code/nel/tools/3d/plugin_max/nel_patch_paint/paint.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/code/nel/tools/3d/plugin_max/nel_patch_paint/paint.cpp b/code/nel/tools/3d/plugin_max/nel_patch_paint/paint.cpp index 3fd00f000..0f615b5ed 100644 --- a/code/nel/tools/3d/plugin_max/nel_patch_paint/paint.cpp +++ b/code/nel/tools/3d/plugin_max/nel_patch_paint/paint.cpp @@ -4095,7 +4095,7 @@ DWORD WINAPI myThread (LPVOID vData) // Create a Landscape. CLandscapeModel *TheLand= (CLandscapeModel*)CNELU::Scene->createModel(LandscapeModelId); - TheLand->Landscape.setTileNear (1000.f); + TheLand->Landscape.setTileNear (10000.f); TheLand->Landscape.TileBank=bank; // Enbable automatique lighting @@ -4192,7 +4192,7 @@ DWORD WINAPI myThread (LPVOID vData) mat.setPos(P); CNELU::Camera->setTransformMode (ITransformable::DirectMatrix); CNELU::Camera->setMatrix (mat); - CNELU::Camera->setPerspective( 75.f*(float)Pi/180.f/*vp->GetFOV()*/, 1.33f, 0.1f, 1000.f); + CNELU::Camera->setPerspective( 75.f*(float)Pi/180.f/*vp->GetFOV()*/, 1.33f, 0.1f, 10000.f); // Resize the sym vector symVector.resize (pData->VectMesh.size()); From b7dbbcac5405a6cf92df284392a4e2433ca03e9d Mon Sep 17 00:00:00 2001 From: kaetemi Date: Wed, 3 Dec 2014 15:16:39 +0100 Subject: [PATCH 7/7] Add script to orient zone patches automatically --- .../plugin_max/nel_patch_converter/script.cpp | 30 +++++ .../3d/plugin_max/nel_patch_edit/editpat.h | 1 + .../tools/3d/plugin_max/nel_patch_edit/np.cpp | 89 +++++++++++++++ .../nel_patch_edit/np_epm_selection.cpp | 44 +++++++ .../3d/plugin_max/scripts/nel_orient_zones.ms | 108 ++++++++++++++++++ 5 files changed, 272 insertions(+) create mode 100644 code/nel/tools/3d/plugin_max/scripts/nel_orient_zones.ms diff --git a/code/nel/tools/3d/plugin_max/nel_patch_converter/script.cpp b/code/nel/tools/3d/plugin_max/nel_patch_converter/script.cpp index 8acae94bd..80e715f21 100644 --- a/code/nel/tools/3d/plugin_max/nel_patch_converter/script.cpp +++ b/code/nel/tools/3d/plugin_max/nel_patch_converter/script.cpp @@ -338,6 +338,8 @@ get_selected_tile_cf(Value** arg_list, int count) if (tri->rpatch->tileSel[i]) array->append(Integer::intern(i+1)); } + if (os.obj != tri) + delete tri; } } @@ -383,6 +385,8 @@ get_selected_patch_cf(Value** arg_list, int count) if (tri->patch.patchSel[i]) array->append(Integer::intern(i+1)); } + if (os.obj != tri) + delete tri; } } @@ -428,6 +432,8 @@ get_selected_vertex_cf(Value** arg_list, int count) if (tri->patch.vertSel[i]) array->append(Integer::intern(i+1)); } + if (os.obj != tri) + delete tri; } } @@ -617,6 +623,8 @@ set_vertex_count_cf(Value** arg_list, int count) { nRet=tri->patch.numVerts; } + if (os.obj != tri) + delete tri; } return Integer::intern(nRet); @@ -655,6 +663,8 @@ set_vector_count_cf(Value** arg_list, int count) { nRet=tri->patch.numVecs; } + if (os.obj != tri) + delete tri; } return Integer::intern(nRet); @@ -702,6 +712,8 @@ set_vertex_pos_cf(Value** arg_list, int count) node->NotifyDependents(FOREVER, PART_ALL, REFMSG_CHANGE); ip->RedrawViews(ip->GetTime()); } + if (os.obj != tri) + delete tri; } } @@ -750,6 +762,8 @@ set_vector_pos_cf(Value** arg_list, int count) node->NotifyDependents(FOREVER, PART_ALL, REFMSG_CHANGE); ip->RedrawViews(ip->GetTime()); } + if (os.obj != tri) + delete tri; } } @@ -792,6 +806,8 @@ get_vertex_pos_cf(Value** arg_list, int count) { vRet=new Point3Value (tri->patch.verts[nVertex].p); } + if (os.obj != tri) + delete tri; } } @@ -834,6 +850,8 @@ get_vector_pos_cf(Value** arg_list, int count) { vRet=new Point3Value (tri->patch.vecs[nVertex].p); } + if (os.obj != tri) + delete tri; } } @@ -877,6 +895,8 @@ get_edge_vect1_cf(Value** arg_list, int count) { nVert=tri->patch.edges[nEdge].vec12; } + if (os.obj != tri) + delete tri; } } @@ -919,6 +939,8 @@ get_edge_vect2_cf(Value** arg_list, int count) { nVert=tri->patch.edges[nEdge].vec21; } + if (os.obj != tri) + delete tri; } } @@ -961,6 +983,8 @@ get_edge_vert1_cf(Value** arg_list, int count) { nVert=tri->patch.edges[nEdge].v1; } + if (os.obj != tri) + delete tri; } } @@ -1004,6 +1028,8 @@ get_edge_vert2_cf(Value** arg_list, int count) { nVert=tri->patch.edges[nEdge].v2; } + if (os.obj != tri) + delete tri; } } @@ -1050,6 +1076,8 @@ get_sel_edge_cf(Value** arg_list, int count) array->append(Integer::intern(i+1)); //array->data[j++]=; } + if (os.obj != tri) + delete tri; } } @@ -1158,6 +1186,8 @@ set_tile_steps_cf(Value** arg_list, int count) nTess=5; tri->rpatch->rTess.TileTesselLevel=nTess; tri->rpatch->InvalidateChannels (PART_ALL); + if (os.obj != tri) + delete tri; } if (bRet) { diff --git a/code/nel/tools/3d/plugin_max/nel_patch_edit/editpat.h b/code/nel/tools/3d/plugin_max/nel_patch_edit/editpat.h index d0bfd1773..ec8947571 100644 --- a/code/nel/tools/3d/plugin_max/nel_patch_edit/editpat.h +++ b/code/nel/tools/3d/plugin_max/nel_patch_edit/editpat.h @@ -755,6 +755,7 @@ class EditPatchMod : public Modifier, IPatchOps, IPatchSelect, ISubMtlAPI, Attac TCHAR *GetObjectName() { return GetString(IDS_TH_EDITPATCH); } void ActivateSubobjSel(int level, XFormModes& modes ); int NeedUseSubselButton() { return 0; } + void SelectSubPatch(int index); void SelectSubComponent( HitRecord *hitRec, BOOL selected, BOOL all, BOOL invert ); void ClearSelection(int selLevel); void SelectAll(int selLevel); diff --git a/code/nel/tools/3d/plugin_max/nel_patch_edit/np.cpp b/code/nel/tools/3d/plugin_max/nel_patch_edit/np.cpp index 7b1c9c644..133d0b4d6 100644 --- a/code/nel/tools/3d/plugin_max/nel_patch_edit/np.cpp +++ b/code/nel/tools/3d/plugin_max/nel_patch_edit/np.cpp @@ -84,6 +84,31 @@ *> Copyright(c) 1994, All Rights Reserved. **********************************************************************/ #include "stdafx.h" + +#if MAX_VERSION_MAJOR >= 14 +# include +# include +# include +# include +# include +# include +# include +# include +# include +#else +# include +# include +// Various MAX and MXS includes +# include +# include +# include +# include +# include +# include +// define the new primitives using macros from SDK +# include +#endif + #include "editpat.h" #include "../nel_patch_lib/vertex_neighborhood.h" @@ -855,3 +880,67 @@ void ResetVert (PatchMesh *patch) patch->computeInteriors(); patch->InvalidateGeomCache (); } + +def_visible_primitive(turn_patch, "RykolTurnPatch"); + +Value *turn_patch_cf (Value** arg_list, int count) +{ + // Make sure we have the correct number of arguments (2) + check_arg_count(RykolTurnPatch, 3, count); + + // Check to see if the arguments match up to what we expect + // We want to use 'TurnAllTexturesOn ' + type_check(arg_list[0], MAXNode, "RykolTurnPatch [Node] [Modifier] [Patch]"); + type_check(arg_list[1], MAXModifier, "RykolTurnPatch [Node] [Modifier] [Patch]"); + type_check(arg_list[2], Integer, "RykolTurnPatch [Node] [Modifier] [Patch]"); + + // Get a good interface pointer + Interface *ip = MAXScript_interface; + + // Get a INode pointer from the argument passed to us + INode *node = arg_list[0]->to_node(); + nlassert (node); + + // Get a Object pointer + ObjectState os = node->EvalWorldState(ip->GetTime()); + + // ok ? + bool bRet=false; + + if (os.obj) + { + // Get class id + if (os.obj->CanConvertToType(RYKOLPATCHOBJ_CLASS_ID)) + { + bRet = true; + RPO *tri = (RPO *)os.obj->ConvertToType(ip->GetTime(), RYKOLPATCHOBJ_CLASS_ID); + if (tri) + { + Modifier *mod = arg_list[1]->to_modifier(); + if (mod) + { + EditPatchMod *epmod = (EditPatchMod *)mod; + epmod->ClearSelection(EP_PATCH); + epmod->SelectSubPatch(arg_list[2]->to_int() - 1); + epmod->DoPatchTurn(true); + epmod->ClearSelection(EP_PATCH); + } + else + { + bRet = false; + } + } + // Note that the TriObject should only be deleted + // if the pointer to it is not equal to the object + // pointer that called ConvertToType() + if (os.obj != tri) + delete tri; + + // redraw and update + node->NotifyDependents(FOREVER, PART_ALL, REFMSG_CHANGE); + ip->RedrawViews(ip->GetTime()); + } + } + + return bRet?&true_value:&false_value; +} \ No newline at end of file diff --git a/code/nel/tools/3d/plugin_max/nel_patch_edit/np_epm_selection.cpp b/code/nel/tools/3d/plugin_max/nel_patch_edit/np_epm_selection.cpp index 3814a2df9..0b15b63e7 100644 --- a/code/nel/tools/3d/plugin_max/nel_patch_edit/np_epm_selection.cpp +++ b/code/nel/tools/3d/plugin_max/nel_patch_edit/np_epm_selection.cpp @@ -236,6 +236,50 @@ void EditPatchMod::SetSelLevel(DWORD level) // ------------------------------------------------------------------------------------------------------------------------------------------------------ +void EditPatchMod::SelectSubPatch(int index) +{ + if (!ip) + return; + TimeValue t = ip->GetTime(); + + ip->ClearCurNamedSelSet(); + + ModContextList mcList; + INodeTab nodes; + ip->GetModContexts(mcList, nodes); + + for (int i = 0; i < mcList.Count(); i++) + { + EditPatchData *patchData =(EditPatchData*)mcList[i]->localData; + + if (!patchData) + return; + + RPatchMesh *rpatch; + PatchMesh *patch = patchData->TempData(this)->GetPatch(t, rpatch); + if (!patch) + return; + + patchData->BeginEdit(t); + if (theHold.Holding()) + theHold.Put(new PatchRestore(patchData, this, patch, rpatch, "SelectSubComponent")); + + patch->patchSel.Set(index); + + patchData->UpdateChanges(patch, rpatch, FALSE); + if (patchData->tempData) + { + patchData->tempData->Invalidate(PART_SELECT); + } + } + PatchSelChanged(); + + UpdateSelectDisplay(); + NotifyDependents(FOREVER, PART_SELECT, REFMSG_CHANGE); +} + +// ------------------------------------------------------------------------------------------------------------------------------------------------------ + // Select a subcomponent within our object(s). WARNING! Because the HitRecord list can // indicate any of the objects contained within the group of patches being edited, we need // to watch for control breaks in the patchData pointer within the HitRecord! diff --git a/code/nel/tools/3d/plugin_max/scripts/nel_orient_zones.ms b/code/nel/tools/3d/plugin_max/scripts/nel_orient_zones.ms new file mode 100644 index 000000000..fb5ba2862 --- /dev/null +++ b/code/nel/tools/3d/plugin_max/scripts/nel_orient_zones.ms @@ -0,0 +1,108 @@ + +gc() +nodes = getCurrentSelection() +max select none +clearselection() + +undo off +( + for cnode in nodes do + ( + if (classof cnode) == Editable_Patch or (classof cnode) == RklPatch then + ( + print cnode.name + selectmore cnode + if (classof cnode) == Editable_Patch and (classof cnode) != RklPatch then + ( + modPanel.addModToSelection (NeL_Convert ()) ui:on + ) + modPanel.addModToSelection (NeL_Edit ()) ui:on + setCommandPanelTaskMode #modify + cmod = modpanel.getCurrentObject() + pcount = (GetRykolPatchCount cnode) + print pcount + for p = 1 to pcount do + ( + --print p + vbegin = (NeLGetPatchVertex cnode p 1) + vend = (NeLGetPatchVertex cnode p 2) + vref = (NeLGetPatchVertex cnode p 3) + begin = (GetRykolVertexPos cnode vbegin) + end = (GetRykolVertexPos cnode vend) + ref = (GetRykolVertexPos cnode vref) + normal = (cross (end - begin) (ref - begin)) + normal = (normalize normal) + + rotnormal = (normal * (rotateZMatrix -90)) + if (normal.z > 0.9) then + ( + -- print "x normal" + rotnormal = (normal * (rotateXMatrix -90)) + ) + -- print rotnormal + + -- print normal + -- print rotnormal + -- print begin + -- print end + dir = (normalize (end - begin)) + -- print dir + score1 = (dot dir rotnormal) + + RykolTurnPatch cnode cmod (p) + vbegin = (NeLGetPatchVertex cnode p 1) + vend = (NeLGetPatchVertex cnode p 2) + begin = (GetRykolVertexPos cnode vbegin) + end = (GetRykolVertexPos cnode vend) + dir = (normalize (end - begin)) + score2 = (dot dir rotnormal) + + RykolTurnPatch cnode cmod (p) + vbegin = (NeLGetPatchVertex cnode p 1) + vend = (NeLGetPatchVertex cnode p 2) + begin = (GetRykolVertexPos cnode vbegin) + end = (GetRykolVertexPos cnode vend) + dir = (normalize (end - begin)) + score3 = (dot dir rotnormal) + + RykolTurnPatch cnode cmod (p) + vbegin = (NeLGetPatchVertex cnode p 1) + vend = (NeLGetPatchVertex cnode p 2) + begin = (GetRykolVertexPos cnode vbegin) + end = (GetRykolVertexPos cnode vend) + dir = (normalize (end - begin)) + score4 = (dot dir rotnormal) + + -- print score1 + -- print score2 + -- print score3 + -- print score4 + + if (score1 > score2 and score1 > score3 and score1 > score4) then + ( + -- print "score 1" + RykolTurnPatch cnode cmod (p) + ) + else if (score2 > score3 and score2 > score4) then + ( + -- print "score 2" + RykolTurnPatch cnode cmod (p) + RykolTurnPatch cnode cmod (p) + ) + else if (score3 > score4) then + ( + -- print "score 3" + RykolTurnPatch cnode cmod (p) + RykolTurnPatch cnode cmod (p) + RykolTurnPatch cnode cmod (p) + ) + else + ( + -- print "score 4" + ) + ) + maxOps.CollapseNode cnode off + max select none + ) + ) +)