日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 > 编程资源 > 编程问答 >内容正文

编程问答

tga格式转化为jpg格式

發布時間:2023/12/20 编程问答 38 豆豆
生活随笔 收集整理的這篇文章主要介紹了 tga格式转化为jpg格式 小編覺得挺不錯的,現在分享給大家,幫大家做個參考.

綜述

很多時候我們需要將tga格式轉化為jpg格式。這方面代碼很少。我給出一個使用matlab實現的

操作

將下面幾個代碼全部放到自己的matlab目錄下即可:
入口程序main.m

main.m

[I,map] = tga_read_image('testimages/50.tga');figurea =imshow(I,map);saveas(a,'myfig.jpg')

tga_read_image.m

function [I,Map] = tga_read_image(info) % function for reading image of Truevision TARGA file, TGA, VDA, ICB VST % % [I,Map] = tga_read_image(file-header) % % or, % % [I,Map] = tga_read_image(filename) % % examples: % 1: info = tga_read_header() % I = tga_read_image(info); % imshow(I(:,:,1:3),[]); % % 2: [I,map] = tga_read_image('testimages/test9.tga'); % figure, imshow(I,map);if(~isstruct(info)), info=tga_read_header(info); end fid=fopen(info.Filename,'rb','l');if(fid<0)fprintf('could not open file %s\n',info.Filename);return endfseek(fid,info.HeaderSize,'bof');bytesp=ceil(info.Depth)/8; npixels=info.Width*info.Height*bytesp; if(~info.Rle)V = fread(fid,npixels,'uint8=>uint8'); elseV = zeros([npixels 1],'uint8'); nV=0;while(nV<npixels)RCfield=fread(fid,1,'uint8=>uint8');RunLengthPacket=bitget(RCfield,8);Npix=double(mod(RCfield,128))+1;if(RunLengthPacket)PixelData=fread(fid,bytesp,'uint8=>uint8');PixelData=repmat(PixelData(:),[Npix 1]);else % Raw PacketsPixelData=fread(fid,Npix*bytesp,'uint8=>uint8');endnVnew=nV+length(PixelData);V(nV+1:nVnew)=PixelData;nV=nVnew;endV=V(1:npixels); endswitch(info.Depth)case 8;I = permute(reshape(V,[info.Width info.Height]),[2 1]);case 16V =uint16(V); V=V(1:2:end)+256*V(2:2:end);Vbits=getbits(V,16);B = Vbits(:,1)+Vbits(:,2)*2+Vbits(:,3)*4+Vbits(:,4)*8+Vbits(:,5)*16;G = Vbits(:,6)+Vbits(:,7)*2+Vbits(:,8)*4+Vbits(:,9)*8+Vbits(:,10)*16;R = Vbits(:,11)+Vbits(:,12)*2+Vbits(:,13)*4+Vbits(:,14)*8+Vbits(:,15)*16;R = permute(reshape(R,[info.Width info.Height]),[2 1]);G = permute(reshape(G,[info.Width info.Height]),[2 1]);B = permute(reshape(B,[info.Width info.Height]),[2 1]);I(:,:,1)=R*8;I(:,:,2)=G*8;I(:,:,3)=B*8;I=uint8(I);case 24I = permute(reshape(V,[3 info.Width info.Height]),[3 2 1]);I=I(:,:,3:-1:1);case 32I = permute(reshape(V,[4 info.Width info.Height]),[3 2 1]);I=I(:,:,[3 2 1 4]); end fclose(fid);Map = info.ColorMap;switch(info.ImageOrigin);case 'bottom left'I=I(end:-1:1,:,:);case 'bottom right'I=I(end:-1:1,end:-1:1,:);case 'top left'I=I(:,:,:);case 'top right'I=I(:,end:-1:1,:); endfunction bits=getbits(a,nbits) a=double(a(:)); bits=zeros([length(a) nbits]); for i=1:nbits, a=a/2; af=floor(a); bits(:,i)=af~=a; a=af; end

tga_read_header

