コミットを比較

...

38 コミット

作成者 SHA1 メッセージ 日付
守矢諏訪子 8be542138b NetBSD向けのステップの変更 2024-05-26 01:15:16 +09:00
守矢諏訪子 16a4156eba NetBSDで靜的リンクを可能に 2024-05-26 01:59:40 +09:00
守矢諏訪子 ff9e0ffa8b . 2024-05-26 00:39:57 +09:00
守矢諏訪子 f9a6ec1c1a 画像をダウンロード機能性 2024-05-24 19:27:56 +09:00
守矢諏訪子 722a860058 色々 2024-05-24 18:33:56 +09:00
守矢諏訪子 a900de4bea 回転:ウィンドウサイズの変更バグの修正 2024-05-24 17:50:54 +09:00
守矢諏訪子 9a7c112f50 必要はディレクトリが存在しない場合(得にNetBSDの問題) 2024-05-22 21:54:09 +09:00
守矢諏訪子 ed94a611e0 画像反転機能性の追加 2024-05-22 21:51:59 +09:00
守矢諏訪子 c734c97210 殆ど直した 2024-05-22 21:24:19 +09:00
守矢諏訪子 992bf65b2a 今まで気づきなかったバグの修正 2024-05-22 21:07:19 +09:00
守矢諏訪子 f206950ae8 再レンダーリングの問題の修正 + 画像回転機能性の追加 2024-05-22 19:10:54 +09:00
守矢諏訪子 4593e6e081 manpageでコントロールの説明の追加 2024-05-22 18:41:01 +09:00
守矢諏訪子 ffc06022ba MakefileとREADME.mdファイルの更新 + NetBSDは「/usr/pkg」→「/usr/local」 + スペルミスの修正 2024-05-04 01:08:05 +09:00
守矢諏訪子 f103d1a815 manpageの追加 2024-05-03 21:40:31 +09:00
守矢諏訪子 631df55822 それで良いかもしん 2024-05-03 16:52:08 +09:00
守矢諏訪子 76f5feb068 . 2024-05-03 15:56:09 +09:00
守矢諏訪子 737d19b9e3 出来るだけポーツツリーを使った方が良い 2024-05-03 15:23:22 +09:00
守矢諏訪子 69c3f95935 OpenBSDで靜的リンクを可能に 2024-05-03 03:40:37 +09:00
守矢諏訪子 dd6b43314d ごめん 2024-05-03 02:41:59 +09:00
守矢諏訪子 b708890310 . 2024-05-03 00:45:39 +09:00
守矢諏訪子 e6bc2ca9af Merge pull request 'マウスでの移動' (#15) from mousemove into master
Reviewed-on: #15
2024-05-03 00:41:34 +09:00
守矢諏訪子 53aa5817ab マウスで使って画像を移動出来る様に 2024-05-03 00:40:48 +09:00
守矢諏訪子 cb6a765e8f Merge branch 'master' of gitler.moe:suwako/mivfx into mousemove 2024-05-02 22:37:00 +09:00
守矢諏訪子 8c0d4ecc84 Merge pull request 'ズーム' (#14) from zoomin into master
Reviewed-on: #14
2024-05-02 22:34:30 +09:00
守矢諏訪子 a952724296 ズームはうまく出来る様にした。そうして、ズームイン限定を消した 2024-05-02 22:33:34 +09:00
守矢諏訪子 f79a52ed85 Merge branch 'master' of gitler.moe:suwako/mivfx into zoomin 2024-05-02 21:46:22 +09:00
守矢諏訪子 047bcda708 それは必要はない 2024-05-02 21:46:08 +09:00
守矢諏訪子 681692740f Merge branch 'master' of gitler.moe:suwako/mivfx into zoomin 2024-05-02 21:45:09 +09:00
守矢諏訪子 6345979d2e マウスでの移動 2024-05-02 20:21:50 +09:00
守矢諏訪子 873f5487ac Pixivからダウンロード出来る様に 2024-05-02 20:09:45 +09:00
守矢諏訪子 9bd753c5d4 ズーム 2024-05-02 19:58:42 +09:00
守矢諏訪子 e95a36b778 サイズ変更の修正 2024-05-02 19:42:10 +09:00
守矢諏訪子 4255b2f172 「Q」キーを押すと、終了する様に 2024-05-02 19:04:11 +09:00
守矢諏訪子 a9a192b9fe 画像は大き過ぎるの場合、画面に合うまで小さくにする様に 2024-05-02 19:00:38 +09:00
守矢諏訪子 3bb0f66e0b ごめん 2024-05-02 18:36:43 +09:00
守矢諏訪子 5e430a59c6 Clownflareは面倒くさいわね・・・ 2024-05-02 18:35:03 +09:00
守矢諏訪子 372d077a49 .desktopファイルの追加 2024-04-25 20:44:14 +09:00
守矢諏訪子 9fc7c4a506 BSD→ISC 2024-04-10 14:13:15 +09:00
10個のファイルの変更578行の追加84行の削除

4
.gitignore vendored
ファイルの表示

@ -1,3 +1,3 @@
mivfx
.ccls-cache
*.tar.gz
release
*.core

ファイルの表示

@ -1,3 +1,24 @@
# 0.6.0
* MakefileとREADME.mdファイルの更新
* NetBSDは「/usr/pkg」→「/usr/local」
* スペルミスの修正
* manpageでコントロールの説明の追加
* 再レンダーリングの問題の修正
* 画像回転機能性の追加
* 画像反転機能性の追加
* 画像をダウンロード機能性
# 0.5.0
* .desktopファイルの追加
* CDNを回避する様に
* 画像は大き過ぎるの場合、画面に合うまで小さくにする様に
* 「Q」キーを押すと、終了する様に
* サイズ変更の修正
* Pixivからダウンロード出来る様に
* ズーム機能性の追加
* マウスで使って画像を移動出来る様に
* OpenBSDで靜的リンクを可能に
# 0.4.0
* URLから画像ファイルを開ける様に
* GPLv2→BSD2clouseライセンスに変更

ファイルの表示

@ -1,11 +1,14 @@
BSD 2-Clause License
Copyright © 2004-2011 by Internet Systems Consortium, Inc. ("ISC")
Copyright © 2018-2024 by 076.moe
Copyright 2024 テクニカル諏訪子
Permission to use, copy, modify, and/or distribute this software for any
purpose with or without fee is hereby granted, provided that the above
copyright notice and this permission notice appear in all copies.
Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met:
1. Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer.
2. Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution.
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS “AS IS” AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
THE SOFTWARE IS PROVIDED "AS IS" AND ISC DISCLAIMS ALL WARRANTIES WITH REGARD
TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND
FITNESS. IN NO EVENT SHALL ISC BE LIABLE FOR ANY SPECIAL, DIRECT, INDIRECT, OR
CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE,
DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS
ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS
SOFTWARE.

20
MISSING-STATIC-NETBSD.md ノーマルファイル
ファイルの表示

@ -0,0 +1,20 @@
gaylandを静的リンクする事が無理ですので、
SDL2からgayland対応を取り消す事が必要になります。
# libSDL2
```
doas su
cd /usr
odl https://ftp.netbsd.org/pub/pkgsrc/stable/pkgsrc.tar.gz
tar zxfv pkgsrc.tar.gz
cd pkgsrc/bootstrap
./bootstrap
cd ../devel
rm -rf SDL2
odl https://076.moe/repo/3rdparty/src/netbsd-SDL2-no-gayland.tar.gz
tar zxfv netbsd-SDL2-no-gayland.tar.gz
rm -rf netbsd-SDL2-no-gayland.tar.gz
cd SDL2
make
make install
```

109
MISSING-STATIC-OPENBSD.md ノーマルファイル
ファイルの表示

@ -0,0 +1,109 @@
# 総合
これは静的リンクを要求している方向けです。
動的リンクしている方は下記のステップを実効する事が不要です。
```
$ doas pkg_add cmake ninja tiff libavif gtest highway libjxl curl asciidoc llcms2 giflib brotli png
$ cd /usr
$ doas cvs -d anoncvs@anoncvs.spacehopper.org:/cvs checkout -rOPENBSD_7_5 -P ports
$ doas chown -R $(whoami):$(whoami) /usr/ports
```
## AMD64・X86_64の場合
```
$ ARCH=amd64
$ curl https://076.moe/repo/bin/odl/odl-0.2.0-openbsd-amd64 > /usr/local/bin/odl
```
## PowerPC 32bitの場合
```
$ ARCH=powerpc
$ curl https://076.moe/repo/bin/odl/odl-0.2.0-openbsd-macppc > /usr/local/bin/odl
```
## i386・X86の場合
```
$ ARCH=i386
$ curl https://076.moe/repo/bin/odl/odl-0.2.0-openbsd-i386 > /usr/local/bin/odl
```
---
# libtiff
```
$ odl http://www.libtiff.org/downloads/tiff-4.6.0t.tar.xz
$ bsdtar -xf tiff-4.6.0t.tar.xz
$ cd tiff-4.6.0t
$ ./configure --enable-static
$ make
$ doas make install
```
# libyuv
```
$ mkdir libyuv
$ cd libyuv
$ odl -o libyuv.tar.gz https://chromium.googlesource.com/libyuv/libyuv/+archive/331c361581896292fb46c8c6905e41262b7ca95f.tar.gz
$ bsdtar -xf libyuv.tar.gz
$ cmake -S . -B build -G Ninja -DBUILD_SHARED_LIBS=OFF
$ cmake --build build
$ doas cmake --install build
```
# libavif
```
$ cd /usr/ports/graphics/libavif
$ make clean
$ sed -i 's/libyuv=ON/libyuv=OFF/' Makefile
$ sed -i 's/SHARED/STATIC/' Makefile
$ sed -i '31i\
-DBUILD_SHARED_LIBS=OFF \\
' Makefile
$ make
$ make fake
$ doas cp /usr/ports/pobj/libavif-0.11.1/fake-${ARCH}/usr/local/lib/libavif.a /usr/local/lib
```
# libgtest
```
$ doas chown -R $(whoami):$(whoami) /usr/ports
$ cd /usr/ports/devel/gtest
$ make clean
$ sed -i 's/SHARED_LIBS/STATIC_LIBS/g' Makefile
$ sed -i 's/STATIC_LIBS=ON/SHARED_LIBS=OFF/' Makefile
$ sed -i 's/gtest_build_tests=ON/gtest_build_tests=OFF/' Makefile
$ make
$ make fake
$ doas cp /usr/ports/pobj/gtest-1.14.0/fake-${ARCH}/usr/local/lib/*.a /usr/local/lib
```
# libhwy
```
$ doas chown -R $(whoami):$(whoami) /usr/ports
$ cd /usr/ports/devel/highway
$ make clean
$ sed -i 's/SHARED_LIBS/STATIC_LIBS/g' Makefile
$ sed -i 's/STATIC_LIBS=ON/SHARED_LIBS=OFF/' Makefile
$ make
$ make fake
$ doas cp /usr/ports/pobj/highway-1.1.0/fake-${ARCH}/usr/local/lib/*.a /usr/local/lib
```
# libjxl
```
$ doas chown -R $(whoami):$(whoami) /usr/ports
$ cd /usr/ports/graphics/libjxl
$ make clean
$ sed -i 's/SHARED_LIBS/STATIC_LIBS/g' Makefile
$ sed -i 's/-DJPEGXL_FORCE_SYSTEM_GTEST:BOOL=ON/-DJPEGXL_FORCE_SYSTEM_GTEST:BOOL=OFF/' Makefile
$ sed -i '46i\
-DJPEGXL_STATIC=ON \\
' Makefile
$ doas cp /usr/local/lib/libbrotlicommon-static.a /usr/local/lib/libbrotlicommon.a
$ doas cp /usr/local/lib/libbrotlidec-static.a /usr/local/lib/libbrotlidec.a
$ doas cp /usr/local/lib/libbrotlienc-static.a /usr/local/lib/libbrotlienc.a
$ doas make
$ doas chown -R $(whoami):$(whoami) /usr/ports
$ make fake
$ doas cp /usr/ports/pobj/libjxl-0.10.1/fake-${ARCH}/usr/local/lib/*.a /usr/local/lib
```

ファイルの表示

@ -1,33 +1,78 @@
NAME=mivfx
VERSION=0.4.0
# Linux、Haiku、かIllumos = /usr、FreeBSDかOpenBSD = /usr/local、NetBSD = /usr/pkg
UNAME_S!=uname -s
UNAME_M!=uname -m
NAME!=cat main.c | grep "const char \*sofname" | awk '{print $$5}' | \
sed "s/\"//g" | sed "s/;//"
VERSION!=cat main.c | grep "const char \*version" | awk '{print $$5}' | \
sed "s/\"//g" | sed "s/;//"
PREFIX=/usr/local
.if ${UNAME_S} == "Linux"
PREFIX=/usr
.endif
CC=cc
FILES=main.c
CFLAGS=-Wall -Wextra -g
CFLAGS=-Wall -Wextra -g -I/usr/include -I/usr/local/include
LIBS=-lSDL2 -lSDL2_image -lcurl
LDFLAGS=-L${PREFIX}/lib
CPPFLAGS=-I${PREFIX}/include
LDFLAGS=-L/usr/lib -L/usr/local/lib
MANPREFIX=${PREFIX}/share/man
.if ${UNAME_S} == "OpenBSD"
MANPREFIX=${PREFIX}/man
LDFLAGS+=-L/usr/X11R6/lib
CFLAGS+=-I/usr/X11R6/include
.elif ${UNAME_S} == "NetBSD"
LDFLAGS+=-L/usr/X11R7/lib -L/usr/pkg/lib
CFLAGS+=-I/usr/X11R7/include -I/usr/pkg/include
.endif
all:
${CC} ${CFLAGS} ${CPPFLAGS} -o ${NAME} ${FILES} ${LDFLAGS} ${LIBS}
${CC} ${CFLAGS} -o ${NAME} ${FILES} ${LDFLAGS} ${LIBS}
strip ${NAME}
clean:
rm -f ${NAME}
dist: clean
mkdir -p ${NAME}-${VERSION}
cp -R LICENSE.txt Makefile README.md CHANGELOG.md\
*.c ${NAME}-${VERSION}
tar zcfv ${NAME}-${VERSION}.tar.gz ${NAME}-${VERSION}
dist:
mkdir -p ${NAME}-${VERSION} release/src
cp -R LICENSE.txt Makefile *.md ${NAME}.desktop ${NAME}.1 *.c ${NAME}-${VERSION}
tar zcfv release/src/${NAME}-${VERSION}.tar.gz ${NAME}-${VERSION}
rm -rf ${NAME}-${VERSION}
install: all
mkdir -p ${DESTDIR}${PREFIX}/bin
release-openbsd:
mkdir -p release/bin
${CC} ${CFLAGS} -o release/bin/${NAME}-${VERSION}-openbsd-${UNAME_M} ${FILES}\
${LDFLAGS} -static ${LIBS} -lc -lm -liconv -lsndio -lsamplerate -lX11\
-lxcb -lXext -lXcursor -lXrender -lXfixes -lXi -lXrandr -lXss -lusbhid -lpthread\
-ljxl -ljxl_cms -llcms2 -lhwy -lc++ -lc++abi -lbrotlidec\
-lbrotlicommon -lbrotlienc -lyuv -ltiff -lz -ljpeg -llzma -lzstd -lavif\
-ldav1d -laom -lsharpyuv -lwebpdemux -lwebp -lnghttp3 -lngtcp2_crypto_quictls\
-lngtcp2 -lssl -lcrypto -lnghttp2 -lXau -lXdmcp
strip release/bin/${NAME}-${VERSION}-openbsd-${UNAME_M}
release-netbsd:
mkdir -p release/bin
${CC} ${CFLAGS} -o release/bin/${NAME}-${VERSION}-netbsd-${UNAME_M} ${FILES}\
${LDFLAGS} -static ${LIBS} -lc -lm -lossaudio -lX11 -lxcb -lXau -lXdmcp -lgcc\
-lXext -lXcursor -lXrender -lXi -lXfixes -lXrandr -lXss -ldrm -lpci -lgbm -lglapi\
-lstdc++ -lexpat -lusbhid -lusb-1.0 -lpthread -lnghttp2 -lidn2 -lunistring\
-lintl -lgssapi -lkrb5 -lhx509 -lssl -lcrypto -lcrypt -lasn1 -lcom_err -lroken\
-lutil -lwind -lheimbase -lheimntlm -lz
strip release/bin/${NAME}-${VERSION}-netbsd-${UNAME_M}
install:
mkdir -p ${DESTDIR}${PREFIX}/bin\
${DESTDIR}${MANPREFIX}/man1\
${DESTDIR}${PREFIX}/share/applications
cp -f ${NAME} ${DESTDIR}${PREFIX}/bin
sed "s/VERSION/${VERSION}/g" < ${NAME}.1 > ${DESTDIR}${MANPREFIX}/man1/${NAME}.1
cp -f ${NAME}.desktop ${DESTDIR}${PREFIX}/share/applications
chmod 755 ${DESTDIR}${PREFIX}/bin/${NAME}
uninstall:
rm -f ${DESTDIR}${PREFIX}/share/applications/${NAME}.desktop
rm -f ${DESTDIR}${PREFIX}/man1/${NAME}.1
rm -f ${DESTDIR}${PREFIX}/bin/${NAME}
.PHONY: all clean install uninstall

ファイルの表示

@ -1,4 +1,4 @@
# mivfx - minimarist image view for x
# mivfx - minimalist image view for x
ミニマリストな画像ビューアー
# インストールする方法
@ -20,34 +20,34 @@ doas make install
## NetBSD
```sh
doas pkgin install SDL2-2.28.5 SDL2_image curl
make PREFIX=/usr/pkg
doas make install PREFIX=/usr/pkg
make
doas make install
```
## CRUX
```sh
doas prt-get depinst libsdl2 sdl2_image curl
make PREFIX=/usr
doas make install PREFIX=/usr
doas prt-get depinst libsdl2 sdl2_image curl bmake
bmake
doas bmake install
```
## Void Linux
```sh
doas xbps-install -S SDL2 SDL2_image curl
make PREFIX=/usr
doas make install PREFIX=/usr
doas xbps-install -S SDL2 SDL2_image curl bmake
bmake
doas bmake install
```
## Artix Linux
```sh
doas pacman -S sdl2 sdl2_image curl
make PREFIX=/usr
doas make install PREFIX=/usr
doas pacman -S sdl2 sdl2_image curl bmake
bmake
doas bmake install
```
## Devuan GNU/Linux
```sh
doas apt install libsdl2-dev libsdl2-image-dev libcurl4
make PREFIX=/usr
doas make install PREFIX=/usr
doas apt install libsdl2-dev libsdl2-image-dev libcurl4 bmake
bmake
doas bmake install
```

327
main.c
ファイルの表示

@ -3,34 +3,73 @@
#include <stdio.h>
#include <stdbool.h>
#include <curl/curl.h>
#include <string.h>
#include <unistd.h>
#define DELAY_MS 50
SDL_Window* window = NULL;
SDL_Renderer* renderer = NULL;
SDL_Texture* texture = NULL;
SDL_Window *window = NULL;
SDL_Renderer *renderer = NULL;
SDL_Texture *texture = NULL;
bool quit = false;
bool hasdownloaded = false; // DDoSを避ける為
float aspectRatio;
int imgX = 10;
int imgY = 10;
int imgWidth;
int imgHeight;
int screenWidth;
int screenHeight;
int init = 0;
char *imgfilename;
char *imgurl;
SDL_Rect renderQuad;
float newWidth;
float newHeight;
const char* sofname = "mivfx";
const char* version = "0.4.0";
// マウス
int mouseX = 10;
int mouseY = 10;
int drag = 0;
bool dlfile(const char* url, const char* filename) {
CURL* curl = curl_easy_init();
// ズーム
float zoom = 1.0f;
// 回転
float angle = 0.0f;
// 反転
bool flippedH = false;
bool flippedV = false;
const char *sofname = "mivfx";
const char *version = "0.6.0";
bool dlfile(const char *url, const char *filename) {
CURL *curl = curl_easy_init();
if (!curl) {
return false;
}
FILE* file = fopen(filename, "wb");
FILE *file = fopen(filename, "wb");
if (!file) {
return false;
}
curl_easy_setopt(curl, CURLOPT_URL, url);
// Clownflareは面倒くさいわね・・・
curl_easy_setopt(
curl,
CURLOPT_USERAGENT,
"Mozilla/5.0 (Windows NT 10.0; rv:102.0) Gecko/20100101 Firefox/102.0"
);
// Pixivも結構面倒くさい
if (
strstr("s.pximg.net", url) == 0 ||
strstr("i.pximg.net", url) == 0
) {
curl_easy_setopt(curl, CURLOPT_REFERER, "https://www.pixiv.net/");
}
curl_easy_setopt(curl, CURLOPT_WRITEDATA, file);
CURLcode res = curl_easy_perform(curl);
fclose(file);
@ -43,10 +82,185 @@ bool dlfile(const char* url, const char* filename) {
return true;
}
char *fromurl(char *imgfile, char *dir) {
char s[512], *p, *tokens[128];
char *last;
int i = 0;
imgurl = imgfile;
snprintf(s, sizeof(s), "%s", imgfile);
for (
(p = strtok_r(s, "/", &last));
p;
(p = strtok_r(NULL, "/", &last))
) {
if (i < 127) tokens[i++] = p;
}
tokens[i] = NULL;
imgfilename = tokens[i - 1];
char *res;
res = (char *)malloc(1024);
if (res == NULL) {
return NULL;
}
snprintf(res, 1024, "%s/%s", dir, imgfilename);
if (!dlfile(imgfile, res)) {
printf("画像をダウンロードに失敗。URL: %s\n", imgfile);
return NULL;
}
return res;
}
void RenderCopy(SDL_Rect renderQuad) {
SDL_RenderCopyEx(
renderer,
texture,
NULL,
&renderQuad,
angle,
NULL,
flippedV ? SDL_FLIP_VERTICAL : (flippedH ? SDL_FLIP_HORIZONTAL : SDL_FLIP_NONE)
);
}
void rotateWindow(int w, int h) {
if (angle >= 360.0f) angle = 0.0f;
else if (angle <= -360.0f) angle = 0.0f;
else if (angle == 270.0f) angle = -90.0f;
else if (angle == -180.0f) angle = 180.0f;
imgWidth = h;
imgHeight = w;
aspectRatio = (float)imgWidth / imgHeight;
SDL_Rect renderQuad = { imgX, imgY, imgWidth, imgHeight };
SDL_RenderClear(renderer);
SDL_SetWindowSize(window, imgWidth + (imgX * 2), imgHeight + (imgY * 2));
RenderCopy(renderQuad);
SDL_RenderPresent(renderer);
}
void windowevent(SDL_Event e) {
int windowWidth, windowHeight;
SDL_GetWindowSize(window, &windowWidth, &windowHeight);
SDL_SetRenderDrawColor(renderer, 0, 0, 0, 255);
if (e.type == SDL_QUIT) {
quit = true;
} else if (e.type == SDL_KEYDOWN) {
if (e.key.keysym.sym == SDLK_q) {
quit = true;
} else if (e.key.keysym.sym == SDLK_e) {
// GIFアニメーションの停止・続き、0.7.0から追加する予定
} else if (e.key.keysym.sym == SDLK_r) {
angle -= 90.0f;
rotateWindow(imgWidth, imgHeight);
} else if (e.key.keysym.sym == SDLK_t) {
angle += 90.0f;
rotateWindow(imgWidth, imgHeight);
} else if (e.key.keysym.sym == SDLK_y) {
SDL_RenderClear(renderer);
SDL_Rect renderQuad = { imgX, imgY, imgWidth, imgHeight };
SDL_SetWindowSize(window, imgWidth + (imgX * 2), imgHeight + (imgY * 2));
RenderCopy(renderQuad);
flippedV = !flippedV;
SDL_RenderPresent(renderer);
} else if (e.key.keysym.sym == SDLK_u) {
SDL_RenderClear(renderer);
SDL_Rect renderQuad = { imgX, imgY, imgWidth, imgHeight };
SDL_SetWindowSize(window, imgWidth + (imgX * 2), imgHeight + (imgY * 2));
RenderCopy(renderQuad);
flippedH = !flippedH;
SDL_RenderPresent(renderer);
} else if (e.key.keysym.sym == SDLK_o) {
bool isurl = strncmp(imgurl, "http://", 7) == 0 ||
strncmp(imgurl, "https://", 8) == 0;
if (isurl && !hasdownloaded) {
char path[1024];
getcwd(path, 1024);
if (fromurl(imgurl, path) != NULL) puts("ダウンロード済み");
hasdownloaded = true;
}
} else if (e.key.keysym.sym == SDLK_p) {
// 画像をrsync|sftp|http postで使って共有する、0.7.0から追加する予定
}
} else if (e.type == SDL_MOUSEBUTTONDOWN) {
if (e.button.button == SDL_BUTTON_LEFT) {
drag = 1;
SDL_GetMouseState(&mouseX, &mouseY);
}
} else if (e.type == SDL_MOUSEBUTTONUP) {
if (e.button.button == SDL_BUTTON_LEFT) {
drag = 0;
}
} else if (e.type == SDL_MOUSEMOTION) {
if (drag) {
int newMouseX, newMouseY;
SDL_GetMouseState(&newMouseX, &newMouseY);
SDL_RenderClear(renderer);
if (newWidth != 0.0f) imgWidth = (newWidth);
if (newHeight != 0.0f) imgHeight = (newHeight);
imgX = newMouseX - (imgWidth / 2);
imgY = newMouseY - (imgHeight / 2);
SDL_Rect renderQuad = { imgX, imgY, imgWidth, imgHeight };
SDL_RenderClear(renderer);
RenderCopy(renderQuad);
SDL_RenderPresent(renderer);
}
} else if (e.type == SDL_MOUSEWHEEL) {
int curWidth = imgWidth;
int curHeight = imgHeight;
float zoomSpeed = 0.1f;
if (e.wheel.y > 0) {
zoom += zoomSpeed;
} else if (e.wheel.y < 0) {
zoom -= zoomSpeed;
}
if (zoom < 0.1f) {
zoom = 0.1f;
}
// 画像のサイズが変わった場合
newWidth = (float)imgWidth * zoom;
newHeight = (float)imgHeight * zoom;
float minLimit = 50.0f;
// 画像は50x50以下じゃ駄目
if (newWidth < minLimit) {
newWidth = minLimit;
newHeight = curHeight;
} else if (newHeight < minLimit) {
printf("%d\n", curWidth);
newWidth = curWidth;
newHeight = minLimit;
}
// テキスチャーのレンダーリングサイズの設定
SDL_RenderClear(renderer);
imgWidth = (int)newWidth;
imgHeight = (int)newHeight;
imgX = (windowWidth - imgWidth) / 2;
imgY = (windowHeight - imgHeight) / 2;
SDL_Rect renderQuad = { imgX, imgY, imgWidth, imgHeight };
SDL_RenderClear(renderer);
RenderCopy(renderQuad);
SDL_RenderPresent(renderer);
} else if (e.type == SDL_WINDOWEVENT && e.window.event == SDL_WINDOWEVENT_RESIZED) {
SDL_RenderClear(renderer);
// ウィンドウのサイズが変わった場合
int newWidth = e.window.data1;
int newHeight = e.window.data2;
@ -54,14 +268,16 @@ void windowevent(SDL_Event e) {
// 縦横比を変わらずに新しい大きさの算数
float newAspectRatio = (float)newWidth / newHeight;
int scaledWidth, scaledHeight;
if (newAspectRatio != aspectRatio) {
// 画像よりウィンドウの方が広い場合
// 画像よりウィンドウの方が広い場合
scaledHeight = angle == 90 || angle == -90 ? newWidth : newHeight;
scaledHeight = newHeight;
scaledWidth = (int)(scaledHeight * aspectRatio);
} else {
// 画像よりウィンドウの方が高い場合
scaledWidth = newWidth;
scaledHeight = newHeight;
scaledWidth = angle == 90 || angle == -90 ? newHeight : newWidth;
scaledHeight = angle == 90 || angle == -90 ? newWidth : newHeight;
}
// 画像は50x50以下じゃ駄目
@ -72,35 +288,66 @@ void windowevent(SDL_Event e) {
// 大きすぎの場合もふざけんな
if (scaledWidth >= (screenWidth-20)) scaledWidth = screenWidth-20;
if (scaledHeight >= (screenHeight-20)) scaledWidth = screenHeight-20;
if (scaledHeight >= (screenHeight-20)) scaledHeight = screenHeight-20;
// テキスチャーのれんダーリングサイズの設定
SDL_Rect renderQuad = { imgWidth, imgHeight, scaledWidth, scaledHeight };
SDL_RenderCopy(renderer, texture, NULL, &renderQuad);
SDL_SetWindowSize(window, scaledWidth, scaledHeight);
imgWidth = scaledWidth;
imgHeight = scaledHeight;
// テキスチャーのレンダーリングサイズの設定
SDL_Rect renderQuad = { imgX, imgY, imgWidth, imgHeight };
SDL_SetWindowSize(window, imgWidth + (imgX * 2), imgHeight + (imgY * 2));
RenderCopy(renderQuad);
SDL_RenderPresent(renderer);
} else if (e.type == SDL_WINDOWEVENT && e.window.event == SDL_WINDOWEVENT_MOVED) {
SDL_Rect renderQuad = { imgX, imgY, imgWidth, imgHeight };
SDL_RenderClear(renderer);
RenderCopy(renderQuad);
SDL_SetWindowSize(window, imgWidth + (imgX * 2), imgHeight + (imgY * 2));
SDL_RenderPresent(renderer);
} else if (e.type == SDL_WINDOWEVENT && e.window.event == SDL_WINDOWEVENT_EXPOSED) {
// 再描画が必要な場合
if (init == 1) return;
init = 1;
// 画面の更新
SDL_RenderClear(renderer);
// テキスチャーの表示
SDL_RenderCopy(renderer, texture, NULL, NULL);
if (
(imgWidth >= (screenWidth - 100)) &&
imgHeight >= (screenHeight - 100)
) {
imgWidth = (screenWidth - 100);
imgHeight = (screenHeight - 100);
} else if (
(imgWidth >= (screenWidth - 100)) &&
imgHeight <= (screenHeight - 100)
) {
imgWidth = (screenWidth - 100);
imgHeight = (imgWidth * aspectRatio);
} else if (
(imgWidth <= (screenWidth - 100)) &&
imgHeight >= (screenHeight - 100)
) {
imgHeight = (screenHeight - 100);
imgWidth = (imgHeight * aspectRatio);
}
// 画面の更新
SDL_Rect renderQuad = { imgX, imgY, imgWidth, imgHeight };
RenderCopy(renderQuad);
SDL_SetWindowSize(window, imgWidth + (imgX * 2), imgHeight + (imgY * 2));
SDL_RenderPresent(renderer);
}
}
int main(int argc, char* argv[]) {
if (argc < 2) {
printf("使用方法: %s <画像ファイル>\n", sofname);
return 1;
}
void usage() {
printf("%s-%s\nusage: %s [file or url]\n", sofname, version, sofname);
}
if (strncmp(argv[1], "-v", 2) == 0) {
printf("%s-%s\n", sofname, version);
return 0;
int main(int argc, char *argv[]) {
if (argc < 2) {
usage();
return 1;
}
// SDL2とSDL2_imageの初期設定
@ -115,25 +362,20 @@ int main(int argc, char* argv[]) {
return 1;
}
const char* imgfile = argv[1];
const char *imgfile = argv[1];
// URLの場合、仮にダウンロードして
bool isurl = strncmp(imgfile, "http://", 7) == 0 ||
strncmp(imgfile, "https://", 8) == 0;
char tmpname[] = "/tmp/netimg.png";
if (isurl) {
if (!dlfile(imgfile, tmpname)) {
printf("画像をダウンロードに失敗。URL: %s\n", imgfile);
SDL_DestroyRenderer(renderer);
SDL_DestroyWindow(window);
SDL_Quit();
return 1;
}
imgfile = tmpname;
imgfile = isurl ? fromurl(argv[1], "/tmp") : argv[1];
if (imgfile == NULL) {
SDL_DestroyRenderer(renderer);
SDL_DestroyWindow(window);
SDL_Quit();
}
// 画像の読込
SDL_Surface* imgsurface = IMG_Load(imgfile);
SDL_Surface *imgsurface = IMG_Load(imgfile);
if (imgsurface == NULL) {
printf("画像の読込に失敗:%s\n", IMG_GetError());
SDL_DestroyRenderer(renderer);
@ -204,9 +446,6 @@ int main(int argc, char* argv[]) {
}
// 掃除
if (isurl) {
remove(tmpname);
}
SDL_DestroyTexture(texture);
SDL_DestroyRenderer(renderer);
SDL_DestroyWindow(window);

48
mivfx.1 ノーマルファイル
ファイルの表示

@ -0,0 +1,48 @@
.TH MIVFX 1 VERSION
.SH NAME
mivfx - minimalist image view for x
.SH SYNOPSIS
.B mivfx
[\fI\,file\fR|\fI\,url\fR]
.SH DESCRIPTION
.PP
ミニマリストな画像ビューアーです。
.SH KEYBINDING
.TP
\fB\,Q\fR
終了
.TP
\fB\,R\fR
画像を-90°で回転する
.TP
\fB\,T\fR
画像を+90°で回転する
.TP
\fB\,Y\fR
縦側に反転する
.TP
\fB\,U\fR
横側に反転する
.TP
\fB\,マウスでスクロール\fR
ズームインやズームアウト
.TP
\fB\,マウスで移動\fR
画像の移動
.SH EXAMPLES
\&...
$ mivfx ~/画像/image.png
.ED
.br
ローカルな画像を開く
\&...
$ mivfx https://076.moe/image.png
.ED
.br
リモートサーバから画像を開く
.SH AUTHORS
.PP
テクニカル諏訪子

9
mivfx.desktop ノーマルファイル
ファイルの表示

@ -0,0 +1,9 @@
[Desktop Entry]
Type=Application
Name=mivfx
GenericName=Image Viewer
GenericName[ja]=画像ビューアー
Exec=mivfx %F
MimeType=image/bmp;image/gif;image/jpeg;image/jpg;image/png;image/tiff;image/x-bmp;image/x-portable-anymap;image/x-portable-bitmap;image/x-portable-graymap;image/x-tga;image/x-xpixmap;image/webp;image/heic;image/svg+xml;application/postscript;image/jp2;image/jxl;image/avif;image/heif;
NoDisplay=true
Icon=mivfx