You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 
 
 

706 lines
19 KiB

  1. /*
  2. * libpipi Proper image processing implementation library
  3. * Copyright (c) 2004-2008 Sam Hocevar <sam@zoy.org>
  4. * All Rights Reserved
  5. *
  6. * $Id$
  7. *
  8. * This library is free software. It comes without any warranty, to
  9. * the extent permitted by applicable law. You can redistribute it
  10. * and/or modify it under the terms of the Do What The Fuck You Want
  11. * To Public License, Version 2, as published by Sam Hocevar. See
  12. * http://sam.zoy.org/wtfpl/COPYING for more details.
  13. */
  14. /*
  15. * context.c: processing stack handling routines
  16. */
  17. #include "config.h"
  18. #include "common.h"
  19. #include <stdio.h>
  20. #include <stdlib.h>
  21. #include <stdarg.h>
  22. #include <string.h>
  23. #include "pipi.h"
  24. #include "pipi_internals.h"
  25. pipi_context_t *pipi_create_context()
  26. {
  27. pipi_context_t *ret;
  28. ret = malloc(sizeof(pipi_context_t));
  29. memset(ret, 0, sizeof(pipi_context_t));
  30. return ret;
  31. }
  32. void pipi_destroy_context(pipi_context_t *ctx)
  33. {
  34. free(ctx);
  35. }
  36. int pipi_command(pipi_context_t *ctx, char const *cmd, ...)
  37. {
  38. if(!strcmp(cmd, "load"))
  39. {
  40. char const *file;
  41. va_list ap;
  42. va_start(ap, cmd);
  43. file = va_arg(ap, char const *);
  44. va_end(ap);
  45. ctx->images[ctx->nimages] = pipi_load(file);
  46. if(ctx->images[ctx->nimages] == NULL)
  47. return -1;
  48. ctx->nimages++;
  49. }
  50. else if(!strcmp(cmd, "save"))
  51. {
  52. char const *file;
  53. va_list ap;
  54. if(ctx->nimages < 1)
  55. return -1;
  56. ctx->nimages--;
  57. va_start(ap, cmd);
  58. file = va_arg(ap, char const *);
  59. va_end(ap);
  60. pipi_save(ctx->images[ctx->nimages], file);
  61. pipi_free(ctx->images[ctx->nimages]);
  62. }
  63. else if(!strcmp(cmd, "dither"))
  64. {
  65. pipi_image_t *src, *dst;
  66. char const *method;
  67. va_list ap;
  68. if(ctx->nimages < 1)
  69. return -1;
  70. va_start(ap, cmd);
  71. method = va_arg(ap, char const *);
  72. va_end(ap);
  73. src = ctx->images[ctx->nimages - 1];
  74. dst = NULL;
  75. if(!strcmp(method, "ost"))
  76. dst = pipi_dither_ostromoukhov(src, 0);
  77. else if(!strcmp(method, "sost"))
  78. dst = pipi_dither_ostromoukhov(src, 1);
  79. else if(!strcmp(method, "ediff"))
  80. {
  81. if(ctx->nimages < 2)
  82. return -1;
  83. dst = pipi_dither_ediff(ctx->images[ctx->nimages - 2], src, 0);
  84. pipi_free(ctx->images[ctx->nimages - 2]);
  85. ctx->nimages--;
  86. }
  87. else if(!strcmp(method, "sediff"))
  88. {
  89. if(ctx->nimages < 2)
  90. return -1;
  91. dst = pipi_dither_ediff(ctx->images[ctx->nimages - 2], src, 1);
  92. pipi_free(ctx->images[ctx->nimages - 2]);
  93. ctx->nimages--;
  94. }
  95. else if(!strcmp(method, "ordered"))
  96. {
  97. if(ctx->nimages < 2)
  98. return -1;
  99. dst = pipi_dither_ordered(ctx->images[ctx->nimages - 2], src);
  100. pipi_free(ctx->images[ctx->nimages - 2]);
  101. ctx->nimages--;
  102. }
  103. else if(!strncmp(method, "halftone", 8))
  104. {
  105. double r, angle = .0;
  106. method = strchr(method, ':');
  107. if(!method)
  108. return -1;
  109. r = atof(method + 1);
  110. method = strchr(method + 1, ':');
  111. if(method)
  112. angle = atof(method + 1);
  113. if(r < 1.)
  114. r = 1.;
  115. dst = pipi_dither_halftone(src, r, angle);
  116. }
  117. else if(!strcmp(method, "random"))
  118. dst = pipi_dither_random(src);
  119. else if(!strcmp(method, "dbs"))
  120. dst = pipi_dither_dbs(src);
  121. if(dst == NULL)
  122. return -1;
  123. pipi_free(src);
  124. ctx->images[ctx->nimages - 1] = dst;
  125. }
  126. else if(!strcmp(cmd, "blur"))
  127. {
  128. pipi_image_t *src, *dst;
  129. char const *arg;
  130. va_list ap;
  131. double w, h, a = 0.0;
  132. if(ctx->nimages < 1)
  133. return -1;
  134. va_start(ap, cmd);
  135. arg = va_arg(ap, char const *);
  136. va_end(ap);
  137. w = h = atof(arg);
  138. arg = strchr(arg, 'x');
  139. if(arg)
  140. {
  141. h = atof(arg + 1);
  142. arg = strchr(arg, 'r');
  143. if(arg)
  144. a = atof(arg + 1);
  145. }
  146. src = ctx->images[ctx->nimages - 1];
  147. dst = pipi_gaussian_blur_ext(src, w, h, a, 0.0, 0.0);
  148. if(dst == NULL)
  149. return -1;
  150. pipi_free(src);
  151. ctx->images[ctx->nimages - 1] = dst;
  152. }
  153. else if(!strcmp(cmd, "boxblur"))
  154. {
  155. pipi_image_t *src, *dst;
  156. char const *arg;
  157. va_list ap;
  158. double w, h;
  159. if(ctx->nimages < 1)
  160. return -1;
  161. va_start(ap, cmd);
  162. arg = va_arg(ap, char const *);
  163. va_end(ap);
  164. w = h = atof(arg);
  165. arg = strchr(arg, 'x');
  166. if(arg)
  167. h = atof(arg + 1);
  168. src = ctx->images[ctx->nimages - 1];
  169. dst = pipi_box_blur_ext(src, w, h);
  170. if(dst == NULL)
  171. return -1;
  172. pipi_free(src);
  173. ctx->images[ctx->nimages - 1] = dst;
  174. }
  175. else if(!strcmp(cmd, "median"))
  176. {
  177. pipi_image_t *src, *dst;
  178. char const *arg;
  179. va_list ap;
  180. double w, h;
  181. if(ctx->nimages < 1)
  182. return -1;
  183. va_start(ap, cmd);
  184. arg = va_arg(ap, char const *);
  185. va_end(ap);
  186. w = h = atof(arg);
  187. arg = strchr(arg, 'x');
  188. if(arg)
  189. h = atof(arg + 1);
  190. src = ctx->images[ctx->nimages - 1];
  191. dst = pipi_median_ext(src, w, h);
  192. if(dst == NULL)
  193. return -1;
  194. pipi_free(src);
  195. ctx->images[ctx->nimages - 1] = dst;
  196. }
  197. else if(!strcmp(cmd, "geometry"))
  198. {
  199. pipi_image_t *src, *dst;
  200. char const *arg;
  201. va_list ap;
  202. int w, h;
  203. if(ctx->nimages < 1)
  204. return -1;
  205. va_start(ap, cmd);
  206. arg = va_arg(ap, char const *);
  207. va_end(ap);
  208. w = atoi(arg);
  209. arg = strchr(arg, 'x');
  210. if(!arg)
  211. return -1;
  212. h = atoi(arg + 1);
  213. if(w <= 0 || h <= 0)
  214. return -1;
  215. src = ctx->images[ctx->nimages - 1];
  216. dst = pipi_resize(src, w, h);
  217. if(dst == NULL)
  218. return -1;
  219. pipi_free(src);
  220. ctx->images[ctx->nimages - 1] = dst;
  221. }
  222. else if(!strcmp(cmd, "tile"))
  223. {
  224. pipi_image_t *src, *dst;
  225. char const *arg;
  226. va_list ap;
  227. int w, h;
  228. if(ctx->nimages < 1)
  229. return -1;
  230. va_start(ap, cmd);
  231. arg = va_arg(ap, char const *);
  232. va_end(ap);
  233. w = atoi(arg);
  234. arg = strchr(arg, 'x');
  235. if(!arg)
  236. return -1;
  237. h = atoi(arg + 1);
  238. if(w <= 0 || h <= 0)
  239. return -1;
  240. src = ctx->images[ctx->nimages - 1];
  241. dst = pipi_tile(src, w, h);
  242. if(dst == NULL)
  243. return -1;
  244. pipi_free(src);
  245. ctx->images[ctx->nimages - 1] = dst;
  246. }
  247. else if(!strcmp(cmd, "scale"))
  248. {
  249. pipi_image_t *src, *dst;
  250. char const *arg;
  251. va_list ap;
  252. double scale;
  253. int w, h;
  254. if(ctx->nimages < 1)
  255. return -1;
  256. src = ctx->images[ctx->nimages - 1];
  257. va_start(ap, cmd);
  258. arg = va_arg(ap, char const *);
  259. va_end(ap);
  260. scale = atof(arg);
  261. w = (int)(scale * src->w + 0.5);
  262. h = (int)(scale * src->h + 0.5);
  263. if(w <= 0 || h <= 0)
  264. return -1;
  265. dst = pipi_resize(src, w, h);
  266. if(dst == NULL)
  267. return -1;
  268. pipi_free(src);
  269. ctx->images[ctx->nimages - 1] = dst;
  270. }
  271. else if(!strcmp(cmd, "brightness"))
  272. {
  273. pipi_image_t *src, *dst;
  274. char const *arg;
  275. va_list ap;
  276. double val;
  277. if(ctx->nimages < 1)
  278. return -1;
  279. va_start(ap, cmd);
  280. arg = va_arg(ap, char const *);
  281. va_end(ap);
  282. val = atof(arg);
  283. src = ctx->images[ctx->nimages - 1];
  284. dst = pipi_brightness(src, val);
  285. if(dst == NULL)
  286. return -1;
  287. pipi_free(src);
  288. ctx->images[ctx->nimages - 1] = dst;
  289. }
  290. else if(!strcmp(cmd, "contrast"))
  291. {
  292. pipi_image_t *src, *dst;
  293. char const *arg;
  294. va_list ap;
  295. double val;
  296. if(ctx->nimages < 1)
  297. return -1;
  298. va_start(ap, cmd);
  299. arg = va_arg(ap, char const *);
  300. va_end(ap);
  301. val = atof(arg);
  302. src = ctx->images[ctx->nimages - 1];
  303. dst = pipi_contrast(src, val);
  304. if(dst == NULL)
  305. return -1;
  306. pipi_free(src);
  307. ctx->images[ctx->nimages - 1] = dst;
  308. }
  309. else if(!strcmp(cmd, "threshold"))
  310. {
  311. pipi_image_t *src, *dst;
  312. char const *arg;
  313. va_list ap;
  314. double val;
  315. if(ctx->nimages < 1)
  316. return -1;
  317. va_start(ap, cmd);
  318. arg = va_arg(ap, char const *);
  319. va_end(ap);
  320. val = atof(arg);
  321. src = ctx->images[ctx->nimages - 1];
  322. dst = pipi_threshold(src, val);
  323. if(dst == NULL)
  324. return -1;
  325. pipi_free(src);
  326. ctx->images[ctx->nimages - 1] = dst;
  327. }
  328. else if(!strcmp(cmd, "hflip"))
  329. {
  330. pipi_image_t *tmp;
  331. if(ctx->nimages < 1)
  332. return -1;
  333. tmp = ctx->images[ctx->nimages - 1];
  334. ctx->images[ctx->nimages - 1] = pipi_hflip(tmp);
  335. pipi_free(tmp);
  336. }
  337. else if(!strcmp(cmd, "vflip"))
  338. {
  339. pipi_image_t *tmp;
  340. if(ctx->nimages < 1)
  341. return -1;
  342. tmp = ctx->images[ctx->nimages - 1];
  343. ctx->images[ctx->nimages - 1] = pipi_vflip(tmp);
  344. pipi_free(tmp);
  345. }
  346. else if(!strcmp(cmd, "rotate90"))
  347. {
  348. pipi_image_t *tmp;
  349. if(ctx->nimages < 1)
  350. return -1;
  351. tmp = ctx->images[ctx->nimages - 1];
  352. ctx->images[ctx->nimages - 1] = pipi_rotate90(tmp);
  353. pipi_free(tmp);
  354. }
  355. else if(!strcmp(cmd, "rotate180"))
  356. {
  357. pipi_image_t *tmp;
  358. if(ctx->nimages < 1)
  359. return -1;
  360. tmp = ctx->images[ctx->nimages - 1];
  361. ctx->images[ctx->nimages - 1] = pipi_rotate180(tmp);
  362. pipi_free(tmp);
  363. }
  364. else if(!strcmp(cmd, "rotate270"))
  365. {
  366. pipi_image_t *tmp;
  367. if(ctx->nimages < 1)
  368. return -1;
  369. tmp = ctx->images[ctx->nimages - 1];
  370. ctx->images[ctx->nimages - 1] = pipi_rotate270(tmp);
  371. pipi_free(tmp);
  372. }
  373. else if(!strcmp(cmd, "order"))
  374. {
  375. pipi_image_t *tmp;
  376. if(ctx->nimages < 1)
  377. return -1;
  378. tmp = ctx->images[ctx->nimages - 1];
  379. ctx->images[ctx->nimages - 1] = pipi_order(tmp);
  380. pipi_free(tmp);
  381. }
  382. else if(!strcmp(cmd, "split"))
  383. {
  384. pipi_image_t *src;
  385. if(ctx->nimages < 1)
  386. return -1;
  387. src = ctx->images[ctx->nimages - 1];
  388. ctx->nimages += 2;
  389. ctx->images[ctx->nimages - 3] = pipi_red(src);
  390. ctx->images[ctx->nimages - 2] = pipi_green(src);
  391. ctx->images[ctx->nimages - 1] = pipi_blue(src);
  392. pipi_free(src);
  393. }
  394. else if(!strcmp(cmd, "combine"))
  395. {
  396. pipi_image_t *dst;
  397. if(ctx->nimages < 3)
  398. return -1;
  399. dst = pipi_rgb(ctx->images[ctx->nimages - 3],
  400. ctx->images[ctx->nimages - 2],
  401. ctx->images[ctx->nimages - 1]);
  402. if(dst == NULL)
  403. return -1;
  404. pipi_free(ctx->images[ctx->nimages - 3]);
  405. pipi_free(ctx->images[ctx->nimages - 2]);
  406. pipi_free(ctx->images[ctx->nimages - 1]);
  407. ctx->images[ctx->nimages - 3] = dst;
  408. ctx->nimages -= 2;
  409. }
  410. else if(!strcmp(cmd, "mean"))
  411. {
  412. pipi_image_t *dst;
  413. if(ctx->nimages < 2)
  414. return -1;
  415. dst = pipi_mean(ctx->images[ctx->nimages - 2],
  416. ctx->images[ctx->nimages - 1]);
  417. if(dst == NULL)
  418. return -1;
  419. pipi_free(ctx->images[ctx->nimages - 2]);
  420. pipi_free(ctx->images[ctx->nimages - 1]);
  421. ctx->images[ctx->nimages - 2] = dst;
  422. ctx->nimages--;
  423. }
  424. else if(!strcmp(cmd, "min"))
  425. {
  426. pipi_image_t *dst;
  427. if(ctx->nimages < 2)
  428. return -1;
  429. dst = pipi_min(ctx->images[ctx->nimages - 2],
  430. ctx->images[ctx->nimages - 1]);
  431. if(dst == NULL)
  432. return -1;
  433. pipi_free(ctx->images[ctx->nimages - 2]);
  434. pipi_free(ctx->images[ctx->nimages - 1]);
  435. ctx->images[ctx->nimages - 2] = dst;
  436. ctx->nimages--;
  437. }
  438. else if(!strcmp(cmd, "max"))
  439. {
  440. pipi_image_t *dst;
  441. if(ctx->nimages < 2)
  442. return -1;
  443. dst = pipi_max(ctx->images[ctx->nimages - 2],
  444. ctx->images[ctx->nimages - 1]);
  445. if(dst == NULL)
  446. return -1;
  447. pipi_free(ctx->images[ctx->nimages - 2]);
  448. pipi_free(ctx->images[ctx->nimages - 1]);
  449. ctx->images[ctx->nimages - 2] = dst;
  450. ctx->nimages--;
  451. }
  452. else if(!strcmp(cmd, "add"))
  453. {
  454. pipi_image_t *dst;
  455. if(ctx->nimages < 2)
  456. return -1;
  457. dst = pipi_add(ctx->images[ctx->nimages - 2],
  458. ctx->images[ctx->nimages - 1]);
  459. if(dst == NULL)
  460. return -1;
  461. pipi_free(ctx->images[ctx->nimages - 2]);
  462. pipi_free(ctx->images[ctx->nimages - 1]);
  463. ctx->images[ctx->nimages - 2] = dst;
  464. ctx->nimages--;
  465. }
  466. else if(!strcmp(cmd, "sub"))
  467. {
  468. pipi_image_t *dst;
  469. if(ctx->nimages < 2)
  470. return -1;
  471. dst = pipi_sub(ctx->images[ctx->nimages - 2],
  472. ctx->images[ctx->nimages - 1]);
  473. if(dst == NULL)
  474. return -1;
  475. pipi_free(ctx->images[ctx->nimages - 2]);
  476. pipi_free(ctx->images[ctx->nimages - 1]);
  477. ctx->images[ctx->nimages - 2] = dst;
  478. ctx->nimages--;
  479. }
  480. else if(!strcmp(cmd, "difference"))
  481. {
  482. pipi_image_t *dst;
  483. if(ctx->nimages < 2)
  484. return -1;
  485. dst = pipi_difference(ctx->images[ctx->nimages - 2],
  486. ctx->images[ctx->nimages - 1]);
  487. if(dst == NULL)
  488. return -1;
  489. pipi_free(ctx->images[ctx->nimages - 2]);
  490. pipi_free(ctx->images[ctx->nimages - 1]);
  491. ctx->images[ctx->nimages - 2] = dst;
  492. ctx->nimages--;
  493. }
  494. else if(!strcmp(cmd, "multiply"))
  495. {
  496. pipi_image_t *dst;
  497. if(ctx->nimages < 2)
  498. return -1;
  499. dst = pipi_multiply(ctx->images[ctx->nimages - 2],
  500. ctx->images[ctx->nimages - 1]);
  501. if(dst == NULL)
  502. return -1;
  503. pipi_free(ctx->images[ctx->nimages - 2]);
  504. pipi_free(ctx->images[ctx->nimages - 1]);
  505. ctx->images[ctx->nimages - 2] = dst;
  506. ctx->nimages--;
  507. }
  508. else if(!strcmp(cmd, "divide"))
  509. {
  510. pipi_image_t *dst;
  511. if(ctx->nimages < 2)
  512. return -1;
  513. dst = pipi_divide(ctx->images[ctx->nimages - 2],
  514. ctx->images[ctx->nimages - 1]);
  515. if(dst == NULL)
  516. return -1;
  517. pipi_free(ctx->images[ctx->nimages - 2]);
  518. pipi_free(ctx->images[ctx->nimages - 1]);
  519. ctx->images[ctx->nimages - 2] = dst;
  520. ctx->nimages--;
  521. }
  522. else if(!strcmp(cmd, "screen"))
  523. {
  524. pipi_image_t *dst;
  525. if(ctx->nimages < 2)
  526. return -1;
  527. dst = pipi_screen(ctx->images[ctx->nimages - 2],
  528. ctx->images[ctx->nimages - 1]);
  529. if(dst == NULL)
  530. return -1;
  531. pipi_free(ctx->images[ctx->nimages - 2]);
  532. pipi_free(ctx->images[ctx->nimages - 1]);
  533. ctx->images[ctx->nimages - 2] = dst;
  534. ctx->nimages--;
  535. }
  536. else if(!strcmp(cmd, "overlay"))
  537. {
  538. pipi_image_t *dst;
  539. if(ctx->nimages < 2)
  540. return -1;
  541. dst = pipi_overlay(ctx->images[ctx->nimages - 2],
  542. ctx->images[ctx->nimages - 1]);
  543. if(dst == NULL)
  544. return -1;
  545. pipi_free(ctx->images[ctx->nimages - 2]);
  546. pipi_free(ctx->images[ctx->nimages - 1]);
  547. ctx->images[ctx->nimages - 2] = dst;
  548. ctx->nimages--;
  549. }
  550. else if(!strcmp(cmd, "wrap"))
  551. {
  552. if(ctx->nimages < 1)
  553. return -1;
  554. ctx->images[ctx->nimages - 1]->wrap = 1;
  555. }
  556. else if(!strcmp(cmd, "autocontrast"))
  557. {
  558. pipi_image_t *tmp;
  559. if(ctx->nimages < 1)
  560. return -1;
  561. tmp = ctx->images[ctx->nimages - 1];
  562. ctx->images[ctx->nimages - 1] = pipi_autocontrast(tmp);
  563. pipi_free(tmp);
  564. }
  565. else if(!strcmp(cmd, "invert"))
  566. {
  567. pipi_image_t *tmp;
  568. if(ctx->nimages < 1)
  569. return -1;
  570. tmp = ctx->images[ctx->nimages - 1];
  571. ctx->images[ctx->nimages - 1] = pipi_invert(tmp);
  572. pipi_free(tmp);
  573. }
  574. else if(!strcmp(cmd, "dilate"))
  575. {
  576. pipi_image_t *tmp;
  577. if(ctx->nimages < 1)
  578. return -1;
  579. tmp = ctx->images[ctx->nimages - 1];
  580. ctx->images[ctx->nimages - 1] = pipi_dilate(tmp);
  581. pipi_free(tmp);
  582. }
  583. else if(!strcmp(cmd, "erode"))
  584. {
  585. pipi_image_t *tmp;
  586. if(ctx->nimages < 1)
  587. return -1;
  588. tmp = ctx->images[ctx->nimages - 1];
  589. ctx->images[ctx->nimages - 1] = pipi_erode(tmp);
  590. pipi_free(tmp);
  591. }
  592. else if(!strcmp(cmd, "gray"))
  593. {
  594. if(ctx->nimages < 1)
  595. return -1;
  596. pipi_getpixels(ctx->images[ctx->nimages - 1], PIPI_PIXELS_Y_F);
  597. }
  598. else if(!strcmp(cmd, "free"))
  599. {
  600. if(ctx->nimages < 1)
  601. return -1;
  602. ctx->nimages--;
  603. pipi_free(ctx->images[ctx->nimages]);
  604. }
  605. else if(!strcmp(cmd, "dup"))
  606. {
  607. if(ctx->nimages < 1)
  608. return -1;
  609. ctx->images[ctx->nimages] = pipi_copy(ctx->images[ctx->nimages - 1]);
  610. ctx->nimages++;
  611. }
  612. else if(!strcmp(cmd, "swap"))
  613. {
  614. pipi_image_t *tmp;
  615. if(ctx->nimages < 2)
  616. return -1;
  617. tmp = ctx->images[ctx->nimages - 1];
  618. ctx->images[ctx->nimages - 1] = ctx->images[ctx->nimages - 2];
  619. ctx->images[ctx->nimages - 2] = tmp;
  620. }
  621. else if(!strcmp(cmd, "roll"))
  622. {
  623. pipi_image_t *tmp;
  624. char const *arg;
  625. va_list ap;
  626. int val;
  627. va_start(ap, cmd);
  628. arg = va_arg(ap, char const *);
  629. va_end(ap);
  630. val = atoi(arg);
  631. if(val <= 0 || ctx->nimages < val)
  632. return -1;
  633. if(val == 1)
  634. return 0;
  635. tmp = ctx->images[ctx->nimages - val];
  636. memmove(ctx->images + ctx->nimages - val,
  637. ctx->images + ctx->nimages - val + 1,
  638. (val - 1) * sizeof(*ctx->images));
  639. ctx->images[ctx->nimages - 1] = tmp;
  640. }
  641. else if(!strcmp(cmd, "line"))
  642. {
  643. char const *arg;
  644. va_list ap;
  645. int x1, y1, x2, y2, aa = 0, ret;
  646. uint32_t color = 0;
  647. if(ctx->nimages < 1)
  648. return -1;
  649. va_start(ap, cmd);
  650. arg = va_arg(ap, char const *);
  651. va_end(ap);
  652. ret = sscanf(arg, "%d,%d,%d,%d,%08x,%d",
  653. &x1, &y1, &x2, &y2, &color, &aa);
  654. if(ret < 5) return -1;
  655. ctx->images[ctx->nimages] = pipi_copy(ctx->images[ctx->nimages - 1]);
  656. pipi_draw_line(ctx->images[ctx->nimages],
  657. x1, y1, x2, y2, color, aa);
  658. ctx->nimages++;
  659. }
  660. else
  661. {
  662. return -1;
  663. }
  664. return 0;
  665. }