2007/05/26

簡單取得PSD長寬

PSD的讀取參考了幾個地方 發現 有讀取 8BIM 跟 8BPS 的 不太一樣


8BIM是讀取資源內容
8BPS是檔頭判斷
以下是程式碼,請參考




bool GetPsdWidthHeight(const wxChar* buf,int size,int&Width,int& Height,bool& ReadWidthHeight)
{
char Head[5];
memcpy(&Head,&buf[0],sizeof(wxChar)*4);

if(strncmp( Head, "8BPS", 4 ))
{
ReadWidthHeight=true;
return false;
}

int check=(BYTE)buf[4]<<8 | (BYTE)buf[5];

if (check != 1)
{
ReadWidthHeight=true;
return false;
}

//Read32; 6 7 8 9
//Read16; 10 11

unsigned channel_count = (BYTE)buf[12]<<8 | (BYTE)buf[13];

if( channel_count >= 0 && channel_count <= 16)
{
Height = (BYTE)buf[14]<<24 | (BYTE)buf[15]<<16 | (BYTE)buf[16]<<8 | (BYTE)buf[17];
Width = (BYTE)buf[18]<<24 | (BYTE)buf[19]<<16 | (BYTE)buf[20]<<8 | (BYTE)buf[21];

ReadWidthHeight=true;
return true;
}

return false;

}



以上 , 不負責讀取所有格式,另有問題概不負責.
歡迎轉載並請標明出處.謝謝


參考:
(1)
http://www.google.com/codesearch?hl=en&q=+lang:c%2B%2B+psd+8BIM+8BPS+-img+show:gNvfT5nXepE:CqZcsEQNy-A:b6xjN1IEDH4&sa=N&amp;cd=2&ct=rc&cs_p=http://gsmp.tfh-berlin.de/mirror/t2-source/6.0/p/paintlib-2.6.2.tar.bz2&cs_f=paintlib-2.6.2/common/plpsddec.cpp#a0


(2)
http://www.google.com/codesearch?hl=en&q=+lang:c%2B%2B+psd+8BIM+8BPS+-img+show:gNvfT5nXepE:CqZcsEQNy-A:b6xjN1IEDH4&sa=N&amp;cd=2&ct=rc&cs_p=http://gsmp.tfh-berlin.de/mirror/t2-source/6.0/p/paintlib-2.6.2.tar.bz2&cs_f=paintlib-2.6.2/common/plpsddec.cpp#a0


沒有留言: