From 9305909c2a7fb39b264cdec01df762323f46ccc0 Mon Sep 17 00:00:00 2001 From: Dagen Brock Date: Sun, 3 May 2020 16:31:13 -0500 Subject: [PATCH 1/3] Multiplatform CICD --- .github/workflows/release.yml | 114 ++++++++++++++++++++++++++++++++++ README.md | 18 ++++++ src/b2d.c | 44 ++++++------- src/b2d.h | 27 ++++---- 4 files changed, 169 insertions(+), 34 deletions(-) create mode 100644 .github/workflows/release.yml diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml new file mode 100644 index 0000000..227cdbd --- /dev/null +++ b/.github/workflows/release.yml @@ -0,0 +1,114 @@ +name: Release Builds +on: push +env: + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} + +jobs: + build-and-store-artifact: + name: Build + runs-on: ${{ matrix.os }} + strategy: + matrix: + os: [ ubuntu-latest, macos-latest, windows-latest ] + steps: + - uses: actions/checkout@v1 + - uses: ilammy/msvc-dev-cmd@v1 + - name: Make GNU + if: matrix.os != 'windows-latest' + working-directory: ./src + run: make + shell: bash + - name: Make Windows + if: matrix.os == 'windows-latest' + working-directory: ./src + run: nmake + - name: Test + run: cd tests ; ./test.sh + - name: Upload binary artifact + if: matrix.os != 'windows-latest' + uses: actions/upload-artifact@v2 + with: + name: ${{ format('binary-{0}', matrix.os) }} + path: b2d + - name: Upload binary artifact exe + if: matrix.os == 'windows-latest' + uses: actions/upload-artifact@v2 + with: + name: ${{ format('binary-{0}', matrix.os) }} + path: b2d.exe + + create-release: + if: startsWith(github.ref, 'refs/tags/v') + name: Create Release + needs: build-and-store-artifact + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v1 + - name: Create Release + id: create_release + uses: actions/create-release@v1.0.0 + env: + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} + with: + tag_name: ${{ github.ref }} + release_name: Release ${{ github.ref }} + draft: false + prerelease: false + - name: Debug dump + env: + UPLOAD_URL: ${{ toJson( steps.create_release.outputs.upload_url )}} + run: | + echo "$UPLOAD_URL" > release_url.txt + echo "UPLOAD_URL= $UPLOAD_URL" + - name: Upload URL for later use + uses: actions/upload-artifact@v2 + with: + name: data + path: release_url.txt + + package-and-upload: + name: Package and Upload + needs: create-release + runs-on: ${{ matrix.os }} + strategy: + matrix: + os: [ ubuntu-latest, macos-latest, windows-latest ] + + steps: + - uses: actions/checkout@v1 + - name: Download Release Data + uses: actions/download-artifact@v1 + with: + name: data + - name: Get Tag Name + id: get_data + shell: bash + run: | + URL=`cat data/release_url.txt | tr -d '"'` + echo ::set-output name=SOURCE_TAG::${GITHUB_REF#refs/tags/} + echo ::set-output name=RELEASE_URL::$URL + echo "URL = $URL" + echo name=SOURCE_TAG::${GITHUB_REF#refs/tags/} + - name: Download Release Binary + uses: actions/download-artifact@v1 + with: + name: ${{ format('binary-{0}', matrix.os) }} + + - name: Package NIX + if: matrix.os != 'windows-latest' + run: | + zip --junk-paths b2d.zip ${{ format('binary-{0}/b2d', matrix.os) }} README.md + - name: Package WIN + if: matrix.os == 'windows-latest' + run: | + 7z.exe a b2d.zip ${{ format('./binary-{0}/b2d.exe', matrix.os) }} README.md + - name: Upload Release Asset + id: upload-release-asset + uses: actions/upload-release-asset@v1.0.1 + env: + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} + with: + upload_url: ${{ steps.get_data.outputs.RELEASE_URL }} + asset_path: ./b2d.zip + asset_name: ${{ format('b2d-{0}-{1}.zip', matrix.os, steps.get_data.outputs.SOURCE_TAG ) }} + asset_content_type: application/zip diff --git a/README.md b/README.md index a2066fd..6b7f56f 100644 --- a/README.md +++ b/README.md @@ -4,7 +4,25 @@ The b2d project provides modern builds of versions of bmp2dhr, a utility for con # Releases - see the releases page +# Usage + +The `b2d` command will show a small amount of help upon execution without any arguments. + +Here's an example of converting a BMP to a LoRes Apple II screen: + +`b2d myimage.bmp L N` + +The `L` is for LoRes output, and the `N` specifies to not include any header, just the raw image data. + # About b2d project is by Dagen Brock Bmp2DHR version 1.0 and 1.1 were publically released by Bill Buckels in 2014 and 2015 respectively. All rights reserved. See archival directory for more information. + +## Changelog +``` +1.3 - Initial b2d project release + - Add no header option + - Bugfixes + - Cross-platform fixes and CICD work for new builds +``` diff --git a/src/b2d.c b/src/b2d.c index b468708..0549806 100644 --- a/src/b2d.c +++ b/src/b2d.c @@ -1581,20 +1581,20 @@ ushort WriteVbmpHeader(FILE *fp) { memset((char *)&mybmp.bfi.bfType[0], 0, sizeof(BMPHEADER)); /* create the info header */ - mybmp.bmi.biSize = (ulong)40; - mybmp.bmi.biWidth = (ulong)140; - mybmp.bmi.biHeight = (ulong)192; + mybmp.bmi.biSize = (uLong)40; + mybmp.bmi.biWidth = (uLong)140; + mybmp.bmi.biHeight = (uLong)192; mybmp.bmi.biPlanes = 1; mybmp.bmi.biBitCount = 4; - mybmp.bmi.biCompression = (ulong)BI_RGB; + mybmp.bmi.biCompression = (uLong)BI_RGB; - mybmp.bmi.biSizeImage = (ulong)outpacket; + mybmp.bmi.biSizeImage = (uLong)outpacket; mybmp.bmi.biSizeImage *= mybmp.bmi.biHeight; /* create the file header */ mybmp.bfi.bfType[0] = 'B'; mybmp.bfi.bfType[1] = 'M'; - mybmp.bfi.bfOffBits = (ulong)sizeof(BMPHEADER) + sizeof(RGBQUAD) * 16; + mybmp.bfi.bfOffBits = (uLong)sizeof(BMPHEADER) + sizeof(RGBQUAD) * 16; mybmp.bfi.bfSize = mybmp.bmi.biSizeImage + mybmp.bfi.bfOffBits; /* write the header for the output BMP */ @@ -2583,7 +2583,7 @@ int savesprite() { /* read and remap a mask line from an open mask file */ /* required by dithered and non-dithered routines when in use */ sshort ReadMaskLine(ushort y) { - ulong pos; + uLong pos; ushort x, packet; uchar ch; @@ -2600,7 +2600,7 @@ sshort ReadMaskLine(ushort y) { } else packet = 140; - pos = (ulong)(191 - y); + pos = (uLong)(191 - y); pos *= packet; pos += maskbmp.bfi.bfOffBits; @@ -3661,24 +3661,24 @@ ushort WriteDIBHeader(FILE *fp, ushort pixels, ushort rasters) { memset((char *)&mybmp.bfi.bfType[0], 0, sizeof(BMPHEADER)); /* create the info header */ - mybmp.bmi.biSize = (ulong)sizeof(BITMAPINFOHEADER); - mybmp.bmi.biWidth = (ulong)pixels; - mybmp.bmi.biHeight = (ulong)rasters; + mybmp.bmi.biSize = (uLong)sizeof(BITMAPINFOHEADER); + mybmp.bmi.biWidth = (uLong)pixels; + mybmp.bmi.biHeight = (uLong)rasters; mybmp.bmi.biPlanes = 1; mybmp.bmi.biBitCount = 24; - mybmp.bmi.biCompression = (ulong)BI_RGB; + mybmp.bmi.biCompression = (uLong)BI_RGB; /* BMP scanlines are padded to a multiple of 4 bytes (DWORD) */ outpacket = (ushort)mybmp.bmi.biWidth * 3; while (outpacket % 4 != 0) outpacket++; - mybmp.bmi.biSizeImage = (ulong)outpacket; + mybmp.bmi.biSizeImage = (uLong)outpacket; mybmp.bmi.biSizeImage *= mybmp.bmi.biHeight; /* create the file header */ mybmp.bfi.bfType[0] = 'B'; mybmp.bfi.bfType[1] = 'M'; - mybmp.bfi.bfOffBits = (ulong)sizeof(BMPHEADER); + mybmp.bfi.bfOffBits = (uLong)sizeof(BMPHEADER); mybmp.bfi.bfSize = mybmp.bmi.biSizeImage + mybmp.bfi.bfOffBits; /* write the header for the output BMP */ @@ -4107,7 +4107,7 @@ FILE *ResizeBMP(FILE *fp, sshort resize) { FILE *fp2; ushort x, y, packet, outpacket, chunks; ushort i, j, r, g, b; - ulong offset = 0L; + uLong offset = 0L; #ifdef TURBOC if (resize == 0) @@ -4875,7 +4875,7 @@ sshort Convert() { ushort x, x1, x2, y, yoff, i, packet, outpacket, width, dwidth, red, green, blue; uchar r, g, b, drawcolor; - ulong pos, prepos; + uLong pos, prepos; /* if using a mask file, open it now */ /* leave it open throughout the conversion session */ @@ -4897,7 +4897,7 @@ sshort Convert() { printf("sizeof(uchar): %lu\n", sizeof(uchar)); printf("sizeof(ushort): %lu\n", sizeof(ushort)); - printf("sizeof(ulong): %lu\n", sizeof(ulong)); + printf("sizeof(uLong): %lu\n", sizeof(uLong)); printf("sizeof(sshort): %lu\n", sizeof(sshort)); #endif @@ -5043,7 +5043,7 @@ sshort Convert() { for (y = 0; y < bmpheight; y++) fwrite((char *)&dibscanline1[0], 1, outpacket, fpreview); /* set the seek distance to scanline 0 in the preview file */ - prepos = (ulong)(bmpheight - 1); + prepos = (uLong)(bmpheight - 1); prepos *= outpacket; prepos += mybmp.bfi.bfOffBits; } @@ -5055,7 +5055,7 @@ sshort Convert() { } /* read BMP from top scanline to bottom scanline */ - pos = (ulong)(bmpheight - 1); + pos = (uLong)(bmpheight - 1); pos *= packet; pos += bfi.bfOffBits; @@ -5292,7 +5292,7 @@ sshort ConvertMono() { FILE *fp, *fpreview; sshort status = INVALID; ushort x, y, i, packet, outpacket, red, green, blue, verbatim; - ulong pos, prepos; + uLong pos, prepos; if ((fp = fopen(bmpfile, "rb")) == NULL) { printf("Error Opening %s for reading!\n", bmpfile); @@ -5381,7 +5381,7 @@ sshort ConvertMono() { for (y = 0; y < bmpheight; y++) fwrite((char *)&dibscanline1[0], 1, outpacket, fpreview); /* set the seek distance to scanline 0 in the preview file */ - prepos = (ulong)(bmpheight - 1); + prepos = (uLong)(bmpheight - 1); prepos *= outpacket; prepos += mybmp.bfi.bfOffBits; } @@ -5393,7 +5393,7 @@ sshort ConvertMono() { } /* read BMP from top scanline to bottom scanline */ - pos = (ulong)(bmpheight - 1); + pos = (uLong)(bmpheight - 1); pos *= packet; pos += bfi.bfOffBits; diff --git a/src/b2d.h b/src/b2d.h index aede4c3..36d3e48 100644 --- a/src/b2d.h +++ b/src/b2d.h @@ -36,6 +36,9 @@ /* ***************************************************************** */ #include "tomthumb.h" +#ifdef __linux__ +#include +#endif /* ***************************************************************** */ /* ========================== defines ============================== */ @@ -112,7 +115,7 @@ typedef unsigned char uchar; typedef unsigned short ushort; -typedef unsigned int ulong; +typedef unsigned int uLong; typedef short sshort; /* Bitmap Header structures */ @@ -124,17 +127,17 @@ typedef struct tagBITMAPINFOHEADER {} #endif { - ulong biSize; - ulong biWidth; - ulong biHeight; + uLong biSize; + uLong biWidth; + uLong biHeight; ushort biPlanes; ushort biBitCount; - ulong biCompression; - ulong biSizeImage; - ulong biXPelsPerMeter; - ulong biYPelsPerMeter; - ulong biClrUsed; - ulong biClrImportant; + uLong biCompression; + uLong biSizeImage; + uLong biXPelsPerMeter; + uLong biYPelsPerMeter; + uLong biClrUsed; + uLong biClrImportant; } BITMAPINFOHEADER; #ifdef MINGW @@ -144,10 +147,10 @@ typedef struct tagBITMAPFILEHEADER #endif { uchar bfType[2]; - ulong bfSize; + uLong bfSize; ushort bfReserved1; ushort bfReserved2; - ulong bfOffBits; + uLong bfOffBits; } BITMAPFILEHEADER; #ifdef MINGW From a00c62d2a1d31e026c6ff4a5bd2d6e4f696d35ba Mon Sep 17 00:00:00 2001 From: Dagen Brock Date: Mon, 8 Jun 2020 21:50:22 -0500 Subject: [PATCH 2/3] remove uppercase code --- src/b2d.c | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/src/b2d.c b/src/b2d.c index 0549806..331a2f7 100644 --- a/src/b2d.c +++ b/src/b2d.c @@ -6740,11 +6740,15 @@ int main(int argc, char **argv) { /* user titling file */ sprintf(usertextfile, "%s.txt", fname); + /* This breaks pathing on Linux which is case sensitive */ + /* Maybe rewrite to not change case of the entire path */ +#if 0 /* upper case basename for Apple II Output */ for (idx = 0; fname[idx] != (uchar)0; idx++) { ch = toupper(fname[idx]); fname[idx] = ch; } +#endif strcpy(hgrwork, fname); if (basename == 1) { From 0363868a669dd9be2e93034b328998be398c2c85 Mon Sep 17 00:00:00 2001 From: Dagen Brock Date: Mon, 8 Jun 2020 22:21:12 -0500 Subject: [PATCH 3/3] only uppercase new filename, not path --- src/b2d.c | 28 +++++++++++++++++----------- tests/test.sh | 2 ++ 2 files changed, 19 insertions(+), 11 deletions(-) diff --git a/src/b2d.c b/src/b2d.c index 331a2f7..d963b86 100644 --- a/src/b2d.c +++ b/src/b2d.c @@ -2027,7 +2027,6 @@ int savelofragment() { /* save single lo-res and double lo-res */ /* save raster images of 48 or 40 scanlines (full graphics or mixed text and graphics) */ - if (lores == 1) { if (appletop == 1) { fl = 802; @@ -3511,13 +3510,13 @@ void FloydSteinberg(int y, int width) { * 2 1 1 2 1 1 (1/8) - + Serpentine - + 1 2 * 1 2 1 1 - + */ /* if error summing is turned-on add the accumulated rounding error @@ -6740,15 +6739,22 @@ int main(int argc, char **argv) { /* user titling file */ sprintf(usertextfile, "%s.txt", fname); - /* This breaks pathing on Linux which is case sensitive */ - /* Maybe rewrite to not change case of the entire path */ -#if 0 /* upper case basename for Apple II Output */ - for (idx = 0; fname[idx] != (uchar)0; idx++) { - ch = toupper(fname[idx]); - fname[idx] = ch; + // get filename part so we only upper case that + char *filename = strrchr(fname, '/'); + // no slash found so use full string + if (!filename) { + filename = fname; + } else { + filename++; // advance pointer past '/' } -#endif + // now upper part/full string + for (idx = 0; filename[idx] != (uchar)0; idx++) { + ch = toupper(filename[idx]); + filename[idx] = ch; + } + + strcpy(hgrwork, fname); if (basename == 1) { diff --git a/tests/test.sh b/tests/test.sh index 3ac1c95..b543e23 100755 --- a/tests/test.sh +++ b/tests/test.sh @@ -4,7 +4,9 @@ echo " --- Super High-Tech Test Suite v0.1234zaxxon ---" ##################################### # LORES echo "LORES TEST START" +echo " - RUN: '$B2D black-40x48.bmp L N'" $B2D black-40x48.bmp L N +echo " - RUN: '$B2D white-40x48.bmp L N'" $B2D white-40x48.bmp L N diff BLACK-40X48.SLO BLACK.LORES