📄 mga_psd.c
字号:
/* (c) HelDoRe PSD unit ... v0.0.3 Supported formats : Rip jpeg from psd */ #define VERPSD " unit v0.0.3"#include <stdio.h>#include "../mga_view.h"#ifdef USE_LIBJPG#include <jpeglib.h>#include <setjmp.h>#endifvoid help_psd(){#ifdef USE_LIBJPGprintf("PSD%s\n + uses libjpeg\n",VERPSD);#endif}#ifdef USE_LIBJPGstruct my_error_mgr { struct jpeg_error_mgr pub; jmp_buf setjmp_buffer;};typedef struct my_error_mgr * my_error_ptr;METHODDEF(void) my_error_exit(j_common_ptr cinfo) { my_error_ptr myerr = (my_error_ptr) cinfo->err; (*cinfo->err->output_message)(cinfo); longjmp(myerr->setjmp_buffer,1); }#endif int detect_psd(){#ifdef USE_LIBJPG short int JPsyg; struct jpeg_decompress_struct cinfo; struct my_error_mgr jerr; JSAMPARRAY buffer; int row_stride,jaka,wer,chan,mode,pos; JPsyg=fgetc32(plik); if (JPsyg != 20563) { return 1; } wer=fgetc16(plik); fseek(plik,6,SEEK_CUR); chan=fgetc16(plik); image_x=fgetc32(plik); image_y=fgetc32(plik); depth=fgetc16(plik); mode=fgetc16(plik); fseek(plik,8,SEEK_CUR); while (tempi!=55551) { tempi=fgetc16b(plik); if (tempi== -1) return 1; fseek(plik,-1,SEEK_CUR); } fseek(plik,-1,SEEK_CUR); fread(&JPsyg,sizeof (short int),1,plik); if (JPsyg != -9985) { return 1; } fseek(plik,-2,SEEK_CUR); pos=ftell(plik); cinfo.err = jpeg_std_error(&jerr.pub); jerr.pub.error_exit = my_error_exit; if (setjmp(jerr.setjmp_buffer)) { jpeg_destroy_decompress(&cinfo); return 2; } jpeg_create_decompress(&cinfo); jpeg_stdio_src(&cinfo,plik); (void) jpeg_read_header(&cinfo,TRUE); (void) jpeg_start_decompress(&cinfo); printf("PSD%s\n",VERPSD); printf("PSD v%i detected : %ix%ix%i chan %i type : ",wer,image_x,image_y,depth,chan); switch(mode) { case 0:printf("bitmap");break; case 1:printf("grayscale");break; case 2:printf("indexed");break; case 3:printf("RGB");break; case 4:printf("CMYK");break; case 7:printf("multichannel");break; case 8:printf("duotone");break; case 9:printf("lab");break; default: break; } printf("\n"); image_x=cinfo.output_width; image_y=cinfo.output_height; jaka=cinfo.num_components; check_image(image_x,image_y,8); printf("PSD jpg detected: %ix%i ",image_x,image_y); if (jaka==3) printf("color"); else printf("grayscale"); printf("\n"); row_stride=cinfo.output_width*cinfo.output_components; buffer=(*cinfo.mem->alloc_sarray)((j_common_ptr) &cinfo,JPOOL_IMAGE,row_stride,1); y=0; while (cinfo.output_scanline <cinfo.output_height) { (void) jpeg_read_scanlines(&cinfo,buffer,1); if (jaka==3) for (x=0;x<image_x;x++) { tabr[x+y*image_x]=buffer[0][x*3]; tabg[x+y*image_x]=buffer[0][x*3+1]; tabb[x+y*image_x]=buffer[0][x*3+2]; } else for (x=0;x<image_x;x++) { tabr[x+y*image_x]=buffer[0][x]; tabg[x+y*image_x]=tabr[x+y*image_x]; tabb[x+y*image_x]=tabr[x+y*image_x]; } y++; } (void) jpeg_finish_decompress(&cinfo); jpeg_destroy_decompress(&cinfo); rewind(plik); fseek(plik,pos+20,SEEK_CUR); tempi=fgetc(plik); if ((tempi==255) && (fgetc(plik)==254)) { fprintf(stderr,"Comment : "); tempi=fgetc(plik); tempi=fgetc(plik); for (x=0;x<tempi-2;x++) { printf("%c",(char)depth=fgetc(plik)); } printf("\n"); } return 0; #else return 1;#endif}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -