コード例 #1
0
ファイル: png.c プロジェクト: cahirwpz/demoscene
bool PngDecodeImage(PngT *png, PixBufT *pixbuf) {
  if (png->ihdr.interlace_method != 0) {
    LOG("Interlaced PNG not supported.");
  } else if (png->ihdr.bit_depth != 8) {
    LOG("Non 8-bit components not supported.");
  } else {
    uint32_t pixelWidth = GetPixelWidth(png);
    uint32_t length = png->ihdr.width * png->ihdr.height * pixelWidth;
    uint32_t dstLength = length + png->ihdr.height;
    uint8_t *encoded = MemNew(dstLength);

    MergeIDATs(png);

    LOG("Uncompressing the image.");

    Inflate(png->idat.data + 2, encoded);

    LOG("Decoding pixels.");

    ReconstructImage(pixbuf->data, encoded,
                     png->ihdr.width, png->ihdr.height, pixelWidth);

    MemUnref(encoded);

    return true;
  }

  return false;
}
コード例 #2
0
ファイル: Package.cpp プロジェクト: Hyzoran/Eoverse
void FZipPackage::LoadAsset( FZipAsset* Asset )
{
	guard;

	Seek( Asset->Location, Begin );
	Asset->Ptr = new uint8[Asset->Size];
	switch (Asset->CompressType)
	{
		case 0:
		{
			//No compression
			Read( Asset->Ptr, Asset->Size );
			break;
		}
		case 8:
		{
			//Deflate
			uint8* CompressData = new uint8[Asset->CompressSize];
			Read( CompressData, Asset->CompressSize );
			Inflate( CompressData, Asset->Ptr, Asset->CompressSize, Asset->Size );
			if (Asset->Type == AT_Text || Asset->Type == AT_Script)
			{
				//Null terminate the data if it has formatted text
				Asset->Ptr[Asset->Size] = 0;
			}
			break;
		}
		default:
		{
			Logf( LOG_ERR, L"Asset '%s' is compressed with an unknown method.", Asset->Name );
		}
	}

	unguard;
}
コード例 #3
0
ファイル: Unzip.cpp プロジェクト: nod3011/genesis4iphone
int Unzip::fileDecode(unsigned char *data)
{
    unsigned char *src=NULL;

    // Go to compressed data:
    fseek(file,compPos,SEEK_SET);

    // Allocate memory:
    src=(unsigned char *)malloc(srcLen);
    if (src==NULL) {
        fclose(file);
        return 1;
    }
    memset(src,0,srcLen);

    // Read in compressed version and decompress
    fread(src,1,srcLen,file);

    Inflate(data,dataLen, src,srcLen);

    free(src);
    src=NULL;
    srcLen=0;

    return 0;
}
コード例 #4
0
ファイル: combo_box.cpp プロジェクト: Zplutor/zaf
void ComboBox::PopupDropDownWindow() {

    auto window = GetWindow();
    if (window == nullptr) {
        return;
    }

    auto window_rect = GetAbsoluteRect();
    window_rect.Inflate(-1, 0);
    window_rect.position.y += GetHeight() - 2;

    std::size_t visible_item_count = drop_down_list_box_->GetItemCount();
    visible_item_count = std::max(visible_item_count, GetMinimumVisibleItemCount());
    visible_item_count = std::min(visible_item_count, GetMaximumVisibleItemCount());

    window_rect.size.height =
        CalculateDropDownListHeight(visible_item_count) + drop_down_list_box_->GetBorderThickness() * 2;

    POINT screen_position = window_rect.position.ToPOINT();
    ClientToScreen(window->GetHandle(), &screen_position);
    window_rect.position = Point::FromPOINT(screen_position);

    drop_down_window_->SetOwner(window);
    drop_down_window_->SetRect(window_rect);
    drop_down_window_->Show();
}
コード例 #5
0
BOOL Flate::Uncompress(CByteArray& dst, const BYTE* src, UINT srcLen)
{
	CBAStreamReader sr(src, srcLen);
	CBAStreamWriter sw(dst);

	Inflate(&sw, &sr);

	return dst.GetSize() != 0;
}
コード例 #6
0
 std::optional<int> PointToNoteNumber(wxPoint pt)
 {
     auto rect = GetClientRect();
     int const disp_half = rect.GetWidth() / 2;
     int const disp_shift = kFullKeysWidth / 2 - disp_half;
     
     double const x = (pt.x + disp_shift);
     int const kOctaveWidth = 7.0 * kKeyWidth;
     
     int octave = (int)(x / (double)kOctaveWidth);
     int x_in_oct = x - (kOctaveWidth * octave);
     
     std::optional<int> found;
     
     for(auto index: kBlackKeyIndices) {
         auto key = kKeyPropertyList[index];
         auto rc = key.rect_;
         rc.SetWidth(kBlackKeyDispWidth);
         rc.Inflate(1, 1);
         if(rc.Contains(x_in_oct - kBlackKeyDispOffset, pt.y)) {
             if(!found) { found = (index + octave * 12); }
             break;
         }
     }
     
     for(auto index: kWhiteKeyIndices) {
         auto key = kKeyPropertyList[index];
         auto rc = key.rect_;
         rc.Inflate(1, 1);
         if(rc.Contains(x_in_oct, pt.y)) {
             if(!found) { found = (index + octave * 12); }
             break;
         }
     }
     
     if(found && 0 <= *found && *found < 128) {
         return *found;
     } else {
         return std::nullopt;
     }
 }