function info = tga_read_header(fname) % function for reading header of Truevision TARGA file, TGA, VDA, ICB VST % % info = tga_read_header(filename); % % examples: % 1, info=tga_read_header() % 2, info=tga_read_header('example.tga');% % typedef struct % % byte identsize; // size of ID field that follows 18 byte header (0 usually) % byte Colormaptype; // type of Color map 0=none, 1=has palette % byte imagetype; // type of image 0=none,1=indexed,2=rgb,3=grey,+8=rle packed % % short Colormapstart; // first Color map entry in palette % short Colormaplength; // number of Colors in palette % byte Colormapbits; // number of bits per palette entry 15,16,24,32% % % short xstart; // image x origin % short ystart; // image y origin % short width; // image width in pixels % short height; // image height in pixels % byte bits; // image bits per pixel 8,16,24,32 % byte descriptor; // image descriptor bits (vh flip bits) % % // pixel data follows header % 24 bits % TGA_HEADERif(exist('fname','var')==0)[filename, pathname] = uigetfile('*.tga;*.vda;*.icb,*.vst', 'Read tga-file');fname = [pathname filename]; endf=fopen(fname,'rb','l'); if(f<0)fprintf('could not open file %s\n',fname);return end info.Filename=fname;% Footer Header fseek(f,-26,'eof'); info.ExtensionArea=fread(f, 1, 'long'); info.DeveloperDirectory=fread(f, 1, 'long'); info.Signature=fread(f, 17, 'char=>char')'; if(strcmp(info.Signature,'TRUEVISION-XFILE.'))info.Version='new'; elseinfo.Version='old'; end% File Start Header fseek(f,0,'bof'); info.IDlength = fread(f, 1, 'uint8'); info.ColorMapType = fread(f, 1, 'uint8'); info.ImageType =fread(f, 1, 'uint8'); switch(info.ImageType )case 0info.ImageTypeString='No Image Data';info.Rle=false;case 1info.ImageTypeString='Uncompressed, Color-mapped image'; info.Rle=false;case 2info.ImageTypeString='Uncompressed, True-color image';info.Rle=false;case 3info.ImageTypeString='Uncompressed, True-color image';info.Rle=false;case 9info.ImageTypeString='Run-length encoded Color-mapped Image'; info.Rle=true;case 10info.ImageTypeString='Run-length encoded True-color Image Image'; info.Rle=true;case 11info.ImageTypeString='Run-length encoded Black-and-white Image';info.Rle=true;otherwiseinfo.ImageTypeString='unknown';info.Rle=false; end% Color Map Specification (offset 3) info.ColorMapStart = fread(f, 1, 'short'); info.ColorMapLength = fread(f, 1, 'short'); info.ColorMapBits = fread(f, 1, 'uint8'); info.ColorMapStoreBits = 8*ceil(info.ColorMapBits/8);% Image specification offset 8 info.XOrigin = fread(f, 1, 'short'); info.YOrigin = fread(f, 1, 'short'); info.Width = fread(f, 1, 'short'); info.Height = fread(f, 1, 'short'); info.Depth = fread(f, 1, 'uint8'); b= bitget(fread(f, 1, 'uint8=>uint8'),1:8); info.ImageDescriptor =b; info.AlphaChannelBits=b(1)+b(2)*2+b(3)*4+b(4)*8; if((b(6)==0)&&(b(5)==0)), info.ImageOrigin='bottom left'; end if((b(6)==0)&&(b(5)==1)), info.ImageOrigin='bottom right'; end if((b(6)==1)&&(b(5)==0)), info.ImageOrigin='top left'; end if((b(6)==1)&&(b(5)==1)), info.ImageOrigin='top right'; end info.ImageID= fread(f, info.IDlength, 'uint8'); if(info.ColorMapType==0)info.ColorMap=[]; elseColorMap = fread(f,info.ColorMapLength*(info.ColorMapStoreBits/8),'uint8=>uint8');switch(info.ColorMapStoreBits)case 16% BitsPerColor = min( info.bits/3, 8);%info.ColorMap=reshape(ColorMap,[info.ColorMapLength 2]);case 24info.ColorMap=reshape(ColorMap,[3 info.ColorMapLength])';info.ColorMap=info.ColorMap(:,3:-1:1);case 32info.ColorMap=reshape(ColorMap,[4 info.ColorMapLength])';info.ColorMap=info.ColorMap(:,[3 2 1 4]);endinfo.ColorMap=double(info.ColorMap)/255; end% Get the header size info.HeaderSize=ftell(f);% Get the file length fseek(f,0,'eof'); info.FileSize = ftell(f); fclose(f);% Closing Header Contains :% Developer Fields % Developer Directory % Extension Size (offset =0) , short % Author Name (offset = 2) , asci 41 % Author Comments ( offset = 43), asci 324 % Date Time, (offset=367), shorts 6 % Job Name/ID(offset=379) , 41 ascii % Job Time (offset = 420) , 41 asci % Software version (offset=467), 3 bytes % Key color (offset=470), long % Pixel Aspect Ratio (offset = 474) , 2shorts % Gamma Value (offset = 478 ), 2 shorts % Color Correction Offset (offset=482), long % Postage Stamp Offset(offset=486), long % Scan Line Offset ( offset=490), long % Attributes Type (offset=494) % Scan Line Table % Postage Stamp Image % Color Correction Table (1K shorts) % Extentsion Area (offset=0), long % Developer Directory (offset=4),long % Signature (offset=8) , ASCI

