driver/pictureviewer/jpeg: remove server-based rescaling code

Conflicts:
	src/system/settings.h
This commit is contained in:
martii
2013-12-24 10:13:15 +01:00
committed by [CST] Focus
parent 4b09040caa
commit a99e8df965
4 changed files with 20 additions and 169 deletions

View File

@@ -63,87 +63,7 @@ void jpeg_cb_error_exit(j_common_ptr cinfo)
// dbout("jpeg_cd_error_exit }\n"); // dbout("jpeg_cd_error_exit }\n");
} }
#define BUFFERLEN 8192 int fh_jpeg_load(const char *filename,unsigned char **buffer,int* x,int* y)
int fh_jpeg_load_via_server(const char *filename,unsigned char *buffer,int x,int y)
{
struct sockaddr_in si_other;
int s, slen=sizeof(si_other);
int bytes, port;
char path[PICV_CLIENT_SERVER_PATHLEN];
struct pic_data pd;
strncpy(path, filename, PICV_CLIENT_SERVER_PATHLEN-1);
path[PICV_CLIENT_SERVER_PATHLEN - 1] = 0;
dbout("fh_jpeg_load_via_server (%s/%d/%d) {\n",basename(filename),x,y);
if ((s=socket(AF_INET, SOCK_STREAM, IPPROTO_TCP))==-1)
{
perror("socket:");
return(FH_ERROR_FILE);
}
port=atoi(g_settings.picviewer_decode_server_port);
printf("Server %s [%d]\n",g_settings.picviewer_decode_server_ip.c_str(),port);
memset((char *) &si_other, 0, sizeof(si_other));
si_other.sin_family = AF_INET;
si_other.sin_port = htons(port);
if (inet_aton(g_settings.picviewer_decode_server_ip.c_str(),
&si_other.sin_addr)==0)
{
fprintf(stderr, "inet_aton() failed\n");
return(FH_ERROR_FILE);
}
if (connect(s, (struct sockaddr *) &si_other, slen)==-1)
{
perror("connect()");
return(FH_ERROR_FILE);
}
if (send(s, path, PICV_CLIENT_SERVER_PATHLEN, 0)==-1)
{
perror("send()");
return(FH_ERROR_FILE);
}
pd.width=htonl(x);
pd.height=htonl(y);
if (send(s, &pd, sizeof(pd), 0)==-1)
{
perror("send()");
return(FH_ERROR_FILE);
}
if (recv(s, &pd, sizeof(pd), 0) < (int)sizeof(pd))
{
perror("recv pic desc");
return(FH_ERROR_FILE);
}
if ((int)ntohl(pd.width) != x || (int)ntohl(pd.height) != y)
{
fprintf(stderr,"ugh, decoded pic has wrong size [%d/%d]<>[%d/%d]\n", ntohl(pd.width), ntohl(pd.height), x, y);
return(FH_ERROR_FILE);
}
unsigned char buf2[BUFFERLEN];
unsigned char* workptr=buffer;
int rest = x*y*2;
while (rest > 0)
{
bytes=recv(s, buf2, MIN(BUFFERLEN,rest), 0);
if(bytes % 2 ==1)
bytes+=recv(s, buf2+bytes, 1, 0);
for(int i=0 ; i < bytes ; i+=2)
{
*workptr = (buf2[i] >> 2) << 3;
workptr++;
*workptr = (buf2[i] << 6) | ((buf2[i+1] >> 5) << 3);
workptr++;
*workptr = (buf2[i+1] << 3);
workptr++;
}
rest-=bytes;
}
dbout("fh_jpeg_load_via_server }\n");
return(FH_ERROR_OK);
}
int fh_jpeg_load_local(const char *filename,unsigned char **buffer,int* x,int* y)
{ {
//dbout("fh_jpeg_load_local (%s/%d/%d) {\n",basename(filename),*x,*y); //dbout("fh_jpeg_load_local (%s/%d/%d) {\n",basename(filename),*x,*y);
struct jpeg_decompress_struct cinfo; struct jpeg_decompress_struct cinfo;
@@ -215,98 +135,46 @@ int fh_jpeg_load_local(const char *filename,unsigned char **buffer,int* x,int* y
return(FH_ERROR_OK); return(FH_ERROR_OK);
} }
int fh_jpeg_load(const char *filename,unsigned char **buffer,int* x,int* y)
{
int ret=FH_ERROR_FILE;
#if 1
if(!g_settings.picviewer_decode_server_ip.empty())
ret=fh_jpeg_load_via_server(filename, *buffer, *x, *y);
if(ret!=FH_ERROR_OK)
#endif
ret=fh_jpeg_load_local(filename, buffer, x, y);
return ret;
}
int fh_jpeg_getsize(const char *filename,int *x,int *y, int wanted_width, int wanted_height) int fh_jpeg_getsize(const char *filename,int *x,int *y, int wanted_width, int wanted_height)
{ {
// dbout("fh_jpeg_getsize {\n"); // dbout("fh_jpeg_getsize {\n");
struct jpeg_decompress_struct cinfo; struct jpeg_decompress_struct cinfo;
struct jpeg_decompress_struct *ciptr;
struct r_jpeg_error_mgr emgr; struct r_jpeg_error_mgr emgr;
int px,py/*,c*/;
FILE *fh; FILE *fh;
ciptr=&cinfo;
if(!(fh=fopen(filename,"rb"))) return(FH_ERROR_FILE); if(!(fh=fopen(filename,"rb"))) return(FH_ERROR_FILE);
ciptr->err=jpeg_std_error(&emgr.pub); cinfo.err=jpeg_std_error(&emgr.pub);
emgr.pub.error_exit=jpeg_cb_error_exit; emgr.pub.error_exit=jpeg_cb_error_exit;
if(setjmp(emgr.envbuffer)==1) if(setjmp(emgr.envbuffer)==1)
{ {
// FATAL ERROR - Free the object and return... // FATAL ERROR - Free the object and return...
jpeg_destroy_decompress(ciptr); jpeg_destroy_decompress(&cinfo);
fclose(fh); fclose(fh);
// dbout("fh_jpeg_getsize } - FATAL ERROR\n"); // dbout("fh_jpeg_getsize } - FATAL ERROR\n");
return(FH_ERROR_FORMAT); return(FH_ERROR_FORMAT);
} }
jpeg_create_decompress(ciptr); jpeg_create_decompress(&cinfo);
jpeg_stdio_src(ciptr,fh); jpeg_stdio_src(&cinfo,fh);
jpeg_read_header(ciptr,TRUE); jpeg_read_header(&cinfo,TRUE);
ciptr->out_color_space=JCS_RGB; cinfo.out_color_space=JCS_RGB;
// should be more flexible... // should be more flexible...
if((int)ciptr->image_width/8 >= wanted_width || if((int)cinfo.image_width/8 >= wanted_width ||
(int)ciptr->image_height/8 >= wanted_height) (int)cinfo.image_height/8 >= wanted_height)
ciptr->scale_denom=8; cinfo.scale_denom=8;
else if((int)ciptr->image_width/4 >= wanted_width || else if((int)cinfo.image_width/4 >= wanted_width ||
(int)ciptr->image_height/4 >= wanted_height) (int)cinfo.image_height/4 >= wanted_height)
ciptr->scale_denom=4; cinfo.scale_denom=4;
else if((int)ciptr->image_width/2 >= wanted_width || else if((int)cinfo.image_width/2 >= wanted_width ||
(int)ciptr->image_height/2 >= wanted_height) (int)cinfo.image_height/2 >= wanted_height)
ciptr->scale_denom=2; cinfo.scale_denom=2;
else else
ciptr->scale_denom=1; cinfo.scale_denom=1;
jpeg_start_decompress(ciptr); jpeg_start_decompress(&cinfo);
px=ciptr->output_width; py=ciptr->output_height; *x=cinfo.output_width; *y=cinfo.output_height;
// c=ciptr->output_components; jpeg_destroy_decompress(&cinfo);
#if 1
if(!g_settings.picviewer_decode_server_ip.empty())
{
// jpeg server resizes pic to desired size
if( px > wanted_width || py > wanted_height)
{
if( (CPictureViewer::m_aspect_ratio_correction*py*wanted_width/px) <= wanted_height)
{
*x=wanted_width;
*y=(int)(CPictureViewer::m_aspect_ratio_correction*py*wanted_width/px);
}
else
{
*x=(int)((1.0/CPictureViewer::m_aspect_ratio_correction)*px*wanted_height/py);
*y=wanted_height;
}
}
else if(CPictureViewer::m_aspect_ratio_correction >=1)
{
*x=px;
*y=(int)(py/CPictureViewer::m_aspect_ratio_correction);
}
else
{
*x=(int)(px/CPictureViewer::m_aspect_ratio_correction);
*y=py;
}
}
else
#endif
{
*x=px;
*y=py;
}
// jpeg_finish_decompress(ciptr);
jpeg_destroy_decompress(ciptr);
fclose(fh); fclose(fh);
// dbout("fh_jpeg_getsize }\n"); // dbout("fh_jpeg_getsize }\n");
return(FH_ERROR_OK); return(FH_ERROR_OK);

View File

@@ -737,7 +737,6 @@ int CNeutrinoApp::loadSetup(const char * fname)
//Picture-Viewer //Picture-Viewer
g_settings.picviewer_slide_time = configfile.getInt32( "picviewer_slide_time", 10); g_settings.picviewer_slide_time = configfile.getInt32( "picviewer_slide_time", 10);
g_settings.picviewer_scaling = configfile.getInt32("picviewer_scaling", 1 /*(int)CPictureViewer::SIMPLE*/); g_settings.picviewer_scaling = configfile.getInt32("picviewer_scaling", 1 /*(int)CPictureViewer::SIMPLE*/);
g_settings.picviewer_decode_server_ip = configfile.getString("picviewer_decode_server_ip", "");
//Audio-Player //Audio-Player
g_settings.audioplayer_display = configfile.getInt32("audioplayer_display",(int)CAudioPlayerGui::ARTIST_TITLE); g_settings.audioplayer_display = configfile.getInt32("audioplayer_display",(int)CAudioPlayerGui::ARTIST_TITLE);
@@ -1177,8 +1176,6 @@ void CNeutrinoApp::saveSetup(const char * fname)
//Picture-Viewer //Picture-Viewer
configfile.setInt32( "picviewer_slide_time", g_settings.picviewer_slide_time); configfile.setInt32( "picviewer_slide_time", g_settings.picviewer_slide_time);
configfile.setInt32( "picviewer_scaling", g_settings.picviewer_scaling ); configfile.setInt32( "picviewer_scaling", g_settings.picviewer_scaling );
configfile.setString( "picviewer_decode_server_ip", g_settings.picviewer_decode_server_ip );
configfile.setString( "picviewer_decode_server_port", g_settings.picviewer_decode_server_port);
//Audio-Player //Audio-Player
configfile.setInt32( "audioplayer_display", g_settings.audioplayer_display ); configfile.setInt32( "audioplayer_display", g_settings.audioplayer_display );

View File

@@ -870,16 +870,6 @@ start-block~neutrino_form-data_pictureviewer
<td>{=L:set.pv.start_dir=}</td> <td>{=L:set.pv.start_dir=}</td>
<td><input type="text" name="network_nfs_picturedir" size="20" value="{=ini-get:/var/tuxbox/config/neutrino.conf;network_nfs_picturedir~cache=}" /></td> <td><input type="text" name="network_nfs_picturedir" size="20" value="{=ini-get:/var/tuxbox/config/neutrino.conf;network_nfs_picturedir~cache=}" /></td>
</tr> </tr>
{=if-not-equal:{=global-var-get:boxtype=}~coolstream~
<tr>
<td>{=L:set.pv.decoding_server_ip=}</td>
<td><input type="text" name="picviewer_decode_server_ip" size="15" maxlength="15" value="{=ini-get:/var/tuxbox/config/neutrino.conf;picviewer_decode_server_ip~cache=}" /></td>
</tr>
<tr>
<td>{=L:set.pv.decoding_server_port=}</td>
<td><input type="text" name="picviewer_decode_server_port" size="5" maxlength="5" value="{=ini-get:/var/tuxbox/config/neutrino.conf;picviewer_decode_server_port~cache=}" /></td>
</tr>
=}
</table> </table>
<br/> <br/>
<input type="hidden" name="tmpl" value="Y_Settings_neutrino_forms.yhtm"/> <input type="hidden" name="tmpl" value="Y_Settings_neutrino_forms.yhtm"/>
@@ -916,8 +906,6 @@ start-block~neutrino_pictureviewer_save_settings
{=ini-set:/var/tuxbox/config/neutrino.conf;picviewer_scaling;{=picviewer_scaling=}~open=} {=ini-set:/var/tuxbox/config/neutrino.conf;picviewer_scaling;{=picviewer_scaling=}~open=}
{=ini-set:/var/tuxbox/config/neutrino.conf;picviewer_slide_time;{=picviewer_slide_time=}~cache=} {=ini-set:/var/tuxbox/config/neutrino.conf;picviewer_slide_time;{=picviewer_slide_time=}~cache=}
{=ini-set:/var/tuxbox/config/neutrino.conf;network_nfs_picturedir;{=network_nfs_picturedir=}~cache=} {=ini-set:/var/tuxbox/config/neutrino.conf;network_nfs_picturedir;{=network_nfs_picturedir=}~cache=}
{=ini-set:/var/tuxbox/config/neutrino.conf;picviewer_decode_server_ip;{=picviewer_decode_server_ip=}~cache=}
{=ini-set:/var/tuxbox/config/neutrino.conf;picviewer_decode_server_port;{=picviewer_decode_server_port=}~save=}
end-block~neutrino_pictureviewer_save_settings end-block~neutrino_pictureviewer_save_settings
# ------- Neutrino form-data: audioplayer ------------------------------- # ------- Neutrino form-data: audioplayer -------------------------------

View File

@@ -638,8 +638,6 @@ struct SNeutrinoSettings
// pictureviewer // pictureviewer
int picviewer_slide_time; int picviewer_slide_time;
int picviewer_scaling; int picviewer_scaling;
std::string picviewer_decode_server_ip;
char picviewer_decode_server_port[6];
//audioplayer //audioplayer
int audioplayer_display; int audioplayer_display;