libwebp符号化yuv 420はwebpピクチャフォーマットである

12317 ワード

yuv 420符号化webp

  • libwebp紹介
  • コード
  • libwebpの紹介


    アドレスとドキュメントのダウンロード

    コード#コード#

    	WebPPicture pic_;
    	WebPConfig config_;
    	WebPMemoryWriter wrt_;
    
    	if (!WebPConfigPreset(&config_, WEBP_PRESET_DEFAULT, 100) ||
    		!WebPPictureInit(&pic_)) {
    		return -1;  
    	}
    
    	config_.lossless = 0;// 
    	//config_.quality = 0; // 
    	config_.method = 0;
    	//config_.sns_strength = 0;
    	//config_.filter_strength = 0;
    	int ret = WebPValidateConfig(&config_);  // not mandatory, but useful
    
    	//pic_.use_argb = 0;
    	pic_.width = width;
    	pic_.height = height;
    	pic_.writer = WebPMemoryWrite;
    	pic_.custom_ptr = &wrt_;
    	WebPMemoryWriterInit(&wrt_);
    
    	if (!WebPPictureAlloc(&pic_)) return -1;
    
    	//  y、u、v   
    	unsigned char *ybase, *ubase, *vbase;
    	ybase = frame_buffer->MutableDataY();
    	ubase = frame_buffer->MutableDataU();
    	vbase = frame_buffer->MutableDataV();
    	int ystride = frame_buffer->StrideY();
    	int ustride = frame_buffer->StrideU();
    	int vstride = frame_buffer->StrideV();
    
    	unsigned char * dest_y = pic_.y;
    	unsigned char * dest_u = pic_.u;
    	unsigned char * dest_v = pic_.v;
    	int dest_ystride = pic_.y_stride;
    	int dest_ustride = pic_.uv_stride;
    	int dest_vstride = pic_.uv_stride;
    	int widthuv = width_ / 2;
    
    	int i;
    	for (i = 0; i < height_; i++) {
    		memcpy(dest_y,ybase,width_);
    		ybase += ystride;
    		dest_y += dest_ystride;
    	}
    
    	for (i = 0; i < height_/2; i++) {
    		memcpy(dest_u, ubase, widthuv);
    		memcpy(dest_v, vbase, widthuv);
    		ubase += ustride;
    		dest_u += dest_ustride;
    		vbase += vstride;
    		dest_v += dest_vstride;
    	}
    
    	//webrtc::ConvertFromI420(frame, webrtc::kABGR, 0, rgba_);
    
    	/*if (destframe_) {
    		WebPFree(destframe_);
    		destframe_ = 0;
    	}*/
    
    	//ret = WebPEncodeRGBA(rgba_, width_, height_, width_ * 4, 90, &destframe_);
    	//ret = WebPEncodeLosslessRGBA(rgba_, width_, height_, width_ * 4, &destframe_);
    
    	
    
    
    	ret = WebPEncode(&config_, &pic_);
    	if (!ret) {
    		return -1;
    	}
    	
    
    	*dest = (char*)wrt_.mem; //webp 
    	*destsize = wrt_.size; // 
    
    	WebPMemoryWriterClear(&wrt_);
    	WebPPictureFree(&pic_);