Mercurial > hg > dmlib
comparison tools/libgfx.c @ 1616:36d073c45327
Refactor the format handling a bit.
author | Matti Hamalainen <ccr@tnsp.org> |
---|---|
date | Tue, 15 May 2018 14:29:32 +0300 |
parents | 2f8f2f7a42c8 |
children | 4c96181c9c09 |
comparison
equal
deleted
inserted
replaced
1615:2f8f2f7a42c8 | 1616:36d073c45327 |
---|---|
1986 | 1986 |
1987 | 1987 |
1988 // | 1988 // |
1989 // List of formats | 1989 // List of formats |
1990 // | 1990 // |
1991 DMImageFormat dmImageFormatList[DM_IMGFMT_LAST] = | 1991 const DMImageFormat dmImageFormatList[] = |
1992 { | 1992 { |
1993 { | 1993 #ifdef DM_USE_LIBPNG |
1994 "PNG", "Portable Network Graphics", | 1994 { |
1995 "png", "Portable Network Graphics", | |
1996 DM_IMGFMT_PNG, DM_FMT_RDWR, | |
1995 fmtProbePNG, | 1997 fmtProbePNG, |
1996 #ifdef DM_USE_LIBPNG | |
1997 dmReadPNGImage, dmReadPNGImageFILE, | 1998 dmReadPNGImage, dmReadPNGImageFILE, |
1998 dmWritePNGImage, dmWritePNGImageFILE, | 1999 dmWritePNGImage, dmWritePNGImageFILE, |
1999 #else | 2000 }, |
2000 NULL, NULL, | |
2001 NULL, NULL, | |
2002 #endif | 2001 #endif |
2003 }, | 2002 { |
2004 { | 2003 "ppm", "Portable PixMap", |
2005 "PPM", "Portable PixMap", | 2004 DM_IMGFMT_PPM, DM_FMT_WR, |
2006 NULL, | 2005 NULL, |
2007 NULL, NULL, | 2006 NULL, NULL, |
2008 dmWritePPMImage, dmWritePPMImageFILE, | 2007 dmWritePPMImage, dmWritePPMImageFILE, |
2009 }, | 2008 }, |
2010 { | 2009 { |
2011 "PCX", "Z-Soft Paintbrush", | 2010 "pcx", "Z-Soft Paintbrush", |
2011 DM_IMGFMT_PCX, DM_FMT_RDWR, | |
2012 fmtProbePCX, | 2012 fmtProbePCX, |
2013 dmReadPCXImage, dmReadPCXImageFILE, | 2013 dmReadPCXImage, dmReadPCXImageFILE, |
2014 dmWritePCXImage, dmWritePCXImageFILE, | 2014 dmWritePCXImage, dmWritePCXImageFILE, |
2015 }, | 2015 }, |
2016 { | 2016 { |
2017 "ILBM", "IFF ILBM", | 2017 "lbm", "IFF ILBM / PBM", |
2018 DM_IMGFMT_ILBM, DM_FMT_RD, | |
2018 fmtProbeILBM, | 2019 fmtProbeILBM, |
2019 dmReadILBMImage, dmReadILBMImageFILE, | 2020 dmReadILBMImage, dmReadILBMImageFILE, |
2020 NULL, NULL, | 2021 NULL, NULL, |
2021 }, | 2022 }, |
2022 { | 2023 { |
2023 "RAW", "Plain bitplaned (planar or non-planar) RAW", | 2024 "raw", "Plain bitplaned (planar or non-planar) RAW", |
2025 DM_IMGFMT_RAW, DM_FMT_WR, | |
2024 NULL, | 2026 NULL, |
2025 NULL, NULL, | 2027 NULL, NULL, |
2026 dmWriteRAWImage, dmWriteRAWImageFILE, | 2028 dmWriteRAWImage, dmWriteRAWImageFILE, |
2027 }, | 2029 }, |
2028 { | 2030 { |
2029 "ARAW", "IFFMaster Amiga RAW", | 2031 "araw", "IFFMaster Amiga RAW", |
2032 DM_IMGFMT_ARAW, DM_FMT_WR, | |
2030 NULL, | 2033 NULL, |
2031 NULL, NULL, | 2034 NULL, NULL, |
2032 dmWriteRAWImage, dmWriteRAWImageFILE, | 2035 dmWriteRAWImage, dmWriteRAWImageFILE, |
2033 } | 2036 } |
2034 }; | 2037 }; |
2035 | 2038 |
2036 | 2039 const int ndmImageFormatList = sizeof(dmImageFormatList) / sizeof(dmImageFormatList[0]); |
2037 int dmImageProbeGeneric(const Uint8 *buf, const size_t len, DMImageFormat **pfmt, int *index) | 2040 |
2038 { | 2041 |
2039 int i, scoreMax = DM_PROBE_SCORE_FALSE, scoreIndex = -1; | 2042 int dmImageProbeGeneric(const Uint8 *buf, const size_t len, const DMImageFormat **pfmt, int *index) |
2040 | 2043 { |
2041 for (i = 0; i < DM_IMGFMT_LAST; i++) | 2044 int scoreMax = DM_PROBE_SCORE_FALSE, scoreIndex = -1; |
2042 { | 2045 |
2043 DMImageFormat *fmt = &dmImageFormatList[i]; | 2046 for (int i = 0; i < ndmImageFormatList; i++) |
2047 { | |
2048 const DMImageFormat *fmt = &dmImageFormatList[i]; | |
2044 if (fmt->probe != NULL) | 2049 if (fmt->probe != NULL) |
2045 { | 2050 { |
2046 int score = fmt->probe(buf, len); | 2051 int score = fmt->probe(buf, len); |
2047 if (score > scoreMax) | 2052 if (score > scoreMax) |
2048 { | 2053 { |