總結

以上是生活随笔為你收集整理的tga格式转化为jpg格式的全部內容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網站內容還不錯,歡迎將生活随笔推薦給好友。

主站蜘蛛池模板: 国产手机在线播放 | 超碰网址 | 99福利视频 | 激情久久免费视频 | 欧美美女视频 | 欧美久久精品一级黑人c片 1000部多毛熟女毛茸茸 | 国产做爰免费观看 | 亚洲欧美一区二区三区情侣bbw | 亚洲a毛片 | 蜜桃精品成人影片 | 国产大片b站 | 芒果视频在线观看免费 | 欧美精品久久久久久久久久 | 卡一卡二视频 | 亚洲自拍激情 | 国产在线第一页 | 久久高清免费 | 香蕉在线观看 | 国产精品激情偷乱一区二区∴ | 久久特黄视频 | 激情999 | 久久人人爽爽人人爽人人片av | 艳妇乳肉豪妇荡乳av无码福利 | 欧美毛片免费看 | 欧美日韩精品国产 | 小泽玛利亚一区二区三区在线观看 | 日韩精品一区二区三区 | 亚洲一区二区三区在线看 | 91色精品 | 果冻传媒18禁免费视频 | 激情天堂网 | 18禁一区二区三区 | 亚洲高清毛片一区二区 | 日韩一区二区视频在线 | 午夜精品一区二区三区三上悠亚 | 无码粉嫩虎白一线天在线观看 | 国产精品亚洲无码 | 一级片网址 | 免费成人黄色网址 | 不卡中文字幕在线 | 中日韩精品一区二区三区 | 中国新婚夫妻性猛交 | 中文免费在线观看 | 网站黄色在线观看 | 做爰视频毛片视频 | 日本视频久久 | 久久久久精彩视频 | 麻豆系列| 九九九视频在线观看 | 日本边添边摸边做边爱 | 1024国产精品 | 国产在线不卡 | 中文字幕不卡在线观看 | 国产一精品一aⅴ一免费 | 午夜一级视频 | 天天插天天摸 | 麻豆影视网站 | 国产香蕉视频在线 | 狠狠人妻久久久久久综合蜜桃 | 爱豆国产剧免费观看大全剧集 | 91精品国产欧美一区二区成人 | 国外成人性视频免费 | 国产精品99在线观看 | 国产又粗又大又爽视频 | 成人免费视频视频 | 动漫艳母在线观看 | 久久高清无码视频 | 长篇h版少妇沉沦交换 | 免费国产一区 | 999视频在线播放 | 久久爱网 | 激情欧美一区二区三区精品 | 爱爱免费视频网站 | 久久天天综合 | 综合久久一区二区 | 久久免费播放视频 | 黄色自拍视频 | 俄罗斯av片 | av日韩不卡 | 无码一区二区三区在线观看 | 无码aⅴ精品一区二区三区 精品久久在线 | 性欧美bb | 朝桐光在线视频 | 在线观看视频91 | 911香蕉视频 | 视频一区二区国产 | 国产精品一区二区av白丝下载 | 帮我拍拍漫画全集免费观看 | 天堂精品久久 | 91精品色 | 视频免费1区二区三区 | 亚洲性综合 | 精品国产一区二区三区在线观看 | 日韩福利一区 | 国产成人精品无码免费看81 | 天堂视频一区二区 | 亚洲码欧美码一区二区三区 | 色欲人妻综合网 | 国产精品一线天粉嫩av |