コード例 #7
0
ファイル: UnicodeString.cpp プロジェクト: Maximus5/FarPlugins
UnicodeString& UnicodeString::Append(const char *lpszAdd, UINT CodePage)
{
	if (lpszAdd && *lpszAdd)
	{
		size_t nAddSize = MultiByteToWideChar(CodePage,0,lpszAdd,-1,nullptr,0);
		size_t nNewLength = m_pData->GetLength() + nAddSize - 1;
		Inflate(nNewLength + 1);
		MultiByteToWideChar(CodePage,0,lpszAdd,(int)nAddSize,m_pData->GetData() + m_pData->GetLength(),(int)m_pData->GetSize());
		m_pData->SetLength(nNewLength);
	}

	return *this;
}
コード例 #8
0
ファイル: zlib.c プロジェクト: DQNEO/minigit
void Code(FILE *input_file, FILE *output_file) {
  switch (test_mode) {
    case DEFLATE_MODE: {
      Deflate(input_file, output_file);
      break;
    }
    case INFLATE_MODE: {
      Inflate(input_file, output_file);
      break;
    }
    default: {
      ERROR("invalid mode: %d", test_mode);
    }
  }
}
コード例 #9
0
ファイル: compressedconnection.cpp プロジェクト: c3c/quazaa
qint64 CCompressedConnection::readFromNetwork(qint64 nBytes)
{
	qint64 nRet = CNetworkConnection::readFromNetwork(nBytes);

	if(m_bCompressedInput)
	{
		Inflate();
		if(m_pZInput->size())
		{
			emit readyRead();
		}
	}

	return nRet;
}
コード例 #10
0
ファイル: UnicodeString.cpp プロジェクト: Maximus5/FarPlugins
size_t UnicodeString::SetLength(size_t nLength)
{
	if (nLength < m_pData->GetLength())
	{
		if (!nLength && m_pData->GetRef() > 1)
		{
			m_pData->DecRef();
			SetEUS();
		}
		else
		{
			Inflate(nLength+1);
			return m_pData->SetLength(nLength);
		}
	}

	return m_pData->GetLength();
}
コード例 #11
0
ファイル: CZlib.cpp プロジェクト: DarkSlim/IVMultiplayer-1
int CZlib::Decompress(CString strFileName, CString strOutput)
{
	// Open the files
	FILE * in = fopen(strFileName.Get(), "r");
	FILE * out = fopen(strOutput.Get(), "w+");

	// Enable binary mode
	SET_BINARY_MODE(in);
	SET_BINARY_MODE(out);

	// Deflate the file
	int iReturn = Inflate(in, out);

	// Close the files
	fclose(in);
	fclose(out);

	return iReturn;
}
コード例 #12
0
ファイル: Package.cpp プロジェクト: Hyzoran/Eoverse
//TODO: Multi-thread this
void FZipPackage::LoadAsset( FStringConst& Path )
{
	guard;

	//Check that the asset exists
	FZipAsset* Asset = (FZipAsset*)FindAsset( Path );
	if(!Asset)
	{
		FString Err = FString( L"Asset '" ) + Path.Data + FString( L"' could not be read." );
		Throw( (wchar_t*)Err.Data, false );
	}
	
	Seek( Asset->Location, Begin );
	Asset->Ptr = new uint8[Asset->Size];
	switch (Asset->CompressType)
	{
		case 0:
		{
			//No compression
			Read( Asset->Ptr, Asset->Size );
			break;
		}
		case 8:
		{
			//Deflate
			uint8* CompressData = new uint8[Asset->CompressSize];
			Read( CompressData, Asset->CompressSize );
			Inflate( CompressData, Asset->Ptr, Asset->CompressSize, Asset->Size );
			if(Asset->Type == AT_Text || Asset->Type == AT_Script)
			{
				//Null terminate the data if it has formatted text
				Asset->Ptr[Asset->Size] = 0;
			}
			break;
		}
		default:
		{
			Logf( LOG_ERR, L"Asset '%s' is compressed with an unknown method.", Asset->Name );
		}
	}

	unguard;
}
コード例 #13
0
ファイル: gzip_stream.cpp プロジェクト: JamShan/Phoenix3D_2.1
// implements ZeroCopyInputStream ----------------------------------
bool GzipInputStream::Next(const void** data, int* size) {
  bool ok = (zerror_ == Z_OK) || (zerror_ == Z_STREAM_END)
      || (zerror_ == Z_BUF_ERROR);
  if ((!ok) || (zcontext_.next_out == NULL)) {
    return false;
  }
  if (zcontext_.next_out != output_position_) {
    DoNextOutput(data, size);
    return true;
  }
  if (zerror_ == Z_STREAM_END) {
    if (zcontext_.next_out != NULL) {
      // sub_stream_ may have concatenated streams to follow
      zerror_ = inflateEnd(&zcontext_);
      if (zerror_ != Z_OK) {
        return false;
      }
      zerror_ = internalInflateInit2(&zcontext_, format_);
      if (zerror_ != Z_OK) {
        return false;
      }
    } else {
      *data = NULL;
      *size = 0;
      return false;
    }
  }
  zerror_ = Inflate(Z_NO_FLUSH);
  if ((zerror_ == Z_STREAM_END) && (zcontext_.next_out == NULL)) {
    // The underlying stream's Next returned false inside Inflate.
    return false;
  }
  ok = (zerror_ == Z_OK) || (zerror_ == Z_STREAM_END)
      || (zerror_ == Z_BUF_ERROR);
  if (!ok) {
    return false;
  }
  DoNextOutput(data, size);
  return true;
}
コード例 #14
0
ファイル: UnicodeString.cpp プロジェクト: Maximus5/FarPlugins
wchar_t *UnicodeString::GetBuffer(size_t nSize)
{
	Inflate(nSize == (size_t)-1?m_pData->GetSize():nSize);
	return m_pData->GetData();
}
コード例 #15
0
/*package*/
void WebHistoryItemClassic::Inflate(
    /* [in] */ Int32 nativeFrame)
{
    mNativeBridge = Inflate(nativeFrame, mFlattenedData);
    mFlattenedData = NULL;
}
コード例 #16
0
ファイル: Rectangle.cpp プロジェクト: riteme/ne2d
void Rectangle::Inflate(const VectorType &size) noexcept {
    Inflate(size.X(), size.Y());
}
コード例 #17
0
ファイル: FindCallersViewWnd.cpp プロジェクト: 250394/Play-
void CFindCallersViewWnd::RefreshLayout()
{
	auto clientRect = GetClientRect();
	clientRect.Inflate(-5, -5);
	m_callersList.SetSizePosition(clientRect);
}
コード例 #18
0
ファイル: stardict.cpp プロジェクト: Armel35/pyglossary
/*!
    \fn StarDict::search( const char *word )
 */
