Mercurial > mplayer.hg
changeset 33046:9684ad0e1291
Move files with auxiliary functions to own directory.
author | ib |
---|---|
date | Mon, 28 Mar 2011 12:37:48 +0000 |
parents | 776a676d5fde |
children | 901dc2c4130f |
files | Makefile gui/app.h gui/bitmap.c gui/bitmap.h gui/skin/cut.c gui/skin/cut.h gui/skin/font.c gui/skin/font.h gui/skin/skin.c gui/skin/skin.h gui/util/bitmap.c gui/util/bitmap.h gui/util/cut.c gui/util/cut.h gui/win32/skinload.c |
diffstat | 15 files changed, 377 insertions(+), 377 deletions(-) [+] |
line wrap: on
line diff
--- a/Makefile Sun Mar 27 21:25:58 2011 +0000 +++ b/Makefile Mon Mar 28 12:37:48 2011 +0000 @@ -517,7 +517,7 @@ SRCS_MPLAYER-$(GL_WIN32) += libvo/w32_common.c SRCS_MPLAYER-$(GL_X11) += libvo/x11_common.c SRCS_MPLAYER-$(MATRIXVIEW) += libvo/vo_matrixview.c libvo/matrixview.c -SRCS_MPLAYER-$(GUI) += gui/bitmap.c +SRCS_MPLAYER-$(GUI) += gui/util/bitmap.c SRCS_MPLAYER-$(GUI_GTK) += gui/app.c \ gui/cfg.c \ gui/interface.c \ @@ -538,9 +538,9 @@ gui/mplayer/gtk/opts.c \ gui/mplayer/gtk/pl.c \ gui/mplayer/gtk/sb.c \ - gui/skin/cut.c \ gui/skin/font.c \ gui/skin/skin.c \ + gui/util/cut.c \ gui/wm/ws.c \ gui/wm/wsxdnd.c \
--- a/gui/app.h Sun Mar 27 21:25:58 2011 +0000 +++ b/gui/app.h Mon Mar 28 12:37:48 2011 +0000 @@ -19,7 +19,7 @@ #ifndef MPLAYER_GUI_APP_H #define MPLAYER_GUI_APP_H -#include "bitmap.h" +#include "util/bitmap.h" #include "wm/ws.h" // User events
--- a/gui/bitmap.c Sun Mar 27 21:25:58 2011 +0000 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,258 +0,0 @@ -/* - * This file is part of MPlayer. - * - * MPlayer is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation; either version 2 of the License, or - * (at your option) any later version. - * - * MPlayer is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License along - * with MPlayer; if not, write to the Free Software Foundation, Inc., - * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. - */ - -#include <stdio.h> -#include <stdlib.h> -#include <string.h> - -#include "bitmap.h" - -#include "help_mp.h" -#include "libavcodec/avcodec.h" -#include "libavutil/intreadwrite.h" -#include "libvo/fastmemcpy.h" -#include "mp_msg.h" - -static int pngRead(unsigned char *fname, txSample *bf) -{ - FILE *fp; - int decode_ok; - void *data; - int len; - AVCodecContext *avctx; - AVFrame *frame; - AVPacket pkt; - - fp = fopen(fname, "rb"); - - if (!fp) { - mp_dbg(MSGT_GPLAYER, MSGL_DBG2, "[png] file read error ( %s )\n", fname); - return 1; - } - - fseek(fp, 0, SEEK_END); - len = ftell(fp); - - if (len > 50 * 1024 * 1024) { - fclose(fp); - return 2; - } - - data = av_malloc(len + FF_INPUT_BUFFER_PADDING_SIZE); - - fseek(fp, 0, SEEK_SET); - fread(data, len, 1, fp); - fclose(fp); - - avctx = avcodec_alloc_context(); - frame = avcodec_alloc_frame(); - avcodec_register_all(); - avcodec_open(avctx, avcodec_find_decoder(CODEC_ID_PNG)); - av_init_packet(&pkt); - pkt.data = data; - pkt.size = len; - // HACK: make PNGs decode normally instead of as CorePNG delta frames - pkt.flags = AV_PKT_FLAG_KEY; - avcodec_decode_video2(avctx, frame, &decode_ok, &pkt); - memset(bf, 0, sizeof(*bf)); - - switch (avctx->pix_fmt) { - case PIX_FMT_GRAY8: - bf->BPP = 8; - break; - - case PIX_FMT_GRAY16BE: - bf->BPP = 16; - break; - - case PIX_FMT_RGB24: - bf->BPP = 24; - break; - - case PIX_FMT_BGRA: - case PIX_FMT_ARGB: - bf->BPP = 32; - break; - - default: - bf->BPP = 0; - break; - } - - if (decode_ok && bf->BPP) { - int bpl; - - bf->Width = avctx->width; - bf->Height = avctx->height; - bpl = bf->Width * (bf->BPP / 8); - bf->ImageSize = bpl * bf->Height; - bf->Image = malloc(bf->ImageSize); - memcpy_pic(bf->Image, frame->data[0], bpl, bf->Height, bpl, frame->linesize[0]); - } - - avcodec_close(avctx); - av_freep(&frame); - av_freep(&avctx); - av_freep(&data); - - mp_dbg(MSGT_GPLAYER, MSGL_DBG2, "[png] filename: %s.\n", fname); - mp_dbg(MSGT_GPLAYER, MSGL_DBG2, "[png] size: %lux%lu bits: %u\n", bf->Width, bf->Height, bf->BPP); - mp_dbg(MSGT_GPLAYER, MSGL_DBG2, "[png] imagesize: %lu\n", bf->ImageSize); - - return !(decode_ok && bf->BPP); -} - -static int conv24to32(txSample *bf) -{ - unsigned char *tmpImage; - unsigned int i, c; - - if (bf->BPP == 24) { - tmpImage = bf->Image; - bf->BPP = 32; - bf->ImageSize = bf->Width * bf->Height * 4; - bf->Image = calloc(1, bf->ImageSize); - - if (!bf->Image) { - free(tmpImage); - mp_dbg(MSGT_GPLAYER, MSGL_DBG2, "[bitmap] not enough memory for image\n"); - return 1; - } - - for (c = 0, i = 0; c < bf->ImageSize; c += 4, i += 3) - *(uint32_t *)&bf->Image[c] = AV_RB24(&tmpImage[i]); - - free(tmpImage); - } - - return 0; -} - -static void Normalize(txSample *bf) -{ - int i; - - for (i = 0; i < (int)bf->ImageSize; i += 4) -#if !HAVE_BIGENDIAN - bf->Image[i + 3] = 0; -#else - bf->Image[i] = 0; -#endif -} - -static unsigned char *fExist(unsigned char *fname) -{ - static unsigned char tmp[512]; - FILE *fl; - unsigned char ext[][6] = { ".png\0", ".PNG\0" }; - int i; - - fl = fopen(fname, "rb"); - - if (fl != NULL) { - fclose(fl); - return fname; - } - - for (i = 0; i < 2; i++) { - snprintf(tmp, sizeof(tmp), "%s%s", fname, ext[i]); - fl = fopen(tmp, "rb"); - - if (fl != NULL) { - fclose(fl); - return tmp; - } - } - - return NULL; -} - -int bpRead(char *fname, txSample *bf) -{ - fname = fExist(fname); - - if (fname == NULL) - return -2; - - if (pngRead(fname, bf)) { - mp_dbg(MSGT_GPLAYER, MSGL_FATAL, "[bitmap] unknown file type ( %s )\n", fname); - return -5; - } - - if (bf->BPP < 24) { - mp_dbg(MSGT_GPLAYER, MSGL_DBG2, "[bitmap] Sorry, only 24 and 32 bpp bitmaps are supported.\n"); - return -1; - } - - if (conv24to32(bf)) - return -8; - - Normalize(bf); - return 0; -} - -void bpFree(txSample *bf) -{ - free(bf->Image); - memset(bf, 0, sizeof(*bf)); -} - -void Convert32to1(txSample *in, txSample *out, int adaptivlimit) -{ - out->Width = in->Width; - out->Height = in->Height; - out->BPP = 1; - out->ImageSize = (out->Width * out->Height + 7) / 8; - - mp_dbg(MSGT_GPLAYER, MSGL_DBG2, "[c32to1] imagesize: %lu\n", out->ImageSize); - - out->Image = calloc(1, out->ImageSize); - - if (out->Image == NULL) - mp_msg(MSGT_GPLAYER, MSGL_WARN, MSGTR_NotEnoughMemoryC32To1); - { - int i, b, c = 0; - unsigned int *buf = NULL; - unsigned char tmp = 0; - int nothaveshape = 1; - - buf = (unsigned int *)in->Image; - - for (b = 0, i = 0; i < (int)(out->Width * out->Height); i++) { - if ((int)buf[i] != adaptivlimit) - tmp = (tmp >> 1) | 128; - else { - tmp = tmp >> 1; - buf[i] = nothaveshape = 0; - } - - if (b++ == 7) { - out->Image[c++] = tmp; - tmp = b = 0; - } - } - - if (b) - out->Image[c] = tmp; - - if (nothaveshape) { - free(out->Image); - out->Image = NULL; - } - } -}
--- a/gui/bitmap.h Sun Mar 27 21:25:58 2011 +0000 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,34 +0,0 @@ -/* - * This file is part of MPlayer. - * - * MPlayer is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation; either version 2 of the License, or - * (at your option) any later version. - * - * MPlayer is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License along - * with MPlayer; if not, write to the Free Software Foundation, Inc., - * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. - */ - -#ifndef MPLAYER_GUI_BITMAP_H -#define MPLAYER_GUI_BITMAP_H - -typedef struct { - unsigned long Width; - unsigned long Height; - unsigned int BPP; - unsigned long ImageSize; - char *Image; -} txSample; - -void bpFree(txSample *bf); -int bpRead(char *fname, txSample *bf); -void Convert32to1(txSample *in, txSample *out, int adaptivlimit); - -#endif /* MPLAYER_GUI_BITMAP_H */
--- a/gui/skin/cut.c Sun Mar 27 21:25:58 2011 +0000 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,48 +0,0 @@ -/* - * This file is part of MPlayer. - * - * MPlayer is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation; either version 2 of the License, or - * (at your option) any later version. - * - * MPlayer is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License along - * with MPlayer; if not, write to the Free Software Foundation, Inc., - * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. - */ - -#include <stdlib.h> -#include <string.h> - -#include "cut.h" - -void cutItemString(char *in, char *out, char sep, int num, size_t maxout) -{ - int n; - unsigned int i, c; - - for (c = 0, n = 0, i = 0; in[i]; i++) { - if (in[i] == sep) - n++; - if (n >= num && in[i] != sep && c + 1 < maxout) - out[c++] = in[i]; - if (n >= num && in[i + 1] == sep) - break; - } - - if (c < maxout) - out[c] = 0; -} - -int cutItemToInt(char *in, char sep, int num) -{ - char tmp[64]; - - cutItem(in, tmp, sep, num); - return atoi(tmp); -}
--- a/gui/skin/cut.h Sun Mar 27 21:25:58 2011 +0000 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,29 +0,0 @@ -/* - * This file is part of MPlayer. - * - * MPlayer is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation; either version 2 of the License, or - * (at your option) any later version. - * - * MPlayer is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License along - * with MPlayer; if not, write to the Free Software Foundation, Inc., - * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. - */ - -#ifndef MPLAYER_GUI_CUT_H -#define MPLAYER_GUI_CUT_H - -#include <stddef.h> - -#define cutItem(in, out, sep, num) cutItemString(in, out, sep, num, sizeof(out)) - -void cutItemString(char *in, char *out, char sep, int num, size_t maxout); -int cutItemToInt(char *in, char sep, int num); - -#endif /* MPLAYER_GUI_CUT_H */
--- a/gui/skin/font.c Sun Mar 27 21:25:58 2011 +0000 +++ b/gui/skin/font.c Mon Mar 28 12:37:48 2011 +0000 @@ -22,8 +22,8 @@ #include <string.h> #include "font.h" -#include "cut.h" #include "gui/interface.h" +#include "gui/util/cut.h" #include "skin.h" #include "libavutil/avstring.h"
--- a/gui/skin/font.h Sun Mar 27 21:25:58 2011 +0000 +++ b/gui/skin/font.h Mon Mar 28 12:37:48 2011 +0000 @@ -20,7 +20,7 @@ #define MPLAYER_GUI_FONT_H #include "gui/app.h" -#include "gui/bitmap.h" +#include "gui/util/bitmap.h" #define ASCII_CHRS 128 // number of ASCII characters #define EXTRA_CHRS 128 // (arbitrary) number of non-ASCII characters
--- a/gui/skin/skin.c Sun Mar 27 21:25:58 2011 +0000 +++ b/gui/skin/skin.c Mon Mar 28 12:37:48 2011 +0000 @@ -20,11 +20,11 @@ #include <string.h> #include "skin.h" -#include "cut.h" #include "font.h" #include "gui/app.h" #include "gui/interface.h" #include "gui/mplayer/widgets.h" +#include "gui/util/cut.h" #include "config.h" #include "help_mp.h"
--- a/gui/skin/skin.h Sun Mar 27 21:25:58 2011 +0000 +++ b/gui/skin/skin.h Mon Mar 28 12:37:48 2011 +0000 @@ -19,7 +19,7 @@ #ifndef MPLAYER_GUI_SKIN_H #define MPLAYER_GUI_SKIN_H -#include "gui/bitmap.h" +#include "gui/util/bitmap.h" int skinBPRead(char *fname, txSample *bf); int skinRead(char *dname);
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/gui/util/bitmap.c Mon Mar 28 12:37:48 2011 +0000 @@ -0,0 +1,258 @@ +/* + * This file is part of MPlayer. + * + * MPlayer is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * MPlayer is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License along + * with MPlayer; if not, write to the Free Software Foundation, Inc., + * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. + */ + +#include <stdio.h> +#include <stdlib.h> +#include <string.h> + +#include "bitmap.h" + +#include "help_mp.h" +#include "libavcodec/avcodec.h" +#include "libavutil/intreadwrite.h" +#include "libvo/fastmemcpy.h" +#include "mp_msg.h" + +static int pngRead(unsigned char *fname, txSample *bf) +{ + FILE *fp; + int decode_ok; + void *data; + int len; + AVCodecContext *avctx; + AVFrame *frame; + AVPacket pkt; + + fp = fopen(fname, "rb"); + + if (!fp) { + mp_dbg(MSGT_GPLAYER, MSGL_DBG2, "[png] file read error ( %s )\n", fname); + return 1; + } + + fseek(fp, 0, SEEK_END); + len = ftell(fp); + + if (len > 50 * 1024 * 1024) { + fclose(fp); + return 2; + } + + data = av_malloc(len + FF_INPUT_BUFFER_PADDING_SIZE); + + fseek(fp, 0, SEEK_SET); + fread(data, len, 1, fp); + fclose(fp); + + avctx = avcodec_alloc_context(); + frame = avcodec_alloc_frame(); + avcodec_register_all(); + avcodec_open(avctx, avcodec_find_decoder(CODEC_ID_PNG)); + av_init_packet(&pkt); + pkt.data = data; + pkt.size = len; + // HACK: make PNGs decode normally instead of as CorePNG delta frames + pkt.flags = AV_PKT_FLAG_KEY; + avcodec_decode_video2(avctx, frame, &decode_ok, &pkt); + memset(bf, 0, sizeof(*bf)); + + switch (avctx->pix_fmt) { + case PIX_FMT_GRAY8: + bf->BPP = 8; + break; + + case PIX_FMT_GRAY16BE: + bf->BPP = 16; + break; + + case PIX_FMT_RGB24: + bf->BPP = 24; + break; + + case PIX_FMT_BGRA: + case PIX_FMT_ARGB: + bf->BPP = 32; + break; + + default: + bf->BPP = 0; + break; + } + + if (decode_ok && bf->BPP) { + int bpl; + + bf->Width = avctx->width; + bf->Height = avctx->height; + bpl = bf->Width * (bf->BPP / 8); + bf->ImageSize = bpl * bf->Height; + bf->Image = malloc(bf->ImageSize); + memcpy_pic(bf->Image, frame->data[0], bpl, bf->Height, bpl, frame->linesize[0]); + } + + avcodec_close(avctx); + av_freep(&frame); + av_freep(&avctx); + av_freep(&data); + + mp_dbg(MSGT_GPLAYER, MSGL_DBG2, "[png] filename: %s.\n", fname); + mp_dbg(MSGT_GPLAYER, MSGL_DBG2, "[png] size: %lux%lu bits: %u\n", bf->Width, bf->Height, bf->BPP); + mp_dbg(MSGT_GPLAYER, MSGL_DBG2, "[png] imagesize: %lu\n", bf->ImageSize); + + return !(decode_ok && bf->BPP); +} + +static int conv24to32(txSample *bf) +{ + unsigned char *tmpImage; + unsigned int i, c; + + if (bf->BPP == 24) { + tmpImage = bf->Image; + bf->BPP = 32; + bf->ImageSize = bf->Width * bf->Height * 4; + bf->Image = calloc(1, bf->ImageSize); + + if (!bf->Image) { + free(tmpImage); + mp_dbg(MSGT_GPLAYER, MSGL_DBG2, "[bitmap] not enough memory for image\n"); + return 1; + } + + for (c = 0, i = 0; c < bf->ImageSize; c += 4, i += 3) + *(uint32_t *)&bf->Image[c] = AV_RB24(&tmpImage[i]); + + free(tmpImage); + } + + return 0; +} + +static void Normalize(txSample *bf) +{ + int i; + + for (i = 0; i < (int)bf->ImageSize; i += 4) +#if !HAVE_BIGENDIAN + bf->Image[i + 3] = 0; +#else + bf->Image[i] = 0; +#endif +} + +static unsigned char *fExist(unsigned char *fname) +{ + static unsigned char tmp[512]; + FILE *fl; + unsigned char ext[][6] = { ".png\0", ".PNG\0" }; + int i; + + fl = fopen(fname, "rb"); + + if (fl != NULL) { + fclose(fl); + return fname; + } + + for (i = 0; i < 2; i++) { + snprintf(tmp, sizeof(tmp), "%s%s", fname, ext[i]); + fl = fopen(tmp, "rb"); + + if (fl != NULL) { + fclose(fl); + return tmp; + } + } + + return NULL; +} + +int bpRead(char *fname, txSample *bf) +{ + fname = fExist(fname); + + if (fname == NULL) + return -2; + + if (pngRead(fname, bf)) { + mp_dbg(MSGT_GPLAYER, MSGL_FATAL, "[bitmap] unknown file type ( %s )\n", fname); + return -5; + } + + if (bf->BPP < 24) { + mp_dbg(MSGT_GPLAYER, MSGL_DBG2, "[bitmap] Sorry, only 24 and 32 bpp bitmaps are supported.\n"); + return -1; + } + + if (conv24to32(bf)) + return -8; + + Normalize(bf); + return 0; +} + +void bpFree(txSample *bf) +{ + free(bf->Image); + memset(bf, 0, sizeof(*bf)); +} + +void Convert32to1(txSample *in, txSample *out, int adaptivlimit) +{ + out->Width = in->Width; + out->Height = in->Height; + out->BPP = 1; + out->ImageSize = (out->Width * out->Height + 7) / 8; + + mp_dbg(MSGT_GPLAYER, MSGL_DBG2, "[c32to1] imagesize: %lu\n", out->ImageSize); + + out->Image = calloc(1, out->ImageSize); + + if (out->Image == NULL) + mp_msg(MSGT_GPLAYER, MSGL_WARN, MSGTR_NotEnoughMemoryC32To1); + { + int i, b, c = 0; + unsigned int *buf = NULL; + unsigned char tmp = 0; + int nothaveshape = 1; + + buf = (unsigned int *)in->Image; + + for (b = 0, i = 0; i < (int)(out->Width * out->Height); i++) { + if ((int)buf[i] != adaptivlimit) + tmp = (tmp >> 1) | 128; + else { + tmp = tmp >> 1; + buf[i] = nothaveshape = 0; + } + + if (b++ == 7) { + out->Image[c++] = tmp; + tmp = b = 0; + } + } + + if (b) + out->Image[c] = tmp; + + if (nothaveshape) { + free(out->Image); + out->Image = NULL; + } + } +}
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/gui/util/bitmap.h Mon Mar 28 12:37:48 2011 +0000 @@ -0,0 +1,34 @@ +/* + * This file is part of MPlayer. + * + * MPlayer is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * MPlayer is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License along + * with MPlayer; if not, write to the Free Software Foundation, Inc., + * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. + */ + +#ifndef MPLAYER_GUI_BITMAP_H +#define MPLAYER_GUI_BITMAP_H + +typedef struct { + unsigned long Width; + unsigned long Height; + unsigned int BPP; + unsigned long ImageSize; + char *Image; +} txSample; + +void bpFree(txSample *bf); +int bpRead(char *fname, txSample *bf); +void Convert32to1(txSample *in, txSample *out, int adaptivlimit); + +#endif /* MPLAYER_GUI_BITMAP_H */
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/gui/util/cut.c Mon Mar 28 12:37:48 2011 +0000 @@ -0,0 +1,48 @@ +/* + * This file is part of MPlayer. + * + * MPlayer is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * MPlayer is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License along + * with MPlayer; if not, write to the Free Software Foundation, Inc., + * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. + */ + +#include <stdlib.h> +#include <string.h> + +#include "cut.h" + +void cutItemString(char *in, char *out, char sep, int num, size_t maxout) +{ + int n; + unsigned int i, c; + + for (c = 0, n = 0, i = 0; in[i]; i++) { + if (in[i] == sep) + n++; + if (n >= num && in[i] != sep && c + 1 < maxout) + out[c++] = in[i]; + if (n >= num && in[i + 1] == sep) + break; + } + + if (c < maxout) + out[c] = 0; +} + +int cutItemToInt(char *in, char sep, int num) +{ + char tmp[64]; + + cutItem(in, tmp, sep, num); + return atoi(tmp); +}
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/gui/util/cut.h Mon Mar 28 12:37:48 2011 +0000 @@ -0,0 +1,29 @@ +/* + * This file is part of MPlayer. + * + * MPlayer is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * MPlayer is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License along + * with MPlayer; if not, write to the Free Software Foundation, Inc., + * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. + */ + +#ifndef MPLAYER_GUI_CUT_H +#define MPLAYER_GUI_CUT_H + +#include <stddef.h> + +#define cutItem(in, out, sep, num) cutItemString(in, out, sep, num, sizeof(out)) + +void cutItemString(char *in, char *out, char sep, int num, size_t maxout); +int cutItemToInt(char *in, char sep, int num); + +#endif /* MPLAYER_GUI_CUT_H */