fix a compile issues for image-decoder's change

This commit is contained in:
侯歌 2024-09-10 16:01:13 +08:00
parent aad2db3557
commit 9aa51de662
3 changed files with 44 additions and 27 deletions

View File

@ -1,6 +1,7 @@
#include <gtest/gtest.h>
#include <cdroid.h>
#include <core/systemclock.h>
#include <image-decoders/imagedecoder.h>
#include <ngl_os.h>
using namespace cdroid;
@ -57,7 +58,8 @@ TEST_F(BENCHMARK,FillBlit){
TEST_F(BENCHMARK,Jpeg){
int64_t t1=SystemClock::uptimeMillis();
for(int i=0;i<100;i++){
RefPtr<ImageSurface>img=ImageSurface::create_from_jpg("radio_logo.jpg");
auto dec =ImageDecoder::create(nullptr,"radio_logo.jpg");
RefPtr<ImageSurface>img=dec->decode();
}
int64_t t2=SystemClock::uptimeMillis();
printf("jpeg decoe time:%f \r\n",(t2-t1)/100.f);

View File

@ -5,6 +5,7 @@
#include <sstream>
#include <core/systemclock.h>
#include <core/path.h>
#include <image-decoders/imagedecoder.h>
#define SLEEP(x) usleep((x)*1000)
using namespace Cairo;
class DRAWABLE:public testing::Test{
@ -111,9 +112,8 @@ TEST_F(DRAWABLE,bitmapalpha){
}
TEST_F(DRAWABLE,ninepatch1){
std::ifstream fs("/home/houzh/Miniwin/apps/ntvplus/assets/drawable/paopao1.9.png");
RefPtr<ImageSurface>img=ImageSurface::create_from_stream(fs);
ASSERT_EQ(1,(int)fs.good());
auto dec = ImageDecoder::create(nullptr,"/home/houzh/Miniwin/apps/ntvplus/assets/drawable/paopao1.9.png");
RefPtr<ImageSurface>img = dec->decode();
NinePatchDrawable *d=new NinePatchDrawable(img);
d->setBounds(50,50,600,200);
d->draw(*ctx);
@ -121,9 +121,8 @@ TEST_F(DRAWABLE,ninepatch1){
}
TEST_F(DRAWABLE,ninepatch2){
std::ifstream fs("/home/houzh/Miniwin/apps/ntvplus/assets/drawable/btn_normal.9.png");//paopao1.9.png");
RefPtr<ImageSurface>img=ImageSurface::create_from_stream(fs);
ASSERT_EQ(1,(int)fs.good());
auto dec = ImageDecoder::create(nullptr,"/home/houzh/Miniwin/apps/ntvplus/assets/drawable/btn_normal.9.png");//paopao1.9.png");
RefPtr<ImageSurface>img= dec->decode();
ctx->set_source_rgb(.4,.4,.0);
ctx->rectangle(0,0,700,300);
ctx->fill();
@ -573,13 +572,31 @@ TEST_F(DRAWABLE,inflatelevellist){
usleep(500000);
}
}
TEST_F(DRAWABLE,gradient_alpha){
GradientDrawable*gd=new GradientDrawable();
gd->setBounds(50,50,500,500);
gd->setShape(1);
for(int i=0;i<100;i++){
gd->setStroke(i*2+8,0xFFFFFFFF,i*2,i);
ctx->set_source_rgb(0,0,0);
ctx->rectangle(0,0,800,600);
ctx->fill();
gd->setColors(std::vector<int>{(int)0xFFFF0000,(int)0xFF00FF00,(int)0xFF0000FF},{.0f,.5f,1.f});
gd->setCornerRadius(20-i);
gd->setAlpha(i*255/100);
gd->draw(*ctx);
ctx->get_target()->write_to_png(std::string("gradient")+std::to_string(i)+".png");
postCompose();
usleep(1000);
}
}
TEST_F(DRAWABLE,gradient_rectangle){
GradientDrawable*gd=new GradientDrawable();
gd->setBounds(50,50,500,500);
for(int shape=0;shape<4;shape++){
gd->setShape(shape);
for(int i=0;i<8;i++){
for(int i=0;i<100;i++){
gd->setStroke(i*2+8,0xFFFFFFFF,i*2,shape*2);
ctx->set_source_rgb(0,0,0);
@ -589,10 +606,11 @@ TEST_F(DRAWABLE,gradient_rectangle){
gd->setColors(std::vector<int>{(int)0xFFFF0000,(int)0xFF00FF00,(int)0xFF0000FF},{.0f,.5f,1.f});
gd->setSize(500-20*i,500-20*i);
gd->setCornerRadius(20-i);
gd->setAlpha(i*8);
gd->draw(*ctx);
ctx->get_target()->write_to_png("gradient1.png");
ctx->get_target()->write_to_png(std::string("gradient")+std::to_string(i)+".png");
postCompose();
usleep(100000);
usleep(1000000);
}
}
}

View File

@ -8,8 +8,7 @@
#include <sys/types.h>
#include <sys/stat.h>
#include <dirent.h>
//#include <svg-cairo.h>
#include <fstream>
#include <image-decoders/imagedecoder.h>
#ifdef ENABLE_CAIROSVG
#include <curl/curl.h>
#endif
@ -69,7 +68,7 @@ public :
size_t pt=path.rfind('.');
if(pt!= std::string::npos){
std::string ext=path.substr(pt+1);
pt=path.find(filter);
pt=path.find(filter);
if(filter.empty()||pt!= std::string::npos)images.push_back(path);
}
return ;
@ -93,8 +92,8 @@ Assets *IMAGE::rm=nullptr;
TEST_F(IMAGE,Bitmap){
loadImages("./","bmp");
for(int i=0;i<images.size();i++){
std::ifstream fs(images[i].c_str());
RefPtr<ImageSurface>img=ImageSurface::create_from_stream(fs);
auto dec = ImageDecoder::create(nullptr,images[i]);
RefPtr<ImageSurface>img=dec->decode();
RECT rect={0,0,800,600};
for(int i=0;i<10;i++){
ctx->set_color(0xFF000000|(i*20<<16));
@ -112,8 +111,8 @@ TEST_F(IMAGE,Image_PNG){
printf("%lu image loaded\r\n",images.size());
for(int i=0;i<images.size();i++){
tmstart();
std::ifstream fs(images[i].c_str());
RefPtr<ImageSurface>img=ImageSurface::create_from_stream(fs);
auto dec = ImageDecoder::create(nullptr,images[i]);
RefPtr<ImageSurface>img=dec->decode();
tmend("decodepng");
RECT rect={0,0,800,600};
ctx->rectangle(rect);
@ -135,8 +134,8 @@ TEST_F(IMAGE,Image_JPG){
printf("%lu img loaded\r\n",images.size());
for(int i=0;i<images.size();i++){
tmstart();
std::ifstream fs(images[i].c_str());
RefPtr<ImageSurface>img=ImageSurface::create_from_stream(fs);
auto dec = ImageDecoder::create(nullptr,images[i]);
RefPtr<ImageSurface>img=dec->decode();
tmend("decodejpg");
RECT rect={0,0,800,600};
ctx->rectangle(rect);ctx->fill();
@ -153,8 +152,8 @@ TEST_F(IMAGE,Image_JPG){
TEST_F(IMAGE,draw){
loadImages("/home/houzh/JPG/","");
for(int i=0;i<images.size();i++){
std::ifstream fs(images[i].c_str());
RefPtr<ImageSurface>img=ImageSurface::create_from_stream(fs);
auto dec = ImageDecoder::create(nullptr,images[i]);
RefPtr<ImageSurface>img=dec->decode();
RECT dst={100,100,200,200};
RECT rs={img->get_width()/2,img->get_height()/2,img->get_width()/2,img->get_height()/2};
ctx->draw_image(img,dst,&rs);
@ -164,9 +163,8 @@ TEST_F(IMAGE,draw){
}
TEST_F(IMAGE,ninepatch1){
std::ifstream fs("/home/houzh/Miniwin/apps/ntvplus/assets/drawable/paopao1.9.png");
RefPtr<ImageSurface>img=ImageSurface::create_from_stream(fs);
ASSERT_EQ(1,(int)fs.good());
auto dec = ImageDecoder::create(nullptr,"/home/houzh/Miniwin/apps/ntvplus/assets/drawable/paopao1.9.png");
RefPtr<ImageSurface>img = dec->decode();
RECT rect={50,50,400,100};
//std::vector<NinePatchBlock> horz,vert;
//img->get_ninepatch(horz,vert);
@ -174,9 +172,8 @@ TEST_F(IMAGE,ninepatch1){
}
TEST_F(IMAGE,ninepatch2){
std::ifstream fs("/home/houzh/Miniwin/apps/ntvplus/assets/drawable/btn_normal.9.png");
RefPtr<ImageSurface>img=ImageSurface::create_from_stream(fs);
ASSERT_EQ(1,(int)fs.good());
auto dec = ImageDecoder::create(nullptr,"/home/houzh/Miniwin/apps/ntvplus/assets/drawable/btn_normal.9.png");
RefPtr<ImageSurface>img = dec->decode();
RECT rect={50,50,400,100};
//std::vector<NinePatchBlock> horz,vert;
//img->get_ninepatch(horz,vert);