skia image lib

本文详细介绍了SkImageDecoder的工作原理及其实现细节,包括如何通过不同的工厂方法获取具体的解码器,以及这些解码器是如何匹配并处理图像流的。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

1.SkImage decoded procedure
SkImageDecoder.DecodeMemory/SkImageDecoder.DecodeFile
SkImageDecoder.DecodeStream
SkImageDecoder.decode
SkImageDecoder.onDecode
SkJPEGImageDecoder.onDecode(SkImageDecoder_libjpeg.cpp)
SkImageDecoder.return_flase(error)


2.factory mode
a.client use abs product in it's code.
client set the product to a specific one before use it.
b.client use the factory to get a specific product.
the key point is how we can get a specific product from the factory.
there are two imporant points here. first we should pass a parameter in;
second, how we can get different factory from the parameter.


3.SkImageDecoder's factory
in SkImageDecoder::DecodeStream, call
SkImageDecoder* codec = SkImageDecoder::Factory(stream);
to get a concrete ImageDecoder.
a. in SkImageDecoder_Factory.cpp

  1. const DecodeReg* curr = DecodeReg::Head();  
  2. while (curr) {  
  3.     codec = curr->factory()(stream);  
  4.     // we rewind here, because we promise later when we call "decode", that  
  5.     // the stream will be at its beginning.  
  6.     stream->rewind();  
  7.     if (codec) {  
  8.         return codec;  
  9.     }  
  10.     curr = curr->next();  
  11. }  


Factory use DecodeReg class, traversal a DecodeReg list
use "codec = curr->factory()(stream);" to find the decoder that match the stream.


b.how does curr->factory()(stream) works?
1)SkTRegistry defined in SkTRegistry.h
typedef SkTRegistry<SkImageDecoder*, SkStream*> DecodeReg;
//template class with two class parameters, first is SkImageDecoder, second is SKStream.
Factory factory() const { return fFact; }
Factory      fFact;
template <typename T, typename P> class SkTRegistry :{
typedef T (*Factory)(P);...}
so curr->factory() will call a function pointer, input the SKStream and return SkImaageDecoer.
2)how is the pointer assigned?
SkTRegistry(Factory fact) {fFact = fact;...}
in the constructor function.
3)when is it called?
in every concrete factory we define the factory.
static SkTRegistry<SkImageDecoder*, SkStream*> gReg(Factory);
static SkTRegistry<SkImageDecoder*, SkStream*> gReg(Factory);
static SkTRegistry<SkImageDecoder*, SkStream*> gReg(Factory);
static SkTRegistry<SkImageDecoder*, SkStream*> gDReg(DFactory);
static SkTRegistry<SkImageEncoder*, SkImageEncoder::Type> gEReg(EFactory);
static SkTRegistry<SkImageEncoder*, SkImageEncoder::Type> gEReg(sk_libpng_efactory);
static SkTRegistry<SkImageDecoder*, SkStream*> gDReg(sk_libpng_dfactory);
static SkTRegistry<SkImageDecoder*, SkStream*> gDReg(DFactory);
static SkTRegistry<SkImageDecoder*, SkStream*> gReg(Factory);
so we will call every decoder's Factory() when traversal the list and return the factory we want.
4)how is the coder above added in called when we just call curr->factory?
in SkImageDecoder_empty.cpp

  1. SkImageDecoder* SkImageDecoder::Factory(SkStream* stream) {  
  2.     for (size_t i = 0; i < SK_ARRAY_COUNT(gPairs); i++) {  
  3.         SkImageDecoder* codec = gPairs[i].fProc(stream);  
  4.         stream->rewind();  
  5.         if (NULL != codec) {  
  6.             return codec;  
  7.         }  
  8.     }  
  9.     return NULL;  
  10. }  



add every in and call it.

转载于:https://www.cnblogs.com/elfylin/archive/2012/04/06/2435366.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值