const char* StarDict::search( const char *word )
{
  char line[256];
  string headword;
  struct entry entry;
  bool found = false;
  uint a;
  string idxFile;

  char buf[m_idxfilesize];
  if( isIdxCompressed ) {
    gzFile gzfile = gzopen( idxFileName.c_str(), "rb" );
    if( gzfile == NULL ) {
      m_isOk = false;
      return "";
    }
    int read = gzread( gzfile, buf, m_idxfilesize );
    if( m_idxfilesize != (uint)read ) {
      m_isOk = false;
      return "";
    }
    idxFile.assign( buf, m_idxfilesize );
    gzclose( gzfile );
  }else{
    ifstream file;
    file.open( idxFileName.c_str() );
    file.readsome( buf, m_idxfilesize );
    idxFile.assign( buf, m_idxfilesize );
    file.close();
  }

  // Find the headword in index file
  uint pos = 0;
  for(uint b=0;b<m_wordcount;b++)
  {
    a = 0;
    do
    {
      line[a] = idxFile[pos];
      a++;
      pos++;
    }while( line[a-1] != '\0' );

    headword = line;

    for(a=0;a<8;a++) line[a] = idxFile[pos++];

    if( headword.compare( word ) != 0 ) continue;

    found = true;

    entry.headword = headword;

    // Get the position of definition in definition file
    entry.position = (unsigned char)line[3] | (unsigned char)line[2] << 8 | (unsigned char)line[1] << 16 | (unsigned char)line[0] << 24;

    // Get the size of definition in definition file
    entry.size = (unsigned char)line[7] | (unsigned char)line[6] << 8 | (unsigned char)line[5] << 16 | (unsigned char)line[4] << 24;

  }

  // If not found, return a null string
  if( !found ) return "";

  // Check if the definition file is compressed
  if( isCompressed )
  {
    // Calculate how many chunks we have to skip
    uint startChunk = entry.position / CHLEN ;
    uint endChunk = (entry.position + entry.size ) / CHLEN;

    // Calculate the position of definition in chunk
    uint pos = entry.position % CHLEN;

    // Size of the chunk we are looking for
    unsigned long chunkLen = 0;
    for(uint a = startChunk; a < endChunk + 1; a++ ) chunkLen += offsets[a];

    // How many bytes we have to skip
    unsigned long skip = 0;
    for(uint a=0;a<startChunk;a++) skip += offsets[a];

    // Definition file
    file.open( dictFileName.c_str() );

    // Jump to chunk we are looking for
    file.seekg( offset + skip );

    // Get the compressed data
    char buf[chunkLen];
    file.readsome( buf, chunkLen );
    string data( buf, chunkLen );
    file.close();

    // Decompress the data
    string result = Inflate( data );

    // Returns only the definition
    return result.substr( pos, entry.size ).c_str();
  }else{
    // The file is not compressed
    file.open( dictFileName.c_str() );

    // Jump to position of definition
    file.seekg( entry.position );

    // Get the definition
    char buf[entry.size];
    file.readsome( buf, entry.size );
    string result( buf, entry.size );
    file.close();

    // Return the result
    return result.c_str();
  }
  return "";
}
コード例 #19
0
ファイル: main.c プロジェクト: solarin4314/PNG_Decoder_WIN32
int IDATParse(struct XPng* xpng, struct XInflate* inflate, struct XBitmap* xbitmap, const unsigned char* stream, int dataLength)
{
	const unsigned char* idatBuffer; // IDAT 정보

	unsigned char*		imageCurBuffer;
	int					imageCurWidthByte;
	int					ColorMapTablePos;
	unsigned char		filter;
	unsigned char		filter_a[RGBA];
	unsigned char*		filter_b ;	
	unsigned char		filter_c[RGBA];
	const unsigned char* outBuf;
	unsigned int					outBufLen;
	int					ColorMapTableLen;
	int					imageWidthByte;
	int					imagePaddingByte;
	const int*			ColorMapTableCur;

	imageCurBuffer = xpng->m_imageCurBuffer;
	imageCurWidthByte = xpng->m_imageCurWidthByte;
	ColorMapTablePos = xpng->m_ColorMapTablePos;
	filter = xpng->m_filter;
	filter_b = xpng->m_filter_b;	
	*(int*)filter_a = *(int*)xpng->m_filter_a;
	*(int*)filter_c = *(int*)xpng->m_filter_c;


	ColorMapTableLen = xpng->m_ColorMapTableLen;
	imageWidthByte = xpng->m_imageWidthByte;
	imagePaddingByte = xpng->m_imagePaddingByte;
	ColorMapTableCur = xpng->m_ColorMapTableCur;

	if(xpng->m_pInflate->m_outBuffer == NULL)
	{
		xpng->m_pInflate->m_outBuffer = (unsigned char*)malloc(DEFAULT_ALLOC_SIZE); // jmlee 초기화
		xpng->m_pInflate->m_outBufferAlloc = DEFAULT_ALLOC_SIZE;
	}


	idatBuffer = (unsigned char *)malloc(dataLength); // 스트림에서 IDAT Data만 가져옴

	memcpy(idatBuffer, stream, dataLength);


	// 압축해제 시작
	if(Inflate(inflate, idatBuffer, dataLength)!=XINFLATE_ERR_OK){
		printf("error!!!!");
	}

	//디코딩 결과 저장
	outBuf = inflate->m_outBuffer;
	outBufLen = inflate->m_outBufferPos;

	// 출력 버퍼에 쓰기.
	while(outBufLen)
	{
		// 매 스캔라인 첫번째 바이트는 filter 정보이다.
		if(imageCurWidthByte == imageWidthByte)
		{
			filter = *outBuf;

			// 필터에 사용할 변수 초기화
			*((unsigned int*)filter_a) = 0;
			*((unsigned int*)filter_c) = 0;
			filter_b = xpng->m_scanline_current;

			// 최초 실행시 더미값 set
			if(xpng->m_bEnd == false)
			{
				filter_b = xpng->m_filter_b_dummy;
				xpng->m_bEnd = true;
			}

			// 기본 초기화
			ColorMapTablePos = 0;

			// 이전 스캔라인 기억 처리
			xpng->m_scanline_before = xpng->m_scanline_current;
			xpng->m_scanline_current = imageCurBuffer;

			// filter 읽었으니 1증가
			outBuf++;
			outBufLen--;
		}

		// 영상 데이타 복사
		switch(filter)
		{
		case FILTER_NONE :

			if(xpng->m_bPaletted)
			{
				unsigned char palPixel;
				while(outBufLen)
				{
					palPixel = *outBuf;

					// 빨레트를 참고해서 RGBA 값 세팅하기
					*(imageCurBuffer + 2) = xpng->m_palette[palPixel * 3 + 0];		// R
					*(imageCurBuffer + 1) = xpng->m_palette[palPixel * 3 + 1];		// G
					*(imageCurBuffer + 0) = xpng->m_palette[palPixel * 3 + 2];		// B

					// RGBA 사용안함
					*(imageCurBuffer + 3) = 255;					// A

					//WriteOnePixel(xbitmap, &xpng->m_palette[palPixel * 3 + 2]);
					//WriteOnePixel(xbitmap, &xpng->m_palette[palPixel * 3 + 1]);
					//WriteOnePixel(xbitmap, &xpng->m_palette[palPixel * 3 + 0]);


					// a값 버리려면 3으로 변경하고 A부분 주석
					MOVETONEXTBUFFER_4_PAL

				}
			}
			else
			{
				if(ColorMapTablePos==0)
				{
					if(ColorMapTableCur == colorMapTable_RGB_2_BGR)
					{
						while(outBufLen>3 && imageCurWidthByte>3)
						{
							*(imageCurBuffer + 2) = *(outBuf+0);		// R
							*(imageCurBuffer + 1) = *(outBuf+1);		// G
							*(imageCurBuffer + 0) = *(outBuf+2);		// B

							MOVETONEXTBUFFER_FAST(3);
						}
					}
					else if(ColorMapTableCur == colorMapTable_RGBA_2_BGRA)
					{
						while(outBufLen>4 && imageCurWidthByte>4)
						{
							*(imageCurBuffer + 2) = *(outBuf+0);		// R
							*(imageCurBuffer + 1) = *(outBuf+1);		// G
							*(imageCurBuffer + 0) = *(outBuf+2);		// B
							*(imageCurBuffer + 3) = *(outBuf+3);		// A

							MOVETONEXTBUFFER_FAST(4);
						}
					}
				}

				while(outBufLen)
				{
					// RGB 를 BGR 로 혹은 RGBA 를 BGRA 로 바꾸기 위해서 테이블 참조
					*(imageCurBuffer + ColorMapTableCur[ColorMapTablePos]) = *outBuf;

					MOVETONEXTBUFFER
				}
			}

			break;

		case FILTER_SUB :

			if(xpng->m_bPaletted){
			}
			else
			{
				// 한번에 3,4 바이트씩 복사한다.
				if(ColorMapTablePos==0)
				{
					if(ColorMapTableCur == colorMapTable_RGB_2_BGR)
					{
						while(outBufLen>3 && imageCurWidthByte>3)
						{
							filter_a[0] = *(imageCurBuffer + 2) = *(outBuf+0) + filter_a[0];	// R
							filter_a[1] = *(imageCurBuffer + 1) = *(outBuf+1) + filter_a[1];	// G
							filter_a[2] = *(imageCurBuffer + 0) = *(outBuf+2) + filter_a[2];	// B

							MOVETONEXTBUFFER_FAST(3);
						}
					}
					else if(ColorMapTableCur == colorMapTable_RGBA_2_BGRA)
					{
						while(outBufLen>4 && imageCurWidthByte>4)
						{
							filter_a[0] = *(imageCurBuffer + 2) = *(outBuf+0) + filter_a[0];	// R
							filter_a[1] = *(imageCurBuffer + 1) = *(outBuf+1) + filter_a[1];	// G
							filter_a[2] = *(imageCurBuffer + 0) = *(outBuf+2) + filter_a[2];	// B
							filter_a[3] = *(imageCurBuffer + 3) = *(outBuf+3) + filter_a[3];	// A

							MOVETONEXTBUFFER_FAST(4);
						}
					}
				}

				while(outBufLen)
				{
					// RGB 를 BGR 로 혹은 RGBA 를 BGRA 로 바꾸기 위해서 테이블 참조
					// + 왼쪽 픽셀 참조
					// + 필터값 저장(좀전 픽셀)
					filter_a[ColorMapTablePos] = *(imageCurBuffer + ColorMapTableCur[ColorMapTablePos]) = *outBuf + filter_a[ColorMapTablePos];
					MOVETONEXTBUFFER
				}
			}
			break;

		case FILTER_UP :

			if(xpng->m_bPaletted){
			}
			else
			{
				if(filter_b==NULL)
				{
					//DOERR(XPNG_ERR_INVALID_DATA);		// 에러 상황이다.
				}

				// 한번에 3, 4바이트씩 복사한다.
				if(ColorMapTablePos==0)
				{
					if(ColorMapTableCur == colorMapTable_RGB_2_BGR)
					{
						while(outBufLen>3 && imageCurWidthByte>3)
						{
							*(imageCurBuffer + 2) = *(outBuf+0) + *(filter_b + 2);	// R
							*(imageCurBuffer + 1) = *(outBuf+1) + *(filter_b + 1);	// G
							*(imageCurBuffer + 0) = *(outBuf+2) + *(filter_b + 0);	// B

							MOVETONEXTBUFFER_FAST(3);
							filter_b+= 3;
						}
					}
					else if(ColorMapTableCur == colorMapTable_RGBA_2_BGRA)
					{
						while(outBufLen>4 && imageCurWidthByte>4)
						{
							*(imageCurBuffer + 2) = *(outBuf+0) + *(filter_b + 2);	// R
							*(imageCurBuffer + 1) = *(outBuf+1) + *(filter_b + 1);	// G
							*(imageCurBuffer + 0) = *(outBuf+2) + *(filter_b + 0);	// B
							*(imageCurBuffer + 3) = *(outBuf+3) + *(filter_b + 3);	// A


							//WriteOnePixel(xbitmap, *outBuf+0 + *(filter_b + 2));
							//WriteOnePixel(xbitmap, *outBuf+1 + *(filter_b + 1));
							//WriteOnePixel(xbitmap, *outBuf+2 + *(filter_b + 0));
							//WriteOnePixel(xbitmap, *outBuf+3 + *(filter_b + 3));

							MOVETONEXTBUFFER_FAST(4);
							filter_b+= 4;
						}
					}
				}

				while(outBufLen)
				{
					// RGB 를 BGR 로 혹은 RGBA 를 BGRA 로 바꾸기 위해서 테이블 참조
					// + 이전 라인 참조
					*(imageCurBuffer + ColorMapTableCur[ColorMapTablePos]) = 
						*outBuf +
						*(filter_b + ColorMapTableCur[ColorMapTablePos]);					// 이전 스캔 라인

					filter_b++;

					MOVETONEXTBUFFER
				}
			}
			break;


		case FILTER_AVERAGE :

			if(xpng->m_bPaletted){
			}
			else
			{
				if(filter_b==NULL)
				{
					//DOERR(XPNG_ERR_INVALID_DATA);		// 에러 상황이다.
				}



				// 한번에 3,4 픽셀 처리하기
				if(ColorMapTablePos==0)
				{
					// todo
					// 이거 테스트 해봐야 하는데.. 적당한 샘플이 없음.. average 는 별로 안쓰이는듯?
				}

				while(outBufLen)
				{
					int a, b;
					unsigned char* dest;
					// 참조할 데이타
					a = filter_a[ColorMapTablePos];								// 왼쪽
					b = *(filter_b + ColorMapTableCur[ColorMapTablePos]);		// 위

					// 현재 출력 지점
					dest = imageCurBuffer + ColorMapTableCur[ColorMapTablePos];

					*dest = *outBuf + (a+b)/2;

					// 좌측 업데이트
					filter_a[ColorMapTablePos] = *dest;
					// 상단 업데이트
					filter_b++;

					MOVETONEXTBUFFER
				}
			}
			break;

		case FILTER_PAETH :
			if(xpng->m_bPaletted){
			}
			else
			{

				int a, b,c,pa,pb,pc;
				int p;
				unsigned char* dest;
				int cur;

				if(filter_b==NULL)
				{
					//DOERR(XPNG_ERR_INVALID_DATA);		// 에러 상황이다.
				}
				/////////////////////////////////////////////////////////////////////////////
				//
				// PAETH 처리를 매크로화
				//
#define DO_PAETH(src, dst)													\
	a = filter_a[src]; b = *(filter_b +dst); c = filter_c[src];		\
	p = a + b - c;													\
	pa = XPNG_ABS(p-a);												\
	pb = XPNG_ABS(p-b);												\
	pc = XPNG_ABS(p-c);												\
	\
	/* 현재 출력 지점 */											\
	dest = imageCurBuffer + dst;									\
	\
	/* 디코딩된 값 */												\
	cur = *(outBuf+src);											\
	\
	/* 합치기 */													\
	if(pa<=pb && pa<=pc)	*dest = cur + a;						\
				else if(pb<=pc)			*dest = cur + b;						\
				else					*dest = cur + c;						\
				\
				/* 필터 업데이트 */												\
				filter_a[src] = *dest;											\
				filter_c[src] = b;


				// 한번에 3,4 픽셀 처리하기
				if(ColorMapTablePos==0)
				{
					if(ColorMapTableCur == colorMapTable_RGB_2_BGR)
					{
						while(outBufLen>3 && imageCurWidthByte>3)
						{
							DO_PAETH(0, 2);		// R
							DO_PAETH(1, 1);		// G
							DO_PAETH(2, 0);		// B

							// 다음 픽셀로
							MOVETONEXTBUFFER_FAST(3);
							filter_b+= 3;
						}
					}
					else if(ColorMapTableCur == colorMapTable_RGBA_2_BGRA)
					{
						while(outBufLen>4 && imageCurWidthByte>4)
						{
							DO_PAETH(0, 2);		// R
							DO_PAETH(1, 1);		// G
							DO_PAETH(2, 0);		// B
							DO_PAETH(3, 3);		// A

							// 다음 픽셀로
							MOVETONEXTBUFFER_FAST(4);
							filter_b+= 4;
						}
					}
				}

				while(outBufLen)
				{
					// 참조할 데이타
					a = filter_a[ColorMapTablePos];								// 왼쪽
					b = *(filter_b + ColorMapTableCur[ColorMapTablePos]);		// 위
					c = filter_c[ColorMapTablePos];								// 왼쪽 위

					p = a + b - c;

					pa = XPNG_ABS(p-a);
					pb = XPNG_ABS(p-b);
					pc = XPNG_ABS(p-c);


					// 현재 출력 지점
					dest = imageCurBuffer + ColorMapTableCur[ColorMapTablePos];

					// 디코딩된 값
					cur = *outBuf;


					// 합치기
					if(pa<=pb && pa<=pc)
						*dest = cur + a;
					else if(pb<=pc)
						*dest = cur + b;
					else 
						*dest = cur + c;

					// 좌측 업데이트
					filter_a[ColorMapTablePos] = *dest;
					// 좌상단 업데이트
					filter_c[ColorMapTablePos] = b;
					// 상단 업데이트
					filter_b++;

					MOVETONEXTBUFFER
				}
			}
			break;
		default :
			return false;
		}
コード例 #20
0
/*
===================
idSWF::LoadSWF
===================
*/
bool idSWF::LoadSWF( const char* fullpath )
{

	idFile* rawfile = fileSystem->OpenFileRead( fullpath );
	if( rawfile == NULL )
	{
		idLib::Printf( "SWF File not found %s\n", fullpath );
		return false;
	}
	
	swfHeader_t header;
	rawfile->Read( &header, sizeof( header ) );
	
	if( header.W != 'W' || header.S != 'S' )
	{
		idLib::Warning( "Wrong signature bytes" );
		delete rawfile;
		return false;
	}
	
	if( header.version > 9 )
	{
		idLib::Warning( "Unsupported version %d", header.version );
		delete rawfile;
		return false;
	}
	
	bool compressed;
	if( header.compression == 'F' )
	{
		compressed = false;
	}
	else if( header.compression == 'C' )
	{
		compressed = true;
	}
	else
	{
		idLib::Warning( "Unsupported compression type %c", header.compression );
		delete rawfile;
		return false;
	}
	idSwap::Little( header.fileLength );
	
	// header.fileLength somewhat annoyingly includes the size of the header
	uint32 fileLength2 = header.fileLength - ( uint32 )sizeof( swfHeader_t );
	
	// slurp the raw file into a giant array, which is somewhat atrocious when loading from the preload since it's already an idFile_Memory
	byte* fileData = ( byte* )Mem_Alloc( fileLength2, TAG_SWF );
	size_t fileSize = rawfile->Read( fileData, fileLength2 );
	delete rawfile;
	
	if( compressed )
	{
		byte* uncompressed = ( byte* )Mem_Alloc( fileLength2, TAG_SWF );
		if( !Inflate( fileData, ( int )fileSize, uncompressed, fileLength2 ) )
		{
			idLib::Warning( "Inflate error" );
			Mem_Free( uncompressed );
			return false;
		}
		Mem_Free( fileData );
		fileData = uncompressed;
	}
	idSWFBitStream bitstream( fileData, fileLength2, false );
	
	swfRect_t frameSize;
	bitstream.ReadRect( frameSize );
	
	if( !frameSize.tl.Compare( vec2_zero ) )
	{
		idLib::Warning( "Invalid frameSize top left" );
		Mem_Free( fileData );
		return false;
	}
	
	frameWidth = frameSize.br.x;
	frameHeight = frameSize.br.y;
	frameRate = bitstream.ReadU16();
	
	// parse everything
	mainsprite->Load( bitstream, true );
	
	// now that all images have been loaded, write out the combined image
	idStr atlasFileName = "generated/";
	atlasFileName += fullpath;
	atlasFileName.SetFileExtension( ".tga" );
	
	WriteSwfImageAtlas( atlasFileName );
	
	Mem_Free( fileData );
	
	return true;
}
コード例 #21
0
ファイル: geo_classes.cpp プロジェクト: am2222/SAGA-GIS
void CSG_Rect::Inflate(double d, bool bPercent)
{
	Inflate(d, d, bPercent);
}
コード例 #22
0
ファイル: UIUtils.cpp プロジェクト: asdlei00/gtkduilib
void CUIRect::Deflate(int cx, int cy)
{
    Inflate(-cx, -cy);
}
コード例 #23
0
ファイル: UnicodeString.cpp プロジェクト: Maximus5/FarPlugins
UnicodeString&  UnicodeString::Upper(size_t nStartPos, size_t nLength)
{
	Inflate(m_pData->GetSize());
	CharUpperBuffW(m_pData->GetData()+nStartPos, nLength==(size_t)-1?(DWORD)(m_pData->GetLength()-nStartPos):(DWORD)nLength);
	return *this;
}
コード例 #24
0
ファイル: zone_filler.cpp プロジェクト: cpavlina/kicad
void ZONE_FILLER::buildUnconnectedThermalStubsPolygonList( SHAPE_POLY_SET& aCornerBuffer,
                                              const ZONE_CONTAINER*       aZone,
                                              const SHAPE_POLY_SET&       aRawFilledArea,
                                              double                aArcCorrection,
                                              double                aRoundPadThermalRotation ) const
{
    SHAPE_LINE_CHAIN spokes;
    BOX2I itemBB;
    VECTOR2I ptTest[4];
    auto zoneBB = aRawFilledArea.BBox();


    int      zone_clearance = aZone->GetZoneClearance();

    int      biggest_clearance = m_board->GetDesignSettings().GetBiggestClearanceValue();
    biggest_clearance = std::max( biggest_clearance, zone_clearance );
    zoneBB.Inflate( biggest_clearance );

    // half size of the pen used to draw/plot zones outlines
    int pen_radius = aZone->GetMinThickness() / 2;

    for( auto module : m_board->Modules() )
    {
        for( auto pad : module->Pads() )
        {
            // Rejects non-standard pads with tht-only thermal reliefs
            if( aZone->GetPadConnection( pad ) == PAD_ZONE_CONN_THT_THERMAL
             && pad->GetAttribute() != PAD_ATTRIB_STANDARD )
                continue;

            if( aZone->GetPadConnection( pad ) != PAD_ZONE_CONN_THERMAL
             && aZone->GetPadConnection( pad ) != PAD_ZONE_CONN_THT_THERMAL )
                continue;

            if( !pad->IsOnLayer( aZone->GetLayer() ) )
                continue;

            if( pad->GetNetCode() != aZone->GetNetCode() )
                continue;

            // Calculate thermal bridge half width
            int thermalBridgeWidth = aZone->GetThermalReliefCopperBridge( pad )
                                     - aZone->GetMinThickness();
            if( thermalBridgeWidth <= 0 )
                continue;

            // we need the thermal bridge half width
            // with a small extra size to be sure we create a stub
            // slightly larger than the actual stub
            thermalBridgeWidth = ( thermalBridgeWidth + 4 ) / 2;

            int thermalReliefGap = aZone->GetThermalReliefGap( pad );

            itemBB = pad->GetBoundingBox();
            itemBB.Inflate( thermalReliefGap );
            if( !( itemBB.Intersects( zoneBB ) ) )
                continue;

            // Thermal bridges are like a segment from a starting point inside the pad
            // to an ending point outside the pad

            // calculate the ending point of the thermal pad, outside the pad
            VECTOR2I endpoint;
            endpoint.x = ( pad->GetSize().x / 2 ) + thermalReliefGap;
            endpoint.y = ( pad->GetSize().y / 2 ) + thermalReliefGap;

            // Calculate the starting point of the thermal stub
            // inside the pad
            VECTOR2I startpoint;
            int copperThickness = aZone->GetThermalReliefCopperBridge( pad )
                                  - aZone->GetMinThickness();

            if( copperThickness < 0 )
                copperThickness = 0;

            // Leave a small extra size to the copper area inside to pad
            copperThickness += KiROUND( IU_PER_MM * 0.04 );

            startpoint.x = std::min( pad->GetSize().x, copperThickness );
            startpoint.y = std::min( pad->GetSize().y, copperThickness );

            startpoint.x /= 2;
            startpoint.y /= 2;

            // This is a CIRCLE pad tweak
            // for circle pads, the thermal stubs orientation is 45 deg
            double fAngle = pad->GetOrientation();
            if( pad->GetShape() == PAD_SHAPE_CIRCLE )
            {
                endpoint.x     = KiROUND( endpoint.x * aArcCorrection );
                endpoint.y     = endpoint.x;
                fAngle = aRoundPadThermalRotation;
            }

            // contour line width has to be taken into calculation to avoid "thermal stub bleed"
            endpoint.x += pen_radius;
            endpoint.y += pen_radius;
            // compute north, south, west and east points for zone connection.
            ptTest[0] = VECTOR2I( 0, endpoint.y );       // lower point
            ptTest[1] = VECTOR2I( 0, -endpoint.y );      // upper point
            ptTest[2] = VECTOR2I( endpoint.x, 0 );       // right point
            ptTest[3] = VECTOR2I( -endpoint.x, 0 );      // left point

            // Test all sides
            for( int i = 0; i < 4; i++ )
            {
                // rotate point
                RotatePoint( ptTest[i], fAngle );

                // translate point
                ptTest[i] += pad->ShapePos();

                if( aRawFilledArea.Contains( ptTest[i] ) )
                    continue;

                spokes.Clear();

                // polygons are rectangles with width of copper bridge value
                switch( i )
                {
                case 0:       // lower stub
                    spokes.Append( -thermalBridgeWidth, endpoint.y );
                    spokes.Append( +thermalBridgeWidth, endpoint.y );
                    spokes.Append( +thermalBridgeWidth, startpoint.y );
                    spokes.Append( -thermalBridgeWidth, startpoint.y );
                    break;

                case 1:       // upper stub
                    spokes.Append( -thermalBridgeWidth, -endpoint.y );
                    spokes.Append( +thermalBridgeWidth, -endpoint.y );
                    spokes.Append( +thermalBridgeWidth, -startpoint.y );
                    spokes.Append( -thermalBridgeWidth, -startpoint.y );
                    break;

                case 2:       // right stub
                    spokes.Append( endpoint.x, -thermalBridgeWidth );
                    spokes.Append( endpoint.x, thermalBridgeWidth );
                    spokes.Append( +startpoint.x, thermalBridgeWidth );
                    spokes.Append( +startpoint.x, -thermalBridgeWidth );
                    break;

                case 3:       // left stub
                    spokes.Append( -endpoint.x, -thermalBridgeWidth );
                    spokes.Append( -endpoint.x, thermalBridgeWidth );
                    spokes.Append( -startpoint.x, thermalBridgeWidth );
                    spokes.Append( -startpoint.x, -thermalBridgeWidth );
                    break;
                }

                aCornerBuffer.NewOutline();

                // add computed polygon to list
                for( int ic = 0; ic < spokes.PointCount(); ic++ )
                {
                    auto cpos = spokes.CPoint( ic );
                    RotatePoint( cpos, fAngle );                               // Rotate according to module orientation
                    cpos += pad->ShapePos();                              // Shift origin to position
                    aCornerBuffer.Append( cpos );
                }
            }
        }
    }
}
コード例 #25
0
ファイル: base_struct.cpp プロジェクト: OpenEE/micad
EDA_RECT& EDA_RECT::Inflate( int aDelta )
{
    Inflate( aDelta, aDelta );
    return *this;
}
コード例 #26
0
ファイル: geo_classes.cpp プロジェクト: am2222/SAGA-GIS
void CSG_Rect::Deflate(double dx, double dy, bool bPercent)
{
	Inflate(-dx, -dy, bPercent);
}
コード例 #27
0
ファイル: UnicodeString.hpp プロジェクト: landswellsong/FAR
		UnicodeString& Unlink() {Inflate(m_pData->GetLength()+1); return *this;}